ctypes-commit Mailing List for ctypes (Page 88)
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-15 07:00:41
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31482 Modified Files: ctypes.h _ctypes.c Log Message: Provide replacements for Python's broken API functions PyUnicode_FromWideChar and PyUnicode_AsWideChar. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** ctypes.h 14 Oct 2004 14:42:04 -0000 1.54 --- ctypes.h 15 Oct 2004 07:00:21 -0000 1.55 *************** *** 290,293 **** --- 290,316 ---- #endif + /* Python's PyUnicode_*WideChar functions are broken ... */ + #ifdef Py_USING_UNICODE + + # undef PyUnicode_FromWideChar + # define PyUnicode_FromWideChar My_PyUnicode_FromWideChar + + # undef PyUnicode_AsWideChar + # define PyUnicode_AsWideChar My_PyUnicode_AsWideChar + + /* see comment in Python's Include/unicodeobject.h */ + # ifdef Py_UNICODE_WIDE + # define My_PyUnicode_FromWideChar My_PyUnicodeUCS4_FromWideChar + # define My_PyUnicode_AsWideChar My_PyUnicodeUCS4_AsWideChar + # else + # define My_PyUnicode_FromWideChar My_PyUnicodeUCS2_FromWideChar + # define My_PyUnicode_AsWideChar My_PyUnicodeUCS2_AsWideChar + # endif + + extern PyObject *My_PyUnicode_FromWideChar(const wchar_t *, int); + extern int My_PyUnicode_AsWideChar(PyUnicodeObject *, wchar_t *, int); + + #endif + /* Local Variables: Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.168 retrieving revision 1.169 diff -C2 -d -r1.168 -r1.169 *** _ctypes.c 14 Oct 2004 18:16:39 -0000 1.168 --- _ctypes.c 15 Oct 2004 07:00:21 -0000 1.169 *************** *** 3896,3899 **** --- 3896,3965 ---- init_callbacks_in_module(m); } + + /***************************************************************** + * replacements for broken Python api functions + */ + + #ifdef HAVE_WCHAR_H + + PyObject *My_PyUnicode_FromWideChar(register const wchar_t *w, + int size) + { + PyUnicodeObject *unicode; + + if (w == NULL) { + PyErr_BadInternalCall(); + return NULL; + } + + unicode = (PyUnicodeObject *)PyUnicode_FromUnicode(NULL, size); + if (!unicode) + return NULL; + + /* Copy the wchar_t data into the new object */ + #ifdef HAVE_USABLE_WCHAR_T + memcpy(unicode->str, w, size * sizeof(wchar_t)); + #else + { + register Py_UNICODE *u; + register int i; + u = PyUnicode_AS_UNICODE(unicode); + /* In Python, the following line has a one-off error */ + for (i = size; i > 0; i--) + *u++ = *w++; + } + #endif + + return (PyObject *)unicode; + } + + int My_PyUnicode_AsWideChar(PyUnicodeObject *unicode, + register wchar_t *w, + int size) + { + if (unicode == NULL) { + PyErr_BadInternalCall(); + return -1; + } + if (size > PyUnicode_GET_SIZE(unicode)) + size = PyUnicode_GET_SIZE(unicode); + #ifdef HAVE_USABLE_WCHAR_T + memcpy(w, unicode->str, size * sizeof(wchar_t)); + #else + { + register Py_UNICODE *u; + register int i; + u = PyUnicode_AS_UNICODE(unicode); + /* In Python, the following line has a one-off error */ + for (i = size; i > 0; i--) + *w++ = *u++; + } + #endif + + return size; + } + + #endif + /* Local Variables: |
From: Thomas H. <th...@us...> - 2004-10-14 18:23:21
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28929 Modified Files: test_leaks.py Log Message: Add some comments about the correctness of the tests. Index: test_leaks.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_leaks.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_leaks.py 14 Oct 2004 18:17:52 -0000 1.2 --- test_leaks.py 14 Oct 2004 18:23:11 -0000 1.3 *************** *** 32,35 **** --- 32,38 ---- def test_no_cycles_objcount(self): + # not correct - gc.get_objects() returns only thos objects + # that the garbage collector tracks. Correct would be to use + # sys.getobjects(), but this is only available in debug build. last_objcount = 0 for x in xrange(20): *************** *** 68,71 **** --- 71,77 ---- def test_cycles_objcount(self): + # not correct - gc.get_objects() returns only thos objects + # that the garbage collector tracks. Correct would be to use + # sys.getobjects(), but this is only available in debug build. last_objcount = 0 for x in xrange(5): |
From: Thomas H. <th...@us...> - 2004-10-14 18:18:04
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27842 Modified Files: test_leaks.py Log Message: When checking for leaks, we have to clear out any caches we have. Index: test_leaks.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_leaks.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_leaks.py 14 Oct 2004 13:18:30 -0000 1.1 --- test_leaks.py 14 Oct 2004 18:17:52 -0000 1.2 *************** *** 1,4 **** --- 1,5 ---- import unittest, sys, gc from ctypes import * + from ctypes import _pointer_type_cache class LeakTestCase(unittest.TestCase): *************** *** 48,53 **** class LIST(Structure): pass - LIST._fields_ = [("pnext", POINTER(LIST))] if hasattr(sys, "gettotalrefcount"): --- 49,55 ---- class LIST(Structure): pass LIST._fields_ = [("pnext", POINTER(LIST))] + del _pointer_type_cache[LIST] # XXX should this be a weakkeydict? + del LIST if hasattr(sys, "gettotalrefcount"): |
From: Thomas H. <th...@us...> - 2004-10-14 18:16:49
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27675 Modified Files: _ctypes.c Log Message: Fix a refcount leak in StructUnion_UpdatePointer_Type(). Implement cycle gc support in the metaclasses (!) StructType_Type and UnionType_Type. FIXME: Should probably be implemented in other metaclasses as well! Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.167 retrieving revision 1.168 diff -C2 -d -r1.167 -r1.168 *** _ctypes.c 14 Oct 2004 14:44:03 -0000 1.167 --- _ctypes.c 14 Oct 2004 18:16:39 -0000 1.168 *************** *** 317,324 **** { PyObject *ptr = PyDict_GetItem(PointerType_cache, self); ! if (ptr ! && PyType_Check(ptr) ! && (NULL == PointerType_set_type((PyTypeObject *)ptr, self))) return -1; return 0; } --- 317,327 ---- { PyObject *ptr = PyDict_GetItem(PointerType_cache, self); ! if (ptr && PyType_Check(ptr)) { ! PyObject *r; ! r = PointerType_set_type((PyTypeObject *)ptr, self); ! if (r == NULL) return -1; + Py_DECREF(r); + } return 0; } *************** *** 374,377 **** --- 377,398 ---- } + static int + CDataType_clear(PyTypeObject *self) + { + StgDictObject *dict = PyType_stgdict((PyObject *)self); + if (dict) + Py_CLEAR(dict->proto); + return PyType_Type.tp_clear((PyObject *)self); + } + + static int + CDataType_traverse(PyTypeObject *self, visitproc visit, void *arg) + { + StgDictObject *dict = PyType_stgdict((PyObject *)self); + if (dict) + Py_VISIT(dict->proto); + return PyType_Type.tp_traverse((PyObject *)self, visit, arg); + } + static PyTypeObject StructType_Type = { PyObject_HEAD_INIT(NULL) *************** *** 395,402 **** (setattrofunc)StructType_setattro, /* tp_setattro */ 0, /* tp_as_buffer */ ! Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ "metatype for the CData Objects", /* tp_doc */ ! 0, /* tp_traverse */ ! 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ --- 416,423 ---- (setattrofunc)StructType_setattro, /* tp_setattro */ 0, /* tp_as_buffer */ ! Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ "metatype for the CData Objects", /* tp_doc */ ! (traverseproc)CDataType_traverse, /* tp_traverse */ ! (inquiry)CDataType_clear, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ *************** *** 438,445 **** (setattrofunc)UnionType_setattro, /* tp_setattro */ 0, /* tp_as_buffer */ ! Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ "metatype for the CData Objects", /* tp_doc */ ! 0, /* tp_traverse */ ! 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ --- 459,466 ---- (setattrofunc)UnionType_setattro, /* tp_setattro */ 0, /* tp_as_buffer */ ! Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ "metatype for the CData Objects", /* tp_doc */ ! (traverseproc)CDataType_traverse, /* tp_traverse */ ! (inquiry)CDataType_clear, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ *************** *** 555,570 **** assert(dict); ! if (-1 == PointerType_SetProto(dict, type)) ! return NULL; ! old_type = PyDict_GetItemString((PyObject *)dict, "_type_"); ! if (old_type && old_type != type) { PyErr_SetString(PyExc_AttributeError, "_type_ already set"); return NULL; } ! if (-1 == PyDict_SetItemString((PyObject *)dict, "_type_", type)) return NULL; Py_INCREF(Py_None); return Py_None; --- 576,596 ---- assert(dict); ! /* FIXME/CHECKME: What about subclasses? */ old_type = PyDict_GetItemString((PyObject *)dict, "_type_"); ! if (old_type == type) ! goto done; /* nothing to do */ ! ! if (old_type && old_type != type && type != Py_None) { PyErr_SetString(PyExc_AttributeError, "_type_ already set"); return NULL; } ! ! if (-1 == PointerType_SetProto(dict, type)) return NULL; + if (-1 == PyDict_SetItemString((PyObject *)dict, "_type_", type)) + return NULL; + done: Py_INCREF(Py_None); return Py_None; |
From: Thomas H. <th...@us...> - 2004-10-14 18:14:46
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27362 Modified Files: stgdict.c Log Message: Remove unused variable. Index: stgdict.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/stgdict.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** stgdict.c 14 Oct 2004 18:06:45 -0000 1.19 --- stgdict.c 14 Oct 2004 18:14:35 -0000 1.20 *************** *** 141,145 **** int union_size, total_align; int field_size = 0; - PyObject *prev_desc = NULL; int bitofs; PyObject *isPacked; --- 141,144 ---- |
From: Thomas H. <th...@us...> - 2004-10-14 18:06:55
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25837 Modified Files: stgdict.c Log Message: Small refactoring - but AFAICT, StgDictObject doesn't seem to need cycle gc support. Index: stgdict.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/stgdict.c,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** stgdict.c 13 Oct 2004 16:53:12 -0000 1.18 --- stgdict.c 14 Oct 2004 18:06:45 -0000 1.19 *************** *** 21,28 **** } static void StgDict_dealloc(StgDictObject *self) { ! Py_XDECREF(self->proto); PyMem_Free(self->ffi_type.elements); ((PyObject *)self)->ob_type->tp_free((PyObject *)self); --- 21,35 ---- } + static int + StgDict_clear(StgDictObject *self) + { + Py_CLEAR(self->proto); + return 0; + } + static void StgDict_dealloc(StgDictObject *self) { ! StgDict_clear(self); PyMem_Free(self->ffi_type.elements); ((PyObject *)self)->ob_type->tp_free((PyObject *)self); |
From: Thomas H. <th...@us...> - 2004-10-14 14:44:14
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4615 Modified Files: _ctypes.c Log Message: Simplify the code, and avoid some dangerous corner cases with GC, as outlined in the python docs in the noddy example. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.166 retrieving revision 1.167 diff -C2 -d -r1.166 -r1.167 *** _ctypes.c 12 Oct 2004 19:03:32 -0000 1.166 --- _ctypes.c 14 Oct 2004 14:44:03 -0000 1.167 *************** *** 1759,1766 **** CData_traverse(CDataObject *self, visitproc visit, void *arg) { ! #define TRAVERSE(o) if(o && visit(o, arg) < 0) return -1 ! TRAVERSE(self->b_objects); ! TRAVERSE((PyObject *)self->b_base); ! #undef TRAVERSE return 0; } --- 1759,1764 ---- CData_traverse(CDataObject *self, visitproc visit, void *arg) { ! Py_VISIT(self->b_objects); ! Py_VISIT((PyObject *)self->b_base); return 0; } *************** *** 1769,1774 **** CData_clear(CDataObject *self) { ! Py_XDECREF(self->b_objects); ! self->b_objects = NULL; if (self->b_needsfree) { #ifdef MS_WIN32 --- 1767,1771 ---- CData_clear(CDataObject *self) { ! Py_CLEAR(self->b_objects); if (self->b_needsfree) { #ifdef MS_WIN32 *************** *** 1794,1799 **** } self->b_ptr = NULL; ! Py_XDECREF(self->b_base); ! self->b_base = NULL; return 0; } --- 1791,1795 ---- } self->b_ptr = NULL; ! Py_CLEAR(self->b_base); return 0; } *************** *** 2640,2650 **** CFuncPtr_traverse(CFuncPtrObject *self, visitproc visit, void *arg) { ! #define TRAVERSE(o) if (o && visit(o, arg) < 0) return -1 ! TRAVERSE(self->callable); ! TRAVERSE(self->restype); ! TRAVERSE(self->argtypes); ! TRAVERSE(self->converters); ! TRAVERSE(self->b_objects); ! #undef TRAVERSE return 0; } --- 2636,2644 ---- CFuncPtr_traverse(CFuncPtrObject *self, visitproc visit, void *arg) { ! Py_VISIT(self->callable); ! Py_VISIT(self->restype); ! Py_VISIT(self->argtypes); ! Py_VISIT(self->converters); ! Py_VISIT(self->b_objects); return 0; } |
From: Thomas H. <th...@us...> - 2004-10-14 14:43:55
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4566 Modified Files: cfield.c Log Message: Simplify the code, and avoid some dangerous corner cases with GC, as outlined in the python docs in the noddy example. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** cfield.c 14 Oct 2004 14:24:37 -0000 1.59 --- cfield.c 14 Oct 2004 14:43:45 -0000 1.60 *************** *** 213,219 **** CField_traverse(CFieldObject *self, visitproc visit, void *arg) { ! #define TRAVERSE(o) if(o && visit(o, arg) < 0) return -1 ! TRAVERSE(self->proto); ! #undef TRAVERSE return 0; } --- 213,217 ---- CField_traverse(CFieldObject *self, visitproc visit, void *arg) { ! Py_VISIT(self->proto); return 0; } *************** *** 222,228 **** CField_clear(CFieldObject *self) { ! PyObject *tmp = self->proto; ! self->proto = NULL; ! Py_XDECREF(tmp); return 0; } --- 220,224 ---- CField_clear(CFieldObject *self) { ! Py_CLEAR(self->proto); return 0; } |
From: Thomas H. <th...@us...> - 2004-10-14 14:42:17
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3992 Modified Files: ctypes.h Log Message: Insert some Python 2.4 macros, if they are not defined. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** ctypes.h 13 Oct 2004 16:53:12 -0000 1.53 --- ctypes.h 14 Oct 2004 14:42:04 -0000 1.54 *************** *** 261,264 **** --- 261,293 ---- extern char *conversion_mode_errors; + /* Python 2.4 macros, which are not available in Python 2.3 */ + + #ifndef Py_CLEAR + #define Py_CLEAR(op) \ + do { \ + if (op) { \ + PyObject *tmp = (PyObject *)(op); \ + (op) = NULL; \ + Py_DECREF(tmp); \ + } \ + } while (0) + #endif + + #ifndef Py_VISIT + /* Utility macro to help write tp_traverse functions. + * To use this macro, the tp_traverse function must name its arguments + * "visit" and "arg". This is intended to keep tp_traverse functions + * looking as much alike as possible. + */ + #define Py_VISIT(op) \ + do { \ + if (op) { \ + int vret = visit((op), arg); \ + if (vret) \ + return vret; \ + } \ + } while (0) + #endif + /* Local Variables: |
From: Thomas H. <th...@us...> - 2004-10-14 14:24:47
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31761 Modified Files: cfield.c Log Message: Implement cycle GC support for CFieldObject. Unfortunately, the tests still show object leaks. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** cfield.c 14 Oct 2004 13:17:31 -0000 1.58 --- cfield.c 14 Oct 2004 14:24:37 -0000 1.59 *************** *** 16,20 **** { CFieldObject *obj; - obj = (CFieldObject *)type->tp_alloc(type, 0); return (PyObject *)obj; --- 16,19 ---- *************** *** 212,219 **** static int CField_clear(CFieldObject *self) { ! Py_XDECREF(self->proto); self->proto = NULL; return 0; } --- 211,228 ---- static int + CField_traverse(CFieldObject *self, visitproc visit, void *arg) + { + #define TRAVERSE(o) if(o && visit(o, arg) < 0) return -1 + TRAVERSE(self->proto); + #undef TRAVERSE + return 0; + } + + static int CField_clear(CFieldObject *self) { ! PyObject *tmp = self->proto; self->proto = NULL; + Py_XDECREF(tmp); return 0; } *************** *** 247,253 **** 0, /* tp_setattro */ 0, /* tp_as_buffer */ ! Py_TPFLAGS_DEFAULT, /* tp_flags */ NULL, /* tp_doc */ ! 0, /* tp_traverse */ (inquiry)CField_clear, /* tp_clear */ 0, /* tp_richcompare */ --- 256,262 ---- 0, /* tp_setattro */ 0, /* tp_as_buffer */ ! Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ NULL, /* tp_doc */ ! (traverseproc)CField_traverse, /* tp_traverse */ (inquiry)CField_clear, /* tp_clear */ 0, /* tp_richcompare */ |
From: Thomas H. <th...@us...> - 2004-10-14 13:18:40
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15517 Added Files: test_leaks.py Log Message: Test for leaking refcounts and objects in structure definitions. --- NEW FILE: test_leaks.py --- import unittest, sys, gc from ctypes import * class LeakTestCase(unittest.TestCase): ################ def make_noncyclic_structures(self, repeat): for i in xrange(repeat): class POINT(Structure): _fields_ = [("x", c_int), ("y", c_int)] class RECT(Structure): _fields_ = [("ul", POINT), ("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): last_refcount = 0 for x in xrange(20): self.make_noncyclic_structures(1000) while gc.collect(): pass total_refcount = sys.gettotalrefcount() if last_refcount >= total_refcount: return # test passed last_refcount = total_refcount self.fail("it seems the total refcounts grows without bounds") def test_no_cycles_objcount(self): last_objcount = 0 for x in xrange(20): self.make_noncyclic_structures(1000) while gc.collect(): pass total_objcount = gc.get_objects() if last_objcount >= total_objcount: return # test passed last_objcount = total_objcount self.fail("it seems the number of objects grows without bounds") ################ def make_cyclic_structures(self, repeat): for i in xrange(repeat): class LIST(Structure): pass LIST._fields_ = [("pnext", POINTER(LIST))] if hasattr(sys, "gettotalrefcount"): def test_cycles_refcount(self): last_refcount = 0 for x in xrange(5): self.make_cyclic_structures(1000) while gc.collect(): pass total_refcount = sys.gettotalrefcount() if last_refcount >= total_refcount: return last_refcount = total_refcount self.fail("it seems the total refcounts grows without bounds") def test_cycles_objcount(self): last_objcount = 0 for x in xrange(5): self.make_cyclic_structures(1000) while gc.collect(): pass total_objcount = len(gc.get_objects()) if last_objcount >= total_objcount: return last_objcount = total_objcount self.fail("it seems the number of objects grows without bounds") if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2004-10-14 13:17:49
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15283 Modified Files: cfield.c Log Message: I totally forgot to Py_DECREF members of CFieldObject instances. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** cfield.c 13 Oct 2004 19:11:34 -0000 1.57 --- cfield.c 14 Oct 2004 13:17:31 -0000 1.58 *************** *** 211,214 **** --- 211,229 ---- }; + static int + CField_clear(CFieldObject *self) + { + Py_XDECREF(self->proto); + self->proto = NULL; + return 0; + } + + static void + CField_dealloc(PyObject *self) + { + CField_clear((CFieldObject *)self); + self->ob_type->tp_free((PyObject *)self); + } + PyTypeObject CField_Type = { PyObject_HEAD_INIT(NULL) *************** *** 217,221 **** sizeof(CFieldObject), /* tp_basicsize */ 0, /* tp_itemsize */ ! 0, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ --- 232,236 ---- sizeof(CFieldObject), /* tp_basicsize */ 0, /* tp_itemsize */ ! CField_dealloc, /* tp_dealloc */ 0, /* tp_print */ 0, /* tp_getattr */ *************** *** 235,239 **** NULL, /* tp_doc */ 0, /* tp_traverse */ ! 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ --- 250,254 ---- NULL, /* tp_doc */ 0, /* tp_traverse */ ! (inquiry)CField_clear, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ |
From: Thomas H. <th...@us...> - 2004-10-14 13:16:33
|
Update of /cvsroot/ctypes/ctypes/unittests/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14975 Modified Files: test_sysalloc.py Log Message: Use the debug version of the test dll, when running a debug build. Index: test_sysalloc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/com/test_sysalloc.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** test_sysalloc.py 16 Sep 2004 20:21:07 -0000 1.5 --- test_sysalloc.py 14 Oct 2004 13:16:23 -0000 1.6 *************** *** 4,18 **** from ctypes.com.automation import BSTR, VARIANT ! ! def find_test_dll(): ! import sys, os ! if os.name == "nt": ! name = "_ctypes_test.pyd" ! else: ! name = "_ctypes_test.so" ! for p in sys.path: ! f = os.path.join(p, name) ! if os.path.isfile(f): ! return f class MallocSpyTest(unittest.TestCase): --- 4,8 ---- from ctypes.com.automation import BSTR, VARIANT ! import _ctypes_test class MallocSpyTest(unittest.TestCase): *************** *** 76,80 **** # *pbstr = SysAllocString(L"Goodbye!"); # } ! GetString = CDLL(find_test_dll()).GetString # XXX Explain why we cannot create b outside the loop! --- 66,70 ---- # *pbstr = SysAllocString(L"Goodbye!"); # } ! GetString = CDLL(_ctypes_test.__file__).GetString # XXX Explain why we cannot create b outside the loop! |
From: Thomas H. <th...@us...> - 2004-10-14 13:16:25
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14923 Modified Files: test_win32.py test_values.py test_slicing.py test_returnfuncptrs.py test_refcounts.py test_prototypes.py test_pointers.py test_functions.py test_callbacks.py Log Message: Use the debug version of the test dll, when running a debug build. Index: test_win32.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_win32.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** test_win32.py 28 Jul 2004 12:56:55 -0000 1.9 --- test_win32.py 14 Oct 2004 13:16:13 -0000 1.10 *************** *** 5,17 **** def find_test_dll(): ! import sys, os ! if os.name == "nt": ! name = "_ctypes_test.pyd" ! else: ! name = "_ctypes_test.so" ! for p in sys.path: ! f = os.path.join(p, name) ! if os.path.isfile(f): ! return f if sys.platform == "win32": --- 5,10 ---- def find_test_dll(): ! import _ctypes_test ! return _ctypes_test.__file__ if sys.platform == "win32": Index: test_returnfuncptrs.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_returnfuncptrs.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** test_returnfuncptrs.py 16 Sep 2004 10:30:28 -0000 1.7 --- test_returnfuncptrs.py 14 Oct 2004 13:16:13 -0000 1.8 *************** *** 3,15 **** def find_test_dll(): ! import sys, os ! if os.name == "nt": ! name = "_ctypes_test.pyd" ! else: ! name = "_ctypes_test.so" ! for p in sys.path: ! f = os.path.join(p, name) ! if os.path.isfile(f): ! return f class ReturnFuncPtrTestCase(unittest.TestCase): --- 3,8 ---- def find_test_dll(): ! import _ctypes_test ! return _ctypes_test.__file__ class ReturnFuncPtrTestCase(unittest.TestCase): Index: test_refcounts.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_refcounts.py,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** test_refcounts.py 28 Jul 2004 12:56:55 -0000 1.15 --- test_refcounts.py 14 Oct 2004 13:16:13 -0000 1.16 *************** *** 6,20 **** OtherCallback = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int, ctypes.c_ulonglong) ! def find_test_dll(): ! import sys, os ! if os.name == "nt": ! name = "_ctypes_test.pyd" ! else: ! name = "_ctypes_test.so" ! for p in sys.path: ! f = os.path.join(p, name) ! if os.path.isfile(f): ! return f ! dll = ctypes.CDLL(find_test_dll()) class RefcountTestCase(unittest.TestCase): --- 6,11 ---- OtherCallback = ctypes.CFUNCTYPE(ctypes.c_int, ctypes.c_int, ctypes.c_ulonglong) ! import _ctypes_test ! dll = ctypes.CDLL(_ctypes_test.__file__) class RefcountTestCase(unittest.TestCase): Index: test_values.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_values.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** test_values.py 28 Jul 2004 12:56:55 -0000 1.12 --- test_values.py 14 Oct 2004 13:16:13 -0000 1.13 *************** *** 6,18 **** from ctypes import * def find_test_dll(): ! import sys, os ! if os.name == "nt": ! name = "_ctypes_test.pyd" ! else: ! name = "_ctypes_test.so" ! for p in sys.path: ! f = os.path.join(p, name) ! if os.path.isfile(f): ! return f class ValuesTestCase(unittest.TestCase): --- 6,11 ---- from ctypes import * def find_test_dll(): ! import _ctypes_test ! return _ctypes_test.__file__ class ValuesTestCase(unittest.TestCase): Index: test_slicing.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_slicing.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_slicing.py 12 Oct 2004 19:11:52 -0000 1.3 --- test_slicing.py 14 Oct 2004 13:16:13 -0000 1.4 *************** *** 3,15 **** def find_test_dll(): ! import sys, os ! if os.name == "nt": ! name = "_ctypes_test.pyd" ! else: ! name = "_ctypes_test.so" ! for p in sys.path: ! f = os.path.join(p, name) ! if os.path.isfile(f): ! return f class SlicesTestCase(unittest.TestCase): --- 3,8 ---- def find_test_dll(): ! import _ctypes_test ! return _ctypes_test.__file__ class SlicesTestCase(unittest.TestCase): Index: test_prototypes.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_prototypes.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** test_prototypes.py 16 Sep 2004 10:30:28 -0000 1.5 --- test_prototypes.py 14 Oct 2004 13:16:13 -0000 1.6 *************** *** 22,36 **** # In this case, there would have to be an additional reference to the argument... ! def find_test_dll(): ! import sys, os ! if os.name == "nt": ! name = "_ctypes_test.pyd" ! else: ! name = "_ctypes_test.so" ! for p in sys.path: ! f = os.path.join(p, name) ! if os.path.isfile(f): ! return f ! testdll = CDLL(find_test_dll()) def c_wbuffer(init): --- 22,27 ---- # In this case, there would have to be an additional reference to the argument... ! import _ctypes_test ! testdll = CDLL(_ctypes_test.__file__) def c_wbuffer(init): Index: test_pointers.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_pointers.py,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** test_pointers.py 28 Jul 2004 12:56:55 -0000 1.15 --- test_pointers.py 14 Oct 2004 13:16:13 -0000 1.16 *************** *** 3,15 **** from ctypes import * def find_test_dll(): ! import sys, os ! if os.name == "nt": ! name = "_ctypes_test.pyd" ! else: ! name = "_ctypes_test.so" ! for p in sys.path: ! f = os.path.join(p, name) ! if os.path.isfile(f): ! return f ctype_types = [c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint, --- 3,8 ---- from ctypes import * def find_test_dll(): ! import _ctypes_test ! return _ctypes_test.__file__ ctype_types = [c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint, Index: test_functions.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_functions.py,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** test_functions.py 16 Sep 2004 10:30:28 -0000 1.37 --- test_functions.py 14 Oct 2004 13:16:13 -0000 1.38 *************** *** 16,28 **** def find_test_dll(): ! import sys, os ! if os.name == "nt": ! name = "_ctypes_test.pyd" ! else: ! name = "_ctypes_test.so" ! for p in sys.path: ! f = os.path.join(p, name) ! if os.path.isfile(f): ! return f class FunctionTestCase(unittest.TestCase): --- 16,21 ---- def find_test_dll(): ! import _ctypes_test ! return _ctypes_test.__file__ class FunctionTestCase(unittest.TestCase): Index: test_callbacks.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_callbacks.py,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** test_callbacks.py 28 Jul 2004 12:56:55 -0000 1.19 --- test_callbacks.py 14 Oct 2004 13:16:13 -0000 1.20 *************** *** 1,4 **** --- 1,5 ---- import unittest from ctypes import * + import _ctypes_test class Callbacks(unittest.TestCase): *************** *** 106,125 **** ################################################################ - def find_test_dll(): - import sys, os - if os.name == "nt": - name = "_ctypes_test.pyd" - else: - name = "_ctypes_test.so" - for p in sys.path: - f = os.path.join(p, name) - if os.path.isfile(f): - return f - class SampleCallbacksTestCase(unittest.TestCase): def test_integrate(self): # Derived from some then non-working code, posted by David Foster ! dll = CDLL(find_test_dll()) # The function prototype called by 'integrate': double func(double); --- 107,115 ---- ################################################################ class SampleCallbacksTestCase(unittest.TestCase): def test_integrate(self): # Derived from some then non-working code, posted by David Foster ! dll = CDLL(_ctypes_test.__file__) # The function prototype called by 'integrate': double func(double); |
From: Thomas H. <th...@us...> - 2004-10-14 13:13:41
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14398 Modified Files: setup.py Log Message: When run with a debug Python build, build extensions in debug mode (on Windows). Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.104 retrieving revision 1.105 diff -C2 -d -r1.104 -r1.105 *** setup.py 21 Sep 2004 14:16:15 -0000 1.104 --- setup.py 14 Oct 2004 13:13:30 -0000 1.105 *************** *** 228,231 **** --- 228,237 ---- class my_build_ext(build_ext.build_ext): + def finalize_options(self): + if self.debug is None: + import imp + self.debug = ('_d.pyd', 'rb', imp.C_EXTENSION) in imp.get_suffixes() + build_ext.build_ext.finalize_options(self) + # First build a static libffi library, then build the _ctypes extension. def run(self): |
From: Thomas H. <th...@us...> - 2004-10-13 19:39:12
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5964 Modified Files: ChangeLog Log Message: Add news about bit fields. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** ChangeLog 8 Oct 2004 20:22:10 -0000 1.64 --- ChangeLog 13 Oct 2004 19:39:00 -0000 1.65 *************** *** 1,2 **** --- 1,20 ---- + 2004-10-13 Thomas Heller <th...@py...> + + * Bit fields in structures and unions are now implemented. They + are defined using a third item in the _fields_ list, which + specifies the number of bits in this field. Bit fields are only + allowed for numeric types, not for character types like c_char. + + 2004-10-12 Thomas Heller <th...@py...> + + * Implemented a cast(obj, ctype) function. This should be used to + convert one type of pointer to abother type of pointer. For + example, a POINTER(c_byte) instance could be converted to a + c_char_p instance pointing to the same memory location, allowing + to access the zero-terminated string pointed to. + + * Unicode should now work on non-windows systems. Tested on Suse + Linux x86 and x86-64, Redhat linux x86 (wide unicode build). + 2004-10-08 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2004-10-13 19:11:44
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31428 Modified Files: cfield.c Log Message: This finally fixes the test suite on linux x86, at least. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** cfield.c 13 Oct 2004 18:30:04 -0000 1.56 --- cfield.c 13 Oct 2004 19:11:34 -0000 1.57 *************** *** 61,64 **** --- 61,65 ---- return NULL; } + #ifdef MS_WIN32 if (bitsize /* this is a bitfield request */ && *pfield_size /* we have a bitfield open */ *************** *** 67,70 **** --- 68,78 ---- /* continue bit field */ fieldtype = CONT_BITFIELD; + #else + if (bitsize /* this is a bitfield request */ + && *pfield_size /* we have a bitfield open */ + && dict->size * 8 <= *pfield_size + && (*pbitofs + bitsize) <= *pfield_size) { + /* continue bit field */ + fieldtype = CONT_BITFIELD; } else if (bitsize /* this is a bitfield request */ && *pfield_size /* we have a bitfield open */ *************** *** 73,76 **** --- 81,85 ---- /* expand bit field */ fieldtype = EXPAND_BITFIELD; + #endif } else if (bitsize) { /* start new bitfield */ |
From: Thomas H. <th...@us...> - 2004-10-13 19:05:50
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29752 Modified Files: _ctypes_test.c Log Message: Sometimes, more compact code is more readable. Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** _ctypes_test.c 12 Oct 2004 19:22:15 -0000 1.32 --- _ctypes_test.c 13 Oct 2004 19:05:40 -0000 1.33 *************** *** 334,370 **** { switch (name) { ! case 'A': ! return bits->A; ! case 'B': ! return bits->B; ! case 'C': ! return bits->C; ! case 'D': ! return bits->D; ! case 'E': ! return bits->E; ! case 'F': ! return bits->F; ! case 'G': ! return bits->G; ! case 'H': ! return bits->H; ! case 'I': ! return bits->I; ! case 'M': ! return bits->M; ! case 'N': ! return bits->N; ! case 'O': ! return bits->O; ! case 'P': ! return bits->P; ! case 'Q': ! return bits->Q; ! case 'R': ! return bits->R; ! case 'S': ! return bits->S; } return 0; --- 334,354 ---- { switch (name) { ! case 'A': return bits->A; ! case 'B': return bits->B; ! case 'C': return bits->C; ! case 'D': return bits->D; ! case 'E': return bits->E; ! case 'F': return bits->F; ! case 'G': return bits->G; ! case 'H': return bits->H; ! case 'I': return bits->I; ! case 'M': return bits->M; ! case 'N': return bits->N; ! case 'O': return bits->O; ! case 'P': return bits->P; ! case 'Q': return bits->Q; ! case 'R': return bits->R; ! case 'S': return bits->S; } return 0; |
From: Thomas H. <th...@us...> - 2004-10-13 18:30:14
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18587 Modified Files: cfield.c Log Message: At least the sizes of structures containing bit fields are now correct with gcc. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** cfield.c 13 Oct 2004 17:25:49 -0000 1.55 --- cfield.c 13 Oct 2004 18:30:04 -0000 1.56 *************** *** 21,41 **** } - /* compilers seem to have different behaviour with this structure. GCC on x86 - * packs the fields into one 32-bit int, MSVC creates one char and one int. - * The WIDEN_BITFIELDS function returns .... XXXX FIXME - */ - struct b_bitfields { char a:2; int b:28; }; - #define WIDEN_BITFIELDS (!(sizeof(struct b_bitfields) - sizeof(int))) - - /* convert to macro? */ - static int - can_continue_bitfield(StgDictObject *prev, StgDictObject *this) - { - if (WIDEN_BITFIELDS) - return prev && this->size == prev->size; - else - return prev == this; - } - /* * Expects the size, index and offset for the current field in *psize and --- 21,24 ---- *************** *** 63,68 **** int fieldtype; #define NO_BITFIELD 0 ! #define CONT_BITFIELD 1 ! #define NEW_BITFIELD 2 self = (CFieldObject *)PyObject_CallObject((PyObject *)&CField_Type, --- 46,52 ---- int fieldtype; #define NO_BITFIELD 0 ! #define NEW_BITFIELD 1 ! #define CONT_BITFIELD 2 ! #define EXPAND_BITFIELD 3 self = (CFieldObject *)PyObject_CallObject((PyObject *)&CField_Type, *************** *** 78,95 **** } if (bitsize /* this is a bitfield request */ - #ifdef _MSC_VER && *pfield_size /* we have a bitfield open */ && dict->size * 8 == *pfield_size /* MSVC */ ! && (*pbitofs + bitsize) <= *pfield_size ! #else ! && *pfield_size /* we have a bitfield open */ ! && ( (*pbitofs + bitsize) <= *pfield_size ! || (*pbitofs + bitsize) <= dict->size) ! #endif ! ) ! { /* continue bit field */ - *pfield_size = max(*pfield_size, dict->size); fieldtype = CONT_BITFIELD; } else if (bitsize) { /* start new bitfield */ --- 62,76 ---- } if (bitsize /* this is a bitfield request */ && *pfield_size /* we have a bitfield open */ && dict->size * 8 == *pfield_size /* MSVC */ ! && (*pbitofs + bitsize) <= *pfield_size) { /* continue bit field */ fieldtype = CONT_BITFIELD; + } else if (bitsize /* this is a bitfield request */ + && *pfield_size /* we have a bitfield open */ + && dict->size * 8 >= *pfield_size /* MSVC */ + && (*pbitofs + bitsize) <= dict->size * 8) { + /* expand bit field */ + fieldtype = EXPAND_BITFIELD; } else if (bitsize) { /* start new bitfield */ *************** *** 164,167 **** --- 145,159 ---- break; + case EXPAND_BITFIELD: + /* XXX needs more */ + *psize += dict->size - *pfield_size/8; + + *pfield_size = dict->size * 8; + + self->size = (bitsize << 16) + *pbitofs; + self->offset = *poffset - size; /* poffset is already updated for the NEXT field */ + *pbitofs += bitsize; + break; + case CONT_BITFIELD: self->size = (bitsize << 16) + *pbitofs; |
From: Thomas H. <th...@us...> - 2004-10-13 17:34:27
|
Update of /cvsroot/ctypes/ctypes/sandbox/bitfields In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2455 Modified Files: bitsizes.c Log Message: GCC packs bit fields differently than MSVC. Another struct. Index: bitsizes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/bitfields/bitsizes.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** bitsizes.c 13 Oct 2004 17:03:10 -0000 1.1 --- bitsizes.c 13 Oct 2004 17:34:09 -0000 1.2 *************** *** 3,6 **** --- 3,21 ---- * bitfields in structures and unions. */ + /* + On Windows, it prints: + + sizeof(char:4, int:4) = 8 + sizeof(char:4, int:32) = 8 + sizeof(char:4, unsigned char:4) = 1 + + On Linux x86 (Suse, Redhat, x86_64), Mac OS/X, Solaris Sparc: + + sizeof(char:4, int:4) = 4 + sizeof(char:4, int:32) = 8 + sizeof(char:4, unsigned char:4) = 1 + + */ + #include <stdio.h> *************** *** 9,12 **** --- 24,29 ---- typedef struct { char a : 4; unsigned char b: 4; } c4uc4; + typedef struct { char a; char b: 4; int i:4; } a_c4i4; + int main(int argc, char **argv) { *************** *** 14,16 **** --- 31,34 ---- printf("sizeof(char:4, int:32) = %d\n", sizeof(c4i32)); printf("sizeof(char:4, unsigned char:4) = %d\n", sizeof(c4uc4)); + printf("sizeof(char, char:4, int:4) = %d\n", sizeof(a_c4i4)); } |
From: Thomas H. <th...@us...> - 2004-10-13 17:26:00
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv398 Modified Files: cfield.c Log Message: Customize bit fields depending on compiler. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** cfield.c 13 Oct 2004 16:53:12 -0000 1.54 --- cfield.c 13 Oct 2004 17:25:49 -0000 1.55 *************** *** 77,88 **** return NULL; } - #ifdef _DEBUG - _asm int 3; - #endif if (bitsize /* this is a bitfield request */ && *pfield_size /* we have a bitfield open */ && dict->size * 8 == *pfield_size /* MSVC */ ! && (*pbitofs + bitsize) <= *pfield_size) { /* continue bit field */ fieldtype = CONT_BITFIELD; } else if (bitsize) { --- 77,94 ---- return NULL; } if (bitsize /* this is a bitfield request */ + #ifdef _MSC_VER && *pfield_size /* we have a bitfield open */ && dict->size * 8 == *pfield_size /* MSVC */ ! && (*pbitofs + bitsize) <= *pfield_size ! #else ! && *pfield_size /* we have a bitfield open */ ! && ( (*pbitofs + bitsize) <= *pfield_size ! || (*pbitofs + bitsize) <= dict->size) ! #endif ! ) ! { /* continue bit field */ + *pfield_size = max(*pfield_size, dict->size); fieldtype = CONT_BITFIELD; } else if (bitsize) { |
From: Thomas H. <th...@us...> - 2004-10-13 17:13:53
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30325 Modified Files: test_bitfields.py Log Message: Separate tests. Index: test_bitfields.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_bitfields.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test_bitfields.py 13 Oct 2004 17:11:15 -0000 1.4 --- test_bitfields.py 13 Oct 2004 17:13:29 -0000 1.5 *************** *** 194,198 **** return detail.__class__, str(detail) ! def test_mixed(self): class X(Structure): _fields_ = [("a", c_byte, 4), --- 194,198 ---- return detail.__class__, str(detail) ! def test_mixed_1(self): class X(Structure): _fields_ = [("a", c_byte, 4), *************** *** 203,206 **** --- 203,207 ---- self.failUnlessEqual(sizeof(X), sizeof(c_int)) + def test_mixed_2(self): class X(Structure): _fields_ = [("a", c_byte, 4), *************** *** 208,211 **** --- 209,213 ---- self.failUnlessEqual(sizeof(X), sizeof(c_int)*2) + def test_mixed_3(self): class X(Structure): _fields_ = [("a", c_byte, 4), |
From: Thomas H. <th...@us...> - 2004-10-13 17:11:39
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29816 Modified Files: test_bitfields.py Log Message: GCC packs bit fields differently than MSVC. Index: test_bitfields.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_bitfields.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_bitfields.py 13 Oct 2004 16:55:07 -0000 1.3 --- test_bitfields.py 13 Oct 2004 17:11:15 -0000 1.4 *************** *** 1,4 **** --- 1,5 ---- from ctypes import * import unittest + import sys import ctypes *************** *** 197,201 **** _fields_ = [("a", c_byte, 4), ("b", c_int, 4)] ! self.failUnlessEqual(sizeof(X), sizeof(c_int)*2) class X(Structure): --- 198,205 ---- _fields_ = [("a", c_byte, 4), ("b", c_int, 4)] ! if sys.platform == "win32": ! self.failUnlessEqual(sizeof(X), sizeof(c_int)*2) ! else: ! self.failUnlessEqual(sizeof(X), sizeof(c_int)) class X(Structure): |
From: Thomas H. <th...@us...> - 2004-10-13 17:03:40
|
Update of /cvsroot/ctypes/ctypes/sandbox/bitfields In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27742 Added Files: bitsizes.c Log Message: C program to examine bitfields. --- NEW FILE: bitsizes.c --- /* * Maybe, eventually, this program can generate a unittest module for testing * bitfields in structures and unions. */ #include <stdio.h> typedef struct { char a : 4; int b : 4; } c4b4; typedef struct { char a : 4; int b : 32; } c4i32; typedef struct { char a : 4; unsigned char b: 4; } c4uc4; int main(int argc, char **argv) { printf("sizeof(char:4, int:4) = %d\n", sizeof(c4b4)); printf("sizeof(char:4, int:32) = %d\n", sizeof(c4i32)); printf("sizeof(char:4, unsigned char:4) = %d\n", sizeof(c4uc4)); } |
From: Thomas H. <th...@us...> - 2004-10-13 17:02:40
|
Update of /cvsroot/ctypes/ctypes/sandbox/bitfields In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27539/bitfields Log Message: Directory /cvsroot/ctypes/ctypes/sandbox/bitfields added to the repository |