ctypes-commit Mailing List for ctypes (Page 56)
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-22 15:40:14
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16808 Modified Files: Tag: branch_1_0 test_returnfuncptrs.py Log Message: fix the test for 64-bit platforms Index: test_returnfuncptrs.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_returnfuncptrs.py,v retrieving revision 1.8 retrieving revision 1.8.6.1 diff -C2 -d -r1.8 -r1.8.6.1 *** test_returnfuncptrs.py 14 Oct 2004 13:16:13 -0000 1.8 --- test_returnfuncptrs.py 22 Apr 2005 15:40:03 -0000 1.8.6.1 *************** *** 23,26 **** --- 23,28 ---- dll = CDLL(find_test_dll()) get_strchr = dll.get_strchr + # the default 'c_int' would not work on systems where sizeof(int) != sizeof(void *) + get_strchr.restype = c_void_p addr = get_strchr() # _CFuncPtr instances are now callable with an integer argument |
From: Thomas H. <th...@us...> - 2005-04-22 15:18:01
|
Update of /cvsroot/ctypes/ctypes/source/gcc/libffi/src/x86 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2175 Modified Files: unix64.S Log Message: Make VARARGS calls work on AMD x86. Patch provided by Andreas Degert, see the links in the source code for more info. Index: unix64.S =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/gcc/libffi/src/x86/unix64.S,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** unix64.S 18 Jun 2004 20:07:15 -0000 1.1 --- unix64.S 22 Apr 2005 15:17:51 -0000 1.2 *************** *** 88,91 **** --- 88,98 ---- addq $176, %rsp .LCFI6: + /* Set %rax to max. number of used SSE registers for vararg calls. + See also: + http://article.gmane.org/gmane.comp.python.ctypes/1702 + http://article.gmane.org/gmane.comp.python.ctypes/1703 + */ + movq $8, %rax + /* Call the user function. */ call *-48(%rbp) |
From: Thomas H. <th...@us...> - 2005-04-22 15:16:53
|
Update of /cvsroot/ctypes/ctypes/source/gcc/libffi/src/x86 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1395 Modified Files: Tag: branch_1_0 unix64.S Log Message: Make VARARGS calls work on AMD x86. Patch provided by Andreas Degert, see the links in the source code for more info. Index: unix64.S =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/gcc/libffi/src/x86/unix64.S,v retrieving revision 1.1 retrieving revision 1.1.4.1 diff -C2 -d -r1.1 -r1.1.4.1 *** unix64.S 18 Jun 2004 20:07:15 -0000 1.1 --- unix64.S 22 Apr 2005 15:16:40 -0000 1.1.4.1 *************** *** 88,91 **** --- 88,98 ---- addq $176, %rsp .LCFI6: + /* Set %rax to max. number of used SSE registers for vararg calls. + See also: + http://article.gmane.org/gmane.comp.python.ctypes/1702 + http://article.gmane.org/gmane.comp.python.ctypes/1703 + */ + movq $8, %rax + /* Call the user function. */ call *-48(%rbp) |
From: Thomas H. <th...@us...> - 2005-04-19 13:06:47
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10261 Modified Files: Tag: branch_1_0 callproc.c Log Message: Fix functions returning function pointers, where sizeof(void*) != sizeof(int) Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.127.2.4 retrieving revision 1.127.2.5 diff -C2 -d -r1.127.2.4 -r1.127.2.5 *** callproc.c 19 Apr 2005 12:45:26 -0000 1.127.2.4 --- callproc.c 19 Apr 2005 13:06:34 -0000 1.127.2.5 *************** *** 769,772 **** --- 769,782 ---- } } + /* void* may have different size than int, so special case this. */ + if (CFuncPtrTypeObject_Check(restype)) { + PyObject *addr = PyLong_FromVoidPtr(*(void **)result); + PyObject *o; + if (addr == NULL) + return NULL; + o = PyObject_CallFunction(restype, "O", addr); + Py_DECREF(addr); + return o; + } if (PyCallable_Check(restype)) return PyObject_CallFunction(restype, "i", |
From: Thomas H. <th...@us...> - 2005-04-19 12:45:37
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31305 Modified Files: Tag: branch_1_0 callproc.c Log Message: Replace a big endian hack by more elegant code. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.127.2.3 retrieving revision 1.127.2.4 diff -C2 -d -r1.127.2.3 -r1.127.2.4 *** callproc.c 19 Apr 2005 06:59:09 -0000 1.127.2.3 --- callproc.c 19 Apr 2005 12:45:26 -0000 1.127.2.4 *************** *** 549,567 **** return 0; } - #if 0 - /* Does this make sense? Now that even Structure and Union types - have an _as_parameter_ property implemented in C, which returns - a PyCArgObject? - */ - if (CDataObject_Check(arg)) { - CDataObject *mem = (CDataObject *)arg; - parm->tag = 'V'; - parm->value.p = mem->b_ptr; - parm->size = mem->b_size; - /* This consumes the refcount of arg */ - parm->obj = arg; - return parm; - } - #endif Py_DECREF(arg); PyErr_Format(PyExc_TypeError, --- 549,552 ---- *************** *** 753,790 **** dict = PyType_stgdict(restype); ! if (dict && dict->getfunc) { ! /* This hack is needed for big endian machines. ! Is there another way? ! */ ! PyObject *retval; ! char c; ! short s; ! int i; ! #if (SIZEOF_LONG != SIZEOF_INT) ! long l; ! #endif ! switch (dict->size) { ! case 1: ! c = (char)*(long *)result; ! retval = dict->getfunc(&c, dict->size); ! break; ! case SIZEOF_SHORT: ! s = (short)*(long *)result; ! retval = dict->getfunc(&s, dict->size); ! break; ! case SIZEOF_INT: ! i = (int)*(long *)result; ! retval = dict->getfunc(&i, dict->size); ! break; ! #if (SIZEOF_LONG != SIZEOF_INT) ! case SIZEOF_LONG: ! l = (long)*(long *)result; ! retval = dict->getfunc(&l, dict->size); ! break; #endif ! default: ! retval = dict->getfunc(result, dict->size); ! break; ! } if (retval == NULL) return NULL; --- 738,759 ---- dict = PyType_stgdict(restype); ! ! /* THIS code should probably move into CallProc, where GetResult is ! called. But doesn't matter too much. */ ! #if IS_BIG_ENDIAN ! if (dict && dict->size < sizeof(ffi_arg)) { ! /* libffi returns the result in a buffer of ! sizeof(ffi_arg). This causes problems on big ! endian machines, since the result buffer cannot ! simply be casted to the actual result type. ! Instead, we must adjust the pointer: ! */ ! char *ptr = result; ! ptr += sizeof(ffi_arg) - dict->size; ! result = ptr; ! } #endif ! if (dict && dict->getfunc) { ! PyObject *retval = dict->getfunc(result, dict->size); if (retval == NULL) return NULL; |
From: Thomas H. <th...@us...> - 2005-04-19 09:00:25
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9820 Modified Files: ChangeLog Log Message: Record changes. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.89 retrieving revision 1.90 diff -C2 -d -r1.89 -r1.90 *** ChangeLog 14 Apr 2005 19:11:06 -0000 1.89 --- ChangeLog 19 Apr 2005 09:00:15 -0000 1.90 *************** *** 1,2 **** --- 1,7 ---- + 2005-04-19 Thomas Heller <th...@py...> + + * Fixed quite a few problems on 64-bit platforms. Reported and + partly patched by Mike Fletcher. + 2005-04-14 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2005-04-19 08:58:46
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8948 Modified Files: Tag: branch_1_0 ChangeLog Log Message: Record changes. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.86.2.3 retrieving revision 1.86.2.4 diff -C2 -d -r1.86.2.3 -r1.86.2.4 *** ChangeLog 14 Apr 2005 18:18:56 -0000 1.86.2.3 --- ChangeLog 19 Apr 2005 08:58:36 -0000 1.86.2.4 *************** *** 1,6 **** 2005-04-14 Thomas Heller <th...@py...> * source/_ctypes.c: Fix a crash when a POINTER type has no _type_. ! Patch provided by Andreas Degert. 2005-04-07 Thomas Heller <th...@py...> --- 1,17 ---- + 2005-04-19 Thomas Heller <th...@py...> + + * Fixed quite a few problems on 64-bit platforms. Reported and + partly patched by Mike Flechter. + + 2005-04-15 Thomas Heller <th...@py...> + + * Added some files from Bob Ippolito's macholib, to help finding + shared libraries on OS X. + 2005-04-14 Thomas Heller <th...@py...> * source/_ctypes.c: Fix a crash when a POINTER type has no _type_. ! Reported by Georg Thalhammer, patch provided by Andreas Degert, ! somewhat modified. 2005-04-07 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2005-04-19 08:32:04
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25733 Modified Files: callproc.c Log Message: Don't convert pointer to C int/long Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.151 retrieving revision 1.152 diff -C2 -d -r1.151 -r1.152 *** callproc.c 18 Apr 2005 11:10:39 -0000 1.151 --- callproc.c 19 Apr 2005 08:31:54 -0000 1.152 *************** *** 1112,1116 **** { if (CDataObject_Check(obj)) ! return PyInt_FromLong((long)((CDataObject *)obj)->b_ptr); PyErr_SetString(PyExc_TypeError, "invalid type"); --- 1112,1116 ---- { if (CDataObject_Check(obj)) ! return PyLong_FromVoidPtr(((CDataObject *)obj)->b_ptr); PyErr_SetString(PyExc_TypeError, "invalid type"); |
From: Thomas H. <th...@us...> - 2005-04-19 06:59:19
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11455 Modified Files: Tag: branch_1_0 callproc.c Log Message: Fix another location where a pointer was truncated to an integer. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.127.2.2 retrieving revision 1.127.2.3 diff -C2 -d -r1.127.2.2 -r1.127.2.3 *** callproc.c 18 Apr 2005 13:36:03 -0000 1.127.2.2 --- callproc.c 19 Apr 2005 06:59:09 -0000 1.127.2.3 *************** *** 1299,1303 **** { if (CDataObject_Check(obj)) ! return PyInt_FromLong((long)((CDataObject *)obj)->b_ptr); PyErr_SetString(PyExc_TypeError, "invalid type"); --- 1299,1303 ---- { if (CDataObject_Check(obj)) ! return PyLong_FromVoidPtr(((CDataObject *)obj)->b_ptr); PyErr_SetString(PyExc_TypeError, "invalid type"); |
From: Thomas H. <th...@us...> - 2005-04-18 15:34:16
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10370 Modified Files: Tag: branch_1_0 test_python_api.py Log Message: a new test Index: test_python_api.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_python_api.py,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -C2 -d -r1.3 -r1.3.6.1 *** test_python_api.py 1 Sep 2004 11:59:02 -0000 1.3 --- test_python_api.py 18 Apr 2005 15:34:07 -0000 1.3.6.1 *************** *** 14,17 **** --- 14,25 ---- class PythonAPITestCase(unittest.TestCase): + def test_PyString_FromStringAndSize(self): + PyString_FromStringAndSize = pythonapi.PyString_FromStringAndSize + + PyString_FromStringAndSize.restype = py_object + PyString_FromStringAndSize.argtypes = c_char_p, c_int + + self.failUnlessEqual(PyString_FromStringAndSize("abcdefghi", 3), "abc") + def test_PyString_FromString(self): pythonapi.PyString_FromString.restype = py_object *************** *** 34,38 **** pythonapi.PyInt_AsLong.argtypes = (py_object,) ! pythonapi.PyInt_AsLong.restype = c_int res = pythonapi.PyInt_AsLong(42) --- 42,46 ---- pythonapi.PyInt_AsLong.argtypes = (py_object,) ! pythonapi.PyInt_AsLong.restype = c_long res = pythonapi.PyInt_AsLong(42) |
From: Thomas H. <th...@us...> - 2005-04-18 15:31:44
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9173 Modified Files: Tag: branch_1_0 test_libc.py Log Message: don't use @ decorators Index: test_libc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_libc.py,v retrieving revision 1.3.2.2 retrieving revision 1.3.2.3 diff -C2 -d -r1.3.2.2 -r1.3.2.3 *** test_libc.py 15 Apr 2005 18:49:38 -0000 1.3.2.2 --- test_libc.py 18 Apr 2005 15:31:31 -0000 1.3.2.3 *************** *** 67,75 **** CMPFUNC = CFUNCTYPE(c_int, c_void_p, c_void_p) ! @ cdecl(None, "libc", [c_void_p, c_int, c_int, CMPFUNC]) def qsort(sequence, cmp_func): itemsize = sizeof(sequence) / len(sequence) qsort._api_(sequence, len(sequence), itemsize, CMPFUNC(cmp_func)) def sortfunc(a, b): --- 67,76 ---- CMPFUNC = CFUNCTYPE(c_int, c_void_p, c_void_p) ! #@ cdecl(None, "libc", [c_void_p, c_int, c_int, CMPFUNC]) def qsort(sequence, cmp_func): itemsize = sizeof(sequence) / len(sequence) qsort._api_(sequence, len(sequence), itemsize, CMPFUNC(cmp_func)) + qsort = cdecl(None, "libc", [c_void_p, c_int, c_int, CMPFUNC])(qsort) def sortfunc(a, b): |
From: Thomas H. <th...@us...> - 2005-04-18 13:36:12
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15731 Modified Files: Tag: branch_1_0 callproc.c Log Message: Don't assume sizeof(ptr) == sizeof(int) Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.127.2.1 retrieving revision 1.127.2.2 diff -C2 -d -r1.127.2.1 -r1.127.2.2 *** callproc.c 4 Apr 2005 15:46:06 -0000 1.127.2.1 --- callproc.c 18 Apr 2005 13:36:03 -0000 1.127.2.2 *************** *** 1121,1125 **** return NULL; } ! return Py_BuildValue("i", handle); } --- 1121,1125 ---- return NULL; } ! return PyLong_FromVoidPtr(handle); } *************** *** 1305,1316 **** } static PyObject * My_PyObj_FromPtr(PyObject *self, PyObject *args) { - int i; PyObject *ob; ! if (!PyArg_ParseTuple(args, "i", &i)) return NULL; - ob = (PyObject *)i; Py_INCREF(ob); return ob; --- 1305,1321 ---- } + static int + converter(PyObject *obj, void **address) + { + *address = PyLong_AsVoidPtr(obj); + return address != NULL; + } + static PyObject * My_PyObj_FromPtr(PyObject *self, PyObject *args) { PyObject *ob; ! if (!PyArg_ParseTuple(args, "O&", converter, &ob)) return NULL; Py_INCREF(ob); return ob; |
From: Thomas H. <th...@us...> - 2005-04-18 13:35:16
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15053 Modified Files: Tag: branch_1_0 _ctypes_test.c Log Message: fix compiler warnings. Credit to Mike Fletcher Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.46 retrieving revision 1.46.2.1 diff -C2 -d -r1.46 -r1.46.2.1 *** _ctypes_test.c 9 Mar 2005 16:42:50 -0000 1.46 --- _ctypes_test.c 18 Apr 2005 13:35:07 -0000 1.46.2.1 *************** *** 163,167 **** if (p) { *p = malloc(sizeof(char *)); ! printf("malloc returned %d\n", (int)*p); **p = message; return 1; --- 163,167 ---- if (p) { *p = malloc(sizeof(char *)); ! printf("malloc returned %p\n", *p); **p = message; return 1; *************** *** 172,176 **** EXPORT(void) my_free(void *p) { ! printf("my_free got %d\n", (int)p); } --- 172,176 ---- EXPORT(void) my_free(void *p) { ! printf("my_free got %p\n", p); } *************** *** 239,247 **** void *ptr; ! printf("_xxx_init got %x %x\n", (int)Xalloc, (int)Xfree); printf("calling\n"); ptr = Xalloc(32); Xfree(ptr); ! printf("calls done, ptr was %x\n", (int)ptr); } --- 239,247 ---- void *ptr; ! printf("_xxx_init got %p %p\n", Xalloc, Xfree); printf("calling\n"); ptr = Xalloc(32); Xfree(ptr); ! printf("calls done, ptr was %p\n", ptr); } |
From: Thomas H. <th...@us...> - 2005-04-18 11:14:26
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8289 Modified Files: test_pointers.py Log Message: declare return type for functions returning pointers Index: test_pointers.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_pointers.py,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** test_pointers.py 15 Apr 2005 12:58:37 -0000 1.17 --- test_pointers.py 18 Apr 2005 11:14:15 -0000 1.18 *************** *** 24,28 **** dll = CDLL(find_test_dll()) func = dll._testfunc_p_p ! i = c_int(12345678) ## func.argtypes = (POINTER(c_int),) --- 24,30 ---- dll = CDLL(find_test_dll()) func = dll._testfunc_p_p ! # pointer is long on AMD64 ! func.restype = c_void_p ! i = c_int(12345678) ## func.argtypes = (POINTER(c_int),) |
From: Thomas H. <th...@us...> - 2005-04-18 11:12:30
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7035 Modified Files: test_prototypes.py Log Message: declare return type for functions returning pointers Index: test_prototypes.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_prototypes.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** test_prototypes.py 14 Oct 2004 13:16:13 -0000 1.6 --- test_prototypes.py 18 Apr 2005 11:12:22 -0000 1.7 *************** *** 33,42 **** def setUp(self): func = testdll._testfunc_p_p ! func.restype = c_int func.argtypes = None def test_int_pointer_arg(self): func = testdll._testfunc_p_p ! self.failUnlessEqual(0, func(0)) ci = c_int(0) --- 33,42 ---- def setUp(self): func = testdll._testfunc_p_p ! func.restype = c_void_p func.argtypes = None def test_int_pointer_arg(self): func = testdll._testfunc_p_p ! self.failUnlessEqual(None, func(0)) ci = c_int(0) |
From: Thomas H. <th...@us...> - 2005-04-18 11:11:58
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6818 Modified Files: test_returnfuncptrs.py Log Message: declare return type for functions returning pointers Index: test_returnfuncptrs.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_returnfuncptrs.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** test_returnfuncptrs.py 14 Oct 2004 13:16:13 -0000 1.8 --- test_returnfuncptrs.py 18 Apr 2005 11:11:49 -0000 1.9 *************** *** 23,26 **** --- 23,27 ---- dll = CDLL(find_test_dll()) get_strchr = dll.get_strchr + get_strchr.restype = c_void_p addr = get_strchr() # _CFuncPtr instances are now callable with an integer argument |
From: Thomas H. <th...@us...> - 2005-04-18 11:10:48
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6059 Modified Files: callproc.c Log Message: Don't assume sizeof(ptr) == sizeof(int) Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.150 retrieving revision 1.151 diff -C2 -d -r1.150 -r1.151 *** callproc.c 8 Apr 2005 13:21:30 -0000 1.150 --- callproc.c 18 Apr 2005 11:10:39 -0000 1.151 *************** *** 933,937 **** return NULL; } ! return Py_BuildValue("i", handle); } --- 933,937 ---- return NULL; } ! return PyLong_FromVoidPtr(handle); } *************** *** 1118,1129 **** } static PyObject * My_PyObj_FromPtr(PyObject *self, PyObject *args) { - int i; PyObject *ob; ! if (!PyArg_ParseTuple(args, "i", &i)) return NULL; - ob = (PyObject *)i; Py_INCREF(ob); return ob; --- 1118,1134 ---- } + static int + converter(PyObject *obj, void **address) + { + *address = PyLong_AsVoidPtr(obj); + return address != NULL; + } + static PyObject * My_PyObj_FromPtr(PyObject *self, PyObject *args) { PyObject *ob; ! if (!PyArg_ParseTuple(args, "O&", converter, &ob)) return NULL; Py_INCREF(ob); return ob; |
From: Thomas H. <th...@us...> - 2005-04-18 11:09:29
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5252 Modified Files: _ctypes_test.c Log Message: avoid compiler warning. Credit to Mike Fletcher Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** _ctypes_test.c 9 Mar 2005 16:42:50 -0000 1.46 --- _ctypes_test.c 18 Apr 2005 11:09:21 -0000 1.47 *************** *** 163,167 **** if (p) { *p = malloc(sizeof(char *)); ! printf("malloc returned %d\n", (int)*p); **p = message; return 1; --- 163,167 ---- if (p) { *p = malloc(sizeof(char *)); ! printf("malloc returned %p\n", *p); **p = message; return 1; *************** *** 172,176 **** EXPORT(void) my_free(void *p) { ! printf("my_free got %d\n", (int)p); } --- 172,176 ---- EXPORT(void) my_free(void *p) { ! printf("my_free got %p\n", p); } *************** *** 239,247 **** void *ptr; ! printf("_xxx_init got %x %x\n", (int)Xalloc, (int)Xfree); printf("calling\n"); ptr = Xalloc(32); Xfree(ptr); ! printf("calls done, ptr was %x\n", (int)ptr); } --- 239,247 ---- void *ptr; ! printf("_xxx_init got %p %p\n", Xalloc, Xfree); printf("calling\n"); ptr = Xalloc(32); Xfree(ptr); ! printf("calls done, ptr was %p\n", ptr); } |
From: Thomas H. <th...@us...> - 2005-04-18 11:08:42
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4815 Modified Files: callbacks.c Log Message: avoid compiler warning Index: callbacks.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v retrieving revision 1.78 retrieving revision 1.79 diff -C2 -d -r1.78 -r1.79 *** callbacks.c 7 Apr 2005 07:47:48 -0000 1.78 --- callbacks.c 18 Apr 2005 11:08:32 -0000 1.79 *************** *** 323,327 **** return NULL; } ! result = ffi_prep_closure(p->pcl, &p->cif, _CallPythonObject, p); if (result != FFI_OK) { PyErr_Format(PyExc_RuntimeError, --- 323,327 ---- return NULL; } ! result = ffi_prep_closure(p->pcl, &p->cif, (void *)_CallPythonObject, p); if (result != FFI_OK) { PyErr_Format(PyExc_RuntimeError, |
From: Thomas H. <th...@us...> - 2005-04-18 09:58:54
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31190 Modified Files: Tag: branch_1_0 decorators.py Log Message: Have to stay compatible with Python 2.3, so no @ decorator syntax. Index: decorators.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/decorators.py,v retrieving revision 1.6.2.1 retrieving revision 1.6.2.2 diff -C2 -d -r1.6.2.1 -r1.6.2.2 *** decorators.py 15 Apr 2005 15:47:54 -0000 1.6.2.1 --- decorators.py 18 Apr 2005 09:58:41 -0000 1.6.2.2 *************** *** 104,108 **** from ctypes import WinError ! @ stdcall(ctypes.c_ulong, "kernel32", [c_ulong, POINTER(c_char), c_ulong]) def GetModuleFileNameA(handle=0): buf = create_string_buffer(256) --- 104,108 ---- from ctypes import WinError ! #@ stdcall(ctypes.c_ulong, "kernel32", [c_ulong, POINTER(c_char), c_ulong]) def GetModuleFileNameA(handle=0): buf = create_string_buffer(256) *************** *** 110,113 **** --- 110,115 ---- raise WinError() return buf.value + GetModuleFileNameA = stdcall(ctypes.c_ulong, "kernel32", + [c_ulong, POINTER(c_char), c_ulong])(GetModuleFileNameA) assert(sys.executable == GetModuleFileNameA()) *************** *** 118,124 **** name_library("libm", "libm") ! @ cdecl(c_double, 'libm', [c_double]) def sqrt(value): return sqrt._api_(value) assert sqrt(4.0) == 2.0 --- 120,127 ---- name_library("libm", "libm") ! #@ cdecl(c_double, 'libm', [c_double]) def sqrt(value): return sqrt._api_(value) + sqrt = cdecl(c_double, 'libm', [c_double])(sqrt) assert sqrt(4.0) == 2.0 |
From: Thomas H. <th...@us...> - 2005-04-18 08:53:06
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30074 Modified Files: decorators.py Log Message: Have to stay compatible with Python 2.3, so no @ decorator syntax. Index: decorators.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/decorators.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** decorators.py 4 Feb 2005 18:15:18 -0000 1.6 --- decorators.py 18 Apr 2005 08:52:58 -0000 1.7 *************** *** 2,119 **** This module implements decorators for native api function calls. ! stdcall(restype, dllname, argtypes[, logging=False]) ! cdecl(restype, dllname, argtypes[, logging=False]) ! ! The decorator functions are used like this: ! ! >>> from ctypes import * ! >>> # wrap the GetModuleFileNameA function ! >>> @ stdcall(c_ulong, 'kernel32', [c_ulong, POINTER(c_char), c_ulong]) ! ... def GetModuleFileNameA(handle=0): ! ... buf = create_string_buffer(256) ! ... if 0 == GetModuleFileNameA._api_(handle, buf, sizeof(buf)): ! ... raise WinError() ! ... return buf.value ! >>> ! >>> sys.executable == GetModuleFileNameA() ! True ! >>> ! >>> @ cdecl(c_char_p, 'msvcrt', [c_char_p, c_int]) ! ... def strchr(string, c): ! ... 'find a character in a string' ! ... return strchr._api_(string, c) ! >>> print strchr('abcdef', ord('x')) ! None ! >>> print strchr('abcdef', ord('c')) ! cdef ! >>> """ ! # This doesn't work, see below. ! ##>>> @ cdecl(c_char_p, 'msvcrt', [c_char_p, c_int]) ! ##... def strchr(string, c): ! ##... 'find a character in a string' ! ##... ! ##>>> print strchr('abcdef', ord('x')) ! ##None ! ##>>> print strchr('abcdef', ord('c')) ! ##cdef ! ##>>> ! import sys import ctypes ! LOGGING = False - ##def _create_func_codestring(func, doc=None): - ## # given a function object <func>, build the source code for - ## # another function, having the same argument list, and a function - ## # body which contains a call to an _api_ function. - ## # - ## # Assuming the <func> has this definition: - ## # def func(first, second="spam", third=42): - ## # .... - ## # a string containing the following code is returned: - ## # def func(first, second="spam", third=42): - ## # return _api_(first, second, third) - ## import inspect - ## args, varargs, varkw, defaults = inspect.getargspec(func) - ## if varkw: - ## raise TypeError, "function argument list cannot contain ** argument" - ## if doc: - ## return "def %s%s:\n %r\n return %s._api_%s" % \ - ## (func.func_name, - ## inspect.formatargspec(args, varargs, varkw, defaults), - ## doc, - ## func.func_name, - ## inspect.formatargspec(args, varargs, varkw)) - ## return "def %s%s:\n return %s._api_%s" % \ - ## (func.func_name, - ## inspect.formatargspec(args, varargs, varkw, defaults), - ## func.func_name, - ## inspect.formatargspec(args, varargs, varkw)) ! ################################################################ ! def stdcall(restype, dll, argtypes, logging=False): ! """stdcall(restype, dll, argtypes, logging=False) -> decorator. - The decorator, when applied to a function, attaches an '_api_' - attribute to the function. Calling this attribute calls the - function exported from the dll, using the MS '__stdcall' calling - convention. ! restype - result type ! dll - name or instance of a dll ! argtypes - list of argument types ! logging - if this is True, the result of each function call ! is printed to stderr. ! """ ! def decorate(func): ! if isinstance(dll, basestring): ! # this call should cache the result ! this_dll = ctypes.CDLL(dll) ! else: ! this_dll = dll ! api = ctypes.WINFUNCTYPE(restype, *argtypes)(func.func_name, this_dll) ! # This simple way to find out an empty function body doesn't work. ! ## if len(func.func_code.co_code) == 4: ! ## codestring = _create_func_codestring(func, func.__doc__) ! ## d = {} ! ## exec codestring in d ! ## func = d[func.func_name] ! func._api_ = api ! if logging or LOGGING: ! def f(*args): ! result = func(*args) ! print >> sys.stderr, "# function call: %s%s -> %s" % (func.func_name, args, result) ! return result ! return f ! else: ! return func ! return decorate ! def cdecl(restype, dll, argtypes, logging=False): ! """cdecl(restype, dll, argtypes, logging=False) -> decorator. The decorator, when applied to a function, attaches an '_api_' --- 2,40 ---- This module implements decorators for native api function calls. ! name_library(name, so_name) ! cdecl(restype, dllname, argtypes) ! stdcall(restype, dllname, argtypes) - windows only """ ! LOGGING = False ! import os import ctypes ! _library_map = {} # map short name to so-name ! _loaded_libs = {} # map so-names to DLL instance ! def name_library(name, so_name): ! """ ! name_library(name, so_name) ! Register the <so_name> for a library. The library will be loaded ! if <name> is referenced in a decorator. ! """ ! _library_map[name] = so_name ! _library_map[so_name] = so_name ! def _get_library(name): ! # load and return a library. The library is cached. ! soname = _library_map.get(name, name) ! try: ! return _loaded_libs[soname] ! except KeyError: ! return _loaded_libs.setdefault(soname, ctypes.CDLL(soname)) ! def cdecl(restype, dllname, argtypes, logging=False): ! """cdecl(restype, dllname, argtypes, logging=False) -> decorator. The decorator, when applied to a function, attaches an '_api_' *************** *** 129,159 **** """ def decorate(func): ! if isinstance(dll, basestring): ! # this call should cache the result ! this_dll = ctypes.CDLL(dll) ! else: ! this_dll = dll ! api = ctypes.CFUNCTYPE(restype, *argtypes)(func.func_name, this_dll) ! # This simple way to find out an empty function body doesn't work. ! ## if len(func.func_code.co_code) == 4: ! ## codestring = _create_func_codestring(func, func.__doc__) ! ## d = {} ! ## exec codestring in d ! ## func = d[func.func_name] func._api_ = api if logging or LOGGING: def f(*args): result = func(*args) ! print >> sys.stderr, func.func_name, args, "->", result return result return f ! else: ! return func return decorate ################################################################ ! ##if __name__ == "__main__": ! if 0: ! import doctest ! doctest.testmod() --- 50,130 ---- """ def decorate(func): ! library = _get_library(dllname) ! api = ctypes.CFUNCTYPE(restype, *argtypes)(func.func_name, library) func._api_ = api + # The following few lines trigger a pychecker bug, see + # https://sourceforge.net/tracker/index.php?func=detail&aid=1114902&group_id=24686&atid=382217 if logging or LOGGING: def f(*args): result = func(*args) ! print >> sys.stderr, "# function call: %s%s -> %s" % (func.func_name, args, result) return result return f ! return func return decorate + if os.name == "nt": + def stdcall(restype, dllname, argtypes, logging=False): + """stdcall(restype, dllname, argtypes, logging=False) -> decorator. + + The decorator, when applied to a function, attaches an '_api_' + attribute to the function. Calling this attribute calls the + function exported from the dll, using the MS '__stdcall' calling + convention. + + restype - result type + dll - name or instance of a dll + argtypes - list of argument types + logging - if this is True, the result of each function call + is printed to stderr. + """ + def decorate(func): + library = _get_library(dllname) + api = ctypes.WINFUNCTYPE(restype, *argtypes)(func.func_name, library) + func._api_ = api + # The following few lines trigger a pychecker bug, see + # https://sourceforge.net/tracker/index.php?func=detail&aid=1114902&group_id=24686&atid=382217 + if logging or LOGGING: + def f(*args): + result = func(*args) + print >> sys.stderr, "# function call: %s%s -> %s" % (func.func_name, args, result) + return result + return f + return func + return decorate + ################################################################ ! def _test(): ! import os, sys ! from ctypes import c_char, c_int, c_ulong, c_double, \ ! POINTER, create_string_buffer, sizeof ! ! if os.name == "nt": ! from ctypes import WinError ! ! #@ stdcall(ctypes.c_ulong, "kernel32", [c_ulong, POINTER(c_char), c_ulong]) ! def GetModuleFileNameA(handle=0): ! buf = create_string_buffer(256) ! if 0 == GetModuleFileNameA._api_(handle, buf, sizeof(buf)): ! raise WinError() ! return buf.value ! GetModuleFileNameA = stdcall(ctypes.c_ulong, "kernel32", ! [c_ulong, POINTER(c_char), c_ulong])(GetModuleFileNameA) ! ! assert(sys.executable == GetModuleFileNameA()) ! ! if os.name == "nt": ! name_library("libm", "msvcrt") ! else: ! name_library("libm", "libm") ! ! #@ cdecl(c_double, 'libm', [c_double]) ! def sqrt(value): ! return sqrt._api_(value) ! sqrt = cdecl(c_double, 'libm', [c_double])(sqrt) ! ! assert sqrt(4.0) == 2.0 ! ! if __name__ == "__main__": ! _test() |
From: Thomas H. <th...@us...> - 2005-04-15 18:49:47
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6407/unittests Modified Files: Tag: branch_1_0 test_libc.py Log Message: Make it work on linux also. Index: test_libc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_libc.py,v retrieving revision 1.3.2.1 retrieving revision 1.3.2.2 diff -C2 -d -r1.3.2.1 -r1.3.2.2 *** test_libc.py 15 Apr 2005 17:07:47 -0000 1.3.2.1 --- test_libc.py 15 Apr 2005 18:49:38 -0000 1.3.2.2 *************** *** 2,20 **** import sys import unittest from ctypes import * ! def get_libc(): ! if os.name == "nt": ! return cdll.msvcrt ! try: ! return CDLL("libc.so.6") ! except OSError: ! return cdll.c - libc = get_libc() if os.name == "nt": ! libm = cdll.msvcrt else: libm = cdll.m class LibTest(unittest.TestCase): --- 2,35 ---- import sys import unittest + from ctypes import * + from ctypes.util import find_library + from ctypes.decorators import cdecl, name_library ! # specify which libraries the decorator has to load. Normally, one ! # would use ful so-names to specify exact the library we want. if os.name == "nt": ! name_library("libc", "msvcrt") ! name_library("libm", "msvcrt") ! elif os.name == "darwin": ! name_library("libc", find_library("c")) ! name_library("libm", find_library("m")) else: + name_library("libc", "libc.so.6") + name_library("libm", find_library("m")) + + # load libraries with cdll magic. I still don't know how to find + # 'libc.so.6' from 'c' on linux, otherwise this could be a lot nicer. + + if os.name == "nt": + libm = libc = cdll.msvcrt + elif sys.platform == "darwin": + libc = cdll.c libm = cdll.m + else: + libc = CDLL("libc.so.6") + libm = cdll.m + class LibTest(unittest.TestCase): *************** *** 27,34 **** def test_cdecl_decorator(self): - from ctypes.decorators import cdecl, name_library - - if os.name == "nt": - name_library("libm", "msvcrt") # @ cdecl(c_double, "libm", [c_double]) --- 42,45 ---- *************** *** 55,60 **** from ctypes.decorators import cdecl, name_library - name_library("libc", "msvcrt") - CMPFUNC = CFUNCTYPE(c_int, c_void_p, c_void_p) @ cdecl(None, "libc", [c_void_p, c_int, c_int, CMPFUNC]) --- 66,69 ---- |
From: Thomas H. <th...@us...> - 2005-04-15 18:20:33
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21962 Modified Files: Tag: branch_1_0 __init__.py Added Files: Tag: branch_1_0 util.py Log Message: Move the find_library function into a new ctypes.util module. --- NEW FILE: util.py --- import os, sys if os.name == "nt": # LoadLibrary already does what we need. def find_library(name): return name elif sys.platform == "darwin": from ctypes.macholib.dyld import dyld_find # use macholib to find the library path def find_library(name): possible = ['lib.%s.dylib' % name, '%s.dylib' % name, '%s.framework/%s' % (name, name)] for dylib in possible: try: return os.path.realpath(dyld_find(dylib)) except ValueError: pass raise ValueError, "%s not found" % (name,) else: def find_library(name): return 'lib%s.so' % name Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.61.2.5 retrieving revision 1.61.2.6 diff -C2 -d -r1.61.2.5 -r1.61.2.6 *** __init__.py 15 Apr 2005 18:01:33 -0000 1.61.2.5 --- __init__.py 15 Apr 2005 18:20:25 -0000 1.61.2.6 *************** *** 412,454 **** return func - def find_lib(name): - from ctypes.macholib.dyld import dyld_find - import os - possible = ['lib'+name+'.dylib', name+'.dylib', name+'.framework/'+name] - - for dylib in possible: - try: - return os.path.realpath(dyld_find(dylib)) - except ValueError: - pass - raise ValueError, "%s not found" % (name,) - class _DLLS(object): def __init__(self, dlltype): self._dlltype = dlltype ! ! if _os.name == "posix" and sys.platform == "darwin": ! def __getattr__(self, name): ! if name[0] == '_': ! raise AttributeError, name ! ## libpath = find_lib(name) ! libpath = "lib%s.dylib" % name ! dll = self._dlltype(libpath) ! setattr(self, name, dll) ! return dll ! elif _os.name == "posix": ! def __getattr__(self, name): ! if name[0] == '_': ! raise AttributeError, name ! dll = self._dlltype("lib%s.so" % name) ! setattr(self, name, dll) ! return dll ! else: ! def __getattr__(self, name): ! if name[0] == '_': ! raise AttributeError, name ! dll = self._dlltype(name) ! setattr(self, name, dll) ! return dll def __getitem__(self, name): --- 412,427 ---- return func class _DLLS(object): def __init__(self, dlltype): self._dlltype = dlltype ! ! def __getattr__(self, name): ! from ctypes.util import find_library ! if name.startswith("__"): ! raise AttributeError, name ! libpath = find_library(name) ! dll = self._dlltype(libpath) ! setattr(self, name, dll) ! return dll def __getitem__(self, name): |
From: Thomas H. <th...@us...> - 2005-04-15 18:20:05
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21735 Modified Files: Tag: branch_1_0 test_functions.py Log Message: Remove silly code. Index: test_functions.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_functions.py,v retrieving revision 1.46 retrieving revision 1.46.2.1 diff -C2 -d -r1.46 -r1.46.2.1 *** test_functions.py 3 Dec 2004 09:09:49 -0000 1.46 --- test_functions.py 15 Apr 2005 18:19:56 -0000 1.46.2.1 *************** *** 304,311 **** def test_byval(self): - try: - cdll._testfunc_byval - except AttributeError: - return # not all systems support this class POINT(Structure): --- 304,307 ---- |
From: Thomas H. <th...@us...> - 2005-04-15 18:19:07
|
Update of /cvsroot/ctypes/ctypes/ctypes/macholib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21006 Added Files: Tag: branch_1_0 .cvsignore Log Message: --- NEW FILE: .cvsignore --- *.pyc *.pyo .svn |