| 1 | #ifndef Ny_HEAPDEF_H |
|---|
| 2 | #define Ny_HEAPDEF_H |
|---|
| 3 | |
|---|
| 4 | /* NyHeapTraverse - argument to traverse |
|---|
| 5 | Defined to avoid complicated function defs |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | typedef struct { |
|---|
| 9 | int flags; |
|---|
| 10 | PyObject *hv; /* A HeapView object providing context to the traversal |
|---|
| 11 | function, if necessary. It is defined as a PyObject |
|---|
| 12 | rather than HeapView to avoid include file dependency. */ |
|---|
| 13 | PyObject *obj; /* The object that is to be traversed */ |
|---|
| 14 | void *arg; /* the argument to pass when visiting referred objects. */ |
|---|
| 15 | visitproc visit; /* The visit procedure to call */ |
|---|
| 16 | PyObject *_hiding_tag_; /* The hiding tag in use by current context. */ |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | } NyHeapTraverse; |
|---|
| 20 | |
|---|
| 21 | /* NyHeapRelate - argument to relate |
|---|
| 22 | Defined to avoid complicated function defs |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | typedef struct NyHeapRelate { |
|---|
| 26 | int flags; /* As yet unused */ |
|---|
| 27 | PyObject *hv; /* Heap view object */ |
|---|
| 28 | PyObject *src; /* Source of relation, and which is dispatched on */ |
|---|
| 29 | PyObject *tgt; /* Target of relation */ |
|---|
| 30 | |
|---|
| 31 | /* visit() should be called once for each unique pointer |
|---|
| 32 | from src to tgt. |
|---|
| 33 | The relation type is indicated by the relatype argument |
|---|
| 34 | and defined in the NYHR_ definitions below. |
|---|
| 35 | The relator argument is an object describing the relation |
|---|
| 36 | and should be newly allocated or INCREFED. |
|---|
| 37 | The arg argument should be the arg passed in NyHeapRelate |
|---|
| 38 | below. |
|---|
| 39 | |
|---|
| 40 | Return value: non-zero, means the relate function should |
|---|
| 41 | not provide any more relations but should return. A zero |
|---|
| 42 | return value means visit may be called again. |
|---|
| 43 | */ |
|---|
| 44 | |
|---|
| 45 | int (*visit)(unsigned int relatype, PyObject *relator, struct NyHeapRelate *arg); |
|---|
| 46 | } NyHeapRelate; |
|---|
| 47 | |
|---|
| 48 | /* Values for 'relatype' argument to be passed to visit callback in NyHeapRelate */ |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | #define NYHR_ATTRIBUTE 1 /* src.relator is tgt */ |
|---|
| 52 | #define NYHR_INDEXVAL 2 /* src[relator] is tgt */ |
|---|
| 53 | #define NYHR_INDEXKEY 3 /* src has key tgt */ |
|---|
| 54 | #define NYHR_INTERATTR 4 /* src->relator == tgt in C only */ |
|---|
| 55 | #define NYHR_HASATTR 5 /* src has attribute tgt (stored as string) */ |
|---|
| 56 | #define NYHR_LOCAL_VAR 6 /* src (a frame) has local variable named <relator> with value tgt */ |
|---|
| 57 | #define NYHR_CELL 7 /* src has cell variable named <relator> containing value tgt */ |
|---|
| 58 | #define NYHR_STACK 8 /* src has a stack entry numbered <relator> with value tgt */ |
|---|
| 59 | #define NYHR_RELSRC 9 /* relator % src is tgt ; tgt is relator % src*/ |
|---|
| 60 | #define NYHR_LIMIT 10 /* All others are < NYHR_LIMIT */ |
|---|
| 61 | |
|---|
| 62 | /* NyHeapDef - structure to define by external type providers to define themselves wrt heapy |
|---|
| 63 | */ |
|---|
| 64 | |
|---|
| 65 | /* Definitions of its function types, useful for casting. */ |
|---|
| 66 | |
|---|
| 67 | typedef int (*NyHeapDef_SizeGetter) (PyObject *obj); |
|---|
| 68 | typedef int (*NyHeapDef_Traverser) (NyHeapTraverse *arg); |
|---|
| 69 | typedef int (*NyHeapDef_RelationGetter) (NyHeapRelate *r); |
|---|
| 70 | |
|---|
| 71 | typedef struct { |
|---|
| 72 | int flags; /* As yet, only 0 */ |
|---|
| 73 | PyTypeObject *type; /* The type it regards */ |
|---|
| 74 | NyHeapDef_SizeGetter size; |
|---|
| 75 | NyHeapDef_Traverser traverse; |
|---|
| 76 | NyHeapDef_RelationGetter relate; |
|---|
| 77 | void *resv3, *resv4, *resv5; /* Reserved for future bin. comp. */ |
|---|
| 78 | } NyHeapDef; |
|---|
| 79 | |
|---|
| 80 | #endif /* Ny_HEAPDEF_H */ |
|---|