FFI: FFI-Kernel-mt.99.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

FFI: FFI-Kernel-mt.99.mcz

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

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

Name: FFI-Kernel-mt.99
Author: mt
Time: 6 June 2020, 4:12:06.438722 pm
UUID: b2510db0-e4fd-fe4d-9235-faafd9fa2880
Ancestors: FFI-Kernel-mt.98

Adds suport for lookup of external types through the 'type constants' protocol. Some FFI calls did this already by, for example, referring to 'unsignedByte' instead of 'byte'. Maybe because of "ExternalType unsignedByte". (This could be used to tackle the #ffiLongVsInt issue by adding #int to 'type constants'. Not sure.)

Makes print-string for external structures reveal whether their contents got copied over into a byte array. Now you can see, e.g., in the inspector or object explorer whether the #identityHash is constantly changing ... and that calls to simple setters might not have the expected effect. Note that user-defined external structures can (and maybe should) implement their own notion of #printOn: as usual.

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

Item was changed:
  ----- Method: ExternalStructure>>printNullOn: (in category 'printing') -----
  printNullOn: stream
 
+ handle ifNil: [
+ ^ stream nextPutAll: '<UNDEFINED>'].
- handle ifNil: [^ stream nextPutAll: '<UNDEFINED>'].
 
  self isNull ifTrue: [
+ ^ stream nextPutAll: '<NULL>'].
+
+ handle isExternalAddress ifFalse: [
+ "Inform the user that this data was copied into object memory."
+ ^ stream nextPut: $<; print: handle identityHash; nextPut: $>].
+ !
- stream nextPutAll: '<NULL>'].!

Item was changed:
  ----- Method: ExternalType class>>atomicTypeNamed: (in category 'instance lookup') -----
  atomicTypeNamed: typeName
  "Supports pointer-type lookup such as for 'long*' and also 'long *'."
 
  | isPointerType actualTypeName type |
+ (isPointerType := typeName last == $*)
+ ifTrue: [actualTypeName := typeName allButLast withoutTrailingBlanks]
- (isPointerType := typeName endsWith: '*')
- ifTrue: [actualTypeName := typeName allButLast withBlanksTrimmed]
  ifFalse: [actualTypeName := typeName].
+
+ (Symbol lookup: actualTypeName)
+ ifNotNil: [:sym | actualTypeName := sym].
+
+ ^ (type := (AtomicTypes at: actualTypeName ifAbsent: [nil])
+ ifNil: [ "Supports 'type constants' protocol of ExternalTypes."
+ (self class includesSelector: actualTypeName)
+ ifTrue: [self perform: actualTypeName]])
- ^ (type := AtomicTypes at: actualTypeName ifAbsent: [nil])
  ifNotNil: [isPointerType ifTrue: [type asPointerType] ifFalse: [type]]!

Item was removed:
- ----- Method: ExternalTypeAlias>>printNullOn: (in category 'printing') -----
- printNullOn: stream
-
- handle ifNil: [^ stream nextPutAll: '<UNDEFINED>'].
-
- self isNull ifTrue: [
- stream nextPutAll: '<NULL>'].!