[pypy-commit] pypy win32-fixes4: reopen branch

mattip noreply at buildbot.pypy.org
Fri Mar 28 08:22:00 CET 2014


Author: mattip <matti.picus at gmail.com>
Branch: win32-fixes4
Changeset: r70312:9ea80c1048f7
Date: 2014-03-28 09:39 +0300
http://bitbucket.org/pypy/pypy/changeset/9ea80c1048f7/

Log:	reopen branch

diff --git a/lib-python/2.7/test/test_genericpath.py b/lib-python/2.7/test/test_genericpath.py
--- a/lib-python/2.7/test/test_genericpath.py
+++ b/lib-python/2.7/test/test_genericpath.py
@@ -232,9 +232,11 @@
         try:
             fsencoding = test_support.TESTFN_ENCODING or "ascii"
             asciival = unicwd.encode(fsencoding)
-            v = asciival.find('?')
-            if v >= 0:
-                raise UnicodeEncodeError(fsencoding, unicwd, v, v, asciival)
+            if fsencoding == "mbcs":
+                # http://bugs.python.org/issue850997
+                v = asciival.find('?')
+                if v >= 0:
+                    raise UnicodeEncodeError(fsencoding, unicwd, v, v, asciival)
         except (AttributeError, UnicodeEncodeError):
             # FS encoding is probably ASCII or windows and codepage is non-Latin1
             pass
diff --git a/pypy/doc/stackless.rst b/pypy/doc/stackless.rst
--- a/pypy/doc/stackless.rst
+++ b/pypy/doc/stackless.rst
@@ -211,6 +211,9 @@
 
 .. __: `recursion depth limit`_
 
+We also do not include any of the recent API additions to Stackless
+Python, like ``set_atomic()``.  Contributions welcome.
+
 
 Recursion depth limit
 +++++++++++++++++++++
diff --git a/pypy/module/_codecs/test/test_codecs.py b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -700,17 +700,17 @@
             return
         toencode = u'caf\xe9', 'caf\xe9'
         try:
-            #test for non-latin1 codepage, more general test needed
+            # test for non-latin1 codepage, more general test needed
             import _winreg
-            key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 
+            key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
                         r'System\CurrentControlSet\Control\Nls\CodePage')
-            if _winreg.QueryValueEx(key, 'ACP')[0] == u'1255': #non-latin1
+            if _winreg.QueryValueEx(key, 'ACP')[0] == u'1255':  # non-latin1
                 toencode = u'caf\xbf','caf\xbf'
         except:
             assert False, 'cannot test mbcs on this windows system, check code page'
         assert u'test'.encode('mbcs') == 'test'
         assert toencode[0].encode('mbcs') == toencode[1]
-        assert u'\u040a'.encode('mbcs') == '?' # some cyrillic letter
+        assert u'\u040a'.encode('mbcs') == '?'  # some cyrillic letter
         assert 'cafx\e9'.decode('mbcs') == u'cafx\e9'
 
     def test_bad_handler_string_result(self):
diff --git a/pypy/module/cpyext/test/test_cpyext.py b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -64,6 +64,8 @@
         kwds["libraries"] = [api_library]
         # '%s' undefined; assuming extern returning int
         kwds["compile_extra"] = ["/we4013"]
+        # tests are not strictly ansi C compliant, compile as C++
+        kwds["compile_extra"].append("/TP")
         # prevent linking with PythonXX.lib
         w_maj, w_min = space.fixedview(space.sys.get('version_info'), 5)[:2]
         kwds["link_extra"] = ["/NODEFAULTLIB:Python%d%d.lib" %
@@ -640,30 +642,30 @@
         body = """
         static PyObject* foo_pi(PyObject* self, PyObject *args)
         {
-            PyObject *true = Py_True;
-            int refcnt = true->ob_refcnt;
+            PyObject *true_obj = Py_True;
+            int refcnt = true_obj->ob_refcnt;
             int refcnt_after;
-            Py_INCREF(true);
-            Py_INCREF(true);
-            PyBool_Check(true);
-            refcnt_after = true->ob_refcnt;
-            Py_DECREF(true);
-            Py_DECREF(true);
+            Py_INCREF(true_obj);
+            Py_INCREF(true_obj);
+            PyBool_Check(true_obj);
+            refcnt_after = true_obj->ob_refcnt;
+            Py_DECREF(true_obj);
+            Py_DECREF(true_obj);
             fprintf(stderr, "REFCNT %i %i\\n", refcnt, refcnt_after);
             return PyBool_FromLong(refcnt_after == refcnt+2 && refcnt < 3);
         }
         static PyObject* foo_bar(PyObject* self, PyObject *args)
         {
-            PyObject *true = Py_True;
+            PyObject *true_obj = Py_True;
             PyObject *tup = NULL;
-            int refcnt = true->ob_refcnt;
+            int refcnt = true_obj->ob_refcnt;
             int refcnt_after;
 
             tup = PyTuple_New(1);
-            Py_INCREF(true);
-            if (PyTuple_SetItem(tup, 0, true) < 0)
+            Py_INCREF(true_obj);
+            if (PyTuple_SetItem(tup, 0, true_obj) < 0)
                 return NULL;
-            refcnt_after = true->ob_refcnt;
+            refcnt_after = true_obj->ob_refcnt;
             Py_DECREF(tup);
             fprintf(stderr, "REFCNT2 %i %i\\n", refcnt, refcnt_after);
             return PyBool_FromLong(refcnt_after == refcnt);
diff --git a/pypy/module/cpyext/test/test_intobject.py b/pypy/module/cpyext/test/test_intobject.py
--- a/pypy/module/cpyext/test/test_intobject.py
+++ b/pypy/module/cpyext/test/test_intobject.py
@@ -107,10 +107,10 @@
             } EnumObject;
 
             static void
-            enum_dealloc(EnumObject *op)
+            enum_dealloc(PyObject *op)
             {
-                    Py_DECREF(op->ob_name);
-                    Py_TYPE(op)->tp_free((PyObject *)op);
+                    Py_DECREF(((EnumObject *)op)->ob_name);
+                    Py_TYPE(op)->tp_free(op);
             }
 
             static PyMemberDef enum_members[] = {
diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py
--- a/pypy/module/micronumpy/boxes.py
+++ b/pypy/module/micronumpy/boxes.py
@@ -161,22 +161,25 @@
         return space.index(self.item(space))
 
     def descr_int(self, space):
-        if isinstance(self, W_UnsignedIntegerBox):
-            box = self.convert_to(space, W_UInt64Box._get_dtype(space))
+        if isinstance(self, W_ComplexFloatingBox):
+            box = self.descr_get_real(space)
         else:
-            box = self.convert_to(space, W_Int64Box._get_dtype(space))
-        return space.int(box.item(space))
+            box = self
+        return space.call_function(space.w_int, box.item(space))
 
     def descr_long(self, space):
-        if isinstance(self, W_UnsignedIntegerBox):
-            box = self.convert_to(space, W_UInt64Box._get_dtype(space))
+        if isinstance(self, W_ComplexFloatingBox):
+            box = self.descr_get_real(space)
         else:
-            box = self.convert_to(space, W_Int64Box._get_dtype(space))
-        return space.long(box.item(space))
+            box = self
+        return space.call_function(space.w_long, box.item(space))
 
     def descr_float(self, space):
-        box = self.convert_to(space, W_Float64Box._get_dtype(space))
-        return space.float(box.item(space))
+        if isinstance(self, W_ComplexFloatingBox):
+            box = self.descr_get_real(space)
+        else:
+            box = self
+        return space.call_function(space.w_float, box.item(space))
 
     def descr_oct(self, space):
         return space.oct(self.descr_int(space))
@@ -185,8 +188,7 @@
         return space.hex(self.descr_int(space))
 
     def descr_nonzero(self, space):
-        dtype = self.get_dtype(space)
-        return space.wrap(dtype.itemtype.bool(self))
+        return space.wrap(self.get_dtype(space).itemtype.bool(self))
 
     def _unaryop_impl(ufunc_name):
         def impl(self, space, w_out=None):
diff --git a/pypy/module/micronumpy/ctors.py b/pypy/module/micronumpy/ctors.py
--- a/pypy/module/micronumpy/ctors.py
+++ b/pypy/module/micronumpy/ctors.py
@@ -48,6 +48,8 @@
         order = 'C'
     else:
         order = space.str_w(w_order)
+        if order == 'K':
+            order = 'C'
         if order != 'C':  # or order != 'F':
             raise oefmt(space.w_ValueError, "Unknown order: %s", order)
 
@@ -100,7 +102,7 @@
 @unwrap_spec(subok=bool)
 def empty_like(space, w_a, w_dtype=None, w_order=None, subok=True):
     w_a = convert_to_array(space, w_a)
-    if w_dtype is None:
+    if space.is_none(w_dtype):
         dtype = w_a.get_dtype()
     else:
         dtype = space.interp_w(descriptor.W_Dtype,
diff --git a/pypy/module/micronumpy/ndarray.py b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -185,7 +185,7 @@
             return chunks.apply(space, self)
         shape = res_shape + self.get_shape()[len(indexes):]
         w_res = W_NDimArray.from_shape(space, shape, self.get_dtype(),
-                                     self.get_order(), w_instance=self)
+                                       self.get_order(), w_instance=self)
         if not w_res.get_size():
             return w_res
         return loop.getitem_array_int(space, self, w_res, iter_shape, indexes,
@@ -201,6 +201,8 @@
             view = chunks.apply(space, self)
             view.implementation.setslice(space, val_arr)
             return
+        if support.product(iter_shape) == 0:
+            return
         loop.setitem_array_int(space, self, iter_shape, indexes, val_arr,
                                prefix)
 
@@ -1169,7 +1171,7 @@
             raise OperationError(space.w_TypeError, space.wrap(
                 "numpy scalars from buffers not supported yet"))
         totalsize = support.product(shape) * dtype.elsize
-        if totalsize+offset > buf.getlength():
+        if totalsize + offset > buf.getlength():
             raise OperationError(space.w_TypeError, space.wrap(
                 "buffer is too small for requested array"))
         storage = rffi.cast(RAW_STORAGE_PTR, raw_ptr)
diff --git a/pypy/module/micronumpy/test/test_ndarray.py b/pypy/module/micronumpy/test/test_ndarray.py
--- a/pypy/module/micronumpy/test/test_ndarray.py
+++ b/pypy/module/micronumpy/test/test_ndarray.py
@@ -334,6 +334,15 @@
         b = array(a, dtype=float)
         assert b == 123.0
 
+        a = array([[123, 456]])
+        assert a.flags['C']
+        b = array(a, order='K')
+        assert b.flags['C']
+        assert (b == a).all()
+        b = array(a, order='K', copy=True)
+        assert b.flags['C']
+        assert (b == a).all()
+
     def test_dtype_attribute(self):
         import numpy as np
         a = np.array(40000, dtype='uint16')
@@ -404,6 +413,8 @@
         assert b.shape == a.shape
         assert b.dtype == a.dtype
         assert b[0,0] != 1
+        b = np.empty_like(np.array(True), dtype=None)
+        assert b.dtype is np.dtype(bool)
         b = np.empty_like(a, dtype='i4')
         assert b.shape == a.shape
         assert b.dtype == np.dtype('i4')
@@ -2369,6 +2380,19 @@
         assert b.shape == b[...].shape
         assert (b == b[...]).all()
 
+    def test_empty_indexing(self):
+        import numpy as np
+        r = np.ones(3)
+        ind = np.array([], np.int32)
+        tmp = np.array([], np.float64)
+        assert r[ind].shape == (0,)
+        r[ind] = 0
+        assert (r == np.ones(3)).all()
+        r[ind] = tmp
+        assert (r == np.ones(3)).all()
+        r[[]] = 0
+        assert (r == np.ones(3)).all()
+
 
 class AppTestNumArrayFromBuffer(BaseNumpyAppTest):
     spaceconfig = dict(usemodules=["micronumpy", "array", "mmap"])
diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py
--- a/pypy/module/micronumpy/test/test_scalar.py
+++ b/pypy/module/micronumpy/test/test_scalar.py
@@ -36,6 +36,24 @@
         exc = raises(ValueError, "int(np.str_('abc'))")
         assert exc.value.message.startswith('invalid literal for int()')
         assert int(np.uint64((2<<63) - 1)) == (2<<63) - 1
+        exc = raises(ValueError, "int(np.float64(np.nan))")
+        assert str(exc.value) == "cannot convert float NaN to integer"
+        exc = raises(OverflowError, "int(np.float64(np.inf))")
+        assert str(exc.value) == "cannot convert float infinity to integer"
+        assert int(np.float64(1e100)) == int(1e100)
+        assert long(np.float64(1e100)) == int(1e100)
+        assert int(np.complex128(1e100+2j)) == int(1e100)
+        exc = raises(OverflowError, "int(np.complex64(1e100+2j))")
+        assert str(exc.value) == "cannot convert float infinity to integer"
+        assert int(np.str_('100000000000000000000')) == 100000000000000000000
+        assert long(np.str_('100000000000000000000')) == 100000000000000000000
+
+        assert float(np.float64(1e100)) == 1e100
+        assert float(np.complex128(1e100+2j)) == 1e100
+        assert float(np.str_('1e100')) == 1e100
+        assert float(np.str_('inf')) == np.inf
+        assert str(float(np.float64(np.nan))) == 'nan'
+
         assert oct(np.int32(11)) == '013'
         assert oct(np.float32(11.6)) == '013'
         assert oct(np.complex64(11-12j)) == '013'
diff --git a/rpython/jit/backend/llgraph/runner.py b/rpython/jit/backend/llgraph/runner.py
--- a/rpython/jit/backend/llgraph/runner.py
+++ b/rpython/jit/backend/llgraph/runner.py
@@ -13,6 +13,7 @@
 from rpython.rtyper.llinterp import LLInterpreter, LLException
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi, rclass, rstr
 
+from rpython.rlib.clibffi import FFI_DEFAULT_ABI
 from rpython.rlib.rarithmetic import ovfcheck, r_uint, r_ulonglong
 from rpython.rlib.rtimer import read_timestamp
 
@@ -66,7 +67,6 @@
         self.args = args
 
 class CallDescr(AbstractDescr):
-    from rpython.rlib.clibffi import FFI_DEFAULT_ABI
     def __init__(self, RESULT, ARGS, extrainfo, ABI=FFI_DEFAULT_ABI):
         self.RESULT = RESULT
         self.ARGS = ARGS
diff --git a/rpython/rlib/test/test_rposix.py b/rpython/rlib/test/test_rposix.py
--- a/rpython/rlib/test/test_rposix.py
+++ b/rpython/rlib/test/test_rposix.py
@@ -59,9 +59,9 @@
         def f():
             return rposix.stat(self.path).st_mtime
         if sys.platform == 'win32':
-            #double vs. float, be satisfied with sub-millisec resolution
+            # double vs. float, be satisfied with sub-millisec resolution
             assert abs(interpret(f, []) - os.stat(self.ufilename).st_mtime) < 1e-4
-        else:    
+        else:
             assert interpret(f, []) == os.stat(self.ufilename).st_mtime
 
     def test_access(self):
diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py b/rpython/rtyper/lltypesystem/ll2ctypes.py
--- a/rpython/rtyper/lltypesystem/ll2ctypes.py
+++ b/rpython/rtyper/lltypesystem/ll2ctypes.py
@@ -358,7 +358,6 @@
 
     if isinstance(T, lltype.Ptr):
         if isinstance(T.TO, lltype.FuncType):
-            
             functype = ctypes.CFUNCTYPE
             if sys.platform == 'win32':
                 from rpython.rlib.clibffi import FFI_STDCALL, FFI_DEFAULT_ABI


More information about the pypy-commit mailing list