ctypes-commit Mailing List for ctypes (Page 60)
Brought to you by:
theller
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(8) |
May
(90) |
Jun
(143) |
Jul
(106) |
Aug
(94) |
Sep
(84) |
Oct
(163) |
Nov
(60) |
Dec
(58) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(128) |
Feb
(79) |
Mar
(227) |
Apr
(192) |
May
(179) |
Jun
(41) |
Jul
(53) |
Aug
(103) |
Sep
(28) |
Oct
(38) |
Nov
(81) |
Dec
(17) |
2006 |
Jan
(184) |
Feb
(111) |
Mar
(188) |
Apr
(67) |
May
(58) |
Jun
(123) |
Jul
(73) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Thomas H. <th...@us...> - 2005-04-06 16:43:09
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29630 Modified Files: cfield.c Log Message: Accept c_char_p and c_wchar_p instances in z_set and Z_set. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.109 retrieving revision 1.110 diff -C2 -d -r1.109 -r1.110 *** cfield.c 6 Apr 2005 16:29:35 -0000 1.109 --- cfield.c 6 Apr 2005 16:42:56 -0000 1.110 *************** *** 801,804 **** --- 801,810 ---- return value; } + /* Do we want to allow c_wchar_p also, with conversion? */ + if (PyObject_IsInstance(value, CTYPE_c_char_p)) { + *(char **)ptr = *(char **)(((CDataObject *)value)->b_ptr); + Py_INCREF(value); + return value; + } if (PyString_Check(value)) { *(char **)ptr = PyString_AS_STRING(value); *************** *** 842,845 **** --- 848,857 ---- return value; } + /* Do we want to allow c_char_p also, with conversion? */ + if (PyObject_IsInstance(value, CTYPE_c_wchar_p)) { + *(wchar_t **)ptr = *(wchar_t **)(((CDataObject *)value)->b_ptr); + Py_INCREF(value); + return value; + } if (PyString_Check(value)) { value = PyUnicode_FromEncodedObject(value, |
From: Thomas H. <th...@us...> - 2005-04-06 16:42:19
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29300 Modified Files: ctypes.h Log Message: Make the CTYPE_... types global. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.93 retrieving revision 1.94 diff -C2 -d -r1.93 -r1.94 *** ctypes.h 6 Apr 2005 11:13:52 -0000 1.93 --- ctypes.h 6 Apr 2005 16:42:08 -0000 1.94 *************** *** 381,384 **** --- 381,387 ---- extern void _AddTraceback(char *, char *, int); + extern PyObject *CTYPE_c_char_p, *CTYPE_c_char, *CTYPE_c_wchar_p, + *CTYPE_c_wchar, *CTYPE_c_void_p, *CTYPE_BSTR; + /* Local Variables: |
From: Thomas H. <th...@us...> - 2005-04-06 16:29:49
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25564 Modified Files: cfield.c Log Message: Don't accept integers any longer for c_char_p and c_wchar_p. API change! Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.108 retrieving revision 1.109 diff -C2 -d -r1.108 -r1.109 *** cfield.c 6 Apr 2005 14:38:00 -0000 1.108 --- cfield.c 6 Apr 2005 16:29:35 -0000 1.109 *************** *** 814,820 **** Py_INCREF(str); return str; - } else if (PyInt_Check(value) || PyLong_Check(value)) { - *(char **)ptr = (char *)PyInt_AsUnsignedLongMask(value); - _RET(value); } PyErr_Format(PyExc_TypeError, --- 814,817 ---- *************** *** 851,858 **** if (!value) return NULL; - } else if (PyInt_Check(value) || PyLong_Check(value)) { - *(wchar_t **)ptr = (wchar_t *)PyInt_AsUnsignedLongMask(value); - Py_INCREF(Py_None); - return Py_None; } else if (!PyUnicode_Check(value)) { PyErr_Format(PyExc_TypeError, --- 848,851 ---- |
From: Thomas H. <th...@us...> - 2005-04-06 15:55:00
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16198 Modified Files: _ctypes.c Log Message: More cleanup of typechecks. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.287 retrieving revision 1.288 diff -C2 -d -r1.287 -r1.288 *** _ctypes.c 6 Apr 2005 14:01:51 -0000 1.287 --- _ctypes.c 6 Apr 2005 15:54:47 -0000 1.288 *************** *** 400,411 **** if (PyCArg_CheckExact(value)) { PyCArgObject *p = (PyCArgObject *)value; ! PyObject *ob = p->obj; ! StgDictObject *dict; ! dict = PyType_stgdict(type); /* If we got a PyCArgObject, we must check if the object packed in it is an instance of the type's dict->proto */ ! if(dict && ob ! && PyObject_IsInstance(ob, dict->itemtype)) { Py_INCREF(value); return value; --- 400,408 ---- if (PyCArg_CheckExact(value)) { PyCArgObject *p = (PyCArgObject *)value; ! StgDictObject *dict = PyType_stgdict(type); /* If we got a PyCArgObject, we must check if the object packed in it is an instance of the type's dict->proto */ ! if(PyObject_IsInstance(p->obj, dict->itemtype)) { Py_INCREF(value); return value; *************** *** 414,418 **** "expected %s instance instead of pointer to %s", ((PyTypeObject *)type)->tp_name, ! ob->ob_type->tp_name); return NULL; } --- 411,415 ---- "expected %s instance instead of pointer to %s", ((PyTypeObject *)type)->tp_name, ! p->obj->ob_type->tp_name); return NULL; } *************** *** 726,732 **** PointerType_from_param(PyObject *type, PyObject *value) { ! if (value == Py_None) ! return PyInt_FromLong(0); /* NULL pointer */ ! if (ArrayObject_Check(value) || PointerObject_Check(value)) { StgDictObject *v = PyObject_stgdict(value); --- 723,730 ---- PointerType_from_param(PyObject *type, PyObject *value) { ! if (value == Py_None) { ! Py_INCREF(Py_None); ! return Py_None; ! } if (ArrayObject_Check(value) || PointerObject_Check(value)) { StgDictObject *v = PyObject_stgdict(value); *************** *** 1219,1245 **** { StgDictObject *typedict = PyType_stgdict(type); - StgDictObject *itemdict = PyType_stgdict(typedict->itemtype); - - /* z_set and Z_set accept integers as well. Until that is fixed, we - have to typecheck here. */ - if (value == Py_None || PyString_Check(value) || PyUnicode_Check(value)) { - /* Call setfunc */ - PyCArgObject *parg; - StgDictObject *dict = PyType_stgdict(type); - parg = new_CArgObject(); - parg->pffi_type = &ffi_type_pointer; - parg->obj = dict->setfunc(&parg->value, value, 0, type); - if (parg->obj == NULL) { - Py_DECREF(parg); - return NULL; - } - return (PyObject *)parg; - } if (ArrayObject_Check(value) || PointerObject_Check(value)) { /* c_char array instance or pointer(c_char(...)) */ ! StgDictObject *dt = PyObject_stgdict(value); ! StgDictObject *dict = dt && dt->itemtype ? PyType_stgdict(dt->itemtype) : NULL; ! if (dict && (dict->setfunc == itemdict->setfunc)) { Py_INCREF(value); return value; --- 1217,1225 ---- { StgDictObject *typedict = PyType_stgdict(type); if (ArrayObject_Check(value) || PointerObject_Check(value)) { /* c_char array instance or pointer(c_char(...)) */ ! PyObject *valueitemtype = PyObject_stgdict(value)->itemtype; ! if (PyObject_IsSubclass(valueitemtype, typedict->itemtype)) { Py_INCREF(value); return value; *************** *** 1248,1254 **** if (PyCArg_CheckExact(value)) { /* byref(c_char(...)) */ ! PyCArgObject *a = (PyCArgObject *)value; ! StgDictObject *dict = PyObject_stgdict(a->obj); ! if (dict && (dict->setfunc == itemdict->setfunc)) { Py_INCREF(value); return value; --- 1228,1233 ---- if (PyCArg_CheckExact(value)) { /* byref(c_char(...)) */ ! PyCArgObject *a = (PyCArgObject *)value; ! if (PyObject_IsInstance(a->obj, typedict->itemtype)) { Py_INCREF(value); return value; *************** *** 1259,1262 **** --- 1238,1256 ---- return value; } + /* z_set and Z_set accept integers as well. Until that is fixed, we + have to typecheck here. */ + if (value == Py_None || PyString_Check(value) || PyUnicode_Check(value)) { + /* Call setfunc */ + PyCArgObject *parg; + + parg = new_CArgObject(); + parg->pffi_type = &ffi_type_pointer; + parg->obj = typedict->setfunc(&parg->value, value, 0, type); + if (parg->obj == NULL) { + Py_DECREF(parg); + return NULL; + } + return (PyObject *)parg; + } /* XXX better message */ PyErr_SetString(PyExc_TypeError, *************** *** 1828,1834 **** CData_Type */ - - char basespec_string[] = "base specification"; - static int CData_traverse(CDataObject *self, visitproc visit, void *arg) --- 1822,1825 ---- *************** *** 1848,1852 **** have to call SysFreeString. */ ! if (PyObject_IsInstance(self, CTYPE_BSTR)) { if (*(BSTR *)self->b_ptr) SysFreeString(*(BSTR *)self->b_ptr); --- 1839,1843 ---- have to call SysFreeString. */ ! if (PyObject_IsInstance((PyObject *)self, CTYPE_BSTR)) { if (*(BSTR *)self->b_ptr) SysFreeString(*(BSTR *)self->b_ptr); |
From: Thomas H. <th...@us...> - 2005-04-06 15:25:12
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7374 Modified Files: test_parameters.py Log Message: POINTER.from_param(None) returns None instead of integer 0. Index: test_parameters.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_parameters.py,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** test_parameters.py 16 Mar 2005 19:53:18 -0000 1.28 --- test_parameters.py 6 Apr 2005 15:25:03 -0000 1.29 *************** *** 98,102 **** self.failUnlessEqual(LPINT(c_int(42)).contents.value, 42) ! self.failUnlessEqual(LPINT.from_param(None), 0) if c_int != c_long: --- 98,102 ---- self.failUnlessEqual(LPINT(c_int(42)).contents.value, 42) ! self.failUnlessEqual(LPINT.from_param(None), None) if c_int != c_long: |
From: Thomas H. <th...@us...> - 2005-04-06 15:11:52
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2658 Modified Files: callproc.c Log Message: Some comments. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.142 retrieving revision 1.143 diff -C2 -d -r1.142 -r1.143 *** callproc.c 6 Apr 2005 14:40:10 -0000 1.142 --- callproc.c 6 Apr 2005 15:11:43 -0000 1.143 *************** *** 392,398 **** --- 392,400 ---- pa->keep = NULL; /* so we cannot forget it later */ + /* ctypes instances know themselves how to pass as argument */ if (stgdict) return stgdict->asparam((CDataObject *)obj, pa); + /* probably a byref(obj) parameter */ if (PyCArg_CheckExact(obj)) { PyCArgObject *carg = (PyCArgObject *)obj; *************** *** 404,408 **** } ! /* Pass as integer by calling i_set */ if (PyInt_Check(obj) || PyLong_Check(obj)) { pa->ffi_type = &ffi_type_sint; --- 406,410 ---- } ! /* Pass as integer by calling i_set() */ if (PyInt_Check(obj) || PyLong_Check(obj)) { pa->ffi_type = &ffi_type_sint; *************** *** 413,417 **** } ! /* Pass as pointer by calling z_set */ if (obj == Py_None || PyString_Check(obj)) { pa->ffi_type = &ffi_type_pointer; --- 415,419 ---- } ! /* Pass as pointer by calling z_set() */ if (obj == Py_None || PyString_Check(obj)) { pa->ffi_type = &ffi_type_pointer; *************** *** 422,429 **** } #ifdef CTYPES_UNICODE ! /* Pass as pointer by calling Z_set */ if (PyUnicode_Check(obj)) { pa->ffi_type = &ffi_type_pointer; ! pa->keep = getentry("Z")->setfunc(&pa->value, obj, 0, NULL); /* CTYPE_c_char_p? */ if (pa->keep == NULL) return -1; --- 424,431 ---- } #ifdef CTYPES_UNICODE ! /* Pass as pointer by calling Z_set() */ if (PyUnicode_Check(obj)) { pa->ffi_type = &ffi_type_pointer; ! pa->keep = getentry("Z")->setfunc(&pa->value, obj, 0, NULL); /* CTYPE_c_wchar_p? */ if (pa->keep == NULL) return -1; *************** *** 650,653 **** --- 652,659 ---- * exception string. */ + /* + We should probably get rid of this function, and instead add a stack frame + with _AddTraceback. + */ void Extend_Error_Info(PyObject *exc_class, char *fmt, ...) { |
From: Thomas H. <th...@us...> - 2005-04-06 15:10:41
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2405 Modified Files: callbacks.c Log Message: Why the hell was that code here? Index: callbacks.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v retrieving revision 1.76 retrieving revision 1.77 diff -C2 -d -r1.76 -r1.77 *** callbacks.c 1 Apr 2005 10:23:08 -0000 1.76 --- callbacks.c 6 Apr 2005 15:10:28 -0000 1.77 *************** *** 370,376 **** void init_callbacks_in_module(PyObject *m) { - if (PyType_Ready((PyTypeObject *)&PyType_Type) < 0) - return; - #ifndef CTYPES_USE_GILSTATE g_interp = PyThreadState_Get()->interp; --- 370,373 ---- |
From: Thomas H. <th...@us...> - 2005-04-06 14:40:20
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26513 Modified Files: callproc.c Log Message: Rename ConvParam to PyObject_asparam. The signature is identical now to ASPARM, except that a third parameter is passed which specifies the argument number we're converting. This function now calls the corresponding setfuncs for each Python type. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.141 retrieving revision 1.142 diff -C2 -d -r1.141 -r1.142 *** callproc.c 6 Apr 2005 07:29:35 -0000 1.141 --- callproc.c 6 Apr 2005 14:40:10 -0000 1.142 *************** *** 34,41 **** 5. If 'converters' are present (converters is a sequence of argtypes' from_param methods), for each item in 'callargs' converter is called and the ! result passed to ConvParam. If 'converters' are not present, each argument is directly passed to ConvParm. ! 6. For each arg, ConvParam stores the contained C data (or a pointer to it, for structures) into the 'struct argument' array. --- 34,41 ---- 5. If 'converters' are present (converters is a sequence of argtypes' from_param methods), for each item in 'callargs' converter is called and the ! result passed to PyObject_asparam. If 'converters' are not present, each argument is directly passed to ConvParm. ! 6. For each arg, PyObject_asparam stores the contained C data (or a pointer to it, for structures) into the 'struct argument' array. *************** *** 385,423 **** /****************************************************************/ ! /* ! * Convert a PyObject * into a parameter suitable to pass to an ! * C function call. ! * ! * 1. Python integers are converted to C int and passed by value. ! * ! * 2. 3-tuples are expected to have a format character in the first ! * item, which must be 'i', 'f', 'd', 'q', or 'P'. ! * The second item will have to be an integer, float, double, long long ! * or integer (denoting an address void *), will be converted to the ! * corresponding C data type and passed by value. ! * ! * 3. Other Python objects are tested for an '_as_parameter_' attribute. ! * The value of this attribute must be an integer which will be passed ! * by value, or a 2-tuple or 3-tuple which will be used according ! * to point 2 above. The third item (if any), is ignored. It is normally ! * used to keep the object alive where this parameter refers to. ! * XXX This convention is dangerous - you can construct arbitrary tuples ! * in Python and pass them. Would it be safer to use a custom container ! * datatype instead of a tuple? ! * ! * 4. Other Python objects cannot be passed as parameters - an exception is raised. ! * ! * 5. ConvParam will store the converted result in a struct containing format ! * and value. ! */ ! ! /* ! * Convert a single Python object into a PyCArgObject and return it. ! */ ! static int ConvParam(PyObject *obj, int index, struct argument *pa) { ! StgDictObject *stgdict; pa->keep = NULL; /* so we cannot forget it later */ if (PyCArg_CheckExact(obj)) { PyCArgObject *carg = (PyCArgObject *)obj; --- 385,398 ---- /****************************************************************/ ! static int PyObject_asparam(PyObject *obj, struct argument *pa, int index) { ! StgDictObject *stgdict = PyObject_stgdict(obj); ! PyObject *arg; pa->keep = NULL; /* so we cannot forget it later */ + + if (stgdict) + return stgdict->asparam((CDataObject *)obj, pa); + if (PyCArg_CheckExact(obj)) { PyCArgObject *carg = (PyCArgObject *)obj; *************** *** 429,531 **** } ! /* check for None, integer, string or unicode and use directly if successful */ ! if (obj == Py_None) { ! pa->ffi_type = &ffi_type_pointer; ! pa->value.p = NULL; ! return 0; ! } ! ! if (PyInt_Check(obj)) { ! pa->ffi_type = &ffi_type_sint; ! pa->value.l = PyInt_AS_LONG(obj); ! return 0; ! } ! ! if (PyLong_Check(obj)) { pa->ffi_type = &ffi_type_sint; ! pa->value.l = (long)PyLong_AsUnsignedLong(obj); ! if (pa->value.l == -1 && PyErr_Occurred()) { ! PyErr_Clear(); ! pa->value.l = PyLong_AsLong(obj); ! if (pa->value.l == -1 && PyErr_Occurred()) { ! PyErr_SetString(PyExc_OverflowError, ! "long int too long to convert"); ! return -1; ! } ! } return 0; } ! if (PyString_Check(obj)) { pa->ffi_type = &ffi_type_pointer; ! pa->value.p = PyString_AS_STRING(obj); ! Py_INCREF(obj); ! pa->keep = obj; return 0; } - #ifdef CTYPES_UNICODE if (PyUnicode_Check(obj)) { - #ifdef HAVE_USABLE_WCHAR_T pa->ffi_type = &ffi_type_pointer; ! pa->value.p = PyUnicode_AS_UNICODE(obj); ! Py_INCREF(obj); ! pa->keep = obj; ! return 0; ! #else ! int size = PyUnicode_GET_SIZE(obj); ! size += 1; /* terminating NUL */ ! size *= sizeof(wchar_t); ! pa->value.p = PyMem_Malloc(size); ! if (!pa->value.p) ! return -1; ! memset(pa->value.p, 0, size); ! pa->keep = PyCObject_FromVoidPtr(pa->value.p, PyMem_Free); ! if (!pa->keep) { ! PyMem_Free(pa->value.p); ! return -1; ! } ! if (-1 == PyUnicode_AsWideChar((PyUnicodeObject *)obj, ! pa->value.p, PyUnicode_GET_SIZE(obj))) return -1; return 0; - #endif } #endif ! stgdict = PyObject_stgdict(obj); ! if (stgdict && stgdict->asparam) { ! /* If it has an stgdict, it must be a CDataObject */ ! return stgdict->asparam((CDataObject *)obj, pa); ! } else { ! PyObject *arg; ! arg = PyObject_GetAttrString(obj, "_as_parameter_"); ! /* Which types should we exactly allow here? ! integers are required for using Python classes ! as parameters (they have to expose the '_as_parameter_' ! attribute) ! */ ! if (arg == 0) { ! PyErr_Format(PyExc_TypeError, ! "Don't know how to convert parameter %d", index); ! return -1; ! } ! if (PyCArg_CheckExact(arg)) { ! PyCArgObject *carg = (PyCArgObject *)arg; ! pa->ffi_type = carg->pffi_type; ! memcpy(&pa->value, &carg->value, sizeof(pa->value)); ! pa->keep = arg; ! return 0; ! } ! if (PyInt_Check(arg)) { ! pa->ffi_type = &ffi_type_sint; ! pa->value.l = PyInt_AS_LONG(arg); ! pa->keep = arg; ! return 0; ! } ! Py_DECREF(arg); PyErr_Format(PyExc_TypeError, "Don't know how to convert parameter %d", index); return -1; } } --- 404,465 ---- } ! /* Pass as integer by calling i_set */ ! if (PyInt_Check(obj) || PyLong_Check(obj)) { pa->ffi_type = &ffi_type_sint; ! pa->keep = getentry("i")->setfunc(&pa->value, obj, 0, NULL); /* CTYPE_c_int? */ ! if (pa->keep == NULL) ! return -1; return 0; } ! /* Pass as pointer by calling z_set */ ! if (obj == Py_None || PyString_Check(obj)) { pa->ffi_type = &ffi_type_pointer; ! pa->keep = getentry("z")->setfunc(&pa->value, obj, 0, NULL); /* CTYPE_c_char_p? */ ! if (pa->keep == NULL) ! return -1; return 0; } #ifdef CTYPES_UNICODE + /* Pass as pointer by calling Z_set */ if (PyUnicode_Check(obj)) { pa->ffi_type = &ffi_type_pointer; ! pa->keep = getentry("Z")->setfunc(&pa->value, obj, 0, NULL); /* CTYPE_c_char_p? */ ! if (pa->keep == NULL) return -1; return 0; } #endif ! ! arg = PyObject_GetAttrString(obj, "_as_parameter_"); ! /* Which types should we exactly allow here? ! integers are required for using Python classes ! as parameters (they have to expose the '_as_parameter_' ! attribute) ! */ ! if (arg == 0) { PyErr_Format(PyExc_TypeError, "Don't know how to convert parameter %d", index); return -1; } + if (PyCArg_CheckExact(arg)) { + PyCArgObject *carg = (PyCArgObject *)arg; + pa->ffi_type = carg->pffi_type; + memcpy(&pa->value, &carg->value, sizeof(pa->value)); + /* consumes the refcount: */ + pa->keep = arg; + return 0; + } + if (PyInt_Check(arg)) { + pa->ffi_type = &ffi_type_sint; + pa->value.l = PyInt_AS_LONG(arg); + /* consumes the refcount: */ + pa->keep = arg; + return 0; + } + Py_DECREF(arg); + PyErr_Format(PyExc_TypeError, + "Don't know how to convert parameter %d", index); + return -1; } *************** *** 816,820 **** } ! err = ConvParam(v, i+1, pa); Py_DECREF(v); if (-1 == err) { --- 750,754 ---- } ! err = PyObject_asparam(v, pa, i+1); Py_DECREF(v); if (-1 == err) { *************** *** 823,827 **** } } else { ! err = ConvParam(arg, i+1, pa); if (-1 == err) { Extend_Error_Info(PyExc_ArgError, "argument %d: ", i+1); --- 757,761 ---- } } else { ! err = PyObject_asparam(arg, pa, i+1); if (-1 == err) { Extend_Error_Info(PyExc_ArgError, "argument %d: ", i+1); *************** *** 989,993 **** a.keep = b.keep = NULL; ! if (-1 == ConvParam(p1, 0, &a) || -1 == ConvParam(p2, 1, &b)) goto done; src = (IUnknown *)a.value.p; --- 923,927 ---- a.keep = b.keep = NULL; ! if (-1 == PyObject_asparam(p1, &a, 0) || -1 == PyObject_asparam(p2, &b, 1)) goto done; src = (IUnknown *)a.value.p; *************** *** 1286,1290 **** return NULL; memset(&a, 0, sizeof(struct argument)); ! if (-1 == ConvParam(obj, 1, &a)) return NULL; result = (CDataObject *)PyObject_CallFunctionObjArgs(ctype, NULL); --- 1220,1224 ---- return NULL; memset(&a, 0, sizeof(struct argument)); ! if (-1 == PyObject_asparam(obj, &a, 1)) return NULL; result = (CDataObject *)PyObject_CallFunctionObjArgs(ctype, NULL); *************** *** 1319,1325 **** if (!PyArg_ParseTuple(args, "OOi", &dst, &src, &size)) return NULL; ! if (-1 == ConvParam(dst, 1, &a_dst)) goto done; ! if (-1 == ConvParam(src, 2, &a_src)) goto done; c_result = memmove(a_dst.value.p, a_src.value.p, size); --- 1253,1259 ---- if (!PyArg_ParseTuple(args, "OOi", &dst, &src, &size)) return NULL; ! if (-1 == PyObject_asparam(dst, &a_dst, 1)) goto done; ! if (-1 == PyObject_asparam(src, &a_src, 2)) goto done; c_result = memmove(a_dst.value.p, a_src.value.p, size); *************** *** 1346,1350 **** return NULL; memset(&a_dst, 0, sizeof(struct argument)); ! if (-1 == ConvParam(dst, 1, &a_dst)) return NULL; c_result = memset(a_dst.value.p, c, count); --- 1280,1284 ---- return NULL; memset(&a_dst, 0, sizeof(struct argument)); ! if (-1 == PyObject_asparam(dst, &a_dst, 1)) return NULL; c_result = memset(a_dst.value.p, c, count); *************** *** 1370,1374 **** return NULL; memset(&a_arg, 0, sizeof(struct argument)); ! if (-1 == ConvParam(src, 1, &a_arg)) return NULL; if (PyTuple_GET_SIZE(args) == 1) --- 1304,1308 ---- return NULL; memset(&a_arg, 0, sizeof(struct argument)); ! if (-1 == PyObject_asparam(src, &a_arg, 1)) return NULL; if (PyTuple_GET_SIZE(args) == 1) *************** *** 1397,1401 **** return NULL; memset(&a_arg, 0, sizeof(struct argument)); ! if (-1 == ConvParam(src, 1, &a_arg)) return NULL; if (PyTuple_GET_SIZE(args) == 1) --- 1331,1335 ---- return NULL; memset(&a_arg, 0, sizeof(struct argument)); ! if (-1 == PyObject_asparam(src, &a_arg, 1)) return NULL; if (PyTuple_GET_SIZE(args) == 1) |
From: Thomas H. <th...@us...> - 2005-04-06 14:38:09
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25758 Modified Files: cfield.c Log Message: Remove the assert(type) in the ?_set functions. It is allowed to call them with type of NULL. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.107 retrieving revision 1.108 diff -C2 -d -r1.107 -r1.108 *** cfield.c 5 Apr 2005 19:01:48 -0000 1.107 --- cfield.c 6 Apr 2005 14:38:00 -0000 1.108 *************** *** 439,443 **** { long val; - assert(type); if (get_long(value, &val) < 0) return NULL; --- 439,442 ---- *************** *** 459,463 **** { unsigned long val; - assert(type); if (get_ulong(value, &val) < 0) return NULL; --- 458,461 ---- *************** *** 480,484 **** { long val; - assert(type); if (get_long(value, &val) < 0) return NULL; --- 478,481 ---- *************** *** 500,504 **** { unsigned long val; - assert(type); if (get_ulong(value, &val) < 0) return NULL; --- 497,500 ---- *************** *** 525,529 **** { long val; - assert(type); if (get_long(value, &val) < 0) return NULL; --- 521,524 ---- *************** *** 546,550 **** vBOOL_set(void *ptr, PyObject *value, unsigned size, PyObject *type) { - assert(type); switch (PyObject_IsTrue(value)) { case -1: --- 541,544 ---- *************** *** 574,578 **** { unsigned long val; - assert(type); if (get_ulong(value, &val) < 0) return NULL; --- 568,571 ---- *************** *** 595,599 **** { long val; - assert(type); if (get_long(value, &val) < 0) return NULL; --- 588,591 ---- *************** *** 615,619 **** { unsigned long val; - assert(type); if (get_ulong(value, &val) < 0) return NULL; --- 607,610 ---- *************** *** 636,640 **** { PY_LONG_LONG val; - assert(type); if (get_longlong(value, &val) < 0) return NULL; --- 627,630 ---- *************** *** 655,659 **** { unsigned PY_LONG_LONG val; - assert(type); if (get_ulonglong(value, &val) < 0) return NULL; --- 645,648 ---- *************** *** 681,685 **** { double x; - assert(type); x = PyFloat_AsDouble(value); if (x == -1 && PyErr_Occurred()) { --- 670,673 ---- *************** *** 703,707 **** { float x; - assert(type); x = (float)PyFloat_AsDouble(value); if (x == -1 && PyErr_Occurred()) { --- 691,694 ---- *************** *** 738,742 **** O_set(void *ptr, PyObject *value, unsigned size, PyObject *type) { - assert(type); *(PyObject **)ptr = value; Py_INCREF(value); --- 725,728 ---- *************** *** 748,752 **** c_set(void *ptr, PyObject *value, unsigned size, PyObject *type) { - assert(type); if (!PyString_Check(value) || (1 != PyString_Size(value))) { PyErr_Format(PyExc_TypeError, --- 734,737 ---- *************** *** 771,775 **** { int len; - assert(type); if (PyString_Check(value)) { value = PyUnicode_FromEncodedObject(value, --- 756,759 ---- *************** *** 812,816 **** z_set(void *ptr, PyObject *value, unsigned size, PyObject *type) { - assert(type); if (value == Py_None) { *(char **)ptr = NULL; --- 796,799 ---- *************** *** 857,861 **** Z_set(void *ptr, PyObject *value, unsigned size, PyObject *type) { - assert(type); if (value == Py_None) { *(wchar_t **)ptr = NULL; --- 840,843 ---- *************** *** 937,941 **** { BSTR bstr; - assert(type); /* convert value into a PyUnicodeObject or NULL */ if (Py_None == value) { --- 919,922 ---- *************** *** 997,1001 **** { void *v; - assert(type); if (value == Py_None) { *(void **)ptr = NULL; --- 978,981 ---- |
From: Thomas H. <th...@us...> - 2005-04-06 14:02:09
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16475 Modified Files: _ctypes.c Log Message: Clean up another typecheck. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.286 retrieving revision 1.287 diff -C2 -d -r1.286 -r1.287 *** _ctypes.c 6 Apr 2005 13:39:54 -0000 1.286 --- _ctypes.c 6 Apr 2005 14:01:51 -0000 1.287 *************** *** 3674,3678 **** { PyListObject *np; ! StgDictObject *stgdict, *itemdict; int i, len; --- 3674,3678 ---- { PyListObject *np; ! StgDictObject *stgdict; int i, len; *************** *** 3684,3694 **** stgdict = PyObject_stgdict((PyObject *)self); ! itemdict = PyType_stgdict(stgdict->itemtype); ! ! if (itemdict->getfunc == getentry("c")->getfunc) { char *ptr = *(char **)self->b_ptr; return PyString_FromStringAndSize(ptr + ilow, len); #ifdef CTYPES_UNICODE ! } else if (itemdict->getfunc == getentry("u")->getfunc) { wchar_t *ptr = *(wchar_t **)self->b_ptr; return PyUnicode_FromWideChar(ptr + ilow, len); --- 3684,3692 ---- stgdict = PyObject_stgdict((PyObject *)self); ! if (stgdict->itemtype == CTYPE_c_char) { char *ptr = *(char **)self->b_ptr; return PyString_FromStringAndSize(ptr + ilow, len); #ifdef CTYPES_UNICODE ! } else if (stgdict->itemtype == CTYPE_c_wchar) { wchar_t *ptr = *(wchar_t **)self->b_ptr; return PyUnicode_FromWideChar(ptr + ilow, len); |
From: Thomas H. <th...@us...> - 2005-04-06 13:40:03
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10906 Modified Files: _ctypes.c Log Message: *** empty log message *** Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.285 retrieving revision 1.286 diff -C2 -d -r1.285 -r1.286 *** _ctypes.c 6 Apr 2005 13:36:40 -0000 1.285 --- _ctypes.c 6 Apr 2005 13:39:54 -0000 1.286 *************** *** 3181,3185 **** Array_item(CDataObject *self, int index) { - int offset, size; PyObject *itemtype; StgDictObject *stgdict; --- 3181,3184 ---- *************** *** 3195,3202 **** stgdict = PyType_stgdict(itemtype); ! size = stgdict->size; ! offset = index * size; ! ! return stgdict->getfunc(self->b_ptr + offset, size, itemtype, self, index); } --- 3194,3198 ---- stgdict = PyType_stgdict(itemtype); ! return stgdict->getfunc(self->b_ptr + stgdict->size * index, stgdict->size, itemtype, self, index); } |
From: Thomas H. <th...@us...> - 2005-04-06 13:36:49
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10174 Modified Files: _ctypes.c Log Message: Another typecheck prettyfied. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.284 retrieving revision 1.285 diff -C2 -d -r1.284 -r1.285 *** _ctypes.c 6 Apr 2005 13:23:29 -0000 1.284 --- _ctypes.c 6 Apr 2005 13:36:40 -0000 1.285 *************** *** 3205,3209 **** Array_slice(CDataObject *self, int ilow, int ihigh) { ! StgDictObject *stgdict, *itemdict; PyListObject *np; int i, len; --- 3205,3209 ---- Array_slice(CDataObject *self, int ilow, int ihigh) { ! StgDictObject *stgdict; PyListObject *np; int i, len; *************** *** 3220,3231 **** stgdict = PyObject_stgdict((PyObject *)self); ! itemdict = PyType_stgdict(stgdict->itemtype); ! ! /* XXX XXX XXX Can we use getfunc here? */ ! if (itemdict->getfunc == getentry("c")->getfunc) { char *ptr = (char *)self->b_ptr; return PyString_FromStringAndSize(ptr + ilow, len); #ifdef CTYPES_UNICODE ! } else if (itemdict->getfunc == getentry("u")->getfunc) { wchar_t *ptr = (wchar_t *)self->b_ptr; return PyUnicode_FromWideChar(ptr + ilow, len); --- 3220,3228 ---- stgdict = PyObject_stgdict((PyObject *)self); ! if (stgdict->itemtype == CTYPE_c_char) { char *ptr = (char *)self->b_ptr; return PyString_FromStringAndSize(ptr + ilow, len); #ifdef CTYPES_UNICODE ! } else if (stgdict->itemtype == CTYPE_c_wchar) { wchar_t *ptr = (wchar_t *)self->b_ptr; return PyUnicode_FromWideChar(ptr + ilow, len); |
From: Thomas H. <th...@us...> - 2005-04-06 13:23:38
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6299 Modified Files: _ctypes.c Log Message: Clean up some typechecks. Add in CTYPE_ prefix to the variables holding some ctypes types. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.283 retrieving revision 1.284 diff -C2 -d -r1.283 -r1.284 *** _ctypes.c 6 Apr 2005 11:18:07 -0000 1.283 --- _ctypes.c 6 Apr 2005 13:23:29 -0000 1.284 *************** *** 170,173 **** --- 170,176 ---- static PyObject *CData_AtAddress(PyObject *type, void *buf); + /* Some simple types */ + static PyObject *CTYPE_c_char, *CTYPE_c_wchar, *CTYPE_c_void_p, *CTYPE_BSTR; + static PyObject * generic_getfunc(void *ptr, unsigned size, *************** *** 1138,1146 **** A permanent annoyance: char arrays are also strings! */ ! /* ! What we really want to check here is if proto is c_char or c_wchar. ! XXX XXX XXX ! */ ! if (itemdict->getfunc == getentry("c")->getfunc) { if (-1 == add_getset(result, CharArray_getsets)) return NULL; --- 1141,1145 ---- A permanent annoyance: char arrays are also strings! */ ! if (proto == CTYPE_c_char) { if (-1 == add_getset(result, CharArray_getsets)) return NULL; *************** *** 1148,1152 **** stgdict->setfunc = CharArray_setfunc; #ifdef CTYPES_UNICODE ! } else if (itemdict->getfunc == getentry("u")->getfunc) { if (-1 == add_getset(result, WCharArray_getsets)) return NULL; --- 1147,1151 ---- stgdict->setfunc = CharArray_setfunc; #ifdef CTYPES_UNICODE ! } else if (proto == CTYPE_c_wchar) { if (-1 == add_getset(result, WCharArray_getsets)) return NULL; *************** *** 1216,1222 **** static char *SIMPLE_TYPE_CHARS = "cbBhHiIlLdfuzZqQPXOv"; - /* We need access to some simple types */ - static PyObject *c_char, *c_wchar, *c_void_p; - static PyObject * string_ptr_from_param(PyObject *type, PyObject *value) --- 1215,1218 ---- *************** *** 1323,1327 **** } stgd = PyObject_stgdict(value); ! if (stgd && (stgd->itemtype == c_char || stgd->itemtype == c_wchar)) { PyCArgObject *parg = new_CArgObject(); if (parg == NULL) --- 1319,1323 ---- } stgd = PyObject_stgdict(value); ! if (stgd && (stgd->itemtype == CTYPE_c_char || stgd->itemtype == CTYPE_c_wchar)) { PyCArgObject *parg = new_CArgObject(); if (parg == NULL) *************** *** 1420,1424 **** case 'z': /* c_char_p */ ml = &c_char_p_method; ! if (c_char == NULL) { PyErr_SetString(PyExc_RuntimeError, "Need to define c_char before c_char_p"); --- 1416,1420 ---- case 'z': /* c_char_p */ ml = &c_char_p_method; ! if (CTYPE_c_char == NULL) { PyErr_SetString(PyExc_RuntimeError, "Need to define c_char before c_char_p"); *************** *** 1426,1435 **** } Py_XDECREF(stgdict->itemtype); ! Py_INCREF(c_char); ! stgdict->itemtype = c_char; break; case 'Z': /* c_wchar_p */ ml = &c_wchar_p_method; ! if (c_wchar == NULL) { PyErr_SetString(PyExc_RuntimeError, "Need to define c_wchar before c_wchar_p"); --- 1422,1431 ---- } Py_XDECREF(stgdict->itemtype); ! Py_INCREF(CTYPE_c_char); ! stgdict->itemtype = CTYPE_c_char; break; case 'Z': /* c_wchar_p */ ml = &c_wchar_p_method; ! if (CTYPE_c_wchar == NULL) { PyErr_SetString(PyExc_RuntimeError, "Need to define c_wchar before c_wchar_p"); *************** *** 1437,1456 **** } Py_XDECREF(stgdict->itemtype); ! Py_INCREF(c_wchar); ! stgdict->itemtype = c_wchar; break; case 'P': /* c_void_p */ ml = &c_void_p_method; ! assert(c_void_p == NULL); Py_INCREF(result); ! c_void_p = (PyObject *)result; break; case 'c': /* c_char */ ! assert(c_char == NULL); ! c_char = (PyObject *)result; break; case 'u': /* c_wchar */ ! assert(c_wchar == NULL); ! c_wchar = (PyObject *)result; break; } --- 1433,1456 ---- } Py_XDECREF(stgdict->itemtype); ! Py_INCREF(CTYPE_c_wchar); ! stgdict->itemtype = CTYPE_c_wchar; break; case 'P': /* c_void_p */ ml = &c_void_p_method; ! assert(CTYPE_c_void_p == NULL); Py_INCREF(result); ! CTYPE_c_void_p = (PyObject *)result; break; case 'c': /* c_char */ ! assert(CTYPE_c_char == NULL); ! CTYPE_c_char = (PyObject *)result; ! break; ! case 'X': /* BSTR */ ! assert(CTYPE_BSTR == NULL); ! CTYPE_BSTR = (PyObject *)result; break; case 'u': /* c_wchar */ ! assert(CTYPE_c_wchar == NULL); ! CTYPE_c_wchar = (PyObject *)result; break; } *************** *** 1845,1858 **** #ifdef MS_WIN32 if (self->b_base == NULL) { ! static SETFUNC BSTR_set; ! StgDictObject *dict = PyObject_stgdict((PyObject *)self); ! ! if (!BSTR_set) ! BSTR_set = getentry("X")->setfunc; ! ! /* A hack, but it works. If we own the memory (b_base is ! NULL), we also have to call SysFreeString. */ ! if (dict && dict->setfunc == BSTR_set) { if (*(BSTR *)self->b_ptr) SysFreeString(*(BSTR *)self->b_ptr); --- 1845,1852 ---- #ifdef MS_WIN32 if (self->b_base == NULL) { ! /* If a BSTR instance owns the memory (b_base is NULL), we ! have to call SysFreeString. */ ! if (PyObject_IsInstance(self, CTYPE_BSTR)) { if (*(BSTR *)self->b_ptr) SysFreeString(*(BSTR *)self->b_ptr); |
From: Thomas H. <th...@us...> - 2005-04-06 13:18:47
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4964 Modified Files: __init__.py Log Message: BSTR is now created in ctypes. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** __init__.py 22 Mar 2005 15:22:30 -0000 1.27 --- __init__.py 6 Apr 2005 13:18:38 -0000 1.28 *************** *** 267,278 **** ################################################################ ! from ctypes import _SimpleCData ! ! class BSTR(_SimpleCData): ! _type_ = "X" ! def __repr__(self): ! return "%s(%r)" % (self.__class__.__name__, self.value) ! ! ################################################################ class helpstring(object): --- 267,271 ---- ################################################################ ! from ctypes import BSTR class helpstring(object): |
From: Thomas H. <th...@us...> - 2005-04-06 13:17:05
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4501 Modified Files: __init__.py Log Message: BSTR is now created in ctypes. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** __init__.py 6 Apr 2005 11:19:49 -0000 1.64 --- __init__.py 6 Apr 2005 13:16:56 -0000 1.65 *************** *** 221,224 **** --- 221,231 ---- c_voidp = c_void_p # backwards compatibility (to a bug) + if _os.name == "nt": + class BSTR(_SimpleCData): + _type_ = "X" + def __repr__(self): + return "%s(%r)" % (self.__class__.__name__, self.value) + + # This cache maps types to pointers to them. _pointer_type_cache = {} |
From: Thomas H. <th...@us...> - 2005-04-06 13:10:40
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2434 Modified Files: automation.py Log Message: BSTR is now created in ctypes. Index: automation.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/automation.py,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** automation.py 17 Feb 2005 15:05:25 -0000 1.21 --- automation.py 6 Apr 2005 13:10:31 -0000 1.22 *************** *** 89,100 **** # and BSTR's we pass to functions are freed too often ;-( ! from _ctypes import _SimpleCData ! ! class BSTR(_SimpleCData): ! _type_ = "X" ! def __repr__(self): ! return "%s(%r)" % (self.__class__.__name__, self.value) ! ! assert(sizeof(BSTR) == 4) ################################################################ --- 89,93 ---- # and BSTR's we pass to functions are freed too often ;-( ! from ctypes import BSTR ################################################################ |
From: Thomas H. <th...@us...> - 2005-04-06 11:20:00
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5453 Modified Files: __init__.py Log Message: Define c_wchar before c_wchar_p. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** __init__.py 5 Apr 2005 16:58:13 -0000 1.63 --- __init__.py 6 Apr 2005 11:19:49 -0000 1.64 *************** *** 253,261 **** set_conversion_mode("ascii", "strict") - class c_wchar_p(_SimpleCData): - _type_ = "Z" - def __repr__(self): - return "%s(%r)" % (self.__class__.__name__, self.value) - class c_wchar(_SimpleCData): _type_ = "u" --- 253,256 ---- *************** *** 263,266 **** --- 258,266 ---- return "c_wchar(%r)" % self.value + class c_wchar_p(_SimpleCData): + _type_ = "Z" + def __repr__(self): + return "%s(%r)" % (self.__class__.__name__, self.value) + POINTER(c_wchar).from_param = c_wchar_p.from_param #_SimpleCData.c_wchar_p_from_param |
From: Thomas H. <th...@us...> - 2005-04-06 11:18:18
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5041 Modified Files: _ctypes.c Log Message: Convert asserts into Python exceptions. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.282 retrieving revision 1.283 diff -C2 -d -r1.282 -r1.283 *** _ctypes.c 6 Apr 2005 11:13:52 -0000 1.282 --- _ctypes.c 6 Apr 2005 11:18:07 -0000 1.283 *************** *** 1420,1424 **** case 'z': /* c_char_p */ ml = &c_char_p_method; ! assert(c_char); Py_XDECREF(stgdict->itemtype); Py_INCREF(c_char); --- 1420,1428 ---- case 'z': /* c_char_p */ ml = &c_char_p_method; ! if (c_char == NULL) { ! PyErr_SetString(PyExc_RuntimeError, ! "Need to define c_char before c_char_p"); ! return NULL; /* don't care about refcount leaks */ ! } Py_XDECREF(stgdict->itemtype); Py_INCREF(c_char); *************** *** 1427,1431 **** case 'Z': /* c_wchar_p */ ml = &c_wchar_p_method; ! assert(c_wchar); Py_XDECREF(stgdict->itemtype); Py_INCREF(c_wchar); --- 1431,1439 ---- case 'Z': /* c_wchar_p */ ml = &c_wchar_p_method; ! if (c_wchar == NULL) { ! PyErr_SetString(PyExc_RuntimeError, ! "Need to define c_wchar before c_wchar_p"); ! return NULL; /* don't care about refcount leaks */ ! } Py_XDECREF(stgdict->itemtype); Py_INCREF(c_wchar); |
From: Thomas H. <th...@us...> - 2005-04-06 11:14:03
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3597 Modified Files: stgdict.c ctypes.h _ctypes.c Log Message: Rename the storage dict's proto member to itemtype. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.92 retrieving revision 1.93 diff -C2 -d -r1.92 -r1.93 *** ctypes.h 6 Apr 2005 07:29:35 -0000 1.92 --- ctypes.h 6 Apr 2005 11:13:52 -0000 1.93 *************** *** 223,227 **** int length; /* number of fields */ ffi_type ffi_type; ! PyObject *proto; SETFUNC setfunc; GETFUNC getfunc; --- 223,227 ---- int length; /* number of fields */ ffi_type ffi_type; ! PyObject *itemtype; /* for pointer and array classes */ SETFUNC setfunc; GETFUNC getfunc; Index: stgdict.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/stgdict.c,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** stgdict.c 1 Apr 2005 15:26:22 -0000 1.33 --- stgdict.c 6 Apr 2005 11:13:52 -0000 1.34 *************** *** 22,26 **** StgDict_clear(StgDictObject *self) { ! Py_CLEAR(self->proto); Py_CLEAR(self->argtypes); Py_CLEAR(self->converters); --- 22,26 ---- StgDict_clear(StgDictObject *self) { ! Py_CLEAR(self->itemtype); Py_CLEAR(self->argtypes); Py_CLEAR(self->converters); *************** *** 54,58 **** sizeof(StgDictObject) - sizeof(PyDictObject)); ! Py_XINCREF(dst->proto); Py_XINCREF(dst->argtypes); Py_XINCREF(dst->converters); --- 54,58 ---- sizeof(StgDictObject) - sizeof(PyDictObject)); ! Py_XINCREF(dst->itemtype); Py_XINCREF(dst->argtypes); Py_XINCREF(dst->converters); Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.281 retrieving revision 1.282 diff -C2 -d -r1.281 -r1.282 *** _ctypes.c 6 Apr 2005 10:32:18 -0000 1.281 --- _ctypes.c 6 Apr 2005 11:13:52 -0000 1.282 *************** *** 404,408 **** is an instance of the type's dict->proto */ if(dict && ob ! && PyObject_IsInstance(ob, dict->proto)) { Py_INCREF(value); return value; --- 404,408 ---- is an instance of the type's dict->proto */ if(dict && ob ! && PyObject_IsInstance(ob, dict->itemtype)) { Py_INCREF(value); return value; *************** *** 453,457 **** StgDictObject *dict = PyType_stgdict((PyObject *)self); if (dict) ! Py_CLEAR(dict->proto); return PyType_Type.tp_clear((PyObject *)self); } --- 453,457 ---- StgDictObject *dict = PyType_stgdict((PyObject *)self); if (dict) ! Py_CLEAR(dict->itemtype); return PyType_Type.tp_clear((PyObject *)self); } *************** *** 462,466 **** StgDictObject *dict = PyType_stgdict((PyObject *)self); if (dict) ! Py_VISIT(dict->proto); return PyType_Type.tp_traverse((PyObject *)self, visit, arg); } --- 462,466 ---- StgDictObject *dict = PyType_stgdict((PyObject *)self); if (dict) ! Py_VISIT(dict->itemtype); return PyType_Type.tp_traverse((PyObject *)self, visit, arg); } *************** *** 611,616 **** } Py_INCREF(proto); ! Py_XDECREF(stgdict->proto); ! stgdict->proto = proto; return 0; } --- 611,616 ---- } Py_INCREF(proto); ! Py_XDECREF(stgdict->itemtype); ! stgdict->itemtype = proto; return 0; } *************** *** 630,634 **** && ArrayObject_Check(value) /* Should we accept subclasses here? */ ! && dict->proto == PyType_stgdict(type)->proto) { *(void **)ptr = ((CDataObject *)value)->b_ptr; /* We need to keep the array alive, not just the arrays b_objects. */ --- 630,634 ---- && ArrayObject_Check(value) /* Should we accept subclasses here? */ ! && dict->itemtype == PyType_stgdict(type)->itemtype) { *(void **)ptr = ((CDataObject *)value)->b_ptr; /* We need to keep the array alive, not just the arrays b_objects. */ *************** *** 729,733 **** StgDictObject *v = PyObject_stgdict(value); StgDictObject *t = PyType_stgdict(type); ! if (PyObject_IsSubclass(v->proto, t->proto)) { Py_INCREF(value); return value; --- 729,733 ---- StgDictObject *v = PyObject_stgdict(value); StgDictObject *t = PyType_stgdict(type); ! if (PyObject_IsSubclass(v->itemtype, t->itemtype)) { Py_INCREF(value); return value; *************** *** 899,903 **** PyObject *type, CDataObject *src, int index) { ! int i; for (i = 0; i < size; ++i) if (((char *)ptr)[i] == '\0') --- 899,903 ---- PyObject *type, CDataObject *src, int index) { ! unsigned i; for (i = 0; i < size; ++i) if (((char *)ptr)[i] == '\0') *************** *** 1114,1118 **** stgdict->length = length; Py_INCREF(proto); ! stgdict->proto = proto; /* create the new instance (which is a class, --- 1114,1118 ---- stgdict->length = length; Py_INCREF(proto); ! stgdict->itemtype = proto; /* create the new instance (which is a class, *************** *** 1140,1143 **** --- 1140,1144 ---- /* What we really want to check here is if proto is c_char or c_wchar. + XXX XXX XXX */ if (itemdict->getfunc == getentry("c")->getfunc) { *************** *** 1222,1226 **** { StgDictObject *typedict = PyType_stgdict(type); ! StgDictObject *itemdict = PyType_stgdict(typedict->proto); /* z_set and Z_set accept integers as well. Until that is fixed, we --- 1223,1227 ---- { StgDictObject *typedict = PyType_stgdict(type); ! StgDictObject *itemdict = PyType_stgdict(typedict->itemtype); /* z_set and Z_set accept integers as well. Until that is fixed, we *************** *** 1243,1247 **** /* c_char array instance or pointer(c_char(...)) */ StgDictObject *dt = PyObject_stgdict(value); ! StgDictObject *dict = dt && dt->proto ? PyType_stgdict(dt->proto) : NULL; if (dict && (dict->setfunc == itemdict->setfunc)) { Py_INCREF(value); --- 1244,1248 ---- /* c_char array instance or pointer(c_char(...)) */ StgDictObject *dt = PyObject_stgdict(value); ! StgDictObject *dict = dt && dt->itemtype ? PyType_stgdict(dt->itemtype) : NULL; if (dict && (dict->setfunc == itemdict->setfunc)) { Py_INCREF(value); *************** *** 1322,1326 **** } stgd = PyObject_stgdict(value); ! if (stgd && (stgd->proto == c_char || stgd->proto == c_wchar)) { PyCArgObject *parg = new_CArgObject(); if (parg == NULL) --- 1323,1327 ---- } stgd = PyObject_stgdict(value); ! if (stgd && (stgd->itemtype == c_char || stgd->itemtype == c_wchar)) { PyCArgObject *parg = new_CArgObject(); if (parg == NULL) *************** *** 1420,1433 **** ml = &c_char_p_method; assert(c_char); ! Py_XDECREF(stgdict->proto); Py_INCREF(c_char); ! stgdict->proto = c_char; break; case 'Z': /* c_wchar_p */ ml = &c_wchar_p_method; assert(c_wchar); ! Py_XDECREF(stgdict->proto); Py_INCREF(c_wchar); ! stgdict->proto = c_wchar; break; case 'P': /* c_void_p */ --- 1421,1434 ---- ml = &c_char_p_method; assert(c_char); ! Py_XDECREF(stgdict->itemtype); Py_INCREF(c_char); ! stgdict->itemtype = c_char; break; case 'Z': /* c_wchar_p */ ml = &c_wchar_p_method; assert(c_wchar); ! Py_XDECREF(stgdict->itemtype); Py_INCREF(c_wchar); ! stgdict->itemtype = c_wchar; break; case 'P': /* c_void_p */ *************** *** 2635,2639 **** dict = PyType_stgdict(ob); /* Create an instance of the pointed-to type */ ! ob = PyObject_CallObject(dict->proto, NULL); if (ob == NULL) goto error; --- 2636,2640 ---- dict = PyType_stgdict(ob); /* Create an instance of the pointed-to type */ ! ob = PyObject_CallObject(dict->itemtype, NULL); if (ob == NULL) goto error; *************** *** 2657,2661 **** if (v == 0) goto error; ! ob = PyObject_CallFunctionObjArgs(dict->proto, v, NULL); --- 2658,2662 ---- if (v == 0) goto error; ! ob = PyObject_CallFunctionObjArgs(dict->itemtype, v, NULL); *************** *** 2747,2752 **** replace with a _from_outparam_ slot call. */ ! if (dict-> proto && PyString_CheckExact(dict->proto)) { ! char *fmt = PyString_AS_STRING(dict->proto); /* simple data type, but no pointer */ if (fmt[0] == 'P') { --- 2748,2754 ---- replace with a _from_outparam_ slot call. */ ! /* XXX XXX This needs to be fixed. dict->itemtype is NEVER a string any more. */ ! if (dict->itemtype && PyString_CheckExact(dict->itemtype)) { ! char *fmt = PyString_AS_STRING(dict->itemtype); /* simple data type, but no pointer */ if (fmt[0] == 'P') { *************** *** 3188,3192 **** stgdict = PyObject_stgdict((PyObject *)self); ! itemtype = stgdict->proto; stgdict = PyType_stgdict(itemtype); --- 3190,3194 ---- stgdict = PyObject_stgdict((PyObject *)self); ! itemtype = stgdict->itemtype; stgdict = PyType_stgdict(itemtype); *************** *** 3216,3221 **** stgdict = PyObject_stgdict((PyObject *)self); ! itemdict = PyType_stgdict(stgdict->proto); if (itemdict->getfunc == getentry("c")->getfunc) { char *ptr = (char *)self->b_ptr; --- 3218,3224 ---- stgdict = PyObject_stgdict((PyObject *)self); ! itemdict = PyType_stgdict(stgdict->itemtype); + /* XXX XXX XXX Can we use getfunc here? */ if (itemdict->getfunc == getentry("c")->getfunc) { char *ptr = (char *)self->b_ptr; *************** *** 3261,3265 **** offset = index * size; ! keep = _CData_set(self->b_ptr + offset, value, size, stgdict->proto); if (keep == NULL) return -1; --- 3264,3268 ---- offset = index * size; ! keep = _CData_set(self->b_ptr + offset, value, size, stgdict->itemtype); if (keep == NULL) return -1; *************** *** 3532,3536 **** assert(stgdict); ! proto = stgdict->proto; itemdict = PyType_stgdict(proto); size = itemdict->size; --- 3535,3539 ---- assert(stgdict); ! proto = stgdict->itemtype; itemdict = PyType_stgdict(proto); size = itemdict->size; *************** *** 3578,3582 **** size = stgdict->size / stgdict->length; ! keep = _CData_set(*(void **)self->b_ptr, value, size, stgdict->proto); if (keep == NULL) return -1; --- 3581,3585 ---- size = stgdict->size / stgdict->length; ! keep = _CData_set(*(void **)self->b_ptr, value, size, stgdict->itemtype); if (keep == NULL) return -1; *************** *** 3597,3601 **** stgdict = PyObject_stgdict((PyObject *)self); assert(stgdict); ! return CData_FromBaseObj(stgdict->proto, (PyObject *)self, 0, *(void **)self->b_ptr); --- 3600,3604 ---- stgdict = PyObject_stgdict((PyObject *)self); assert(stgdict); ! return CData_FromBaseObj(stgdict->itemtype, (PyObject *)self, 0, *(void **)self->b_ptr); *************** *** 3616,3624 **** stgdict = PyObject_stgdict((PyObject *)self); if (!CDataObject_Check(value) ! || 0 == PyObject_IsInstance(value, stgdict->proto)) { /* XXX PyObject_IsInstance could return -1! */ PyErr_Format(PyExc_TypeError, "expected %s instead of %s", ! ((PyTypeObject *)(stgdict->proto))->tp_name, value->ob_type->tp_name); return -1; --- 3619,3627 ---- stgdict = PyObject_stgdict((PyObject *)self); if (!CDataObject_Check(value) ! || 0 == PyObject_IsInstance(value, stgdict->itemtype)) { /* XXX PyObject_IsInstance could return -1! */ PyErr_Format(PyExc_TypeError, "expected %s instead of %s", ! ((PyTypeObject *)(stgdict->itemtype))->tp_name, value->ob_type->tp_name); return -1; *************** *** 3686,3690 **** stgdict = PyObject_stgdict((PyObject *)self); ! itemdict = PyType_stgdict(stgdict->proto); if (itemdict->getfunc == getentry("c")->getfunc) { --- 3689,3693 ---- stgdict = PyObject_stgdict((PyObject *)self); ! itemdict = PyType_stgdict(stgdict->itemtype); if (itemdict->getfunc == getentry("c")->getfunc) { |
From: Thomas H. <th...@us...> - 2005-04-06 10:32:34
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25617 Modified Files: _ctypes.c Log Message: The storagedict's proto member doesn't point to a string object anymore. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.280 retrieving revision 1.281 diff -C2 -d -r1.280 -r1.281 *** _ctypes.c 6 Apr 2005 10:18:27 -0000 1.280 --- _ctypes.c 6 Apr 2005 10:32:18 -0000 1.281 *************** *** 1227,1230 **** --- 1227,1231 ---- have to typecheck here. */ if (value == Py_None || PyString_Check(value) || PyUnicode_Check(value)) { + /* Call setfunc */ PyCArgObject *parg; StgDictObject *dict = PyType_stgdict(type); *************** *** 1321,1336 **** } stgd = PyObject_stgdict(value); ! if (stgd) { ! if (stgd->proto == c_char || stgd->proto == c_wchar) { ! PyCArgObject *parg = new_CArgObject(); ! if (parg == NULL) ! return NULL; ! parg->pffi_type = &ffi_type_pointer; ! Py_INCREF(value); ! parg->obj = value; ! /* Remember: b_ptr points to where the pointer is stored! */ ! parg->value.p = *(void **)(((CDataObject *)value)->b_ptr); ! return (PyObject *)parg; ! } } /* XXX better message */ --- 1322,1335 ---- } stgd = PyObject_stgdict(value); ! if (stgd && (stgd->proto == c_char || stgd->proto == c_wchar)) { ! PyCArgObject *parg = new_CArgObject(); ! if (parg == NULL) ! return NULL; ! parg->pffi_type = &ffi_type_pointer; ! Py_INCREF(value); ! parg->obj = value; ! /* Remember: b_ptr points to where the pointer is stored! */ ! parg->value.p = *(void **)(((CDataObject *)value)->b_ptr); ! return (PyObject *)parg; } /* XXX better message */ *************** *** 1387,1392 **** stgdict = (StgDictObject *)PyObject_CallObject( (PyObject *)&StgDict_Type, NULL); ! if (!stgdict) return NULL; fmt = getentry(PyString_AS_STRING(proto)); --- 1386,1393 ---- stgdict = (StgDictObject *)PyObject_CallObject( (PyObject *)&StgDict_Type, NULL); ! if (!stgdict) { ! Py_DECREF(proto); return NULL; + } fmt = getentry(PyString_AS_STRING(proto)); *************** *** 1399,1407 **** stgdict->getfunc = fmt->getfunc; stgdict->asparam = Simple_asparam; - /* This consumes the refcount on proto which we have */ - stgdict->proto = proto; ! /* replace the class dict by our updated spam dict */ if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) { Py_DECREF(result); Py_DECREF((PyObject *)stgdict); --- 1400,1407 ---- stgdict->getfunc = fmt->getfunc; stgdict->asparam = Simple_asparam; ! /* replace the class dict by the storage dict */ if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) { + Py_DECREF(proto); Py_DECREF(result); Py_DECREF((PyObject *)stgdict); *************** *** 1463,1466 **** --- 1463,1467 ---- } } + Py_DECREF(proto); return (PyObject *)result; } |
From: Thomas H. <th...@us...> - 2005-04-06 10:18:37
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22622 Modified Files: _ctypes.c Log Message: c_char_p and c_wchar_p now have their stgdict->proto set to c_char resp. c_wchar. This allows a common from_param function for c_char_p and c_wchar_p. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.279 retrieving revision 1.280 diff -C2 -d -r1.279 -r1.280 *** _ctypes.c 6 Apr 2005 09:28:38 -0000 1.279 --- _ctypes.c 6 Apr 2005 10:18:27 -0000 1.280 *************** *** 1215,1225 **** static char *SIMPLE_TYPE_CHARS = "cbBhHiIlLdfuzZqQPXOv"; static PyObject * string_ptr_from_param(PyObject *type, PyObject *value) { ! if (PyObject_IsInstance(value, type)) { ! Py_INCREF(value); ! return value; ! } /* z_set and Z_set accept integers as well. Until that is fixed, we have to typecheck here. */ --- 1215,1227 ---- static char *SIMPLE_TYPE_CHARS = "cbBhHiIlLdfuzZqQPXOv"; + /* We need access to some simple types */ + static PyObject *c_char, *c_wchar, *c_void_p; + static PyObject * string_ptr_from_param(PyObject *type, PyObject *value) { ! StgDictObject *typedict = PyType_stgdict(type); ! StgDictObject *itemdict = PyType_stgdict(typedict->proto); ! /* z_set and Z_set accept integers as well. Until that is fixed, we have to typecheck here. */ *************** *** 1237,1281 **** return (PyObject *)parg; } - /* XXX better message */ - PyErr_SetString(PyExc_TypeError, - "wrong type"); - return NULL; - } - - static PyObject * - c_wchar_p_from_param(PyObject *type, PyObject *value) - { - if (ArrayObject_Check(value) || PointerObject_Check(value)) { - /* c_wchar array instance or pointer(c_wchar(...)) */ - StgDictObject *dt = PyObject_stgdict(value); - StgDictObject *dict = dt && dt->proto ? PyType_stgdict(dt->proto) : NULL; - if (dict && (dict->setfunc == getentry("u")->setfunc)) { - Py_INCREF(value); - return value; - } - } - if (PyCArg_CheckExact(value)) { - /* byref(c_char(...)) */ - PyCArgObject *a = (PyCArgObject *)value; - StgDictObject *dict = PyObject_stgdict(a->obj); - if (dict && (dict->setfunc == getentry("u")->setfunc)) { - Py_INCREF(value); - return value; - } - } - return string_ptr_from_param(type, value); - } - - static PyObject * - c_char_p_from_param(PyObject *type, PyObject *value) - { - /* It seems that c_char_p's stgdict->proto should better be c_char, - and c_wchar_p's stgdict->proto shoule be c_wchar. Something like that. - */ if (ArrayObject_Check(value) || PointerObject_Check(value)) { /* c_char array instance or pointer(c_char(...)) */ StgDictObject *dt = PyObject_stgdict(value); StgDictObject *dict = dt && dt->proto ? PyType_stgdict(dt->proto) : NULL; ! if (dict && (dict->setfunc == getentry("c")->setfunc)) { Py_INCREF(value); return value; --- 1239,1247 ---- return (PyObject *)parg; } if (ArrayObject_Check(value) || PointerObject_Check(value)) { /* c_char array instance or pointer(c_char(...)) */ StgDictObject *dt = PyObject_stgdict(value); StgDictObject *dict = dt && dt->proto ? PyType_stgdict(dt->proto) : NULL; ! if (dict && (dict->setfunc == itemdict->setfunc)) { Py_INCREF(value); return value; *************** *** 1286,1295 **** PyCArgObject *a = (PyCArgObject *)value; StgDictObject *dict = PyObject_stgdict(a->obj); ! if (dict && (dict->setfunc == getentry("c")->setfunc)) { Py_INCREF(value); return value; } } ! return string_ptr_from_param(type, value); } --- 1252,1268 ---- PyCArgObject *a = (PyCArgObject *)value; StgDictObject *dict = PyObject_stgdict(a->obj); ! if (dict && (dict->setfunc == itemdict->setfunc)) { Py_INCREF(value); return value; } } ! if (PyObject_IsInstance(value, type)) { ! Py_INCREF(value); ! return value; ! } ! /* XXX better message */ ! PyErr_SetString(PyExc_TypeError, ! "wrong type"); ! return NULL; } *************** *** 1348,1358 **** } stgd = PyObject_stgdict(value); ! if (stgd && CDataObject_Check(value) && stgd->proto && PyString_Check(stgd->proto)) { ! PyCArgObject *parg; ! ! switch (PyString_AS_STRING(stgd->proto)[0]) { ! case 'z': /* c_char_p */ ! case 'Z': /* c_wchar_p */ ! parg = new_CArgObject(); if (parg == NULL) return NULL; --- 1321,1327 ---- } stgd = PyObject_stgdict(value); ! if (stgd) { ! if (stgd->proto == c_char || stgd->proto == c_wchar) { ! PyCArgObject *parg = new_CArgObject(); if (parg == NULL) return NULL; *************** *** 1372,1377 **** static PyMethodDef c_void_p_method = { "from_param", c_void_p_from_param, METH_O }; ! static PyMethodDef c_char_p_method = { "from_param", c_char_p_from_param, METH_O }; ! static PyMethodDef c_wchar_p_method = { "from_param", c_wchar_p_from_param, METH_O }; static int --- 1341,1346 ---- static PyMethodDef c_void_p_method = { "from_param", c_void_p_from_param, METH_O }; ! static PyMethodDef c_char_p_method = { "from_param", string_ptr_from_param, METH_O }; ! static PyMethodDef c_wchar_p_method = { "from_param", string_ptr_from_param, METH_O }; static int *************** *** 1445,1461 **** 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; } --- 1414,1447 ---- Overrides the SimpleType_from_param generic method. */ + ml = NULL; if (result->tp_base == &Simple_Type) { switch (PyString_AS_STRING(proto)[0]) { case 'z': /* c_char_p */ ml = &c_char_p_method; + assert(c_char); + Py_XDECREF(stgdict->proto); + Py_INCREF(c_char); + stgdict->proto = c_char; break; case 'Z': /* c_wchar_p */ ml = &c_wchar_p_method; + assert(c_wchar); + Py_XDECREF(stgdict->proto); + Py_INCREF(c_wchar); + stgdict->proto = c_wchar; break; case 'P': /* c_void_p */ ml = &c_void_p_method; + assert(c_void_p == NULL); + Py_INCREF(result); + c_void_p = (PyObject *)result; break; ! case 'c': /* c_char */ ! assert(c_char == NULL); ! c_char = (PyObject *)result; ! break; ! case 'u': /* c_wchar */ ! assert(c_wchar == NULL); ! c_wchar = (PyObject *)result; break; } |
From: Thomas H. <th...@us...> - 2005-04-06 09:28:51
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6161 Modified Files: _ctypes.c Log Message: Refactoring. Move common code from c_char_p_from_param() and c_wchar_p_from_param() into string_ptr_from_param(). Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.278 retrieving revision 1.279 diff -C2 -d -r1.278 -r1.279 *** _ctypes.c 6 Apr 2005 07:29:35 -0000 1.278 --- _ctypes.c 6 Apr 2005 09:28:38 -0000 1.279 *************** *** 1216,1239 **** static PyObject * ! c_wchar_p_from_param(PyObject *type, PyObject *value) { ! /* ! Z_set handles None, Unicode, String, but not Array, Pointer, ! CArgObject. ! ! But it handles, although it shouldn't, int and long. ! Would be an api change to fix this. ! */ ! if (value == Py_None) { ! Py_INCREF(Py_None); ! return Py_None; } ! if (PyUnicode_Check(value) || PyString_Check(value)) { PyCArgObject *parg; ! struct fielddesc *fd = getentry("Z"); parg = new_CArgObject(); parg->pffi_type = &ffi_type_pointer; ! parg->obj = fd->setfunc(&parg->value, value, 0, type); if (parg->obj == NULL) { Py_DECREF(parg); --- 1216,1234 ---- static PyObject * ! string_ptr_from_param(PyObject *type, PyObject *value) { ! if (PyObject_IsInstance(value, type)) { ! Py_INCREF(value); ! return value; } ! /* z_set and Z_set accept integers as well. Until that is fixed, we ! have to typecheck here. */ ! if (value == Py_None || PyString_Check(value) || PyUnicode_Check(value)) { PyCArgObject *parg; ! StgDictObject *dict = PyType_stgdict(type); parg = new_CArgObject(); parg->pffi_type = &ffi_type_pointer; ! parg->obj = dict->setfunc(&parg->value, value, 0, type); if (parg->obj == NULL) { Py_DECREF(parg); *************** *** 1242,1249 **** return (PyObject *)parg; } ! if (PyObject_IsInstance(value, type)) { ! Py_INCREF(value); ! return value; ! } if (ArrayObject_Check(value) || PointerObject_Check(value)) { /* c_wchar array instance or pointer(c_wchar(...)) */ --- 1237,1249 ---- return (PyObject *)parg; } ! /* XXX better message */ ! PyErr_SetString(PyExc_TypeError, ! "wrong type"); ! return NULL; ! } ! ! static PyObject * ! c_wchar_p_from_param(PyObject *type, PyObject *value) ! { if (ArrayObject_Check(value) || PointerObject_Check(value)) { /* c_wchar array instance or pointer(c_wchar(...)) */ *************** *** 1264,1271 **** } } ! /* XXX better message */ ! PyErr_SetString(PyExc_TypeError, ! "wrong type"); ! return NULL; } --- 1264,1268 ---- } } ! return string_ptr_from_param(type, value); } *************** *** 1273,1304 **** c_char_p_from_param(PyObject *type, PyObject *value) { ! /* ! setfunc (which is z_set) handles None, String, and Unicode, but not ! Array, Pointer, c_char_p, and CArgObject. Instead (!) it accepts ! integers as well, which seems wrong. ! ! And fixing this would be a severe api change. ! */ ! if (value == Py_None) { ! Py_INCREF(Py_None); ! return Py_None; ! } ! if (PyString_Check(value) || PyUnicode_Check(value)) { ! PyCArgObject *parg; ! struct fielddesc *fd = getentry("z"); ! ! parg = new_CArgObject(); ! parg->pffi_type = &ffi_type_pointer; ! parg->obj = fd->setfunc(&parg->value, value, 0, type); ! if (parg->obj == NULL) { ! Py_DECREF(parg); ! return NULL; ! } ! return (PyObject *)parg; ! } ! if (PyObject_IsInstance(value, type)) { ! Py_INCREF(value); ! return value; ! } if (ArrayObject_Check(value) || PointerObject_Check(value)) { /* c_char array instance or pointer(c_char(...)) */ --- 1270,1276 ---- c_char_p_from_param(PyObject *type, PyObject *value) { ! /* It seems that c_char_p's stgdict->proto should better be c_char, ! and c_wchar_p's stgdict->proto shoule be c_wchar. Something like that. ! */ if (ArrayObject_Check(value) || PointerObject_Check(value)) { /* c_char array instance or pointer(c_char(...)) */ *************** *** 1319,1326 **** } } ! /* XXX better message */ ! PyErr_SetString(PyExc_TypeError, ! "wrong type"); ! return NULL; } --- 1291,1295 ---- } } ! return string_ptr_from_param(type, value); } |
From: Thomas H. <th...@us...> - 2005-04-06 07:29:47
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8179 Modified Files: ctypes.h callproc.c _ctypes.c Log Message: Get rid of the tag member in PyCArgObject. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.91 retrieving revision 1.92 diff -C2 -d -r1.91 -r1.92 *** ctypes.h 1 Apr 2005 15:10:36 -0000 1.91 --- ctypes.h 6 Apr 2005 07:29:35 -0000 1.92 *************** *** 89,93 **** PyObject_HEAD ffi_type *pffi_type; - char tag; union { char c; --- 89,92 ---- Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.140 retrieving revision 1.141 diff -C2 -d -r1.140 -r1.141 *** callproc.c 4 Apr 2005 15:39:04 -0000 1.140 --- callproc.c 6 Apr 2005 07:29:35 -0000 1.141 *************** *** 271,275 **** return NULL; p->pffi_type = NULL; - p->tag = '\0'; p->obj = NULL; memset(&p->value, 0, sizeof(p->value)); --- 271,274 ---- *************** *** 288,355 **** { char buffer[256]; ! switch(self->tag) { ! case 'b': ! case 'B': ! sprintf(buffer, "<cparam '%c' (%d)>", ! self->tag, self->value.b); ! break; ! case 'h': ! case 'H': ! sprintf(buffer, "<cparam '%c' (%d)>", ! self->tag, self->value.h); ! break; ! case 'i': ! case 'I': ! sprintf(buffer, "<cparam '%c' (%d)>", ! self->tag, self->value.i); ! break; ! case 'l': ! case 'L': ! sprintf(buffer, "<cparam '%c' (%ld)>", ! self->tag, self->value.l); ! break; ! #ifdef HAVE_LONG_LONG ! case 'q': ! case 'Q': ! sprintf(buffer, #ifdef MS_WIN32 ! "<cparam '%c' (%I64d)>", #else ! "<cparam '%c' (%qd)>", #endif ! self->tag, self->value.q); ! break; #endif ! case 'd': ! sprintf(buffer, "<cparam '%c' (%f)>", ! self->tag, self->value.d); ! break; ! case 'f': ! sprintf(buffer, "<cparam '%c' (%f)>", ! self->tag, self->value.f); ! break; ! ! case 'c': ! sprintf(buffer, "<cparam '%c' (%c)>", ! self->tag, self->value.c); ! break; ! ! /* Hm, are these 'z' and 'Z' codes useful at all? ! Shouldn't they be replaced by the functionality of c_string ! and c_wstring ? ! */ ! case 'z': ! case 'Z': ! case 'P': ! sprintf(buffer, "<cparam '%c' (%08lx)>", ! self->tag, (long)self->value.p); ! break; ! ! default: ! sprintf(buffer, "<cparam '%c' at %08lx>", ! self->tag, (long)self); ! break; ! } return PyString_FromString(buffer); } --- 287,344 ---- { char buffer[256]; ! ! if (self->pffi_type == &ffi_type_pointer) { ! sprintf(buffer, "<cparam 'P' (%08lx)>", (long)self->value.p); ! } else ! ! switch(self->pffi_type->type) { ! case FFI_TYPE_SINT8: ! sprintf(buffer, "<cparam 'b' (%d)>", self->value.b); ! break; ! case FFI_TYPE_UINT8: ! sprintf(buffer, "<cparam 'B' (%d)>", self->value.b); ! break; ! case FFI_TYPE_SINT16: ! sprintf(buffer, "<cparam 'h' (%d)>", self->value.h); ! break; ! case FFI_TYPE_UINT16: ! sprintf(buffer, "<cparam 'H' (%d)>", self->value.h); ! break; ! case FFI_TYPE_SINT32: ! sprintf(buffer, "<cparam 'l' (%d)>", self->value.i); ! break; ! case FFI_TYPE_UINT32: ! sprintf(buffer, "<cparam 'L' (%d)>", self->value.i); ! break; #ifdef HAVE_LONG_LONG ! case FFI_TYPE_SINT64: ! sprintf(buffer, #ifdef MS_WIN32 ! "<cparam 'q' (%I64d)>", #else ! "<cparam 'q' (%qd)>", #endif ! self->value.q); ! break; ! case FFI_TYPE_UINT64: ! sprintf(buffer, ! #ifdef MS_WIN32 ! "<cparam 'Q' (%I64d)>", ! #else ! "<cparam 'Q' (%qd)>", #endif ! self->value.q); ! break; ! #endif ! case FFI_TYPE_DOUBLE: ! sprintf(buffer, "<cparam 'd' (%f)>", self->value.d); ! break; ! case FFI_TYPE_FLOAT: ! sprintf(buffer, "<cparam 'f' (%f)>", self->value.f); ! break; ! default: ! sprintf(buffer, "<cparam '?' at %08lx>", (long)self); ! break; ! } return PyString_FromString(buffer); } *************** *** 1200,1204 **** return NULL; - parg->tag = 'P'; parg->pffi_type = &ffi_type_pointer; Py_INCREF(obj); --- 1189,1192 ---- Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.277 retrieving revision 1.278 diff -C2 -d -r1.277 -r1.278 *** _ctypes.c 6 Apr 2005 06:55:45 -0000 1.277 --- _ctypes.c 6 Apr 2005 07:29:35 -0000 1.278 *************** *** 1235,1239 **** parg = new_CArgObject(); parg->pffi_type = &ffi_type_pointer; - parg->tag = 'Z'; parg->obj = fd->setfunc(&parg->value, value, 0, type); if (parg->obj == NULL) { --- 1235,1238 ---- *************** *** 1291,1295 **** parg = new_CArgObject(); parg->pffi_type = &ffi_type_pointer; - parg->tag = 'z'; parg->obj = fd->setfunc(&parg->value, value, 0, type); if (parg->obj == NULL) { --- 1290,1293 ---- *************** *** 1342,1346 **** parg = new_CArgObject(); parg->pffi_type = &ffi_type_pointer; - parg->tag = 'z'; parg->obj = fd->setfunc(&parg->value, value, 0, type); if (parg->obj == NULL) { --- 1340,1343 ---- *************** *** 1356,1360 **** parg = new_CArgObject(); parg->pffi_type = &ffi_type_pointer; - parg->tag = 'Z'; parg->obj = fd->setfunc(&parg->value, value, 0, type); if (parg->obj == NULL) { --- 1353,1356 ---- *************** *** 1393,1397 **** return NULL; parg->pffi_type = &ffi_type_pointer; - parg->tag = 'Z'; Py_INCREF(value); parg->obj = value; --- 1389,1392 ---- *************** *** 1535,1552 **** { StgDictObject *dict; - char *fmt; PyCArgObject *parg; - dict = PyType_stgdict(type); - parg = new_CArgObject(); if (parg == NULL) return NULL; ! /* We should get rid of the tag member, probably */ ! fmt = PyString_AsString(dict->proto); ! parg->tag = fmt[0]; parg->pffi_type = &dict->ffi_type; - parg->obj = dict->setfunc(&parg->value, value, 0, type); if (parg->obj == NULL) { --- 1530,1541 ---- { StgDictObject *dict; PyCArgObject *parg; parg = new_CArgObject(); if (parg == NULL) return NULL; ! dict = PyType_stgdict(type); parg->pffi_type = &dict->ffi_type; parg->obj = dict->setfunc(&parg->value, value, 0, type); if (parg->obj == NULL) { *************** *** 2574,2578 **** } - parg->tag = 'P'; parg->pffi_type = &ffi_type_pointer; parg->obj = obj; --- 2563,2566 ---- |
From: Thomas H. <th...@us...> - 2005-04-06 06:55:55
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30888 Modified Files: _ctypes.c Log Message: Fading out the need for the tag member in PyCArgObject. pffi_type should be enough. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.276 retrieving revision 1.277 diff -C2 -d -r1.276 -r1.277 *** _ctypes.c 5 Apr 2005 20:26:20 -0000 1.276 --- _ctypes.c 6 Apr 2005 06:55:45 -0000 1.277 *************** *** 1377,1381 **** /* byref(c_xxx()) */ PyCArgObject *a = (PyCArgObject *)value; ! if (a->tag == 'P') { Py_INCREF(value); return value; --- 1377,1381 ---- /* byref(c_xxx()) */ PyCArgObject *a = (PyCArgObject *)value; ! if (a->pffi_type == &ffi_type_pointer) { Py_INCREF(value); return value; *************** *** 2804,2810 **** */ if (dict-> proto && PyString_CheckExact(dict->proto)) { ! char *tag = PyString_AS_STRING(dict->proto); /* simple data type, but no pointer */ ! if (tag[0] == 'P') { Py_INCREF(result); return result; --- 2804,2810 ---- */ if (dict-> proto && PyString_CheckExact(dict->proto)) { ! char *fmt = PyString_AS_STRING(dict->proto); /* simple data type, but no pointer */ ! if (fmt[0] == 'P') { Py_INCREF(result); return result; |
From: Thomas H. <th...@us...> - 2005-04-05 20:26:28
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26731 Modified Files: _ctypes.c Log Message: Description of SETFUNC, GETFUNC, ASPARAM. Remove invalid descriptions. Remove unused code in SimpleType_from_param. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.275 retrieving revision 1.276 diff -C2 -d -r1.275 -r1.276 *** _ctypes.c 5 Apr 2005 16:58:40 -0000 1.275 --- _ctypes.c 5 Apr 2005 20:26:20 -0000 1.276 *************** *** 1,5 **** /* xyz_asparam(CDataObject *self, struct argument *pa) ! Instance method. --- 1,40 ---- + /* + The most important internal functions: + ====================================== + + PyObject *SETFUNC(void *ptr, PyObject *value, unsigned size, PyObject *type); + + 'type' is a ctypes type - it has an stgdict. + + SETFUNC checks if value is 'compatible' with 'type', then stores 'value' + into the memory block pointed to by 'ptr'. The interpretation of 'size' + depends on the type: for array types it means the length of the array + (could that also be accessed via the storage dict?), for integer types it + may specify bit offset and size (in structure fields). + + Returns a Python object which must be kept alive to keep the memory block + contents valid. + + ----- + + PyObject *GETFUNC(void *ptr, unsigned size, PyObject *type, CDataObject *base, int index); + + Construct an instance of 'type' from the memory block 'ptr'. 'size' has + the same meaning as in SETFUNC, if 'base' is non-NULL, the resulting + instance uses the memory of 'base'. 'index' is used to specify which + objects from 'base' must be kept alive. + + ----- + + int ASPARAM(CDataObject *self, struct argument *pa); + + ASPARAM knows how a ctypes instance is used as parameter in a function + call. + + */ + /* xyz_asparam(CDataObject *self, struct argument *pa) ! Instance method. *************** *** 1183,1187 **** c_wchar_p_from_param(PyObject *type, PyObject *value) { ! /* Again, this should use setfunc (Z_set). Z_set handles None, Unicode, String, but not Array, Pointer, CArgObject. --- 1218,1222 ---- c_wchar_p_from_param(PyObject *type, PyObject *value) { ! /* Z_set handles None, Unicode, String, but not Array, Pointer, CArgObject. *************** *** 1239,1246 **** c_char_p_from_param(PyObject *type, PyObject *value) { ! /* This should use setfunc in the same way as SimpleType_from_param does it. ! setfunc (which is z_set) handles None, String, and Unicode, ! but not Array, Pointer, c_char_p, and CArgObject. ! Instead (!) it accepts integers as well, which seems wrong. And fixing this would be a severe api change. --- 1274,1281 ---- c_char_p_from_param(PyObject *type, PyObject *value) { ! /* ! setfunc (which is z_set) handles None, String, and Unicode, but not ! Array, Pointer, c_char_p, and CArgObject. Instead (!) it accepts ! integers as well, which seems wrong. And fixing this would be a severe api change. *************** *** 1482,1504 **** /* ! * This is a *class method*. ! * Convert a parameter into something that ConvParam can handle. ! * ! * This is either an instance of the requested type, a Python integer, or a ! * 'magic' 3-tuple. ! * ! * (These are somewhat related to Martin v. Loewis 'Enhanced Argument Tuples', ! * described in PEP 286.) ! * ! * The tuple must contain ! * ! * - a format character, currently 'ifdqc' are understood ! * which will inform ConvParam about how to push the argument on the stack. ! * ! * - a corresponding Python object: i - integer, f - float, d - float, ! * q - longlong, c - integer ! * ! * - any object which can be used to keep the original parameter alive ! * as long as the tuple lives. */ static PyObject * --- 1517,1533 ---- /* ! The from_param protocol should change. Suggested by Andreas Degert. ! ! The ctypes buildin types probably should NOT have a from_param method any ! longer. The from_param method of other types must return something that ! ConvParam can handle: int, string, or a ctypes instance. ! ! When a ctypes type is used in the argtypes list: ! - argtypes[i] is the type ! - converters[i] is type.from_param or NULL ! ! ConvParam does: ! - if converters[i] is non-NULL: call it with the actual argument, use the result ! - if converters[i] is NULL: call argtypes[i]->setfunc with the actual argument, use the result */ static PyObject * *************** *** 1509,1519 **** PyCArgObject *parg; - /* If the value is already an instance of the requested type, - we can use it as is */ - if (1 == PyObject_IsInstance(value, type)) { - Py_INCREF(value); - return value; - } - dict = PyType_stgdict(type); --- 1538,1541 ---- |