Author: Amaury Forgeot d'Arc <amaur...@gmail.com>
Branch: const-correctness
Changeset: r66935:66c9a93ea930
Date: 2013-09-13 00:09 +0200
http://bitbucket.org/pypy/pypy/changeset/66c9a93ea930/

Log:    More fixes, seems to translate

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
@@ -930,6 +930,7 @@
 
     def descr_setstate(self, space, w_state):
         from rpython.rtyper.lltypesystem import rffi
+        from rpython.rlib.rawstorage import RAW_STORAGE_PTR
 
         shape = space.getitem(w_state, space.wrap(1))
         dtype = space.getitem(w_state, space.wrap(2))
@@ -937,9 +938,11 @@
         isfortran = space.getitem(w_state, space.wrap(3))
         storage = space.getitem(w_state, space.wrap(4))
 
+        raw_storage = rffi.str2charp(space.str_w(storage), 
track_allocation=False)
+        raw_storage = rffi.cast(RAW_STORAGE_PTR, raw_storage)
         self.implementation = W_NDimArray.from_shape_and_storage(space,
                 [space.int_w(i) for i in space.listview(shape)],
-                rffi.str2charp(space.str_w(storage), track_allocation=False),
+                raw_storage,
                 dtype, owning=True).implementation
 
     def descr___array_finalize__(self, space, w_obj):
diff --git a/rpython/rtyper/lltypesystem/lltype.py 
b/rpython/rtyper/lltypesystem/lltype.py
--- a/rpython/rtyper/lltypesystem/lltype.py
+++ b/rpython/rtyper/lltypesystem/lltype.py
@@ -104,6 +104,8 @@
         return not (self == other)
 
     def _is_convertible_from(self, other):
+        # Sometimes this function is called with something completely
+        # different, for example the string "??".
         if self == other:
             return True
         return remove_const(self) == other
diff --git a/rpython/rtyper/rmodel.py b/rpython/rtyper/rmodel.py
--- a/rpython/rtyper/rmodel.py
+++ b/rpython/rtyper/rmodel.py
@@ -125,7 +125,7 @@
                 realtype = typeOf(value)
             except (AssertionError, AttributeError, TypeError):
                 realtype = '???'
-            if realtype != lltype.remove_const(self.lowleveltype):
+            if not lltype.isConvertibleFrom(self.lowleveltype, realtype):
                 raise TyperError("convert_const(self = %r, value = %r)" % (
                     self, value))
         return value
diff --git a/rpython/rtyper/rptr.py b/rpython/rtyper/rptr.py
--- a/rpython/rtyper/rptr.py
+++ b/rpython/rtyper/rptr.py
@@ -112,7 +112,7 @@
 
 class __extend__(pairtype(PtrRepr, PtrRepr)):
     def convert_from_to((r_ptr1, r_ptr2), v, llop):
-        assert r_ptr1.lowleveltype == r_ptr2.lowleveltype
+        assert lltype.isConvertibleFrom(r_ptr2.lowleveltype, 
r_ptr1.lowleveltype)
         return v
 
 
diff --git a/rpython/rtyper/rtyper.py b/rpython/rtyper/rtyper.py
--- a/rpython/rtyper/rtyper.py
+++ b/rpython/rtyper/rtyper.py
@@ -23,7 +23,7 @@
 from rpython.rtyper.exceptiondata import ExceptionData
 from rpython.rtyper.lltypesystem.lltype import (Signed, Void, LowLevelType,
     Ptr, ContainerType, FuncType, functionptr, typeOf, RuntimeTypeInfo,
-    attachRuntimeTypeInfo, Primitive)
+    attachRuntimeTypeInfo, Primitive, isConvertibleFrom)
 from rpython.rtyper.rmodel import Repr, inputconst, BrokenReprTyperError
 from rpython.rtyper.typesystem import LowLevelTypeSystem
 from rpython.rtyper.normalizecalls import perform_normalizations
@@ -861,7 +861,7 @@
             if v is NotImplemented:
                 raise TyperError("don't know how to convert from %r to %r" %
                                  (r_from, r_to))
-            if v.concretetype != r_to.lowleveltype:
+            if not isConvertibleFrom(r_to.lowleveltype, v.concretetype):
                 raise TyperError("bug in conversion from %r to %r: "
                                  "returned a %r" % (r_from, r_to,
                                                     v.concretetype))
diff --git a/rpython/rtyper/tool/rffi_platform.py 
b/rpython/rtyper/tool/rffi_platform.py
--- a/rpython/rtyper/tool/rffi_platform.py
+++ b/rpython/rtyper/tool/rffi_platform.py
@@ -489,7 +489,7 @@
     def prepare_code(self):
         yield '#ifdef %s' % self.macro
         yield 'int i;'
-        yield 'char *p = %s;' % self.name
+        yield 'const char *p = %s;' % self.name
         yield 'dump("defined", 1);'
         yield 'for (i = 0; p[i] != 0; i++ ) {'
         yield '  printf("value_%d: %d\\n", i, (int)(unsigned char)p[i]);'
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to