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