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