[pypy-svn] r70014 - pypy/branch/sepcomp/pypy/rpython/lltypesystem

xoraxax at codespeak.net xoraxax at codespeak.net
Wed Dec 9 12:51:14 CET 2009


Author: xoraxax
Date: Wed Dec  9 12:51:14 2009
New Revision: 70014

Modified:
   pypy/branch/sepcomp/pypy/rpython/lltypesystem/lltype.py
Log:
... belongs to last commit.

Modified: pypy/branch/sepcomp/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/sepcomp/pypy/rpython/lltypesystem/lltype.py	(original)
+++ pypy/branch/sepcomp/pypy/rpython/lltypesystem/lltype.py	Wed Dec  9 12:51:14 2009
@@ -76,6 +76,12 @@
 
     _is_compatible = __eq__
 
+    def __getstate__(self):
+        return self.__dict__
+
+    def __setstate__(self, val):
+        self.__dict__.update(val)
+
     def _enforce(self, value):
         if typeOf(value) != self:
             raise TypeError
@@ -106,11 +112,6 @@
             self.__cached_hash = result
         return result
 
-    # due to this dynamic hash value, we should forbid
-    # pickling, until we have an algorithm for that.
-    # but we just provide a tag for external help.
-    __hash_is_not_constant__ = True
-
     def __repr__(self):
         return '<%s>' % (self,)
 
@@ -1260,6 +1261,7 @@
 
 class _container(object):
     __slots__ = ()
+    _exported = False
     def _parentstructure(self, check=True):
         return None
     def _check(self):
@@ -1280,7 +1282,7 @@
 
     __slots__ = ('_TYPE',
                  '_parent_type', '_parent_index', '_keepparent',
-                 '_wrparent',
+                 '_wrparent',"_exported",
                  '__weakref__',
                  '_storage')
 
@@ -1651,7 +1653,9 @@
             return id(self)
 
     def __setattr__(self, attr, value):
-        raise AttributeError("cannot change the attributes of %r" % (self,))
+        if attr != "_exported":
+            raise AttributeError("cannot change the attributes of %r" % (self,))
+        _container.__setattr__(self, attr, value)
 
 class _opaque(_parentable):
     def __init__(self, TYPE, parent=None, parentindex=None, **attrs):
@@ -1696,8 +1700,18 @@
             return _parentable._normalizedcontainer(self)
 
 
+class _external_reference(_container):
+    def __init__(self, TYPE, name, component=None):
+        self._TYPE = TYPE
+        self.name = name
+        self.component = component
+        self.iddata = str(component) + name
+
+    def _getid(self):
+        return id(self.iddata)
+
+
 class _pyobject(Hashable, _container):
-    __slots__ = []   # or we get in trouble with pickling
 
     _TYPE = PyObject
 
@@ -1764,6 +1778,10 @@
     o = _pyobject(obj)
     return _ptr(Ptr(PyObject), o) 
 
+def externalptr(TYPE, name, component=None):
+    o = _external_reference(TYPE, name, component)
+    return _ptr(Ptr(TYPE), o, solid=True)
+
 def cast_ptr_to_int(ptr):
     return ptr._cast_to_int()
 



More information about the Pypy-commit mailing list