Author: Antonio Cuni <anto.c...@gmail.com> Branch: Changeset: r46425:c5a046bdc0b8 Date: 2011-08-10 18:18 +0200 http://bitbucket.org/pypy/pypy/changeset/c5a046bdc0b8/
Log: merge heads diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py --- a/lib_pypy/_ctypes/structure.py +++ b/lib_pypy/_ctypes/structure.py @@ -14,6 +14,15 @@ raise TypeError("Expected CData subclass, got %s" % (tp,)) if isinstance(tp, StructOrUnionMeta): tp._make_final() + if len(f) == 3: + if (not hasattr(tp, '_type_') + or not isinstance(tp._type_, str) + or tp._type_ not in "iIhHbBlL"): + #XXX: are those all types? + # we just dont get the type name + # in the interp levle thrown TypeError + # from rawffi if there are more + raise TypeError('bit fields not allowed for type ' + tp.__name__) all_fields = [] for cls in reversed(inspect.getmro(superclass)): @@ -116,7 +125,7 @@ if name == '_fields_': if self.__dict__.get('_fields_', None) is not None: raise AttributeError("_fields_ is final") - if self in [v for k, v in value]: + if self in [f[1] for f in value]: raise AttributeError("Structure or union cannot contain itself") names_and_fields( self, diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_bitfields.py b/pypy/module/test_lib_pypy/ctypes_tests/test_bitfields.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_bitfields.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_bitfields.py @@ -5,8 +5,6 @@ import ctypes -py.test.skip("bitfields not supported") - def setup_module(mod): import conftest _ctypes_test = str(conftest.sofile) @@ -14,7 +12,7 @@ func.argtypes = POINTER(BITS), c_char mod.func = func -class BITS(BaseCTypesTestChecker): +class BITS(Structure): _fields_ = [("A", c_int, 1), ("B", c_int, 2), ("C", c_int, 3), @@ -197,6 +195,8 @@ try: func(*args, **kw) except Exception, detail: + import traceback + traceback.print_exc() return detail.__class__, str(detail) def test_mixed_1(self): @@ -228,3 +228,24 @@ class Y(Structure): _anonymous_ = ["_"] _fields_ = [("_", X)] + + def test_set_fields_attr(self): + class A(Structure): + pass + A._fields_ = [("a", c_byte), + ("b", c_ubyte)] + + def test_set_fields_attr_bitfields(self): + class A(Structure): + pass + A._fields_ = [("a", POINTER(A)), + ("b", c_ubyte, 4)] + + + def test_set_fields_cycle_fails(self): + class A(Structure): + pass + import pytest + pytest.raises(AttributeError, """ + A._fields_ = [("a", A)] + """) diff --git a/pypy/tool/gdb_pypy.py b/pypy/tool/gdb_pypy.py --- a/pypy/tool/gdb_pypy.py +++ b/pypy/tool/gdb_pypy.py @@ -65,7 +65,7 @@ """ prog2typeids = {} - + def __init__(self, gdb=None): # dependency injection, for tests if gdb is None: @@ -137,7 +137,7 @@ val" and see the nice string, and "p *val" to see the underyling struct fields """ - + def __init__(self, val): self.val = val @@ -172,7 +172,8 @@ @classmethod def lookup(cls, val, gdb=None): t = val.type - if is_ptr(t, gdb) and re.match(r'pypy_list\d*', t.target().tag): + if (is_ptr(t, gdb) and t.target().tag is not None and + re.match(r'pypy_list\d*', t.target().tag)): return cls(val) return None diff --git a/pypy/tool/test/test_gdb_pypy.py b/pypy/tool/test/test_gdb_pypy.py --- a/pypy/tool/test/test_gdb_pypy.py +++ b/pypy/tool/test/test_gdb_pypy.py @@ -29,7 +29,7 @@ class Struct(object): code = FakeGdb.TYPE_CODE_STRUCT - + def __init__(self, fieldnames, tag): self._fields = [Field(name=name) for name in fieldnames] self.tag = tag @@ -178,3 +178,6 @@ mylist.type.target().tag = 'pypy_list1234' printer = gdb_pypy.RPyListPrinter.lookup(mylist, FakeGdb) assert printer.to_string() == 'r[40, 41, 42] (len=3, alloc=5)' + + mylist.type.target().tag = None + assert gdb_pypy.RPyListPrinter.lookup(mylist, FakeGdb) is None \ No newline at end of file diff --git a/pypy/translator/goal/app_main.py b/pypy/translator/goal/app_main.py --- a/pypy/translator/goal/app_main.py +++ b/pypy/translator/goal/app_main.py @@ -33,11 +33,9 @@ except: # not an integer: print it to stderr try: - stderr = sys.stderr - except AttributeError: + print >> sys.stderr, exitcode + except: pass # too bad - else: - stderr.write(exitcode) exitcode = 1 raise SystemExit(exitcode) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit