• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "_cffi_include.h"
2 
3 
4 #define AA  (42)
5 #define BB  (&bb)
6 static int bb = 16261;
7 
foo42(int a,int * b)8 int foo42(int a, int *b)
9 {
10     return a - *b;
11 }
12 
foo64(int a)13 int foo64(int a)
14 {
15     return ~a;
16 }
17 
18 struct foo_s {
19     int a;
20 };
21 
22 /************************************************************/
23 
24 static void *_cffi_types[] = {
25     _CFFI_OP(_CFFI_OP_FUNCTION, 1),
26     _CFFI_OP(_CFFI_OP_PRIMITIVE, _CFFI_PRIM_INT),
27     _CFFI_OP(_CFFI_OP_POINTER, 1),
28     _CFFI_OP(_CFFI_OP_FUNCTION_END, 0),
29     _CFFI_OP(_CFFI_OP_FUNCTION, 1),
30     _CFFI_OP(_CFFI_OP_PRIMITIVE, _CFFI_PRIM_INT),
31     _CFFI_OP(_CFFI_OP_FUNCTION_END, 0),
32     _CFFI_OP(_CFFI_OP_STRUCT_UNION, 0),
33 };
34 
35 #ifndef PYPY_VERSION
36 static PyObject *
_cffi_f_foo42(PyObject * self,PyObject * args)37 _cffi_f_foo42(PyObject *self, PyObject *args)
38 {
39   int x0;
40   int * x1;
41   Py_ssize_t datasize;
42   int result;
43   PyObject *arg0;
44   PyObject *arg1;
45 
46   if (!PyArg_ParseTuple(args, "OO:foo42", &arg0, &arg1))
47     return NULL;
48 
49   x0 = _cffi_to_c_int(arg0, int);
50   if (x0 == (int)-1 && PyErr_Occurred())
51     return NULL;
52 
53   datasize = _cffi_prepare_pointer_call_argument(
54       _cffi_types[1], arg1, (char **)&x1);
55   if (datasize != 0) {
56     if (datasize < 0)
57       return NULL;
58     x1 = alloca(datasize);
59     memset((void *)x1, 0, datasize);
60     if (_cffi_convert_array_from_object((char *)x1, _cffi_types[1], arg1) < 0)
61       return NULL;
62   }
63 
64   Py_BEGIN_ALLOW_THREADS
65   _cffi_restore_errno();
66   { result = foo42(x0, x1); }
67   _cffi_save_errno();
68   Py_END_ALLOW_THREADS
69 
70   return _cffi_from_c_int(result, int);
71 }
72 #else
_cffi_f_foo42(int x0,int * x1)73 static int _cffi_f_foo42(int x0, int *x1)
74 {
75   return foo42(x0, x1);
76 }
77 #endif
78 
79 #ifndef PYPY_VERSION
80 static PyObject *
_cffi_f_foo64(PyObject * self,PyObject * arg0)81 _cffi_f_foo64(PyObject *self, PyObject *arg0)
82 {
83   int x0;
84   int result;
85 
86   x0 = _cffi_to_c_int(arg0, int);
87   if (x0 == (int)-1 && PyErr_Occurred())
88     return NULL;
89 
90   Py_BEGIN_ALLOW_THREADS
91   _cffi_restore_errno();
92   { result = foo64(x0); }
93   _cffi_save_errno();
94   Py_END_ALLOW_THREADS
95 
96   return _cffi_from_c_int(result, int);
97 }
98 #else
_cffi_f_foo64(int x0)99 static int _cffi_f_foo64(int x0)
100 {
101   return foo64(x0);
102 }
103 #endif
104 
_cffi_const_AA(unsigned long long * output)105 static int _cffi_const_AA(unsigned long long *output)
106 {
107     *output = (unsigned long long)((AA) << 0);   // integer
108     return (AA) <= 0;
109 }
110 
_cffi_const_BB(char * output)111 static void _cffi_const_BB(char *output)
112 {
113     *(int **)output = BB;
114 }
115 
116 static const struct _cffi_global_s _cffi_globals[] = {
117     { "AA",    &_cffi_const_AA, _CFFI_OP(_CFFI_OP_CONSTANT_INT, 0) },
118     { "BB",    &_cffi_const_BB, _CFFI_OP(_CFFI_OP_CONSTANT, 2) },
119     { "bb",    &bb, _CFFI_OP(_CFFI_OP_GLOBAL_VAR, 1) },
120     { "foo42", &_cffi_f_foo42, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_V, 0) },
121     { "foo64", &_cffi_f_foo64, _CFFI_OP(_CFFI_OP_CPYTHON_BLTN_O, 4) },
122 };
123 
124 struct _cffi_align_foo_s { char x; struct foo_s y; };
125 
126 static const struct _cffi_struct_union_s _cffi_struct_unions[] = {
127     { "foo_s", 7, 0,
128       sizeof(struct foo_s),
129       offsetof(struct _cffi_align_foo_s, y),
130       1, 0 },
131 };
132 
133 static const struct _cffi_field_s _cffi_fields[] = {
134     { "a", offsetof(struct foo_s, a), sizeof(((struct foo_s *)0)->a),
135       _CFFI_OP(_CFFI_OP_NOOP, 1) },
136 };
137 
138 static const struct _cffi_type_context_s _cffi_type_context = {
139     _cffi_types,
140     _cffi_globals,
141     _cffi_fields,
142     _cffi_struct_unions,
143     NULL,
144     NULL,
145     5,  /* num_globals */
146     1,  /* num_struct_unions */
147     0,
148     0,
149     NULL,
150     8,  /* num_types */
151 };
152 
153 #ifndef PYPY_VERSION
154 PyMODINIT_FUNC
initmanual(void)155 initmanual(void)
156 {
157     _cffi_init("manual", 0x2601, &_cffi_type_context);
158 }
159 #else
160 PyMODINIT_FUNC
_cffi_pypyinit_manual(const void * p[])161 _cffi_pypyinit_manual(const void *p[])
162 {
163     p[0] = (const void *)0x2601;
164     p[1] = &_cffi_type_context;
165 }
166 #endif
167