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