Author: Romain Guillebert <romain...@gmail.com>
Branch: numpy-pickle
Changeset: r63891:44b9969e7d20
Date: 2013-05-06 17:10 +0200
http://bitbucket.org/pypy/pypy/changeset/44b9969e7d20/

Log:    Make the translator happy

diff --git a/pypy/module/micronumpy/arrayimpl/concrete.py 
b/pypy/module/micronumpy/arrayimpl/concrete.py
--- a/pypy/module/micronumpy/arrayimpl/concrete.py
+++ b/pypy/module/micronumpy/arrayimpl/concrete.py
@@ -325,11 +325,11 @@
         return None
 
 class ConcreteArray(ConcreteArrayNotOwning):
-    def __init__(self, shape, dtype, order, strides, backstrides, 
storage=None):
+    def __init__(self, shape, dtype, order, strides, backstrides, 
storage=lltype.nullptr(RAW_STORAGE)):
         null_storage = lltype.nullptr(RAW_STORAGE)
         ConcreteArrayNotOwning.__init__(self, shape, dtype, order, strides, 
backstrides,
                                         null_storage)
-        if storage is None:
+        if storage == lltype.nullptr(RAW_STORAGE):
             self.storage = dtype.itemtype.malloc(self.size)
         else:
             self.storage = storage
diff --git a/pypy/module/micronumpy/interp_dtype.py 
b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -132,14 +132,16 @@
 
     def set_fields(self, space, w_fields):
         if w_fields == space.w_None:
-            self.fields = {}
+            self.fields = None
         else:
             iter = space.iter(w_fields)
             while True:
                 try:
                     key = space.next(iter)
                     value = space.getitem(w_fields, key)
-                    self.fields[space.str_w(space.next(iter))] = 
space.int_w(space.getitem(value, 1)), space.getitem(value, 0)
+                    dtype = space.getitem(value, space.wrap(0))
+                    assert isinstance(dtype, W_Dtype)
+                    self.fields[space.str_w(space.next(iter))] = 
space.int_w(space.getitem(value, space.wrap(1))), dtype
                 except OperationError, e:
                     if not e.match(space, space.w_StopIteration):
                         raise
@@ -223,7 +225,9 @@
             #TODO: Change this when alignment is implemented :
             size = 0
             for key in self.fields:
-                size += self.fields[key].get_size()
+                dtype = self.fields[key][1]
+                assert isinstance(dtype, W_Dtype)
+                size += dtype.get_size()
             w_size = space.wrap(size)
             alignment = space.wrap(1)
         else:
@@ -240,14 +244,13 @@
         if space.int_w(space.getitem(w_data, space.wrap(0))) != 3:
             raise OperationError(space.w_NotImplementedError, 
space.wrap("Pickling protocol version not supported"))
 
-        self.native = space.getitem(w_data, space.wrap(1)) == byteorder_prefix
+        self.native = space.str_w(space.getitem(w_data, space.wrap(1))) == 
byteorder_prefix
 
         fieldnames = space.getitem(w_data, space.wrap(2))
         self.set_names(space, fieldnames)
 
         fields = space.getitem(w_data, space.wrap(3))
-        if fields != space.w_None:
-            self.set_fields(space, fields)
+        self.set_fields(space, fields)
 
 class W_ComplexDtype(W_Dtype):
     def __init__(self, itemtype, num, kind, name, char, w_box_type,
diff --git a/pypy/module/micronumpy/interp_numarray.py 
b/pypy/module/micronumpy/interp_numarray.py
--- a/pypy/module/micronumpy/interp_numarray.py
+++ b/pypy/module/micronumpy/interp_numarray.py
@@ -778,8 +778,13 @@
     def descr_reduce(self, space):
         from rpython.rtyper.lltypesystem import rffi
         from rpython.rlib.rstring import StringBuilder
+        from pypy.interpreter.mixedmodule import MixedModule
 
-        reconstruct = 
space.getbuiltinmodule("_numpypy").get("multiarray").get("_reconstruct")
+        numpypy = space.getbuiltinmodule("_numpypy")
+        assert isinstance(numpypy, MixedModule)
+        multiarray = numpypy.get("multiarray")
+        assert isinstance(multiarray, MixedModule)
+        reconstruct = multiarray.get("_reconstruct")
 
         parameters = space.newtuple([space.gettypefor(W_NDimArray), 
space.newtuple([space.wrap(0)]), space.wrap("b")])
 
@@ -801,6 +806,7 @@
 
         shape = space.getitem(w_state, space.wrap(1))
         dtype = space.getitem(w_state, space.wrap(2))
+        assert isinstance(dtype, interp_dtype.W_Dtype)
         isfortran = space.getitem(w_state, space.wrap(3))
         storage = space.getitem(w_state, space.wrap(4))
 
@@ -1035,6 +1041,7 @@
     return space.wrap(arr)
 
 def _reconstruct(space, w_subtype, w_shape, w_dtype):
+    assert isinstance(w_dtype, interp_dtype.W_Dtype)
     return descr_new_array(space, w_subtype, w_shape, w_dtype)
 
 W_FlatIterator.typedef = TypeDef(
diff --git a/rpython/rtyper/lltypesystem/rffi.py 
b/rpython/rtyper/lltypesystem/rffi.py
--- a/rpython/rtyper/lltypesystem/rffi.py
+++ b/rpython/rtyper/lltypesystem/rffi.py
@@ -696,7 +696,10 @@
     def str2charp(s, track_allocation=True):
         """ str -> char*
         """
-        array = lltype.malloc(TYPEP.TO, len(s) + 1, flavor='raw', 
track_allocation=track_allocation)
+        if track_allocation:
+            array = lltype.malloc(TYPEP.TO, len(s) + 1, flavor='raw', 
track_allocation=True)
+        else:
+            array = lltype.malloc(TYPEP.TO, len(s) + 1, flavor='raw', 
track_allocation=False)
         i = len(s)
         array[i] = lastchar
         i -= 1
@@ -704,10 +707,13 @@
             array[i] = s[i]
             i -= 1
         return array
-    str2charp._annenforceargs_ = [strtype]
+    str2charp._annenforceargs_ = [strtype, bool]
 
     def free_charp(cp, track_allocation=True):
-        lltype.free(cp, flavor='raw', track_allocation=track_allocation)
+        if track_allocation:
+            lltype.free(cp, flavor='raw', track_allocation=True)
+        else:
+            lltype.free(cp, flavor='raw', track_allocation=False)
 
     # char* -> str
     # doesn't free char*
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to