[ctypes-commit] ctypes/source stgdict.c, 1.39, 1.40 ctypes.h, 1.105, 1.106
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2006-06-09 19:20:24
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv18271 Modified Files: stgdict.c ctypes.h Log Message: Correct the support for nested anonymous Structure/Union fields. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.105 retrieving revision 1.106 diff -C2 -d -r1.105 -r1.106 *** ctypes.h 9 Jun 2006 05:50:10 -0000 1.105 --- ctypes.h 9 Jun 2006 19:20:20 -0000 1.106 *************** *** 182,185 **** --- 182,186 ---- GETFUNC getfunc; /* getter function if proto is NULL */ SETFUNC setfunc; /* setter function if proto is NULL */ + int anonymous; } CFieldObject; Index: stgdict.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/stgdict.c,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** stgdict.c 2 Jun 2006 21:13:09 -0000 1.39 --- stgdict.c 9 Jun 2006 19:20:20 -0000 1.40 *************** *** 148,152 **** */ static int ! MakeFields(PyObject *type, CFieldObject *descr) { Py_ssize_t i; --- 148,153 ---- */ static int ! MakeFields(PyObject *type, CFieldObject *descr, ! Py_ssize_t index, Py_ssize_t offset) { Py_ssize_t i; *************** *** 183,186 **** --- 184,198 ---- return -1; } + if (fdescr->anonymous) { + int rc = MakeFields(type, fdescr, + index + fdescr->index, + offset + fdescr->offset); + Py_DECREF(fdescr); + if (rc == -1) { + Py_DECREF(fieldlist); + return -1; + } + continue; + } new_descr = (CFieldObject *)PyObject_CallObject((PyObject *)&CField_Type, NULL); assert(new_descr->ob_type == &CField_Type); *************** *** 191,196 **** } new_descr->size = fdescr->size; ! new_descr->offset = fdescr->offset + descr->offset; ! new_descr->index = fdescr->index + descr->index; new_descr->proto = fdescr->proto; Py_XINCREF(new_descr->proto); --- 203,208 ---- } new_descr->size = fdescr->size; ! new_descr->offset = fdescr->offset + offset; ! new_descr->index = fdescr->index + index; new_descr->proto = fdescr->proto; Py_XINCREF(new_descr->proto); *************** *** 232,236 **** for (i = 0; i < PySequence_Fast_GET_SIZE(anon_names); ++i) { PyObject *fname = PySequence_Fast_GET_ITEM(anon_names, i); /* borrowed */ ! PyObject *descr = PyObject_GetAttr(type, fname); if (descr == NULL) { Py_DECREF(anon_names); --- 244,248 ---- for (i = 0; i < PySequence_Fast_GET_SIZE(anon_names); ++i) { PyObject *fname = PySequence_Fast_GET_ITEM(anon_names, i); /* borrowed */ ! CFieldObject *descr = (CFieldObject *)PyObject_GetAttr(type, fname); if (descr == NULL) { Py_DECREF(anon_names); *************** *** 238,243 **** } assert(descr->ob_type == &CField_Type); /* descr is in the field descriptor. */ ! if (-1 == MakeFields(type, (CFieldObject *)descr)) { Py_DECREF(descr); Py_DECREF(anon_names); --- 250,259 ---- } assert(descr->ob_type == &CField_Type); + descr->anonymous = 1; + /* descr is in the field descriptor. */ ! if (-1 == MakeFields(type, (CFieldObject *)descr, ! ((CFieldObject *)descr)->index, ! ((CFieldObject *)descr)->offset)) { Py_DECREF(descr); Py_DECREF(anon_names); |