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