Commits

Romain Guillebert committed 44b9969

Make the translator happy

Comments (0)

Files changed (4)

pypy/module/micronumpy/arrayimpl/concrete.py

         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

pypy/module/micronumpy/interp_dtype.py

 
     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
             #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:
         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,

pypy/module/micronumpy/interp_numarray.py

     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")])
 
 
         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))
 
     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(

rpython/rtyper/lltypesystem/rffi.py

     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
             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*