author | Claus Gittinger <cg@exept.de> |
Fri, 07 Oct 2011 20:01:43 +0200 | |
changeset 13782 | 1994fe87f21e |
parent 13412 | 9a5f99d66cd9 |
child 14037 | 38519c7f45fa |
permissions | -rw-r--r-- |
8728 | 1 |
" |
2 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
9464 | 3 |
All Rights Reserved |
8728 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
8533 | 12 |
"{ Package: 'stx:libbasic' }" |
13 |
||
14 |
ExternalFunction subclass:#ExternalLibraryFunction |
|
9465 | 15 |
instanceVariableNames:'flags moduleName returnType argumentTypes owningClass' |
10270 | 16 |
classVariableNames:'DLLPATH FLAG_VIRTUAL FLAG_NONVIRTUAL FLAG_ASYNC |
17 |
FLAG_UNLIMITEDSTACK FLAG_RETVAL_IS_CONST CALLTYPE_MASK |
|
18 |
CALLTYPE_API CALLTYPE_C CALLTYPE_OLE CALLTYPE_V8 CALLTYPE_V9 |
|
19 |
CALLTYPE_UNIX64' |
|
9464 | 20 |
poolDictionaries:'' |
21 |
category:'System-Support' |
|
8533 | 22 |
! |
23 |
||
9322 | 24 |
!ExternalLibraryFunction primitiveDefinitions! |
25 |
%{ |
|
26 |
||
9337 | 27 |
#ifdef HAVE_FFI |
28 |
# include <ffi.h> |
|
9322 | 29 |
# define MAX_ARGS 128 |
9365 | 30 |
|
31 |
extern ffi_type *__get_ffi_type_sint(); |
|
32 |
extern ffi_type *__get_ffi_type_sint8(); |
|
33 |
extern ffi_type *__get_ffi_type_sint16(); |
|
34 |
extern ffi_type *__get_ffi_type_sint32(); |
|
35 |
extern ffi_type *__get_ffi_type_sint64(); |
|
36 |
extern ffi_type *__get_ffi_type_uint(); |
|
37 |
extern ffi_type *__get_ffi_type_uint8(); |
|
38 |
extern ffi_type *__get_ffi_type_uint16(); |
|
39 |
extern ffi_type *__get_ffi_type_uint32(); |
|
40 |
extern ffi_type *__get_ffi_type_uint64(); |
|
41 |
extern ffi_type *__get_ffi_type_float(); |
|
42 |
extern ffi_type *__get_ffi_type_double(); |
|
43 |
extern ffi_type *__get_ffi_type_void(); |
|
44 |
extern ffi_type *__get_ffi_type_pointer(); |
|
45 |
||
13412 | 46 |
#else |
47 |
#error "HAVE_FFI not defined!" |
|
9337 | 48 |
#endif |
9322 | 49 |
|
50 |
%} |
|
51 |
! ! |
|
52 |
||
8728 | 53 |
!ExternalLibraryFunction class methodsFor:'documentation'! |
54 |
||
55 |
copyright |
|
56 |
" |
|
57 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
9464 | 58 |
All Rights Reserved |
8728 | 59 |
|
60 |
This software is furnished under a license and may be used |
|
61 |
only in accordance with the terms of that license and with the |
|
62 |
inclusion of the above copyright notice. This software may not |
|
63 |
be provided or otherwise made available to, or used by, any |
|
64 |
other person. No title to or ownership of the software is |
|
65 |
hereby transferred. |
|
66 |
" |
|
9322 | 67 |
! |
68 |
||
9331 | 69 |
documentation |
70 |
" |
|
71 |
instances of me are used to interface to external library functions (as found in a dll/shared object). |
|
72 |
||
12680 | 73 |
Inside a method, when a special external-call pragma such as: |
74 |
<api: bool MessageBeep(uint)> |
|
75 |
||
76 |
is encountered by the parser, the compiler generates a call via |
|
77 |
<correspondingExternalLibraryFunctionObject> invokeWithArguments: argumentArray. |
|
9331 | 78 |
|
79 |
In the invoke method, the library is checked to be loaded (and loaded if not already), |
|
9336 | 80 |
the arguments are converted to C and pushed onto the C-stack, the function is called, |
9331 | 81 |
and finally, the return value is converted back from C to a smalltalk object. |
12680 | 82 |
|
83 |
The parser supports the call-syntax of various other smalltalk dialects: |
|
84 |
Squeak / ST-X: |
|
85 |
<cdecl: [async] [virtual|nonVirtual][const] returnType functionNameStringOrIndex ( argType1..argTypeN ) module: moduleName > |
|
86 |
<apicall: [async] [virtual|nonVirtual][const] returnType functionNameStringOrIndex ( argType1..argTypeN ) module: moduleName > |
|
87 |
||
88 |
Dolphin: |
|
89 |
<stdcall: [virtual|nonVirtual][const] returnType functionNameStringOrIndex argType1..argTypeN> |
|
90 |
<cdecl: [virtual|nonVirtual][const] returnType functionNameStringOrIndex argType1..argTypeN> |
|
91 |
||
92 |
ST/V: |
|
93 |
<api: functionName argType1 .. argTypeN returnType> |
|
94 |
<ccall: functionName argType1 .. argTypeN returnType> |
|
95 |
<ole: vFunctionIndex argType1 .. argTypeN returnType> |
|
96 |
||
97 |
VisualWorks: |
|
98 |
<c: ...> |
|
99 |
<c: #define NAME value> |
|
9331 | 100 |
" |
101 |
! |
|
102 |
||
9322 | 103 |
example |
104 |
" |
|
9464 | 105 |
[exBegin] |
106 |
|f| |
|
9322 | 107 |
|
9464 | 108 |
f := ExternalLibraryFunction new. |
109 |
f name:'MessageBeep' |
|
110 |
module:'user32.dll' |
|
111 |
callType:#WINAPI |
|
112 |
returnType:#boolean |
|
113 |
argumentTypes:#(uint). |
|
9322 | 114 |
|
9464 | 115 |
f invokeWith:1. |
116 |
[exEnd] |
|
9322 | 117 |
" |
8728 | 118 |
! ! |
8533 | 119 |
|
8550 | 120 |
!ExternalLibraryFunction class methodsFor:'instance creation'! |
121 |
||
9465 | 122 |
name:functionName module:moduleName returnType:returnType argumentTypes:argTypes |
8550 | 123 |
^ self new |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
124 |
name:functionName module:moduleName |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
125 |
returnType:returnType argumentTypes:argTypes |
9465 | 126 |
|
127 |
"Created: / 01-08-2006 / 15:19:08 / cg" |
|
9463 | 128 |
! ! |
129 |
||
130 |
!ExternalLibraryFunction class methodsFor:'class initialization'! |
|
131 |
||
11050 | 132 |
addToDllPath:aDirectoryPathName |
133 |
"can be used during initialization, to add more places for dll-loading" |
|
134 |
||
11053 | 135 |
|oldPath| |
136 |
||
137 |
oldPath := self dllPath. |
|
138 |
(oldPath includes:aDirectoryPathName) ifFalse:[ |
|
11586 | 139 |
self dllPath:(oldPath asOrderedCollection copyWith:aDirectoryPathName) |
11053 | 140 |
] |
11050 | 141 |
! |
142 |
||
10270 | 143 |
dllPath |
13337 | 144 |
^ DLLPATH |
10270 | 145 |
! |
146 |
||
147 |
dllPath:aCollectionOfDirectoryPathNames |
|
148 |
DLLPATH := aCollectionOfDirectoryPathNames |
|
149 |
! |
|
150 |
||
9463 | 151 |
initialize |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
152 |
"using inline access to corresponding c--defines to avoid duplicate places of knowledge" |
13337 | 153 |
|
154 |
DLLPATH isNil ifTrue:[ |
|
155 |
DLLPATH := #('.'). |
|
156 |
FLAG_VIRTUAL := %{ __MKSMALLINT(__EXTL_FLAG_VIRTUAL) %}. "/ a virtual c++ call |
|
157 |
FLAG_NONVIRTUAL := %{ __MKSMALLINT(__EXTL_FLAG_NONVIRTUAL) %}. "/ a non-virtual c++ call |
|
158 |
FLAG_UNLIMITEDSTACK := %{ __MKSMALLINT(__EXTL_FLAG_UNLIMITEDSTACK) %}. "/ unlimitedstack under unix |
|
159 |
FLAG_ASYNC := %{ __MKSMALLINT(__EXTL_FLAG_ASYNC) %}. "/ async under win32 |
|
160 |
FLAG_RETVAL_IS_CONST := %{ __MKSMALLINT(__EXTL_FLAG_RETVAL_IS_CONST) %}."/ return value is not to be registered for finalization |
|
9463 | 161 |
|
13337 | 162 |
CALLTYPE_API := %{ __MKSMALLINT(__EXTL_CALLTYPE_API) %}. "/ WINAPI-call (win32 only) |
163 |
CALLTYPE_C := %{ __MKSMALLINT(__EXTL_CALLTYPE_C) %}. "/ regular C-call (the default) |
|
164 |
CALLTYPE_V8 := %{ __MKSMALLINT(__EXTL_CALLTYPE_V8) %}. "/ v8 call (sparc only) |
|
165 |
CALLTYPE_V9 := %{ __MKSMALLINT(__EXTL_CALLTYPE_V9) %}. "/ v9 call (sparc only) |
|
166 |
CALLTYPE_UNIX64 := %{ __MKSMALLINT(__EXTL_CALLTYPE_UNIX64) %}. "/ unix64 call (alpha only) |
|
9463 | 167 |
|
13337 | 168 |
CALLTYPE_MASK := %{ __MKSMALLINT(__EXTL_CALLTYPE_MASK) %}. |
169 |
]. |
|
9465 | 170 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
171 |
" |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
172 |
self initialize |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
173 |
" |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
174 |
|
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
175 |
"Modified: / 03-10-2006 / 21:27:47 / cg" |
11053 | 176 |
! |
177 |
||
178 |
removeFromDllPath:aDirectoryPathName |
|
179 |
"remove added places from dll-loading" |
|
180 |
||
181 |
|oldPath| |
|
182 |
||
183 |
oldPath := self dllPath. |
|
184 |
self dllPath:(oldPath asOrderedCollection copyWithout:aDirectoryPathName) |
|
185 |
||
186 |
" |
|
187 |
self dllPath. |
|
11586 | 188 |
self addToDllPath:'C:\aaa\bbb'. |
11053 | 189 |
self dllPath. |
190 |
self removeFromDllPath:'C:\aaa\bbb'. |
|
191 |
self dllPath. |
|
192 |
" |
|
8550 | 193 |
! ! |
194 |
||
9321 | 195 |
!ExternalLibraryFunction class methodsFor:'constants'! |
196 |
||
197 |
callTypeAPI |
|
9463 | 198 |
^ CALLTYPE_API |
9321 | 199 |
|
9463 | 200 |
"Modified: / 01-08-2006 / 13:44:41 / cg" |
9435 | 201 |
! |
202 |
||
9321 | 203 |
callTypeC |
9463 | 204 |
^ CALLTYPE_C |
9321 | 205 |
|
9463 | 206 |
"Modified: / 01-08-2006 / 13:44:49 / cg" |
9435 | 207 |
! |
208 |
||
9321 | 209 |
callTypeCDecl |
9463 | 210 |
^ CALLTYPE_C |
9321 | 211 |
|
9463 | 212 |
"Modified: / 01-08-2006 / 13:44:52 / cg" |
9435 | 213 |
! |
214 |
||
10619 | 215 |
callTypeMASK |
216 |
^ CALLTYPE_MASK |
|
217 |
||
218 |
"Modified: / 01-08-2006 / 13:44:57 / cg" |
|
219 |
! |
|
220 |
||
9321 | 221 |
callTypeOLE |
9463 | 222 |
^ CALLTYPE_OLE |
9435 | 223 |
|
9463 | 224 |
"Modified: / 01-08-2006 / 13:44:57 / cg" |
9321 | 225 |
! ! |
226 |
||
227 |
!ExternalLibraryFunction methodsFor:'accessing'! |
|
228 |
||
229 |
argumentTypes |
|
230 |
^ argumentTypes |
|
9463 | 231 |
! |
232 |
||
11426 | 233 |
argumentTypesString |
11586 | 234 |
^ String |
235 |
streamContents:[:s | |
|
236 |
argumentTypes do:[:eachArgType | |
|
237 |
eachArgType printOn:s. |
|
238 |
] separatedBy:[ |
|
239 |
s nextPutAll:','. |
|
240 |
]. |
|
241 |
]. |
|
11426 | 242 |
! |
243 |
||
9463 | 244 |
beAsync |
245 |
"let this execute in a separate thread, in par with the other execution thread(s). |
|
246 |
Ignored under unix/linux (until those support multiple threads too)." |
|
247 |
||
248 |
flags := (flags ? 0) bitOr: FLAG_ASYNC. |
|
249 |
||
250 |
"Created: / 01-08-2006 / 13:42:38 / cg" |
|
251 |
! |
|
252 |
||
9465 | 253 |
beCallTypeAPI |
254 |
flags := (flags ? 0) bitOr: CALLTYPE_API. |
|
255 |
||
256 |
"Created: / 01-08-2006 / 15:12:40 / cg" |
|
257 |
! |
|
258 |
||
259 |
beCallTypeC |
|
260 |
flags := (flags ? 0) bitOr: CALLTYPE_C. |
|
261 |
||
262 |
"Created: / 01-08-2006 / 15:12:40 / cg" |
|
263 |
! |
|
264 |
||
10481 | 265 |
beCallTypeOLE |
266 |
flags := (flags ? 0) bitOr: FLAG_VIRTUAL. |
|
267 |
||
268 |
"Created: / 01-08-2006 / 15:12:40 / cg" |
|
269 |
! |
|
270 |
||
9465 | 271 |
beCallTypeUNIX64 |
272 |
flags := (flags ? 0) bitOr: CALLTYPE_UNIX64. |
|
273 |
||
274 |
"Created: / 01-08-2006 / 15:13:38 / cg" |
|
275 |
! |
|
276 |
||
277 |
beCallTypeV8 |
|
278 |
flags := (flags ? 0) bitOr: CALLTYPE_V8. |
|
279 |
||
280 |
"Created: / 01-08-2006 / 15:13:28 / cg" |
|
281 |
! |
|
282 |
||
283 |
beCallTypeV9 |
|
284 |
flags := (flags ? 0) bitOr: CALLTYPE_V9. |
|
285 |
||
286 |
"Created: / 01-08-2006 / 15:13:31 / cg" |
|
287 |
! |
|
288 |
||
289 |
beCallTypeWINAPI |
|
290 |
self beCallTypeAPI |
|
291 |
||
292 |
"Modified: / 01-08-2006 / 15:14:02 / cg" |
|
293 |
! |
|
294 |
||
9525 | 295 |
beConstReturnValue |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
296 |
"specify that a pointer return value is not to be finalized |
9525 | 297 |
(i.e. points to static data or data which is freed by c)" |
298 |
||
299 |
flags := (flags ? 0) bitOr: FLAG_RETVAL_IS_CONST. |
|
300 |
||
301 |
"Created: / 01-08-2006 / 13:56:48 / cg" |
|
302 |
! |
|
303 |
||
9463 | 304 |
beNonVirtualCPP |
305 |
"specify this as a non-virtual c++-function" |
|
306 |
||
307 |
flags := (flags ? 0) bitOr: FLAG_NONVIRTUAL. |
|
308 |
||
309 |
"Created: / 01-08-2006 / 13:56:44 / cg" |
|
310 |
! |
|
311 |
||
312 |
beUnlimitedStack |
|
313 |
"let this execute on the c-stack (as opposed to the thread-stack) |
|
314 |
for unlimited auto-sized-stack under unix/linux. |
|
315 |
Ignored under windows." |
|
316 |
||
317 |
flags := (flags ? 0) bitOr: FLAG_UNLIMITEDSTACK. |
|
318 |
||
319 |
"Created: / 01-08-2006 / 13:41:54 / cg" |
|
320 |
! |
|
321 |
||
322 |
beVirtualCPP |
|
323 |
"specify this as a virtual c++-function" |
|
324 |
||
325 |
flags := (flags ? 0) bitOr: FLAG_VIRTUAL. |
|
326 |
||
327 |
"Created: / 01-08-2006 / 13:56:48 / cg" |
|
328 |
! |
|
329 |
||
9465 | 330 |
callTypeNumber |
331 |
^ (flags ? 0) bitAnd: CALLTYPE_MASK. |
|
332 |
||
333 |
"Created: / 01-08-2006 / 15:12:10 / cg" |
|
334 |
! |
|
335 |
||
9463 | 336 |
isAsync |
337 |
"is this executed in a separate thread, in par with the other execution thread(s) ?" |
|
338 |
||
339 |
^ (flags ? 0) bitTest: FLAG_ASYNC. |
|
340 |
||
341 |
"Created: / 01-08-2006 / 13:46:53 / cg" |
|
342 |
! |
|
343 |
||
9519 | 344 |
isCPPFunction |
345 |
"is this a virtual or non-virtual c++-function ?" |
|
346 |
||
347 |
^ (flags ? 0) bitTest: (FLAG_VIRTUAL bitOr: FLAG_NONVIRTUAL). |
|
348 |
||
349 |
"Created: / 01-08-2006 / 13:56:54 / cg" |
|
350 |
! |
|
351 |
||
9465 | 352 |
isCallTypeAPI |
353 |
^ ((flags ? 0) bitAnd: CALLTYPE_MASK) == CALLTYPE_API. |
|
354 |
||
355 |
"Created: / 01-08-2006 / 15:21:16 / cg" |
|
356 |
! |
|
357 |
||
358 |
isCallTypeC |
|
359 |
^ ((flags ? 0) bitAnd: CALLTYPE_MASK) == CALLTYPE_C. |
|
360 |
||
361 |
"Created: / 01-08-2006 / 15:21:23 / cg" |
|
362 |
! |
|
363 |
||
10483 | 364 |
isCallTypeOLE |
365 |
^ ((flags ? 0) bitTest: FLAG_VIRTUAL). |
|
366 |
||
367 |
"Created: / 01-08-2006 / 15:21:23 / cg" |
|
368 |
! |
|
369 |
||
9525 | 370 |
isConstReturnValue |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
371 |
"is the pointer return value not to be finalized |
9525 | 372 |
(i.e. points to static data or data which is freed by c)" |
373 |
||
374 |
^ (flags ? 0) bitTest: FLAG_RETVAL_IS_CONST. |
|
375 |
||
376 |
"Created: / 01-08-2006 / 13:56:48 / cg" |
|
377 |
! |
|
378 |
||
9463 | 379 |
isNonVirtualCPP |
380 |
"is this a non-virtual c++-function ?" |
|
381 |
||
382 |
^ (flags ? 0) bitTest: FLAG_NONVIRTUAL. |
|
383 |
||
384 |
"Created: / 01-08-2006 / 13:56:51 / cg" |
|
385 |
! |
|
386 |
||
387 |
isUnlimitedStack |
|
388 |
"will this execute on the c-stack (as opposed to the thread-stack) |
|
389 |
for unlimited auto-sized-stack under unix/linux. |
|
390 |
Ignored under windows." |
|
391 |
||
392 |
^ (flags ? 0) bitTest: FLAG_UNLIMITEDSTACK. |
|
393 |
||
394 |
"Created: / 01-08-2006 / 14:17:07 / cg" |
|
395 |
! |
|
396 |
||
397 |
isVirtualCPP |
|
398 |
"is this a virtual c++-function ?" |
|
399 |
||
400 |
^ (flags ? 0) bitTest: FLAG_VIRTUAL. |
|
401 |
||
402 |
"Created: / 01-08-2006 / 13:56:54 / cg" |
|
10483 | 403 |
! |
404 |
||
11426 | 405 |
moduleName |
406 |
^ moduleName |
|
407 |
! |
|
408 |
||
10484 | 409 |
returnType |
410 |
^ returnType |
|
411 |
! |
|
412 |
||
10483 | 413 |
vtableIndex |
414 |
name isNumber ifFalse:[^ nil]. |
|
415 |
^ name. |
|
9321 | 416 |
! ! |
417 |
||
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
418 |
!ExternalLibraryFunction methodsFor:'invoking'! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
419 |
|
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
420 |
invoke |
9321 | 421 |
self hasCode ifFalse:[ |
11586 | 422 |
self prepareInvoke. |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
423 |
]. |
10440 | 424 |
^ self invokeFFIWithArguments:nil |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
425 |
! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
426 |
|
9347 | 427 |
invokeCPPVirtualOn:anInstance |
9341 | 428 |
self hasCode ifFalse:[ |
11586 | 429 |
self prepareInvoke. |
9341 | 430 |
]. |
10440 | 431 |
^ self invokeCPPVirtualFFIOn:anInstance withArguments:nil |
9341 | 432 |
! |
433 |
||
9347 | 434 |
invokeCPPVirtualOn:instance with:arg |
9341 | 435 |
self hasCode ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
436 |
self prepareInvoke. |
9341 | 437 |
]. |
9347 | 438 |
^ self invokeCPPVirtualFFIOn:instance withArguments:(Array with:arg) |
9341 | 439 |
! |
440 |
||
9347 | 441 |
invokeCPPVirtualOn:instance with:arg1 with:arg2 |
9341 | 442 |
self hasCode ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
443 |
self prepareInvoke. |
9341 | 444 |
]. |
9347 | 445 |
^ self invokeCPPVirtualFFIOn:instance withArguments:(Array with:arg1 with:arg2) |
9341 | 446 |
! |
447 |
||
9347 | 448 |
invokeCPPVirtualOn:instance with:arg1 with:arg2 with:arg3 |
9341 | 449 |
self hasCode ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
450 |
self prepareInvoke. |
9341 | 451 |
]. |
9347 | 452 |
^ self invokeCPPVirtualFFIOn:instance withArguments:(Array with:arg1 with:arg2 with:arg3) |
9341 | 453 |
! |
454 |
||
9347 | 455 |
invokeCPPVirtualOn:instance with:arg1 with:arg2 with:arg3 with:arg4 |
9341 | 456 |
self hasCode ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
457 |
self prepareInvoke. |
9341 | 458 |
]. |
9347 | 459 |
^ self invokeCPPVirtualFFIOn:instance withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
9341 | 460 |
! |
461 |
||
10481 | 462 |
invokeCPPVirtualOn:instance withArguments:args |
463 |
self hasCode ifFalse:[ |
|
11586 | 464 |
self prepareInvoke. |
10481 | 465 |
]. |
466 |
^ self invokeCPPVirtualFFIOn:instance withArguments:args |
|
467 |
! |
|
468 |
||
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
469 |
invokeWith:arg |
9321 | 470 |
self hasCode ifFalse:[ |
9464 | 471 |
self prepareInvoke. |
9321 | 472 |
]. |
473 |
^ self invokeFFIWithArguments:(Array with:arg) |
|
474 |
! |
|
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
475 |
|
9321 | 476 |
invokeWith:arg1 with:arg2 |
477 |
self hasCode ifFalse:[ |
|
9464 | 478 |
self prepareInvoke. |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
479 |
]. |
9321 | 480 |
^ self invokeFFIWithArguments:(Array with:arg1 with:arg2) |
481 |
! |
|
482 |
||
483 |
invokeWith:arg1 with:arg2 with:arg3 |
|
484 |
self hasCode ifFalse:[ |
|
9464 | 485 |
self prepareInvoke. |
9321 | 486 |
]. |
487 |
^ self invokeFFIWithArguments:(Array with:arg1 with:arg2 with:arg3) |
|
488 |
! |
|
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
489 |
|
9321 | 490 |
invokeWith:arg1 with:arg2 with:arg3 with:arg4 |
491 |
self hasCode ifFalse:[ |
|
9464 | 492 |
self prepareInvoke. |
9321 | 493 |
]. |
494 |
^ self invokeFFIWithArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
|
495 |
! |
|
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
496 |
|
9321 | 497 |
invokeWithArguments:argArray |
498 |
self hasCode ifFalse:[ |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
499 |
self prepareInvoke. |
9321 | 500 |
]. |
9465 | 501 |
^ self invokeFFIwithArguments:argArray forCPPInstance:nil |
502 |
||
503 |
"Modified: / 01-08-2006 / 16:04:08 / cg" |
|
9321 | 504 |
! ! |
505 |
||
506 |
!ExternalLibraryFunction methodsFor:'printing'! |
|
507 |
||
508 |
printOn:aStream |
|
509 |
aStream nextPutAll:'<'. |
|
9465 | 510 |
self isCallTypeAPI ifTrue:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
511 |
'API:' printOn:aStream. |
9465 | 512 |
] ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
513 |
'C:' printOn:aStream. |
9465 | 514 |
]. |
9321 | 515 |
aStream nextPutAll:' '. |
516 |
name printOn:aStream. |
|
9465 | 517 |
moduleName notNil ifTrue:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
518 |
aStream nextPutAll:' module:'. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
519 |
moduleName printOn:aStream. |
9465 | 520 |
]. |
9321 | 521 |
aStream nextPutAll:'>'. |
9465 | 522 |
|
523 |
"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
|
524 |
! ! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
525 |
|
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
526 |
!ExternalLibraryFunction methodsFor:'private'! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
527 |
|
10213 | 528 |
adjustTypes |
529 |
argumentTypes notNil ifTrue:[ |
|
530 |
argumentTypes := argumentTypes collect:[:argType | self ffiTypeSymbolForType:argType]. |
|
531 |
]. |
|
532 |
returnType := self ffiTypeSymbolForType:returnType. |
|
533 |
! |
|
534 |
||
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
535 |
linkToModule |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
536 |
"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
|
537 |
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
|
538 |
|
9465 | 539 |
|handle moduleNameUsed functionName| |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
540 |
|
10481 | 541 |
name isNumber ifTrue:[ |
13782
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
542 |
self isCPPFunction ifTrue:[ |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
543 |
"/ no need to load a dll. |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
544 |
^ self |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
545 |
] |
10481 | 546 |
]. |
547 |
||
13782
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
548 |
"/ in some other smalltalks, there is no moduleName in the ffi-spec; |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
549 |
"/ instead, the class provides the libraryName... |
9465 | 550 |
(moduleNameUsed := moduleName) isNil ifTrue:[ |
13782
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
551 |
owningClass isNil ifTrue:[ |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
552 |
self error:'Missing moduleName'. |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
553 |
]. |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
554 |
moduleNameUsed := owningClass theNonMetaclass libraryName asSymbol. |
9321 | 555 |
]. |
11586 | 556 |
moduleHandle isNil ifTrue:[ |
13782
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
557 |
handle := self loadLibrary:moduleNameUsed. |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
558 |
handle isNil ifTrue:[ |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
559 |
self error:('Cannot load module: "%1"' bindWith: moduleNameUsed). |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
560 |
]. |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
561 |
moduleHandle := handle. |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
562 |
]. |
9341 | 563 |
name isNumber ifFalse:[ |
13782
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
564 |
functionName := name. |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
565 |
(moduleHandle getFunctionAddress:functionName into:self) isNil ifTrue:[ |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
566 |
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
|
567 |
|
13782
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
568 |
(moduleHandle getFunctionAddress:functionName into:self) isNil ifTrue:[ |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
569 |
moduleHandle := nil. |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
570 |
self error:'Missing function: ', name, ' in module: ', moduleNameUsed. |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
571 |
]. |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
572 |
]. |
9321 | 573 |
]. |
9392 | 574 |
|
9465 | 575 |
"Modified: / 01-08-2006 / 16:24:14 / cg" |
13782
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
576 |
"Modified (comment): / 07-10-2011 / 16:43:11 / cg" |
9321 | 577 |
! |
578 |
||
10270 | 579 |
loadLibrary:dllName |
12436 | 580 |
|handle nameString filename| |
10279
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
581 |
|
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
582 |
filename := dllName asFilename. |
12436 | 583 |
nameString := filename name. |
10279
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
584 |
|
12937 | 585 |
"try to load, maybe the system knows where to find the dll" |
586 |
handle := ObjectFileLoader loadDynamicObject:filename. |
|
587 |
handle notNil ifTrue:[^ handle ]. |
|
588 |
||
12436 | 589 |
filename isAbsolute ifFalse:[ |
13333
1463a5e4f9fa
comment/format in: #loadLibrary:
Stefan Vogel <sv@exept.de>
parents:
12937
diff
changeset
|
590 |
"First ask the class defining the ExternalFunction for the location of the dlls ..." |
13334 | 591 |
owningClass notNil ifTrue:[ |
592 |
owningClass dllPath do:[:eachDirectory | |
|
593 |
handle := ObjectFileLoader |
|
594 |
loadDynamicObject:(eachDirectory asFilename construct:nameString) pathName. |
|
595 |
handle notNil ifTrue:[^ handle ]. |
|
596 |
]. |
|
12937 | 597 |
]. |
598 |
".. then ask the system" |
|
599 |
self class dllPath do:[:eachDirectory | |
|
600 |
handle := ObjectFileLoader |
|
601 |
loadDynamicObject:(eachDirectory asFilename construct:nameString) pathName. |
|
602 |
handle notNil ifTrue:[^ handle ]. |
|
603 |
]. |
|
10279
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
604 |
]. |
10270 | 605 |
|
12436 | 606 |
filename suffix isEmpty ifTrue:[ |
12937 | 607 |
"/ try again with the OS-specific dll-extension |
608 |
^ self loadLibrary:(filename withSuffix:ObjectFileLoader sharedLibrarySuffix) |
|
10270 | 609 |
]. |
12436 | 610 |
|
10270 | 611 |
^ nil |
612 |
! |
|
613 |
||
9321 | 614 |
prepareInvoke |
10270 | 615 |
(moduleHandle isNil or:[self hasCode not]) ifTrue:[ |
12450 | 616 |
self linkToModule. |
617 |
self adjustTypes. |
|
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
618 |
]. |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
619 |
! ! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
620 |
|
8550 | 621 |
!ExternalLibraryFunction methodsFor:'private-accessing'! |
622 |
||
9327 | 623 |
ffiTypeSymbolForType:aType |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
624 |
"map type to one of the ffi-supported ones: |
12657
7da296a8eeb6
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12656
diff
changeset
|
625 |
sint8, sint16, sint32, sint64 |
7da296a8eeb6
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12656
diff
changeset
|
626 |
uint8, uint16, uint32, uint64 |
7da296a8eeb6
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12656
diff
changeset
|
627 |
bool void pointer handle |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
628 |
" |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
629 |
|
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
630 |
aType == #sint8 ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
631 |
aType == #sint16 ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
632 |
aType == #sint32 ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
633 |
aType == #sint64 ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
634 |
aType == #uint8 ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
635 |
aType == #uint16 ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
636 |
aType == #uint32 ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
637 |
aType == #uint64 ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
638 |
aType == #double ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
639 |
aType == #float ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
640 |
aType == #char ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
641 |
aType == #void ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
642 |
aType == #bool ifTrue:[^ aType ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
643 |
aType == #pointer ifTrue:[^ aType ]. |
12657
7da296a8eeb6
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12656
diff
changeset
|
644 |
aType == #charPointer ifTrue:[^ aType ]. |
7da296a8eeb6
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12656
diff
changeset
|
645 |
aType == #wcharPointer ifTrue:[^ aType ]. |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
646 |
|
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
647 |
aType == #int8 ifTrue:[^ #sint8 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
648 |
aType == #int16 ifTrue:[^ #sint16 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
649 |
aType == #int32 ifTrue:[^ #sint32 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
650 |
aType == #int64 ifTrue:[^ #sint64 ]. |
12450 | 651 |
|
652 |
aType == #voidPointer ifTrue:[^ #pointer ]. |
|
653 |
aType == #uint8Pointer ifTrue:[^ #pointer ]. |
|
12449
ca958524b42f
comment/format in: #prepareInvoke
Claus Gittinger <cg@exept.de>
parents:
12436
diff
changeset
|
654 |
aType == #voidPointerPointer ifTrue:[^ #pointer ]. |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
655 |
|
10213 | 656 |
aType == #short ifTrue:[^ #sint16 ]. |
11586 | 657 |
aType == #long ifTrue:[^ #long ]. |
658 |
aType == #int ifTrue:[^ #int ]. |
|
659 |
aType == #uint ifTrue:[^ #uint ]. |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
660 |
aType == #ushort ifTrue:[^ #uint16 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
661 |
aType == #unsignedShort ifTrue:[^ #uint16 ]. |
11586 | 662 |
aType == #ulong ifTrue:[^ #ulong ]. |
663 |
aType == #unsignedLong ifTrue:[^ #ulong ]. |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
664 |
aType == #uchar ifTrue:[^ #uint8 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
665 |
aType == #unsignedChar ifTrue:[^ #uint8 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
666 |
aType == #byte ifTrue:[^ #uint8 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
667 |
aType == #dword ifTrue:[^ #uint32 ]. |
10213 | 668 |
aType == #sdword ifTrue:[^ #sint32 ]. |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
669 |
aType == #word ifTrue:[^ #uint16 ]. |
10213 | 670 |
aType == #sword ifTrue:[^ #sint16 ]. |
12503
cb1a875c3d63
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12474
diff
changeset
|
671 |
aType == #longlong ifTrue:[^ #sint64 ]. |
12450 | 672 |
aType == #longLong ifTrue:[^ #sint64 ]. |
12503
cb1a875c3d63
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12474
diff
changeset
|
673 |
aType == #ulonglong ifTrue:[^ #uint64 ]. |
12450 | 674 |
aType == #ulongLong ifTrue:[^ #uint64 ]. |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
675 |
aType == #handle ifTrue:[^ #pointer ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
676 |
aType == #lpstr ifTrue:[^ #charPointer ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
677 |
aType == #hresult ifTrue:[^ #uint32 ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
678 |
aType == #boolean ifTrue:[^ #bool ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
679 |
aType == #ulongReturn ifTrue:[^ #uint32 ]. "/ TODO - care for 64bit machines |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
680 |
aType == #none ifTrue:[^ #void ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
681 |
aType == #struct ifTrue:[^ #pointer ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
682 |
aType == #structIn ifTrue:[^ #pointer ]. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
683 |
aType == #structOut ifTrue:[^ #pointer ]. |
10981 | 684 |
aType == #unsigned ifTrue:[^ #uint ]. |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
685 |
|
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
686 |
(aType isString or:[aType isSymbol]) ifFalse:[ |
12657
7da296a8eeb6
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12656
diff
changeset
|
687 |
CType isNil ifTrue:[ |
7da296a8eeb6
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12656
diff
changeset
|
688 |
self error:'unknown type'. |
7da296a8eeb6
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12656
diff
changeset
|
689 |
]. |
7da296a8eeb6
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12656
diff
changeset
|
690 |
^ aType typeSymbol. |
9483 | 691 |
]. |
692 |
||
12579
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
693 |
(aType endsWith:'*') ifTrue:[ |
12657
7da296a8eeb6
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12656
diff
changeset
|
694 |
^ #pointer. |
12579
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
695 |
]. |
12449
ca958524b42f
comment/format in: #prepareInvoke
Claus Gittinger <cg@exept.de>
parents:
12436
diff
changeset
|
696 |
(aType endsWith:'Pointer') ifTrue:[ |
12657
7da296a8eeb6
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12656
diff
changeset
|
697 |
^ #pointer. |
12449
ca958524b42f
comment/format in: #prepareInvoke
Claus Gittinger <cg@exept.de>
parents:
12436
diff
changeset
|
698 |
]. |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
699 |
^ aType |
10625 | 700 |
|
701 |
"Modified: / 14-06-2007 / 17:21:42 / cg" |
|
9322 | 702 |
! |
703 |
||
9466 | 704 |
name:functionNameOrVirtualIndex module:aModuleName returnType:aReturnType argumentTypes:argTypes |
705 |
name := functionNameOrVirtualIndex. |
|
706 |
functionNameOrVirtualIndex isNumber ifTrue:[ |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
707 |
self beVirtualCPP. |
9466 | 708 |
]. |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
709 |
moduleName := aModuleName. |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
710 |
returnType := aReturnType. |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
711 |
argumentTypes := argTypes. |
9465 | 712 |
|
713 |
"Created: / 01-08-2006 / 15:19:52 / cg" |
|
9466 | 714 |
"Modified: / 02-08-2006 / 17:20:13 / cg" |
9465 | 715 |
! |
716 |
||
11426 | 717 |
owningClass |
718 |
^ owningClass |
|
719 |
! |
|
720 |
||
9465 | 721 |
owningClass:aClass |
722 |
owningClass := aClass. |
|
723 |
||
724 |
"Created: / 01-08-2006 / 15:22:50 / cg" |
|
10603 | 725 |
! |
726 |
||
11586 | 727 |
setModuleName:aModuleName |
10603 | 728 |
aModuleName ~= moduleName ifTrue:[ |
11586 | 729 |
self code:nil. |
730 |
moduleHandle := nil. |
|
731 |
moduleName := aModuleName. |
|
10603 | 732 |
]. |
733 |
||
734 |
"Created: / 07-06-2007 / 10:20:17 / cg" |
|
8550 | 735 |
! ! |
736 |
||
9342 | 737 |
!ExternalLibraryFunction methodsFor:'private-invoking'! |
738 |
||
9347 | 739 |
invokeCPPVirtualFFIOn:instance withArguments:arguments |
9463 | 740 |
^ self invokeFFIwithArguments:arguments forCPPInstance:instance |
741 |
||
742 |
"Modified: / 01-08-2006 / 13:55:30 / cg" |
|
9342 | 743 |
! |
744 |
||
9347 | 745 |
invokeFFIWithArguments:arguments |
9463 | 746 |
^ self invokeFFIwithArguments:arguments forCPPInstance:nil |
747 |
||
748 |
"Modified: / 01-08-2006 / 13:55:35 / cg" |
|
9347 | 749 |
! |
750 |
||
10440 | 751 |
invokeFFIwithArguments:argumentsOrNil forCPPInstance:aCPlusPlusObjectOrNil |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
752 |
|argTypeSymbols returnTypeSymbol failureCode failureInfo returnValue stClass vtOffset |
12579
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
753 |
virtual async unlimitedStack callTypeNumber returnValueClass argValueClass |
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
754 |
oldReturnType oldArgumentTypes |
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
755 |
| |
9342 | 756 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
757 |
argTypeSymbols := argumentTypes. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
758 |
returnTypeSymbol := returnType. |
9346 | 759 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
760 |
virtual := self isVirtualCPP. |
9524 | 761 |
(virtual "or:[self isNonVirtualCPP]") ifTrue:[ |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
762 |
aCPlusPlusObjectOrNil isNil ifTrue:[ |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
763 |
"/ must have a c++ object instance |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
764 |
self primitiveFailed. |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
765 |
]. |
9463 | 766 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
767 |
"/ and it must be a kind of ExternalStructure !! |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
768 |
(aCPlusPlusObjectOrNil isKindOf:ExternalStructure) ifFalse:[ |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
769 |
self primitiveFailed. |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
770 |
]. |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
771 |
virtual ifTrue:[ |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
772 |
vtOffset := name. |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
773 |
(vtOffset between:0 and:10000) ifFalse:[ |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
774 |
self primitiveFailed. |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
775 |
] |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
776 |
]. |
9463 | 777 |
] ifFalse:[ |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
778 |
aCPlusPlusObjectOrNil notNil ifTrue:[ |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
779 |
"/ must NOT have a c++ object instance |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
780 |
self primitiveFailed. |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
781 |
]. |
9342 | 782 |
]. |
9463 | 783 |
async := self isAsync. |
784 |
unlimitedStack := self isUnlimitedStack. |
|
9465 | 785 |
callTypeNumber := self callTypeNumber. |
10512 | 786 |
"/ Transcript show:name; show:' async:'; showCR:async. |
9342 | 787 |
|
9459
6cd520c582b3
change from unlimited to big stack, to allow for interrupts to be handled
ca
parents:
9436
diff
changeset
|
788 |
%{ /* STACK: 100000 */ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
789 |
#ifdef HAVE_FFI |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
790 |
# ifdef __GNUC__ |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
791 |
# define HAS_LONGLONG |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
792 |
# endif |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
793 |
# if defined(__BORLANDC__) || defined(__VISUALC__) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
794 |
# define HAS_INT64 |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
795 |
# endif |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
796 |
|
9342 | 797 |
ffi_cif __cif; |
798 |
ffi_type *__argTypesIncludingThis[MAX_ARGS+1]; |
|
799 |
ffi_type **__argTypes = __argTypesIncludingThis; |
|
800 |
ffi_type *__returnType = NULL; |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
801 |
|
9342 | 802 |
union u { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
803 |
int iVal; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
804 |
float fVal; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
805 |
double dVal; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
806 |
void *pointerVal; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
807 |
# if defined(HAS_LONGLONG) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
808 |
long long longLongVal; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
809 |
# else |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
810 |
# ifdef HAS_INT64 |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
811 |
__int64__ longLongVal; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
812 |
# else |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
813 |
struct ll { long low; long hi; } longLongVal; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
814 |
# endif |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
815 |
# endif |
9342 | 816 |
}; |
817 |
union u __argValuesIncludingThis[MAX_ARGS+1]; |
|
818 |
union u *__argValues = __argValuesIncludingThis; |
|
819 |
union u __returnValue; |
|
820 |
void *__argValuePointersIncludingThis[MAX_ARGS+1]; |
|
821 |
void **__argValuePointers = __argValuePointersIncludingThis; |
|
822 |
void *__returnValuePointer; |
|
823 |
int __numArgs, __numArgsIncludingThis; |
|
824 |
static int null = 0; |
|
825 |
int i; |
|
826 |
ffi_abi __callType = FFI_DEFAULT_ABI; |
|
827 |
VOIDFUNC codeAddress = (VOIDFUNC)__INST(code_); |
|
10440 | 828 |
int __numArgsWanted; |
12579
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
829 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
830 |
# define __FAIL__(fcode) \ |
10603 | 831 |
{ \ |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
832 |
failureCode = fcode; goto getOutOfHere; \ |
10603 | 833 |
} |
9342 | 834 |
|
10440 | 835 |
if (argumentsOrNil == nil) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
836 |
__numArgs = 0; |
10440 | 837 |
} else if (__isArray(argumentsOrNil)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
838 |
__numArgs = __arraySize(argumentsOrNil); |
9342 | 839 |
} else { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
840 |
__FAIL__(@symbol(BadArgumentVector)) |
10440 | 841 |
} |
842 |
if (argTypeSymbols == nil) { |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
843 |
__numArgsWanted = 0; |
10440 | 844 |
} else if (__isArray(argTypeSymbols)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
845 |
__numArgsWanted = __arraySize(argTypeSymbols); |
10440 | 846 |
} else { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
847 |
__FAIL__(@symbol(BadArgumentTypeVector)) |
10440 | 848 |
} |
849 |
||
850 |
if (__numArgs != __numArgsWanted) { |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
851 |
__FAIL__(@symbol(ArgumentCountMismatch)) |
9342 | 852 |
} |
853 |
if (__numArgs > MAX_ARGS) { |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
854 |
__FAIL__(@symbol(TooManyArguments)) |
9342 | 855 |
} |
856 |
||
857 |
/* |
|
858 |
* validate the return type |
|
859 |
*/ |
|
860 |
__returnValuePointer = &__returnValue; |
|
9479 | 861 |
|
9483 | 862 |
if (returnTypeSymbol == @symbol(voidPointer)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
863 |
returnTypeSymbol = @symbol(handle); |
9483 | 864 |
} |
9479 | 865 |
|
9342 | 866 |
if (returnTypeSymbol == @symbol(int)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
867 |
__returnType = __get_ffi_type_sint(); |
9342 | 868 |
} else if (returnTypeSymbol == @symbol(uint)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
869 |
__returnType = __get_ffi_type_uint(); |
9479 | 870 |
} else if (returnTypeSymbol == @symbol(uint8)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
871 |
__returnType = __get_ffi_type_uint8(); |
9479 | 872 |
} else if (returnTypeSymbol == @symbol(uint16)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
873 |
__returnType = __get_ffi_type_uint16(); |
9479 | 874 |
} else if (returnTypeSymbol == @symbol(uint32)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
875 |
__returnType = __get_ffi_type_uint32(); |
9479 | 876 |
} else if (returnTypeSymbol == @symbol(uint64)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
877 |
__returnType = __get_ffi_type_uint64(); |
9479 | 878 |
|
879 |
} else if (returnTypeSymbol == @symbol(sint)) { |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
880 |
__returnType = __get_ffi_type_sint(); |
9479 | 881 |
} else if (returnTypeSymbol == @symbol(sint8)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
882 |
__returnType = __get_ffi_type_sint8(); |
9479 | 883 |
} else if (returnTypeSymbol == @symbol(sint16)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
884 |
__returnType = __get_ffi_type_sint16(); |
9479 | 885 |
} else if (returnTypeSymbol == @symbol(sint32)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
886 |
__returnType = __get_ffi_type_sint32(); |
9479 | 887 |
} else if (returnTypeSymbol == @symbol(sint64)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
888 |
__returnType = __get_ffi_type_sint64(); |
9479 | 889 |
|
9342 | 890 |
} else if (returnTypeSymbol == @symbol(long)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
891 |
if (sizeof(long) == 4) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
892 |
returnTypeSymbol = @symbol(sint32); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
893 |
__returnType = __get_ffi_type_sint32(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
894 |
} else if (sizeof(long) == 8) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
895 |
returnTypeSymbol = @symbol(sint64); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
896 |
__returnType = __get_ffi_type_sint64(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
897 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
898 |
__FAIL__(@symbol(UnknownReturnType)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
899 |
} |
9479 | 900 |
|
9342 | 901 |
} else if (returnTypeSymbol == @symbol(ulong)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
902 |
if (sizeof(long) == 4) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
903 |
returnTypeSymbol = @symbol(uint32); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
904 |
__returnType = __get_ffi_type_uint32(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
905 |
}else if (sizeof(long) == 8) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
906 |
returnTypeSymbol = @symbol(uint64); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
907 |
__returnType = __get_ffi_type_uint64(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
908 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
909 |
__FAIL__(@symbol(UnknownReturnType)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
910 |
} |
9479 | 911 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
912 |
} else if (returnTypeSymbol == @symbol(bool)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
913 |
__returnType = __get_ffi_type_uint(); |
9479 | 914 |
|
9342 | 915 |
} else if (returnTypeSymbol == @symbol(float)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
916 |
__returnType = __get_ffi_type_float(); |
9342 | 917 |
} else if (returnTypeSymbol == @symbol(double)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
918 |
__returnType = __get_ffi_type_double(); |
9479 | 919 |
|
9342 | 920 |
} else if (returnTypeSymbol == @symbol(void)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
921 |
__returnType = __get_ffi_type_void(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
922 |
__returnValuePointer = NULL; |
11586 | 923 |
} else if ((returnTypeSymbol == @symbol(pointer)) |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
924 |
|| (returnTypeSymbol == @symbol(handle)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
925 |
|| (returnTypeSymbol == @symbol(charPointer)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
926 |
|| (returnTypeSymbol == @symbol(bytePointer)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
927 |
|| (returnTypeSymbol == @symbol(floatPointer)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
928 |
|| (returnTypeSymbol == @symbol(doublePointer)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
929 |
|| (returnTypeSymbol == @symbol(intPointer)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
930 |
|| (returnTypeSymbol == @symbol(shortPointer)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
931 |
|| (returnTypeSymbol == @symbol(wcharPointer))) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
932 |
__returnType = __get_ffi_type_pointer(); |
9342 | 933 |
} else { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
934 |
if (__isSymbol(returnTypeSymbol) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
935 |
&& ((returnValueClass = __GLOBAL_GET(returnTypeSymbol)) != nil)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
936 |
if (! __isBehaviorLike(returnValueClass)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
937 |
__FAIL__(@symbol(NonBehaviorReturnType)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
938 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
939 |
if (! __qIsSubclassOfExternalAddress(returnValueClass)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
940 |
__FAIL__(@symbol(NonExternalAddressReturnType)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
941 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
942 |
__returnType = __get_ffi_type_pointer(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
943 |
returnTypeSymbol = @symbol(pointer); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
944 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
945 |
__FAIL__(@symbol(UnknownReturnType)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
946 |
} |
9342 | 947 |
} |
948 |
||
949 |
/* |
|
950 |
* validate the c++ object |
|
951 |
*/ |
|
952 |
if (aCPlusPlusObjectOrNil != nil) { |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
953 |
struct cPlusPlusInstance { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
954 |
void **vTable; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
955 |
}; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
956 |
struct cPlusPlusInstance *inst; |
9342 | 957 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
958 |
if (__isExternalAddressLike(aCPlusPlusObjectOrNil)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
959 |
inst = (void *)(__externalAddressVal(aCPlusPlusObjectOrNil)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
960 |
} else if (__isExternalBytesLike(aCPlusPlusObjectOrNil)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
961 |
inst = (void *)(__externalBytesVal(aCPlusPlusObjectOrNil)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
962 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
963 |
__FAIL__(@symbol(InvalidInstance)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
964 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
965 |
__argValues[0].pointerVal = inst; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
966 |
__argValuePointersIncludingThis[0] = &(__argValues[0]); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
967 |
__argTypes[0] = __get_ffi_type_pointer(); |
9342 | 968 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
969 |
__argValuePointers = &__argValuePointersIncludingThis[1]; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
970 |
__argTypes = &__argTypesIncludingThis[1]; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
971 |
__argValues = &__argValuesIncludingThis[1]; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
972 |
__numArgsIncludingThis = __numArgs + 1; |
9347 | 973 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
974 |
if (virtual == true) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
975 |
if (! __isSmallInteger(vtOffset)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
976 |
__FAIL__(@symbol(InvalidVTableIndex)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
977 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
978 |
codeAddress = inst->vTable[__intVal(vtOffset)]; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
979 |
# ifdef VERBOSE |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
980 |
printf("virtual codeAddress: %x\n", codeAddress); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
981 |
# endif |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
982 |
} |
9342 | 983 |
} else { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
984 |
__numArgsIncludingThis = __numArgs; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
985 |
# ifdef VERBOSE |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
986 |
printf("codeAddress: %x\n", codeAddress); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
987 |
# endif |
9342 | 988 |
} |
989 |
||
990 |
/* |
|
991 |
* validate all arg types and setup arg-buffers |
|
992 |
*/ |
|
993 |
for (i=0; i<__numArgs; i++) { |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
994 |
ffi_type *thisType; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
995 |
void *argValuePtr; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
996 |
OBJ typeSymbol; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
997 |
OBJ arg; |
9342 | 998 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
999 |
failureInfo = __mkSmallInteger(i+1); /* in case there is one */ |
9465 | 1000 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1001 |
typeSymbol = __ArrayInstPtr(argTypeSymbols)->a_element[i]; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1002 |
arg = __ArrayInstPtr(argumentsOrNil)->a_element[i]; |
9342 | 1003 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1004 |
if (typeSymbol == @symbol(handle)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1005 |
typeSymbol = @symbol(pointer); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1006 |
} else if (typeSymbol == @symbol(voidPointer)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1007 |
typeSymbol = @symbol(pointer); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1008 |
} |
9479 | 1009 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1010 |
if (typeSymbol == @symbol(long)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1011 |
if (sizeof(long) == sizeof(int)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1012 |
typeSymbol = @symbol(sint); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1013 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1014 |
if (sizeof(long) == 4) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1015 |
typeSymbol = @symbol(sint32); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1016 |
} else if (sizeof(long) == 8) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1017 |
typeSymbol = @symbol(sint64); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1018 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1019 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1020 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1021 |
if (typeSymbol == @symbol(ulong)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1022 |
if (sizeof(unsigned long) == sizeof(unsigned int)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1023 |
typeSymbol = @symbol(uint); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1024 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1025 |
if (sizeof(long) == 4) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1026 |
typeSymbol = @symbol(uint32); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1027 |
} else if (sizeof(long) == 8) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1028 |
typeSymbol = @symbol(uint64); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1029 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1030 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1031 |
} |
9342 | 1032 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1033 |
if (typeSymbol == @symbol(int) || typeSymbol == @symbol(sint)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1034 |
thisType = __get_ffi_type_sint(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1035 |
if (__isSmallInteger(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1036 |
__argValues[i].iVal = __intVal(arg); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1037 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1038 |
__argValues[i].iVal = __signedLongIntVal(arg); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1039 |
if (__argValues[i].iVal == 0) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1040 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1041 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1042 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1043 |
argValuePtr = &(__argValues[i].iVal); |
9479 | 1044 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1045 |
} else if (typeSymbol == @symbol(uint)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1046 |
thisType = __get_ffi_type_uint(); |
9342 | 1047 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1048 |
if (__isSmallInteger(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1049 |
__argValues[i].iVal = __intVal(arg); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1050 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1051 |
__argValues[i].iVal = __unsignedLongIntVal(arg); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1052 |
if (__argValues[i].iVal == 0) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1053 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1054 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1055 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1056 |
argValuePtr = &(__argValues[i].iVal); |
9479 | 1057 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1058 |
} else if (typeSymbol == @symbol(uint8)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1059 |
thisType = __get_ffi_type_uint8(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1060 |
if (! __isSmallInteger(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1061 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1062 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1063 |
__argValues[i].iVal = __intVal(arg); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1064 |
if (((unsigned)(__argValues[i].iVal)) > 0xFF) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1065 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1066 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1067 |
argValuePtr = &(__argValues[i].iVal); |
9479 | 1068 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1069 |
} else if (typeSymbol == @symbol(sint8)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1070 |
thisType = __get_ffi_type_sint8(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1071 |
if (! __isSmallInteger(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1072 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1073 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1074 |
__argValues[i].iVal = __intVal(arg); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1075 |
if (((__argValues[i].iVal) < -0x80) || ((__argValues[i].iVal) > 0x7F)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1076 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1077 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1078 |
argValuePtr = &(__argValues[i].iVal); |
9479 | 1079 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1080 |
} else if (typeSymbol == @symbol(uint16)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1081 |
thisType = __get_ffi_type_uint16(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1082 |
if (! __isSmallInteger(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1083 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1084 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1085 |
__argValues[i].iVal = __intVal(arg); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1086 |
if (((unsigned)(__argValues[i].iVal)) > 0xFFFF) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1087 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1088 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1089 |
argValuePtr = &(__argValues[i].iVal); |
9479 | 1090 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1091 |
} else if (typeSymbol == @symbol(sint16)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1092 |
thisType = __get_ffi_type_sint16(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1093 |
if (! __isSmallInteger(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1094 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1095 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1096 |
__argValues[i].iVal = __intVal(arg); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1097 |
if (((__argValues[i].iVal) < -0x8000) || ((__argValues[i].iVal) > 0x7FFF)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1098 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1099 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1100 |
argValuePtr = &(__argValues[i].iVal); |
9479 | 1101 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1102 |
} else if ((typeSymbol == @symbol(uint32)) || (typeSymbol == @symbol(sint32))) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1103 |
thisType = __get_ffi_type_uint32(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1104 |
if (__isSmallInteger(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1105 |
__argValues[i].iVal = __intVal(arg); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1106 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1107 |
__argValues[i].iVal = __unsignedLongIntVal(arg); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1108 |
if (__argValues[i].iVal == 0) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1109 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1110 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1111 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1112 |
argValuePtr = &(__argValues[i].iVal); |
9479 | 1113 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1114 |
} else if (typeSymbol == @symbol(float)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1115 |
thisType = __get_ffi_type_float(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1116 |
if (__isSmallInteger(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1117 |
__argValues[i].fVal = (float)(__intVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1118 |
} else if (__isFloat(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1119 |
__argValues[i].fVal = (float)(__floatVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1120 |
} else if (__isShortFloat(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1121 |
__argValues[i].fVal = (float)(__shortFloatVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1122 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1123 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1124 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1125 |
argValuePtr = &(__argValues[i].fVal); |
9479 | 1126 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1127 |
} else if (typeSymbol == @symbol(double)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1128 |
thisType = __get_ffi_type_double(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1129 |
if (__isSmallInteger(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1130 |
__argValues[i].dVal = (double)(__intVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1131 |
} else if (__isFloat(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1132 |
__argValues[i].dVal = (double)(__floatVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1133 |
} else if (__isShortFloat(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1134 |
__argValues[i].dVal = (double)(__shortFloatVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1135 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1136 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1137 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1138 |
argValuePtr = &(__argValues[i].dVal); |
9479 | 1139 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1140 |
} else if (typeSymbol == @symbol(void)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1141 |
thisType = __get_ffi_type_void(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1142 |
argValuePtr = &null; |
9479 | 1143 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1144 |
} else if (typeSymbol == @symbol(charPointer)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1145 |
thisType = __get_ffi_type_pointer(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1146 |
if (__isStringLike(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1147 |
if (async == true) goto badArgForAsyncCall; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1148 |
__argValues[i].pointerVal = (void *)(__stringVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1149 |
} else if (__isBytes(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1150 |
if (async == true) goto badArgForAsyncCall; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1151 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1152 |
} else if (__isExternalAddressLike(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1153 |
__argValues[i].pointerVal = (void *)(__externalAddressVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1154 |
} else if (__isExternalBytesLike(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1155 |
__argValues[i].pointerVal = (void *)(__externalBytesVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1156 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1157 |
if (arg == nil) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1158 |
__argValues[i].pointerVal = (void *)0; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1159 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1160 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1161 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1162 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1163 |
argValuePtr = &(__argValues[i].pointerVal);; |
10603 | 1164 |
|
12656 | 1165 |
} else if (typeSymbol == @symbol(wcharPointer)) { |
1166 |
thisType = __get_ffi_type_pointer(); |
|
1167 |
if (__isUnicode16String(arg)) { |
|
1168 |
if (async == true) goto badArgForAsyncCall; |
|
1169 |
__argValues[i].pointerVal = (void *)(__unicode16StringVal(arg)); |
|
1170 |
} else if (__isBytes(arg)) { |
|
1171 |
if (async == true) goto badArgForAsyncCall; |
|
1172 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
|
1173 |
} else if (__isExternalAddressLike(arg)) { |
|
1174 |
__argValues[i].pointerVal = (void *)(__externalAddressVal(arg)); |
|
1175 |
} else if (__isExternalBytesLike(arg)) { |
|
1176 |
__argValues[i].pointerVal = (void *)(__externalBytesVal(arg)); |
|
1177 |
} else { |
|
1178 |
if (arg == nil) { |
|
1179 |
__argValues[i].pointerVal = (void *)0; |
|
1180 |
} else { |
|
1181 |
__FAIL__(@symbol(InvalidArgument)) |
|
1182 |
} |
|
1183 |
} |
|
1184 |
argValuePtr = &(__argValues[i].pointerVal);; |
|
1185 |
||
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1186 |
} else if (typeSymbol == @symbol(floatPointer)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1187 |
thisType = __get_ffi_type_pointer(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1188 |
if (__isBytes(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1189 |
if (async == true) goto badArgForAsyncCall; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1190 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1191 |
} else if (__isExternalAddressLike(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1192 |
__argValues[i].pointerVal = (void *)(__externalAddressVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1193 |
} else if (__isExternalBytesLike(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1194 |
__argValues[i].pointerVal = (void *)(__externalBytesVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1195 |
} else if (__isFloats(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1196 |
char *p = (char *)(__FloatArrayInstPtr(arg)->f_element); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1197 |
int nInstBytes; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1198 |
OBJ cls; |
10603 | 1199 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1200 |
if (async == true) goto badArgForAsyncCall; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1201 |
cls = __qClass(arg); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1202 |
nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1203 |
p = p + nInstBytes; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1204 |
__argValues[i].pointerVal = p; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1205 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1206 |
if (arg == nil) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1207 |
__argValues[i].pointerVal = (void *)0; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1208 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1209 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1210 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1211 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1212 |
argValuePtr = &(__argValues[i].pointerVal);; |
10603 | 1213 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1214 |
} else if (typeSymbol == @symbol(doublePointer)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1215 |
thisType = __get_ffi_type_pointer(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1216 |
if (__isBytes(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1217 |
if (async == true) goto badArgForAsyncCall; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1218 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1219 |
} else if (__isExternalAddressLike(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1220 |
__argValues[i].pointerVal = (void *)(__externalAddressVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1221 |
} else if (__isExternalBytesLike(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1222 |
__argValues[i].pointerVal = (void *)(__externalBytesVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1223 |
} else if (__isDoubles(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1224 |
char *p = (char *)(__DoubleArrayInstPtr(arg)->d_element); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1225 |
int nInstBytes; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1226 |
OBJ cls; |
10603 | 1227 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1228 |
if (async == true) goto badArgForAsyncCall; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1229 |
cls = __qClass(arg); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1230 |
nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1231 |
p = p + nInstBytes; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1232 |
# ifdef __NEED_DOUBLE_ALIGN |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1233 |
if ((INT)pFirst & (__DOUBLE_ALIGN-1)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1234 |
int delta = __DOUBLE_ALIGN - ((INT)p & (__DOUBLE_ALIGN-1)); |
10603 | 1235 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1236 |
p += delta; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1237 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1238 |
# endif |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1239 |
__argValues[i].pointerVal = p; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1240 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1241 |
if (arg == nil) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1242 |
__argValues[i].pointerVal = (void *)0; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1243 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1244 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1245 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1246 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1247 |
argValuePtr = &(__argValues[i].pointerVal);; |
9479 | 1248 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1249 |
} else if (typeSymbol == @symbol(pointer)) { |
9524 | 1250 |
commonPointerTypeArg: ; |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1251 |
thisType = __get_ffi_type_pointer(); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1252 |
if (arg == nil) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1253 |
__argValues[i].pointerVal = NULL; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1254 |
} else if (__isExternalAddressLike(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1255 |
__argValues[i].pointerVal = (void *)(__externalAddressVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1256 |
} else if (__isExternalBytesLike(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1257 |
__argValues[i].pointerVal = (void *)(__externalBytesVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1258 |
} else if (__isByteArrayLike(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1259 |
if (async == true) goto badArgForAsyncCall; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1260 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
12591 | 1261 |
} else if (__isWordArray(arg) || __isSignedWordArray(arg) |
1262 |
|| __isIntegerArray(arg) || __isSignedIntegerArray(arg)) { |
|
1263 |
if (async == true) goto badArgForAsyncCall; |
|
1264 |
__argValues[i].pointerVal = (void *)(__integerArrayVal(arg)); |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1265 |
} else if (__isFloatArray(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1266 |
if (async == true) goto badArgForAsyncCall; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1267 |
__argValues[i].pointerVal = (void *)(__FloatArrayInstPtr(arg)->f_element); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1268 |
} else if (__isDoubleArray(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1269 |
if (async == true) goto badArgForAsyncCall; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1270 |
__argValues[i].pointerVal = (void *)(__DoubleArrayInstPtr(arg)->d_element); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1271 |
} else if (__isStringLike(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1272 |
if (async == true) { |
9435 | 1273 |
badArgForAsyncCall: ; |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1274 |
__FAIL__(@symbol(BadArgForAsyncCall)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1275 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1276 |
__argValues[i].pointerVal = (void *)(__stringVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1277 |
} else if (__isBytes(arg) || __isWords(arg) || __isLongs(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1278 |
char *p = (char *)(__byteArrayVal(arg)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1279 |
int nInstBytes; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1280 |
OBJ cls; |
9483 | 1281 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1282 |
if (async == true) goto badArgForAsyncCall; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1283 |
cls = __qClass(arg); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1284 |
nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1285 |
__argValues[i].pointerVal = p + nInstBytes; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1286 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1287 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1288 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1289 |
argValuePtr = &(__argValues[i].pointerVal);; |
9479 | 1290 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1291 |
} else if (typeSymbol == @symbol(bool)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1292 |
thisType = __get_ffi_type_uint(); |
9342 | 1293 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1294 |
if (arg == true) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1295 |
__argValues[i].iVal = 1; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1296 |
} else if (arg == false) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1297 |
__argValues[i].iVal = 0; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1298 |
} else if (__isSmallInteger(arg)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1299 |
__argValues[i].iVal = __intVal(arg); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1300 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1301 |
__argValues[i].iVal = __unsignedLongIntVal(arg); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1302 |
if (__argValues[i].iVal == 0) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1303 |
__FAIL__(@symbol(InvalidArgument)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1304 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1305 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1306 |
argValuePtr = &(__argValues[i].iVal); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1307 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1308 |
if (__isSymbol(typeSymbol) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1309 |
&& ((argValueClass = __GLOBAL_GET(typeSymbol)) != nil)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1310 |
if (! __isBehaviorLike(argValueClass)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1311 |
__FAIL__(@symbol(NonBehaviorArgumentType)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1312 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1313 |
if (! __qIsSubclassOfExternalAddress(argValueClass)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1314 |
__FAIL__(@symbol(NonExternalAddressArgumentType)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1315 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1316 |
goto commonPointerTypeArg; /* sorry */ |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1317 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1318 |
__FAIL__(@symbol(UnknownArgumentType)) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1319 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1320 |
} |
9342 | 1321 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1322 |
__argTypes[i] = thisType; |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1323 |
__argValuePointers[i] = argValuePtr; |
9483 | 1324 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1325 |
# ifdef VERBOSE |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1326 |
printf("arg%d: %x\n", i, __argValues[i].iVal); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1327 |
# endif |
9342 | 1328 |
} |
9465 | 1329 |
failureInfo = nil; |
9342 | 1330 |
|
1331 |
__callType = FFI_DEFAULT_ABI; |
|
1332 |
||
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1333 |
# ifdef CALLTYPE_FFI_STDCALL |
9465 | 1334 |
if (callTypeNumber == @global(CALLTYPE_API)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1335 |
__callType = CALLTYPE_FFI_STDCALL; |
9342 | 1336 |
} |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1337 |
# endif |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1338 |
# ifdef CALLTYPE_FFI_V8 |
9465 | 1339 |
if (callTypeNumber == @global(CALLTYPE_V8)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1340 |
__callType = CALLTYPE_FFI_V8; |
9342 | 1341 |
} |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1342 |
# endif |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1343 |
# ifdef CALLTYPE_FFI_V9 |
9465 | 1344 |
if (callTypeNumber == @global(CALLTYPE_V9)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1345 |
__callType = CALLTYPE_FFI_V9; |
9342 | 1346 |
} |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1347 |
# endif |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1348 |
# ifdef CALLTYPE_FFI_UNIX64 |
9465 | 1349 |
if (callTypeNumber == @global(CALLTYPE_UNIX64)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1350 |
__callType = CALLTYPE_FFI_UNIX64; |
9342 | 1351 |
} |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1352 |
# endif |
9342 | 1353 |
|
1354 |
if (ffi_prep_cif(&__cif, __callType, __numArgsIncludingThis, __returnType, __argTypesIncludingThis) != FFI_OK) { |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1355 |
__FAIL__(@symbol(FFIPrepareFailed)) |
9342 | 1356 |
} |
9463 | 1357 |
if (async == true) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1358 |
# ifdef VERBOSE |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1359 |
printf("async call 0x%x\n", codeAddress); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1360 |
# endif |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1361 |
# ifdef WIN32 |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1362 |
__STX_C_CALL4( "ffi_call", ffi_call, &__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1363 |
# else |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1364 |
__BEGIN_INTERRUPTABLE__ |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1365 |
ffi_call(&__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1366 |
__END_INTERRUPTABLE__ |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1367 |
# endif |
9435 | 1368 |
} else { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1369 |
if (unlimitedStack == true) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1370 |
# ifdef VERBOSE |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1371 |
printf("UNLIMITEDSTACKCALL call 0x%x\n", codeAddress); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1372 |
# endif |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1373 |
# if 0 |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1374 |
__UNLIMITEDSTACKCALL__(ffi_call, &__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1375 |
# endif |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1376 |
} else { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1377 |
# ifdef VERBOSE |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1378 |
printf("call 0x%x\n", codeAddress); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1379 |
# endif |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1380 |
ffi_call(&__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1381 |
} |
9435 | 1382 |
} |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1383 |
# ifdef VERBOSE |
9524 | 1384 |
printf("retval is %d (0x%x)\n", __returnValue.iVal, __returnValue.iVal); |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1385 |
# endif |
11586 | 1386 |
if ((returnTypeSymbol == @symbol(int)) |
1387 |
|| (returnTypeSymbol == @symbol(sint)) |
|
9479 | 1388 |
|| (returnTypeSymbol == @symbol(sint8)) |
1389 |
|| (returnTypeSymbol == @symbol(sint16)) |
|
1390 |
|| (returnTypeSymbol == @symbol(sint32))) { |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1391 |
RETURN ( __MKINT(__returnValue.iVal) ); |
9342 | 1392 |
} |
1393 |
if ((returnTypeSymbol == @symbol(uint)) |
|
1394 |
|| (returnTypeSymbol == @symbol(uint8)) |
|
1395 |
|| (returnTypeSymbol == @symbol(uint16)) |
|
1396 |
|| (returnTypeSymbol == @symbol(uint32))) { |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1397 |
RETURN ( __MKUINT(__returnValue.iVal) ); |
9342 | 1398 |
} |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1399 |
if (returnTypeSymbol == @symbol(bool)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1400 |
RETURN ( __returnValue.iVal ? true : false ); |
9342 | 1401 |
} |
1402 |
if (returnTypeSymbol == @symbol(float)) { |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1403 |
RETURN ( __MKFLOAT(__returnValue.fVal )); |
9342 | 1404 |
} |
1405 |
if (returnTypeSymbol == @symbol(double)) { |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1406 |
RETURN ( __MKFLOAT(__returnValue.dVal )); |
9342 | 1407 |
} |
1408 |
if (returnTypeSymbol == @symbol(void)) { |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1409 |
RETURN ( nil ); |
9342 | 1410 |
} |
9463 | 1411 |
if (returnTypeSymbol == @symbol(char)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1412 |
RETURN ( __MKCHARACTER(__returnValue.iVal & 0xFF) ); |
9463 | 1413 |
} |
1414 |
if (returnTypeSymbol == @symbol(wchar)) { |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1415 |
RETURN ( __MKUCHARACTER(__returnValue.iVal & 0xFFFF) ); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1416 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1417 |
if (returnTypeSymbol == @symbol(sint64)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1418 |
RETURN ( __MKINT64(&__returnValue.longLongVal) ); |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1419 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1420 |
if (returnTypeSymbol == @symbol(uint64)) { |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1421 |
RETURN ( __MKUINT64(&__returnValue.longLongVal) ); |
9463 | 1422 |
} |
11586 | 1423 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1424 |
# ifdef VERBOSE |
11586 | 1425 |
printf("%x\n", __returnValue.pointerVal); |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1426 |
# endif |
9346 | 1427 |
if (returnTypeSymbol == @symbol(handle)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1428 |
returnValue = __MKEXTERNALADDRESS(__returnValue.pointerVal); |
9346 | 1429 |
} else if (returnTypeSymbol == @symbol(pointer)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1430 |
returnValue = __MKEXTERNALBYTES(__returnValue.pointerVal); |
10603 | 1431 |
} else if (returnTypeSymbol == @symbol(bytePointer)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1432 |
returnValue = __MKEXTERNALBYTES(__returnValue.pointerVal); |
9463 | 1433 |
} else if (returnTypeSymbol == @symbol(charPointer)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1434 |
returnValue = __MKSTRING(__returnValue.pointerVal); |
9463 | 1435 |
} else if (returnTypeSymbol == @symbol(wcharPointer)) { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1436 |
returnValue = __MKU16STRING(__returnValue.pointerVal); |
9342 | 1437 |
} else { |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1438 |
__FAIL__(@symbol(UnknownReturnType2)) |
9342 | 1439 |
} |
10603 | 1440 |
#else /* no FFI support */ |
10618
343d0bf4646a
Now can compile even #ifndef HAVE_FFI
Stefan Vogel <sv@exept.de>
parents:
10614
diff
changeset
|
1441 |
failureCode = @symbol(FFINotSupported); |
10603 | 1442 |
#endif /* HAVE_FFI */ |
9342 | 1443 |
getOutOfHere: ; |
1444 |
%}. |
|
1445 |
failureCode notNil ifTrue:[ |
|
12579
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
1446 |
(failureCode == #UnknownReturnType |
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
1447 |
or:[ failureCode == #UnknownArgumentType ]) ifTrue:[ |
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
1448 |
oldReturnType := returnType. |
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
1449 |
oldArgumentTypes := argumentTypes. |
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
1450 |
self adjustTypes. |
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
1451 |
((oldReturnType ~= returnType) or:[oldArgumentTypes ~= argumentTypes]) ifTrue:[ |
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
1452 |
thisContext restart |
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
1453 |
]. |
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
1454 |
]. |
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
1455 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1456 |
self primitiveFailed. "see failureCode and failureInfo for details" |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1457 |
^ nil |
9342 | 1458 |
]. |
1459 |
||
9483 | 1460 |
returnType isSymbol ifTrue:[ |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1461 |
returnValueClass notNil ifTrue:[ |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1462 |
self isConstReturnValue ifTrue:[ |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1463 |
returnValue changeClassTo:returnValueClass. |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1464 |
^ returnValue |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1465 |
]. |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1466 |
^ returnValueClass fromExternalAddress:returnValue. |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1467 |
]. |
9483 | 1468 |
] ifFalse:[ |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1469 |
returnType isCPointer ifTrue:[ |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1470 |
returnType baseType isCStruct ifTrue:[ |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1471 |
stClass := Smalltalk classNamed:returnType baseType name. |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1472 |
stClass notNil ifTrue:[ |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1473 |
self isConstReturnValue ifTrue:[ |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1474 |
returnValue changeClassTo:returnValueClass. |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1475 |
^ returnValue |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1476 |
]. |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1477 |
^ stClass fromExternalAddress:returnValue. |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1478 |
]. |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1479 |
]. |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1480 |
returnType baseType isCChar ifTrue:[ |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1481 |
^ returnValue stringAt:1 |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1482 |
]. |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1483 |
]. |
9342 | 1484 |
]. |
1485 |
||
1486 |
^ returnValue |
|
9463 | 1487 |
|
1488 |
"Created: / 01-08-2006 / 13:56:23 / cg" |
|
10603 | 1489 |
"Modified: / 11-06-2007 / 01:50:36 / cg" |
9342 | 1490 |
! ! |
1491 |
||
10481 | 1492 |
!ExternalLibraryFunction methodsFor:'testing'! |
1493 |
||
10603 | 1494 |
isExternalLibraryFunction |
1495 |
"return true, if the receiver is some kind of externalLibrary function; |
|
1496 |
true is returned here" |
|
1497 |
||
1498 |
^true |
|
1499 |
||
1500 |
"Created: / 07-06-2007 / 10:36:40 / cg" |
|
10481 | 1501 |
! ! |
1502 |
||
8533 | 1503 |
!ExternalLibraryFunction class methodsFor:'documentation'! |
1504 |
||
13412 | 1505 |
version_CVS |
13782
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
1506 |
^ '$Header: /cvs/stx/stx/libbasic/ExternalLibraryFunction.st,v 1.84 2011-10-07 18:01:43 cg Exp $' |
12436 | 1507 |
! |
1508 |
||
13412 | 1509 |
version_SVN |
13782
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
1510 |
^ '§ Id: ExternalLibraryFunction.st 10643 2011-06-08 21:53:07Z vranyj1 §' |
8533 | 1511 |
! ! |
9463 | 1512 |
|
1513 |
ExternalLibraryFunction initialize! |