[pypy-svn] r49803 - pypy/branch/pypy-more-delayedptr/translator/c

arigo at codespeak.net arigo at codespeak.net
Fri Dec 14 19:21:16 CET 2007


Author: arigo
Date: Fri Dec 14 19:21:16 2007
New Revision: 49803

Modified:
   pypy/branch/pypy-more-delayedptr/translator/c/database.py
Log:
Restore the original logic about delayed func ptr, just skip some of
it for delayed non-func ptrs.


Modified: pypy/branch/pypy-more-delayedptr/translator/c/database.py
==============================================================================
--- pypy/branch/pypy-more-delayedptr/translator/c/database.py	(original)
+++ pypy/branch/pypy-more-delayedptr/translator/c/database.py	Fri Dec 14 19:21:16 2007
@@ -42,7 +42,8 @@
         self.pendingsetupnodes = []
         self.containernodes = {}
         self.containerlist = []
-        self.delayedobjptrs = []
+        self.delayedfunctionnames = {}
+        self.delayedfunctionptrs = []
         self.completedcontainers = 0
         self.containerstats = {}
         self.externalfuncs = {}
@@ -187,16 +188,35 @@
                 if obj:   # test if the ptr is non-NULL
                     try:
                         container = obj._obj
-                    except lltype.DelayedPointer, e:
+                    except lltype.DelayedPointer:
                         # hack hack hack
                         name = obj._obj0
                         assert name.startswith('delayed!')
                         n = len('delayed!')
                         if len(name) == n:
                             raise
-                        self.delayedobjptrs.append(obj)
-                        return e   # not a string - the caller can't really use
-                                   # this.  We don't have a name to provide yet
+                        if isinstance(lltype.typeOf(obj).TO, lltype.FuncType):
+                            if id(obj) in self.delayedfunctionnames:
+                                return self.delayedfunctionnames[id(obj)][0]
+                            funcname = name[n:]
+                            funcname = self.namespace.uniquename('g_'+funcname)
+                            self.delayedfunctionnames[id(obj)] = funcname, obj
+                        else:
+                            funcname = None      # can't use the name of a
+                                                 # delayed non-function ptr
+                        self.delayedfunctionptrs.append(obj)
+                        return funcname
+                        # /hack hack hack
+                    else:
+                        # hack hack hack
+                        if id(obj) in self.delayedfunctionnames:
+                            # this used to be a delayed function,
+                            # make sure we use the same name
+                            forcename = self.delayedfunctionnames[id(obj)][0]
+                            node = self.getcontainernode(container,
+                                                         forcename=forcename)
+                            assert node.ptrname == forcename
+                            return forcename
                         # /hack hack hack
 
                     if isinstance(container, int):
@@ -299,15 +319,15 @@
                     dump()
                     show_i += 1000
 
-            if self.delayedobjptrs:
-                lst = self.delayedobjptrs
-                self.delayedobjptrs = []
+            if self.delayedfunctionptrs:
+                lst = self.delayedfunctionptrs
+                self.delayedfunctionptrs = []
                 progress = False
                 for fnptr in lst:
                     try:
                         fnptr._obj
                     except lltype.DelayedPointer:   # still not resolved
-                        self.delayedobjptrs.append(fnptr)
+                        self.delayedfunctionptrs.append(fnptr)
                     else:
                         self.get(fnptr)
                         progress = True
@@ -323,7 +343,7 @@
 
             break     # database is now complete
 
-        assert not self.delayedobjptrs
+        assert not self.delayedfunctionptrs
         self.completed = True
         if show_progress:
             dump()



More information about the Pypy-commit mailing list