| 1 |
#ifndef Py_CORE_CROSSINTERP_DATA_REGISTRY_H |
| 2 |
# error "this header must not be included directly" |
| 3 |
#endif |
| 4 |
|
| 5 |
|
| 6 |
// For now we use a global registry of shareable classes. An |
| 7 |
// alternative would be to add a tp_* slot for a class's |
| 8 |
// xidatafunc. It would be simpler and more efficient. |
| 9 |
|
| 10 |
struct _xid_regitem; |
| 11 |
|
| 12 |
typedef struct _xid_regitem { |
| 13 |
struct _xid_regitem *prev; |
| 14 |
struct _xid_regitem *next; |
| 15 |
/* This can be a dangling pointer, but only if weakref is set. */ |
| 16 |
PyTypeObject *cls; |
| 17 |
/* This is NULL for builtin types. */ |
| 18 |
PyObject *weakref; |
| 19 |
size_t refcount; |
| 20 |
_PyXIData_getdata_t getdata; |
| 21 |
} _PyXIData_regitem_t; |
| 22 |
|
| 23 |
typedef struct { |
| 24 |
int global; /* builtin types or heap types */ |
| 25 |
int initialized; |
| 26 |
PyMutex mutex; |
| 27 |
_PyXIData_regitem_t *head; |
| 28 |
} _PyXIData_registry_t; |
| 29 |
|
| 30 |
PyAPI_FUNC(int) _PyXIData_RegisterClass( |
| 31 |
PyThreadState *, |
| 32 |
PyTypeObject *, |
| 33 |
_PyXIData_getdata_t); |
| 34 |
PyAPI_FUNC(int) _PyXIData_UnregisterClass( |
| 35 |
PyThreadState *, |
| 36 |
PyTypeObject *); |
| 37 |
|
| 38 |
struct _xid_lookup_state { |
| 39 |
// XXX Remove this field once we have a tp_* slot. |
| 40 |
_PyXIData_registry_t registry; |
| 41 |
}; |