Skip to content

Commit 92d3598

Browse files
committed
progress
1 parent b1e0ab4 commit 92d3598

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Objects/recordobject.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,32 @@ record_hash(PyRecordObject *v)
181181
PyObject *
182182
record_getattro(PyObject *obj, PyObject *name)
183183
{
184-
// TODO
185-
return NULL;
184+
if (name == NULL || PyUnicode_GetLength(name) == 0) {
185+
PyErr_SetString(PyExc_TypeError, "record name cannot be zero length");
186+
return NULL;
187+
}
188+
189+
PyRecordObject* tmp = (PyRecordObject*) obj;
190+
PyObject *ret, *val;
191+
Py_ssize_t n, i;
192+
193+
n = PyTuple_GET_SIZE(tmp->names);
194+
i = 0;
195+
for (i = 0; i < n; i++) {
196+
val = PyTuple_GET_ITEM(tmp->names, i);
197+
if (val == NULL) {
198+
PyErr_SetString(PyExc_TypeError, "invalid name inside of record object");
199+
return NULL;
200+
}
201+
202+
if (PyUnicode_Compare(name, val) == 0) {
203+
ret = tmp->ob_item[i];
204+
Py_INCREF(ret);
205+
return ret;
206+
}
207+
}
208+
209+
return PyObject_GenericGetAttr(obj, name);
186210
}
187211

188212
static PyObject *

0 commit comments

Comments
 (0)