Skip to content

Commit 0c36250

Browse files
committed
boilerplate
1 parent 30268e2 commit 0c36250

File tree

6 files changed

+163
-0
lines changed

6 files changed

+163
-0
lines changed

Include/Python.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
#include "rangeobject.h"
9090
#include "memoryobject.h"
9191
#include "tupleobject.h"
92+
#include "recordobject.h"
9293
#include "listobject.h"
9394
#include "dictobject.h"
9495
#include "cpython/odictobject.h"

Include/cpython/recordobject.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef Py_CPYTHON_RECORDOBJECT_H
2+
# error "this header file must not be included directly"
3+
#endif
4+
5+
typedef struct {
6+
PyObject_VAR_HEAD
7+
PyObject *names;
8+
/* ob_item contains space for 'ob_size' elements.
9+
Items must normally not be NULL, except during construction when
10+
the record is not yet visible outside the function that builds it. */
11+
PyObject *ob_item[1];
12+
} PyRecordObject;

Include/recordobject.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* Record object interface */
2+
3+
#ifndef Py_RECORDOBJECT_H
4+
#define Py_RECORDOBJECT_H
5+
#ifdef __cplusplus
6+
extern "C" {
7+
#endif
8+
9+
PyAPI_DATA(PyTypeObject) PyRecord_Type;
10+
PyAPI_FUNC(PyObject *) PyRecord_New(Py_ssize_t size);
11+
#define PyRecord_Check(op) Py_IS_TYPE(op, &PyRecord_Type)
12+
13+
#ifndef Py_LIMITED_API
14+
# define Py_CPYTHON_RECORDOBJECT_H
15+
# include "cpython/recordobject.h"
16+
# undef Py_CPYTHON_RECORDOBJECT_H
17+
#endif
18+
19+
#ifdef __cplusplus
20+
}
21+
#endif
22+
#endif /* !Py_RECORDOBJECT_H */

Makefile.pre.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ OBJECT_OBJS= \
438438
Objects/sliceobject.o \
439439
Objects/structseq.o \
440440
Objects/tupleobject.o \
441+
Objects/recordobject.o \
441442
Objects/typeobject.o \
442443
Objects/unicodeobject.o \
443444
Objects/unicodectype.o \
@@ -1100,6 +1101,7 @@ PYTHON_HEADERS= \
11001101
$(srcdir)/Include/traceback.h \
11011102
$(srcdir)/Include/tracemalloc.h \
11021103
$(srcdir)/Include/tupleobject.h \
1104+
$(srcdir)/Include/recordobject.h \
11031105
$(srcdir)/Include/unicodeobject.h \
11041106
$(srcdir)/Include/warnings.h \
11051107
$(srcdir)/Include/weakrefobject.h \
@@ -1138,6 +1140,7 @@ PYTHON_HEADERS= \
11381140
$(srcdir)/Include/cpython/sysmodule.h \
11391141
$(srcdir)/Include/cpython/traceback.h \
11401142
$(srcdir)/Include/cpython/tupleobject.h \
1143+
$(srcdir)/Include/cpython/recordobject.h \
11411144
$(srcdir)/Include/cpython/unicodeobject.h \
11421145
\
11431146
$(srcdir)/Include/internal/pycore_abstract.h \

Objects/recordobject.c

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
2+
/* Record object implementation */
3+
4+
#include "Python.h"
5+
#include "pycore_abstract.h" // _PyIndex_Check()
6+
#include "pycore_gc.h" // _PyObject_GC_IS_TRACKED()
7+
#include "pycore_initconfig.h" // _PyStatus_OK()
8+
#include "pycore_object.h" // _PyObject_GC_TRACK()
9+
#include "recordobject.h"
10+
11+
PyAPI_FUNC(PyObject *) PyRecord_New(Py_ssize_t size)
12+
{
13+
return NULL;
14+
}
15+
16+
static void
17+
record_dealloc(PyRecordObject *op)
18+
{
19+
// TODO
20+
}
21+
22+
static PyObject *
23+
record_repr(PyRecordObject *v)
24+
{
25+
// TODO
26+
return NULL;
27+
}
28+
29+
static Py_ssize_t
30+
record_length(PyRecordObject *a)
31+
{
32+
return Py_SIZE(a);
33+
}
34+
35+
static PyObject *
36+
recorditem(PyRecordObject *a, Py_ssize_t i)
37+
{
38+
if (i < 0 || i >= Py_SIZE(a)) {
39+
PyErr_SetString(PyExc_IndexError, "record index out of range");
40+
return NULL;
41+
}
42+
Py_INCREF(a->ob_item[i]);
43+
return a->ob_item[i];
44+
}
45+
46+
47+
static PySequenceMethods record_as_sequence = {
48+
(lenfunc)record_length, /* sq_length */
49+
0, /* sq_concat */
50+
0, /* sq_repeat */
51+
(ssizeargfunc)recorditem, /* sq_item */
52+
0, /* sq_slice */
53+
0, /* sq_ass_item */
54+
0, /* sq_ass_slice */
55+
0, /* sq_contains */
56+
};
57+
58+
static Py_hash_t
59+
record_hash(PyRecordObject *v)
60+
{
61+
return -1;
62+
}
63+
64+
PyObject *
65+
record_getattro(PyObject *obj, PyObject *name)
66+
{
67+
// TODO
68+
return NULL;
69+
}
70+
71+
static PyObject *
72+
record_rich_compare(PyObject *v, PyObject *w, int op)
73+
{
74+
return NULL;
75+
}
76+
77+
static PyObject *
78+
record_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
79+
{
80+
return NULL;
81+
}
82+
83+
PyTypeObject PyRecord_Type = {
84+
PyVarObject_HEAD_INIT(&PyType_Type, 0)
85+
"record",
86+
sizeof(PyRecordObject) - sizeof(PyObject *),
87+
sizeof(PyObject *),
88+
(destructor)record_dealloc, /* tp_dealloc */
89+
0, /* tp_vectorcall_offset */
90+
0, /* tp_getattr */
91+
0, /* tp_setattr */
92+
0, /* tp_as_async */
93+
(reprfunc)record_repr, /* tp_repr */
94+
0, /* tp_as_number */
95+
&record_as_sequence, /* tp_as_sequence */
96+
0, /* tp_as_mapping */
97+
(hashfunc)record_hash, /* tp_hash */
98+
0, /* tp_call */
99+
0, /* tp_str */
100+
record_getattro, /* tp_getattro */
101+
0, /* tp_setattro */
102+
0, /* tp_as_buffer */
103+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
104+
0, /* tp_doc */
105+
0, /* tp_traverse */
106+
0, /* tp_clear */
107+
record_rich_compare, /* tp_richcompare */
108+
0, /* tp_weaklistoffset */
109+
0, /* tp_iter */
110+
0, /* tp_iternext */
111+
0, /* tp_methods */
112+
0, /* tp_members */
113+
0, /* tp_getset */
114+
0, /* tp_base */
115+
0, /* tp_dict */
116+
0, /* tp_descr_get */
117+
0, /* tp_descr_set */
118+
0, /* tp_dictoffset */
119+
0, /* tp_init */
120+
0, /* tp_alloc */
121+
record_new, /* tp_new */
122+
PyObject_GC_Del, /* tp_free */
123+
0,
124+
};

Python/bltinmodule.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,6 +3036,7 @@ _PyBuiltin_Init(PyInterpreterState *interp)
30363036
SETBUILTIN("str", &PyUnicode_Type);
30373037
SETBUILTIN("super", &PySuper_Type);
30383038
SETBUILTIN("tuple", &PyTuple_Type);
3039+
SETBUILTIN("record", &PyRecord_Type);
30393040
SETBUILTIN("type", &PyType_Type);
30403041
SETBUILTIN("zip", &PyZip_Type);
30413042
debug = PyBool_FromLong(config->optimization_level == 0);

0 commit comments

Comments
 (0)