[ctypes-commit] ctypes/source _ctypes.c,1.210,1.211
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2005-03-07 17:29:35
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24058 Modified Files: _ctypes.c Log Message: Refactoring. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.210 retrieving revision 1.211 diff -C2 -d -r1.210 -r1.211 *** _ctypes.c 7 Mar 2005 09:26:36 -0000 1.210 --- _ctypes.c 7 Mar 2005 17:29:22 -0000 1.211 *************** *** 2026,2030 **** /* If KeepRef fails, we are stumped. The dst memory block has already been changed */ ! return KeepRef(mem, index, result); } --- 2026,2031 ---- /* If KeepRef fails, we are stumped. The dst memory block has already been changed */ ! return KeepRef(mem, index, result); ! } *************** *** 2350,2354 **** if (!PyArg_ParseTuple(args, "is", &index, &name)) return NULL; ! self = (CFuncPtrObject *)GenericCData_new(type, args, kwds); self->index = index + 0x1000; --- 2351,2355 ---- if (!PyArg_ParseTuple(args, "is", &index, &name)) return NULL; ! self = (CFuncPtrObject *)GenericCData_new(type, args, kwds); self->index = index + 0x1000; *************** *** 2466,2475 **** static PyObject * ! CFuncPtr_call(CFuncPtrObject *self, PyObject *args, PyObject *kwds) { PyObject *restype; PyObject *converters; PyObject *checker; StgDictObject *dict = PyObject_stgdict((PyObject *)self); #ifdef MS_WIN32 IUnknown *piunk = NULL; --- 2467,2488 ---- static PyObject * ! _build_callargs(CFuncPtrObject *self, PyObject *argtypes, PyObject *inargs, PyObject *kwds) ! { ! if (self->index) ! return PyTuple_GetSlice(inargs, 1, PyTuple_GET_SIZE(inargs)); ! Py_INCREF(inargs); ! return inargs; ! } ! ! static PyObject * ! CFuncPtr_call(CFuncPtrObject *self, PyObject *inargs, PyObject *kwds) { PyObject *restype; PyObject *converters; PyObject *checker; + PyObject *argtypes; StgDictObject *dict = PyObject_stgdict((PyObject *)self); + PyObject *result; + PyObject *callargs; #ifdef MS_WIN32 IUnknown *piunk = NULL; *************** *** 2481,2484 **** --- 2494,2498 ---- converters = self->converters ? self->converters : dict->converters; checker = self->checker ? self->checker : dict->checker; + argtypes = self->argtypes ? self->argtypes : dict->argtypes; #ifdef MS_WIN32 *************** *** 2486,2490 **** /* It's a COM method */ CDataObject *this; ! this = (CDataObject *)PyTuple_GetItem(args, 0); /* borrowed ref! */ if (!this) { PyErr_SetString(PyExc_ValueError, --- 2500,2504 ---- /* It's a COM method */ CDataObject *this; ! this = (CDataObject *)PyTuple_GetItem(inargs, 0); /* borrowed ref! */ if (!this) { PyErr_SetString(PyExc_ValueError, *************** *** 2511,2524 **** } pProc = ((void **)piunk->lpVtbl)[self->index - 0x1000]; } #endif if (converters) { int required = PyTuple_GET_SIZE(converters); ! int actual = PyTuple_GET_SIZE(args); ! #ifdef MS_WIN32 ! if (piunk) ! required ++; ! #endif if ((dict->flags & FUNCFLAG_CDECL) == FUNCFLAG_CDECL) { /* For cdecl functions, we allow more actual arguments --- 2525,2540 ---- } pProc = ((void **)piunk->lpVtbl)[self->index - 0x1000]; + } else { + pProc = *(void **)self->b_ptr; } #endif + callargs = _build_callargs(self, argtypes, inargs, kwds); + if (callargs == NULL) + return NULL; if (converters) { int required = PyTuple_GET_SIZE(converters); ! int actual = PyTuple_GET_SIZE(callargs); ! if ((dict->flags & FUNCFLAG_CDECL) == FUNCFLAG_CDECL) { /* For cdecl functions, we allow more actual arguments *************** *** 2526,2529 **** --- 2542,2546 ---- */ if (required > actual) { + Py_DECREF(callargs); PyErr_Format(PyExc_TypeError, "this function takes at least %d argument%s (%d given)", *************** *** 2534,2537 **** --- 2551,2555 ---- } } else if (required != actual) { + Py_DECREF(callargs); PyErr_Format(PyExc_TypeError, "this function takes %d argument%s (%d given)", *************** *** 2542,2567 **** } } #ifdef MS_WIN32 ! if (piunk) { ! PyObject *a = PyTuple_GetSlice(args, 1, PyTuple_GET_SIZE(args)); ! PyObject *result; ! result = _CallProc(pProc, ! a, ! piunk, ! dict->flags, ! converters, ! restype, ! checker); ! Py_DECREF(a); ! return result; ! } #endif ! return _CallProc(*(void **)self->b_ptr, ! args, ! NULL, ! dict->flags, ! converters, ! restype, ! checker); } --- 2560,2577 ---- } } + + result = _CallProc(pProc, + callargs, #ifdef MS_WIN32 ! piunk, ! #else ! NULL, #endif ! dict->flags, ! converters, ! restype, ! checker); ! Py_DECREF(callargs); ! return result; } *************** *** 3163,3167 **** if (!result) return -1; ! /* consumes the refcount the setfunc returns */ return KeepRef(self, 0, result); --- 3173,3177 ---- if (!result) return -1; ! /* consumes the refcount the setfunc returns */ return KeepRef(self, 0, result); *************** *** 3172,3176 **** { PyObject *value = NULL; ! /* XXX Optimize. PyArg_ParseTuple is slow... */ if (!PyArg_ParseTuple(args, "|O", &value)) --- 3182,3187 ---- { PyObject *value = NULL; ! int len = PyTuple_GET_SIZE(args); ! /* XXX Optimize. PyArg_ParseTuple is slow... */ if (!PyArg_ParseTuple(args, "|O", &value)) |