1 /**
2   Mirror _tupleobject.h
3 
4   Another generally useful object type is a tuple of object pointers.
5   For Python, this is an immutable type.  C code can change the tuple items
6   (but not their number), and even use tuples are general-purpose arrays of
7   object references, but in general only brand new tuples should be mutated,
8   not ones that might already have been exposed to Python code.
9  */
10 module deimos.python.tupleobject;
11 
12 import core.stdc.stdio;
13 import deimos.python.pyport;
14 import deimos.python.object;
15 
16 extern(C):
17 // Python-header-file: Include/tupleobject.h:
18 
19 /** ob_item contains space for 'ob_size' elements.
20  * Items must normally not be NULL, except during construction when
21  * the tuple is not yet visible outside the function that builds it.
22  *
23  * subclass of PyVarObject
24  */
25 struct PyTupleObject {
26     mixin PyObject_VAR_HEAD;
27 
28     // Will the D layout for a 1-PyObject* array be the same as the C layout?
29     // I think the D array will be larger.
30     PyObject*[1] _ob_item;
31     /// _
32     PyObject** ob_item()() {
33         return _ob_item.ptr;
34     }
35 }
36 
37 /// _
38 mixin(PyAPI_DATA!"PyTypeObject PyTuple_Type");
39 /// _
40 mixin(PyAPI_DATA!"PyTypeObject PyTupleIter_Type");
41 
42 // D translation of C macro:
43 /// _
44 int PyTuple_Check()(PyObject* op) {
45     return PyObject_TypeCheck(op, &PyTuple_Type);
46 }
47 // D translation of C macro:
48 /// _
49 int PyTuple_CheckExact()(PyObject* op) {
50     return Py_TYPE(op) == &PyTuple_Type;
51 }
52 
53 /// _
54 PyObject* PyTuple_New(Py_ssize_t size);
55 /// _
56 Py_ssize_t PyTuple_Size(PyObject*);
57 /// _
58 PyObject_BorrowedRef* PyTuple_GetItem(PyObject*, Py_ssize_t);
59 /// _
60 int PyTuple_SetItem(PyObject*, Py_ssize_t, PyObject*);
61 /// _
62 PyObject* PyTuple_GetSlice(PyObject*, Py_ssize_t, Py_ssize_t);
63 /// _
64 int _PyTuple_Resize(PyObject**, Py_ssize_t);
65 /// _
66 PyObject* PyTuple_Pack(Py_ssize_t, ...);
67 
68 // D translations of C macros:
69 // XXX: These do not work.
70 /// _
71 PyObject_BorrowedRef* PyTuple_GET_ITEM()(PyObject* op, Py_ssize_t i) {
72     return (cast(PyTupleObject*) op).ob_item[i];
73 }
74 /// _
75 size_t PyTuple_GET_SIZE()(PyObject* op) {
76     return (cast(PyTupleObject*) op).ob_size;
77 }
78 /// _
79 PyObject* PyTuple_SET_ITEM()(PyObject* op, Py_ssize_t i, PyObject* v) {
80     PyTupleObject* opAsTuple = cast(PyTupleObject*) op;
81     opAsTuple.ob_item[i] = v;
82     return v;
83 }
84 
85 version(Python_2_6_Or_Later){
86     /// Availability: >= 2.6
87     int PyTuple_ClearFreeList();
88 }
89 version(Python_3_2_Or_Later) {
90     /// Availability: >= 3.2
91     void _PyTuple_DebugMallocStats(FILE* out_);
92 }