Author: Alex Gaynor <[email protected]>
Branch: malloc-value
Changeset: r48068:b2ed57719eb3
Date: 2011-10-14 16:28 -0400
http://bitbucket.org/pypy/pypy/changeset/b2ed57719eb3/

Log:    failing test, not sure where in the annotator/rtyper I need to
        modify

diff --git a/pypy/rpython/lltypesystem/lltype.py 
b/pypy/rpython/lltypesystem/lltype.py
--- a/pypy/rpython/lltypesystem/lltype.py
+++ b/pypy/rpython/lltypesystem/lltype.py
@@ -1960,6 +1960,8 @@
         initialization = 'example'
     elif flavor == 'raw':
         initialization = 'raw'
+    elif flavor == 'value':
+        initialization = 'value'
     else:
         initialization = 'malloc'
     if isinstance(T, Struct):
@@ -1973,6 +1975,8 @@
         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 T._gckind == 'gc' and flavor == 'value':
+        raise TypeError("Can't malloc with flavor value on a gc struct/array")
     if flavor == "raw" and not immortal and track_allocation:
         leakfinder.remember_malloc(o, framedepth=2)
     solid = immortal or not flavor.startswith('gc') # immortal or non-gc case
diff --git a/pypy/rpython/lltypesystem/test/test_lltype.py 
b/pypy/rpython/lltypesystem/test/test_lltype.py
--- a/pypy/rpython/lltypesystem/test/test_lltype.py
+++ b/pypy/rpython/lltypesystem/test/test_lltype.py
@@ -820,6 +820,9 @@
     assert c.real == 4.0
     assert c.imag == 5.0
 
+    S = GcStruct("S", ("x", Signed))
+    py.test.raises(TypeError, malloc, S, flavor="value")
+
 
 class TestTrackAllocation:
     def test_automatic_tracking(self):
diff --git a/pypy/translator/c/test/test_lltyped.py 
b/pypy/translator/c/test/test_lltyped.py
--- a/pypy/translator/c/test/test_lltyped.py
+++ b/pypy/translator/c/test/test_lltyped.py
@@ -312,14 +312,14 @@
         from pypy.rpython.lltypesystem.rstr import STR
         from pypy.rpython.lltypesystem import rffi, llmemory, lltype
         P = lltype.Ptr(lltype.FixedSizeArray(lltype.Char, 1))
-        
+
         def f():
             a = llstr("xyz")
             b = (llmemory.cast_ptr_to_adr(a) + llmemory.offsetof(STR, 'chars')
                  + llmemory.itemoffsetof(STR.chars, 0))
             buf = rffi.cast(rffi.VOIDP, b)
             return buf[2]
-        
+
         fn = self.getcompiled(f, [])
         res = fn()
         assert res == 'z'
@@ -436,6 +436,24 @@
         res = fn(100)
         assert res == 42
 
+    def test_malloc_value(self):
+        T = Struct('complex', ('real', Float), ('imag', Float))
+        def f(n):
+            x = malloc(T, flavor="value")
+            x.real = 0.0
+            x.imag = 0.0
+            for i in range(n):
+                z = malloc(T, flavor="value")
+                z.real = x.real
+                z.imag = x.imag
+                x = z
+            return x.real + x.real
+
+        fn = self.getcompiled(f, [int])
+        res = fn(100)
+        assert res == 200
+
+
     def test_arithmetic_cornercases(self):
         import operator, sys
         from pypy.rlib.unroll import unrolling_iterable
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to