[squeak-dev] FFI: FFI-Kernel-mt.210.mcz

commits at source.squeak.org commits at source.squeak.org
Wed Aug 18 08:08:21 UTC 2021

Marcel Taeumel uploaded a new version of FFI-Kernel to project FFI:

==================== Summary ====================

Name: FFI-Kernel-mt.210
Author: mt
Time: 18 August 2021, 10:08:19.325508 am
UUID: 694f587f-daa5-8e40-9b51-b8b7037f72e5
Ancestors: FFI-Kernel-mt.209

Fixes a regresion with type invalidation, which is an issue when updating existing FFI setup.

More robust re-initialization of existing atomic types. Now supports renaming and add/remove using the AtomicTypeCodes table.

=============== Diff against FFI-Kernel-mt.209 ===============

Item was changed:
  ----- Method: ExternalType class>>basicInitializeAtomicTypes (in category 'class initialization') -----
+ 	"Strong references required because there is no lazy initialization like there is for struct types and array types."
+ 	AtomicTypes ifNil: [AtomicTypes := Dictionary new].
+ 	"Add new atomic types using the current configuration of AtomicTypeCodes."
+ 	AtomicTypeCodes keysDo: [:typeName |
+ 		(AtomicTypes includesKey: typeName) ifFalse: [
+ 			self newTypeForAtomicNamed: typeName]].
+ 	"Remove discarded types."
+ 	AtomicTypes keys do: [:typeName |
+ 		(AtomicTypeCodes includesKey: typeName) ifFalse: [
+ 			AtomicTypes removeKey: typeName]].!
- 	AtomicTypes ifNil: [
- 		AtomicTypes := Dictionary new. "Strong references required because there is no lazy atomic type initialization like there is for struct types and array types."
- 		self atomicTypeNames do: [:typeName |
- 			self newTypeForAtomicNamed: typeName]].!

Item was changed:
  ----- Method: ExternalType class>>initializeAtomicTypeCodes (in category 'class initialization') -----
  	"ExternalType initializeAtomicTypeCodes"
  	AtomicTypeCodes := OrderedDictionary newFrom: {
  		#'void' -> FFITypeVoid.
  		#'bool' -> FFITypeBool.
  		#'uint8_t' -> FFITypeUnsignedInt8.
  		#'int8_t' -> FFITypeSignedInt8.
  		#'uint16_t' -> FFITypeUnsignedInt16.
  		#'int16_t' -> FFITypeSignedInt16.
  		#'uint32_t' -> FFITypeUnsignedInt32.
  		#'int32_t' -> FFITypeSignedInt32.
  		#'uint64_t' -> FFITypeUnsignedInt64.
  		#'int64_t' -> FFITypeSignedInt64.
  		#'uchar8_t' -> FFITypeUnsignedChar8.
  		#'char8_t' -> FFITypeSignedChar8.
  		#'uchar16_t' -> FFITypeUnsignedChar16.
  		#'char16_t' -> FFITypeSignedChar16.
  		#'uchar32_t' -> FFITypeUnsignedChar32.
  		#'char32_t' -> FFITypeSignedChar32.
  		#'float' -> FFITypeSingleFloat.
  		#'double' -> FFITypeDoubleFloat}.
+ 	"We must now update the names of all known atomic types."
+ 	AtomicTypes ifNotNil: [
+ 		AtomicTypes keys do: [:oldName |
+ 			| type newName |
+ 			type := AtomicTypes at: oldName.
+ 			newName := AtomicTypeCodes keyAtValue: type atomicType.
+ 			(AtomicTypes includesKey: newName) ifFalse: [
+ 				"Only store new names. Do not support name swap."
+ 				AtomicTypes removeKey: oldName.
+ 				AtomicTypes at: newName put: type.
+ 				type setAtomicTypeName: newName]]].!
- 	"We must now reset all atomic types because their names might have changed."
- 	AtomicTypes := nil.!

Item was changed:
  ----- Method: ExternalType class>>initializeStructureTypes (in category 'class initialization') -----
  	"(Re-)initialize all structure types and all array types. Preserves object identity of all involved types. If the amount of types changed, use #resetAllStructureTypes instead."
  	self basicInitializeStructureTypes.
  	self invalidateStructureTypes.
  	"1) Initialize all array types that have an atomic-or-pointer type as their content type."
+ 	self allArrayTypesDo: [:arrayType |
- 	self arrayTypesDo: [:arrayType |
  		(arrayType contentType isAtomic or: [arrayType contentType isPointerType]) ifTrue: [
  			arrayType newContentType: arrayType contentType]].
  	"2) Trigger #noticeModificationOf: callback to actually initialize all structure types."
  	ExternalStructure defineAllFields.
  	"Finally do some garbage collection."
  	self cleanupUnusedTypes.!

Item was changed:
  ----- Method: ExternalType class>>invalidateStructureTypes (in category 'class initialization') -----
+ 	self allStructTypesDo:[:structType |
- 	self structTypesDo:[:structType |
  		structType "asNonPointerType" invalidate.
  		structType asPointerType invalidate].
+ 	self allArrayTypesDo: [:arrayType |
- 	self arrayTypesDo: [:arrayType |
  		arrayType "asNonPointerType" invalidate.
  		arrayType asPointerType invalidate].!

More information about the Squeak-dev mailing list