[pypy-commit] pypy object-dtype2: refactor fill, fix for value of pointers (arigato), take care around __del__, instantiate gcstruct in __init__
mattip
noreply at buildbot.pypy.org
Tue Mar 31 00:19:31 CEST 2015
Author: mattip <matti.picus at gmail.com>
Branch: object-dtype2
Changeset: r76650:8258a094da18
Date: 2015-03-31 01:20 +0300
http://bitbucket.org/pypy/pypy/changeset/8258a094da18/
Log: refactor fill, fix for value of pointers (arigato), take care around
__del__, instantiate gcstruct in __init__
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
@@ -346,8 +346,8 @@
def customtrace(gc, obj, callback, arg):
#debug_print('in customtrace w/obj', obj)
- length = rffi.cast(lltype.Signed, obj + offset_of_length)
- step = rffi.cast(lltype.Signed, obj + offset_of_step)
+ length = rffi.cast(rffi.SIGNEDP, obj + offset_of_length)[0]
+ step = rffi.cast(rffi.SIGNEDP, obj + offset_of_step)[0]
storage = obj + offset_of_storage
debug_print('tracing', length, 'objects in ndarray.storage')
i = 0
@@ -362,7 +362,6 @@
lambda_customtrace = lambda: customtrace
def _setup():
- print 'registering custom trace for OBJECTSTORE'
rgc.register_custom_trace_hook(OBJECTSTORE, lambda_customtrace)
@jit.dont_look_inside
@@ -393,7 +392,7 @@
def fill(self, space, box):
self.dtype.itemtype.fill(self.storage, self.dtype.elsize,
- box, 0, self.size, 0)
+ box, 0, self.size, 0, self.gcstruct)
def set_shape(self, space, orig_array, new_shape):
strides, backstrides = calc_strides(new_shape, self.dtype,
@@ -423,14 +422,18 @@
gcstruct = lltype.nullptr(OBJECTSTORE)
if storage == lltype.nullptr(RAW_STORAGE):
length = support.product(shape)
- storage = dtype.itemtype.malloc(length * dtype.elsize, zero=zero)
if dtype.num == NPY.OBJECT:
+ storage = dtype.itemtype.malloc(length * dtype.elsize, zero=True)
gcstruct = _create_objectstore(storage, length, dtype.elsize)
+ else:
+ storage = dtype.itemtype.malloc(length * dtype.elsize, zero=zero)
ConcreteArrayNotOwning.__init__(self, shape, dtype, order, strides, backstrides,
storage)
self.gcstruct = gcstruct
def __del__(self):
+ if self.gcstruct:
+ self.gcstruct.length = 0
free_raw_storage(self.storage, track_allocation=False)
@@ -469,6 +472,7 @@
parent = parent.parent # one level only
self.parent = parent
self.storage = parent.storage
+ self.gcstruct = parent.gcstruct
self.order = parent.order
self.dtype = dtype
self.size = support.product(shape) * self.dtype.elsize
@@ -526,6 +530,7 @@
class VoidBoxStorage(BaseConcreteArray):
def __init__(self, size, dtype):
self.storage = alloc_raw_storage(size)
+ self.gcstruct = lltype.nullptr(OBJECTSTORE)
self.dtype = dtype
self.size = size
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -196,7 +196,7 @@
with arr as storage:
self._write(storage, i, offset, self.unbox(box))
- def fill(self, storage, width, box, start, stop, offset):
+ def fill(self, storage, width, box, start, stop, offset, gcstruct):
value = self.unbox(box)
for i in xrange(start, stop, width):
self._write(storage, i, offset, value)
@@ -1157,7 +1157,7 @@
with arr as storage:
self._write(storage, i, offset, self.unbox(box))
- def fill(self, storage, width, box, start, stop, offset):
+ def fill(self, storage, width, box, start, stop, offset, gcstruct):
value = self.unbox(box)
for i in xrange(start, stop, width):
self._write(storage, i, offset, value)
@@ -1677,10 +1677,10 @@
w_obj = _all_objs_for_tests[res]
return w_obj
- def fill(self, storage, width, box, start, stop, offset):
+ def fill(self, storage, width, box, start, stop, offset, gcstruct):
value = self.unbox(box)
for i in xrange(start, stop, width):
- self._write(storage, i, offset, value, XXX)
+ self._write(storage, i, offset, value, gcstruct)
def unbox(self, box):
assert isinstance(box, self.BoxType)
@@ -1851,7 +1851,7 @@
def bool(self, v):
return bool(self.to_str(v))
- def fill(self, storage, width, box, start, stop, offset):
+ def fill(self, storage, width, box, start, stop, offset, gcstruct):
for i in xrange(start, stop, width):
self._store(storage, i, offset, box, width)
@@ -2006,7 +2006,7 @@
for k in range(size):
storage[k + i + ofs] = box_storage[k + box.ofs]
- def fill(self, storage, width, box, start, stop, offset):
+ def fill(self, storage, width, box, start, stop, offset, gcstruct):
assert isinstance(box, boxes.W_VoidBox)
assert width == box.dtype.elsize
for i in xrange(start, stop, width):
More information about the pypy-commit
mailing list