1 /******************************** -*- C -*- **************************** 2 * 3 * External definitions for C - Smalltalk interface module 4 * 5 * 6 ***********************************************************************/ 7 8 /*********************************************************************** 9 * 10 * Copyright 1988,89,90,91,92,94,95,99,2000,2001,2002,2006,2008,2009 11 * Free Software Foundation, Inc. 12 * Written by Steve Byrne. 13 * 14 * This file is part of GNU Smalltalk. 15 * 16 * GNU Smalltalk is free software; you can redistribute it and/or modify it 17 * under the terms of the GNU General Public License as published by the Free 18 * Software Foundation; either version 2, or (at your option) any later 19 * version. 20 * 21 * Linking GNU Smalltalk statically or dynamically with other modules is 22 * making a combined work based on GNU Smalltalk. Thus, the terms and 23 * conditions of the GNU General Public License cover the whole 24 * combination. 25 * 26 * In addition, as a special exception, the Free Software Foundation 27 * give you permission to combine GNU Smalltalk with free software 28 * programs or libraries that are released under the GNU LGPL and with 29 * independent programs running under the GNU Smalltalk virtual machine. 30 * 31 * You may copy and distribute such a system following the terms of the 32 * GNU GPL for GNU Smalltalk and the licenses of the other code 33 * concerned, provided that you include the source code of that other 34 * code when and as the GNU GPL requires distribution of source code. 35 * 36 * Note that people who make modified versions of GNU Smalltalk are not 37 * obligated to grant this special exception for their modified 38 * versions; it is their choice whether to do so. The GNU General 39 * Public License gives permission to release a modified version without 40 * this exception; this exception also makes it possible to release a 41 * modified version which carries forward this exception. 42 * 43 * GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT 44 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 45 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 46 * more details. 47 * 48 * You should have received a copy of the GNU General Public License along with 49 * GNU Smalltalk; see the file COPYING. If not, write to the Free Software 50 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 51 * 52 ***********************************************************************/ 53 54 55 56 #ifndef GST_CINT_H 57 #define GST_CINT_H 58 59 typedef enum 60 { /* types for C parameters */ 61 CDATA_CHAR, 62 CDATA_UCHAR, 63 CDATA_SHORT, 64 CDATA_USHORT, 65 CDATA_LONG, 66 CDATA_ULONG, 67 CDATA_FLOAT, 68 CDATA_DOUBLE, 69 CDATA_STRING, 70 CDATA_OOP, /* no conversion to-from C (OOP) */ 71 CDATA_INT, 72 CDATA_UINT, 73 CDATA_LONG_DOUBLE, 74 75 CDATA_UNKNOWN, /* when there is no type a priori */ 76 CDATA_STRING_OUT, /* for things that modify string params */ 77 CDATA_SYMBOL, 78 CDATA_BYTEARRAY, 79 CDATA_BYTEARRAY_OUT, 80 CDATA_BOOLEAN, 81 CDATA_VOID, /* valid only as a return type */ 82 CDATA_VARIADIC, /* for parameters, this param is an 83 array to be interpreted as 84 arguments. Note that only simple 85 conversions are performed in this 86 case. */ 87 CDATA_VARIADIC_OOP, /* for parameters, this param is an 88 array whose elements are OOPs to be 89 passed. */ 90 CDATA_COBJECT, /* a C object is being passed */ 91 CDATA_COBJECT_PTR, /* a C object pointer is being passed */ 92 CDATA_SELF, /* pass self as the corresponding 93 argument */ 94 CDATA_SELF_OOP, /* pass self as an OOP */ 95 CDATA_WCHAR, 96 CDATA_WSTRING, 97 CDATA_WSTRING_OUT, 98 CDATA_SYMBOL_OUT, 99 CDATA_LONGLONG, 100 CDATA_ULONGLONG 101 } 102 cdata_type; 103 104 /* Value of errno which is checked by the Smalltalk base classes. */ 105 extern int _gst_errno 106 ATTRIBUTE_HIDDEN; 107 108 typedef struct gst_c_callable 109 { 110 OBJ_HEADER; 111 OOP typeOOP; /* CObject fields */ 112 OOP storageOOP; /* CObject fields */ 113 OOP returnTypeOOP; /* Smalltalk return type */ 114 OOP argTypesOOP; /* array of argument types */ 115 OOP blockOOP; /* only for CCallbackDescriptor */ 116 } 117 *gst_c_callable; 118 119 /* Returns the size of an object passed to a C routine with type TYPE. */ 120 extern int _gst_c_type_size (int type); 121 122 /* Called after GC to invalidate the cache for the libffi representation 123 of CFunctionDescriptors. */ 124 extern void _gst_invalidate_croutine_cache (void); 125 126 /* Invokes a C routine. Arguments passed from Smalltalk are stored starting 127 from ARGS, and the object to which the message that called-out was 128 sent is RECEIVER. CFUNCOOP is the C function descriptor used 129 to control the mapping of argument types from Smalltalk to C types 130 and determines the mapping of the C function's return type into a 131 Smalltalk type. The result is NULL if the call was not successful, 132 an OOP holding the result otherwise. */ 133 extern OOP _gst_invoke_croutine (OOP cFuncOOP, 134 OOP receiver, 135 OOP *args) 136 ATTRIBUTE_HIDDEN; 137 138 /* Defines the mapping between a string function name FUNCNAME and the 139 address FUNCADDR of that function, for later use in 140 lookup_function. The mapping table will expand as needed to 141 hold new entries as they are added. */ 142 extern void _gst_define_cfunc (const char *funcName, PTR funcAddr) 143 ATTRIBUTE_HIDDEN; 144 145 /* Adds to the mapping table the standard C functions supported by 146 GNU Smalltalk. */ 147 extern void _gst_init_cfuncs (void) 148 ATTRIBUTE_HIDDEN; 149 150 /* Set the value of errno which is checked by Smalltalk to be errnum. */ 151 extern void _gst_set_errno(int errnum) 152 ATTRIBUTE_HIDDEN; 153 154 /* Returns the address for the latest C function which has been 155 registered using _gst_define_cfunc with the name FUNCNAME. Returns 156 NULL if there is no such function. */ 157 extern PTR _gst_lookup_function (const char *funcName) 158 ATTRIBUTE_HIDDEN; 159 160 /* Creates a closure for the CCallbackDescriptor CALLBACKOOP and stores it 161 in the object. */ 162 extern void _gst_make_closure (OOP callbackOOP) 163 ATTRIBUTE_HIDDEN; 164 165 /* Frees the info for the closure in the CCallbackDescriptor CALLBACKOOP. */ 166 extern void _gst_free_closure (OOP callbackOOP) 167 ATTRIBUTE_HIDDEN; 168 169 /* Call lt_dlopenext with FILENAME, and invoke gst_initModule if it is 170 found in the library. If MODULE is false, add the file to the list 171 of libraries that Smalltalk searches for external symbols. */ 172 extern mst_Boolean _gst_dlopen (const char *filename, mst_Boolean module); 173 174 /* Add DIR at the beginning of the libltdl search path. */ 175 extern void _gst_dladdsearchdir (const char *dir) 176 ATTRIBUTE_HIDDEN; 177 178 /* Push the current libltdl search path. */ 179 extern void _gst_dlpushsearchpath (void) 180 ATTRIBUTE_HIDDEN; 181 182 /* Pop the saved search path into the current libltdl search path. */ 183 extern void _gst_dlpopsearchpath (void) 184 ATTRIBUTE_HIDDEN; 185 186 #endif /* GST_CINT_H */ 187