Debian Codegraph @

doc/misc/parse_c_type.rst

raw
1 ==================================================
2 CPython C extension module produced by recompile()
3 ==================================================
4
5 Global variable::
6
7 _cffi_opcode_t _cffi_types[];
8
9 Every ``_cffi_types`` entry is initially an odd integer. At runtime, it
10 is fixed to be a ``CTypeDescrObject *`` when the odd integer is
11 interpreted and turned into a real ``<ctype>`` object.
12
13 The generated C functions are listed in ``_cffi_globals``, a sorted array
14 of entries which get turned lazily into real ``<builtin function
15 objects>``. Each entry in this array has an index in the ``_cffi_types``
16 array, which describe the function type (``OP_FUNCTION`` opcode, see
17 below). We turn the odd integers describing argument and return types
18 into real CTypeDescrObjects at the point where the entry is turned
19 into a real builtin function object.
20
21 The odd integers are "opcodes" that contain a type info in the lowest
22 byte. The remaining high bytes of the integer is an "arg" that depends
23 on the type info:
24
25 OP_PRIMITIVE
26 the arg tells which primitive type it is (an index in some list)
27
28 OP_POINTER
29 the arg is the index of the item type in the ``_cffi_types`` array.
30
31 OP_ARRAY
32 the arg is the index of the item type in the ``_cffi_types`` array.
33 followed by another opcode that contains (uintptr_t)length_of_array.
34
35 OP_OPEN_ARRAY
36 for syntax like "int[]". same as OP_ARRAY but without the length
37
38 OP_STRUCT_UNION
39 the arg is the index of the struct/union in ``_cffi_structs_unions``
40
41 OP_ENUM
42 the arg is the index of the enum in ``_cffi_enums``
43
44 OP_TYPENAME
45 the arg is the index of the typename in ``_cffi_typenames``
46
47 OP_FUNCTION
48 the arg is the index of the result type in ``_cffi_types``.
49 followed by other opcodes for the arguments.
50 terminated by ``OP_FUNCTION_END``.
51
52 OP_FUNCTION_END
53 the arg's lowest bit is set if there is a "..." argument.
54
55 OP_NOOP
56 simple indirection: the arg is the index to look further in
57
58 There are other opcodes, used not inside ``_cffi_types`` but in other
59 individual ``type_op`` fields. Most importantly, these are used
60 on ``_cffi_globals`` entries:
61
62 OP_CPYTHON_BLTN_*
63 declare a function
64
65 OP_CONSTANT
66 declare a non-integral constant
67
68 OP_CONSTANT_INT
69 declare an int constant
70
71 OP_GLOBAL_VAR
72 declare a global var