author | Claus Gittinger <cg@exept.de> |
Mon, 04 Mar 2019 09:41:45 +0100 | |
changeset 23828 | cbcc99660889 |
parent 23785 | 617f45e9fffa |
child 23829 | 209adc65cf44 |
permissions | -rw-r--r-- |
23828 | 1 |
"{ Encoding: utf8 }" |
2 |
||
8728 | 3 |
" |
4 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
9464 | 5 |
All Rights Reserved |
8728 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
8533 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
19311 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
8533 | 18 |
ExternalFunction subclass:#ExternalLibraryFunction |
9465 | 19 |
instanceVariableNames:'flags moduleName returnType argumentTypes owningClass' |
20299 | 20 |
classVariableNames:'CALLTYPE_API CALLTYPE_C CALLTYPE_MASK CALLTYPE_OLE |
21 |
CALLTYPE_UNIX64 CALLTYPE_V8 CALLTYPE_V9 DLLPATH DllMapping |
|
22 |
FLAG_ASYNC FLAG_NONVIRTUAL FLAG_OBJECTIVEC FLAG_RETVAL_IS_CONST |
|
23 |
FLAG_UNLIMITEDSTACK FLAG_VIRTUAL LastModuleHandleHolder |
|
21409 | 24 |
LastModuleHandleName Verbose FLAG_RETVAL_MUST_FREE' |
9464 | 25 |
poolDictionaries:'' |
26 |
category:'System-Support' |
|
8533 | 27 |
! |
28 |
||
9322 | 29 |
!ExternalLibraryFunction primitiveDefinitions! |
30 |
%{ |
|
20297
85746bbcaf03
compiler warning eliminated
Claus Gittinger <cg@exept.de>
parents:
20295
diff
changeset
|
31 |
#include "stxOSDefs.h" |
85746bbcaf03
compiler warning eliminated
Claus Gittinger <cg@exept.de>
parents:
20295
diff
changeset
|
32 |
|
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
33 |
#define VERBOSE |
9322 | 34 |
|
20290
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
35 |
#ifdef VERBOSE |
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
36 |
# define DEBUGCODE_IF(flag, code) if ((flag) == true) { code } |
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
37 |
# else |
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
38 |
# define DEBUG_IF(flag, code) /* nothing */ |
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
39 |
# endif |
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
40 |
|
9337 | 41 |
#ifdef HAVE_FFI |
20288
604e46cfbf18
ffi for mingw - 64-bit machine has no API_CALL
Claus Gittinger <cg@exept.de>
parents:
19951
diff
changeset
|
42 |
|
9337 | 43 |
# include <ffi.h> |
9322 | 44 |
# define MAX_ARGS 128 |
9365 | 45 |
|
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
46 |
# ifdef USE_STANDARD_FFI |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
47 |
# define __get_ffi_type_sint() &ffi_type_sint |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
48 |
# define __get_ffi_type_sint8() &ffi_type_sint8 |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
49 |
# define __get_ffi_type_sint16() &ffi_type_sint16 |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
50 |
# define __get_ffi_type_sint32() &ffi_type_sint32 |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
51 |
# define __get_ffi_type_sint64() &ffi_type_sint64 |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
52 |
# define __get_ffi_type_uint() &ffi_type_uint |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
53 |
# define __get_ffi_type_uint8() &ffi_type_uint8 |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
54 |
# define __get_ffi_type_uint16() &ffi_type_uint16 |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
55 |
# define __get_ffi_type_uint32() &ffi_type_uint32 |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
56 |
# define __get_ffi_type_uint64() &ffi_type_uint64 |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
57 |
# define __get_ffi_type_float() &ffi_type_float |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
58 |
# define __get_ffi_type_double() &ffi_type_double |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
59 |
# define __get_ffi_type_void() &ffi_type_void |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
60 |
# define __get_ffi_type_pointer() &ffi_type_pointer |
19931 | 61 |
|
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
62 |
# else |
19931 | 63 |
|
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
64 |
extern ffi_type *__get_ffi_type_sint(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
65 |
extern ffi_type *__get_ffi_type_sint8(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
66 |
extern ffi_type *__get_ffi_type_sint16(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
67 |
extern ffi_type *__get_ffi_type_sint32(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
68 |
extern ffi_type *__get_ffi_type_sint64(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
69 |
extern ffi_type *__get_ffi_type_uint(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
70 |
extern ffi_type *__get_ffi_type_uint8(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
71 |
extern ffi_type *__get_ffi_type_uint16(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
72 |
extern ffi_type *__get_ffi_type_uint32(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
73 |
extern ffi_type *__get_ffi_type_uint64(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
74 |
extern ffi_type *__get_ffi_type_float(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
75 |
extern ffi_type *__get_ffi_type_double(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
76 |
extern ffi_type *__get_ffi_type_void(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
77 |
extern ffi_type *__get_ffi_type_pointer(); |
20307 | 78 |
extern INTLFUNC __get_ffi_prep_cif(); |
79 |
extern INTLFUNC __get_ffi_call(); |
|
19536 | 80 |
# ifdef _MINGW__ |
81 |
# define ffi_prep_cif (*(__get_ffi_prep_cif())) |
|
20307 | 82 |
# define ffi_call (*(__get_ffi_call())) |
19536 | 83 |
# endif |
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
84 |
# endif |
9365 | 85 |
|
19931 | 86 |
# define TYPE_UINT __get_ffi_type_uint() |
87 |
# define TYPE_UINT8 __get_ffi_type_uint8() |
|
88 |
# define TYPE_UINT16 __get_ffi_type_uint16() |
|
89 |
# define TYPE_UINT32 __get_ffi_type_uint32() |
|
90 |
# define TYPE_UINT64 __get_ffi_type_uint64() |
|
91 |
||
92 |
# define TYPE_SINT __get_ffi_type_sint() |
|
93 |
# define TYPE_SINT8 __get_ffi_type_sint8() |
|
94 |
# define TYPE_SINT16 __get_ffi_type_sint16() |
|
95 |
# define TYPE_SINT32 __get_ffi_type_sint32() |
|
96 |
# define TYPE_SINT64 __get_ffi_type_sint64() |
|
97 |
||
98 |
# define TYPE_POINTER __get_ffi_type_pointer() |
|
19950 | 99 |
# define TYPE_FLOAT __get_ffi_type_float() |
100 |
# define TYPE_DOUBLE __get_ffi_type_double() |
|
101 |
# define TYPE_VOID __get_ffi_type_void() |
|
19931 | 102 |
|
103 |
#else /* NO FFI */ |
|
104 |
||
105 |
# define MAX_ARGS 15 |
|
106 |
# define TYPE_UINT 1 |
|
107 |
# define TYPE_UINT8 2 |
|
108 |
# define TYPE_UINT16 3 |
|
109 |
# define TYPE_UINT32 4 |
|
110 |
# define TYPE_UINT64 5 |
|
111 |
||
112 |
# define TYPE_SINT 11 |
|
113 |
# define TYPE_SINT8 12 |
|
114 |
# define TYPE_SINT16 13 |
|
115 |
# define TYPE_SINT32 14 |
|
116 |
# define TYPE_SINT64 15 |
|
117 |
||
118 |
# define TYPE_POINTER 20 |
|
119 |
# define TYPE_FLOAT 30 |
|
120 |
# define TYPE_DOUBLE 31 |
|
121 |
# define TYPE_VOID 40 |
|
122 |
||
123 |
# define FFI_DEFAULT_ABI 0 |
|
124 |
# define CALLTYPE_FFI_STDCALL 0 |
|
125 |
||
9337 | 126 |
#endif |
9322 | 127 |
|
128 |
%} |
|
129 |
! ! |
|
130 |
||
8728 | 131 |
!ExternalLibraryFunction class methodsFor:'documentation'! |
132 |
||
133 |
copyright |
|
134 |
" |
|
135 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
9464 | 136 |
All Rights Reserved |
8728 | 137 |
|
138 |
This software is furnished under a license and may be used |
|
139 |
only in accordance with the terms of that license and with the |
|
140 |
inclusion of the above copyright notice. This software may not |
|
141 |
be provided or otherwise made available to, or used by, any |
|
142 |
other person. No title to or ownership of the software is |
|
143 |
hereby transferred. |
|
144 |
" |
|
9322 | 145 |
! |
146 |
||
9331 | 147 |
documentation |
148 |
" |
|
149 |
instances of me are used to interface to external library functions (as found in a dll/shared object). |
|
19933 | 150 |
Foreign function calls are based on the FFI library if available. |
151 |
A limited fallback implementation is provided for systems with no libffi. |
|
152 |
(this may have limitations on the supported argument types; for example, |
|
153 |
the x86_64 fallback does not support float/double arguments). |
|
19950 | 154 |
Therefore the fallback should be considered a temporary workaround, |
19933 | 155 |
until libffi has been ported. |
19950 | 156 |
|
12680 | 157 |
Inside a method, when a special external-call pragma such as: |
19950 | 158 |
<api: bool MessageBeep(uint)> |
12680 | 159 |
|
160 |
is encountered by the parser, the compiler generates a call via |
|
19950 | 161 |
<correspondingExternalLibraryFunctionObject> invokeWithArguments: argumentArray. |
19549 | 162 |
and the correspondingExternalLibraryFunctionObject is kept in the literal array. |
9331 | 163 |
|
164 |
In the invoke method, the library is checked to be loaded (and loaded if not already), |
|
9336 | 165 |
the arguments are converted to C and pushed onto the C-stack, the function is called, |
9331 | 166 |
and finally, the return value is converted back from C to a smalltalk object. |
12680 | 167 |
|
168 |
The parser supports the call-syntax of various other smalltalk dialects: |
|
19950 | 169 |
Squeak / ST-X: |
170 |
<cdecl: [async] [virtual|nonVirtual][const] returnType functionNameStringOrIndex ( argType1..argTypeN ) module: moduleName > |
|
171 |
<apicall: [async] [virtual|nonVirtual][const] returnType functionNameStringOrIndex ( argType1..argTypeN ) module: moduleName > |
|
12680 | 172 |
|
19950 | 173 |
Dolphin: |
174 |
<stdcall: [virtual|nonVirtual][const] returnType functionNameStringOrIndex argType1..argTypeN> |
|
175 |
<cdecl: [virtual|nonVirtual][const] returnType functionNameStringOrIndex argType1..argTypeN> |
|
12680 | 176 |
|
19950 | 177 |
ST/V: |
178 |
<api: functionName argType1 .. argTypeN returnType> |
|
179 |
<ccall: functionName argType1 .. argTypeN returnType> |
|
180 |
<ole: vFunctionIndex argType1 .. argTypeN returnType> |
|
12680 | 181 |
|
19950 | 182 |
VisualWorks: |
183 |
<c: ...> |
|
184 |
<c: #define NAME value> |
|
9331 | 185 |
" |
186 |
! |
|
187 |
||
9322 | 188 |
example |
189 |
" |
|
21837 | 190 |
[exBegin] |
191 |
|f| |
|
14037 | 192 |
|
21837 | 193 |
f := ExternalLibraryFunction new. |
194 |
f beCallTypeWINAPI. |
|
14037 | 195 |
|
21837 | 196 |
f name:'MessageBeep' |
197 |
module:'user32.dll' |
|
198 |
returnType:#boolean |
|
199 |
argumentTypes:#(uint). |
|
14037 | 200 |
|
21837 | 201 |
f invokeWith:1. |
202 |
[exEnd] |
|
14037 | 203 |
|
204 |
Synchronous vs. Asynchronous calls: |
|
205 |
||
14516
359e4d2234af
class: ExternalLibraryFunction
Stefan Vogel <sv@exept.de>
parents:
14506
diff
changeset
|
206 |
by default, foreign function calls are synchronous, effectively blocking the whole ST/X system |
23828 | 207 |
(that is by purpose,´because most C-code is not prepared for being interrupted, and also, normal |
14037 | 208 |
code is not prepared for a garbage collector to move objects around, while another C thread might |
209 |
access the data...). |
|
14625 | 210 |
Therefore, the following will block all ST/X activity for 10 seconds |
14037 | 211 |
(try interacting with the launcher while the Sleep is performing): |
212 |
||
21837 | 213 |
[exBegin] |
214 |
|f| |
|
9322 | 215 |
|
21837 | 216 |
f := ExternalLibraryFunction new. |
217 |
f beCallTypeWINAPI. |
|
14037 | 218 |
|
21837 | 219 |
f name:'Sleep' |
220 |
module:'kernel32.dll' |
|
221 |
returnType:#void |
|
222 |
argumentTypes:#(uint). |
|
14037 | 223 |
|
21837 | 224 |
f invokeWith:10000. |
225 |
[exEnd] |
|
9322 | 226 |
|
14037 | 227 |
if you know what you do and you do not pass any possibly moving objects (such as strings) as argument, |
228 |
the call can be made asynchronous. In that case, ONLY the calling thread will be blocked; all other smalltalk |
|
21837 | 229 |
threads will continue to execute. |
14037 | 230 |
(try interacting now with the launcher while the Sleep is performing): |
21837 | 231 |
[exBegin] |
232 |
|f| |
|
14037 | 233 |
|
21837 | 234 |
f := ExternalLibraryFunction new. |
235 |
f beCallTypeWINAPI. |
|
236 |
f beAsync. |
|
14037 | 237 |
|
21837 | 238 |
f name:'Sleep' |
239 |
module:'kernel32.dll' |
|
240 |
returnType:#void |
|
241 |
argumentTypes:#(uint). |
|
14037 | 242 |
|
21837 | 243 |
f invokeWith:10000. |
244 |
[exEnd] |
|
14037 | 245 |
|
9322 | 246 |
" |
8728 | 247 |
! ! |
8533 | 248 |
|
8550 | 249 |
!ExternalLibraryFunction class methodsFor:'instance creation'! |
250 |
||
9465 | 251 |
name:functionName module:moduleName returnType:returnType argumentTypes:argTypes |
8550 | 252 |
^ self new |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
253 |
name:functionName module:moduleName |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
254 |
returnType:returnType argumentTypes:argTypes |
9465 | 255 |
|
256 |
"Created: / 01-08-2006 / 15:19:08 / cg" |
|
9463 | 257 |
! ! |
258 |
||
259 |
!ExternalLibraryFunction class methodsFor:'class initialization'! |
|
260 |
||
11050 | 261 |
addToDllPath:aDirectoryPathName |
262 |
"can be used during initialization, to add more places for dll-loading" |
|
263 |
||
19487 | 264 |
|oldPath newPath| |
11053 | 265 |
|
266 |
oldPath := self dllPath. |
|
22144 | 267 |
oldPath isNil ifTrue:[ oldPath := OrderedCollection new ]. |
11053 | 268 |
(oldPath includes:aDirectoryPathName) ifFalse:[ |
22144 | 269 |
newPath := oldPath asOrderedCollection. |
270 |
newPath add:aDirectoryPathName. |
|
271 |
self dllPath:newPath |
|
11053 | 272 |
] |
20289 | 273 |
|
274 |
" |
|
275 |
self addToDllPath:'c:\matrix\API\dll' |
|
276 |
" |
|
11050 | 277 |
! |
278 |
||
22802 | 279 |
defaultDLLPath |
280 |
"return a default dll-path, as per operating system" |
|
281 |
||
282 |
|path try| |
|
283 |
||
284 |
path := OrderedCollection with:'.'. |
|
285 |
try := [:dir | dir asFilename exists ifTrue:[path add:dir]]. |
|
286 |
||
287 |
OperatingSystem isUNIXlike ifTrue:[ |
|
288 |
#( |
|
289 |
'/lib' |
|
290 |
'/usr/lib' |
|
291 |
'/usr/local/lib' |
|
292 |
'/opt/lib' |
|
293 |
'/opt/local/lib' |
|
294 |
) do:try |
|
295 |
]. |
|
296 |
^ path |
|
297 |
||
298 |
" |
|
299 |
self defaultDLLPath |
|
300 |
" |
|
301 |
! |
|
302 |
||
14103 | 303 |
dllMapping |
304 |
"allows for dll's to be replaced, |
|
305 |
for example, if you want to use the mozilla sqlite dll |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19549
diff
changeset
|
306 |
C:\Program Files\Mozilla Firefox\mozsqlite3.dll |
14103 | 307 |
for the sqlite3, execute: |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19549
diff
changeset
|
308 |
ExternalLibraryFunction |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19549
diff
changeset
|
309 |
dllMapping at:'sqlite3' |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19549
diff
changeset
|
310 |
put: 'C:\Program Files\Mozilla Firefox\mozsqlite3.dll' |
19549 | 311 |
for mingw: |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19549
diff
changeset
|
312 |
ExternalLibraryFunction |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19549
diff
changeset
|
313 |
dllMapping at:'sqlite3' |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19549
diff
changeset
|
314 |
put:'C:\mingw64\opt\bin\libsqlite3-0.dll' |
14103 | 315 |
" |
316 |
||
317 |
DllMapping isNil ifTrue:[ |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19549
diff
changeset
|
318 |
DllMapping := Dictionary new. |
14103 | 319 |
]. |
320 |
^ DllMapping |
|
321 |
||
322 |
"Created: / 10-04-2012 / 12:21:45 / cg" |
|
323 |
! |
|
324 |
||
21055 | 325 |
dllMapping:aDictionary |
326 |
"allows for dll's to be replaced, |
|
327 |
for example, if you want to use the mozilla sqlite dll |
|
328 |
C:\Program Files\Mozilla Firefox\mozsqlite3.dll |
|
329 |
for the sqlite3, execute: |
|
330 |
ExternalLibraryFunction |
|
331 |
dllMapping at:'sqlite3' |
|
332 |
put: 'C:\Program Files\Mozilla Firefox\mozsqlite3.dll' |
|
333 |
for mingw: |
|
334 |
ExternalLibraryFunction |
|
335 |
dllMapping at:'sqlite3' |
|
336 |
put:'C:\mingw64\opt\bin\libsqlite3-0.dll' |
|
337 |
" |
|
338 |
||
339 |
DllMapping := aDictionary |
|
340 |
||
341 |
"Created: / 26-11-2016 / 04:06:14 / cg" |
|
342 |
! |
|
343 |
||
20299 | 344 |
dllMappingAt:baseLibname put:aNameOrPath |
345 |
"allows for dll's to be replaced, |
|
346 |
for example, if you want to use the mozilla sqlite dll |
|
20307 | 347 |
C:\Program Files\Mozilla Firefox\mozsqlite3.dll |
20299 | 348 |
for the sqlite3, execute: |
20307 | 349 |
ExternalLibraryFunction |
350 |
dllMappingAt:'sqlite3' |
|
351 |
put: 'C:\Program Files\Mozilla Firefox\mozsqlite3.dll' |
|
20299 | 352 |
for mingw: |
20307 | 353 |
ExternalLibraryFunction |
354 |
dllMappingAt:'sqlite3' |
|
355 |
put:'C:\mingw64\opt\bin\libsqlite3-0.dll' |
|
20299 | 356 |
" |
357 |
||
358 |
self dllMapping at:baseLibname put: aNameOrPath |
|
359 |
! |
|
360 |
||
10270 | 361 |
dllPath |
19549 | 362 |
"provide a default dllPath, where external libraries are searched for" |
363 |
||
13337 | 364 |
^ DLLPATH |
21401 | 365 |
|
366 |
" |
|
367 |
ExternalLibraryFunction dllPath |
|
368 |
" |
|
369 |
||
370 |
"Modified (comment): / 12-02-2017 / 02:15:23 / cg" |
|
10270 | 371 |
! |
372 |
||
373 |
dllPath:aCollectionOfDirectoryPathNames |
|
19549 | 374 |
"provide a default dllPath, where external libraries are searched for" |
375 |
||
10270 | 376 |
DLLPATH := aCollectionOfDirectoryPathNames |
377 |
! |
|
378 |
||
20958 | 379 |
flushModuleHandlesForLibrary:aLibraryName |
380 |
self flushModuleHandlesForWhich:[:fn | fn moduleName = aLibraryName]. |
|
381 |
||
382 |
" |
|
383 |
self flushModuleHandlesForLibrary:'ole32.dll' |
|
384 |
" |
|
385 |
||
386 |
"Created: / 12-11-2016 / 11:49:09 / cg" |
|
387 |
! |
|
388 |
||
389 |
flushModuleHandlesForWhich:aBlock |
|
390 |
self allInstancesDo:[:fn | |
|
391 |
(aBlock value:fn) ifTrue:[ |
|
392 |
fn setModuleHandle:nil. |
|
393 |
] |
|
394 |
]. |
|
395 |
||
396 |
" |
|
397 |
self flushModuleHandlesForLibrary:'ole32.dll' |
|
398 |
" |
|
399 |
||
400 |
"Created: / 12-11-2016 / 11:48:32 / cg" |
|
401 |
! |
|
402 |
||
9463 | 403 |
initialize |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
404 |
"using inline access to corresponding c--defines to avoid duplicate places of knowledge" |
13337 | 405 |
|
406 |
DLLPATH isNil ifTrue:[ |
|
22802 | 407 |
DLLPATH := self defaultDLLPath. |
20309 | 408 |
]. |
18228 | 409 |
%{ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18228
diff
changeset
|
410 |
#ifndef __SCHTEAM__ |
20309 | 411 |
@global(FLAG_VIRTUAL) = __MKSMALLINT(__EXTL_FLAG_VIRTUAL); // a virtual c++ call |
412 |
@global(FLAG_NONVIRTUAL) = __MKSMALLINT(__EXTL_FLAG_NONVIRTUAL); // a non-virtual c++ call |
|
413 |
@global(FLAG_OBJECTIVEC) = __MKSMALLINT(__EXTL_FLAG_OBJECTIVEC); // an objectiveC message send |
|
414 |
@global(FLAG_UNLIMITEDSTACK) = __MKSMALLINT(__EXTL_FLAG_UNLIMITEDSTACK); // unlimitedstack under unix |
|
415 |
@global(FLAG_ASYNC) = __MKSMALLINT(__EXTL_FLAG_ASYNC); // async under win32 |
|
21410 | 416 |
@global(FLAG_RETVAL_IS_CONST) = __MKSMALLINT(__EXTL_FLAG_RETVAL_IS_CONST); // retvalue is not to be registered for finalization |
417 |
@global(FLAG_RETVAL_MUST_FREE) = __MKSMALLINT(__EXTL_FLAG_RETVAL_MUST_FREE); // retvalue is to be freed |
|
9463 | 418 |
|
20309 | 419 |
@global(CALLTYPE_API) = __MKSMALLINT(__EXTL_CALLTYPE_API); // WINAPI-call (win32 only) |
420 |
@global(CALLTYPE_C) = __MKSMALLINT(__EXTL_CALLTYPE_C); // regular C-call (the default) |
|
421 |
@global(CALLTYPE_V8) = __MKSMALLINT(__EXTL_CALLTYPE_V8); // v8 call (sparc only) |
|
422 |
@global(CALLTYPE_V9) = __MKSMALLINT(__EXTL_CALLTYPE_V9); // v9 call (sparc only) |
|
423 |
@global(CALLTYPE_UNIX64) = __MKSMALLINT(__EXTL_CALLTYPE_UNIX64); // unix64 call (alpha only) |
|
9463 | 424 |
|
20309 | 425 |
@global(CALLTYPE_MASK) = __MKSMALLINT(__EXTL_CALLTYPE_MASK); |
18228 | 426 |
#endif |
20309 | 427 |
%}. |
9465 | 428 |
|
22802 | 429 |
"DLLPATH := nil. |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
430 |
self initialize |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
431 |
" |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
432 |
|
21410 | 433 |
"Modified: / 12-02-2017 / 23:43:23 / cg" |
11053 | 434 |
! |
435 |
||
436 |
removeFromDllPath:aDirectoryPathName |
|
437 |
"remove added places from dll-loading" |
|
438 |
||
439 |
|oldPath| |
|
440 |
||
441 |
oldPath := self dllPath. |
|
22144 | 442 |
oldPath notNil ifTrue:[ |
23228 | 443 |
self dllPath:(oldPath copyWithout:aDirectoryPathName) |
22144 | 444 |
]. |
11053 | 445 |
|
446 |
" |
|
23228 | 447 |
|prevDllPath| |
448 |
||
449 |
prevDllPath := self dllPath. |
|
450 |
self removeFromDllPath:'C:\aaa\bbb'. |
|
11586 | 451 |
self addToDllPath:'C:\aaa\bbb'. |
23228 | 452 |
self assert:self dllPath size = (prevDllPath size + 1). |
11053 | 453 |
self removeFromDllPath:'C:\aaa\bbb'. |
23228 | 454 |
self assert:self dllPath size = (prevDllPath size). |
11053 | 455 |
" |
23228 | 456 |
|
457 |
"Modified (comment): / 23-07-2018 / 11:16:26 / Stefan Vogel" |
|
8550 | 458 |
! ! |
459 |
||
9321 | 460 |
!ExternalLibraryFunction class methodsFor:'constants'! |
461 |
||
462 |
callTypeAPI |
|
9463 | 463 |
^ CALLTYPE_API |
9321 | 464 |
|
9463 | 465 |
"Modified: / 01-08-2006 / 13:44:41 / cg" |
9435 | 466 |
! |
467 |
||
9321 | 468 |
callTypeC |
9463 | 469 |
^ CALLTYPE_C |
9321 | 470 |
|
9463 | 471 |
"Modified: / 01-08-2006 / 13:44:49 / cg" |
9435 | 472 |
! |
473 |
||
9321 | 474 |
callTypeCDecl |
9463 | 475 |
^ CALLTYPE_C |
9321 | 476 |
|
9463 | 477 |
"Modified: / 01-08-2006 / 13:44:52 / cg" |
9435 | 478 |
! |
479 |
||
10619 | 480 |
callTypeMASK |
481 |
^ CALLTYPE_MASK |
|
482 |
||
483 |
"Modified: / 01-08-2006 / 13:44:57 / cg" |
|
484 |
! |
|
485 |
||
9321 | 486 |
callTypeOLE |
9463 | 487 |
^ CALLTYPE_OLE |
9435 | 488 |
|
9463 | 489 |
"Modified: / 01-08-2006 / 13:44:57 / cg" |
22544 | 490 |
! |
491 |
||
492 |
callTypeUNIX64 |
|
493 |
^ CALLTYPE_UNIX64 |
|
494 |
||
495 |
"Modified: / 01-08-2006 / 13:44:57 / cg" |
|
23828 | 496 |
! |
497 |
||
498 |
invokeSelectors |
|
499 |
^ #( |
|
500 |
#'invoke' |
|
501 |
#'invokeWith:' |
|
502 |
#'invokeWith:with:' |
|
503 |
#'invokeWith:with:with:' |
|
504 |
#'invokeWith:with:with:with:' |
|
505 |
#'invokeWithArguments:' |
|
506 |
#'invokeCPPVirtualOn:' |
|
507 |
#'invokeCPPVirtualOn:with:' |
|
508 |
#'invokeCPPVirtualOn:with:with:' |
|
509 |
#'invokeCPPVirtualOn:with:with:with:' |
|
510 |
#'invokeCPPVirtualOn:with:with:with:with:' |
|
511 |
#'invokeCPPVirtualOn:withArguments:' |
|
512 |
#'invokeObjCOn:' |
|
513 |
#'invokeObjCOn:with:' |
|
514 |
#'invokeObjCOn:with:with:' |
|
515 |
#'invokeObjCOn:with:with:with:' |
|
516 |
#'invokeObjCOn:with:with:with:with:' |
|
517 |
#'invokeObjCOn:withArguments:' |
|
518 |
) |
|
519 |
||
520 |
"Created: / 04-03-2019 / 09:35:51 / Claus Gittinger" |
|
9321 | 521 |
! ! |
522 |
||
19505 | 523 |
!ExternalLibraryFunction class methodsFor:'debugging'! |
524 |
||
525 |
verbose:aBoolean |
|
526 |
"turn on/off tracing of calls" |
|
527 |
||
528 |
Verbose := aBoolean |
|
529 |
||
530 |
" |
|
531 |
ExternalLibraryFunction verbose:true |
|
532 |
" |
|
533 |
||
534 |
"Created: / 30-03-2016 / 17:28:23 / cg" |
|
535 |
! ! |
|
536 |
||
19490 | 537 |
!ExternalLibraryFunction class methodsFor:'type name mapping'! |
538 |
||
539 |
ffiTypeSymbolForType:aType |
|
22162 | 540 |
"map aType to one of the ffi-supported ones: |
20528 | 541 |
sint8, sint16, sint32, sint64 |
542 |
uint8, uint16, uint32, uint64 |
|
543 |
long ulong int uint |
|
544 |
bool float double void pointer handle |
|
19490 | 545 |
" |
546 |
||
547 |
aType == #sint8 ifTrue:[^ aType ]. |
|
548 |
aType == #sint16 ifTrue:[^ aType ]. |
|
549 |
aType == #sint32 ifTrue:[^ aType ]. |
|
550 |
aType == #sint64 ifTrue:[^ aType ]. |
|
551 |
aType == #uint8 ifTrue:[^ aType ]. |
|
552 |
aType == #uint16 ifTrue:[^ aType ]. |
|
553 |
aType == #uint32 ifTrue:[^ aType ]. |
|
554 |
aType == #uint64 ifTrue:[^ aType ]. |
|
555 |
aType == #double ifTrue:[^ aType ]. |
|
556 |
aType == #float ifTrue:[^ aType ]. |
|
557 |
aType == #char ifTrue:[^ aType ]. |
|
558 |
aType == #void ifTrue:[^ aType ]. |
|
559 |
aType == #bool ifTrue:[^ aType ]. |
|
560 |
aType == #pointer ifTrue:[^ aType ]. |
|
561 |
aType == #charPointer ifTrue:[^ aType ]. |
|
562 |
aType == #wcharPointer ifTrue:[^ aType ]. |
|
563 |
||
564 |
aType == #int8 ifTrue:[^ #sint8 ]. |
|
565 |
aType == #int16 ifTrue:[^ #sint16 ]. |
|
566 |
aType == #int32 ifTrue:[^ #sint32 ]. |
|
567 |
aType == #int64 ifTrue:[^ #sint64 ]. |
|
568 |
||
569 |
aType == #voidPointer ifTrue:[^ #pointer ]. |
|
570 |
aType == #uint8Pointer ifTrue:[^ #pointer ]. |
|
571 |
aType == #voidPointerPointer ifTrue:[^ #pointer ]. |
|
572 |
||
573 |
aType == #short ifTrue:[^ #sint16 ]. |
|
574 |
aType == #long ifTrue:[^ #long ]. |
|
575 |
aType == #int ifTrue:[^ #int ]. |
|
576 |
aType == #uint ifTrue:[^ #uint ]. |
|
577 |
aType == #ushort ifTrue:[^ #uint16 ]. |
|
578 |
aType == #ulong ifTrue:[^ #ulong ]. |
|
579 |
aType == #uchar ifTrue:[^ #uint8 ]. |
|
580 |
aType == #byte ifTrue:[^ #uint8 ]. |
|
581 |
aType == #longlong ifTrue:[^ #sint64 ]. |
|
582 |
aType == #longLong ifTrue:[^ #sint64 ]. |
|
583 |
aType == #ulonglong ifTrue:[^ #uint64 ]. |
|
584 |
aType == #ulongLong ifTrue:[^ #uint64 ]. |
|
585 |
||
22162 | 586 |
aType == #unsignedInt ifTrue:[^ #uint ]. |
587 |
aType == #unsignedShort ifTrue:[^ #uint16 ]. |
|
588 |
aType == #unsignedLong ifTrue:[^ #ulong ]. |
|
589 |
aType == #unsignedChar ifTrue:[^ #uint8 ]. |
|
590 |
||
19490 | 591 |
"/ windefs |
592 |
aType == #dword ifTrue:[^ #uint32 ]. |
|
593 |
aType == #sdword ifTrue:[^ #sint32 ]. |
|
594 |
aType == #word ifTrue:[^ #uint16 ]. |
|
595 |
aType == #sword ifTrue:[^ #sint16 ]. |
|
596 |
aType == #handle ifTrue:[^ #pointer ]. |
|
597 |
aType == #lpstr ifTrue:[^ #charPointer ]. |
|
19501 | 598 |
"/ aType == #hresult ifTrue:[^ #uint32 ]. -- keep this; it is translated later (in invoke) |
19490 | 599 |
aType == #boolean ifTrue:[^ #bool ]. |
600 |
"/ care for 64bit machines |
|
22901 | 601 |
aType == #ulongReturn ifTrue:[^ ExternalBytes sizeofPointer == 8 ifTrue:[#uint64] ifFalse:[#uint32]]. |
19490 | 602 |
aType == #none ifTrue:[^ #void ]. |
603 |
aType == #struct ifTrue:[^ #pointer ]. |
|
604 |
aType == #structIn ifTrue:[^ #pointer ]. |
|
605 |
aType == #structOut ifTrue:[^ #pointer ]. |
|
606 |
aType == #structInOut ifTrue:[^ #pointer ]. |
|
607 |
aType == #unsigned ifTrue:[^ #uint ]. |
|
608 |
||
609 |
aType == #ATOM ifTrue:[^ #uint16 ]. |
|
610 |
aType == #BOOL ifTrue:[^ #int ]. |
|
611 |
aType == #BOOLEAN ifTrue:[^ #uint8 ]. |
|
612 |
aType == #BYTE ifTrue:[^ #uint8 ]. |
|
613 |
aType == #DWORD ifTrue:[^ #uint32 ]. |
|
614 |
aType == #HANDLE ifTrue:[^ #pointer ]. |
|
19535 | 615 |
aType == #HRESULT ifTrue:[^ #hresult ]. |
19501 | 616 |
|
22162 | 617 |
aType == #LPWSTR ifTrue:[^ #wcharPointer]. |
20528 | 618 |
aType == #BSTR ifTrue:[^ #wcharPointer]. |
619 |
||
19490 | 620 |
"/ care for 64bit machines |
22901 | 621 |
aType == #SIZE_T ifTrue:[^ ExternalBytes sizeofPointer == 8 ifTrue:[#uint64] ifFalse:[#uint32]]. |
19490 | 622 |
|
623 |
(aType isString or:[aType isSymbol]) ifFalse:[ |
|
20528 | 624 |
CType isNil ifTrue:[ |
625 |
self error:'unknown type'. |
|
626 |
]. |
|
627 |
^ aType typeSymbol. |
|
19490 | 628 |
]. |
629 |
||
630 |
(aType endsWith:'*') ifTrue:[ |
|
20528 | 631 |
^ #pointer. |
19490 | 632 |
]. |
633 |
(aType endsWith:'Pointer') ifTrue:[ |
|
20528 | 634 |
^ #pointer. |
19490 | 635 |
]. |
636 |
^ aType |
|
637 |
||
22162 | 638 |
"Modified: / 04-08-2017 / 10:36:37 / cg" |
19490 | 639 |
! ! |
640 |
||
9321 | 641 |
!ExternalLibraryFunction methodsFor:'accessing'! |
642 |
||
643 |
argumentTypes |
|
644 |
^ argumentTypes |
|
9463 | 645 |
! |
646 |
||
11426 | 647 |
argumentTypesString |
11586 | 648 |
^ String |
649 |
streamContents:[:s | |
|
650 |
argumentTypes do:[:eachArgType | |
|
651 |
eachArgType printOn:s. |
|
652 |
] separatedBy:[ |
|
653 |
s nextPutAll:','. |
|
654 |
]. |
|
655 |
]. |
|
11426 | 656 |
! |
657 |
||
9463 | 658 |
beAsync |
659 |
"let this execute in a separate thread, in par with the other execution thread(s). |
|
660 |
Ignored under unix/linux (until those support multiple threads too)." |
|
661 |
||
22556 | 662 |
flags := flags bitOr: FLAG_ASYNC. |
9463 | 663 |
|
664 |
"Created: / 01-08-2006 / 13:42:38 / cg" |
|
665 |
! |
|
666 |
||
9465 | 667 |
beCallTypeAPI |
22556 | 668 |
flags := flags bitOr: CALLTYPE_API. |
9465 | 669 |
|
670 |
"Created: / 01-08-2006 / 15:12:40 / cg" |
|
671 |
! |
|
672 |
||
673 |
beCallTypeC |
|
22556 | 674 |
flags := flags bitOr: CALLTYPE_C. |
9465 | 675 |
|
676 |
"Created: / 01-08-2006 / 15:12:40 / cg" |
|
677 |
! |
|
678 |
||
10481 | 679 |
beCallTypeOLE |
22556 | 680 |
flags := flags bitOr: FLAG_VIRTUAL. |
10481 | 681 |
|
682 |
"Created: / 01-08-2006 / 15:12:40 / cg" |
|
683 |
! |
|
684 |
||
9465 | 685 |
beCallTypeUNIX64 |
22556 | 686 |
flags := flags bitOr: CALLTYPE_UNIX64. |
9465 | 687 |
|
688 |
"Created: / 01-08-2006 / 15:13:38 / cg" |
|
689 |
! |
|
690 |
||
691 |
beCallTypeV8 |
|
22556 | 692 |
flags := flags bitOr: CALLTYPE_V8. |
9465 | 693 |
|
694 |
"Created: / 01-08-2006 / 15:13:28 / cg" |
|
695 |
! |
|
696 |
||
697 |
beCallTypeV9 |
|
22556 | 698 |
flags := flags bitOr: CALLTYPE_V9. |
9465 | 699 |
|
700 |
"Created: / 01-08-2006 / 15:13:31 / cg" |
|
701 |
! |
|
702 |
||
703 |
beCallTypeWINAPI |
|
704 |
self beCallTypeAPI |
|
705 |
||
706 |
"Modified: / 01-08-2006 / 15:14:02 / cg" |
|
707 |
! |
|
708 |
||
9525 | 709 |
beConstReturnValue |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
710 |
"specify that a pointer return value is not to be finalized |
9525 | 711 |
(i.e. points to static data or data which is freed by c)" |
712 |
||
22556 | 713 |
flags := flags bitOr: FLAG_RETVAL_IS_CONST. |
9525 | 714 |
|
715 |
"Created: / 01-08-2006 / 13:56:48 / cg" |
|
716 |
! |
|
717 |
||
21410 | 718 |
beMustFreeReturnValue |
719 |
"specify that a pointer return value is to be freed explicitly by st/x |
|
720 |
(i.e. points to mallocd data which is not freed by c)" |
|
721 |
||
22556 | 722 |
flags := flags bitOr: FLAG_RETVAL_MUST_FREE. |
21410 | 723 |
|
724 |
"Created: / 12-02-2017 / 23:41:48 / cg" |
|
725 |
! |
|
726 |
||
9463 | 727 |
beNonVirtualCPP |
728 |
"specify this as a non-virtual c++-function" |
|
729 |
||
22556 | 730 |
flags := flags bitOr: FLAG_NONVIRTUAL. |
9463 | 731 |
|
732 |
"Created: / 01-08-2006 / 13:56:44 / cg" |
|
733 |
! |
|
734 |
||
19311 | 735 |
beObjectiveC |
736 |
"specify this as an objective-c message send" |
|
737 |
||
22556 | 738 |
flags := flags bitOr: FLAG_OBJECTIVEC. |
19311 | 739 |
|
740 |
"Created: / 01-08-2006 / 13:56:48 / cg" |
|
741 |
! |
|
742 |
||
9463 | 743 |
beUnlimitedStack |
744 |
"let this execute on the c-stack (as opposed to the thread-stack) |
|
745 |
for unlimited auto-sized-stack under unix/linux. |
|
746 |
Ignored under windows." |
|
747 |
||
22556 | 748 |
flags := flags bitOr: FLAG_UNLIMITEDSTACK. |
9463 | 749 |
|
750 |
"Created: / 01-08-2006 / 13:41:54 / cg" |
|
751 |
! |
|
752 |
||
753 |
beVirtualCPP |
|
754 |
"specify this as a virtual c++-function" |
|
755 |
||
22556 | 756 |
flags := flags bitOr: FLAG_VIRTUAL. |
9463 | 757 |
|
758 |
"Created: / 01-08-2006 / 13:56:48 / cg" |
|
759 |
! |
|
760 |
||
9465 | 761 |
callTypeNumber |
22556 | 762 |
^ flags bitAnd: CALLTYPE_MASK. |
9465 | 763 |
|
764 |
"Created: / 01-08-2006 / 15:12:10 / cg" |
|
765 |
! |
|
766 |
||
9463 | 767 |
isAsync |
768 |
"is this executed in a separate thread, in par with the other execution thread(s) ?" |
|
769 |
||
22556 | 770 |
^ flags bitTest: FLAG_ASYNC. |
9463 | 771 |
|
772 |
"Created: / 01-08-2006 / 13:46:53 / cg" |
|
773 |
! |
|
774 |
||
9519 | 775 |
isCPPFunction |
776 |
"is this a virtual or non-virtual c++-function ?" |
|
777 |
||
22556 | 778 |
^ flags bitTest: (FLAG_VIRTUAL bitOr: FLAG_NONVIRTUAL). |
9519 | 779 |
|
780 |
"Created: / 01-08-2006 / 13:56:54 / cg" |
|
781 |
! |
|
782 |
||
9465 | 783 |
isCallTypeAPI |
19490 | 784 |
"is this a windows API-call linkage call. |
785 |
Attention: this uses a different call API (callee unwinds the stack), |
|
786 |
and MUST be declared as such for many Kernel functions. |
|
787 |
The calltype API is one of the worst historic garbage kept by MS..." |
|
788 |
||
22556 | 789 |
^ (flags bitAnd: CALLTYPE_MASK) == CALLTYPE_API. |
9465 | 790 |
|
791 |
"Created: / 01-08-2006 / 15:21:16 / cg" |
|
792 |
! |
|
793 |
||
794 |
isCallTypeC |
|
19490 | 795 |
"is this a regular C-call (attention: on windows, there are two kinds of calls)" |
796 |
||
22556 | 797 |
^ (flags bitAnd: CALLTYPE_MASK) == CALLTYPE_C. |
9465 | 798 |
|
799 |
"Created: / 01-08-2006 / 15:21:23 / cg" |
|
800 |
! |
|
801 |
||
10483 | 802 |
isCallTypeOLE |
19490 | 803 |
"is this an OLE-object call ? (eg. a virtual c++ call; same as isCallTypeCPP)" |
804 |
||
22556 | 805 |
^ flags bitTest: FLAG_VIRTUAL. |
10483 | 806 |
|
807 |
"Created: / 01-08-2006 / 15:21:23 / cg" |
|
20958 | 808 |
"Modified (format): / 12-11-2016 / 11:37:38 / cg" |
10483 | 809 |
! |
810 |
||
9525 | 811 |
isConstReturnValue |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
812 |
"is the pointer return value not to be finalized |
9525 | 813 |
(i.e. points to static data or data which is freed by c)" |
814 |
||
22556 | 815 |
^ flags bitTest: FLAG_RETVAL_IS_CONST. |
9525 | 816 |
|
817 |
"Created: / 01-08-2006 / 13:56:48 / cg" |
|
818 |
! |
|
819 |
||
9463 | 820 |
isNonVirtualCPP |
821 |
"is this a non-virtual c++-function ?" |
|
822 |
||
22556 | 823 |
^ flags bitTest: FLAG_NONVIRTUAL. |
9463 | 824 |
|
825 |
"Created: / 01-08-2006 / 13:56:51 / cg" |
|
826 |
! |
|
827 |
||
19311 | 828 |
isObjectiveC |
829 |
"is this an objective-C message?" |
|
830 |
||
22556 | 831 |
^ flags bitTest: FLAG_OBJECTIVEC. |
19311 | 832 |
! |
833 |
||
9463 | 834 |
isUnlimitedStack |
835 |
"will this execute on the c-stack (as opposed to the thread-stack) |
|
836 |
for unlimited auto-sized-stack under unix/linux. |
|
837 |
Ignored under windows." |
|
838 |
||
22556 | 839 |
^ flags bitTest: FLAG_UNLIMITEDSTACK. |
9463 | 840 |
|
841 |
"Created: / 01-08-2006 / 14:17:07 / cg" |
|
842 |
! |
|
843 |
||
844 |
isVirtualCPP |
|
19490 | 845 |
"is this a virtual c++-function (same as isCallTypeOLE) ?" |
9463 | 846 |
|
22556 | 847 |
^ flags bitTest: FLAG_VIRTUAL. |
9463 | 848 |
|
849 |
"Created: / 01-08-2006 / 13:56:54 / cg" |
|
10483 | 850 |
! |
851 |
||
11426 | 852 |
moduleName |
853 |
^ moduleName |
|
854 |
! |
|
855 |
||
21409 | 856 |
mustFreeReturnValue |
22556 | 857 |
"answer true, if a pointer to some C-datum is returned, which must be freed by ST/X. |
21409 | 858 |
(i.e. points to malloc'd data which is NOT freed by c)" |
859 |
||
22556 | 860 |
^ flags bitTest: FLAG_RETVAL_MUST_FREE. |
21409 | 861 |
|
862 |
"Created: / 12-02-2017 / 23:31:27 / cg" |
|
863 |
! |
|
864 |
||
10484 | 865 |
returnType |
866 |
^ returnType |
|
867 |
! |
|
868 |
||
10483 | 869 |
vtableIndex |
870 |
name isNumber ifFalse:[^ nil]. |
|
871 |
^ name. |
|
9321 | 872 |
! ! |
873 |
||
20289 | 874 |
|
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
875 |
!ExternalLibraryFunction methodsFor:'invoking'! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
876 |
|
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
877 |
invoke |
23828 | 878 |
"call the function with no arguments" |
879 |
||
9321 | 880 |
self hasCode ifFalse:[ |
23828 | 881 |
self prepareInvoke. |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
882 |
]. |
19311 | 883 |
^ self invokeFFIwithArguments:nil forCPPInstance:nil |
23828 | 884 |
|
885 |
"Modified (comment): / 04-03-2019 / 09:41:20 / Claus Gittinger" |
|
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
886 |
! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
887 |
|
9347 | 888 |
invokeCPPVirtualOn:anInstance |
23828 | 889 |
"call a CPP virtual function with no arguments" |
890 |
||
9341 | 891 |
self hasCode ifFalse:[ |
23828 | 892 |
self prepareInvoke. |
9341 | 893 |
]. |
23828 | 894 |
^ self invokeFFIwithArguments:nil forCPPInstance:anInstance |
895 |
||
896 |
"Modified (comment): / 04-03-2019 / 09:39:27 / Claus Gittinger" |
|
9341 | 897 |
! |
898 |
||
23828 | 899 |
invokeCPPVirtualOn:anInstance with:arg |
900 |
"call a CPP virtual function with 1 argument" |
|
901 |
||
9341 | 902 |
self hasCode ifFalse:[ |
23828 | 903 |
self prepareInvoke. |
9341 | 904 |
]. |
23828 | 905 |
^ self |
906 |
invokeFFIwithArguments:(Array with:arg) |
|
907 |
forCPPInstance:anInstance |
|
908 |
||
909 |
"Modified (comment): / 04-03-2019 / 09:39:34 / Claus Gittinger" |
|
9341 | 910 |
! |
911 |
||
23828 | 912 |
invokeCPPVirtualOn:anInstance with:arg1 with:arg2 |
913 |
"call a CPP virtual function with 2 arguments" |
|
914 |
||
9341 | 915 |
self hasCode ifFalse:[ |
23828 | 916 |
self prepareInvoke. |
9341 | 917 |
]. |
23828 | 918 |
^ self |
919 |
invokeFFIwithArguments:(Array with:arg1 with:arg2) |
|
920 |
forCPPInstance:anInstance |
|
921 |
||
922 |
"Modified (comment): / 04-03-2019 / 09:39:38 / Claus Gittinger" |
|
923 |
! |
|
924 |
||
925 |
invokeCPPVirtualOn:anInstance with:arg1 with:arg2 with:arg3 |
|
926 |
"call a CPP virtual function with 3 arguments" |
|
927 |
||
928 |
self hasCode ifFalse:[ |
|
929 |
self prepareInvoke. |
|
930 |
]. |
|
931 |
^ self |
|
932 |
invokeFFIwithArguments:(Array with:arg1 with:arg2 with:arg3) |
|
933 |
forCPPInstance:anInstance |
|
934 |
||
935 |
"Modified (comment): / 04-03-2019 / 09:39:43 / Claus Gittinger" |
|
9341 | 936 |
! |
937 |
||
23828 | 938 |
invokeCPPVirtualOn:anInstance with:arg1 with:arg2 with:arg3 with:arg4 |
939 |
"call a CPP virtual function with 4 arguments" |
|
940 |
||
9341 | 941 |
self hasCode ifFalse:[ |
23828 | 942 |
self prepareInvoke. |
9341 | 943 |
]. |
23828 | 944 |
^ self |
945 |
invokeFFIwithArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
946 |
forCPPInstance:anInstance |
|
947 |
||
948 |
"Modified (comment): / 04-03-2019 / 09:39:48 / Claus Gittinger" |
|
9341 | 949 |
! |
950 |
||
23828 | 951 |
invokeCPPVirtualOn:anInstance withArguments:args |
952 |
"call a CPP virtual function with up to maxArgs (15) arguments" |
|
953 |
||
9341 | 954 |
self hasCode ifFalse:[ |
23828 | 955 |
self prepareInvoke. |
9341 | 956 |
]. |
23828 | 957 |
^ self |
958 |
invokeFFIwithArguments:args |
|
959 |
forCPPInstance:anInstance |
|
960 |
||
961 |
"Modified (comment): / 04-03-2019 / 09:39:57 / Claus Gittinger" |
|
9341 | 962 |
! |
963 |
||
23828 | 964 |
invokeObjCOn:anInstance |
965 |
"call an ObjC method with no arguments" |
|
966 |
||
10481 | 967 |
self hasCode ifFalse:[ |
23828 | 968 |
self prepareObjCInvoke. |
10481 | 969 |
]. |
23828 | 970 |
^ self invokeFFIwithArguments:nil forCPPInstance:anInstance |
971 |
||
972 |
"Created: / 04-03-2019 / 09:12:12 / Claus Gittinger" |
|
973 |
! |
|
974 |
||
975 |
invokeObjCOn:anInstance withArguments:args |
|
976 |
"call an ObjC method with up to maxArgs (15) arguments" |
|
977 |
||
978 |
self hasCode ifFalse:[ |
|
979 |
self prepareObjCInvoke. |
|
980 |
]. |
|
981 |
^ self invokeFFIwithArguments:args forCPPInstance:anInstance |
|
982 |
||
983 |
"Created: / 04-03-2019 / 09:39:03 / Claus Gittinger" |
|
10481 | 984 |
! |
985 |
||
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
986 |
invokeWith:arg |
23828 | 987 |
"call the function with 1 argument" |
988 |
||
9321 | 989 |
self hasCode ifFalse:[ |
23828 | 990 |
self prepareInvoke. |
9321 | 991 |
]. |
19311 | 992 |
^ self invokeFFIwithArguments:(Array with:arg) forCPPInstance:nil |
23828 | 993 |
|
994 |
"Modified (comment): / 04-03-2019 / 09:41:14 / Claus Gittinger" |
|
9321 | 995 |
! |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
996 |
|
9321 | 997 |
invokeWith:arg1 with:arg2 |
23828 | 998 |
"call the function with 2 arguments" |
999 |
||
9321 | 1000 |
self hasCode ifFalse:[ |
23828 | 1001 |
self prepareInvoke. |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1002 |
]. |
19311 | 1003 |
^ self invokeFFIwithArguments:(Array with:arg1 with:arg2) forCPPInstance:nil |
23828 | 1004 |
|
1005 |
"Modified (comment): / 04-03-2019 / 09:41:07 / Claus Gittinger" |
|
9321 | 1006 |
! |
1007 |
||
1008 |
invokeWith:arg1 with:arg2 with:arg3 |
|
23828 | 1009 |
"call the function with 3 arguments" |
1010 |
||
9321 | 1011 |
self hasCode ifFalse:[ |
23828 | 1012 |
self prepareInvoke. |
9321 | 1013 |
]. |
19311 | 1014 |
^ self invokeFFIwithArguments:(Array with:arg1 with:arg2 with:arg3) forCPPInstance:nil |
23828 | 1015 |
|
1016 |
"Modified (comment): / 04-03-2019 / 09:41:01 / Claus Gittinger" |
|
9321 | 1017 |
! |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1018 |
|
9321 | 1019 |
invokeWith:arg1 with:arg2 with:arg3 with:arg4 |
23828 | 1020 |
"call the function with 4 arguments" |
1021 |
||
9321 | 1022 |
self hasCode ifFalse:[ |
23828 | 1023 |
self prepareInvoke. |
9321 | 1024 |
]. |
19311 | 1025 |
^ self invokeFFIwithArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) forCPPInstance:nil |
23828 | 1026 |
|
1027 |
"Modified (comment): / 04-03-2019 / 09:40:56 / Claus Gittinger" |
|
9321 | 1028 |
! |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1029 |
|
9321 | 1030 |
invokeWithArguments:argArray |
23828 | 1031 |
"call the function with up to maxArgs (15) arguments" |
1032 |
||
9321 | 1033 |
self hasCode ifFalse:[ |
23828 | 1034 |
self prepareInvoke. |
9321 | 1035 |
]. |
9465 | 1036 |
^ self invokeFFIwithArguments:argArray forCPPInstance:nil |
1037 |
||
1038 |
"Modified: / 01-08-2006 / 16:04:08 / cg" |
|
23828 | 1039 |
"Modified (comment): / 04-03-2019 / 09:40:48 / Claus Gittinger" |
9321 | 1040 |
! ! |
1041 |
||
1042 |
!ExternalLibraryFunction methodsFor:'printing'! |
|
1043 |
||
1044 |
printOn:aStream |
|
21487 | 1045 |
aStream nextPut:$<. |
9465 | 1046 |
self isCallTypeAPI ifTrue:[ |
21487 | 1047 |
'API:' printOn:aStream. |
9465 | 1048 |
] ifFalse:[ |
21487 | 1049 |
self isCallTypeOLE ifTrue:[ |
1050 |
'OLE:' printOn:aStream. |
|
1051 |
] ifFalse:[ |
|
1052 |
self isCallTypeC ifTrue:[ |
|
1053 |
'C:' printOn:aStream. |
|
1054 |
] ifFalse:[ |
|
22556 | 1055 |
aStream nextPutAll:'Error: unknown call type '. |
21487 | 1056 |
]. |
1057 |
]. |
|
9465 | 1058 |
]. |
21487 | 1059 |
aStream space. |
9321 | 1060 |
name printOn:aStream. |
9465 | 1061 |
moduleName notNil ifTrue:[ |
21487 | 1062 |
aStream nextPutAll:' module:'. |
1063 |
moduleName printOn:aStream. |
|
9465 | 1064 |
]. |
21487 | 1065 |
aStream nextPut:$>. |
9465 | 1066 |
|
14356 | 1067 |
"Modified: / 25-09-2012 / 12:06:14 / cg" |
21487 | 1068 |
"Modified: / 17-02-2017 / 09:48:25 / stefan" |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1069 |
! ! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1070 |
|
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1071 |
!ExternalLibraryFunction methodsFor:'private'! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1072 |
|
10213 | 1073 |
adjustTypes |
19490 | 1074 |
"map all those existing type names to a small number of definite ffi type names. |
1075 |
This is needed, because there are so many different C-type names found in code imported |
|
1076 |
from various Smalltalk dialects' library function call declarations. |
|
1077 |
For example: all of word, WORD, unsignedShort, ushort, uShort etc. will map to uint16. |
|
1078 |
Also, this deals with pointer size differences." |
|
1079 |
||
19313 | 1080 |
argumentTypes notEmptyOrNil ifTrue:[ |
19535 | 1081 |
argumentTypes := argumentTypes collect:[:argType | self class ffiTypeSymbolForType:argType]. |
10213 | 1082 |
]. |
19490 | 1083 |
returnType := self class ffiTypeSymbolForType:returnType. |
10213 | 1084 |
! |
1085 |
||
22141 | 1086 |
convertArgument:arg |
1087 |
"a chance to convert arguments to one of the primitive (native) types." |
|
1088 |
||
1089 |
CDatum notNil ifTrue:[ |
|
1090 |
arg isCDatum ifTrue:[ |
|
1091 |
arg offset == 0 ifTrue:[ |
|
1092 |
^ (arg data) |
|
1093 |
]. |
|
1094 |
arg data isExternalBytes ifTrue:[ |
|
1095 |
^ ExternalAddress newAddress:(arg data address + arg offset). |
|
1096 |
]. |
|
1097 |
]. |
|
1098 |
]. |
|
1099 |
^ arg. |
|
1100 |
||
1101 |
"Created: / 01-08-2017 / 14:00:45 / cg" |
|
1102 |
! |
|
1103 |
||
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1104 |
linkToModule |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1105 |
"link this function to the external module. |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1106 |
I.e. retrieve the module handle and the code pointer." |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1107 |
|
9465 | 1108 |
|handle moduleNameUsed functionName| |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1109 |
|
10481 | 1110 |
name isNumber ifTrue:[ |
20311 | 1111 |
self isCPPFunction ifTrue:[ |
1112 |
"/ no need to load a dll. |
|
1113 |
^ self |
|
1114 |
] |
|
10481 | 1115 |
]. |
1116 |
||
13782
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
1117 |
"/ in some other smalltalks, there is no moduleName in the ffi-spec; |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
1118 |
"/ instead, the class provides the libraryName... |
9465 | 1119 |
(moduleNameUsed := moduleName) isNil ifTrue:[ |
22904 | 1120 |
owningClass notNil ifTrue:[ |
1121 |
moduleNameUsed := owningClass theNonMetaclass perform:#libraryName ifNotUnderstood:nil. |
|
20311 | 1122 |
]. |
22904 | 1123 |
moduleNameUsed isNil ifTrue:[ |
1124 |
self error:'Missing shared library name'. |
|
1125 |
]. |
|
1126 |
moduleNameUsed := moduleNameUsed asSymbol. |
|
9321 | 1127 |
]. |
11586 | 1128 |
moduleHandle isNil ifTrue:[ |
20311 | 1129 |
"/ speedup. in 95% of all calls, the same moduleName is resolved here |
1130 |
(LastModuleHandleHolder isNil |
|
1131 |
or:[ (handle := LastModuleHandleHolder at:1) isNil |
|
20958 | 1132 |
or:[ handle == -1 |
1133 |
or:[ LastModuleHandleName ~= moduleNameUsed ]]]) ifTrue:[ |
|
19342 | 1134 |
|
20311 | 1135 |
handle := self loadLibrary:moduleNameUsed. |
1136 |
LastModuleHandleHolder := WeakArray with:handle. |
|
1137 |
LastModuleHandleName := moduleNameUsed. |
|
1138 |
]. |
|
20958 | 1139 |
self assert:(handle isInteger not). |
20311 | 1140 |
moduleHandle := handle. |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1141 |
]. |
9341 | 1142 |
name isNumber ifFalse:[ |
20311 | 1143 |
functionName := name. |
1144 |
(moduleHandle getFunctionAddress:functionName into:self) isNil ifTrue:[ |
|
1145 |
(moduleHandle getFunctionAddress:('_', functionName) into:self) isNil ifTrue:[ |
|
1146 |
moduleHandle := nil. |
|
1147 |
LastModuleHandleHolder := LastModuleHandleName := nil. |
|
23227 | 1148 |
ObjectFileLoader::ObjectFileLoadError raiseRequestErrorString:'Missing function: "', name, '" in shared library: "', moduleNameUsed, '"'. |
20311 | 1149 |
]. |
1150 |
]. |
|
9321 | 1151 |
]. |
9392 | 1152 |
|
22163 | 1153 |
"Modified: / 04-08-2017 / 20:10:41 / cg" |
22904 | 1154 |
"Modified: / 11-05-2018 / 12:18:14 / stefan" |
23227 | 1155 |
"Modified: / 22-07-2018 / 15:16:19 / Stefan Vogel" |
9321 | 1156 |
! |
1157 |
||
10270 | 1158 |
loadLibrary:dllName |
19490 | 1159 |
"load a dll. |
21408 | 1160 |
Returns a handle or nil. |
19490 | 1161 |
Notice the dllMapping mechanism, which can be used to silently load different dlls. |
1162 |
This is useful, if some code has a hardcoded dll-name in it, which needs to be changed, |
|
1163 |
but you do not want or cannot recompile the methods (i.e. no source avail)" |
|
1164 |
||
23228 | 1165 |
|handle nameString filename dllPaths hasSuffix| |
10279
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
1166 |
|
23227 | 1167 |
ObjectFileLoader isNil ifTrue:[ |
1168 |
"no libcomp loaded" |
|
1169 |
^ self primitiveFailed:'libcomp:ObjectFileLoader is not available'. |
|
1170 |
]. |
|
1171 |
||
20958 | 1172 |
(ObjectFileLoader notNil and:[ObjectFileLoader canLoadObjectFiles]) ifFalse:[ |
23227 | 1173 |
ObjectFileLoader::ObjectFileLoadError raiseErrorString:('ObjectFileLoader cannot load dll/module: "%1"' bindWith:nameString)e. |
1174 |
^ nil. |
|
20561 | 1175 |
]. |
1176 |
||
14103 | 1177 |
filename := dllName. |
1178 |
DllMapping notNil ifTrue:[ |
|
20390 | 1179 |
filename := DllMapping at:filename ifAbsent:[ filename ] |
14103 | 1180 |
]. |
1181 |
||
1182 |
filename := filename asFilename. |
|
10279
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
1183 |
|
12937 | 1184 |
"try to load, maybe the system knows where to find the dll" |
1185 |
handle := ObjectFileLoader loadDynamicObject:filename. |
|
23228 | 1186 |
handle notNil ifTrue:[ |
1187 |
^ handle |
|
1188 |
]. |
|
1189 |
||
1190 |
nameString := filename name. |
|
1191 |
hasSuffix := filename suffix notEmpty. |
|
1192 |
||
1193 |
filename isAbsolute ifTrue:[ |
|
1194 |
hasSuffix ifFalse:[ |
|
1195 |
"/ try again with the OS-specific dll-extension |
|
1196 |
ObjectFileLoader sharedLibrarySuffixes do:[:eachPossibleSuffix | |
|
1197 |
handle := ObjectFileLoader loadDynamicObject:(filename withSuffix:eachPossibleSuffix). |
|
1198 |
handle notNil ifTrue:[ |
|
1199 |
^ handle |
|
1200 |
]. |
|
1201 |
]. |
|
1202 |
]. |
|
1203 |
] ifFalse:[ |
|
20390 | 1204 |
"First ask the class defining the ExternalFunction for the location of the dlls ..." |
20996 | 1205 |
dllPaths := #(). |
20390 | 1206 |
owningClass notNil ifTrue:[ |
23228 | 1207 |
dllPaths := owningClass dllPath. |
20390 | 1208 |
]. |
23228 | 1209 |
".. then ask the system .. and the settings" |
1210 |
dllPaths := dllPaths, self class dllPath, UserPreferences current dllPath. |
|
22144 | 1211 |
|
20996 | 1212 |
dllPaths do:[:eachDirectory | |
20390 | 1213 |
|libraryName| |
1214 |
||
1215 |
libraryName := eachDirectory asFilename construct:nameString. |
|
23228 | 1216 |
hasSuffix ifTrue:[ |
1217 |
handle := ObjectFileLoader loadDynamicObject:libraryName. |
|
1218 |
handle notNil ifTrue:[ |
|
1219 |
^ handle |
|
1220 |
]. |
|
1221 |
] ifFalse:[ |
|
21411 | 1222 |
ObjectFileLoader sharedLibrarySuffixes do:[:eachPossibleSuffix | |
1223 |
handle := ObjectFileLoader loadDynamicObject:(libraryName withSuffix:eachPossibleSuffix). |
|
23228 | 1224 |
handle notNil ifTrue:[ |
1225 |
^ handle |
|
1226 |
]. |
|
21411 | 1227 |
]. |
1228 |
]. |
|
20390 | 1229 |
]. |
10279
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
1230 |
]. |
10270 | 1231 |
|
12436 | 1232 |
|
21400 | 1233 |
"/ check for: the dll-path in: |
1234 |
"/ - owningClass dllPath |
|
1235 |
"/ - self class dllPath |
|
1236 |
"/ check for: the dll-name mapping |
|
1237 |
"/ - DllMapping (the classVar, but accessed via self class dllMapping) |
|
1238 |
"/ this can map both basenames and whole pathnames |
|
1239 |
"/ eg: self class dllMapping at:'libtesseract' put:('/opt/local/lib/libtesseract.dylib'). |
|
1240 |
"/ see also the settings dialog for external libraries. |
|
23227 | 1241 |
ObjectFileLoader::ObjectFileLoadError |
1242 |
raiseErrorString:('Cannot find or load dll/module: "%1" (check dllPath settings)' bindWith:nameString). |
|
10270 | 1243 |
^ nil |
14103 | 1244 |
|
21411 | 1245 |
"Modified: / 13-02-2017 / 01:14:05 / cg" |
23228 | 1246 |
"Modified: / 22-07-2018 / 16:34:24 / Stefan Vogel" |
10270 | 1247 |
! |
1248 |
||
9321 | 1249 |
prepareInvoke |
19490 | 1250 |
"called before invoked. |
19535 | 1251 |
When called the very first time, moduleHandle is nil, |
19490 | 1252 |
and we ensure that the dll is loaded, the function address is extracted" |
1253 |
||
10270 | 1254 |
(moduleHandle isNil or:[self hasCode not]) ifTrue:[ |
19535 | 1255 |
self linkToModule. |
1256 |
self adjustTypes. |
|
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1257 |
]. |
23828 | 1258 |
! |
1259 |
||
1260 |
prepareObjCInvoke |
|
1261 |
"called before invoked" |
|
1262 |
||
1263 |
"Created: / 04-03-2019 / 09:20:39 / Claus Gittinger" |
|
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1264 |
! ! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1265 |
|
8550 | 1266 |
!ExternalLibraryFunction methodsFor:'private-accessing'! |
1267 |
||
9466 | 1268 |
name:functionNameOrVirtualIndex module:aModuleName returnType:aReturnType argumentTypes:argTypes |
22556 | 1269 |
flags := 0. |
9466 | 1270 |
name := functionNameOrVirtualIndex. |
1271 |
functionNameOrVirtualIndex isNumber ifTrue:[ |
|
22556 | 1272 |
self beVirtualCPP. |
9466 | 1273 |
]. |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1274 |
moduleName := aModuleName. |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1275 |
returnType := aReturnType. |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
1276 |
argumentTypes := argTypes. |
9465 | 1277 |
|
1278 |
"Created: / 01-08-2006 / 15:19:52 / cg" |
|
9466 | 1279 |
"Modified: / 02-08-2006 / 17:20:13 / cg" |
9465 | 1280 |
! |
1281 |
||
11426 | 1282 |
owningClass |
1283 |
^ owningClass |
|
1284 |
! |
|
1285 |
||
9465 | 1286 |
owningClass:aClass |
1287 |
owningClass := aClass. |
|
1288 |
||
1289 |
"Created: / 01-08-2006 / 15:22:50 / cg" |
|
10603 | 1290 |
! |
1291 |
||
11586 | 1292 |
setModuleName:aModuleName |
10603 | 1293 |
aModuleName ~= moduleName ifTrue:[ |
11586 | 1294 |
self code:nil. |
1295 |
moduleHandle := nil. |
|
1296 |
moduleName := aModuleName. |
|
10603 | 1297 |
]. |
1298 |
||
1299 |
"Created: / 07-06-2007 / 10:20:17 / cg" |
|
8550 | 1300 |
! ! |
1301 |
||
9342 | 1302 |
!ExternalLibraryFunction methodsFor:'private-invoking'! |
1303 |
||
9347 | 1304 |
invokeCPPVirtualFFIOn:instance withArguments:arguments |
9463 | 1305 |
^ self invokeFFIwithArguments:arguments forCPPInstance:instance |
1306 |
||
1307 |
"Modified: / 01-08-2006 / 13:55:30 / cg" |
|
9342 | 1308 |
! |
1309 |
||
9347 | 1310 |
invokeFFIWithArguments:arguments |
9463 | 1311 |
^ self invokeFFIwithArguments:arguments forCPPInstance:nil |
1312 |
||
1313 |
"Modified: / 01-08-2006 / 13:55:35 / cg" |
|
9347 | 1314 |
! |
1315 |
||
22141 | 1316 |
invokeFFIwithArguments:argumentsOrNilIn forCPPInstance:aReceiverOrNil |
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1317 |
"basic invoke mechanism. Calls the function represented by the receiver with argumentsOrNil. |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1318 |
For cplusplus, aReceiverOrNil is required to be an externalStructure like object; |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1319 |
for objectiveC, it must be an ObjectiveC object" |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1320 |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1321 |
|argTypeSymbols returnTypeSymbol failureCode failureArgNr failureInfo returnValue stClass vtOffset |
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1322 |
virtual objectiveC async unlimitedStack callTypeNumber returnValueClass argValueClass |
22141 | 1323 |
oldReturnType oldArgumentTypes mustFreeRetVal alreadyFreed argumentsOrNil| |
9342 | 1324 |
|
22141 | 1325 |
argumentsOrNil := argumentsOrNilIn. |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1326 |
argTypeSymbols := argumentTypes. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1327 |
returnTypeSymbol := returnType. |
9346 | 1328 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1329 |
virtual := self isVirtualCPP. |
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1330 |
objectiveC := self isObjectiveC. |
9524 | 1331 |
(virtual "or:[self isNonVirtualCPP]") ifTrue:[ |
20309 | 1332 |
aReceiverOrNil isNil ifTrue:[ |
1333 |
"/ must have a c++ object instance |
|
1334 |
self primitiveFailed. |
|
1335 |
]. |
|
9463 | 1336 |
|
20309 | 1337 |
"/ and it must be a kind of ExternalStructure !! |
1338 |
(aReceiverOrNil isKindOf:ExternalStructure) ifFalse:[ |
|
1339 |
self primitiveFailed. |
|
1340 |
]. |
|
1341 |
virtual ifTrue:[ |
|
1342 |
vtOffset := name. |
|
1343 |
(vtOffset between:0 and:10000) ifFalse:[ |
|
1344 |
self primitiveFailed. |
|
1345 |
] |
|
1346 |
]. |
|
9463 | 1347 |
] ifFalse:[ |
20309 | 1348 |
objectiveC ifTrue:[ |
1349 |
aReceiverOrNil isNil ifTrue:[ |
|
1350 |
"/ must have an objective-c object instance |
|
1351 |
self primitiveFailed. |
|
1352 |
]. |
|
1353 |
(aReceiverOrNil isObjectiveCObject) ifFalse:[ |
|
1354 |
self primitiveFailed |
|
1355 |
] |
|
1356 |
] ifFalse:[ |
|
1357 |
aReceiverOrNil notNil ifTrue:[ |
|
1358 |
"/ must NOT have a c++/objectiveC object instance |
|
1359 |
self primitiveFailed. |
|
1360 |
] |
|
1361 |
]. |
|
9342 | 1362 |
]. |
9463 | 1363 |
async := self isAsync. |
1364 |
unlimitedStack := self isUnlimitedStack. |
|
9465 | 1365 |
callTypeNumber := self callTypeNumber. |
21412 | 1366 |
mustFreeRetVal := self mustFreeReturnValue. |
1367 |
alreadyFreed := false. |
|
21748 | 1368 |
|
23785 | 1369 |
argumentsOrNil size ~~ 0 ifTrue:[ |
22141 | 1370 |
argumentsOrNil := argumentsOrNil collect:[:arg | self convertArgument:arg] |
1371 |
]. |
|
1372 |
||
10512 | 1373 |
"/ Transcript show:name; show:' async:'; showCR:async. |
9342 | 1374 |
|
9459
6cd520c582b3
change from unlimited to big stack, to allow for interrupts to be handled
ca
parents:
9436
diff
changeset
|
1375 |
%{ /* STACK: 100000 */ |
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1376 |
|
19931 | 1377 |
#define VERBOSE |
1378 |
||
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1379 |
#ifdef HAVE_FFI |
19931 | 1380 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1381 |
# ifdef __GNUC__ |
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1382 |
# ifndef HAS_LONGLONG |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1383 |
# define HAS_LONGLONG |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1384 |
# endif |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1385 |
# endif |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1386 |
# if defined(__BORLANDC__) || defined(__VISUALC__) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1387 |
# define HAS_INT64 |
19364 | 1388 |
# ifndef __LO32 |
1389 |
# define __LO32(ll) ((ll) & 0xFFFFFFFFL) |
|
1390 |
# define __HI32(ll) (((ll)>>32) & 0xFFFFFFFFL) |
|
1391 |
# endif |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1392 |
# endif |
19931 | 1393 |
|
1394 |
||
9342 | 1395 |
ffi_cif __cif; |
1396 |
ffi_type *__argTypesIncludingThis[MAX_ARGS+1]; |
|
1397 |
ffi_type **__argTypes = __argTypesIncludingThis; |
|
1398 |
ffi_type *__returnType = NULL; |
|
19931 | 1399 |
ffi_type *thisType; |
1400 |
ffi_abi __callType = FFI_DEFAULT_ABI; |
|
1401 |
||
1402 |
#else |
|
1403 |
||
1404 |
int __argTypesIncludingThis[MAX_ARGS+1]; |
|
1405 |
int *__argTypes = __argTypesIncludingThis; |
|
1406 |
int __returnType = 0; |
|
1407 |
int thisType; |
|
1408 |
int __callType = FFI_DEFAULT_ABI; |
|
20290
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
1409 |
|
19951 | 1410 |
#endif |
20290
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
1411 |
|
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
1412 |
int __numFloatOrDoubleArgs = 0; |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1413 |
|
9342 | 1414 |
union u { |
20309 | 1415 |
INT iVal; |
1416 |
float fVal; |
|
1417 |
double dVal; |
|
1418 |
void *pointerVal; |
|
19365
83a120bf2212
Fix syntax error bug with gcc32
Stefan Vogel <sv@exept.de>
parents:
19364
diff
changeset
|
1419 |
# if 0 && defined(HAS_LONGLONG) |
20309 | 1420 |
long long longLongVal; |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1421 |
# else |
20309 | 1422 |
__int64__ longLongVal; |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1423 |
# endif |
9342 | 1424 |
}; |
1425 |
union u __argValuesIncludingThis[MAX_ARGS+1]; |
|
1426 |
union u *__argValues = __argValuesIncludingThis; |
|
1427 |
union u __returnValue; |
|
1428 |
void *__argValuePointersIncludingThis[MAX_ARGS+1]; |
|
1429 |
void **__argValuePointers = __argValuePointersIncludingThis; |
|
1430 |
void *__returnValuePointer; |
|
1431 |
int __numArgs, __numArgsIncludingThis; |
|
19311 | 1432 |
static INT null = 0; |
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1433 |
int i = -1; |
20307 | 1434 |
voidFUNC codeAddress = (voidFUNC)__INST(code_); |
10440 | 1435 |
int __numArgsWanted; |
12579
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
1436 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1437 |
# define __FAIL__(fcode) \ |
10603 | 1438 |
{ \ |
20309 | 1439 |
failureCode = fcode; failureArgNr = __mkSmallInteger(i+1); goto getOutOfHere; \ |
10603 | 1440 |
} |
9342 | 1441 |
|
10440 | 1442 |
if (argumentsOrNil == nil) { |
20309 | 1443 |
__numArgs = 0; |
21402 | 1444 |
} else if (__isArrayLike(argumentsOrNil)) { |
20309 | 1445 |
__numArgs = __arraySize(argumentsOrNil); |
9342 | 1446 |
} else { |
20309 | 1447 |
__FAIL__(@symbol(BadArgumentVector)) |
10440 | 1448 |
} |
1449 |
if (argTypeSymbols == nil) { |
|
20309 | 1450 |
__numArgsWanted = 0; |
21402 | 1451 |
} else if (__isArrayLike(argTypeSymbols)) { |
20309 | 1452 |
__numArgsWanted = __arraySize(argTypeSymbols); |
10440 | 1453 |
} else { |
20309 | 1454 |
__FAIL__(@symbol(BadArgumentTypeVector)) |
10440 | 1455 |
} |
1456 |
||
1457 |
if (__numArgs != __numArgsWanted) { |
|
20309 | 1458 |
__FAIL__(@symbol(ArgumentCountMismatch)) |
9342 | 1459 |
} |
1460 |
if (__numArgs > MAX_ARGS) { |
|
20309 | 1461 |
__FAIL__(@symbol(TooManyArguments)) |
9342 | 1462 |
} |
1463 |
||
1464 |
/* |
|
19501 | 1465 |
* validate the return type and map it to an ffi_type |
9342 | 1466 |
*/ |
1467 |
__returnValuePointer = &__returnValue; |
|
9479 | 1468 |
|
9483 | 1469 |
if (returnTypeSymbol == @symbol(voidPointer)) { |
20309 | 1470 |
returnTypeSymbol = @symbol(handle); |
19501 | 1471 |
} else if (returnTypeSymbol == @symbol(hresult)) { |
20309 | 1472 |
returnTypeSymbol = @symbol(uint32); |
9483 | 1473 |
} |
9479 | 1474 |
|
9342 | 1475 |
if (returnTypeSymbol == @symbol(int)) { |
20309 | 1476 |
__returnType = TYPE_SINT; |
9342 | 1477 |
} else if (returnTypeSymbol == @symbol(uint)) { |
20309 | 1478 |
__returnType = TYPE_UINT; |
9479 | 1479 |
} else if (returnTypeSymbol == @symbol(uint8)) { |
20309 | 1480 |
__returnType = TYPE_UINT8; |
9479 | 1481 |
} else if (returnTypeSymbol == @symbol(uint16)) { |
20309 | 1482 |
__returnType = TYPE_UINT16; |
9479 | 1483 |
} else if (returnTypeSymbol == @symbol(uint32)) { |
20309 | 1484 |
__returnType = TYPE_UINT32; |
9479 | 1485 |
} else if (returnTypeSymbol == @symbol(uint64)) { |
20309 | 1486 |
__returnType = TYPE_UINT64; |
9479 | 1487 |
|
1488 |
} else if (returnTypeSymbol == @symbol(sint)) { |
|
20309 | 1489 |
__returnType = TYPE_SINT; |
9479 | 1490 |
} else if (returnTypeSymbol == @symbol(sint8)) { |
20309 | 1491 |
__returnType = TYPE_SINT8; |
9479 | 1492 |
} else if (returnTypeSymbol == @symbol(sint16)) { |
20309 | 1493 |
__returnType = TYPE_SINT16; |
9479 | 1494 |
} else if (returnTypeSymbol == @symbol(sint32)) { |
20309 | 1495 |
__returnType = TYPE_SINT32; |
9479 | 1496 |
} else if (returnTypeSymbol == @symbol(sint64)) { |
20309 | 1497 |
__returnType = TYPE_SINT64; |
9479 | 1498 |
|
9342 | 1499 |
} else if (returnTypeSymbol == @symbol(long)) { |
20309 | 1500 |
if (sizeof(long) == 4) { |
1501 |
returnTypeSymbol = @symbol(sint32); |
|
1502 |
__returnType = TYPE_SINT32; |
|
1503 |
} else if (sizeof(long) == 8) { |
|
1504 |
returnTypeSymbol = @symbol(sint64); |
|
1505 |
__returnType = TYPE_SINT64; |
|
1506 |
} else { |
|
1507 |
__FAIL__(@symbol(UnknownReturnType)) |
|
1508 |
} |
|
9479 | 1509 |
|
9342 | 1510 |
} else if (returnTypeSymbol == @symbol(ulong)) { |
20309 | 1511 |
if (sizeof(long) == 4) { |
1512 |
returnTypeSymbol = @symbol(uint32); |
|
1513 |
__returnType = TYPE_UINT32; |
|
1514 |
}else if (sizeof(long) == 8) { |
|
1515 |
returnTypeSymbol = @symbol(uint64); |
|
1516 |
__returnType = TYPE_UINT64; |
|
1517 |
} else { |
|
1518 |
__FAIL__(@symbol(UnknownReturnType)) |
|
1519 |
} |
|
9479 | 1520 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1521 |
} else if (returnTypeSymbol == @symbol(bool)) { |
20309 | 1522 |
__returnType = TYPE_UINT; |
9479 | 1523 |
|
9342 | 1524 |
} else if (returnTypeSymbol == @symbol(float)) { |
20309 | 1525 |
__returnType = TYPE_FLOAT; |
9342 | 1526 |
} else if (returnTypeSymbol == @symbol(double)) { |
20309 | 1527 |
__returnType = TYPE_DOUBLE; |
9479 | 1528 |
|
9342 | 1529 |
} else if (returnTypeSymbol == @symbol(void)) { |
20309 | 1530 |
__returnType = TYPE_VOID; |
1531 |
__returnValuePointer = NULL; |
|
11586 | 1532 |
} else if ((returnTypeSymbol == @symbol(pointer)) |
20309 | 1533 |
|| (returnTypeSymbol == @symbol(handle)) |
1534 |
|| (returnTypeSymbol == @symbol(charPointer)) |
|
1535 |
|| (returnTypeSymbol == @symbol(bytePointer)) |
|
1536 |
|| (returnTypeSymbol == @symbol(floatPointer)) |
|
1537 |
|| (returnTypeSymbol == @symbol(doublePointer)) |
|
1538 |
|| (returnTypeSymbol == @symbol(intPointer)) |
|
1539 |
|| (returnTypeSymbol == @symbol(shortPointer)) |
|
1540 |
|| (returnTypeSymbol == @symbol(wcharPointer))) { |
|
1541 |
__returnType = TYPE_POINTER; |
|
9342 | 1542 |
} else { |
20309 | 1543 |
if (__isSymbol(returnTypeSymbol) |
1544 |
&& ((returnValueClass = __GLOBAL_GET(returnTypeSymbol)) != nil)) { |
|
1545 |
if (! __isBehaviorLike(returnValueClass)) { |
|
1546 |
__FAIL__(@symbol(NonBehaviorReturnType)) |
|
1547 |
} |
|
1548 |
if (! __qIsSubclassOfExternalAddress(returnValueClass)) { |
|
1549 |
__FAIL__(@symbol(NonExternalAddressReturnType)) |
|
1550 |
} |
|
1551 |
__returnType = TYPE_POINTER; |
|
1552 |
returnTypeSymbol = @symbol(pointer); |
|
1553 |
} else { |
|
1554 |
__FAIL__(@symbol(UnknownReturnType)) |
|
1555 |
} |
|
9342 | 1556 |
} |
1557 |
||
1558 |
/* |
|
1559 |
* validate the c++ object |
|
1560 |
*/ |
|
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1561 |
if (aReceiverOrNil != nil) { |
20309 | 1562 |
struct cPlusPlusInstance { |
1563 |
void **vTable; |
|
1564 |
}; |
|
1565 |
struct cPlusPlusInstance *inst; |
|
9342 | 1566 |
|
20309 | 1567 |
if (__isExternalAddressLike(aReceiverOrNil)) { |
1568 |
inst = (void *)(__externalAddressVal(aReceiverOrNil)); |
|
1569 |
} else if (__isExternalBytesLike(aReceiverOrNil)) { |
|
1570 |
inst = (void *)(__externalBytesVal(aReceiverOrNil)); |
|
1571 |
} else { |
|
1572 |
__FAIL__(@symbol(InvalidInstance)) |
|
1573 |
} |
|
1574 |
__argValues[0].pointerVal = inst; |
|
1575 |
__argValuePointersIncludingThis[0] = &(__argValues[0]); |
|
1576 |
__argTypes[0] = TYPE_POINTER; |
|
9342 | 1577 |
|
20309 | 1578 |
__argValuePointers = &__argValuePointersIncludingThis[1]; |
1579 |
__argTypes = &__argTypesIncludingThis[1]; |
|
1580 |
__argValues = &__argValuesIncludingThis[1]; |
|
1581 |
__numArgsIncludingThis = __numArgs + 1; |
|
9347 | 1582 |
|
20309 | 1583 |
if (virtual == true) { |
1584 |
if (! __isSmallInteger(vtOffset)) { |
|
1585 |
__FAIL__(@symbol(InvalidVTableIndex)) |
|
1586 |
} |
|
1587 |
codeAddress = inst->vTable[__intVal(vtOffset)]; |
|
1588 |
DEBUGCODE_IF( @global(Verbose), { |
|
1589 |
printf("virtual %"_ld_" codeAddress: %"_lx_"\n", (INT)(__intVal(vtOffset)), (INT)codeAddress); |
|
1590 |
}) |
|
1591 |
} |
|
9342 | 1592 |
} else { |
20309 | 1593 |
__numArgsIncludingThis = __numArgs; |
1594 |
DEBUGCODE_IF( @global(Verbose), { |
|
1595 |
printf("codeAddress: %"_lx_"\n", (INT)codeAddress); |
|
1596 |
}) |
|
9342 | 1597 |
} |
1598 |
||
1599 |
/* |
|
19501 | 1600 |
* validate all arg types, map each to an ffi_type, and setup arg-buffers |
9342 | 1601 |
*/ |
1602 |
for (i=0; i<__numArgs; i++) { |
|
20309 | 1603 |
void *argValuePtr; |
1604 |
OBJ typeSymbol; |
|
1605 |
OBJ arg; |
|
9342 | 1606 |
|
20309 | 1607 |
failureInfo = __mkSmallInteger(i+1); /* in case there is one */ |
9465 | 1608 |
|
20309 | 1609 |
typeSymbol = __ArrayInstPtr(argTypeSymbols)->a_element[i]; |
1610 |
arg = __ArrayInstPtr(argumentsOrNil)->a_element[i]; |
|
9342 | 1611 |
|
20309 | 1612 |
if (typeSymbol == @symbol(handle)) { |
1613 |
typeSymbol = @symbol(pointer); |
|
1614 |
} else if (typeSymbol == @symbol(voidPointer)) { |
|
1615 |
typeSymbol = @symbol(pointer); |
|
1616 |
} else if (returnTypeSymbol == @symbol(hresult)) { |
|
1617 |
typeSymbol = @symbol(uint32); |
|
1618 |
} |
|
9479 | 1619 |
|
20309 | 1620 |
if (typeSymbol == @symbol(long)) { |
1621 |
if (sizeof(long) == sizeof(int)) { |
|
1622 |
typeSymbol = @symbol(sint); |
|
1623 |
} else { |
|
1624 |
if (sizeof(long) == 4) { |
|
1625 |
typeSymbol = @symbol(sint32); |
|
1626 |
} else if (sizeof(long) == 8) { |
|
1627 |
typeSymbol = @symbol(sint64); |
|
1628 |
} |
|
1629 |
} |
|
1630 |
} |
|
1631 |
if (typeSymbol == @symbol(ulong)) { |
|
1632 |
if (sizeof(unsigned long) == sizeof(unsigned int)) { |
|
1633 |
typeSymbol = @symbol(uint); |
|
1634 |
} else { |
|
1635 |
if (sizeof(long) == 4) { |
|
1636 |
typeSymbol = @symbol(uint32); |
|
1637 |
} else if (sizeof(long) == 8) { |
|
1638 |
typeSymbol = @symbol(uint64); |
|
1639 |
} |
|
1640 |
} |
|
1641 |
} |
|
9342 | 1642 |
|
20309 | 1643 |
if (typeSymbol == @symbol(int) || typeSymbol == @symbol(sint)) { |
1644 |
thisType = TYPE_SINT; |
|
1645 |
if (__isSmallInteger(arg)) { |
|
1646 |
__argValues[i].iVal = __intVal(arg); |
|
1647 |
} else { |
|
1648 |
__argValues[i].iVal = __signedLongIntVal(arg); |
|
1649 |
if (__argValues[i].iVal == 0) { |
|
1650 |
DEBUGCODE_IF( @global(Verbose), { |
|
1651 |
printf("invalidArgument: arg%d sint value out of range [%d]\n", i+1, __LINE__); |
|
1652 |
}) |
|
1653 |
__FAIL__(@symbol(InvalidArgument)) |
|
1654 |
} |
|
1655 |
} |
|
1656 |
argValuePtr = &(__argValues[i].iVal); |
|
9479 | 1657 |
|
20309 | 1658 |
} else if (typeSymbol == @symbol(uint)) { |
1659 |
thisType = TYPE_UINT; |
|
9342 | 1660 |
|
20309 | 1661 |
if (__isSmallInteger(arg)) { |
1662 |
__argValues[i].iVal = __intVal(arg); |
|
1663 |
} else { |
|
1664 |
__argValues[i].iVal = __unsignedLongIntVal(arg); |
|
1665 |
if (__argValues[i].iVal == 0) { |
|
1666 |
DEBUGCODE_IF( @global(Verbose), { |
|
1667 |
printf("invalidArgument: arg%d uint value out of range [%d]\n", i+1, __LINE__); |
|
1668 |
}) |
|
1669 |
__FAIL__(@symbol(InvalidArgument)) |
|
1670 |
} |
|
1671 |
} |
|
1672 |
argValuePtr = &(__argValues[i].iVal); |
|
9479 | 1673 |
|
20309 | 1674 |
} else if (typeSymbol == @symbol(uint8)) { |
1675 |
thisType = TYPE_UINT8; |
|
1676 |
if (! __isSmallInteger(arg)) { |
|
1677 |
DEBUGCODE_IF( @global(Verbose), { |
|
1678 |
printf("invalidArgument: arg%d uint8 value out of range [%d]\n", i+1, __LINE__); |
|
1679 |
}) |
|
1680 |
__FAIL__(@symbol(InvalidArgument)) |
|
1681 |
} |
|
1682 |
__argValues[i].iVal = __intVal(arg); |
|
1683 |
if (((unsigned)(__argValues[i].iVal)) > 0xFF) { |
|
1684 |
DEBUGCODE_IF( @global(Verbose), { |
|
1685 |
printf("invalidArgument: arg%d uint8 value out of range [%d]\n", i+1, __LINE__); |
|
1686 |
}) |
|
1687 |
__FAIL__(@symbol(InvalidArgument)) |
|
1688 |
} |
|
1689 |
argValuePtr = &(__argValues[i].iVal); |
|
9479 | 1690 |
|
20309 | 1691 |
} else if (typeSymbol == @symbol(sint8)) { |
1692 |
thisType = TYPE_SINT8; |
|
1693 |
if (! __isSmallInteger(arg)) { |
|
1694 |
DEBUGCODE_IF( @global(Verbose), { |
|
1695 |
printf("invalidArgument: arg%d sint8 value out of range [%d]\n", i+1, __LINE__); |
|
1696 |
}) |
|
1697 |
__FAIL__(@symbol(InvalidArgument)) |
|
1698 |
} |
|
1699 |
__argValues[i].iVal = __intVal(arg); |
|
1700 |
if (((__argValues[i].iVal) < -0x80) || ((__argValues[i].iVal) > 0x7F)) { |
|
1701 |
DEBUGCODE_IF( @global(Verbose), { |
|
1702 |
printf("invalidArgument: arg%d sint8 value out of range [%d]\n", i+1, __LINE__); |
|
1703 |
}) |
|
1704 |
__FAIL__(@symbol(InvalidArgument)) |
|
1705 |
} |
|
1706 |
argValuePtr = &(__argValues[i].iVal); |
|
9479 | 1707 |
|
20309 | 1708 |
} else if (typeSymbol == @symbol(uint16)) { |
1709 |
thisType = TYPE_UINT16; |
|
1710 |
if (! __isSmallInteger(arg)) { |
|
1711 |
DEBUGCODE_IF( @global(Verbose), { |
|
1712 |
printf("invalidArgument: arg%d uint16 value out of range [%d]\n", i+1, __LINE__); |
|
1713 |
}) |
|
1714 |
__FAIL__(@symbol(InvalidArgument)) |
|
1715 |
} |
|
1716 |
__argValues[i].iVal = __intVal(arg); |
|
1717 |
if (((unsigned)(__argValues[i].iVal)) > 0xFFFF) { |
|
1718 |
DEBUGCODE_IF( @global(Verbose), { |
|
1719 |
printf("invalidArgument: arg%d uint16 value out of range [%d]\n", i+1, __LINE__); |
|
1720 |
}) |
|
1721 |
__FAIL__(@symbol(InvalidArgument)) |
|
1722 |
} |
|
1723 |
argValuePtr = &(__argValues[i].iVal); |
|
9479 | 1724 |
|
20309 | 1725 |
} else if (typeSymbol == @symbol(sint16)) { |
1726 |
thisType = TYPE_SINT16; |
|
1727 |
if (! __isSmallInteger(arg)) { |
|
1728 |
DEBUGCODE_IF( @global(Verbose), { |
|
1729 |
printf("invalidArgument: arg%d sint16 value out of range [%d]\n", i+1, __LINE__); |
|
1730 |
}) |
|
1731 |
__FAIL__(@symbol(InvalidArgument)) |
|
1732 |
} |
|
1733 |
__argValues[i].iVal = __intVal(arg); |
|
1734 |
if (((__argValues[i].iVal) < -0x8000) || ((__argValues[i].iVal) > 0x7FFF)) { |
|
1735 |
DEBUGCODE_IF( @global(Verbose), { |
|
1736 |
printf("invalidArgument: arg%d sint16 value out of range [%d]\n", i+1, __LINE__); |
|
1737 |
}) |
|
1738 |
__FAIL__(@symbol(InvalidArgument)) |
|
1739 |
} |
|
1740 |
argValuePtr = &(__argValues[i].iVal); |
|
9479 | 1741 |
|
20309 | 1742 |
} else if (typeSymbol == @symbol(uint32)) { |
1743 |
thisType = TYPE_UINT32; |
|
1744 |
if (__isSmallInteger(arg)) { |
|
1745 |
__argValues[i].iVal = __intVal(arg); |
|
1746 |
} else { |
|
1747 |
__argValues[i].iVal = __unsignedLongIntVal(arg); |
|
1748 |
if (__argValues[i].iVal == 0) { |
|
1749 |
DEBUGCODE_IF( @global(Verbose), { |
|
1750 |
printf("invalidArgument: arg%d uint32 value out of range [%d]\n", i+1, __LINE__); |
|
1751 |
}) |
|
1752 |
__FAIL__(@symbol(InvalidArgument)) |
|
1753 |
} |
|
1754 |
} |
|
19334 | 1755 |
# if __POINTER_SIZE__ == 8 |
20309 | 1756 |
if ((__argValues[i].iVal) < 0) { |
1757 |
DEBUGCODE_IF( @global(Verbose), { |
|
1758 |
printf("invalidArgument: arg%d uint32 value out of range [%d]\n", i+1, __LINE__); |
|
1759 |
}) |
|
1760 |
__FAIL__(@symbol(InvalidArgument)) |
|
1761 |
} |
|
19334 | 1762 |
# endif |
20309 | 1763 |
argValuePtr = &(__argValues[i].iVal); |
19334 | 1764 |
|
20309 | 1765 |
} else if (typeSymbol == @symbol(sint32)) { |
1766 |
thisType = TYPE_SINT32; |
|
1767 |
if (__isSmallInteger(arg)) { |
|
1768 |
__argValues[i].iVal = __intVal(arg); |
|
1769 |
} else { |
|
1770 |
__argValues[i].iVal = __signedLongIntVal(arg); |
|
1771 |
if (__argValues[i].iVal == 0) { |
|
1772 |
DEBUGCODE_IF( @global(Verbose), { |
|
1773 |
printf("invalidArgument: arg%d sint32 value out of range [%d]\n", i+1, __LINE__); |
|
1774 |
}) |
|
1775 |
__FAIL__(@symbol(InvalidArgument)) |
|
1776 |
} |
|
1777 |
} |
|
19334 | 1778 |
# if __POINTER_SIZE__ == 8 |
20309 | 1779 |
if (((__argValues[i].iVal) < -0x80000000LL) || ((__argValues[i].iVal) > 0x7FFFFFFFLL)) { |
1780 |
DEBUGCODE_IF( @global(Verbose), { |
|
1781 |
printf("invalidArgument: arg%d sint32 value (%"_lx_") out of range [%d]\n", i+1, __argValues[i].iVal, __LINE__); |
|
1782 |
}) |
|
1783 |
__FAIL__(@symbol(InvalidArgument)) |
|
1784 |
} |
|
19334 | 1785 |
# endif |
20309 | 1786 |
argValuePtr = &(__argValues[i].iVal); |
19334 | 1787 |
|
20309 | 1788 |
} else if (typeSymbol == @symbol(uint64)) { |
1789 |
thisType = TYPE_UINT64; |
|
1790 |
if (__isSmallInteger(arg)) { |
|
1791 |
__argValues[i].iVal = __intVal(arg); |
|
1792 |
} else { |
|
1793 |
__argValues[i].iVal = __unsignedLongIntVal(arg); |
|
1794 |
if (__argValues[i].iVal == 0) { |
|
1795 |
DEBUGCODE_IF( @global(Verbose), { |
|
1796 |
printf("invalidArgument: arg%d uint64 value out of range [%d]\n", i+1, __LINE__); |
|
1797 |
}) |
|
1798 |
__FAIL__(@symbol(InvalidArgument)) |
|
1799 |
} |
|
1800 |
} |
|
1801 |
argValuePtr = &(__argValues[i].iVal); |
|
19334 | 1802 |
|
20309 | 1803 |
} else if (typeSymbol == @symbol(sint64)) { |
1804 |
thisType = TYPE_SINT64; |
|
1805 |
if (__isSmallInteger(arg)) { |
|
1806 |
__argValues[i].iVal = __intVal(arg); |
|
1807 |
} else { |
|
1808 |
__argValues[i].iVal = __signedLongIntVal(arg); |
|
1809 |
if (__argValues[i].iVal == 0) { |
|
1810 |
DEBUGCODE_IF( @global(Verbose), { |
|
1811 |
printf("invalidArgument: arg%d sint64 value out of range [%d]\n", i+1, __LINE__); |
|
1812 |
}) |
|
1813 |
__FAIL__(@symbol(InvalidArgument)) |
|
1814 |
} |
|
1815 |
} |
|
1816 |
argValuePtr = &(__argValues[i].iVal); |
|
9479 | 1817 |
|
20309 | 1818 |
} else if (typeSymbol == @symbol(float)) { |
1819 |
thisType = TYPE_FLOAT; |
|
1820 |
if (__isSmallInteger(arg)) { |
|
1821 |
__argValues[i].fVal = (float)(__intVal(arg)); |
|
1822 |
} else if (__isFloat(arg)) { |
|
1823 |
__argValues[i].fVal = (float)(__floatVal(arg)); |
|
1824 |
} else if (__isShortFloat(arg)) { |
|
1825 |
__argValues[i].fVal = (float)(__shortFloatVal(arg)); |
|
1826 |
} else { |
|
1827 |
DEBUGCODE_IF( @global(Verbose), { |
|
1828 |
printf("invalidArgument: arg%d non float value [%d]\n", i+1, __LINE__); |
|
1829 |
}) |
|
1830 |
__FAIL__(@symbol(InvalidArgument)) |
|
1831 |
} |
|
1832 |
argValuePtr = &(__argValues[i].fVal); |
|
1833 |
} else if (typeSymbol == @symbol(double)) { |
|
1834 |
thisType = TYPE_DOUBLE; |
|
1835 |
if (__isSmallInteger(arg)) { |
|
1836 |
__argValues[i].dVal = (double)(__intVal(arg)); |
|
1837 |
} else if (__isFloat(arg)) { |
|
1838 |
__argValues[i].dVal = (double)(__floatVal(arg)); |
|
1839 |
} else if (__isShortFloat(arg)) { |
|
1840 |
__argValues[i].dVal = (double)(__shortFloatVal(arg)); |
|
1841 |
} else { |
|
1842 |
DEBUGCODE_IF( @global(Verbose), { |
|
1843 |
printf("invalidArgument: arg%d non double value [%d]\n", i+1, __LINE__); |
|
1844 |
}) |
|
1845 |
__FAIL__(@symbol(InvalidArgument)) |
|
1846 |
} |
|
1847 |
argValuePtr = &(__argValues[i].dVal); |
|
9479 | 1848 |
|
20309 | 1849 |
} else if (typeSymbol == @symbol(void)) { |
1850 |
thisType = TYPE_VOID; |
|
1851 |
argValuePtr = &null; |
|
9479 | 1852 |
|
20309 | 1853 |
} else if (typeSymbol == @symbol(charPointer)) { |
1854 |
thisType = TYPE_POINTER; |
|
1855 |
if (__isStringLike(arg)) { |
|
1856 |
if (async == true) goto badArgForAsyncCall; |
|
1857 |
__argValues[i].pointerVal = (void *)(__stringVal(arg)); |
|
1858 |
} else if (__isBytes(arg)) { |
|
1859 |
if (async == true) goto badArgForAsyncCall; |
|
1860 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
|
1861 |
} else if (__isExternalAddressLike(arg)) { |
|
1862 |
__argValues[i].pointerVal = (void *)(__externalAddressVal(arg)); |
|
1863 |
} else if (__isExternalBytesLike(arg)) { |
|
1864 |
__argValues[i].pointerVal = (void *)(__externalBytesVal(arg)); |
|
1865 |
} else { |
|
1866 |
if (arg == nil) { |
|
1867 |
__argValues[i].pointerVal = (void *)0; |
|
1868 |
} else { |
|
1869 |
DEBUGCODE_IF( @global(Verbose), { |
|
1870 |
printf("invalidArgument: arg%d non charPointer value [%d]\n", i+1, __LINE__); |
|
1871 |
}) |
|
1872 |
__FAIL__(@symbol(InvalidArgument)) |
|
1873 |
} |
|
1874 |
} |
|
1875 |
argValuePtr = &(__argValues[i].pointerVal);; |
|
10603 | 1876 |
|
20309 | 1877 |
} else if (typeSymbol == @symbol(wcharPointer)) { |
1878 |
thisType = TYPE_POINTER; |
|
1879 |
if (__isUnicode16String(arg)) { |
|
1880 |
if (async == true) goto badArgForAsyncCall; |
|
1881 |
__argValues[i].pointerVal = (void *)(__unicode16StringVal(arg)); |
|
1882 |
} else if (__isBytes(arg)) { |
|
1883 |
if (async == true) goto badArgForAsyncCall; |
|
1884 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
|
1885 |
} else if (__isExternalAddressLike(arg)) { |
|
1886 |
__argValues[i].pointerVal = (void *)(__externalAddressVal(arg)); |
|
1887 |
} else if (__isExternalBytesLike(arg)) { |
|
1888 |
__argValues[i].pointerVal = (void *)(__externalBytesVal(arg)); |
|
1889 |
} else { |
|
1890 |
if (arg == nil) { |
|
1891 |
__argValues[i].pointerVal = (void *)0; |
|
1892 |
} else { |
|
1893 |
DEBUGCODE_IF( @global(Verbose), { |
|
1894 |
printf("invalidArgument: arg%d non wcharPointer value [%d]\n", i+1, __LINE__); |
|
1895 |
}) |
|
1896 |
__FAIL__(@symbol(InvalidArgument)) |
|
1897 |
} |
|
1898 |
} |
|
1899 |
argValuePtr = &(__argValues[i].pointerVal);; |
|
12656 | 1900 |
|
20309 | 1901 |
} else if (typeSymbol == @symbol(floatPointer)) { |
1902 |
thisType = TYPE_POINTER; |
|
1903 |
if (__isBytes(arg)) { |
|
1904 |
if (async == true) goto badArgForAsyncCall; |
|
1905 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
|
1906 |
} else if (__isExternalAddressLike(arg)) { |
|
1907 |
__argValues[i].pointerVal = (void *)(__externalAddressVal(arg)); |
|
1908 |
} else if (__isExternalBytesLike(arg)) { |
|
1909 |
__argValues[i].pointerVal = (void *)(__externalBytesVal(arg)); |
|
1910 |
} else if (__isFloats(arg)) { |
|
1911 |
char *p = (char *)(__FloatArrayInstPtr(arg)->f_element); |
|
1912 |
int nInstBytes; |
|
1913 |
OBJ cls; |
|
10603 | 1914 |
|
20309 | 1915 |
if (async == true) goto badArgForAsyncCall; |
1916 |
cls = __qClass(arg); |
|
1917 |
nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1918 |
p = p + nInstBytes; |
|
1919 |
__argValues[i].pointerVal = p; |
|
1920 |
} else { |
|
1921 |
if (arg == nil) { |
|
1922 |
__argValues[i].pointerVal = (void *)0; |
|
1923 |
} else { |
|
1924 |
DEBUGCODE_IF( @global(Verbose), { |
|
1925 |
printf("invalidArgument: arg%d non floatPointer value [%d]\n", i+1, __LINE__); |
|
1926 |
}) |
|
1927 |
__FAIL__(@symbol(InvalidArgument)) |
|
1928 |
} |
|
1929 |
} |
|
1930 |
argValuePtr = &(__argValues[i].pointerVal);; |
|
10603 | 1931 |
|
20309 | 1932 |
} else if (typeSymbol == @symbol(doublePointer)) { |
1933 |
thisType = TYPE_POINTER; |
|
1934 |
if (__isBytes(arg)) { |
|
1935 |
if (async == true) goto badArgForAsyncCall; |
|
1936 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
|
1937 |
} else if (__isExternalAddressLike(arg)) { |
|
1938 |
__argValues[i].pointerVal = (void *)(__externalAddressVal(arg)); |
|
1939 |
} else if (__isExternalBytesLike(arg)) { |
|
1940 |
__argValues[i].pointerVal = (void *)(__externalBytesVal(arg)); |
|
1941 |
} else if (__isDoubles(arg)) { |
|
1942 |
char *p = (char *)(__DoubleArrayInstPtr(arg)->d_element); |
|
1943 |
int nInstBytes; |
|
1944 |
OBJ cls; |
|
10603 | 1945 |
|
20309 | 1946 |
if (async == true) goto badArgForAsyncCall; |
1947 |
cls = __qClass(arg); |
|
1948 |
nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1949 |
p = p + nInstBytes; |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1950 |
# ifdef __NEED_DOUBLE_ALIGN |
20309 | 1951 |
if ((INT)(__DoubleArrayInstPtr(arg)->d_element) & (__DOUBLE_ALIGN-1)) { |
1952 |
int delta = __DOUBLE_ALIGN - ((INT)p & (__DOUBLE_ALIGN-1)); |
|
10603 | 1953 |
|
20309 | 1954 |
p += delta; |
1955 |
} |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1956 |
# endif |
20309 | 1957 |
__argValues[i].pointerVal = p; |
1958 |
} else { |
|
1959 |
if (arg == nil) { |
|
1960 |
__argValues[i].pointerVal = (void *)0; |
|
1961 |
} else { |
|
1962 |
DEBUGCODE_IF( @global(Verbose), { |
|
1963 |
printf("invalidArgument: arg%d non doublePointer value [%d]\n", i+1, __LINE__); |
|
1964 |
}) |
|
1965 |
__FAIL__(@symbol(InvalidArgument)) |
|
1966 |
} |
|
1967 |
} |
|
1968 |
argValuePtr = &(__argValues[i].pointerVal);; |
|
9479 | 1969 |
|
20309 | 1970 |
} else if (typeSymbol == @symbol(pointer)) { |
20290
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
1971 |
commonPointerTypeArg: ; |
20309 | 1972 |
thisType = TYPE_POINTER; |
1973 |
if (arg == nil) { |
|
1974 |
__argValues[i].pointerVal = NULL; |
|
1975 |
} else if (__isExternalAddressLike(arg)) { |
|
1976 |
__argValues[i].pointerVal = (void *)(__externalAddressVal(arg)); |
|
1977 |
} else if (__isExternalBytesLike(arg)) { |
|
1978 |
__argValues[i].pointerVal = (void *)(__externalBytesVal(arg)); |
|
1979 |
} else if (__isByteArrayLike(arg)) { |
|
1980 |
if (async == true) goto badArgForAsyncCall; |
|
1981 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
|
1982 |
} else if (__isWordArray(arg) || __isSignedWordArray(arg) |
|
1983 |
|| __isIntegerArray(arg) || __isSignedIntegerArray(arg)) { |
|
1984 |
if (async == true) goto badArgForAsyncCall; |
|
1985 |
__argValues[i].pointerVal = (void *)(__integerArrayVal(arg)); |
|
1986 |
} else if (__isFloatArray(arg)) { |
|
1987 |
if (async == true) goto badArgForAsyncCall; |
|
1988 |
__argValues[i].pointerVal = (void *)(__FloatArrayInstPtr(arg)->f_element); |
|
1989 |
} else if (__isDoubleArray(arg)) { |
|
1990 |
if (async == true) goto badArgForAsyncCall; |
|
1991 |
__argValues[i].pointerVal = (void *)(__DoubleArrayInstPtr(arg)->d_element); |
|
1992 |
} else if (__isStringLike(arg)) { |
|
1993 |
if (async == true) { |
|
9435 | 1994 |
badArgForAsyncCall: ; |
20309 | 1995 |
DEBUGCODE_IF( @global(Verbose), { |
1996 |
printf("invalidArgument: arg%d not allowed for async call [%d]\n", i+1, __LINE__); |
|
1997 |
}) |
|
1998 |
__FAIL__(@symbol(BadArgForAsyncCall)) |
|
1999 |
} |
|
2000 |
__argValues[i].pointerVal = (void *)(__stringVal(arg)); |
|
2001 |
} else if (__isBytes(arg) || __isWords(arg) || __isLongs(arg)) { |
|
2002 |
char *p = (char *)(__byteArrayVal(arg)); |
|
2003 |
int nInstBytes; |
|
2004 |
OBJ cls; |
|
9483 | 2005 |
|
20309 | 2006 |
if (async == true) goto badArgForAsyncCall; |
2007 |
cls = __qClass(arg); |
|
2008 |
nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
2009 |
__argValues[i].pointerVal = p + nInstBytes; |
|
2010 |
} else { |
|
2011 |
DEBUGCODE_IF( @global(Verbose), { |
|
2012 |
printf("invalidArgument: arg%d non pointer value [%d]\n", i+1, __LINE__); |
|
2013 |
}) |
|
2014 |
__FAIL__(@symbol(InvalidArgument)) |
|
2015 |
} |
|
2016 |
argValuePtr = &(__argValues[i].pointerVal);; |
|
9479 | 2017 |
|
20309 | 2018 |
} else if (typeSymbol == @symbol(bool)) { |
2019 |
thisType = TYPE_UINT; |
|
9342 | 2020 |
|
20309 | 2021 |
if (arg == true) { |
2022 |
__argValues[i].iVal = 1; |
|
2023 |
} else if (arg == false) { |
|
2024 |
__argValues[i].iVal = 0; |
|
2025 |
} else if (__isSmallInteger(arg)) { |
|
2026 |
__argValues[i].iVal = __intVal(arg); |
|
2027 |
} else { |
|
2028 |
__argValues[i].iVal = __unsignedLongIntVal(arg); |
|
2029 |
if (__argValues[i].iVal == 0) { |
|
2030 |
DEBUGCODE_IF( @global(Verbose), { |
|
2031 |
printf("invalidArgument: arg%d non bool value [%d]\n", i+1, __LINE__); |
|
2032 |
}) |
|
2033 |
__FAIL__(@symbol(InvalidArgument)) |
|
2034 |
} |
|
2035 |
} |
|
2036 |
argValuePtr = &(__argValues[i].iVal); |
|
2037 |
} else { |
|
2038 |
if (__isSymbol(typeSymbol) |
|
2039 |
&& ((argValueClass = __GLOBAL_GET(typeSymbol)) != nil)) { |
|
2040 |
if (! __isBehaviorLike(argValueClass)) { |
|
2041 |
__FAIL__(@symbol(NonBehaviorArgumentType)) |
|
2042 |
} |
|
2043 |
if (! __qIsSubclassOfExternalAddress(argValueClass)) { |
|
2044 |
__FAIL__(@symbol(NonExternalAddressArgumentType)) |
|
2045 |
} |
|
2046 |
goto commonPointerTypeArg; /* sorry */ |
|
2047 |
} else { |
|
2048 |
__FAIL__(@symbol(UnknownArgumentType)) |
|
2049 |
} |
|
2050 |
} |
|
9342 | 2051 |
|
20309 | 2052 |
__argTypes[i] = thisType; |
2053 |
__argValuePointers[i] = argValuePtr; |
|
9483 | 2054 |
|
20309 | 2055 |
if ((thisType == TYPE_FLOAT) || (thisType == TYPE_DOUBLE)) { |
2056 |
__numFloatOrDoubleArgs++; |
|
2057 |
} |
|
2058 |
DEBUGCODE_IF( @global(Verbose), { |
|
2059 |
printf("arg%d: %"_lx_" type:%"_lx_"\n", i+1, (INT)(__argValues[i].iVal), (INT)thisType); |
|
2060 |
}) |
|
9342 | 2061 |
} |
9465 | 2062 |
failureInfo = nil; |
9342 | 2063 |
|
9465 | 2064 |
if (callTypeNumber == @global(CALLTYPE_API)) { |
20288
604e46cfbf18
ffi for mingw - 64-bit machine has no API_CALL
Claus Gittinger <cg@exept.de>
parents:
19951
diff
changeset
|
2065 |
# ifdef __MINGW64__ |
20309 | 2066 |
__callType = FFI_DEFAULT_ABI; |
20288
604e46cfbf18
ffi for mingw - 64-bit machine has no API_CALL
Claus Gittinger <cg@exept.de>
parents:
19951
diff
changeset
|
2067 |
# else |
20309 | 2068 |
# ifdef CALLTYPE_API |
2069 |
__callType = CALLTYPE_API; |
|
2070 |
# else |
|
2071 |
# ifdef CALLTYPE_FFI_STDCALL |
|
2072 |
__callType = CALLTYPE_FFI_STDCALL; |
|
2073 |
# else |
|
2074 |
DEBUGCODE_IF( @global(Verbose), { |
|
2075 |
printf("STDCALL\n"); |
|
2076 |
}) |
|
2077 |
failureCode = @symbol(FFICallTypeNotSupported); |
|
2078 |
goto getOutOfHere; |
|
2079 |
# endif |
|
20288
604e46cfbf18
ffi for mingw - 64-bit machine has no API_CALL
Claus Gittinger <cg@exept.de>
parents:
19951
diff
changeset
|
2080 |
# endif |
19931 | 2081 |
# endif |
9342 | 2082 |
} |
19931 | 2083 |
|
2084 |
// these calltypes are only supported on some systems; others report an error |
|
9465 | 2085 |
if (callTypeNumber == @global(CALLTYPE_V8)) { |
19931 | 2086 |
# ifdef CALLTYPE_FFI_V8 |
20309 | 2087 |
__callType = CALLTYPE_FFI_V8; |
19931 | 2088 |
# else |
20309 | 2089 |
failureCode = @symbol(FFICallTypeNotSupported); |
2090 |
goto getOutOfHere; |
|
19931 | 2091 |
# endif |
9342 | 2092 |
} |
19931 | 2093 |
|
9465 | 2094 |
if (callTypeNumber == @global(CALLTYPE_V9)) { |
19931 | 2095 |
# ifdef CALLTYPE_FFI_V9 |
20309 | 2096 |
__callType = CALLTYPE_FFI_V9; |
19931 | 2097 |
# else |
20309 | 2098 |
failureCode = @symbol(FFICallTypeNotSupported); |
2099 |
goto getOutOfHere; |
|
19931 | 2100 |
# endif |
9342 | 2101 |
} |
19931 | 2102 |
|
9465 | 2103 |
if (callTypeNumber == @global(CALLTYPE_UNIX64)) { |
19931 | 2104 |
# ifdef CALLTYPE_FFI_UNIX64 |
20309 | 2105 |
__callType = CALLTYPE_FFI_UNIX64; |
19931 | 2106 |
# else |
20309 | 2107 |
failureCode = @symbol(FFICallTypeNotSupported); |
2108 |
goto getOutOfHere; |
|
19931 | 2109 |
# endif |
9342 | 2110 |
} |
2111 |
||
19931 | 2112 |
# ifdef HAVE_FFI |
20288
604e46cfbf18
ffi for mingw - 64-bit machine has no API_CALL
Claus Gittinger <cg@exept.de>
parents:
19951
diff
changeset
|
2113 |
# ifdef VERBOSE |
604e46cfbf18
ffi for mingw - 64-bit machine has no API_CALL
Claus Gittinger <cg@exept.de>
parents:
19951
diff
changeset
|
2114 |
if (@global(Verbose) == true) { |
20309 | 2115 |
printf("prep: numargs=%d\n", __numArgsIncludingThis); |
20288
604e46cfbf18
ffi for mingw - 64-bit machine has no API_CALL
Claus Gittinger <cg@exept.de>
parents:
19951
diff
changeset
|
2116 |
} |
604e46cfbf18
ffi for mingw - 64-bit machine has no API_CALL
Claus Gittinger <cg@exept.de>
parents:
19951
diff
changeset
|
2117 |
# endif |
604e46cfbf18
ffi for mingw - 64-bit machine has no API_CALL
Claus Gittinger <cg@exept.de>
parents:
19951
diff
changeset
|
2118 |
|
9342 | 2119 |
if (ffi_prep_cif(&__cif, __callType, __numArgsIncludingThis, __returnType, __argTypesIncludingThis) != FFI_OK) { |
20309 | 2120 |
__FAIL__(@symbol(FFIPrepareFailed)) |
9342 | 2121 |
} |
9463 | 2122 |
if (async == true) { |
20309 | 2123 |
DEBUGCODE_IF( @global(Verbose), { |
2124 |
printf("async call 0x%"_lx_"\n", (INT)codeAddress); |
|
2125 |
}) |
|
19931 | 2126 |
# ifdef __win32__ |
20309 | 2127 |
__STX_C_CALL4( "ffi_call", ffi_call, &__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis); |
19931 | 2128 |
# else |
20309 | 2129 |
__BEGIN_INTERRUPTABLE__ |
2130 |
ffi_call(&__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis); |
|
2131 |
__END_INTERRUPTABLE__ |
|
19931 | 2132 |
# endif |
9435 | 2133 |
} else { |
20309 | 2134 |
if (unlimitedStack == true) { |
2135 |
DEBUGCODE_IF( @global(Verbose), { |
|
2136 |
printf("UNLIMITEDSTACKCALL call 0x%"_lx_"\n", (INT)codeAddress); |
|
2137 |
}) |
|
2138 |
__UNLIMITEDSTACKCALL4__((OBJFUNC)ffi_call, (INT)(&__cif), (INT)codeAddress, (INT)__returnValuePointer, (INT)__argValuePointersIncludingThis); |
|
2139 |
} else { |
|
2140 |
DEBUGCODE_IF( @global(Verbose), { |
|
2141 |
printf("call 0x%"_lx_"\n", (INT)codeAddress); |
|
2142 |
}) |
|
2143 |
ffi_call(&__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis); |
|
2144 |
} |
|
9435 | 2145 |
} |
19931 | 2146 |
|
2147 |
# else /* NO FFI */ |
|
2148 |
||
2149 |
// this is a fallback; simply assume that pointer and regular args |
|
2150 |
// can be passed in the same registers, and that all args are casted to the same |
|
2151 |
// (pointer-) size. |
|
2152 |
// Also, that float/doubles are passed down in regular registers, |
|
21748 | 2153 |
// and the return types float and double are handled differently from ints. |
19931 | 2154 |
// If that is not correct for your CPU/architecture, an ifndef is required here. |
20290
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
2155 |
// No longer limited to non-double args: for x86_64, sort by non-float/float args and |
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
2156 |
// pass down separately. |
19931 | 2157 |
|
2158 |
{ |
|
20309 | 2159 |
VOIDPTRFUNC fi = (VOIDPTRFUNC)codeAddress; |
2160 |
DOUBLEFUNC fd = (DOUBLEFUNC)codeAddress; |
|
2161 |
int rI[MAX_ARGS], dI[MAX_ARGS]; |
|
2162 |
int i; |
|
19931 | 2163 |
|
20309 | 2164 |
// sort the float/double args into a separate arglist and pass them AFTER the regular args. |
2165 |
// This is possible, because all doubles are passed in floating-pnt registers, |
|
2166 |
// no matter where they are in the arglist. |
|
2167 |
int argI = 0, nonDoubleI = 0, doubleI = 0; |
|
20290
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
2168 |
|
20309 | 2169 |
for (argI=0; argI<__numArgsIncludingThis; argI++) { |
20290
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
2170 |
# if defined(__x86_64__) |
20309 | 2171 |
if ((__argTypesIncludingThis[argI] == TYPE_DOUBLE) |
2172 |
|| (__argTypesIncludingThis[argI] == TYPE_FLOAT)) { |
|
2173 |
dI[doubleI++] = argI; |
|
2174 |
} else |
|
20290
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
2175 |
# endif // __x86_64__ |
20309 | 2176 |
{ |
2177 |
rI[nonDoubleI++] = argI; |
|
2178 |
} |
|
2179 |
} |
|
2180 |
for (i=doubleI; i<__numArgsIncludingThis; i++) dI[doubleI++] = 0; |
|
2181 |
for (i=nonDoubleI; i<__numArgsIncludingThis; i++) rI[nonDoubleI++] = 0; |
|
20290
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
2182 |
|
20309 | 2183 |
DEBUGCODE_IF( @global(Verbose), { |
2184 |
printf("call %p with %d args (%d regular, %d double)\n", codeAddress, __numArgsIncludingThis, |
|
2185 |
nonDoubleI, doubleI); |
|
2186 |
}) |
|
2187 |
if (doubleI == 0) { |
|
2188 |
// no double args |
|
2189 |
switch (__returnType) { |
|
2190 |
case TYPE_FLOAT: |
|
2191 |
case TYPE_DOUBLE: |
|
2192 |
DEBUGCODE_IF( @global(Verbose), { |
|
2193 |
printf("non-double arg; double retval\n"); |
|
2194 |
}) |
|
2195 |
switch (__numArgsIncludingThis) { |
|
2196 |
case 0: |
|
2197 |
__returnValue.dVal = (*fd)(); |
|
2198 |
break; |
|
2199 |
case 1: |
|
2200 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal ); |
|
2201 |
break; |
|
2202 |
case 2: |
|
2203 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal ); |
|
2204 |
break; |
|
2205 |
case 3: |
|
2206 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2207 |
__argValues[rI[2]].pointerVal ); |
|
2208 |
break; |
|
2209 |
case 4: |
|
2210 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2211 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal ); |
|
2212 |
break; |
|
2213 |
case 5: |
|
2214 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2215 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2216 |
__argValues[rI[4]].pointerVal ); |
|
2217 |
break; |
|
2218 |
case 6: |
|
2219 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2220 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2221 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal ); |
|
2222 |
break; |
|
2223 |
case 7: |
|
2224 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2225 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2226 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2227 |
__argValues[rI[6]].pointerVal ); |
|
2228 |
break; |
|
2229 |
case 8: |
|
2230 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2231 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2232 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2233 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal ); |
|
2234 |
break; |
|
2235 |
case 9: |
|
2236 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2237 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2238 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2239 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2240 |
__argValues[rI[8]].pointerVal ); |
|
2241 |
break; |
|
2242 |
case 10: |
|
2243 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2244 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2245 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2246 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2247 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal ); |
|
2248 |
break; |
|
2249 |
case 11: |
|
2250 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2251 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2252 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2253 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2254 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2255 |
__argValues[rI[10]].pointerVal ); |
|
2256 |
break; |
|
2257 |
case 12: |
|
2258 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2259 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2260 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2261 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2262 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2263 |
__argValues[rI[10]].pointerVal, __argValues[rI[11]].pointerVal ); |
|
2264 |
break; |
|
2265 |
case 13: |
|
2266 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2267 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2268 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2269 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2270 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2271 |
__argValues[rI[10]].pointerVal, __argValues[rI[11]].pointerVal, |
|
2272 |
__argValues[rI[12]].pointerVal ); |
|
2273 |
break; |
|
2274 |
case 14: |
|
2275 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2276 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2277 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2278 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2279 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2280 |
__argValues[rI[10]].pointerVal, __argValues[rI[11]].pointerVal, |
|
2281 |
__argValues[rI[12]].pointerVal, __argValues[rI[13]].pointerVal ); |
|
2282 |
break; |
|
2283 |
case 15: |
|
2284 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2285 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2286 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2287 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2288 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2289 |
__argValues[rI[10]].pointerVal, __argValues[rI[11]].pointerVal, |
|
2290 |
__argValues[rI[12]].pointerVal, __argValues[rI[13]].pointerVal, |
|
2291 |
__argValues[rI[14]].pointerVal ); |
|
2292 |
break; |
|
2293 |
default: |
|
2294 |
failureCode = @symbol(TooManyArguments); |
|
2295 |
goto getOutOfHere; |
|
2296 |
} |
|
2297 |
break; |
|
19931 | 2298 |
|
20309 | 2299 |
default: |
2300 |
DEBUGCODE_IF( @global(Verbose), { |
|
2301 |
printf("non-double arg; non-double retval\n"); |
|
2302 |
}) |
|
2303 |
switch (__numArgsIncludingThis) { |
|
2304 |
case 0: |
|
2305 |
__returnValue.pointerVal = (*fi)(); |
|
2306 |
break; |
|
2307 |
case 1: |
|
2308 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal ); |
|
2309 |
break; |
|
2310 |
case 2: |
|
2311 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal ); |
|
2312 |
break; |
|
2313 |
case 3: |
|
2314 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, __argValues[rI[2]].pointerVal ); |
|
2315 |
break; |
|
2316 |
case 4: |
|
2317 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, __argValues[rI[2]].pointerVal, |
|
2318 |
__argValues[rI[3]].pointerVal ); |
|
2319 |
break; |
|
2320 |
case 5: |
|
2321 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, __argValues[rI[2]].pointerVal, |
|
2322 |
__argValues[rI[3]].pointerVal, __argValues[rI[4]].pointerVal ); |
|
2323 |
break; |
|
2324 |
case 6: |
|
2325 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, __argValues[rI[2]].pointerVal, |
|
2326 |
__argValues[rI[3]].pointerVal, __argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal ); |
|
2327 |
break; |
|
2328 |
case 7: |
|
2329 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, __argValues[rI[2]].pointerVal, |
|
2330 |
__argValues[rI[3]].pointerVal, __argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2331 |
__argValues[rI[6]].pointerVal ); |
|
2332 |
break; |
|
2333 |
case 8: |
|
2334 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, __argValues[rI[2]].pointerVal, |
|
2335 |
__argValues[rI[3]].pointerVal, __argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2336 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal ); |
|
2337 |
break; |
|
2338 |
case 9: |
|
2339 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, __argValues[rI[2]].pointerVal, |
|
2340 |
__argValues[rI[3]].pointerVal, __argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2341 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, __argValues[rI[8]].pointerVal ); |
|
2342 |
break; |
|
2343 |
case 10: |
|
2344 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, __argValues[rI[2]].pointerVal, |
|
2345 |
__argValues[rI[3]].pointerVal, __argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2346 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, __argValues[rI[8]].pointerVal, |
|
2347 |
__argValues[rI[9]].pointerVal ); |
|
2348 |
break; |
|
2349 |
case 11: |
|
2350 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, __argValues[rI[2]].pointerVal, |
|
2351 |
__argValues[rI[3]].pointerVal, __argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2352 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, __argValues[rI[8]].pointerVal, |
|
2353 |
__argValues[rI[9]].pointerVal, __argValues[rI[10]].pointerVal ); |
|
2354 |
break; |
|
2355 |
case 12: |
|
2356 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, __argValues[rI[2]].pointerVal, |
|
2357 |
__argValues[rI[3]].pointerVal, __argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2358 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, __argValues[rI[8]].pointerVal, |
|
2359 |
__argValues[rI[9]].pointerVal, __argValues[rI[10]].pointerVal, __argValues[rI[11]].pointerVal ); |
|
2360 |
break; |
|
2361 |
case 13: |
|
2362 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, __argValues[rI[2]].pointerVal, |
|
2363 |
__argValues[rI[3]].pointerVal, __argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2364 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, __argValues[rI[8]].pointerVal, |
|
2365 |
__argValues[rI[9]].pointerVal, __argValues[rI[10]].pointerVal, __argValues[rI[11]].pointerVal, |
|
2366 |
__argValues[rI[12]].pointerVal ); |
|
2367 |
break; |
|
2368 |
case 14: |
|
2369 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, __argValues[rI[2]].pointerVal, |
|
2370 |
__argValues[rI[3]].pointerVal, __argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2371 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, __argValues[rI[8]].pointerVal, |
|
2372 |
__argValues[rI[9]].pointerVal, __argValues[rI[10]].pointerVal, __argValues[rI[11]].pointerVal, |
|
2373 |
__argValues[rI[12]].pointerVal, __argValues[rI[13]].pointerVal ); |
|
2374 |
break; |
|
2375 |
case 15: |
|
2376 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, __argValues[rI[2]].pointerVal, |
|
2377 |
__argValues[rI[3]].pointerVal, __argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2378 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, __argValues[rI[8]].pointerVal, |
|
2379 |
__argValues[rI[9]].pointerVal, __argValues[rI[10]].pointerVal, __argValues[rI[11]].pointerVal, |
|
2380 |
__argValues[rI[12]].pointerVal, __argValues[rI[13]].pointerVal, __argValues[rI[14]].pointerVal ); |
|
2381 |
break; |
|
2382 |
default: |
|
2383 |
failureCode = @symbol(TooManyArguments); |
|
2384 |
goto getOutOfHere; |
|
2385 |
} |
|
2386 |
} |
|
2387 |
} else { |
|
2388 |
// has double args |
|
2389 |
switch (__returnType) { |
|
2390 |
case TYPE_FLOAT: |
|
2391 |
case TYPE_DOUBLE: |
|
2392 |
DEBUGCODE_IF( @global(Verbose), { |
|
2393 |
printf("double arg(s); double retval\n"); |
|
2394 |
}) |
|
2395 |
switch (__numArgsIncludingThis) { |
|
2396 |
case 0: |
|
2397 |
__returnValue.dVal = (*fd)( ); |
|
2398 |
break; |
|
2399 |
case 1: |
|
2400 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, |
|
2401 |
__argValues[dI[0]].dVal ); |
|
2402 |
break; |
|
2403 |
case 2: |
|
2404 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2405 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal |
|
2406 |
); |
|
2407 |
break; |
|
2408 |
case 3: |
|
2409 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2410 |
__argValues[rI[2]].pointerVal, |
|
2411 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2412 |
__argValues[dI[2]].dVal |
|
2413 |
); |
|
2414 |
break; |
|
2415 |
case 4: |
|
2416 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2417 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2418 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2419 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal |
|
2420 |
); |
|
2421 |
break; |
|
2422 |
case 5: |
|
2423 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2424 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2425 |
__argValues[rI[4]].pointerVal, |
|
2426 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2427 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2428 |
__argValues[dI[4]].dVal |
|
2429 |
); |
|
2430 |
break; |
|
2431 |
case 6: |
|
2432 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2433 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2434 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2435 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2436 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2437 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal |
|
2438 |
); |
|
2439 |
break; |
|
2440 |
case 7: |
|
2441 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2442 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2443 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2444 |
__argValues[rI[6]].pointerVal, |
|
2445 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2446 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2447 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2448 |
__argValues[dI[6]].dVal |
|
2449 |
); |
|
2450 |
break; |
|
2451 |
case 8: |
|
2452 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2453 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2454 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2455 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2456 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2457 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2458 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2459 |
__argValues[dI[6]].dVal, __argValues[dI[7]].dVal |
|
2460 |
); |
|
2461 |
break; |
|
2462 |
case 9: |
|
2463 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2464 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2465 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2466 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2467 |
__argValues[rI[8]].pointerVal, |
|
2468 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2469 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2470 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2471 |
__argValues[dI[6]].dVal, __argValues[dI[7]].dVal, |
|
2472 |
__argValues[dI[8]].dVal |
|
2473 |
); |
|
2474 |
break; |
|
2475 |
case 10: |
|
2476 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2477 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2478 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2479 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2480 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2481 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2482 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2483 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2484 |
__argValues[dI[6]].dVal, __argValues[dI[7]].dVal, |
|
2485 |
__argValues[dI[8]].dVal, __argValues[dI[9]].dVal |
|
2486 |
); |
|
2487 |
break; |
|
2488 |
case 11: |
|
2489 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2490 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2491 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2492 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2493 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2494 |
__argValues[rI[10]].pointerVal, |
|
2495 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2496 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2497 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2498 |
__argValues[dI[6]].dVal, __argValues[dI[7]].dVal, |
|
2499 |
__argValues[dI[8]].dVal, __argValues[dI[9]].dVal, |
|
2500 |
__argValues[dI[10]].dVal |
|
2501 |
); |
|
2502 |
break; |
|
2503 |
case 12: |
|
2504 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2505 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2506 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2507 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2508 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2509 |
__argValues[rI[10]].pointerVal, __argValues[rI[11]].pointerVal, |
|
2510 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2511 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2512 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2513 |
__argValues[dI[6]].dVal, __argValues[dI[7]].dVal, |
|
2514 |
__argValues[dI[8]].dVal, __argValues[dI[9]].dVal, |
|
2515 |
__argValues[dI[10]].dVal, __argValues[dI[11]].dVal |
|
2516 |
); |
|
2517 |
break; |
|
2518 |
case 13: |
|
2519 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2520 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2521 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2522 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2523 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2524 |
__argValues[rI[10]].pointerVal, __argValues[rI[11]].pointerVal, |
|
2525 |
__argValues[rI[12]].pointerVal, |
|
2526 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2527 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2528 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2529 |
__argValues[dI[6]].dVal, __argValues[dI[7]].dVal, |
|
2530 |
__argValues[dI[8]].dVal, __argValues[dI[9]].dVal, |
|
2531 |
__argValues[dI[10]].dVal, __argValues[dI[11]].dVal, |
|
2532 |
__argValues[dI[12]].dVal |
|
2533 |
); |
|
2534 |
break; |
|
2535 |
case 14: |
|
2536 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2537 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2538 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2539 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2540 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2541 |
__argValues[rI[10]].pointerVal, __argValues[rI[11]].pointerVal, |
|
2542 |
__argValues[rI[12]].pointerVal, __argValues[rI[13]].pointerVal, |
|
2543 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2544 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2545 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2546 |
__argValues[dI[6]].dVal, __argValues[dI[7]].dVal, |
|
2547 |
__argValues[dI[8]].dVal, __argValues[dI[9]].dVal, |
|
2548 |
__argValues[dI[10]].dVal, __argValues[dI[11]].dVal, |
|
2549 |
__argValues[dI[12]].dVal, __argValues[dI[13]].dVal |
|
2550 |
); |
|
2551 |
break; |
|
2552 |
case 15: |
|
2553 |
__returnValue.dVal = (*fd)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2554 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2555 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2556 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2557 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2558 |
__argValues[rI[10]].pointerVal, __argValues[rI[11]].pointerVal, |
|
2559 |
__argValues[rI[12]].pointerVal, __argValues[rI[13]].pointerVal, |
|
2560 |
__argValues[rI[14]].pointerVal, |
|
2561 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2562 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2563 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2564 |
__argValues[dI[6]].dVal, __argValues[dI[7]].dVal, |
|
2565 |
__argValues[dI[8]].dVal, __argValues[dI[9]].dVal, |
|
2566 |
__argValues[dI[10]].dVal, __argValues[dI[11]].dVal, |
|
2567 |
__argValues[dI[12]].dVal, __argValues[dI[13]].dVal, |
|
2568 |
__argValues[dI[14]].dVal |
|
2569 |
); |
|
2570 |
break; |
|
2571 |
default: |
|
2572 |
failureCode = @symbol(TooManyArguments); |
|
2573 |
goto getOutOfHere; |
|
2574 |
} |
|
2575 |
break; |
|
20290
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
2576 |
|
20309 | 2577 |
default: |
2578 |
DEBUGCODE_IF( @global(Verbose), { |
|
2579 |
printf("double arg(s); non-double retval\n"); |
|
2580 |
}) |
|
2581 |
switch (__numArgsIncludingThis) { |
|
2582 |
case 0: |
|
2583 |
__returnValue.pointerVal = (*fi)( ); |
|
2584 |
break; |
|
2585 |
case 1: |
|
2586 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, |
|
2587 |
__argValues[dI[0]].dVal ); |
|
2588 |
break; |
|
2589 |
case 2: |
|
2590 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2591 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal |
|
2592 |
); |
|
2593 |
break; |
|
2594 |
case 3: |
|
2595 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2596 |
__argValues[rI[2]].pointerVal, |
|
2597 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2598 |
__argValues[dI[2]].dVal |
|
2599 |
); |
|
2600 |
break; |
|
2601 |
case 4: |
|
2602 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2603 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2604 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2605 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal |
|
2606 |
); |
|
2607 |
break; |
|
2608 |
case 5: |
|
2609 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2610 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2611 |
__argValues[rI[4]].pointerVal, |
|
2612 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2613 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2614 |
__argValues[dI[4]].dVal |
|
2615 |
); |
|
2616 |
break; |
|
2617 |
case 6: |
|
2618 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2619 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2620 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2621 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2622 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2623 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal |
|
2624 |
); |
|
2625 |
break; |
|
2626 |
case 7: |
|
2627 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2628 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2629 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2630 |
__argValues[rI[6]].pointerVal, |
|
2631 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2632 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2633 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2634 |
__argValues[dI[6]].dVal |
|
2635 |
); |
|
2636 |
break; |
|
2637 |
case 8: |
|
2638 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2639 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2640 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2641 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2642 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2643 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2644 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2645 |
__argValues[dI[6]].dVal, __argValues[dI[7]].dVal |
|
2646 |
); |
|
2647 |
break; |
|
2648 |
case 9: |
|
2649 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2650 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2651 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2652 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2653 |
__argValues[rI[8]].pointerVal, |
|
2654 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2655 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2656 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2657 |
__argValues[dI[6]].dVal, __argValues[dI[7]].dVal, |
|
2658 |
__argValues[dI[8]].dVal |
|
2659 |
); |
|
2660 |
break; |
|
2661 |
case 10: |
|
2662 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2663 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2664 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2665 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2666 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2667 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2668 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2669 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2670 |
__argValues[dI[6]].dVal, __argValues[dI[7]].dVal, |
|
2671 |
__argValues[dI[8]].dVal, __argValues[dI[9]].dVal |
|
2672 |
); |
|
2673 |
break; |
|
2674 |
case 11: |
|
2675 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2676 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2677 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2678 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2679 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2680 |
__argValues[rI[10]].pointerVal, |
|
2681 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2682 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2683 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2684 |
__argValues[dI[6]].dVal, __argValues[dI[7]].dVal, |
|
2685 |
__argValues[dI[8]].dVal, __argValues[dI[9]].dVal, |
|
2686 |
__argValues[dI[10]].dVal |
|
2687 |
); |
|
2688 |
break; |
|
2689 |
case 12: |
|
2690 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2691 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2692 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2693 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2694 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2695 |
__argValues[rI[10]].pointerVal, __argValues[rI[11]].pointerVal, |
|
2696 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2697 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2698 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2699 |
__argValues[dI[6]].dVal, __argValues[dI[7]].dVal, |
|
2700 |
__argValues[dI[8]].dVal, __argValues[dI[9]].dVal, |
|
2701 |
__argValues[dI[10]].dVal, __argValues[dI[11]].dVal |
|
2702 |
); |
|
2703 |
break; |
|
2704 |
case 13: |
|
2705 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2706 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2707 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2708 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2709 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2710 |
__argValues[rI[10]].pointerVal, __argValues[rI[11]].pointerVal, |
|
2711 |
__argValues[rI[12]].pointerVal, |
|
2712 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2713 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2714 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2715 |
__argValues[dI[6]].dVal, __argValues[dI[7]].dVal, |
|
2716 |
__argValues[dI[8]].dVal, __argValues[dI[9]].dVal, |
|
2717 |
__argValues[dI[10]].dVal, __argValues[dI[11]].dVal, |
|
2718 |
__argValues[dI[12]].dVal |
|
2719 |
); |
|
2720 |
break; |
|
2721 |
case 14: |
|
2722 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2723 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2724 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2725 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2726 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2727 |
__argValues[rI[10]].pointerVal, __argValues[rI[11]].pointerVal, |
|
2728 |
__argValues[rI[12]].pointerVal, __argValues[rI[13]].pointerVal, |
|
2729 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2730 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2731 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2732 |
__argValues[dI[6]].dVal, __argValues[dI[7]].dVal, |
|
2733 |
__argValues[dI[8]].dVal, __argValues[dI[9]].dVal, |
|
2734 |
__argValues[dI[10]].dVal, __argValues[dI[11]].dVal, |
|
2735 |
__argValues[dI[12]].dVal, __argValues[dI[13]].dVal |
|
2736 |
); |
|
2737 |
break; |
|
2738 |
case 15: |
|
2739 |
__returnValue.pointerVal = (*fi)( __argValues[rI[0]].pointerVal, __argValues[rI[1]].pointerVal, |
|
2740 |
__argValues[rI[2]].pointerVal, __argValues[rI[3]].pointerVal, |
|
2741 |
__argValues[rI[4]].pointerVal, __argValues[rI[5]].pointerVal, |
|
2742 |
__argValues[rI[6]].pointerVal, __argValues[rI[7]].pointerVal, |
|
2743 |
__argValues[rI[8]].pointerVal, __argValues[rI[9]].pointerVal, |
|
2744 |
__argValues[rI[10]].pointerVal, __argValues[rI[11]].pointerVal, |
|
2745 |
__argValues[rI[12]].pointerVal, __argValues[rI[13]].pointerVal, |
|
2746 |
__argValues[rI[14]].pointerVal, |
|
2747 |
__argValues[dI[0]].dVal, __argValues[dI[1]].dVal, |
|
2748 |
__argValues[dI[2]].dVal, __argValues[dI[3]].dVal, |
|
2749 |
__argValues[dI[4]].dVal, __argValues[dI[5]].dVal, |
|
2750 |
__argValues[dI[6]].dVal, __argValues[dI[7]].dVal, |
|
2751 |
__argValues[dI[8]].dVal, __argValues[dI[9]].dVal, |
|
2752 |
__argValues[dI[10]].dVal, __argValues[dI[11]].dVal, |
|
2753 |
__argValues[dI[12]].dVal, __argValues[dI[13]].dVal, |
|
2754 |
__argValues[dI[14]].dVal |
|
2755 |
); |
|
2756 |
break; |
|
2757 |
default: |
|
2758 |
failureCode = @symbol(TooManyArguments); |
|
2759 |
goto getOutOfHere; |
|
2760 |
} |
|
2761 |
} |
|
2762 |
} |
|
19931 | 2763 |
} |
20290
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
2764 |
# endif // alternative to FFI |
19931 | 2765 |
|
20290
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
2766 |
DEBUGCODE_IF( @global(Verbose), { |
20309 | 2767 |
printf("retval is %"_ld_" (0x%"_lx_")\n", (INT)(__returnValue.iVal), (INT)(__returnValue.iVal)); |
20290
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
2768 |
}) |
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2769 |
|
11586 | 2770 |
if ((returnTypeSymbol == @symbol(int)) |
2771 |
|| (returnTypeSymbol == @symbol(sint)) |
|
9479 | 2772 |
|| (returnTypeSymbol == @symbol(sint8)) |
2773 |
|| (returnTypeSymbol == @symbol(sint16)) |
|
2774 |
|| (returnTypeSymbol == @symbol(sint32))) { |
|
20309 | 2775 |
DEBUGCODE_IF( @global(Verbose), { |
2776 |
printf("return int: %"_lx_"\n", (INT)(__returnValue.iVal)); |
|
2777 |
}) |
|
2778 |
RETURN ( __MKINT(__returnValue.iVal) ); |
|
9342 | 2779 |
} |
2780 |
if ((returnTypeSymbol == @symbol(uint)) |
|
2781 |
|| (returnTypeSymbol == @symbol(uint8)) |
|
2782 |
|| (returnTypeSymbol == @symbol(uint16)) |
|
2783 |
|| (returnTypeSymbol == @symbol(uint32))) { |
|
20309 | 2784 |
DEBUGCODE_IF( @global(Verbose), { |
2785 |
printf("return uint: %"_lx_"\n", (INT)(__returnValue.iVal)); |
|
2786 |
}) |
|
2787 |
RETURN ( __MKUINT(__returnValue.iVal) ); |
|
9342 | 2788 |
} |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
2789 |
if (returnTypeSymbol == @symbol(bool)) { |
20309 | 2790 |
RETURN ( __returnValue.iVal ? true : false ); |
9342 | 2791 |
} |
2792 |
if (returnTypeSymbol == @symbol(float)) { |
|
20309 | 2793 |
RETURN ( __MKFLOAT(__returnValue.fVal )); |
9342 | 2794 |
} |
2795 |
if (returnTypeSymbol == @symbol(double)) { |
|
20309 | 2796 |
RETURN ( __MKFLOAT(__returnValue.dVal )); |
9342 | 2797 |
} |
2798 |
if (returnTypeSymbol == @symbol(void)) { |
|
20309 | 2799 |
RETURN ( nil ); |
9342 | 2800 |
} |
9463 | 2801 |
if (returnTypeSymbol == @symbol(char)) { |
20309 | 2802 |
RETURN ( __MKCHARACTER(__returnValue.iVal & 0xFF) ); |
9463 | 2803 |
} |
2804 |
if (returnTypeSymbol == @symbol(wchar)) { |
|
20309 | 2805 |
RETURN ( __MKUCHARACTER(__returnValue.iVal & 0xFFFF) ); |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
2806 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
2807 |
if (returnTypeSymbol == @symbol(sint64)) { |
19356 | 2808 |
# if (__POINTER_SIZE__ == 8) |
19355 | 2809 |
|
20309 | 2810 |
DEBUGCODE_IF( @global(Verbose), { |
2811 |
printf("return sint64: %"_lx_"\n", (INT)(__returnValue.longLongVal)); |
|
2812 |
}) |
|
2813 |
RETURN ( __MKINT(__returnValue.longLongVal) ); |
|
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2814 |
# else |
20309 | 2815 |
DEBUGCODE_IF( @global(Verbose), { |
2816 |
printf("return sint64: %lx%08lx\n", __HI32(__returnValue.longLongVal), __LO32(__returnValue.longLongVal)); |
|
2817 |
}) |
|
2818 |
RETURN ( __MKINT64(&__returnValue.longLongVal) ); |
|
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2819 |
# endif |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
2820 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
2821 |
if (returnTypeSymbol == @symbol(uint64)) { |
19356 | 2822 |
# if (__POINTER_SIZE__ == 8) |
20309 | 2823 |
DEBUGCODE_IF( @global(Verbose), { |
2824 |
printf("return uint64: %"_lx_"\n", (unsigned INT)(__returnValue.longLongVal)); |
|
2825 |
}) |
|
2826 |
RETURN ( __MKUINT(__returnValue.longLongVal) ); |
|
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2827 |
# else |
20309 | 2828 |
DEBUGCODE_IF( @global(Verbose), { |
2829 |
printf("return sint64: %lx%08lx\n", __HI32(__returnValue.longLongVal), __LO32(__returnValue.longLongVal)); |
|
2830 |
}) |
|
2831 |
RETURN ( __MKUINT64(&__returnValue.longLongVal) ); |
|
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2832 |
# endif |
9463 | 2833 |
} |
11586 | 2834 |
|
20290
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
2835 |
DEBUGCODE_IF( @global(Verbose), { |
20309 | 2836 |
printf("return pointer: %"_lx_"\n", (INT)(__returnValue.pointerVal)); |
20290
952d5b62a161
implemented a non-FFI-based callout scheme which works with OSX
Claus Gittinger <cg@exept.de>
parents:
20289
diff
changeset
|
2837 |
}) |
9346 | 2838 |
if (returnTypeSymbol == @symbol(handle)) { |
21748 | 2839 |
returnValue = __MKEXTERNALADDRESS(__returnValue.pointerVal); |
9346 | 2840 |
} else if (returnTypeSymbol == @symbol(pointer)) { |
20309 | 2841 |
returnValue = __MKEXTERNALBYTES(__returnValue.pointerVal); |
10603 | 2842 |
} else if (returnTypeSymbol == @symbol(bytePointer)) { |
20309 | 2843 |
returnValue = __MKEXTERNALBYTES(__returnValue.pointerVal); |
9463 | 2844 |
} else if (returnTypeSymbol == @symbol(charPointer)) { |
20309 | 2845 |
returnValue = __MKSTRING(__returnValue.pointerVal); |
22556 | 2846 |
if (mustFreeRetVal == true) { |
21412 | 2847 |
free(__returnValue.pointerVal); |
2848 |
alreadyFreed = true; |
|
21748 | 2849 |
} |
9463 | 2850 |
} else if (returnTypeSymbol == @symbol(wcharPointer)) { |
20309 | 2851 |
returnValue = __MKU16STRING(__returnValue.pointerVal); |
22556 | 2852 |
if (mustFreeRetVal == true) { |
21412 | 2853 |
free(__returnValue.pointerVal); |
2854 |
alreadyFreed = true; |
|
21748 | 2855 |
} |
9342 | 2856 |
} else { |
20309 | 2857 |
__FAIL__(@symbol(UnknownReturnType2)) |
9342 | 2858 |
} |
19931 | 2859 |
|
9342 | 2860 |
getOutOfHere: ; |
2861 |
%}. |
|
2862 |
failureCode notNil ifTrue:[ |
|
20309 | 2863 |
(failureCode == #UnknownReturnType or:[ failureCode == #UnknownArgumentType ]) ifTrue:[ |
2864 |
oldReturnType := returnType. |
|
2865 |
oldArgumentTypes := argumentTypes. |
|
2866 |
self adjustTypes. |
|
2867 |
((oldReturnType ~= returnType) or:[oldArgumentTypes ~= argumentTypes]) ifTrue:[ |
|
2868 |
thisContext restart |
|
2869 |
]. |
|
2870 |
]. |
|
2871 |
(failureCode == #BadArgForAsyncCall) ifTrue:[ |
|
2872 |
^ self tryAgainWithAsyncSafeArguments:argumentsOrNil forCPPInstance:aReceiverOrNil |
|
2873 |
]. |
|
2874 |
(failureCode == #FFINotSupported) ifTrue:[ |
|
22140 | 2875 |
^ self primitiveFailed:'FFI support missing in this build'. |
20309 | 2876 |
]. |
12579
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
2877 |
|
22140 | 2878 |
(failureCode == #InvalidArgument) ifTrue:[ |
2879 |
^ self primitiveFailed:('cannot convert argument: #%1' bindWith:failureArgNr). |
|
2880 |
] ifFalse:[ |
|
2881 |
^ self primitiveFailed. "see failureCode and failureInfo for details" |
|
2882 |
]. |
|
2883 |
"/ ^ nil |
|
9342 | 2884 |
]. |
2885 |
||
21412 | 2886 |
(mustFreeRetVal and:[alreadyFreed not]) ifTrue:[ |
2887 |
returnValue registerForFinalization. |
|
2888 |
]. |
|
2889 |
||
9483 | 2890 |
returnType isSymbol ifTrue:[ |
20309 | 2891 |
returnValueClass notNil ifTrue:[ |
2892 |
self isConstReturnValue ifTrue:[ |
|
2893 |
returnValue changeClassTo:returnValueClass. |
|
2894 |
^ returnValue |
|
2895 |
]. |
|
2896 |
^ returnValueClass fromExternalAddress:returnValue. |
|
2897 |
]. |
|
9483 | 2898 |
] ifFalse:[ |
20309 | 2899 |
returnType isCPointer ifTrue:[ |
2900 |
returnType baseType isCStruct ifTrue:[ |
|
2901 |
stClass := Smalltalk classNamed:returnType baseType name. |
|
2902 |
stClass notNil ifTrue:[ |
|
2903 |
self isConstReturnValue ifTrue:[ |
|
2904 |
returnValue changeClassTo:returnValueClass. |
|
2905 |
^ returnValue |
|
2906 |
]. |
|
2907 |
^ stClass fromExternalAddress:returnValue. |
|
2908 |
]. |
|
2909 |
]. |
|
2910 |
returnType baseType isCChar ifTrue:[ |
|
2911 |
^ returnValue stringAt:1 |
|
2912 |
]. |
|
2913 |
]. |
|
9342 | 2914 |
]. |
2915 |
||
2916 |
^ returnValue |
|
9463 | 2917 |
|
2918 |
"Created: / 01-08-2006 / 13:56:23 / cg" |
|
21748 | 2919 |
"Modified: / 15-05-2017 / 19:48:52 / mawalch" |
22141 | 2920 |
"Modified: / 01-08-2017 / 14:03:52 / cg" |
23785 | 2921 |
"Modified: / 01-03-2019 / 15:40:14 / Claus Gittinger" |
14037 | 2922 |
! |
2923 |
||
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
2924 |
tryAgainWithAsyncSafeArguments:argumentsOrNil forCPPInstance:aReceiverOrNil |
14037 | 2925 |
"invoked by the call primitive, iff GC-unsave arguments where passed to the call. |
2926 |
Here, allocate non-movable blocks of memory and copy the arguments into them, |
|
2927 |
then try the call again, copy changed values back, and release the memeory." |
|
2928 |
||
2929 |
|saveArguments anyBadArg result originalToSaveArgMapping| |
|
2930 |
||
2931 |
argumentsOrNil isNil ifTrue:[ |
|
14625 | 2932 |
^ self primitiveFailed |
14037 | 2933 |
]. |
14506
e53548cdc24d
changed: #tryAgainWithAsyncSafeArguments:forCPPInstance:
anwild
parents:
14412
diff
changeset
|
2934 |
thisContext isRecursive ifTrue: [^self primitiveFailed]. |
14037 | 2935 |
|
2936 |
anyBadArg := false. |
|
2937 |
originalToSaveArgMapping := IdentityDictionary new. |
|
2938 |
||
14625 | 2939 |
saveArguments := argumentsOrNil |
2940 |
collect:[:eachArg | |
|
2941 |
|saveArg| |
|
14037 | 2942 |
|
14625 | 2943 |
(originalToSaveArgMapping includesKey:eachArg) ifTrue:[ |
2944 |
saveArg := originalToSaveArgMapping at:eachArg |
|
2945 |
] ifFalse:[ |
|
2946 |
eachArg isString ifTrue:[ |
|
2947 |
saveArg := (ExternalBytes fromString:eachArg) register. |
|
2948 |
anyBadArg := true. |
|
2949 |
originalToSaveArgMapping at:eachArg put:saveArg. |
|
2950 |
] ifFalse:[ |
|
2951 |
eachArg isByteCollection ifTrue:[ |
|
2952 |
saveArg := (ExternalBytes from:eachArg) register. |
|
2953 |
originalToSaveArgMapping at:eachArg put:saveArg. |
|
2954 |
anyBadArg := true. |
|
2955 |
] ifFalse:[ |
|
2956 |
saveArg := eachArg |
|
2957 |
] |
|
2958 |
]. |
|
2959 |
]. |
|
2960 |
saveArg |
|
2961 |
]. |
|
14037 | 2962 |
|
2963 |
anyBadArg ifFalse:[ |
|
14625 | 2964 |
"avoid recursion..." |
2965 |
^ self primitiveFailed |
|
14037 | 2966 |
]. |
2967 |
||
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
2968 |
result := self invokeFFIwithArguments:saveArguments forCPPInstance:aReceiverOrNil. |
14037 | 2969 |
|
2970 |
"/ copy back !! |
|
2971 |
originalToSaveArgMapping keysAndValuesDo:[:arg :saveArg | |
|
14625 | 2972 |
arg isSymbol ifFalse:[ |
2973 |
arg replaceFrom:1 to:(arg size) with:saveArg startingAt:1. |
|
2974 |
]. |
|
2975 |
saveArg free. |
|
14037 | 2976 |
]. |
2977 |
^ result. |
|
14506
e53548cdc24d
changed: #tryAgainWithAsyncSafeArguments:forCPPInstance:
anwild
parents:
14412
diff
changeset
|
2978 |
|
e53548cdc24d
changed: #tryAgainWithAsyncSafeArguments:forCPPInstance:
anwild
parents:
14412
diff
changeset
|
2979 |
"Modified (format): / 06-11-2012 / 10:52:41 / anwild" |
9342 | 2980 |
! ! |
2981 |
||
10481 | 2982 |
!ExternalLibraryFunction methodsFor:'testing'! |
2983 |
||
10603 | 2984 |
isExternalLibraryFunction |
2985 |
"return true, if the receiver is some kind of externalLibrary function; |
|
2986 |
true is returned here" |
|
2987 |
||
2988 |
^true |
|
2989 |
||
2990 |
"Created: / 07-06-2007 / 10:36:40 / cg" |
|
10481 | 2991 |
! ! |
2992 |
||
8533 | 2993 |
!ExternalLibraryFunction class methodsFor:'documentation'! |
2994 |
||
19487 | 2995 |
version |
2996 |
^ '$Header$' |
|
2997 |
! |
|
2998 |
||
13412 | 2999 |
version_CVS |
19311 | 3000 |
^ '$Header$' |
12436 | 3001 |
! |
3002 |
||
13412 | 3003 |
version_SVN |
19311 | 3004 |
^ '$ Id: ExternalLibraryFunction.st 10643 2011-06-08 21:53:07Z vranyj1 $' |
8533 | 3005 |
! ! |
9463 | 3006 |
|
19311 | 3007 |
|
9463 | 3008 |
ExternalLibraryFunction initialize! |