Advertisement
luckydonald

Untitled

Aug 4th, 2021
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.03 KB | None | 0 0
  1. ; search for "# ERROR HERE" below.
  2.  
  3.  
  4. #define _CFFI_
  5.  
  6. /* We try to define Py_LIMITED_API before including Python.h.
  7.  
  8. Mess: we can only define it if Py_DEBUG, Py_TRACE_REFS and
  9. Py_REF_DEBUG are not defined. This is a best-effort approximation:
  10. we can learn about Py_DEBUG from pyconfig.h, but it is unclear if
  11. the same works for the other two macros. Py_DEBUG implies them,
  12. but not the other way around.
  13.  
  14. The implementation is messy (issue #350): on Windows, with _MSC_VER,
  15. we have to define Py_LIMITED_API even before including pyconfig.h.
  16. In that case, we guess what pyconfig.h will do to the macros above,
  17. and check our guess after the #include.
  18.  
  19. Note that on Windows, with CPython 3.x, you need >= 3.5 and virtualenv
  20. version >= 16.0.0. With older versions of either, you don't get a
  21. copy of PYTHON3.DLL in the virtualenv. We can't check the version of
  22. CPython *before* we even include pyconfig.h. ffi.set_source() puts
  23. a ``#define _CFFI_NO_LIMITED_API'' at the start of this file if it is
  24. running on Windows < 3.5, as an attempt at fixing it, but that's
  25. arguably wrong because it may not be the target version of Python.
  26. Still better than nothing I guess. As another workaround, you can
  27. remove the definition of Py_LIMITED_API here.
  28.  
  29. See also 'py_limited_api' in cffi/setuptools_ext.py.
  30. */
  31. #if !defined(_CFFI_USE_EMBEDDING) && !defined(Py_LIMITED_API)
  32. # ifdef _MSC_VER
  33. # if !defined(_DEBUG) && !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG) && !defined(_CFFI_NO_LIMITED_API)
  34. # define Py_LIMITED_API
  35. # endif
  36. # include <pyconfig.h>
  37. /* sanity-check: Py_LIMITED_API will cause crashes if any of these
  38. are also defined. Normally, the Python file PC/pyconfig.h does not
  39. cause any of these to be defined, with the exception that _DEBUG
  40. causes Py_DEBUG. Double-check that. */
  41. # ifdef Py_LIMITED_API
  42. # if defined(Py_DEBUG)
  43. # error "pyconfig.h unexpectedly defines Py_DEBUG, but Py_LIMITED_API is set"
  44. # endif
  45. # if defined(Py_TRACE_REFS)
  46. # error "pyconfig.h unexpectedly defines Py_TRACE_REFS, but Py_LIMITED_API is set"
  47. # endif
  48. # if defined(Py_REF_DEBUG)
  49. # error "pyconfig.h unexpectedly defines Py_REF_DEBUG, but Py_LIMITED_API is set"
  50. # endif
  51. # endif
  52. # else
  53. # include <pyconfig.h>
  54. # if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG) && !defined(_CFFI_NO_LIMITED_API)
  55. # define Py_LIMITED_API
  56. # endif
  57. # endif
  58. #endif
  59.  
  60. #include <Python.h>
  61. #ifdef __cplusplus
  62. extern "C" {
  63. #endif
  64. #include <stddef.h>
  65.  
  66. /* This part is from file 'cffi/parse_c_type.h'. It is copied at the
  67. beginning of C sources generated by CFFI's ffi.set_source(). */
  68.  
  69. typedef void *_cffi_opcode_t;
  70.  
  71. #define _CFFI_OP(opcode, arg) (_cffi_opcode_t)(opcode | (((uintptr_t)(arg)) << 8))
  72. #define _CFFI_GETOP(cffi_opcode) ((unsigned char)(uintptr_t)cffi_opcode)
  73. #define _CFFI_GETARG(cffi_opcode) (((intptr_t)cffi_opcode) >> 8)
  74.  
  75. #define _CFFI_OP_PRIMITIVE 1
  76. #define _CFFI_OP_POINTER 3
  77. #define _CFFI_OP_ARRAY 5
  78. #define _CFFI_OP_OPEN_ARRAY 7
  79. #define _CFFI_OP_STRUCT_UNION 9
  80. #define _CFFI_OP_ENUM 11
  81. #define _CFFI_OP_FUNCTION 13
  82. #define _CFFI_OP_FUNCTION_END 15
  83. #define _CFFI_OP_NOOP 17
  84. #define _CFFI_OP_BITFIELD 19
  85. #define _CFFI_OP_TYPENAME 21
  86. #define _CFFI_OP_CPYTHON_BLTN_V 23 // varargs
  87. #define _CFFI_OP_CPYTHON_BLTN_N 25 // noargs
  88. #define _CFFI_OP_CPYTHON_BLTN_O 27 // O (i.e. a single arg)
  89. #define _CFFI_OP_CONSTANT 29
  90. #define _CFFI_OP_CONSTANT_INT 31
  91. #define _CFFI_OP_GLOBAL_VAR 33
  92. #define _CFFI_OP_DLOPEN_FUNC 35
  93. #define _CFFI_OP_DLOPEN_CONST 37
  94. #define _CFFI_OP_GLOBAL_VAR_F 39
  95. #define _CFFI_OP_EXTERN_PYTHON 41
  96.  
  97. #define _CFFI_PRIM_VOID 0
  98. #define _CFFI_PRIM_BOOL 1
  99. #define _CFFI_PRIM_CHAR 2
  100. #define _CFFI_PRIM_SCHAR 3
  101. #define _CFFI_PRIM_UCHAR 4
  102. #define _CFFI_PRIM_SHORT 5
  103. #define _CFFI_PRIM_USHORT 6
  104. #define _CFFI_PRIM_INT 7
  105. #define _CFFI_PRIM_UINT 8
  106. #define _CFFI_PRIM_LONG 9
  107. #define _CFFI_PRIM_ULONG 10
  108. #define _CFFI_PRIM_LONGLONG 11
  109. #define _CFFI_PRIM_ULONGLONG 12
  110. #define _CFFI_PRIM_FLOAT 13
  111. #define _CFFI_PRIM_DOUBLE 14
  112. #define _CFFI_PRIM_LONGDOUBLE 15
  113.  
  114. #define _CFFI_PRIM_WCHAR 16
  115. #define _CFFI_PRIM_INT8 17
  116. #define _CFFI_PRIM_UINT8 18
  117. #define _CFFI_PRIM_INT16 19
  118. #define _CFFI_PRIM_UINT16 20
  119. #define _CFFI_PRIM_INT32 21
  120. #define _CFFI_PRIM_UINT32 22
  121. #define _CFFI_PRIM_INT64 23
  122. #define _CFFI_PRIM_UINT64 24
  123. #define _CFFI_PRIM_INTPTR 25
  124. #define _CFFI_PRIM_UINTPTR 26
  125. #define _CFFI_PRIM_PTRDIFF 27
  126. #define _CFFI_PRIM_SIZE 28
  127. #define _CFFI_PRIM_SSIZE 29
  128. #define _CFFI_PRIM_INT_LEAST8 30
  129. #define _CFFI_PRIM_UINT_LEAST8 31
  130. #define _CFFI_PRIM_INT_LEAST16 32
  131. #define _CFFI_PRIM_UINT_LEAST16 33
  132. #define _CFFI_PRIM_INT_LEAST32 34
  133. #define _CFFI_PRIM_UINT_LEAST32 35
  134. #define _CFFI_PRIM_INT_LEAST64 36
  135. #define _CFFI_PRIM_UINT_LEAST64 37
  136. #define _CFFI_PRIM_INT_FAST8 38
  137. #define _CFFI_PRIM_UINT_FAST8 39
  138. #define _CFFI_PRIM_INT_FAST16 40
  139. #define _CFFI_PRIM_UINT_FAST16 41
  140. #define _CFFI_PRIM_INT_FAST32 42
  141. #define _CFFI_PRIM_UINT_FAST32 43
  142. #define _CFFI_PRIM_INT_FAST64 44
  143. #define _CFFI_PRIM_UINT_FAST64 45
  144. #define _CFFI_PRIM_INTMAX 46
  145. #define _CFFI_PRIM_UINTMAX 47
  146. #define _CFFI_PRIM_FLOATCOMPLEX 48
  147. #define _CFFI_PRIM_DOUBLECOMPLEX 49
  148. #define _CFFI_PRIM_CHAR16 50
  149. #define _CFFI_PRIM_CHAR32 51
  150.  
  151. #define _CFFI__NUM_PRIM 52
  152. #define _CFFI__UNKNOWN_PRIM (-1)
  153. #define _CFFI__UNKNOWN_FLOAT_PRIM (-2)
  154. #define _CFFI__UNKNOWN_LONG_DOUBLE (-3)
  155.  
  156. #define _CFFI__IO_FILE_STRUCT (-1)
  157.  
  158.  
  159. struct _cffi_global_s {
  160. const char *name;
  161. void *address;
  162. _cffi_opcode_t type_op;
  163. void *size_or_direct_fn; // OP_GLOBAL_VAR: size, or 0 if unknown
  164. // OP_CPYTHON_BLTN_*: addr of direct function
  165. };
  166.  
  167. struct _cffi_getconst_s {
  168. unsigned long long value;
  169. const struct _cffi_type_context_s *ctx;
  170. int gindex;
  171. };
  172.  
  173. struct _cffi_struct_union_s {
  174. const char *name;
  175. int type_index; // -> _cffi_types, on a OP_STRUCT_UNION
  176. int flags; // _CFFI_F_* flags below
  177. size_t size;
  178. int alignment;
  179. int first_field_index; // -> _cffi_fields array
  180. int num_fields;
  181. };
  182. #define _CFFI_F_UNION 0x01 // is a union, not a struct
  183. #define _CFFI_F_CHECK_FIELDS 0x02 // complain if fields are not in the
  184. // "standard layout" or if some are missing
  185. #define _CFFI_F_PACKED 0x04 // for CHECK_FIELDS, assume a packed struct
  186. #define _CFFI_F_EXTERNAL 0x08 // in some other ffi.include()
  187. #define _CFFI_F_OPAQUE 0x10 // opaque
  188.  
  189. struct _cffi_field_s {
  190. const char *name;
  191. size_t field_offset;
  192. size_t field_size;
  193. _cffi_opcode_t field_type_op;
  194. };
  195.  
  196. struct _cffi_enum_s {
  197. const char *name;
  198. int type_index; // -> _cffi_types, on a OP_ENUM
  199. int type_prim; // _CFFI_PRIM_xxx
  200. const char *enumerators; // comma-delimited string
  201. };
  202.  
  203. struct _cffi_typename_s {
  204. const char *name;
  205. int type_index; /* if opaque, points to a possibly artificial
  206. OP_STRUCT which is itself opaque */
  207. };
  208.  
  209. struct _cffi_type_context_s {
  210. _cffi_opcode_t *types;
  211. const struct _cffi_global_s *globals;
  212. const struct _cffi_field_s *fields;
  213. const struct _cffi_struct_union_s *struct_unions;
  214. const struct _cffi_enum_s *enums;
  215. const struct _cffi_typename_s *typenames;
  216. int num_globals;
  217. int num_struct_unions;
  218. int num_enums;
  219. int num_typenames;
  220. const char *const *includes;
  221. int num_types;
  222. int flags; /* future extension */
  223. };
  224.  
  225. struct _cffi_parse_info_s {
  226. const struct _cffi_type_context_s *ctx;
  227. _cffi_opcode_t *output;
  228. unsigned int output_size;
  229. size_t error_location;
  230. const char *error_message;
  231. };
  232.  
  233. struct _cffi_externpy_s {
  234. const char *name;
  235. size_t size_of_result;
  236. void *reserved1, *reserved2;
  237. };
  238.  
  239. #ifdef _CFFI_INTERNAL
  240. static int parse_c_type(struct _cffi_parse_info_s *info, const char *input);
  241. static int search_in_globals(const struct _cffi_type_context_s *ctx,
  242. const char *search, size_t search_len);
  243. static int search_in_struct_unions(const struct _cffi_type_context_s *ctx,
  244. const char *search, size_t search_len);
  245. #endif
  246.  
  247. /* this block of #ifs should be kept exactly identical between
  248. c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py
  249. and cffi/_cffi_include.h */
  250. #if defined(_MSC_VER)
  251. # include <malloc.h> /* for alloca() */
  252. # if _MSC_VER < 1600 /* MSVC < 2010 */
  253. typedef __int8 int8_t;
  254. typedef __int16 int16_t;
  255. typedef __int32 int32_t;
  256. typedef __int64 int64_t;
  257. typedef unsigned __int8 uint8_t;
  258. typedef unsigned __int16 uint16_t;
  259. typedef unsigned __int32 uint32_t;
  260. typedef unsigned __int64 uint64_t;
  261. typedef __int8 int_least8_t;
  262. typedef __int16 int_least16_t;
  263. typedef __int32 int_least32_t;
  264. typedef __int64 int_least64_t;
  265. typedef unsigned __int8 uint_least8_t;
  266. typedef unsigned __int16 uint_least16_t;
  267. typedef unsigned __int32 uint_least32_t;
  268. typedef unsigned __int64 uint_least64_t;
  269. typedef __int8 int_fast8_t;
  270. typedef __int16 int_fast16_t;
  271. typedef __int32 int_fast32_t;
  272. typedef __int64 int_fast64_t;
  273. typedef unsigned __int8 uint_fast8_t;
  274. typedef unsigned __int16 uint_fast16_t;
  275. typedef unsigned __int32 uint_fast32_t;
  276. typedef unsigned __int64 uint_fast64_t;
  277. typedef __int64 intmax_t;
  278. typedef unsigned __int64 uintmax_t;
  279. # else
  280. # include <stdint.h>
  281. # endif
  282. # if _MSC_VER < 1800 /* MSVC < 2013 */
  283. # ifndef __cplusplus
  284. typedef unsigned char _Bool;
  285. # endif
  286. # endif
  287. #else
  288. # include <stdint.h>
  289. # if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux)
  290. # include <alloca.h>
  291. # endif
  292. #endif
  293.  
  294. #ifdef __GNUC__
  295. # define _CFFI_UNUSED_FN __attribute__((unused))
  296. #else
  297. # define _CFFI_UNUSED_FN /* nothing */
  298. #endif
  299.  
  300. #ifdef __cplusplus
  301. # ifndef _Bool
  302. typedef bool _Bool; /* semi-hackish: C++ has no _Bool; bool is builtin */
  303. # endif
  304. #endif
  305.  
  306. /********** CPython-specific section **********/
  307. #ifndef PYPY_VERSION
  308.  
  309.  
  310. #if PY_MAJOR_VERSION >= 3
  311. # define PyInt_FromLong PyLong_FromLong
  312. #endif
  313.  
  314. #define _cffi_from_c_double PyFloat_FromDouble
  315. #define _cffi_from_c_float PyFloat_FromDouble
  316. #define _cffi_from_c_long PyInt_FromLong
  317. #define _cffi_from_c_ulong PyLong_FromUnsignedLong
  318. #define _cffi_from_c_longlong PyLong_FromLongLong
  319. #define _cffi_from_c_ulonglong PyLong_FromUnsignedLongLong
  320. #define _cffi_from_c__Bool PyBool_FromLong
  321.  
  322. #define _cffi_to_c_double PyFloat_AsDouble
  323. #define _cffi_to_c_float PyFloat_AsDouble
  324.  
  325. #define _cffi_from_c_int(x, type) \
  326. (((type)-1) > 0 ? /* unsigned */ \
  327. (sizeof(type) < sizeof(long) ? \
  328. PyInt_FromLong((long)x) : \
  329. sizeof(type) == sizeof(long) ? \
  330. PyLong_FromUnsignedLong((unsigned long)x) : \
  331. PyLong_FromUnsignedLongLong((unsigned long long)x)) : \
  332. (sizeof(type) <= sizeof(long) ? \
  333. PyInt_FromLong((long)x) : \
  334. PyLong_FromLongLong((long long)x)))
  335.  
  336. #define _cffi_to_c_int(o, type) \
  337. ((type)( \
  338. sizeof(type) == 1 ? (((type)-1) > 0 ? (type)_cffi_to_c_u8(o) \
  339. : (type)_cffi_to_c_i8(o)) : \
  340. sizeof(type) == 2 ? (((type)-1) > 0 ? (type)_cffi_to_c_u16(o) \
  341. : (type)_cffi_to_c_i16(o)) : \
  342. sizeof(type) == 4 ? (((type)-1) > 0 ? (type)_cffi_to_c_u32(o) \
  343. : (type)_cffi_to_c_i32(o)) : \
  344. sizeof(type) == 8 ? (((type)-1) > 0 ? (type)_cffi_to_c_u64(o) \
  345. : (type)_cffi_to_c_i64(o)) : \
  346. (Py_FatalError("unsupported size for type " #type), (type)0)))
  347.  
  348. #define _cffi_to_c_i8 \
  349. ((int(*)(PyObject *))_cffi_exports[1])
  350. #define _cffi_to_c_u8 \
  351. ((int(*)(PyObject *))_cffi_exports[2])
  352. #define _cffi_to_c_i16 \
  353. ((int(*)(PyObject *))_cffi_exports[3])
  354. #define _cffi_to_c_u16 \
  355. ((int(*)(PyObject *))_cffi_exports[4])
  356. #define _cffi_to_c_i32 \
  357. ((int(*)(PyObject *))_cffi_exports[5])
  358. #define _cffi_to_c_u32 \
  359. ((unsigned int(*)(PyObject *))_cffi_exports[6])
  360. #define _cffi_to_c_i64 \
  361. ((long long(*)(PyObject *))_cffi_exports[7])
  362. #define _cffi_to_c_u64 \
  363. ((unsigned long long(*)(PyObject *))_cffi_exports[8])
  364. #define _cffi_to_c_char \
  365. ((int(*)(PyObject *))_cffi_exports[9])
  366. #define _cffi_from_c_pointer \
  367. ((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[10])
  368. #define _cffi_to_c_pointer \
  369. ((char *(*)(PyObject *, struct _cffi_ctypedescr *))_cffi_exports[11])
  370. #define _cffi_get_struct_layout \
  371. not used any more
  372. #define _cffi_restore_errno \
  373. ((void(*)(void))_cffi_exports[13])
  374. #define _cffi_save_errno \
  375. ((void(*)(void))_cffi_exports[14])
  376. #define _cffi_from_c_char \
  377. ((PyObject *(*)(char))_cffi_exports[15])
  378. #define _cffi_from_c_deref \
  379. ((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[16])
  380. #define _cffi_to_c \
  381. ((int(*)(char *, struct _cffi_ctypedescr *, PyObject *))_cffi_exports[17])
  382. #define _cffi_from_c_struct \
  383. ((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[18])
  384. #define _cffi_to_c_wchar_t \
  385. ((_cffi_wchar_t(*)(PyObject *))_cffi_exports[19])
  386. #define _cffi_from_c_wchar_t \
  387. ((PyObject *(*)(_cffi_wchar_t))_cffi_exports[20])
  388. #define _cffi_to_c_long_double \
  389. ((long double(*)(PyObject *))_cffi_exports[21])
  390. #define _cffi_to_c__Bool \
  391. ((_Bool(*)(PyObject *))_cffi_exports[22])
  392. #define _cffi_prepare_pointer_call_argument \
  393. ((Py_ssize_t(*)(struct _cffi_ctypedescr *, \
  394. PyObject *, char **))_cffi_exports[23])
  395. #define _cffi_convert_array_from_object \
  396. ((int(*)(char *, struct _cffi_ctypedescr *, PyObject *))_cffi_exports[24])
  397. #define _CFFI_CPIDX 25
  398. #define _cffi_call_python \
  399. ((void(*)(struct _cffi_externpy_s *, char *))_cffi_exports[_CFFI_CPIDX])
  400. #define _cffi_to_c_wchar3216_t \
  401. ((int(*)(PyObject *))_cffi_exports[26])
  402. #define _cffi_from_c_wchar3216_t \
  403. ((PyObject *(*)(int))_cffi_exports[27])
  404. #define _CFFI_NUM_EXPORTS 28
  405.  
  406. struct _cffi_ctypedescr;
  407.  
  408. static void *_cffi_exports[_CFFI_NUM_EXPORTS];
  409.  
  410. #define _cffi_type(index) ( \
  411. assert((((uintptr_t)_cffi_types[index]) & 1) == 0), \
  412. (struct _cffi_ctypedescr *)_cffi_types[index])
  413.  
  414. static PyObject *_cffi_init(const char *module_name, Py_ssize_t version,
  415. const struct _cffi_type_context_s *ctx)
  416. {
  417. PyObject *module, *o_arg, *new_module;
  418. void *raw[] = {
  419. (void *)module_name,
  420. (void *)version,
  421. (void *)_cffi_exports,
  422. (void *)ctx,
  423. };
  424.  
  425. module = PyImport_ImportModule("_cffi_backend");
  426. if (module == NULL)
  427. goto failure;
  428.  
  429. o_arg = PyLong_FromVoidPtr((void *)raw);
  430. if (o_arg == NULL)
  431. goto failure;
  432.  
  433. new_module = PyObject_CallMethod(
  434. module, (char *)"_init_cffi_1_0_external_module", (char *)"O", o_arg);
  435.  
  436. Py_DECREF(o_arg);
  437. Py_DECREF(module);
  438. return new_module;
  439.  
  440. failure:
  441. Py_XDECREF(module);
  442. return NULL;
  443. }
  444.  
  445.  
  446. #ifdef HAVE_WCHAR_H
  447. typedef wchar_t _cffi_wchar_t;
  448. #else
  449. typedef uint16_t _cffi_wchar_t; /* same random pick as _cffi_backend.c */
  450. #endif
  451.  
  452. _CFFI_UNUSED_FN static uint16_t _cffi_to_c_char16_t(PyObject *o)
  453. {
  454. if (sizeof(_cffi_wchar_t) == 2)
  455. return (uint16_t)_cffi_to_c_wchar_t(o);
  456. else
  457. return (uint16_t)_cffi_to_c_wchar3216_t(o);
  458. }
  459.  
  460. _CFFI_UNUSED_FN static PyObject *_cffi_from_c_char16_t(uint16_t x)
  461. {
  462. if (sizeof(_cffi_wchar_t) == 2)
  463. return _cffi_from_c_wchar_t((_cffi_wchar_t)x);
  464. else
  465. return _cffi_from_c_wchar3216_t((int)x);
  466. }
  467.  
  468. _CFFI_UNUSED_FN static int _cffi_to_c_char32_t(PyObject *o)
  469. {
  470. if (sizeof(_cffi_wchar_t) == 4)
  471. return (int)_cffi_to_c_wchar_t(o);
  472. else
  473. return (int)_cffi_to_c_wchar3216_t(o);
  474. }
  475.  
  476. _CFFI_UNUSED_FN static PyObject *_cffi_from_c_char32_t(unsigned int x)
  477. {
  478. if (sizeof(_cffi_wchar_t) == 4)
  479. return _cffi_from_c_wchar_t((_cffi_wchar_t)x);
  480. else
  481. return _cffi_from_c_wchar3216_t((int)x);
  482. }
  483.  
  484. union _cffi_union_alignment_u {
  485. unsigned char m_char;
  486. unsigned short m_short;
  487. unsigned int m_int;
  488. unsigned long m_long;
  489. unsigned long long m_longlong;
  490. float m_float;
  491. double m_double;
  492. long double m_longdouble;
  493. };
  494.  
  495. struct _cffi_freeme_s {
  496. struct _cffi_freeme_s *next;
  497. union _cffi_union_alignment_u alignment;
  498. };
  499.  
  500. _CFFI_UNUSED_FN static int
  501. _cffi_convert_array_argument(struct _cffi_ctypedescr *ctptr, PyObject *arg,
  502. char **output_data, Py_ssize_t datasize,
  503. struct _cffi_freeme_s **freeme)
  504. {
  505. char *p;
  506. if (datasize < 0)
  507. return -1;
  508.  
  509. p = *output_data;
  510. if (p == NULL) {
  511. struct _cffi_freeme_s *fp = (struct _cffi_freeme_s *)PyObject_Malloc(
  512. offsetof(struct _cffi_freeme_s, alignment) + (size_t)datasize);
  513. if (fp == NULL)
  514. return -1;
  515. fp->next = *freeme;
  516. *freeme = fp;
  517. p = *output_data = (char *)&fp->alignment;
  518. }
  519. memset((void *)p, 0, (size_t)datasize);
  520. return _cffi_convert_array_from_object(p, ctptr, arg);
  521. }
  522.  
  523. _CFFI_UNUSED_FN static void
  524. _cffi_free_array_arguments(struct _cffi_freeme_s *freeme)
  525. {
  526. do {
  527. void *p = (void *)freeme;
  528. freeme = freeme->next;
  529. PyObject_Free(p);
  530. } while (freeme != NULL);
  531. }
  532.  
  533. /********** end CPython-specific section **********/
  534. #else
  535. _CFFI_UNUSED_FN
  536. static void (*_cffi_call_python_org)(struct _cffi_externpy_s *, char *);
  537. # define _cffi_call_python _cffi_call_python_org
  538. #endif
  539.  
  540.  
  541. #define _cffi_array_len(array) (sizeof(array) / sizeof((array)[0]))
  542.  
  543. #define _cffi_prim_int(size, sign) \
  544. ((size) == 1 ? ((sign) ? _CFFI_PRIM_INT8 : _CFFI_PRIM_UINT8) : \
  545. (size) == 2 ? ((sign) ? _CFFI_PRIM_INT16 : _CFFI_PRIM_UINT16) : \
  546. (size) == 4 ? ((sign) ? _CFFI_PRIM_INT32 : _CFFI_PRIM_UINT32) : \
  547. (size) == 8 ? ((sign) ? _CFFI_PRIM_INT64 : _CFFI_PRIM_UINT64) : \
  548. _CFFI__UNKNOWN_PRIM)
  549.  
  550. #define _cffi_prim_float(size) \
  551. ((size) == sizeof(float) ? _CFFI_PRIM_FLOAT : \
  552. (size) == sizeof(double) ? _CFFI_PRIM_DOUBLE : \
  553. (size) == sizeof(long double) ? _CFFI__UNKNOWN_LONG_DOUBLE : \
  554. _CFFI__UNKNOWN_FLOAT_PRIM)
  555.  
  556. #define _cffi_check_int(got, got_nonpos, expected) \
  557. ((got_nonpos) == (expected <= 0) && \
  558. (got) == (unsigned long long)expected)
  559.  
  560. #ifdef MS_WIN32
  561. # define _cffi_stdcall __stdcall
  562. #else
  563. # define _cffi_stdcall /* nothing */
  564. #endif
  565.  
  566. #ifdef __cplusplus
  567. }
  568. #endif
  569.  
  570. /************************************************************/
  571.  
  572. #include "/Users/luckydonald/git/kpdemetriou:newhope-cffi/sources2/definitions.h"
  573.  
  574. /************************************************************/
  575.  
  576. static void *_cffi_types[] = {
  577. /* 0 */ _CFFI_OP(_CFFI_OP_FUNCTION, 6), // struct intensity_data()(char const *)
  578. /* 1 */ _CFFI_OP(_CFFI_OP_POINTER, 3), // char const *
  579. /* 2 */ _CFFI_OP(_CFFI_OP_FUNCTION_END, 0),
  580. /* 3 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 2), // char
  581. /* 4 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 14), // double
  582. /* 5 */ _CFFI_OP(_CFFI_OP_PRIMITIVE, 7), // int
  583. /* 6 */ _CFFI_OP(_CFFI_OP_STRUCT_UNION, 0), // struct intensity_data
  584. };
  585.  
  586. static struct intensity_data _cffi_d_jpeg_intensities(char const * x0)
  587. {
  588. return jpeg_intensities(x0);
  589. }
  590. #ifndef PYPY_VERSION
  591. static PyObject *
  592. _cffi_f_jpeg_intensities(PyObject *self, PyObject *arg0)
  593. {
  594. char const * x0;
  595. Py_ssize_t datasize;
  596. struct _cffi_freeme_s *large_args_free = NULL;
  597. struct intensity_data result;
  598. PyObject *pyresult;
  599.  
  600. datasize = _cffi_prepare_pointer_call_argument(
  601. _cffi_type(1), arg0, (char **)&x0);
  602. if (datasize != 0) {
  603. x0 = ((size_t)datasize) <= 640 ? (char const *)alloca((size_t)datasize) : NULL;
  604. if (_cffi_convert_array_argument(_cffi_type(1), arg0, (char **)&x0,
  605. datasize, &large_args_free) < 0)
  606. return NULL;
  607. }
  608.  
  609. Py_BEGIN_ALLOW_THREADS
  610. _cffi_restore_errno();
  611. { result = jpeg_intensities(x0); }
  612. _cffi_save_errno();
  613. Py_END_ALLOW_THREADS
  614.  
  615. (void)self; /* unused */
  616. pyresult = _cffi_from_c_struct((char *)&result, _cffi_type(6));
  617. if (large_args_free != NULL) _cffi_free_array_arguments(large_args_free);
  618. return pyresult;
  619. }
  620. #else
  621. static void _cffi_f_jpeg_intensities(struct intensity_data *result, char const * x0)
  622. {
  623. { *result = jpeg_intensities(x0); }
  624. }
  625. #endif
  626.  
  627. static struct intensity_data _cffi_d_png_intensities(char const * x0)
  628. {
  629. return png_intensities(x0);
  630. }
  631. #ifndef PYPY_VERSION
  632. static PyObject *
  633. _cffi_f_png_intensities(PyObject *self, PyObject *arg0)
  634. {
  635. char const * x0;
  636. Py_ssize_t datasize;
  637. struct _cffi_freeme_s *large_args_free = NULL;
  638. struct intensity_data result;
  639. PyObject *pyresult;
  640.  
  641. datasize = _cffi_prepare_pointer_call_argument(
  642. _cffi_type(1), arg0, (char **)&x0);
  643. if (datasize != 0) {
  644. x0 = ((size_t)datasize) <= 640 ? (char const *)alloca((size_t)datasize) : NULL;
  645. if (_cffi_convert_array_argument(_cffi_type(1), arg0, (char **)&x0,
  646. datasize, &large_args_free) < 0)
  647. return NULL;
  648. }
  649.  
  650. Py_BEGIN_ALLOW_THREADS
  651. _cffi_restore_errno();
  652. { result = png_intensities(x0); }
  653. _cffi_save_errno();
  654. Py_END_ALLOW_THREADS
  655.  
  656. (void)self; /* unused */
  657. pyresult = _cffi_from_c_struct((char *)&result, _cffi_type(6));
  658. if (large_args_free != NULL) _cffi_free_array_arguments(large_args_free);
  659. return pyresult;
  660. }
  661. #else
  662. static void _cffi_f_png_intensities(struct intensity_data *result, char const * x0)
  663. {
  664. { *result = png_intensities(x0); }
  665. }
  666. #endif
  667.  
  668. _CFFI_UNUSED_FN
  669. static void _cffi_checkfld_struct_intensity_data(struct intensity_data *p)
  670. {
  671. /* only to generate compile-time warnings or errors */
  672. (void)p;
  673. { double *tmp = &p->nw; (void)tmp; }
  674. { double *tmp = &p->ne; (void)tmp; }
  675. { double *tmp = &p->sw; (void)tmp; }
  676. { double *tmp = &p->se; (void)tmp; }
  677. (void)((p->error) | 0); /* check that 'struct intensity_data.error' is an integer */
  678. }
  679. struct _cffi_align_struct_intensity_data { char x; struct intensity_data y; };
  680.  
  681. static struct intensity_data *_cffi_var_intensity_data(void)
  682. {
  683. return &(intensity_data); # ERROR HERE
  684. }
  685.  
  686. static const struct _cffi_global_s _cffi_globals[] = {
  687. { "intensity_data", (void *)_cffi_var_intensity_data, _CFFI_OP(_CFFI_OP_GLOBAL_VAR_F, 6), (void *)0 },
  688. { "jpeg_intensities", (void *)_cffi_f_jpeg_intensities, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_O, 0), (void *)_cffi_d_jpeg_intensities },
  689. { "png_intensities", (void *)_cffi_f_png_intensities, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_O, 0), (void *)_cffi_d_png_intensities },
  690. };
  691.  
  692. static const struct _cffi_field_s _cffi_fields[] = {
  693. { "nw", offsetof(struct intensity_data, nw),
  694. sizeof(((struct intensity_data *)0)->nw),
  695. _CFFI_OP(_CFFI_OP_NOOP, 4) },
  696. { "ne", offsetof(struct intensity_data, ne),
  697. sizeof(((struct intensity_data *)0)->ne),
  698. _CFFI_OP(_CFFI_OP_NOOP, 4) },
  699. { "sw", offsetof(struct intensity_data, sw),
  700. sizeof(((struct intensity_data *)0)->sw),
  701. _CFFI_OP(_CFFI_OP_NOOP, 4) },
  702. { "se", offsetof(struct intensity_data, se),
  703. sizeof(((struct intensity_data *)0)->se),
  704. _CFFI_OP(_CFFI_OP_NOOP, 4) },
  705. { "error", offsetof(struct intensity_data, error),
  706. sizeof(((struct intensity_data *)0)->error),
  707. _CFFI_OP(_CFFI_OP_NOOP, 5) },
  708. };
  709.  
  710. static const struct _cffi_struct_union_s _cffi_struct_unions[] = {
  711. { "intensity_data", 6, _CFFI_F_CHECK_FIELDS,
  712. sizeof(struct intensity_data), offsetof(struct _cffi_align_struct_intensity_data, y), 0, 5 },
  713. };
  714.  
  715. static const struct _cffi_type_context_s _cffi_type_context = {
  716. _cffi_types,
  717. _cffi_globals,
  718. _cffi_fields,
  719. _cffi_struct_unions,
  720. NULL, /* no enums */
  721. NULL, /* no typenames */
  722. 3, /* num_globals */
  723. 1, /* num_struct_unions */
  724. 0, /* num_enums */
  725. 0, /* num_typenames */
  726. NULL, /* no includes */
  727. 7, /* num_types */
  728. 0, /* flags */
  729. };
  730.  
  731. #ifdef __GNUC__
  732. # pragma GCC visibility push(default) /* for -fvisibility= */
  733. #endif
  734.  
  735. #ifdef PYPY_VERSION
  736. PyMODINIT_FUNC
  737. _cffi_pypyinit__intensities(const void *p[])
  738. {
  739. p[0] = (const void *)0x2601;
  740. p[1] = &_cffi_type_context;
  741. #if PY_MAJOR_VERSION >= 3
  742. return NULL;
  743. #endif
  744. }
  745. # ifdef _MSC_VER
  746. PyMODINIT_FUNC
  747. # if PY_MAJOR_VERSION >= 3
  748. PyInit__intensities(void) { return NULL; }
  749. # else
  750. init_intensities(void) { }
  751. # endif
  752. # endif
  753. #elif PY_MAJOR_VERSION >= 3
  754. PyMODINIT_FUNC
  755. PyInit__intensities(void)
  756. {
  757. return _cffi_init("images_intensities._intensities", 0x2601, &_cffi_type_context);
  758. }
  759. #else
  760. PyMODINIT_FUNC
  761. init_intensities(void)
  762. {
  763. _cffi_init("images_intensities._intensities", 0x2601, &_cffi_type_context);
  764. }
  765. #endif
  766.  
  767. #ifdef __GNUC__
  768. # pragma GCC visibility pop
  769. #endif
  770.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement