[squeak-dev] FFI Inbox: FFI-Callbacks-mt.10.mcz

commits at source.squeak.org commits at source.squeak.org
Sat May 1 09:01:07 UTC 2021


A new version of FFI-Callbacks was added to project FFI Inbox:
http://source.squeak.org/FFIinbox/FFI-Callbacks-mt.10.mcz

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

Name: FFI-Callbacks-mt.10
Author: mt
Time: 1 May 2021, 11:01:07.42119 am
UUID: f1cd0f2a-9e6b-ec40-9d68-d2a72e0ad829
Ancestors: FFI-Callbacks-mt.9

Maybe, at some point, we will be able to configure blocks as FFI callbacks more conveniently. Here is an example of how to invoke the block with example objects to derive the signature to be used for FFI. (Not working; just a sketch)

=============== Diff against FFI-Callbacks-mt.9 ===============

Item was added:
+ ----- Method: BlockClosure>>signature: (in category '*FFI-Callbacks') -----
+ signature: signature
+ 
+ 	^ FFICallback
+ 		signature: signature
+ 		block: self!

Item was added:
+ ----- Method: BlockClosure>>signatureByValue: (in category '*FFI-Callbacks') -----
+ signatureByValue: arg1
+ 
+ 	^ self signatureByValueWithArguments: {arg1}!

Item was added:
+ ----- Method: BlockClosure>>signatureByValue:value: (in category '*FFI-Callbacks') -----
+ signatureByValue: arg1 value: arg2
+ 
+ 	^ self signatureByValueWithArguments: {arg1. arg2}!

Item was added:
+ ----- Method: BlockClosure>>signatureByValue:value:value: (in category '*FFI-Callbacks') -----
+ signatureByValue: arg1 value: arg2 value: arg3
+ 
+ 	^ self signatureByValueWithArguments: {arg1. arg2. arg3}!

Item was added:
+ ----- Method: BlockClosure>>signatureByValue:value:value:value: (in category '*FFI-Callbacks') -----
+ signatureByValue: arg1 value: arg2 value: arg3 value: arg4
+ 
+ 	^ self signatureByValueWithArguments: {arg1. arg2. arg3. arg4}!

Item was added:
+ ----- Method: BlockClosure>>signatureByValue:value:value:value:value: (in category '*FFI-Callbacks') -----
+ signatureByValue: arg1 value: arg2 value: arg3 value: arg4 value: arg5
+ 
+ 	^ self signatureByValueWithArguments: {arg1. arg2. arg3. arg4. arg5}!

Item was added:
+ ----- Method: BlockClosure>>signatureByValueWithArguments: (in category '*FFI-Callbacks') -----
+ signatureByValueWithArguments: someObjects
+ 
+ 	| result signature |
+ 	self flag: #todo. "mt: Consider #wordSize, the use of (non-atomic) ExternalStructure or ExternalData as arguments etc. This unsafe mapping from smalltalk objects ot external types might be related to the ongoing discussion on how to improve type checks in the Squeak FFI plugin. See http://forum.world.st/FFI-Inbox-FFI-Kernel-nice-119-mcz-tp5118848.html"
+ 	
+ 	result := self valueWithArguments: someObjects.
+ 	signature := Array streamContents: [:s |
+ 		{result}, someObjects do: [:each |
+ 			each isInteger ifTrue: [ s nextPut: 'int32_t' ].
+ 			each isFloat ifTrue: [ s nextPut: 'double' ].
+ 			"..."
+ 			]].
+ 	
+ 	self flag: #pointerOrNot. "mt: While it might be hidden in Squeak, the call must now whether to pass the arguments by value or by reference."
+ 	self notYetImplemented.
+ 	
+ 	^ FFICallback
+ 		signature: signature
+ 		block: self!



More information about the Squeak-dev mailing list