[pypy-commit] pypy object-dtype2: create a gc customtrace, improperly call the hook
mattip
noreply at buildbot.pypy.org
Thu Mar 19 18:46:46 CET 2015
Author: mattip <matti.picus at gmail.com>
Branch: object-dtype2
Changeset: r76477:383a91bc4802
Date: 2015-03-19 19:46 +0200
http://bitbucket.org/pypy/pypy/changeset/383a91bc4802/
Log: create a gc customtrace, improperly call the hook
diff --git a/pypy/module/micronumpy/compile.py b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -511,8 +511,6 @@
dtype = get_dtype_cache(interp.space).w_int64dtype
elif self.v == 'float':
dtype = get_dtype_cache(interp.space).w_float64dtype
- elif self.v == 'object':
- dtype = get_dtype_cache(interp.space).w_objectdtype
else:
raise BadToken('unknown v to dtype "%s"' % self.v)
return dtype
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
@@ -4,8 +4,8 @@
from rpython.rlib.debug import make_sure_not_resized
from rpython.rlib.rawstorage import alloc_raw_storage, free_raw_storage, \
raw_storage_getitem, raw_storage_setitem, RAW_STORAGE
-from rpython.rtyper.lltypesystem import rffi, lltype
-from pypy.module.micronumpy import support, loop
+from rpython.rtyper.lltypesystem import rffi, lltype, llmemory
+from pypy.module.micronumpy import support, loop, constants as NPY
from pypy.module.micronumpy.base import convert_to_array, W_NDimArray, \
ArrayArgumentException
from pypy.module.micronumpy.iterators import ArrayIter
@@ -13,6 +13,8 @@
RecordChunk, calc_strides, calc_new_strides, shape_agreement,
calculate_broadcast_strides, calc_backstrides)
from rpython.rlib.objectmodel import keepalive_until_here
+from rpython.rtyper.annlowlevel import cast_gcref_to_instance
+from pypy.interpreter.baseobjspace import W_Root
class BaseConcreteArray(object):
@@ -333,6 +335,35 @@
loop.setslice(space, impl.get_shape(), impl, self)
return impl
+OBJECTSTORE = lltype.GcStruct('ObjectStore',
+ ('length', lltype.Signed),
+ ('step', lltype.Signed),
+ ('storage', llmemory.Address),
+ rtti=True)
+offset_of_storage = llmemory.offsetof(OBJECTSTORE, 'storage')
+offset_of_length = llmemory.offsetof(OBJECTSTORE, 'length')
+offset_of_step = llmemory.offsetof(OBJECTSTORE, 'step')
+
+def customtrace(gc, obj, callback, arg):
+ print 'in customtrace w/obj',obj
+ length = rffi.cast(lltype.Signed, obj + offset_of_length)
+ step = rffi.cast(lltype.Signed, obj + offset_of_step)
+ storage = obj + offset_of_storage
+ print 'tracing', length, 'objects in ndarray.storage'
+ for i in range(length):
+ gcref = rffi.cast(llmemory.GCREF, storage)
+ w_obj = cast_gcref_to_instance(W_Root, gcref)
+ print w_obj
+ gc._trace_callback(callback, arg, storage)
+ storage += step
+
+lambda_customtrace = lambda: customtrace
+
+def _setup():
+ print 'registering custom trace for OBJECTSTORE'
+ rgc.register_custom_trace_hook(OBJECTSTORE, lambda_customtrace)
+
+
class ConcreteArrayNotOwning(BaseConcreteArray):
def __init__(self, shape, dtype, order, strides, backstrides, storage, start=0):
@@ -347,7 +378,7 @@
self.backstrides = backstrides
self.storage = storage
self.start = start
- self.gcstruct = None
+ self.gcstruct = lltype.nullptr(OBJECTSTORE)
def fill(self, space, box):
self.dtype.itemtype.fill(self.storage, self.dtype.elsize,
@@ -375,32 +406,25 @@
def base(self):
return None
-OBJECTSTORE = lltype.GcStruct('ObjectStore',
- ('storage', llmemory.Address),
- rtti=True)
-def customtrace(gc, obj, callback, arg):
- xxxx
-lambda_customtrace = lambda: customtrace
-
-
class ConcreteArray(ConcreteArrayNotOwning):
def __init__(self, shape, dtype, order, strides, backstrides,
storage=lltype.nullptr(RAW_STORAGE), zero=True):
-
- gcstruct = None
+ gcstruct = lltype.nullptr(OBJECTSTORE)
if storage == lltype.nullptr(RAW_STORAGE):
- storage = dtype.itemtype.malloc(support.product(shape) *
- dtype.elsize, zero=zero)
+ length = support.product(shape)
+ storage = dtype.itemtype.malloc(length * dtype.elsize, zero=zero)
if dtype.num == NPY.OBJECT:
- rgc.register_custom_trace_hook(OBJECTSTORE, lambda_customtrace)
+ _setup() # make sure gc hook is registered
gcstruct = lltype.malloc(OBJECTSTORE)
- gcstruct.storage = storage
+ 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
ConcreteArrayNotOwning.__init__(self, shape, dtype, order, strides, backstrides,
storage)
self.gcstruct = gcstruct
def __del__(self):
- rgc.
free_raw_storage(self.storage, track_allocation=False)
diff --git a/pypy/module/micronumpy/test/test_ndarray.py b/pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_ndarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -17,6 +17,7 @@
def __init__(self):
self.base = self
self.elsize = 1
+ self.num = 0
def create_slice(space, a, chunks):
More information about the pypy-commit
mailing list