[pypy-svn] r28589 - in pypy/dist/pypy/rpython/lltypesystem: . test

arigo at codespeak.net arigo at codespeak.net
Fri Jun 9 16:11:57 CEST 2006


Author: arigo
Date: Fri Jun  9 16:11:55 2006
New Revision: 28589

Modified:
   pypy/dist/pypy/rpython/lltypesystem/lltype.py
   pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py
Log:
Some clean-up and a test for lltype.


Modified: pypy/dist/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/lltype.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/lltype.py	Fri Jun  9 16:11:55 2006
@@ -252,8 +252,8 @@
     def _short_name(self):
         return "%s %s" % (self.__class__.__name__, self._name)
 
-    def _defl(self, parent=None, parentindex=None, **kwds):
-        return _struct(self, parent=parent, parentindex=parentindex, **kwds)
+    def _defl(self, parent=None, parentindex=None):
+        return _struct(self, parent=parent, parentindex=parentindex)
 
     def _container_example(self):
         if self._arrayfld is None:
@@ -445,8 +445,8 @@
     def _container_example(self):
         return _opaque(self)
 
-    def _defl(self, parent=None, parentindex=None, **kwds):
-        return _opaque(self, parent=parent, parentindex=parentindex, **kwds)
+    def _defl(self, parent=None, parentindex=None):
+        return _opaque(self, parent=parent, parentindex=parentindex)
 
 RuntimeTypeInfo = OpaqueType("RuntimeTypeInfo")
 
@@ -459,8 +459,6 @@
     def _inline_is_varsize(self, last):
         raise TypeError, "%r cannot be inlined in structure" % self
 
-FOR_TESTING_ONLY = "for testing only"
-
 class PyObjectType(ContainerType):
     _gckind = 'cpy'
     __name__ = 'PyObject'
@@ -468,12 +466,8 @@
         return "PyObject"
     def _inline_is_varsize(self, last):
         return False
-    def _defl(self, parent=None, parentindex=None, extra_args=()):
-        if not extra_args:
-            ob_type = FOR_TESTING_ONLY
-        else:
-            ob_type = extra_args[0]
-        return _pyobjheader(ob_type, parent, parentindex)
+    def _defl(self, parent=None, parentindex=None):
+        return _pyobjheader(Ellipsis, parent, parentindex)
 
 PyObject = PyObjectType()
 
@@ -1194,11 +1188,11 @@
 
     __slots__ = ()
 
-    def __new__(self, TYPE, n=None, parent=None, parentindex=None, **kwds):
+    def __new__(self, TYPE, n=None, parent=None, parentindex=None):
         my_variety = _struct_variety(TYPE._names)
         return object.__new__(my_variety)
 
-    def __init__(self, TYPE, n=None, parent=None, parentindex=None, **kwds):
+    def __init__(self, TYPE, n=None, parent=None, parentindex=None):
         _parentable.__init__(self, TYPE)
         if n is not None and TYPE._arrayfld is None:
             raise TypeError("%r is not variable-sized" % (TYPE,))
@@ -1208,8 +1202,6 @@
         for fld, typ in TYPE._flds.items():
             if fld == TYPE._arrayfld:
                 value = _array(typ, n, parent=self, parentindex=fld)
-            elif fld == first:
-                value = typ._defl(parent=self, parentindex=fld, **kwds)
             else:
                 value = typ._defl(parent=self, parentindex=fld)
             setattr(self, fld, value)
@@ -1261,6 +1253,9 @@
         assert isinstance(self._TYPE, FixedSizeArray)
         setattr(self, 'item%d' % index, value)
 
+    def _setup_extra_args(self, *args):
+        getattr(self, self._TYPE._names[0])._setup_extra_args(*args)
+
 class _array(_parentable):
     _kind = "array"
 
@@ -1482,12 +1477,14 @@
 
     def __init__(self, ob_type, parent=None, parentindex=None):
         _parentable.__init__(self, PyObject)
-        assert (ob_type is FOR_TESTING_ONLY or
-                typeOf(ob_type) == Ptr(PyObject))
-        self.ob_type = ob_type
+        self._setup_extra_args(ob_type)
         if parent is not None:
             self._setparentstructure(parent, parentindex)
 
+    def _setup_extra_args(self, ob_type):
+        assert ob_type is Ellipsis or typeOf(ob_type) == Ptr(PyObject)
+        self.ob_type = ob_type
+
     def __repr__(self):
         return '<%s>' % (self,)
 
@@ -1495,15 +1492,17 @@
         return "pyobjheader of type %r" % (self.ob_type,)
 
 
-def malloc(T, n=None, flavor='gc', immortal=False, **kwds):
+def malloc(T, n=None, flavor='gc', immortal=False, extra_args=()):
     if isinstance(T, Struct):
-        o = _struct(T, n, **kwds)
+        o = _struct(T, n)
     elif isinstance(T, Array):
-        o = _array(T, n, **kwds)
+        o = _array(T, n)
     else:
         raise TypeError, "malloc for Structs and Arrays only"
     if T._gckind != 'gc' and not immortal and flavor.startswith('gc'):
         raise TypeError, "gc flavor malloc of a non-GC non-immortal structure"
+    if extra_args:
+        o._setup_extra_args(*extra_args)
     solid = immortal or not flavor.startswith('gc') # immortal or non-gc case
     return _ptr(Ptr(T), o, solid)
 

Modified: pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/test/test_lltype.py	Fri Jun  9 16:11:55 2006
@@ -714,3 +714,21 @@
     del s1, s2
     s3 = cast_pointer(Ptr(S1), h1)
     assert s3.x == 17
+
+def test_name_clash():
+    import re
+    from pypy.rpython.lltypesystem import lltype
+    fn = lltype.__file__
+    if fn.lower().endswith('pyc') or fn.lower().endswith('pyo'):
+        fn = fn[:-1]
+    f = open(fn, 'r')
+    data = f.read()
+    f.close()
+    words = dict.fromkeys(re.compile(r"[a-zA-Z][_a-zA-Z0-9]*").findall(data))
+    words = words.keys()
+    S = GcStruct('name_clash', *[(word, Signed) for word in words])
+    s = malloc(S)
+    for i, word in enumerate(words):
+        setattr(s, word, i)
+    for i, word in enumerate(words):
+        assert getattr(s, word) == i



More information about the Pypy-commit mailing list