[pypy-svn] r14374 - in pypy/dist/pypy: rpython translator/c translator/c/test

arigo at codespeak.net arigo at codespeak.net
Thu Jul 7 12:39:53 CEST 2005


Author: arigo
Date: Thu Jul  7 12:39:48 2005
New Revision: 14374

Modified:
   pypy/dist/pypy/rpython/rstr.py
   pypy/dist/pypy/rpython/rtyper.py
   pypy/dist/pypy/translator/c/test/test_genc.py
   pypy/dist/pypy/translator/c/wrapper.py
Log:
- fixed a corner case where genc's gen_wrapper() would create more low-level
  helpers that would never be specialized.  Test included.
- fixed PyObject-to-Char conversion



Modified: pypy/dist/pypy/rpython/rstr.py
==============================================================================
--- pypy/dist/pypy/rpython/rstr.py	(original)
+++ pypy/dist/pypy/rpython/rstr.py	Thu Jul  7 12:39:48 2005
@@ -426,6 +426,7 @@
         v_chars = llops.genop('getsubstruct', [v_result, cchars],
                               resulttype=Ptr(STR.chars))
         llops.gencapicall('PyString_ToLLCharArray', [v, v_chars])
+        v_result = llops.convertvar(v_result, string_repr, r_to)
         return v_result
 
 class __extend__(pairtype(StringRepr, PyObjRepr)):

Modified: pypy/dist/pypy/rpython/rtyper.py
==============================================================================
--- pypy/dist/pypy/rpython/rtyper.py	(original)
+++ pypy/dist/pypy/rpython/rtyper.py	Thu Jul  7 12:39:48 2005
@@ -87,26 +87,27 @@
         perform_normalizations(self.annotator)
         # new blocks can be created as a result of specialize_block(), so
         # we need to be careful about the loop here.
-        already_seen = {}
+        self.already_seen = {}
 
-        def specialize_more_blocks():
-            while True:
-                # look for blocks not specialized yet
-                pending = [block for block in self.annotator.annotated
-                                 if block not in already_seen]
-                if not pending:
-                    break
-                # specialize all blocks in the 'pending' list
-                for block in pending:
-                    self.specialize_block(block)
-                    already_seen[block] = True
-                # make sure all reprs so far have had their setup() called
-                self.call_all_setups()
-
-        specialize_more_blocks()
+        self.specialize_more_blocks()
         self.exceptiondata.make_helpers(self)
-        specialize_more_blocks()   # for the helpers just made
+        self.specialize_more_blocks()   # for the helpers just made
+
+    def specialize_more_blocks(self):
+        while True:
+            # look for blocks not specialized yet
+            pending = [block for block in self.annotator.annotated
+                             if block not in self.already_seen]
+            if not pending:
+                break
+            # specialize all blocks in the 'pending' list
+            for block in pending:
+                self.specialize_block(block)
+                self.already_seen[block] = True
+            # make sure all reprs so far have had their setup() called
+            self.call_all_setups()
 
+        # re-raise the first TyperError caught
         if self.typererror:
             exc, value, tb = self.typererror
             self.typererror = None

Modified: pypy/dist/pypy/translator/c/test/test_genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_genc.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_genc.py	Thu Jul  7 12:39:48 2005
@@ -227,3 +227,22 @@
     assert res == str(lst)
     mallocs, frees = module.malloc_counters()
     assert mallocs == frees
+
+def test_rstr():
+    def fn(i):
+        return "hello"[i]
+    t = Translator(fn)
+    t.annotate([int])
+    t.specialize()
+
+    db = LowLevelDatabase(t)
+    entrypoint = db.get(pyobjectptr(fn))
+    db.complete()
+
+    module = compile_db(db)
+
+    f1 = getattr(module, entrypoint)
+    res = f1(1)
+    assert res == 'e'
+    mallocs, frees = module.malloc_counters()
+    assert mallocs == frees

Modified: pypy/dist/pypy/translator/c/wrapper.py
==============================================================================
--- pypy/dist/pypy/translator/c/wrapper.py	(original)
+++ pypy/dist/pypy/translator/c/wrapper.py	Thu Jul  7 12:39:48 2005
@@ -27,7 +27,7 @@
     FUNCTYPE = typeOf(f).TO
     assert len(FUNCTYPE.ARGS) == nb_positional_args + vararg
 
-    newops = LowLevelOpList(None)
+    newops = LowLevelOpList(translator.rtyper)
 
     # "def wrapper(self, args, kwds)"
     vself = Variable('self')
@@ -113,6 +113,11 @@
     block.closeblock(Link([vresult], wgraph.returnblock))
     checkgraph(wgraph)
 
+    if translator.rtyper is not None:
+        # the above convertvar()s may have created and annotated new helpers
+        # that need to be specialized now
+        translator.rtyper.specialize_more_blocks()
+
     return functionptr(FuncType([PyObjPtr,
                                  PyObjPtr,
                                  PyObjPtr],



More information about the Pypy-commit mailing list