FFI: FFI-Callbacks-mt.7.mcz

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

FFI: FFI-Callbacks-mt.7.mcz

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

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

Name: FFI-Callbacks-mt.7
Author: mt
Time: 1 May 2021, 9:06:54.87419 am
UUID: 1094c754-1e24-d342-8822-31dce676cd6a
Ancestors: FFI-Callbacks-mt.6

Fixes regression. I forgot to resolve materialize pointers from integers when reading intRegArgs.

(For debugging, adds #mostRecent shortcut to FFICallbackContext class.)

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

Item was changed:
  ----- Method: FFICallback>>evaluateDynamic: (in category 'callback - evaluators') -----
  evaluateDynamic: callbackContext
  "Read all arguments and make the call(back). Assume that 'handle' and 'type' are set correctly. Only watch out for the sign. See field definition in FFICallbackContext to explore alternative ways to read the arguments."
 
  | byteOffset args intArgs intPos floatArgs floatPos |
 
  handle := callbackContext stackPtr getHandle.
  type := callbackContext stackPtr contentType.
  byteOffset := 1.
 
  intArgs := callbackContext integerArguments.
  intPos := 0.
  floatArgs := callbackContext floatArguments.
  floatPos := 0.
 
  args := Array new: argumentTypes size.
  1 to: args size do: [:argIndex |
+ | argType data isPointer |
- | argType data |
  argType := argumentTypes at: argIndex.
 
  "1) Try to read arguments from registers."
+ data := (intPos < intArgs size and: [(isPointer := argType isPointerType) or: [argType isIntegerType]])
- data := (intPos < intArgs size and: [argType isPointerType or: [argType isIntegerType]])
  ifTrue: [intPos := intPos + 1. intArgs at: intPos]
  ifFalse: [(floatPos < floatArgs size and: [argType isFloatType])
  ifTrue: [floatPos := floatPos + 1. floatArgs at: floatPos]].
 
+ data
+ ifNotNil: [ "1b) Materialize pointers from integers."
+ isPointer ifTrue: [
+ self flag: #designSmell. "mt: If we had a way to set, for example, double** as container type and double* as content type for intArgs, we would not have to construct the correct external object here but already had it."
+ self flag: #discuss. "mt: Should we resolve atomic types? That is, double* to an actual float object etc? Well, for pointers to external structures (unions, ...) it would make sense to provide an actual instance of that structure to the callback... If so, we just need to send #value below."
+ data := (ExternalData
+ fromHandle: (ExternalAddress fromInteger: data)
+ type: argType) size: 1; "value; " yourself]]
+ ifNil: [ "2) If nothing was read, read the argument from the stack."
+ data := argType handle: handle at: byteOffset.
+ byteOffset := byteOffset
+ + ((type byteSize max: argType byteSize) roundUpTo: type byteAlignment)].
- "2) If nothing was read, read the argument from the stack."
- data ifNil: [
- data := argType handle: handle at: byteOffset.
- byteOffset := byteOffset
- + ((type byteSize max: argType byteSize) roundUpTo: type byteAlignment)].
 
  args at: argIndex put: data].
 
  ^ self
  setResult: (evaluableObject valueWithArguments: args)
  inContext: callbackContext!

Item was added:
+ ----- Method: FFICallbackContext class>>mostRecent (in category 'instance lookup') -----
+ mostRecent
+
+ ^ FFICallbackMemory mostRecentCallbackContext!