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