author | Claus Gittinger <cg@exept.de> |
Sat, 13 Jan 2007 00:18:42 +0100 | |
changeset 10326 | b1103ad3581f |
parent 10279 | 60c42983fdd4 |
child 10440 | b643af58f8bf |
permissions | -rw-r--r-- |
8728 | 1 |
" |
2 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
9464 | 3 |
All Rights Reserved |
8728 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
8533 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
14 |
ExternalFunction subclass:#ExternalLibraryFunction |
|
9465 | 15 |
instanceVariableNames:'flags moduleName returnType argumentTypes owningClass' |
10270 | 16 |
classVariableNames:'DLLPATH FLAG_VIRTUAL FLAG_NONVIRTUAL FLAG_ASYNC |
17 |
FLAG_UNLIMITEDSTACK FLAG_RETVAL_IS_CONST CALLTYPE_MASK |
|
18 |
CALLTYPE_API CALLTYPE_C CALLTYPE_OLE CALLTYPE_V8 CALLTYPE_V9 |
|
19 |
CALLTYPE_UNIX64' |
|
9464 | 20 |
poolDictionaries:'' |
21 |
category:'System-Support' |
|
8533 | 22 |
! |
23 |
||
9322 | 24 |
!ExternalLibraryFunction primitiveDefinitions! |
25 |
%{ |
|
26 |
||
9337 | 27 |
#ifdef HAVE_FFI |
28 |
# include <ffi.h> |
|
9322 | 29 |
# define MAX_ARGS 128 |
9365 | 30 |
|
31 |
extern ffi_type *__get_ffi_type_sint(); |
|
32 |
extern ffi_type *__get_ffi_type_sint8(); |
|
33 |
extern ffi_type *__get_ffi_type_sint16(); |
|
34 |
extern ffi_type *__get_ffi_type_sint32(); |
|
35 |
extern ffi_type *__get_ffi_type_sint64(); |
|
36 |
extern ffi_type *__get_ffi_type_uint(); |
|
37 |
extern ffi_type *__get_ffi_type_uint8(); |
|
38 |
extern ffi_type *__get_ffi_type_uint16(); |
|
39 |
extern ffi_type *__get_ffi_type_uint32(); |
|
40 |
extern ffi_type *__get_ffi_type_uint64(); |
|
41 |
extern ffi_type *__get_ffi_type_float(); |
|
42 |
extern ffi_type *__get_ffi_type_double(); |
|
43 |
extern ffi_type *__get_ffi_type_void(); |
|
44 |
extern ffi_type *__get_ffi_type_pointer(); |
|
45 |
||
9337 | 46 |
#endif |
9322 | 47 |
|
48 |
%} |
|
49 |
! ! |
|
50 |
||
8728 | 51 |
!ExternalLibraryFunction class methodsFor:'documentation'! |
52 |
||
53 |
copyright |
|
54 |
" |
|
55 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
9464 | 56 |
All Rights Reserved |
8728 | 57 |
|
58 |
This software is furnished under a license and may be used |
|
59 |
only in accordance with the terms of that license and with the |
|
60 |
inclusion of the above copyright notice. This software may not |
|
61 |
be provided or otherwise made available to, or used by, any |
|
62 |
other person. No title to or ownership of the software is |
|
63 |
hereby transferred. |
|
64 |
" |
|
9322 | 65 |
! |
66 |
||
9331 | 67 |
documentation |
68 |
" |
|
69 |
instances of me are used to interface to external library functions (as found in a dll/shared object). |
|
70 |
When a special external-call pragma such as: |
|
9464 | 71 |
<api: bool MessageBeep(uint)> |
9331 | 72 |
|
73 |
is encountered by the parser in a method, the compiler generates a call via |
|
9464 | 74 |
<correspondingExternalLibraryFunctionObject> invokeWithArguments: argumentArray. |
9331 | 75 |
|
76 |
In the invoke method, the library is checked to be loaded (and loaded if not already), |
|
9336 | 77 |
the arguments are converted to C and pushed onto the C-stack, the function is called, |
9331 | 78 |
and finally, the return value is converted back from C to a smalltalk object. |
79 |
" |
|
80 |
! |
|
81 |
||
9322 | 82 |
example |
83 |
" |
|
9464 | 84 |
[exBegin] |
85 |
|f| |
|
9322 | 86 |
|
9464 | 87 |
f := ExternalLibraryFunction new. |
88 |
f name:'MessageBeep' |
|
89 |
module:'user32.dll' |
|
90 |
callType:#WINAPI |
|
91 |
returnType:#boolean |
|
92 |
argumentTypes:#(uint). |
|
9322 | 93 |
|
9464 | 94 |
f invokeWith:1. |
95 |
[exEnd] |
|
9322 | 96 |
" |
8728 | 97 |
! ! |
8533 | 98 |
|
8550 | 99 |
!ExternalLibraryFunction class methodsFor:'instance creation'! |
100 |
||
9465 | 101 |
name:functionName module:moduleName returnType:returnType argumentTypes:argTypes |
8550 | 102 |
^ self new |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
103 |
name:functionName module:moduleName |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
104 |
returnType:returnType argumentTypes:argTypes |
9465 | 105 |
|
106 |
"Created: / 01-08-2006 / 15:19:08 / cg" |
|
9463 | 107 |
! ! |
108 |
||
109 |
!ExternalLibraryFunction class methodsFor:'class initialization'! |
|
110 |
||
10270 | 111 |
dllPath |
112 |
^ DLLPATH ? #( '.' ) |
|
113 |
! |
|
114 |
||
115 |
dllPath:aCollectionOfDirectoryPathNames |
|
116 |
DLLPATH := aCollectionOfDirectoryPathNames |
|
117 |
! |
|
118 |
||
9463 | 119 |
initialize |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
120 |
"using inline access to corresponding c--defines to avoid duplicate places of knowledge" |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
121 |
FLAG_VIRTUAL := %{ __MKSMALLINT(__EXTL_FLAG_VIRTUAL) %}. "/ a virtual c++ call |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
122 |
FLAG_NONVIRTUAL := %{ __MKSMALLINT(__EXTL_FLAG_NONVIRTUAL) %}. "/ a non-virtual c++ call |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
123 |
FLAG_UNLIMITEDSTACK := %{ __MKSMALLINT(__EXTL_FLAG_UNLIMITEDSTACK) %}. "/ unlimitedstack under unix |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
124 |
FLAG_ASYNC := %{ __MKSMALLINT(__EXTL_FLAG_ASYNC) %}. "/ async under win32 |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
125 |
FLAG_RETVAL_IS_CONST := %{ __MKSMALLINT(__EXTL_FLAG_RETVAL_IS_CONST) %}."/ return value is not to be registered for finalization |
9463 | 126 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
127 |
CALLTYPE_API := %{ __MKSMALLINT(__EXTL_CALLTYPE_API) %}. "/ WINAPI-call (win32 only) |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
128 |
CALLTYPE_C := %{ __MKSMALLINT(__EXTL_CALLTYPE_C) %}. "/ regular C-call (the default) |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
129 |
CALLTYPE_V8 := %{ __MKSMALLINT(__EXTL_CALLTYPE_V8) %}. "/ v8 call (sparc only) |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
130 |
CALLTYPE_V9 := %{ __MKSMALLINT(__EXTL_CALLTYPE_V9) %}. "/ v9 call (sparc only) |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
131 |
CALLTYPE_UNIX64 := %{ __MKSMALLINT(__EXTL_CALLTYPE_UNIX64) %}. "/ unix64 call (alpha only) |
9463 | 132 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
133 |
CALLTYPE_MASK := %{ __MKSMALLINT(__EXTL_CALLTYPE_MASK) %}. |
9465 | 134 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
135 |
" |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
136 |
self initialize |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
137 |
" |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
138 |
|
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
139 |
"Modified: / 03-10-2006 / 21:27:47 / cg" |
8550 | 140 |
! ! |
141 |
||
9321 | 142 |
!ExternalLibraryFunction class methodsFor:'constants'! |
143 |
||
144 |
callTypeAPI |
|
9463 | 145 |
^ CALLTYPE_API |
9321 | 146 |
|
9463 | 147 |
"Modified: / 01-08-2006 / 13:44:41 / cg" |
9435 | 148 |
! |
149 |
||
9321 | 150 |
callTypeC |
9463 | 151 |
^ CALLTYPE_C |
9321 | 152 |
|
9463 | 153 |
"Modified: / 01-08-2006 / 13:44:49 / cg" |
9435 | 154 |
! |
155 |
||
9321 | 156 |
callTypeCDecl |
9463 | 157 |
^ CALLTYPE_C |
9321 | 158 |
|
9463 | 159 |
"Modified: / 01-08-2006 / 13:44:52 / cg" |
9435 | 160 |
! |
161 |
||
9321 | 162 |
callTypeOLE |
9463 | 163 |
^ CALLTYPE_OLE |
9435 | 164 |
|
9463 | 165 |
"Modified: / 01-08-2006 / 13:44:57 / cg" |
9321 | 166 |
! ! |
167 |
||
168 |
!ExternalLibraryFunction methodsFor:'accessing'! |
|
169 |
||
170 |
argumentTypes |
|
171 |
^ argumentTypes |
|
9463 | 172 |
! |
173 |
||
174 |
beAsync |
|
175 |
"let this execute in a separate thread, in par with the other execution thread(s). |
|
176 |
Ignored under unix/linux (until those support multiple threads too)." |
|
177 |
||
178 |
flags := (flags ? 0) bitOr: FLAG_ASYNC. |
|
179 |
||
180 |
"Created: / 01-08-2006 / 13:42:38 / cg" |
|
181 |
! |
|
182 |
||
9465 | 183 |
beCallTypeAPI |
184 |
flags := (flags ? 0) bitOr: CALLTYPE_API. |
|
185 |
||
186 |
"Created: / 01-08-2006 / 15:12:40 / cg" |
|
187 |
! |
|
188 |
||
189 |
beCallTypeC |
|
190 |
flags := (flags ? 0) bitOr: CALLTYPE_C. |
|
191 |
||
192 |
"Created: / 01-08-2006 / 15:12:40 / cg" |
|
193 |
! |
|
194 |
||
195 |
beCallTypeUNIX64 |
|
196 |
flags := (flags ? 0) bitOr: CALLTYPE_UNIX64. |
|
197 |
||
198 |
"Created: / 01-08-2006 / 15:13:38 / cg" |
|
199 |
! |
|
200 |
||
201 |
beCallTypeV8 |
|
202 |
flags := (flags ? 0) bitOr: CALLTYPE_V8. |
|
203 |
||
204 |
"Created: / 01-08-2006 / 15:13:28 / cg" |
|
205 |
! |
|
206 |
||
207 |
beCallTypeV9 |
|
208 |
flags := (flags ? 0) bitOr: CALLTYPE_V9. |
|
209 |
||
210 |
"Created: / 01-08-2006 / 15:13:31 / cg" |
|
211 |
! |
|
212 |
||
213 |
beCallTypeWINAPI |
|
214 |
self beCallTypeAPI |
|
215 |
||
216 |
"Modified: / 01-08-2006 / 15:14:02 / cg" |
|
217 |
! |
|
218 |
||
9525 | 219 |
beConstReturnValue |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
220 |
"specify that a pointer return value is not to be finalized |
9525 | 221 |
(i.e. points to static data or data which is freed by c)" |
222 |
||
223 |
flags := (flags ? 0) bitOr: FLAG_RETVAL_IS_CONST. |
|
224 |
||
225 |
"Created: / 01-08-2006 / 13:56:48 / cg" |
|
226 |
! |
|
227 |
||
9463 | 228 |
beNonVirtualCPP |
229 |
"specify this as a non-virtual c++-function" |
|
230 |
||
231 |
flags := (flags ? 0) bitOr: FLAG_NONVIRTUAL. |
|
232 |
||
233 |
"Created: / 01-08-2006 / 13:56:44 / cg" |
|
234 |
! |
|
235 |
||
236 |
beUnlimitedStack |
|
237 |
"let this execute on the c-stack (as opposed to the thread-stack) |
|
238 |
for unlimited auto-sized-stack under unix/linux. |
|
239 |
Ignored under windows." |
|
240 |
||
241 |
flags := (flags ? 0) bitOr: FLAG_UNLIMITEDSTACK. |
|
242 |
||
243 |
"Created: / 01-08-2006 / 13:41:54 / cg" |
|
244 |
! |
|
245 |
||
246 |
beVirtualCPP |
|
247 |
"specify this as a virtual c++-function" |
|
248 |
||
249 |
flags := (flags ? 0) bitOr: FLAG_VIRTUAL. |
|
250 |
||
251 |
"Created: / 01-08-2006 / 13:56:48 / cg" |
|
252 |
! |
|
253 |
||
9465 | 254 |
callTypeNumber |
255 |
^ (flags ? 0) bitAnd: CALLTYPE_MASK. |
|
256 |
||
257 |
"Created: / 01-08-2006 / 15:12:10 / cg" |
|
258 |
! |
|
259 |
||
9463 | 260 |
isAsync |
261 |
"is this executed in a separate thread, in par with the other execution thread(s) ?" |
|
262 |
||
263 |
^ (flags ? 0) bitTest: FLAG_ASYNC. |
|
264 |
||
265 |
"Created: / 01-08-2006 / 13:46:53 / cg" |
|
266 |
! |
|
267 |
||
9519 | 268 |
isCPPFunction |
269 |
"is this a virtual or non-virtual c++-function ?" |
|
270 |
||
271 |
^ (flags ? 0) bitTest: (FLAG_VIRTUAL bitOr: FLAG_NONVIRTUAL). |
|
272 |
||
273 |
"Created: / 01-08-2006 / 13:56:54 / cg" |
|
274 |
! |
|
275 |
||
9465 | 276 |
isCallTypeAPI |
277 |
^ ((flags ? 0) bitAnd: CALLTYPE_MASK) == CALLTYPE_API. |
|
278 |
||
279 |
"Created: / 01-08-2006 / 15:21:16 / cg" |
|
280 |
! |
|
281 |
||
282 |
isCallTypeC |
|
283 |
^ ((flags ? 0) bitAnd: CALLTYPE_MASK) == CALLTYPE_C. |
|
284 |
||
285 |
"Created: / 01-08-2006 / 15:21:23 / cg" |
|
286 |
! |
|
287 |
||
9525 | 288 |
isConstReturnValue |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
289 |
"is the pointer return value not to be finalized |
9525 | 290 |
(i.e. points to static data or data which is freed by c)" |
291 |
||
292 |
^ (flags ? 0) bitTest: FLAG_RETVAL_IS_CONST. |
|
293 |
||
294 |
"Created: / 01-08-2006 / 13:56:48 / cg" |
|
295 |
! |
|
296 |
||
9463 | 297 |
isNonVirtualCPP |
298 |
"is this a non-virtual c++-function ?" |
|
299 |
||
300 |
^ (flags ? 0) bitTest: FLAG_NONVIRTUAL. |
|
301 |
||
302 |
"Created: / 01-08-2006 / 13:56:51 / cg" |
|
303 |
! |
|
304 |
||
305 |
isUnlimitedStack |
|
306 |
"will this execute on the c-stack (as opposed to the thread-stack) |
|
307 |
for unlimited auto-sized-stack under unix/linux. |
|
308 |
Ignored under windows." |
|
309 |
||
310 |
^ (flags ? 0) bitTest: FLAG_UNLIMITEDSTACK. |
|
311 |
||
312 |
"Created: / 01-08-2006 / 14:17:07 / cg" |
|
313 |
! |
|
314 |
||
315 |
isVirtualCPP |
|
316 |
"is this a virtual c++-function ?" |
|
317 |
||
318 |
^ (flags ? 0) bitTest: FLAG_VIRTUAL. |
|
319 |
||
320 |
"Created: / 01-08-2006 / 13:56:54 / cg" |
|
9321 | 321 |
! ! |
322 |
||
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
323 |
!ExternalLibraryFunction methodsFor:'invoking'! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
324 |
|
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
325 |
invoke |
9321 | 326 |
self hasCode ifFalse:[ |
9464 | 327 |
self prepareInvoke. |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
328 |
]. |
9321 | 329 |
^ self invokeFFIWithArguments:#() |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
330 |
! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
331 |
|
9347 | 332 |
invokeCPPVirtualOn:anInstance |
9341 | 333 |
self hasCode ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
334 |
self prepareInvoke. |
9341 | 335 |
]. |
9347 | 336 |
^ self invokeCPPVirtualFFIOn:anInstance withArguments:#() |
9341 | 337 |
! |
338 |
||
9347 | 339 |
invokeCPPVirtualOn:instance with:arg |
9341 | 340 |
self hasCode ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
341 |
self prepareInvoke. |
9341 | 342 |
]. |
9347 | 343 |
^ self invokeCPPVirtualFFIOn:instance withArguments:(Array with:arg) |
9341 | 344 |
! |
345 |
||
9347 | 346 |
invokeCPPVirtualOn:instance with:arg1 with:arg2 |
9341 | 347 |
self hasCode ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
348 |
self prepareInvoke. |
9341 | 349 |
]. |
9347 | 350 |
^ self invokeCPPVirtualFFIOn:instance withArguments:(Array with:arg1 with:arg2) |
9341 | 351 |
! |
352 |
||
9347 | 353 |
invokeCPPVirtualOn:instance with:arg1 with:arg2 with:arg3 |
9341 | 354 |
self hasCode ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
355 |
self prepareInvoke. |
9341 | 356 |
]. |
9347 | 357 |
^ self invokeCPPVirtualFFIOn:instance withArguments:(Array with:arg1 with:arg2 with:arg3) |
9341 | 358 |
! |
359 |
||
9347 | 360 |
invokeCPPVirtualOn:instance with:arg1 with:arg2 with:arg3 with:arg4 |
9341 | 361 |
self hasCode ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
362 |
self prepareInvoke. |
9341 | 363 |
]. |
9347 | 364 |
^ self invokeCPPVirtualFFIOn:instance withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
9341 | 365 |
! |
366 |
||
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
367 |
invokeWith:arg |
9321 | 368 |
self hasCode ifFalse:[ |
9464 | 369 |
self prepareInvoke. |
9321 | 370 |
]. |
371 |
^ self invokeFFIWithArguments:(Array with:arg) |
|
372 |
! |
|
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
373 |
|
9321 | 374 |
invokeWith:arg1 with:arg2 |
375 |
self hasCode ifFalse:[ |
|
9464 | 376 |
self prepareInvoke. |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
377 |
]. |
9321 | 378 |
^ self invokeFFIWithArguments:(Array with:arg1 with:arg2) |
379 |
! |
|
380 |
||
381 |
invokeWith:arg1 with:arg2 with:arg3 |
|
382 |
self hasCode ifFalse:[ |
|
9464 | 383 |
self prepareInvoke. |
9321 | 384 |
]. |
385 |
^ self invokeFFIWithArguments:(Array with:arg1 with:arg2 with:arg3) |
|
386 |
! |
|
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
387 |
|
9321 | 388 |
invokeWith:arg1 with:arg2 with:arg3 with:arg4 |
389 |
self hasCode ifFalse:[ |
|
9464 | 390 |
self prepareInvoke. |
9321 | 391 |
]. |
392 |
^ self invokeFFIWithArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
393 |
! |
|
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
394 |
|
9321 | 395 |
invokeWithArguments:argArray |
396 |
self hasCode ifFalse:[ |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
397 |
self prepareInvoke. |
9321 | 398 |
]. |
9465 | 399 |
^ self invokeFFIwithArguments:argArray forCPPInstance:nil |
400 |
||
401 |
"Modified: / 01-08-2006 / 16:04:08 / cg" |
|
9321 | 402 |
! ! |
403 |
||
404 |
!ExternalLibraryFunction methodsFor:'printing'! |
|
405 |
||
406 |
printOn:aStream |
|
407 |
aStream nextPutAll:'<'. |
|
9465 | 408 |
self isCallTypeAPI ifTrue:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
409 |
'API:' printOn:aStream. |
9465 | 410 |
] ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
411 |
'C:' printOn:aStream. |
9465 | 412 |
]. |
9321 | 413 |
aStream nextPutAll:' '. |
414 |
name printOn:aStream. |
|
9465 | 415 |
moduleName notNil ifTrue:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
416 |
aStream nextPutAll:' module:'. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
417 |
moduleName printOn:aStream. |
9465 | 418 |
]. |
9321 | 419 |
aStream nextPutAll:'>'. |
9465 | 420 |
|
421 |
"Modified: / 01-08-2006 / 15:21:42 / cg" |
|
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
422 |
! ! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
423 |
|
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
424 |
!ExternalLibraryFunction methodsFor:'private'! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
425 |
|
10213 | 426 |
adjustTypes |
427 |
argumentTypes notNil ifTrue:[ |
|
428 |
argumentTypes := argumentTypes collect:[:argType | self ffiTypeSymbolForType:argType]. |
|
429 |
]. |
|
430 |
returnType := self ffiTypeSymbolForType:returnType. |
|
431 |
! |
|
432 |
||
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
433 |
linkToModule |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
434 |
"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
|
435 |
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
|
436 |
|
9465 | 437 |
|handle moduleNameUsed functionName| |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
438 |
|
9465 | 439 |
(moduleNameUsed := moduleName) isNil ifTrue:[ |
10270 | 440 |
owningClass isNil ifTrue:[ |
441 |
self error:'Missing moduleName'. |
|
442 |
]. |
|
443 |
moduleNameUsed := owningClass theNonMetaclass libraryName asSymbol. |
|
9321 | 444 |
]. |
10270 | 445 |
moduleHandle isNil ifTrue:[ |
446 |
handle := self loadLibrary:moduleNameUsed. |
|
447 |
handle isNil ifTrue:[ |
|
448 |
self error:'Cannot load module: ', moduleNameUsed. |
|
449 |
]. |
|
450 |
moduleHandle := handle. |
|
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
451 |
]. |
9341 | 452 |
name isNumber ifFalse:[ |
10270 | 453 |
functionName := name. |
454 |
(moduleHandle getFunctionAddress:functionName into:self) isNil ifTrue:[ |
|
455 |
functionName := ('_', functionName) asSymbol. |
|
9418
df5d2576402d
resolve function - if function with name not exists add an underscore in front and retry
ca
parents:
9399
diff
changeset
|
456 |
|
10270 | 457 |
(moduleHandle getFunctionAddress:functionName into:self) isNil ifTrue:[ |
458 |
moduleHandle := nil. |
|
459 |
self error:'Missing function: ', name, ' in module: ', moduleNameUsed. |
|
460 |
]. |
|
461 |
]. |
|
9321 | 462 |
]. |
9392 | 463 |
|
9465 | 464 |
"Modified: / 01-08-2006 / 16:24:14 / cg" |
9321 | 465 |
! |
466 |
||
10270 | 467 |
loadLibrary:dllName |
10279
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
468 |
|handle filename| |
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
469 |
|
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
470 |
filename := dllName asFilename. |
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
471 |
|
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
472 |
filename exists ifTrue:[ |
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
473 |
handle := ObjectFileLoader |
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
474 |
loadDynamicObject:(filename pathName). |
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
475 |
handle notNil ifTrue:[^ handle ]. |
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
476 |
]. |
10270 | 477 |
|
478 |
self class dllPath do:[:eachDirectory | |
|
479 |
handle := ObjectFileLoader |
|
480 |
loadDynamicObject:(eachDirectory asFilename construct:dllName) pathName. |
|
481 |
handle notNil ifTrue:[^ handle ]. |
|
482 |
]. |
|
483 |
^ nil |
|
484 |
! |
|
485 |
||
9321 | 486 |
prepareInvoke |
10270 | 487 |
(moduleHandle isNil or:[self hasCode not]) ifTrue:[ |
488 |
self linkToModule. |
|
489 |
self adjustTypes. |
|
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
490 |
]. |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
491 |
! ! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
492 |
|
8550 | 493 |
!ExternalLibraryFunction methodsFor:'private-accessing'! |
494 |
||
9327 | 495 |
ffiTypeSymbolForType:aType |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
496 |
"map type to one of the ffi-supported ones: |
10213 | 497 |
sint8, sint16, sint32, sint64 |
498 |
uint8, uint16, uint32, uint64 |
|
499 |
bool void handle |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
500 |
" |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
501 |
|
9340 | 502 |
|t| |
9322 | 503 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
504 |
aType == #sint8 ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
505 |
aType == #sint16 ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
506 |
aType == #sint32 ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
507 |
aType == #sint64 ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
508 |
aType == #uint8 ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
509 |
aType == #uint16 ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
510 |
aType == #uint32 ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
511 |
aType == #uint64 ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
512 |
aType == #double ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
513 |
aType == #float ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
514 |
aType == #char ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
515 |
aType == #void ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
516 |
aType == #bool ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
517 |
aType == #pointer ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
518 |
|
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
519 |
aType == #int8 ifTrue:[^ #sint8 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
520 |
aType == #int16 ifTrue:[^ #sint16 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
521 |
aType == #int32 ifTrue:[^ #sint32 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
522 |
aType == #int64 ifTrue:[^ #sint64 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
523 |
aType == #voidPointer ifTrue:[^ #pointer ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
524 |
|
10213 | 525 |
aType == #short ifTrue:[^ #sint16 ]. |
526 |
aType == #long ifTrue:[^ #long ]. |
|
527 |
aType == #int ifTrue:[^ #int ]. |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
528 |
aType == #ushort ifTrue:[^ #uint16 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
529 |
aType == #unsignedShort ifTrue:[^ #uint16 ]. |
10213 | 530 |
aType == #ulong ifTrue:[^ #ulong ]. |
531 |
aType == #unsignedLong ifTrue:[^ #ulong ]. |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
532 |
aType == #uchar ifTrue:[^ #uint8 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
533 |
aType == #unsignedChar ifTrue:[^ #uint8 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
534 |
aType == #byte ifTrue:[^ #uint8 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
535 |
aType == #dword ifTrue:[^ #uint32 ]. |
10213 | 536 |
aType == #sdword ifTrue:[^ #sint32 ]. |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
537 |
aType == #word ifTrue:[^ #uint16 ]. |
10213 | 538 |
aType == #sword ifTrue:[^ #sint16 ]. |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
539 |
aType == #handle ifTrue:[^ #pointer ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
540 |
aType == #lpstr ifTrue:[^ #charPointer ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
541 |
aType == #hresult ifTrue:[^ #uint32 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
542 |
aType == #boolean ifTrue:[^ #bool ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
543 |
aType == #ulongReturn ifTrue:[^ #uint32 ]. "/ TODO - care for 64bit machines |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
544 |
aType == #none ifTrue:[^ #void ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
545 |
aType == #struct ifTrue:[^ #pointer ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
546 |
aType == #structIn ifTrue:[^ #pointer ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
547 |
aType == #structOut ifTrue:[^ #pointer ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
548 |
|
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
549 |
(aType isString or:[aType isSymbol]) ifFalse:[ |
10213 | 550 |
CType isNil ifTrue:[ |
551 |
self error:'unknown type'. |
|
552 |
]. |
|
553 |
^ aType typeSymbol. |
|
9483 | 554 |
]. |
555 |
||
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
556 |
^ aType |
9322 | 557 |
! |
558 |
||
9466 | 559 |
name:functionNameOrVirtualIndex module:aModuleName returnType:aReturnType argumentTypes:argTypes |
560 |
name := functionNameOrVirtualIndex. |
|
561 |
functionNameOrVirtualIndex isNumber ifTrue:[ |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
562 |
self beVirtualCPP. |
9466 | 563 |
]. |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
564 |
moduleName := aModuleName. |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
565 |
returnType := aReturnType. |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
566 |
argumentTypes := argTypes. |
9465 | 567 |
|
568 |
"Created: / 01-08-2006 / 15:19:52 / cg" |
|
9466 | 569 |
"Modified: / 02-08-2006 / 17:20:13 / cg" |
9465 | 570 |
! |
571 |
||
572 |
owningClass:aClass |
|
573 |
owningClass := aClass. |
|
574 |
||
575 |
"Created: / 01-08-2006 / 15:22:50 / cg" |
|
8550 | 576 |
! ! |
577 |
||
9342 | 578 |
!ExternalLibraryFunction methodsFor:'private-invoking'! |
579 |
||
9347 | 580 |
invokeCPPVirtualFFIOn:instance withArguments:arguments |
9463 | 581 |
^ self invokeFFIwithArguments:arguments forCPPInstance:instance |
582 |
||
583 |
"Modified: / 01-08-2006 / 13:55:30 / cg" |
|
9342 | 584 |
! |
585 |
||
9347 | 586 |
invokeFFIWithArguments:arguments |
9463 | 587 |
^ self invokeFFIwithArguments:arguments forCPPInstance:nil |
588 |
||
589 |
"Modified: / 01-08-2006 / 13:55:35 / cg" |
|
9347 | 590 |
! |
591 |
||
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
592 |
invokeFFIwithArguments:arguments forCPPInstance:aCPlusPlusObjectOrNil |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
593 |
|argTypeSymbols returnTypeSymbol failureCode failureInfo returnValue stClass vtOffset |
9524 | 594 |
virtual async unlimitedStack callTypeNumber returnValueClass argValueClass| |
9342 | 595 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
596 |
argTypeSymbols := argumentTypes. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
597 |
returnTypeSymbol := returnType. |
9346 | 598 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
599 |
virtual := self isVirtualCPP. |
9524 | 600 |
(virtual "or:[self isNonVirtualCPP]") ifTrue:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
601 |
aCPlusPlusObjectOrNil isNil ifTrue:[ |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
602 |
"/ must have a c++ object instance |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
603 |
self primitiveFailed. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
604 |
]. |
9463 | 605 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
606 |
"/ and it must be a kind of ExternalStructure !! |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
607 |
(aCPlusPlusObjectOrNil isKindOf:ExternalStructure) ifFalse:[ |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
608 |
self primitiveFailed. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
609 |
]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
610 |
virtual ifTrue:[ |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
611 |
vtOffset := name. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
612 |
(vtOffset between:0 and:10000) ifFalse:[ |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
613 |
self primitiveFailed. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
614 |
] |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
615 |
]. |
9463 | 616 |
] ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
617 |
aCPlusPlusObjectOrNil notNil ifTrue:[ |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
618 |
"/ must NOT have a c++ object instance |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
619 |
self primitiveFailed. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
620 |
]. |
9342 | 621 |
]. |
9463 | 622 |
async := self isAsync. |
623 |
unlimitedStack := self isUnlimitedStack. |
|
9465 | 624 |
callTypeNumber := self callTypeNumber. |
9342 | 625 |
|
9459
6cd520c582b3
change from unlimited to big stack, to allow for interrupts to be handled
ca
parents:
9436
diff
changeset
|
626 |
%{ /* STACK: 100000 */ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
627 |
#ifdef HAVE_FFI |
9342 | 628 |
ffi_cif __cif; |
629 |
ffi_type *__argTypesIncludingThis[MAX_ARGS+1]; |
|
630 |
ffi_type **__argTypes = __argTypesIncludingThis; |
|
631 |
ffi_type *__returnType = NULL; |
|
632 |
union u { |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
633 |
int iVal; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
634 |
float fVal; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
635 |
double dVal; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
636 |
void *pointerVal; |
9342 | 637 |
}; |
638 |
union u __argValuesIncludingThis[MAX_ARGS+1]; |
|
639 |
union u *__argValues = __argValuesIncludingThis; |
|
640 |
union u __returnValue; |
|
641 |
void *__argValuePointersIncludingThis[MAX_ARGS+1]; |
|
642 |
void **__argValuePointers = __argValuePointersIncludingThis; |
|
643 |
void *__returnValuePointer; |
|
644 |
int __numArgs, __numArgsIncludingThis; |
|
645 |
static int null = 0; |
|
646 |
int i; |
|
647 |
ffi_abi __callType = FFI_DEFAULT_ABI; |
|
648 |
VOIDFUNC codeAddress = (VOIDFUNC)__INST(code_); |
|
649 |
||
650 |
if (arguments == nil) { |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
651 |
__numArgs = 0; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
652 |
if (argTypeSymbols != nil) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
653 |
if (! __isArray(argTypeSymbols) |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
654 |
|| (__arraySize(argTypeSymbols) != __numArgs)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
655 |
failureCode = @symbol(ArgumentCountMismatch); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
656 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
657 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
658 |
} |
9342 | 659 |
} else { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
660 |
if (! __isArray(arguments) |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
661 |
|| ! __isArray(argTypeSymbols) |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
662 |
|| (__arraySize(argTypeSymbols) != (__numArgs = __arraySize(arguments)))) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
663 |
failureCode = @symbol(ArgumentCountMismatch); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
664 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
665 |
} |
9342 | 666 |
} |
667 |
if (__numArgs > MAX_ARGS) { |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
668 |
failureCode = @symbol(TooManyArguments); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
669 |
goto getOutOfHere; |
9342 | 670 |
} |
671 |
||
672 |
/* |
|
673 |
* validate the return type |
|
674 |
*/ |
|
675 |
__returnValuePointer = &__returnValue; |
|
9479 | 676 |
|
9483 | 677 |
if (returnTypeSymbol == @symbol(voidPointer)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
678 |
returnTypeSymbol = @symbol(handle); |
9483 | 679 |
} |
9479 | 680 |
|
9342 | 681 |
if (returnTypeSymbol == @symbol(int)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
682 |
__returnType = __get_ffi_type_sint(); |
9342 | 683 |
} else if (returnTypeSymbol == @symbol(uint)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
684 |
__returnType = __get_ffi_type_uint(); |
9479 | 685 |
} else if (returnTypeSymbol == @symbol(uint8)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
686 |
__returnType = __get_ffi_type_uint8(); |
9479 | 687 |
} else if (returnTypeSymbol == @symbol(uint16)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
688 |
__returnType = __get_ffi_type_uint16(); |
9479 | 689 |
} else if (returnTypeSymbol == @symbol(uint32)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
690 |
__returnType = __get_ffi_type_uint32(); |
9479 | 691 |
} else if (returnTypeSymbol == @symbol(uint64)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
692 |
__returnType = __get_ffi_type_uint64(); |
9479 | 693 |
|
694 |
} else if (returnTypeSymbol == @symbol(sint)) { |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
695 |
__returnType = __get_ffi_type_sint(); |
9479 | 696 |
} else if (returnTypeSymbol == @symbol(sint8)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
697 |
__returnType = __get_ffi_type_sint8(); |
9479 | 698 |
} else if (returnTypeSymbol == @symbol(sint16)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
699 |
__returnType = __get_ffi_type_sint16(); |
9479 | 700 |
} else if (returnTypeSymbol == @symbol(sint32)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
701 |
__returnType = __get_ffi_type_sint32(); |
9479 | 702 |
} else if (returnTypeSymbol == @symbol(sint64)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
703 |
__returnType = __get_ffi_type_sint64(); |
9479 | 704 |
|
9342 | 705 |
} else if (returnTypeSymbol == @symbol(long)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
706 |
if (sizeof(long) == 4) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
707 |
returnTypeSymbol = @symbol(sint32); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
708 |
__returnType = __get_ffi_type_sint32(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
709 |
} else if (sizeof(long) == 8) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
710 |
returnTypeSymbol = @symbol(sint64); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
711 |
__returnType = __get_ffi_type_sint64(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
712 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
713 |
failureCode = @symbol(UnknownReturnType); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
714 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
715 |
} |
9479 | 716 |
|
9342 | 717 |
} else if (returnTypeSymbol == @symbol(ulong)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
718 |
if (sizeof(long) == 4) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
719 |
returnTypeSymbol = @symbol(uint32); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
720 |
__returnType = __get_ffi_type_uint32(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
721 |
}else if (sizeof(long) == 8) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
722 |
returnTypeSymbol = @symbol(uint64); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
723 |
__returnType = __get_ffi_type_uint64(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
724 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
725 |
failureCode = @symbol(UnknownReturnType); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
726 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
727 |
} |
9479 | 728 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
729 |
} else if (returnTypeSymbol == @symbol(bool)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
730 |
__returnType = __get_ffi_type_uint(); |
9479 | 731 |
|
9342 | 732 |
} else if (returnTypeSymbol == @symbol(float)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
733 |
__returnType = __get_ffi_type_float(); |
9342 | 734 |
} else if (returnTypeSymbol == @symbol(double)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
735 |
__returnType = __get_ffi_type_double(); |
9479 | 736 |
|
9342 | 737 |
} else if (returnTypeSymbol == @symbol(void)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
738 |
__returnType = __get_ffi_type_void(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
739 |
__returnValuePointer = NULL; |
9479 | 740 |
} else if ((returnTypeSymbol == @symbol(pointer)) || (returnTypeSymbol == @symbol(handle))) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
741 |
__returnType = __get_ffi_type_pointer(); |
9463 | 742 |
} else if (returnTypeSymbol == @symbol(charPointer)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
743 |
__returnType = __get_ffi_type_pointer(); |
9463 | 744 |
} else if (returnTypeSymbol == @symbol(wcharPointer)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
745 |
__returnType = __get_ffi_type_pointer(); |
9342 | 746 |
} else { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
747 |
if (__isSymbol(returnTypeSymbol) |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
748 |
&& ((returnValueClass = __GLOBAL_GET(returnTypeSymbol)) != nil)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
749 |
if (! __isBehaviorLike(returnValueClass)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
750 |
failureCode = @symbol(NonBehaviorReturnType); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
751 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
752 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
753 |
if (! __qIsSubclassOfExternalAddress(returnValueClass)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
754 |
failureCode = @symbol(NonExternalAddressReturnType); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
755 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
756 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
757 |
__returnType = __get_ffi_type_pointer(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
758 |
returnTypeSymbol = @symbol(pointer); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
759 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
760 |
failureCode = @symbol(UnknownReturnType); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
761 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
762 |
} |
9342 | 763 |
} |
764 |
||
765 |
/* |
|
766 |
* validate the c++ object |
|
767 |
*/ |
|
768 |
if (aCPlusPlusObjectOrNil != nil) { |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
769 |
struct cPlusPlusInstance { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
770 |
void **vTable; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
771 |
}; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
772 |
struct cPlusPlusInstance *inst; |
9342 | 773 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
774 |
if (__isExternalAddressLike(aCPlusPlusObjectOrNil)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
775 |
inst = (void *)(__externalAddressVal(aCPlusPlusObjectOrNil)); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
776 |
} else if (__isExternalBytesLike(aCPlusPlusObjectOrNil)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
777 |
inst = (void *)(__externalBytesVal(aCPlusPlusObjectOrNil)); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
778 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
779 |
failureCode = @symbol(InvalidInstance); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
780 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
781 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
782 |
__argValues[0].pointerVal = inst; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
783 |
__argValuePointersIncludingThis[0] = &(__argValues[0]); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
784 |
__argTypes[0] = __get_ffi_type_pointer(); |
9342 | 785 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
786 |
__argValuePointers = &__argValuePointersIncludingThis[1]; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
787 |
__argTypes = &__argTypesIncludingThis[1]; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
788 |
__argValues = &__argValuesIncludingThis[1]; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
789 |
__numArgsIncludingThis = __numArgs + 1; |
9347 | 790 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
791 |
if (virtual == true) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
792 |
if (! __isSmallInteger(vtOffset)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
793 |
failureCode = @symbol(InvalidVTableIndex); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
794 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
795 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
796 |
codeAddress = inst->vTable[__intVal(vtOffset)]; |
9464 | 797 |
#ifdef VERBOSE |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
798 |
printf("virtual codeAddress: %x\n", codeAddress); |
9464 | 799 |
#endif |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
800 |
} |
9342 | 801 |
} else { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
802 |
__numArgsIncludingThis = __numArgs; |
9524 | 803 |
#ifdef VERBOSE |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
804 |
printf("codeAddress: %x\n", codeAddress); |
9524 | 805 |
#endif |
9342 | 806 |
} |
807 |
||
808 |
/* |
|
809 |
* validate all arg types and setup arg-buffers |
|
810 |
*/ |
|
811 |
for (i=0; i<__numArgs; i++) { |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
812 |
ffi_type *thisType; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
813 |
void *argValuePtr; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
814 |
OBJ typeSymbol; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
815 |
OBJ arg; |
9342 | 816 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
817 |
failureInfo = __mkSmallInteger(i+1); /* in case there is one */ |
9465 | 818 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
819 |
typeSymbol = __ArrayInstPtr(argTypeSymbols)->a_element[i]; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
820 |
arg = __ArrayInstPtr(arguments)->a_element[i]; |
9342 | 821 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
822 |
if (typeSymbol == @symbol(handle)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
823 |
typeSymbol = @symbol(pointer); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
824 |
} else if (typeSymbol == @symbol(voidPointer)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
825 |
typeSymbol = @symbol(pointer); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
826 |
} |
9479 | 827 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
828 |
if (typeSymbol == @symbol(long)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
829 |
if (sizeof(long) == sizeof(int)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
830 |
typeSymbol = @symbol(sint); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
831 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
832 |
if (sizeof(long) == 4) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
833 |
typeSymbol = @symbol(sint32); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
834 |
} else if (sizeof(long) == 8) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
835 |
typeSymbol = @symbol(sint64); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
836 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
837 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
838 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
839 |
if (typeSymbol == @symbol(ulong)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
840 |
if (sizeof(unsigned long) == sizeof(unsigned int)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
841 |
typeSymbol = @symbol(uint); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
842 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
843 |
if (sizeof(long) == 4) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
844 |
typeSymbol = @symbol(uint32); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
845 |
} else if (sizeof(long) == 8) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
846 |
typeSymbol = @symbol(uint64); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
847 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
848 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
849 |
} |
9342 | 850 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
851 |
if (typeSymbol == @symbol(int)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
852 |
thisType = __get_ffi_type_sint(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
853 |
if (__isSmallInteger(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
854 |
__argValues[i].iVal = __intVal(arg); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
855 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
856 |
__argValues[i].iVal = __signedLongIntVal(arg); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
857 |
if (__argValues[i].iVal == 0) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
858 |
failureCode = @symbol(InvalidArgument); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
859 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
860 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
861 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
862 |
argValuePtr = &(__argValues[i].iVal); |
9479 | 863 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
864 |
} else if (typeSymbol == @symbol(uint)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
865 |
thisType = __get_ffi_type_uint(); |
9342 | 866 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
867 |
if (__isSmallInteger(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
868 |
__argValues[i].iVal = __intVal(arg); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
869 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
870 |
__argValues[i].iVal = __unsignedLongIntVal(arg); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
871 |
if (__argValues[i].iVal == 0) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
872 |
failureCode = @symbol(InvalidArgument); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
873 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
874 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
875 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
876 |
argValuePtr = &(__argValues[i].iVal); |
9479 | 877 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
878 |
} else if (typeSymbol == @symbol(uint8)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
879 |
thisType = __get_ffi_type_uint8(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
880 |
if (! __isSmallInteger(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
881 |
failureCode = @symbol(InvalidArgument); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
882 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
883 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
884 |
__argValues[i].iVal = __intVal(arg); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
885 |
if (((unsigned)(__argValues[i].iVal)) > 0xFF) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
886 |
failureCode = @symbol(InvalidArgument); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
887 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
888 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
889 |
argValuePtr = &(__argValues[i].iVal); |
9479 | 890 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
891 |
} else if (typeSymbol == @symbol(sint8)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
892 |
thisType = __get_ffi_type_sint8(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
893 |
if (! __isSmallInteger(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
894 |
failureCode = @symbol(InvalidArgument); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
895 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
896 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
897 |
__argValues[i].iVal = __intVal(arg); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
898 |
if (((__argValues[i].iVal) < -0x80) || ((__argValues[i].iVal) > 0x7F)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
899 |
failureCode = @symbol(InvalidArgument); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
900 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
901 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
902 |
argValuePtr = &(__argValues[i].iVal); |
9479 | 903 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
904 |
} else if (typeSymbol == @symbol(uint16)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
905 |
thisType = __get_ffi_type_uint16(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
906 |
if (! __isSmallInteger(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
907 |
failureCode = @symbol(InvalidArgument); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
908 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
909 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
910 |
__argValues[i].iVal = __intVal(arg); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
911 |
if (((unsigned)(__argValues[i].iVal)) > 0xFFFF) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
912 |
failureCode = @symbol(InvalidArgument); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
913 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
914 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
915 |
argValuePtr = &(__argValues[i].iVal); |
9479 | 916 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
917 |
} else if (typeSymbol == @symbol(sint16)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
918 |
thisType = __get_ffi_type_sint16(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
919 |
if (! __isSmallInteger(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
920 |
failureCode = @symbol(InvalidArgument); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
921 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
922 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
923 |
__argValues[i].iVal = __intVal(arg); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
924 |
if (((__argValues[i].iVal) < -0x8000) || ((__argValues[i].iVal) > 0x7FFF)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
925 |
failureCode = @symbol(InvalidArgument); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
926 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
927 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
928 |
argValuePtr = &(__argValues[i].iVal); |
9479 | 929 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
930 |
} else if ((typeSymbol == @symbol(uint32)) || (typeSymbol == @symbol(sint32))) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
931 |
thisType = __get_ffi_type_uint32(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
932 |
if (__isSmallInteger(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
933 |
__argValues[i].iVal = __intVal(arg); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
934 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
935 |
__argValues[i].iVal = __unsignedLongIntVal(arg); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
936 |
if (__argValues[i].iVal == 0) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
937 |
failureCode = @symbol(InvalidArgument); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
938 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
939 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
940 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
941 |
argValuePtr = &(__argValues[i].iVal); |
9479 | 942 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
943 |
} else if (typeSymbol == @symbol(float)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
944 |
thisType = __get_ffi_type_float(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
945 |
if (__isSmallInteger(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
946 |
__argValues[i].fVal = (float)(__intVal(arg)); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
947 |
} else if (__isFloat(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
948 |
__argValues[i].fVal = (float)(__floatVal(arg)); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
949 |
} else if (__isShortFloat(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
950 |
__argValues[i].fVal = (float)(__shortFloatVal(arg)); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
951 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
952 |
failureCode = @symbol(InvalidArgument); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
953 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
954 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
955 |
argValuePtr = &(__argValues[i].fVal); |
9479 | 956 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
957 |
} else if (typeSymbol == @symbol(double)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
958 |
thisType = __get_ffi_type_double(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
959 |
if (__isSmallInteger(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
960 |
__argValues[i].dVal = (double)(__intVal(arg)); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
961 |
} else if (__isFloat(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
962 |
__argValues[i].dVal = (double)(__floatVal(arg)); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
963 |
} else if (__isShortFloat(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
964 |
__argValues[i].dVal = (double)(__shortFloatVal(arg)); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
965 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
966 |
failureCode = @symbol(InvalidArgument); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
967 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
968 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
969 |
argValuePtr = &(__argValues[i].dVal); |
9479 | 970 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
971 |
} else if (typeSymbol == @symbol(void)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
972 |
thisType = __get_ffi_type_void(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
973 |
argValuePtr = &null; |
9479 | 974 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
975 |
} else if (typeSymbol == @symbol(charPointer)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
976 |
thisType = __get_ffi_type_pointer(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
977 |
if (__isString(arg) || __isSymbol(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
978 |
if (async == true) goto badArgForAsyncCall; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
979 |
__argValues[i].pointerVal = (void *)(__stringVal(arg)); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
980 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
981 |
if (__isBytes(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
982 |
if (async == true) goto badArgForAsyncCall; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
983 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
984 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
985 |
if (arg == nil) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
986 |
__argValues[i].pointerVal = (void *)0; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
987 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
988 |
failureCode = @symbol(InvalidArgument); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
989 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
990 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
991 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
992 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
993 |
argValuePtr = &(__argValues[i].pointerVal);; |
9479 | 994 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
995 |
} else if (typeSymbol == @symbol(pointer)) { |
9524 | 996 |
commonPointerTypeArg: ; |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
997 |
thisType = __get_ffi_type_pointer(); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
998 |
if (arg == nil) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
999 |
__argValues[i].pointerVal = NULL; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1000 |
} else if (__isExternalAddressLike(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1001 |
__argValues[i].pointerVal = (void *)(__externalAddressVal(arg)); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1002 |
} else if (__isExternalBytesLike(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1003 |
__argValues[i].pointerVal = (void *)(__externalBytesVal(arg)); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1004 |
} else if (__isByteArray(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1005 |
if (async == true) goto badArgForAsyncCall; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1006 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1007 |
} else if (__isFloatArray(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1008 |
if (async == true) goto badArgForAsyncCall; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1009 |
__argValues[i].pointerVal = (void *)(__FloatArrayInstPtr(arg)->f_element); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1010 |
} else if (__isDoubleArray(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1011 |
if (async == true) goto badArgForAsyncCall; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1012 |
__argValues[i].pointerVal = (void *)(__DoubleArrayInstPtr(arg)->d_element); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1013 |
} else if (__isString(arg) || __isSymbol(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1014 |
if (async == true) { |
9435 | 1015 |
badArgForAsyncCall: ; |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1016 |
failureCode = @symbol(BadArgForAsyncCall); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1017 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1018 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1019 |
__argValues[i].pointerVal = (void *)(__stringVal(arg)); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1020 |
} else if (__isBytes(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1021 |
char *p = (char *)(__byteArrayVal(arg)); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1022 |
int nInstBytes; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1023 |
OBJ cls; |
9483 | 1024 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1025 |
cls = __qClass(arg); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1026 |
nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1027 |
__argValues[i].pointerVal = p + nInstBytes; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1028 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1029 |
failureCode = @symbol(InvalidArgument); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1030 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1031 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1032 |
argValuePtr = &(__argValues[i].pointerVal);; |
9479 | 1033 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1034 |
} else if (typeSymbol == @symbol(bool)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1035 |
thisType = __get_ffi_type_uint(); |
9342 | 1036 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1037 |
if (arg == true) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1038 |
__argValues[i].iVal = 1; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1039 |
} else if (arg == false) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1040 |
__argValues[i].iVal = 0; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1041 |
} else if (__isSmallInteger(arg)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1042 |
__argValues[i].iVal = __intVal(arg); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1043 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1044 |
__argValues[i].iVal = __unsignedLongIntVal(arg); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1045 |
if (__argValues[i].iVal == 0) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1046 |
failureCode = @symbol(InvalidArgument); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1047 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1048 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1049 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1050 |
argValuePtr = &(__argValues[i].iVal); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1051 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1052 |
if (__isSymbol(typeSymbol) |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1053 |
&& ((argValueClass = __GLOBAL_GET(typeSymbol)) != nil)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1054 |
if (! __isBehaviorLike(argValueClass)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1055 |
failureCode = @symbol(NonBehaviorArgumentType); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1056 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1057 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1058 |
if (! __qIsSubclassOfExternalAddress(argValueClass)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1059 |
failureCode = @symbol(NonExternalAddressArgumentType); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1060 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1061 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1062 |
goto commonPointerTypeArg; /* sorry */ |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1063 |
} else { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1064 |
failureCode = @symbol(UnknownArgumentType); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1065 |
goto getOutOfHere; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1066 |
} |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1067 |
} |
9342 | 1068 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1069 |
__argTypes[i] = thisType; |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1070 |
__argValuePointers[i] = argValuePtr; |
9483 | 1071 |
|
9524 | 1072 |
#ifdef VERBOSE |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1073 |
printf("arg%d: %x\n", i, __argValues[i].iVal); |
9524 | 1074 |
#endif |
9342 | 1075 |
} |
9465 | 1076 |
failureInfo = nil; |
9342 | 1077 |
|
1078 |
__callType = FFI_DEFAULT_ABI; |
|
1079 |
||
1080 |
#ifdef CALLTYPE_FFI_STDCALL |
|
9465 | 1081 |
if (callTypeNumber == @global(CALLTYPE_API)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1082 |
__callType = CALLTYPE_FFI_STDCALL; |
9342 | 1083 |
} |
1084 |
#endif |
|
1085 |
#ifdef CALLTYPE_FFI_V8 |
|
9465 | 1086 |
if (callTypeNumber == @global(CALLTYPE_V8)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1087 |
__callType = CALLTYPE_FFI_V8; |
9342 | 1088 |
} |
1089 |
#endif |
|
1090 |
#ifdef CALLTYPE_FFI_V9 |
|
9465 | 1091 |
if (callTypeNumber == @global(CALLTYPE_V9)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1092 |
__callType = CALLTYPE_FFI_V9; |
9342 | 1093 |
} |
1094 |
#endif |
|
1095 |
#ifdef CALLTYPE_FFI_UNIX64 |
|
9465 | 1096 |
if (callTypeNumber == @global(CALLTYPE_UNIX64)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1097 |
__callType = CALLTYPE_FFI_UNIX64; |
9342 | 1098 |
} |
1099 |
#endif |
|
1100 |
||
1101 |
if (ffi_prep_cif(&__cif, __callType, __numArgsIncludingThis, __returnType, __argTypesIncludingThis) != FFI_OK) { |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1102 |
failureCode = @symbol(FFIPrepareFailed); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1103 |
goto getOutOfHere; |
9342 | 1104 |
} |
9463 | 1105 |
if (async == true) { |
9524 | 1106 |
#ifdef VERBOSE |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1107 |
printf("async call 0x%x\n", codeAddress); |
9524 | 1108 |
#endif |
9436 | 1109 |
#ifdef WIN32 |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1110 |
__STX_C_CALL4( "ffi_call", ffi_call, &__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis); |
9436 | 1111 |
#else |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1112 |
__BEGIN_INTERRUPTABLE__ |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1113 |
ffi_call(&__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1114 |
__END_INTERRUPTABLE__ |
9436 | 1115 |
#endif |
9435 | 1116 |
} else { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1117 |
if (unlimitedStack == true) { |
9524 | 1118 |
#ifdef VERBOSE |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1119 |
printf("UNLIMITEDSTACKCALL call 0x%x\n", codeAddress); |
9524 | 1120 |
#endif |
9463 | 1121 |
#if 0 |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1122 |
__UNLIMITEDSTACKCALL__(ffi_call, &__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis); |
9463 | 1123 |
#endif |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1124 |
} else { |
9524 | 1125 |
#ifdef VERBOSE |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1126 |
printf("call 0x%x\n", codeAddress); |
9524 | 1127 |
#endif |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1128 |
ffi_call(&__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis); |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1129 |
} |
9435 | 1130 |
} |
9524 | 1131 |
#ifdef VERBOSE |
1132 |
printf("retval is %d (0x%x)\n", __returnValue.iVal, __returnValue.iVal); |
|
1133 |
#endif |
|
9479 | 1134 |
if ((returnTypeSymbol == @symbol(sint)) |
1135 |
|| (returnTypeSymbol == @symbol(sint8)) |
|
1136 |
|| (returnTypeSymbol == @symbol(sint16)) |
|
1137 |
|| (returnTypeSymbol == @symbol(sint32))) { |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1138 |
RETURN ( __MKINT(__returnValue.iVal) ); |
9342 | 1139 |
} |
1140 |
if ((returnTypeSymbol == @symbol(uint)) |
|
1141 |
|| (returnTypeSymbol == @symbol(uint8)) |
|
1142 |
|| (returnTypeSymbol == @symbol(uint16)) |
|
1143 |
|| (returnTypeSymbol == @symbol(uint32))) { |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1144 |
RETURN ( __MKUINT(__returnValue.iVal) ); |
9342 | 1145 |
} |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1146 |
if (returnTypeSymbol == @symbol(bool)) { |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1147 |
RETURN ( __returnValue.iVal ? true : false ); |
9342 | 1148 |
} |
1149 |
if (returnTypeSymbol == @symbol(float)) { |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1150 |
RETURN ( __MKFLOAT(__returnValue.fVal )); |
9342 | 1151 |
} |
1152 |
if (returnTypeSymbol == @symbol(double)) { |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1153 |
RETURN ( __MKFLOAT(__returnValue.dVal )); |
9342 | 1154 |
} |
1155 |
if (returnTypeSymbol == @symbol(void)) { |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1156 |
RETURN ( nil ); |
9342 | 1157 |
} |
9463 | 1158 |
if (returnTypeSymbol == @symbol(char)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1159 |
RETURN ( __MKCHARACTER(__returnValue.iVal & 0xFF) ); |
9463 | 1160 |
} |
1161 |
if (returnTypeSymbol == @symbol(wchar)) { |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1162 |
RETURN ( __MKUCHARACTER(__returnValue.iVal & 0xFFFF) ); |
9463 | 1163 |
} |
9346 | 1164 |
if (returnTypeSymbol == @symbol(handle)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1165 |
returnValue = __MKEXTERNALADDRESS(__returnValue.pointerVal); |
9346 | 1166 |
} else if (returnTypeSymbol == @symbol(pointer)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1167 |
returnValue = __MKEXTERNALBYTES(__returnValue.pointerVal); |
9463 | 1168 |
} else if (returnTypeSymbol == @symbol(charPointer)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1169 |
returnValue = __MKSTRING(__returnValue.pointerVal); |
9463 | 1170 |
} else if (returnTypeSymbol == @symbol(wcharPointer)) { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1171 |
returnValue = __MKU16STRING(__returnValue.pointerVal); |
9342 | 1172 |
} else { |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1173 |
failureCode = @symbol(UnknownReturnType2); |
9342 | 1174 |
} |
1175 |
getOutOfHere: ; |
|
1176 |
||
1177 |
#else /* no FFI support */ |
|
1178 |
failureCode = @symbol(FFINotSupported); |
|
1179 |
#endif /* HAVE_FFI */ |
|
1180 |
%}. |
|
1181 |
failureCode notNil ifTrue:[ |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1182 |
self primitiveFailed. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1183 |
^ nil |
9342 | 1184 |
]. |
1185 |
||
9483 | 1186 |
returnType isSymbol ifTrue:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1187 |
returnValueClass notNil ifTrue:[ |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1188 |
self isConstReturnValue ifTrue:[ |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1189 |
returnValue changeClassTo:returnValueClass. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1190 |
^ returnValue |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1191 |
]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1192 |
^ returnValueClass fromExternalAddress:returnValue. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1193 |
]. |
9483 | 1194 |
] ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1195 |
returnType isCPointer ifTrue:[ |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1196 |
returnType baseType isCStruct ifTrue:[ |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1197 |
stClass := Smalltalk classNamed:returnType baseType name. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1198 |
stClass notNil ifTrue:[ |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1199 |
self isConstReturnValue ifTrue:[ |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1200 |
returnValue changeClassTo:returnValueClass. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1201 |
^ returnValue |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1202 |
]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1203 |
^ stClass fromExternalAddress:returnValue. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1204 |
]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1205 |
]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1206 |
returnType baseType isCChar ifTrue:[ |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1207 |
^ returnValue stringAt:1 |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1208 |
]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1209 |
]. |
9342 | 1210 |
]. |
1211 |
||
1212 |
^ returnValue |
|
9463 | 1213 |
|
1214 |
"Created: / 01-08-2006 / 13:56:23 / cg" |
|
9465 | 1215 |
"Modified: / 01-08-2006 / 15:59:44 / cg" |
9342 | 1216 |
! ! |
1217 |
||
8533 | 1218 |
!ExternalLibraryFunction class methodsFor:'documentation'! |
1219 |
||
1220 |
version |
|
10279
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
1221 |
^ '$Header: /cvs/stx/stx/libbasic/ExternalLibraryFunction.st,v 1.48 2006-12-21 06:29:00 ca Exp $' |
8533 | 1222 |
! ! |
9463 | 1223 |
|
1224 |
ExternalLibraryFunction initialize! |