[squeak-dev] FFI: FFI-Callbacks-mt.28.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Aug 19 10:02:35 UTC 2021


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

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

Name: FFI-Callbacks-mt.28
Author: mt
Time: 19 August 2021, 12:02:33.914627 pm
UUID: 00c82084-ed47-0941-b5a7-515c07ea4e8d
Ancestors: FFI-Callbacks-mt.27

Fixes regression from previous commit. Adding an extra unpacking step needs to retain the strong (arg) reference of the comparator to make use of managed callback.

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

Item was changed:
  ----- Method: CStandardLibrary>>compare:through: (in category '*FFI-Callbacks') -----
  compare: contentType through: evaluable
  	"Answers a callback for comparing the given contentType through the given evaluable, i.e., messages sends or blocks. Supports pointer types as contentType via array-type indirection. Automatically unpacks pointers to atomics so that evaluable can directly work on Smalltalk objects. Does not support void as contentType."
  	
  	<callback: int32_t (*)(const void*, const void*)>
  	
  	| argType signature |
  	self assert: [evaluable numArgs = 2].
  	
  	argType := contentType isPointerType
  		ifTrue: [(contentType asArrayType: nil) "HACKY!!"]
  		ifFalse: [contentType].
  
  	signature := ((thisContext method pragmaAt: #callback:) argumentAt: 1) copy.
  	signature at: 2 put: argType asPointerType.
  	signature at: 3 put: argType asPointerType.	
  	
+ 	(contentType isAtomic or: [contentType isPointerType "e.g., array of int*"])
+ 		ifTrue: ["Re-write evaluable to keep the strong reference as stack argument"
+ 			| source newEvaluable |
+ 			self flag: #hacky.
+ 			source := '[:arg1 :arg2 | {1} value: arg1 value value: arg2 value]'
+ 				format: { evaluable decompile decompileString }.
+ 			newEvaluable := Compiler evaluate: source.
+ 			newEvaluable receiver: evaluable receiver. "TODO: other bindings?"
+ 			evaluable becomeForward: newEvaluable].
+ 		
+ 	^ evaluable gcSignature: signature!
- 	^ ((contentType isAtomic or: [contentType isPointerType])
- 		ifTrue: [ [:arg1 :arg2 | evaluable value: arg1 value value: arg2 value] ]
- 		ifFalse: [evaluable]) gcSignature: signature!



More information about the Squeak-dev mailing list