Author: mattip <matti.pi...@gmail.com> Branch: object-dtype2 Changeset: r76415:275dc69bef98 Date: 2015-03-16 19:04 +0200 http://bitbucket.org/pypy/pypy/changeset/275dc69bef98/
Log: wip - gc customtrace 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,6 +511,8 @@ 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 @@ -1,5 +1,5 @@ from pypy.interpreter.error import OperationError, oefmt -from rpython.rlib import jit +from rpython.rlib import jit, rgc from rpython.rlib.buffer import Buffer from rpython.rlib.debug import make_sure_not_resized from rpython.rlib.rawstorage import alloc_raw_storage, free_raw_storage, \ @@ -17,7 +17,7 @@ class BaseConcreteArray(object): _immutable_fields_ = ['dtype?', 'storage', 'start', 'size', 'shape[*]', - 'strides[*]', 'backstrides[*]', 'order'] + 'strides[*]', 'backstrides[*]', 'order', 'gcstruct'] start = 0 parent = None flags = 0 @@ -347,6 +347,7 @@ self.backstrides = backstrides self.storage = storage self.start = start + self.gcstruct = None def fill(self, space, box): self.dtype.itemtype.fill(self.storage, self.dtype.elsize, @@ -374,20 +375,32 @@ 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 if storage == lltype.nullptr(RAW_STORAGE): storage = dtype.itemtype.malloc(support.product(shape) * dtype.elsize, zero=zero) if dtype.num == NPY.OBJECT: - # Register a customtrace function for this storage - pass + rgc.register_custom_trace_hook(OBJECTSTORE, lambda_customtrace) + gcstruct = lltype.malloc(OBJECTSTORE) + gcstruct.storage = storage ConcreteArrayNotOwning.__init__(self, shape, dtype, order, strides, backstrides, storage) + self.gcstruct = gcstruct def __del__(self): + rgc. free_raw_storage(self.storage, track_allocation=False) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit