author | Claus Gittinger <cg@exept.de> |
Mon, 06 Jun 2016 10:00:18 +0200 | |
changeset 19950 | ee2f6bfd55c1 |
parent 19933 | d45636ff51df |
child 19951 | 2ba5ef097a79 |
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 |
||
19311 | 14 |
"{ NameSpace: Smalltalk }" |
15 |
||
8533 | 16 |
ExternalFunction subclass:#ExternalLibraryFunction |
9465 | 17 |
instanceVariableNames:'flags moduleName returnType argumentTypes owningClass' |
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
18 |
classVariableNames:'DLLPATH FLAG_VIRTUAL FLAG_NONVIRTUAL FLAG_OBJECTIVEC FLAG_ASYNC |
10270 | 19 |
FLAG_UNLIMITEDSTACK FLAG_RETVAL_IS_CONST CALLTYPE_MASK |
20 |
CALLTYPE_API CALLTYPE_C CALLTYPE_OLE CALLTYPE_V8 CALLTYPE_V9 |
|
19342 | 21 |
CALLTYPE_UNIX64 DllMapping Verbose LastModuleHandleHolder |
22 |
LastModuleHandleName' |
|
9464 | 23 |
poolDictionaries:'' |
24 |
category:'System-Support' |
|
8533 | 25 |
! |
26 |
||
9322 | 27 |
!ExternalLibraryFunction primitiveDefinitions! |
28 |
%{ |
|
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
29 |
#define VERBOSE |
9322 | 30 |
|
9337 | 31 |
#ifdef HAVE_FFI |
32 |
# include <ffi.h> |
|
9322 | 33 |
# define MAX_ARGS 128 |
9365 | 34 |
|
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
35 |
# ifdef USE_STANDARD_FFI |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
36 |
# define __get_ffi_type_sint() &ffi_type_sint |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
37 |
# define __get_ffi_type_sint8() &ffi_type_sint8 |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
38 |
# define __get_ffi_type_sint16() &ffi_type_sint16 |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
39 |
# define __get_ffi_type_sint32() &ffi_type_sint32 |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
40 |
# define __get_ffi_type_sint64() &ffi_type_sint64 |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
41 |
# define __get_ffi_type_uint() &ffi_type_uint |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
42 |
# define __get_ffi_type_uint8() &ffi_type_uint8 |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
43 |
# define __get_ffi_type_uint16() &ffi_type_uint16 |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
44 |
# define __get_ffi_type_uint32() &ffi_type_uint32 |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
45 |
# define __get_ffi_type_uint64() &ffi_type_uint64 |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
46 |
# define __get_ffi_type_float() &ffi_type_float |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
47 |
# define __get_ffi_type_double() &ffi_type_double |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
48 |
# define __get_ffi_type_void() &ffi_type_void |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
49 |
# define __get_ffi_type_pointer() &ffi_type_pointer |
19931 | 50 |
|
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
51 |
# else |
19931 | 52 |
|
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
53 |
extern ffi_type *__get_ffi_type_sint(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
54 |
extern ffi_type *__get_ffi_type_sint8(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
55 |
extern ffi_type *__get_ffi_type_sint16(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
56 |
extern ffi_type *__get_ffi_type_sint32(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
57 |
extern ffi_type *__get_ffi_type_sint64(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
58 |
extern ffi_type *__get_ffi_type_uint(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
59 |
extern ffi_type *__get_ffi_type_uint8(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
60 |
extern ffi_type *__get_ffi_type_uint16(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
61 |
extern ffi_type *__get_ffi_type_uint32(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
62 |
extern ffi_type *__get_ffi_type_uint64(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
63 |
extern ffi_type *__get_ffi_type_float(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
64 |
extern ffi_type *__get_ffi_type_double(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
65 |
extern ffi_type *__get_ffi_type_void(); |
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
66 |
extern ffi_type *__get_ffi_type_pointer(); |
19535 | 67 |
extern INTFUNC __get_ffi_prep_cif(); |
68 |
extern INTFUNC __get_ffi_call(); |
|
19536 | 69 |
# ifdef _MINGW__ |
70 |
# define ffi_prep_cif (*(__get_ffi_prep_cif())) |
|
71 |
# define ffi_call (*(__get_ffi_call())) |
|
72 |
# endif |
|
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
73 |
# endif |
9365 | 74 |
|
19931 | 75 |
# define TYPE_UINT __get_ffi_type_uint() |
76 |
# define TYPE_UINT8 __get_ffi_type_uint8() |
|
77 |
# define TYPE_UINT16 __get_ffi_type_uint16() |
|
78 |
# define TYPE_UINT32 __get_ffi_type_uint32() |
|
79 |
# define TYPE_UINT64 __get_ffi_type_uint64() |
|
80 |
||
81 |
# define TYPE_SINT __get_ffi_type_sint() |
|
82 |
# define TYPE_SINT8 __get_ffi_type_sint8() |
|
83 |
# define TYPE_SINT16 __get_ffi_type_sint16() |
|
84 |
# define TYPE_SINT32 __get_ffi_type_sint32() |
|
85 |
# define TYPE_SINT64 __get_ffi_type_sint64() |
|
86 |
||
87 |
# define TYPE_POINTER __get_ffi_type_pointer() |
|
19950 | 88 |
# define TYPE_FLOAT __get_ffi_type_float() |
89 |
# define TYPE_DOUBLE __get_ffi_type_double() |
|
90 |
# define TYPE_VOID __get_ffi_type_void() |
|
19931 | 91 |
|
92 |
#else /* NO FFI */ |
|
93 |
||
94 |
# define MAX_ARGS 15 |
|
95 |
# define TYPE_UINT 1 |
|
96 |
# define TYPE_UINT8 2 |
|
97 |
# define TYPE_UINT16 3 |
|
98 |
# define TYPE_UINT32 4 |
|
99 |
# define TYPE_UINT64 5 |
|
100 |
||
101 |
# define TYPE_SINT 11 |
|
102 |
# define TYPE_SINT8 12 |
|
103 |
# define TYPE_SINT16 13 |
|
104 |
# define TYPE_SINT32 14 |
|
105 |
# define TYPE_SINT64 15 |
|
106 |
||
107 |
# define TYPE_POINTER 20 |
|
108 |
# define TYPE_FLOAT 30 |
|
109 |
# define TYPE_DOUBLE 31 |
|
110 |
# define TYPE_VOID 40 |
|
111 |
||
112 |
# define FFI_DEFAULT_ABI 0 |
|
113 |
# define CALLTYPE_FFI_STDCALL 0 |
|
114 |
||
9337 | 115 |
#endif |
9322 | 116 |
|
117 |
%} |
|
118 |
! ! |
|
119 |
||
8728 | 120 |
!ExternalLibraryFunction class methodsFor:'documentation'! |
121 |
||
122 |
copyright |
|
123 |
" |
|
124 |
COPYRIGHT (c) 2004 by eXept Software AG |
|
9464 | 125 |
All Rights Reserved |
8728 | 126 |
|
127 |
This software is furnished under a license and may be used |
|
128 |
only in accordance with the terms of that license and with the |
|
129 |
inclusion of the above copyright notice. This software may not |
|
130 |
be provided or otherwise made available to, or used by, any |
|
131 |
other person. No title to or ownership of the software is |
|
132 |
hereby transferred. |
|
133 |
" |
|
9322 | 134 |
! |
135 |
||
9331 | 136 |
documentation |
137 |
" |
|
138 |
instances of me are used to interface to external library functions (as found in a dll/shared object). |
|
19933 | 139 |
Foreign function calls are based on the FFI library if available. |
140 |
A limited fallback implementation is provided for systems with no libffi. |
|
141 |
(this may have limitations on the supported argument types; for example, |
|
142 |
the x86_64 fallback does not support float/double arguments). |
|
19950 | 143 |
Therefore the fallback should be considered a temporary workaround, |
19933 | 144 |
until libffi has been ported. |
19950 | 145 |
|
12680 | 146 |
Inside a method, when a special external-call pragma such as: |
19950 | 147 |
<api: bool MessageBeep(uint)> |
12680 | 148 |
|
149 |
is encountered by the parser, the compiler generates a call via |
|
19950 | 150 |
<correspondingExternalLibraryFunctionObject> invokeWithArguments: argumentArray. |
19549 | 151 |
and the correspondingExternalLibraryFunctionObject is kept in the literal array. |
9331 | 152 |
|
153 |
In the invoke method, the library is checked to be loaded (and loaded if not already), |
|
9336 | 154 |
the arguments are converted to C and pushed onto the C-stack, the function is called, |
9331 | 155 |
and finally, the return value is converted back from C to a smalltalk object. |
12680 | 156 |
|
157 |
The parser supports the call-syntax of various other smalltalk dialects: |
|
19950 | 158 |
Squeak / ST-X: |
159 |
<cdecl: [async] [virtual|nonVirtual][const] returnType functionNameStringOrIndex ( argType1..argTypeN ) module: moduleName > |
|
160 |
<apicall: [async] [virtual|nonVirtual][const] returnType functionNameStringOrIndex ( argType1..argTypeN ) module: moduleName > |
|
12680 | 161 |
|
19950 | 162 |
Dolphin: |
163 |
<stdcall: [virtual|nonVirtual][const] returnType functionNameStringOrIndex argType1..argTypeN> |
|
164 |
<cdecl: [virtual|nonVirtual][const] returnType functionNameStringOrIndex argType1..argTypeN> |
|
12680 | 165 |
|
19950 | 166 |
ST/V: |
167 |
<api: functionName argType1 .. argTypeN returnType> |
|
168 |
<ccall: functionName argType1 .. argTypeN returnType> |
|
169 |
<ole: vFunctionIndex argType1 .. argTypeN returnType> |
|
12680 | 170 |
|
19950 | 171 |
VisualWorks: |
172 |
<c: ...> |
|
173 |
<c: #define NAME value> |
|
9331 | 174 |
" |
175 |
! |
|
176 |
||
9322 | 177 |
example |
178 |
" |
|
14625 | 179 |
[exBegin] |
180 |
|f| |
|
14037 | 181 |
|
14625 | 182 |
f := ExternalLibraryFunction new. |
183 |
f beCallTypeWINAPI. |
|
14037 | 184 |
|
14625 | 185 |
f name:'MessageBeep' |
186 |
module:'user32.dll' |
|
187 |
returnType:#boolean |
|
188 |
argumentTypes:#(uint). |
|
14037 | 189 |
|
14625 | 190 |
f invokeWith:1. |
191 |
[exEnd] |
|
14037 | 192 |
|
193 |
Synchronous vs. Asynchronous calls: |
|
194 |
||
14516
359e4d2234af
class: ExternalLibraryFunction
Stefan Vogel <sv@exept.de>
parents:
14506
diff
changeset
|
195 |
by default, foreign function calls are synchronous, effectively blocking the whole ST/X system |
19514 | 196 |
(that is by purpose,´because most C-code is not prepared for being interrupted, and also, normal |
14037 | 197 |
code is not prepared for a garbage collector to move objects around, while another C thread might |
198 |
access the data...). |
|
14625 | 199 |
Therefore, the following will block all ST/X activity for 10 seconds |
14037 | 200 |
(try interacting with the launcher while the Sleep is performing): |
201 |
||
14625 | 202 |
[exBegin] |
203 |
|f| |
|
9322 | 204 |
|
14625 | 205 |
f := ExternalLibraryFunction new. |
206 |
f beCallTypeWINAPI. |
|
14037 | 207 |
|
14625 | 208 |
f name:'Sleep' |
209 |
module:'kernel32.dll' |
|
210 |
returnType:#void |
|
211 |
argumentTypes:#(uint). |
|
14037 | 212 |
|
14625 | 213 |
f invokeWith:10000. |
214 |
[exEnd] |
|
9322 | 215 |
|
14037 | 216 |
if you know what you do and you do not pass any possibly moving objects (such as strings) as argument, |
217 |
the call can be made asynchronous. In that case, ONLY the calling thread will be blocked; all other smalltalk |
|
218 |
threads wil continue to execute. |
|
219 |
(try interacting now with the launcher while the Sleep is performing): |
|
14625 | 220 |
[exBegin] |
221 |
|f| |
|
14037 | 222 |
|
14625 | 223 |
f := ExternalLibraryFunction new. |
224 |
f beCallTypeWINAPI. |
|
225 |
f beAsync. |
|
14037 | 226 |
|
14625 | 227 |
f name:'Sleep' |
228 |
module:'kernel32.dll' |
|
229 |
returnType:#void |
|
230 |
argumentTypes:#(uint). |
|
14037 | 231 |
|
14625 | 232 |
f invokeWith:10000. |
233 |
[exEnd] |
|
14037 | 234 |
|
9322 | 235 |
" |
8728 | 236 |
! ! |
8533 | 237 |
|
8550 | 238 |
!ExternalLibraryFunction class methodsFor:'instance creation'! |
239 |
||
9465 | 240 |
name:functionName module:moduleName returnType:returnType argumentTypes:argTypes |
8550 | 241 |
^ self new |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
242 |
name:functionName module:moduleName |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
243 |
returnType:returnType argumentTypes:argTypes |
9465 | 244 |
|
245 |
"Created: / 01-08-2006 / 15:19:08 / cg" |
|
9463 | 246 |
! ! |
247 |
||
248 |
!ExternalLibraryFunction class methodsFor:'class initialization'! |
|
249 |
||
11050 | 250 |
addToDllPath:aDirectoryPathName |
251 |
"can be used during initialization, to add more places for dll-loading" |
|
252 |
||
19487 | 253 |
|oldPath newPath| |
11053 | 254 |
|
255 |
oldPath := self dllPath. |
|
256 |
(oldPath includes:aDirectoryPathName) ifFalse:[ |
|
19535 | 257 |
newPath := oldPath asOrderedCollection. |
258 |
newPath add:aDirectoryPathName. |
|
259 |
self dllPath:newPath |
|
11053 | 260 |
] |
11050 | 261 |
! |
262 |
||
14103 | 263 |
dllMapping |
264 |
"allows for dll's to be replaced, |
|
265 |
for example, if you want to use the mozilla sqlite dll |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19549
diff
changeset
|
266 |
C:\Program Files\Mozilla Firefox\mozsqlite3.dll |
14103 | 267 |
for the sqlite3, execute: |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19549
diff
changeset
|
268 |
ExternalLibraryFunction |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19549
diff
changeset
|
269 |
dllMapping at:'sqlite3' |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19549
diff
changeset
|
270 |
put: 'C:\Program Files\Mozilla Firefox\mozsqlite3.dll' |
19549 | 271 |
for mingw: |
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19549
diff
changeset
|
272 |
ExternalLibraryFunction |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19549
diff
changeset
|
273 |
dllMapping at:'sqlite3' |
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19549
diff
changeset
|
274 |
put:'C:\mingw64\opt\bin\libsqlite3-0.dll' |
14103 | 275 |
" |
276 |
||
277 |
DllMapping isNil ifTrue:[ |
|
19860
324edacff5cc
unified cpu and os defines;
Claus Gittinger <cg@exept.de>
parents:
19549
diff
changeset
|
278 |
DllMapping := Dictionary new. |
14103 | 279 |
]. |
280 |
^ DllMapping |
|
281 |
||
282 |
"Created: / 10-04-2012 / 12:21:45 / cg" |
|
283 |
! |
|
284 |
||
10270 | 285 |
dllPath |
19549 | 286 |
"provide a default dllPath, where external libraries are searched for" |
287 |
||
13337 | 288 |
^ DLLPATH |
10270 | 289 |
! |
290 |
||
291 |
dllPath:aCollectionOfDirectoryPathNames |
|
19549 | 292 |
"provide a default dllPath, where external libraries are searched for" |
293 |
||
10270 | 294 |
DLLPATH := aCollectionOfDirectoryPathNames |
295 |
! |
|
296 |
||
9463 | 297 |
initialize |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
298 |
"using inline access to corresponding c--defines to avoid duplicate places of knowledge" |
13337 | 299 |
|
300 |
DLLPATH isNil ifTrue:[ |
|
14625 | 301 |
DLLPATH := #('.'). |
18228 | 302 |
%{ |
18240
28af09029a8b
ifdef for SCHTEAM engine changed (not relevant for ST/X)
Claus Gittinger <cg@exept.de>
parents:
18228
diff
changeset
|
303 |
#ifndef __SCHTEAM__ |
18228 | 304 |
@global(FLAG_VIRTUAL) = __MKSMALLINT(__EXTL_FLAG_VIRTUAL); // a virtual c++ call |
305 |
@global(FLAG_NONVIRTUAL) = __MKSMALLINT(__EXTL_FLAG_NONVIRTUAL); // a non-virtual c++ call |
|
306 |
@global(FLAG_OBJECTIVEC) = __MKSMALLINT(__EXTL_FLAG_OBJECTIVEC); // an objectiveC message send |
|
307 |
@global(FLAG_UNLIMITEDSTACK) = __MKSMALLINT(__EXTL_FLAG_UNLIMITEDSTACK); // unlimitedstack under unix |
|
308 |
@global(FLAG_ASYNC) = __MKSMALLINT(__EXTL_FLAG_ASYNC); // async under win32 |
|
309 |
@global(FLAG_RETVAL_IS_CONST) = __MKSMALLINT(__EXTL_FLAG_RETVAL_IS_CONST); // return value is not to be registered for finalization |
|
9463 | 310 |
|
18228 | 311 |
@global(CALLTYPE_API) = __MKSMALLINT(__EXTL_CALLTYPE_API); // WINAPI-call (win32 only) |
312 |
@global(CALLTYPE_C) = __MKSMALLINT(__EXTL_CALLTYPE_C); // regular C-call (the default) |
|
313 |
@global(CALLTYPE_V8) = __MKSMALLINT(__EXTL_CALLTYPE_V8); // v8 call (sparc only) |
|
314 |
@global(CALLTYPE_V9) = __MKSMALLINT(__EXTL_CALLTYPE_V9); // v9 call (sparc only) |
|
315 |
@global(CALLTYPE_UNIX64) = __MKSMALLINT(__EXTL_CALLTYPE_UNIX64); // unix64 call (alpha only) |
|
9463 | 316 |
|
18228 | 317 |
@global(CALLTYPE_MASK) = __MKSMALLINT(__EXTL_CALLTYPE_MASK); |
318 |
#endif |
|
319 |
%} |
|
13337 | 320 |
]. |
9465 | 321 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
322 |
" |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
323 |
self initialize |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
324 |
" |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
325 |
|
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
326 |
"Modified: / 03-10-2006 / 21:27:47 / cg" |
11053 | 327 |
! |
328 |
||
329 |
removeFromDllPath:aDirectoryPathName |
|
330 |
"remove added places from dll-loading" |
|
331 |
||
332 |
|oldPath| |
|
333 |
||
334 |
oldPath := self dllPath. |
|
335 |
self dllPath:(oldPath asOrderedCollection copyWithout:aDirectoryPathName) |
|
336 |
||
337 |
" |
|
338 |
self dllPath. |
|
11586 | 339 |
self addToDllPath:'C:\aaa\bbb'. |
11053 | 340 |
self dllPath. |
341 |
self removeFromDllPath:'C:\aaa\bbb'. |
|
342 |
self dllPath. |
|
343 |
" |
|
8550 | 344 |
! ! |
345 |
||
9321 | 346 |
!ExternalLibraryFunction class methodsFor:'constants'! |
347 |
||
348 |
callTypeAPI |
|
9463 | 349 |
^ CALLTYPE_API |
9321 | 350 |
|
9463 | 351 |
"Modified: / 01-08-2006 / 13:44:41 / cg" |
9435 | 352 |
! |
353 |
||
9321 | 354 |
callTypeC |
9463 | 355 |
^ CALLTYPE_C |
9321 | 356 |
|
9463 | 357 |
"Modified: / 01-08-2006 / 13:44:49 / cg" |
9435 | 358 |
! |
359 |
||
9321 | 360 |
callTypeCDecl |
9463 | 361 |
^ CALLTYPE_C |
9321 | 362 |
|
9463 | 363 |
"Modified: / 01-08-2006 / 13:44:52 / cg" |
9435 | 364 |
! |
365 |
||
10619 | 366 |
callTypeMASK |
367 |
^ CALLTYPE_MASK |
|
368 |
||
369 |
"Modified: / 01-08-2006 / 13:44:57 / cg" |
|
370 |
! |
|
371 |
||
9321 | 372 |
callTypeOLE |
9463 | 373 |
^ CALLTYPE_OLE |
9435 | 374 |
|
9463 | 375 |
"Modified: / 01-08-2006 / 13:44:57 / cg" |
9321 | 376 |
! ! |
377 |
||
19505 | 378 |
!ExternalLibraryFunction class methodsFor:'debugging'! |
379 |
||
380 |
verbose:aBoolean |
|
381 |
"turn on/off tracing of calls" |
|
382 |
||
383 |
Verbose := aBoolean |
|
384 |
||
385 |
" |
|
386 |
ExternalLibraryFunction verbose:true |
|
387 |
" |
|
388 |
||
389 |
"Created: / 30-03-2016 / 17:28:23 / cg" |
|
390 |
! ! |
|
391 |
||
19490 | 392 |
!ExternalLibraryFunction class methodsFor:'type name mapping'! |
393 |
||
394 |
ffiTypeSymbolForType:aType |
|
395 |
"map type to one of the ffi-supported ones: |
|
19535 | 396 |
sint8, sint16, sint32, sint64 |
397 |
uint8, uint16, uint32, uint64 |
|
398 |
bool void pointer handle |
|
19490 | 399 |
" |
400 |
||
401 |
aType == #sint8 ifTrue:[^ aType ]. |
|
402 |
aType == #sint16 ifTrue:[^ aType ]. |
|
403 |
aType == #sint32 ifTrue:[^ aType ]. |
|
404 |
aType == #sint64 ifTrue:[^ aType ]. |
|
405 |
aType == #uint8 ifTrue:[^ aType ]. |
|
406 |
aType == #uint16 ifTrue:[^ aType ]. |
|
407 |
aType == #uint32 ifTrue:[^ aType ]. |
|
408 |
aType == #uint64 ifTrue:[^ aType ]. |
|
409 |
aType == #double ifTrue:[^ aType ]. |
|
410 |
aType == #float ifTrue:[^ aType ]. |
|
411 |
aType == #char ifTrue:[^ aType ]. |
|
412 |
aType == #void ifTrue:[^ aType ]. |
|
413 |
aType == #bool ifTrue:[^ aType ]. |
|
414 |
aType == #pointer ifTrue:[^ aType ]. |
|
415 |
aType == #charPointer ifTrue:[^ aType ]. |
|
416 |
aType == #wcharPointer ifTrue:[^ aType ]. |
|
417 |
||
418 |
aType == #int8 ifTrue:[^ #sint8 ]. |
|
419 |
aType == #int16 ifTrue:[^ #sint16 ]. |
|
420 |
aType == #int32 ifTrue:[^ #sint32 ]. |
|
421 |
aType == #int64 ifTrue:[^ #sint64 ]. |
|
422 |
||
423 |
aType == #voidPointer ifTrue:[^ #pointer ]. |
|
424 |
aType == #uint8Pointer ifTrue:[^ #pointer ]. |
|
425 |
aType == #voidPointerPointer ifTrue:[^ #pointer ]. |
|
426 |
||
427 |
aType == #short ifTrue:[^ #sint16 ]. |
|
428 |
aType == #long ifTrue:[^ #long ]. |
|
429 |
aType == #int ifTrue:[^ #int ]. |
|
430 |
aType == #uint ifTrue:[^ #uint ]. |
|
431 |
aType == #ushort ifTrue:[^ #uint16 ]. |
|
432 |
aType == #unsignedShort ifTrue:[^ #uint16 ]. |
|
433 |
aType == #ulong ifTrue:[^ #ulong ]. |
|
434 |
aType == #unsignedLong ifTrue:[^ #ulong ]. |
|
435 |
aType == #uchar ifTrue:[^ #uint8 ]. |
|
436 |
aType == #unsignedChar ifTrue:[^ #uint8 ]. |
|
437 |
aType == #byte ifTrue:[^ #uint8 ]. |
|
438 |
aType == #longlong ifTrue:[^ #sint64 ]. |
|
439 |
aType == #longLong ifTrue:[^ #sint64 ]. |
|
440 |
aType == #ulonglong ifTrue:[^ #uint64 ]. |
|
441 |
aType == #ulongLong ifTrue:[^ #uint64 ]. |
|
442 |
||
443 |
"/ windefs |
|
444 |
aType == #dword ifTrue:[^ #uint32 ]. |
|
445 |
aType == #sdword ifTrue:[^ #sint32 ]. |
|
446 |
aType == #word ifTrue:[^ #uint16 ]. |
|
447 |
aType == #sword ifTrue:[^ #sint16 ]. |
|
448 |
aType == #handle ifTrue:[^ #pointer ]. |
|
449 |
aType == #lpstr ifTrue:[^ #charPointer ]. |
|
19501 | 450 |
"/ aType == #hresult ifTrue:[^ #uint32 ]. -- keep this; it is translated later (in invoke) |
19490 | 451 |
aType == #boolean ifTrue:[^ #bool ]. |
452 |
"/ care for 64bit machines |
|
453 |
aType == #ulongReturn ifTrue:[^ ExternalAddress pointerSize == 8 ifTrue:[#uint64] ifFalse:[#uint32]]. |
|
454 |
aType == #none ifTrue:[^ #void ]. |
|
455 |
aType == #struct ifTrue:[^ #pointer ]. |
|
456 |
aType == #structIn ifTrue:[^ #pointer ]. |
|
457 |
aType == #structOut ifTrue:[^ #pointer ]. |
|
458 |
aType == #structInOut ifTrue:[^ #pointer ]. |
|
459 |
aType == #unsigned ifTrue:[^ #uint ]. |
|
460 |
||
461 |
aType == #ATOM ifTrue:[^ #uint16 ]. |
|
462 |
aType == #BOOL ifTrue:[^ #int ]. |
|
463 |
aType == #BOOLEAN ifTrue:[^ #uint8 ]. |
|
464 |
aType == #BYTE ifTrue:[^ #uint8 ]. |
|
465 |
aType == #DWORD ifTrue:[^ #uint32 ]. |
|
466 |
aType == #HANDLE ifTrue:[^ #pointer ]. |
|
19535 | 467 |
aType == #HRESULT ifTrue:[^ #hresult ]. |
19501 | 468 |
|
19490 | 469 |
"/ care for 64bit machines |
470 |
aType == #SIZE_T ifTrue:[^ ExternalAddress pointerSize == 8 ifTrue:[#uint64] ifFalse:[#uint32]]. |
|
19494 | 471 |
aType == #BSTR ifTrue:[^ #wcharPointer]. |
19490 | 472 |
|
473 |
(aType isString or:[aType isSymbol]) ifFalse:[ |
|
19535 | 474 |
CType isNil ifTrue:[ |
475 |
self error:'unknown type'. |
|
476 |
]. |
|
477 |
^ aType typeSymbol. |
|
19490 | 478 |
]. |
479 |
||
480 |
(aType endsWith:'*') ifTrue:[ |
|
19535 | 481 |
^ #pointer. |
19490 | 482 |
]. |
483 |
(aType endsWith:'Pointer') ifTrue:[ |
|
19535 | 484 |
^ #pointer. |
19490 | 485 |
]. |
486 |
^ aType |
|
487 |
||
19501 | 488 |
"Modified (format): / 30-03-2016 / 13:45:09 / cg" |
19490 | 489 |
! ! |
490 |
||
9321 | 491 |
!ExternalLibraryFunction methodsFor:'accessing'! |
492 |
||
493 |
argumentTypes |
|
494 |
^ argumentTypes |
|
9463 | 495 |
! |
496 |
||
11426 | 497 |
argumentTypesString |
11586 | 498 |
^ String |
499 |
streamContents:[:s | |
|
500 |
argumentTypes do:[:eachArgType | |
|
501 |
eachArgType printOn:s. |
|
502 |
] separatedBy:[ |
|
503 |
s nextPutAll:','. |
|
504 |
]. |
|
505 |
]. |
|
11426 | 506 |
! |
507 |
||
9463 | 508 |
beAsync |
509 |
"let this execute in a separate thread, in par with the other execution thread(s). |
|
510 |
Ignored under unix/linux (until those support multiple threads too)." |
|
511 |
||
512 |
flags := (flags ? 0) bitOr: FLAG_ASYNC. |
|
513 |
||
514 |
"Created: / 01-08-2006 / 13:42:38 / cg" |
|
515 |
! |
|
516 |
||
9465 | 517 |
beCallTypeAPI |
518 |
flags := (flags ? 0) bitOr: CALLTYPE_API. |
|
519 |
||
520 |
"Created: / 01-08-2006 / 15:12:40 / cg" |
|
521 |
! |
|
522 |
||
523 |
beCallTypeC |
|
524 |
flags := (flags ? 0) bitOr: CALLTYPE_C. |
|
525 |
||
526 |
"Created: / 01-08-2006 / 15:12:40 / cg" |
|
527 |
! |
|
528 |
||
10481 | 529 |
beCallTypeOLE |
530 |
flags := (flags ? 0) bitOr: FLAG_VIRTUAL. |
|
531 |
||
532 |
"Created: / 01-08-2006 / 15:12:40 / cg" |
|
533 |
! |
|
534 |
||
9465 | 535 |
beCallTypeUNIX64 |
536 |
flags := (flags ? 0) bitOr: CALLTYPE_UNIX64. |
|
537 |
||
538 |
"Created: / 01-08-2006 / 15:13:38 / cg" |
|
539 |
! |
|
540 |
||
541 |
beCallTypeV8 |
|
542 |
flags := (flags ? 0) bitOr: CALLTYPE_V8. |
|
543 |
||
544 |
"Created: / 01-08-2006 / 15:13:28 / cg" |
|
545 |
! |
|
546 |
||
547 |
beCallTypeV9 |
|
548 |
flags := (flags ? 0) bitOr: CALLTYPE_V9. |
|
549 |
||
550 |
"Created: / 01-08-2006 / 15:13:31 / cg" |
|
551 |
! |
|
552 |
||
553 |
beCallTypeWINAPI |
|
554 |
self beCallTypeAPI |
|
555 |
||
556 |
"Modified: / 01-08-2006 / 15:14:02 / cg" |
|
557 |
! |
|
558 |
||
9525 | 559 |
beConstReturnValue |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
560 |
"specify that a pointer return value is not to be finalized |
9525 | 561 |
(i.e. points to static data or data which is freed by c)" |
562 |
||
563 |
flags := (flags ? 0) bitOr: FLAG_RETVAL_IS_CONST. |
|
564 |
||
565 |
"Created: / 01-08-2006 / 13:56:48 / cg" |
|
566 |
! |
|
567 |
||
9463 | 568 |
beNonVirtualCPP |
569 |
"specify this as a non-virtual c++-function" |
|
570 |
||
571 |
flags := (flags ? 0) bitOr: FLAG_NONVIRTUAL. |
|
572 |
||
573 |
"Created: / 01-08-2006 / 13:56:44 / cg" |
|
574 |
! |
|
575 |
||
19311 | 576 |
beObjectiveC |
577 |
"specify this as an objective-c message send" |
|
578 |
||
579 |
flags := (flags ? 0) bitOr: FLAG_OBJECTIVEC. |
|
580 |
||
581 |
"Created: / 01-08-2006 / 13:56:48 / cg" |
|
582 |
! |
|
583 |
||
9463 | 584 |
beUnlimitedStack |
585 |
"let this execute on the c-stack (as opposed to the thread-stack) |
|
586 |
for unlimited auto-sized-stack under unix/linux. |
|
587 |
Ignored under windows." |
|
588 |
||
589 |
flags := (flags ? 0) bitOr: FLAG_UNLIMITEDSTACK. |
|
590 |
||
591 |
"Created: / 01-08-2006 / 13:41:54 / cg" |
|
592 |
! |
|
593 |
||
594 |
beVirtualCPP |
|
595 |
"specify this as a virtual c++-function" |
|
596 |
||
597 |
flags := (flags ? 0) bitOr: FLAG_VIRTUAL. |
|
598 |
||
599 |
"Created: / 01-08-2006 / 13:56:48 / cg" |
|
600 |
! |
|
601 |
||
9465 | 602 |
callTypeNumber |
603 |
^ (flags ? 0) bitAnd: CALLTYPE_MASK. |
|
604 |
||
605 |
"Created: / 01-08-2006 / 15:12:10 / cg" |
|
606 |
! |
|
607 |
||
9463 | 608 |
isAsync |
609 |
"is this executed in a separate thread, in par with the other execution thread(s) ?" |
|
610 |
||
611 |
^ (flags ? 0) bitTest: FLAG_ASYNC. |
|
612 |
||
613 |
"Created: / 01-08-2006 / 13:46:53 / cg" |
|
614 |
! |
|
615 |
||
9519 | 616 |
isCPPFunction |
617 |
"is this a virtual or non-virtual c++-function ?" |
|
618 |
||
619 |
^ (flags ? 0) bitTest: (FLAG_VIRTUAL bitOr: FLAG_NONVIRTUAL). |
|
620 |
||
621 |
"Created: / 01-08-2006 / 13:56:54 / cg" |
|
622 |
! |
|
623 |
||
9465 | 624 |
isCallTypeAPI |
19490 | 625 |
"is this a windows API-call linkage call. |
626 |
Attention: this uses a different call API (callee unwinds the stack), |
|
627 |
and MUST be declared as such for many Kernel functions. |
|
628 |
The calltype API is one of the worst historic garbage kept by MS..." |
|
629 |
||
9465 | 630 |
^ ((flags ? 0) bitAnd: CALLTYPE_MASK) == CALLTYPE_API. |
631 |
||
632 |
"Created: / 01-08-2006 / 15:21:16 / cg" |
|
633 |
! |
|
634 |
||
635 |
isCallTypeC |
|
19490 | 636 |
"is this a regular C-call (attention: on windows, there are two kinds of calls)" |
637 |
||
9465 | 638 |
^ ((flags ? 0) bitAnd: CALLTYPE_MASK) == CALLTYPE_C. |
639 |
||
640 |
"Created: / 01-08-2006 / 15:21:23 / cg" |
|
641 |
! |
|
642 |
||
10483 | 643 |
isCallTypeOLE |
19490 | 644 |
"is this an OLE-object call ? (eg. a virtual c++ call; same as isCallTypeCPP)" |
645 |
||
10483 | 646 |
^ ((flags ? 0) bitTest: FLAG_VIRTUAL). |
647 |
||
648 |
"Created: / 01-08-2006 / 15:21:23 / cg" |
|
649 |
! |
|
650 |
||
9525 | 651 |
isConstReturnValue |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
652 |
"is the pointer return value not to be finalized |
9525 | 653 |
(i.e. points to static data or data which is freed by c)" |
654 |
||
655 |
^ (flags ? 0) bitTest: FLAG_RETVAL_IS_CONST. |
|
656 |
||
657 |
"Created: / 01-08-2006 / 13:56:48 / cg" |
|
658 |
! |
|
659 |
||
9463 | 660 |
isNonVirtualCPP |
661 |
"is this a non-virtual c++-function ?" |
|
662 |
||
663 |
^ (flags ? 0) bitTest: FLAG_NONVIRTUAL. |
|
664 |
||
665 |
"Created: / 01-08-2006 / 13:56:51 / cg" |
|
666 |
! |
|
667 |
||
19311 | 668 |
isObjectiveC |
669 |
"is this an objective-C message?" |
|
670 |
||
671 |
^ (flags ? 0) bitTest: FLAG_OBJECTIVEC. |
|
672 |
! |
|
673 |
||
9463 | 674 |
isUnlimitedStack |
675 |
"will this execute on the c-stack (as opposed to the thread-stack) |
|
676 |
for unlimited auto-sized-stack under unix/linux. |
|
677 |
Ignored under windows." |
|
678 |
||
679 |
^ (flags ? 0) bitTest: FLAG_UNLIMITEDSTACK. |
|
680 |
||
681 |
"Created: / 01-08-2006 / 14:17:07 / cg" |
|
682 |
! |
|
683 |
||
684 |
isVirtualCPP |
|
19490 | 685 |
"is this a virtual c++-function (same as isCallTypeOLE) ?" |
9463 | 686 |
|
687 |
^ (flags ? 0) bitTest: FLAG_VIRTUAL. |
|
688 |
||
689 |
"Created: / 01-08-2006 / 13:56:54 / cg" |
|
10483 | 690 |
! |
691 |
||
11426 | 692 |
moduleName |
693 |
^ moduleName |
|
694 |
! |
|
695 |
||
10484 | 696 |
returnType |
697 |
^ returnType |
|
698 |
! |
|
699 |
||
10483 | 700 |
vtableIndex |
701 |
name isNumber ifFalse:[^ nil]. |
|
702 |
^ name. |
|
9321 | 703 |
! ! |
704 |
||
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
705 |
!ExternalLibraryFunction methodsFor:'invoking'! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
706 |
|
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
707 |
invoke |
9321 | 708 |
self hasCode ifFalse:[ |
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
709 |
self prepareInvoke. |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
710 |
]. |
19311 | 711 |
^ self invokeFFIwithArguments:nil forCPPInstance:nil |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
712 |
! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
713 |
|
9347 | 714 |
invokeCPPVirtualOn:anInstance |
9341 | 715 |
self hasCode ifFalse:[ |
11586 | 716 |
self prepareInvoke. |
9341 | 717 |
]. |
10440 | 718 |
^ self invokeCPPVirtualFFIOn:anInstance withArguments:nil |
9341 | 719 |
! |
720 |
||
9347 | 721 |
invokeCPPVirtualOn:instance with:arg |
9341 | 722 |
self hasCode ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
723 |
self prepareInvoke. |
9341 | 724 |
]. |
9347 | 725 |
^ self invokeCPPVirtualFFIOn:instance withArguments:(Array with:arg) |
9341 | 726 |
! |
727 |
||
9347 | 728 |
invokeCPPVirtualOn:instance with:arg1 with:arg2 |
9341 | 729 |
self hasCode ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
730 |
self prepareInvoke. |
9341 | 731 |
]. |
9347 | 732 |
^ self invokeCPPVirtualFFIOn:instance withArguments:(Array with:arg1 with:arg2) |
9341 | 733 |
! |
734 |
||
9347 | 735 |
invokeCPPVirtualOn:instance with:arg1 with:arg2 with:arg3 |
9341 | 736 |
self hasCode ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
737 |
self prepareInvoke. |
9341 | 738 |
]. |
9347 | 739 |
^ self invokeCPPVirtualFFIOn:instance withArguments:(Array with:arg1 with:arg2 with:arg3) |
9341 | 740 |
! |
741 |
||
9347 | 742 |
invokeCPPVirtualOn:instance with:arg1 with:arg2 with:arg3 with:arg4 |
9341 | 743 |
self hasCode ifFalse:[ |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
744 |
self prepareInvoke. |
9341 | 745 |
]. |
9347 | 746 |
^ self invokeCPPVirtualFFIOn:instance withArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) |
9341 | 747 |
! |
748 |
||
10481 | 749 |
invokeCPPVirtualOn:instance withArguments:args |
750 |
self hasCode ifFalse:[ |
|
11586 | 751 |
self prepareInvoke. |
10481 | 752 |
]. |
753 |
^ self invokeCPPVirtualFFIOn:instance withArguments:args |
|
754 |
! |
|
755 |
||
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
756 |
invokeWith:arg |
9321 | 757 |
self hasCode ifFalse:[ |
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
758 |
self prepareInvoke. |
9321 | 759 |
]. |
19311 | 760 |
^ self invokeFFIwithArguments:(Array with:arg) forCPPInstance:nil |
9321 | 761 |
! |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
762 |
|
9321 | 763 |
invokeWith:arg1 with:arg2 |
764 |
self hasCode ifFalse:[ |
|
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
765 |
self prepareInvoke. |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
766 |
]. |
19311 | 767 |
^ self invokeFFIwithArguments:(Array with:arg1 with:arg2) forCPPInstance:nil |
9321 | 768 |
! |
769 |
||
770 |
invokeWith:arg1 with:arg2 with:arg3 |
|
771 |
self hasCode ifFalse:[ |
|
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
772 |
self prepareInvoke. |
9321 | 773 |
]. |
19311 | 774 |
^ self invokeFFIwithArguments:(Array with:arg1 with:arg2 with:arg3) forCPPInstance:nil |
9321 | 775 |
! |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
776 |
|
9321 | 777 |
invokeWith:arg1 with:arg2 with:arg3 with:arg4 |
778 |
self hasCode ifFalse:[ |
|
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
779 |
self prepareInvoke. |
9321 | 780 |
]. |
19311 | 781 |
^ self invokeFFIwithArguments:(Array with:arg1 with:arg2 with:arg3 with:arg4) forCPPInstance:nil |
9321 | 782 |
! |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
783 |
|
9321 | 784 |
invokeWithArguments:argArray |
785 |
self hasCode ifFalse:[ |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
786 |
self prepareInvoke. |
9321 | 787 |
]. |
9465 | 788 |
^ self invokeFFIwithArguments:argArray forCPPInstance:nil |
789 |
||
790 |
"Modified: / 01-08-2006 / 16:04:08 / cg" |
|
9321 | 791 |
! ! |
792 |
||
793 |
!ExternalLibraryFunction methodsFor:'printing'! |
|
794 |
||
795 |
printOn:aStream |
|
796 |
aStream nextPutAll:'<'. |
|
9465 | 797 |
self isCallTypeAPI ifTrue:[ |
14625 | 798 |
'API:' printOn:aStream. |
9465 | 799 |
] ifFalse:[ |
14625 | 800 |
self isCallTypeOLE ifTrue:[ |
801 |
'OLE:' printOn:aStream. |
|
802 |
] ifFalse:[ |
|
803 |
self isCallTypeC ifTrue:[ |
|
804 |
'C:' printOn:aStream. |
|
805 |
] ifFalse:[ |
|
806 |
self error. |
|
807 |
]. |
|
808 |
]. |
|
9465 | 809 |
]. |
9321 | 810 |
aStream nextPutAll:' '. |
811 |
name printOn:aStream. |
|
9465 | 812 |
moduleName notNil ifTrue:[ |
14625 | 813 |
aStream nextPutAll:' module:'. |
814 |
moduleName printOn:aStream. |
|
9465 | 815 |
]. |
9321 | 816 |
aStream nextPutAll:'>'. |
9465 | 817 |
|
14356 | 818 |
"Modified: / 25-09-2012 / 12:06:14 / cg" |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
819 |
! ! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
820 |
|
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
821 |
!ExternalLibraryFunction methodsFor:'private'! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
822 |
|
10213 | 823 |
adjustTypes |
19490 | 824 |
"map all those existing type names to a small number of definite ffi type names. |
825 |
This is needed, because there are so many different C-type names found in code imported |
|
826 |
from various Smalltalk dialects' library function call declarations. |
|
827 |
For example: all of word, WORD, unsignedShort, ushort, uShort etc. will map to uint16. |
|
828 |
Also, this deals with pointer size differences." |
|
829 |
||
19313 | 830 |
argumentTypes notEmptyOrNil ifTrue:[ |
19535 | 831 |
argumentTypes := argumentTypes collect:[:argType | self class ffiTypeSymbolForType:argType]. |
10213 | 832 |
]. |
19490 | 833 |
returnType := self class ffiTypeSymbolForType:returnType. |
10213 | 834 |
! |
835 |
||
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
836 |
linkToModule |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
837 |
"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
|
838 |
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
|
839 |
|
9465 | 840 |
|handle moduleNameUsed functionName| |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
841 |
|
10481 | 842 |
name isNumber ifTrue:[ |
19535 | 843 |
self isCPPFunction ifTrue:[ |
844 |
"/ no need to load a dll. |
|
845 |
^ self |
|
846 |
] |
|
10481 | 847 |
]. |
848 |
||
13782
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
849 |
"/ in some other smalltalks, there is no moduleName in the ffi-spec; |
1994fe87f21e
comment/format in: #linkToModule
Claus Gittinger <cg@exept.de>
parents:
13412
diff
changeset
|
850 |
"/ instead, the class provides the libraryName... |
9465 | 851 |
(moduleNameUsed := moduleName) isNil ifTrue:[ |
19535 | 852 |
owningClass isNil ifTrue:[ |
853 |
self error:'Missing moduleName'. |
|
854 |
]. |
|
855 |
moduleNameUsed := owningClass theNonMetaclass libraryName asSymbol. |
|
9321 | 856 |
]. |
11586 | 857 |
moduleHandle isNil ifTrue:[ |
19535 | 858 |
"/ speedup. in 95% of all calls, the same moduleName is resolved here |
859 |
(LastModuleHandleHolder isNil |
|
860 |
or:[ (handle := LastModuleHandleHolder at:1) isNil |
|
861 |
or:[ LastModuleHandleName ~= moduleNameUsed ]]) ifTrue:[ |
|
19342 | 862 |
|
19535 | 863 |
handle := self loadLibrary:moduleNameUsed. |
864 |
handle isNil ifTrue:[ |
|
865 |
self error:('Cannot find or load dll/module: "%1"' bindWith: moduleNameUsed). |
|
866 |
]. |
|
867 |
LastModuleHandleHolder := WeakArray with:handle. |
|
868 |
LastModuleHandleName := moduleNameUsed. |
|
869 |
]. |
|
870 |
moduleHandle := handle. |
|
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
871 |
]. |
9341 | 872 |
name isNumber ifFalse:[ |
19535 | 873 |
functionName := name. |
874 |
(moduleHandle getFunctionAddress:functionName into:self) isNil ifTrue:[ |
|
875 |
(moduleHandle getFunctionAddress:('_', functionName) into:self) isNil ifTrue:[ |
|
876 |
moduleHandle := nil. |
|
877 |
self error:'Missing function: ', name, ' in module: ', moduleNameUsed. |
|
878 |
]. |
|
879 |
]. |
|
9321 | 880 |
]. |
9392 | 881 |
|
14103 | 882 |
"Modified: / 10-04-2012 / 12:12:44 / cg" |
9321 | 883 |
! |
884 |
||
10270 | 885 |
loadLibrary:dllName |
19490 | 886 |
"load a dll. |
887 |
Notice the dllMapping mechanism, which can be used to silently load different dlls. |
|
888 |
This is useful, if some code has a hardcoded dll-name in it, which needs to be changed, |
|
889 |
but you do not want or cannot recompile the methods (i.e. no source avail)" |
|
890 |
||
12436 | 891 |
|handle nameString filename| |
10279
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
892 |
|
14103 | 893 |
filename := dllName. |
894 |
DllMapping notNil ifTrue:[ |
|
19535 | 895 |
filename := DllMapping at:filename ifAbsent:[ filename ] |
14103 | 896 |
]. |
897 |
||
898 |
filename := filename asFilename. |
|
12436 | 899 |
nameString := filename name. |
10279
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
900 |
|
12937 | 901 |
"try to load, maybe the system knows where to find the dll" |
902 |
handle := ObjectFileLoader loadDynamicObject:filename. |
|
903 |
handle notNil ifTrue:[^ handle ]. |
|
904 |
||
12436 | 905 |
filename isAbsolute ifFalse:[ |
19535 | 906 |
"First ask the class defining the ExternalFunction for the location of the dlls ..." |
907 |
owningClass notNil ifTrue:[ |
|
908 |
owningClass dllPath do:[:eachDirectory | |
|
909 |
handle := ObjectFileLoader |
|
910 |
loadDynamicObject:(eachDirectory asFilename construct:nameString) pathName. |
|
911 |
handle notNil ifTrue:[^ handle ]. |
|
912 |
]. |
|
913 |
]. |
|
914 |
".. then ask the system" |
|
915 |
self class dllPath do:[:eachDirectory | |
|
916 |
handle := ObjectFileLoader |
|
917 |
loadDynamicObject:(eachDirectory asFilename construct:nameString) pathName. |
|
918 |
handle notNil ifTrue:[^ handle ]. |
|
919 |
]. |
|
10279
60c42983fdd4
first test whether the dllName is the complete filename
ca
parents:
10270
diff
changeset
|
920 |
]. |
10270 | 921 |
|
12436 | 922 |
filename suffix isEmpty ifTrue:[ |
19535 | 923 |
"/ try again with the OS-specific dll-extension |
924 |
^ self loadLibrary:(filename withSuffix:ObjectFileLoader sharedLibrarySuffix) |
|
10270 | 925 |
]. |
12436 | 926 |
|
10270 | 927 |
^ nil |
14103 | 928 |
|
929 |
"Modified: / 10-04-2012 / 12:21:06 / cg" |
|
10270 | 930 |
! |
931 |
||
9321 | 932 |
prepareInvoke |
19490 | 933 |
"called before invoked. |
19535 | 934 |
When called the very first time, moduleHandle is nil, |
19490 | 935 |
and we ensure that the dll is loaded, the function address is extracted" |
936 |
||
10270 | 937 |
(moduleHandle isNil or:[self hasCode not]) ifTrue:[ |
19535 | 938 |
self linkToModule. |
939 |
self adjustTypes. |
|
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
940 |
]. |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
941 |
! ! |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
942 |
|
8550 | 943 |
!ExternalLibraryFunction methodsFor:'private-accessing'! |
944 |
||
9466 | 945 |
name:functionNameOrVirtualIndex module:aModuleName returnType:aReturnType argumentTypes:argTypes |
946 |
name := functionNameOrVirtualIndex. |
|
947 |
functionNameOrVirtualIndex isNumber ifTrue:[ |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
948 |
self beVirtualCPP. |
9466 | 949 |
]. |
8891
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
950 |
moduleName := aModuleName. |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
951 |
returnType := aReturnType. |
c30a030ff5ec
more FFI (foreign function interface) support - still incomplete
Stefan Vogel <sv@exept.de>
parents:
8728
diff
changeset
|
952 |
argumentTypes := argTypes. |
9465 | 953 |
|
954 |
"Created: / 01-08-2006 / 15:19:52 / cg" |
|
9466 | 955 |
"Modified: / 02-08-2006 / 17:20:13 / cg" |
9465 | 956 |
! |
957 |
||
11426 | 958 |
owningClass |
959 |
^ owningClass |
|
960 |
! |
|
961 |
||
9465 | 962 |
owningClass:aClass |
963 |
owningClass := aClass. |
|
964 |
||
965 |
"Created: / 01-08-2006 / 15:22:50 / cg" |
|
10603 | 966 |
! |
967 |
||
11586 | 968 |
setModuleName:aModuleName |
10603 | 969 |
aModuleName ~= moduleName ifTrue:[ |
11586 | 970 |
self code:nil. |
971 |
moduleHandle := nil. |
|
972 |
moduleName := aModuleName. |
|
10603 | 973 |
]. |
974 |
||
975 |
"Created: / 07-06-2007 / 10:20:17 / cg" |
|
8550 | 976 |
! ! |
977 |
||
9342 | 978 |
!ExternalLibraryFunction methodsFor:'private-invoking'! |
979 |
||
9347 | 980 |
invokeCPPVirtualFFIOn:instance withArguments:arguments |
9463 | 981 |
^ self invokeFFIwithArguments:arguments forCPPInstance:instance |
982 |
||
983 |
"Modified: / 01-08-2006 / 13:55:30 / cg" |
|
9342 | 984 |
! |
985 |
||
9347 | 986 |
invokeFFIWithArguments:arguments |
9463 | 987 |
^ self invokeFFIwithArguments:arguments forCPPInstance:nil |
988 |
||
989 |
"Modified: / 01-08-2006 / 13:55:35 / cg" |
|
9347 | 990 |
! |
991 |
||
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
992 |
invokeFFIwithArguments:argumentsOrNil forCPPInstance:aReceiverOrNil |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
993 |
"basic invoke mechanism. Calls the function represented by the receiver with argumentsOrNil. |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
994 |
For cplusplus, aReceiverOrNil is required to be an externalStructure like object; |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
995 |
for objectiveC, it must be an ObjectiveC object" |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
996 |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
997 |
|argTypeSymbols returnTypeSymbol failureCode failureArgNr failureInfo returnValue stClass vtOffset |
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
998 |
virtual objectiveC async unlimitedStack callTypeNumber returnValueClass argValueClass |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
999 |
oldReturnType oldArgumentTypes| |
9342 | 1000 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1001 |
argTypeSymbols := argumentTypes. |
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1002 |
returnTypeSymbol := returnType. |
9346 | 1003 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1004 |
virtual := self isVirtualCPP. |
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1005 |
objectiveC := self isObjectiveC. |
9524 | 1006 |
(virtual "or:[self isNonVirtualCPP]") ifTrue:[ |
19535 | 1007 |
aReceiverOrNil isNil ifTrue:[ |
1008 |
"/ must have a c++ object instance |
|
1009 |
self primitiveFailed. |
|
1010 |
]. |
|
9463 | 1011 |
|
19535 | 1012 |
"/ and it must be a kind of ExternalStructure !! |
1013 |
(aReceiverOrNil isKindOf:ExternalStructure) ifFalse:[ |
|
1014 |
self primitiveFailed. |
|
1015 |
]. |
|
1016 |
virtual ifTrue:[ |
|
1017 |
vtOffset := name. |
|
1018 |
(vtOffset between:0 and:10000) ifFalse:[ |
|
1019 |
self primitiveFailed. |
|
1020 |
] |
|
1021 |
]. |
|
9463 | 1022 |
] ifFalse:[ |
19535 | 1023 |
objectiveC ifTrue:[ |
1024 |
aReceiverOrNil isNil ifTrue:[ |
|
1025 |
"/ must have an objective-c object instance |
|
1026 |
self primitiveFailed. |
|
1027 |
]. |
|
1028 |
(aReceiverOrNil isObjectiveCObject) ifFalse:[ |
|
1029 |
self primitiveFailed |
|
1030 |
] |
|
1031 |
] ifFalse:[ |
|
1032 |
aReceiverOrNil notNil ifTrue:[ |
|
1033 |
"/ must NOT have a c++/objectiveC object instance |
|
1034 |
self primitiveFailed. |
|
1035 |
] |
|
1036 |
]. |
|
9342 | 1037 |
]. |
9463 | 1038 |
async := self isAsync. |
1039 |
unlimitedStack := self isUnlimitedStack. |
|
9465 | 1040 |
callTypeNumber := self callTypeNumber. |
10512 | 1041 |
"/ Transcript show:name; show:' async:'; showCR:async. |
9342 | 1042 |
|
9459
6cd520c582b3
change from unlimited to big stack, to allow for interrupts to be handled
ca
parents:
9436
diff
changeset
|
1043 |
%{ /* STACK: 100000 */ |
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1044 |
|
19931 | 1045 |
#define VERBOSE |
1046 |
||
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1047 |
#ifdef HAVE_FFI |
19931 | 1048 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1049 |
# ifdef __GNUC__ |
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1050 |
# ifndef HAS_LONGLONG |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1051 |
# define HAS_LONGLONG |
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1052 |
# endif |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1053 |
# endif |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1054 |
# if defined(__BORLANDC__) || defined(__VISUALC__) |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1055 |
# define HAS_INT64 |
19364 | 1056 |
# ifndef __LO32 |
1057 |
# define __LO32(ll) ((ll) & 0xFFFFFFFFL) |
|
1058 |
# define __HI32(ll) (((ll)>>32) & 0xFFFFFFFFL) |
|
1059 |
# endif |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1060 |
# endif |
19931 | 1061 |
|
1062 |
||
9342 | 1063 |
ffi_cif __cif; |
1064 |
ffi_type *__argTypesIncludingThis[MAX_ARGS+1]; |
|
1065 |
ffi_type **__argTypes = __argTypesIncludingThis; |
|
1066 |
ffi_type *__returnType = NULL; |
|
19931 | 1067 |
ffi_type *thisType; |
1068 |
ffi_abi __callType = FFI_DEFAULT_ABI; |
|
1069 |
||
1070 |
#else |
|
1071 |
||
1072 |
int __argTypesIncludingThis[MAX_ARGS+1]; |
|
1073 |
int *__argTypes = __argTypesIncludingThis; |
|
1074 |
int __returnType = 0; |
|
1075 |
int thisType; |
|
1076 |
int __callType = FFI_DEFAULT_ABI; |
|
19932 | 1077 |
int __anyFloatOrDoubleArg = 0; |
19931 | 1078 |
#endif |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1079 |
|
9342 | 1080 |
union u { |
19535 | 1081 |
INT iVal; |
1082 |
float fVal; |
|
1083 |
double dVal; |
|
1084 |
void *pointerVal; |
|
19365
83a120bf2212
Fix syntax error bug with gcc32
Stefan Vogel <sv@exept.de>
parents:
19364
diff
changeset
|
1085 |
# if 0 && defined(HAS_LONGLONG) |
19535 | 1086 |
long long longLongVal; |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1087 |
# else |
19535 | 1088 |
__int64__ longLongVal; |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1089 |
# endif |
9342 | 1090 |
}; |
1091 |
union u __argValuesIncludingThis[MAX_ARGS+1]; |
|
1092 |
union u *__argValues = __argValuesIncludingThis; |
|
1093 |
union u __returnValue; |
|
1094 |
void *__argValuePointersIncludingThis[MAX_ARGS+1]; |
|
1095 |
void **__argValuePointers = __argValuePointersIncludingThis; |
|
1096 |
void *__returnValuePointer; |
|
1097 |
int __numArgs, __numArgsIncludingThis; |
|
19311 | 1098 |
static INT null = 0; |
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1099 |
int i = -1; |
9342 | 1100 |
VOIDFUNC codeAddress = (VOIDFUNC)__INST(code_); |
10440 | 1101 |
int __numArgsWanted; |
12579
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
1102 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1103 |
# define __FAIL__(fcode) \ |
10603 | 1104 |
{ \ |
19535 | 1105 |
failureCode = fcode; failureArgNr = __mkSmallInteger(i+1); goto getOutOfHere; \ |
10603 | 1106 |
} |
9342 | 1107 |
|
10440 | 1108 |
if (argumentsOrNil == nil) { |
19535 | 1109 |
__numArgs = 0; |
10440 | 1110 |
} else if (__isArray(argumentsOrNil)) { |
19535 | 1111 |
__numArgs = __arraySize(argumentsOrNil); |
9342 | 1112 |
} else { |
19535 | 1113 |
__FAIL__(@symbol(BadArgumentVector)) |
10440 | 1114 |
} |
1115 |
if (argTypeSymbols == nil) { |
|
19535 | 1116 |
__numArgsWanted = 0; |
10440 | 1117 |
} else if (__isArray(argTypeSymbols)) { |
19535 | 1118 |
__numArgsWanted = __arraySize(argTypeSymbols); |
10440 | 1119 |
} else { |
19535 | 1120 |
__FAIL__(@symbol(BadArgumentTypeVector)) |
10440 | 1121 |
} |
1122 |
||
1123 |
if (__numArgs != __numArgsWanted) { |
|
19535 | 1124 |
__FAIL__(@symbol(ArgumentCountMismatch)) |
9342 | 1125 |
} |
1126 |
if (__numArgs > MAX_ARGS) { |
|
19535 | 1127 |
__FAIL__(@symbol(TooManyArguments)) |
9342 | 1128 |
} |
1129 |
||
1130 |
/* |
|
19501 | 1131 |
* validate the return type and map it to an ffi_type |
9342 | 1132 |
*/ |
1133 |
__returnValuePointer = &__returnValue; |
|
9479 | 1134 |
|
9483 | 1135 |
if (returnTypeSymbol == @symbol(voidPointer)) { |
19535 | 1136 |
returnTypeSymbol = @symbol(handle); |
19501 | 1137 |
} else if (returnTypeSymbol == @symbol(hresult)) { |
19535 | 1138 |
returnTypeSymbol = @symbol(uint32); |
9483 | 1139 |
} |
9479 | 1140 |
|
9342 | 1141 |
if (returnTypeSymbol == @symbol(int)) { |
19931 | 1142 |
__returnType = TYPE_SINT; |
9342 | 1143 |
} else if (returnTypeSymbol == @symbol(uint)) { |
19931 | 1144 |
__returnType = TYPE_UINT; |
9479 | 1145 |
} else if (returnTypeSymbol == @symbol(uint8)) { |
19931 | 1146 |
__returnType = TYPE_UINT8; |
9479 | 1147 |
} else if (returnTypeSymbol == @symbol(uint16)) { |
19931 | 1148 |
__returnType = TYPE_UINT16; |
9479 | 1149 |
} else if (returnTypeSymbol == @symbol(uint32)) { |
19931 | 1150 |
__returnType = TYPE_UINT32; |
9479 | 1151 |
} else if (returnTypeSymbol == @symbol(uint64)) { |
19931 | 1152 |
__returnType = TYPE_UINT64; |
9479 | 1153 |
|
1154 |
} else if (returnTypeSymbol == @symbol(sint)) { |
|
19931 | 1155 |
__returnType = TYPE_SINT; |
9479 | 1156 |
} else if (returnTypeSymbol == @symbol(sint8)) { |
19931 | 1157 |
__returnType = TYPE_SINT8; |
9479 | 1158 |
} else if (returnTypeSymbol == @symbol(sint16)) { |
19931 | 1159 |
__returnType = TYPE_SINT16; |
9479 | 1160 |
} else if (returnTypeSymbol == @symbol(sint32)) { |
19931 | 1161 |
__returnType = TYPE_SINT32; |
9479 | 1162 |
} else if (returnTypeSymbol == @symbol(sint64)) { |
19931 | 1163 |
__returnType = TYPE_SINT64; |
9479 | 1164 |
|
9342 | 1165 |
} else if (returnTypeSymbol == @symbol(long)) { |
19535 | 1166 |
if (sizeof(long) == 4) { |
1167 |
returnTypeSymbol = @symbol(sint32); |
|
19931 | 1168 |
__returnType = TYPE_SINT32; |
19535 | 1169 |
} else if (sizeof(long) == 8) { |
1170 |
returnTypeSymbol = @symbol(sint64); |
|
19931 | 1171 |
__returnType = TYPE_SINT64; |
19535 | 1172 |
} else { |
1173 |
__FAIL__(@symbol(UnknownReturnType)) |
|
1174 |
} |
|
9479 | 1175 |
|
9342 | 1176 |
} else if (returnTypeSymbol == @symbol(ulong)) { |
19535 | 1177 |
if (sizeof(long) == 4) { |
1178 |
returnTypeSymbol = @symbol(uint32); |
|
19931 | 1179 |
__returnType = TYPE_UINT32; |
19535 | 1180 |
}else if (sizeof(long) == 8) { |
1181 |
returnTypeSymbol = @symbol(uint64); |
|
19931 | 1182 |
__returnType = TYPE_UINT64; |
19535 | 1183 |
} else { |
1184 |
__FAIL__(@symbol(UnknownReturnType)) |
|
1185 |
} |
|
9479 | 1186 |
|
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
1187 |
} else if (returnTypeSymbol == @symbol(bool)) { |
19931 | 1188 |
__returnType = TYPE_UINT; |
9479 | 1189 |
|
9342 | 1190 |
} else if (returnTypeSymbol == @symbol(float)) { |
19931 | 1191 |
__returnType = TYPE_FLOAT; |
9342 | 1192 |
} else if (returnTypeSymbol == @symbol(double)) { |
19931 | 1193 |
__returnType = TYPE_DOUBLE; |
9479 | 1194 |
|
9342 | 1195 |
} else if (returnTypeSymbol == @symbol(void)) { |
19931 | 1196 |
__returnType = TYPE_VOID; |
19535 | 1197 |
__returnValuePointer = NULL; |
11586 | 1198 |
} else if ((returnTypeSymbol == @symbol(pointer)) |
19535 | 1199 |
|| (returnTypeSymbol == @symbol(handle)) |
1200 |
|| (returnTypeSymbol == @symbol(charPointer)) |
|
1201 |
|| (returnTypeSymbol == @symbol(bytePointer)) |
|
1202 |
|| (returnTypeSymbol == @symbol(floatPointer)) |
|
1203 |
|| (returnTypeSymbol == @symbol(doublePointer)) |
|
1204 |
|| (returnTypeSymbol == @symbol(intPointer)) |
|
1205 |
|| (returnTypeSymbol == @symbol(shortPointer)) |
|
1206 |
|| (returnTypeSymbol == @symbol(wcharPointer))) { |
|
19931 | 1207 |
__returnType = TYPE_POINTER; |
9342 | 1208 |
} else { |
19535 | 1209 |
if (__isSymbol(returnTypeSymbol) |
1210 |
&& ((returnValueClass = __GLOBAL_GET(returnTypeSymbol)) != nil)) { |
|
1211 |
if (! __isBehaviorLike(returnValueClass)) { |
|
1212 |
__FAIL__(@symbol(NonBehaviorReturnType)) |
|
1213 |
} |
|
1214 |
if (! __qIsSubclassOfExternalAddress(returnValueClass)) { |
|
1215 |
__FAIL__(@symbol(NonExternalAddressReturnType)) |
|
1216 |
} |
|
19931 | 1217 |
__returnType = TYPE_POINTER; |
19535 | 1218 |
returnTypeSymbol = @symbol(pointer); |
1219 |
} else { |
|
1220 |
__FAIL__(@symbol(UnknownReturnType)) |
|
1221 |
} |
|
9342 | 1222 |
} |
1223 |
||
1224 |
/* |
|
1225 |
* validate the c++ object |
|
1226 |
*/ |
|
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
1227 |
if (aReceiverOrNil != nil) { |
19535 | 1228 |
struct cPlusPlusInstance { |
1229 |
void **vTable; |
|
1230 |
}; |
|
1231 |
struct cPlusPlusInstance *inst; |
|
9342 | 1232 |
|
19535 | 1233 |
if (__isExternalAddressLike(aReceiverOrNil)) { |
1234 |
inst = (void *)(__externalAddressVal(aReceiverOrNil)); |
|
1235 |
} else if (__isExternalBytesLike(aReceiverOrNil)) { |
|
1236 |
inst = (void *)(__externalBytesVal(aReceiverOrNil)); |
|
1237 |
} else { |
|
1238 |
__FAIL__(@symbol(InvalidInstance)) |
|
1239 |
} |
|
1240 |
__argValues[0].pointerVal = inst; |
|
1241 |
__argValuePointersIncludingThis[0] = &(__argValues[0]); |
|
19931 | 1242 |
__argTypes[0] = TYPE_POINTER; |
9342 | 1243 |
|
19535 | 1244 |
__argValuePointers = &__argValuePointersIncludingThis[1]; |
1245 |
__argTypes = &__argTypesIncludingThis[1]; |
|
1246 |
__argValues = &__argValuesIncludingThis[1]; |
|
1247 |
__numArgsIncludingThis = __numArgs + 1; |
|
9347 | 1248 |
|
19535 | 1249 |
if (virtual == true) { |
1250 |
if (! __isSmallInteger(vtOffset)) { |
|
1251 |
__FAIL__(@symbol(InvalidVTableIndex)) |
|
1252 |
} |
|
1253 |
codeAddress = inst->vTable[__intVal(vtOffset)]; |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1254 |
# ifdef VERBOSE |
19535 | 1255 |
if (@global(Verbose) == true) { |
19931 | 1256 |
printf("virtual %"_ld_" codeAddress: %"_lx_"\n", (INT)(__intVal(vtOffset)), (INT)codeAddress); |
19535 | 1257 |
} |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1258 |
# endif |
19535 | 1259 |
} |
9342 | 1260 |
} else { |
19535 | 1261 |
__numArgsIncludingThis = __numArgs; |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1262 |
# ifdef VERBOSE |
19535 | 1263 |
if (@global(Verbose) == true) { |
1264 |
printf("codeAddress: %"_lx_"\n", (INT)codeAddress); |
|
1265 |
} |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1266 |
# endif |
9342 | 1267 |
} |
1268 |
||
1269 |
/* |
|
19501 | 1270 |
* validate all arg types, map each to an ffi_type, and setup arg-buffers |
9342 | 1271 |
*/ |
1272 |
for (i=0; i<__numArgs; i++) { |
|
19535 | 1273 |
void *argValuePtr; |
1274 |
OBJ typeSymbol; |
|
1275 |
OBJ arg; |
|
9342 | 1276 |
|
19535 | 1277 |
failureInfo = __mkSmallInteger(i+1); /* in case there is one */ |
9465 | 1278 |
|
19535 | 1279 |
typeSymbol = __ArrayInstPtr(argTypeSymbols)->a_element[i]; |
1280 |
arg = __ArrayInstPtr(argumentsOrNil)->a_element[i]; |
|
9342 | 1281 |
|
19535 | 1282 |
if (typeSymbol == @symbol(handle)) { |
1283 |
typeSymbol = @symbol(pointer); |
|
1284 |
} else if (typeSymbol == @symbol(voidPointer)) { |
|
1285 |
typeSymbol = @symbol(pointer); |
|
1286 |
} else if (returnTypeSymbol == @symbol(hresult)) { |
|
1287 |
typeSymbol = @symbol(uint32); |
|
1288 |
} |
|
9479 | 1289 |
|
19535 | 1290 |
if (typeSymbol == @symbol(long)) { |
1291 |
if (sizeof(long) == sizeof(int)) { |
|
1292 |
typeSymbol = @symbol(sint); |
|
1293 |
} else { |
|
1294 |
if (sizeof(long) == 4) { |
|
1295 |
typeSymbol = @symbol(sint32); |
|
1296 |
} else if (sizeof(long) == 8) { |
|
1297 |
typeSymbol = @symbol(sint64); |
|
1298 |
} |
|
1299 |
} |
|
1300 |
} |
|
1301 |
if (typeSymbol == @symbol(ulong)) { |
|
1302 |
if (sizeof(unsigned long) == sizeof(unsigned int)) { |
|
1303 |
typeSymbol = @symbol(uint); |
|
1304 |
} else { |
|
1305 |
if (sizeof(long) == 4) { |
|
1306 |
typeSymbol = @symbol(uint32); |
|
1307 |
} else if (sizeof(long) == 8) { |
|
1308 |
typeSymbol = @symbol(uint64); |
|
1309 |
} |
|
1310 |
} |
|
1311 |
} |
|
9342 | 1312 |
|
19535 | 1313 |
if (typeSymbol == @symbol(int) || typeSymbol == @symbol(sint)) { |
19931 | 1314 |
thisType = TYPE_SINT; |
19535 | 1315 |
if (__isSmallInteger(arg)) { |
1316 |
__argValues[i].iVal = __intVal(arg); |
|
1317 |
} else { |
|
1318 |
__argValues[i].iVal = __signedLongIntVal(arg); |
|
1319 |
if (__argValues[i].iVal == 0) { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1320 |
# ifdef VERBOSE |
19535 | 1321 |
if (@global(Verbose) == true) { |
1322 |
printf("invalidArgument: arg%d sint value out of range [%d]\n", i+1, __LINE__); |
|
1323 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1324 |
# endif |
19535 | 1325 |
__FAIL__(@symbol(InvalidArgument)) |
1326 |
} |
|
1327 |
} |
|
1328 |
argValuePtr = &(__argValues[i].iVal); |
|
9479 | 1329 |
|
19535 | 1330 |
} else if (typeSymbol == @symbol(uint)) { |
19931 | 1331 |
thisType = TYPE_UINT; |
9342 | 1332 |
|
19535 | 1333 |
if (__isSmallInteger(arg)) { |
1334 |
__argValues[i].iVal = __intVal(arg); |
|
1335 |
} else { |
|
1336 |
__argValues[i].iVal = __unsignedLongIntVal(arg); |
|
1337 |
if (__argValues[i].iVal == 0) { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1338 |
# ifdef VERBOSE |
19535 | 1339 |
if (@global(Verbose) == true) { |
1340 |
printf("invalidArgument: arg%d uint value out of range [%d]\n", i+1, __LINE__); |
|
1341 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1342 |
# endif |
19535 | 1343 |
__FAIL__(@symbol(InvalidArgument)) |
1344 |
} |
|
1345 |
} |
|
1346 |
argValuePtr = &(__argValues[i].iVal); |
|
9479 | 1347 |
|
19535 | 1348 |
} else if (typeSymbol == @symbol(uint8)) { |
19931 | 1349 |
thisType = TYPE_UINT8; |
19535 | 1350 |
if (! __isSmallInteger(arg)) { |
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1351 |
# ifdef VERBOSE |
19535 | 1352 |
if (@global(Verbose) == true) { |
1353 |
printf("invalidArgument: arg%d uint8 value out of range [%d]\n", i+1, __LINE__); |
|
1354 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1355 |
# endif |
19535 | 1356 |
__FAIL__(@symbol(InvalidArgument)) |
1357 |
} |
|
1358 |
__argValues[i].iVal = __intVal(arg); |
|
1359 |
if (((unsigned)(__argValues[i].iVal)) > 0xFF) { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1360 |
# ifdef VERBOSE |
19535 | 1361 |
if (@global(Verbose) == true) { |
1362 |
printf("invalidArgument: arg%d uint8 value out of range [%d]\n", i+1, __LINE__); |
|
1363 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1364 |
# endif |
19535 | 1365 |
__FAIL__(@symbol(InvalidArgument)) |
1366 |
} |
|
1367 |
argValuePtr = &(__argValues[i].iVal); |
|
9479 | 1368 |
|
19535 | 1369 |
} else if (typeSymbol == @symbol(sint8)) { |
19931 | 1370 |
thisType = TYPE_SINT8; |
19535 | 1371 |
if (! __isSmallInteger(arg)) { |
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1372 |
# ifdef VERBOSE |
19535 | 1373 |
if (@global(Verbose) == true) { |
1374 |
printf("invalidArgument: arg%d sint8 value out of range [%d]\n", i+1, __LINE__); |
|
1375 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1376 |
# endif |
19535 | 1377 |
__FAIL__(@symbol(InvalidArgument)) |
1378 |
} |
|
1379 |
__argValues[i].iVal = __intVal(arg); |
|
1380 |
if (((__argValues[i].iVal) < -0x80) || ((__argValues[i].iVal) > 0x7F)) { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1381 |
# ifdef VERBOSE |
19535 | 1382 |
if (@global(Verbose) == true) { |
1383 |
printf("invalidArgument: arg%d sint8 value out of range [%d]\n", i+1, __LINE__); |
|
1384 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1385 |
# endif |
19535 | 1386 |
__FAIL__(@symbol(InvalidArgument)) |
1387 |
} |
|
1388 |
argValuePtr = &(__argValues[i].iVal); |
|
9479 | 1389 |
|
19535 | 1390 |
} else if (typeSymbol == @symbol(uint16)) { |
19931 | 1391 |
thisType = TYPE_UINT16; |
19535 | 1392 |
if (! __isSmallInteger(arg)) { |
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1393 |
# ifdef VERBOSE |
19535 | 1394 |
if (@global(Verbose) == true) { |
1395 |
printf("invalidArgument: arg%d uint16 value out of range [%d]\n", i+1, __LINE__); |
|
1396 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1397 |
# endif |
19535 | 1398 |
__FAIL__(@symbol(InvalidArgument)) |
1399 |
} |
|
1400 |
__argValues[i].iVal = __intVal(arg); |
|
1401 |
if (((unsigned)(__argValues[i].iVal)) > 0xFFFF) { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1402 |
# ifdef VERBOSE |
19535 | 1403 |
if (@global(Verbose) == true) { |
1404 |
printf("invalidArgument: arg%d uint16 value out of range [%d]\n", i+1, __LINE__); |
|
1405 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1406 |
# endif |
19535 | 1407 |
__FAIL__(@symbol(InvalidArgument)) |
1408 |
} |
|
1409 |
argValuePtr = &(__argValues[i].iVal); |
|
9479 | 1410 |
|
19535 | 1411 |
} else if (typeSymbol == @symbol(sint16)) { |
19931 | 1412 |
thisType = TYPE_SINT16; |
19535 | 1413 |
if (! __isSmallInteger(arg)) { |
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1414 |
# ifdef VERBOSE |
19535 | 1415 |
if (@global(Verbose) == true) { |
1416 |
printf("invalidArgument: arg%d sint16 value out of range [%d]\n", i+1, __LINE__); |
|
1417 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1418 |
# endif |
19535 | 1419 |
__FAIL__(@symbol(InvalidArgument)) |
1420 |
} |
|
1421 |
__argValues[i].iVal = __intVal(arg); |
|
1422 |
if (((__argValues[i].iVal) < -0x8000) || ((__argValues[i].iVal) > 0x7FFF)) { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1423 |
# ifdef VERBOSE |
19535 | 1424 |
if (@global(Verbose) == true) { |
1425 |
printf("invalidArgument: arg%d sint16 value out of range [%d]\n", i+1, __LINE__); |
|
1426 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1427 |
# endif |
19535 | 1428 |
__FAIL__(@symbol(InvalidArgument)) |
1429 |
} |
|
1430 |
argValuePtr = &(__argValues[i].iVal); |
|
9479 | 1431 |
|
19535 | 1432 |
} else if (typeSymbol == @symbol(uint32)) { |
19931 | 1433 |
thisType = TYPE_UINT32; |
19535 | 1434 |
if (__isSmallInteger(arg)) { |
1435 |
__argValues[i].iVal = __intVal(arg); |
|
1436 |
} else { |
|
1437 |
__argValues[i].iVal = __unsignedLongIntVal(arg); |
|
1438 |
if (__argValues[i].iVal == 0) { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1439 |
# ifdef VERBOSE |
19535 | 1440 |
if (@global(Verbose) == true) { |
1441 |
printf("invalidArgument: arg%d uint32 value out of range [%d]\n", i+1, __LINE__); |
|
1442 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1443 |
# endif |
19535 | 1444 |
__FAIL__(@symbol(InvalidArgument)) |
1445 |
} |
|
1446 |
} |
|
19334 | 1447 |
# if __POINTER_SIZE__ == 8 |
19535 | 1448 |
if ((__argValues[i].iVal) < 0) { |
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1449 |
# ifdef VERBOSE |
19535 | 1450 |
if (@global(Verbose) == true) { |
1451 |
printf("invalidArgument: arg%d uint32 value out of range [%d]\n", i+1, __LINE__); |
|
1452 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1453 |
# endif |
19535 | 1454 |
__FAIL__(@symbol(InvalidArgument)) |
1455 |
} |
|
19334 | 1456 |
# endif |
19535 | 1457 |
argValuePtr = &(__argValues[i].iVal); |
19334 | 1458 |
|
19535 | 1459 |
} else if (typeSymbol == @symbol(sint32)) { |
19931 | 1460 |
thisType = TYPE_SINT32; |
19535 | 1461 |
if (__isSmallInteger(arg)) { |
1462 |
__argValues[i].iVal = __intVal(arg); |
|
1463 |
} else { |
|
1464 |
__argValues[i].iVal = __signedLongIntVal(arg); |
|
1465 |
if (__argValues[i].iVal == 0) { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1466 |
# ifdef VERBOSE |
19535 | 1467 |
if (@global(Verbose) == true) { |
1468 |
printf("invalidArgument: arg%d sint32 value out of range [%d]\n", i+1, __LINE__); |
|
1469 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1470 |
# endif |
19535 | 1471 |
__FAIL__(@symbol(InvalidArgument)) |
1472 |
} |
|
1473 |
} |
|
19334 | 1474 |
# if __POINTER_SIZE__ == 8 |
19535 | 1475 |
if (((__argValues[i].iVal) < -0x80000000LL) || ((__argValues[i].iVal) > 0x7FFFFFFFLL)) { |
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1476 |
# ifdef VERBOSE |
19535 | 1477 |
if (@global(Verbose) == true) { |
1478 |
printf("invalidArgument: arg%d sint32 value (%"_lx_") out of range [%d]\n", i+1, __argValues[i].iVal, __LINE__); |
|
1479 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1480 |
# endif |
19535 | 1481 |
__FAIL__(@symbol(InvalidArgument)) |
1482 |
} |
|
19334 | 1483 |
# endif |
19535 | 1484 |
argValuePtr = &(__argValues[i].iVal); |
19334 | 1485 |
|
19535 | 1486 |
} else if (typeSymbol == @symbol(uint64)) { |
19931 | 1487 |
thisType = TYPE_UINT64; |
19535 | 1488 |
if (__isSmallInteger(arg)) { |
1489 |
__argValues[i].iVal = __intVal(arg); |
|
1490 |
} else { |
|
1491 |
__argValues[i].iVal = __unsignedLongIntVal(arg); |
|
1492 |
if (__argValues[i].iVal == 0) { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1493 |
# ifdef VERBOSE |
19535 | 1494 |
if (@global(Verbose) == true) { |
1495 |
printf("invalidArgument: arg%d uint64 value out of range [%d]\n", i+1, __LINE__); |
|
1496 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1497 |
# endif |
19535 | 1498 |
__FAIL__(@symbol(InvalidArgument)) |
1499 |
} |
|
1500 |
} |
|
1501 |
argValuePtr = &(__argValues[i].iVal); |
|
19334 | 1502 |
|
19535 | 1503 |
} else if (typeSymbol == @symbol(sint64)) { |
19931 | 1504 |
thisType = TYPE_SINT64; |
19535 | 1505 |
if (__isSmallInteger(arg)) { |
1506 |
__argValues[i].iVal = __intVal(arg); |
|
1507 |
} else { |
|
1508 |
__argValues[i].iVal = __signedLongIntVal(arg); |
|
1509 |
if (__argValues[i].iVal == 0) { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1510 |
# ifdef VERBOSE |
19535 | 1511 |
if (@global(Verbose) == true) { |
1512 |
printf("invalidArgument: arg%d sint64 value out of range [%d]\n", i+1, __LINE__); |
|
1513 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1514 |
# endif |
19535 | 1515 |
__FAIL__(@symbol(InvalidArgument)) |
1516 |
} |
|
1517 |
} |
|
1518 |
argValuePtr = &(__argValues[i].iVal); |
|
9479 | 1519 |
|
19535 | 1520 |
} else if (typeSymbol == @symbol(float)) { |
19931 | 1521 |
thisType = TYPE_FLOAT; |
19535 | 1522 |
if (__isSmallInteger(arg)) { |
1523 |
__argValues[i].fVal = (float)(__intVal(arg)); |
|
1524 |
} else if (__isFloat(arg)) { |
|
1525 |
__argValues[i].fVal = (float)(__floatVal(arg)); |
|
1526 |
} else if (__isShortFloat(arg)) { |
|
1527 |
__argValues[i].fVal = (float)(__shortFloatVal(arg)); |
|
1528 |
} else { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1529 |
# ifdef VERBOSE |
19535 | 1530 |
if (@global(Verbose) == true) { |
1531 |
printf("invalidArgument: arg%d non float value [%d]\n", i+1, __LINE__); |
|
1532 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1533 |
# endif |
19535 | 1534 |
__FAIL__(@symbol(InvalidArgument)) |
1535 |
} |
|
1536 |
argValuePtr = &(__argValues[i].fVal); |
|
1537 |
} else if (typeSymbol == @symbol(double)) { |
|
19931 | 1538 |
thisType = TYPE_DOUBLE; |
19535 | 1539 |
if (__isSmallInteger(arg)) { |
1540 |
__argValues[i].dVal = (double)(__intVal(arg)); |
|
1541 |
} else if (__isFloat(arg)) { |
|
1542 |
__argValues[i].dVal = (double)(__floatVal(arg)); |
|
1543 |
} else if (__isShortFloat(arg)) { |
|
1544 |
__argValues[i].dVal = (double)(__shortFloatVal(arg)); |
|
1545 |
} else { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1546 |
# ifdef VERBOSE |
19535 | 1547 |
if (@global(Verbose) == true) { |
1548 |
printf("invalidArgument: arg%d non double value [%d]\n", i+1, __LINE__); |
|
1549 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1550 |
# endif |
19535 | 1551 |
__FAIL__(@symbol(InvalidArgument)) |
1552 |
} |
|
1553 |
argValuePtr = &(__argValues[i].dVal); |
|
9479 | 1554 |
|
19535 | 1555 |
} else if (typeSymbol == @symbol(void)) { |
19931 | 1556 |
thisType = TYPE_VOID; |
19535 | 1557 |
argValuePtr = &null; |
9479 | 1558 |
|
19535 | 1559 |
} else if (typeSymbol == @symbol(charPointer)) { |
19931 | 1560 |
thisType = TYPE_POINTER; |
19535 | 1561 |
if (__isStringLike(arg)) { |
1562 |
if (async == true) goto badArgForAsyncCall; |
|
1563 |
__argValues[i].pointerVal = (void *)(__stringVal(arg)); |
|
1564 |
} else if (__isBytes(arg)) { |
|
1565 |
if (async == true) goto badArgForAsyncCall; |
|
1566 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
|
1567 |
} else if (__isExternalAddressLike(arg)) { |
|
1568 |
__argValues[i].pointerVal = (void *)(__externalAddressVal(arg)); |
|
1569 |
} else if (__isExternalBytesLike(arg)) { |
|
1570 |
__argValues[i].pointerVal = (void *)(__externalBytesVal(arg)); |
|
1571 |
} else { |
|
1572 |
if (arg == nil) { |
|
1573 |
__argValues[i].pointerVal = (void *)0; |
|
1574 |
} else { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1575 |
# ifdef VERBOSE |
19535 | 1576 |
if (@global(Verbose) == true) { |
1577 |
printf("invalidArgument: arg%d non charPointer value [%d]\n", i+1, __LINE__); |
|
1578 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1579 |
# endif |
19535 | 1580 |
__FAIL__(@symbol(InvalidArgument)) |
1581 |
} |
|
1582 |
} |
|
1583 |
argValuePtr = &(__argValues[i].pointerVal);; |
|
10603 | 1584 |
|
19535 | 1585 |
} else if (typeSymbol == @symbol(wcharPointer)) { |
19931 | 1586 |
thisType = TYPE_POINTER; |
19535 | 1587 |
if (__isUnicode16String(arg)) { |
1588 |
if (async == true) goto badArgForAsyncCall; |
|
1589 |
__argValues[i].pointerVal = (void *)(__unicode16StringVal(arg)); |
|
1590 |
} else if (__isBytes(arg)) { |
|
1591 |
if (async == true) goto badArgForAsyncCall; |
|
1592 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
|
1593 |
} else if (__isExternalAddressLike(arg)) { |
|
1594 |
__argValues[i].pointerVal = (void *)(__externalAddressVal(arg)); |
|
1595 |
} else if (__isExternalBytesLike(arg)) { |
|
1596 |
__argValues[i].pointerVal = (void *)(__externalBytesVal(arg)); |
|
1597 |
} else { |
|
1598 |
if (arg == nil) { |
|
1599 |
__argValues[i].pointerVal = (void *)0; |
|
1600 |
} else { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1601 |
# ifdef VERBOSE |
19535 | 1602 |
if (@global(Verbose) == true) { |
1603 |
printf("invalidArgument: arg%d non wcharPointer value [%d]\n", i+1, __LINE__); |
|
1604 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1605 |
# endif |
19535 | 1606 |
__FAIL__(@symbol(InvalidArgument)) |
1607 |
} |
|
1608 |
} |
|
1609 |
argValuePtr = &(__argValues[i].pointerVal);; |
|
12656 | 1610 |
|
19535 | 1611 |
} else if (typeSymbol == @symbol(floatPointer)) { |
19931 | 1612 |
thisType = TYPE_POINTER; |
19535 | 1613 |
if (__isBytes(arg)) { |
1614 |
if (async == true) goto badArgForAsyncCall; |
|
1615 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
|
1616 |
} else if (__isExternalAddressLike(arg)) { |
|
1617 |
__argValues[i].pointerVal = (void *)(__externalAddressVal(arg)); |
|
1618 |
} else if (__isExternalBytesLike(arg)) { |
|
1619 |
__argValues[i].pointerVal = (void *)(__externalBytesVal(arg)); |
|
1620 |
} else if (__isFloats(arg)) { |
|
1621 |
char *p = (char *)(__FloatArrayInstPtr(arg)->f_element); |
|
1622 |
int nInstBytes; |
|
1623 |
OBJ cls; |
|
10603 | 1624 |
|
19535 | 1625 |
if (async == true) goto badArgForAsyncCall; |
1626 |
cls = __qClass(arg); |
|
1627 |
nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1628 |
p = p + nInstBytes; |
|
1629 |
__argValues[i].pointerVal = p; |
|
1630 |
} else { |
|
1631 |
if (arg == nil) { |
|
1632 |
__argValues[i].pointerVal = (void *)0; |
|
1633 |
} else { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1634 |
# ifdef VERBOSE |
19535 | 1635 |
if (@global(Verbose) == true) { |
1636 |
printf("invalidArgument: arg%d non floatPointer value [%d]\n", i+1, __LINE__); |
|
1637 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1638 |
# endif |
19535 | 1639 |
__FAIL__(@symbol(InvalidArgument)) |
1640 |
} |
|
1641 |
} |
|
1642 |
argValuePtr = &(__argValues[i].pointerVal);; |
|
10603 | 1643 |
|
19535 | 1644 |
} else if (typeSymbol == @symbol(doublePointer)) { |
19931 | 1645 |
thisType = TYPE_POINTER; |
19535 | 1646 |
if (__isBytes(arg)) { |
1647 |
if (async == true) goto badArgForAsyncCall; |
|
1648 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
|
1649 |
} else if (__isExternalAddressLike(arg)) { |
|
1650 |
__argValues[i].pointerVal = (void *)(__externalAddressVal(arg)); |
|
1651 |
} else if (__isExternalBytesLike(arg)) { |
|
1652 |
__argValues[i].pointerVal = (void *)(__externalBytesVal(arg)); |
|
1653 |
} else if (__isDoubles(arg)) { |
|
1654 |
char *p = (char *)(__DoubleArrayInstPtr(arg)->d_element); |
|
1655 |
int nInstBytes; |
|
1656 |
OBJ cls; |
|
10603 | 1657 |
|
19535 | 1658 |
if (async == true) goto badArgForAsyncCall; |
1659 |
cls = __qClass(arg); |
|
1660 |
nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1661 |
p = p + nInstBytes; |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1662 |
# ifdef __NEED_DOUBLE_ALIGN |
19535 | 1663 |
if ((INT)(__DoubleArrayInstPtr(arg)->d_element) & (__DOUBLE_ALIGN-1)) { |
1664 |
int delta = __DOUBLE_ALIGN - ((INT)p & (__DOUBLE_ALIGN-1)); |
|
10603 | 1665 |
|
19535 | 1666 |
p += delta; |
1667 |
} |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1668 |
# endif |
19535 | 1669 |
__argValues[i].pointerVal = p; |
1670 |
} else { |
|
1671 |
if (arg == nil) { |
|
1672 |
__argValues[i].pointerVal = (void *)0; |
|
1673 |
} else { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1674 |
# ifdef VERBOSE |
19535 | 1675 |
if (@global(Verbose) == true) { |
1676 |
printf("invalidArgument: arg%d non doublePointer value [%d]\n", i+1, __LINE__); |
|
1677 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1678 |
# endif |
19535 | 1679 |
__FAIL__(@symbol(InvalidArgument)) |
1680 |
} |
|
1681 |
} |
|
1682 |
argValuePtr = &(__argValues[i].pointerVal);; |
|
9479 | 1683 |
|
19535 | 1684 |
} else if (typeSymbol == @symbol(pointer)) { |
9524 | 1685 |
commonPointerTypeArg: ; |
19931 | 1686 |
thisType = TYPE_POINTER; |
19535 | 1687 |
if (arg == nil) { |
1688 |
__argValues[i].pointerVal = NULL; |
|
1689 |
} else if (__isExternalAddressLike(arg)) { |
|
1690 |
__argValues[i].pointerVal = (void *)(__externalAddressVal(arg)); |
|
1691 |
} else if (__isExternalBytesLike(arg)) { |
|
1692 |
__argValues[i].pointerVal = (void *)(__externalBytesVal(arg)); |
|
1693 |
} else if (__isByteArrayLike(arg)) { |
|
1694 |
if (async == true) goto badArgForAsyncCall; |
|
1695 |
__argValues[i].pointerVal = (void *)(__byteArrayVal(arg)); |
|
1696 |
} else if (__isWordArray(arg) || __isSignedWordArray(arg) |
|
1697 |
|| __isIntegerArray(arg) || __isSignedIntegerArray(arg)) { |
|
1698 |
if (async == true) goto badArgForAsyncCall; |
|
1699 |
__argValues[i].pointerVal = (void *)(__integerArrayVal(arg)); |
|
1700 |
} else if (__isFloatArray(arg)) { |
|
1701 |
if (async == true) goto badArgForAsyncCall; |
|
1702 |
__argValues[i].pointerVal = (void *)(__FloatArrayInstPtr(arg)->f_element); |
|
1703 |
} else if (__isDoubleArray(arg)) { |
|
1704 |
if (async == true) goto badArgForAsyncCall; |
|
1705 |
__argValues[i].pointerVal = (void *)(__DoubleArrayInstPtr(arg)->d_element); |
|
1706 |
} else if (__isStringLike(arg)) { |
|
1707 |
if (async == true) { |
|
9435 | 1708 |
badArgForAsyncCall: ; |
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1709 |
# ifdef VERBOSE |
19535 | 1710 |
if (@global(Verbose) == true) { |
1711 |
printf("invalidArgument: arg%d not allowed for async call [%d]\n", i+1, __LINE__); |
|
1712 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1713 |
# endif |
19535 | 1714 |
__FAIL__(@symbol(BadArgForAsyncCall)) |
1715 |
} |
|
1716 |
__argValues[i].pointerVal = (void *)(__stringVal(arg)); |
|
1717 |
} else if (__isBytes(arg) || __isWords(arg) || __isLongs(arg)) { |
|
1718 |
char *p = (char *)(__byteArrayVal(arg)); |
|
1719 |
int nInstBytes; |
|
1720 |
OBJ cls; |
|
9483 | 1721 |
|
19535 | 1722 |
if (async == true) goto badArgForAsyncCall; |
1723 |
cls = __qClass(arg); |
|
1724 |
nInstBytes = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
|
1725 |
__argValues[i].pointerVal = p + nInstBytes; |
|
1726 |
} else { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1727 |
# ifdef VERBOSE |
19535 | 1728 |
if (@global(Verbose) == true) { |
1729 |
printf("invalidArgument: arg%d non pointer value [%d]\n", i+1, __LINE__); |
|
1730 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1731 |
# endif |
19535 | 1732 |
__FAIL__(@symbol(InvalidArgument)) |
1733 |
} |
|
1734 |
argValuePtr = &(__argValues[i].pointerVal);; |
|
9479 | 1735 |
|
19535 | 1736 |
} else if (typeSymbol == @symbol(bool)) { |
19931 | 1737 |
thisType = TYPE_UINT; |
9342 | 1738 |
|
19535 | 1739 |
if (arg == true) { |
1740 |
__argValues[i].iVal = 1; |
|
1741 |
} else if (arg == false) { |
|
1742 |
__argValues[i].iVal = 0; |
|
1743 |
} else if (__isSmallInteger(arg)) { |
|
1744 |
__argValues[i].iVal = __intVal(arg); |
|
1745 |
} else { |
|
1746 |
__argValues[i].iVal = __unsignedLongIntVal(arg); |
|
1747 |
if (__argValues[i].iVal == 0) { |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1748 |
# ifdef VERBOSE |
19535 | 1749 |
if (@global(Verbose) == true) { |
1750 |
printf("invalidArgument: arg%d non bool value [%d]\n", i+1, __LINE__); |
|
1751 |
} |
|
19341
2ab29dd7ec1a
mingw 64bit fixes (xxLL in constants - sigh)
Claus Gittinger <cg@exept.de>
parents:
19334
diff
changeset
|
1752 |
# endif |
19535 | 1753 |
__FAIL__(@symbol(InvalidArgument)) |
1754 |
} |
|
1755 |
} |
|
1756 |
argValuePtr = &(__argValues[i].iVal); |
|
1757 |
} else { |
|
1758 |
if (__isSymbol(typeSymbol) |
|
1759 |
&& ((argValueClass = __GLOBAL_GET(typeSymbol)) != nil)) { |
|
1760 |
if (! __isBehaviorLike(argValueClass)) { |
|
1761 |
__FAIL__(@symbol(NonBehaviorArgumentType)) |
|
1762 |
} |
|
1763 |
if (! __qIsSubclassOfExternalAddress(argValueClass)) { |
|
1764 |
__FAIL__(@symbol(NonExternalAddressArgumentType)) |
|
1765 |
} |
|
1766 |
goto commonPointerTypeArg; /* sorry */ |
|
1767 |
} else { |
|
1768 |
__FAIL__(@symbol(UnknownArgumentType)) |
|
1769 |
} |
|
1770 |
} |
|
9342 | 1771 |
|
19535 | 1772 |
__argTypes[i] = thisType; |
1773 |
__argValuePointers[i] = argValuePtr; |
|
9483 | 1774 |
|
19932 | 1775 |
if ((thisType == TYPE_FLOAT) || (thisType == TYPE_DOUBLE)) { |
1776 |
__anyFloatOrDoubleArg = 1; |
|
1777 |
} |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1778 |
# ifdef VERBOSE |
19535 | 1779 |
if (@global(Verbose) == true) { |
1780 |
printf("arg%d: %"_lx_" type:%"_lx_"\n", i+1, (INT)(__argValues[i].iVal), (INT)thisType); |
|
1781 |
} |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
1782 |
# endif |
9342 | 1783 |
} |
9465 | 1784 |
failureInfo = nil; |
9342 | 1785 |
|
9465 | 1786 |
if (callTypeNumber == @global(CALLTYPE_API)) { |
19931 | 1787 |
# ifdef CALLTYPE_FFI_STDCALL |
19535 | 1788 |
__callType = CALLTYPE_FFI_STDCALL; |
19931 | 1789 |
# ifdef VERBOSE |
19535 | 1790 |
if (@global(Verbose) == true) { |
1791 |
printf("STDCALL\n"); |
|
1792 |
} |
|
19931 | 1793 |
# endif |
1794 |
# else |
|
1795 |
failureCode = @symbol(FFICallTypeNotSupported); |
|
1796 |
goto getOutOfHere; |
|
1797 |
# endif |
|
9342 | 1798 |
} |
19931 | 1799 |
|
1800 |
// these calltypes are only supported on some systems; others report an error |
|
9465 | 1801 |
if (callTypeNumber == @global(CALLTYPE_V8)) { |
19931 | 1802 |
# ifdef CALLTYPE_FFI_V8 |
19535 | 1803 |
__callType = CALLTYPE_FFI_V8; |
19931 | 1804 |
# else |
1805 |
failureCode = @symbol(FFICallTypeNotSupported); |
|
1806 |
goto getOutOfHere; |
|
1807 |
# endif |
|
9342 | 1808 |
} |
19931 | 1809 |
|
9465 | 1810 |
if (callTypeNumber == @global(CALLTYPE_V9)) { |
19931 | 1811 |
# ifdef CALLTYPE_FFI_V9 |
19535 | 1812 |
__callType = CALLTYPE_FFI_V9; |
19931 | 1813 |
# else |
1814 |
failureCode = @symbol(FFICallTypeNotSupported); |
|
1815 |
goto getOutOfHere; |
|
1816 |
# endif |
|
9342 | 1817 |
} |
19931 | 1818 |
|
9465 | 1819 |
if (callTypeNumber == @global(CALLTYPE_UNIX64)) { |
19931 | 1820 |
# ifdef CALLTYPE_FFI_UNIX64 |
19535 | 1821 |
__callType = CALLTYPE_FFI_UNIX64; |
19931 | 1822 |
# else |
1823 |
failureCode = @symbol(FFICallTypeNotSupported); |
|
1824 |
goto getOutOfHere; |
|
1825 |
# endif |
|
9342 | 1826 |
} |
1827 |
||
19931 | 1828 |
# ifdef HAVE_FFI |
9342 | 1829 |
if (ffi_prep_cif(&__cif, __callType, __numArgsIncludingThis, __returnType, __argTypesIncludingThis) != FFI_OK) { |
19535 | 1830 |
__FAIL__(@symbol(FFIPrepareFailed)) |
9342 | 1831 |
} |
9463 | 1832 |
if (async == true) { |
19931 | 1833 |
# ifdef VERBOSE |
19535 | 1834 |
if (@global(Verbose) == true) { |
1835 |
printf("async call 0x%"_lx_"\n", (INT)codeAddress); |
|
1836 |
} |
|
19931 | 1837 |
# endif |
1838 |
# ifdef __win32__ |
|
19535 | 1839 |
__STX_C_CALL4( "ffi_call", ffi_call, &__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis); |
19931 | 1840 |
# else |
19535 | 1841 |
__BEGIN_INTERRUPTABLE__ |
1842 |
ffi_call(&__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis); |
|
1843 |
__END_INTERRUPTABLE__ |
|
19931 | 1844 |
# endif |
9435 | 1845 |
} else { |
19535 | 1846 |
if (unlimitedStack == true) { |
19931 | 1847 |
# ifdef VERBOSE |
19535 | 1848 |
if (@global(Verbose) == true) { |
1849 |
printf("UNLIMITEDSTACKCALL call 0x%"_lx_"\n", (INT)codeAddress); |
|
1850 |
} |
|
19931 | 1851 |
# endif |
19535 | 1852 |
__UNLIMITEDSTACKCALL4__((OBJFUNC)ffi_call, (INT)(&__cif), (INT)codeAddress, (INT)__returnValuePointer, (INT)__argValuePointersIncludingThis); |
1853 |
} else { |
|
19931 | 1854 |
# ifdef VERBOSE |
19535 | 1855 |
if (@global(Verbose) == true) { |
1856 |
printf("call 0x%"_lx_"\n", (INT)codeAddress); |
|
1857 |
} |
|
19931 | 1858 |
# endif |
19535 | 1859 |
ffi_call(&__cif, codeAddress, __returnValuePointer, __argValuePointersIncludingThis); |
1860 |
} |
|
9435 | 1861 |
} |
19931 | 1862 |
|
1863 |
# else /* NO FFI */ |
|
1864 |
||
1865 |
// this is a fallback; simply assume that pointer and regular args |
|
1866 |
// can be passed in the same registers, and that all args are casted to the same |
|
1867 |
// (pointer-) size. |
|
1868 |
// Also, that float/doubles are passed down in regular registers, |
|
1869 |
// and the return types float and double are handled diferently from ints. |
|
1870 |
// If that is not correct for your CPU/architecture, an ifndef is required here. |
|
1871 |
||
19932 | 1872 |
# if defined(__x86_64__) |
1873 |
if (__anyFloatOrDoubleArg) { |
|
1874 |
# ifdef VERBOSE |
|
1875 |
if (@global(Verbose) == true) { |
|
1876 |
printf("float/double args currently not supported\n"); |
|
1877 |
} |
|
1878 |
# endif |
|
1879 |
failureCode = @symbol(FFIDoubleArgNotSupported); |
|
1880 |
goto getOutOfHere; |
|
1881 |
} |
|
1882 |
# endif |
|
1883 |
||
19931 | 1884 |
# if !defined(SomeArchitechtureForWhichAboveIsNotTrue) |
1885 |
{ |
|
1886 |
VOIDPTRFUNC fi = (VOIDPTRFUNC)codeAddress; |
|
1887 |
DOUBLEFUNC fd = (DOUBLEFUNC)codeAddress; |
|
1888 |
||
1889 |
switch (__returnType) { |
|
1890 |
case TYPE_FLOAT: |
|
1891 |
case TYPE_DOUBLE: |
|
1892 |
switch (__numArgsIncludingThis) { |
|
1893 |
case 0: |
|
1894 |
__returnValue.dVal = (*fd)(); |
|
1895 |
break; |
|
1896 |
case 1: |
|
1897 |
__returnValue.dVal = (*fd)( __argValues[0].pointerVal ); |
|
1898 |
break; |
|
1899 |
case 2: |
|
1900 |
__returnValue.dVal = (*fd)( __argValues[0].pointerVal, __argValues[1].pointerVal ); |
|
1901 |
break; |
|
1902 |
case 3: |
|
1903 |
__returnValue.dVal = (*fd)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal ); |
|
1904 |
break; |
|
1905 |
case 4: |
|
1906 |
__returnValue.dVal = (*fd)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
1907 |
__argValues[3].pointerVal ); |
|
1908 |
break; |
|
1909 |
case 5: |
|
1910 |
__returnValue.dVal = (*fd)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
1911 |
__argValues[3].pointerVal, __argValues[4].pointerVal ); |
|
1912 |
break; |
|
1913 |
case 6: |
|
1914 |
__returnValue.dVal = (*fd)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
1915 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal ); |
|
1916 |
break; |
|
1917 |
case 7: |
|
1918 |
__returnValue.dVal = (*fd)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
1919 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
1920 |
__argValues[6].pointerVal ); |
|
1921 |
break; |
|
1922 |
case 8: |
|
1923 |
__returnValue.dVal = (*fd)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
1924 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
1925 |
__argValues[6].pointerVal, __argValues[7].pointerVal ); |
|
1926 |
break; |
|
1927 |
case 9: |
|
1928 |
__returnValue.dVal = (*fd)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
1929 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
1930 |
__argValues[6].pointerVal, __argValues[7].pointerVal, __argValues[8].pointerVal ); |
|
1931 |
break; |
|
1932 |
case 10: |
|
1933 |
__returnValue.dVal = (*fd)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
1934 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
1935 |
__argValues[6].pointerVal, __argValues[7].pointerVal, __argValues[8].pointerVal, |
|
1936 |
__argValues[9].pointerVal ); |
|
1937 |
break; |
|
1938 |
case 11: |
|
1939 |
__returnValue.dVal = (*fd)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
1940 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
1941 |
__argValues[6].pointerVal, __argValues[7].pointerVal, __argValues[8].pointerVal, |
|
1942 |
__argValues[9].pointerVal, __argValues[10].pointerVal ); |
|
1943 |
break; |
|
1944 |
case 12: |
|
1945 |
__returnValue.dVal = (*fd)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
1946 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
1947 |
__argValues[6].pointerVal, __argValues[7].pointerVal, __argValues[8].pointerVal, |
|
1948 |
__argValues[9].pointerVal, __argValues[10].pointerVal, __argValues[11].pointerVal ); |
|
1949 |
break; |
|
1950 |
case 13: |
|
1951 |
__returnValue.dVal = (*fd)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
1952 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
1953 |
__argValues[6].pointerVal, __argValues[7].pointerVal, __argValues[8].pointerVal, |
|
1954 |
__argValues[9].pointerVal, __argValues[10].pointerVal, __argValues[11].pointerVal, |
|
1955 |
__argValues[12].pointerVal ); |
|
1956 |
break; |
|
1957 |
case 14: |
|
1958 |
__returnValue.dVal = (*fd)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
1959 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
1960 |
__argValues[6].pointerVal, __argValues[7].pointerVal, __argValues[8].pointerVal, |
|
1961 |
__argValues[9].pointerVal, __argValues[10].pointerVal, __argValues[11].pointerVal, |
|
1962 |
__argValues[12].pointerVal, __argValues[13].pointerVal ); |
|
1963 |
break; |
|
1964 |
case 15: |
|
1965 |
__returnValue.dVal = (*fd)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
1966 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
1967 |
__argValues[6].pointerVal, __argValues[7].pointerVal, __argValues[8].pointerVal, |
|
1968 |
__argValues[9].pointerVal, __argValues[10].pointerVal, __argValues[11].pointerVal, |
|
1969 |
__argValues[12].pointerVal, __argValues[13].pointerVal, __argValues[14].pointerVal ); |
|
1970 |
break; |
|
1971 |
default: |
|
19932 | 1972 |
failureCode = @symbol(TooManyArguments); |
19931 | 1973 |
goto getOutOfHere; |
1974 |
} |
|
1975 |
break; |
|
1976 |
||
1977 |
default: |
|
1978 |
switch (__numArgsIncludingThis) { |
|
1979 |
case 0: |
|
1980 |
__returnValue.pointerVal = (*fi)(); |
|
1981 |
break; |
|
1982 |
case 1: |
|
1983 |
__returnValue.pointerVal = (*fi)( __argValues[0].pointerVal ); |
|
1984 |
break; |
|
1985 |
case 2: |
|
1986 |
__returnValue.pointerVal = (*fi)( __argValues[0].pointerVal, __argValues[1].pointerVal ); |
|
1987 |
break; |
|
1988 |
case 3: |
|
1989 |
__returnValue.pointerVal = (*fi)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal ); |
|
1990 |
break; |
|
1991 |
case 4: |
|
1992 |
__returnValue.pointerVal = (*fi)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
1993 |
__argValues[3].pointerVal ); |
|
1994 |
break; |
|
1995 |
case 5: |
|
1996 |
__returnValue.pointerVal = (*fi)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
1997 |
__argValues[3].pointerVal, __argValues[4].pointerVal ); |
|
1998 |
break; |
|
1999 |
case 6: |
|
2000 |
__returnValue.pointerVal = (*fi)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
2001 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal ); |
|
2002 |
break; |
|
2003 |
case 7: |
|
2004 |
__returnValue.pointerVal = (*fi)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
2005 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
2006 |
__argValues[6].pointerVal ); |
|
2007 |
break; |
|
2008 |
case 8: |
|
2009 |
__returnValue.pointerVal = (*fi)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
2010 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
2011 |
__argValues[6].pointerVal, __argValues[7].pointerVal ); |
|
2012 |
break; |
|
2013 |
case 9: |
|
2014 |
__returnValue.pointerVal = (*fi)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
2015 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
2016 |
__argValues[6].pointerVal, __argValues[7].pointerVal, __argValues[8].pointerVal ); |
|
2017 |
break; |
|
2018 |
case 10: |
|
2019 |
__returnValue.pointerVal = (*fi)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
2020 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
2021 |
__argValues[6].pointerVal, __argValues[7].pointerVal, __argValues[8].pointerVal, |
|
2022 |
__argValues[9].pointerVal ); |
|
2023 |
break; |
|
2024 |
case 11: |
|
2025 |
__returnValue.pointerVal = (*fi)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
2026 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
2027 |
__argValues[6].pointerVal, __argValues[7].pointerVal, __argValues[8].pointerVal, |
|
2028 |
__argValues[9].pointerVal, __argValues[10].pointerVal ); |
|
2029 |
break; |
|
2030 |
case 12: |
|
2031 |
__returnValue.pointerVal = (*fi)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
2032 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
2033 |
__argValues[6].pointerVal, __argValues[7].pointerVal, __argValues[8].pointerVal, |
|
2034 |
__argValues[9].pointerVal, __argValues[10].pointerVal, __argValues[11].pointerVal ); |
|
2035 |
break; |
|
2036 |
case 13: |
|
2037 |
__returnValue.pointerVal = (*fi)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
2038 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
2039 |
__argValues[6].pointerVal, __argValues[7].pointerVal, __argValues[8].pointerVal, |
|
2040 |
__argValues[9].pointerVal, __argValues[10].pointerVal, __argValues[11].pointerVal, |
|
2041 |
__argValues[12].pointerVal ); |
|
2042 |
break; |
|
2043 |
case 14: |
|
2044 |
__returnValue.pointerVal = (*fi)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
2045 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
2046 |
__argValues[6].pointerVal, __argValues[7].pointerVal, __argValues[8].pointerVal, |
|
2047 |
__argValues[9].pointerVal, __argValues[10].pointerVal, __argValues[11].pointerVal, |
|
2048 |
__argValues[12].pointerVal, __argValues[13].pointerVal ); |
|
2049 |
break; |
|
2050 |
case 15: |
|
2051 |
__returnValue.pointerVal = (*fi)( __argValues[0].pointerVal, __argValues[1].pointerVal, __argValues[2].pointerVal, |
|
2052 |
__argValues[3].pointerVal, __argValues[4].pointerVal, __argValues[5].pointerVal, |
|
2053 |
__argValues[6].pointerVal, __argValues[7].pointerVal, __argValues[8].pointerVal, |
|
2054 |
__argValues[9].pointerVal, __argValues[10].pointerVal, __argValues[11].pointerVal, |
|
2055 |
__argValues[12].pointerVal, __argValues[13].pointerVal, __argValues[14].pointerVal ); |
|
2056 |
break; |
|
2057 |
default: |
|
19932 | 2058 |
failureCode = @symbol(TooManyArguments); |
19931 | 2059 |
goto getOutOfHere; |
2060 |
} |
|
2061 |
} |
|
2062 |
} |
|
2063 |
# else |
|
2064 |
failureCode = @symbol(FFINotSupported); |
|
2065 |
goto getOutOfHere; |
|
2066 |
# endif |
|
2067 |
# endif |
|
2068 |
||
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
2069 |
# ifdef VERBOSE |
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2070 |
if (@global(Verbose) == true) { |
19535 | 2071 |
printf("retval is %"_ld_" (0x%"_lx_")\n", (INT)(__returnValue.iVal), (INT)(__returnValue.iVal)); |
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2072 |
} |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
2073 |
# endif |
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2074 |
|
11586 | 2075 |
if ((returnTypeSymbol == @symbol(int)) |
2076 |
|| (returnTypeSymbol == @symbol(sint)) |
|
9479 | 2077 |
|| (returnTypeSymbol == @symbol(sint8)) |
2078 |
|| (returnTypeSymbol == @symbol(sint16)) |
|
2079 |
|| (returnTypeSymbol == @symbol(sint32))) { |
|
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2080 |
# ifdef VERBOSE |
19535 | 2081 |
if (@global(Verbose) == true) { |
19931 | 2082 |
printf("return int: %"_lx_"\n", (INT)(__returnValue.iVal)); |
19535 | 2083 |
} |
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2084 |
# endif |
19535 | 2085 |
RETURN ( __MKINT(__returnValue.iVal) ); |
9342 | 2086 |
} |
2087 |
if ((returnTypeSymbol == @symbol(uint)) |
|
2088 |
|| (returnTypeSymbol == @symbol(uint8)) |
|
2089 |
|| (returnTypeSymbol == @symbol(uint16)) |
|
2090 |
|| (returnTypeSymbol == @symbol(uint32))) { |
|
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2091 |
# ifdef VERBOSE |
19535 | 2092 |
if (@global(Verbose) == true) { |
19931 | 2093 |
printf("return uint: %"_lx_"\n", (INT)(__returnValue.iVal)); |
19535 | 2094 |
} |
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2095 |
# endif |
19535 | 2096 |
RETURN ( __MKUINT(__returnValue.iVal) ); |
9342 | 2097 |
} |
10025
053904a63549
stc-compiled ExternalLibraryFunctions
Claus Gittinger <cg@exept.de>
parents:
9981
diff
changeset
|
2098 |
if (returnTypeSymbol == @symbol(bool)) { |
19535 | 2099 |
RETURN ( __returnValue.iVal ? true : false ); |
9342 | 2100 |
} |
2101 |
if (returnTypeSymbol == @symbol(float)) { |
|
19535 | 2102 |
RETURN ( __MKFLOAT(__returnValue.fVal )); |
9342 | 2103 |
} |
2104 |
if (returnTypeSymbol == @symbol(double)) { |
|
19535 | 2105 |
RETURN ( __MKFLOAT(__returnValue.dVal )); |
9342 | 2106 |
} |
2107 |
if (returnTypeSymbol == @symbol(void)) { |
|
19535 | 2108 |
RETURN ( nil ); |
9342 | 2109 |
} |
9463 | 2110 |
if (returnTypeSymbol == @symbol(char)) { |
19535 | 2111 |
RETURN ( __MKCHARACTER(__returnValue.iVal & 0xFF) ); |
9463 | 2112 |
} |
2113 |
if (returnTypeSymbol == @symbol(wchar)) { |
|
19535 | 2114 |
RETURN ( __MKUCHARACTER(__returnValue.iVal & 0xFFFF) ); |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
2115 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
2116 |
if (returnTypeSymbol == @symbol(sint64)) { |
19356 | 2117 |
# if (__POINTER_SIZE__ == 8) |
19355 | 2118 |
|
2119 |
# ifdef VERBOSE |
|
19535 | 2120 |
if (@global(Verbose) == true) { |
2121 |
printf("return sint64: %"_lx_"\n", (INT)(__returnValue.longLongVal)); |
|
2122 |
} |
|
19355 | 2123 |
# endif |
19535 | 2124 |
RETURN ( __MKINT(__returnValue.longLongVal) ); |
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2125 |
# else |
19355 | 2126 |
# ifdef VERBOSE |
19535 | 2127 |
if (@global(Verbose) == true) { |
2128 |
printf("return sint64: %lx%08lx\n", __HI32(__returnValue.longLongVal), __LO32(__returnValue.longLongVal)); |
|
2129 |
} |
|
19355 | 2130 |
# endif |
19535 | 2131 |
RETURN ( __MKINT64(&__returnValue.longLongVal) ); |
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2132 |
# endif |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
2133 |
} |
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
2134 |
if (returnTypeSymbol == @symbol(uint64)) { |
19356 | 2135 |
# if (__POINTER_SIZE__ == 8) |
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2136 |
# ifdef VERBOSE |
19535 | 2137 |
if (@global(Verbose) == true) { |
2138 |
printf("return uint64: %"_lx_"\n", (unsigned INT)(__returnValue.longLongVal)); |
|
2139 |
} |
|
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2140 |
# endif |
19535 | 2141 |
RETURN ( __MKUINT(__returnValue.longLongVal) ); |
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2142 |
# else |
19355 | 2143 |
# ifdef VERBOSE |
19535 | 2144 |
if (@global(Verbose) == true) { |
2145 |
printf("return sint64: %lx%08lx\n", __HI32(__returnValue.longLongVal), __LO32(__returnValue.longLongVal)); |
|
2146 |
} |
|
19355 | 2147 |
# endif |
19535 | 2148 |
RETURN ( __MKUINT64(&__returnValue.longLongVal) ); |
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2149 |
# endif |
9463 | 2150 |
} |
11586 | 2151 |
|
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
2152 |
# ifdef VERBOSE |
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2153 |
if (@global(Verbose) == true) { |
19535 | 2154 |
printf("return pointer: %"_lx_"\n", (INT)(__returnValue.pointerVal)); |
19314
698cf296ef6d
mingw64 and debugging stuff
Claus Gittinger <cg@exept.de>
parents:
19313
diff
changeset
|
2155 |
} |
12504
c9987bb76eb6
untested long long return value
Claus Gittinger <cg@exept.de>
parents:
12503
diff
changeset
|
2156 |
# endif |
9346 | 2157 |
if (returnTypeSymbol == @symbol(handle)) { |
19535 | 2158 |
returnValue = __MKEXTERNALADDRESS(__returnValue.pointerVal); |
9346 | 2159 |
} else if (returnTypeSymbol == @symbol(pointer)) { |
19535 | 2160 |
returnValue = __MKEXTERNALBYTES(__returnValue.pointerVal); |
10603 | 2161 |
} else if (returnTypeSymbol == @symbol(bytePointer)) { |
19535 | 2162 |
returnValue = __MKEXTERNALBYTES(__returnValue.pointerVal); |
9463 | 2163 |
} else if (returnTypeSymbol == @symbol(charPointer)) { |
19535 | 2164 |
returnValue = __MKSTRING(__returnValue.pointerVal); |
9463 | 2165 |
} else if (returnTypeSymbol == @symbol(wcharPointer)) { |
19535 | 2166 |
returnValue = __MKU16STRING(__returnValue.pointerVal); |
9342 | 2167 |
} else { |
19535 | 2168 |
__FAIL__(@symbol(UnknownReturnType2)) |
9342 | 2169 |
} |
19931 | 2170 |
//#else /* no FFI support */ |
2171 |
// failureCode = @symbol(FFINotSupported); |
|
2172 |
//#endif /* HAVE_FFI */ |
|
2173 |
||
9342 | 2174 |
getOutOfHere: ; |
2175 |
%}. |
|
2176 |
failureCode notNil ifTrue:[ |
|
19535 | 2177 |
(failureCode == #UnknownReturnType or:[ failureCode == #UnknownArgumentType ]) ifTrue:[ |
2178 |
oldReturnType := returnType. |
|
2179 |
oldArgumentTypes := argumentTypes. |
|
2180 |
self adjustTypes. |
|
2181 |
((oldReturnType ~= returnType) or:[oldArgumentTypes ~= argumentTypes]) ifTrue:[ |
|
2182 |
thisContext restart |
|
2183 |
]. |
|
2184 |
]. |
|
2185 |
(failureCode == #BadArgForAsyncCall) ifTrue:[ |
|
2186 |
^ self tryAgainWithAsyncSafeArguments:argumentsOrNil forCPPInstance:aReceiverOrNil |
|
2187 |
]. |
|
2188 |
(failureCode == #FFINotSupported) ifTrue:[ |
|
2189 |
self primitiveFailed:'FFI support missing in this build'. |
|
2190 |
]. |
|
12579
516bba5b3e57
changed: #ffiTypeSymbolForType:
Claus Gittinger <cg@exept.de>
parents:
12504
diff
changeset
|
2191 |
|
19535 | 2192 |
self primitiveFailed. "see failureCode and failureInfo for details" |
2193 |
^ nil |
|
9342 | 2194 |
]. |
2195 |
||
9483 | 2196 |
returnType isSymbol ifTrue:[ |
19535 | 2197 |
returnValueClass notNil ifTrue:[ |
2198 |
self isConstReturnValue ifTrue:[ |
|
2199 |
returnValue changeClassTo:returnValueClass. |
|
2200 |
^ returnValue |
|
2201 |
]. |
|
2202 |
^ returnValueClass fromExternalAddress:returnValue. |
|
2203 |
]. |
|
9483 | 2204 |
] ifFalse:[ |
19535 | 2205 |
returnType isCPointer ifTrue:[ |
2206 |
returnType baseType isCStruct ifTrue:[ |
|
2207 |
stClass := Smalltalk classNamed:returnType baseType name. |
|
2208 |
stClass notNil ifTrue:[ |
|
2209 |
self isConstReturnValue ifTrue:[ |
|
2210 |
returnValue changeClassTo:returnValueClass. |
|
2211 |
^ returnValue |
|
2212 |
]. |
|
2213 |
^ stClass fromExternalAddress:returnValue. |
|
2214 |
]. |
|
2215 |
]. |
|
2216 |
returnType baseType isCChar ifTrue:[ |
|
2217 |
^ returnValue stringAt:1 |
|
2218 |
]. |
|
2219 |
]. |
|
9342 | 2220 |
]. |
2221 |
||
2222 |
^ returnValue |
|
9463 | 2223 |
|
2224 |
"Created: / 01-08-2006 / 13:56:23 / cg" |
|
19514 | 2225 |
"Modified: / 31-03-2016 / 00:03:03 / cg" |
14037 | 2226 |
! |
2227 |
||
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
2228 |
tryAgainWithAsyncSafeArguments:argumentsOrNil forCPPInstance:aReceiverOrNil |
14037 | 2229 |
"invoked by the call primitive, iff GC-unsave arguments where passed to the call. |
2230 |
Here, allocate non-movable blocks of memory and copy the arguments into them, |
|
2231 |
then try the call again, copy changed values back, and release the memeory." |
|
2232 |
||
2233 |
|saveArguments anyBadArg result originalToSaveArgMapping| |
|
2234 |
||
2235 |
argumentsOrNil isNil ifTrue:[ |
|
14625 | 2236 |
^ self primitiveFailed |
14037 | 2237 |
]. |
14506
e53548cdc24d
changed: #tryAgainWithAsyncSafeArguments:forCPPInstance:
anwild
parents:
14412
diff
changeset
|
2238 |
thisContext isRecursive ifTrue: [^self primitiveFailed]. |
14037 | 2239 |
|
2240 |
anyBadArg := false. |
|
2241 |
originalToSaveArgMapping := IdentityDictionary new. |
|
2242 |
||
14625 | 2243 |
saveArguments := argumentsOrNil |
2244 |
collect:[:eachArg | |
|
2245 |
|saveArg| |
|
14037 | 2246 |
|
14625 | 2247 |
(originalToSaveArgMapping includesKey:eachArg) ifTrue:[ |
2248 |
saveArg := originalToSaveArgMapping at:eachArg |
|
2249 |
] ifFalse:[ |
|
2250 |
eachArg isString ifTrue:[ |
|
2251 |
saveArg := (ExternalBytes fromString:eachArg) register. |
|
2252 |
anyBadArg := true. |
|
2253 |
originalToSaveArgMapping at:eachArg put:saveArg. |
|
2254 |
] ifFalse:[ |
|
2255 |
eachArg isByteCollection ifTrue:[ |
|
2256 |
saveArg := (ExternalBytes from:eachArg) register. |
|
2257 |
originalToSaveArgMapping at:eachArg put:saveArg. |
|
2258 |
anyBadArg := true. |
|
2259 |
] ifFalse:[ |
|
2260 |
saveArg := eachArg |
|
2261 |
] |
|
2262 |
]. |
|
2263 |
]. |
|
2264 |
saveArg |
|
2265 |
]. |
|
14037 | 2266 |
|
2267 |
anyBadArg ifFalse:[ |
|
14625 | 2268 |
"avoid recursion..." |
2269 |
^ self primitiveFailed |
|
14037 | 2270 |
]. |
2271 |
||
14659
410089913ca1
allow use of the standard (system) ffi
Claus Gittinger <cg@exept.de>
parents:
14632
diff
changeset
|
2272 |
result := self invokeFFIwithArguments:saveArguments forCPPInstance:aReceiverOrNil. |
14037 | 2273 |
|
2274 |
"/ copy back !! |
|
2275 |
originalToSaveArgMapping keysAndValuesDo:[:arg :saveArg | |
|
14625 | 2276 |
arg isSymbol ifFalse:[ |
2277 |
arg replaceFrom:1 to:(arg size) with:saveArg startingAt:1. |
|
2278 |
]. |
|
2279 |
saveArg free. |
|
14037 | 2280 |
]. |
2281 |
^ result. |
|
14506
e53548cdc24d
changed: #tryAgainWithAsyncSafeArguments:forCPPInstance:
anwild
parents:
14412
diff
changeset
|
2282 |
|
e53548cdc24d
changed: #tryAgainWithAsyncSafeArguments:forCPPInstance:
anwild
parents:
14412
diff
changeset
|
2283 |
"Modified (format): / 06-11-2012 / 10:52:41 / anwild" |
9342 | 2284 |
! ! |
2285 |
||
10481 | 2286 |
!ExternalLibraryFunction methodsFor:'testing'! |
2287 |
||
10603 | 2288 |
isExternalLibraryFunction |
2289 |
"return true, if the receiver is some kind of externalLibrary function; |
|
2290 |
true is returned here" |
|
2291 |
||
2292 |
^true |
|
2293 |
||
2294 |
"Created: / 07-06-2007 / 10:36:40 / cg" |
|
10481 | 2295 |
! ! |
2296 |
||
8533 | 2297 |
!ExternalLibraryFunction class methodsFor:'documentation'! |
2298 |
||
19487 | 2299 |
version |
2300 |
^ '$Header$' |
|
2301 |
! |
|
2302 |
||
13412 | 2303 |
version_CVS |
19311 | 2304 |
^ '$Header$' |
12436 | 2305 |
! |
2306 |
||
13412 | 2307 |
version_SVN |
19311 | 2308 |
^ '$ Id: ExternalLibraryFunction.st 10643 2011-06-08 21:53:07Z vranyj1 $' |
8533 | 2309 |
! ! |
9463 | 2310 |
|
19311 | 2311 |
|
9463 | 2312 |
ExternalLibraryFunction initialize! |