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