• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /* This part is from file 'cffi/parse_c_type.h'.  It is copied at the
3    beginning of C sources generated by CFFI's ffi.set_source(). */
4 
5 typedef void *_cffi_opcode_t;
6 
7 #define _CFFI_OP(opcode, arg)   (_cffi_opcode_t)(opcode | (((uintptr_t)(arg)) << 8))
8 #define _CFFI_GETOP(cffi_opcode)    ((unsigned char)(uintptr_t)cffi_opcode)
9 #define _CFFI_GETARG(cffi_opcode)   (((intptr_t)cffi_opcode) >> 8)
10 
11 #define _CFFI_OP_PRIMITIVE       1
12 #define _CFFI_OP_POINTER         3
13 #define _CFFI_OP_ARRAY           5
14 #define _CFFI_OP_OPEN_ARRAY      7
15 #define _CFFI_OP_STRUCT_UNION    9
16 #define _CFFI_OP_ENUM           11
17 #define _CFFI_OP_FUNCTION       13
18 #define _CFFI_OP_FUNCTION_END   15
19 #define _CFFI_OP_NOOP           17
20 #define _CFFI_OP_BITFIELD       19
21 #define _CFFI_OP_TYPENAME       21
22 #define _CFFI_OP_CPYTHON_BLTN_V 23   // varargs
23 #define _CFFI_OP_CPYTHON_BLTN_N 25   // noargs
24 #define _CFFI_OP_CPYTHON_BLTN_O 27   // O  (i.e. a single arg)
25 #define _CFFI_OP_CONSTANT       29
26 #define _CFFI_OP_CONSTANT_INT   31
27 #define _CFFI_OP_GLOBAL_VAR     33
28 #define _CFFI_OP_DLOPEN_FUNC    35
29 #define _CFFI_OP_DLOPEN_CONST   37
30 #define _CFFI_OP_GLOBAL_VAR_F   39
31 #define _CFFI_OP_EXTERN_PYTHON  41
32 
33 #define _CFFI_PRIM_VOID          0
34 #define _CFFI_PRIM_BOOL          1
35 #define _CFFI_PRIM_CHAR          2
36 #define _CFFI_PRIM_SCHAR         3
37 #define _CFFI_PRIM_UCHAR         4
38 #define _CFFI_PRIM_SHORT         5
39 #define _CFFI_PRIM_USHORT        6
40 #define _CFFI_PRIM_INT           7
41 #define _CFFI_PRIM_UINT          8
42 #define _CFFI_PRIM_LONG          9
43 #define _CFFI_PRIM_ULONG        10
44 #define _CFFI_PRIM_LONGLONG     11
45 #define _CFFI_PRIM_ULONGLONG    12
46 #define _CFFI_PRIM_FLOAT        13
47 #define _CFFI_PRIM_DOUBLE       14
48 #define _CFFI_PRIM_LONGDOUBLE   15
49 
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_PRIM_FLOATCOMPLEX 48
83 #define _CFFI_PRIM_DOUBLECOMPLEX 49
84 #define _CFFI_PRIM_CHAR16       50
85 #define _CFFI_PRIM_CHAR32       51
86 
87 #define _CFFI__NUM_PRIM         52
88 #define _CFFI__UNKNOWN_PRIM           (-1)
89 #define _CFFI__UNKNOWN_FLOAT_PRIM     (-2)
90 #define _CFFI__UNKNOWN_LONG_DOUBLE    (-3)
91 
92 #define _CFFI__IO_FILE_STRUCT         (-1)
93 
94 
95 struct _cffi_global_s {
96     const char *name;
97     void *address;
98     _cffi_opcode_t type_op;
99     void *size_or_direct_fn;  // OP_GLOBAL_VAR: size, or 0 if unknown
100                               // OP_CPYTHON_BLTN_*: addr of direct function
101 };
102 
103 struct _cffi_getconst_s {
104     unsigned long long value;
105     const struct _cffi_type_context_s *ctx;
106     int gindex;
107 };
108 
109 struct _cffi_struct_union_s {
110     const char *name;
111     int type_index;          // -> _cffi_types, on a OP_STRUCT_UNION
112     int flags;               // _CFFI_F_* flags below
113     size_t size;
114     int alignment;
115     int first_field_index;   // -> _cffi_fields array
116     int num_fields;
117 };
118 #define _CFFI_F_UNION         0x01   // is a union, not a struct
119 #define _CFFI_F_CHECK_FIELDS  0x02   // complain if fields are not in the
120                                      // "standard layout" or if some are missing
121 #define _CFFI_F_PACKED        0x04   // for CHECK_FIELDS, assume a packed struct
122 #define _CFFI_F_EXTERNAL      0x08   // in some other ffi.include()
123 #define _CFFI_F_OPAQUE        0x10   // opaque
124 
125 struct _cffi_field_s {
126     const char *name;
127     size_t field_offset;
128     size_t field_size;
129     _cffi_opcode_t field_type_op;
130 };
131 
132 struct _cffi_enum_s {
133     const char *name;
134     int type_index;          // -> _cffi_types, on a OP_ENUM
135     int type_prim;           // _CFFI_PRIM_xxx
136     const char *enumerators; // comma-delimited string
137 };
138 
139 struct _cffi_typename_s {
140     const char *name;
141     int type_index;   /* if opaque, points to a possibly artificial
142                          OP_STRUCT which is itself opaque */
143 };
144 
145 struct _cffi_type_context_s {
146     _cffi_opcode_t *types;
147     const struct _cffi_global_s *globals;
148     const struct _cffi_field_s *fields;
149     const struct _cffi_struct_union_s *struct_unions;
150     const struct _cffi_enum_s *enums;
151     const struct _cffi_typename_s *typenames;
152     int num_globals;
153     int num_struct_unions;
154     int num_enums;
155     int num_typenames;
156     const char *const *includes;
157     int num_types;
158     int flags;      /* future extension */
159 };
160 
161 struct _cffi_parse_info_s {
162     const struct _cffi_type_context_s *ctx;
163     _cffi_opcode_t *output;
164     unsigned int output_size;
165     size_t error_location;
166     const char *error_message;
167 };
168 
169 struct _cffi_externpy_s {
170     const char *name;
171     size_t size_of_result;
172     void *reserved1, *reserved2;
173 };
174 
175 #ifdef _CFFI_INTERNAL
176 static int parse_c_type(struct _cffi_parse_info_s *info, const char *input);
177 static int search_in_globals(const struct _cffi_type_context_s *ctx,
178                              const char *search, size_t search_len);
179 static int search_in_struct_unions(const struct _cffi_type_context_s *ctx,
180                                    const char *search, size_t search_len);
181 #endif
182