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.

parse_c_type.h 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* This part is from file 'cffi/parse_c_type.h'. It is copied at the
  2. beginning of C sources generated by CFFI's ffi.set_source(). */
  3. typedef void *_cffi_opcode_t;
  4. #define _CFFI_OP(opcode, arg) (_cffi_opcode_t)(opcode | (((uintptr_t)(arg)) << 8))
  5. #define _CFFI_GETOP(cffi_opcode) ((unsigned char)(uintptr_t)cffi_opcode)
  6. #define _CFFI_GETARG(cffi_opcode) (((intptr_t)cffi_opcode) >> 8)
  7. #define _CFFI_OP_PRIMITIVE 1
  8. #define _CFFI_OP_POINTER 3
  9. #define _CFFI_OP_ARRAY 5
  10. #define _CFFI_OP_OPEN_ARRAY 7
  11. #define _CFFI_OP_STRUCT_UNION 9
  12. #define _CFFI_OP_ENUM 11
  13. #define _CFFI_OP_FUNCTION 13
  14. #define _CFFI_OP_FUNCTION_END 15
  15. #define _CFFI_OP_NOOP 17
  16. #define _CFFI_OP_BITFIELD 19
  17. #define _CFFI_OP_TYPENAME 21
  18. #define _CFFI_OP_CPYTHON_BLTN_V 23 // varargs
  19. #define _CFFI_OP_CPYTHON_BLTN_N 25 // noargs
  20. #define _CFFI_OP_CPYTHON_BLTN_O 27 // O (i.e. a single arg)
  21. #define _CFFI_OP_CONSTANT 29
  22. #define _CFFI_OP_CONSTANT_INT 31
  23. #define _CFFI_OP_GLOBAL_VAR 33
  24. #define _CFFI_OP_DLOPEN_FUNC 35
  25. #define _CFFI_OP_DLOPEN_CONST 37
  26. #define _CFFI_OP_GLOBAL_VAR_F 39
  27. #define _CFFI_OP_EXTERN_PYTHON 41
  28. #define _CFFI_PRIM_VOID 0
  29. #define _CFFI_PRIM_BOOL 1
  30. #define _CFFI_PRIM_CHAR 2
  31. #define _CFFI_PRIM_SCHAR 3
  32. #define _CFFI_PRIM_UCHAR 4
  33. #define _CFFI_PRIM_SHORT 5
  34. #define _CFFI_PRIM_USHORT 6
  35. #define _CFFI_PRIM_INT 7
  36. #define _CFFI_PRIM_UINT 8
  37. #define _CFFI_PRIM_LONG 9
  38. #define _CFFI_PRIM_ULONG 10
  39. #define _CFFI_PRIM_LONGLONG 11
  40. #define _CFFI_PRIM_ULONGLONG 12
  41. #define _CFFI_PRIM_FLOAT 13
  42. #define _CFFI_PRIM_DOUBLE 14
  43. #define _CFFI_PRIM_LONGDOUBLE 15
  44. #define _CFFI_PRIM_WCHAR 16
  45. #define _CFFI_PRIM_INT8 17
  46. #define _CFFI_PRIM_UINT8 18
  47. #define _CFFI_PRIM_INT16 19
  48. #define _CFFI_PRIM_UINT16 20
  49. #define _CFFI_PRIM_INT32 21
  50. #define _CFFI_PRIM_UINT32 22
  51. #define _CFFI_PRIM_INT64 23
  52. #define _CFFI_PRIM_UINT64 24
  53. #define _CFFI_PRIM_INTPTR 25
  54. #define _CFFI_PRIM_UINTPTR 26
  55. #define _CFFI_PRIM_PTRDIFF 27
  56. #define _CFFI_PRIM_SIZE 28
  57. #define _CFFI_PRIM_SSIZE 29
  58. #define _CFFI_PRIM_INT_LEAST8 30
  59. #define _CFFI_PRIM_UINT_LEAST8 31
  60. #define _CFFI_PRIM_INT_LEAST16 32
  61. #define _CFFI_PRIM_UINT_LEAST16 33
  62. #define _CFFI_PRIM_INT_LEAST32 34
  63. #define _CFFI_PRIM_UINT_LEAST32 35
  64. #define _CFFI_PRIM_INT_LEAST64 36
  65. #define _CFFI_PRIM_UINT_LEAST64 37
  66. #define _CFFI_PRIM_INT_FAST8 38
  67. #define _CFFI_PRIM_UINT_FAST8 39
  68. #define _CFFI_PRIM_INT_FAST16 40
  69. #define _CFFI_PRIM_UINT_FAST16 41
  70. #define _CFFI_PRIM_INT_FAST32 42
  71. #define _CFFI_PRIM_UINT_FAST32 43
  72. #define _CFFI_PRIM_INT_FAST64 44
  73. #define _CFFI_PRIM_UINT_FAST64 45
  74. #define _CFFI_PRIM_INTMAX 46
  75. #define _CFFI_PRIM_UINTMAX 47
  76. #define _CFFI_PRIM_FLOATCOMPLEX 48
  77. #define _CFFI_PRIM_DOUBLECOMPLEX 49
  78. #define _CFFI_PRIM_CHAR16 50
  79. #define _CFFI_PRIM_CHAR32 51
  80. #define _CFFI__NUM_PRIM 52
  81. #define _CFFI__UNKNOWN_PRIM (-1)
  82. #define _CFFI__UNKNOWN_FLOAT_PRIM (-2)
  83. #define _CFFI__UNKNOWN_LONG_DOUBLE (-3)
  84. #define _CFFI__IO_FILE_STRUCT (-1)
  85. struct _cffi_global_s {
  86. const char *name;
  87. void *address;
  88. _cffi_opcode_t type_op;
  89. void *size_or_direct_fn; // OP_GLOBAL_VAR: size, or 0 if unknown
  90. // OP_CPYTHON_BLTN_*: addr of direct function
  91. };
  92. struct _cffi_getconst_s {
  93. unsigned long long value;
  94. const struct _cffi_type_context_s *ctx;
  95. int gindex;
  96. };
  97. struct _cffi_struct_union_s {
  98. const char *name;
  99. int type_index; // -> _cffi_types, on a OP_STRUCT_UNION
  100. int flags; // _CFFI_F_* flags below
  101. size_t size;
  102. int alignment;
  103. int first_field_index; // -> _cffi_fields array
  104. int num_fields;
  105. };
  106. #define _CFFI_F_UNION 0x01 // is a union, not a struct
  107. #define _CFFI_F_CHECK_FIELDS 0x02 // complain if fields are not in the
  108. // "standard layout" or if some are missing
  109. #define _CFFI_F_PACKED 0x04 // for CHECK_FIELDS, assume a packed struct
  110. #define _CFFI_F_EXTERNAL 0x08 // in some other ffi.include()
  111. #define _CFFI_F_OPAQUE 0x10 // opaque
  112. struct _cffi_field_s {
  113. const char *name;
  114. size_t field_offset;
  115. size_t field_size;
  116. _cffi_opcode_t field_type_op;
  117. };
  118. struct _cffi_enum_s {
  119. const char *name;
  120. int type_index; // -> _cffi_types, on a OP_ENUM
  121. int type_prim; // _CFFI_PRIM_xxx
  122. const char *enumerators; // comma-delimited string
  123. };
  124. struct _cffi_typename_s {
  125. const char *name;
  126. int type_index; /* if opaque, points to a possibly artificial
  127. OP_STRUCT which is itself opaque */
  128. };
  129. struct _cffi_type_context_s {
  130. _cffi_opcode_t *types;
  131. const struct _cffi_global_s *globals;
  132. const struct _cffi_field_s *fields;
  133. const struct _cffi_struct_union_s *struct_unions;
  134. const struct _cffi_enum_s *enums;
  135. const struct _cffi_typename_s *typenames;
  136. int num_globals;
  137. int num_struct_unions;
  138. int num_enums;
  139. int num_typenames;
  140. const char *const *includes;
  141. int num_types;
  142. int flags; /* future extension */
  143. };
  144. struct _cffi_parse_info_s {
  145. const struct _cffi_type_context_s *ctx;
  146. _cffi_opcode_t *output;
  147. unsigned int output_size;
  148. size_t error_location;
  149. const char *error_message;
  150. };
  151. struct _cffi_externpy_s {
  152. const char *name;
  153. size_t size_of_result;
  154. void *reserved1, *reserved2;
  155. };
  156. #ifdef _CFFI_INTERNAL
  157. static int parse_c_type(struct _cffi_parse_info_s *info, const char *input);
  158. static int search_in_globals(const struct _cffi_type_context_s *ctx,
  159. const char *search, size_t search_len);
  160. static int search_in_struct_unions(const struct _cffi_type_context_s *ctx,
  161. const char *search, size_t search_len);
  162. #endif