|
| 1 | + |
| 2 | +#include <Python.h> |
| 3 | +#include <stddef.h> |
| 4 | + |
| 5 | +/* this block of #ifs should be kept exactly identical between |
| 6 | + c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py |
| 7 | + and cffi/_cffi_include.h */ |
| 8 | +#if defined(_MSC_VER) |
| 9 | +# include <malloc.h> /* for alloca() */ |
| 10 | +# if _MSC_VER < 1600 /* MSVC < 2010 */ |
| 11 | + typedef __int8 int8_t; |
| 12 | + typedef __int16 int16_t; |
| 13 | + typedef __int32 int32_t; |
| 14 | + typedef __int64 int64_t; |
| 15 | + typedef unsigned __int8 uint8_t; |
| 16 | + typedef unsigned __int16 uint16_t; |
| 17 | + typedef unsigned __int32 uint32_t; |
| 18 | + typedef unsigned __int64 uint64_t; |
| 19 | + typedef __int8 int_least8_t; |
| 20 | + typedef __int16 int_least16_t; |
| 21 | + typedef __int32 int_least32_t; |
| 22 | + typedef __int64 int_least64_t; |
| 23 | + typedef unsigned __int8 uint_least8_t; |
| 24 | + typedef unsigned __int16 uint_least16_t; |
| 25 | + typedef unsigned __int32 uint_least32_t; |
| 26 | + typedef unsigned __int64 uint_least64_t; |
| 27 | + typedef __int8 int_fast8_t; |
| 28 | + typedef __int16 int_fast16_t; |
| 29 | + typedef __int32 int_fast32_t; |
| 30 | + typedef __int64 int_fast64_t; |
| 31 | + typedef unsigned __int8 uint_fast8_t; |
| 32 | + typedef unsigned __int16 uint_fast16_t; |
| 33 | + typedef unsigned __int32 uint_fast32_t; |
| 34 | + typedef unsigned __int64 uint_fast64_t; |
| 35 | + typedef __int64 intmax_t; |
| 36 | + typedef unsigned __int64 uintmax_t; |
| 37 | +# else |
| 38 | +# include <stdint.h> |
| 39 | +# endif |
| 40 | +# if _MSC_VER < 1800 /* MSVC < 2013 */ |
| 41 | +# ifndef __cplusplus |
| 42 | + typedef unsigned char _Bool; |
| 43 | +# endif |
| 44 | +# endif |
| 45 | +# define _cffi_float_complex_t _Fcomplex /* include <complex.h> for it */ |
| 46 | +# define _cffi_double_complex_t _Dcomplex /* include <complex.h> for it */ |
| 47 | +#else |
| 48 | +# include <stdint.h> |
| 49 | +# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux) |
| 50 | +# include <alloca.h> |
| 51 | +# endif |
| 52 | +# define _cffi_float_complex_t float _Complex |
| 53 | +# define _cffi_double_complex_t double _Complex |
| 54 | +#endif |
| 55 | + |
| 56 | +#if PY_MAJOR_VERSION < 3 |
| 57 | +# undef PyCapsule_CheckExact |
| 58 | +# undef PyCapsule_GetPointer |
| 59 | +# define PyCapsule_CheckExact(capsule) (PyCObject_Check(capsule)) |
| 60 | +# define PyCapsule_GetPointer(capsule, name) \ |
| 61 | + (PyCObject_AsVoidPtr(capsule)) |
| 62 | +#endif |
| 63 | + |
| 64 | +#if PY_MAJOR_VERSION >= 3 |
| 65 | +# define PyInt_FromLong PyLong_FromLong |
| 66 | +#endif |
| 67 | + |
| 68 | +#define _cffi_from_c_double PyFloat_FromDouble |
| 69 | +#define _cffi_from_c_float PyFloat_FromDouble |
| 70 | +#define _cffi_from_c_long PyInt_FromLong |
| 71 | +#define _cffi_from_c_ulong PyLong_FromUnsignedLong |
| 72 | +#define _cffi_from_c_longlong PyLong_FromLongLong |
| 73 | +#define _cffi_from_c_ulonglong PyLong_FromUnsignedLongLong |
| 74 | +#define _cffi_from_c__Bool PyBool_FromLong |
| 75 | + |
| 76 | +#define _cffi_to_c_double PyFloat_AsDouble |
| 77 | +#define _cffi_to_c_float PyFloat_AsDouble |
| 78 | + |
| 79 | +#define _cffi_from_c_int_const(x) \ |
| 80 | + (((x) > 0) ? \ |
| 81 | + ((unsigned long long)(x) <= (unsigned long long)LONG_MAX) ? \ |
| 82 | + PyInt_FromLong((long)(x)) : \ |
| 83 | + PyLong_FromUnsignedLongLong((unsigned long long)(x)) : \ |
| 84 | + ((long long)(x) >= (long long)LONG_MIN) ? \ |
| 85 | + PyInt_FromLong((long)(x)) : \ |
| 86 | + PyLong_FromLongLong((long long)(x))) |
| 87 | + |
| 88 | +#define _cffi_from_c_int(x, type) \ |
| 89 | + (((type)-1) > 0 ? /* unsigned */ \ |
| 90 | + (sizeof(type) < sizeof(long) ? \ |
| 91 | + PyInt_FromLong((long)x) : \ |
| 92 | + sizeof(type) == sizeof(long) ? \ |
| 93 | + PyLong_FromUnsignedLong((unsigned long)x) : \ |
| 94 | + PyLong_FromUnsignedLongLong((unsigned long long)x)) : \ |
| 95 | + (sizeof(type) <= sizeof(long) ? \ |
| 96 | + PyInt_FromLong((long)x) : \ |
| 97 | + PyLong_FromLongLong((long long)x))) |
| 98 | + |
| 99 | +#define _cffi_to_c_int(o, type) \ |
| 100 | + ((type)( \ |
| 101 | + sizeof(type) == 1 ? (((type)-1) > 0 ? (type)_cffi_to_c_u8(o) \ |
| 102 | + : (type)_cffi_to_c_i8(o)) : \ |
| 103 | + sizeof(type) == 2 ? (((type)-1) > 0 ? (type)_cffi_to_c_u16(o) \ |
| 104 | + : (type)_cffi_to_c_i16(o)) : \ |
| 105 | + sizeof(type) == 4 ? (((type)-1) > 0 ? (type)_cffi_to_c_u32(o) \ |
| 106 | + : (type)_cffi_to_c_i32(o)) : \ |
| 107 | + sizeof(type) == 8 ? (((type)-1) > 0 ? (type)_cffi_to_c_u64(o) \ |
| 108 | + : (type)_cffi_to_c_i64(o)) : \ |
| 109 | + (Py_FatalError("unsupported size for type " #type), (type)0))) |
| 110 | + |
| 111 | +#define _cffi_to_c_i8 \ |
| 112 | + ((int(*)(PyObject *))_cffi_exports[1]) |
| 113 | +#define _cffi_to_c_u8 \ |
| 114 | + ((int(*)(PyObject *))_cffi_exports[2]) |
| 115 | +#define _cffi_to_c_i16 \ |
| 116 | + ((int(*)(PyObject *))_cffi_exports[3]) |
| 117 | +#define _cffi_to_c_u16 \ |
| 118 | + ((int(*)(PyObject *))_cffi_exports[4]) |
| 119 | +#define _cffi_to_c_i32 \ |
| 120 | + ((int(*)(PyObject *))_cffi_exports[5]) |
| 121 | +#define _cffi_to_c_u32 \ |
| 122 | + ((unsigned int(*)(PyObject *))_cffi_exports[6]) |
| 123 | +#define _cffi_to_c_i64 \ |
| 124 | + ((long long(*)(PyObject *))_cffi_exports[7]) |
| 125 | +#define _cffi_to_c_u64 \ |
| 126 | + ((unsigned long long(*)(PyObject *))_cffi_exports[8]) |
| 127 | +#define _cffi_to_c_char \ |
| 128 | + ((int(*)(PyObject *))_cffi_exports[9]) |
| 129 | +#define _cffi_from_c_pointer \ |
| 130 | + ((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[10]) |
| 131 | +#define _cffi_to_c_pointer \ |
| 132 | + ((char *(*)(PyObject *, CTypeDescrObject *))_cffi_exports[11]) |
| 133 | +#define _cffi_get_struct_layout \ |
| 134 | + ((PyObject *(*)(Py_ssize_t[]))_cffi_exports[12]) |
| 135 | +#define _cffi_restore_errno \ |
| 136 | + ((void(*)(void))_cffi_exports[13]) |
| 137 | +#define _cffi_save_errno \ |
| 138 | + ((void(*)(void))_cffi_exports[14]) |
| 139 | +#define _cffi_from_c_char \ |
| 140 | + ((PyObject *(*)(char))_cffi_exports[15]) |
| 141 | +#define _cffi_from_c_deref \ |
| 142 | + ((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[16]) |
| 143 | +#define _cffi_to_c \ |
| 144 | + ((int(*)(char *, CTypeDescrObject *, PyObject *))_cffi_exports[17]) |
| 145 | +#define _cffi_from_c_struct \ |
| 146 | + ((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[18]) |
| 147 | +#define _cffi_to_c_wchar_t \ |
| 148 | + ((wchar_t(*)(PyObject *))_cffi_exports[19]) |
| 149 | +#define _cffi_from_c_wchar_t \ |
| 150 | + ((PyObject *(*)(wchar_t))_cffi_exports[20]) |
| 151 | +#define _cffi_to_c_long_double \ |
| 152 | + ((long double(*)(PyObject *))_cffi_exports[21]) |
| 153 | +#define _cffi_to_c__Bool \ |
| 154 | + ((_Bool(*)(PyObject *))_cffi_exports[22]) |
| 155 | +#define _cffi_prepare_pointer_call_argument \ |
| 156 | + ((Py_ssize_t(*)(CTypeDescrObject *, PyObject *, char **))_cffi_exports[23]) |
| 157 | +#define _cffi_convert_array_from_object \ |
| 158 | + ((int(*)(char *, CTypeDescrObject *, PyObject *))_cffi_exports[24]) |
| 159 | +#define _CFFI_NUM_EXPORTS 25 |
| 160 | + |
| 161 | +typedef struct _ctypedescr CTypeDescrObject; |
| 162 | + |
| 163 | +static void *_cffi_exports[_CFFI_NUM_EXPORTS]; |
| 164 | +static PyObject *_cffi_types, *_cffi_VerificationError; |
| 165 | + |
| 166 | +static int _cffi_setup_custom(PyObject *lib); /* forward */ |
| 167 | + |
| 168 | +static PyObject *_cffi_setup(PyObject *self, PyObject *args) |
| 169 | +{ |
| 170 | + PyObject *library; |
| 171 | + int was_alive = (_cffi_types != NULL); |
| 172 | + (void)self; /* unused */ |
| 173 | + if (!PyArg_ParseTuple(args, "OOO", &_cffi_types, &_cffi_VerificationError, |
| 174 | + &library)) |
| 175 | + return NULL; |
| 176 | + Py_INCREF(_cffi_types); |
| 177 | + Py_INCREF(_cffi_VerificationError); |
| 178 | + if (_cffi_setup_custom(library) < 0) |
| 179 | + return NULL; |
| 180 | + return PyBool_FromLong(was_alive); |
| 181 | +} |
| 182 | + |
| 183 | +union _cffi_union_alignment_u { |
| 184 | + unsigned char m_char; |
| 185 | + unsigned short m_short; |
| 186 | + unsigned int m_int; |
| 187 | + unsigned long m_long; |
| 188 | + unsigned long long m_longlong; |
| 189 | + float m_float; |
| 190 | + double m_double; |
| 191 | + long double m_longdouble; |
| 192 | +}; |
| 193 | + |
| 194 | +struct _cffi_freeme_s { |
| 195 | + struct _cffi_freeme_s *next; |
| 196 | + union _cffi_union_alignment_u alignment; |
| 197 | +}; |
| 198 | + |
| 199 | +#ifdef __GNUC__ |
| 200 | + __attribute__((unused)) |
| 201 | +#endif |
| 202 | +static int _cffi_convert_array_argument(CTypeDescrObject *ctptr, PyObject *arg, |
| 203 | + char **output_data, Py_ssize_t datasize, |
| 204 | + struct _cffi_freeme_s **freeme) |
| 205 | +{ |
| 206 | + char *p; |
| 207 | + if (datasize < 0) |
| 208 | + return -1; |
| 209 | + |
| 210 | + p = *output_data; |
| 211 | + if (p == NULL) { |
| 212 | + struct _cffi_freeme_s *fp = (struct _cffi_freeme_s *)PyObject_Malloc( |
| 213 | + offsetof(struct _cffi_freeme_s, alignment) + (size_t)datasize); |
| 214 | + if (fp == NULL) |
| 215 | + return -1; |
| 216 | + fp->next = *freeme; |
| 217 | + *freeme = fp; |
| 218 | + p = *output_data = (char *)&fp->alignment; |
| 219 | + } |
| 220 | + memset((void *)p, 0, (size_t)datasize); |
| 221 | + return _cffi_convert_array_from_object(p, ctptr, arg); |
| 222 | +} |
| 223 | + |
| 224 | +#ifdef __GNUC__ |
| 225 | + __attribute__((unused)) |
| 226 | +#endif |
| 227 | +static void _cffi_free_array_arguments(struct _cffi_freeme_s *freeme) |
| 228 | +{ |
| 229 | + do { |
| 230 | + void *p = (void *)freeme; |
| 231 | + freeme = freeme->next; |
| 232 | + PyObject_Free(p); |
| 233 | + } while (freeme != NULL); |
| 234 | +} |
| 235 | + |
| 236 | +static int _cffi_init(void) |
| 237 | +{ |
| 238 | + PyObject *module, *c_api_object = NULL; |
| 239 | + |
| 240 | + module = PyImport_ImportModule("_cffi_backend"); |
| 241 | + if (module == NULL) |
| 242 | + goto failure; |
| 243 | + |
| 244 | + c_api_object = PyObject_GetAttrString(module, "_C_API"); |
| 245 | + if (c_api_object == NULL) |
| 246 | + goto failure; |
| 247 | + if (!PyCapsule_CheckExact(c_api_object)) { |
| 248 | + PyErr_SetNone(PyExc_ImportError); |
| 249 | + goto failure; |
| 250 | + } |
| 251 | + memcpy(_cffi_exports, PyCapsule_GetPointer(c_api_object, "cffi"), |
| 252 | + _CFFI_NUM_EXPORTS * sizeof(void *)); |
| 253 | + |
| 254 | + Py_DECREF(module); |
| 255 | + Py_DECREF(c_api_object); |
| 256 | + return 0; |
| 257 | + |
| 258 | + failure: |
| 259 | + Py_XDECREF(module); |
| 260 | + Py_XDECREF(c_api_object); |
| 261 | + return -1; |
| 262 | +} |
| 263 | + |
| 264 | +#define _cffi_type(num) ((CTypeDescrObject *)PyList_GET_ITEM(_cffi_types, num)) |
| 265 | + |
| 266 | +/**********/ |
| 267 | + |
| 268 | + |
| 269 | + |
| 270 | +#include <tk.h> |
| 271 | +#define TK_HEX_VERSION ((TK_MAJOR_VERSION << 24) | (TK_MINOR_VERSION << 16) | (TK_RELEASE_LEVEL << 8) | (TK_RELEASE_SERIAL << 0)) |
| 272 | +#ifdef TCL_WIDE_INT_TYPE |
| 273 | +#define HAVE_WIDE_INT_TYPE 1 |
| 274 | +#else |
| 275 | +#define HAVE_WIDE_INT_TYPE 0 |
| 276 | +#endif |
| 277 | + |
| 278 | + |
| 279 | +static int _cffi_const_HAVE_WIDE_INT_TYPE(PyObject *lib) |
| 280 | +{ |
| 281 | + PyObject *o; |
| 282 | + int res; |
| 283 | + o = _cffi_from_c_int_const(HAVE_WIDE_INT_TYPE); |
| 284 | + if (o == NULL) |
| 285 | + return -1; |
| 286 | + res = PyObject_SetAttrString(lib, "HAVE_WIDE_INT_TYPE", o); |
| 287 | + Py_DECREF(o); |
| 288 | + if (res < 0) |
| 289 | + return -1; |
| 290 | + return ((void)lib,0); |
| 291 | +} |
| 292 | + |
| 293 | +static int _cffi_const_TK_HEX_VERSION(PyObject *lib) |
| 294 | +{ |
| 295 | + PyObject *o; |
| 296 | + int res; |
| 297 | + o = _cffi_from_c_int_const(TK_HEX_VERSION); |
| 298 | + if (o == NULL) |
| 299 | + return -1; |
| 300 | + res = PyObject_SetAttrString(lib, "TK_HEX_VERSION", o); |
| 301 | + Py_DECREF(o); |
| 302 | + if (res < 0) |
| 303 | + return -1; |
| 304 | + return _cffi_const_HAVE_WIDE_INT_TYPE(lib); |
| 305 | +} |
| 306 | + |
| 307 | +static int _cffi_setup_custom(PyObject *lib) |
| 308 | +{ |
| 309 | + return _cffi_const_TK_HEX_VERSION(lib); |
| 310 | +} |
| 311 | + |
| 312 | +static PyMethodDef _cffi_methods[] = { |
| 313 | + {"_cffi_setup", _cffi_setup, METH_VARARGS, NULL}, |
| 314 | + {NULL, NULL, 0, NULL} /* Sentinel */ |
| 315 | +}; |
| 316 | + |
| 317 | +#if PY_MAJOR_VERSION >= 3 |
| 318 | + |
| 319 | +static struct PyModuleDef _cffi_module_def = { |
| 320 | + PyModuleDef_HEAD_INIT, |
| 321 | + "_cffi__x993bc6b9x15ee1dff", |
| 322 | + NULL, |
| 323 | + -1, |
| 324 | + _cffi_methods, |
| 325 | + NULL, NULL, NULL, NULL |
| 326 | +}; |
| 327 | + |
| 328 | +PyMODINIT_FUNC |
| 329 | +PyInit__cffi__x993bc6b9x15ee1dff(void) |
| 330 | +{ |
| 331 | + PyObject *lib; |
| 332 | + lib = PyModule_Create(&_cffi_module_def); |
| 333 | + if (lib == NULL) |
| 334 | + return NULL; |
| 335 | + if (((void)lib,0) < 0 || _cffi_init() < 0) { |
| 336 | + Py_DECREF(lib); |
| 337 | + return NULL; |
| 338 | + } |
| 339 | + return lib; |
| 340 | +} |
| 341 | + |
| 342 | +#else |
| 343 | + |
| 344 | +PyMODINIT_FUNC |
| 345 | +init_cffi__x993bc6b9x15ee1dff(void) |
| 346 | +{ |
| 347 | + PyObject *lib; |
| 348 | + lib = Py_InitModule("_cffi__x993bc6b9x15ee1dff", _cffi_methods); |
| 349 | + if (lib == NULL) |
| 350 | + return; |
| 351 | + if (((void)lib,0) < 0 || _cffi_init() < 0) |
| 352 | + return; |
| 353 | + return; |
| 354 | +} |
| 355 | + |
| 356 | +#endif |
0 commit comments