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

commits at source.squeak.org commits at source.squeak.org
Tue Aug 17 10:00:19 UTC 2021


Marcel Taeumel uploaded a new version of FFI-Kernel to project FFI:
http://source.squeak.org/FFI/FFI-Kernel-mt.206.mcz

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

Name: FFI-Kernel-mt.206
Author: mt
Time: 17 August 2021, 12:00:18.644505 pm
UUID: 11a34cdc-d7d8-6b47-8bd8-a0774f3aeefc
Ancestors: FFI-Kernel-mt.205

Some clean-up and bugfixes:
- Generalize #becomeUnknownType to simplify edits to existing type aliases
- Use #isCharType where appropriate
- Nuke obsolete lookup functions in ExternalFunction
- Fix "instance list" protocol on ExternalType class; "all" includes type aliases, others do no; this is now consistent with #atomicTypesDo: and #allAtomicTypesDo:
- Nuke obsolete #becomeKnownTypeSafely on ExternalType now that #doneCompiling on ExternalStructure class works differently; only needed on ExternalUnknownType
- Adds some commentary

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

Item was changed:
  ----- Method: ExternalArrayType>>newTypeAlias (in category 'private') -----
  newTypeAlias
  	"A little bit expensive but easy to implement. Once the size information is encoded in the headerWord, we might be able to do some cheap update like for the alias-to-pointer type."
  
- 	| newUnknownType |	
  	self isTypeAlias ifFalse: [^ self].
+ 	self becomeUnknownType becomeKnownType.!
- 
- 	newUnknownType := ExternalUnknownType basicNew
- 		compiledSpec: self compiledSpec;
- 		byteAlignment: self byteAlignment;
- 		setReferentClass: referentClass;
- 		setReferencedType: referencedType;
- 		yourself.
- 	
- 	"Make my pointer type common again by setting the referentClass."
- 	newUnknownType setReferencedType: referencedType.
- 	referencedType setReferentClass: referentClass.
- 		
- 	self becomeForward: newUnknownType.
- 	newUnknownType becomeKnownType.!

Item was changed:
  ----- Method: ExternalData>>mightBeCString (in category 'testing') -----
  mightBeCString
  
+ 	^ self contentType isCharType and: [self size isNil]!
- 	^ self contentType = ExternalType char and: [self size isNil]!

Item was removed:
- ----- Method: ExternalFunction class>>atomicTypeNamed: (in category 'compiler support') -----
- atomicTypeNamed: aString
- 	^ExternalType atomicTypeNamed: aString!

Item was removed:
- ----- Method: ExternalFunction class>>structTypeNamed: (in category 'compiler support') -----
- structTypeNamed: aString
- 	^ExternalType structTypeNamed: aString!

Item was changed:
  ----- Method: ExternalPointerType>>isStringType (in category 'testing - special') -----
  isStringType
  	"If pointer to atomic, the atomic type is encoded directly in the headerWord. Might change in the future; use #asNonPointerType in that case."
  	
+ 	^ self isCharType!
- 	^ self atomicType = FFITypeUnsignedChar!

Item was added:
+ ----- Method: ExternalType class>>allArrayTypeNames (in category 'instance list') -----
+ allArrayTypeNames
+ 	"Answers the names of the currently known array types. Includes alias-to-array types."
+ 	
+ 	^ self allArrayTypes collect: [:each | each typeName]!

Item was added:
+ ----- Method: ExternalType class>>allArrayTypes (in category 'instance list') -----
+ allArrayTypes
+ 	"Answers all array types. Includes alias-to-array types."
+ 	
+ 	^ Array streamContents: [:stream |
+ 		self allArrayTypesDo: [:type | stream nextPut: type]]!

Item was added:
+ ----- Method: ExternalType class>>allArrayTypesDo: (in category 'instance list') -----
+ allArrayTypesDo: block
+ 	
+ 	self arrayTypesDo: block.
+ 
+ 	"Alias-to-array types are managed in StructTypes but are actual array types."
+ 	StructTypes do: [:each |
+ 		(each notNil "may be garbage collected" and: [each isArrayType])
+ 			ifTrue: [block value: each]].!

Item was added:
+ ----- Method: ExternalType class>>allAtomicTypeNames (in category 'instance list') -----
+ allAtomicTypeNames
+ 	"Answers the names of the currently known atomic types. Includes names for alias-to-atomic types."
+ 
+ 	^ self allAtomicTypes collect: [:type | type typeName] !

Item was added:
+ ----- Method: ExternalType class>>allAtomicTypes (in category 'instance list') -----
+ allAtomicTypes
+ 	"Answers the currently known atomic types. Includes alias-to-atomic types."
+ 
+ 	^ Array streamContents: [:stream |
+ 		self allAtomicTypesDo: [:type | stream nextPut: type]]!

Item was added:
+ ----- Method: ExternalType class>>allAtomicTypesDo: (in category 'instance list') -----
+ allAtomicTypesDo: block
+ 
+ 	self atomicTypesDo: block.
+ 	
+ 	self typeAliasTypesDo: [:type |
+ 		type isAtomic ifTrue: [block value: type]].!

Item was added:
+ ----- Method: ExternalType class>>allPointerTypeNames (in category 'instance list') -----
+ allPointerTypeNames
+ 
+ 	^ self allPointerTypes collect: [:each | each typeName]!

Item was added:
+ ----- Method: ExternalType class>>allPointerTypes (in category 'instance list') -----
+ allPointerTypes
+ 	"Answers the pointer types. Includes alias-to-pointer types."
+ 
+ 	^ Array streamContents: [:stream |	
+ 		self allPointerTypesDo: [:type | stream nextPut: type]]!

Item was added:
+ ----- Method: ExternalType class>>allPointerTypesDo: (in category 'instance list') -----
+ allPointerTypesDo: block
+ 	"Enumerat all pointer types, including alias-to-pointer types."
+ 
+ 	self pointerTypesDo: block.
+ 		
+ 	"Type alias-to-pointer types are managed in StructTypes but are actual pointer types."
+ 	StructTypes do: [:each | (each notNil and: [each isPointerType])
+ 		ifTrue: [block value: each]].!

Item was added:
+ ----- Method: ExternalType class>>allStructTypeNames (in category 'instance list') -----
+ allStructTypeNames
+ 	"Answers the names of the currently known struct types. Includes alias-to-struct types."
+ 
+ 	^ self allStructTypes collect: [:each | each typeName]!

Item was added:
+ ----- Method: ExternalType class>>allStructTypes (in category 'instance list') -----
+ allStructTypes
+ 	"Answers the currently known struct types, including alias-to-struct types."
+ 
+ 	^ Array streamContents: [:stream |
+ 		self allStructTypesDo: [:type | stream nextPut: type]]!

Item was added:
+ ----- Method: ExternalType class>>allStructTypesDo: (in category 'instance list') -----
+ allStructTypesDo: block
+ 	"Enumerate all struct types. Includes types for packed structs and unions. Includes type aliases."
+ 	
+ 	StructTypes do: [:each | (each notNil and: [each isStructureType])
+ 		ifTrue: [block value: each]]!

Item was changed:
  ----- Method: ExternalType class>>arrayTypesDo: (in category 'instance list') -----
  arrayTypesDo: block
  	
  	ArrayTypes do: [:sizes | sizes do: [:each |
  		each notNil "may be garbage collected"
+ 			ifTrue: [block value: each]]].!
- 			ifTrue: [block value: each]]].
- 
- 	"Type aliases to array types are managed in StructTypes but are actual array types."
- 	StructTypes do: [:each |
- 		(each notNil "may be garbage collected" and: [each isArrayType])
- 			ifTrue: [block value: each]].!

Item was changed:
  ----- Method: ExternalType class>>pointerTypes (in category 'instance list') -----
  pointerTypes
+ 	"Answers the pointer types."
- 	"Answers the currently known pointer types, including type-alias-to-pointer types."
  
  	^ Array streamContents: [:stream |	
  		self pointerTypesDo: [:type | stream nextPut: type]]!

Item was changed:
  ----- Method: ExternalType class>>pointerTypesDo: (in category 'instance list') -----
  pointerTypesDo: block
+ 	"Enumerate all pointer types. No alias-to-pointer types, but pointer types for other type aliases."
- 	"Answers the currently known pointer types, including type-alias-to-pointer types."
  
+ 	self allAtomicTypesDo: [:type |
- 	self atomicTypesDo: [:type |
  		block value: type asPointerType].
+ 	self allStructTypesDo: [:type |
- 	self structTypesDo: [:type |
  		block value: type asPointerType].
+ 	self allArrayTypesDo: [:type |
+ 		block value: type asPointerType].!
- 	self arrayTypesDo: [:type |
- 		block value: type asPointerType].
- 		
- 	"Type aliases to pointer types are managed in StructTypes but are actual pointer types."
- 	StructTypes do: [:each | (each notNil and: [each isPointerType])
- 		ifTrue: [block value: each]].!

Item was removed:
- ----- Method: ExternalType>>becomeKnownTypeSafely (in category 'private') -----
- becomeKnownTypeSafely
- 	"Ignore. We are already a known type."
- 	
- 	self assert: [self isUnknownType not].!

Item was added:
+ ----- Method: ExternalType>>becomeUnknownType (in category 'private') -----
+ becomeUnknownType
+ 
+ 	| newUnknownType |
+ 	newUnknownType := ExternalUnknownType basicNew
+ 		compiledSpec: self compiledSpec;
+ 		byteAlignment: self byteAlignment;
+ 		setReferentClass: referentClass;
+ 		setReferencedType: referencedType;
+ 		yourself.
+ 	
+ 	"Make my pointer type common again by setting the referentClass."
+ 	newUnknownType setReferencedType: referencedType.
+ 	referencedType setReferentClass: referentClass.
+ 		
+ 	self becomeForward: newUnknownType.
+ 	^ newUnknownType!

Item was changed:
  ----- Method: ExternalUnknownType>>becomeArrayType (in category 'construction') -----
  becomeArrayType
  	"I am now positive on #isTypeAliasForArray :-) Make myself an array type. Not that easy because Arraytype as extra instVars #size and #contentType."
  	
+ 	^ self
+ 		becomeKnownTypeClass: ExternalArrayType
+ 		with: [:arrayType |
+ 			arrayType
+ 				setContentType: referentClass originalType contentType; "Hmm..."
+ 				setSize: referentClass originalType size; "Hmm..."
+ 				setByteSize: referentClass originalType byteSize "Hmm..."]!
- 	| newArrayType |	
- 	newArrayType := ExternalArrayType basicNew
- 		compiledSpec: self compiledSpec;
- 		byteAlignment: self byteAlignment;
- 		setReferentClass: referentClass;
- 		setReferencedType: referencedType;
- 		setContentType: referentClass originalType contentType; "Hmm..."
- 		setSize: referentClass originalType size; "Hmm..."
- 		setByteSize: referentClass originalType byteSize; "Hmm..."
- 		yourself.
- 
- 	self becomeForward: newArrayType.	
- 
- 	^ newArrayType!

Item was added:
+ ----- Method: ExternalUnknownType>>becomeKnownTypeClass:with: (in category 'construction') -----
+ becomeKnownTypeClass: typeClass with: initBlock
+ 
+ 	| newKnownType |	
+ 	newKnownType := typeClass basicNew
+ 		compiledSpec: self compiledSpec;
+ 		byteAlignment: self byteAlignment;
+ 		setReferentClass: referentClass;
+ 		setReferencedType: referencedType.
+ 	initBlock value: newKnownType.
+ 	self becomeForward: newKnownType.	
+ 	^ newKnownType!

Item was changed:
  ----- Method: ExternalUnknownType>>becomeKnownTypeSafely (in category 'construction') -----
  becomeKnownTypeSafely
  	"Give me some purpose. :-)"
  
  	^ [self becomeKnownType]
  		ifError: [:msg |
+ 			Transcript showln: ('[FFI] Type for {1} still unknown: {2}' format: {referentClass. msg}).
- 			Transcript showln: '[FFI] Type still unknown: ', msg.
  			self assert: [self isUnknownType].
  			self].!

Item was changed:
  ----- Method: ExternalUnknownType>>becomeStructureType (in category 'construction') -----
  becomeStructureType
+ 	"Fast path because no extra instVars in ExternalStructureType."
+ 	
- 
  	self changeClassTo: ExternalStructureType.!

Item was added:
+ ----- Method: ExternalUnknownType>>becomeUnknownType (in category 'private') -----
+ becomeUnknownType
+ 
+ 	self assert: [self isUnknownType].!

Item was changed:
+ ----- Method: ExternalUnknownType>>newReferentClass: (in category 'private') -----
- ----- Method: ExternalUnknownType>>newReferentClass: (in category 'construction') -----
  newReferentClass: classOrNil
  
  	self assert: [classOrNil notNil].
  	
  	referentClass := classOrNil.
  	compiledSpec := referentClass compiledSpec.
  	byteAlignment := referentClass byteAlignment.!

Item was changed:
+ ----- Method: ExternalUnknownType>>newTypeAlias (in category 'private') -----
- ----- Method: ExternalUnknownType>>newTypeAlias (in category 'construction') -----
  newTypeAlias
  	"A type alias is done compiling and its type can now be initialized completely. See ExternalTypeAlias class >> #originalTypeName and #isSkipped."
  
  	self assert: [referentClass isBehavior].
  
  	referentClass isTypeAlias
  		ifTrue: [^ self becomeKnownType].
  		
  	self error: '[FFI] Only type aliases can become a known type later on'.!



More information about the Squeak-dev mailing list