ctypes-commit Mailing List for ctypes (Page 24)
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...> - 2006-02-10 18:35:34
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7044 Modified Files: Tag: branch_1_0 __init__.py Log Message: wstring_at is now also a foreign function, exported from the _ctypes extension. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.61.2.30 retrieving revision 1.61.2.31 diff -C2 -d -r1.61.2.30 -r1.61.2.31 *** __init__.py 10 Feb 2006 18:27:16 -0000 1.61.2.30 --- __init__.py 10 Feb 2006 18:35:24 -0000 1.61.2.31 *************** *** 253,258 **** raise TypeError, init - from _ctypes import wstring_at - POINTER(c_char).from_param = c_char_p.from_param #_SimpleCData.c_char_p_from_param --- 253,256 ---- *************** *** 422,425 **** --- 420,436 ---- return _string_at(ptr, size) + try: + from _ctypes import _wstring_at_addr + except ImportError: + pass + else: + _wstring_at = CFUNCTYPE(py_object, c_void_p, c_int)(_wstring_at_addr) + def wstring_at(ptr, size=0): + """wstring_at(addr[, size]) -> string + + Return the string at addr.""" + return _wstring_at(ptr, size) + + from decorators import cdecl if _os.name == "nt": |
From: Thomas H. <th...@us...> - 2006-02-10 18:27:42
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2749 Modified Files: Tag: branch_1_0 callproc.c _ctypes.c Log Message: string_at is now also a foreign function, exported from the _ctypes extension. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.127.2.24 retrieving revision 1.127.2.25 diff -C2 -d -r1.127.2.24 -r1.127.2.25 *** callproc.c 9 Feb 2006 20:23:06 -0000 1.127.2.24 --- callproc.c 10 Feb 2006 18:27:30 -0000 1.127.2.25 *************** *** 1479,1508 **** } - static char string_at_doc[] = - "string_at(addr[, size]) -> string\n\ - \n\ - Return the string at addr.\n"; - - static PyObject * - string_at(PyObject *self, PyObject *args) - { - PyObject *result = NULL; - PyObject *src; - struct argument a_arg; - int size; - - if (!PyArg_ParseTuple(args, "O|i:string_at", &src, &size)) - return NULL; - memset(&a_arg, 0, sizeof(struct argument)); - if (-1 == ConvParam(src, 1, &a_arg)) - 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; - } - #ifdef CTYPES_UNICODE static char wstring_at_doc[] = --- 1479,1482 ---- *************** *** 1535,1539 **** PyMethodDef module_methods[] = { - {"string_at", string_at, METH_VARARGS, string_at_doc}, {"cast", cast, METH_VARARGS, cast_doc}, #ifdef CTYPES_UNICODE --- 1509,1512 ---- Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.48 retrieving revision 1.226.2.49 diff -C2 -d -r1.226.2.48 -r1.226.2.49 *** _ctypes.c 9 Feb 2006 20:29:15 -0000 1.226.2.48 --- _ctypes.c 10 Feb 2006 18:27:30 -0000 1.226.2.49 *************** *** 4326,4329 **** --- 4326,4337 ---- #endif + static PyObject * + string_at(const char *ptr, int size) + { + if (size == 0) + return PyString_FromString(ptr); + return PyString_FromStringAndSize(ptr, size); + } + DL_EXPORT(void) init_ctypes(void) *************** *** 4449,4452 **** --- 4457,4461 ---- PyModule_AddObject(m, "_memmove_addr", PyLong_FromVoidPtr(memmove)); PyModule_AddObject(m, "_memset_addr", PyLong_FromVoidPtr(memset)); + PyModule_AddObject(m, "_string_at_addr", PyLong_FromVoidPtr(string_at)); #ifdef RTLD_LOCAL |
From: Thomas H. <th...@us...> - 2006-02-10 18:27:31
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2729 Modified Files: Tag: branch_1_0 test_memfunctions.py Log Message: string_at is now also a foreign function, exported from the _ctypes extension. Index: test_memfunctions.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_memfunctions.py,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** test_memfunctions.py 9 Feb 2006 20:58:39 -0000 1.1.2.3 --- test_memfunctions.py 10 Feb 2006 18:27:22 -0000 1.1.2.4 *************** *** 1,2 **** --- 1,3 ---- + import sys import unittest from ctypes import * *************** *** 11,26 **** self.failUnlessEqual(a.value, "Hello, World") ! ## self.failUnlessEqual(string_at(result), "Hello, World") ! ## self.failUnlessEqual(string_at(result, 5), "Hello") ! ## self.failUnlessEqual(string_at(result, 16), "Hello, World\0\0\0\0") def test_memset(self): a = create_string_buffer(1000000) result = memset(a, ord('x'), 16) - - ## self.failUnlessEqual(string_at(result), "xxxxxxxxxxxxxxxx") - ## self.failUnlessEqual(string_at(a), "xxxxxxxxxxxxxxxx") self.failUnlessEqual(a.value, "xxxxxxxxxxxxxxxx") def test_cast(self): a = (c_ubyte * 32)(*map(ord, "abcdef")) --- 12,28 ---- self.failUnlessEqual(a.value, "Hello, World") ! self.failUnlessEqual(string_at(result), "Hello, World") ! self.failUnlessEqual(string_at(result, 5), "Hello") ! self.failUnlessEqual(string_at(result, 16), "Hello, World\0\0\0\0") def test_memset(self): a = create_string_buffer(1000000) result = memset(a, ord('x'), 16) self.failUnlessEqual(a.value, "xxxxxxxxxxxxxxxx") + self.failUnlessEqual(string_at(result), "xxxxxxxxxxxxxxxx") + self.failUnlessEqual(string_at(a), "xxxxxxxxxxxxxxxx") + self.failUnlessEqual(string_at(a, 20), "xxxxxxxxxxxxxxxx\0\0\0\0") + def test_cast(self): a = (c_ubyte * 32)(*map(ord, "abcdef")) *************** *** 29,32 **** --- 31,44 ---- [97, 98, 99, 100, 101, 102, 0]) + def test_string_at(self): + s = string_at("foo bar") + # XXX The following may be wrong, depending on how Python + # manages string instances + self.failUnlessEqual(2, sys.getrefcount(s)) + self.failUnless(s, "foo bar") + + self.failUnlessEqual(string_at("foo bar", 8), "foo bar\0") + self.failUnlessEqual(string_at("foo bar", 3), "foo") + try: create_unicode_buffer *************** *** 40,46 **** self.failUnlessEqual(a.value, "Hello, World") ! ## self.failUnlessEqual(wstring_at(a), "Hello, World") ! ## self.failUnlessEqual(wstring_at(a, 5), "Hello") ! ## self.failUnlessEqual(wstring_at(a, 16), "Hello, World\0\0\0\0") if __name__ == "__main__": --- 52,58 ---- self.failUnlessEqual(a.value, "Hello, World") ! self.failUnlessEqual(wstring_at(a), "Hello, World") ! self.failUnlessEqual(wstring_at(a, 5), "Hello") ! self.failUnlessEqual(wstring_at(a, 16), "Hello, World\0\0\0\0") if __name__ == "__main__": |
From: Thomas H. <th...@us...> - 2006-02-10 18:27:26
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2677 Modified Files: Tag: branch_1_0 __init__.py Log Message: string_at is now also a foreign function, exported from the _ctypes extension. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.61.2.29 retrieving revision 1.61.2.30 diff -C2 -d -r1.61.2.29 -r1.61.2.30 *** __init__.py 9 Feb 2006 20:29:09 -0000 1.61.2.29 --- __init__.py 10 Feb 2006 18:27:16 -0000 1.61.2.30 *************** *** 402,406 **** # functions ! from _ctypes import _memmove_addr, _memset_addr, string_at, cast if sizeof(c_uint) == sizeof(c_void_p): --- 402,406 ---- # functions ! from _ctypes import _memmove_addr, _memset_addr, _string_at_addr, cast if sizeof(c_uint) == sizeof(c_void_p): *************** *** 415,418 **** --- 415,424 ---- memset = CFUNCTYPE(c_void_p, c_void_p, c_int, c_size_t)(_memset_addr) + _string_at = CFUNCTYPE(py_object, c_void_p, c_int)(_string_at_addr) + def string_at(ptr, size=0): + """string_at(addr[, size]) -> string + + Return the string at addr.""" + return _string_at(ptr, size) from decorators import cdecl |
From: Thomas H. <th...@us...> - 2006-02-09 21:03:58
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14055 Modified Files: Tag: branch_1_0 ChangeLog Log Message: Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.86.2.37 retrieving revision 1.86.2.38 diff -C2 -d -r1.86.2.37 -r1.86.2.38 *** ChangeLog 3 Feb 2006 01:53:08 -0000 1.86.2.37 --- ChangeLog 9 Feb 2006 21:03:50 -0000 1.86.2.38 *************** *** 1,2 **** --- 1,14 ---- + 2006-02-09 Thomas Heller <th...@py...> + + * memmove and memset are now implemented as foreign functions, + using the standard ctypes mechanism. The addresses are exported + by the _ctypes extension, restype and argtypes are set in + ctypes/__init__.py. + + This Required to extend c_void_p.from_param to accept int/long + arguments as well. + + memmove and memset now work on 64-bit platforms. + 2006-02-02 Hye-Shik Chang <pe...@Fr...> |
From: Thomas H. <th...@us...> - 2006-02-09 20:58:47
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11767 Modified Files: Tag: branch_1_0 test_memfunctions.py Log Message: Disable the string_at and wstring_at functions to prove that the memmove and memset functions actually work now, even on amd64. Index: test_memfunctions.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_memfunctions.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** test_memfunctions.py 7 Feb 2006 20:45:32 -0000 1.1.2.2 --- test_memfunctions.py 9 Feb 2006 20:58:39 -0000 1.1.2.3 *************** *** 11,17 **** self.failUnlessEqual(a.value, "Hello, World") ! self.failUnlessEqual(string_at(result), "Hello, World") ! self.failUnlessEqual(string_at(result, 5), "Hello") ! self.failUnlessEqual(string_at(result, 16), "Hello, World\0\0\0\0") def test_memset(self): --- 11,17 ---- self.failUnlessEqual(a.value, "Hello, World") ! ## self.failUnlessEqual(string_at(result), "Hello, World") ! ## self.failUnlessEqual(string_at(result, 5), "Hello") ! ## self.failUnlessEqual(string_at(result, 16), "Hello, World\0\0\0\0") def test_memset(self): *************** *** 19,24 **** result = memset(a, ord('x'), 16) ! self.failUnlessEqual(string_at(result), "xxxxxxxxxxxxxxxx") ! self.failUnlessEqual(string_at(a), "xxxxxxxxxxxxxxxx") self.failUnlessEqual(a.value, "xxxxxxxxxxxxxxxx") --- 19,24 ---- result = memset(a, ord('x'), 16) ! ## self.failUnlessEqual(string_at(result), "xxxxxxxxxxxxxxxx") ! ## self.failUnlessEqual(string_at(a), "xxxxxxxxxxxxxxxx") self.failUnlessEqual(a.value, "xxxxxxxxxxxxxxxx") *************** *** 40,46 **** self.failUnlessEqual(a.value, "Hello, World") ! self.failUnlessEqual(wstring_at(a), "Hello, World") ! self.failUnlessEqual(wstring_at(a, 5), "Hello") ! self.failUnlessEqual(wstring_at(a, 16), "Hello, World\0\0\0\0") if __name__ == "__main__": --- 40,46 ---- self.failUnlessEqual(a.value, "Hello, World") ! ## self.failUnlessEqual(wstring_at(a), "Hello, World") ! ## self.failUnlessEqual(wstring_at(a, 5), "Hello") ! ## self.failUnlessEqual(wstring_at(a, 16), "Hello, World\0\0\0\0") if __name__ == "__main__": |
From: Thomas H. <th...@us...> - 2006-02-09 20:29:26
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31104 Modified Files: Tag: branch_1_0 _ctypes.c Log Message: Make _memset_addr and _memmove_addr symbols private, and move them out of the #ifdef MS_WIN32 block. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.47 retrieving revision 1.226.2.48 diff -C2 -d -r1.226.2.47 -r1.226.2.48 *** _ctypes.c 9 Feb 2006 20:23:06 -0000 1.226.2.47 --- _ctypes.c 9 Feb 2006 20:29:15 -0000 1.226.2.48 *************** *** 4440,4446 **** PyModule_AddObject(m, "COMError", ComError); - PyModule_AddObject(m, "memmove_addr", PyLong_FromVoidPtr(memmove)); - PyModule_AddObject(m, "memset_addr", PyLong_FromVoidPtr(memset)); - PyModule_AddObject(m, "FUNCFLAG_HRESULT", PyInt_FromLong(FUNCFLAG_HRESULT)); PyModule_AddObject(m, "FUNCFLAG_STDCALL", PyInt_FromLong(FUNCFLAG_STDCALL)); --- 4440,4443 ---- *************** *** 4450,4453 **** --- 4447,4453 ---- PyModule_AddStringConstant(m, "__version__", "0.9.9.1"); + PyModule_AddObject(m, "_memmove_addr", PyLong_FromVoidPtr(memmove)); + PyModule_AddObject(m, "_memset_addr", PyLong_FromVoidPtr(memset)); + #ifdef RTLD_LOCAL PyModule_AddObject(m, "RTLD_LOCAL", PyInt_FromLong(RTLD_LOCAL)); |
From: Thomas H. <th...@us...> - 2006-02-09 20:29:18
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31054 Modified Files: Tag: branch_1_0 __init__.py Log Message: Make _memset_addr and _memmove_addr symbols private, and move them out of the #ifdef MS_WIN32 block. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.61.2.28 retrieving revision 1.61.2.29 diff -C2 -d -r1.61.2.28 -r1.61.2.29 *** __init__.py 9 Feb 2006 20:22:58 -0000 1.61.2.28 --- __init__.py 9 Feb 2006 20:29:09 -0000 1.61.2.29 *************** *** 402,406 **** # functions ! from _ctypes import memmove_addr, memset_addr, string_at, cast if sizeof(c_uint) == sizeof(c_void_p): --- 402,406 ---- # functions ! from _ctypes import _memmove_addr, _memset_addr, string_at, cast if sizeof(c_uint) == sizeof(c_void_p): *************** *** 410,417 **** ## void *memmove(void *, const void *, size_t); ! memmove = CFUNCTYPE(c_size_t, c_void_p, c_void_p, c_size_t)(memmove_addr) ## void *memset(void *, int, size_t) ! memset = CFUNCTYPE(c_void_p, c_void_p, c_int, c_size_t)(memset_addr) --- 410,417 ---- ## void *memmove(void *, const void *, size_t); ! memmove = CFUNCTYPE(c_size_t, c_void_p, c_void_p, c_size_t)(_memmove_addr) ## void *memset(void *, int, size_t) ! memset = CFUNCTYPE(c_void_p, c_void_p, c_int, c_size_t)(_memset_addr) |
From: Thomas H. <th...@us...> - 2006-02-09 20:26:50
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29750 Modified Files: Tag: branch_1_0 simple_types.txt Log Message: *** empty log message *** Index: simple_types.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/simple_types.txt,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** simple_types.txt 3 Feb 2006 08:32:06 -0000 1.1.2.1 --- simple_types.txt 9 Feb 2006 20:26:34 -0000 1.1.2.2 *************** *** 137,148 **** The constructor accepts one optional argument, which must be an ! integer, or ``None``. ! The ``from_param`` class method accepts Python strings or unicode ! strings, as well as ``None``. The ``value`` attribute accepts and returns None or integer. ! XXX Why does from_param accept an integer, and the constructor doesn't? --- 137,149 ---- The constructor accepts one optional argument, which must be an ! integer or long interpreted as address, or ``None``. ! The ``from_param`` class method accepts everything that could be used ! as a pointer. XXX Should accept objects using the buffer interface as ! well. The ``value`` attribute accepts and returns None or integer. ! XXX Shouldn't the constructor accept the same types than from_param? |
From: Thomas H. <th...@us...> - 2006-02-09 20:23:18
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28118 Modified Files: Tag: branch_1_0 callproc.c _ctypes.c Log Message: memmove and memset are now implemented by using foreign functions. Requires to extend c_void_p.from_param to accept int/long arguments as well. The addresses are exported by the _ctypes extension, restype and argtypes are set in ctypes/__init__.py. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.127.2.23 retrieving revision 1.127.2.24 diff -C2 -d -r1.127.2.23 -r1.127.2.24 *** callproc.c 7 Feb 2006 20:20:04 -0000 1.127.2.23 --- callproc.c 9 Feb 2006 20:23:06 -0000 1.127.2.24 *************** *** 1479,1535 **** } - static char memmove_doc[] = - "memmove(dst, src, count) -> adress\n\ - \n\ - Copy count bytes from src to dst, return the dst address as integer.\n"; - - static PyObject * - c_memmove(PyObject *self, PyObject *args) - { - struct argument a_dst, a_src; - int size; - void *c_result; - PyObject *result = NULL; - PyObject *dst, *src; - - memset(&a_dst, 0, sizeof(struct argument)); - memset(&a_src, 0, sizeof(struct argument)); - if (!PyArg_ParseTuple(args, "OOi:memmove", &dst, &src, &size)) - return NULL; - if (-1 == ConvParam(dst, 1, &a_dst)) - goto done; - if (-1 == ConvParam(src, 2, &a_src)) - goto done; - c_result = memmove(a_dst.value.p, a_src.value.p, size); - result = PyLong_FromVoidPtr(c_result); - done: - Py_XDECREF(a_dst.keep); - Py_XDECREF(a_src.keep); - return result; - } - - static char memset_doc[] = - "memset(dst, c, count) -> adress\n\ - \n\ - Set count bytes starting at dst to c, return the dst address as integer.\n"; - static PyObject * - c_memset(PyObject *self, PyObject *args) - { - PyObject *dst, *result; - struct argument a_dst; - void *c_result; - int c, count; - - if (!PyArg_ParseTuple(args, "Oii:memset", &dst, &c, &count)) - return NULL; - memset(&a_dst, 0, sizeof(struct argument)); - if (-1 == ConvParam(dst, 1, &a_dst)) - return NULL; - c_result = memset(a_dst.value.p, c, count); - result = PyLong_FromVoidPtr(c_result); - Py_XDECREF(a_dst.keep); - return result; - } - static char string_at_doc[] = "string_at(addr[, size]) -> string\n\ --- 1479,1482 ---- *************** *** 1589,1594 **** PyMethodDef module_methods[] = { {"string_at", string_at, METH_VARARGS, string_at_doc}, - {"memmove", c_memmove, METH_VARARGS, memmove_doc}, - {"memset", c_memset, METH_VARARGS, memset_doc}, {"cast", cast, METH_VARARGS, cast_doc}, #ifdef CTYPES_UNICODE --- 1536,1539 ---- Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.46 retrieving revision 1.226.2.47 diff -C2 -d -r1.226.2.46 -r1.226.2.47 *** _ctypes.c 2 Feb 2006 20:38:22 -0000 1.226.2.46 --- _ctypes.c 9 Feb 2006 20:23:06 -0000 1.226.2.47 *************** *** 1148,1155 **** --- 1148,1173 ---- #endif + /* None */ if (value == Py_None) { Py_INCREF(Py_None); return Py_None; } + /* Should probably allow buffer interface as well */ + /* int, long */ + if (PyInt_Check(value) || PyLong_Check(value)) { + PyCArgObject *parg; + struct fielddesc *fd = getentry("P"); + + parg = new_CArgObject(); + parg->pffi_type = &ffi_type_pointer; + parg->tag = 'P'; + parg->obj = fd->setfunc(&parg->value, value, 0); + if (parg->obj == NULL) { + Py_DECREF(parg); + return NULL; + } + return (PyObject *)parg; + } + /* string */ if (PyString_Check(value)) { PyCArgObject *parg; *************** *** 1166,1169 **** --- 1184,1188 ---- return (PyObject *)parg; } + /* unicode */ if (PyUnicode_Check(value)) { PyCArgObject *parg; *************** *** 1180,1183 **** --- 1199,1203 ---- return (PyObject *)parg; } + /* c_void_p instance (or subclass) */ if (PyObject_IsInstance(value, type)) { /* c_void_p instances */ *************** *** 1185,1188 **** --- 1205,1209 ---- return value; } + /* ctypes array or pointer instance */ if (ArrayObject_Check(value) || PointerObject_Check(value)) { /* Any array or pointer is accepted */ *************** *** 1190,1193 **** --- 1211,1215 ---- return value; } + /* byref(...) */ if (PyCArg_CheckExact(value)) { /* byref(c_xxx()) */ *************** *** 1198,1201 **** --- 1220,1224 ---- } } + /* c_char_p, c_wchar_p */ stgd = PyObject_stgdict(value); if (stgd && CDataObject_Check(value) && stgd->proto && PyString_Check(stgd->proto)) { *************** *** 4417,4420 **** --- 4440,4446 ---- PyModule_AddObject(m, "COMError", ComError); + PyModule_AddObject(m, "memmove_addr", PyLong_FromVoidPtr(memmove)); + PyModule_AddObject(m, "memset_addr", PyLong_FromVoidPtr(memset)); + PyModule_AddObject(m, "FUNCFLAG_HRESULT", PyInt_FromLong(FUNCFLAG_HRESULT)); PyModule_AddObject(m, "FUNCFLAG_STDCALL", PyInt_FromLong(FUNCFLAG_STDCALL)); |
From: Thomas H. <th...@us...> - 2006-02-09 20:23:09
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28053 Modified Files: Tag: branch_1_0 __init__.py Log Message: memmove and memset are now implemented by using foreign functions. Requires to extend c_void_p.from_param to accept int/long arguments as well. The addresses are exported by the _ctypes extension, restype and argtypes are set in ctypes/__init__.py. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.61.2.27 retrieving revision 1.61.2.28 diff -C2 -d -r1.61.2.27 -r1.61.2.28 *** __init__.py 27 Jan 2006 17:57:50 -0000 1.61.2.27 --- __init__.py 9 Feb 2006 20:22:58 -0000 1.61.2.28 *************** *** 402,406 **** # functions ! from _ctypes import memmove, memset, string_at, cast from decorators import cdecl --- 402,418 ---- # functions ! from _ctypes import memmove_addr, memset_addr, string_at, cast ! ! if sizeof(c_uint) == sizeof(c_void_p): ! c_size_t = c_uint ! elif sizeof(c_ulong) == sizeof(c_void_p): ! c_size_t = c_ulong ! ! ## void *memmove(void *, const void *, size_t); ! memmove = CFUNCTYPE(c_size_t, c_void_p, c_void_p, c_size_t)(memmove_addr) ! ! ## void *memset(void *, int, size_t) ! memset = CFUNCTYPE(c_void_p, c_void_p, c_int, c_size_t)(memset_addr) ! from decorators import cdecl |
From: Thomas H. <th...@us...> - 2006-02-08 20:43:48
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5200 Modified Files: Tag: branch_1_0 test-cf.py Log Message: Use -u flag for Python. Index: test-cf.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/Attic/test-cf.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** test-cf.py 7 Feb 2006 20:22:58 -0000 1.1.2.1 --- test-cf.py 8 Feb 2006 20:43:39 -0000 1.1.2.2 *************** *** 4,43 **** hostinfo = [ # Not python 2.3 or newer: ! ## ("x86-openbsd1", "/usr/local/bin/python"), ("x86-solaris1", ! "env PATH=/opt/SUNWspro/bin:/usr/local/bin:/usr/local/sbin:$PATH python"), ! ("x86-linux1", "/usr/bin/python"), # Permission denied ! ("x86-linux2", "/usr/bin/python"), # Host key verification failed ! ("x86-freebsd1", "/usr/local/bin/python"), # ImportError: _ctypes.so: Undefined PLT symbol "PyGILState_Ensure" # Python without threading module??? ! ("x86-netbsd1", "/usr/pkg/bin/python2.3"), ! ("amd64-linux1", "/usr/bin/python"), # Same platform as the previous one: ! ## ("amd64-linux2", "/usr/bin/python"), # Host key verification failed ! ("alpha-linux1", "/usr/bin/python"), # No route to host: ! ("ppc-osx1", "/sw/bin/python"), # No route to host: ! ("ppc-osx2", "/usr/bin/python"), # Not python 2.3 or newer: ! ## ("sparc-solaris1", "/usr/local/bin/python"), ! ## ("sparc-solaris2", "/usr/local/bin/python"), ! ("openpower-linux1", "python")] import sys, os --- 4,43 ---- hostinfo = [ # Not python 2.3 or newer: ! ## ("x86-openbsd1", "/usr/local/bin/python -u"), ("x86-solaris1", ! "env PATH=/opt/SUNWspro/bin:/usr/local/bin:/usr/local/sbin:$PATH python -u"), ! ("x86-linux1", "/usr/bin/python -u"), # Permission denied ! ("x86-linux2", "/usr/bin/python -u"), # Host key verification failed ! ("x86-freebsd1", "/usr/local/bin/python -u"), # ImportError: _ctypes.so: Undefined PLT symbol "PyGILState_Ensure" # Python without threading module??? ! ("x86-netbsd1", "/usr/pkg/bin/python2.3 -u"), ! ("amd64-linux1", "/usr/bin/python -u"), # Same platform as the previous one: ! ## ("amd64-linux2", "/usr/bin/python -u"), # Host key verification failed ! ("alpha-linux1", "/usr/bin/python -u"), # No route to host: ! ("ppc-osx1", "/sw/bin/python -u"), # No route to host: ! ("ppc-osx2", "/usr/bin/python -u"), # Not python 2.3 or newer: ! ## ("sparc-solaris1", "/usr/local/bin/python -u"), ! ## ("sparc-solaris2", "/usr/local/bin/python -u"), ! ("openpower-linux1", "python -u")] import sys, os *************** *** 46,52 **** print "*" * 20, hostname, "*" * 20 if len(sys.argv) > 1: ! cmd = "cd ~/ctypes; %s setup.py %s" % (python, " ".join(sys.argv[1:])) else: ! cmd = "cd ~/ctypes; %s setup.py -q build_ext -f test -v " % python print cmd ret = os.system('ssh -l theller cf-shell.sf.net "ssh %s \'%s\'"' % (hostname, cmd)) --- 46,52 ---- print "*" * 20, hostname, "*" * 20 if len(sys.argv) > 1: ! cmd = "cd ~/ctypes-0.9.9.1; %s setup.py %s" % (python, " ".join(sys.argv[1:])) else: ! cmd = "cd ~/ctypes-0.9.9.1; %s setup.py -q build_ext -f test -v " % python print cmd ret = os.system('ssh -l theller cf-shell.sf.net "ssh %s \'%s\'"' % (hostname, cmd)) |
From: Thomas H. <th...@us...> - 2006-02-08 07:11:11
|
Update of /cvsroot/ctypes/ctypes/comtypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31623 Modified Files: Tag: branch_1_0 test_safearray.py Log Message: Fix NameError. Index: test_safearray.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/test/Attic/test_safearray.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** test_safearray.py 8 Nov 2005 20:43:38 -0000 1.1.2.1 --- test_safearray.py 8 Feb 2006 07:11:02 -0000 1.1.2.2 *************** *** 24,26 **** if __name__ == "__main__": ! unittest.main() --- 24,26 ---- if __name__ == "__main__": ! ut.main() |
From: Thomas H. <th...@us...> - 2006-02-07 20:45:41
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2154 Modified Files: Tag: branch_1_0 test_memfunctions.py Log Message: Allocate large buffers. This increases the chance that memory addresses do no longer fit in a int on platforms where sizeof(void *) > sizeof(int). Index: test_memfunctions.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_memfunctions.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** test_memfunctions.py 3 Nov 2005 19:49:19 -0000 1.1.2.1 --- test_memfunctions.py 7 Feb 2006 20:45:32 -0000 1.1.2.2 *************** *** 4,8 **** class MemFunctionsTest(unittest.TestCase): def test_memmove(self): ! a = create_string_buffer(32) p = "Hello, World" result = memmove(a, p, len(p)) --- 4,10 ---- class MemFunctionsTest(unittest.TestCase): def test_memmove(self): ! # large buffers apparently increase the chance that the memory ! # is allocated in high address space. ! a = create_string_buffer(1000000) p = "Hello, World" result = memmove(a, p, len(p)) *************** *** 14,18 **** def test_memset(self): ! a = create_string_buffer(32) result = memset(a, ord('x'), 16) --- 16,20 ---- def test_memset(self): ! a = create_string_buffer(1000000) result = memset(a, ord('x'), 16) *************** *** 34,38 **** def test_wstring_at(self): p = create_unicode_buffer("Hello, World") ! a = create_unicode_buffer(32) result = memmove(a, p, len(p) * sizeof(c_wchar)) self.failUnlessEqual(a.value, "Hello, World") --- 36,40 ---- def test_wstring_at(self): p = create_unicode_buffer("Hello, World") ! a = create_unicode_buffer(1000000) result = memmove(a, p, len(p) * sizeof(c_wchar)) self.failUnlessEqual(a.value, "Hello, World") |
From: Thomas H. <th...@us...> - 2006-02-07 20:23:17
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24234 Added Files: Tag: branch_1_0 test-cf.py Log Message: A script to test ctypes on te various SF compilefarm servers - when they are working and reachable ;-) --- NEW FILE: test-cf.py --- # Script to build and test ctypes on the compile-farm servers. # Accepts the same arguments as setup.py hostinfo = [ # Not python 2.3 or newer: ## ("x86-openbsd1", "/usr/local/bin/python"), ("x86-solaris1", "env PATH=/opt/SUNWspro/bin:/usr/local/bin:/usr/local/sbin:$PATH python"), ("x86-linux1", "/usr/bin/python"), # Permission denied ("x86-linux2", "/usr/bin/python"), # Host key verification failed ("x86-freebsd1", "/usr/local/bin/python"), # ImportError: _ctypes.so: Undefined PLT symbol "PyGILState_Ensure" # Python without threading module??? ("x86-netbsd1", "/usr/pkg/bin/python2.3"), ("amd64-linux1", "/usr/bin/python"), # Same platform as the previous one: ## ("amd64-linux2", "/usr/bin/python"), # Host key verification failed ("alpha-linux1", "/usr/bin/python"), # No route to host: ("ppc-osx1", "/sw/bin/python"), # No route to host: ("ppc-osx2", "/usr/bin/python"), # Not python 2.3 or newer: ## ("sparc-solaris1", "/usr/local/bin/python"), ## ("sparc-solaris2", "/usr/local/bin/python"), ("openpower-linux1", "python")] import sys, os for hostname, python in hostinfo: print "*" * 20, hostname, "*" * 20 if len(sys.argv) > 1: cmd = "cd ~/ctypes; %s setup.py %s" % (python, " ".join(sys.argv[1:])) else: cmd = "cd ~/ctypes; %s setup.py -q build_ext -f test -v " % python print cmd ret = os.system('ssh -l theller cf-shell.sf.net "ssh %s \'%s\'"' % (hostname, cmd)) if ret: print "(RETCODE %s)" % ret print "-" * 50 print |
From: Thomas H. <th...@us...> - 2006-02-07 20:21:14
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23509 Modified Files: Tag: branch_1_0 test_cfuncs.py Log Message: long and ulong function parameters need argtypes (on 64-bit platforms). Index: test_cfuncs.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_cfuncs.py,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** test_cfuncs.py 27 Jan 2006 18:18:54 -0000 1.1.2.3 --- test_cfuncs.py 7 Feb 2006 20:21:06 -0000 1.1.2.4 *************** *** 93,96 **** --- 93,97 ---- def test_ulong(self): self._dll.tf_L.restype = c_ulong + self._dll.tf_L.argtypes = (c_ulong,) self.failUnlessEqual(self._dll.tf_L(4294967295), 1431655765) self.failUnlessEqual(self.U(), 4294967295) *************** *** 98,102 **** def test_ulong_plus(self): self._dll.tf_bL.restype = c_ulong ! self.failUnlessEqual(self._dll.tf_bL(0, 4294967295), 1431655765) self.failUnlessEqual(self.U(), 4294967295) --- 99,104 ---- def test_ulong_plus(self): self._dll.tf_bL.restype = c_ulong ! self._dll.tf_bL.argtypes = (c_char, c_ulong) ! self.failUnlessEqual(self._dll.tf_bL(' ', 4294967295), 1431655765) self.failUnlessEqual(self.U(), 4294967295) |
From: Thomas H. <th...@us...> - 2006-02-07 20:20:13
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22971 Modified Files: Tag: branch_1_0 callproc.c Log Message: Repair 'integer' parameter passing (on 32-bit platforms). The mem... functions are still broken on 64-bit platforms since they do int -> void * conversions (reported by Hye-Shik Chan). Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.127.2.22 retrieving revision 1.127.2.23 diff -C2 -d -r1.127.2.22 -r1.127.2.23 *** callproc.c 3 Feb 2006 01:53:08 -0000 1.127.2.22 --- callproc.c 7 Feb 2006 20:20:04 -0000 1.127.2.23 *************** *** 474,489 **** if (PyInt_Check(obj)) { ! pa->ffi_type = &ffi_type_slong; ! pa->value.l = PyInt_AS_LONG(obj); return 0; } if (PyLong_Check(obj)) { ! pa->ffi_type = &ffi_type_slong; ! pa->value.l = (long)PyLong_AsUnsignedLong(obj); ! if (pa->value.l == -1 && PyErr_Occurred()) { PyErr_Clear(); ! pa->value.l = PyLong_AsLong(obj); ! if (pa->value.l == -1 && PyErr_Occurred()) { PyErr_SetString(PyExc_OverflowError, "long int too long to convert"); --- 474,489 ---- 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 = (long)PyLong_AsUnsignedLong(obj); ! if (pa->value.i == -1 && PyErr_Occurred()) { PyErr_Clear(); ! pa->value.i = PyLong_AsLong(obj); ! if (pa->value.i == -1 && PyErr_Occurred()) { PyErr_SetString(PyExc_OverflowError, "long int too long to convert"); *************** *** 553,557 **** if (PyInt_Check(arg)) { pa->ffi_type = &ffi_type_sint; ! pa->value.l = PyInt_AS_LONG(arg); pa->keep = arg; return 0; --- 553,557 ---- if (PyInt_Check(arg)) { pa->ffi_type = &ffi_type_sint; ! pa->value.i = PyInt_AS_LONG(arg); pa->keep = arg; return 0; *************** *** 938,942 **** goto cleanup; ! #if WORDS_BIGENDIAN /* libffi returns the result in a buffer with sizeof(ffi_arg). This causes problems on big endian machines, since the result buffer --- 938,942 ---- goto cleanup; ! #ifdef WORDS_BIGENDIAN /* libffi returns the result in a buffer with sizeof(ffi_arg). This causes problems on big endian machines, since the result buffer |
From: Hye-Shik C. <pe...@us...> - 2006-02-04 06:50:41
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3911 Modified Files: Tag: branch_1_0 setup.py Log Message: Solaris assembler doesn't like sysv.S to link with ffi.o. Add a workaround for that. See: http://gcc.gnu.org/ml/gcc-patches/2002-11/msg01815.html Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.122.2.13 retrieving revision 1.122.2.14 diff -C2 -d -r1.122.2.13 -r1.122.2.14 *** setup.py 1 Feb 2006 20:52:49 -0000 1.122.2.13 --- setup.py 4 Feb 2006 06:50:29 -0000 1.122.2.14 *************** *** 255,258 **** --- 255,260 ---- extra_link_args.extend(['-read_only_relocs', 'warning']) include_dirs.append("source/darwin") + elif sys.platform == "sunos5": + extra_link_args.extend(['-mimpure-text']) extensions = [Extension("_ctypes", |
From: Hye-Shik C. <pe...@us...> - 2006-02-04 06:33:13
|
Update of /cvsroot/ctypes/ctypes/source/libffi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31869 Modified Files: Tag: branch_1_0 configure configure.ac fficonfig.h.in Log Message: Disable the raw-api support since we don't need it and some code for raw-api even doesn't compile in Solaris assembler. Index: fficonfig.h.in =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/libffi/Attic/fficonfig.h.in,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** fficonfig.h.in 1 Feb 2006 20:31:51 -0000 1.1.2.4 --- fficonfig.h.in 4 Feb 2006 06:33:05 -0000 1.1.2.5 *************** *** 12,15 **** --- 12,18 ---- #undef EH_FRAME_FLAGS + /* Define this is you do not want support for the raw API. */ + #undef FFI_NO_RAW_API + /* Define to 1 if you have `alloca', as a function or macro. */ #undef HAVE_ALLOCA Index: configure.ac =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/libffi/Attic/configure.ac,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** configure.ac 1 Feb 2006 20:31:51 -0000 1.1.2.4 --- configure.ac 4 Feb 2006 06:33:05 -0000 1.1.2.5 *************** *** 186,189 **** --- 186,191 ---- AC_SUBST(SHELL) + AC_DEFINE(FFI_NO_RAW_API, 1, [Define this is you do not want support for the raw API.]) + AC_CONFIG_COMMANDS(include, [test -d include || mkdir include]) AC_CONFIG_COMMANDS(src, [ Index: configure =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/libffi/Attic/configure,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** configure 1 Feb 2006 20:31:51 -0000 1.1.2.4 --- configure 4 Feb 2006 06:33:05 -0000 1.1.2.5 *************** *** 5456,5459 **** --- 5456,5465 ---- + + cat >>confdefs.h <<\_ACEOF + #define FFI_NO_RAW_API 1 + _ACEOF + + ac_config_commands="$ac_config_commands include" |
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31719 Modified Files: Tag: branch_1_0 manual.txt manual.html libraries.txt functions.txt callbacks.txt Added Files: Tag: branch_1_0 utilities.txt simple_types.txt Log Message: Index: functions.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/functions.txt,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** functions.txt 2 Feb 2006 21:06:15 -0000 1.1.2.2 --- functions.txt 3 Feb 2006 08:32:06 -0000 1.1.2.3 *************** *** 1,5 **** ! Functions ! --------- Functions exported from loaded shared libraries can be accessed in two --- 1,5 ---- ! Function objects ! ---------------- Functions exported from loaded shared libraries can be accessed in two *************** *** 40,45 **** detects a failure, or return the needed return value otherwise. ! Prototypes ! ---------- Another way to access a function exported from shared libraries is to --- 40,45 ---- detects a failure, or return the needed return value otherwise. ! Function prototypes ! ~~~~~~~~~~~~~~~~~~~ Another way to access a function exported from shared libraries is to *************** *** 108,112 **** COM methods (Windows only) ! -------------------------- XXX Should this be left undocumented? Mentioned for completeness. --- 108,112 ---- COM methods (Windows only) ! ~~~~~~~~~~~~~~~~~~~~~~~~~~ XXX Should this be left undocumented? Mentioned for completeness. Index: libraries.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/libraries.txt,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** libraries.txt 2 Feb 2006 20:32:29 -0000 1.1.2.1 --- libraries.txt 3 Feb 2006 08:32:06 -0000 1.1.2.2 *************** *** 16,20 **** class LibraryLoader ! ------------------- Instances of this ``LibraryLoader`` are used to load shared libraries. --- 16,20 ---- class LibraryLoader ! ~~~~~~~~~~~~~~~~~~~ Instances of this ``LibraryLoader`` are used to load shared libraries. *************** *** 75,79 **** Predefined library loaders ! -------------------------- ctypes provides some LibraryLoader instances, the differences are the --- 75,79 ---- Predefined library loaders ! ~~~~~~~~~~~~~~~~~~~~~~~~~~ ctypes provides some LibraryLoader instances, the differences are the Index: callbacks.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/callbacks.txt,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** callbacks.txt 2 Feb 2006 21:06:15 -0000 1.1.2.1 --- callbacks.txt 3 Feb 2006 08:32:06 -0000 1.1.2.2 *************** *** 1,4 **** Callback functions ! ------------------ ctypes is able to create C callable functions from Python callables. --- 1,4 ---- Callback functions ! ~~~~~~~~~~~~~~~~~~ ctypes is able to create C callable functions from Python callables. Index: manual.html =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/manual.html,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** manual.html 2 Feb 2006 21:06:15 -0000 1.1.2.4 --- manual.html 3 Feb 2006 08:32:06 -0000 1.1.2.5 *************** *** 293,308 **** <div class="document" id="ctypes-manual"> <h1 class="title">ctypes manual</h1> ! <p>(work in progress)</p> <div class="contents topic"> <p class="topic-title first"><a id="contents" name="contents">Contents</a></p> <ul class="simple"> ! <li><a class="reference" href="#shared-libraries-dlls" id="id1" name="id1">Shared Libraries, DLLs</a></li> <li><a class="reference" href="#class-libraryloader" id="id2" name="id2">class LibraryLoader</a></li> <li><a class="reference" href="#predefined-library-loaders" id="id3" name="id3">Predefined library loaders</a></li> ! <li><a class="reference" href="#functions" id="id4" name="id4">Functions</a></li> ! <li><a class="reference" href="#prototypes" id="id5" name="id5">Prototypes</a></li> <li><a class="reference" href="#com-methods-windows-only" id="id6" name="id6">COM methods (Windows only)</a></li> <li><a class="reference" href="#callback-functions" id="id7" name="id7">Callback functions</a></li> </ul> </div> <div class="section"> --- 293,326 ---- <div class="document" id="ctypes-manual"> <h1 class="title">ctypes manual</h1> ! <p>(work in progress, $Revision$)</p> <div class="contents topic"> <p class="topic-title first"><a id="contents" name="contents">Contents</a></p> <ul class="simple"> ! <li><a class="reference" href="#shared-libraries-dlls" id="id1" name="id1">Shared Libraries, DLLs</a><ul> <li><a class="reference" href="#class-libraryloader" id="id2" name="id2">class LibraryLoader</a></li> <li><a class="reference" href="#predefined-library-loaders" id="id3" name="id3">Predefined library loaders</a></li> ! </ul> ! </li> ! <li><a class="reference" href="#function-objects" id="id4" name="id4">Function objects</a><ul> ! <li><a class="reference" href="#function-prototypes" id="id5" name="id5">Function prototypes</a></li> <li><a class="reference" href="#com-methods-windows-only" id="id6" name="id6">COM methods (Windows only)</a></li> <li><a class="reference" href="#callback-functions" id="id7" name="id7">Callback functions</a></li> </ul> + </li> + <li><a class="reference" href="#simple-types" id="id8" name="id8">Simple types</a><ul> + <li><a class="reference" href="#class-attributes-of-simple-types" id="id9" name="id9">Class attributes of simple types</a></li> + <li><a class="reference" href="#class-methods-of-simple-types" id="id10" name="id10">Class methods of simple types</a></li> + <li><a class="reference" href="#instance-attributes-of-simple-types" id="id11" name="id11">Instance attributes of simple types</a></li> + <li><a class="reference" href="#numeric-types" id="id12" name="id12">Numeric types</a></li> + <li><a class="reference" href="#character-types" id="id13" name="id13">Character types</a></li> + <li><a class="reference" href="#pointer-types" id="id14" name="id14">Pointer types</a></li> + <li><a class="reference" href="#string-types" id="id15" name="id15">String types</a></li> + </ul> + </li> + <li><a class="reference" href="#builtin-functions" id="id16" name="id16">Builtin functions</a><ul> + <li><a class="reference" href="#deprecated-functions" id="id17" name="id17">Deprecated functions</a></li> + </ul> + </li> + </ul> </div> <div class="section"> *************** *** 318,324 **** especially usefull for interactive use, it is equivalent to calling <tt class="docutils literal"><span class="pre">load_version</span></tt> with no version specified.</p> - </div> <div class="section"> ! <h1><a class="toc-backref" href="#id2" id="class-libraryloader" name="class-libraryloader">class LibraryLoader</a></h1> <p>Instances of this <tt class="docutils literal"><span class="pre">LibraryLoader</span></tt> are used to load shared libraries. They have the following methods:</p> --- 336,341 ---- especially usefull for interactive use, it is equivalent to calling <tt class="docutils literal"><span class="pre">load_version</span></tt> with no version specified.</p> <div class="section"> ! <h2><a class="toc-backref" href="#id2" id="class-libraryloader" name="class-libraryloader">class LibraryLoader</a></h2> <p>Instances of this <tt class="docutils literal"><span class="pre">LibraryLoader</span></tt> are used to load shared libraries. They have the following methods:</p> *************** *** 371,375 **** </div> <div class="section"> ! <h1><a class="toc-backref" href="#id3" id="predefined-library-loaders" name="predefined-library-loaders">Predefined library loaders</a></h1> <p>ctypes provides some LibraryLoader instances, the differences are the calling conventions the functions will use, the default return type of --- 388,392 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id3" id="predefined-library-loaders" name="predefined-library-loaders">Predefined library loaders</a></h2> <p>ctypes provides some LibraryLoader instances, the differences are the calling conventions the functions will use, the default return type of *************** *** 419,424 **** </blockquote> </div> <div class="section"> ! <h1><a class="toc-backref" href="#id4" id="functions" name="functions">Functions</a></h1> <p>Functions exported from loaded shared libraries can be accessed in two ways. The easiest way is to access them as attributes of library --- 436,442 ---- </blockquote> </div> + </div> <div class="section"> ! <h1><a class="toc-backref" href="#id4" id="function-objects" name="function-objects">Function objects</a></h1> <p>Functions exported from loaded shared libraries can be accessed in two ways. The easiest way is to access them as attributes of library *************** *** 454,460 **** should validate the library function result, raise an error if it detects a failure, or return the needed return value otherwise.</p> - </div> <div class="section"> ! <h1><a class="toc-backref" href="#id5" id="prototypes" name="prototypes">Prototypes</a></h1> <p>Another way to access a function exported from shared libraries is to first create a prototype by calling a factory function, specifying the --- 472,477 ---- should validate the library function result, raise an error if it detects a failure, or return the needed return value otherwise.</p> <div class="section"> ! <h2><a class="toc-backref" href="#id5" id="function-prototypes" name="function-prototypes">Function prototypes</a></h2> <p>Another way to access a function exported from shared libraries is to first create a prototype by calling a factory function, specifying the *************** *** 514,518 **** </div> <div class="section"> ! <h1><a class="toc-backref" href="#id6" id="com-methods-windows-only" name="com-methods-windows-only">COM methods (Windows only)</a></h1> <p>XXX Should this be left undocumented? Mentioned for completeness.</p> <p>The prototypes created by <tt class="docutils literal"><span class="pre">WINFUNCTYPE</span></tt> can be called with a --- 531,535 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id6" id="com-methods-windows-only" name="com-methods-windows-only">COM methods (Windows only)</a></h2> <p>XXX Should this be left undocumented? Mentioned for completeness.</p> <p>The prototypes created by <tt class="docutils literal"><span class="pre">WINFUNCTYPE</span></tt> can be called with a *************** *** 531,535 **** </div> <div class="section"> ! <h1><a class="toc-backref" href="#id7" id="callback-functions" name="callback-functions">Callback functions</a></h1> <p>ctypes is able to create C callable functions from Python callables. This is useful because sometimes library functions need a callback --- 548,552 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id7" id="callback-functions" name="callback-functions">Callback functions</a></h2> <p>ctypes is able to create C callable functions from Python callables. This is useful because sometimes library functions need a callback *************** *** 558,561 **** --- 575,747 ---- </div> </div> + <div class="section"> + <h1><a class="toc-backref" href="#id8" id="simple-types" name="simple-types">Simple types</a></h1> + <p>Simple types have some special behaviour: When they are accessed as + structure or union fields, items of array instances, or as foreign + function return values, they are transparently converted from and to + the native Python types int, long, string, and unicode.</p> + <p>This is <em>not</em> the case for subclasses of simply data types, so while a + <tt class="docutils literal"><span class="pre">c_void_p</span></tt> type is transparently converted from and to Python + integer or long, a subclass of c_void_p is <em>not</em> converted. This + allows to almost completely define new behaviour.</p> + <div class="section"> + <h2><a class="toc-backref" href="#id9" id="class-attributes-of-simple-types" name="class-attributes-of-simple-types">Class attributes of simple types</a></h2> + <p><tt class="docutils literal"><span class="pre">__ctype__be__</span></tt>, <tt class="docutils literal"><span class="pre">__ctype_le__</span></tt></p> + <blockquote> + If the type supports different byte order (pointer types do NOT + support this), <tt class="docutils literal"><span class="pre">__ctype_be__</span></tt> and <tt class="docutils literal"><span class="pre">__ctype_le__</span></tt> are types + with bug endian and little endian byte order. For example, + <tt class="docutils literal"><span class="pre">c_int.__ctype_be__</span></tt> is an integer type with the memory block in + big endian byte order.</blockquote> + </div> + <div class="section"> + <h2><a class="toc-backref" href="#id10" id="class-methods-of-simple-types" name="class-methods-of-simple-types">Class methods of simple types</a></h2> + <p>(To be exact, these are not class methods, instead these are methods + of the metaclass. The most prominent difference to classmethods is + that you can call these methods on the class, but not on the instance + of the simple type.)</p> + <p><tt class="docutils literal"><span class="pre">__ctypes_from_outparam__</span></tt></p> + <blockquote> + TBD</blockquote> + <p><tt class="docutils literal"><span class="pre">from_address</span></tt></p> + <blockquote> + TBD</blockquote> + <p><tt class="docutils literal"><span class="pre">from_param</span></tt></p> + <blockquote> + <p>This is a class method (an instance method of the metaclass, to be + exact) that will be used to adapt function parameters. If a + <tt class="docutils literal"><span class="pre">c_int</span></tt> type is specified in a functions argtypes sequence, + <tt class="docutils literal"><span class="pre">c_int.from_param(arg)</span></tt> will be called by ctypes and the result + will be passed to the foreign function call as parameter.</p> + <p><tt class="docutils literal"><span class="pre">from_param</span></tt> usually returns an internal object that you cannot + use on Python code - it makes only sense to pass this to foreign + functions.</p> + <p>On one hand, <tt class="docutils literal"><span class="pre">from_param</span></tt> is a performance optimization - it + allows to pass Python integers to function calls expecting a + <tt class="docutils literal"><span class="pre">c_int</span></tt> argument type, without having to create a full-features + <tt class="docutils literal"><span class="pre">c_int</span></tt> instance.</p> + <p>On the other hand, <tt class="docutils literal"><span class="pre">from_param</span></tt> can adapt other objects to + parameters. XXX explain the automatic <tt class="docutils literal"><span class="pre">byref</span></tt> call for byref + arguments.</p> + </blockquote> + <p><tt class="docutils literal"><span class="pre">in_dll</span></tt></p> + <blockquote> + TBD</blockquote> + </div> + <div class="section"> + <h2><a class="toc-backref" href="#id11" id="instance-attributes-of-simple-types" name="instance-attributes-of-simple-types">Instance attributes of simple types</a></h2> + <p><tt class="docutils literal"><span class="pre">_type_</span></tt></p> + <blockquote> + Implementation artifact: the typecode for this type, a single + character string code compatible to what the struct module uses. + Additional characters are used for types that the struct module + does not support.</blockquote> + <p><tt class="docutils literal"><span class="pre">_objects</span></tt> (never modify this)</p> + <blockquote> + Implementation artifact: a Python object keeping references to + other objects which must be kept alive. Never modify anything on + the returned object. XXX Should probably not be exposed.</blockquote> + <p><tt class="docutils literal"><span class="pre">_b_base_</span></tt> (readonly)</p> + <blockquote> + Implementation artifact: the base object owning the memory block + (if any).</blockquote> + <p><tt class="docutils literal"><span class="pre">_b_needsfree_</span></tt> (readonly)</p> + <blockquote> + Implementation artifact: does this object have to free it's memory + block on destruction.</blockquote> + <p><tt class="docutils literal"><span class="pre">value</span></tt></p> + <blockquote> + Allows to get or set the current value of the object. For simpe + types, this is always a native Python object like integer, long, + string, or unicode.</blockquote> + <p><tt class="docutils literal"><span class="pre">_as_parameter_</span></tt> (readonly)</p> + <blockquote> + Implementation artifact (?): how to pass this object as function + parameter.</blockquote> + </div> + <div class="section"> + <h2><a class="toc-backref" href="#id12" id="numeric-types" name="numeric-types">Numeric types</a></h2> + <p>Integer types are <tt class="docutils literal"><span class="pre">c_byte</span></tt>, <tt class="docutils literal"><span class="pre">c_short</span></tt>, <tt class="docutils literal"><span class="pre">c_int</span></tt>, <tt class="docutils literal"><span class="pre">c_long</span></tt>, + <tt class="docutils literal"><span class="pre">c_longlong</span></tt> and there unsigned variants <tt class="docutils literal"><span class="pre">c_ubyte</span></tt>, <tt class="docutils literal"><span class="pre">c_ushort</span></tt>, + <tt class="docutils literal"><span class="pre">c_uint</span></tt>, <tt class="docutils literal"><span class="pre">c_ulong</span></tt> and <tt class="docutils literal"><span class="pre">c_longlong</span></tt>, floating point types are + <tt class="docutils literal"><span class="pre">c_float</span></tt> and <tt class="docutils literal"><span class="pre">c_double</span></tt>.</p> + <p>The constructor and the <tt class="docutils literal"><span class="pre">from_param</span></tt> class method accept a Python + integer for integer types, a Python float for floating point types.</p> + <p>On 32-bit platforms where sizeof(int) == sizeof(long), <tt class="docutils literal"><span class="pre">c_int</span></tt> is an + alias for <tt class="docutils literal"><span class="pre">c_long</span></tt>, on 64-bit platforms where sizeof(long) == + sizeof(long long), <tt class="docutils literal"><span class="pre">c_long</span></tt> is an alias for <tt class="docutils literal"><span class="pre">c_longlong</span></tt>.</p> + </div> + <div class="section"> + <h2><a class="toc-backref" href="#id13" id="character-types" name="character-types">Character types</a></h2> + <p>Character types are <tt class="docutils literal"><span class="pre">c_char</span></tt> and <tt class="docutils literal"><span class="pre">c_wchar</span></tt>, representing the C + <tt class="docutils literal"><span class="pre">char</span></tt> and <tt class="docutils literal"><span class="pre">wchar_t</span></tt> types.</p> + <p>The constructor and the <tt class="docutils literal"><span class="pre">from_param</span></tt> class method accept a single + character Python string or unicode string. Conversion between string + and unicode, if needed, is done according to the ctypes + encoding/decoding rules.</p> + </div> + <div class="section"> + <h2><a class="toc-backref" href="#id14" id="pointer-types" name="pointer-types">Pointer types</a></h2> + <p>The only simple pointer type is <tt class="docutils literal"><span class="pre">c_void_p</span></tt>, which represents the C + <tt class="docutils literal"><span class="pre">void</span> <span class="pre">*</span></tt> datra type. <tt class="docutils literal"><span class="pre">c_void_p</span></tt> can also be written as + <tt class="docutils literal"><span class="pre">POINTER(None)</span></tt>.</p> + <p>The constructor accepts one optional argument, which must be an + integer, or <tt class="docutils literal"><span class="pre">None</span></tt>.</p> + <p>The <tt class="docutils literal"><span class="pre">from_param</span></tt> class method accepts Python strings or unicode + strings, as well as <tt class="docutils literal"><span class="pre">None</span></tt>.</p> + <p>The <tt class="docutils literal"><span class="pre">value</span></tt> attribute accepts and returns None or integer.</p> + <p>XXX Why does from_param accept an integer, and the constructor doesn't?</p> + </div> + <div class="section"> + <h2><a class="toc-backref" href="#id15" id="string-types" name="string-types">String types</a></h2> + <p>ctypes has the <tt class="docutils literal"><span class="pre">c_char_p</span></tt> and <tt class="docutils literal"><span class="pre">c_wchar_p</span></tt> types which represent + const pointers to zero terminated strings in C: <tt class="docutils literal"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></tt> and + <tt class="docutils literal"><span class="pre">const</span> <span class="pre">wchar_t</span> <span class="pre">*</span></tt>. Since Python strings and unicode instances are + immutable, these types should be considered readonly: do not pass them + to functions that write into the buffer.</p> + <p>The constructor accepts one optional argument, which must be a Python + string or unicode string, an integer, or <tt class="docutils literal"><span class="pre">None</span></tt>.</p> + <p>The <tt class="docutils literal"><span class="pre">from_param</span></tt> class method accepts Python strings or unicode + strings, as well as <tt class="docutils literal"><span class="pre">None</span></tt>. Conversion between string and unicode, + if needed, is done according to the ctypes encoding/decoding rules.</p> + <p>XXX Why does the constructor accept an integer, and from_param doesn't?</p> + </div> + </div> + <div class="section"> + <h1><a class="toc-backref" href="#id16" id="builtin-functions" name="builtin-functions">Builtin functions</a></h1> + <p><tt class="docutils literal"><span class="pre">CFUNCTYPE(restype,</span> <span class="pre">*argtypes)</span></tt></p> + <p><tt class="docutils literal"><span class="pre">WINFUNCTYPE(restype,</span> <span class="pre">*argtypes)</span></tt> (Windows only)</p> + <p><tt class="docutils literal"><span class="pre">addressof(object)</span></tt></p> + <p><tt class="docutils literal"><span class="pre">alignment(object)</span></tt></p> + <p><tt class="docutils literal"><span class="pre">sizeof(object)</span></tt></p> + <p><tt class="docutils literal"><span class="pre">byref(object)</span></tt></p> + <p><tt class="docutils literal"><span class="pre">cast(object,</span> <span class="pre">typ)</span></tt></p> + <p><tt class="docutils literal"><span class="pre">POINTER(cls)</span></tt></p> + <p><tt class="docutils literal"><span class="pre">pointer(object)</span></tt></p> + <p><tt class="docutils literal"><span class="pre">string_at(addr[,</span> <span class="pre">size])</span></tt></p> + <p><tt class="docutils literal"><span class="pre">wstring_at(addr[,</span> <span class="pre">size])</span></tt></p> + <p><tt class="docutils literal"><span class="pre">create_string_buffer(init,</span> <span class="pre">size=None)</span></tt></p> + <p><tt class="docutils literal"><span class="pre">create_unicode_buffer(init,</span> <span class="pre">size=None)</span></tt></p> + <p><tt class="docutils literal"><span class="pre">memmove(dst,</span> <span class="pre">src,</span> <span class="pre">count)</span></tt></p> + <p><tt class="docutils literal"><span class="pre">memset(dst,</span> <span class="pre">c,</span> <span class="pre">count)</span></tt></p> + <p><tt class="docutils literal"><span class="pre">set_conversion_mode(encoding,</span> <span class="pre">errors)</span></tt></p> + <p><tt class="docutils literal"><span class="pre">DllCanUnloadNow()</span></tt>, <tt class="docutils literal"><span class="pre">DllGetClassObject(rclsid,</span> <span class="pre">riid,</span> <span class="pre">ppv)</span></tt> (Windows only)</p> + <p><tt class="docutils literal"><span class="pre">WinError(code=None,</span> <span class="pre">descr=None)</span></tt></p> + <p><tt class="docutils literal"><span class="pre">FormatError([integer])</span></tt> (Windows only)</p> + <p><tt class="docutils literal"><span class="pre">GetLastError()</span></tt> (Windows only)</p> + <div class="section"> + <h2><a class="toc-backref" href="#id17" id="deprecated-functions" name="deprecated-functions">Deprecated functions</a></h2> + <p><tt class="docutils literal"><span class="pre">c_buffer(init,</span> <span class="pre">size=None)</span></tt></p> + <blockquote> + Deprecated.</blockquote> + <p><tt class="docutils literal"><span class="pre">ARRAY(cls,</span> <span class="pre">len)</span></tt></p> + <blockquote> + Deprecated.</blockquote> + <p><tt class="docutils literal"><span class="pre">SetPointerType(pointer_class,</span> <span class="pre">cls)</span></tt></p> + <blockquote> + Deprecated.</blockquote> + </div> + </div> + </div> </body> </html> Index: manual.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/manual.txt,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -C2 -d -r1.1.2.5 -r1.1.2.6 *** manual.txt 2 Feb 2006 21:06:15 -0000 1.1.2.5 --- manual.txt 3 Feb 2006 08:32:06 -0000 1.1.2.6 *************** *** 3,7 **** ============= ! (work in progress) .. contents:: --- 3,7 ---- ============= ! (work in progress, $Revision$) .. contents:: *************** *** 10,11 **** --- 10,13 ---- .. include:: functions.txt .. include:: callbacks.txt + .. include:: simple_types.txt + .. include:: utilities.txt --- NEW FILE: utilities.txt --- Builtin functions ----------------- ``CFUNCTYPE(restype, *argtypes)`` ``WINFUNCTYPE(restype, *argtypes)`` (Windows only) ``addressof(object)`` ``alignment(object)`` ``sizeof(object)`` ``byref(object)`` ``cast(object, typ)`` ``POINTER(cls)`` ``pointer(object)`` ``string_at(addr[, size])`` ``wstring_at(addr[, size])`` ``create_string_buffer(init, size=None)`` ``create_unicode_buffer(init, size=None)`` ``memmove(dst, src, count)`` ``memset(dst, c, count)`` ``set_conversion_mode(encoding, errors)`` ``DllCanUnloadNow()``, ``DllGetClassObject(rclsid, riid, ppv)`` (Windows only) ``WinError(code=None, descr=None)`` ``FormatError([integer])`` (Windows only) ``GetLastError()`` (Windows only) Deprecated functions ~~~~~~~~~~~~~~~~~~~~ ``c_buffer(init, size=None)`` Deprecated. ``ARRAY(cls, len)`` Deprecated. ``SetPointerType(pointer_class, cls)`` Deprecated. --- NEW FILE: simple_types.txt --- Simple types ------------ Simple types have some special behaviour: When they are accessed as structure or union fields, items of array instances, or as foreign function return values, they are transparently converted from and to the native Python types int, long, string, and unicode. This is *not* the case for subclasses of simply data types, so while a ``c_void_p`` type is transparently converted from and to Python integer or long, a subclass of c_void_p is *not* converted. This allows to almost completely define new behaviour. Class attributes of simple types ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``__ctype__be__``, ``__ctype_le__`` If the type supports different byte order (pointer types do NOT support this), ``__ctype_be__`` and ``__ctype_le__`` are types with bug endian and little endian byte order. For example, ``c_int.__ctype_be__`` is an integer type with the memory block in big endian byte order. Class methods of simple types ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (To be exact, these are not class methods, instead these are methods of the metaclass. The most prominent difference to classmethods is that you can call these methods on the class, but not on the instance of the simple type.) ``__ctypes_from_outparam__`` TBD ``from_address`` TBD ``from_param`` This is a class method (an instance method of the metaclass, to be exact) that will be used to adapt function parameters. If a ``c_int`` type is specified in a functions argtypes sequence, ``c_int.from_param(arg)`` will be called by ctypes and the result will be passed to the foreign function call as parameter. ``from_param`` usually returns an internal object that you cannot use on Python code - it makes only sense to pass this to foreign functions. On one hand, ``from_param`` is a performance optimization - it allows to pass Python integers to function calls expecting a ``c_int`` argument type, without having to create a full-features ``c_int`` instance. On the other hand, ``from_param`` can adapt other objects to parameters. XXX explain the automatic ``byref`` call for byref arguments. ``in_dll`` TBD Instance attributes of simple types ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``_type_`` Implementation artifact: the typecode for this type, a single character string code compatible to what the struct module uses. Additional characters are used for types that the struct module does not support. ``_objects`` (never modify this) Implementation artifact: a Python object keeping references to other objects which must be kept alive. Never modify anything on the returned object. XXX Should probably not be exposed. ``_b_base_`` (readonly) Implementation artifact: the base object owning the memory block (if any). ``_b_needsfree_`` (readonly) Implementation artifact: does this object have to free it's memory block on destruction. ``value`` Allows to get or set the current value of the object. For simpe types, this is always a native Python object like integer, long, string, or unicode. ``_as_parameter_`` (readonly) Implementation artifact (?): how to pass this object as function parameter. Numeric types ~~~~~~~~~~~~~ Integer types are ``c_byte``, ``c_short``, ``c_int``, ``c_long``, ``c_longlong`` and there unsigned variants ``c_ubyte``, ``c_ushort``, ``c_uint``, ``c_ulong`` and ``c_longlong``, floating point types are ``c_float`` and ``c_double``. The constructor and the ``from_param`` class method accept a Python integer for integer types, a Python float for floating point types. On 32-bit platforms where sizeof(int) == sizeof(long), ``c_int`` is an alias for ``c_long``, on 64-bit platforms where sizeof(long) == sizeof(long long), ``c_long`` is an alias for ``c_longlong``. Character types ~~~~~~~~~~~~~~~ Character types are ``c_char`` and ``c_wchar``, representing the C ``char`` and ``wchar_t`` types. The constructor and the ``from_param`` class method accept a single character Python string or unicode string. Conversion between string and unicode, if needed, is done according to the ctypes encoding/decoding rules. Pointer types ~~~~~~~~~~~~~ The only simple pointer type is ``c_void_p``, which represents the C ``void *`` datra type. ``c_void_p`` can also be written as ``POINTER(None)``. The constructor accepts one optional argument, which must be an integer, or ``None``. The ``from_param`` class method accepts Python strings or unicode strings, as well as ``None``. The ``value`` attribute accepts and returns None or integer. XXX Why does from_param accept an integer, and the constructor doesn't? String types ~~~~~~~~~~~~ ctypes has the ``c_char_p`` and ``c_wchar_p`` types which represent const pointers to zero terminated strings in C: ``const char *`` and ``const wchar_t *``. Since Python strings and unicode instances are immutable, these types should be considered readonly: do not pass them to functions that write into the buffer. The constructor accepts one optional argument, which must be a Python string or unicode string, an integer, or ``None``. The ``from_param`` class method accepts Python strings or unicode strings, as well as ``None``. Conversion between string and unicode, if needed, is done according to the ctypes encoding/decoding rules. XXX Why does the constructor accept an integer, and from_param doesn't? |
From: Hye-Shik C. <pe...@us...> - 2006-02-03 02:36:30
|
Update of /cvsroot/ctypes/ctypes/ctypes/wrap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3246 Modified Files: Tag: branch_1_0 codegenerator.py Log Message: Fix inconsistent use of tab/spaces (which is refused by compileall.py) Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wrap/codegenerator.py,v retrieving revision 1.6.2.5 retrieving revision 1.6.2.6 diff -C2 -d -r1.6.2.5 -r1.6.2.6 *** codegenerator.py 21 Oct 2005 18:18:00 -0000 1.6.2.5 --- codegenerator.py 3 Feb 2006 02:36:16 -0000 1.6.2.6 *************** *** 3,6 **** --- 3,9 ---- # $Log$ + # Revision 1.6.2.6 2006/02/03 02:36:16 perky + # Fix inconsistent use of tab/spaces (which is refused by compileall.py) + # # Revision 1.6.2.5 2005/10/21 18:18:00 theller # The codegenerator now by default assumes 'char *' and 'wchar_t *' *************** *** 328,332 **** print >> self.stream, "# %s = %s # alias" % (alias.name, alias.alias) print "# unresolved alias: %s = %s" % (alias.name, alias.alias) ! def Macro(self, macro): --- 331,335 ---- print >> self.stream, "# %s = %s # alias" % (alias.name, alias.alias) print "# unresolved alias: %s = %s" % (alias.name, alias.alias) ! def Macro(self, macro): *************** *** 388,392 **** Union = Structure ! _typedefs = 0 def Typedef(self, tp): --- 391,395 ---- Union = Structure ! _typedefs = 0 def Typedef(self, tp): *************** *** 417,421 **** self.generate(tp.returns) self.generate_all(tp.iterArgTypes()) ! _pointertypes = 0 def PointerType(self, tp): --- 420,424 ---- self.generate(tp.returns) self.generate_all(tp.iterArgTypes()) ! _pointertypes = 0 def PointerType(self, tp): *************** *** 728,736 **** def cmpitems(a, b): ! a = getattr(a, "location", None) ! b = getattr(b, "location", None) ! if a is None: return -1 ! if b is None: return 1 ! return cmp(a[0],b[0]) or cmp(int(a[1]),int(b[1])) cmpitems = staticmethod(cmpitems) --- 731,739 ---- def cmpitems(a, b): ! a = getattr(a, "location", None) ! b = getattr(b, "location", None) ! if a is None: return -1 ! if b is None: return 1 ! return cmp(a[0],b[0]) or cmp(int(a[1]),int(b[1])) cmpitems = staticmethod(cmpitems) *************** *** 793,797 **** if types: items = [i for i in items if isinstance(i, types)] ! if symbols: syms = set(symbols) --- 796,800 ---- if types: items = [i for i in items if isinstance(i, types)] ! if symbols: syms = set(symbols) *************** *** 827,829 **** gen.print_stats(sys.stderr) print >> sys.stderr, "needed %d loop(s)" % loops - --- 830,831 ---- |
From: Hye-Shik C. <pe...@us...> - 2006-02-03 01:53:17
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16833/source Modified Files: Tag: branch_1_0 callproc.c Log Message: Fix ConvParam() to convert Python int and long types via libffi signed long. This fixes a compatibility problem on alpha and ia64. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.127.2.21 retrieving revision 1.127.2.22 diff -C2 -d -r1.127.2.21 -r1.127.2.22 *** callproc.c 1 Feb 2006 20:52:49 -0000 1.127.2.21 --- callproc.c 3 Feb 2006 01:53:08 -0000 1.127.2.22 *************** *** 474,478 **** if (PyInt_Check(obj)) { ! pa->ffi_type = &ffi_type_sint; pa->value.l = PyInt_AS_LONG(obj); return 0; --- 474,478 ---- if (PyInt_Check(obj)) { ! pa->ffi_type = &ffi_type_slong; pa->value.l = PyInt_AS_LONG(obj); return 0; *************** *** 480,484 **** if (PyLong_Check(obj)) { ! pa->ffi_type = &ffi_type_sint; pa->value.l = (long)PyLong_AsUnsignedLong(obj); if (pa->value.l == -1 && PyErr_Occurred()) { --- 480,484 ---- if (PyLong_Check(obj)) { ! pa->ffi_type = &ffi_type_slong; pa->value.l = (long)PyLong_AsUnsignedLong(obj); if (pa->value.l == -1 && PyErr_Occurred()) { |
From: Hye-Shik C. <pe...@us...> - 2006-02-03 01:53:17
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16833 Modified Files: Tag: branch_1_0 ChangeLog Log Message: Fix ConvParam() to convert Python int and long types via libffi signed long. This fixes a compatibility problem on alpha and ia64. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.86.2.36 retrieving revision 1.86.2.37 diff -C2 -d -r1.86.2.36 -r1.86.2.37 *** ChangeLog 1 Feb 2006 20:50:03 -0000 1.86.2.36 --- ChangeLog 3 Feb 2006 01:53:08 -0000 1.86.2.37 *************** *** 1,2 **** --- 1,8 ---- + 2006-02-02 Hye-Shik Chang <pe...@Fr...> + + * source/callproc.c: ConvParam() is fixed to convert Python + int and long types via libffi signed long. This fixes a + compatibility problem on alpha and ia64. + 2006-02-01 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2006-02-02 21:06:25
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16675 Modified Files: Tag: branch_1_0 manual.txt manual.html functions.txt Added Files: Tag: branch_1_0 callbacks.txt Log Message: Callbacks section added. Index: functions.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/functions.txt,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** functions.txt 2 Feb 2006 20:32:29 -0000 1.1.2.1 --- functions.txt 2 Feb 2006 21:06:15 -0000 1.1.2.2 *************** *** 106,107 **** --- 106,128 ---- something else, or raise an error if it detects that the library function has failed. + + COM methods (Windows only) + -------------------------- + + XXX Should this be left undocumented? Mentioned for completeness. + + The prototypes created by ``WINFUNCTYPE`` can be called with a + positive small integer ``index``, a string ``name``, an optional + ``paramflags`` tuple, and a optional ``iid`` parameter. + + This creates a function object wrapping a COM method. ``index`` is + the index into the COM object's virtual function table, ``name`` is + the name of the COM method (only useful for debugging), ``paramflags`` + has the same meaning as for normal function objects, and ``iid`` is a + string or buffer containing the interface iid of the COM interface + this method belongs to. ``iid`` is used to get extended COM error + information in case the method returns a FAILED HRESULT value. + + Note that COM methods expect an additional first argument that is NOT + listed in the prototypes ``argtypes`` when they are called: this must + be the integer address of a COM interface pointer. Index: manual.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/manual.txt,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** manual.txt 2 Feb 2006 20:32:29 -0000 1.1.2.4 --- manual.txt 2 Feb 2006 21:06:15 -0000 1.1.2.5 *************** *** 9,10 **** --- 9,11 ---- .. include:: libraries.txt .. include:: functions.txt + .. include:: callbacks.txt Index: manual.html =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/manual.html,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** manual.html 2 Feb 2006 20:32:29 -0000 1.1.2.3 --- manual.html 2 Feb 2006 21:06:15 -0000 1.1.2.4 *************** *** 302,305 **** --- 302,307 ---- <li><a class="reference" href="#functions" id="id4" name="id4">Functions</a></li> <li><a class="reference" href="#prototypes" id="id5" name="id5">Prototypes</a></li> + <li><a class="reference" href="#com-methods-windows-only" id="id6" name="id6">COM methods (Windows only)</a></li> + <li><a class="reference" href="#callback-functions" id="id7" name="id7">Callback functions</a></li> </ul> </div> *************** *** 511,514 **** --- 513,560 ---- function has failed.</p> </div> + <div class="section"> + <h1><a class="toc-backref" href="#id6" id="com-methods-windows-only" name="com-methods-windows-only">COM methods (Windows only)</a></h1> + <p>XXX Should this be left undocumented? Mentioned for completeness.</p> + <p>The prototypes created by <tt class="docutils literal"><span class="pre">WINFUNCTYPE</span></tt> can be called with a + positive small integer <tt class="docutils literal"><span class="pre">index</span></tt>, a string <tt class="docutils literal"><span class="pre">name</span></tt>, an optional + <tt class="docutils literal"><span class="pre">paramflags</span></tt> tuple, and a optional <tt class="docutils literal"><span class="pre">iid</span></tt> parameter.</p> + <p>This creates a function object wrapping a COM method. <tt class="docutils literal"><span class="pre">index</span></tt> is + the index into the COM object's virtual function table, <tt class="docutils literal"><span class="pre">name</span></tt> is + the name of the COM method (only useful for debugging), <tt class="docutils literal"><span class="pre">paramflags</span></tt> + has the same meaning as for normal function objects, and <tt class="docutils literal"><span class="pre">iid</span></tt> is a + string or buffer containing the interface iid of the COM interface + this method belongs to. <tt class="docutils literal"><span class="pre">iid</span></tt> is used to get extended COM error + information in case the method returns a FAILED HRESULT value.</p> + <p>Note that COM methods expect an additional first argument that is NOT + listed in the prototypes <tt class="docutils literal"><span class="pre">argtypes</span></tt> when they are called: this must + be the integer address of a COM interface pointer.</p> + </div> + <div class="section"> + <h1><a class="toc-backref" href="#id7" id="callback-functions" name="callback-functions">Callback functions</a></h1> + <p>ctypes is able to create C callable functions from Python callables. + This is useful because sometimes library functions need a callback + function parameter, the <tt class="docutils literal"><span class="pre">qsort</span></tt> C function is such an example.</p> + <p>Callback functions are created by first creating a function prototype + with a call to <tt class="docutils literal"><span class="pre">CFUNCTYPE</span></tt> or <tt class="docutils literal"><span class="pre">WINFUNCTYPE</span></tt>, specifying the return + type and the argument types that the callback function will receive.</p> + <p>Calling the prototype with a single Python callable will create and + return a C callable function pointer or callback function. Note that + this allows using prototypes as decorators creating callback + functions (Windows example):</p> + <pre class="literal-block"> + @WINFUNCTYPE(BOOL, HWND, LPARAM) + def enumwindowsproc(hwnd, lParam): + .... + return True + </pre> + <p>When a Python exception is raised in the Python callable, the return + value of the C callable function is undefined.</p> + <p>Important note: You must keep a reference to the callback AS LONG as + foreign code will call it! Segfaults will result if the callback is + cleaned up by Python's garbage collector and external code will still + try to call it.</p> + <p>Callback objects can also be called from Python - this may be useful + for debugging.</p> + </div> </div> </body> --- NEW FILE: callbacks.txt --- Callback functions ------------------ ctypes is able to create C callable functions from Python callables. This is useful because sometimes library functions need a callback function parameter, the ``qsort`` C function is such an example. Callback functions are created by first creating a function prototype with a call to ``CFUNCTYPE`` or ``WINFUNCTYPE``, specifying the return type and the argument types that the callback function will receive. Calling the prototype with a single Python callable will create and return a C callable function pointer or callback function. Note that this allows using prototypes as decorators creating callback functions (Windows example):: @WINFUNCTYPE(BOOL, HWND, LPARAM) def enumwindowsproc(hwnd, lParam): .... return True When a Python exception is raised in the Python callable, the return value of the C callable function is undefined. Important note: You must keep a reference to the callback AS LONG as foreign code will call it! Segfaults will result if the callback is cleaned up by Python's garbage collector and external code will still try to call it. Callback objects can also be called from Python - this may be useful for debugging. |
From: Thomas H. <th...@us...> - 2006-02-02 20:38:33
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4730 Modified Files: Tag: branch_1_0 _ctypes.c Log Message: Initialize optional parameters to be safe. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.45 retrieving revision 1.226.2.46 diff -C2 -d -r1.226.2.45 -r1.226.2.46 *** _ctypes.c 1 Feb 2006 20:52:49 -0000 1.226.2.45 --- _ctypes.c 2 Feb 2006 20:38:22 -0000 1.226.2.46 *************** *** 2551,2556 **** char *name = NULL; PyObject *paramflags = NULL; ! GUID *iid; ! int iid_len; if (!PyArg_ParseTuple(args, "is|Oz#", &index, &name, ¶mflags, &iid, &iid_len)) --- 2551,2556 ---- char *name = NULL; PyObject *paramflags = NULL; ! GUID *iid = NULL; ! int iid_len = 0; if (!PyArg_ParseTuple(args, "is|Oz#", &index, &name, ¶mflags, &iid, &iid_len)) |