Author: Carl Friedrich Bolz <[email protected]>
Branch: guard-compatible
Changeset: r83198:1fa01a98cde5
Date: 2016-03-20 19:19 +0100
http://bitbucket.org/pypy/pypy/changeset/1fa01a98cde5/
Log: merge default
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -11,3 +11,15 @@
The backend manages 64-bit values in the literal pool of the assembly instead
of loading them as immediates.
It includes a simplification for the operation 'zero_array'. Start and length
parameters are bytes instead of size.
+.. branch: remove-py-log
+
+Replace py.log with something simpler, which should speed up logging
+
+.. branch: where_1_arg
+
+Implemented numpy.where for 1 argument (thanks sergem)
+
+.. branch: fix_indexing_by_numpy_int
+
+Implement yet another strange numpy indexing compatibility; indexing by a
scalar
+returns a scalar
diff --git a/pypy/module/micronumpy/arrayops.py
b/pypy/module/micronumpy/arrayops.py
--- a/pypy/module/micronumpy/arrayops.py
+++ b/pypy/module/micronumpy/arrayops.py
@@ -71,8 +71,8 @@
"""
if space.is_none(w_y):
if space.is_none(w_x):
- raise OperationError(space.w_NotImplementedError, space.wrap(
- "1-arg where unsupported right now"))
+ arr = convert_to_array(space, w_arr)
+ return arr.descr_nonzero(space)
raise OperationError(space.w_ValueError, space.wrap(
"Where should be called with either 1 or 3 arguments"))
if space.is_none(w_x):
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
@@ -267,6 +267,11 @@
"interpreted as a valid boolean index")
elif isinstance(w_idx, boxes.W_GenericBox):
w_ret = self.getitem_array_int(space, w_idx)
+
+ if isinstance(w_idx, boxes.W_IntegerBox):
+ # if w_idx is integer then getitem_array_int must contain a
single value and we must return it.
+ # Get 0-th element of the w_ret.
+ w_ret = w_ret.implementation.descr_getitem(space, self,
space.wrap(0))
else:
try:
w_ret = self.implementation.descr_getitem(space, self, w_idx)
diff --git a/pypy/module/micronumpy/test/test_arrayops.py
b/pypy/module/micronumpy/test/test_arrayops.py
--- a/pypy/module/micronumpy/test/test_arrayops.py
+++ b/pypy/module/micronumpy/test/test_arrayops.py
@@ -54,8 +54,24 @@
assert (where(False, 1, [1, 2, 3]) == [1, 2, 3]).all()
assert (where([1, 2, 3], True, False) == [True, True, True]).all()
- #def test_where_1_arg(self):
- # xxx
+ def test_where_1_arg(self):
+ from numpy import where, array
+
+ result = where([1,0,1])
+
+ assert isinstance(result, tuple)
+ assert len(result) == 1
+ assert (result[0] == array([0, 2])).all()
+
+ def test_where_1_arg_2d(self):
+ from numpy import where, array
+
+ result = where([[1,0,1],[2,-1,-1]])
+
+ assert isinstance(result, tuple)
+ assert len(result) == 2
+ assert (result[0] == array([0, 0, 1, 1, 1])).all()
+ assert (result[1] == array([0, 2, 0, 1, 2])).all()
def test_where_invalidates(self):
from numpy import where, ones, zeros, array
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
@@ -3437,6 +3437,21 @@
a.itemset(1, 2, 100)
assert a[1, 2] == 100
+ def test_index_int(self):
+ import numpy as np
+ a = np.array([10, 20, 30], dtype='int64')
+ res = a[np.int64(1)]
+ assert isinstance(res, np.int64)
+ assert res == 20
+ res = a[np.int32(0)]
+ assert isinstance(res, np.int64)
+ assert res == 10
+
+ b = a.astype(float)
+ res = b[np.int64(1)]
+ assert res == 20.0
+ assert isinstance(res, np.float64)
+
def test_index(self):
import numpy as np
a = np.array([1], np.uint16)
@@ -3448,6 +3463,7 @@
assert exc.value.message == 'only integer arrays with one element
' \
'can be converted to an index'
+
def test_int_array_index(self):
from numpy import array
assert (array([])[[]] == []).all()
diff --git a/pypy/module/thread/test/test_lock.py
b/pypy/module/thread/test/test_lock.py
--- a/pypy/module/thread/test/test_lock.py
+++ b/pypy/module/thread/test/test_lock.py
@@ -3,6 +3,7 @@
import sys, os
from pypy.module.thread.test.support import GenericTestThread
from rpython.translator.c.test.test_genc import compile
+import platform
class AppTestLock(GenericTestThread):
@@ -63,6 +64,8 @@
else:
assert self.runappdirect, "missing lock._py3k_acquire()"
+ @py.test.mark.xfail(platform.machine() == 's390x',
+ reason='may fail this test under heavy load')
def test_ping_pong(self):
# The purpose of this test is that doing a large number of ping-pongs
# between two threads, using locks, should complete in a reasonable
diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py
--- a/rpython/memory/gc/incminimark.py
+++ b/rpython/memory/gc/incminimark.py
@@ -1654,15 +1654,15 @@
else:
self.nursery_objects_shadows.clear()
#
+ # visit the P and O lists from rawrefcount, if enabled.
+ if self.rrc_enabled:
+ self.rrc_minor_collection_free()
+ #
# Walk the list of young raw-malloced objects, and either free
# them or make them old.
if self.young_rawmalloced_objects:
self.free_young_rawmalloced_objects()
#
- # visit the P and O lists from rawrefcount, if enabled.
- if self.rrc_enabled:
- self.rrc_minor_collection_free()
- #
# All live nursery objects are out of the nursery or pinned inside
# the nursery. Create nursery barriers to protect the pinned objects,
# fill the rest of the nursery with zeros and reset the current nursery
diff --git a/rpython/memory/gc/test/test_rawrefcount.py
b/rpython/memory/gc/test/test_rawrefcount.py
--- a/rpython/memory/gc/test/test_rawrefcount.py
+++ b/rpython/memory/gc/test/test_rawrefcount.py
@@ -29,7 +29,8 @@
assert count2 - count1 == expected_trigger
def _rawrefcount_pair(self, intval, is_light=False, is_pyobj=False,
- create_old=False, create_immortal=False):
+ create_old=False, create_immortal=False,
+ force_external=False):
if is_light:
rc = REFCNT_FROM_PYPY_LIGHT
else:
@@ -40,7 +41,13 @@
if create_immortal:
p1 = lltype.malloc(S, immortal=True)
else:
- p1 = self.malloc(S)
+ saved = self.gc.nonlarge_max
+ try:
+ if force_external:
+ self.gc.nonlarge_max = 1
+ p1 = self.malloc(S)
+ finally:
+ self.gc.nonlarge_max = saved
p1.x = intval
if create_immortal:
self.consider_constant(p1)
@@ -220,9 +227,10 @@
def test_pypy_nonlight_dies_quickly_old(self):
self.test_pypy_nonlight_dies_quickly(old=True)
- def test_pyobject_pypy_link_dies_on_minor_collection(self):
+ @py.test.mark.parametrize('external', [False, True])
+ def test_pyobject_pypy_link_dies_on_minor_collection(self, external):
p1, p1ref, r1, r1addr, check_alive = (
- self._rawrefcount_pair(42, is_pyobj=True))
+ self._rawrefcount_pair(42, is_pyobj=True, force_external=external))
check_alive(0)
r1.ob_refcnt += 1 # the pyobject is kept alive
self._collect(major=False)
@@ -231,9 +239,12 @@
self.gc.check_no_more_rawrefcount_state()
lltype.free(r1, flavor='raw')
- def test_pyobject_dies(self, old=False):
+ @py.test.mark.parametrize('old,external', [
+ (False, False), (True, False), (False, True)])
+ def test_pyobject_dies(self, old, external):
p1, p1ref, r1, r1addr, check_alive = (
- self._rawrefcount_pair(42, is_pyobj=True, create_old=old))
+ self._rawrefcount_pair(42, is_pyobj=True, create_old=old,
+ force_external=external))
check_alive(0)
if old:
self._collect(major=False)
@@ -247,9 +258,12 @@
self.gc.check_no_more_rawrefcount_state()
lltype.free(r1, flavor='raw')
- def test_pyobject_survives_from_obj(self, old=False):
+ @py.test.mark.parametrize('old,external', [
+ (False, False), (True, False), (False, True)])
+ def test_pyobject_survives_from_obj(self, old, external):
p1, p1ref, r1, r1addr, check_alive = (
- self._rawrefcount_pair(42, is_pyobj=True, create_old=old))
+ self._rawrefcount_pair(42, is_pyobj=True, create_old=old,
+ force_external=external))
check_alive(0)
self.stackroots.append(p1)
self._collect(major=False)
@@ -269,11 +283,6 @@
self.gc.check_no_more_rawrefcount_state()
lltype.free(r1, flavor='raw')
- def test_pyobject_dies_old(self):
- self.test_pyobject_dies(old=True)
- def test_pyobject_survives_from_obj_old(self):
- self.test_pyobject_survives_from_obj(old=True)
-
def test_pyobject_attached_to_prebuilt_obj(self):
p1, p1ref, r1, r1addr, check_alive = (
self._rawrefcount_pair(42, create_immortal=True))
diff --git a/rpython/rlib/rvmprof/src/vmprof_config.h
b/rpython/rlib/rvmprof/src/vmprof_config.h
--- a/rpython/rlib/rvmprof/src/vmprof_config.h
+++ b/rpython/rlib/rvmprof/src/vmprof_config.h
@@ -1,6 +1,17 @@
#define HAVE_SYS_UCONTEXT_H
-#if defined(__FreeBSD__) || defined(__APPLE__)
+#if defined(__FreeBSD__)
#define PC_FROM_UCONTEXT uc_mcontext.mc_rip
+#elif defined( __APPLE__)
+ #if ((ULONG_MAX) == (UINT_MAX))
+ #define PC_FROM_UCONTEXT uc_mcontext->__ss.__eip
+ #else
+ #define PC_FROM_UCONTEXT uc_mcontext->__ss.__rip
+ #endif
+#elif defined(__arm__)
+#define PC_FROM_UCONTEXT uc_mcontext.arm_ip
+#elif defined(__linux) && defined(__i386) && defined(__GNUC__)
+#define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_EIP]
#else
+/* linux, gnuc */
#define PC_FROM_UCONTEXT uc_mcontext.gregs[REG_RIP]
#endif
diff --git a/rpython/rlib/rvmprof/src/vmprof_getpc.h
b/rpython/rlib/rvmprof/src/vmprof_getpc.h
--- a/rpython/rlib/rvmprof/src/vmprof_getpc.h
+++ b/rpython/rlib/rvmprof/src/vmprof_getpc.h
@@ -43,9 +43,6 @@
#ifndef BASE_GETPC_H_
#define BASE_GETPC_H_
-
-#include "vmprof_config.h"
-
// On many linux systems, we may need _GNU_SOURCE to get access to
// the defined constants that define the register we want to see (eg
// REG_EIP). Note this #define must come first!
@@ -58,6 +55,8 @@
#define _XOPEN_SOURCE 500
#endif
+#include "vmprof_config.h"
+
#include <string.h> // for memcmp
#if defined(HAVE_SYS_UCONTEXT_H)
#include <sys/ucontext.h>
@@ -112,13 +111,8 @@
// PC_FROM_UCONTEXT in config.h. The only thing we need to do here,
// then, is to do the magic call-unrolling for systems that support it.
-#if defined(__linux) && defined(__i386) && defined(__GNUC__)
-intptr_t GetPC(ucontext_t *signal_ucontext) {
- return signal_ucontext->uc_mcontext.gregs[REG_EIP];
-}
-
-// Special case #2: Windows, which has to do something totally different.
-#elif defined(_WIN32) || defined(__CYGWIN__) || defined(__CYGWIN32__) ||
defined(__MINGW32__)
+// Special case Windows, which has to do something totally different.
+#if defined(_WIN32) || defined(__CYGWIN__) || defined(__CYGWIN32__) ||
defined(__MINGW32__)
// If this is ever implemented, probably the way to do it is to have
// profiler.cc use a high-precision timer via timeSetEvent:
// http://msdn2.microsoft.com/en-us/library/ms712713.aspx
@@ -141,18 +135,10 @@
// Normal cases. If this doesn't compile, it's probably because
// PC_FROM_UCONTEXT is the empty string. You need to figure out
// the right value for your system, and add it to the list in
-// configure.ac (or set it manually in your config.h).
+// vmrpof_config.h
#else
intptr_t GetPC(ucontext_t *signal_ucontext) {
-#ifdef __APPLE__
-#if ((ULONG_MAX) == (UINT_MAX))
- return (signal_ucontext->uc_mcontext->__ss.__eip);
-#else
- return (signal_ucontext->uc_mcontext->__ss.__rip);
-#endif
-#else
return signal_ucontext->PC_FROM_UCONTEXT; // defined in config.h
-#endif
}
#endif
diff --git a/rpython/rlib/test/test_rthread.py
b/rpython/rlib/test/test_rthread.py
--- a/rpython/rlib/test/test_rthread.py
+++ b/rpython/rlib/test/test_rthread.py
@@ -5,6 +5,7 @@
from rpython.translator.c.test.test_boehm import AbstractGCTestClass
from rpython.rtyper.lltypesystem import lltype, rffi
import py
+import platform
def test_lock():
l = allocate_lock()
@@ -92,6 +93,8 @@
res = fn()
assert res == 42
+ @py.test.mark.xfail(platform.machine() == 's390x',
+ reason='may fail this test under heavy load')
def test_gc_locking(self):
import time
from rpython.rlib.debug import ll_assert
diff --git a/rpython/rlib/test/test_runicode.py
b/rpython/rlib/test/test_runicode.py
--- a/rpython/rlib/test/test_runicode.py
+++ b/rpython/rlib/test/test_runicode.py
@@ -4,6 +4,8 @@
import sys, random
from rpython.rlib import runicode
+from hypothesis import given, settings, strategies
+
def test_unichr():
assert runicode.UNICHR(0xffff) == u'\uffff'
@@ -172,6 +174,17 @@
"utf-32 utf-32-be utf-32-le").split():
self.checkdecode(uni, encoding)
+ # Same as above, but uses Hypothesis to generate non-surrogate unicode
+ # characters.
+ @settings(max_examples=10000)
+ @given(strategies.characters(blacklist_categories=["Cs"]))
+ def test_random_hypothesis(self, uni):
+ if sys.version >= "2.7":
+ self.checkdecode(uni, "utf-7")
+ for encoding in ("utf-8 utf-16 utf-16-be utf-16-le "
+ "utf-32 utf-32-be utf-32-le").split():
+ self.checkdecode(uni, encoding)
+
def test_maxunicode(self):
uni = unichr(sys.maxunicode)
if sys.version >= "2.7":
diff --git a/rpython/tool/ansi_print.py b/rpython/tool/ansi_print.py
--- a/rpython/tool/ansi_print.py
+++ b/rpython/tool/ansi_print.py
@@ -50,9 +50,9 @@
# some more methods used by sandlib
call = _make_method(':call', (34,))
result = _make_method(':result', (34,))
- exception = _make_method(':exception', (34,)),
- vpath = _make_method(':vpath', (35,)),
- timeout = _make_method('', (1, 31)),
+ exception = _make_method(':exception', (34,))
+ vpath = _make_method(':vpath', (35,))
+ timeout = _make_method('', (1, 31))
# directly calling the logger writes "[name] text" with no particular color
__call__ = _make_method('', ())
diff --git a/rpython/translator/sandbox/sandlib.py
b/rpython/translator/sandbox/sandlib.py
--- a/rpython/translator/sandbox/sandlib.py
+++ b/rpython/translator/sandbox/sandlib.py
@@ -527,6 +527,9 @@
node = self.get_node(vpathname)
return node.keys()
+ def do_ll_os__ll_os_unlink(self, vpathname):
+ raise OSError(errno.EPERM, "write access denied")
+
def do_ll_os__ll_os_getuid(self):
return UID
do_ll_os__ll_os_geteuid = do_ll_os__ll_os_getuid
diff --git a/testrunner/runner.py b/testrunner/runner.py
--- a/testrunner/runner.py
+++ b/testrunner/runner.py
@@ -240,8 +240,8 @@
s = 'setting'
if os.environ.get('MAKEFLAGS'):
s = 'overriding'
- out.write("%s MAKEFLAGS to '-j1'\n" % s)
- os.environ['MAKEFLAGS'] = '-j1'
+ out.write("%s MAKEFLAGS to ' ' (space)\n" % s)
+ os.environ['MAKEFLAGS'] = ' '
failure = False
for testname in testdirs:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit