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