File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed
Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -181,8 +181,32 @@ record_hash(PyRecordObject *v)
181181PyObject *
182182record_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
188212static PyObject *
You can’t perform that action at this time.
0 commit comments