@@ -179,7 +179,7 @@ declare_type(PyFloat_Type, float, PyFloatObject);
179179declare_type (PySlice_Type , slice , PySliceObject );
180180declare_type (PyByteArray_Type , bytearray , PyByteArrayObject );
181181declare_type (PyCFunction_Type , builtin_function_or_method , PyCFunctionObject );
182- declare_type (PyWrapperDescr_Type , method_descriptor , PyWrapperDescrObject ); // LS: previously wrapper_descriptor
182+ declare_type (PyWrapperDescr_Type , wrapper_descriptor , PyWrapperDescrObject );
183183// tfel: Both method_descriptor maps to both PyWrapperDescr_Type and
184184// PyMethodDescr_Type. This reflects our interpreter, but we need to make sure
185185// that the dynamic type for method_descriptor is always going to be
@@ -210,10 +210,79 @@ initialize_type(PyEllipsis_Type, ellipsis, _object);
210210initialize_type (_PyWeakref_ProxyType , ProxyType , PyWeakReference );
211211initialize_type (_PyWeakref_CallableProxyType , CallableProxyType , PyWeakReference );
212212
213- POLYGLOT_DECLARE_TYPE (PyThreadState );
214213POLYGLOT_DECLARE_TYPE (newfunc );
215214POLYGLOT_DECLARE_TYPE (Py_buffer );
216215
216+ /* primitive and pointer type declarations */
217+
218+ #define REGISTER_BASIC_TYPE (typename ) \
219+ POLYGLOT_DECLARE_TYPE(typename); \
220+ NO_INLINE polyglot_typeid get_ ## typename ## _typeid(void) { \
221+ return polyglot_ ## typename ## _typeid(); \
222+ }
223+
224+ /* just a renaming to avoid name clash with Java types */
225+ typedef void * void_ptr_t ;
226+ typedef char char_t ;
227+ typedef float float_t ;
228+ typedef double double_t ;
229+ typedef int int_t ;
230+ typedef unsigned int uint_t ;
231+ typedef long long_t ;
232+ typedef unsigned long ulong_t ;
233+ typedef long long longlong_t ;
234+ typedef unsigned long long ulonglong_t ;
235+
236+ REGISTER_BASIC_TYPE (void_ptr_t );
237+ REGISTER_BASIC_TYPE (int_t );
238+ REGISTER_BASIC_TYPE (uint_t );
239+ REGISTER_BASIC_TYPE (long_t );
240+ REGISTER_BASIC_TYPE (ulong_t );
241+ REGISTER_BASIC_TYPE (longlong_t );
242+ REGISTER_BASIC_TYPE (ulonglong_t );
243+ REGISTER_BASIC_TYPE (int64_t );
244+ REGISTER_BASIC_TYPE (int32_t );
245+ REGISTER_BASIC_TYPE (int16_t );
246+ REGISTER_BASIC_TYPE (int8_t );
247+ REGISTER_BASIC_TYPE (uint64_t );
248+ REGISTER_BASIC_TYPE (uint32_t );
249+ REGISTER_BASIC_TYPE (uint16_t );
250+ REGISTER_BASIC_TYPE (uint8_t );
251+ REGISTER_BASIC_TYPE (Py_complex );
252+ REGISTER_BASIC_TYPE (char_t );
253+ REGISTER_BASIC_TYPE (PyObject );
254+ REGISTER_BASIC_TYPE (PyTypeObject );
255+ REGISTER_BASIC_TYPE (float_t );
256+ REGISTER_BASIC_TYPE (double_t );
257+ REGISTER_BASIC_TYPE (Py_ssize_t );
258+ REGISTER_BASIC_TYPE (size_t );
259+ REGISTER_BASIC_TYPE (PyThreadState );
260+
261+ /* For pointers, make them look like an array of size 1 such that it is
262+ possible to dereference the pointer by accessing element 0. */
263+ #define REGISTER_POINTER_TYPE (basetype , ptrtype ) \
264+ typedef basetype* ptrtype; \
265+ POLYGLOT_DECLARE_TYPE(ptrtype); \
266+ NO_INLINE polyglot_typeid get_ ## ptrtype ## _typeid(void) { \
267+ return polyglot_array_typeid(polyglot_ ## basetype ## _typeid(), 1); \
268+ }
269+
270+ REGISTER_POINTER_TYPE (int64_t , int64_ptr_t );
271+ REGISTER_POINTER_TYPE (int32_t , int32_ptr_t );
272+ REGISTER_POINTER_TYPE (int16_t , int16_ptr_t );
273+ REGISTER_POINTER_TYPE (int8_t , int8_ptr_t );
274+ REGISTER_POINTER_TYPE (char_t , char_ptr_t );
275+ REGISTER_POINTER_TYPE (uint64_t , uint64_ptr_t );
276+ REGISTER_POINTER_TYPE (uint32_t , uint32_ptr_t );
277+ REGISTER_POINTER_TYPE (uint16_t , uint16_ptr_t );
278+ REGISTER_POINTER_TYPE (uint8_t , uint8_ptr_t );
279+ REGISTER_POINTER_TYPE (Py_complex , Py_complex_ptr_t );
280+ REGISTER_POINTER_TYPE (PyObject , PyObject_ptr_t );
281+ REGISTER_POINTER_TYPE (PyObject_ptr_t , PyObject_ptr_ptr_t );
282+ REGISTER_POINTER_TYPE (float_t , float_ptr_t );
283+ REGISTER_POINTER_TYPE (double_t , double_ptr_t );
284+ REGISTER_POINTER_TYPE (Py_ssize_t , Py_ssize_ptr_t );
285+
217286
218287static void initialize_globals () {
219288 // register native NULL
@@ -413,7 +482,6 @@ polyglot_typeid get_byte_array_typeid(uint64_t len) {
413482 return polyglot_array_typeid (polyglot_i8_typeid (), len );
414483}
415484
416- POLYGLOT_DECLARE_TYPE (uint32_t );
417485/** to be used from Java code only; returns the type ID for a uint32_t array */
418486polyglot_typeid get_uint32_t_array_typeid (uint64_t len ) {
419487 return polyglot_array_typeid (polyglot_uint32_t_typeid (), len );
0 commit comments