[ctypes-commit] ctypes/source _ctypes.c,1.224,1.225
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2005-03-16 19:45:38
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7180 Modified Files: _ctypes.c Log Message: Subclasses of c_char_p, c_wchar_p, and c_void_p were not able to override the from_param class method in their class definitions because SimpleType_new overwrote them. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.224 retrieving revision 1.225 diff -C2 -d -r1.224 -r1.225 *** _ctypes.c 16 Mar 2005 17:50:25 -0000 1.224 --- _ctypes.c 16 Mar 2005 19:45:27 -0000 1.225 *************** *** 113,116 **** --- 113,117 ---- PyObject *PyExc_ArgError; + static PyTypeObject Simple_Type; char *conversion_mode_encoding = NULL; *************** *** 1202,1206 **** #else ! static PyMethodDef c_void_p_method = { "from_param", c_void_p_from_param, METH_VARARGS }; static PyMethodDef c_char_p_method = { "from_param", c_char_p_from_param, METH_VARARGS }; --- 1203,1207 ---- #else ! #error static PyMethodDef c_void_p_method = { "from_param", c_void_p_from_param, METH_VARARGS }; static PyMethodDef c_char_p_method = { "from_param", c_char_p_from_param, METH_VARARGS }; *************** *** 1262,1308 **** result->tp_dict = (PyObject *)stgdict; ! switch (PyString_AS_STRING(proto)[0]) { ! case 'z': /* c_char_p */ ! ml = &c_char_p_method; ! break; ! case 'Z': /* c_wchar_p */ ! ml = &c_wchar_p_method; ! break; ! case 'P': /* c_void_p */ ! ml = &c_void_p_method; ! break; ! default: ! ml = NULL; ! break; ! } ! if (ml) { #if (PYTHON_API_VERSION >= 1012) ! PyObject *meth; ! int x; ! meth = PyDescr_NewClassMethod(result, ml); ! if (!meth) ! return NULL; #else ! PyObject *meth, *func; ! int x; ! func = PyCFunction_New(ml, NULL); ! if (!func) ! return NULL; ! meth = PyObject_CallFunctionObjArgs( ! (PyObject *)&PyClassMethod_Type, ! func, NULL); ! Py_DECREF(func); ! if (!meth) { ! return NULL; ! } #endif ! x = PyDict_SetItemString(result->tp_dict, ! ml->ml_name, ! meth); ! Py_DECREF(meth); ! if (x == -1) { ! Py_DECREF(result); ! return NULL; } } --- 1263,1315 ---- result->tp_dict = (PyObject *)stgdict; ! /* Install from_param class methods in ctypes base classes. ! Overrides the SimpleType_from_param generic method. ! */ ! if (result->tp_base == &Simple_Type) { ! switch (PyString_AS_STRING(proto)[0]) { ! case 'z': /* c_char_p */ ! ml = &c_char_p_method; ! break; ! case 'Z': /* c_wchar_p */ ! ml = &c_wchar_p_method; ! break; ! case 'P': /* c_void_p */ ! ml = &c_void_p_method; ! break; ! default: ! ml = NULL; ! break; ! } ! if (ml) { #if (PYTHON_API_VERSION >= 1012) ! PyObject *meth; ! int x; ! meth = PyDescr_NewClassMethod(result, ml); ! if (!meth) ! return NULL; #else ! #error ! PyObject *meth, *func; ! int x; ! func = PyCFunction_New(ml, NULL); ! if (!func) ! return NULL; ! meth = PyObject_CallFunctionObjArgs( ! (PyObject *)&PyClassMethod_Type, ! func, NULL); ! Py_DECREF(func); ! if (!meth) { ! return NULL; ! } #endif ! x = PyDict_SetItemString(result->tp_dict, ! ml->ml_name, ! meth); ! Py_DECREF(meth); ! if (x == -1) { ! Py_DECREF(result); ! return NULL; ! } } } |