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