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