[pypy-commit] pypy object-dtype2: custom gc trace translates and even gets called during gc.collect, but segfaults

mattip noreply at buildbot.pypy.org
Thu Mar 26 20:28:48 CET 2015


Author: mattip <matti.picus at gmail.com>
Branch: object-dtype2
Changeset: r76581:b49651372062
Date: 2015-03-26 21:27 +0200
http://bitbucket.org/pypy/pypy/changeset/b49651372062/

Log:	custom gc trace translates and even gets called during gc.collect,
	but segfaults

diff --git a/pypy/module/micronumpy/__init__.py b/pypy/module/micronumpy/__init__.py
--- a/pypy/module/micronumpy/__init__.py
+++ b/pypy/module/micronumpy/__init__.py
@@ -30,6 +30,9 @@
     for c in ['MAXDIMS', 'CLIP', 'WRAP', 'RAISE']:
         interpleveldefs[c] = 'space.wrap(constants.%s)' % c
 
+    def startup(self, space):
+        from pypy.module.micronumpy.concrete import _setup
+        _setup()
 
 class UMathModule(MixedModule):
     appleveldefs = {}
diff --git a/pypy/module/micronumpy/concrete.py b/pypy/module/micronumpy/concrete.py
--- a/pypy/module/micronumpy/concrete.py
+++ b/pypy/module/micronumpy/concrete.py
@@ -353,7 +353,7 @@
     for i in range(length):
         gcref = rffi.cast(llmemory.GCREF, storage)
         w_obj = cast_gcref_to_instance(W_Root, gcref)
-        print w_obj 
+        print 'tracing', w_obj 
         gc._trace_callback(callback, arg, storage)
         storage += step
     
@@ -363,6 +363,15 @@
     print 'registering custom trace for OBJECTSTORE'
     rgc.register_custom_trace_hook(OBJECTSTORE, lambda_customtrace)
 
+ at jit.dont_look_inside
+def _create_objectstore(storage, length, elsize):
+    gcstruct = lltype.malloc(OBJECTSTORE)
+    # JIT does not support cast_ptr_to_adr
+    gcstruct.storage = llmemory.cast_ptr_to_adr(storage)
+    print 'create gcstruct',gcstruct,'with storage',storage,'as',gcstruct.storage
+    gcstruct.length = length
+    gcstruct.step = elsize
+    return gcstruct
 
 
 class ConcreteArrayNotOwning(BaseConcreteArray):
@@ -414,12 +423,7 @@
             length = support.product(shape) 
             storage = dtype.itemtype.malloc(length * dtype.elsize, zero=zero)
             if dtype.num == NPY.OBJECT:
-                _setup() # make sure gc hook is registered
-                gcstruct = lltype.malloc(OBJECTSTORE)
-                gcstruct.storage = llmemory.cast_ptr_to_adr(storage)
-                print 'create gcstruct',gcstruct,'with storage',storage,'as',gcstruct.storage
-                gcstruct.length = length
-                gcstruct.step = dtype.elsize
+                gcstruct = _create_objectstore(storage, length, dtype.elsize)
         ConcreteArrayNotOwning.__init__(self, shape, dtype, order, strides, backstrides,
                                         storage)
         self.gcstruct = gcstruct
diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py
--- a/pypy/module/micronumpy/test/test_dtypes.py
+++ b/pypy/module/micronumpy/test/test_dtypes.py
@@ -1378,6 +1378,7 @@
         assert res[0] == "foobar"
 
     def test_keep_object_alive(self):
+        # XXX how can I run this test?
         import numpy as np
         import gc
         class O(object):
@@ -1387,5 +1388,4 @@
         a = np.array(fiveOs, dtype=object)
         del fiveOs
         gc.collect()
-        gc.collect()
         assert a[2].whatami() == 'an object'


More information about the pypy-commit mailing list