| 1 |
/* This files contains various key structs that are widely used |
| 2 |
* and do not depend on other headers. */ |
| 3 |
|
| 4 |
#ifndef Py_INTERNAL_STRUCTS_H |
| 5 |
#define Py_INTERNAL_STRUCTS_H |
| 6 |
#ifdef __cplusplus |
| 7 |
extern "C" { |
| 8 |
#endif |
| 9 |
|
| 10 |
#include <stdint.h> // uint16_t |
| 11 |
|
| 12 |
|
| 13 |
typedef struct { |
| 14 |
uint16_t value_and_backoff; |
| 15 |
} _Py_BackoffCounter; |
| 16 |
|
| 17 |
/* Each instruction in a code object is a fixed-width value, |
| 18 |
* currently 2 bytes: 1-byte opcode + 1-byte oparg. The EXTENDED_ARG |
| 19 |
* opcode allows for larger values but the current limit is 3 uses |
| 20 |
* of EXTENDED_ARG (see Python/compile.c), for a maximum |
| 21 |
* 32-bit value. This aligns with the note in Python/compile.c |
| 22 |
* (compiler_addop_i_line) indicating that the max oparg value is |
| 23 |
* 2**32 - 1, rather than INT_MAX. |
| 24 |
*/ |
| 25 |
typedef union { |
| 26 |
uint16_t cache; |
| 27 |
struct { |
| 28 |
uint8_t code; |
| 29 |
uint8_t arg; |
| 30 |
} op; |
| 31 |
_Py_BackoffCounter counter; // First cache entry of specializable op |
| 32 |
} _Py_CODEUNIT; |
| 33 |
|
| 34 |
|
| 35 |
/* Abstract tree node. */ |
| 36 |
typedef struct { |
| 37 |
PyObject_HEAD |
| 38 |
} PyHamtNode; |
| 39 |
|
| 40 |
|
| 41 |
/* An HAMT immutable mapping collection. */ |
| 42 |
typedef struct { |
| 43 |
PyObject_HEAD |
| 44 |
PyHamtNode *h_root; |
| 45 |
PyObject *h_weakreflist; |
| 46 |
Py_ssize_t h_count; |
| 47 |
} PyHamtObject; |
| 48 |
|
| 49 |
typedef struct { |
| 50 |
PyObject_VAR_HEAD |
| 51 |
uint32_t b_bitmap; |
| 52 |
PyObject *b_array[1]; |
| 53 |
} PyHamtNode_Bitmap; |
| 54 |
|
| 55 |
#include "pycore_context.h" // _PyContextTokenMissing |
| 56 |
|
| 57 |
// Define this to get precise tracking of stackrefs. |
| 58 |
// #define Py_STACKREF_DEBUG 1 |
| 59 |
|
| 60 |
// Define this to get precise tracking of closed stackrefs. |
| 61 |
// This will use unbounded memory, as it can only grow. |
| 62 |
// Use this to track double closes in short-lived programs |
| 63 |
// #define Py_STACKREF_CLOSE_DEBUG 1 |
| 64 |
|
| 65 |
|
| 66 |
typedef union _PyStackRef { |
| 67 |
#if !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG) |
| 68 |
uint64_t index; |
| 69 |
#else |
| 70 |
uintptr_t bits; |
| 71 |
#endif |
| 72 |
} _PyStackRef; |
| 73 |
|
| 74 |
// A stackref that can be stored in a regular C local variable and be visible |
| 75 |
// to the GC in the free threading build. |
| 76 |
// Used in combination with _PyThreadState_PushCStackRef(). |
| 77 |
typedef struct _PyCStackRef { |
| 78 |
_PyStackRef ref; |
| 79 |
#ifdef Py_GIL_DISABLED |
| 80 |
struct _PyCStackRef *next; |
| 81 |
#endif |
| 82 |
} _PyCStackRef; |
| 83 |
|
| 84 |
|
| 85 |
#ifdef __cplusplus |
| 86 |
} |
| 87 |
#endif |
| 88 |
#endif /* Py_INTERNAL_STRUCTS_H */ |