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