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