[ctypes-commit] ctypes/source _ctypes.c,1.184,1.185
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2004-11-25 09:37:56
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11132 Modified Files: _ctypes.c Log Message: More refactoring - moved code around, made CData_GetList() static. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.184 retrieving revision 1.185 diff -C2 -d -r1.184 -r1.185 *** _ctypes.c 25 Nov 2004 09:01:20 -0000 1.184 --- _ctypes.c 25 Nov 2004 09:37:44 -0000 1.185 *************** *** 658,662 **** memcpy(self->b_ptr, ptr, size); - /* What about CData_GetList()? We don't care, since we have a copy of the data */ return 0; } --- 658,661 ---- *************** *** 712,717 **** Py_DECREF(value); - /* What about CData_GetList()? No need to do something, since we have - a copy of the data */ return 0; } --- 711,714 ---- *************** *** 770,774 **** done: Py_DECREF(value); ! /* What about CData_GetList()? We don't care, since we have a copy of the data */ return result; } --- 767,771 ---- done: Py_DECREF(value); ! return result; } *************** *** 1584,1617 **** * Code to keep needed objects alive */ - static int - CanKeepRef(CDataObject *target, int index) - { - PyObject *objects = CData_GetList(target); - if (!objects) - return -1; - if (index < 0 || PyList_Size(objects) <= index) { - PyErr_SetString(PyExc_IndexError, - "invalid index"); - return -1; - } - return 0; - } ! static int ! KeepRef(CDataObject *target, int index, PyObject *keep) ! { ! int result; ! PyObject *list = CData_GetList(target); ! result = PyList_SetItem(list, index, keep); ! if (result == -1) ! return -1; ! return 0; ! } ! ! /* ! * Return a list of size <size> filled with None's. ! */ static PyObject * ! RepeatedList(PyObject *ob, int size) { int i; --- 1581,1588 ---- * Code to keep needed objects alive */ ! /* Return a list of size <size> filled with None's. */ static PyObject * ! NoneList(int size) { int i; *************** *** 1622,1637 **** return NULL; for (i = 0; i < size; ++i) { ! Py_INCREF(ob); ! PyList_SET_ITEM(list, i, ob); } return list; } - static PyObject * - NoneList(int size) - { - return RepeatedList(Py_None, size); - } - #define ASSERT_CDATA(x) assert(((x)->b_base == NULL) ^ ((x)->b_objects == NULL)) --- 1593,1602 ---- return NULL; for (i = 0; i < size; ++i) { ! Py_INCREF(Py_None); ! PyList_SET_ITEM(list, i, Py_None); } return list; } #define ASSERT_CDATA(x) assert(((x)->b_base == NULL) ^ ((x)->b_objects == NULL)) *************** *** 1640,1644 **** * Borrowed reference! */ ! PyObject * CData_GetList(CDataObject *mem) { --- 1605,1609 ---- * Borrowed reference! */ ! static PyObject * CData_GetList(CDataObject *mem) { *************** *** 1692,1695 **** --- 1657,1693 ---- } + static PyObject * + GetKeepedObjects(CDataObject *target) + { + return CData_GetList(target); + } + + /* set an exception and return -1 if a call to KeepRef will fail, 0 otherwise */ + static int + CanKeepRef(CDataObject *target, int index) + { + PyObject *objects = CData_GetList(target); + if (!objects) + return -1; + if (index < 0 || PyList_Size(objects) <= index) { + PyErr_SetString(PyExc_IndexError, + "invalid index"); + return -1; + } + return 0; + } + + /* Keep a reference to 'keep' in the 'target', at index 'index' */ + static int + KeepRef(CDataObject *target, int index, PyObject *keep) + { + int result; + PyObject *list = CData_GetList(target); + result = PyList_SetItem(list, index, keep); + if (result == -1) + return -1; + return 0; + } + /******************************************************************/ /* *************** *** 1968,1972 **** /* XXX */; ! value = CData_GetList(src); Py_INCREF(value); return value; --- 1966,1970 ---- /* XXX */; ! value = GetKeepedObjects(src); Py_INCREF(value); return value; *************** *** 1989,1993 **** *(void **)ptr = src->b_ptr; ! keep = CData_GetList(src); /* We are assigning an array object to a field which represents --- 1987,1991 ---- *(void **)ptr = src->b_ptr; ! keep = GetKeepedObjects(src); /* We are assigning an array object to a field which represents *************** *** 3366,3370 **** return -1; ! keep = CData_GetList(dst); Py_INCREF(keep); return KeepRef(self, 0, keep); --- 3364,3368 ---- return -1; ! keep = GetKeepedObjects(dst); Py_INCREF(keep); return KeepRef(self, 0, keep); |