[pypy-commit] pypy numpypy-problems: adding coerce to StringType has implications for W_FlexibleBox.__init__
mattip
noreply at buildbot.pypy.org
Tue Aug 21 23:05:31 CEST 2012
Author: mattip <matti.picus at gmail.com>
Branch: numpypy-problems
Changeset: r56781:42eb715f33bf
Date: 2012-08-21 23:42 +0300
http://bitbucket.org/pypy/pypy/changeset/42eb715f33bf/
Log: adding coerce to StringType has implications for
W_FlexibleBox.__init__
diff --git a/pypy/module/micronumpy/interp_boxes.py b/pypy/module/micronumpy/interp_boxes.py
--- a/pypy/module/micronumpy/interp_boxes.py
+++ b/pypy/module/micronumpy/interp_boxes.py
@@ -209,13 +209,15 @@
class W_FlexibleBox(W_GenericBox):
- def __init__(self, arr, ofs, dtype):
- self.arr = arr # we have to keep array alive
+ def __init__(self, arr, ofs=0, dtype=None):
+ self.value = arr # we have to keep array alive
self.ofs = ofs
+ if not dtype:
+ dtype = arr.dtype
self.dtype = dtype
def get_dtype(self, space):
- return self.arr.dtype
+ return self.value.dtype
@unwrap_spec(self=W_GenericBox)
def descr_index(space, self):
@@ -229,7 +231,7 @@
except KeyError:
raise OperationError(space.w_IndexError,
space.wrap("Field %s does not exist" % item))
- return dtype.itemtype.read(self.arr, self.ofs, ofs, dtype)
+ return dtype.itemtype.read(self.value, self.ofs, ofs, dtype)
@unwrap_spec(item=str)
def descr_setitem(self, space, item, w_value):
@@ -238,7 +240,7 @@
except KeyError:
raise OperationError(space.w_IndexError,
space.wrap("Field %s does not exist" % item))
- dtype.itemtype.store(self.arr, self.ofs, ofs,
+ dtype.itemtype.store(self.value, self.ofs, ofs,
dtype.coerce(space, w_value))
class W_CharacterBox(W_FlexibleBox):
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
@@ -900,6 +900,10 @@
T = lltype.Char
BoxType = interp_boxes.W_StringBox
+ @specialize.argtype(1)
+ def box(self, value):
+ return self.BoxType(rffi.cast(self.T, value), 0, None)
+
def _coerce(self, space, w_item):
return self.box(space.str_w(space.call_function(space.w_str, w_item)))
More information about the pypy-commit
mailing list