You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

638 lines
21 KiB

  1. #define _CFFI_
  2. #include <Python.h>
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <stddef.h>
  7. /* This part is from file 'cffi/parse_c_type.h'. It is copied at the
  8. beginning of C sources generated by CFFI's ffi.set_source(). */
  9. typedef void *_cffi_opcode_t;
  10. #define _CFFI_OP(opcode, arg) (_cffi_opcode_t)(opcode | (((uintptr_t)(arg)) << 8))
  11. #define _CFFI_GETOP(cffi_opcode) ((unsigned char)(uintptr_t)cffi_opcode)
  12. #define _CFFI_GETARG(cffi_opcode) (((intptr_t)cffi_opcode) >> 8)
  13. #define _CFFI_OP_PRIMITIVE 1
  14. #define _CFFI_OP_POINTER 3
  15. #define _CFFI_OP_ARRAY 5
  16. #define _CFFI_OP_OPEN_ARRAY 7
  17. #define _CFFI_OP_STRUCT_UNION 9
  18. #define _CFFI_OP_ENUM 11
  19. #define _CFFI_OP_FUNCTION 13
  20. #define _CFFI_OP_FUNCTION_END 15
  21. #define _CFFI_OP_NOOP 17
  22. #define _CFFI_OP_BITFIELD 19
  23. #define _CFFI_OP_TYPENAME 21
  24. #define _CFFI_OP_CPYTHON_BLTN_V 23 // varargs
  25. #define _CFFI_OP_CPYTHON_BLTN_N 25 // noargs
  26. #define _CFFI_OP_CPYTHON_BLTN_O 27 // O (i.e. a single arg)
  27. #define _CFFI_OP_CONSTANT 29
  28. #define _CFFI_OP_CONSTANT_INT 31
  29. #define _CFFI_OP_GLOBAL_VAR 33
  30. #define _CFFI_OP_DLOPEN_FUNC 35
  31. #define _CFFI_OP_DLOPEN_CONST 37
  32. #define _CFFI_OP_GLOBAL_VAR_F 39
  33. #define _CFFI_OP_EXTERN_PYTHON 41
  34. #define _CFFI_PRIM_VOID 0
  35. #define _CFFI_PRIM_BOOL 1
  36. #define _CFFI_PRIM_CHAR 2
  37. #define _CFFI_PRIM_SCHAR 3
  38. #define _CFFI_PRIM_UCHAR 4
  39. #define _CFFI_PRIM_SHORT 5
  40. #define _CFFI_PRIM_USHORT 6
  41. #define _CFFI_PRIM_INT 7
  42. #define _CFFI_PRIM_UINT 8
  43. #define _CFFI_PRIM_LONG 9
  44. #define _CFFI_PRIM_ULONG 10
  45. #define _CFFI_PRIM_LONGLONG 11
  46. #define _CFFI_PRIM_ULONGLONG 12
  47. #define _CFFI_PRIM_FLOAT 13
  48. #define _CFFI_PRIM_DOUBLE 14
  49. #define _CFFI_PRIM_LONGDOUBLE 15
  50. #define _CFFI_PRIM_WCHAR 16
  51. #define _CFFI_PRIM_INT8 17
  52. #define _CFFI_PRIM_UINT8 18
  53. #define _CFFI_PRIM_INT16 19
  54. #define _CFFI_PRIM_UINT16 20
  55. #define _CFFI_PRIM_INT32 21
  56. #define _CFFI_PRIM_UINT32 22
  57. #define _CFFI_PRIM_INT64 23
  58. #define _CFFI_PRIM_UINT64 24
  59. #define _CFFI_PRIM_INTPTR 25
  60. #define _CFFI_PRIM_UINTPTR 26
  61. #define _CFFI_PRIM_PTRDIFF 27
  62. #define _CFFI_PRIM_SIZE 28
  63. #define _CFFI_PRIM_SSIZE 29
  64. #define _CFFI_PRIM_INT_LEAST8 30
  65. #define _CFFI_PRIM_UINT_LEAST8 31
  66. #define _CFFI_PRIM_INT_LEAST16 32
  67. #define _CFFI_PRIM_UINT_LEAST16 33
  68. #define _CFFI_PRIM_INT_LEAST32 34
  69. #define _CFFI_PRIM_UINT_LEAST32 35
  70. #define _CFFI_PRIM_INT_LEAST64 36
  71. #define _CFFI_PRIM_UINT_LEAST64 37
  72. #define _CFFI_PRIM_INT_FAST8 38
  73. #define _CFFI_PRIM_UINT_FAST8 39
  74. #define _CFFI_PRIM_INT_FAST16 40
  75. #define _CFFI_PRIM_UINT_FAST16 41
  76. #define _CFFI_PRIM_INT_FAST32 42
  77. #define _CFFI_PRIM_UINT_FAST32 43
  78. #define _CFFI_PRIM_INT_FAST64 44
  79. #define _CFFI_PRIM_UINT_FAST64 45
  80. #define _CFFI_PRIM_INTMAX 46
  81. #define _CFFI_PRIM_UINTMAX 47
  82. #define _CFFI__NUM_PRIM 48
  83. #define _CFFI__UNKNOWN_PRIM (-1)
  84. #define _CFFI__UNKNOWN_FLOAT_PRIM (-2)
  85. #define _CFFI__UNKNOWN_LONG_DOUBLE (-3)
  86. #define _CFFI__IO_FILE_STRUCT (-1)
  87. struct _cffi_global_s {
  88. const char *name;
  89. void *address;
  90. _cffi_opcode_t type_op;
  91. void *size_or_direct_fn; // OP_GLOBAL_VAR: size, or 0 if unknown
  92. // OP_CPYTHON_BLTN_*: addr of direct function
  93. };
  94. struct _cffi_getconst_s {
  95. unsigned long long value;
  96. const struct _cffi_type_context_s *ctx;
  97. int gindex;
  98. };
  99. struct _cffi_struct_union_s {
  100. const char *name;
  101. int type_index; // -> _cffi_types, on a OP_STRUCT_UNION
  102. int flags; // _CFFI_F_* flags below
  103. size_t size;
  104. int alignment;
  105. int first_field_index; // -> _cffi_fields array
  106. int num_fields;
  107. };
  108. #define _CFFI_F_UNION 0x01 // is a union, not a struct
  109. #define _CFFI_F_CHECK_FIELDS 0x02 // complain if fields are not in the
  110. // "standard layout" or if some are missing
  111. #define _CFFI_F_PACKED 0x04 // for CHECK_FIELDS, assume a packed struct
  112. #define _CFFI_F_EXTERNAL 0x08 // in some other ffi.include()
  113. #define _CFFI_F_OPAQUE 0x10 // opaque
  114. struct _cffi_field_s {
  115. const char *name;
  116. size_t field_offset;
  117. size_t field_size;
  118. _cffi_opcode_t field_type_op;
  119. };
  120. struct _cffi_enum_s {
  121. const char *name;
  122. int type_index; // -> _cffi_types, on a OP_ENUM
  123. int type_prim; // _CFFI_PRIM_xxx
  124. const char *enumerators; // comma-delimited string
  125. };
  126. struct _cffi_typename_s {
  127. const char *name;
  128. int type_index; /* if opaque, points to a possibly artificial
  129. OP_STRUCT which is itself opaque */
  130. };
  131. struct _cffi_type_context_s {
  132. _cffi_opcode_t *types;
  133. const struct _cffi_global_s *globals;
  134. const struct _cffi_field_s *fields;
  135. const struct _cffi_struct_union_s *struct_unions;
  136. const struct _cffi_enum_s *enums;
  137. const struct _cffi_typename_s *typenames;
  138. int num_globals;
  139. int num_struct_unions;
  140. int num_enums;
  141. int num_typenames;
  142. const char *const *includes;
  143. int num_types;
  144. int flags; /* future extension */
  145. };
  146. struct _cffi_parse_info_s {
  147. const struct _cffi_type_context_s *ctx;
  148. _cffi_opcode_t *output;
  149. unsigned int output_size;
  150. size_t error_location;
  151. const char *error_message;
  152. };
  153. struct _cffi_externpy_s {
  154. const char *name;
  155. size_t size_of_result;
  156. void *reserved1, *reserved2;
  157. };
  158. #ifdef _CFFI_INTERNAL
  159. static int parse_c_type(struct _cffi_parse_info_s *info, const char *input);
  160. static int search_in_globals(const struct _cffi_type_context_s *ctx,
  161. const char *search, size_t search_len);
  162. static int search_in_struct_unions(const struct _cffi_type_context_s *ctx,
  163. const char *search, size_t search_len);
  164. #endif
  165. /* this block of #ifs should be kept exactly identical between
  166. c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py
  167. and cffi/_cffi_include.h */
  168. #if defined(_MSC_VER)
  169. # include <malloc.h> /* for alloca() */
  170. # if _MSC_VER < 1600 /* MSVC < 2010 */
  171. typedef __int8 int8_t;
  172. typedef __int16 int16_t;
  173. typedef __int32 int32_t;
  174. typedef __int64 int64_t;
  175. typedef unsigned __int8 uint8_t;
  176. typedef unsigned __int16 uint16_t;
  177. typedef unsigned __int32 uint32_t;
  178. typedef unsigned __int64 uint64_t;
  179. typedef __int8 int_least8_t;
  180. typedef __int16 int_least16_t;
  181. typedef __int32 int_least32_t;
  182. typedef __int64 int_least64_t;
  183. typedef unsigned __int8 uint_least8_t;
  184. typedef unsigned __int16 uint_least16_t;
  185. typedef unsigned __int32 uint_least32_t;
  186. typedef unsigned __int64 uint_least64_t;
  187. typedef __int8 int_fast8_t;
  188. typedef __int16 int_fast16_t;
  189. typedef __int32 int_fast32_t;
  190. typedef __int64 int_fast64_t;
  191. typedef unsigned __int8 uint_fast8_t;
  192. typedef unsigned __int16 uint_fast16_t;
  193. typedef unsigned __int32 uint_fast32_t;
  194. typedef unsigned __int64 uint_fast64_t;
  195. typedef __int64 intmax_t;
  196. typedef unsigned __int64 uintmax_t;
  197. # else
  198. # include <stdint.h>
  199. # endif
  200. # if _MSC_VER < 1800 /* MSVC < 2013 */
  201. typedef unsigned char _Bool;
  202. # endif
  203. #else
  204. # include <stdint.h>
  205. # if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux)
  206. # include <alloca.h>
  207. # endif
  208. #endif
  209. #ifdef __GNUC__
  210. # define _CFFI_UNUSED_FN __attribute__((unused))
  211. #else
  212. # define _CFFI_UNUSED_FN /* nothing */
  213. #endif
  214. /********** CPython-specific section **********/
  215. #ifndef PYPY_VERSION
  216. #if PY_MAJOR_VERSION >= 3
  217. # define PyInt_FromLong PyLong_FromLong
  218. #endif
  219. #define _cffi_from_c_double PyFloat_FromDouble
  220. #define _cffi_from_c_float PyFloat_FromDouble
  221. #define _cffi_from_c_long PyInt_FromLong
  222. #define _cffi_from_c_ulong PyLong_FromUnsignedLong
  223. #define _cffi_from_c_longlong PyLong_FromLongLong
  224. #define _cffi_from_c_ulonglong PyLong_FromUnsignedLongLong
  225. #define _cffi_to_c_double PyFloat_AsDouble
  226. #define _cffi_to_c_float PyFloat_AsDouble
  227. #define _cffi_from_c_int(x, type) \
  228. (((type)-1) > 0 ? /* unsigned */ \
  229. (sizeof(type) < sizeof(long) ? \
  230. PyInt_FromLong((long)x) : \
  231. sizeof(type) == sizeof(long) ? \
  232. PyLong_FromUnsignedLong((unsigned long)x) : \
  233. PyLong_FromUnsignedLongLong((unsigned long long)x)) : \
  234. (sizeof(type) <= sizeof(long) ? \
  235. PyInt_FromLong((long)x) : \
  236. PyLong_FromLongLong((long long)x)))
  237. #define _cffi_to_c_int(o, type) \
  238. ((type)( \
  239. sizeof(type) == 1 ? (((type)-1) > 0 ? (type)_cffi_to_c_u8(o) \
  240. : (type)_cffi_to_c_i8(o)) : \
  241. sizeof(type) == 2 ? (((type)-1) > 0 ? (type)_cffi_to_c_u16(o) \
  242. : (type)_cffi_to_c_i16(o)) : \
  243. sizeof(type) == 4 ? (((type)-1) > 0 ? (type)_cffi_to_c_u32(o) \
  244. : (type)_cffi_to_c_i32(o)) : \
  245. sizeof(type) == 8 ? (((type)-1) > 0 ? (type)_cffi_to_c_u64(o) \
  246. : (type)_cffi_to_c_i64(o)) : \
  247. (Py_FatalError("unsupported size for type " #type), (type)0)))
  248. #define _cffi_to_c_i8 \
  249. ((int(*)(PyObject *))_cffi_exports[1])
  250. #define _cffi_to_c_u8 \
  251. ((int(*)(PyObject *))_cffi_exports[2])
  252. #define _cffi_to_c_i16 \
  253. ((int(*)(PyObject *))_cffi_exports[3])
  254. #define _cffi_to_c_u16 \
  255. ((int(*)(PyObject *))_cffi_exports[4])
  256. #define _cffi_to_c_i32 \
  257. ((int(*)(PyObject *))_cffi_exports[5])
  258. #define _cffi_to_c_u32 \
  259. ((unsigned int(*)(PyObject *))_cffi_exports[6])
  260. #define _cffi_to_c_i64 \
  261. ((long long(*)(PyObject *))_cffi_exports[7])
  262. #define _cffi_to_c_u64 \
  263. ((unsigned long long(*)(PyObject *))_cffi_exports[8])
  264. #define _cffi_to_c_char \
  265. ((int(*)(PyObject *))_cffi_exports[9])
  266. #define _cffi_from_c_pointer \
  267. ((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[10])
  268. #define _cffi_to_c_pointer \
  269. ((char *(*)(PyObject *, CTypeDescrObject *))_cffi_exports[11])
  270. #define _cffi_get_struct_layout \
  271. not used any more
  272. #define _cffi_restore_errno \
  273. ((void(*)(void))_cffi_exports[13])
  274. #define _cffi_save_errno \
  275. ((void(*)(void))_cffi_exports[14])
  276. #define _cffi_from_c_char \
  277. ((PyObject *(*)(char))_cffi_exports[15])
  278. #define _cffi_from_c_deref \
  279. ((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[16])
  280. #define _cffi_to_c \
  281. ((int(*)(char *, CTypeDescrObject *, PyObject *))_cffi_exports[17])
  282. #define _cffi_from_c_struct \
  283. ((PyObject *(*)(char *, CTypeDescrObject *))_cffi_exports[18])
  284. #define _cffi_to_c_wchar_t \
  285. ((wchar_t(*)(PyObject *))_cffi_exports[19])
  286. #define _cffi_from_c_wchar_t \
  287. ((PyObject *(*)(wchar_t))_cffi_exports[20])
  288. #define _cffi_to_c_long_double \
  289. ((long double(*)(PyObject *))_cffi_exports[21])
  290. #define _cffi_to_c__Bool \
  291. ((_Bool(*)(PyObject *))_cffi_exports[22])
  292. #define _cffi_prepare_pointer_call_argument \
  293. ((Py_ssize_t(*)(CTypeDescrObject *, PyObject *, char **))_cffi_exports[23])
  294. #define _cffi_convert_array_from_object \
  295. ((int(*)(char *, CTypeDescrObject *, PyObject *))_cffi_exports[24])
  296. #define _cffi_call_python \
  297. ((void(*)(struct _cffi_externpy_s *, char *))_cffi_exports[25])
  298. #define _CFFI_NUM_EXPORTS 26
  299. typedef struct _ctypedescr CTypeDescrObject;
  300. static void *_cffi_exports[_CFFI_NUM_EXPORTS];
  301. #define _cffi_type(index) ( \
  302. assert((((uintptr_t)_cffi_types[index]) & 1) == 0), \
  303. (CTypeDescrObject *)_cffi_types[index])
  304. static PyObject *_cffi_init(const char *module_name, Py_ssize_t version,
  305. const struct _cffi_type_context_s *ctx)
  306. {
  307. PyObject *module, *o_arg, *new_module;
  308. void *raw[] = {
  309. (void *)module_name,
  310. (void *)version,
  311. (void *)_cffi_exports,
  312. (void *)ctx,
  313. };
  314. module = PyImport_ImportModule("_cffi_backend");
  315. if (module == NULL)
  316. goto failure;
  317. o_arg = PyLong_FromVoidPtr((void *)raw);
  318. if (o_arg == NULL)
  319. goto failure;
  320. new_module = PyObject_CallMethod(
  321. module, (char *)"_init_cffi_1_0_external_module", (char *)"O", o_arg);
  322. Py_DECREF(o_arg);
  323. Py_DECREF(module);
  324. return new_module;
  325. failure:
  326. Py_XDECREF(module);
  327. return NULL;
  328. }
  329. _CFFI_UNUSED_FN
  330. static PyObject **_cffi_unpack_args(PyObject *args_tuple, Py_ssize_t expected,
  331. const char *fnname)
  332. {
  333. if (PyTuple_GET_SIZE(args_tuple) != expected) {
  334. PyErr_Format(PyExc_TypeError,
  335. "%.150s() takes exactly %zd arguments (%zd given)",
  336. fnname, expected, PyTuple_GET_SIZE(args_tuple));
  337. return NULL;
  338. }
  339. return &PyTuple_GET_ITEM(args_tuple, 0); /* pointer to the first item,
  340. the others follow */
  341. }
  342. /********** end CPython-specific section **********/
  343. #else
  344. _CFFI_UNUSED_FN
  345. static void (*_cffi_call_python)(struct _cffi_externpy_s *, char *);
  346. #endif
  347. #define _cffi_array_len(array) (sizeof(array) / sizeof((array)[0]))
  348. #define _cffi_prim_int(size, sign) \
  349. ((size) == 1 ? ((sign) ? _CFFI_PRIM_INT8 : _CFFI_PRIM_UINT8) : \
  350. (size) == 2 ? ((sign) ? _CFFI_PRIM_INT16 : _CFFI_PRIM_UINT16) : \
  351. (size) == 4 ? ((sign) ? _CFFI_PRIM_INT32 : _CFFI_PRIM_UINT32) : \
  352. (size) == 8 ? ((sign) ? _CFFI_PRIM_INT64 : _CFFI_PRIM_UINT64) : \
  353. _CFFI__UNKNOWN_PRIM)
  354. #define _cffi_prim_float(size) \
  355. ((size) == sizeof(float) ? _CFFI_PRIM_FLOAT : \
  356. (size) == sizeof(double) ? _CFFI_PRIM_DOUBLE : \
  357. (size) == sizeof(long double) ? _CFFI__UNKNOWN_LONG_DOUBLE : \
  358. _CFFI__UNKNOWN_FLOAT_PRIM)
  359. #define _cffi_check_int(got, got_nonpos, expected) \
  360. ((got_nonpos) == (expected <= 0) && \
  361. (got) == (unsigned long long)expected)
  362. #ifdef __cplusplus
  363. }
  364. #endif
  365. /************************************************************/
  366. #include <dlfcn.h>
  367. /************************************************************/
  368. static void *_cffi_types[] = {
  369. /* 0 */ _CFFI_OP(_CFFI_OP_FUNCTION, 6), // uint64_t()(char const *)
  370. /* 1 */ _CFFI_OP(_CFFI_OP_POINTER, 5), // char const *
  371. /* 2 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0),
  372. /* 3 */ _CFFI_OP(_CFFI_OP_FUNCTION, 7), // void()(void)
  373. /* 4 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0),
  374. /* 5 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 2), // char
  375. /* 6 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 24), // uint64_t
  376. /* 7 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 0), // void
  377. };
  378. static uint64_t _cffi_d_ext_get_ahash(char const * x0)
  379. {
  380. return ext_get_ahash(x0);
  381. }
  382. #ifndef PYPY_VERSION
  383. static PyObject *
  384. _cffi_f_ext_get_ahash(PyObject *self, PyObject *arg0)
  385. {
  386. char const * x0;
  387. Py_ssize_t datasize;
  388. uint64_t result;
  389. datasize = _cffi_prepare_pointer_call_argument(
  390. _cffi_type(1), arg0, (char **)&x0);
  391. if (datasize != 0) {
  392. if (datasize < 0)
  393. return NULL;
  394. x0 = (char const *)alloca((size_t)datasize);
  395. memset((void *)x0, 0, (size_t)datasize);
  396. if (_cffi_convert_array_from_object((char *)x0, _cffi_type(1), arg0) < 0)
  397. return NULL;
  398. }
  399. Py_BEGIN_ALLOW_THREADS
  400. _cffi_restore_errno();
  401. { result = ext_get_ahash(x0); }
  402. _cffi_save_errno();
  403. Py_END_ALLOW_THREADS
  404. (void)self; /* unused */
  405. return _cffi_from_c_int(result, uint64_t);
  406. }
  407. #else
  408. # define _cffi_f_ext_get_ahash _cffi_d_ext_get_ahash
  409. #endif
  410. static uint64_t _cffi_d_ext_get_dhash(char const * x0)
  411. {
  412. return ext_get_dhash(x0);
  413. }
  414. #ifndef PYPY_VERSION
  415. static PyObject *
  416. _cffi_f_ext_get_dhash(PyObject *self, PyObject *arg0)
  417. {
  418. char const * x0;
  419. Py_ssize_t datasize;
  420. uint64_t result;
  421. datasize = _cffi_prepare_pointer_call_argument(
  422. _cffi_type(1), arg0, (char **)&x0);
  423. if (datasize != 0) {
  424. if (datasize < 0)
  425. return NULL;
  426. x0 = (char const *)alloca((size_t)datasize);
  427. memset((void *)x0, 0, (size_t)datasize);
  428. if (_cffi_convert_array_from_object((char *)x0, _cffi_type(1), arg0) < 0)
  429. return NULL;
  430. }
  431. Py_BEGIN_ALLOW_THREADS
  432. _cffi_restore_errno();
  433. { result = ext_get_dhash(x0); }
  434. _cffi_save_errno();
  435. Py_END_ALLOW_THREADS
  436. (void)self; /* unused */
  437. return _cffi_from_c_int(result, uint64_t);
  438. }
  439. #else
  440. # define _cffi_f_ext_get_dhash _cffi_d_ext_get_dhash
  441. #endif
  442. static uint64_t _cffi_d_ext_get_phash(char const * x0)
  443. {
  444. return ext_get_phash(x0);
  445. }
  446. #ifndef PYPY_VERSION
  447. static PyObject *
  448. _cffi_f_ext_get_phash(PyObject *self, PyObject *arg0)
  449. {
  450. char const * x0;
  451. Py_ssize_t datasize;
  452. uint64_t result;
  453. datasize = _cffi_prepare_pointer_call_argument(
  454. _cffi_type(1), arg0, (char **)&x0);
  455. if (datasize != 0) {
  456. if (datasize < 0)
  457. return NULL;
  458. x0 = (char const *)alloca((size_t)datasize);
  459. memset((void *)x0, 0, (size_t)datasize);
  460. if (_cffi_convert_array_from_object((char *)x0, _cffi_type(1), arg0) < 0)
  461. return NULL;
  462. }
  463. Py_BEGIN_ALLOW_THREADS
  464. _cffi_restore_errno();
  465. { result = ext_get_phash(x0); }
  466. _cffi_save_errno();
  467. Py_END_ALLOW_THREADS
  468. (void)self; /* unused */
  469. return _cffi_from_c_int(result, uint64_t);
  470. }
  471. #else
  472. # define _cffi_f_ext_get_phash _cffi_d_ext_get_phash
  473. #endif
  474. static void _cffi_d_init(void)
  475. {
  476. init();
  477. }
  478. #ifndef PYPY_VERSION
  479. static PyObject *
  480. _cffi_f_init(PyObject *self, PyObject *noarg)
  481. {
  482. Py_BEGIN_ALLOW_THREADS
  483. _cffi_restore_errno();
  484. { init(); }
  485. _cffi_save_errno();
  486. Py_END_ALLOW_THREADS
  487. (void)self; /* unused */
  488. (void)noarg; /* unused */
  489. Py_INCREF(Py_None);
  490. return Py_None;
  491. }
  492. #else
  493. # define _cffi_f_init _cffi_d_init
  494. #endif
  495. static void _cffi_d_teardown(void)
  496. {
  497. teardown();
  498. }
  499. #ifndef PYPY_VERSION
  500. static PyObject *
  501. _cffi_f_teardown(PyObject *self, PyObject *noarg)
  502. {
  503. Py_BEGIN_ALLOW_THREADS
  504. _cffi_restore_errno();
  505. { teardown(); }
  506. _cffi_save_errno();
  507. Py_END_ALLOW_THREADS
  508. (void)self; /* unused */
  509. (void)noarg; /* unused */
  510. Py_INCREF(Py_None);
  511. return Py_None;
  512. }
  513. #else
  514. # define _cffi_f_teardown _cffi_d_teardown
  515. #endif
  516. static const struct _cffi_global_s _cffi_globals[] = {
  517. { "ext_get_ahash", (void *)_cffi_f_ext_get_ahash, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_O, 0), (void *)_cffi_d_ext_get_ahash },
  518. { "ext_get_dhash", (void *)_cffi_f_ext_get_dhash, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_O, 0), (void *)_cffi_d_ext_get_dhash },
  519. { "ext_get_phash", (void *)_cffi_f_ext_get_phash, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_O, 0), (void *)_cffi_d_ext_get_phash },
  520. { "init", (void *)_cffi_f_init, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_N, 3), (void *)_cffi_d_init },
  521. { "teardown", (void *)_cffi_f_teardown, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_N, 3), (void *)_cffi_d_teardown },
  522. };
  523. static const struct _cffi_type_context_s _cffi_type_context = {
  524. _cffi_types,
  525. _cffi_globals,
  526. NULL, /* no fields */
  527. NULL, /* no struct_unions */
  528. NULL, /* no enums */
  529. NULL, /* no typenames */
  530. 5, /* num_globals */
  531. 0, /* num_struct_unions */
  532. 0, /* num_enums */
  533. 0, /* num_typenames */
  534. NULL, /* no includes */
  535. 8, /* num_types */
  536. 0, /* flags */
  537. };
  538. #ifdef PYPY_VERSION
  539. PyMODINIT_FUNC
  540. _cffi_pypyinit__ffi_test_py(const void *p[])
  541. {
  542. p[0] = (const void *)0x2601;
  543. p[1] = &_cffi_type_context;
  544. }
  545. # ifdef _MSC_VER
  546. PyMODINIT_FUNC
  547. # if PY_MAJOR_VERSION >= 3
  548. PyInit__ffi_test_py(void) { return NULL; }
  549. # else
  550. init_ffi_test_py(void) { }
  551. # endif
  552. # endif
  553. #elif PY_MAJOR_VERSION >= 3
  554. PyMODINIT_FUNC
  555. PyInit__ffi_test_py(void)
  556. {
  557. return _cffi_init("_ffi_test_py", 0x2601, &_cffi_type_context);
  558. }
  559. #else
  560. PyMODINIT_FUNC
  561. init_ffi_test_py(void)
  562. {
  563. _cffi_init("_ffi_test_py", 0x2601, &_cffi_type_context);
  564. }
  565. #endif