Author: Philip Jenvey <pjen...@underboss.org>
Branch: py3k
Changeset: r70321:170a3218cb26
Date: 2014-03-27 16:17 -0700
http://bitbucket.org/pypy/pypy/changeset/170a3218cb26/

Log:    merge default

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/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" %
@@ -642,30 +644,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
@@ -110,10 +110,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,15 +161,18 @@
         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_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.call_method(space.builtin, 'oct', self.descr_int(space))
@@ -178,8 +181,7 @@
         return space.call_method(space.builtin, '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/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')
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 str(exc.value).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)) == '0o13'
         assert oct(np.float32(11.6)) == '0o13'
         assert oct(np.complex64(11-12j)) == '0o13'
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to