-
Notifications
You must be signed in to change notification settings - Fork 67
/
VMFFIWorkerReturnMarshallingTest.class.st
71 lines (54 loc) · 1.9 KB
/
VMFFIWorkerReturnMarshallingTest.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Class {
#name : #VMFFIWorkerReturnMarshallingTest,
#superclass : #VMFFIReturnMarshallingTest,
#instVars : [
'tfExternalFunction',
'returnHolder',
'cif',
'parameters',
'semaphoreIndex',
'task',
'taskAddressOop',
'worker',
'workerOop'
],
#category : #VMMakerTests
}
{ #category : #'tests - marshalling return' }
VMFFIWorkerReturnMarshallingTest >> doTestCalloutWithReturnType: aLibFFIType returnValue: valueToReturn asserting: aBlock [
tfExternalFunction := self
createExternalFunctionFor: [ valueToReturn ]
withArgumentTypes: #()
withReturnType: aLibFFIType.
returnHolder := interpreter malloc: aLibFFIType size.
aLibFFIType fromSmalltalk: valueToReturn putInto: returnHolder.
cif := interpreter getHandlerAsCif: (memory fetchPointer: 1 ofObject: tfExternalFunction).
parameters := interpreter
allocateParameters: 2
using: [ :aNumber | interpreter calloc: (interpreter sizeof: #'void *') _: aNumber ].
task := interpreter worker_task_new: tfExternalFunction _: cif _: parameters _: returnHolder _: semaphoreIndex.
taskAddressOop := self newExternalAddress: task asInteger.
worker := interpreter libFFI testWorker.
workerOop := self newObjectWithSlots: 1.
memory
storePointer: 0
ofObject: workerOop
withValue: (self newExternalAddress: worker asInteger).
worker tasks add: task.
interpreter push: workerOop.
interpreter push: taskAddressOop.
interpreter primitiveWorkerExtractReturnValue.
aBlock value.
]
{ #category : #'tests - marshalling return' }
VMFFIWorkerReturnMarshallingTest >> initializationOptions [
^ super initializationOptions , {
#FEATURE_THREADED_FFI . true }
]
{ #category : #'tests - marshalling return' }
VMFFIWorkerReturnMarshallingTest >> testPrimitiveCalloutReturningVoidPushesTheReceiver [
self
doTestCalloutWithReturnType: interpreter libFFI void
returnValue: nil
asserting: [ self assert: interpreter stackTop equals: workerOop].
]