Skip to content

Commit 548afb7

Browse files
committed
first impl
1 parent 0c36250 commit 548afb7

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

Objects/recordobject.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,47 @@
88
#include "pycore_object.h" // _PyObject_GC_TRACK()
99
#include "recordobject.h"
1010

11+
static inline void
12+
record_gc_track(PyRecordObject *op)
13+
{
14+
_PyObject_GC_TRACK(op);
15+
}
16+
17+
static PyRecordObject *
18+
record_alloc(Py_ssize_t size)
19+
{
20+
PyRecordObject *op;
21+
if (size < 0) {
22+
PyErr_BadInternalCall();
23+
return NULL;
24+
}
25+
26+
{
27+
/* Check for overflow */
28+
if ((size_t)size > ((size_t)PY_SSIZE_T_MAX - (sizeof(PyRecordObject) -
29+
sizeof(PyObject *))) / sizeof(PyObject *)) {
30+
return (PyRecordObject *)PyErr_NoMemory();
31+
}
32+
op = PyObject_GC_NewVar(PyRecordObject, &PyRecord_Type, size);
33+
if (op == NULL)
34+
return NULL;
35+
}
36+
return op;
37+
}
38+
1139
PyAPI_FUNC(PyObject *) PyRecord_New(Py_ssize_t size)
1240
{
13-
return NULL;
41+
PyRecordObject *op;
42+
op = record_alloc(size);
43+
if (op == NULL) {
44+
return NULL;
45+
}
46+
op->names = NULL;
47+
for (Py_ssize_t i = 0; i < size; i++) {
48+
op->ob_item[i] = NULL;
49+
}
50+
record_gc_track(op);
51+
return (PyObject *) op;
1452
}
1553

1654
static void

0 commit comments

Comments
 (0)