ctypes-commit Mailing List for ctypes (Page 59)
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-08 07:39:33
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13819 Modified Files: test_complete_cover.py Log Message: oops Index: test_complete_cover.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_complete_cover.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** test_complete_cover.py 8 Apr 2005 07:34:52 -0000 1.7 --- test_complete_cover.py 8 Apr 2005 07:39:25 -0000 1.8 *************** *** 37,41 **** self.failUnlessEqual(repr(X.b), "<Field type=c_long, ofs=8, bits=3>") ! elif sizeof(clong) == 8: self.failUnlessEqual(repr(X.a), "<Field type=c_long, ofs=0, size=8>") --- 37,41 ---- self.failUnlessEqual(repr(X.b), "<Field type=c_long, ofs=8, bits=3>") ! elif sizeof(c_long) == 8: self.failUnlessEqual(repr(X.a), "<Field type=c_long, ofs=0, size=8>") |
From: Thomas H. <th...@us...> - 2005-04-08 07:35:07
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11143 Modified Files: test_complete_cover.py Log Message: More tests, and fixes for 64 bit platforms. Index: test_complete_cover.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_complete_cover.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** test_complete_cover.py 7 Apr 2005 09:26:36 -0000 1.6 --- test_complete_cover.py 8 Apr 2005 07:34:52 -0000 1.7 *************** *** 14,17 **** --- 14,18 ---- class X(Structure): _fields_ = [("a", c_long), + ("c", c_char), ("b", c_long, 3), ("z", c_char_p), *************** *** 21,24 **** --- 22,26 ---- class X(Structure): _fields_ = [("a", c_long), + ("c", c_char), ("b", c_long, 3), ("u", c_wchar), *************** *** 28,35 **** ("P", c_void_p), ("p", POINTER(c_long))] ! self.failUnlessEqual(repr(X.a), ! "<Field type=c_long, ofs=0, size=4>") ! self.failUnlessEqual(repr(X.b), ! "<Field type=c_long, ofs=4, bits=3>") X().p = None --- 30,47 ---- ("P", c_void_p), ("p", POINTER(c_long))] ! if sizeof(c_long) == 4: ! self.failUnlessEqual(repr(X.a), ! "<Field type=c_long, ofs=0, size=4>") ! self.failUnlessEqual(repr(X.c), ! "<Field type=c_char, ofs=4, size=1>") ! self.failUnlessEqual(repr(X.b), ! "<Field type=c_long, ofs=8, bits=3>") ! elif sizeof(clong) == 8: ! self.failUnlessEqual(repr(X.a), ! "<Field type=c_long, ofs=0, size=8>") ! self.failUnlessEqual(repr(X.c), ! "<Field type=c_char, ofs=8, size=1>") ! self.failUnlessEqual(repr(X.b), ! "<Field type=c_long, ofs=16, bits=3>") X().p = None |
From: Thomas H. <th...@us...> - 2005-04-08 07:16:17
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2315 Modified Files: callproc.c Log Message: The _asparam functions must set the pdata field. Less copying of data, and no special case for structures any more. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.145 retrieving revision 1.146 diff -C2 -d -r1.145 -r1.146 *** callproc.c 7 Apr 2005 20:31:26 -0000 1.145 --- callproc.c 8 Apr 2005 07:16:04 -0000 1.146 *************** *** 397,400 **** --- 397,401 ---- if (obj == Py_None) { pa->ffi_type = &ffi_type_pointer; + pa->pdata = &pa->value.p; pa->value.p = NULL; return 0; *************** *** 402,405 **** --- 403,407 ---- if (PyInt_Check(obj)) { pa->ffi_type = &ffi_type_sint; + pa->pdata = &pa->value.i; pa->value.i = PyInt_AS_LONG(obj); return 0; *************** *** 407,410 **** --- 409,413 ---- if (PyLong_Check(obj)) { pa->ffi_type = &ffi_type_sint; + pa->pdata = &pa->value.i; pa->value.i = (int)PyLong_AsUnsignedLongMask(obj); return 0; *************** *** 412,415 **** --- 415,419 ---- if (PyString_Check(obj)) { pa->ffi_type = &ffi_type_pointer; + pa->pdata = &pa->value.p; pa->value.p = PyString_AS_STRING(obj); Py_INCREF(obj); *************** *** 423,427 **** 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; --- 427,432 ---- if (PyUnicode_Check(obj)) { pa->ffi_type = &ffi_type_pointer; ! pa->pdata = &pa->value.p; ! pa->keep = getentry("Z")->setfunc(&pa->value.p, obj, 0, NULL); /* CTYPE_c_wchar_p? */ if (pa->keep == NULL) return -1; *************** *** 434,438 **** Py_INCREF(obj); pa->keep = obj; ! memcpy(&pa->value, &carg->value, sizeof(pa->value)); return 0; } --- 439,443 ---- Py_INCREF(obj); pa->keep = obj; ! pa->pdata = &carg->value; return 0; } *************** *** 452,456 **** PyCArgObject *carg = (PyCArgObject *)arg; pa->ffi_type = carg->pffi_type; ! memcpy(&pa->value, &carg->value, sizeof(pa->value)); /* consumes the refcount: */ pa->keep = arg; --- 457,461 ---- PyCArgObject *carg = (PyCArgObject *)arg; pa->ffi_type = carg->pffi_type; ! pa->pdata = &carg->value; /* consumes the refcount: */ pa->keep = arg; *************** *** 459,463 **** if (PyInt_Check(arg)) { pa->ffi_type = &ffi_type_sint; ! pa->value.l = PyInt_AS_LONG(arg); /* consumes the refcount: */ pa->keep = arg; --- 464,469 ---- if (PyInt_Check(arg)) { pa->ffi_type = &ffi_type_sint; ! pa->pdata = &pa->value.i; ! pa->value.i = PyInt_AS_LONG(arg); /* consumes the refcount: */ pa->keep = arg; *************** *** 736,744 **** memset(args, 0, sizeof(struct argument) * argcount); rvalue = alloca(max(rtype->size, sizeof(ffi_arg))); - avalues = (void **)alloca(sizeof(void *) * argcount); - atypes = (ffi_type **)alloca(sizeof(ffi_type *) * argcount); if (pIunk) { args[0].ffi_type = &ffi_type_pointer; args[0].value.p = pIunk; pa = &args[1]; --- 742,749 ---- memset(args, 0, sizeof(struct argument) * argcount); rvalue = alloca(max(rtype->size, sizeof(ffi_arg))); if (pIunk) { args[0].ffi_type = &ffi_type_pointer; + args[0].pdata = &args[0].value.p; args[0].value.p = pIunk; pa = &args[1]; *************** *** 784,793 **** --- 789,803 ---- } + avalues = (void **)alloca(sizeof(void *) * argcount); + atypes = (ffi_type **)alloca(sizeof(ffi_type *) * argcount); for (i = 0; i < argcount; ++i) { atypes[i] = args[i].ffi_type; + avalues[i] = args[i].pdata; + /* if (atypes[i]->type == FFI_TYPE_STRUCT) avalues[i] = (void *)args[i].value.p; else avalues[i] = (void *)&args[i].value; + */ } *************** *** 939,944 **** if (-1 == PyObject_asparam(p1, &a, 0) || -1 == PyObject_asparam(p2, &b, 1)) goto done; ! src = (IUnknown *)a.value.p; ! pdst = (IUnknown **)b.value.p; if (pdst == NULL) --- 949,956 ---- if (-1 == PyObject_asparam(p1, &a, 0) || -1 == PyObject_asparam(p2, &b, 1)) goto done; ! assert(a.pdata != NULL); ! assert(b.pdata != NULL); ! src = (IUnknown *)*(void **)a.pdata; ! pdst = (IUnknown **)*(void **)b.pdata; if (pdst == NULL) *************** *** 1236,1239 **** --- 1248,1252 ---- if (-1 == PyObject_asparam(obj, &a, 1)) return NULL; + assert(a.pdata != NULL); result = (CDataObject *)PyObject_CallFunctionObjArgs(ctype, NULL); if (result == NULL) { *************** *** 1243,1247 **** // result->b_size // a.ffi_type->size ! memcpy(result->b_ptr, &a.value, min(result->b_size, a.ffi_type->size)); Py_XDECREF(a.keep); --- 1256,1260 ---- // result->b_size // a.ffi_type->size ! memcpy(result->b_ptr, a.pdata, min(result->b_size, a.ffi_type->size)); Py_XDECREF(a.keep); *************** *** 1271,1275 **** if (-1 == PyObject_asparam(src, &a_src, 2)) goto done; ! c_result = memmove(a_dst.value.p, a_src.value.p, size); result = PyLong_FromVoidPtr(c_result); done: --- 1284,1288 ---- if (-1 == PyObject_asparam(src, &a_src, 2)) goto done; ! c_result = memmove(*(void **)a_dst.pdata, *(void **)a_src.pdata, size); result = PyLong_FromVoidPtr(c_result); done: *************** *** 1296,1300 **** if (-1 == PyObject_asparam(dst, &a_dst, 1)) return NULL; ! c_result = memset(a_dst.value.p, c, count); result = PyLong_FromVoidPtr(c_result); Py_XDECREF(a_dst.keep); --- 1309,1313 ---- if (-1 == PyObject_asparam(dst, &a_dst, 1)) return NULL; ! c_result = memset(*(void **)a_dst.pdata, c, count); result = PyLong_FromVoidPtr(c_result); Py_XDECREF(a_dst.keep); *************** *** 1321,1327 **** return NULL; if (PyTuple_GET_SIZE(args) == 1) ! result = PyString_FromString(a_arg.value.p); else ! result = PyString_FromStringAndSize(a_arg.value.p, size); Py_XDECREF(a_arg.keep); return result; --- 1334,1340 ---- return NULL; if (PyTuple_GET_SIZE(args) == 1) ! result = PyString_FromString(*(void **)a_arg.pdata); else ! result = PyString_FromStringAndSize(*(void **)a_arg.pdata, size); Py_XDECREF(a_arg.keep); return result; *************** *** 1348,1354 **** return NULL; if (PyTuple_GET_SIZE(args) == 1) ! result = PyUnicode_FromWideChar(a_arg.value.p, wcslen(a_arg.value.p)); else ! result = PyUnicode_FromWideChar(a_arg.value.p, size); Py_XDECREF(a_arg.keep); return result; --- 1361,1367 ---- return NULL; if (PyTuple_GET_SIZE(args) == 1) ! result = PyUnicode_FromWideChar(*(void **)a_arg.pdata, wcslen(*(void **)a_arg.pdata)); else ! result = PyUnicode_FromWideChar(*(void **)a_arg.pdata, size); Py_XDECREF(a_arg.keep); return result; |
From: Thomas H. <th...@us...> - 2005-04-08 07:15:22
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1767 Modified Files: _ctypes.c Log Message: The _asparam functions must set the pdata field. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.294 retrieving revision 1.295 diff -C2 -d -r1.294 -r1.295 *** _ctypes.c 6 Apr 2005 20:39:11 -0000 1.294 --- _ctypes.c 8 Apr 2005 07:15:12 -0000 1.295 *************** *** 207,213 **** { if (type == NULL) { ! PyErr_SetString(PyExc_SystemError, "ctypes bug: generic_getfunc called with NULL type"); ! return NULL; } return CData_FromBaseObj(type, (PyObject *)src, 0, ptr); --- 207,213 ---- { if (type == NULL) { ! PyErr_SetString(PyExc_SystemError, /*COV*/ "ctypes bug: generic_getfunc called with NULL type"); ! return NULL; /*COV*/ } return CData_FromBaseObj(type, (PyObject *)src, 0, ptr); *************** *** 240,244 **** value->ob_type->tp_name, ((PyTypeObject *)type)->tp_name); ! return NULL; } --- 240,244 ---- value->ob_type->tp_name, ((PyTypeObject *)type)->tp_name); ! return NULL; /*COV*/ } *************** *** 271,275 **** StgDictObject *dict = PyObject_stgdict((PyObject *)self); pa->ffi_type = &dict->ffi_type; ! pa->value.p = self->b_ptr; Py_INCREF(self); pa->keep = (PyObject *)self; --- 271,275 ---- StgDictObject *dict = PyObject_stgdict((PyObject *)self); pa->ffi_type = &dict->ffi_type; ! pa->pdata = self->b_ptr; Py_INCREF(self); pa->keep = (PyObject *)self; *************** *** 441,445 **** ((PyTypeObject *)type)->tp_name, p->obj->ob_type->tp_name); ! return NULL; } PyErr_Format(PyExc_TypeError, --- 441,445 ---- ((PyTypeObject *)type)->tp_name, p->obj->ob_type->tp_name); ! return NULL; /*COV*/ } PyErr_Format(PyExc_TypeError, *************** *** 673,676 **** --- 673,677 ---- pa->ffi_type = &ffi_type_pointer; pa->value.p = *(void **)self->b_ptr; + pa->pdata = &pa->value.p; Py_INCREF(self); pa->keep = (PyObject *)self; *************** *** 1086,1089 **** --- 1087,1091 ---- pa->ffi_type = &ffi_type_pointer; pa->value.p = self->b_ptr; + pa->pdata = &pa->value.p; Py_INCREF(self); pa->keep = (PyObject *)self; *************** *** 1344,1347 **** --- 1346,1350 ---- assert(sizeof(pa->value) >= self->b_size); memcpy(&pa->value, self->b_ptr, self->b_size); + pa->pdata = &pa->value; Py_INCREF(self); pa->keep = (PyObject *)self; *************** *** 1646,1649 **** --- 1649,1653 ---- pa->ffi_type = &ffi_type_pointer; pa->value.p = *(void **)self->b_ptr; + pa->pdata = &pa->value.p; Py_INCREF(self); pa->keep = (PyObject *)self; |
From: Thomas H. <th...@us...> - 2005-04-08 07:14:35
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1290 Modified Files: ctypes.h Log Message: Change 'struct argument'. Add a 'void *pdata' member - this points to the actual data (required by libffi). The temp storage area only needs space for int or void*. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.94 retrieving revision 1.95 diff -C2 -d -r1.94 -r1.95 *** ctypes.h 6 Apr 2005 16:42:08 -0000 1.94 --- ctypes.h 8 Apr 2005 07:14:25 -0000 1.95 *************** *** 167,184 **** extern PyMethodDef module_methods[]; struct argument { ! ffi_type *ffi_type; ! PyObject *keep; ! union result { ! char c; ! char b; ! short h; int i; - long l; - #ifdef HAVE_LONG_LONG - PY_LONG_LONG q; - #endif - double d; - float f; void *p; } value; --- 167,178 ---- extern PyMethodDef module_methods[]; + /* Hold one argument for a libffi function call. */ struct argument { ! ffi_type *ffi_type; /* type of argument */ ! void *pdata; /* pointer to arguments data */ ! ! PyObject *keep; /* a Python object to keep alive during the function call */ ! union result { /* temporary storage area */ int i; void *p; } value; |
From: Thomas H. <th...@us...> - 2005-04-08 06:19:56
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6439 Modified Files: cfield.c Log Message: Code coverage ignore marker. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.112 retrieving revision 1.113 diff -C2 -d -r1.112 -r1.113 *** cfield.c 6 Apr 2005 19:00:28 -0000 1.112 --- cfield.c 8 Apr 2005 06:19:46 -0000 1.113 *************** *** 333,337 **** Py_DECREF(v); if (x == -1 && PyErr_Occurred()) ! return -1; *p = x; return 0; --- 333,337 ---- Py_DECREF(v); if (x == -1 && PyErr_Occurred()) ! return -1; /*COV*/ *p = x; return 0; *************** *** 348,352 **** Py_DECREF(v); if (x == -1 && PyErr_Occurred()) ! return -1; *p = x; return 0; --- 348,352 ---- Py_DECREF(v); if (x == -1 && PyErr_Occurred()) ! return -1; /*COV*/ *p = x; return 0; *************** *** 364,368 **** Py_DECREF(v); if (x == -1 && PyErr_Occurred()) ! return -1; *p = x; return 0; --- 364,368 ---- Py_DECREF(v); if (x == -1 && PyErr_Occurred()) ! return -1; /*COV*/ *p = x; return 0; *************** *** 379,383 **** Py_DECREF(v); if (x == -1 && PyErr_Occurred()) ! return -1; *p = x; return 0; --- 379,383 ---- Py_DECREF(v); if (x == -1 && PyErr_Occurred()) ! return -1; /*COV*/ *p = x; return 0; *************** *** 761,765 **** conversion_mode_errors); if (!value) ! return NULL; } else if (!PyUnicode_Check(value)) { PyErr_Format(PyExc_TypeError, --- 761,765 ---- conversion_mode_errors); if (!value) ! return NULL; /*COV*/ } else if (!PyUnicode_Check(value)) { PyErr_Format(PyExc_TypeError, |
From: Thomas H. <th...@us...> - 2005-04-07 20:31:41
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10425 Modified Files: callproc.c Log Message: Simpler and better code for PyObject_asparam. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.144 retrieving revision 1.145 diff -C2 -d -r1.144 -r1.145 *** callproc.c 7 Apr 2005 18:43:44 -0000 1.144 --- callproc.c 7 Apr 2005 20:31:26 -0000 1.145 *************** *** 395,427 **** if (stgdict) return stgdict->asparam((CDataObject *)obj, pa); ! ! /* probably a byref(obj) parameter */ ! if (PyCArg_CheckExact(obj)) { ! PyCArgObject *carg = (PyCArgObject *)obj; ! pa->ffi_type = carg->pffi_type; ! Py_INCREF(obj); ! pa->keep = obj; ! memcpy(&pa->value, &carg->value, sizeof(pa->value)); return 0; } ! ! /* 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)) { --- 395,423 ---- if (stgdict) return stgdict->asparam((CDataObject *)obj, pa); ! 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.i = PyInt_AS_LONG(obj); return 0; } ! if (PyLong_Check(obj)) { ! pa->ffi_type = &ffi_type_sint; ! pa->value.i = (int)PyLong_AsUnsignedLongMask(obj); ! 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 + /* XXX See Z_set. */ + /* XXX PyUnicode_AsWideChar(), */ /* Pass as pointer by calling Z_set() */ if (PyUnicode_Check(obj)) { *************** *** 433,436 **** --- 429,440 ---- } #endif + if (PyCArg_CheckExact(obj)) { + PyCArgObject *carg = (PyCArgObject *)obj; + pa->ffi_type = carg->pffi_type; + Py_INCREF(obj); + pa->keep = obj; + memcpy(&pa->value, &carg->value, sizeof(pa->value)); + return 0; + } arg = PyObject_GetAttrString(obj, "_as_parameter_"); |
From: Thomas H. <th...@us...> - 2005-04-07 18:43:53
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10936 Modified Files: callproc.c Log Message: Restructure the code and rename a local variable for clarity. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.143 retrieving revision 1.144 diff -C2 -d -r1.143 -r1.144 *** callproc.c 6 Apr 2005 15:11:43 -0000 1.143 --- callproc.c 7 Apr 2005 18:43:44 -0000 1.144 *************** *** 711,719 **** { int i, n, argcount, argtype_count; ! void *resbuf; ! struct argument *args, *pa; ! ffi_type **atypes; ! ffi_type *rtype; ! void **avalues; PyObject *retval = NULL; --- 711,723 ---- { int i, n, argcount, argtype_count; ! struct argument *pa; ! ! struct argument *args; /* array of temp storage for arguments */ ! ! ffi_type **atypes; /* array of argument ffi_types */ ! void **avalues; /* array of pointers to libffi argument values */ ! ffi_type *rtype; /* return value ffi_type */ ! void *rvalue; /* pointer to libffi return value */ ! PyObject *retval = NULL; *************** *** 722,729 **** if (pIunk) ++argcount; args = (struct argument *)alloca(sizeof(struct argument) * argcount); memset(args, 0, sizeof(struct argument) * argcount); ! argtype_count = argtypes ? PyTuple_GET_SIZE(argtypes) : 0; if (pIunk) { args[0].ffi_type = &ffi_type_pointer; --- 726,738 ---- if (pIunk) ++argcount; + argtype_count = argtypes ? PyTuple_GET_SIZE(argtypes) : 0; + rtype = GetType(restype); args = (struct argument *)alloca(sizeof(struct argument) * argcount); memset(args, 0, sizeof(struct argument) * argcount); ! rvalue = alloca(max(rtype->size, sizeof(ffi_arg))); ! avalues = (void **)alloca(sizeof(void *) * argcount); ! atypes = (ffi_type **)alloca(sizeof(ffi_type *) * argcount); ! if (pIunk) { args[0].ffi_type = &ffi_type_pointer; *************** *** 771,779 **** } - rtype = GetType(restype); - resbuf = alloca(max(rtype->size, sizeof(ffi_arg))); - - avalues = (void **)alloca(sizeof(void *) * argcount); - atypes = (ffi_type **)alloca(sizeof(ffi_type *) * argcount); for (i = 0; i < argcount; ++i) { atypes[i] = args[i].ffi_type; --- 780,783 ---- *************** *** 785,802 **** if (-1 == _call_function_pointer(flags, pProc, avalues, atypes, ! rtype, resbuf, argcount)) goto cleanup; #ifdef MS_WIN32 if (flags & FUNCFLAG_HRESULT) { ! if (*(int *)resbuf & 0x80000000) ! retval = PyErr_SetFromWindowsErr(*(int *)resbuf); else ! retval = PyInt_FromLong(*(int *)resbuf); } else #endif ! retval = GetResult(restype, resbuf, checker); /* Overwrite result memory, to catch bugs. */ ! memset(resbuf, 0x55, max(rtype->size, sizeof(ffi_arg))); cleanup: for (i = 0; i < argcount; ++i) --- 789,806 ---- if (-1 == _call_function_pointer(flags, pProc, avalues, atypes, ! rtype, rvalue, argcount)) goto cleanup; #ifdef MS_WIN32 if (flags & FUNCFLAG_HRESULT) { ! if (*(int *)rvalue & 0x80000000) ! retval = PyErr_SetFromWindowsErr(*(int *)rvalue); else ! retval = PyInt_FromLong(*(int *)rvalue); } else #endif ! retval = GetResult(restype, rvalue, checker); /* Overwrite result memory, to catch bugs. */ ! memset(rvalue, 0x55, max(rtype->size, sizeof(ffi_arg))); cleanup: for (i = 0; i < argcount; ++i) |
From: Thomas H. <th...@us...> - 2005-04-07 12:50:18
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3818 Modified Files: Tag: branch_1_0 _ctypes.c Log Message: Changed version number to 0.9.8. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.1 retrieving revision 1.226.2.2 diff -C2 -d -r1.226.2.1 -r1.226.2.2 *** _ctypes.c 4 Apr 2005 15:51:04 -0000 1.226.2.1 --- _ctypes.c 7 Apr 2005 12:50:08 -0000 1.226.2.2 *************** *** 4051,4055 **** PyModule_AddObject(m, "FUNCFLAG_CDECL", PyInt_FromLong(FUNCFLAG_CDECL)); PyModule_AddObject(m, "FUNCFLAG_PYTHONAPI", PyInt_FromLong(FUNCFLAG_PYTHONAPI)); ! PyModule_AddStringConstant(m, "__version__", "0.9.6"); PyExc_ArgError = PyErr_NewException("ctypes.ArgumentError", NULL, NULL); --- 4051,4055 ---- PyModule_AddObject(m, "FUNCFLAG_CDECL", PyInt_FromLong(FUNCFLAG_CDECL)); PyModule_AddObject(m, "FUNCFLAG_PYTHONAPI", PyInt_FromLong(FUNCFLAG_PYTHONAPI)); ! PyModule_AddStringConstant(m, "__version__", "0.9.8"); PyExc_ArgError = PyErr_NewException("ctypes.ArgumentError", NULL, NULL); |
From: Thomas H. <th...@us...> - 2005-04-07 12:49:52
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3738 Modified Files: Tag: branch_1_0 __init__.py Log Message: Changed version number to 0.9.8. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.61 retrieving revision 1.61.2.1 diff -C2 -d -r1.61 -r1.61.2.1 *** __init__.py 18 Mar 2005 17:39:31 -0000 1.61 --- __init__.py 7 Apr 2005 12:49:43 -0000 1.61.2.1 *************** *** 9,13 **** del _magicfile ! __version__ = "0.9.6" from _ctypes import Union, Structure, Array --- 9,13 ---- del _magicfile ! __version__ = "0.9.8" from _ctypes import Union, Structure, Array *************** *** 212,217 **** class c_char_p(_SimpleCData): _type_ = "z" ! def __repr__(self): ! return "%s(%r)" % (self.__class__.__name__, self.value) class c_void_p(_SimpleCData): --- 212,224 ---- class c_char_p(_SimpleCData): _type_ = "z" ! if _os.name == "nt": ! def __repr__(self): ! if windll.kernel32.IsBadStringPtrA(self, -1): ! return "%s(0x%x)" % (self.__class__.__name__, cast(self, c_uint).value) ! else: ! return "%s(%r)" % (self.__class__.__name__, self.value) ! else: ! def __repr__(self): ! return "%s(%r)" % (self.__class__.__name__, self.value) class c_void_p(_SimpleCData): *************** *** 255,260 **** class c_wchar_p(_SimpleCData): _type_ = "Z" ! def __repr__(self): ! return "%s(%r)" % (self.__class__.__name__, self.value) class c_wchar(_SimpleCData): --- 262,274 ---- class c_wchar_p(_SimpleCData): _type_ = "Z" ! if _os.name == "nt": ! def __repr__(self): ! if windll.kernel32.IsBadStringPtrW(self, -1): ! return "%s(0x%x)" % (self.__class__.__name__, cast(self, c_uint).value) ! else: ! return "%s(%r)" % (self.__class__.__name__, self.value) ! else: ! def __repr__(self): ! return "%s(%r)" % (self.__class__.__name__, self.value) class c_wchar(_SimpleCData): |
From: Thomas H. <th...@us...> - 2005-04-07 12:49:50
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3676 Modified Files: Tag: branch_1_0 setup.py ChangeLog Log Message: Changed version number to 0.9.8. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.122 retrieving revision 1.122.2.1 diff -C2 -d -r1.122 -r1.122.2.1 *** setup.py 17 Mar 2005 19:30:07 -0000 1.122 --- setup.py 7 Apr 2005 12:49:28 -0000 1.122.2.1 *************** *** 12,16 **** LIBFFI_SOURCES='source/gcc/libffi' ! __version__ = "0.9.6" ################################################################ --- 12,16 ---- LIBFFI_SOURCES='source/gcc/libffi' ! __version__ = "0.9.8" ################################################################ Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.86.2.1 retrieving revision 1.86.2.2 diff -C2 -d -r1.86.2.1 -r1.86.2.2 *** ChangeLog 4 Apr 2005 15:55:55 -0000 1.86.2.1 --- ChangeLog 7 Apr 2005 12:49:35 -0000 1.86.2.2 *************** *** 1,2 **** --- 1,6 ---- + 2005-04-07 Thomas Heller <th...@py...> + + * Changed version number to 0.9.8. + 2005-04-04 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2005-04-07 10:12:14
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11491 Modified Files: ChangeLog Log Message: Record changes. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.87 retrieving revision 1.88 diff -C2 -d -r1.87 -r1.88 *** ChangeLog 1 Apr 2005 19:29:43 -0000 1.87 --- ChangeLog 7 Apr 2005 10:11:58 -0000 1.88 *************** *** 1,2 **** --- 1,17 ---- + 2005-04-06 Thomas Heller <th...@py...> + + * c_char_p and c_wchar_p no longer accept integers or longs in the + constructor or in their from_param method. Use cast instead. + + * c_char_p/c_wchar_p instances, c_char/c_wchar arrays, and + byref(c_char/c_wchar) can now be assigned to c_char_p/c_wchar_p + structure fields. + + 2005-04-05 Thomas Heller <th...@py...> + + * source/cfield.c: get_long, get_ulong, get_longlong and + get_ulonglong now accept all ctypes int/uint instances in addition + to Python int and long. + 2005-04-01 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2005-04-07 09:26:49
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19917 Modified Files: test_complete_cover.py Log Message: Make the test work when unicode not available. Index: test_complete_cover.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_complete_cover.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** test_complete_cover.py 6 Apr 2005 18:38:15 -0000 1.5 --- test_complete_cover.py 7 Apr 2005 09:26:36 -0000 1.6 *************** *** 7,19 **** # tests to make coverage of source/cfield.c more complete ! class X(Structure): ! _fields_ = [("a", c_long), ! ("b", c_long, 3), ! ("u", c_wchar), ! ("U", c_wchar * 3), ! ("z", c_char_p), ! ("Z", c_wchar_p), ! ("P", c_void_p), ! ("p", POINTER(c_long))] self.failUnlessEqual(repr(X.a), "<Field type=c_long, ofs=0, size=4>") --- 7,31 ---- # tests to make coverage of source/cfield.c more complete ! has_wchar = False ! try: ! c_wchar ! has_wchar = True ! except NameError: ! class X(Structure): ! _fields_ = [("a", c_long), ! ("b", c_long, 3), ! ("z", c_char_p), ! ("P", c_void_p), ! ("p", POINTER(c_long))] ! else: ! class X(Structure): ! _fields_ = [("a", c_long), ! ("b", c_long, 3), ! ("u", c_wchar), ! ("U", c_wchar * 3), ! ("z", c_char_p), ! ("Z", c_wchar_p), ! ("P", c_void_p), ! ("p", POINTER(c_long))] self.failUnlessEqual(repr(X.a), "<Field type=c_long, ofs=0, size=4>") *************** *** 22,42 **** X().p = None ! # single unicode character ! self.failUnlessRaises(TypeError, lambda: setattr(X(), "u", 42)) ! self.failUnlessRaises(TypeError, lambda: setattr(X(), "u", "abc")) ! ## self.failUnlessRaises(UnicodeDecodeError, lambda: setattr(X(), "u", "ä")) ! # unicode array ! self.failUnlessRaises(TypeError, lambda: setattr(X(), "U", 42)) ! X().U = "abc" ! ## self.failUnlessRaises(UnicodeDecodeError, lambda: setattr(X(), "U", "ä")) self.failUnlessRaises(TypeError, lambda: setattr(X(), "z", 42)) X().z = cast(42, c_char_p) - self.failUnlessRaises(TypeError, lambda: setattr(X(), "Z", 42)) - self.failUnlessRaises(TypeError, lambda: setattr(X(), "Z", 3.14)) - X().Z = cast(42, c_wchar_p) - x = X() x.P = None --- 34,56 ---- X().p = None ! if has_wchar: ! # single unicode character ! self.failUnlessRaises(TypeError, lambda: setattr(X(), "u", 42)) ! self.failUnlessRaises(TypeError, lambda: setattr(X(), "u", "abc")) ! ## self.failUnlessRaises(UnicodeDecodeError, lambda: setattr(X(), "u", "ä")) ! # unicode array ! self.failUnlessRaises(TypeError, lambda: setattr(X(), "U", 42)) ! X().U = "abc" ! ## self.failUnlessRaises(UnicodeDecodeError, lambda: setattr(X(), "U", "ä")) ! ! self.failUnlessRaises(TypeError, lambda: setattr(X(), "Z", 42)) ! X().Z = cast(42, c_wchar_p) ! ! self.failUnlessRaises(TypeError, lambda: setattr(X(), "Z", 3.14)) self.failUnlessRaises(TypeError, lambda: setattr(X(), "z", 42)) X().z = cast(42, c_char_p) x = X() x.P = None |
From: Thomas H. <th...@us...> - 2005-04-07 09:21:44
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16329 Modified Files: test_callbacks.py Log Message: Remove debug print. Index: test_callbacks.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_callbacks.py,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** test_callbacks.py 7 Apr 2005 07:45:09 -0000 1.22 --- test_callbacks.py 7 Apr 2005 09:21:35 -0000 1.23 *************** *** 12,16 **** def tearDown(self): import gc ! print gc.collect() def callback(self, *args): --- 12,16 ---- def tearDown(self): import gc ! gc.collect() def callback(self, *args): |
From: Thomas H. <th...@us...> - 2005-04-07 07:48:00
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26623/source Modified Files: callbacks.c Log Message: Beautify a big endian hack Index: callbacks.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v retrieving revision 1.77 retrieving revision 1.78 diff -C2 -d -r1.77 -r1.78 *** callbacks.c 6 Apr 2005 15:10:28 -0000 1.77 --- callbacks.c 7 Apr 2005 07:47:48 -0000 1.78 *************** *** 234,273 **** CHECK("'calling callback function'", result); if (result && result != Py_None) { /* XXX What is returned for Py_None ? */ - /* another big endian hack */ - union { - char c; - short s; - int i; - long l; - } r; PyObject *keep; ! switch (pinfo->ffi_restype->size) { ! case 1: ! keep = pinfo->setfunc(&r, result, 0, pinfo->restype); ! CHECK("'converting callback result'", keep); ! *(ffi_arg *)mem = r.c; ! break; ! case SIZEOF_SHORT: ! keep = pinfo->setfunc(&r, result, 0, pinfo->restype); ! CHECK("'converting callback result'", keep); ! *(ffi_arg *)mem = r.s; ! break; ! case SIZEOF_INT: ! keep = pinfo->setfunc(&r, result, 0, pinfo->restype); ! CHECK("'converting callback result'", keep); ! *(ffi_arg *)mem = r.i; ! break; ! #if (SIZEOF_LONG != SIZEOF_INT) ! case SIZEOF_LONG: ! keep = pinfo->setfunc(&r, result, 0, pinfo->restype); ! CHECK("'converting callback result'", keep); ! *(ffi_arg *)mem = r.l; ! break; ! #endif ! default: ! keep = pinfo->setfunc(mem, result, 0, pinfo->restype); ! CHECK("'converting callback result'", keep); ! break; } /* assert (keep == Py_None); */ /* XXX We have no way to keep the needed reference XXX */ --- 234,247 ---- CHECK("'calling callback function'", result); if (result && result != Py_None) { /* XXX What is returned for Py_None ? */ PyObject *keep; ! #if IS_BIG_ENDIAN ! if (pinfo->ffi_restype->size < sizeof(ffi_arg)) { ! char *ptr = mem; ! ptr += sizeof(ffi_arg) - pinfo->ffi_restype->size; ! mem = ptr; } + #endif + keep = pinfo->setfunc(mem, result, 0, pinfo->restype); + CHECK("'converting callback result'", keep); /* assert (keep == Py_None); */ /* XXX We have no way to keep the needed reference XXX */ |
From: Thomas H. <th...@us...> - 2005-04-07 07:45:26
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25818/unittests Modified Files: test_callbacks.py Log Message: comments abolut OS X Index: test_callbacks.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_callbacks.py,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** test_callbacks.py 21 Oct 2004 08:06:17 -0000 1.21 --- test_callbacks.py 7 Apr 2005 07:45:09 -0000 1.22 *************** *** 3,12 **** import _ctypes_test class Callbacks(unittest.TestCase): functype = CFUNCTYPE ! ## def tearDown(self): ! ## import gc ! ## gc.collect() def callback(self, *args): --- 3,16 ---- import _ctypes_test + # This behaves strange on OS X. Commenting out the tearDown makes the tests crash + # with illegal instruction, however that occurs only when more than one test is run. + # A single test does work. + class Callbacks(unittest.TestCase): functype = CFUNCTYPE ! def tearDown(self): ! import gc ! print gc.collect() def callback(self, *args): |
From: Thomas H. <th...@us...> - 2005-04-06 20:39:29
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29255 Modified Files: _ctypes.c Log Message: TODO comment, thoughts. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.293 retrieving revision 1.294 diff -C2 -d -r1.293 -r1.294 *** _ctypes.c 6 Apr 2005 19:23:50 -0000 1.293 --- _ctypes.c 6 Apr 2005 20:39:11 -0000 1.294 *************** *** 1,2 **** --- 1,31 ---- + /* + TODO: + ===== + + It seems we need a FROMPARAM slot in the storage dict. We cannot use + SETFUNC for that, because SETFUNC completely copies the instance into a + memory block. + + int FROMPARAM(PyObject *value, struct argument *pa, PyObject *type); + + + AND: + + Maybe 'struct argument' should be changed to remove the special casing of + structure types. Currently, 'struct argument' contains the value itself + except for structure types, where it contains a pointer to the data. + + It would probably be better to have only a pointer in 'struct argument' + which is set by FROMPARAM and ASPARAM to point to the data. + + struct argument { + ffi_type *ffi_type; + PyObject *keep; + void *pdata; + } + + In this way, FROMPARAM does not need to allocate a new object. + + */ /* The most important internal functions: |
From: Thomas H. <th...@us...> - 2005-04-06 19:24:00
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13364 Modified Files: _ctypes.c Log Message: string_ptr_from_param and SimpleType_from_param now do exactly the same. Remove them and use a generic_from_param function. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.292 retrieving revision 1.293 diff -C2 -d -r1.292 -r1.293 *** _ctypes.c 6 Apr 2005 19:12:47 -0000 1.292 --- _ctypes.c 6 Apr 2005 19:23:50 -0000 1.293 *************** *** 1201,1221 **** /******************************************************************/ - /* - SimpleType_Type - */ - /* - - SimpleType_new ensures that the new Simple_Type subclass created has a valid - _type_ attribute. - - */ - - static char *SIMPLE_TYPE_CHARS = "cbBhHiIlLdfuzZqQPXOv"; - static PyObject * ! string_ptr_from_param(PyObject *type, PyObject *value) { StgDictObject *typedict = PyType_stgdict(type); PyCArgObject *parg = new_CArgObject(); /* This makes function calls somewhat slower, imo, since a PyCArgObject is allocated for each argument. When from_param will --- 1201,1211 ---- /******************************************************************/ static PyObject * ! generic_from_param(PyObject *type, PyObject *value) { StgDictObject *typedict = PyType_stgdict(type); PyCArgObject *parg = new_CArgObject(); + if (parg == NULL) + return NULL; /* This makes function calls somewhat slower, imo, since a PyCArgObject is allocated for each argument. When from_param will *************** *** 1223,1227 **** can be made faster again. */ ! parg->pffi_type = &ffi_type_pointer; parg->obj = typedict->setfunc(&parg->value, value, 0, type); if (parg->obj == NULL) { --- 1213,1217 ---- can be made faster again. */ ! parg->pffi_type = &typedict->ffi_type; parg->obj = typedict->setfunc(&parg->value, value, 0, type); if (parg->obj == NULL) { *************** *** 1232,1235 **** --- 1222,1237 ---- } + /* + SimpleType_Type + */ + /* + + SimpleType_new ensures that the new Simple_Type subclass created has a valid + _type_ attribute. + + */ + + static char *SIMPLE_TYPE_CHARS = "cbBhHiIlLdfuzZqQPXOv"; + static PyObject * c_void_p_from_param(PyObject *type, PyObject *value) *************** *** 1304,1309 **** 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 --- 1306,1309 ---- *************** *** 1375,1380 **** result->tp_dict = (PyObject *)stgdict; ! /* Install from_param class methods in ctypes base classes. ! Overrides the SimpleType_from_param generic method. */ ml = NULL; --- 1375,1380 ---- result->tp_dict = (PyObject *)stgdict; ! /* Install special from_param class methods in ctypes base classes. ! Overrides the generic_from_param generic method. */ ml = NULL; *************** *** 1382,1386 **** switch (PyString_AS_STRING(proto)[0]) { case 'z': /* c_char_p */ - ml = &c_char_p_method; if (CTYPE_c_char == NULL) { PyErr_SetString(PyExc_RuntimeError, --- 1382,1385 ---- *************** *** 1395,1399 **** break; case 'Z': /* c_wchar_p */ - ml = &c_wchar_p_method; if (CTYPE_c_wchar == NULL) { PyErr_SetString(PyExc_RuntimeError, --- 1394,1397 ---- *************** *** 1462,1487 **** - if converters[i] is NULL: call argtypes[i]->setfunc with the actual argument, use the result */ - static PyObject * - SimpleType_from_param(PyObject *type, PyObject *value) - { - 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) { - Py_DECREF(parg); - return NULL; - } - return (PyObject *)parg; - } static PyMethodDef SimpleType_methods[] = { ! { "from_param", SimpleType_from_param, METH_O, from_param_doc }, { "from_address", CDataType_from_address, METH_O, from_address_doc }, { "in_dll", CDataType_in_dll, METH_VARARGS, in_dll_doc}, --- 1460,1466 ---- - if converters[i] is NULL: call argtypes[i]->setfunc with the actual argument, use the result */ static PyMethodDef SimpleType_methods[] = { ! { "from_param", generic_from_param, METH_O, from_param_doc }, { "from_address", CDataType_from_address, METH_O, from_address_doc }, { "in_dll", CDataType_in_dll, METH_VARARGS, in_dll_doc}, |
From: Thomas H. <th...@us...> - 2005-04-06 19:12:57
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6878 Modified Files: _ctypes.c Log Message: oops. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.291 retrieving revision 1.292 diff -C2 -d -r1.291 -r1.292 *** _ctypes.c 6 Apr 2005 19:00:29 -0000 1.291 --- _ctypes.c 6 Apr 2005 19:12:47 -0000 1.292 *************** *** 1217,1220 **** --- 1217,1221 ---- { StgDictObject *typedict = PyType_stgdict(type); + PyCArgObject *parg = new_CArgObject(); /* This makes function calls somewhat slower, imo, since a PyCArgObject is allocated for each argument. When from_param will *************** *** 1222,1226 **** can be made faster again. */ - parg = new_CArgObject(); parg->pffi_type = &ffi_type_pointer; parg->obj = typedict->setfunc(&parg->value, value, 0, type); --- 1223,1226 ---- |
From: Thomas H. <th...@us...> - 2005-04-06 19:00:50
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32269 Modified Files: cfield.c _ctypes.c Log Message: z_set and Z_set now accept a byref to a c_char/c_wchar instance. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.111 retrieving revision 1.112 diff -C2 -d -r1.111 -r1.112 *** cfield.c 6 Apr 2005 18:35:40 -0000 1.111 --- cfield.c 6 Apr 2005 19:00:28 -0000 1.112 *************** *** 816,819 **** --- 816,832 ---- return str; } + /* Pointer to a single character. Not sure if this makes sense, since + c_char_p should be used to represent a pointer to a zero terminated + string. + */ + if (PyCArg_CheckExact(value)) { + /* byref(c_char instance) */ + PyCArgObject *carg = (PyCArgObject *)value; + if (PyObject_IsInstance(carg->obj, CTYPE_c_char)) { + *(char **)ptr = ((CDataObject *)carg->obj)->b_ptr; + Py_INCREF(value); + return value; + } + } /* Do we want to allow c_wchar_p also, with conversion? */ if (PyObject_IsInstance(value, CTYPE_c_char_p)) { *************** *** 871,874 **** --- 884,900 ---- return value; } + /* Pointer to a single character. Not sure if this makes sense, since + c_char_p should be used to represent a pointer to a zero terminated + string. + */ + if (PyCArg_CheckExact(value)) { + /* byref(c_char instance) */ + PyCArgObject *carg = (PyCArgObject *)value; + if (PyObject_IsInstance(carg->obj, CTYPE_c_wchar)) { + *(wchar_t **)ptr = (wchar_t *)((CDataObject *)carg->obj)->b_ptr; + Py_INCREF(value); + return value; + } + } if (ArrayObject_Check(value)) { PyObject *itemtype = PyObject_stgdict(value)->itemtype; Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.290 retrieving revision 1.291 diff -C2 -d -r1.290 -r1.291 *** _ctypes.c 6 Apr 2005 18:35:40 -0000 1.290 --- _ctypes.c 6 Apr 2005 19:00:29 -0000 1.291 *************** *** 1217,1231 **** { StgDictObject *typedict = PyType_stgdict(type); ! PyCArgObject *parg; ! ! if (PyCArg_CheckExact(value)) { ! /* byref(c_char(...)) */ ! PyCArgObject *a = (PyCArgObject *)value; ! if (PyObject_IsInstance(a->obj, typedict->itemtype)) { ! Py_INCREF(value); ! return value; ! } ! } ! /* Call setfunc */ parg = new_CArgObject(); parg->pffi_type = &ffi_type_pointer; --- 1217,1225 ---- { StgDictObject *typedict = PyType_stgdict(type); ! /* This makes function calls somewhat slower, imo, since a ! PyCArgObject is allocated for each argument. When from_param will ! be a slot function in the stgdict, the signature can change and it ! can be made faster again. ! */ parg = new_CArgObject(); parg->pffi_type = &ffi_type_pointer; |
From: Thomas H. <th...@us...> - 2005-04-06 18:40:40
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23303 Modified Files: test_stringptr.py test_setfunc.py Log Message: c_char_p and c_wchar_p setfunc does now accept arrays of c_char/c_wchar or pointers to them. Moved this code from string_ptr_from_param into z_set and Z_set. Index: test_stringptr.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_stringptr.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** test_stringptr.py 22 Jul 2004 12:41:26 -0000 1.8 --- test_stringptr.py 6 Apr 2005 18:40:31 -0000 1.9 *************** *** 48,57 **** # c_char_p and Python string is compatible ! # c_char_p and c_buffer is NOT compatible self.failUnlessEqual(x.str, None) x.str = "Hello, World" self.failUnlessEqual(x.str, "Hello, World") b = c_buffer("Hello, World") ! self.failUnlessRaises(TypeError, setattr, x, "str", b) --- 48,60 ---- # c_char_p and Python string is compatible ! # c_char_p and c_buffer IS NOW compatible self.failUnlessEqual(x.str, None) x.str = "Hello, World" self.failUnlessEqual(x.str, "Hello, World") b = c_buffer("Hello, World") ! x.str = b ! self.failUnlessEqual(x.str, "Hello, World") ! b.value = "spam, spam" ! self.failUnlessEqual(x.str, "spam, spam") Index: test_setfunc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_setfunc.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_setfunc.py 5 Apr 2005 19:30:28 -0000 1.1 --- test_setfunc.py 6 Apr 2005 18:40:31 -0000 1.2 *************** *** 29,33 **** if obj == param: continue ! self.failUnlessEqual(repr(param), "<cparam '%s' (42)>" % cls._type_) for obj in (c_char("x"), c_char_p("x"), "x", c_float(42), c_double(42), 42.0): --- 29,34 ---- if obj == param: continue ! self.failUnlessEqual(repr(param), "<cparam '%s' (42)>" % cls._type_, ! (repr(param), obj, cls, cls._type_)) for obj in (c_char("x"), c_char_p("x"), "x", c_float(42), c_double(42), 42.0): *************** *** 46,49 **** --- 47,63 ---- self.assertRaises(TypeError, setattr, x, "v", obj) + class TestStrings(unittest.TestCase): + + def test_init(self): + pass + + def test_fromparam(self): + c_char_p.from_param("abc") + c_char_p.from_param(u"abc") + c_char_p.from_param(c_char_p("abc")) + c_char_p.from_param(byref(c_char("x"))) + #fails print c_char_p.from_param(c_wchar_p(u"abc")) + print c_char_p.from_param(cast(42, c_char_p)) + if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2005-04-06 18:39:15
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22425 Modified Files: test_parameters.py Log Message: c_char_p and c_wchar_p setfunc does now accept arrays of c_char/c_wchar or pointers to them. Moved this code from string_ptr_from_param into z_set and Z_set. Index: test_parameters.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_parameters.py,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** test_parameters.py 6 Apr 2005 15:25:03 -0000 1.29 --- test_parameters.py 6 Apr 2005 18:39:06 -0000 1.30 *************** *** 67,71 **** # returns the argument itself: a = c_char_p("123") ! self.failUnless(c_char_p.from_param(a) is a) def test_cw_strings(self): --- 67,72 ---- # returns the argument itself: a = c_char_p("123") ! c_char_p.from_param(a) ! ## self.failUnless(c_char_p.from_param(a) is a) def test_cw_strings(self): *************** *** 86,90 **** pa = c_wchar_p.from_param(c_wchar_p(u"123")) ! self.failUnlessEqual(type(pa), c_wchar_p) def test_int_pointers(self): --- 87,91 ---- pa = c_wchar_p.from_param(c_wchar_p(u"123")) ! ## self.failUnlessEqual(type(pa), c_wchar_p) def test_int_pointers(self): |
From: Thomas H. <th...@us...> - 2005-04-06 18:38:24
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21943 Modified Files: test_complete_cover.py Log Message: c_char_p and c_wchar_p setfunc does now accept arrays of c_char/c_wchar or pointers to them. Moved this code from string_ptr_from_param into z_set and Z_set. Index: test_complete_cover.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_complete_cover.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test_complete_cover.py 31 Mar 2005 13:46:22 -0000 1.4 --- test_complete_cover.py 6 Apr 2005 18:38:15 -0000 1.5 *************** *** 32,39 **** ## self.failUnlessRaises(UnicodeDecodeError, lambda: setattr(X(), "U", "ä")) ! X().z = 42 ! X().Z = 42 self.failUnlessRaises(TypeError, lambda: setattr(X(), "Z", 3.14)) x = X() --- 32,41 ---- ## self.failUnlessRaises(UnicodeDecodeError, lambda: setattr(X(), "U", "ä")) ! self.failUnlessRaises(TypeError, lambda: setattr(X(), "z", 42)) ! X().z = cast(42, c_char_p) ! self.failUnlessRaises(TypeError, lambda: setattr(X(), "Z", 42)) self.failUnlessRaises(TypeError, lambda: setattr(X(), "Z", 3.14)) + X().Z = cast(42, c_wchar_p) x = X() *************** *** 80,83 **** --- 82,88 ---- # from_param print c_int.from_param(c_int(42)) + ## print c_int.from_param(c_longlong(42L)) + ## c = c_char("x") + ## print c_int.from_param(c) def test_pointer(self): |
From: Thomas H. <th...@us...> - 2005-04-06 18:35:54
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19997 Modified Files: cfield.c _ctypes.c Log Message: c_char_p and c_wchar_p setfunc does now accept arrays of c_char/c_wchar or pointers to them. Moved this code from string_ptr_from_param into z_set and Z_set. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.110 retrieving revision 1.111 diff -C2 -d -r1.110 -r1.111 *** cfield.c 6 Apr 2005 16:42:56 -0000 1.110 --- cfield.c 6 Apr 2005 18:35:40 -0000 1.111 *************** *** 801,815 **** 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); Py_INCREF(value); return value; ! } else if (PyUnicode_Check(value)) { PyObject *str = PyUnicode_AsEncodedString(value, conversion_mode_encoding, --- 801,810 ---- return value; } if (PyString_Check(value)) { *(char **)ptr = PyString_AS_STRING(value); Py_INCREF(value); return value; ! } ! if (PyUnicode_Check(value)) { PyObject *str = PyUnicode_AsEncodedString(value, conversion_mode_encoding, *************** *** 821,824 **** --- 816,841 ---- return str; } + /* 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 (ArrayObject_Check(value)) { + PyObject *itemtype = PyObject_stgdict(value)->itemtype; + if (PyObject_IsSubclass(itemtype, CTYPE_c_char)) { + *(char **)ptr = ((CDataObject *)value)->b_ptr; + Py_INCREF(value); + return value; + } + } + if (PointerObject_Check(value)) { + PyObject *itemtype = PyObject_stgdict(value)->itemtype; + if (PyObject_IsSubclass(itemtype, CTYPE_c_char)) { + *(char **)ptr = *(char **)((CDataObject *)value)->b_ptr; + Py_INCREF(value); + return value; + } + } PyErr_Format(PyExc_TypeError, "string or integer address expected instead of %s instance", *************** *** 854,857 **** --- 871,890 ---- return value; } + if (ArrayObject_Check(value)) { + PyObject *itemtype = PyObject_stgdict(value)->itemtype; + if (PyObject_IsSubclass(itemtype, CTYPE_c_wchar)) { + *(char **)ptr = ((CDataObject *)value)->b_ptr; + Py_INCREF(value); + return value; + } + } + if (PointerObject_Check(value)) { + PyObject *itemtype = PyObject_stgdict(value)->itemtype; + if (PyObject_IsSubclass(itemtype, CTYPE_c_wchar)) { + *(char **)ptr = *(char **)((CDataObject *)value)->b_ptr; + Py_INCREF(value); + return value; + } + } if (PyString_Check(value)) { value = PyUnicode_FromEncodedObject(value, Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.289 retrieving revision 1.290 diff -C2 -d -r1.289 -r1.290 *** _ctypes.c 6 Apr 2005 16:44:47 -0000 1.289 --- _ctypes.c 6 Apr 2005 18:35:40 -0000 1.290 *************** *** 1219,1230 **** PyCArgObject *parg; - 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; - } - } if (PyCArg_CheckExact(value)) { /* byref(c_char(...)) */ --- 1219,1222 ---- *************** *** 3721,3725 **** }; ! static PyTypeObject Pointer_Type = { PyObject_HEAD_INIT(NULL) 0, --- 3713,3717 ---- }; ! PyTypeObject Pointer_Type = { PyObject_HEAD_INIT(NULL) 0, |
From: Thomas H. <th...@us...> - 2005-04-06 16:45:07
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30233 Modified Files: _ctypes.c Log Message: Make the CTYPE_... types global. Add c_char_p and c_wchar_p. Moved some code from string_ptr_from_param into z_set and Z_get. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.288 retrieving revision 1.289 diff -C2 -d -r1.288 -r1.289 *** _ctypes.c 6 Apr 2005 15:54:47 -0000 1.288 --- _ctypes.c 6 Apr 2005 16:44:47 -0000 1.289 *************** *** 171,175 **** /* Some simple types */ ! static PyObject *CTYPE_c_char, *CTYPE_c_wchar, *CTYPE_c_void_p, *CTYPE_BSTR; static PyObject * --- 171,175 ---- /* Some simple types */ ! PyObject *CTYPE_c_char_p, *CTYPE_c_char, *CTYPE_c_wchar, *CTYPE_c_wchar_p, *CTYPE_c_void_p, *CTYPE_BSTR; static PyObject * *************** *** 1217,1220 **** --- 1217,1221 ---- { StgDictObject *typedict = PyType_stgdict(type); + PyCArgObject *parg; if (ArrayObject_Check(value) || PointerObject_Check(value)) { *************** *** 1234,1260 **** } } ! 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)) { ! /* 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, ! "wrong type"); ! return NULL; } --- 1235,1247 ---- } } ! /* Call setfunc */ ! 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; } *************** *** 1418,1421 **** --- 1405,1410 ---- Py_INCREF(CTYPE_c_char); stgdict->itemtype = CTYPE_c_char; + assert(CTYPE_c_char_p == NULL); + CTYPE_c_char_p = (PyObject *)result; break; case 'Z': /* c_wchar_p */ *************** *** 1429,1432 **** --- 1418,1423 ---- Py_INCREF(CTYPE_c_wchar); stgdict->itemtype = CTYPE_c_wchar; + assert(CTYPE_c_wchar_p == NULL); + CTYPE_c_wchar_p = (PyObject *)result; break; case 'P': /* c_void_p */ |