Spaces:
Running
Running
| /* We try to define Py_LIMITED_API before including Python.h. | |
| Mess: we can only define it if Py_DEBUG, Py_TRACE_REFS and | |
| Py_REF_DEBUG are not defined. This is a best-effort approximation: | |
| we can learn about Py_DEBUG from pyconfig.h, but it is unclear if | |
| the same works for the other two macros. Py_DEBUG implies them, | |
| but not the other way around. | |
| The implementation is messy (issue #350): on Windows, with _MSC_VER, | |
| we have to define Py_LIMITED_API even before including pyconfig.h. | |
| In that case, we guess what pyconfig.h will do to the macros above, | |
| and check our guess after the #include. | |
| Note that on Windows, with CPython 3.x, you need >= 3.5 and virtualenv | |
| version >= 16.0.0. With older versions of either, you don't get a | |
| copy of PYTHON3.DLL in the virtualenv. We can't check the version of | |
| CPython *before* we even include pyconfig.h. ffi.set_source() puts | |
| a ``#define _CFFI_NO_LIMITED_API'' at the start of this file if it is | |
| running on Windows < 3.5, as an attempt at fixing it, but that's | |
| arguably wrong because it may not be the target version of Python. | |
| Still better than nothing I guess. As another workaround, you can | |
| remove the definition of Py_LIMITED_API here. | |
| See also 'py_limited_api' in cffi/setuptools_ext.py. | |
| */ | |
| /* sanity-check: Py_LIMITED_API will cause crashes if any of these | |
| are also defined. Normally, the Python file PC/pyconfig.h does not | |
| cause any of these to be defined, with the exception that _DEBUG | |
| causes Py_DEBUG. Double-check that. */ | |
| extern "C" { | |
| /* this block of #ifs should be kept exactly identical between | |
| c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py | |
| and cffi/_cffi_include.h */ | |
| typedef __int8 int8_t; | |
| typedef __int16 int16_t; | |
| typedef __int32 int32_t; | |
| typedef __int64 int64_t; | |
| typedef unsigned __int8 uint8_t; | |
| typedef unsigned __int16 uint16_t; | |
| typedef unsigned __int32 uint32_t; | |
| typedef unsigned __int64 uint64_t; | |
| typedef __int8 int_least8_t; | |
| typedef __int16 int_least16_t; | |
| typedef __int32 int_least32_t; | |
| typedef __int64 int_least64_t; | |
| typedef unsigned __int8 uint_least8_t; | |
| typedef unsigned __int16 uint_least16_t; | |
| typedef unsigned __int32 uint_least32_t; | |
| typedef unsigned __int64 uint_least64_t; | |
| typedef __int8 int_fast8_t; | |
| typedef __int16 int_fast16_t; | |
| typedef __int32 int_fast32_t; | |
| typedef __int64 int_fast64_t; | |
| typedef unsigned __int8 uint_fast8_t; | |
| typedef unsigned __int16 uint_fast16_t; | |
| typedef unsigned __int32 uint_fast32_t; | |
| typedef unsigned __int64 uint_fast64_t; | |
| typedef __int64 intmax_t; | |
| typedef unsigned __int64 uintmax_t; | |
| typedef unsigned char _Bool; | |
| typedef bool _Bool; /* semi-hackish: C++ has no _Bool; bool is builtin */ | |
| /********** CPython-specific section **********/ | |
| struct _cffi_ctypedescr; | |
| static void *_cffi_exports[_CFFI_NUM_EXPORTS]; | |
| static PyObject *_cffi_init(const char *module_name, Py_ssize_t version, | |
| const struct _cffi_type_context_s *ctx) | |
| { | |
| PyObject *module, *o_arg, *new_module; | |
| void *raw[] = { | |
| (void *)module_name, | |
| (void *)version, | |
| (void *)_cffi_exports, | |
| (void *)ctx, | |
| }; | |
| module = PyImport_ImportModule("_cffi_backend"); | |
| if (module == NULL) | |
| goto failure; | |
| o_arg = PyLong_FromVoidPtr((void *)raw); | |
| if (o_arg == NULL) | |
| goto failure; | |
| new_module = PyObject_CallMethod( | |
| module, (char *)"_init_cffi_1_0_external_module", (char *)"O", o_arg); | |
| Py_DECREF(o_arg); | |
| Py_DECREF(module); | |
| return new_module; | |
| failure: | |
| Py_XDECREF(module); | |
| return NULL; | |
| } | |
| typedef wchar_t _cffi_wchar_t; | |
| typedef uint16_t _cffi_wchar_t; /* same random pick as _cffi_backend.c */ | |
| _CFFI_UNUSED_FN static uint16_t _cffi_to_c_char16_t(PyObject *o) | |
| { | |
| if (sizeof(_cffi_wchar_t) == 2) | |
| return (uint16_t)_cffi_to_c_wchar_t(o); | |
| else | |
| return (uint16_t)_cffi_to_c_wchar3216_t(o); | |
| } | |
| _CFFI_UNUSED_FN static PyObject *_cffi_from_c_char16_t(uint16_t x) | |
| { | |
| if (sizeof(_cffi_wchar_t) == 2) | |
| return _cffi_from_c_wchar_t((_cffi_wchar_t)x); | |
| else | |
| return _cffi_from_c_wchar3216_t((int)x); | |
| } | |
| _CFFI_UNUSED_FN static int _cffi_to_c_char32_t(PyObject *o) | |
| { | |
| if (sizeof(_cffi_wchar_t) == 4) | |
| return (int)_cffi_to_c_wchar_t(o); | |
| else | |
| return (int)_cffi_to_c_wchar3216_t(o); | |
| } | |
| _CFFI_UNUSED_FN static PyObject *_cffi_from_c_char32_t(unsigned int x) | |
| { | |
| if (sizeof(_cffi_wchar_t) == 4) | |
| return _cffi_from_c_wchar_t((_cffi_wchar_t)x); | |
| else | |
| return _cffi_from_c_wchar3216_t((int)x); | |
| } | |
| union _cffi_union_alignment_u { | |
| unsigned char m_char; | |
| unsigned short m_short; | |
| unsigned int m_int; | |
| unsigned long m_long; | |
| unsigned long long m_longlong; | |
| float m_float; | |
| double m_double; | |
| long double m_longdouble; | |
| }; | |
| struct _cffi_freeme_s { | |
| struct _cffi_freeme_s *next; | |
| union _cffi_union_alignment_u alignment; | |
| }; | |
| _CFFI_UNUSED_FN static int | |
| _cffi_convert_array_argument(struct _cffi_ctypedescr *ctptr, PyObject *arg, | |
| char **output_data, Py_ssize_t datasize, | |
| struct _cffi_freeme_s **freeme) | |
| { | |
| char *p; | |
| if (datasize < 0) | |
| return -1; | |
| p = *output_data; | |
| if (p == NULL) { | |
| struct _cffi_freeme_s *fp = (struct _cffi_freeme_s *)PyObject_Malloc( | |
| offsetof(struct _cffi_freeme_s, alignment) + (size_t)datasize); | |
| if (fp == NULL) | |
| return -1; | |
| fp->next = *freeme; | |
| *freeme = fp; | |
| p = *output_data = (char *)&fp->alignment; | |
| } | |
| memset((void *)p, 0, (size_t)datasize); | |
| return _cffi_convert_array_from_object(p, ctptr, arg); | |
| } | |
| _CFFI_UNUSED_FN static void | |
| _cffi_free_array_arguments(struct _cffi_freeme_s *freeme) | |
| { | |
| do { | |
| void *p = (void *)freeme; | |
| freeme = freeme->next; | |
| PyObject_Free(p); | |
| } while (freeme != NULL); | |
| } | |
| /********** end CPython-specific section **********/ | |
| _CFFI_UNUSED_FN | |
| static void (*_cffi_call_python_org)(struct _cffi_externpy_s *, char *); | |
| } | |