[pypy-svn] r21840 - in pypy/dist/pypy/translator/c: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Mon Jan 9 17:23:13 CET 2006


Author: cfbolz
Date: Mon Jan  9 17:23:12 2006
New Revision: 21840

Modified:
   pypy/dist/pypy/translator/c/funcgen.py
   pypy/dist/pypy/translator/c/test/test_lladdresses.py
Log:
implement flavored_malloc and flavored_free in genc, so far only with the "raw"
flavor.


Modified: pypy/dist/pypy/translator/c/funcgen.py
==============================================================================
--- pypy/dist/pypy/translator/c/funcgen.py	(original)
+++ pypy/dist/pypy/translator/c/funcgen.py	Mon Jan  9 17:23:12 2006
@@ -434,7 +434,9 @@
         line = '%s\n%s' % (line, self.check_directcall_result(op, err))
         return line
 
-    OP_INDIRECT_CALL = OP_DIRECT_CALL # XXX for now
+    # the following works since the extra arguments that indirect_call has
+    # is of type Void, which is removed by OP_DIRECT_CALL
+    OP_INDIRECT_CALL = OP_DIRECT_CALL
 
     def check_directcall_result(self, op, err):
         return 'if (RPyExceptionOccurred())\n\tFAIL(%s);' % err
@@ -558,6 +560,27 @@
         result += '\n%s->%s = %s;' % (eresult, lenfld, elength)
         return result
 
+    def OP_FLAVORED_MALLOC(self, op, err):
+        print op
+        TYPE = self.lltypemap(op.result).TO
+        typename = self.db.gettype(TYPE)
+        eresult = self.expr(op.result)
+        esize = 'sizeof(%s)' % cdecl(typename, '')
+        flavor = op.args[0].value
+        if flavor == "raw": 
+            return "OP_RAW_MALLOC(%s, %s, %s);" % (esize, eresult, err) 
+        else:
+            raise NotImplementedError
+
+    def OP_FLAVORED_FREE(self, op, err):
+        flavor = op.args[0].value
+        if flavor == "raw":
+            return "OP_RAW_FREE(%s, %s, %s)" % (self.expr(op.args[1]),
+                                                self.expr(op.result),
+                                                err)
+        else:
+            raise NotImplementedError
+
     def OP_CAST_POINTER(self, op, err):
         TYPE = self.lltypemap(op.result)
         typename = self.db.gettype(TYPE)

Modified: pypy/dist/pypy/translator/c/test/test_lladdresses.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_lladdresses.py	(original)
+++ pypy/dist/pypy/translator/c/test/test_lladdresses.py	Mon Jan  9 17:23:12 2006
@@ -1,6 +1,7 @@
 from pypy.rpython.memory.lladdress import *
 from pypy.annotation.model import SomeAddress, SomeChar
 from pypy.translator.c.test.test_genc import compile
+from pypy.rpython.objectmodel import free_non_gc_object
 
 def test_null():
     def f():
@@ -86,3 +87,16 @@
     fc = compile(f, [])
     res = fc()
     assert res == int('011100' * 2, 2)
+
+def test_flavored_malloc():
+    class A(object):
+        _alloc_flavor_ = "raw"
+        def __init__(self, val):
+            self.val = val
+    def f(x):
+        a = A(x + 1)
+        result = a.val
+        free_non_gc_object(a)
+        return result
+    fn = compile(f, [int])
+    assert fn(1) == 2



More information about the Pypy-commit mailing list