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