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

commits at source.squeak.org commits at source.squeak.org
Fri May 14 13:01:55 UTC 2021


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

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

Name: FFI-Kernel-mt.143
Author: mt
Time: 14 May 2021, 3:01:53.90276 pm
UUID: 94cef049-a4ee-534b-ad41-145d09816d5d
Ancestors: FFI-Kernel-mt.142

Adds a generic way to compare external objects for identity and equality.

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

Item was added:
+ ----- Method: ByteArray>>ffiEqual: (in category '*FFI-Kernel-comparing') -----
+ ffiEqual: other
+ 
+ 	^ self = other withoutReadWriter!

Item was added:
+ ----- Method: ByteArray>>ffiIdentical: (in category '*FFI-Kernel-comparing') -----
+ ffiIdentical: other
+ 
+ 	^ self == other withoutReadWriter!

Item was added:
+ ----- Method: ExternalData>>ffiEqual: (in category 'comparing') -----
+ ffiEqual: other
+ 	"WARNING!! EXPENSIVE!! We can compare bytes if the types are compatible."
+ 	
+ 	(self ffiIdentical: other) ifTrue: [^ true].
+ 	
+ 	self flag: #todo. "mt: Which types are actually compatible? :-)"
+ 	self externalType asNonPointerType = other externalType asNonPointerType ifFalse: [^ false].
+ 	
+ 	self flag: #todo. "mt: Follow pointers? Detect cycles? Hmmm... :-) See #free as inspiration."
+ 	^ self copy getHandle ffiEqual: other copy getHandle!

Item was added:
+ ----- Method: ExternalData>>ffiEqualityHash (in category 'comparing') -----
+ ffiEqualityHash
+ 	"WARNING!! EXPENSIVE!!"
+ 	
+ 	self ffiIdentityHash
+ 		bitXor: self copy getHandle hash!

Item was added:
+ ----- Method: ExternalObject>>= (in category 'comparing') -----
+ = other
+ 	"By default, we use the not-so-expensive check for external indentity like Object does. Subclasses can choose to use #ffiEqual:, which compares types and bytes, or implement their own domain-specific notion of equality."
+ 	
+ 	^ self ffiIdentical: other!

Item was added:
+ ----- Method: ExternalObject>>ffiEqual: (in category 'comparing') -----
+ ffiEqual: other
+ 	"We do not know better."
+ 	
+ 	^ self ffiIdentical: other!

Item was added:
+ ----- Method: ExternalObject>>ffiEqualityHash (in category 'comparing') -----
+ ffiEqualityHash
+ 
+ 	^ self ffiIdentityHash!

Item was added:
+ ----- Method: ExternalObject>>ffiIdentical: (in category 'comparing') -----
+ ffiIdentical: other
+ 	"Define identity for external objects. External objects sharing an external address are considered 'externally identical.' "
+ 	
+ 	self == other ifTrue: [^ true].
+ 	other isExternalObject ifFalse: [^ false].
+ 	self getHandle species = other getHandle species ifFalse: [^ false].
+ 	
+ 	^ (self getHandle ffiIdentical: other getHandle) or: [
+ 			self checkHandle. other checkHandle.
+ 			self getHandle isExternalAddress
+ 				and: [other getHandle isExternalAddress]
+ 				and: [self getHandle = other getHandle]]!

Item was added:
+ ----- Method: ExternalObject>>ffiIdentityHash (in category 'comparing') -----
+ ffiIdentityHash
+ 
+ 	^ self species scaledIdentityHash bitXor: self getHandle scaledIdentityHash!

Item was added:
+ ----- Method: ExternalObject>>hash (in category 'comparing') -----
+ hash
+ 
+ 	^ self ffiIdentityHash!

Item was added:
+ ----- Method: ExternalStructure>>ffiEqual: (in category 'comparing') -----
+ ffiEqual: other
+ 	"We can compare bytes if the types are compatible."
+ 	
+ 	(self ffiIdentical: other) ifTrue: [^ true].
+ 	self externalType asNonPointerType = other externalType asNonPointerType ifFalse: [^ false].
+ 	^ self asArray ffiEqual: other asArray!

Item was added:
+ ----- Method: ExternalStructure>>ffiEqualityHash (in category 'comparing') -----
+ ffiEqualityHash
+ 	
+ 	^ self ffiIdentityHash
+ 		bitXor: self asArray ffiEqualityHash!

Item was added:
+ ----- Method: ExternalStructure>>ffiIdentical: (in category 'comparing') -----
+ ffiIdentical: other
+ 	"Overwritten to also check the receiver's external type."
+ 	
+ 	(super ffiIdentical: other) ifFalse: [^ false].
+ 	^ self externalType = other externalType!

Item was added:
+ ----- Method: ExternalStructure>>ffiIdentityHash (in category 'comparing') -----
+ ffiIdentityHash
+ 
+ 	^ super ffiIdentityHash bitXor: self externalType scaledIdentityHash!

Item was removed:
- ----- Method: ExternalTypeAlias>>= (in category 'comparing') -----
- = anExternalTypeAlias
- 	^self class = anExternalTypeAlias class and: [self value = anExternalTypeAlias value]!

Item was removed:
- ----- Method: ExternalTypeAlias>>hash (in category 'comparing') -----
- hash
- 	^self class hash hashMultiply bitXor: self value hash!

Item was added:
+ ----- Method: Object>>ffiEqual: (in category '*FFI-Kernel') -----
+ ffiEqual: other
+ 	
+ 	^ self = other!

Item was added:
+ ----- Method: Object>>ffiIdentical: (in category '*FFI-Kernel') -----
+ ffiIdentical: other
+ 	
+ 	^ self == other!

Item was changed:
  (PackageInfo named: 'FFI-Kernel') postscript: 'Smalltalk removeFromStartUpList: ExternalAddress.
  Smalltalk removeFromStartUpList: ExternalObject.
  
+ ExternalType resetAllTypes.
- "Adds housekeeping for array types."
- ExternalType resetAllStructureTypes.
  
  "Re-generate all field accessors because in ExternalData, #size: was replaced with #setSet: and a new constructors for content and container types."
  ExternalStructure defineAllFields.
  '!



More information about the Squeak-dev mailing list