ctypes-commit Mailing List for ctypes (Page 85)
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...> - 2004-10-28 17:45:48
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8120 Modified Files: __init__.py Log Message: Renamed get_string into string_at, and get_wstring into wstring_at. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** __init__.py 27 Oct 2004 20:04:21 -0000 1.45 --- __init__.py 28 Oct 2004 17:45:37 -0000 1.46 *************** *** 247,251 **** raise TypeError, init ! from _ctypes import get_wstring POINTER(c_char).from_param = c_char_p.from_param #_SimpleCData.c_char_p_from_param --- 247,251 ---- raise TypeError, init ! from _ctypes import wstring_at POINTER(c_char).from_param = c_char_p.from_param #_SimpleCData.c_char_p_from_param *************** *** 380,382 **** # functions ! from _ctypes import memmove, memset, get_string, cast --- 380,382 ---- # functions ! from _ctypes import memmove, memset, string_at, cast |
From: Thomas H. <th...@us...> - 2004-10-28 17:45:44
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8040 Modified Files: ChangeLog ANNOUNCE Log Message: Renamed get_string into string_at, and get_wstring into wstring_at. Index: ANNOUNCE =================================================================== RCS file: /cvsroot/ctypes/ctypes/ANNOUNCE,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** ANNOUNCE 16 Sep 2004 14:34:05 -0000 1.16 --- ANNOUNCE 28 Oct 2004 17:45:15 -0000 1.17 *************** *** 1,4 **** ! ctypes 0.9.1 released - Sept 14, 2004 ! ===================================== Overview --- 1,4 ---- ! ctypes 0.9.2 released - Oct 28, 2004 ! ==================================== Overview *************** *** 13,19 **** callback functions in pure Python. ! ctypes runs on Windows, MacOS X, Linux, Solaris, FreeBSD. It may ! also run on other systems, provided that libffi supports this ! platform. On windows, ctypes contains a ctypes.com package which allows to --- 13,19 ---- callback functions in pure Python. ! ctypes runs on Windows, MacOS X, Linux, Solaris, FreeBSD, OpenBSD. ! It may also run on other systems, provided that libffi supports ! this platform. On windows, ctypes contains a ctypes.com package which allows to *************** *** 21,119 **** ! Changes in 0.9.1 ! ! ctypes 0.9.1 should be fully compatible again with Gary Bishop's ! readline module which is also used by IPython. ! ! ctypes changes ! ! The internal conversions that ctypes does between unicode and ! strings can now use a specified encoding and error handling. A ! set_conversion_mode() function allows to set them, it returns the ! previous values. The inital values are ('mbcs', 'ignore') on ! Windows, and ('ascii', 'strict') on other systems. ! ! When internal processing of an argument for a function call fails, ! the new ctypes.ArgumentError is raised. ! ! CDLL and its subclasses now accept an optional second handle ! parameter. If this is supplied, it is used instead of calling ! LoadLibrary() or dlopen() to get one. ! ! Sometimes objects have been freed too early when calling functions ! where argtypes have been set. ! ! Fixed the create_unicode_buffer function - it was returning c_char ! arrays instead of c_wchar arrays. ! ! Both create_string_buffer and create_unicode_buffer can now be ! called with string and unicode instances, they will do the needed ! conversions themselves. ! ! ctypes now allows calling Python C api functions. The 'pythonapi' ! symbol should be used to access these functions, this will ! automatically use the correct calling convention and exception ! handling. The 'py_object' type is the ctypes variant of 'PyObject *'. ! This feature should also work if you are using a static python ! build. ! ! It is now possible to call cdecl functions with more arguments ! than the length of the argtypes sequence specifies - this allows ! to provide functions like sprintf() with a proper prototype. ! ! It is now possible to create strings or unicode strings if you ! have the integer address by calling c_char_p(address) or ! c_wchar_p(address). Integers can also be assigned to structure ! fields of type c_char_p and c_wchar_p. ! ! c_char_p and c_wchar_p both accept strings and unicode strings - ! if needed they are encoded or decoded using 'strict' error ! handling. ! ! The _ctypes.call_function function, although private and ! deprecated, has been put back in - it is used by Gary Bishop's ! readline module. ! Array and pointer instances now support slicing, for pointers only ! getslice is implemented (setslice is too dangerous, probably). ! Slices are represented as lists of the elements, except ! for character and unicode character pointer and arrays, where ! strings resp. unicode strings are used instead. ! On windows, the include files were missing from the source ! distribution. ! The alignment function was not exported by the ctypes module. It ! returns the alignment requirements in bytes of a type or instance. ! ctypes.com changes ! Applied a patch from Bruce Dodson which fixes an infinite loop in ! readtlb.py if a typelib references types defined in another ! typelib. readtlb still generates bad code for such cases, but the ! results could be edited by hand if the dependencies can be sorted ! out. ! ctypes now caches the types that WINFUNCTYPE and CFUNCTYPE ! creates, to avoid unneeeded creation of classes. This ! makes importing files containing a lot of COM interfaces (like the ! ones that the readtlb tool generates) a lot (10 x) faster. ! COM servers now print a short usage message when they are run ! without the /regserver or /unregserver flag. ! VARIANT does now handle the COM DATE type (VT_DATE) as Python ! datetime. - VARIANT now handles integers and longs correctly - if longs are - too large they are stored as doubles (VT_R8). Integers are now - stored as VT_I4 instead of VT_INT. Detailed changelogs are in CVS: ! <http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/ChangeLog?rev=HEAD> ! <http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/win32/com/ChangeLog?rev=HEAD> --- 21,62 ---- ! Changes in 0.9.2 ! Fixed several bugs and memory leaks. ! ctypes is now tested on Windows, Linux (x86 and x86_64), OpenBSD ! and Mac OS X. ! Implemented some helper functions: memmove, memset, string_at, wstring_at. ! The former act as their C library counterpart, the latter two allow ! to read a zero-terminated (wide) strings at a certain address. + Implemented a cast(cobj, ctype) function, which creates a new object + of the specified ctype from an existing object. ! ctypes now explicitely allocates executable memory for the callbacks ! it creates, this makes it work correctly on platforms where ! executing data is normally forbidden (OpenBSD, Win XP SP2 on AMD 64). ! Fixed the unicode handling on non-windows platforms. ! Bit fields in structures and unions are now implemented. ! For a bit field, one would specify the width in bits as the third ! part in the _fields_ list like this: ! class BitFieldSample(Structure): ! _fields_ = [("anInt", c_int), ! ("aBitField", c_int, 3)] ! POINTER(None) now returns c_void_p. This change was made for easier ! code generation, and makes sense since 'None' is the ctypes way to ! spell 'void'. Detailed changelogs are in CVS: ! <http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/ChangeLog?rev=HEAD> ! <http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/win32/com/ChangeLog?rev=HEAD> Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.67 retrieving revision 1.68 diff -C2 -d -r1.67 -r1.68 *** ChangeLog 15 Oct 2004 08:23:18 -0000 1.67 --- ChangeLog 28 Oct 2004 17:45:14 -0000 1.68 *************** *** 1,4 **** --- 1,26 ---- + 2004-10-28 Thomas Heller <th...@py...> + + * Renamed the functions: get_string -> string_at, + get_wstring -> wstring_at + + 2004-10-20 Thomas Heller <th...@py...> + + * Cycle GC support added for the PointerType_Type metaclass. + This makes the test_leaks unittests work. + Reverted the changes for lazy structures again. + + * Remove CFuncPtrType_from_param again. Later. + + 2004-10-19 Thomas Heller <th...@py...> + + * unittests\test_cfuncs.py: Fixed the test to work on OS X. The + problem probably was that OS X loads several different instances + of the _ctypes_test shared library. + 2004-10-15 Thomas Heller <th...@py...> + * Implemented memmove, memset and get_string functions. They will operate + on any type of argument, so they should be used carefully. + * Reinstalled the magic _abstract_ attribute for Structure and Union types. If this attribute is defined, the _fields_ attribute |
From: Thomas H. <th...@us...> - 2004-10-28 17:42:30
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7247 Modified Files: test_memfunctions.py Log Message: Fix the test when unicode not available. Index: test_memfunctions.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_memfunctions.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test_memfunctions.py 27 Oct 2004 20:00:20 -0000 1.4 --- test_memfunctions.py 28 Oct 2004 17:42:19 -0000 1.5 *************** *** 9,15 **** self.failUnlessEqual(a.value, "Hello, World") ! self.failUnlessEqual(get_string(result), "Hello, World") ! self.failUnlessEqual(get_string(result, 5), "Hello") ! self.failUnlessEqual(get_string(result, 16), "Hello, World\0\0\0\0") def test_memset(self): --- 9,15 ---- 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): *************** *** 17,22 **** result = memset(a, ord('x'), 16) ! self.failUnlessEqual(get_string(result), "xxxxxxxxxxxxxxxx") ! self.failUnlessEqual(get_string(a), "xxxxxxxxxxxxxxxx") self.failUnlessEqual(a.value, "xxxxxxxxxxxxxxxx") --- 17,22 ---- result = memset(a, ord('x'), 16) ! self.failUnlessEqual(string_at(result), "xxxxxxxxxxxxxxxx") ! self.failUnlessEqual(string_at(a), "xxxxxxxxxxxxxxxx") self.failUnlessEqual(a.value, "xxxxxxxxxxxxxxxx") *************** *** 27,39 **** [97, 98, 99, 100, 101, 102, 0]) ! def test_get_wstring(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") ! self.failUnlessEqual(get_wstring(a), "Hello, World") ! self.failUnlessEqual(get_wstring(a, 5), "Hello") ! self.failUnlessEqual(get_wstring(a, 16), "Hello, World\0\0\0\0") if __name__ == "__main__": --- 27,44 ---- [97, 98, 99, 100, 101, 102, 0]) ! try: ! create_unicode_buffer ! except NameError: ! pass ! else: ! 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") ! 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...> - 2004-10-27 20:04:32
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1308 Modified Files: __init__.py Log Message: Export _ctypes' get_wstring function. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** __init__.py 25 Oct 2004 10:11:16 -0000 1.44 --- __init__.py 27 Oct 2004 20:04:21 -0000 1.45 *************** *** 246,249 **** --- 246,251 ---- return buf raise TypeError, init + + from _ctypes import get_wstring POINTER(c_char).from_param = c_char_p.from_param #_SimpleCData.c_char_p_from_param |
From: Thomas H. <th...@us...> - 2004-10-27 20:00:29
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv497 Modified Files: test_memfunctions.py Log Message: Test the get_wstring function. Index: test_memfunctions.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_memfunctions.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_memfunctions.py 25 Oct 2004 10:09:56 -0000 1.3 --- test_memfunctions.py 27 Oct 2004 20:00:20 -0000 1.4 *************** *** 27,30 **** --- 27,40 ---- [97, 98, 99, 100, 101, 102, 0]) + def test_get_wstring(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") + + self.failUnlessEqual(get_wstring(a), "Hello, World") + self.failUnlessEqual(get_wstring(a, 5), "Hello") + self.failUnlessEqual(get_wstring(a, 16), "Hello, World\0\0\0\0") + if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2004-10-27 19:59:12
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32600 Modified Files: callproc.c Log Message: Refactor some code, and implement a get_wstring function. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.112 retrieving revision 1.113 diff -C2 -d -r1.112 -r1.113 *** callproc.c 18 Oct 2004 08:07:05 -0000 1.112 --- callproc.c 27 Oct 2004 19:58:56 -0000 1.113 *************** *** 768,771 **** --- 768,772 ---- Is there another way? */ + PyObject *retval; char c; short s; *************** *** 777,794 **** case 1: c = (char)result->value.l; ! return dict->getfunc(&c, dict->size); case SIZEOF_SHORT: s = (short)result->value.l; ! return dict->getfunc(&s, dict->size); case SIZEOF_INT: i = (int)result->value.l; ! return dict->getfunc(&i, dict->size); #if (SIZEOF_LONG != SIZEOF_INT) case SIZEOF_LONG: l = (long)result->value.l; ! return dict->getfunc(&l, dict->size); #endif } ! return dict->getfunc(&result->value, dict->size); } if (PyCallable_Check(restype)) --- 778,802 ---- case 1: c = (char)result->value.l; ! retval = dict->getfunc(&c, dict->size); ! break; case SIZEOF_SHORT: s = (short)result->value.l; ! retval = dict->getfunc(&s, dict->size); ! break; case SIZEOF_INT: i = (int)result->value.l; ! retval = dict->getfunc(&i, dict->size); ! break; #if (SIZEOF_LONG != SIZEOF_INT) case SIZEOF_LONG: l = (long)result->value.l; ! retval = dict->getfunc(&l, dict->size); ! break; #endif + default: + retval = dict->getfunc(&result->value, dict->size); + break; } ! return retval; } if (PyCallable_Check(restype)) *************** *** 1382,1385 **** --- 1390,1421 ---- } + #ifdef CTYPES_UNICODE + static char get_wstring_doc[] = + "get_wstring(addr[, size]) -> unicode string\n\ + \n\ + Return the wide string at addr.\n"; + + static PyObject * + get_wstring(PyObject *self, PyObject *args) + { + PyObject *result = NULL; + PyObject *src; + struct argument a_arg; + int size; + + if (!PyArg_ParseTuple(args, "O|i", &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 = PyUnicode_FromWideChar(a_arg.value.p, wcslen(a_arg.value.p)); + else + result = PyUnicode_FromWideChar(a_arg.value.p, size); + Py_XDECREF(a_arg.keep); + return result; + } + #endif + PyMethodDef module_methods[] = { {"get_string", get_string, METH_VARARGS, get_string_doc}, *************** *** 1388,1391 **** --- 1424,1428 ---- {"cast", cast, METH_VARARGS, cast_doc}, #ifdef CTYPES_UNICODE + {"get_wstring", get_wstring, METH_VARARGS, get_wstring_doc}, {"set_conversion_mode", set_conversion_mode, METH_VARARGS, set_conversion_mode_doc}, #endif |
From: Thomas H. <th...@us...> - 2004-10-27 17:32:24
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27942 Modified Files: test_leaks.py Log Message: Uncomment work in progress. Index: test_leaks.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_leaks.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** test_leaks.py 27 Oct 2004 17:28:37 -0000 1.6 --- test_leaks.py 27 Oct 2004 17:32:16 -0000 1.7 *************** *** 85,96 **** self.fail("leaking objects") ! def test_dll_leak_1(self): ! dll = cdll.LoadLibrary("msvcrt.dll") ! ## dll = CDLL("msvcrt.dll") ! ## dll = cdll.msvcrt ! dll._inp.restype = c_byte ! del dll ! gc.collect() ! print gc.garbage if __name__ == "__main__": --- 85,96 ---- self.fail("leaking objects") ! ## def test_dll_leak_1(self): ! ## dll = cdll.LoadLibrary("msvcrt.dll") ! #### dll = CDLL("msvcrt.dll") ! #### dll = cdll.msvcrt ! ## dll._inp.restype = c_byte ! ## del dll ! ## gc.collect() ! ## print gc.garbage if __name__ == "__main__": |
From: Thomas H. <th...@us...> - 2004-10-27 17:28:45
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26739 Modified Files: test_leaks.py Log Message: Less noise in unittests. Index: test_leaks.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_leaks.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** test_leaks.py 20 Oct 2004 11:08:45 -0000 1.5 --- test_leaks.py 27 Oct 2004 17:28:37 -0000 1.6 *************** *** 15,21 **** ("br", POINT)] ! if not hasattr(sys, "gettotalrefcount"): ! print >> sys.stderr, "(can only test for refcount leaks in debug build!)" ! else: def test_no_cycles_refcount(self): --- 15,19 ---- ("br", POINT)] ! if hasattr(sys, "gettotalrefcount"): def test_no_cycles_refcount(self): *************** *** 87,90 **** --- 85,97 ---- self.fail("leaking objects") + def test_dll_leak_1(self): + dll = cdll.LoadLibrary("msvcrt.dll") + ## dll = CDLL("msvcrt.dll") + ## dll = cdll.msvcrt + dll._inp.restype = c_byte + del dll + gc.collect() + print gc.garbage + if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2004-10-27 17:27:39
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26361 Modified Files: cfield.c Log Message: One letter fix to make the bitfield tests work on OS X: 1L -> 1LL Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** cfield.c 22 Oct 2004 07:09:58 -0000 1.65 --- cfield.c 27 Oct 2004 17:27:30 -0000 1.66 *************** *** 386,390 **** # define BIT_MASK(size) ((1 << NUM_BITS(size))-1) #else ! # define BIT_MASK(size) ((1L << NUM_BITS(size))-1) #endif --- 386,390 ---- # define BIT_MASK(size) ((1 << NUM_BITS(size))-1) #else ! # define BIT_MASK(size) ((1LL << NUM_BITS(size))-1) #endif |
From: Thomas H. <th...@us...> - 2004-10-25 10:21:58
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1334 Modified Files: _ctypes_test.c Log Message: The callback must return PY_LONG_LONG. Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** _ctypes_test.c 21 Oct 2004 15:34:04 -0000 1.35 --- _ctypes_test.c 25 Oct 2004 10:21:48 -0000 1.36 *************** *** 144,148 **** } ! EXPORT(PY_LONG_LONG) _testfunc_callback_q_qf(PY_LONG_LONG value, int (*func)(PY_LONG_LONG)) { PY_LONG_LONG sum = 0; --- 144,149 ---- } ! EXPORT(PY_LONG_LONG) _testfunc_callback_q_qf(PY_LONG_LONG value, ! PY_LONG_LONG (*func)(PY_LONG_LONG)) { PY_LONG_LONG sum = 0; |
From: Thomas H. <th...@us...> - 2004-10-25 10:11:25
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31752 Modified Files: __init__.py Log Message: Export _ctypes' cast function. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** __init__.py 20 Oct 2004 08:12:58 -0000 1.43 --- __init__.py 25 Oct 2004 10:11:16 -0000 1.44 *************** *** 246,250 **** return buf raise TypeError, init - POINTER(c_char).from_param = c_char_p.from_param #_SimpleCData.c_char_p_from_param --- 246,249 ---- *************** *** 379,381 **** # functions ! from _ctypes import memmove, memset, get_string --- 378,380 ---- # functions ! from _ctypes import memmove, memset, get_string, cast |
From: Thomas H. <th...@us...> - 2004-10-25 10:10:05
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31378 Modified Files: test_memfunctions.py Log Message: Test the cast function. Index: test_memfunctions.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_memfunctions.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_memfunctions.py 15 Oct 2004 16:55:50 -0000 1.2 --- test_memfunctions.py 25 Oct 2004 10:09:56 -0000 1.3 *************** *** 21,24 **** --- 21,30 ---- self.failUnlessEqual(a.value, "xxxxxxxxxxxxxxxx") + def test_cast(self): + a = (c_ubyte * 32)(*map(ord, "abcdef")) + self.failUnlessEqual(cast(a, c_char_p).value, "abcdef") + self.failUnlessEqual(cast(a, POINTER(c_byte))[:7], + [97, 98, 99, 100, 101, 102, 0]) + if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2004-10-25 07:56:45
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3813 Modified Files: malloc_closure.c Log Message: Save a few bytes by making ITEM a union instead of a structure. Index: malloc_closure.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/malloc_closure.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** malloc_closure.c 24 Oct 2004 18:16:42 -0000 1.9 --- malloc_closure.c 25 Oct 2004 07:56:35 -0000 1.10 *************** *** 24,30 **** #endif ! typedef struct _tagITEM { ffi_closure closure; ! struct _tagITEM *next; } ITEM; --- 24,30 ---- #endif ! typedef union _tagITEM { ffi_closure closure; ! union _tagITEM *next; } ITEM; *************** *** 46,50 **** #else if (!_pagesize) { - // _pagesize = sysconf(_SC_PAGESIZE); _pagesize = getpagesize(); } --- 46,49 ---- |
From: Thomas H. <th...@us...> - 2004-10-24 18:16:52
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9712 Modified Files: malloc_closure.c Log Message: OS X doesn't have sysconf. Index: malloc_closure.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/malloc_closure.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** malloc_closure.c 21 Oct 2004 19:59:25 -0000 1.8 --- malloc_closure.c 24 Oct 2004 18:16:42 -0000 1.9 *************** *** 46,50 **** #else if (!_pagesize) { ! _pagesize = sysconf(_SC_PAGESIZE); } #endif --- 46,51 ---- #else if (!_pagesize) { ! // _pagesize = sysconf(_SC_PAGESIZE); ! _pagesize = getpagesize(); } #endif |
From: Thomas H. <th...@us...> - 2004-10-22 19:34:00
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28916 Modified Files: test_functions.py Log Message: Make it somewhat simpler. Index: test_functions.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_functions.py,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** test_functions.py 14 Oct 2004 13:16:13 -0000 1.38 --- test_functions.py 22 Oct 2004 19:33:52 -0000 1.39 *************** *** 15,28 **** WINFUNCTYPE = CFUNCTYPE ! def find_test_dll(): ! import _ctypes_test ! return _ctypes_test.__file__ class FunctionTestCase(unittest.TestCase): - def setUp(self): - global dll - dll = CDLL(find_test_dll()) - def test_mro(self): # in Python 2.3, this raises TypeError: MRO conflict among bases classes, --- 15,23 ---- WINFUNCTYPE = CFUNCTYPE ! import _ctypes_test ! dll = CDLL(_ctypes_test.__file__) class FunctionTestCase(unittest.TestCase): def test_mro(self): # in Python 2.3, this raises TypeError: MRO conflict among bases classes, *************** *** 162,165 **** --- 157,161 ---- def test_stringresult(self): f = dll._testfunc_p_p + f.argtypes = None f.restype = c_char_p result = f("123") |
From: Thomas H. <th...@us...> - 2004-10-22 08:07:31
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5604 Removed Files: oleregenumformatetc.py Log Message: This file was checked in by accident. --- oleregenumformatetc.py DELETED --- |
From: Thomas H. <th...@us...> - 2004-10-22 07:27:28
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30601 Modified Files: test_structures.py Log Message: Revert the last traces from StructUnion_setattro. Index: test_structures.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_structures.py,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** test_structures.py 28 Sep 2004 14:00:45 -0000 1.24 --- test_structures.py 22 Oct 2004 07:27:18 -0000 1.25 *************** *** 27,108 **** [("a", c_int)]) - def test_lazy_subclass(self): - class X(Structure): - pass - - class Y(X): - pass - - class Z(X): - pass - - self.assertRaises(TypeError, sizeof, X) - self.assertRaises(TypeError, sizeof, Y) - self.assertRaises(TypeError, sizeof, Z) - - X._pack_ = 0 - Y._pack_ = 0 - Z._pack_ = 0 - - X._fields_ = [("a", c_int)] - Y._fields_ = X._fields_ + [("b", c_int)] - Z._fields_ = X._fields_ - - self.failUnlessEqual(sizeof(X), sizeof(c_int)) - self.failUnlessEqual(sizeof(Y), sizeof(c_int)*2) - self.failUnlessEqual(sizeof(Z), sizeof(c_int)) - - self.failUnlessEqual(X._fields_, - [("a", c_int)]) - - self.failUnlessEqual(Y._fields_, - [("a", c_int), ("b", c_int)]) - - self.failUnlessEqual(Z._fields_, - [("a", c_int)]) - - self.assertRaises(AttributeError, setattr, X, "_pack_", 32) - self.assertRaises(AttributeError, setattr, Y, "_pack_", 32) - self.assertRaises(AttributeError, setattr, Z, "_pack_", 32) - - def test_lazy_union(self): - class X(Union): - pass - - class Y(X): - pass - - class Z(X): - pass - - self.assertRaises(TypeError, sizeof, X) - self.assertRaises(TypeError, sizeof, Y) - self.assertRaises(TypeError, sizeof, Z) - - X._pack_ = 0 - Y._pack_ = 0 - Z._pack_ = 0 - - X._fields_ = [("a", c_int)] - Y._fields_ = X._fields_ + [("b", c_int)] - Z._fields_ = X._fields_ - - self.failUnlessEqual(sizeof(X), sizeof(c_int)) - self.failUnlessEqual(sizeof(Y), sizeof(c_int)) - self.failUnlessEqual(sizeof(Z), sizeof(c_int)) - - self.failUnlessEqual(X._fields_, - [("a", c_int)]) - - self.failUnlessEqual(Y._fields_, - [("a", c_int), ("b", c_int)]) - - self.failUnlessEqual(Z._fields_, - [("a", c_int)]) - - self.assertRaises(AttributeError, setattr, X, "_pack_", 32) - self.assertRaises(AttributeError, setattr, Y, "_pack_", 32) - self.assertRaises(AttributeError, setattr, Z, "_pack_", 32) - class StructureTestCase(unittest.TestCase): formats = {"c": c_char, --- 27,30 ---- *************** *** 332,336 **** - # no longer true: ## def test_subclass_creation(self): ## meta = type(Structure) --- 254,257 ---- *************** *** 343,350 **** def test_abstract_class(self): class X(Structure): ! pass # try 'X()' cls, msg = self.get_except(eval, "X()", locals()) ! self.failUnlessEqual((cls, msg), (TypeError, "Cannot create instance: no _fields_")) def test_methods(self): --- 264,271 ---- def test_abstract_class(self): class X(Structure): ! _abstract_ = "something" # try 'X()' cls, msg = self.get_except(eval, "X()", locals()) ! self.failUnlessEqual((cls, msg), (TypeError, "abstract class")) def test_methods(self): |
From: Thomas H. <th...@us...> - 2004-10-22 07:22:10
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29482 Modified Files: _ctypes.c Log Message: Revert the last traces from StructUnion_setattro. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.176 retrieving revision 1.177 diff -C2 -d -r1.176 -r1.177 *** _ctypes.c 20 Oct 2004 16:53:19 -0000 1.176 --- _ctypes.c 22 Oct 2004 07:22:00 -0000 1.177 *************** *** 311,366 **** static int - StructUnionType_setattro(PyTypeObject *self, PyObject *name, PyObject *value, - int isStruct) - { - /* keep this for bw compatibility */ - if (PyDict_GetItemString(self->tp_dict, "_abstract_")) - return PyObject_GenericSetAttr((PyObject *)self, name, value); - - if (PyString_Check(name) - && 0 == strcmp("_fields_", PyString_AS_STRING(name))) { - PyObject *dict; - if (PyType_stgdict((PyObject *)self)) { - PyErr_SetString(PyExc_AttributeError, - "_fields_ attribute cannot be overwritten"); - return -1; - } - dict = StgDict_FromDict(value, self->tp_dict, isStruct); - if (dict == NULL) - return -1; - - /* replace the class dict by our updated stgdict, which holds info - about storage requirements of the instances */ - if (-1 == PyDict_Update(dict, self->tp_dict)) { - Py_DECREF(dict); - return -1; - } - Py_DECREF(self->tp_dict); - self->tp_dict = dict; - } - if (PyString_Check(name) - && 0 == strcmp("_pack_", PyString_AS_STRING(name))) { - if (PyType_stgdict((PyObject *)self)) { - PyErr_SetString(PyExc_AttributeError, - "_pack_ attribute cannot be overwritten"); - return -1; - } - } - return PyObject_GenericSetAttr((PyObject *)self, name, value); - } - - static int - StructType_setattro(PyTypeObject *self, PyObject *name, PyObject *value) - { - return StructUnionType_setattro(self, name, value, 1); - } - - static int - UnionType_setattro(PyTypeObject *self, PyObject *name, PyObject *value) - { - return StructUnionType_setattro(self, name, value, 0); - } - - static int CDataType_clear(PyTypeObject *self) { --- 311,314 ---- *************** *** 399,403 **** 0, /* tp_str */ 0, /* tp_getattro */ ! (setattrofunc)StructType_setattro, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ --- 347,351 ---- 0, /* tp_str */ 0, /* tp_getattro */ ! 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ *************** *** 442,446 **** 0, /* tp_str */ 0, /* tp_getattro */ ! (setattrofunc)UnionType_setattro, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ --- 390,394 ---- 0, /* tp_str */ 0, /* tp_getattro */ ! 0, /* tp_setattro */ 0, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ *************** *** 2766,2780 **** }; - static PyObject * - StructUnion_new(PyTypeObject *type, PyObject *args, PyObject *kw) - { - if (!PyType_stgdict((PyObject *)type)) { - PyErr_SetString(PyExc_TypeError, - "Cannot create instance: no _fields_"); - return NULL; - } - return GenericCData_new(type, args, kw); - } - static PyTypeObject Struct_Type = { PyObject_HEAD_INIT(NULL) --- 2714,2717 ---- *************** *** 2816,2820 **** Struct_init, /* tp_init */ 0, /* tp_alloc */ ! StructUnion_new, /* tp_new */ 0, /* tp_free */ }; --- 2753,2757 ---- Struct_init, /* tp_init */ 0, /* tp_alloc */ ! GenericCData_new, /* tp_new */ 0, /* tp_free */ }; *************** *** 2859,2863 **** Struct_init, /* tp_init */ 0, /* tp_alloc */ ! StructUnion_new, /* tp_new */ 0, /* tp_free */ }; --- 2796,2800 ---- Struct_init, /* tp_init */ 0, /* tp_alloc */ ! GenericCData_new, /* tp_new */ 0, /* tp_free */ }; |
From: Thomas H. <th...@us...> - 2004-10-22 07:10:16
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27270 Modified Files: cfield.c Log Message: The processor's endianness is now detected in the setup script, and passed to the compiler as IS_BUG_ENDIAN macro. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** cfield.c 19 Oct 2004 19:41:47 -0000 1.64 --- cfield.c 22 Oct 2004 07:09:58 -0000 1.65 *************** *** 20,32 **** } - static int - is_big_endian(void) - { - short word = 0x4321; - if ((*(char *)&word) != 0x21) - return 1; - return 0; - } - /* * Expects the size, index and offset for the current field in *psize and --- 20,23 ---- *************** *** 138,145 **** switch (fieldtype) { case NEW_BITFIELD: ! if (is_big_endian()) ! self->size = (bitsize << 16) + *pfield_size - *pbitofs - bitsize; ! else ! self->size = (bitsize << 16) + *pbitofs; *pbitofs = bitsize; /* fall through */ --- 129,137 ---- switch (fieldtype) { case NEW_BITFIELD: ! #ifdef IS_BIG_ENDIAN ! self->size = (bitsize << 16) + *pfield_size - *pbitofs - bitsize; ! #else ! self->size = (bitsize << 16) + *pbitofs; ! #endif *pbitofs = bitsize; /* fall through */ *************** *** 171,178 **** *pfield_size = dict->size * 8; ! if (is_big_endian()) ! self->size = (bitsize << 16) + *pfield_size - *pbitofs - bitsize; ! else ! self->size = (bitsize << 16) + *pbitofs; self->offset = *poffset - size; /* poffset is already updated for the NEXT field */ *pbitofs += bitsize; --- 163,171 ---- *pfield_size = dict->size * 8; ! #ifdef IS_BIG_ENDIAN ! self->size = (bitsize << 16) + *pfield_size - *pbitofs - bitsize; ! #else ! self->size = (bitsize << 16) + *pbitofs; ! #endif self->offset = *poffset - size; /* poffset is already updated for the NEXT field */ *pbitofs += bitsize; *************** *** 180,187 **** case CONT_BITFIELD: ! if (is_big_endian()) ! self->size = (bitsize << 16) + *pfield_size - *pbitofs - bitsize; ! else ! self->size = (bitsize << 16) + *pbitofs; self->offset = *poffset - size; /* poffset is already updated for the NEXT field */ *pbitofs += bitsize; --- 173,181 ---- case CONT_BITFIELD: ! #ifdef IS_BIG_ENDIAN ! self->size = (bitsize << 16) + *pfield_size - *pbitofs - bitsize; ! #else ! self->size = (bitsize << 16) + *pbitofs; ! #endif self->offset = *poffset - size; /* poffset is already updated for the NEXT field */ *pbitofs += bitsize; |
From: Thomas H. <th...@us...> - 2004-10-22 07:09:59
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27216 Modified Files: setup.py Log Message: The processor's endianness is now detected in the setup script, and passed to the compiler as IS_BUG_ENDIAN macro. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.109 retrieving revision 1.110 diff -C2 -d -r1.109 -r1.110 *** setup.py 21 Oct 2004 20:08:37 -0000 1.109 --- setup.py 22 Oct 2004 07:09:48 -0000 1.110 *************** *** 327,333 **** import struct, binascii if "12345678" == binascii.hexlify(struct.pack("i", 0x12345678)): ! kw["define_macros"] = [("ENDIAN", "BIG")] ! else: ! kw["define_macros"] = [("ENDIAN", "LITTLE")] # common header file --- 327,331 ---- import struct, binascii if "12345678" == binascii.hexlify(struct.pack("i", 0x12345678)): ! kw["define_macros"] = [("IS_BIG_ENDIAN", "1")] # common header file |
From: Thomas H. <th...@us...> - 2004-10-21 20:08:59
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21660 Modified Files: setup.py Log Message: Detect endianness in the setup script. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.108 retrieving revision 1.109 diff -C2 -d -r1.108 -r1.109 *** setup.py 21 Oct 2004 08:05:40 -0000 1.108 --- setup.py 21 Oct 2004 20:08:37 -0000 1.109 *************** *** 325,328 **** --- 325,334 ---- "source/malloc_closure.c"] + import struct, binascii + if "12345678" == binascii.hexlify(struct.pack("i", 0x12345678)): + kw["define_macros"] = [("ENDIAN", "BIG")] + else: + kw["define_macros"] = [("ENDIAN", "LITTLE")] + # common header file kw["depends"] = ["source/ctypes.h"] |
From: Thomas H. <th...@us...> - 2004-10-21 19:59:49
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19813 Modified Files: malloc_closure.c Log Message: Remove the todo comment, since the work is now done. Remove the small docs that are no longer correct. Index: malloc_closure.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/malloc_closure.c,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** malloc_closure.c 21 Oct 2004 18:44:34 -0000 1.7 --- malloc_closure.c 21 Oct 2004 19:59:25 -0000 1.8 *************** *** 1,24 **** - /* - * Memory blocks with executable permission are allocated of size BLOCKSIZE. - * They are chained together, and the start of the chain is the global 'start' - * pointer. - * - * Each block has an array of ffi_closure in it. The ffi_closure.cif field is - * used to mark an entry used or free, and the block has a 'used' field which - * counts the used entries. - * - * MallocClosure() returns a pointer to an ffi_closure entry, allocating a new - * block when needed. - * - * FreeClosure(ffi_closure*) marks the ffi_closure entry unused again. - * If a memory block has only unused entries, it is freed again - unless it is - * the last one in use. - */ - - /* - * The functions would probably be much faster if we would maintain a linked - * list of free and used entries - this would avoid the linear searches. - */ - #include <Python.h> #include <ffi.h> --- 1,2 ---- |
From: Thomas H. <th...@us...> - 2004-10-21 18:44:44
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6341 Modified Files: malloc_closure.c Log Message: Simpler and faster approach. Index: malloc_closure.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/malloc_closure.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** malloc_closure.c 21 Oct 2004 15:33:23 -0000 1.6 --- malloc_closure.c 21 Oct 2004 18:44:34 -0000 1.7 *************** *** 25,41 **** #include "ctypes.h" ! /* BLOCKSIZE can be adjusted. Larger blocksize will make MallocClosure() and ! FreeClosure() somewhat slower, but allocate less blocks from the system. ! It may be that some systems have a limit of how many mmap'd blocks can be ! open. ! ! sizeof(ffi_closure) typically is: ! ! Windows: 28 bytes ! Linux x86, OpenBSD x86: 24 bytes ! Linux x86_64: 48 bytes */ ! #define BLOCKSIZE _pagesize * 4 /* #define MALLOC_CLOSURE_DEBUG */ /* enable for some debugging output */ --- 25,34 ---- #include "ctypes.h" ! /* BLOCKSIZE can be adjusted. Larger blocksize will take a larger memory ! overhead, but allocate less blocks from the system. It may be that some ! systems have a limit of how many mmap'd blocks can be open. */ ! #define BLOCKSIZE _pagesize /* #define MALLOC_CLOSURE_DEBUG */ /* enable for some debugging output */ *************** *** 53,70 **** #endif ! typedef struct _tagblock { ! struct _tagblock *next; ! struct _tagblock *prev; ! int count; ! int used; ! ffi_closure closure[0]; ! } BLOCK; ! static BLOCK *start; /* points to the list of allocated blocks */ ! static unsigned int _pagesize; /* the system's pagesize */ ! static BLOCK *allocate_block(void) { ! BLOCK *block; #ifdef MS_WIN32 if (!_pagesize) { --- 46,63 ---- #endif ! typedef struct _tagITEM { ! ffi_closure closure; ! struct _tagITEM *next; ! } ITEM; ! static ITEM *free_list; ! int _pagesize; ! static void more_core(void) { ! ITEM *item; ! int count, i; ! ! /* determine the pagesize */ #ifdef MS_WIN32 if (!_pagesize) { *************** *** 73,204 **** _pagesize = systeminfo.dwPageSize; } - - block = (BLOCK *)VirtualAlloc(NULL, - BLOCKSIZE, - MEM_COMMIT, - PAGE_EXECUTE_READWRITE); - if (block == NULL) - return NULL; #else if (!_pagesize) { _pagesize = sysconf(_SC_PAGESIZE); } ! block = (BLOCK *)mmap(NULL, ! BLOCKSIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); ! if (block == (void *)MAP_FAILED) ! return NULL; ! memset(block, 0, BLOCKSIZE); #endif - block->count = (BLOCKSIZE - sizeof(block)) / sizeof(ffi_closure); #ifdef MALLOC_CLOSURE_DEBUG ! printf("One BLOCK has %d closures of %d bytes each\n", ! block->count, sizeof(ffi_closure)); ! block->count = 1; ! printf("ALLOCATED block %p\n", block); ! #endif ! return block; ! } ! ! static void free_block(BLOCK *block) ! { ! #ifdef MS_WIN32 ! if (0 == VirtualFree(block, 0, MEM_RELEASE)) ! Py_FatalError("ctypes: executable memory head corrupted"); ! #else ! if (-1 == munmap((void *)block, BLOCKSIZE)) ! Py_FatalError("ctypes: executable memory head corrupted"); #endif } /******************************************************************/ void FreeClosure(void *p) { ! BLOCK *block = start; ! ffi_closure *pcl = (ffi_closure *)p; ! int i; ! ! while (block) { ! /* We could calculate the entry by pointer arithmetic, ! to avoid a linear search. ! */ ! for (i = 0; i < block->count; ++i) { ! if (&block->closure[i] == pcl) { ! block->closure[i].cif = NULL; ! --block->used; ! goto done; ! } ! } ! block = block->next; ! } ! Py_FatalError("ctypes: closure not found in any block"); ! ! done: ! if (block->used == 0) { ! if (block == start && block->next == NULL) { ! /* don't free the last block */ ! #ifdef MALLOC_CLOSURE_DEBUG ! printf("Don't free the very last block %p\n", block); ! #endif ! return; ! } ! /* unlink the current block from the chain */ ! if (block->next) ! block->next->prev = block->prev; ! if (block->prev) { ! block->prev->next = block->next; ! } else { ! start = block->next; ! start->prev = NULL; ! } ! ! /* now, the block can be freed */ ! free_block(block); ! #ifdef MALLOC_CLOSURE_DEBUG ! printf("FREEING block %p\n", block); ! #endif ! } } void *MallocClosure(void) { ! BLOCK *block = start; ! int i; ! ! if (start == NULL) ! block = start = allocate_block(); ! ! while(block) { ! if (block->used < block->count) { ! /* This block has a free entry */ ! for (i = 0; i < block->count; ++i) { ! if (block->closure[i].cif == NULL) { ! block->closure[i].cif = (ffi_cif *)-1; ! ++block->used; ! return &block->closure[i]; ! } ! } ! /* oops, where is it? */ ! Py_FatalError("ctypes: use count on block is wrong"); ! } ! if (block->next) ! /* try the next block, if there is one */ ! block = block->next; ! else { ! /* need a fresh block */ ! BLOCK *new_block = allocate_block(); ! if (new_block == NULL) ! return NULL; ! /* insert into chain */ ! new_block->prev = block; ! block->next = new_block; ! block = new_block; ! } ! } ! return NULL; } --- 66,129 ---- _pagesize = systeminfo.dwPageSize; } #else if (!_pagesize) { _pagesize = sysconf(_SC_PAGESIZE); } ! #endif ! ! /* calculate the number of nodes to allocate */ ! count = BLOCKSIZE / sizeof(ITEM); ! ! /* allocate a memory block */ ! #ifdef MS_WIN32 ! item = (ITEM *)VirtualAlloc(NULL, ! count * sizeof(ITEM), ! MEM_COMMIT, ! PAGE_EXECUTE_READWRITE); ! if (item == NULL) ! return; ! #else ! item = (ITEM *)mmap(NULL, ! count * sizeof(ITEM), PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); ! if (item == (void *)MAP_FAILED) ! return; #endif #ifdef MALLOC_CLOSURE_DEBUG ! printf("block at %p allocated (%d bytes), %d ITEMs\n", ! item, count * sizeof(ITEM), count); #endif + /* put them into the free list */ + for (i = 0; i < count; ++i) { + item->next = free_list; + free_list = item; + ++item; + } } /******************************************************************/ + /* put the item back into the free list */ void FreeClosure(void *p) { ! ITEM *item = (ITEM *)p; ! item->next = free_list; ! free_list = item; } + /* return one item from the free list, allocating more if needed */ void *MallocClosure(void) { ! ITEM *item; ! if (!free_list) ! more_core(); ! if (!free_list) ! return NULL; ! item = free_list; ! free_list = item->next; ! return item; } |
From: Thomas H. <th...@us...> - 2004-10-21 15:38:43
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31116 Removed Files: test_lazy_struct.py Log Message: --- test_lazy_struct.py DELETED --- |
From: Thomas H. <th...@us...> - 2004-10-21 15:34:14
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30199 Modified Files: _ctypes_test.c Log Message: Don't rely on the _wcsdup function. Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** _ctypes_test.c 19 Oct 2004 09:08:53 -0000 1.34 --- _ctypes_test.c 21 Oct 2004 15:34:04 -0000 1.35 *************** *** 70,78 **** EXPORT(wchar_t *) my_wcsdup(wchar_t *src) { ! #ifdef MS_WIN32 ! return _wcsdup(src); ! #else ! return wcsdup(src); ! #endif } --- 70,79 ---- EXPORT(wchar_t *) my_wcsdup(wchar_t *src) { ! int len = wcslen(src); ! wchar_t *ptr = malloc((len + 1) * sizeof(wchar_t)); ! if (ptr == NULL) ! return NULL; ! memcpy(ptr, src, (len+1) * sizeof(wchar_t)); ! return ptr; } |