[pypy-commit] pypy py3.5: hg merge default

2019-02-06 Thread ambv
Author: ukasz Langa 
Branch: py3.5
Changeset: r95863:706d2757733b
Date: 2019-02-06 12:01 +0100
http://bitbucket.org/pypy/pypy/changeset/706d2757733b/

Log:hg merge default

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -4,8 +4,10 @@
 *~
 .*.swp
 .idea
+.mypy_cache
 .project
 .pydevproject
+.vscode
 __pycache__
 .venv
 .cache
diff --git a/rpython/rtyper/lltypesystem/module/test/math_cases.py 
b/rpython/rtyper/lltypesystem/module/test/math_cases.py
--- a/rpython/rtyper/lltypesystem/module/test/math_cases.py
+++ b/rpython/rtyper/lltypesystem/module/test/math_cases.py
@@ -59,9 +59,6 @@
 ('copysign', (1.5, -0.0), -1.5),
 ('copysign', (1.5, INFINITY), 1.5),
 ('copysign', (1.5, -INFINITY), -1.5),
-]
-if sys.platform != 'win32':# all NaNs seem to be negative there...?
-IRREGCASES += [
 ('copysign', (1.5, NAN), 1.5),
 ('copysign', (1.75, -NAN), -1.75),  # special case for -NAN here
 ]
diff --git a/rpython/translator/c/primitive.py 
b/rpython/translator/c/primitive.py
--- a/rpython/translator/c/primitive.py
+++ b/rpython/translator/c/primitive.py
@@ -123,9 +123,9 @@
 return '(-Py_HUGE_VAL)'
 elif math.isnan(value):
 if is_positive_nan(value):
-return '(Py_HUGE_VAL/Py_HUGE_VAL)'
+return '(_PyPy_dg_stdnan(0))'
 else:
-return '(-(Py_HUGE_VAL/Py_HUGE_VAL))'
+return '(_PyPy_dg_stdnan(1))'
 else:
 x = repr(value)
 assert not x.startswith('n')
@@ -142,9 +142,9 @@
 elif math.isnan(value):
 # XXX are these expressions ok?
 if is_positive_nan(value):
-return '((float)(Py_HUGE_VAL/Py_HUGE_VAL))'
+return '((float)(_PyPy_dg_stdnan(0)))'
 else:
-return '(-(float)(Py_HUGE_VAL/Py_HUGE_VAL))'
+return '((float)(_PyPy_dg_stdnan(1)))'
 else:
 return repr(value) + 'f'
 
diff --git a/rpython/translator/c/src/support.c 
b/rpython/translator/c/src/support.c
--- a/rpython/translator/c/src/support.c
+++ b/rpython/translator/c/src/support.c
@@ -9,6 +9,26 @@
 #include 
 
 /*** misc ***/
+#define Sign_bit 0x8000
+#define NAN_WORD0 0x7ff8
+#define NAN_WORD1 0
+#define PY_UINT32_T unsigned int
+
+#ifndef __BIG_ENDIAN__
+#define IEEE_8087
+#endif
+
+#ifdef IEEE_8087
+#define word0(x) (x)->L[1]
+#define word1(x) (x)->L[0]
+#else
+#define word0(x) (x)->L[0]
+#define word1(x) (x)->L[1]
+#endif
+#define dval(x) (x)->d
+
+typedef PY_UINT32_T ULong;
+typedef union { double d; ULong L[2]; } U;
 
 RPY_EXTERN
 void RPyAssertFailed(const char* filename, long lineno,
@@ -25,3 +45,20 @@
   fprintf(stderr, "Invalid RPython operation (NULL ptr or bad array index)\n");
   abort();
 }
+
+/* Return a 'standard' NaN value.
+   There are exactly two quiet NaNs that don't arise by 'quieting' signaling
+   NaNs (see IEEE 754-2008, section 6.2.1).  If sign == 0, return the one whose
+   sign bit is cleared.  Otherwise, return the one whose sign bit is set.
+*/
+
+double
+_PyPy_dg_stdnan(int sign)
+{
+U rv;
+word0() = NAN_WORD0;
+word1() = NAN_WORD1;
+if (sign)
+word0() |= Sign_bit;
+return dval();
+}
diff --git a/rpython/translator/c/src/support.h 
b/rpython/translator/c/src/support.h
--- a/rpython/translator/c/src/support.h
+++ b/rpython/translator/c/src/support.h
@@ -38,6 +38,9 @@
 RPY_EXTERN
 void RPyAbort(void);
 
+RPY_EXTERN
+double _PyPy_dg_stdnan(int sign);
+
 #if defined(RPY_LL_ASSERT) || defined(RPY_SANDBOXED)
 /* obscure macros that can be used as expressions and lvalues to refer
  * to a field of a structure or an item in an array in a "safe" way --
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2019-02-05 Thread mjacob
Author: Manuel Jacob 
Branch: py3.5
Changeset: r95853:4a4b466ea459
Date: 2019-02-06 02:42 +0100
http://bitbucket.org/pypy/pypy/changeset/4a4b466ea459/

Log:hg merge default

diff --git a/pypy/module/zlib/interp_zlib.py b/pypy/module/zlib/interp_zlib.py
--- a/pypy/module/zlib/interp_zlib.py
+++ b/pypy/module/zlib/interp_zlib.py
@@ -113,22 +113,8 @@
 Wrapper around zlib's z_stream structure which provides convenient
 compression functionality.
 """
-def __init__(self, space, level=rzlib.Z_DEFAULT_COMPRESSION,
- method=rzlib.Z_DEFLATED, # \
- wbits=rzlib.MAX_WBITS,   #  \   undocumented
- memLevel=rzlib.DEF_MEM_LEVEL,#  /parameters
- strategy=rzlib.Z_DEFAULT_STRATEGY,   # /
- zdict=None,
- stream=None):
+def __init__(self, space, stream):
 ZLibObject.__init__(self, space)
-if stream is None:
-try:
-stream = rzlib.deflateInit(level, method, wbits,
-   memLevel, strategy, zdict=zdict)
-except rzlib.RZlibError as e:
-raise zlib_error(space, e.msg)
-except ValueError:
-raise oefmt(space.w_ValueError, "Invalid initialization 
option")
 self.stream = stream
 self.register_finalizer(space)
 
@@ -220,11 +206,17 @@
 zdict = None
 else:
 zdict = space.charbuf_w(w_zdict)
-stream = space.allocate_instance(Compress, w_subtype)
-stream = space.interp_w(Compress, stream)
-Compress.__init__(stream, space, level,
-  method, wbits, memLevel, strategy, zdict)
-return stream
+w_stream = space.allocate_instance(Compress, w_subtype)
+w_stream = space.interp_w(Compress, w_stream)
+try:
+stream = rzlib.deflateInit(level, method, wbits, memLevel, strategy,
+   zdict=zdict)
+except rzlib.RZlibError as e:
+raise zlib_error(space, e.msg)
+except ValueError:
+raise oefmt(space.w_ValueError, "Invalid initialization option")
+Compress.__init__(w_stream, space, stream)
+return w_stream
 
 
 Compress.typedef = TypeDef(
@@ -244,15 +236,7 @@
 Wrapper around zlib's z_stream structure which provides convenient
 decompression functionality.
 """
-def __init__(
-self,
-space,
-wbits=rzlib.MAX_WBITS,
-zdict=None,
-stream=None,
-unused_data="",
-unconsumed_tail="",
-):
+def __init__(self, space, stream, zdict, unused_data, unconsumed_tail):
 """
 Initialize a new decompression object.
 
@@ -262,13 +246,7 @@
 inflateInit2.
 """
 ZLibObject.__init__(self, space)
-if stream is None:
-try:
-stream = rzlib.inflateInit(wbits, zdict=zdict)
-except rzlib.RZlibError as e:
-raise zlib_error(space, e.msg)
-except ValueError:
-raise oefmt(space.w_ValueError, "Invalid initialization 
option")
+
 self.stream = stream
 self.zdict = zdict
 self.unused_data = unused_data
@@ -383,10 +361,16 @@
 zdict = None
 else:
 zdict = space.charbuf_w(w_zdict)
-stream = space.allocate_instance(Decompress, w_subtype)
-stream = space.interp_w(Decompress, stream)
-Decompress.__init__(stream, space, wbits, zdict)
-return stream
+w_stream = space.allocate_instance(Decompress, w_subtype)
+w_stream = space.interp_w(Decompress, w_stream)
+try:
+stream = rzlib.inflateInit(wbits, zdict=zdict)
+except rzlib.RZlibError as e:
+raise zlib_error(space, e.msg)
+except ValueError:
+raise oefmt(space.w_ValueError, "Invalid initialization option")
+Decompress.__init__(w_stream, space, stream, zdict, '', '')
+return w_stream
 
 def default_buffer_size(space):
 return space.newint(rzlib.OUTPUT_BUFFER_SIZE)
diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py
--- a/rpython/rlib/rgc.py
+++ b/rpython/rlib/rgc.py
@@ -1406,6 +1406,11 @@
 return _ResizableListSupportingRawPtr(lst)
 
 def nonmoving_raw_ptr_for_resizable_list(lst):
+if must_split_gc_address_space():
+raise ValueError
+return _nonmoving_raw_ptr_for_resizable_list(lst)
+
+def _nonmoving_raw_ptr_for_resizable_list(lst):
 assert isinstance(lst, _ResizableListSupportingRawPtr)
 return lst._nonmoving_raw_ptr_for_resizable_list()
 
@@ -1450,7 +1455,7 @@
 return hop.inputarg(hop.args_r[0], 0)
 
 class Entry(ExtRegistryEntry):
-_about_ = nonmoving_raw_ptr_for_resizable_list
+_about_ = _nonmoving_raw_ptr_for_resizable_list
 
 def compute_result_annotation(self, s_list):
 from rpython.rtyper.lltypesystem import lltype, rffi
___
pypy-commit mailing list

[pypy-commit] pypy py3.5: hg merge default

2019-01-31 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r95765:2b258d7b2475
Date: 2019-01-31 22:50 +0100
http://bitbucket.org/pypy/pypy/changeset/2b258d7b2475/

Log:hg merge default

diff --git a/extra_tests/cffi_tests/cffi1/test_pkgconfig.py 
b/extra_tests/cffi_tests/cffi1/test_pkgconfig.py
new file mode 100644
--- /dev/null
+++ b/extra_tests/cffi_tests/cffi1/test_pkgconfig.py
@@ -0,0 +1,95 @@
+# Generated by pypy/tool/import_cffi.py
+import sys
+import subprocess
+import py
+import cffi.pkgconfig as pkgconfig
+from cffi import PkgConfigError
+
+
+def mock_call(libname, flag):
+assert libname=="foobarbaz"
+flags = {
+"--cflags": "-I/usr/include/python3.6m -DABCD -DCFFI_TEST=1 -O42\n",
+"--libs": "-L/usr/lib64 -lpython3.6 -shared\n",
+}
+return flags[flag]
+
+
+def test_merge_flags():
+d1 = {"ham": [1, 2, 3], "spam" : ["a", "b", "c"], "foo" : []}
+d2 = {"spam" : ["spam", "spam", "spam"], "bar" : ["b", "a", "z"]}
+
+pkgconfig.merge_flags(d1, d2)
+assert d1 == {
+"ham": [1, 2, 3],
+"spam" : ["a", "b", "c", "spam", "spam", "spam"],
+"bar" : ["b", "a", "z"],
+"foo" : []}
+
+
+def test_pkgconfig():
+assert pkgconfig.flags_from_pkgconfig([]) == {}
+
+saved = pkgconfig.call
+try:
+pkgconfig.call = mock_call
+flags = pkgconfig.flags_from_pkgconfig(["foobarbaz"])
+finally:
+pkgconfig.call = saved
+assert flags == {
+'include_dirs': ['/usr/include/python3.6m'],
+'library_dirs': ['/usr/lib64'],
+'libraries': ['python3.6'],
+'define_macros': [('ABCD', None), ('CFFI_TEST', '1')],
+'extra_compile_args': ['-O42'],
+'extra_link_args': ['-shared']
+}
+
+class mock_subprocess:
+PIPE = Ellipsis
+class Popen:
+def __init__(self, cmd, stdout, stderr):
+if mock_subprocess.RESULT is None:
+raise OSError("oops can't run")
+assert cmd == ['pkg-config', '--print-errors', '--cflags', 
'libfoo']
+def communicate(self):
+bout, berr, rc = mock_subprocess.RESULT
+self.returncode = rc
+return bout, berr
+
+def test_call():
+saved = pkgconfig.subprocess
+try:
+pkgconfig.subprocess = mock_subprocess
+
+mock_subprocess.RESULT = None
+e = py.test.raises(PkgConfigError, pkgconfig.call, "libfoo", 
"--cflags")
+assert str(e.value) == "cannot run pkg-config: oops can't run"
+
+mock_subprocess.RESULT = b"", "Foo error!\n", 1
+e = py.test.raises(PkgConfigError, pkgconfig.call, "libfoo", 
"--cflags")
+assert str(e.value) == "Foo error!"
+
+mock_subprocess.RESULT = b"abc\\def\n", "", 0
+e = py.test.raises(PkgConfigError, pkgconfig.call, "libfoo", 
"--cflags")
+assert str(e.value).startswith("pkg-config --cflags libfoo returned an 
"
+   "unsupported backslash-escaped output:")
+
+mock_subprocess.RESULT = b"abc def\n", "", 0
+result = pkgconfig.call("libfoo", "--cflags")
+assert result == "abc def\n"
+
+mock_subprocess.RESULT = b"abc def\n", "", 0
+result = pkgconfig.call("libfoo", "--cflags")
+assert result == "abc def\n"
+
+if sys.version_info >= (3,):
+mock_subprocess.RESULT = b"\xff\n", "", 0
+e = py.test.raises(PkgConfigError, pkgconfig.call,
+   "libfoo", "--cflags", encoding="utf-8")
+assert str(e.value) == (
+"pkg-config --cflags libfoo returned bytes that cannot be "
+"decoded with encoding 'utf-8':\nb'\\xff\\n'")
+
+finally:
+pkgconfig.subprocess = saved
diff --git a/lib_pypy/cffi/__init__.py b/lib_pypy/cffi/__init__.py
--- a/lib_pypy/cffi/__init__.py
+++ b/lib_pypy/cffi/__init__.py
@@ -3,6 +3,7 @@
 
 from .api import FFI
 from .error import CDefError, FFIError, VerificationError, VerificationMissing
+from .error import PkgConfigError
 
 __version__ = "1.12.0"
 __version_info__ = (1, 12, 0)
diff --git a/lib_pypy/cffi/api.py b/lib_pypy/cffi/api.py
--- a/lib_pypy/cffi/api.py
+++ b/lib_pypy/cffi/api.py
@@ -643,6 +643,16 @@
 self._assigned_source = (str(module_name), source,
  source_extension, kwds)
 
+def set_source_pkgconfig(self, module_name, pkgconfig_libs, source,
+ source_extension='.c', **kwds):
+from . import pkgconfig
+if not isinstance(pkgconfig_libs, list):
+raise TypeError("the pkgconfig_libs argument must be a list "
+"of package names")
+kwds2 = pkgconfig.flags_from_pkgconfig(pkgconfig_libs)
+pkgconfig.merge_flags(kwds, kwds2)
+self.set_source(module_name, source, source_extension, **kwds)
+
 def distutils_extension(self, tmpdir='build', verbose=True):
 from distutils.dir_util import mkpath
 from .recompiler 

[pypy-commit] pypy py3.5: hg merge default

2019-01-31 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r95756:e01a180ee74a
Date: 2019-01-31 16:11 +
http://bitbucket.org/pypy/pypy/changeset/e01a180ee74a/

Log:hg merge default

diff --git a/extra_tests/cffi_tests/cffi0/test_function.py 
b/extra_tests/cffi_tests/cffi0/test_function.py
--- a/extra_tests/cffi_tests/cffi0/test_function.py
+++ b/extra_tests/cffi_tests/cffi0/test_function.py
@@ -46,14 +46,15 @@
 assert x != math.sin(1.23)# rounding effects
 assert abs(x - math.sin(1.23)) < 1E-6
 
-def test_lround_no_return_value(self):
+def test_getenv_no_return_value(self):
 # check that 'void'-returning functions work too
 ffi = FFI(backend=self.Backend())
 ffi.cdef("""
-void lround(double x);
+void getenv(char *);
 """)
-m = ffi.dlopen(lib_m)
-x = m.lround(1.23)
+needs_dlopen_none()
+m = ffi.dlopen(None)
+x = m.getenv(b"FOO")
 assert x is None
 
 def test_dlopen_filename(self):
diff --git a/pypy/doc/interpreter.rst b/pypy/doc/interpreter.rst
--- a/pypy/doc/interpreter.rst
+++ b/pypy/doc/interpreter.rst
@@ -156,7 +156,7 @@
 environment found in `Frames`.  Frames and Functions have references
 to a code object. Here is a list of Code attributes:
 
-* ``co_flags`` flags if this code object has nested scopes/generators
+* ``co_flags`` flags if this code object has nested scopes/generators/etc.
 * ``co_stacksize`` the maximum depth the stack can reach while executing the 
code
 * ``co_code`` the actual bytecode string
 
diff --git a/pypy/doc/release-v7.0.0.rst b/pypy/doc/release-v7.0.0.rst
--- a/pypy/doc/release-v7.0.0.rst
+++ b/pypy/doc/release-v7.0.0.rst
@@ -107,7 +107,10 @@
   ``PyOS_InputHook``, ``PyErr_FormatFromCause`` (Py3.6),
 * Implement new wordcode instruction encoding (Py3.6)
 * Log additional gc-minor and gc-collect-step info in the PYPYLOG
-* Set ``reverse-debugger`` active by default. For more information, see
+* The ``reverse-debugger`` (revdb) branch has been merged to the default
+  branch, so it should always be up-to-date.  You still need a special pypy
+  build, but you can compile it from the same source as the one we distribute
+  for the v7.0.0 release.  For more information, see
   https://bitbucket.org/pypy/revdb
 * Support underscores in numerical literals like ``'4_2'`` (Py3.6)
 * Pre-emptively raise MemoryError if the size of dequeue in 
``_collections.deque``
@@ -126,7 +129,8 @@
 * Speed up ``max(list-of-int)`` from non-jitted code
 * Fix Windows ``os.listdir()`` for some cases (see CPython #32539)
 * Add ``select.PIPE_BUF``
-* Use ``subprocess`` to avoid shell injection in ``shutil`` module
+* Use ``subprocess`` to avoid shell injection in ``shutil`` module - backport
+  of https://bugs.python.org/issue34540
 * Rename ``_Py_ZeroStruct`` to ``_Py_FalseStruct`` (Py3.5, Py3.6)
 * Remove some cpyext names for Py3.5, Py3.6
 * Enable use of unicode file names in ``dlopen``
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -512,6 +512,7 @@
 header = DEFAULT_HEADER
 if func.__name__ in FUNCTIONS_BY_HEADER[header]:
 raise ValueError("%s already registered" % func.__name__)
+func._revdb_c_only_ = True   # hack for revdb
 api_function = COnlyApiFunction(argtypes, restype, func)
 FUNCTIONS_BY_HEADER[header][func.__name__] = api_function
 return api_function
diff --git a/rpython/rlib/rgc.py b/rpython/rlib/rgc.py
--- a/rpython/rlib/rgc.py
+++ b/rpython/rlib/rgc.py
@@ -67,7 +67,7 @@
 """Returns True if we have a "split GC address space", i.e. if
 we are translating with an option that doesn't support taking raw
 addresses inside GC objects and "hacking" at them.  This is
-notably the case with --reversedb."""
+notably the case with --revdb."""
 return False
 
 # for test purposes we allow objects to be pinned and use
diff --git a/rpython/rlib/src/boehm-rawrefcount.c 
b/rpython/rlib/src/boehm-rawrefcount.c
--- a/rpython/rlib/src/boehm-rawrefcount.c
+++ b/rpython/rlib/src/boehm-rawrefcount.c
@@ -191,6 +191,7 @@
 #endif
 assert(result->ob_refcnt == REFCNT_FROM_PYPY);
 result->ob_refcnt = 1;
+result->ob_pypy_link = 0;
 p->pyobj = NULL;
 *pp = p->next_in_bucket;
 p->next_in_bucket = hash_free_list;
diff --git a/rpython/translator/revdb/gencsupp.py 
b/rpython/translator/revdb/gencsupp.py
--- a/rpython/translator/revdb/gencsupp.py
+++ b/rpython/translator/revdb/gencsupp.py
@@ -51,6 +51,10 @@
 ## return False
 
 def prepare_function(funcgen):
+if getattr(getattr(funcgen.graph, 'func', None), '_revdb_c_only_', False):
+extra_enter_text = 'RPY_REVDB_C_ONLY_ENTER'
+extra_return_text = 'RPY_REVDB_C_ONLY_LEAVE'
+return extra_enter_text, extra_return_text
 stack_bottom = False

[pypy-commit] pypy py3.5: hg merge default

2019-01-25 Thread antocuni
Author: Antonio Cuni 
Branch: py3.5
Changeset: r95728:75ae721dc112
Date: 2019-01-25 16:44 +0100
http://bitbucket.org/pypy/pypy/changeset/75ae721dc112/

Log:hg merge default

diff --git a/pypy/doc/how-to-release.rst b/pypy/doc/how-to-release.rst
--- a/pypy/doc/how-to-release.rst
+++ b/pypy/doc/how-to-release.rst
@@ -16,9 +16,6 @@
 How to Create a PyPy Release
 
 
-Overview
-
-
 As a meta rule setting up issues in the tracker for items here may help not
 forgetting things. A set of todo files may also work.
 
@@ -28,17 +25,54 @@
 
 
 Release Steps
--
+++
 
-* If needed, make a release branch
-* Bump the
-  pypy version number in module/sys/version.py and in
-  module/cpyext/include/patchlevel.h and in doc/conf.py. The branch
-  will capture the revision number of this change for the release.
+Make the release branch
+
 
-  Some of the next updates may be done before or after branching; make
-  sure things are ported back to the trunk and to the branch as
-  necessary.
+This is needed only in case you are doing a new major version; if not, you can
+probably reuse the existing release branch.
+
+We want to be able to freely merge default into the branch and vice-versa;
+thus we need to do a complicate dance to avoid to patch the version number
+when we do a merge::
+
+  $ hg up -r default
+  $ # edit the version to e.g. 7.0.0-final
+  $ hg ci
+  $ hg branch release-pypy2.7-7.x && hg ci
+  $ hg up -r default
+  $ # edit the version to 7.1.0-alpha0
+  $ hg ci
+  $ hg up -r release-pypy2.7-7.x
+  $ hg merge default
+  $ # edit the version to AGAIN 7.0.0-final
+  $ hg ci
+
+Then, we need to do the same for the 3.x branch::
+
+  $ hg up -r py3.5
+  $ hg merge default # this brings the version fo 7.1.0-alpha0
+  $ hg branch release-pypy3.5-7.x
+  $ # edit the version to 7.0.0-final
+  $ hg ci
+  $ hg up -r py3.5
+  $ hg merge release-pypy3.5-7.x
+  $ # edit the version to 7.1.0-alpha0
+  $ hg ci
+
+To change the version, you need to edit three files:
+
+  - ``module/sys/version.py``
+
+  - ``module/cpyext/include/patchlevel.h``
+
+  - ``doc/conf.py``
+
+
+Other steps
+---
+
 
 * Make sure the RPython builds on the buildbot pass with no failures
 
diff --git a/pypy/module/cpyext/include/patchlevel.h 
b/pypy/module/cpyext/include/patchlevel.h
--- a/pypy/module/cpyext/include/patchlevel.h
+++ b/pypy/module/cpyext/include/patchlevel.h
@@ -32,7 +32,7 @@
  * module/sys/version.py
  * doc/conf.py
  */
-#define PYPY_VERSION "7.1.0"
+#define PYPY_VERSION "7.1.0-alpha0"
 #define PYPY_VERSION_NUM  0x0701
 /* Defined to mean a PyPy where cpyext holds more regular references
to PyObjects, e.g. staying alive as long as the internal PyPy object
diff --git a/pypy/module/sys/version.py b/pypy/module/sys/version.py
--- a/pypy/module/sys/version.py
+++ b/pypy/module/sys/version.py
@@ -13,7 +13,7 @@
 # make sure to keep PYPY_VERSION in sync with:
 #module/cpyext/include/patchlevel.h
 #doc/conf.py
-PYPY_VERSION   = (7, 1, 0, "alpha0", 0)
+PYPY_VERSION   = (7, 1, 0, "alpha", 0)
 
 
 import pypy
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default; this bump the version to 7.1-alpha0

2019-01-25 Thread antocuni
Author: Antonio Cuni 
Branch: py3.5
Changeset: r95723:4b2995821717
Date: 2019-01-25 15:52 +0100
http://bitbucket.org/pypy/pypy/changeset/4b2995821717/

Log:hg merge default; this bump the version to 7.1-alpha0

diff --git a/pypy/doc/conf.py b/pypy/doc/conf.py
--- a/pypy/doc/conf.py
+++ b/pypy/doc/conf.py
@@ -65,10 +65,15 @@
 # |version| and |release|, also used in various other places throughout the
 # built documents.
 #
+
+# Make sure to keep this in sync with:
+#module/sys/version.py
+#module/cpyext/include/patchlevel.h
+#
 # The short X.Y version.
-version = '6.0'
+version = '7.1'
 # The full version, including alpha/beta/rc tags.
-release = '6.0.0'
+release = '7.1.0'
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
diff --git a/pypy/module/cpyext/include/patchlevel.h 
b/pypy/module/cpyext/include/patchlevel.h
--- a/pypy/module/cpyext/include/patchlevel.h
+++ b/pypy/module/cpyext/include/patchlevel.h
@@ -28,10 +28,12 @@
 /* Version as a string */
 #define PY_VERSION "3.5.3"
 
-/* PyPy version as a string */
-#define PYPY_VERSION "6.1.0-alpha0"
-#define PYPY_VERSION_NUM  0x0601
-
+/* PyPy version as a string: make sure to keep this in sync with:
+ * module/sys/version.py
+ * doc/conf.py
+ */
+#define PYPY_VERSION "7.1.0"
+#define PYPY_VERSION_NUM  0x0701
 /* Defined to mean a PyPy where cpyext holds more regular references
to PyObjects, e.g. staying alive as long as the internal PyPy object
stays alive. */
diff --git a/pypy/module/sys/version.py b/pypy/module/sys/version.py
--- a/pypy/module/sys/version.py
+++ b/pypy/module/sys/version.py
@@ -10,7 +10,10 @@
 #XXX # sync CPYTHON_VERSION with patchlevel.h, package.py
 CPYTHON_API_VERSION= 1013   #XXX # sync with include/modsupport.h
 
-PYPY_VERSION   = (6, 1, 0, "alpha", 0)#XXX # sync patchlevel.h
+# make sure to keep PYPY_VERSION in sync with:
+#module/cpyext/include/patchlevel.h
+#doc/conf.py
+PYPY_VERSION   = (7, 1, 0, "alpha0", 0)
 
 
 import pypy
diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -991,7 +991,9 @@
 items = d.items()
 d.clear()
 d[key] = value
-d.update(items)
+# r_dict.update does not support list of tuples, do it manually
+for key, value in items:
+d[key] = value
 
 @specialize.call_location()
 def move_to_end(d, key, last=True):
diff --git a/rpython/rlib/test/test_objectmodel.py 
b/rpython/rlib/test/test_objectmodel.py
--- a/rpython/rlib/test/test_objectmodel.py
+++ b/rpython/rlib/test/test_objectmodel.py
@@ -708,6 +708,15 @@
 move_to_end(d, 'key1', last=False)
 assert d.items() == [('key1', 'val1'), ('key2', 'val2'), ('key3', 'val3')]
 
+def test_r_dict_move_to_end():
+d = r_dict(strange_key_eq, strange_key_hash)
+d['1key'] = 'val1'
+d['2key'] = 'val2'
+d['3key'] = 'val3'
+# does not crash, we can't check that it actually moves to end on CPython
+move_to_end(d, '1key')
+move_to_end(d, '1key', last=False)
+
 def test_import_from_mixin():
 class M:# old-style
 def f(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2019-01-16 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r95654:f7b6aeba6694
Date: 2019-01-16 20:36 +
http://bitbucket.org/pypy/pypy/changeset/f7b6aeba6694/

Log:hg merge default

diff --git a/pypy/conftest.py b/pypy/conftest.py
--- a/pypy/conftest.py
+++ b/pypy/conftest.py
@@ -14,6 +14,14 @@
 rsyncdirs = ['.', '../lib-python', '../lib_pypy', '../demo']
 rsyncignore = ['_cache']
 
+try:
+from hypothesis import settings
+except ImportError:
+pass
+else:
+settings.register_profile('default', deadline=None)
+settings.load_profile('default')
+
 # PyPy's command line extra options (these are added
 # to py.test's standard options)
 #
diff --git a/rpython/translator/platform/windows.py 
b/rpython/translator/platform/windows.py
--- a/rpython/translator/platform/windows.py
+++ b/rpython/translator/platform/windows.py
@@ -83,12 +83,14 @@
  stderr=subprocess.PIPE)
 
 stdout, stderr = popen.communicate()
-if popen.wait() != 0:
+if popen.wait() != 0 or stdout[:5].lower() == 'error':
+log.msg('Running "%s" errored: \n\nstdout:\n%s\n\nstderr:\n%s' 
% (
+vcvars, stdout.split()[0], stderr))
 return None
-if stdout[:5].lower() == 'error':
-log.msg('Running "%s" errored: %s' %(vcvars, 
stdout.split()[0]))
-return None
-except:
+else:
+log.msg('Running "%s" succeeded' %(vcvars,))
+except Exception as e:
+log.msg('Running "%s" failed: "%s"', (vcvars, str(e)))
 return None
 
 stdout = stdout.replace("\r\n", "\n")
@@ -189,8 +191,13 @@
 self.cc = cc
 
 # detect version of current compiler
-returncode, stdout, stderr = _run_subprocess(self.cc, [],
+try:
+returncode, stdout, stderr = _run_subprocess(self.cc, [],
  env=self.c_environ)
+except EnvironmentError:
+log.msg('Could not run %s using PATH=\n%s' %(self.cc,
+'\n'.join(self.c_environ['PATH'].split(';'
+raise
 r = re.search(r'Microsoft.+C/C\+\+.+\s([0-9]+)\.([0-9]+).*', stderr)
 if r is not None:
 self.version = int(''.join(r.groups())) / 10 - 60
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-12-29 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.5
Changeset: r95535:f81df27a6bf7
Date: 2018-12-30 03:20 +0100
http://bitbucket.org/pypy/pypy/changeset/f81df27a6bf7/

Log:hg merge default

diff --git a/pypy/objspace/std/test/test_unicodeobject.py 
b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -1105,9 +1105,8 @@
 assert type(str(z)) is str
 assert str(z) == u'foobaz'
 #
-# two completely corner cases where we differ from CPython:
-#assert unicode(encoding='supposedly_the_encoding') == u''
-#assert unicode(errors='supposedly_the_error') == u''
+assert str(encoding='supposedly_the_encoding') == u''
+assert str(errors='supposedly_the_error') == u''
 e = raises(TypeError, str, u'', 'supposedly_the_encoding')
 assert str(e.value) == 'decoding str is not supported'
 e = raises(TypeError, str, u'', errors='supposedly_the_error')
diff --git a/pypy/objspace/std/unicodeobject.py 
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -223,20 +223,18 @@
 @staticmethod
 def descr_new(space, w_unicodetype, w_object=None, w_encoding=None,
   w_errors=None):
-if w_object is None:
-w_object = W_UnicodeObject.EMPTY
-w_obj = w_object
-
 encoding, errors = _get_encoding_and_errors(space, w_encoding,
 w_errors)
-if encoding is None and errors is None:
-# this is very quick if w_obj is already a w_unicode
-w_value = unicode_from_object(space, w_obj)
+if w_object is None:
+w_value = W_UnicodeObject.EMPTY
+elif encoding is None and errors is None:
+# this is very quick if w_object is already a w_unicode
+w_value = unicode_from_object(space, w_object)
 else:
-if space.isinstance_w(w_obj, space.w_unicode):
+if space.isinstance_w(w_object, space.w_unicode):
 raise oefmt(space.w_TypeError,
 "decoding str is not supported")
-w_value = unicode_from_encoded_object(space, w_obj,
+w_value = unicode_from_encoded_object(space, w_object,
   encoding, errors)
 if space.is_w(w_unicodetype, space.w_unicode):
 return w_value
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-11-20 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r95351:5811240c082f
Date: 2018-11-20 20:25 +
http://bitbucket.org/pypy/pypy/changeset/5811240c082f/

Log:hg merge default

diff --git a/extra_tests/cffi_tests/cffi1/test_parse_c_type.py 
b/extra_tests/cffi_tests/cffi1/test_parse_c_type.py
--- a/extra_tests/cffi_tests/cffi1/test_parse_c_type.py
+++ b/extra_tests/cffi_tests/cffi1/test_parse_c_type.py
@@ -4,7 +4,7 @@
 from cffi import cffi_opcode
 
 if '__pypy__' in sys.builtin_module_names:
-py.test.skip("not available on pypy")
+py.test.skip("not available on pypy", allow_module_level=True)
 
 cffi_dir = os.path.dirname(cffi_opcode.__file__)
 
diff --git a/pypy/module/_rawffi/alt/test/test_ffitype.py 
b/pypy/module/_rawffi/alt/test/test_ffitype.py
--- a/pypy/module/_rawffi/alt/test/test_ffitype.py
+++ b/pypy/module/_rawffi/alt/test/test_ffitype.py
@@ -1,6 +1,5 @@
-from pypy.module._rawffi.alt.test.test_funcptr import BaseAppTestFFI
-
-class AppTestFFIType(BaseAppTestFFI):
+class AppTestFFIType(object):
+spaceconfig = dict(usemodules=('_rawffi',))
 
 def test_simple_types(self):
 from _rawffi.alt import types
@@ -8,7 +7,7 @@
 assert str(types.uint) == ""
 assert types.sint.name == 'sint'
 assert types.uint.name == 'uint'
-
+
 def test_sizeof(self):
 from _rawffi.alt import types
 assert types.sbyte.sizeof() == 1
@@ -36,4 +35,3 @@
 assert x is types.char_p
 x = types.Pointer(types.unichar)
 assert x is types.unichar_p
-
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-11-16 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r95327:10b8fc6af4a3
Date: 2018-11-16 20:02 +
http://bitbucket.org/pypy/pypy/changeset/10b8fc6af4a3/

Log:hg merge default

diff --git a/extra_tests/__init__.py b/extra_tests/__init__.py
new file mode 100644
diff --git a/pypy/module/test_lib_pypy/cffi_tests/__init__.py 
b/extra_tests/cffi_tests/__init__.py
rename from pypy/module/test_lib_pypy/cffi_tests/__init__.py
rename to extra_tests/cffi_tests/__init__.py
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi0/__init__.py 
b/extra_tests/cffi_tests/cffi0/__init__.py
rename from pypy/module/test_lib_pypy/cffi_tests/cffi0/__init__.py
rename to extra_tests/cffi_tests/cffi0/__init__.py
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi0/backend_tests.py 
b/extra_tests/cffi_tests/cffi0/backend_tests.py
rename from pypy/module/test_lib_pypy/cffi_tests/cffi0/backend_tests.py
rename to extra_tests/cffi_tests/cffi0/backend_tests.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi0/backend_tests.py
+++ b/extra_tests/cffi_tests/cffi0/backend_tests.py
@@ -3,7 +3,7 @@
 import platform
 import sys, ctypes
 from cffi import FFI, CDefError, FFIError, VerificationMissing
-from pypy.module.test_lib_pypy.cffi_tests.support import *
+from extra_tests.cffi_tests.support import *
 
 SIZE_OF_INT   = ctypes.sizeof(ctypes.c_int)
 SIZE_OF_LONG  = ctypes.sizeof(ctypes.c_long)
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi0/callback_in_thread.py 
b/extra_tests/cffi_tests/cffi0/callback_in_thread.py
rename from pypy/module/test_lib_pypy/cffi_tests/cffi0/callback_in_thread.py
rename to extra_tests/cffi_tests/cffi0/callback_in_thread.py
diff --git 
a/pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/distutils_module/setup.py 
b/extra_tests/cffi_tests/cffi0/snippets/distutils_module/setup.py
rename from 
pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/distutils_module/setup.py
rename to extra_tests/cffi_tests/cffi0/snippets/distutils_module/setup.py
diff --git 
a/pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/distutils_module/snip_basic_verify.py
 b/extra_tests/cffi_tests/cffi0/snippets/distutils_module/snip_basic_verify.py
rename from 
pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/distutils_module/snip_basic_verify.py
rename to 
extra_tests/cffi_tests/cffi0/snippets/distutils_module/snip_basic_verify.py
diff --git 
a/pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/distutils_package_1/setup.py
 b/extra_tests/cffi_tests/cffi0/snippets/distutils_package_1/setup.py
rename from 
pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/distutils_package_1/setup.py
rename to extra_tests/cffi_tests/cffi0/snippets/distutils_package_1/setup.py
diff --git 
a/pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/distutils_package_1/snip_basic_verify1/__init__.py
 
b/extra_tests/cffi_tests/cffi0/snippets/distutils_package_1/snip_basic_verify1/__init__.py
rename from 
pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/distutils_package_1/snip_basic_verify1/__init__.py
rename to 
extra_tests/cffi_tests/cffi0/snippets/distutils_package_1/snip_basic_verify1/__init__.py
diff --git 
a/pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/distutils_package_2/setup.py
 b/extra_tests/cffi_tests/cffi0/snippets/distutils_package_2/setup.py
rename from 
pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/distutils_package_2/setup.py
rename to extra_tests/cffi_tests/cffi0/snippets/distutils_package_2/setup.py
diff --git 
a/pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/distutils_package_2/snip_basic_verify2/__init__.py
 
b/extra_tests/cffi_tests/cffi0/snippets/distutils_package_2/snip_basic_verify2/__init__.py
rename from 
pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/distutils_package_2/snip_basic_verify2/__init__.py
rename to 
extra_tests/cffi_tests/cffi0/snippets/distutils_package_2/snip_basic_verify2/__init__.py
diff --git 
a/pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/infrastructure/setup.py 
b/extra_tests/cffi_tests/cffi0/snippets/infrastructure/setup.py
rename from 
pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/infrastructure/setup.py
rename to extra_tests/cffi_tests/cffi0/snippets/infrastructure/setup.py
diff --git 
a/pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/infrastructure/snip_infrastructure/__init__.py
 
b/extra_tests/cffi_tests/cffi0/snippets/infrastructure/snip_infrastructure/__init__.py
rename from 
pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/infrastructure/snip_infrastructure/__init__.py
rename to 
extra_tests/cffi_tests/cffi0/snippets/infrastructure/snip_infrastructure/__init__.py
diff --git 
a/pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/setuptools_module/setup.py
 b/extra_tests/cffi_tests/cffi0/snippets/setuptools_module/setup.py
rename from 
pypy/module/test_lib_pypy/cffi_tests/cffi0/snippets/setuptools_module/setup.py
rename to extra_tests/cffi_tests/cffi0/snippets/setuptools_module/setup.py
diff --git 

[pypy-commit] pypy py3.5: hg merge default

2018-10-25 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r95244:c7d3ff6df4ef
Date: 2018-10-25 18:31 +0200
http://bitbucket.org/pypy/pypy/changeset/c7d3ff6df4ef/

Log:hg merge default

diff --git a/lib_pypy/pyrepl/unix_console.py b/lib_pypy/pyrepl/unix_console.py
--- a/lib_pypy/pyrepl/unix_console.py
+++ b/lib_pypy/pyrepl/unix_console.py
@@ -27,6 +27,12 @@
 from .console import Console, Event
 from .unix_eventqueue import EventQueue
 from .trace import trace
+try:
+from __pypy__ import pyos_inputhook
+except ImportError:
+def pyos_inputhook():
+pass
+
 
 class InvalidTerminal(RuntimeError):
 pass
@@ -76,8 +82,8 @@
 pass
 def register(self, fd, flag):
 self.fd = fd
-def poll(self, timeout=None):
-r,w,e = select.select([self.fd],[],[],timeout)
+def poll(self):   # note: a 'timeout' argument would be *milliseconds*
+r,w,e = select.select([self.fd],[],[])
 return r
 
 POLLIN = getattr(select, "POLLIN", None)
@@ -407,6 +413,7 @@
 def get_event(self, block=1):
 while self.event_queue.empty():
 while 1: # All hail Unix!
+pyos_inputhook()
 try:
 self.push_char(os.read(self.input_fd, 1))
 except (IOError, OSError) as err:
diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py
--- a/pypy/module/__pypy__/__init__.py
+++ b/pypy/module/__pypy__/__init__.py
@@ -110,6 +110,7 @@
 'stack_almost_full' : 'interp_magic.stack_almost_full',
 'fsencode'  : 'interp_magic.fsencode',
 'fsdecode'  : 'interp_magic.fsdecode',
+'pyos_inputhook': 'interp_magic.pyos_inputhook',
 }
 
 submodules = {
diff --git a/pypy/module/__pypy__/interp_magic.py 
b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -209,3 +209,13 @@
 def revdb_stop(space):
 from pypy.interpreter.reverse_debugging import stop_point
 stop_point()
+
+def pyos_inputhook(space):
+"""Call PyOS_InputHook() from the CPython C API."""
+if not space.config.objspace.usemodules.cpyext:
+return
+w_modules = space.sys.get('modules')
+if space.finditem_str(w_modules, 'cpyext') is None:
+return  # cpyext not imported yet, ignore
+from pypy.module.cpyext.api import invoke_pyos_inputhook
+invoke_pyos_inputhook(space)
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -647,6 +647,7 @@
 'Py_FrozenFlag', 'Py_TabcheckFlag', 'Py_UnicodeFlag', 
'Py_IgnoreEnvironmentFlag',
 'Py_DivisionWarningFlag', 'Py_DontWriteBytecodeFlag', 
'Py_NoUserSiteDirectory',
 '_Py_QnewFlag', 'Py_Py3kWarningFlag', 'Py_HashRandomizationFlag', 
'_Py_PackageContext',
+'PyOS_InputHook',
 
 'PyMem_RawMalloc', 'PyMem_RawCalloc', 'PyMem_RawRealloc', 'PyMem_RawFree',
 'PyMem_Malloc', 'PyMem_Calloc', 'PyMem_Realloc', 'PyMem_Free',
@@ -1183,6 +1184,10 @@
 state.C._PyPy_object_dealloc = rffi.llexternal(
 '_PyPy_object_dealloc', [PyObject], lltype.Void,
 compilation_info=eci, _nowrapper=True)
+FUNCPTR = lltype.Ptr(lltype.FuncType([], rffi.INT))
+state.C.get_pyos_inputhook = rffi.llexternal(
+'_PyPy_get_PyOS_InputHook', [], FUNCPTR,
+compilation_info=eci, _nowrapper=True)
 
 
 def init_function(func):
@@ -1789,6 +1794,12 @@
 return
 return exec_def(space, w_mod, mod_as_pyobj)
 
+def invoke_pyos_inputhook(space):
+state = space.fromcache(State)
+c_inputhook = state.C.get_pyos_inputhook()
+if c_inputhook:
+generic_cpy_call(space, c_inputhook)
+
 @specialize.ll()
 def generic_cpy_call(space, func, *args):
 FT = lltype.typeOf(func).TO
diff --git a/pypy/module/cpyext/include/pythonrun.h 
b/pypy/module/cpyext/include/pythonrun.h
--- a/pypy/module/cpyext/include/pythonrun.h
+++ b/pypy/module/cpyext/include/pythonrun.h
@@ -41,6 +41,11 @@
 
 #define Py_CompileString(str, filename, start) Py_CompileStringFlags(str, 
filename, start, NULL)
 
+/* Stuff with no proper home (yet) */
+PyAPI_DATA(int) (*PyOS_InputHook)(void);
+typedef int (*_pypy_pyos_inputhook)(void);
+PyAPI_FUNC(_pypy_pyos_inputhook) _PyPy_get_PyOS_InputHook(void);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/pypy/module/cpyext/src/missing.c b/pypy/module/cpyext/src/missing.c
--- a/pypy/module/cpyext/src/missing.c
+++ b/pypy/module/cpyext/src/missing.c
@@ -31,3 +31,7 @@
 void _Py_setfilesystemdefaultencoding(const char *enc) {
 Py_FileSystemDefaultEncoding = enc;
 }
+int (*PyOS_InputHook)(void) = 0;  /* only ever filled in by C extensions */
+PyAPI_FUNC(_pypy_pyos_inputhook) _PyPy_get_PyOS_InputHook(void) {
+return PyOS_InputHook;
+}
diff --git a/pypy/module/cpyext/test/test_misc.py 
b/pypy/module/cpyext/test/test_misc.py
new file mode 100644
--- 

[pypy-commit] pypy py3.5: hg merge default

2018-10-20 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r95227:115a0ddc5b54
Date: 2018-10-20 14:48 +0200
http://bitbucket.org/pypy/pypy/changeset/115a0ddc5b54/

Log:hg merge default

diff --git a/pypy/module/_cffi_backend/cdlopen.py 
b/pypy/module/_cffi_backend/cdlopen.py
--- a/pypy/module/_cffi_backend/cdlopen.py
+++ b/pypy/module/_cffi_backend/cdlopen.py
@@ -1,31 +1,24 @@
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
 from rpython.rlib.objectmodel import specialize, we_are_translated
-from rpython.rlib.rdynload import DLLHANDLE, dlopen, dlsym, dlclose, 
DLOpenError
+from rpython.rlib.rdynload import DLLHANDLE, dlsym, dlclose
 
 from pypy.interpreter.error import oefmt
-from pypy.module._rawffi.interp_rawffi import wrap_dlopenerror
 
 from pypy.module._cffi_backend.parse_c_type import (
 _CFFI_OPCODE_T, GLOBAL_S, CDL_INTCONST_S, STRUCT_UNION_S, FIELD_S,
 ENUM_S, TYPENAME_S, ll_set_cdl_realize_global_int)
 from pypy.module._cffi_backend.realize_c_type import getop
 from pypy.module._cffi_backend.lib_obj import W_LibObject
-from pypy.module._cffi_backend import cffi_opcode, cffi1_module
-
+from pypy.module._cffi_backend import cffi_opcode, cffi1_module, misc
 
 class W_DlOpenLibObject(W_LibObject):
 
-def __init__(self, ffi, filename, flags):
-with rffi.scoped_str2charp(filename) as ll_libname:
-if filename is None:
-filename = ""
-try:
-handle = dlopen(ll_libname, flags)
-except DLOpenError as e:
-raise wrap_dlopenerror(ffi.space, e, filename)
-W_LibObject.__init__(self, ffi, filename)
+def __init__(self, ffi, w_filename, flags):
+space = ffi.space
+fname, handle = misc.dlopen_w(space, w_filename, flags)
+W_LibObject.__init__(self, ffi, fname)
 self.libhandle = handle
-self.register_finalizer(ffi.space)
+self.register_finalizer(space)
 
 def _finalize_(self):
 h = self.libhandle
diff --git a/pypy/module/_cffi_backend/ffi_obj.py 
b/pypy/module/_cffi_backend/ffi_obj.py
--- a/pypy/module/_cffi_backend/ffi_obj.py
+++ b/pypy/module/_cffi_backend/ffi_obj.py
@@ -572,8 +572,8 @@
 return self.ffi_type(w_arg, ACCEPT_STRING | ACCEPT_CDATA)
 
 
-@unwrap_spec(filename="fsencode_or_none", flags=int)
-def descr_dlopen(self, filename, flags=0):
+@unwrap_spec(flags=int)
+def descr_dlopen(self, w_filename, flags=0):
 """\
 Load and return a dynamic library identified by 'name'.  The standard
 C library can be loaded by passing None.
@@ -584,7 +584,7 @@
 first access."""
 #
 from pypy.module._cffi_backend import cdlopen
-return cdlopen.W_DlOpenLibObject(self, filename, flags)
+return cdlopen.W_DlOpenLibObject(self, w_filename, flags)
 
 
 def descr_dlclose(self, w_lib):
diff --git a/pypy/module/_cffi_backend/libraryobj.py 
b/pypy/module/_cffi_backend/libraryobj.py
--- a/pypy/module/_cffi_backend/libraryobj.py
+++ b/pypy/module/_cffi_backend/libraryobj.py
@@ -4,28 +4,21 @@
 from pypy.interpreter.error import oefmt
 from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef
-from pypy.module._rawffi.interp_rawffi import wrap_dlopenerror
 
 from rpython.rtyper.lltypesystem import rffi
-from rpython.rlib.rdynload import DLLHANDLE, dlopen, dlsym, dlclose, 
DLOpenError
+from rpython.rlib.rdynload import DLLHANDLE, dlsym, dlclose
 
 from pypy.module._cffi_backend.cdataobj import W_CData
 from pypy.module._cffi_backend.ctypeobj import W_CType
+from pypy.module._cffi_backend import misc
 
 
 class W_Library(W_Root):
 _immutable_ = True
 
-def __init__(self, space, filename, flags):
+def __init__(self, space, w_filename, flags):
 self.space = space
-with rffi.scoped_str2charp(filename) as ll_libname:
-if filename is None:
-filename = ""
-try:
-self.handle = dlopen(ll_libname, flags)
-except DLOpenError as e:
-raise wrap_dlopenerror(space, e, filename)
-self.name = filename
+self.name, self.handle = misc.dlopen_w(space, w_filename, flags)
 self.register_finalizer(space)
 
 def _finalize_(self):
@@ -104,7 +97,7 @@
 W_Library.typedef.acceptable_as_base_class = False
 
 
-@unwrap_spec(filename="fsencode_or_none", flags=int)
-def load_library(space, filename, flags=0):
-lib = W_Library(space, filename, flags)
+@unwrap_spec(flags=int)
+def load_library(space, w_filename, flags=0):
+lib = W_Library(space, w_filename, flags)
 return lib
diff --git a/pypy/module/_cffi_backend/misc.py 
b/pypy/module/_cffi_backend/misc.py
--- a/pypy/module/_cffi_backend/misc.py
+++ b/pypy/module/_cffi_backend/misc.py
@@ -1,15 +1,24 @@
 from __future__ import with_statement
+import sys
 
 from pypy.interpreter.error import OperationError, oefmt
+from pypy.module._rawffi.interp_rawffi import wrap_dlopenerror
 
 from 

[pypy-commit] pypy py3.5: hg merge default

2018-10-08 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r95194:248ed5fa4ded
Date: 2018-10-08 20:30 +0200
http://bitbucket.org/pypy/pypy/changeset/248ed5fa4ded/

Log:hg merge default

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
@@ -761,6 +761,26 @@
 assert b"\\u3042\u3xxx".decode("unicode-escape", "test.handler1") == \
 u"\u3042[<92><117><51>]xxx"
 
+def test_unicode_internal_error_handler_infinite_loop(self):
+import codecs
+class MyException(Exception):
+pass
+seen = [0]
+def handler_unicodeinternal(exc):
+if not isinstance(exc, UnicodeDecodeError):
+raise TypeError("don't know how to handle %r" % exc)
+seen[0] += 1
+if seen[0] == 20:   # stop the 20th time this is called
+raise MyException
+return (u"\x01", 4)   # 4 < len(input), so will try and fail again
+codecs.register_error("test.inf", handler_unicodeinternal)
+try:
+b"\x00\x00\x00\x00\x00".decode("unicode-internal", "test.inf")
+except MyException:
+pass
+else:
+raise AssertionError("should have gone into infinite loop")
+
 def test_encode_error_bad_handler(self):
 import codecs
 codecs.register_error("test.bad_handler", lambda e: (repl, 1))
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -93,8 +93,11 @@
 
 if sys.platform == 'win32':
 dash = '_'
+WIN32 = True
 else:
 dash = ''
+WIN32 = False
+
 
 def fclose(fp):
 try:
@@ -610,7 +613,7 @@
 'PyObject_CallMethod', 'PyObject_CallFunctionObjArgs', 
'PyObject_CallMethodObjArgs',
 '_PyObject_CallFunction_SizeT', '_PyObject_CallMethod_SizeT',
 
-'PyObject_GetBuffer', 'PyBuffer_Release',
+'PyObject_DelItemString', 'PyObject_GetBuffer', 'PyBuffer_Release',
 '_Py_setfilesystemdefaultencoding',
 
 'PyCapsule_New', 'PyCapsule_IsValid', 'PyCapsule_GetPointer',
@@ -1664,7 +1667,11 @@
 try:
 ll_libname = rffi.str2charp(path)
 try:
-dll = rdynload.dlopen(ll_libname, space.sys.dlopenflags)
+if WIN32:
+# Allow other DLLs in the same directory with "path"
+dll = rdynload.dlopenex(ll_libname)
+else:
+dll = rdynload.dlopen(ll_libname, space.sys.dlopenflags)
 finally:
 lltype.free(ll_libname, flavor='raw')
 except rdynload.DLOpenError as e:
diff --git a/pypy/module/cpyext/eval.py b/pypy/module/cpyext/eval.py
--- a/pypy/module/cpyext/eval.py
+++ b/pypy/module/cpyext/eval.py
@@ -9,6 +9,7 @@
 from pypy.module.cpyext.pyobject import PyObject
 from pypy.module.cpyext.pyerrors import PyErr_SetFromErrno
 from pypy.module.cpyext.funcobject import PyCodeObject
+from pypy.module.cpyext.frameobject import PyFrameObject
 from pypy.module.__builtin__ import compiling
 
 PyCompilerFlags = cpython_struct(
@@ -58,6 +59,11 @@
 return None
 return caller.get_w_globals()# borrowed ref
 
+@cpython_api([], PyFrameObject, error=CANNOT_FAIL, result_borrowed=True)
+def PyEval_GetFrame(space):
+caller = space.getexecutioncontext().gettopframe_nohidden()
+return caller# borrowed ref, may be null
+
 @cpython_api([PyCodeObject, PyObject, PyObject], PyObject)
 def PyEval_EvalCode(space, w_code, w_globals, w_locals):
 """This is a simplified interface to PyEval_EvalCodeEx(), with just
diff --git a/pypy/module/cpyext/include/abstract.h 
b/pypy/module/cpyext/include/abstract.h
--- a/pypy/module/cpyext/include/abstract.h
+++ b/pypy/module/cpyext/include/abstract.h
@@ -4,6 +4,15 @@
 extern "C" {
 #endif
 
+ PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, char *key);
+
+   /*
+ Remove the mapping for object, key, from the object *o.
+ Returns -1 on failure.  This is equivalent to
+ the Python statement: del o[key].
+   */
+
+
 /* new buffer API */
 
 #define PyObject_CheckBuffer(obj) \
@@ -27,6 +36,27 @@
 /* Releases a Py_buffer obtained from getbuffer ParseTuple's s*.
 */
 
+/*  Mapping protocol:*/
+
+ /* implemented as a macro:
+
+ int PyMapping_DelItemString(PyObject *o, char *key);
+
+ Remove the mapping for object, key, from the object *o.
+ Returns -1 on failure.  This is equivalent to
+ the Python statement: del o[key].
+   */
+#define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K))
+
+ /* implemented as a macro:
+
+ int PyMapping_DelItem(PyObject *o, PyObject *key);
+
+ Remove the mapping for object, key, from the object *o.
+ Returns -1 on failure.  This is equivalent to
+ the Python statement: del o[key].
+   */
+#define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K))
 
 #ifdef __cplusplus
 }

[pypy-commit] pypy py3.5: hg merge default

2018-09-23 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r95155:700122e469d9
Date: 2018-09-23 11:07 +0200
http://bitbucket.org/pypy/pypy/changeset/700122e469d9/

Log:hg merge default

diff --git a/lib-python/3/test/test_inspect.py 
b/lib-python/3/test/test_inspect.py
--- a/lib-python/3/test/test_inspect.py
+++ b/lib-python/3/test/test_inspect.py
@@ -61,6 +61,9 @@
 
 git = mod.StupidGit()
 
+class ExampleClassWithSlot(object):
+__slots__ = 'myslot'
+
 class IsTestBase(unittest.TestCase):
 predicates = set([inspect.isbuiltin, inspect.isclass, inspect.iscode,
   inspect.isframe, inspect.isfunction, inspect.ismethod,
@@ -131,8 +134,11 @@
 self.istest(inspect.iscoroutinefunction, 
'coroutine_function_example')
 
 if hasattr(types, 'MemberDescriptorType'):
-self.istest(inspect.ismemberdescriptor,
-'type(lambda: None).__globals__')
+# App-level slots are member descriptors on both PyPy and
+# CPython, but the various built-in attributes are all
+# getsetdescriptors on PyPy.  So check ismemberdescriptor()
+# with an app-level slot.
+self.istest(inspect.ismemberdescriptor, 
'ExampleClassWithSlot.myslot')
 else:
 
self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days))
 
diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -486,6 +486,8 @@
 return cobj, cobj._to_ffi_param(), type(cobj)
 
 def _convert_args_for_callback(self, argtypes, args):
+from _ctypes.structure import StructOrUnion
+#
 assert len(argtypes) == len(args)
 newargs = []
 for argtype, arg in zip(argtypes, args):
@@ -495,6 +497,10 @@
 param = param._get_buffer_value()
 elif self._is_primitive(argtype):
 param = param.value
+elif isinstance(param, StructOrUnion):   # not a *pointer* to 
struct
+newparam = StructOrUnion.__new__(type(param))
+param._copy_to(newparam._buffer.buffer)
+param = newparam
 newargs.append(param)
 return newargs
 
diff --git a/lib_pypy/cffi/setuptools_ext.py b/lib_pypy/cffi/setuptools_ext.py
--- a/lib_pypy/cffi/setuptools_ext.py
+++ b/lib_pypy/cffi/setuptools_ext.py
@@ -162,6 +162,17 @@
 module_path = module_name.split('.')
 module_path[-1] += '.py'
 generate_mod(os.path.join(self.build_lib, *module_path))
+def get_source_files(self):
+# This is called from 'setup.py sdist' only.  Exclude
+# the generate .py module in this case.
+saved_py_modules = self.py_modules
+try:
+if saved_py_modules:
+self.py_modules = [m for m in saved_py_modules
+ if m != module_name]
+return base_class.get_source_files(self)
+finally:
+self.py_modules = saved_py_modules
 dist.cmdclass['build_py'] = build_py_make_mod
 
 # distutils and setuptools have no notion I could find of a
@@ -171,6 +182,7 @@
 # the module.  So we add it here, which gives a few apparently
 # harmless warnings about not finding the file outside the
 # build directory.
+# Then we need to hack more in get_source_files(); see above.
 if dist.py_modules is None:
 dist.py_modules = []
 dist.py_modules.append(module_name)
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
@@ -36,3 +36,6 @@
 .. branch: pyparser-improvements-3
 
 Small refactorings in the Python parser.
+
+.. branch: fix-readme-typo
+
diff --git a/pypy/module/__builtin__/functional.py 
b/pypy/module/__builtin__/functional.py
--- a/pypy/module/__builtin__/functional.py
+++ b/pypy/module/__builtin__/functional.py
@@ -108,101 +108,98 @@
 max_jitdriver = jit.JitDriver(name='max',
 greens=['has_key', 'has_item', 'w_type'], reds='auto')
 
-def make_min_max(unroll):
-@specialize.arg(2)
-def min_max_impl(space, args, implementation_of):
-if implementation_of == "max":
-compare = space.gt
-jitdriver = max_jitdriver
+@specialize.arg(4)
+def min_max_sequence(space, w_sequence, w_key, w_default, implementation_of):
+if implementation_of == "max":
+compare = space.gt
+jitdriver = max_jitdriver
+else:
+compare = space.lt
+jitdriver = min_jitdriver
+w_iter = space.iter(w_sequence)
+w_type = space.type(w_iter)
+has_key = w_key is not None
+has_item = False
+w_max_item = w_default
+w_max_val = None
+while True:
+jitdriver.jit_merge_point(has_key=has_key, has_item=has_item,
+  w_type=w_type)
+try:
+w_item 

[pypy-commit] pypy py3.5: hg merge default

2018-09-15 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r95127:d9a97ab80c60
Date: 2018-09-16 00:03 +0200
http://bitbucket.org/pypy/pypy/changeset/d9a97ab80c60/

Log:hg merge default

diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py 
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -342,11 +342,7 @@
 py.test.raises(OverflowError, newp, pp, max + 1)
 py.test.raises(OverflowError, newp, pp, min - 1 - 2 ** 32)
 py.test.raises(OverflowError, newp, pp, min - 1 - 2 ** 64)
-py.test.raises(OverflowError, newp, pp, min - 1 + 2 ** 32)
-py.test.raises(OverflowError, newp, pp, min - 1 + 2 ** 64)
 py.test.raises(OverflowError, newp, pp, max + 1)
-py.test.raises(OverflowError, newp, pp, max + 1 - 2 ** 32)
-py.test.raises(OverflowError, newp, pp, max + 1 - 2 ** 64)
 py.test.raises(OverflowError, newp, pp, max + 1 + 2 ** 32)
 py.test.raises(OverflowError, newp, pp, max + 1 + 2 ** 64)
 py.test.raises(TypeError, newp, pp, 1.0)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-09-15 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r95125:3b0f38d2f3e8
Date: 2018-09-15 23:53 +0200
http://bitbucket.org/pypy/pypy/changeset/3b0f38d2f3e8/

Log:hg merge default

diff --git a/pypy/module/_cffi_backend/misc.py 
b/pypy/module/_cffi_backend/misc.py
--- a/pypy/module/_cffi_backend/misc.py
+++ b/pypy/module/_cffi_backend/misc.py
@@ -135,21 +135,14 @@
 # This version accepts a Python int too, and does convertions from
 # other types of objects.  It refuses floats.
 try:
-value = space.int_w(w_ob)
+return space.int_w(w_ob, allow_conversion=False)
 except OperationError as e:
 if not (e.match(space, space.w_OverflowError) or
 e.match(space, space.w_TypeError)):
 raise
-else:
-return value
-try:
-bigint = space.bigint_w(w_ob, allow_conversion=False)
-except OperationError as e:
-if not e.match(space, space.w_TypeError):
-raise
 if _is_a_float(space, w_ob):
 raise
-bigint = space.bigint_w(space.int(w_ob), allow_conversion=False)
+bigint = space.bigint_w(w_ob, allow_conversion=True)
 try:
 return bigint.tolonglong()
 except OverflowError:
@@ -157,20 +150,15 @@
 
 def as_long(space, w_ob):
 # Same as as_long_long(), but returning an int instead.
-if space.isinstance_w(w_ob, space.w_int):  # shortcut
-return space.int_w(w_ob)
 try:
-bigint = space.bigint_w(w_ob, allow_conversion=False)
+return space.int_w(w_ob, allow_conversion=False)
 except OperationError as e:
-if not e.match(space, space.w_TypeError):
+if not (e.match(space, space.w_OverflowError) or
+e.match(space, space.w_TypeError)):
 raise
 if _is_a_float(space, w_ob):
 raise
-bigint = space.bigint_w(space.int(w_ob), allow_conversion=False)
-try:
-return bigint.toint()
-except OverflowError:
-raise OperationError(space.w_OverflowError, space.newtext(ovf_msg))
+return space.int_w(w_ob, allow_conversion=True)
 
 def as_unsigned_long_long(space, w_ob, strict):
 # (possibly) convert and cast a Python object to an unsigned long long.
@@ -178,23 +166,19 @@
 # objects.  If 'strict', complains with OverflowError; if 'not strict',
 # mask the result and round floats.
 try:
-value = space.int_w(w_ob)
+value = space.int_w(w_ob, allow_conversion=False)
 except OperationError as e:
 if not (e.match(space, space.w_OverflowError) or
 e.match(space, space.w_TypeError)):
 raise
+if strict and _is_a_float(space, w_ob):
+raise
 else:
 if strict and value < 0:
 raise OperationError(space.w_OverflowError, space.newtext(neg_msg))
 return r_ulonglong(value)
-try:
-bigint = space.bigint_w(w_ob, allow_conversion=False)
-except OperationError as e:
-if not e.match(space, space.w_TypeError):
-raise
-if strict and _is_a_float(space, w_ob):
-raise
-bigint = space.bigint_w(space.int(w_ob), allow_conversion=False)
+# note that if not 'strict', then space.int() will round down floats
+bigint = space.bigint_w(space.int(w_ob), allow_conversion=False)
 if strict:
 try:
 return bigint.toulonglong()
@@ -208,13 +192,19 @@
 def as_unsigned_long(space, w_ob, strict):
 # same as as_unsigned_long_long(), but returning just an Unsigned
 try:
-bigint = space.bigint_w(w_ob, allow_conversion=False)
+value = space.int_w(w_ob, allow_conversion=False)
 except OperationError as e:
-if not e.match(space, space.w_TypeError):
+if not (e.match(space, space.w_OverflowError) or
+e.match(space, space.w_TypeError)):
 raise
 if strict and _is_a_float(space, w_ob):
 raise
-bigint = space.bigint_w(space.int(w_ob), allow_conversion=False)
+else:
+if strict and value < 0:
+raise OperationError(space.w_OverflowError, space.newtext(neg_msg))
+return r_uint(value)
+# note that if not 'strict', then space.int() will round down floats
+bigint = space.bigint_w(space.int(w_ob), allow_conversion=False)
 if strict:
 try:
 return bigint.touint()
@@ -247,7 +237,12 @@
 
 def _standard_object_as_bool(space, w_ob):
 if space.isinstance_w(w_ob, space.w_int):
-return space.bigint_w(w_ob).tobool()
+try:
+return space.int_w(w_ob) != 0
+except OperationError as e:
+if not e.match(space, space.w_OverflowError):
+raise
+return space.bigint_w(w_ob).tobool()
 if space.isinstance_w(w_ob, space.w_float):
 return space.float_w(w_ob) != 0.0
 raise _NotStandardObject
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py 

[pypy-commit] pypy py3.5: hg merge default

2018-09-15 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r95123:84f081c9bba4
Date: 2018-09-15 22:53 +0200
http://bitbucket.org/pypy/pypy/changeset/84f081c9bba4/

Log:hg merge default

diff --git a/README.rst b/README.rst
--- a/README.rst
+++ b/README.rst
@@ -4,7 +4,7 @@
 
 Welcome to PyPy!
 
-PyPy is an interperter that implements the Python programming language, based
+PyPy is an interpreter that implements the Python programming language, based
 on the RPython compiler framework for dynamic language implementations.
 
 The home page for the interpreter is:
@@ -15,29 +15,29 @@
 
 http://doc.pypy.org/
 
-More documentation about the RPython framework can be found here
+More documentation about the RPython framework can be found here:
 
-http://rpython.readthedocs.io
+http://rpython.readthedocs.io/
 
-The source for the documentation is in the pypy/doc directory 
+The source for the documentation is in the pypy/doc directory.
+
 
 Using PyPy instead of CPython
-=
+-
 
-Please read the information at http://pypy.org to find the correct way to
+Please read the information at http://pypy.org/ to find the correct way to
 download and use PyPy as an alternative to CPython. 
 
+
 Building
-
+
 
 Building PyPy is not the recommended way to obtain the PyPy alternative python
 interpreter. It is time-consuming and requires significant computing resources.
-More information can be found here
+More information can be found here:
 
 http://doc.pypy.org/en/latest/build.html
 
 Enjoy and send us feedback!
 
 the pypy-dev team 
-
-
diff --git a/pypy/module/_cffi_backend/ctypeptr.py 
b/pypy/module/_cffi_backend/ctypeptr.py
--- a/pypy/module/_cffi_backend/ctypeptr.py
+++ b/pypy/module/_cffi_backend/ctypeptr.py
@@ -317,9 +317,7 @@
 if isinstance(self.ctitem, ctypeprim.W_CTypePrimitiveBool):
 self._must_be_string_of_zero_or_one(value)
 keepalives[i] = value
-buf, buf_flag = rffi.get_nonmovingbuffer_final_null(value)
-rffi.cast(rffi.CCHARPP, cdata)[0] = buf
-return ord(buf_flag)# 4, 5 or 6
+return misc.write_string_as_charp(cdata, value)
 #
 if (space.isinstance_w(w_init, space.w_list) or
 space.isinstance_w(w_init, space.w_tuple)):
diff --git a/pypy/module/_cffi_backend/misc.py 
b/pypy/module/_cffi_backend/misc.py
--- a/pypy/module/_cffi_backend/misc.py
+++ b/pypy/module/_cffi_backend/misc.py
@@ -3,7 +3,7 @@
 from pypy.interpreter.error import OperationError, oefmt
 
 from rpython.rlib import jit
-from rpython.rlib.objectmodel import specialize
+from rpython.rlib.objectmodel import specialize, we_are_translated
 from rpython.rlib.rarithmetic import r_uint, r_ulonglong
 from rpython.rlib.unroll import unrolling_iterable
 from rpython.rtyper.lltypesystem import lltype, llmemory, rffi
@@ -102,6 +102,12 @@
 def write_raw_longdouble_data(target, source):
 rffi.cast(rffi.LONGDOUBLEP, target)[0] = source
 
+@jit.dont_look_inside# lets get_nonmovingbuffer_final_null be inlined
+def write_string_as_charp(target, string):
+buf, buf_flag = rffi.get_nonmovingbuffer_final_null(string)
+rffi.cast(rffi.CCHARPP, target)[0] = buf
+return ord(buf_flag)# 4, 5 or 6
+
 # 
 
 sprintf_longdouble = rffi.llexternal(
@@ -151,7 +157,7 @@
 
 def as_long(space, w_ob):
 # Same as as_long_long(), but returning an int instead.
-if space.is_w(space.type(w_ob), space.w_int):   # shortcut
+if space.isinstance_w(w_ob, space.w_int):  # shortcut
 return space.int_w(w_ob)
 try:
 bigint = space.bigint_w(w_ob, allow_conversion=False)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-09-11 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r95092:cbe861385419
Date: 2018-09-11 15:38 +0200
http://bitbucket.org/pypy/pypy/changeset/cbe861385419/

Log:hg merge default

diff --git a/pypy/objspace/std/test/test_unicodeobject.py 
b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -1105,7 +1105,12 @@
 assert type(str(z)) is str
 assert str(z) == u'foobaz'
 #
-e = raises(TypeError, str, u'text', 'supposedly_the_encoding')
+# two completely corner cases where we differ from CPython:
+#assert unicode(encoding='supposedly_the_encoding') == u''
+#assert unicode(errors='supposedly_the_error') == u''
+e = raises(TypeError, str, u'', 'supposedly_the_encoding')
+assert str(e.value) == 'decoding str is not supported'
+e = raises(TypeError, str, u'', errors='supposedly_the_error')
 assert str(e.value) == 'decoding str is not supported'
 e = raises(TypeError, str, u, 'supposedly_the_encoding')
 assert str(e.value) == 'decoding str is not supported'
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-09-11 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r95090:ae9f77ce8df2
Date: 2018-09-11 15:30 +0200
http://bitbucket.org/pypy/pypy/changeset/ae9f77ce8df2/

Log:hg merge default

diff --git a/pypy/doc/cpython_differences.rst b/pypy/doc/cpython_differences.rst
--- a/pypy/doc/cpython_differences.rst
+++ b/pypy/doc/cpython_differences.rst
@@ -330,7 +330,8 @@
 -
 
 * Hash randomization (``-R``) `is ignored in PyPy`_.  In CPython
-  before 3.4 it has `little point`_.
+  before 3.4 it has `little point`_.  Both CPython >= 3.4 and PyPy3
+  implement the randomized SipHash algorithm and ignore ``-R``.
 
 * You can't store non-string keys in type objects.  For example::
 
diff --git a/pypy/module/select/__init__.py b/pypy/module/select/__init__.py
--- a/pypy/module/select/__init__.py
+++ b/pypy/module/select/__init__.py
@@ -3,6 +3,7 @@
 
 import sys
 import os
+from rpython.rlib import _rsocket_rffi as _c
 
 
 class Module(MixedModule):
@@ -31,6 +32,10 @@
 for symbol in symbol_map:
 interpleveldefs[symbol] = "space.wrap(interp_kqueue.%s)" % symbol
 
+if _c.PIPE_BUF is not None:
+interpleveldefs['PIPE_BUF'] = 'space.wrap(%r)' % _c.PIPE_BUF
+
+
 def buildloaders(cls):
 from rpython.rlib import rpoll
 for name in rpoll.eventnames:
diff --git a/pypy/module/select/test/test_select.py 
b/pypy/module/select/test/test_select.py
--- a/pypy/module/select/test/test_select.py
+++ b/pypy/module/select/test/test_select.py
@@ -319,6 +319,11 @@
 # ^^^ CPython gives 100, PyPy gives 1.  I think both are OK as
 # long as there is no crash.
 
+def test_PIPE_BUF(self):
+# no PIPE_BUF on Windows; this test class is skipped on Windows.
+import select
+assert isinstance(select.PIPE_BUF, int)
+
 
 class AppTestSelectWithSockets(_AppTestSelect):
 """Same tests with connected sockets.
diff --git a/pypy/objspace/std/test/test_unicodeobject.py 
b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -1088,3 +1088,26 @@
 assert u'A\u03a3\u0345'.lower() == u'a\u03c2\u0345'
 assert u'\u03a3\u0345 '.lower() == u'\u03c3\u0345 '
 
+def test_unicode_constructor_misc(self):
+x = u'foo'
+x += u'bar'
+assert str(x) is x
+#
+class U(str):
+def __str__(self):
+return u'BOK'
+u = U(x)
+assert str(u) == u'BOK'
+#
+class U2(str):
+pass
+z = U2(u'foobaz')
+assert type(str(z)) is str
+assert str(z) == u'foobaz'
+#
+e = raises(TypeError, str, u'text', 'supposedly_the_encoding')
+assert str(e.value) == 'decoding str is not supported'
+e = raises(TypeError, str, u, 'supposedly_the_encoding')
+assert str(e.value) == 'decoding str is not supported'
+e = raises(TypeError, str, z, 'supposedly_the_encoding')
+assert str(e.value) == 'decoding str is not supported'
diff --git a/rpython/doc/examples.rst b/rpython/doc/examples.rst
--- a/rpython/doc/examples.rst
+++ b/rpython/doc/examples.rst
@@ -19,7 +19,7 @@
   * Typhon, 'A virtual machine for Monte', in active development,
 https://github.com/monte-language/typhon
   * Tulip, an untyped functional language, in language design mode, maintained,
- https://github.com/tulip-lang/tulip/
+https://github.com/tulip-lang/tulip/
   * Pycket, a Racket implementation, proof of concept, small language core
 working, a lot of primitives are missing. Slow development 
 https://github.com/samth/pycket
diff --git a/rpython/rlib/_rsocket_rffi.py b/rpython/rlib/_rsocket_rffi.py
--- a/rpython/rlib/_rsocket_rffi.py
+++ b/rpython/rlib/_rsocket_rffi.py
@@ -33,6 +33,7 @@
 'arpa/inet.h',
 'stdint.h',
 'errno.h',
+'limits.h',
 )
 if _HAS_AF_PACKET:
 includes += ('netpacket/packet.h',
@@ -113,6 +114,7 @@
 F_GETFL = platform.DefinedConstantInteger('F_GETFL')
 F_SETFL = platform.DefinedConstantInteger('F_SETFL')
 FIONBIO = platform.DefinedConstantInteger('FIONBIO')
+PIPE_BUF = platform.DefinedConstantInteger('PIPE_BUF')
 
 INVALID_SOCKET = platform.DefinedConstantInteger('INVALID_SOCKET')
 INET_ADDRSTRLEN = platform.DefinedConstantInteger('INET_ADDRSTRLEN')
@@ -1085,6 +1087,7 @@
 WSAEWOULDBLOCK = cConfig.WSAEWOULDBLOCK or cConfig.EWOULDBLOCK
 WSAEAFNOSUPPORT = cConfig.WSAEAFNOSUPPORT or cConfig.EAFNOSUPPORT
 EISCONN = cConfig.EISCONN or cConfig.WSAEISCONN
+PIPE_BUF = cConfig.PIPE_BUF# may be None
 
 linux = cConfig.linux
 WIN32 = cConfig.WIN32
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-09-01 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r95058:33d16cf29160
Date: 2018-09-01 15:56 +0200
http://bitbucket.org/pypy/pypy/changeset/33d16cf29160/

Log:hg merge default

diff --git a/lib_pypy/_ctypes/array.py b/lib_pypy/_ctypes/array.py
--- a/lib_pypy/_ctypes/array.py
+++ b/lib_pypy/_ctypes/array.py
@@ -189,6 +189,7 @@
 self._buffer = self._ffiarray(self._length_, autofree=True)
 for i, arg in enumerate(args):
 self[i] = arg
+_init_no_arg_ = __init__
 
 def _fix_index(self, index):
 if index < 0:
diff --git a/lib_pypy/_ctypes/basics.py b/lib_pypy/_ctypes/basics.py
--- a/lib_pypy/_ctypes/basics.py
+++ b/lib_pypy/_ctypes/basics.py
@@ -110,7 +110,7 @@
 raise ValueError(
 "Buffer size too small (%d instead of at least %d bytes)"
 % (buf.nbytes, offset + size))
-result = self()
+result = self._newowninstance_()
 dest = result._buffer.buffer
 try:
 raw_addr = buf._pypy_raw_address() + offset
@@ -121,6 +121,11 @@
 memmove(dest, raw_addr, size)
 return result
 
+def _newowninstance_(self):
+result = self.__new__(self)
+result._init_no_arg_()
+return result
+
 
 class CArgObject(object):
 """ simple wrapper around buffer, just for the case of freeing
@@ -151,6 +156,7 @@
 
 def __init__(self, *args, **kwds):
 raise TypeError("%s has no type" % (type(self),))
+_init_no_arg_ = __init__
 
 def _ensure_objects(self):
 if '_objects' not in self.__dict__:
diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -267,6 +267,7 @@
 return
 
 raise TypeError("Unknown constructor %s" % (args,))
+_init_no_arg_ = __init__
 
 def _wrap_callable(self, to_call, argtypes):
 def f(*args):
@@ -557,7 +558,7 @@
 keepalive, newarg, newargtype = 
self._conv_param(argtype, defval)
 else:
 import ctypes
-val = argtype._type_()
+val = argtype._type_._newowninstance_()
 keepalive = None
 newarg = ctypes.byref(val)
 newargtype = type(newarg)
diff --git a/lib_pypy/_ctypes/pointer.py b/lib_pypy/_ctypes/pointer.py
--- a/lib_pypy/_ctypes/pointer.py
+++ b/lib_pypy/_ctypes/pointer.py
@@ -67,8 +67,11 @@
 self._buffer = ffiarray(1, autofree=True)
 if value is not None:
 self.contents = value
+def _init_no_arg_(self):
+self._buffer = ffiarray(1, autofree=True)
 self._ffiarray = ffiarray
 self.__init__ = __init__
+self._init_no_arg_ = _init_no_arg_
 self._type_ = TP
 
 def _build_ffiargtype(self):
@@ -136,27 +139,21 @@
 if not (isinstance(tp, _CDataMeta) and tp._is_pointer_like()):
 raise TypeError("cast() argument 2 must be a pointer type, not %s"
 % (tp,))
+result = tp._newowninstance_()
 if isinstance(obj, int):
-result = tp()
 result._buffer[0] = obj
 return result
 elif obj is None:
-result = tp()
 return result
 elif isinstance(obj, Array):
-ptr = tp.__new__(tp)
-ptr._buffer = tp._ffiarray(1, autofree=True)
-ptr._buffer[0] = obj._buffer
-result = ptr
+result._buffer[0] = obj._buffer
 elif isinstance(obj, bytes):
-result = tp()
 result._buffer[0] = memoryview(obj)._pypy_raw_address()
 return result
 elif not (isinstance(obj, _CData) and type(obj)._is_pointer_like()):
 raise TypeError("cast() argument 1 must be a pointer, not %s"
 % (type(obj),))
 else:
-result = tp()
 result._buffer[0] = obj._buffer[0]
 
 # The casted objects '_objects' member:
diff --git a/lib_pypy/_ctypes/primitive.py b/lib_pypy/_ctypes/primitive.py
--- a/lib_pypy/_ctypes/primitive.py
+++ b/lib_pypy/_ctypes/primitive.py
@@ -378,11 +378,14 @@
 self._buffer = self._ffiarray(1, autofree=True)
 if value is not DEFAULT_VALUE:
 self.value = value
+_init_no_arg_ = __init__
 
 def _ensure_objects(self):
-if self._type_ not in 'zZP':
-assert self._objects is None
-return self._objects
+# No '_objects' is the common case for primitives.  Examples
+# where there is an _objects is if _type in 'zZP', or if
+# self comes from 'from_buffer(buf)'.  See module/test_lib_pypy/
+# ctypes_test/test_buffers.py: test_from_buffer_keepalive.
+return getattr(self, '_objects', None)
 
 def _getvalue(self):
 return self._buffer[0]
diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py
--- a/lib_pypy/_ctypes/structure.py
+++ 

[pypy-commit] pypy py3.5: hg merge default (and port the changes from 2.7/types.py to 3/types.py)

2018-08-09 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r94983:f938ea58f52c
Date: 2018-08-09 16:32 +0200
http://bitbucket.org/pypy/pypy/changeset/f938ea58f52c/

Log:hg merge default (and port the changes from 2.7/types.py to
3/types.py)

diff --git a/lib-python/3/types.py b/lib-python/3/types.py
--- a/lib-python/3/types.py
+++ b/lib-python/3/types.py
@@ -41,9 +41,19 @@
 FrameType = type(tb.tb_frame)
 tb = None; del tb
 
-# For Jython, the following two types are identical
+#
+# On CPython, FunctionType.__code__ is a 'getset_descriptor', but
+# FunctionType.__globals__ is a 'member_descriptor', just like app-level
+# slots.  On PyPy, all descriptors of built-in types are
+# 'getset_descriptor', but the app-level slots are 'member_descriptor'
+# as well.  (On Jython the situation might still be different.)
+#
+# Note that MemberDescriptorType was equal to GetSetDescriptorType in
+# PyPy <= 6.0.
+#
 GetSetDescriptorType = type(FunctionType.__code__)
-MemberDescriptorType = type(FunctionType.__globals__)
+class _C: __slots__ = 's'
+MemberDescriptorType = type(_C.s)
 
 del sys, _f, _g, _C, _c,   # Not for export
 
diff --git a/lib_pypy/cffi/_cffi_errors.h b/lib_pypy/cffi/_cffi_errors.h
--- a/lib_pypy/cffi/_cffi_errors.h
+++ b/lib_pypy/cffi/_cffi_errors.h
@@ -50,7 +50,9 @@
 "import sys\n"
 "class FileLike:\n"
 "  def write(self, x):\n"
-"of.write(x)\n"
+"try:\n"
+"  of.write(x)\n"
+"except: pass\n"
 "self.buf += x\n"
 "fl = FileLike()\n"
 "fl.buf = ''\n"
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -2076,7 +2076,7 @@
 else:
 skip_leading_underscores = False
 for name in all:
-if skip_leading_underscores and name[0]=='_':
+if skip_leading_underscores and name and name[0] == '_':
 continue
 into_locals[name] = getattr(module, name)
 ''', filename=__file__)
diff --git a/pypy/module/imp/test/test_import.py 
b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -101,8 +101,8 @@
  foobar= "found = 123",
  barbaz= "other = 543")
 setuppkg("pkg.withoutall",
- __init__  = "",
- foobar= "found = 123")
+ __init__  = "globals()[''] = 456",
+ foobar= "found = 123\n")
 setuppkg("pkg.bogusall",
  __init__  = "__all__ = 42")
 setuppkg("pkg_r", inpkg = "import x.y")
@@ -703,6 +703,13 @@
 exec("from pkg.withoutall import *", d)
 assert d["foobar"].found == 123
 
+def test_import_star_empty_string(self):
+for case in ["not-imported-yet", "already-imported"]:
+d = {}
+exec("from pkg.withoutall import *", d)
+assert "" in d
+
+
 def test_import_star_with_bogus___all__(self):
 for case in ["not-imported-yet", "already-imported"]:
 try:
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi0/backend_tests.py 
b/pypy/module/test_lib_pypy/cffi_tests/cffi0/backend_tests.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi0/backend_tests.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/cffi0/backend_tests.py
@@ -1946,3 +1946,30 @@
 # only works with the Python FFI instances
 ffi = FFI(backend=self.Backend())
 assert ffi.sizeof("struct{int a;}") == ffi.sizeof("int")
+
+def test_callback_large_struct(self):
+ffi = FFI(backend=self.Backend())
+# more than 8 bytes
+ffi.cdef("struct foo_s { unsigned long a, b, c; };")
+#
+@ffi.callback("void(struct foo_s)")
+def cb(s):
+seen.append(ffi.typeof(s))
+s.a += 1
+s.b += 2
+s.c += 3
+seen.append(s.a)
+seen.append(s.b)
+seen.append(s.c)
+#
+s1 = ffi.new("struct foo_s *", {'a': 100, 'b': 200, 'c': 300})
+seen = []
+cb(s1[0])
+assert len(seen) == 4
+assert s1.a == 100 # unmodified
+assert s1.b == 200
+assert s1.c == 300
+assert seen[0] == ffi.typeof("struct foo_s")
+assert seen[1] == 101
+assert seen[2] == 202
+assert seen[3] == 303
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_ownlib.py 
b/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_ownlib.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_ownlib.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/cffi0/test_ownlib.py
@@ -103,6 +103,11 @@
 {
 return (unsigned int)(a + 42);
 }
+
+EXPORT void modify_struct_value(RECT r)
+{
+r.left = r.right = r.top = r.bottom = 500;
+}
 """
 
 class TestOwnLib(object):
@@ -331,3 +336,25 @@
 assert lib.foo_2bytes(u+'\u1234') == u+'\u125e'
 assert 

[pypy-commit] pypy py3.5: hg merge default

2018-08-07 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r94973:b9da0b002569
Date: 2018-08-07 23:10 +0200
http://bitbucket.org/pypy/pypy/changeset/b9da0b002569/

Log:hg merge default

diff too long, truncating to 2000 out of 2739 lines

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
@@ -7,7 +7,8 @@
 
 .. branch: cppyy-packaging
 
-Upgrade to backend 1.2.0, improved handling of templated methods and
+Main items: vastly better template resolution and improved performance. In
+detail: upgrade to backend 1.4, improved handling of templated methods and
 functions (in particular automatic deduction of types), improved pythonization
 interface, range of compatibility fixes for Python3, free functions now take
 fast libffi path when possible, moves for strings (incl. from Python str),
diff --git a/pypy/module/_cffi_backend/errorbox.py 
b/pypy/module/_cffi_backend/errorbox.py
--- a/pypy/module/_cffi_backend/errorbox.py
+++ b/pypy/module/_cffi_backend/errorbox.py
@@ -69,7 +69,10 @@
 import sys
 class FileLike:
 def write(self, x):
-of.write(x)
+try:
+of.write(x)
+except:
+pass
 self.buf += x
 fl = FileLike()
 fl.buf = ''
diff --git a/pypy/module/_cppyy/capi/loadable_capi.py 
b/pypy/module/_cppyy/capi/loadable_capi.py
--- a/pypy/module/_cppyy/capi/loadable_capi.py
+++ b/pypy/module/_cppyy/capi/loadable_capi.py
@@ -1,13 +1,18 @@
 import os
+
 from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rlib.rarithmetic import intmask
 from rpython.rlib import jit, jit_libffi, libffi, rdynload, objectmodel
 from rpython.rlib.rarithmetic import r_singlefloat
 from rpython.tool import leakfinder
 
-from pypy.interpreter.gateway import interp2app
-from pypy.interpreter.error import oefmt
+from pypy.interpreter.error import OperationError, oefmt
+from pypy.interpreter.argument import Arguments
+from pypy.interpreter.gateway import interp2app, interpindirect2app
+from pypy.interpreter.typedef import TypeDef
+from pypy.objspace.std.iterobject import W_AbstractSeqIterObject
 
+from pypy.module._rawffi.array import W_ArrayInstance
 from pypy.module._cffi_backend import ctypefunc, ctypeprim, cdataobj, misc
 from pypy.module._cffi_backend import newtype
 from pypy.module._cppyy import ffitypes
@@ -23,10 +28,11 @@
 
 class _Arg: # poor man's union
 _immutable_ = True
-def __init__(self, tc, h = 0, l = -1, s = '', p = rffi.cast(rffi.VOIDP, 
0)):
+def __init__(self, tc, h = 0, l = -1, d = -1., s = '', p = 
rffi.cast(rffi.VOIDP, 0)):
 self.tc  = tc
 self._handle = h
 self._long   = l
+self._double = d
 self._string = s
 self._voidp  = p
 
@@ -40,6 +46,11 @@
 def __init__(self, val):
 _Arg.__init__(self, 'l', l = val)
 
+class _ArgD(_Arg):
+_immutable_ = True
+def __init__(self, val):
+_Arg.__init__(self, 'd', d = val)
+
 class _ArgS(_Arg):
 _immutable_ = True
 def __init__(self, val):
@@ -89,6 +100,9 @@
 assert obj._voidp != rffi.cast(rffi.VOIDP, 0)
 data = rffi.cast(rffi.VOIDPP, data)
 data[0] = obj._voidp
+elif obj.tc == 'd':
+assert isinstance(argtype, ctypeprim.W_CTypePrimitiveFloat)
+misc.write_raw_float_data(data, rffi.cast(rffi.DOUBLE, 
obj._double), argtype.size)
 else:# only other use is string
 assert obj.tc == 's'
 n = len(obj._string)
@@ -182,6 +196,7 @@
 'call_f'   : ([c_method, c_object, c_int, c_voidp],   c_float),
 'call_d'   : ([c_method, c_object, c_int, c_voidp],   
c_double),
 'call_ld'  : ([c_method, c_object, c_int, c_voidp],   
c_ldouble),
+'call_nld' : ([c_method, c_object, c_int, c_voidp],   
c_double),
 
 'call_r'   : ([c_method, c_object, c_int, c_voidp],   c_voidp),
 # call_s actually takes an size_t* as last parameter, but this 
will do
@@ -236,6 +251,8 @@
 'method_prototype' : ([c_scope, c_method, c_int], 
c_ccharp),
 'is_const_method'  : ([c_method], c_int),
 
+'get_num_templated_methods': ([c_scope],  c_int),
+'get_templated_method_name': ([c_scope, c_index], 
c_ccharp),
 'exists_method_template'   : ([c_scope, c_ccharp],c_int),
 'method_is_template'   : ([c_scope, c_index], c_int),
 'get_method_template'  : ([c_scope, c_ccharp, c_ccharp],   
 c_method),
@@ -272,9 +289,11 @@
 'stdstring2charp'  : ([c_object, c_voidp],

[pypy-commit] pypy py3.5: hg merge default

2018-07-23 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r94885:130fbb74dab5
Date: 2018-07-23 18:20 +0200
http://bitbucket.org/pypy/pypy/changeset/130fbb74dab5/

Log:hg merge default

diff too long, truncating to 2000 out of 2216 lines

diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -43,14 +43,10 @@
 "_jitlog",
 ])
 
-from rpython.jit.backend import detect_cpu
-try:
-if detect_cpu.autodetect().startswith('x86'):
-if not sys.platform.startswith('openbsd'):
-working_modules.add('_vmprof')
-working_modules.add('faulthandler')
-except detect_cpu.ProcessorAutodetectError:
-pass
+import rpython.rlib.rvmprof.cintf
+if rpython.rlib.rvmprof.cintf.IS_SUPPORTED:
+working_modules.add('_vmprof')
+working_modules.add('faulthandler')
 
 translation_modules = default_modules.copy()
 translation_modules.update([
@@ -323,3 +319,4 @@
 parser = to_optparse(config) #, useoptions=["translation.*"])
 option, args = parser.parse_args()
 print config
+print working_modules
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
@@ -7,9 +7,12 @@
 
 .. branch: cppyy-packaging
 
-Upgrade to backend 1.1.0, improved handling of templated methods and
+Upgrade to backend 1.2.0, improved handling of templated methods and
 functions (in particular automatic deduction of types), improved pythonization
-interface, and a range of compatibility fixes for Python3
+interface, range of compatibility fixes for Python3, free functions now take
+fast libffi path when possible, moves for strings (incl. from Python str),
+easier/faster handling of std::vector by numpy, improved and faster object
+identity preservation
 
 .. branch: socket_default_timeout_blockingness
 
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py 
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -3935,8 +3935,8 @@
 
 def test_char_pointer_conversion():
 import warnings
-assert __version__.startswith(("1.8", "1.9", "1.10", "1.11", "1.12")), (
-"consider turning the warning into an error")
+assert __version__.startswith("1."), (
+"the warning will be an error if we ever release cffi 2.x")
 BCharP = new_pointer_type(new_primitive_type("char"))
 BIntP = new_pointer_type(new_primitive_type("int"))
 BVoidP = new_pointer_type(new_void_type())
diff --git a/pypy/module/_cppyy/converter.py b/pypy/module/_cppyy/converter.py
--- a/pypy/module/_cppyy/converter.py
+++ b/pypy/module/_cppyy/converter.py
@@ -1,15 +1,12 @@
 import sys
 
 from pypy.interpreter.error import OperationError, oefmt
-
 from rpython.rtyper.lltypesystem import rffi, lltype
 from rpython.rlib.rarithmetic import r_singlefloat, r_longfloat
 from rpython.rlib import rfloat, rawrefcount
-
 from pypy.module._rawffi.interp_rawffi import letter2tp
 from pypy.module._rawffi.array import W_ArrayInstance
-
-from pypy.module._cppyy import helper, capi, ffitypes
+from pypy.module._cppyy import helper, capi, ffitypes, lowlevelviews
 
 # Converter objects are used to translate between RPython and C++. They are
 # defined by the type name for which they provide conversion. Uses are for
@@ -149,7 +146,8 @@
 # read access, so no copy needed
 address_value = self._get_raw_address(space, w_obj, offset)
 address = rffi.cast(rffi.ULONG, address_value)
-return W_ArrayInstance(space, letter2tp(space, self.typecode), 
self.size, address)
+return lowlevelviews.W_LowLevelView(
+space, letter2tp(space, self.typecode), self.size, address)
 
 def to_memory(self, space, w_obj, w_value, offset):
 # copy the full array (uses byte copy for now)
@@ -190,7 +188,8 @@
 # read access, so no copy needed
 address_value = self._get_raw_address(space, w_obj, offset)
 address = rffi.cast(rffi.ULONGP, address_value)
-return W_ArrayInstance(space, letter2tp(space, self.typecode), 
self.size, address[0])
+return lowlevelviews.W_LowLevelView(
+space, letter2tp(space, self.typecode), self.size, address[0])
 
 def to_memory(self, space, w_obj, w_value, offset):
 # copy only the pointer value
@@ -438,7 +437,7 @@
 from pypy.module._cppyy import interp_cppyy
 return interp_cppyy.get_nullptr(space)
 shape = letter2tp(space, 'P')
-return W_ArrayInstance(space, shape, sys.maxint/shape.size, ptrval)
+return lowlevelviews.W_LowLevelView(space, shape, 
sys.maxint/shape.size, ptrval)
 
 def to_memory(self, space, w_obj, w_value, offset):
 address = rffi.cast(rffi.VOIDPP, self._get_raw_address(space, w_obj, 
offset))
@@ -491,7 +490,7 @@
 from pypy.module._cppyy.interp_cppyy import W_CPPInstance
 

[pypy-commit] pypy py3.5: hg merge default

2018-07-06 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r94818:4db575509642
Date: 2018-07-06 18:25 +0200
http://bitbucket.org/pypy/pypy/changeset/4db575509642/

Log:hg merge default

diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py
--- a/pypy/module/__pypy__/__init__.py
+++ b/pypy/module/__pypy__/__init__.py
@@ -48,6 +48,7 @@
 'int_lshift':  'interp_intop.int_lshift',
 'int_rshift':  'interp_intop.int_rshift',
 'uint_rshift': 'interp_intop.uint_rshift',
+'int_mulmod':  'interp_intop.int_mulmod',
 }
 
 
diff --git a/pypy/module/__pypy__/interp_intop.py 
b/pypy/module/__pypy__/interp_intop.py
--- a/pypy/module/__pypy__/interp_intop.py
+++ b/pypy/module/__pypy__/interp_intop.py
@@ -2,7 +2,7 @@
 from rpython.rtyper.lltypesystem import lltype
 from rpython.rtyper.lltypesystem.lloperation import llop
 from rpython.rlib.rarithmetic import r_uint, intmask
-from rpython.rlib.rarithmetic import int_c_div, int_c_mod
+from rpython.rlib.rarithmetic import int_c_div, int_c_mod, mulmod
 from rpython.rlib import jit
 
 
@@ -39,3 +39,7 @@
 n = r_uint(n)
 x = llop.uint_rshift(lltype.Unsigned, n, m)
 return space.newint(intmask(x))
+
+@unwrap_spec(a=int, b=int, c=int)
+def int_mulmod(space, a, b, c):
+return space.newint(mulmod(a, b, c))
diff --git a/pypy/module/__pypy__/test/test_intop.py 
b/pypy/module/__pypy__/test/test_intop.py
--- a/pypy/module/__pypy__/test/test_intop.py
+++ b/pypy/module/__pypy__/test/test_intop.py
@@ -102,3 +102,7 @@
 assert intop.uint_rshift(-1, 1) == sys.maxsize
 assert intop.uint_rshift(-1, bits-2) == 3
 assert intop.uint_rshift(-1, bits-1) == 1
+
+def test_mulmod(self):
+from __pypy__ import intop
+assert intop.int_mulmod(9373891, 9832739, 2**31-1) == 1025488209
diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py
--- a/pypy/objspace/std/intobject.py
+++ b/pypy/objspace/std/intobject.py
@@ -371,20 +371,23 @@
 return wrapint(space, a)
 
 
-@jit.look_inside_iff(lambda space, iv, iw, iz:
- jit.isconstant(iw) and jit.isconstant(iz))
 def _pow(space, iv, iw, iz):
 """Helper for pow"""
-if iw < 0:
-if iz != 0:
-raise oefmt(space.w_ValueError,
-"pow() 2nd argument cannot be negative when 3rd "
-"argument specified")
+if iz == 0:
+return _pow_nomod(iv, iw)
+else:
+return _pow_mod(space, iv, iw, iz)
+
+@jit.look_inside_iff(lambda iv, iw: jit.isconstant(iw))
+def _pow_nomod(iv, iw):
+if iw <= 0:
+if iw == 0:
+return 1
 # bounce it, since it always returns float
 raise ValueError
 temp = iv
 ix = 1
-while iw > 0:
+while True:
 if iw & 1:
 try:
 ix = ovfcheck(ix * temp)
@@ -397,12 +400,40 @@
 temp = ovfcheck(temp * temp) # Square the value of temp
 except OverflowError:
 raise
-if iz:
-# If we did a multiplication, perform a modulo
-ix %= iz
-temp %= iz
-if iz:
-ix %= iz
+return ix
+
+@jit.look_inside_iff(lambda space, iv, iw, iz:
+ jit.isconstant(iw) and jit.isconstant(iz))
+def _pow_mod(space, iv, iw, iz):
+from rpython.rlib.rarithmetic import mulmod
+
+if iw <= 0:
+if iw == 0:
+return 1 % iz   # != 1, for iz == 1 or iz < 0
+raise oefmt(space.w_ValueError,
+"pow() 2nd argument cannot be negative when 3rd "
+"argument specified")
+if iz < 0:
+try:
+iz = ovfcheck(-iz)
+except OverflowError:
+raise
+iz_negative = True
+else:
+iz_negative = False
+
+temp = iv
+ix = 1
+while True:
+if iw & 1:
+ix = mulmod(ix, temp, iz)
+iw >>= 1   # Shift exponent down by 1 bit
+if iw == 0:
+break
+temp = mulmod(temp, temp, iz)
+
+if iz_negative and ix > 0:
+ix -= iz
 return ix
 
 
diff --git a/pypy/objspace/std/test/test_intobject.py 
b/pypy/objspace/std/test/test_intobject.py
--- a/pypy/objspace/std/test/test_intobject.py
+++ b/pypy/objspace/std/test/test_intobject.py
@@ -1,7 +1,8 @@
 # encoding: utf-8
 import sys
+from pypy.interpreter.error import OperationError
 from pypy.objspace.std import intobject as iobj
-from rpython.rlib.rarithmetic import r_uint, is_valid_int
+from rpython.rlib.rarithmetic import r_uint, is_valid_int, intmask
 from rpython.rlib.rbigint import rbigint
 
 class TestW_IntObject:
@@ -169,6 +170,63 @@
 assert space.isinstance_w(v, space.w_int)
 assert space.bigint_w(v).eq(rbigint.fromlong(pow(10, 20)))
 
+try:
+from hypothesis import given, strategies, example
+except ImportError:
+pass
+else:
+@given(
+   

[pypy-commit] pypy py3.5: hg merge default

2018-07-06 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r94816:8c7fd9e901c7
Date: 2018-07-06 16:27 +0200
http://bitbucket.org/pypy/pypy/changeset/8c7fd9e901c7/

Log:hg merge default

diff --git a/pypy/module/_cppyy/converter.py b/pypy/module/_cppyy/converter.py
--- a/pypy/module/_cppyy/converter.py
+++ b/pypy/module/_cppyy/converter.py
@@ -82,10 +82,9 @@
 
 
 class TypeConverter(object):
-_immutable_fields_ = ['cffi_name', 'uses_local', 'name']
+_immutable_fields_ = ['cffi_name', 'name']
 
 cffi_name  = None
-uses_local = False
 name   = ""
 
 def __init__(self, space, extra):
@@ -108,10 +107,10 @@
 from pypy.module._cppyy.interp_cppyy import FastCallNotPossible
 raise FastCallNotPossible
 
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 self._is_abstract(space)
 
-def convert_argument_libffi(self, space, w_obj, address, call_local):
+def convert_argument_libffi(self, space, w_obj, address, scratch):
 from pypy.module._cppyy.interp_cppyy import FastCallNotPossible
 raise FastCallNotPossible
 
@@ -125,10 +124,10 @@
 def to_memory(self, space, w_obj, w_value, offset):
 self._is_abstract(space)
 
-def finalize_call(self, space, w_obj, call_local):
+def finalize_call(self, space, w_obj):
 pass
 
-def free_argument(self, space, arg, call_local):
+def free_argument(self, space, arg):
 pass
 
 
@@ -172,7 +171,7 @@
 state = space.fromcache(ffitypes.State)
 return state.c_voidp
 
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 w_tc = space.findattr(w_obj, space.newtext('typecode'))
 if w_tc is not None and space.text_w(w_tc) != self.typecode:
 raise oefmt(space.w_TypeError,
@@ -208,7 +207,7 @@
 class NumericTypeConverterMixin(object):
 _mixin_ = True
 
-def convert_argument_libffi(self, space, w_obj, address, call_local):
+def convert_argument_libffi(self, space, w_obj, address, scratch):
 x = rffi.cast(self.c_ptrtype, address)
 x[0] = self._unwrap_object(space, w_obj)
 
@@ -228,26 +227,23 @@
 
 class ConstRefNumericTypeConverterMixin(NumericTypeConverterMixin):
 _mixin_ = True
-_immutable_fields_ = ['uses_local']
-
-uses_local = True
 
 def cffi_type(self, space):
 state = space.fromcache(ffitypes.State)
 return state.c_voidp
 
-def convert_argument_libffi(self, space, w_obj, address, call_local):
-assert rffi.sizeof(self.c_type) <= 2*rffi.sizeof(rffi.VOIDP)  # see 
interp_cppyy.py
+def convert_argument_libffi(self, space, w_obj, address, scratch):
 obj = self._unwrap_object(space, w_obj)
-typed_buf = rffi.cast(self.c_ptrtype, call_local)
+typed_buf = rffi.cast(self.c_ptrtype, scratch)
 typed_buf[0] = obj
 x = rffi.cast(rffi.VOIDPP, address)
-x[0] = call_local
+x[0] = scratch
+
 
 class IntTypeConverterMixin(NumericTypeConverterMixin):
 _mixin_ = True
 
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 x = rffi.cast(self.c_ptrtype, address)
 x[0] = self._unwrap_object(space, w_obj)
 ba = rffi.cast(rffi.CCHARP, address)
@@ -256,7 +252,7 @@
 class FloatTypeConverterMixin(NumericTypeConverterMixin):
 _mixin_ = True
 
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 x = rffi.cast(self.c_ptrtype, address)
 x[0] = self._unwrap_object(space, w_obj)
 ba = rffi.cast(rffi.CCHARP, address)
@@ -273,18 +269,18 @@
 state = space.fromcache(ffitypes.State)
 return state.c_void
 
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 self._is_abstract(space)
 
 
 class BoolConverter(ffitypes.typeid(bool), TypeConverter):
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 x = rffi.cast(rffi.LONGP, address)
 x[0] = self._unwrap_object(space, w_obj)
 ba = rffi.cast(rffi.CCHARP, address)
 ba[capi.c_function_arg_typeoffset(space)] = 'b'
 
-def convert_argument_libffi(self, space, w_obj, address, call_local):
+def convert_argument_libffi(self, space, w_obj, address, scratch):
 x = rffi.cast(rffi.LONGP, address)
 x[0] = self._unwrap_object(space, w_obj)
 
@@ -303,13 +299,13 @@
 address[0] = '\x00'
 
 class CharConverter(ffitypes.typeid(rffi.CHAR), TypeConverter):
-def convert_argument(self, space, w_obj, address, call_local):
+def convert_argument(self, space, w_obj, address):
 x = rffi.cast(rffi.CCHARP, address)
 x[0] = 

[pypy-commit] pypy py3.5: hg merge default

2018-07-05 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r94806:87b7c6c07f22
Date: 2018-07-05 17:28 +0200
http://bitbucket.org/pypy/pypy/changeset/87b7c6c07f22/

Log:hg merge default

(issue #2837 not closed, needs different fix in pypy3)

diff --git a/pypy/module/sys/test/test_sysmodule.py 
b/pypy/module/sys/test/test_sysmodule.py
--- a/pypy/module/sys/test/test_sysmodule.py
+++ b/pypy/module/sys/test/test_sysmodule.py
@@ -358,6 +358,29 @@
 print(ascii(err.getvalue()))
 assert err.getvalue().endswith("ValueError: %s\n" % input)
 
+def test_excepthook_flushes_stdout(self): r"""
+import sys, io
+savestdout = sys.stdout
+out = io.StringIO()
+sys.stdout = out
+
+eh = sys.__excepthook__
+
+try:
+raise ValueError(42)
+except ValueError as exc:
+print("hello") # with end-of-line
+eh(*sys.exc_info())
+try:
+raise ValueError(42)
+except ValueError as exc:
+print(123, 456, end="") # no end-of-line here
+eh(*sys.exc_info())
+
+sys.stdout = savestdout
+assert out.getvalue() == 'hello\n123 456'   # no final \n added in 3.x
+"""
+
 # FIXME: testing the code for a lost or replaced excepthook in
 # Python/pythonrun.c::PyErr_PrintEx() is tricky.
 
diff --git a/rpython/rlib/rvmprof/dummy.py b/rpython/rlib/rvmprof/dummy.py
--- a/rpython/rlib/rvmprof/dummy.py
+++ b/rpython/rlib/rvmprof/dummy.py
@@ -23,4 +23,4 @@
 pass
 
 def stop_sampling(self):
-pass
+return -1
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-07-01 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r94794:bd8889a5d67f
Date: 2018-07-01 22:40 +0200
http://bitbucket.org/pypy/pypy/changeset/bd8889a5d67f/

Log:hg merge default

diff --git a/pypy/interpreter/test/test_raise.py 
b/pypy/interpreter/test/test_raise.py
--- a/pypy/interpreter/test/test_raise.py
+++ b/pypy/interpreter/test/test_raise.py
@@ -309,6 +309,17 @@
 return object()
 raises(TypeError, "raise MyException")
 
+def test_with_exit_True(self):
+class X:
+def __enter__(self):
+pass
+def __exit__(self, *args):
+return True
+def g():
+with X():
+return 42
+assert False, "unreachable"
+assert g() == 42
 
 def test_pop_exception_value(self):
 # assert that this code don't crash
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-05-23 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r94679:7920e2af5244
Date: 2018-05-23 22:58 +0200
http://bitbucket.org/pypy/pypy/changeset/7920e2af5244/

Log:hg merge default

diff --git a/pypy/module/cpyext/include/patchlevel.h 
b/pypy/module/cpyext/include/patchlevel.h
--- a/pypy/module/cpyext/include/patchlevel.h
+++ b/pypy/module/cpyext/include/patchlevel.h
@@ -29,8 +29,8 @@
 #define PY_VERSION "3.5.3"
 
 /* PyPy version as a string */
-#define PYPY_VERSION "6.0.0"
-#define PYPY_VERSION_NUM  0x0600
+#define PYPY_VERSION "6.1.0-alpha0"
+#define PYPY_VERSION_NUM  0x0601
 
 /* Defined to mean a PyPy where cpyext holds more regular references
to PyObjects, e.g. staying alive as long as the internal PyPy object
diff --git a/pypy/module/sys/version.py b/pypy/module/sys/version.py
--- a/pypy/module/sys/version.py
+++ b/pypy/module/sys/version.py
@@ -10,7 +10,7 @@
 #XXX # sync CPYTHON_VERSION with patchlevel.h, package.py
 CPYTHON_API_VERSION= 1013   #XXX # sync with include/modsupport.h
 
-PYPY_VERSION   = (6, 0, 0, "final", 0)#XXX # sync patchlevel.h
+PYPY_VERSION   = (6, 1, 0, "alpha", 0)#XXX # sync patchlevel.h
 
 
 import pypy
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-05-23 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r94677:8e91ac1e6132
Date: 2018-05-23 22:46 +0200
http://bitbucket.org/pypy/pypy/changeset/8e91ac1e6132/

Log:hg merge default

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-05-23 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r94667:cfbe109033a4
Date: 2018-05-23 21:04 +0200
http://bitbucket.org/pypy/pypy/changeset/cfbe109033a4/

Log:hg merge default

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-05-14 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r94591:2396fb397495
Date: 2018-05-14 22:34 +0100
http://bitbucket.org/pypy/pypy/changeset/2396fb397495/

Log:hg merge default

diff --git a/pypy/interpreter/unicodehelper.py 
b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -168,6 +168,222 @@
 return decode_utf8(space, string, allow_surrogates=True)
 
 # 
+# utf-16
+
+def str_decode_utf_16(s, size, errors, final=True,
+   errorhandler=None):
+result, length, byteorder = str_decode_utf_16_helper(s, size, errors, 
final,
+ errorhandler, 
"native",
+ 'utf-16-' + 
BYTEORDER2)
+return result, length
+
+def str_decode_utf_16_be(s, size, errors, final=True,
+  errorhandler=None):
+result, length, byteorder = str_decode_utf_16_helper(s, size, errors, 
final,
+ errorhandler, "big",
+ 'utf-16-be')
+return result, length
+
+def str_decode_utf_16_le(s, size, errors, final=True,
+  errorhandler=None):
+result, length, byteorder = str_decode_utf_16_helper(s, size, errors, 
final,
+ errorhandler, 
"little",
+ 'utf-16-le')
+return result, length
+
+def str_decode_utf_16_helper(s, size, errors, final=True,
+ errorhandler=None,
+ byteorder="native",
+ public_encoding_name='utf16'):
+if errorhandler is None:
+errorhandler = default_unicode_error_decode
+bo = 0
+
+if BYTEORDER == 'little':
+ihi = 1
+ilo = 0
+else:
+ihi = 0
+ilo = 1
+
+#  Check for BOM marks (U+FEFF) in the input and adjust current
+#  byte order setting accordingly. In native mode, the leading BOM
+#  mark is skipped, in all other modes, it is copied to the output
+#  stream as-is (giving a ZWNBSP character).
+pos = 0
+if byteorder == 'native':
+if size >= 2:
+bom = (ord(s[ihi]) << 8) | ord(s[ilo])
+if BYTEORDER == 'little':
+if bom == 0xFEFF:
+pos += 2
+bo = -1
+elif bom == 0xFFFE:
+pos += 2
+bo = 1
+else:
+if bom == 0xFEFF:
+pos += 2
+bo = 1
+elif bom == 0xFFFE:
+pos += 2
+bo = -1
+elif byteorder == 'little':
+bo = -1
+else:
+bo = 1
+if size == 0:
+return u'', 0, bo
+if bo == -1:
+# force little endian
+ihi = 1
+ilo = 0
+
+elif bo == 1:
+# force big endian
+ihi = 0
+ilo = 1
+
+result = UnicodeBuilder(size // 2)
+
+#XXX I think the errors are not correctly handled here
+while pos < size:
+# remaining bytes at the end? (size should be even)
+if len(s) - pos < 2:
+if not final:
+break
+r, pos = errorhandler(errors, public_encoding_name,
+  "truncated data",
+  s, pos, len(s))
+result.append(r)
+if len(s) - pos < 2:
+break
+ch = (ord(s[pos + ihi]) << 8) | ord(s[pos + ilo])
+pos += 2
+if ch < 0xD800 or ch > 0xDFFF:
+result.append(unichr(ch))
+continue
+# UTF-16 code pair:
+if len(s) - pos < 2:
+pos -= 2
+if not final:
+break
+errmsg = "unexpected end of data"
+r, pos = errorhandler(errors, public_encoding_name,
+  errmsg, s, pos, len(s))
+result.append(r)
+if len(s) - pos < 2:
+break
+elif 0xD800 <= ch <= 0xDBFF:
+ch2 = (ord(s[pos+ihi]) << 8) | ord(s[pos+ilo])
+pos += 2
+if 0xDC00 <= ch2 <= 0xDFFF:
+if MAXUNICODE < 65536:
+result.append(unichr(ch))
+result.append(unichr(ch2))
+else:
+result.append(UNICHRch & 0x3FF)<<10) |
+   (ch2 & 0x3FF)) + 0x1))
+continue
+else:
+r, pos = errorhandler(errors, public_encoding_name,
+  "illegal UTF-16 surrogate",
+  s, pos - 4, pos - 2)
+result.append(r)
+ 

[pypy-commit] pypy py3.5: hg merge default

2018-05-13 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r94556:0c21724e75bd
Date: 2018-05-14 04:28 +0100
http://bitbucket.org/pypy/pypy/changeset/0c21724e75bd/

Log:hg merge default

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-05-13 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r94553:d43acd762a29
Date: 2018-05-14 03:57 +0100
http://bitbucket.org/pypy/pypy/changeset/d43acd762a29/

Log:hg merge default

diff --git a/rpython/jit/metainterp/pyjitpl.py 
b/rpython/jit/metainterp/pyjitpl.py
--- a/rpython/jit/metainterp/pyjitpl.py
+++ b/rpython/jit/metainterp/pyjitpl.py
@@ -430,7 +430,6 @@
 for const1 in switchdict.const_keys_in_order:
 box = self.execute(rop.INT_EQ, valuebox, const1)
 assert box.getint() == 0
-target = switchdict.dict[const1.getint()]
 self.metainterp.generate_guard(rop.GUARD_FALSE, box,
resumepc=orgpc)
 else:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-05-09 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r94517:6aceee434fd0
Date: 2018-05-09 19:45 +0200
http://bitbucket.org/pypy/pypy/changeset/6aceee434fd0/

Log:hg merge default

diff --git a/pypy/doc/architecture.rst b/pypy/doc/architecture.rst
--- a/pypy/doc/architecture.rst
+++ b/pypy/doc/architecture.rst
@@ -73,3 +73,63 @@
 This division between bytecode evaluator and object space gives a lot of
 flexibility.  One can plug in different :doc:`object spaces ` to get
 different or enriched behaviours of the Python objects.
+
+Layers
+--
+
+RPython
+~~~
+:ref:`RPython ` is the language in which we write 
interpreters.
+Not the entire PyPy project is written in RPython, only the parts that are
+compiled in the translation process. The interesting point is that RPython
+has no parser, it's compiled from the live python objects, which makes it
+possible to do all kinds of metaprogramming during import time. In short,
+Python is a meta programming language for RPython.
+
+The RPython standard library is to be found in the ``rlib`` subdirectory.
+
+Consult `Getting Started with RPython`_ for further reading
+
+Translation
+~~~
+The translation toolchain - this is the part that takes care of translating
+RPython to flow graphs and then to C. There is more in the
+:doc:`architecture ` document written about it.
+
+It lives in the ``rpython`` directory: ``flowspace``, ``annotator``
+and ``rtyper``.
+
+PyPy Interpreter
+
+This is in the ``pypy`` directory.  ``pypy/interpreter`` is a standard
+interpreter for Python written in RPython.  The fact that it is
+RPython is not apparent at first.  Built-in modules are written in
+``pypy/module/*``.  Some modules that CPython implements in C are
+simply written in pure Python; they are in the top-level ``lib_pypy``
+directory.  The standard library of Python (with a few changes to
+accomodate PyPy) is in ``lib-python``.
+
+JIT Compiler
+
+:ref:`Just-in-Time Compiler (JIT) `: we have a tracing JIT that 
traces the
+interpreter written in RPython, rather than the user program that it
+interprets.  As a result it applies to any interpreter, i.e. any
+language.  But getting it to work correctly is not trivial: it
+requires a small number of precise "hints" and possibly some small
+refactorings of the interpreter.  The JIT itself also has several
+almost-independent parts: the tracer itself in ``rpython/jit/metainterp``, the
+optimizer in ``rpython/jit/metainterp/optimizer`` that optimizes a list of
+residual operations, and the backend in ``rpython/jit/backend/``
+that turns it into machine code.  Writing a new backend is a
+traditional way to get into the project.
+
+Garbage Collectors
+~~
+Garbage Collectors (GC): as you may notice if you are used to CPython's
+C code, there are no ``Py_INCREF/Py_DECREF`` equivalents in RPython code.
+:ref:`rpython:garbage-collection` is inserted
+during translation.  Moreover, this is not reference counting; it is a real
+GC written as more RPython code.  The best one we have so far is in
+``rpython/memory/gc/incminimark.py``.
+
+.. _`Getting started with RPython`: 
http://rpython.readthedocs.org/en/latest/getting-started.html
diff --git a/pypy/doc/build.rst b/pypy/doc/build.rst
--- a/pypy/doc/build.rst
+++ b/pypy/doc/build.rst
@@ -267,14 +267,14 @@
 * PyPy 2.5.1 or earlier: normal users would see permission errors.
   Installers need to run ``pypy -c "import gdbm"`` and other similar
   commands at install time; the exact list is in
-  :source:`pypy/tool/release/package.py `.  Users
+  :source:`pypy/tool/release/package.py`.  Users
   seeing a broken installation of PyPy can fix it after-the-fact if they
   have sudo rights, by running once e.g. ``sudo pypy -c "import gdbm``.
 
 * PyPy 2.6 and later: anyone would get ``ImportError: no module named
   _gdbm_cffi``.  Installers need to run ``pypy _gdbm_build.py`` in the
   ``lib_pypy`` directory during the installation process (plus others;
-  see the exact list in :source:`pypy/tool/release/package.py `).
+  see the exact list in :source:`pypy/tool/release/package.py`).
   Users seeing a broken
   installation of PyPy can fix it after-the-fact, by running ``pypy
   /path/to/lib_pypy/_gdbm_build.py``.  This command produces a file
diff --git a/pypy/doc/coding-guide.rst b/pypy/doc/coding-guide.rst
--- a/pypy/doc/coding-guide.rst
+++ b/pypy/doc/coding-guide.rst
@@ -539,7 +539,7 @@
 
 hg help branch
 
-.. _official wiki: http://mercurial.selenic.com/wiki/Branch
+.. _official wiki: https://www.mercurial-scm.org/wiki/
 
 
 .. _using-development-tracker:
@@ -547,15 +547,7 @@
 Using the development bug/feature tracker
 -
 
-We have a `development tracker`_, based on Richard Jones'
-`roundup`_ application.  You can file bugs,
-feature requests or see what's going on
-for the next milestone, both from an E-Mail and from a
-web interface.
-
-.. _development tracker: 

[pypy-commit] pypy py3.5: hg merge default

2018-05-09 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r94506:e4a332215983
Date: 2018-05-09 18:55 +0200
http://bitbucket.org/pypy/pypy/changeset/e4a332215983/

Log:hg 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
@@ -5,5 +5,16 @@
 .. this is a revision shortly after release-pypy-6.0.0
 .. startrev: e50e11af23f1
 
+.. branch: cppyy-packaging
 
+Upgrade to backend 0.6.0, support exception handling from wrapped functions,
+update enum handling, const correctness for data members and associated tests,
+support anonymous enums, support for function pointer arguments
 
+.. branch: socket_default_timeout_blockingness
+
+Make sure 'blocking-ness' of socket is set along with default timeout
+
+.. branch: crypt_h
+
+Include crypt.h for crypt() on Linux
diff --git a/pypy/module/_cppyy/__init__.py b/pypy/module/_cppyy/__init__.py
--- a/pypy/module/_cppyy/__init__.py
+++ b/pypy/module/_cppyy/__init__.py
@@ -7,6 +7,7 @@
 interpleveldefs = {
 '_resolve_name'  : 'interp_cppyy.resolve_name',
 '_scope_byname'  : 'interp_cppyy.scope_byname',
+'_is_static_data': 'interp_cppyy.is_static_data',
 '_is_template'   : 'interp_cppyy.is_template',
 '_std_string_name'   : 'interp_cppyy.std_string_name',
 '_set_class_generator'   : 'interp_cppyy.set_class_generator',
@@ -21,7 +22,7 @@
 }
 
 appleveldefs = {
-'_init_pythonify': 'pythonify._init_pythonify',
+'_post_import_startup'   : 'pythonify._post_import_startup',
 'add_pythonization'  : 'pythonify.add_pythonization',
 'Template'   : 'pythonify.CPPTemplate',
 }
@@ -34,9 +35,3 @@
 # code generation is not, so give it a chance to run now
 from pypy.module._cppyy import capi
 capi.register_pythonizations(space)
-
-def startup(self, space):
-from pypy.module._cppyy import capi
-capi.verify_backend(space)  # may raise ImportError
-
-space.call_method(self, '_init_pythonify')
diff --git a/pypy/module/_cppyy/capi/loadable_capi.py 
b/pypy/module/_cppyy/capi/loadable_capi.py
--- a/pypy/module/_cppyy/capi/loadable_capi.py
+++ b/pypy/module/_cppyy/capi/loadable_capi.py
@@ -308,7 +308,7 @@
 c_call = state.capi_calls[name]
 except KeyError:
 if state.backend is None:
-load_backend(space)
+verify_backend(space)
 iface = state.capi_call_ifaces[name]
 cfunc = W_RCTypeFunc(space, iface[0], iface[1], False)
 c_call = state.backend.load_function(cfunc, 'cppyy_'+name)
@@ -421,7 +421,7 @@
 _cdata_to_ptr(space, call_capi(space, 'function_address_from_index', 
args)))
 def c_function_address_from_method(space, cppmethod):
 return rffi.cast(C_FUNC_PTR,
-_cdata_to_ptr(space, call_capi(space, 'function_address_from_method', 
_ArgH(cppmethod
+_cdata_to_ptr(space, call_capi(space, 'function_address_from_method', 
[_ArgH(cppmethod)])))
 
 # handling of function argument buffer ---
 def c_allocate_function_args(space, size):
diff --git a/pypy/module/_cppyy/converter.py b/pypy/module/_cppyy/converter.py
--- a/pypy/module/_cppyy/converter.py
+++ b/pypy/module/_cppyy/converter.py
@@ -686,6 +686,34 @@
 decref(space, rffi.cast(PyObject, rffi.cast(rffi.VOIDPP, arg)[0]))
 
 
+class FunctionPointerConverter(TypeConverter):
+_immutable_fields_ = ['signature']
+
+def __init__(self, space, signature):
+self.signature = signature
+
+def convert_argument(self, space, w_obj, address, call_local):
+# TODO: atm, does not actually get an overload, but a staticmethod
+from pypy.module._cppyy.interp_cppyy import W_CPPOverload
+cppol = space.interp_w(W_CPPOverload, w_obj)
+
+# find the function with matching signature
+for i in range(len(cppol.functions)):
+m = cppol.functions[i]
+if m.signature(False) == self.signature:
+x = rffi.cast(rffi.VOIDPP, address)
+x[0] = rffi.cast(rffi.VOIDP,
+capi.c_function_address_from_method(space, m.cppmethod))
+address = rffi.cast(capi.C_OBJECT, address)
+ba = rffi.cast(rffi.CCHARP, address)
+ba[capi.c_function_arg_typeoffset(space)] = 'p'
+return
+
+# lookup failed
+raise oefmt(space.w_TypeError,
+"no overload found matching %s", self.signature)
+
+
 class MacroConverter(TypeConverter):
 def from_memory(self, space, w_obj, w_pycppclass, offset):
 # TODO: get the actual type info from somewhere ...
@@ -749,6 +777,14 @@
 return InstancePtrPtrConverter(space, clsdecl)
 elif compound == "":
 return InstanceConverter(space, clsdecl)
+elif "(anonymous)" in name:

[pypy-commit] pypy py3.5: hg merge default

2018-04-20 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r94397:b7da70a8fd2c
Date: 2018-04-20 17:13 +0100
http://bitbucket.org/pypy/pypy/changeset/b7da70a8fd2c/

Log:hg merge default

diff --git a/pypy/module/cpyext/test/test_datetime.py 
b/pypy/module/cpyext/test/test_datetime.py
--- a/pypy/module/cpyext/test/test_datetime.py
+++ b/pypy/module/cpyext/test/test_datetime.py
@@ -1,3 +1,5 @@
+import pytest
+
 from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
 from pypy.module.cpyext.test.test_api import BaseApiTest
 from pypy.module.cpyext.cdatetime import *
@@ -82,6 +84,14 @@
 date = datetime.datetime.fromtimestamp(0)
 assert space.unwrap(space.str(w_date)) == str(date)
 
+@pytest.mark.parametrize('name', ['Time', 'DateTime', 'Date', 'Delta'])
+def test_basicsize(self, space, name):
+datetime = _PyDateTime_Import(space)
+py_size = getattr(datetime, "c_%sType" % name).c_tp_basicsize
+c_size = rffi.sizeof(cts.gettype("PyDateTime_%s" % name))
+assert py_size == c_size
+
+
 class AppTestDatetime(AppTestCpythonExtensionBase):
 def test_CAPI(self):
 module = self.import_extension('foo', [
@@ -271,9 +281,9 @@
 6, 6, 6, 6, args, PyDateTimeAPI->TimeType);
  """),
 ("datetime_with_tzinfo", "METH_O",
- """ 
+ """
  PyObject * obj;
- int tzrefcnt = args->ob_refcnt; 
+ int tzrefcnt = args->ob_refcnt;
  PyDateTime_IMPORT;
  obj = PyDateTimeAPI->DateTime_FromDateAndTime(
 2000, 6, 6, 6, 6, 6, 6, args,
@@ -291,7 +301,7 @@
 return NULL;
 }
 return obj;
-
+
  """),
 ], prologue='#include "datetime.h"\n')
 from datetime import tzinfo, datetime, timedelta, time
@@ -339,4 +349,4 @@
 assert module.checks(o) == (True,) * 3 + (False,) * 7 # 
isinstance(datetime, date)
 o = tzinfo()
 assert module.checks(o) == (False,) * 8 + (True,) * 2
-
+
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-04-15 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r94339:7967a85cf805
Date: 2018-04-15 17:56 +0100
http://bitbucket.org/pypy/pypy/changeset/7967a85cf805/

Log:hg merge default

diff --git a/pypy/tool/pytest/genreportdata.py 
b/pypy/tool/pytest/genreportdata.py
deleted file mode 100755
--- a/pypy/tool/pytest/genreportdata.py
+++ /dev/null
@@ -1,30 +0,0 @@
-#! /usr/bin/env python
-import py
-import sys
-
-mydir = py.path.local(__file__).dirpath().realpath()
-from pypy.tool.pytest import htmlreport 
-from pypy.tool.pytest import confpath 
-
-if __name__ == '__main__':
-if len(sys.argv) > 1:
-testresultdir = py.path.local(sys.argv[1])
-assert testresultdir.check(dir=1)
-else:
-testresultdir = confpath.testresultdir 
-assert testresultdir.check(dir=1)
-try:
-resultwc = py.path.svnwc(testresultdir)
-print "updating", resultwc
-resultwc.update()
-except (KeyboardInterrupt, RuntimeError):
-raise
-except Exception as e: #py.process.ExecutionFailed,e:
-print >> sys.stderr, "Warning: ",e #Subversion update failed"
-
-print "traversing", mydir 
-rep = htmlreport.HtmlReport(testresultdir)
-rep.parselatest()
-
-print "making html files"
-rep.makeindex(testresultdir.join('index.html'))
diff --git a/pypy/tool/pytest/htmlreport.py b/pypy/tool/pytest/htmlreport.py
deleted file mode 100644
--- a/pypy/tool/pytest/htmlreport.py
+++ /dev/null
@@ -1,239 +0,0 @@
-#! /usr/bin/env python
-
-"""
-the html test reporter 
-
-"""
-import sys, os, re
-import pprint
-import py 
-from pypy.tool.pytest import result
-from pypy.tool.pytest.overview import ResultCache 
-
-# 
-# various interesting path objects 
-#
-
-html = py.xml.html
-NBSP = py.xml.raw("")
-
-class HtmlReport(object): 
-def __init__(self, resultdir): 
-self.resultcache = ResultCache(resultdir)
-
-def parselatest(self): 
-self.resultcache.parselatest()
-
-# 
-# rendering 
-# 
-
-def render_latest_table(self, results): 
-table = html.table(
-[html.th(x, align='left') 
-for x in ("failure", "filename", "revision", 
-  "user", "platform", "elapsed", 
-  "options", "last error line"
-  )], 
-)
-r = results[:]
-def f(x, y): 
-xnum = x.isok() and 1 or (x.istimeout() and 2 or 3)
-ynum = y.isok() and 1 or (y.istimeout() and 2 or 3)
-res = -cmp(xnum, ynum)
-if res == 0: 
-return cmp(x['execution-time'], y['execution-time'])
-return res 
-r.sort(f) 
-for result in r: 
-table.append(self.render_result_row(result))
-return table 
-
-def render_result_row(self, result): 
-dp = py.path.local(result['fspath']) 
-
-options = " ".join([x for x in result.get('options', []) if x!= 
'core'])
-if not options: 
-options = NBSP
-
-failureratio = 100 * (1.0 - result.ratio_of_passed())
-self.data[result.testname] = failureratio
-return html.tr(
-html.td("%.2f%%" % failureratio, 
-style = "background-color: %s" % 
(getresultcolor(result),)), 
-html.td(self.render_test_references(result)),
-html.td(result['pypy-revision']),
-html.td(result['userhost'][:15]), 
-html.td(result['platform']), 
-html.td("%.2fs" % result['execution-time']),
-html.td(options), 
-html.td(result.repr_short_error() or NBSP)
-)
-
-def getrelpath(self, p): 
-return p.relto(self.indexpath.dirpath())
-
-def render_test_references(self, result): 
-dest = self.make_single_test_result(result)
-#XXX: ask hg for differences between test and vendor branch
-modified = result.ismodifiedtest() and " [mod]" or ""
-return html.div(html.a(result.path.purebasename + modified, 
-  href=self.getrelpath(dest)),
-  style="background-color: transparent")
-
-def make_single_test_result(self, result): 
-cache = self.indexpath.dirpath('.cache', result['userhost'][:15])
-cache.ensure(dir=1)
-dest = cache.join(result.path.basename).new(ext='.html')
-doc = ViewResult(result)
-doc.writetopath(dest)
-return dest
-
-def getcorelists(self): 
-def iscore(result): 
-return 'core' in result.get('options', []) 
-coretests = []
-noncoretests = []
-for name in self.resultcache.getnames(): 
-result = self.resultcache.getlatestrelevant(name)
-if iscore(result): 
-coretests.append(result)
-else: 
-   

[pypy-commit] pypy py3.5: hg merge default

2018-03-19 Thread mjacob
Author: Manuel Jacob 
Branch: py3.5
Changeset: r94017:d12c359516b2
Date: 2018-03-19 23:21 +0100
http://bitbucket.org/pypy/pypy/changeset/d12c359516b2/

Log:hg merge default

diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -15,6 +15,7 @@
 from rpython.rlib.listsort import make_timsort_class
 from rpython.rlib.objectmodel import (
 import_from_mixin, instantiate, newlist_hint, resizelist_hint, specialize)
+from rpython.rlib.rarithmetic import ovfcheck
 from rpython.rlib import longlong2float
 from rpython.tool.sourcetools import func_with_new_name
 
@@ -848,7 +849,12 @@
 """Extend w_list from a generic iterable"""
 length_hint = self.space.length_hint(w_iterable, 0)
 if length_hint:
-w_list._resize_hint(w_list.length() + length_hint)
+try:
+newsize_hint = ovfcheck(w_list.length() + length_hint)
+except OverflowError:
+pass
+else:
+w_list._resize_hint(newsize_hint)
 
 extended = _do_extend_from_iterable(self.space, w_list, w_iterable)
 
diff --git a/pypy/objspace/std/test/test_listobject.py 
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -618,6 +618,18 @@
 assert l == [1.2, 2.3, 3.4, 4.5]
 assert l is l0
 
+def test_extend_iterable_length_hint_overflow(self):
+import sys
+class CustomIterable(object):
+def __iter__(self):
+if False:
+yield
+def __length_hint__(self):
+return sys.maxsize
+a = [1, 2, 3, 4]
+a.extend(CustomIterable())
+assert a == [1, 2, 3, 4]
+
 def test_sort(self):
 l = l0 = [1, 5, 3, 0]
 l.sort()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-03-19 Thread mjacob
Author: Manuel Jacob 
Branch: py3.5
Changeset: r94004:fcbdf6d13402
Date: 2018-03-19 16:55 +0100
http://bitbucket.org/pypy/pypy/changeset/fcbdf6d13402/

Log:hg 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
@@ -52,3 +52,13 @@
 .. branch: refactor-slots
 
 Refactor cpyext slots.
+
+
+.. branch: call-loopinvariant-into-bridges
+
+Speed up branchy code that does a lot of function inlining by saving one call
+to read the TLS in most bridges.
+
+.. branch: rpython-sprint
+
+Refactor in rpython signatures
diff --git a/pypy/module/posix/test/test_posix2.py 
b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -1403,6 +1403,7 @@
 if len(e.value.args) > 2:
 assert e.value.args[2] == "\\foo\\bar\\baz"
 
+@py.test.mark.skipif("sys.platform != 'win32'")
 def test_rename(self):
 os = self.posix
 fname = self.path2 + 'rename.txt'
diff --git a/pypy/module/unicodedata/test/test_hyp.py 
b/pypy/module/unicodedata/test/test_hyp.py
--- a/pypy/module/unicodedata/test/test_hyp.py
+++ b/pypy/module/unicodedata/test/test_hyp.py
@@ -1,6 +1,7 @@
+import sys
 import pytest
 try:
-from hypothesis import given, strategies as st, example, settings
+from hypothesis import given, strategies as st, example, settings, assume
 except ImportError:
 pytest.skip("hypothesis required")
 
@@ -40,9 +41,14 @@
 
 @pytest.mark.parametrize('NF1, NF2, NF3', compositions)
 @example(s=u'---\uafb8\u11a7---')  # issue 2289
-@example(s=u'\ufacf')
 @settings(max_examples=1000)
 @given(s=st.text())
 def test_composition(s, space, NF1, NF2, NF3):
+# 'chr(0xfacf) normalizes to chr(0x2284a), which is too big')
+assume(not (s == u'\ufacf' and sys.maxunicode == 65535))
 norm1, norm2, norm3 = [make_normalization(space, form) for form in [NF1, 
NF2, NF3]]
 assert norm2(norm1(s)) == norm3(s)
+
+if sys.maxunicode != 65535:
+# conditionally generate the example via an unwrapped decorator
+test_composition = example(s=u'\ufacf')(test_composition)
diff --git a/rpython/annotator/signature.py b/rpython/annotator/signature.py
--- a/rpython/annotator/signature.py
+++ b/rpython/annotator/signature.py
@@ -14,16 +14,16 @@
 
 def _annotation_key(t):
 from rpython.rtyper import extregistry
-if type(t) is list:
+if isinstance(t, list):
 assert len(t) == 1
 return ('list', _annotation_key(t[0]))
-elif type(t) is dict:
+elif isinstance(t, dict):
 assert len(t.keys()) == 1
 return ('dict', _annotation_key(t.items()[0]))
 elif isinstance(t, tuple):
 return tuple([_annotation_key(i) for i in t])
 elif extregistry.is_registered(t):
-# XXX should it really be always different?
+# XXX do we want to do something in this case?
 return t
 return t
 
@@ -38,24 +38,36 @@
 return t
 return _compute_annotation(t, bookkeeper)
 
+
+def _validate_annotation_size(t):
+try:
+_ = iter(t)
+except TypeError:  # if it's not an iterable, just return
+return t   # (size does not matter)
+if isinstance(t, tuple):  # we accept tuples with any length, because
+return t  # their in-memory representation is predictable
+if len(t) > 1:
+raise TypeError("Cannot specify multiple types in a %s (try using 
tuple)", type(t))
+
+
 def _compute_annotation(t, bookkeeper=None):
 from rpython.rtyper.lltypesystem import lltype
 from rpython.rtyper.llannotation import lltype_to_annotation
+_validate_annotation_size(t)
 if isinstance(t, SomeObject):
 return t
 elif isinstance(t, lltype.LowLevelType):
 return lltype_to_annotation(t)
 elif isinstance(t, list):
-assert len(t) == 1, "We do not support type joining in list"
-listdef = ListDef(bookkeeper, annotation(t[0]), mutated=True, 
resized=True)
-return SomeList(listdef)
+return SomeList(
+ListDef(bookkeeper, annotation(t[0]),
+mutated=True, resized=True))
 elif isinstance(t, tuple):
 return SomeTuple(tuple([annotation(i) for i in t]))
 elif isinstance(t, dict):
-assert len(t) == 1, "We do not support type joining in dict"
-result = SomeDict(DictDef(bookkeeper, annotation(t.keys()[0]),
-annotation(t.values()[0])))
-return result
+return SomeDict(
+DictDef(bookkeeper,
+annotation(t.keys()[0]), annotation(t.values()[0])))
 elif type(t) is types.NoneType:
 return s_None
 elif extregistry.is_registered(t):
@@ -84,13 +96,12 @@
 elif t is types.NoneType:
 return s_None
 elif bookkeeper and extregistry.is_registered_type(t):
-entry = 

[pypy-commit] pypy py3.5: hg merge default

2018-02-19 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r93839:dd3b9bfab6a0
Date: 2018-02-20 02:47 +
http://bitbucket.org/pypy/pypy/changeset/dd3b9bfab6a0/

Log:hg merge default

diff --git a/pypy/module/test_lib_pypy/pyrepl/__init__.py 
b/extra_tests/test_pyrepl/__init__.py
rename from pypy/module/test_lib_pypy/pyrepl/__init__.py
rename to extra_tests/test_pyrepl/__init__.py
--- a/pypy/module/test_lib_pypy/pyrepl/__init__.py
+++ b/extra_tests/test_pyrepl/__init__.py
@@ -1,3 +1,1 @@
-import sys
-import lib_pypy.pyrepl
-sys.modules['pyrepl'] = sys.modules['lib_pypy.pyrepl']
+
diff --git a/pypy/module/test_lib_pypy/pyrepl/infrastructure.py 
b/extra_tests/test_pyrepl/infrastructure.py
rename from pypy/module/test_lib_pypy/pyrepl/infrastructure.py
rename to extra_tests/test_pyrepl/infrastructure.py
diff --git a/pypy/module/test_lib_pypy/pyrepl/test_basic.py 
b/extra_tests/test_pyrepl/test_basic.py
rename from pypy/module/test_lib_pypy/pyrepl/test_basic.py
rename to extra_tests/test_pyrepl/test_basic.py
diff --git a/pypy/module/test_lib_pypy/pyrepl/test_bugs.py 
b/extra_tests/test_pyrepl/test_bugs.py
rename from pypy/module/test_lib_pypy/pyrepl/test_bugs.py
rename to extra_tests/test_pyrepl/test_bugs.py
diff --git a/pypy/module/test_lib_pypy/pyrepl/test_functional.py 
b/extra_tests/test_pyrepl/test_functional.py
rename from pypy/module/test_lib_pypy/pyrepl/test_functional.py
rename to extra_tests/test_pyrepl/test_functional.py
--- a/pypy/module/test_lib_pypy/pyrepl/test_functional.py
+++ b/extra_tests/test_pyrepl/test_functional.py
@@ -7,7 +7,8 @@
 import sys
 
 
-def pytest_funcarg__child(request):
+@pytest.fixture()
+def child():
 try:
 import pexpect
 except ImportError:
diff --git a/pypy/module/test_lib_pypy/pyrepl/test_keymap.py 
b/extra_tests/test_pyrepl/test_keymap.py
rename from pypy/module/test_lib_pypy/pyrepl/test_keymap.py
rename to extra_tests/test_pyrepl/test_keymap.py
diff --git a/pypy/module/test_lib_pypy/pyrepl/test_reader.py 
b/extra_tests/test_pyrepl/test_reader.py
rename from pypy/module/test_lib_pypy/pyrepl/test_reader.py
rename to extra_tests/test_pyrepl/test_reader.py
diff --git a/pypy/module/test_lib_pypy/pyrepl/test_readline.py 
b/extra_tests/test_pyrepl/test_readline.py
rename from pypy/module/test_lib_pypy/pyrepl/test_readline.py
rename to extra_tests/test_pyrepl/test_readline.py
diff --git a/pypy/module/test_lib_pypy/pyrepl/test_wishes.py 
b/extra_tests/test_pyrepl/test_wishes.py
rename from pypy/module/test_lib_pypy/pyrepl/test_wishes.py
rename to extra_tests/test_pyrepl/test_wishes.py
diff --git a/pypy/doc/gc_info.rst b/pypy/doc/gc_info.rst
--- a/pypy/doc/gc_info.rst
+++ b/pypy/doc/gc_info.rst
@@ -1,17 +1,137 @@
-Garbage collector configuration
-===
+Garbage collector documentation and configuration
+=
+
+
+Incminimark
+---
+
+PyPy's default garbage collector is called incminimark - it's an incremental,
+generational moving collector. Here we hope to explain a bit how it works
+and how it can be tuned to suit the workload.
+
+Incminimark first allocates objects in so called *nursery* - place for young
+objects, where allocation is very cheap, being just a pointer bump. The nursery
+size is a very crucial variable - depending on your workload (one or many
+processes) and cache sizes you might want to experiment with it via
+*PYPY_GC_NURSERY* environment variable. When the nursery is full, there is
+performed a minor collection. Freed objects are no longer referencable and
+just die, just by not being referenced any more; on the other hand, objects
+found to still be alive must survive and are copied from the nursery
+to the old generation. Either to arenas, which are collections
+of objects of the same size, or directly allocated with malloc if they're
+larger.  (A third category, the very large objects, are initially allocated
+outside the nursery and never move.)
+
+Since Incminimark is an incremental GC, the major collection is incremental,
+meaning there should not be any pauses longer than 1ms.
+
+
+Fragmentation
+-
+
+Before we discuss issues of "fragmentation", we need a bit of precision.
+There are two kinds of related but distinct issues:
+
+* If the program allocates a lot of memory, and then frees it all by
+  dropping all references to it, then we might expect to see the RSS
+  to drop.  (RSS = Resident Set Size on Linux, as seen by "top"; it is an
+  approximation of the actual memory usage from the OS's point of view.)
+  This might not occur: the RSS may remain at its highest value.  This
+  issue is more precisely caused by the process not returning "free"
+  memory to the OS.  We call this case "unreturned memory".
+
+* After doing the above, if the RSS didn't go down, then at least future
+  allocations should not cause the RSS to grow more.  That is, the process
+  should reuse unreturned memory as long as it has got some left.  If 

[pypy-commit] pypy py3.5: hg merge default

2018-01-12 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r93660:0ec5e7c14574
Date: 2018-01-12 17:38 +
http://bitbucket.org/pypy/pypy/changeset/0ec5e7c14574/

Log:hg merge default

diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -50,3 +50,4 @@
  release-pypy3.5-v5.10.0
  release-pypy3.5-v5.10.0
 09f9160b643e3f02ccb8c843b2fbb4e5cbf54082 release-pypy3.5-v5.10.0
+3f6eaa010fce78cc7973bdc1dfdb95970f08fed2 release-pypy3.5-v5.10.1
diff --git a/lib_pypy/cffi.egg-info/PKG-INFO b/lib_pypy/cffi.egg-info/PKG-INFO
--- a/lib_pypy/cffi.egg-info/PKG-INFO
+++ b/lib_pypy/cffi.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: cffi
-Version: 1.11.2
+Version: 1.11.3
 Summary: Foreign Function Interface for Python calling C code.
 Home-page: http://cffi.readthedocs.org
 Author: Armin Rigo, Maciej Fijalkowski
diff --git a/lib_pypy/cffi/__init__.py b/lib_pypy/cffi/__init__.py
--- a/lib_pypy/cffi/__init__.py
+++ b/lib_pypy/cffi/__init__.py
@@ -4,8 +4,8 @@
 from .api import FFI
 from .error import CDefError, FFIError, VerificationError, VerificationMissing
 
-__version__ = "1.11.2"
-__version_info__ = (1, 11, 2)
+__version__ = "1.11.3"
+__version_info__ = (1, 11, 3)
 
 # The verifier module file names are based on the CRC32 of a string that
 # contains the following version number.  It may be older than __version__
diff --git a/lib_pypy/cffi/_cffi_include.h b/lib_pypy/cffi/_cffi_include.h
--- a/lib_pypy/cffi/_cffi_include.h
+++ b/lib_pypy/cffi/_cffi_include.h
@@ -7,11 +7,38 @@
we can learn about Py_DEBUG from pyconfig.h, but it is unclear if
the same works for the other two macros.  Py_DEBUG implies them,
but not the other way around.
+
+   Issue #350: more mess: on Windows, with _MSC_VER, we have to define
+   Py_LIMITED_API even before including pyconfig.h.  In that case, we
+   guess what pyconfig.h will do to the macros above, and check our
+   guess after the #include.
 */
 #if !defined(_CFFI_USE_EMBEDDING) && !defined(Py_LIMITED_API)
-#  include 
-#  if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG)
-#define Py_LIMITED_API
+#  ifdef _MSC_VER
+#if !defined(_DEBUG) && !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && 
!defined(Py_REF_DEBUG)
+#  define Py_LIMITED_API
+#endif
+#include 
+ /* sanity-check: Py_LIMITED_API will cause crashes if any of these
+are also defined.  Normally, the Python file PC/pyconfig.h does not
+cause any of these to be defined, with the exception that _DEBUG
+causes Py_DEBUG.  Double-check that. */
+#ifdef Py_LIMITED_API
+#  if defined(Py_DEBUG)
+#error "pyconfig.h unexpectedly defines Py_DEBUG but _DEBUG is not set"
+#  endif
+#  if defined(Py_TRACE_REFS)
+#error "pyconfig.h unexpectedly defines Py_TRACE_REFS"
+#  endif
+#  if defined(Py_REF_DEBUG)
+#error "pyconfig.h unexpectedly defines Py_REF_DEBUG"
+#  endif
+#endif
+#  else
+#include 
+#if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG)
+#  define Py_LIMITED_API
+#endif
 #  endif
 #endif
 
diff --git a/lib_pypy/cffi/_embedding.h b/lib_pypy/cffi/_embedding.h
--- a/lib_pypy/cffi/_embedding.h
+++ b/lib_pypy/cffi/_embedding.h
@@ -247,7 +247,7 @@
 
 if (f != NULL && f != Py_None) {
 PyFile_WriteString("\nFrom: " _CFFI_MODULE_NAME
-   "\ncompiled with cffi version: 1.11.2"
+   "\ncompiled with cffi version: 1.11.3"
"\n_cffi_backend module: ", f);
 modules = PyImport_GetModuleDict();
 mod = PyDict_GetItemString(modules, "_cffi_backend");
diff --git a/lib_pypy/cffi/recompiler.py b/lib_pypy/cffi/recompiler.py
--- a/lib_pypy/cffi/recompiler.py
+++ b/lib_pypy/cffi/recompiler.py
@@ -295,8 +295,9 @@
 base_module_name = self.module_name.split('.')[-1]
 if self.ffi._embedding is not None:
 prnt('#define _CFFI_MODULE_NAME  "%s"' % (self.module_name,))
-prnt('#define _CFFI_PYTHON_STARTUP_CODE  %s' %
- (self._string_literal(self.ffi._embedding),))
+prnt('static const char _CFFI_PYTHON_STARTUP_CODE[] = {')
+self._print_string_literal_in_array(self.ffi._embedding)
+prnt('0 };')
 prnt('#ifdef PYPY_VERSION')
 prnt('# define _CFFI_PYTHON_STARTUP_FUNC  _cffi_pypyinit_%s' % (
 base_module_name,))
@@ -1271,17 +1272,18 @@
   _generate_cpy_extern_python_plus_c_ctx = \
   _generate_cpy_extern_python_ctx
 
-def _string_literal(self, s):
-def _char_repr(c):
-# escape with a '\' the characters '\', '"' or (for trigraphs) '?'
-if c in '\\"?': return '\\' + c
-if ' ' <= c < '\x7F': return c
-if c == '\n': return '\\n'
-return '\\%03o' % 

[pypy-commit] pypy py3.5: hg merge default

2018-01-10 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r93650:52e62b9d7e92
Date: 2018-01-10 22:44 +0100
http://bitbucket.org/pypy/pypy/changeset/52e62b9d7e92/

Log:hg merge default

diff --git a/pypy/module/_cffi_backend/test/test_recompiler.py 
b/pypy/module/_cffi_backend/test/test_recompiler.py
--- a/pypy/module/_cffi_backend/test/test_recompiler.py
+++ b/pypy/module/_cffi_backend/test/test_recompiler.py
@@ -8,7 +8,8 @@
 
 @unwrap_spec(cdef='text', module_name='text', source='text', packed=int)
 def prepare(space, cdef, module_name, source, w_includes=None,
-w_extra_source=None, w_min_version=None, packed=False):
+w_extra_source=None, w_min_version=None, packed=False,
+w_extra_compile_args=None):
 try:
 import cffi
 from cffi import FFI# <== the system one, which
@@ -55,10 +56,14 @@
 sources = []
 if w_extra_source is not None:
 sources.append(space.str_w(w_extra_source))
+kwargs = {}
+if w_extra_compile_args is not None:
+kwargs['extra_compile_args'] = space.unwrap(w_extra_compile_args)
 ext = ffiplatform.get_extension(c_file, module_name,
 include_dirs=[str(rdir)],
 export_symbols=['_cffi_pypyinit_' + base_module_name],
-sources=sources)
+sources=sources,
+**kwargs)
 ffiplatform.compile(str(rdir), ext)
 
 for extension in ['so', 'pyd', 'dylib']:
@@ -2055,3 +2060,51 @@
"Such structs are only supported as return value if the function is 
"
"'API mode' and non-variadic (i.e. declared inside 
ffibuilder.cdef()"
"+ffibuilder.set_source() and not taking a final '...' argument)")
+
+def test_gcc_visibility_hidden(self):
+import sys
+if sys.platform == 'win32':
+skip("test for gcc/clang")
+ffi, lib = self.prepare("""
+int f(int);
+""", "test_gcc_visibility_hidden", """
+int f(int a) { return a + 40; }
+""", extra_compile_args=['-fvisibility=hidden'])
+assert lib.f(2) == 42
+
+def test_override_default_definition(self):
+ffi, lib = self.prepare("""
+typedef long int16_t, char16_t;
+""", "test_override_default_definition", """
+""")
+assert ffi.typeof("int16_t") is ffi.typeof("char16_t") is 
ffi.typeof("long")
+
+def test_char16_char32_plain_c(self):
+ffi, lib = self.prepare("""
+char16_t foo_2bytes(char16_t);
+char32_t foo_4bytes(char32_t);
+""", "test_char16_char32_type_nocpp", """
+#if !defined(__cplusplus) || (!defined(_LIBCPP_VERSION) && __cplusplus 
< 201103L)
+typedef uint_least16_t char16_t;
+typedef uint_least32_t char32_t;
+#endif
+
+char16_t foo_2bytes(char16_t a) { return (char16_t)(a + 42); }
+char32_t foo_4bytes(char32_t a) { return (char32_t)(a + 42); }
+""", min_version=(1, 11, 0))
+assert lib.foo_2bytes(u'\u1234') == u'\u125e'
+assert lib.foo_4bytes(u'\u1234') == u'\u125e'
+assert lib.foo_4bytes(u'\U00012345') == u'\U0001236f'
+raises(TypeError, lib.foo_2bytes, u'\U00012345')
+raises(TypeError, lib.foo_2bytes, 1234)
+raises(TypeError, lib.foo_4bytes, 1234)
+
+def test_loader_spec(self):
+import sys
+ffi, lib = self.prepare("", "test_loader_spec", "")
+if sys.version_info < (3,):
+assert not hasattr(lib, '__loader__')
+assert not hasattr(lib, '__spec__')
+else:
+assert lib.__loader__ is None
+assert lib.__spec__ is None
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2018-01-05 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r93628:799e8d00a8ec
Date: 2018-01-05 20:17 +
http://bitbucket.org/pypy/pypy/changeset/799e8d00a8ec/

Log:hg merge default

diff too long, truncating to 2000 out of 4420 lines

diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -46,3 +46,7 @@
 84a2f3e6a7f88f2fe698e473998755b3bd1a12e2 release-pypy2.7-v5.9.0
 0e7ea4fe15e82d5124e805e2e4a37cae1a402d4b release-pypy2.7-v5.10.0
 a91df6163fb76df245091f741dbf6a23ddc72374 release-pypy3.5-v5.10.0
+a91df6163fb76df245091f741dbf6a23ddc72374 release-pypy3.5-v5.10.0
+ release-pypy3.5-v5.10.0
+ release-pypy3.5-v5.10.0
+09f9160b643e3f02ccb8c843b2fbb4e5cbf54082 release-pypy3.5-v5.10.0
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -339,8 +339,10 @@
   Stanisaw Halik
   Julien Phalip
   Roman Podoliaka
+  Steve Papanik
   Eli Stevens
   Boglarka Vezer
+  gabrielg
   PavloKapyshin
   Tomer Chachamu
   Christopher Groskopf
@@ -363,11 +365,13 @@
   Konrad Delong
   Dinu Gherman
   pizi
+  Tom Pruina
   James Robert
   Armin Ronacher
   Diana Popa
   Mads Kiilerich
   Brett Cannon
+  Caleb Hattingh
   aliceinwire
   Zooko Wilcox-O Hearn
   James Lan
@@ -388,6 +392,7 @@
   Jason Madden
   Yaroslav Fedevych
   Even Wiik Thomassen
+  m...@funkyhat.org
   Stefan Marr
 
   Heinrich-Heine University, Germany 
diff --git a/lib_pypy/_ctypes/array.py b/lib_pypy/_ctypes/array.py
--- a/lib_pypy/_ctypes/array.py
+++ b/lib_pypy/_ctypes/array.py
@@ -12,7 +12,8 @@
 if cls == (_CData,): # this is the Array class defined below
 res._ffiarray = None
 return res
-if not hasattr(res, '_length_') or not isinstance(res._length_, int):
+if not hasattr(res, '_length_') or not isinstance(res._length_,
+  (int, long)):
 raise AttributeError(
 "class must define a '_length_' attribute, "
 "which must be a positive integer")
diff --git a/pypy/doc/contributor.rst b/pypy/doc/contributor.rst
--- a/pypy/doc/contributor.rst
+++ b/pypy/doc/contributor.rst
@@ -217,6 +217,7 @@
   Alejandro J. Cura
   Vladimir Kryachko
   Gabriel
+  Thomas Hisch
   Mark Williams
   Kunal Grover
   Nathan Taylor
@@ -306,8 +307,10 @@
   Stanisaw Halik
   Julien Phalip
   Roman Podoliaka
+  Steve Papanik
   Eli Stevens
   Boglarka Vezer
+  gabrielg
   PavloKapyshin
   Tomer Chachamu
   Christopher Groskopf
@@ -330,11 +333,13 @@
   Konrad Delong
   Dinu Gherman
   pizi
+  Tom Pruina
   James Robert
   Armin Ronacher
   Diana Popa
   Mads Kiilerich
   Brett Cannon
+  Caleb Hattingh
   aliceinwire
   Zooko Wilcox-O Hearn
   James Lan
@@ -355,4 +360,5 @@
   Jason Madden
   Yaroslav Fedevych
   Even Wiik Thomassen
+  m...@funkyhat.org
   Stefan Marr
diff --git a/pypy/doc/cpython_differences.rst b/pypy/doc/cpython_differences.rst
--- a/pypy/doc/cpython_differences.rst
+++ b/pypy/doc/cpython_differences.rst
@@ -558,6 +558,15 @@
   ``del foo.bar`` where ``foo`` is a module (or class) that contains the
   function ``bar``, is significantly slower than CPython.
 
+* Various built-in functions in CPython accept only positional arguments
+  and not keyword arguments.  That can be considered a long-running
+  historical detail: newer functions tend to accept keyword arguments
+  and older function are occasionally fixed to do so as well.  In PyPy,
+  most built-in functions accept keyword arguments (``help()`` shows the
+  argument names).  But don't rely on it too much because future
+  versions of PyPy may have to rename the arguments if CPython starts
+  accepting them too.
+
 .. _`is ignored in PyPy`: http://bugs.python.org/issue14621
 .. _`little point`: 
http://events.ccc.de/congress/2012/Fahrplan/events/5152.en.html
 .. _`#2072`: https://bitbucket.org/pypy/pypy/issue/2072/
diff --git a/pypy/doc/tool/makecontributor.py b/pypy/doc/tool/makecontributor.py
--- a/pypy/doc/tool/makecontributor.py
+++ b/pypy/doc/tool/makecontributor.py
@@ -81,6 +81,7 @@
 'Yasir Suhail':['yasirs'],
 'Squeaky': ['squeaky'],
 "Amaury Forgeot d'Arc": ['amaur...@gmail.com'],
+"Dodan Mihai": ['mihai.do...@gmail.com'],
 }
 
 alias_map = {}
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
@@ -5,3 +5,8 @@
 .. this is a revision shortly after release-pypy2.7-v5.10.0
 .. startrev: 6b024edd9d12
 
+.. branch: cpyext-avoid-roundtrip
+
+Big refactoring of some cpyext code, which avoids a lot of nonsense when
+calling C from Python and vice-versa: the result is a big speedup in
+function/method calls, up to 6 times faster.
diff --git a/pypy/module/_cppyy/converter.py b/pypy/module/_cppyy/converter.py
--- a/pypy/module/_cppyy/converter.py
+++ b/pypy/module/_cppyy/converter.py
@@ -682,8 +682,8 @@
 if hasattr(space, "fake"):
 raise 

[pypy-commit] pypy py3.5: hg merge default

2017-12-22 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r93553:c653db1b380d
Date: 2017-12-22 16:26 +0100
http://bitbucket.org/pypy/pypy/changeset/c653db1b380d/

Log:hg merge default

diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -44,3 +44,5 @@
 d72f9800a42b46a8056951b1da2426d2c2d8d502 release-pypy3.5-v5.9.0
 03d614975835870da65ff0481e1edad68ebbcb8d release-pypy2.7-v5.9.0
 84a2f3e6a7f88f2fe698e473998755b3bd1a12e2 release-pypy2.7-v5.9.0
+0e7ea4fe15e82d5124e805e2e4a37cae1a402d4b release-pypy2.7-v5.10.0
+a91df6163fb76df245091f741dbf6a23ddc72374 release-pypy3.5-v5.10.0
diff --git a/pypy/doc/index-of-whatsnew.rst b/pypy/doc/index-of-whatsnew.rst
--- a/pypy/doc/index-of-whatsnew.rst
+++ b/pypy/doc/index-of-whatsnew.rst
@@ -7,6 +7,7 @@
 .. toctree::
 
whatsnew-head.rst
+   whatsnew-pypy2-5.10.0.rst
whatsnew-pypy2-5.9.0.rst
whatsnew-pypy2-5.8.0.rst
whatsnew-pypy2-5.7.0.rst
diff --git a/pypy/doc/release-v5.10.0.rst b/pypy/doc/release-v5.10.0.rst
--- a/pypy/doc/release-v5.10.0.rst
+++ b/pypy/doc/release-v5.10.0.rst
@@ -19,6 +19,12 @@
 several issues and bugs raised by the growing community of PyPy users.
 As always, we strongly recommend updating.
 
+There are quite a few important changes that are in the pipeline that did not
+make it into the 5.10 release. Most important are speed improvements to cpyext
+(which will make numpy and pandas a bit faster) and utf8 branch that changes
+internal representation of unicode to utf8, which should help especially the
+Python 3.5 version of PyPy.
+
 This release concludes the Mozilla Open Source `grant`_ for having a compatible
 PyPy 3.5 release and we're very grateful for that.  Of course, we will continue
 to improve PyPy 3.5 and probably move to 3.6 during the course of 2018.
@@ -53,7 +59,7 @@
 We also welcome developers of other `dynamic languages`_ to see what RPython
 can do for them.
 
-The PyPy 2.7 release supports: 
+The PyPy release supports: 
 
   * **x86** machines on most common operating systems
 (Linux 32/64 bits, Mac OS X 64 bits, Windows 32 bits, OpenBSD, FreeBSD)
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
@@ -2,41 +2,6 @@
 What's new in PyPy2.7 5.10+
 ===
 
-.. this is a revision shortly after release-pypy2.7-v5.9.0
-.. startrev:d56dadcef996
+.. this is a revision shortly after release-pypy2.7-v5.10.0
+.. startrev: 6b024edd9d12
 
-
-.. branch: cppyy-packaging
-
-Cleanup and improve cppyy packaging
-
-.. branch: docs-osx-brew-openssl
-
-.. branch: keep-debug-symbols
-
-Add a smartstrip tool, which can optionally keep the debug symbols in a
-separate file, instead of just stripping them away. Use it in packaging
-
-.. branch: bsd-patches
-
-Fix failures on FreeBSD, contributed by David Naylor as patches on the issue
-tracker (issues 2694, 2695, 2696, 2697)
-
-.. branch: run-extra-tests
-
-Run extra_tests/ in buildbot
-
-.. branch: vmprof-0.4.10
-
-Upgrade the _vmprof backend to vmprof 0.4.10
-
-.. branch: fix-vmprof-stacklet-switch
-.. branch: fix-vmprof-stacklet-switch-2
-Fix a vmprof+continulets (i.e. greenelts, eventlet, gevent, ...)
-
-.. branch: win32-vcvars
-
-.. branch: rdict-fast-hash
-
-Make it possible to declare that the hash function of an r_dict is fast in 
RPython.
-
diff --git a/pypy/doc/whatsnew-pypy2-5.10.0.rst 
b/pypy/doc/whatsnew-pypy2-5.10.0.rst
new file mode 100644
--- /dev/null
+++ b/pypy/doc/whatsnew-pypy2-5.10.0.rst
@@ -0,0 +1,42 @@
+==
+What's new in PyPy2.7 5.10
+==
+
+.. this is a revision shortly after release-pypy2.7-v5.9.0
+.. startrev:d56dadcef996
+
+
+.. branch: cppyy-packaging
+
+Cleanup and improve cppyy packaging
+
+.. branch: docs-osx-brew-openssl
+
+.. branch: keep-debug-symbols
+
+Add a smartstrip tool, which can optionally keep the debug symbols in a
+separate file, instead of just stripping them away. Use it in packaging
+
+.. branch: bsd-patches
+
+Fix failures on FreeBSD, contributed by David Naylor as patches on the issue
+tracker (issues 2694, 2695, 2696, 2697)
+
+.. branch: run-extra-tests
+
+Run extra_tests/ in buildbot
+
+.. branch: vmprof-0.4.10
+
+Upgrade the _vmprof backend to vmprof 0.4.10
+
+.. branch: fix-vmprof-stacklet-switch
+.. branch: fix-vmprof-stacklet-switch-2
+Fix a vmprof+continulets (i.e. greenelts, eventlet, gevent, ...)
+
+.. branch: win32-vcvars
+
+.. branch: rdict-fast-hash
+
+Make it possible to declare that the hash function of an r_dict is fast in 
RPython.
+
diff --git a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c 
b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
--- a/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
+++ b/pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test.c
@@ -3,9 +3,7 @@
 #define MS_WIN32
 #endif
 
-#include "src/precommondefs.h"
-
-#define EXPORT(x)  RPY_EXPORTED x
+#define EXPORT(x)  extern x
 
 #include 
 #include 
@@ -272,7 +270,7 

[pypy-commit] pypy py3.5: hg merge default

2017-12-18 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r93467:a04f367d45a5
Date: 2017-12-18 13:13 +0100
http://bitbucket.org/pypy/pypy/changeset/a04f367d45a5/

Log:hg merge default

diff --git a/rpython/rlib/rwin32.py b/rpython/rlib/rwin32.py
--- a/rpython/rlib/rwin32.py
+++ b/rpython/rlib/rwin32.py
@@ -210,6 +210,10 @@
 'FormatMessageA',
 [DWORD, rffi.VOIDP, DWORD, DWORD, rffi.CCHARP, DWORD, rffi.VOIDP],
 DWORD)
+FormatMessageW = winexternal(
+'FormatMessageW',
+[DWORD, rffi.VOIDP, DWORD, DWORD, rffi.CWCHARP, DWORD, rffi.VOIDP],
+DWORD)
 
 _get_osfhandle = rffi.llexternal('_get_osfhandle', [rffi.INT], HANDLE)
 
@@ -286,6 +290,8 @@
 # A bit like strerror...
 def FormatError(code):
 return llimpl_FormatError(code)
+def FormatErrorW(code):
+return llimpl_FormatErrorW(code)
 
 def llimpl_FormatError(code):
 "Return a message corresponding to the given Windows error code."
@@ -318,6 +324,37 @@
 
 return result
 
+def llimpl_FormatErrorW(code):
+"Return a unicode message corresponding to the given Windows error 
code."
+buf = lltype.malloc(rffi.CWCHARPP.TO, 1, flavor='raw')
+buf[0] = lltype.nullptr(rffi.CWCHARP.TO)
+try:
+msglen = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+FORMAT_MESSAGE_FROM_SYSTEM | 
+FORMAT_MESSAGE_IGNORE_INSERTS,
+None,
+rffi.cast(DWORD, code),
+DEFAULT_LANGUAGE,
+rffi.cast(rffi.CWCHARP, buf),
+0, None)
+buflen = intmask(msglen)
+
+# remove trailing cr/lf and dots
+s_buf = buf[0]
+while buflen > 0 and (ord(s_buf[buflen - 1]) <= ord(' ') or
+  s_buf[buflen - 1] == u'.'):
+buflen -= 1
+
+if buflen <= 0:
+result = u'Windows Error %d' % (code,)
+else:
+result = rffi.wcharpsize2unicode(s_buf, buflen)
+finally:
+LocalFree(rffi.cast(rffi.VOIDP, buf[0]))
+lltype.free(buf, flavor='raw')
+
+return result
+
 def lastSavedWindowsError(context="Windows Error"):
 code = GetLastError_saved()
 return WindowsError(code, context)
diff --git a/rpython/rlib/test/test_rwin32.py b/rpython/rlib/test/test_rwin32.py
--- a/rpython/rlib/test/test_rwin32.py
+++ b/rpython/rlib/test/test_rwin32.py
@@ -64,3 +64,7 @@
 msg = rwin32.FormatError(34)
 assert '%2' in msg
 
+def test_formaterror_unicode():
+msg = rwin32.FormatErrorW(34)
+assert type(msg) is unicode
+assert u'%2' in msg
diff --git a/rpython/rtyper/lltypesystem/rffi.py 
b/rpython/rtyper/lltypesystem/rffi.py
--- a/rpython/rtyper/lltypesystem/rffi.py
+++ b/rpython/rtyper/lltypesystem/rffi.py
@@ -1011,6 +1011,7 @@
 
 # char**
 CCHARPP = lltype.Ptr(lltype.Array(CCHARP, hints={'nolength': True}))
+CWCHARPP = lltype.Ptr(lltype.Array(CWCHARP, hints={'nolength': True}))
 
 def liststr2charpp(l):
 """ list[str] -> char**, NULL terminated
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-12-17 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r93454:774bffb126ce
Date: 2017-12-17 22:14 +
http://bitbucket.org/pypy/pypy/changeset/774bffb126ce/

Log:hg merge default

diff --git a/pypy/module/cpyext/pyerrors.py b/pypy/module/cpyext/pyerrors.py
--- a/pypy/module/cpyext/pyerrors.py
+++ b/pypy/module/cpyext/pyerrors.py
@@ -154,7 +154,7 @@
 error indicator."""
 raise oefmt(space.w_TypeError, "bad argument type for built-in operation")
 
-@cpython_api([], lltype.Void)
+@cpython_api([], lltype.Void, error=None)
 def PyErr_BadInternalCall(space):
 raise oefmt(space.w_SystemError, "Bad internal call!")
 
diff --git a/pypy/module/cpyext/test/test_pyerrors.py 
b/pypy/module/cpyext/test/test_pyerrors.py
--- a/pypy/module/cpyext/test/test_pyerrors.py
+++ b/pypy/module/cpyext/test/test_pyerrors.py
@@ -463,3 +463,15 @@
 ])
 res = module.test(StopIteration("foo!"))
 assert res == "foo!"
+
+def test_PyErr_BadInternalCall(self):
+# NB. it only seemed to fail when run with '-s'... but I think
+# that it always printed stuff to stderr
+module = self.import_extension('foo', [
+("oops", "METH_NOARGS",
+ r'''
+ PyErr_BadInternalCall();
+ return NULL;
+ '''),
+])
+raises(SystemError, module.oops)
diff --git a/pypy/module/cpyext/test/test_tupleobject.py 
b/pypy/module/cpyext/test/test_tupleobject.py
--- a/pypy/module/cpyext/test/test_tupleobject.py
+++ b/pypy/module/cpyext/test/test_tupleobject.py
@@ -1,6 +1,7 @@
 import py
 
-from pypy.module.cpyext.pyobject import PyObject, PyObjectP, make_ref, from_ref
+from pypy.module.cpyext.pyobject import (
+PyObject, PyObjectP, make_ref, from_ref, incref)
 from pypy.module.cpyext.test.test_api import BaseApiTest, raises_w
 from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
 from rpython.rtyper.lltypesystem import rffi, lltype
@@ -14,6 +15,7 @@
 def test_tupleobject(self, space):
 assert not PyTuple_Check(space, space.w_None)
 with raises_w(space, SystemError):
+incref(space, space.w_None)
 PyTuple_SetItem(space, space.w_None, 0, space.w_None)
 atuple = space.newtuple([space.wrap(0), space.wrap(1),
  space.wrap('yay')])
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-12-15 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r93433:4d0d6cd1346b
Date: 2017-12-16 02:18 +
http://bitbucket.org/pypy/pypy/changeset/4d0d6cd1346b/

Log:hg merge default

diff --git a/pypy/doc/how-to-release.rst b/pypy/doc/how-to-release.rst
--- a/pypy/doc/how-to-release.rst
+++ b/pypy/doc/how-to-release.rst
@@ -62,7 +62,7 @@
   * go to pypy/tool/release and run
 ``force-builds.py ``
 The following JIT binaries should be built, however, we need more buildbots
-windows, linux-32, linux-64, osx64, armhf-raring, armhf-raspberrian, armel,
+windows, linux-32, linux-64, osx64, armhf-raspberrian, armel,
 freebsd64 
 
   * wait for builds to complete, make sure there are no failures
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
@@ -36,6 +36,6 @@
 
 .. branch: win32-vcvars
 
-.. branch rdict-fast-hash
+.. branch: rdict-fast-hash
 
 Make it possible to declare that the hash function of an r_dict is fast in 
RPython.
diff --git a/pypy/module/test_lib_pypy/test_greenlet.py 
b/pypy/module/_continuation/test/test_greenlet.py
rename from pypy/module/test_lib_pypy/test_greenlet.py
rename to pypy/module/_continuation/test/test_greenlet.py
diff --git a/pypy/tool/release/force-builds.py 
b/pypy/tool/release/force-builds.py
--- a/pypy/tool/release/force-builds.py
+++ b/pypy/tool/release/force-builds.py
@@ -29,7 +29,6 @@
 'pypy-c-jit-macosx-x86-64',
 'pypy-c-jit-win-x86-32',
 'pypy-c-jit-linux-s390x',
-'build-pypy-c-jit-linux-armhf-raring',
 'build-pypy-c-jit-linux-armhf-raspbian',
 'build-pypy-c-jit-linux-armel',
 ]
diff --git a/pypy/tool/release/repackage.sh b/pypy/tool/release/repackage.sh
--- a/pypy/tool/release/repackage.sh
+++ b/pypy/tool/release/repackage.sh
@@ -23,7 +23,7 @@
 
 # Download latest builds from the buildmaster, rename the top
 # level directory, and repackage ready to be uploaded to bitbucket
-for plat in linux linux64 linux-armhf-raspbian linux-armhf-raring linux-armel 
osx64 s390x
+for plat in linux linux64 linux-armhf-raspbian linux-armel osx64 s390x
   do
 echo downloading package for $plat
 if wget -q --show-progress 
http://buildbot.pypy.org/nightly/$branchname/pypy-c-jit-latest-$plat.tar.bz2
diff --git a/rpython/jit/metainterp/optimizeopt/optimizer.py 
b/rpython/jit/metainterp/optimizeopt/optimizer.py
--- a/rpython/jit/metainterp/optimizeopt/optimizer.py
+++ b/rpython/jit/metainterp/optimizeopt/optimizer.py
@@ -273,7 +273,6 @@
 self.jitdriver_sd = jitdriver_sd
 self.cpu = metainterp_sd.cpu
 self.interned_refs = self.cpu.ts.new_ref_dict()
-self.interned_ints = {}
 self.resumedata_memo = resume.ResumeDataLoopMemo(metainterp_sd)
 self.pendingfields = None # set temporarily to a list, normally by
   # heap.py, as we're about to generate a guard
diff --git a/rpython/rlib/rmmap.py b/rpython/rlib/rmmap.py
--- a/rpython/rlib/rmmap.py
+++ b/rpython/rlib/rmmap.py
@@ -492,6 +492,7 @@
 
 self.setslice(start, data)
 self.pos = start + data_len
+return data_len
 
 def write_byte(self, byte):
 if len(byte) != 1:
diff --git a/rpython/rlib/rstruct/standardfmttable.py 
b/rpython/rlib/rstruct/standardfmttable.py
--- a/rpython/rlib/rstruct/standardfmttable.py
+++ b/rpython/rlib/rstruct/standardfmttable.py
@@ -105,6 +105,18 @@
 _pack_string(fmtiter, string, count-1)
 
 
+def pack_halffloat(fmtiter):
+size = 2
+fl = fmtiter.accept_float_arg()
+try:
+result = ieee.pack_float(fmtiter.wbuf, fmtiter.pos,
+ fl, size, fmtiter.bigendian)
+except OverflowError:
+raise StructOverflowError("float too large for format 'e'")
+else:
+fmtiter.advance(size)
+return result
+
 def make_float_packer(TYPE):
 size = rffi.sizeof(TYPE)
 def packer(fmtiter):
@@ -247,6 +259,11 @@
 end = count
 fmtiter.appendobj(data[1:end])
 
+@specialize.argtype(0)
+def unpack_halffloat(fmtiter):
+data = fmtiter.read(2)
+fmtiter.appendobj(ieee.unpack_float(data, fmtiter.bigendian))
+
 def make_ieee_unpacker(TYPE):
 @specialize.argtype(0)
 def unpack_ieee(fmtiter):
@@ -374,6 +391,8 @@
   'needcount' : True },
 'p':{ 'size' : 1, 'pack' : pack_pascal, 'unpack' : unpack_pascal,
   'needcount' : True },
+'e':{ 'size' : 2, 'pack' : pack_halffloat,
+'unpack' : unpack_halffloat},
 'f':{ 'size' : 4, 'pack' : make_float_packer(rffi.FLOAT),
 'unpack' : unpack_float},
 'd':{ 'size' : 8, 'pack' : make_float_packer(rffi.DOUBLE),
diff --git a/rpython/rlib/rstruct/test/test_pack.py 
b/rpython/rlib/rstruct/test/test_pack.py
--- a/rpython/rlib/rstruct/test/test_pack.py
+++ b/rpython/rlib/rstruct/test/test_pack.py
@@ -138,6 +138,19 @@
 self.check('f', 123.456)
 self.check('d', 123.456789)
 

[pypy-commit] pypy py3.5: hg merge default

2017-12-12 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r93402:da4b6cf751a5
Date: 2017-12-12 23:37 +
http://bitbucket.org/pypy/pypy/changeset/da4b6cf751a5/

Log:hg merge default

diff --git a/pypy/module/test_lib_pypy/test_json_extra.py 
b/extra_tests/test_json.py
rename from pypy/module/test_lib_pypy/test_json_extra.py
rename to extra_tests/test_json.py
--- a/pypy/module/test_lib_pypy/test_json_extra.py
+++ b/extra_tests/test_json.py
@@ -1,4 +1,6 @@
-import py, json
+import pytest
+import json
+from hypothesis import given, strategies
 
 def is_(x, y):
 return type(x) is type(y) and x == y
@@ -6,12 +8,26 @@
 def test_no_ensure_ascii():
 assert is_(json.dumps(u"\u1234", ensure_ascii=False), u'"\u1234"')
 assert is_(json.dumps("\xc0", ensure_ascii=False), '"\xc0"')
-e = py.test.raises(UnicodeDecodeError, json.dumps,
-   (u"\u1234", "\xc0"), ensure_ascii=False)
-assert str(e.value).startswith("'ascii' codec can't decode byte 0xc0 ")
-e = py.test.raises(UnicodeDecodeError, json.dumps,
-   ("\xc0", u"\u1234"), ensure_ascii=False)
-assert str(e.value).startswith("'ascii' codec can't decode byte 0xc0 ")
+with pytest.raises(UnicodeDecodeError) as excinfo:
+json.dumps((u"\u1234", "\xc0"), ensure_ascii=False)
+assert str(excinfo.value).startswith(
+"'ascii' codec can't decode byte 0xc0 ")
+with pytest.raises(UnicodeDecodeError) as excinfo:
+json.dumps(("\xc0", u"\u1234"), ensure_ascii=False)
+assert str(excinfo.value).startswith(
+"'ascii' codec can't decode byte 0xc0 ")
 
 def test_issue2191():
 assert is_(json.dumps(u"xxx", ensure_ascii=False), u'"xxx"')
+
+jsondata = strategies.recursive(
+strategies.none() |
+strategies.booleans() |
+strategies.floats(allow_nan=False) |
+strategies.text(),
+lambda children: strategies.lists(children) |
+strategies.dictionaries(strategies.text(), children))
+
+@given(jsondata)
+def test_roundtrip(d):
+assert json.loads(json.dumps(d)) == d
diff --git a/pypy/doc/build.rst b/pypy/doc/build.rst
--- a/pypy/doc/build.rst
+++ b/pypy/doc/build.rst
@@ -149,7 +149,7 @@
 xz-devel # For lzma on PyPy3.
 (XXX plus the SLES11 version of libgdbm-dev and tk-dev)
 
-On Mac OS X::
+On Mac OS X:
 
 Most of these build-time dependencies are installed alongside
 the Developer Tools. However, note that in order for the installation to
diff --git a/pypy/doc/cpython_differences.rst b/pypy/doc/cpython_differences.rst
--- a/pypy/doc/cpython_differences.rst
+++ b/pypy/doc/cpython_differences.rst
@@ -362,7 +362,11 @@
 containers (as list items or in sets for example), the exact rule of
 equality used is "``if x is y or x == y``" (on both CPython and PyPy);
 as a consequence, because all ``nans`` are identical in PyPy, you
-cannot have several of them in a set, unlike in CPython.  (Issue `#1974`__)
+cannot have several of them in a set, unlike in CPython.  (Issue `#1974`__).
+Another consequence is that ``cmp(float('nan'), float('nan')) == 0``, because
+``cmp`` checks with ``is`` first whether the arguments are identical (there is
+no good value to return from this call to ``cmp``, because ``cmp`` pretends
+that there is a total order on floats, but that is wrong for NaNs).
 
 .. __: 
https://bitbucket.org/pypy/pypy/issue/1974/different-behaviour-for-collections-of
 
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
@@ -1,31 +1,41 @@
-===
-What's new in PyPy2.7 5.10+
-===
-
-.. this is a revision shortly after release-pypy2.7-v5.9.0
-.. startrev:d56dadcef996
-
-.. branch: cppyy-packaging
-Cleanup and improve cppyy packaging
-
-.. branch: docs-osx-brew-openssl
-
-.. branch: keep-debug-symbols
-Add a smartstrip tool, which can optionally keep the debug symbols in a
-separate file, instead of just stripping them away. Use it in packaging
-
-.. branch: bsd-patches
-Fix failures on FreeBSD, contributed by David Naylor as patches on the issue
-tracker (issues 2694, 2695, 2696, 2697)
-
-.. branch: run-extra-tests
-Run extra_tests/ in buildbot
-
-.. branch: vmprof-0.4.10
-Upgrade the _vmprof backend to vmprof 0.4.10
-
-.. branch: fix-vmprof-stacklet-switch
-Fix a vmprof+continulets (i.e. greenelts, eventlet, gevent, ...)
-
-.. branch: win32-vcvars
-
+===
+What's new in PyPy2.7 5.10+
+===
+
+.. this is a revision shortly after release-pypy2.7-v5.9.0
+.. startrev:d56dadcef996
+
+
+.. branch: cppyy-packaging
+
+Cleanup and improve cppyy packaging
+
+.. branch: docs-osx-brew-openssl
+
+.. branch: keep-debug-symbols
+
+Add a smartstrip tool, which can optionally keep the debug symbols in a
+separate file, instead of just stripping them away. Use it in packaging
+
+.. branch: bsd-patches
+
+Fix failures on FreeBSD, contributed by David Naylor as patches on the issue

[pypy-commit] pypy py3.5: hg merge default

2017-12-05 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r93278:e7bcb8094e51
Date: 2017-12-05 22:02 +
http://bitbucket.org/pypy/pypy/changeset/e7bcb8094e51/

Log:hg merge default

diff --git a/lib_pypy/resource.py b/lib_pypy/resource.py
--- a/lib_pypy/resource.py
+++ b/lib_pypy/resource.py
@@ -20,6 +20,7 @@
 or via the attributes ru_utime, ru_stime, ru_maxrss, and so on."""
 
 __metaclass__ = _structseq.structseqtype
+name = "resource.struct_rusage"
 
 ru_utime = _structseq.structseqfield(0,"user time used")
 ru_stime = _structseq.structseqfield(1,"system time used")
diff --git a/pypy/module/cpyext/test/test_codecs.py 
b/pypy/module/cpyext/test/test_codecs.py
--- a/pypy/module/cpyext/test/test_codecs.py
+++ b/pypy/module/cpyext/test/test_codecs.py
@@ -11,5 +11,5 @@
 w_encoded = space.call_method(w_encoder, 'encode', 
space.wrap(u'spm'))
 w_decoder = PyCodec_IncrementalDecoder(space, utf8, None)
 w_decoded = space.call_method(w_decoder, 'decode', w_encoded)
-assert space.unwrap(w_decoded) == u'spm'
+assert space.unicode_w(w_decoded) == u'spm'
 rffi.free_charp(utf8)
diff --git a/pypy/module/cpyext/test/test_eval.py 
b/pypy/module/cpyext/test/test_eval.py
--- a/pypy/module/cpyext/test/test_eval.py
+++ b/pypy/module/cpyext/test/test_eval.py
@@ -131,7 +131,7 @@
 finally:
 rffi.free_charp(buf)
 w_a = space.getitem(w_globals, space.wrap("a"))
-assert space.unwrap(w_a) == u'caf\xe9'
+assert space.unicode_w(w_a) == u'caf\xe9'
 lltype.free(flags, flavor='raw')
 
 def test_run_file(self, space):
diff --git a/pypy/module/cpyext/test/test_object.py 
b/pypy/module/cpyext/test/test_object.py
--- a/pypy/module/cpyext/test/test_object.py
+++ b/pypy/module/cpyext/test/test_object.py
@@ -8,7 +8,7 @@
 from pypy.module.cpyext.object import (
 PyObject_IsTrue, PyObject_Not, PyObject_GetAttrString,
 PyObject_DelAttrString, PyObject_GetAttr, PyObject_DelAttr,
-PyObject_GetItem, 
+PyObject_GetItem,
 PyObject_IsInstance, PyObject_IsSubclass, PyObject_AsFileDescriptor,
 PyObject_Hash)
 
@@ -570,7 +570,7 @@
 PyObject *a = PyTuple_GetItem(args, 0);
 PyObject *b = PyTuple_GetItem(args, 1);
 int res = PyObject_RichCompareBool(a, b, Py_EQ);
-return PyLong_FromLong(res);  
+return PyLong_FromLong(res);
 """),])
 a = float('nan')
 b = float('nan')
diff --git a/pypy/module/cpyext/test/test_unicodeobject.py 
b/pypy/module/cpyext/test/test_unicodeobject.py
--- a/pypy/module/cpyext/test/test_unicodeobject.py
+++ b/pypy/module/cpyext/test/test_unicodeobject.py
@@ -372,7 +372,7 @@
 word = space.wrap(u'spam')
 array = rffi.cast(rffi.CWCHARP, PyUnicode_AsUnicode(space, word))
 array2 = PyUnicode_AsUnicode(space, word)
-for (i, char) in enumerate(space.unwrap(word)):
+for (i, char) in enumerate(space.unicode_w(word)):
 assert array[i] == char
 assert array2[i] == char
 with raises_w(space, TypeError):
@@ -409,12 +409,12 @@
 def test_fromstring(self, space):
 s = rffi.str2charp(u'sp\x09m'.encode("utf-8"))
 w_res = PyUnicode_FromString(space, s)
-assert space.unwrap(w_res) == u'sp\x09m'
+assert space.unicode_w(w_res) == u'sp\x09m'
 
 res = PyUnicode_FromStringAndSize(space, s, 4)
 w_res = from_ref(space, res)
 Py_DecRef(space, res)
-assert space.unwrap(w_res) == u'sp\x09m'
+assert space.unicode_w(w_res) == u'sp\x09m'
 rffi.free_charp(s)
 
 def test_internfromstring(self, space):
@@ -457,17 +457,17 @@
 u = rffi.str2charp(u'sp\x134m'.encode("utf-8"))
 w_u = PyUnicode_DecodeUTF8(space, u, 5, None)
 assert space.type(w_u) is space.w_unicode
-assert space.unwrap(w_u) == u'sp\x134m'
+assert space.unicode_w(w_u) == u'sp\x134m'
 
 w_u = PyUnicode_DecodeUTF8(space, u, 2, None)
 assert space.type(w_u) is space.w_unicode
-assert space.unwrap(w_u) == 'sp'
+assert space.unicode_w(w_u) == 'sp'
 rffi.free_charp(u)
 
 def test_encode_utf8(self, space):
 u = rffi.unicode2wcharp(u'sp\x09m')
 w_s = PyUnicode_EncodeUTF8(space, u, 4, None)
-assert space.unwrap(w_s) == u'sp\x09m'.encode('utf-8')
+assert space.unicode_w(w_s) == u'sp\x09m'.encode('utf-8')
 rffi.free_wcharp(u)
 
 def test_encode_decimal(self, space):
@@ -631,12 +631,12 @@
 def test_decode(self, space):
 b_text = rffi.str2charp('caf\x82xx')
 b_encoding = rffi.str2charp('cp437')
-assert space.unwrap(
+assert space.unicode_w(
 PyUnicode_Decode(space, b_text, 4, b_encoding, None)) == u'caf\xe9'
 
 w_text = PyUnicode_FromEncodedObject(space, space.newbytes("test"), 
b_encoding, None)
 

[pypy-commit] pypy py3.5: hg merge default

2017-11-30 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r93230:c932756506d4
Date: 2017-12-01 02:26 +
http://bitbucket.org/pypy/pypy/changeset/c932756506d4/

Log:hg merge default

diff --git a/rpython/jit/metainterp/optimizeopt/intutils.py 
b/rpython/jit/metainterp/optimizeopt/intutils.py
--- a/rpython/jit/metainterp/optimizeopt/intutils.py
+++ b/rpython/jit/metainterp/optimizeopt/intutils.py
@@ -273,7 +273,8 @@
 return r
 
 def contains(self, val):
-assert not isinstance(val, long)
+if not we_are_translated():
+assert not isinstance(val, long)
 if not isinstance(val, int):
 if ((not self.has_lower or self.lower == MININT) and
 not self.has_upper or self.upper == MAXINT):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-11-29 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r93216:fcf5d3fb56f4
Date: 2017-11-29 18:34 +
http://bitbucket.org/pypy/pypy/changeset/fcf5d3fb56f4/

Log:hg merge default

diff --git a/extra_tests/test_textio.py b/extra_tests/test_textio.py
--- a/extra_tests/test_textio.py
+++ b/extra_tests/test_textio.py
@@ -1,28 +1,48 @@
 from hypothesis import given, strategies as st
 
 from io import BytesIO, TextIOWrapper
+import os
 
-LINESEP = ['', '\r', '\n', '\r\n']
+def translate_newlines(text):
+text = text.replace('\r\n', '\n')
+text = text.replace('\r', '\n')
+return text.replace('\n', os.linesep)
 
 @st.composite
-def text_with_newlines(draw):
-sep = draw(st.sampled_from(LINESEP))
-lines = draw(st.lists(st.text(max_size=10), max_size=10))
-return sep.join(lines)
+def st_readline_universal(
+draw, st_nlines=st.integers(min_value=0, max_value=10)):
+n_lines = draw(st_nlines)
+lines = draw(st.lists(
+st.text(st.characters(blacklist_characters='\r\n')),
+min_size=n_lines, max_size=n_lines))
+limits = []
+for line in lines:
+limit = draw(st.integers(min_value=0, max_value=len(line) + 5))
+limits.append(limit)
+limits.append(-1)
+endings = draw(st.lists(
+st.sampled_from(['\n', '\r', '\r\n']),
+min_size=n_lines, max_size=n_lines))
+return (
+''.join(line + ending for line, ending in zip(lines, endings)),
+limits)
 
-@given(txt=text_with_newlines(),
-   mode=st.sampled_from(['\r', '\n', '\r\n', '']),
-   limit=st.integers(min_value=-1))
-def test_readline(txt, mode, limit):
+@given(data=st_readline_universal(),
+   mode=st.sampled_from(['\r', '\n', '\r\n', '', None]))
+def test_readline(data, mode):
+txt, limits = data
 textio = TextIOWrapper(
-BytesIO(txt.encode('utf-8')), encoding='utf-8', newline=mode)
+BytesIO(txt.encode('utf-8', 'surrogatepass')),
+encoding='utf-8', errors='surrogatepass', newline=mode)
 lines = []
-while True:
+for limit in limits:
 line = textio.readline(limit)
-if limit > 0:
-assert len(line) < limit
+if limit >= 0:
+assert len(line) <= limit
 if line:
 lines.append(line)
-else:
+elif limit:
 break
-assert u''.join(lines) == txt
+if mode is None:
+txt = translate_newlines(txt)
+assert txt.startswith(u''.join(lines))
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
@@ -26,3 +26,6 @@
 
 .. branch: fix-vmprof-stacklet-switch
 Fix a vmprof+continulets (i.e. greenelts, eventlet, gevent, ...)
+
+.. branch: win32-vcvars
+
diff --git a/pypy/doc/windows.rst b/pypy/doc/windows.rst
--- a/pypy/doc/windows.rst
+++ b/pypy/doc/windows.rst
@@ -25,8 +25,10 @@
 
 This compiler, while the standard one for Python 2.7, is deprecated. Microsoft 
has
 made it available as the `Microsoft Visual C++ Compiler for Python 2.7`_ (the 
link
-was checked in Nov 2016). Note that the compiler suite will be installed in
-``C:\Users\\AppData\Local\Programs\Common\Microsoft\Visual C++ for 
Python``.
+was checked in Nov 2016). Note that the compiler suite may be installed in
+``C:\Users\\AppData\Local\Programs\Common\Microsoft\Visual C++ for 
Python``
+or in
+``C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python``.
 A current version of ``setuptools`` will be able to find it there. For
 Windows 10, you must right-click the download, and under ``Properties`` ->
 ``Compatibility`` mark it as ``Run run this program in comatibility mode for``
@@ -41,7 +43,6 @@
 ---
 
 We routinely test translation using v9, also known as Visual Studio 2008.
-Our buildbot is still using the Express Edition, not the compiler noted above.
 Other configurations may work as well.
 
 The translation scripts will set up the appropriate environment variables
@@ -81,6 +82,30 @@
 
 .. _build instructions: http://pypy.org/download.html#building-from-source
 
+Setting Up Visual Studio for building SSL in Python3
+
+
+On Python3, the ``ssl`` module is based on ``cffi``, and requires a build step 
after
+translation. However ``distutils`` does not support the Micorosft-provided 
Visual C
+compiler, and ``cffi`` depends on ``distutils`` to find the compiler. The
+traditional solution to this problem is to install the ``setuptools`` module
+via running ``-m ensurepip`` which installs ``pip`` and ``setuptools``. However
+``pip`` requires ``ssl``. So we have a chicken-and-egg problem: ``ssl`` 
depends on
+``cffi`` which depends on ``setuptools``, which depends on ``ensurepip``, which
+depends on ``ssl``.
+
+In order to solve this, the buildbot sets an environment varaible that helps
+``distutils`` find the compiler without ``setuptools``::
+
+ set 

[pypy-commit] pypy py3.5: hg merge default

2017-11-25 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r93183:8125ba2d1fc1
Date: 2017-11-26 03:02 +
http://bitbucket.org/pypy/pypy/changeset/8125ba2d1fc1/

Log:hg merge default

diff --git a/extra_tests/test_textio.py b/extra_tests/test_textio.py
new file mode 100644
--- /dev/null
+++ b/extra_tests/test_textio.py
@@ -0,0 +1,28 @@
+from hypothesis import given, strategies as st
+
+from io import BytesIO, TextIOWrapper
+
+LINESEP = ['', '\r', '\n', '\r\n']
+
+@st.composite
+def text_with_newlines(draw):
+sep = draw(st.sampled_from(LINESEP))
+lines = draw(st.lists(st.text(max_size=10), max_size=10))
+return sep.join(lines)
+
+@given(txt=text_with_newlines(),
+   mode=st.sampled_from(['\r', '\n', '\r\n', '']),
+   limit=st.integers(min_value=-1))
+def test_readline(txt, mode, limit):
+textio = TextIOWrapper(
+BytesIO(txt.encode('utf-8')), encoding='utf-8', newline=mode)
+lines = []
+while True:
+line = textio.readline(limit)
+if limit > 0:
+assert len(line) < limit
+if line:
+lines.append(line)
+else:
+break
+assert u''.join(lines) == txt
diff --git a/pypy/module/_io/interp_stringio.py 
b/pypy/module/_io/interp_stringio.py
--- a/pypy/module/_io/interp_stringio.py
+++ b/pypy/module/_io/interp_stringio.py
@@ -2,21 +2,115 @@
 from pypy.interpreter.typedef import (
 TypeDef, generic_new_descr, GetSetProperty)
 from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
-from pypy.module._io.interp_textio import W_TextIOBase, 
W_IncrementalNewlineDecoder
+from pypy.module._io.interp_textio import (
+W_TextIOBase, W_IncrementalNewlineDecoder)
 from pypy.module._io.interp_iobase import convert_size
 
+class UnicodeIO(object):
+def __init__(self, data=None, pos=0):
+if data is None:
+data = []
+self.data = data
+self.pos = pos
+
+def resize(self, newlength):
+if len(self.data) > newlength:
+self.data = self.data[:newlength]
+if len(self.data) < newlength:
+self.data.extend([u'\0'] * (newlength - len(self.data)))
+
+def read(self, size):
+start = self.pos
+available = len(self.data) - start
+if available <= 0:
+return u''
+if size >= 0 and size <= available:
+end = start + size
+else:
+end = len(self.data)
+assert 0 <= start <= end
+self.pos = end
+return u''.join(self.data[start:end])
+
+def _convert_limit(self, limit):
+if limit < 0 or limit > len(self.data) - self.pos:
+limit = len(self.data) - self.pos
+assert limit >= 0
+return limit
+
+def readline_universal(self, limit):
+# Universal newline search. Find any of \r, \r\n, \n
+limit = self._convert_limit(limit)
+start = self.pos
+end = start + limit
+pos = start
+while pos < end:
+ch = self.data[pos]
+pos += 1
+if ch == '\n':
+break
+if ch == '\r':
+if pos >= end:
+break
+if self.data[pos] == '\n':
+pos += 1
+break
+else:
+break
+self.pos = pos
+result = u''.join(self.data[start:pos])
+return result
+
+def readline(self, marker, limit):
+start = self.pos
+limit = self._convert_limit(limit)
+end = start + limit
+found = False
+for pos in range(start, end - len(marker) + 1):
+ch = self.data[pos]
+if ch == marker[0]:
+for j in range(1, len(marker)):
+if self.data[pos + j] != marker[j]:
+break  # from inner loop
+else:
+pos += len(marker)
+found = True
+break
+if not found:
+pos = end
+self.pos = pos
+result = u''.join(self.data[start:pos])
+return result
+
+def write(self, string):
+length = len(string)
+if self.pos + length > len(self.data):
+self.resize(self.pos + length)
+
+for i in range(length):
+self.data[self.pos + i] = string[i]
+self.pos += length
+
+def seek(self, pos):
+self.pos = pos
+
+def truncate(self, size):
+if size < len(self.data):
+self.resize(size)
+
+def getvalue(self):
+return u''.join(self.data)
+
 
 class W_StringIO(W_TextIOBase):
 def __init__(self, space):
 W_TextIOBase.__init__(self, space)
-self.buf = []
-self.pos = 0
+self.buf = UnicodeIO()
 
 @unwrap_spec(w_newline = WrappedDefault(u"\n"))
 def descr_init(self, space, w_initvalue=None, w_newline=None):
 # In case __init__ is called multiple 

[pypy-commit] pypy py3.5: hg merge default

2017-11-20 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r93107:3e868c28555c
Date: 2017-11-21 01:59 +
http://bitbucket.org/pypy/pypy/changeset/3e868c28555c/

Log:hg merge default

diff --git a/lib-python/2.7/test/test_urllib2net.py 
b/lib-python/2.7/test/test_urllib2net.py
--- a/lib-python/2.7/test/test_urllib2net.py
+++ b/lib-python/2.7/test/test_urllib2net.py
@@ -286,7 +286,7 @@
 self.assertEqual(u.fp._sock.fp._sock.gettimeout(), 120)
 u.close()
 
-FTP_HOST = 'ftp://ftp.debian.org/debian/'
+FTP_HOST = 'ftp://www.pythontest.net/'
 
 def test_ftp_basic(self):
 self.assertIsNone(socket.getdefaulttimeout())
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
@@ -20,3 +20,9 @@
 
 .. branch: run-extra-tests
 Run extra_tests/ in buildbot
+
+.. branch: vmprof-0.4.10
+Upgrade the _vmprof backend to vmprof 0.4.10
+
+.. branch: fix-vmprof-stacklet-switch
+Fix a vmprof+continulets (i.e. greenelts, eventlet, gevent, ...)
diff --git a/pypy/module/_continuation/test/test_stacklet.py 
b/pypy/module/_continuation/test/test_stacklet.py
--- a/pypy/module/_continuation/test/test_stacklet.py
+++ b/pypy/module/_continuation/test/test_stacklet.py
@@ -8,6 +8,35 @@
 cls.w_translated = cls.space.wrap(
 os.path.join(os.path.dirname(__file__),
  'test_translated.py'))
+cls.w_stack = cls.space.appexec([], """():
+import sys
+def stack(f=None):
+'''
+get the call-stack of the caller or the specified frame
+'''
+if f is None:
+f = sys._getframe(1)
+res = []
+seen = set()
+while f:
+if f in seen:
+# frame cycle
+res.append('...')
+break
+if f.f_code.co_name == 'runtest':
+# if we are running with -A, cut all the stack above
+# the test function
+break
+seen.add(f)
+res.append(f.f_code.co_name)
+f = f.f_back
+#print res
+return res
+return stack
+   """)
+if cls.runappdirect:
+# make sure that "self.stack" does not pass the self
+cls.w_stack = staticmethod(cls.w_stack.im_func)
 
 def test_new_empty(self):
 from _continuation import continulet
@@ -339,17 +368,24 @@
 def test_f_back(self):
 import sys
 from _continuation import continulet
+stack = self.stack
 #
 def bar(c):
+assert stack() == ['bar', 'foo', 'test_f_back']
 c.switch(sys._getframe(0))
 c.switch(sys._getframe(0).f_back)
 c.switch(sys._getframe(1))
+#
+assert stack() == ['bar', 'foo', 'main', 'test_f_back']
 c.switch(sys._getframe(1).f_back)
+#
+assert stack() == ['bar', 'foo', 'main2', 'test_f_back']
 assert sys._getframe(2) is f3_foo.f_back
 c.switch(sys._getframe(2))
 def foo(c):
 bar(c)
 #
+assert stack() == ['test_f_back']
 c = continulet(foo)
 f1_bar = c.switch()
 assert f1_bar.f_code.co_name == 'bar'
@@ -358,14 +394,20 @@
 f3_foo = c.switch()
 assert f3_foo is f2_foo
 assert f1_bar.f_back is f3_foo
+#
 def main():
 f4_main = c.switch()
 assert f4_main.f_code.co_name == 'main'
 assert f3_foo.f_back is f1_bar# not running, so a loop
+assert stack() == ['main', 'test_f_back']
+assert stack(f1_bar) == ['bar', 'foo', '...']
+#
 def main2():
 f5_main2 = c.switch()
 assert f5_main2.f_code.co_name == 'main2'
 assert f3_foo.f_back is f1_bar# not running, so a loop
+assert stack(f1_bar) == ['bar', 'foo', '...']
+#
 main()
 main2()
 res = c.switch()
diff --git a/pypy/module/_continuation/test/test_translated.py 
b/pypy/module/_continuation/test/test_translated.py
--- a/pypy/module/_continuation/test/test_translated.py
+++ b/pypy/module/_continuation/test/test_translated.py
@@ -5,6 +5,7 @@
 py.test.skip("to run on top of a translated pypy-c")
 
 import sys, random
+from rpython.tool.udir import udir
 
 # 
 
@@ -92,6 +93,33 @@
 from pypy.conftest import option
 if not option.runappdirect:
 py.test.skip("meant only for -A run")
+cls.w_vmprof_file = cls.space.wrap(str(udir.join('profile.vmprof')))
+
+def test_vmprof(self):
+"""
+The point of this test is to 

[pypy-commit] pypy py3.5: hg merge default

2017-11-13 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r93006:19326fb34a67
Date: 2017-11-13 21:07 +
http://bitbucket.org/pypy/pypy/changeset/19326fb34a67/

Log:hg merge default

diff --git a/extra_tests/test_bytes.py b/extra_tests/test_bytes.py
--- a/extra_tests/test_bytes.py
+++ b/extra_tests/test_bytes.py
@@ -1,25 +1,27 @@
 from hypothesis import strategies as st
 from hypothesis import given, example
 
-@given(st.binary(), st.binary(), st.binary())
+st_bytestring = st.binary() | st.binary().map(bytearray)
+
+@given(st_bytestring, st_bytestring, st_bytestring)
 def test_find(u, prefix, suffix):
 s = prefix + u + suffix
 assert 0 <= s.find(u) <= len(prefix)
 assert s.find(u, len(prefix), len(s) - len(suffix)) == len(prefix)
 
-@given(st.binary(), st.binary(), st.binary())
+@given(st_bytestring, st_bytestring, st_bytestring)
 def test_index(u, prefix, suffix):
 s = prefix + u + suffix
 assert 0 <= s.index(u) <= len(prefix)
 assert s.index(u, len(prefix), len(s) - len(suffix)) == len(prefix)
 
-@given(st.binary(), st.binary(), st.binary())
+@given(st_bytestring, st_bytestring, st_bytestring)
 def test_rfind(u, prefix, suffix):
 s = prefix + u + suffix
 assert s.rfind(u) >= len(prefix)
 assert s.rfind(u, len(prefix), len(s) - len(suffix)) == len(prefix)
 
-@given(st.binary(), st.binary(), st.binary())
+@given(st_bytestring, st_bytestring, st_bytestring)
 def test_rindex(u, prefix, suffix):
 s = prefix + u + suffix
 assert s.rindex(u) >= len(prefix)
@@ -34,20 +36,20 @@
 start = max(start + len(u), 0)
 return start, end
 
-@given(st.binary(), st.binary())
+@given(st_bytestring, st_bytestring)
 def test_startswith_basic(u, v):
 assert u.startswith(v) is (u[:len(v)] == v)
 
 @example(b'x', b'', 1)
 @example(b'x', b'', 2)
-@given(st.binary(), st.binary(), st.integers())
+@given(st_bytestring, st_bytestring, st.integers())
 def test_startswith_start(u, v, start):
 expected = u[start:].startswith(v) if v else (start <= len(u))
 assert u.startswith(v, start) is expected
 
 @example(b'x', b'', 1, 0)
 @example(b'xx', b'', -1, 0)
-@given(st.binary(), st.binary(), st.integers(), st.integers())
+@given(st_bytestring, st_bytestring, st.integers(), st.integers())
 def test_startswith_3(u, v, start, end):
 if v:
 expected = u[start:end].startswith(v)
@@ -56,7 +58,7 @@
 expected = start0 <= len(u) and start0 <= end0
 assert u.startswith(v, start, end) is expected
 
-@given(st.binary(), st.binary())
+@given(st_bytestring, st_bytestring)
 def test_endswith_basic(u, v):
 if len(v) > len(u):
 assert u.endswith(v) is False
@@ -65,14 +67,14 @@
 
 @example(b'x', b'', 1)
 @example(b'x', b'', 2)
-@given(st.binary(), st.binary(), st.integers())
+@given(st_bytestring, st_bytestring, st.integers())
 def test_endswith_2(u, v, start):
 expected = u[start:].endswith(v) if v else (start <= len(u))
 assert u.endswith(v, start) is expected
 
 @example(b'x', b'', 1, 0)
 @example(b'xx', b'', -1, 0)
-@given(st.binary(), st.binary(), st.integers(), st.integers())
+@given(st_bytestring, st_bytestring, st.integers(), st.integers())
 def test_endswith_3(u, v, start, end):
 if v:
 expected = u[start:end].endswith(v)
diff --git a/lib-python/2.7/inspect.py b/lib-python/2.7/inspect.py
--- a/lib-python/2.7/inspect.py
+++ b/lib-python/2.7/inspect.py
@@ -40,6 +40,10 @@
 import linecache
 from operator import attrgetter
 from collections import namedtuple
+try:
+from cpyext import is_cpyext_function as _is_cpyext_function
+except ImportError:
+_is_cpyext_function = lambda obj: False
 
 # These constants are from Include/code.h.
 CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS = 0x1, 0x2, 0x4, 0x8
@@ -230,7 +234,7 @@
 __doc__ documentation string
 __name__original name of this function or method
 __self__instance to which a method is bound, or None"""
-return isinstance(object, types.BuiltinFunctionType)
+return isinstance(object, types.BuiltinFunctionType) or 
_is_cpyext_function(object)
 
 def isroutine(object):
 """Return true if the object is any kind of function or method."""
diff --git a/lib-python/2.7/warnings.py b/lib-python/2.7/warnings.py
--- a/lib-python/2.7/warnings.py
+++ b/lib-python/2.7/warnings.py
@@ -43,11 +43,12 @@
 unicodetype = unicode
 except NameError:
 unicodetype = ()
+template = "%s: %s: %s\n"
 try:
 message = str(message)
 except UnicodeEncodeError:
-pass
-s =  "%s: %s: %s\n" % (lineno, category.__name__, message)
+template = unicode(template)
+s = template % (lineno, category.__name__, message)
 line = linecache.getline(filename, lineno) if line is None else line
 if line:
 line = line.strip()
diff --git a/pypy/interpreter/pyparser/future.py 
b/pypy/interpreter/pyparser/future.py
--- a/pypy/interpreter/pyparser/future.py
+++ 

[pypy-commit] pypy py3.5: hg merge default

2017-11-06 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92956:ed4ba7032f9d
Date: 2017-11-06 16:53 +
http://bitbucket.org/pypy/pypy/changeset/ed4ba7032f9d/

Log:hg merge default

diff --git a/lib_pypy/_tkinter/app.py b/lib_pypy/_tkinter/app.py
--- a/lib_pypy/_tkinter/app.py
+++ b/lib_pypy/_tkinter/app.py
@@ -185,6 +185,9 @@
 if err == tklib.TCL_ERROR:
 self.raiseTclError()
 
+def interpaddr(self):
+return int(tkffi.cast('size_t', self.interp))
+
 def _var_invoke(self, func, *args, **kwargs):
 if self.threaded and self.thread_id != tklib.Tcl_GetCurrentThread():
 # The current thread is not the interpreter thread.
diff --git a/rpython/jit/metainterp/test/test_del.py 
b/rpython/jit/metainterp/test/test_del.py
--- a/rpython/jit/metainterp/test/test_del.py
+++ b/rpython/jit/metainterp/test/test_del.py
@@ -82,46 +82,5 @@
 assert res == 1
 self.check_resops(call_r=1)   # for the case B(), but not for the case 
A()
 
-def test_keepalive(self):
-py.test.skip("XXX fails")   # hum, I think the test itself is broken
-#
-mydriver = JitDriver(reds = ['n', 'states'], greens = [])
-class State:
-num = 1
-class X:
-def __init__(self, state):
-self.state = state
-def __del__(self):
-self.state.num += 1
-@dont_look_inside
-def do_stuff():
-pass
-def f(n):
-states = []
-while n > 0:
-mydriver.jit_merge_point(n=n, states=states)
-state = State()
-states.append(state)
-x = X(state)
-do_stuff()
-state.num *= 1000
-do_stuff()
-keepalive_until_here(x)
-n -= 1
-return states
-def main(n):
-states = f(n)
-rgc.collect()
-rgc.collect()
-err = 1001
-for state in states:
-if state.num != 1001:
-err = state.num
-print 'ERROR:', err
-return err
-assert main(20) == 1001
-res = self.meta_interp(main, [20])
-assert res == 1001
-
 class TestLLtype(DelTests, LLJitMixin):
 pass
diff --git a/testrunner/get_info.py b/testrunner/get_info.py
new file mode 100644
--- /dev/null
+++ b/testrunner/get_info.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+"""
+Dump some translation information to stdout as JSON. Used by buildbot.
+"""
+
+import sys
+import os
+import json
+
+BASE_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
+TARGET_BASENAME = 'pypy-c'
+
+def make_info_dict():
+target = TARGET_BASENAME
+if sys.platform.startswith('win'):
+target += '.exe'
+target_path = os.path.join(BASE_DIR, 'pypy', 'goal', target)
+return {'target_path': target_path}
+
+def dump_info():
+return json.dumps(make_info_dict())
+
+if __name__ == '__main__':
+print dump_info()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-11-04 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92931:a433b30d93a4
Date: 2017-11-04 21:06 +
http://bitbucket.org/pypy/pypy/changeset/a433b30d93a4/

Log:hg merge default

diff --git a/extra_tests/requirements.txt b/extra_tests/requirements.txt
new file mode 100644
--- /dev/null
+++ b/extra_tests/requirements.txt
@@ -0,0 +1,2 @@
+pytest
+hypothesis
diff --git a/extra_tests/test_bytes.py b/extra_tests/test_bytes.py
new file mode 100644
--- /dev/null
+++ b/extra_tests/test_bytes.py
@@ -0,0 +1,82 @@
+from hypothesis import strategies as st
+from hypothesis import given, example
+
+@given(st.binary(), st.binary(), st.binary())
+def test_find(u, prefix, suffix):
+s = prefix + u + suffix
+assert 0 <= s.find(u) <= len(prefix)
+assert s.find(u, len(prefix), len(s) - len(suffix)) == len(prefix)
+
+@given(st.binary(), st.binary(), st.binary())
+def test_index(u, prefix, suffix):
+s = prefix + u + suffix
+assert 0 <= s.index(u) <= len(prefix)
+assert s.index(u, len(prefix), len(s) - len(suffix)) == len(prefix)
+
+@given(st.binary(), st.binary(), st.binary())
+def test_rfind(u, prefix, suffix):
+s = prefix + u + suffix
+assert s.rfind(u) >= len(prefix)
+assert s.rfind(u, len(prefix), len(s) - len(suffix)) == len(prefix)
+
+@given(st.binary(), st.binary(), st.binary())
+def test_rindex(u, prefix, suffix):
+s = prefix + u + suffix
+assert s.rindex(u) >= len(prefix)
+assert s.rindex(u, len(prefix), len(s) - len(suffix)) == len(prefix)
+
+def adjust_indices(u, start, end):
+if end < 0:
+end = max(end + len(u), 0)
+else:
+end = min(end, len(u))
+if start < 0:
+start = max(start + len(u), 0)
+return start, end
+
+@given(st.binary(), st.binary())
+def test_startswith_basic(u, v):
+assert u.startswith(v) is (u[:len(v)] == v)
+
+@example(b'x', b'', 1)
+@example(b'x', b'', 2)
+@given(st.binary(), st.binary(), st.integers())
+def test_startswith_start(u, v, start):
+expected = u[start:].startswith(v) if v else (start <= len(u))
+assert u.startswith(v, start) is expected
+
+@example(b'x', b'', 1, 0)
+@example(b'xx', b'', -1, 0)
+@given(st.binary(), st.binary(), st.integers(), st.integers())
+def test_startswith_3(u, v, start, end):
+if v:
+expected = u[start:end].startswith(v)
+else:  # CPython leaks implementation details in this case
+start0, end0 = adjust_indices(u, start, end)
+expected = start0 <= len(u) and start0 <= end0
+assert u.startswith(v, start, end) is expected
+
+@given(st.binary(), st.binary())
+def test_endswith_basic(u, v):
+if len(v) > len(u):
+assert u.endswith(v) is False
+else:
+assert u.endswith(v) is (u[len(u) - len(v):] == v)
+
+@example(b'x', b'', 1)
+@example(b'x', b'', 2)
+@given(st.binary(), st.binary(), st.integers())
+def test_endswith_2(u, v, start):
+expected = u[start:].endswith(v) if v else (start <= len(u))
+assert u.endswith(v, start) is expected
+
+@example(b'x', b'', 1, 0)
+@example(b'xx', b'', -1, 0)
+@given(st.binary(), st.binary(), st.integers(), st.integers())
+def test_endswith_3(u, v, start, end):
+if v:
+expected = u[start:end].endswith(v)
+else:  # CPython leaks implementation details in this case
+start0, end0 = adjust_indices(u, start, end)
+expected = start0 <= len(u) and start0 <= end0
+assert u.endswith(v, start, end) is expected
diff --git a/extra_tests/test_unicode.py b/extra_tests/test_unicode.py
--- a/extra_tests/test_unicode.py
+++ b/extra_tests/test_unicode.py
@@ -1,3 +1,4 @@
+import sys
 import pytest
 from hypothesis import strategies as st
 from hypothesis import given, settings, example
@@ -32,3 +33,89 @@
 @given(s=st.text())
 def test_composition(s, norm1, norm2, norm3):
 assert normalize(norm2, normalize(norm1, s)) == normalize(norm3, s)
+
+@given(st.text(), st.text(), st.text())
+def test_find(u, prefix, suffix):
+s = prefix + u + suffix
+assert 0 <= s.find(u) <= len(prefix)
+assert s.find(u, len(prefix), len(s) - len(suffix)) == len(prefix)
+
+@given(st.text(), st.text(), st.text())
+def test_index(u, prefix, suffix):
+s = prefix + u + suffix
+assert 0 <= s.index(u) <= len(prefix)
+assert s.index(u, len(prefix), len(s) - len(suffix)) == len(prefix)
+
+@given(st.text(), st.text(), st.text())
+def test_rfind(u, prefix, suffix):
+s = prefix + u + suffix
+assert s.rfind(u) >= len(prefix)
+assert s.rfind(u, len(prefix), len(s) - len(suffix)) == len(prefix)
+
+@given(st.text(), st.text(), st.text())
+def test_rindex(u, prefix, suffix):
+s = prefix + u + suffix
+assert s.rindex(u) >= len(prefix)
+assert s.rindex(u, len(prefix), len(s) - len(suffix)) == len(prefix)
+
+def adjust_indices(u, start, end):
+if end < 0:
+end = max(end + len(u), 0)
+else:
+end = min(end, len(u))
+if start < 0:
+start = max(start + len(u), 0)
+return start, end
+

[pypy-commit] pypy py3.5: hg merge default

2017-10-24 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92842:1c9a8dfaca36
Date: 2017-10-25 04:05 +0100
http://bitbucket.org/pypy/pypy/changeset/1c9a8dfaca36/

Log:hg merge default

diff --git a/lib_pypy/_ctypes/basics.py b/lib_pypy/_ctypes/basics.py
--- a/lib_pypy/_ctypes/basics.py
+++ b/lib_pypy/_ctypes/basics.py
@@ -165,6 +165,10 @@
 def _get_buffer_value(self):
 return self._buffer[0]
 
+def _copy_to(self, addr):
+target = type(self).from_address(addr)._buffer
+target[0] = self._get_buffer_value()
+
 def _to_ffi_param(self):
 if self.__class__._is_pointer_like():
 return self._get_buffer_value()
diff --git a/lib_pypy/_ctypes/pointer.py b/lib_pypy/_ctypes/pointer.py
--- a/lib_pypy/_ctypes/pointer.py
+++ b/lib_pypy/_ctypes/pointer.py
@@ -113,7 +113,9 @@
 cobj = self._type_.from_param(value)
 if ensure_objects(cobj) is not None:
 store_reference(self, index, cobj._objects)
-self._subarray(index)[0] = cobj._get_buffer_value()
+address = self._buffer[0]
+address += index * sizeof(self._type_)
+cobj._copy_to(address)
 
 def __bool__(self):
 return self._buffer[0] != 0
diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py
--- a/lib_pypy/_ctypes/structure.py
+++ b/lib_pypy/_ctypes/structure.py
@@ -290,6 +290,11 @@
 def _get_buffer_value(self):
 return self._buffer.buffer
 
+def _copy_to(self, addr):
+from ctypes import memmove
+origin = self._get_buffer_value()
+memmove(addr, origin, self._fficompositesize_)
+
 def _to_ffi_param(self):
 return self._buffer
 
diff --git a/pypy/module/_continuation/test/test_stacklet.py 
b/pypy/module/_continuation/test/test_stacklet.py
--- a/pypy/module/_continuation/test/test_stacklet.py
+++ b/pypy/module/_continuation/test/test_stacklet.py
@@ -290,66 +290,87 @@
 def test_random_switching(self):
 from _continuation import continulet
 #
+seen = []
+#
 def t1(c1):
-return c1.switch()
+seen.append(3)
+res = c1.switch()
+seen.append(6)
+return res
+#
 def s1(c1, n):
+seen.append(2)
 assert n == 123
 c2 = t1(c1)
-return c1.switch('a') + 1
+seen.append(7)
+res = c1.switch('a') + 1
+seen.append(10)
+return res
 #
 def s2(c2, c1):
+seen.append(5)
 res = c1.switch(c2)
+seen.append(8)
 assert res == 'a'
-return c2.switch('b') + 2
+res = c2.switch('b') + 2
+seen.append(12)
+return res
 #
 def f():
+seen.append(1)
 c1 = continulet(s1, 123)
 c2 = continulet(s2, c1)
 c1.switch()
+seen.append(4)
 res = c2.switch()
+seen.append(9)
 assert res == 'b'
 res = c1.switch(1000)
+seen.append(11)
 assert res == 1001
-return c2.switch(2000)
+res = c2.switch(2000)
+seen.append(13)
+return res
 #
 res = f()
 assert res == 2002
+assert seen == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
 
 def test_f_back(self):
 import sys
 from _continuation import continulet
 #
-def g(c):
+def bar(c):
 c.switch(sys._getframe(0))
 c.switch(sys._getframe(0).f_back)
 c.switch(sys._getframe(1))
 c.switch(sys._getframe(1).f_back)
-assert sys._getframe(2) is f3.f_back
+assert sys._getframe(2) is f3_foo.f_back
 c.switch(sys._getframe(2))
-def f(c):
-g(c)
+def foo(c):
+bar(c)
 #
-c = continulet(f)
-f1 = c.switch()
-assert f1.f_code.co_name == 'g'
-f2 = c.switch()
-assert f2.f_code.co_name == 'f'
-f3 = c.switch()
-assert f3 is f2
-assert f1.f_back is f3
+c = continulet(foo)
+f1_bar = c.switch()
+assert f1_bar.f_code.co_name == 'bar'
+f2_foo = c.switch()
+assert f2_foo.f_code.co_name == 'foo'
+f3_foo = c.switch()
+assert f3_foo is f2_foo
+assert f1_bar.f_back is f3_foo
 def main():
-f4 = c.switch()
-assert f4.f_code.co_name == 'main', repr(f4.f_code.co_name)
-assert f3.f_back is f1# not running, so a loop
+f4_main = c.switch()
+assert f4_main.f_code.co_name == 'main'
+assert f3_foo.f_back is f1_bar# not running, so a loop
 def main2():
-f5 = c.switch()
-assert f5.f_code.co_name == 'main2', repr(f5.f_code.co_name)
-assert f3.f_back is f1# 

[pypy-commit] pypy py3.5: hg merge default

2017-10-09 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92691:be539692837f
Date: 2017-10-10 01:30 +0200
http://bitbucket.org/pypy/pypy/changeset/be539692837f/

Log:hg merge default

diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -13,7 +13,7 @@
 ssizessizeargfunc, ssizeobjargproc, iternextfunc, initproc, richcmpfunc,
 cmpfunc, hashfunc, descrgetfunc, descrsetfunc, objobjproc, objobjargproc,
 getbufferproc, ssizessizeobjargproc)
-from pypy.module.cpyext.pyobject import make_ref, decref, from_ref
+from pypy.module.cpyext.pyobject import make_ref, from_ref, as_pyobj
 from pypy.module.cpyext.pyerrors import PyErr_Occurred
 from pypy.module.cpyext.memoryobject import fill_Py_buffer
 from pypy.module.cpyext.state import State
@@ -90,20 +90,21 @@
 args_w = space.fixedview(w_args)
 return generic_cpy_call(space, func_binary, w_self, args_w[0])
 
+def _get_ob_type(space, w_obj):
+# please ensure that w_obj stays alive
+ob_type = as_pyobj(space, space.type(w_obj))
+return rffi.cast(PyTypeObjectPtr, ob_type)
+
 def wrap_binaryfunc_l(space, w_self, w_args, func):
 func_binary = rffi.cast(binaryfunc, func)
 check_num_args(space, w_args, 1)
 args_w = space.fixedview(w_args)
-ref = make_ref(space, w_self)
-decref(space, ref)
 return generic_cpy_call(space, func_binary, w_self, args_w[0])
 
 def wrap_binaryfunc_r(space, w_self, w_args, func):
 func_binary = rffi.cast(binaryfunc, func)
 check_num_args(space, w_args, 1)
 args_w = space.fixedview(w_args)
-ref = make_ref(space, w_self)
-decref(space, ref)
 return generic_cpy_call(space, func_binary, args_w[0], w_self)
 
 def wrap_ternaryfunc(space, w_self, w_args, func):
@@ -121,8 +122,6 @@
 func_ternary = rffi.cast(ternaryfunc, func)
 check_num_argsv(space, w_args, 1, 2)
 args_w = space.fixedview(w_args)
-ref = make_ref(space, w_self)
-decref(space, ref)
 arg3 = space.w_None
 if len(args_w) > 1:
 arg3 = args_w[1]
@@ -314,12 +313,10 @@
 
 def wrap_getreadbuffer(space, w_self, w_args, func):
 func_target = rffi.cast(readbufferproc, func)
-py_obj = make_ref(space, w_self)
-py_type = py_obj.c_ob_type
+py_type = _get_ob_type(space, w_self)
 rbp = rffi.cast(rffi.VOIDP, 0)
 if py_type.c_tp_as_buffer:
 rbp = rffi.cast(rffi.VOIDP, py_type.c_tp_as_buffer.c_bf_releasebuffer)
-decref(space, py_obj)
 with lltype.scoped_alloc(rffi.VOIDPP.TO, 1) as ptr:
 index = rffi.cast(Py_ssize_t, 0)
 size = generic_cpy_call(space, func_target, w_self, index, ptr)
@@ -332,9 +329,7 @@
 
 def wrap_getwritebuffer(space, w_self, w_args, func):
 func_target = rffi.cast(readbufferproc, func)
-py_obj = make_ref(space, w_self)
-py_type = py_obj.c_ob_type
-decref(space, py_obj)
+py_type = _get_ob_type(space, w_self)
 rbp = rffi.cast(rffi.VOIDP, 0)
 if py_type.c_tp_as_buffer:
 rbp = rffi.cast(rffi.VOIDP, py_type.c_tp_as_buffer.c_bf_releasebuffer)
@@ -350,12 +345,10 @@
 
 def wrap_getbuffer(space, w_self, w_args, func):
 func_target = rffi.cast(getbufferproc, func)
-py_obj = make_ref(space, w_self)
-py_type = py_obj.c_ob_type
+py_type = _get_ob_type(space, w_self)
 rbp = rffi.cast(rffi.VOIDP, 0)
 if py_type.c_tp_as_buffer:
 rbp = rffi.cast(rffi.VOIDP, py_type.c_tp_as_buffer.c_bf_releasebuffer)
-decref(space, py_obj)
 with lltype.scoped_alloc(Py_buffer) as pybuf:
 _flags = 0
 if space.len_w(w_args) > 0:
diff --git a/rpython/rlib/runicode.py b/rpython/rlib/runicode.py
--- a/rpython/rlib/runicode.py
+++ b/rpython/rlib/runicode.py
@@ -877,32 +877,31 @@
 ch = ord(s[pos])
 pos += 1
 ch2 = 0
-if 0xD800 <= ch < 0xDC00:
-if not allow_surrogates:
-ru, rs, pos = errorhandler(errors, public_encoding_name,
-   'surrogates not allowed',
-   s, pos-1, pos)
-if rs is not None:
-# py3k only
-if len(rs) % 4 != 0:
-errorhandler('strict', public_encoding_name,
- 'surrogates not allowed',
- s, pos-1, pos)
-result.append(rs)
-continue
-for ch in ru:
-if ord(ch) < 0xD800:
-_STORECHAR32(result, ord(ch), byteorder)
-else:
-errorhandler('strict', public_encoding_name,
- 'surrogates not allowed',
- s, pos-1, pos)
+if not allow_surrogates and 0xD800 <= ch < 0xE000:
+ru, rs, pos = errorhandler(errors, public_encoding_name,
+  

[pypy-commit] pypy py3.5: hg merge default

2017-10-09 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92680:ebfa68d4
Date: 2017-10-09 16:11 +0200
http://bitbucket.org/pypy/pypy/changeset/ebfa68d4/

Log:hg merge default

diff --git a/lib_pypy/cffi.egg-info/PKG-INFO b/lib_pypy/cffi.egg-info/PKG-INFO
--- a/lib_pypy/cffi.egg-info/PKG-INFO
+++ b/lib_pypy/cffi.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: cffi
-Version: 1.11.1
+Version: 1.11.2
 Summary: Foreign Function Interface for Python calling C code.
 Home-page: http://cffi.readthedocs.org
 Author: Armin Rigo, Maciej Fijalkowski
diff --git a/lib_pypy/cffi/__init__.py b/lib_pypy/cffi/__init__.py
--- a/lib_pypy/cffi/__init__.py
+++ b/lib_pypy/cffi/__init__.py
@@ -4,8 +4,8 @@
 from .api import FFI
 from .error import CDefError, FFIError, VerificationError, VerificationMissing
 
-__version__ = "1.11.1"
-__version_info__ = (1, 11, 1)
+__version__ = "1.11.2"
+__version_info__ = (1, 11, 2)
 
 # The verifier module file names are based on the CRC32 of a string that
 # contains the following version number.  It may be older than __version__
diff --git a/lib_pypy/cffi/_cffi_include.h b/lib_pypy/cffi/_cffi_include.h
--- a/lib_pypy/cffi/_cffi_include.h
+++ b/lib_pypy/cffi/_cffi_include.h
@@ -238,9 +238,9 @@
 _CFFI_UNUSED_FN static PyObject *_cffi_from_c_char16_t(uint16_t x)
 {
 if (sizeof(_cffi_wchar_t) == 2)
-return _cffi_from_c_wchar_t(x);
+return _cffi_from_c_wchar_t((_cffi_wchar_t)x);
 else
-return _cffi_from_c_wchar3216_t(x);
+return _cffi_from_c_wchar3216_t((int)x);
 }
 
 _CFFI_UNUSED_FN static int _cffi_to_c_char32_t(PyObject *o)
@@ -254,7 +254,7 @@
 _CFFI_UNUSED_FN static PyObject *_cffi_from_c_char32_t(int x)
 {
 if (sizeof(_cffi_wchar_t) == 4)
-return _cffi_from_c_wchar_t(x);
+return _cffi_from_c_wchar_t((_cffi_wchar_t)x);
 else
 return _cffi_from_c_wchar3216_t(x);
 }
diff --git a/lib_pypy/cffi/_embedding.h b/lib_pypy/cffi/_embedding.h
--- a/lib_pypy/cffi/_embedding.h
+++ b/lib_pypy/cffi/_embedding.h
@@ -247,7 +247,7 @@
 
 if (f != NULL && f != Py_None) {
 PyFile_WriteString("\nFrom: " _CFFI_MODULE_NAME
-   "\ncompiled with cffi version: 1.11.1"
+   "\ncompiled with cffi version: 1.11.2"
"\n_cffi_backend module: ", f);
 modules = PyImport_GetModuleDict();
 mod = PyDict_GetItemString(modules, "_cffi_backend");
diff --git a/pypy/doc/build.rst b/pypy/doc/build.rst
--- a/pypy/doc/build.rst
+++ b/pypy/doc/build.rst
@@ -119,7 +119,7 @@
 
 To run untranslated tests, you need the Boehm garbage collector libgc.
 
-On recent Debian and Ubuntu (like 17.04), this is the command to install
+On recent Debian and Ubuntu (16.04 onwards), this is the command to install
 all build-time dependencies::
 
 apt-get install gcc make libffi-dev pkg-config zlib1g-dev libbz2-dev \
@@ -127,7 +127,7 @@
 tk-dev libgc-dev python-cffi \
 liblzma-dev libncursesw5-dev # these two only needed on PyPy3
 
-On older Debian and Ubuntu (12.04 to 16.04)::
+On older Debian and Ubuntu (12.04-14.04)::
 
 apt-get install gcc make libffi-dev pkg-config libz-dev libbz2-dev \
 libsqlite3-dev libncurses-dev libexpat1-dev libssl-dev libgdbm-dev \
@@ -149,12 +149,23 @@
 xz-devel # For lzma on PyPy3.
 (XXX plus the SLES11 version of libgdbm-dev and tk-dev)
 
-On Mac OS X, most of these build-time dependencies are installed alongside
+On Mac OS X::
+
+Most of these build-time dependencies are installed alongside
 the Developer Tools. However, note that in order for the installation to
 find them you may need to run::
 
 xcode-select --install
 
+An exception is OpenSSL, which is no longer provided with the operating
+system. It can be obtained via Homebrew (with ``$ brew install openssl``),
+but it will not be available on the system path by default. The easiest
+way to enable it for building pypy is to set an environment variable::
+
+export PKG_CONFIG_PATH=$(brew --prefix)/opt/openssl/lib/pkgconfig
+
+After setting this, translation (described next) will find the OpenSSL libs
+as expected.
 
 Run the translation
 ---
@@ -187,18 +198,18 @@
entire pypy interpreter. This step is currently singe threaded, and RAM
hungry. As part of this step,  the chain creates a large number of C code
files and a Makefile to compile them in a
-   directory controlled by the ``PYPY_USESSION_DIR`` environment variable.  
+   directory controlled by the ``PYPY_USESSION_DIR`` environment variable.
 2. Create an executable ``pypy-c`` by running the Makefile. This step can
-   utilize all possible cores on the machine.  
-3. Copy the needed binaries to the current directory.  
-4. Generate c-extension modules for any cffi-based stdlib modules.  
+   utilize all possible cores on the machine.
+3. Copy the needed binaries to the current directory.
+4. Generate 

[pypy-commit] pypy py3.5: hg merge default

2017-10-07 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r92621:e1232edfd557
Date: 2017-10-06 04:26 +0200
http://bitbucket.org/pypy/pypy/changeset/e1232edfd557/

Log:hg merge default

diff too long, truncating to 2000 out of 8213 lines

diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -40,3 +40,7 @@
 2875f328eae2216a87f3d6f335092832eb031f56 release-pypy3.5-v5.7.1
 c925e73810367cd960a32592dd7f728f436c125c release-pypy2.7-v5.8.0
 a37ecfe5f142bc971a86d17305cc5d1d70abec64 release-pypy3.5-v5.8.0
+03d614975835870da65ff0481e1edad68ebbcb8d release-pypy2.7-v5.9.0
+d72f9800a42b46a8056951b1da2426d2c2d8d502 release-pypy3.5-v5.9.0
+03d614975835870da65ff0481e1edad68ebbcb8d release-pypy2.7-v5.9.0
+84a2f3e6a7f88f2fe698e473998755b3bd1a12e2 release-pypy2.7-v5.9.0
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
@@ -3,13 +3,6 @@
 ===
 
 .. this is a revision shortly after release-pypy2.7-v5.9.0
-.. startrev:899e5245de1e
+.. startrev:d56dadcef996
 
-.. branch: cpyext-jit
 
-Differentiate the code to call METH_NOARGS, METH_O and METH_VARARGS in cpyext:
-this allows to write specialized code which is much faster than previous
-completely generic version. Moreover, let the JIT to look inside the cpyext
-module: the net result is that cpyext calls are up to 7x faster. However, this
-is true only for very simple situations: in all real life code, we are still
-much slower than CPython (more optimizations to come)
diff --git a/pypy/doc/whatsnew-pypy2-5.9.0.rst 
b/pypy/doc/whatsnew-pypy2-5.9.0.rst
--- a/pypy/doc/whatsnew-pypy2-5.9.0.rst
+++ b/pypy/doc/whatsnew-pypy2-5.9.0.rst
@@ -85,3 +85,12 @@
 .. branch: py_ssize_t
 
 Explicitly use Py_ssize_t as the Signed type in pypy c-api
+
+.. branch: cpyext-jit
+
+Differentiate the code to call METH_NOARGS, METH_O and METH_VARARGS in cpyext:
+this allows to write specialized code which is much faster than previous
+completely generic version. Moreover, let the JIT to look inside the cpyext
+module: the net result is that cpyext calls are up to 7x faster. However, this
+is true only for very simple situations: in all real life code, we are still
+much slower than CPython (more optimizations to come)
diff --git a/pypy/module/_cppyy/__init__.py b/pypy/module/_cppyy/__init__.py
--- a/pypy/module/_cppyy/__init__.py
+++ b/pypy/module/_cppyy/__init__.py
@@ -1,12 +1,10 @@
 from pypy.interpreter.mixedmodule import MixedModule
 
 class Module(MixedModule):
-"This module provides runtime bindings to C++ code for which reflection\n\
-info has been generated. Current supported back-ends are Reflex and 
CINT.\n\
-See http://doc.pypy.org/en/latest/cppyy.html for full details."
+"This module brigdes the cppyy frontend with its backend, through PyPy.\n\
+See http://cppyy.readthedocs.io/en/latest for full details."
 
 interpleveldefs = {
-'_load_dictionary'   : 'interp_cppyy.load_dictionary',
 '_resolve_name'  : 'interp_cppyy.resolve_name',
 '_scope_byname'  : 'interp_cppyy.scope_byname',
 '_template_byname'   : 'interp_cppyy.template_byname',
@@ -15,14 +13,13 @@
 '_set_function_generator': 'interp_cppyy.set_function_generator',
 '_register_class': 'interp_cppyy.register_class',
 '_get_nullptr'   : 'interp_cppyy.get_nullptr',
-'CPPInstanceBase': 'interp_cppyy.W_CPPInstance',
+'CPPClassBase'   : 'interp_cppyy.W_CPPClass',
 'addressof'  : 'interp_cppyy.addressof',
 'bind_object': 'interp_cppyy.bind_object',
 }
 
 appleveldefs = {
 '_init_pythonify': 'pythonify._init_pythonify',
-'load_reflection_info'   : 'pythonify.load_reflection_info',
 'add_pythonization'  : 'pythonify.add_pythonization',
 'Template'   : 'pythonify.CPPTemplate',
 }
diff --git a/pypy/module/_cppyy/backend/create_cppyy_package.py 
b/pypy/module/_cppyy/backend/create_cppyy_package.py
deleted file mode 100755
--- a/pypy/module/_cppyy/backend/create_cppyy_package.py
+++ /dev/null
@@ -1,649 +0,0 @@
-#!/usr/bin/env python
-from __future__ import print_function
-
-import os, sys
-import argparse, re, shutil, tarfile, urllib2
-
-
-DEBUG_TESTBUILD = False
-
-TARBALL_CACHE_DIR = 'releases'
-
-ROOT_KEEP = ['build', 'cmake', 'config', 'core', 'etc', 'interpreter',
- 'io', 'LICENSE', 'net', 'Makefile', 'CMakeLists.txt', 'math',
- 'main'] # main only needed in more recent root b/c of rootcling
-ROOT_CORE_KEEP = ['CMakeLists.txt', 'base', 'clib', 'clingutils', 'cont',
-  'dictgen', 'foundation', 'lzma', 'macosx', 'meta',
-  'metacling', 'metautils', 'rootcling_stage1', 'textinput',
-  'thread', 'unix', 'utils', 'winnt', 'zip']
-ROOT_IO_KEEP = ['CMakeLists.txt', 'io', 'rootpcm']
-ROOT_NET_KEEP = 

[pypy-commit] pypy py3.5: hg merge default

2017-10-01 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92547:4978206b1665
Date: 2017-10-02 01:53 +0200
http://bitbucket.org/pypy/pypy/changeset/4978206b1665/

Log:hg merge default

diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -768,7 +768,7 @@
 def __init__(self, method_name, slot_name, function, wrapper1, wrapper2, 
doc):
 self.method_name = method_name
 self.slot_name = slot_name
-self.slot_names = ("c_" + slot_name).split(".")
+self.slot_names = tuple(("c_" + slot_name).split("."))
 self.slot_func = function
 self.wrapper_func = wrapper1
 self.wrapper_func_kwds = wrapper2
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -257,31 +257,19 @@
 # overwrite slots that are already set: these ones are probably
 # coming from a parent C type.
 
-if w_type.is_heaptype():
-typedef = None
-search_dict_w = w_type.dict_w
-else:
-typedef = w_type.layout.typedef
-search_dict_w = None
-
 for method_name, slot_name, slot_names, slot_apifunc in 
slotdefs_for_tp_slots:
 slot_func_helper = None
-if typedef is not None:
-# built-in types: expose as many slots as possible, even
-# if it happens to come from some parent class
-slot_apifunc = get_slot_tp_function(space, typedef, slot_name)
+w_descr = w_type.dict_w.get(method_name, None)
+if w_descr:
+# use the slot_apifunc (userslots) to lookup at runtime
+pass
+elif len(slot_names) ==1:
+# 'inherit' from tp_base
+slot_func_helper = getattr(pto.c_tp_base, slot_names[0])
 else:
-w_descr = search_dict_w.get(method_name, None)
-if w_descr:
-# use the slot_apifunc (userslots) to lookup at runtime
-pass
-elif len(slot_names) ==1:
-# 'inherit' from tp_base
-slot_func_helper = getattr(pto.c_tp_base, slot_names[0])
-else:
-struct = getattr(pto.c_tp_base, slot_names[0])
-if struct:
-slot_func_helper = getattr(struct, slot_names[1])
+struct = getattr(pto.c_tp_base, slot_names[0])
+if struct:
+slot_func_helper = getattr(struct, slot_names[1])
 
 if not slot_func_helper:
 if not slot_apifunc:
@@ -290,6 +278,16 @@
 slot_func_helper = slot_apifunc.get_llhelper(space)
 fill_slot(space, pto, w_type, slot_names, slot_func_helper)
 
+def update_all_slots_builtin(space, w_type, pto):
+typedef = w_type.layout.typedef
+for method_name, slot_name, slot_names, slot_apifunc in 
slotdefs_for_tp_slots:
+slot_apifunc = get_slot_tp_function(space, typedef, slot_name)
+if not slot_apifunc:
+warn_missing_slot(space, method_name, slot_name, w_type)
+continue
+slot_func_helper = slot_apifunc.get_llhelper(space)
+fill_slot(space, pto, w_type, slot_names, slot_func_helper)
+
 @specialize.arg(3)
 def fill_slot(space, pto, w_type, slot_names, slot_func_helper):
 # XXX special case wrapper-functions and use a "specific" slot func
@@ -702,7 +700,10 @@
 if pto.c_tp_itemsize < pto.c_tp_base.c_tp_itemsize:
 pto.c_tp_itemsize = pto.c_tp_base.c_tp_itemsize
 
-update_all_slots(space, w_type, pto)
+if w_type.is_heaptype():
+update_all_slots(space, w_type, pto)
+else:
+update_all_slots_builtin(space, w_type, pto)
 if not pto.c_tp_new:
 base_object_pyo = make_ref(space, space.w_object)
 base_object_pto = rffi.cast(PyTypeObjectPtr, base_object_pyo)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-10-01 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92544:41b2cbb76719
Date: 2017-10-02 01:02 +0200
http://bitbucket.org/pypy/pypy/changeset/41b2cbb76719/

Log:hg merge default

diff --git a/pypy/doc/release-v5.9.0.rst b/pypy/doc/release-v5.9.0.rst
--- a/pypy/doc/release-v5.9.0.rst
+++ b/pypy/doc/release-v5.9.0.rst
@@ -10,15 +10,18 @@
 This new PyPy2.7 release includes the upstream stdlib version 2.7.13, and
 PyPy3.5 includes the upstream stdlib version 3.5.3.
 
-NumPy and Pandas now work on PyPy2.7. Issues that appeared as excessive memory
+NumPy and Pandas now work on PyPy2.7 (together with Cython 0.27.1). Issues
+that appeared as excessive memory
 use were cleared up and other incompatibilities were resolved. The C-API
 compatibility layer does slow down code which crosses the python-c interface
 often, we have ideas on how it could be improved, and still recommend
 using pure python on PyPy or interfacing via CFFI_. Many other modules
 based on C-API exentions now work on PyPy as well.
 
-Cython 0.27 (released last week) should support more projects with PyPy, both
-on PyPy2.7 and PyPy3.5 beta.
+Cython 0.27.1 (released very recently) supports more projects with PyPy, both
+on PyPy2.7 and PyPy3.5 beta. Note version **0.27.1** is now the minimum
+version that supports this version of PyPy, due to some interactions with
+updated C-API interface code.
 
 We optimized the JSON parser for recurring string keys, which should decrease
 memory use to 50% and increase parsing speed by up to 15% for large JSON files
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
@@ -4,3 +4,12 @@
 
 .. this is a revision shortly after release-pypy2.7-v5.9.0
 .. startrev:899e5245de1e
+
+.. branch: cpyext-jit
+
+Differentiate the code to call METH_NOARGS, METH_O and METH_VARARGS in cpyext:
+this allows to write specialized code which is much faster than previous
+completely generic version. Moreover, let the JIT to look inside the cpyext
+module: the net result is that cpyext calls are up to 7x faster. However, this
+is true only for very simple situations: in all real life code, we are still
+much slower than CPython (more optimizations to come)
diff --git a/pypy/module/_cffi_backend/cffi1_module.py 
b/pypy/module/_cffi_backend/cffi1_module.py
--- a/pypy/module/_cffi_backend/cffi1_module.py
+++ b/pypy/module/_cffi_backend/cffi1_module.py
@@ -1,4 +1,5 @@
 from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.rlib import jit
 
 from pypy.interpreter.error import oefmt
 from pypy.interpreter.module import Module
@@ -15,7 +16,7 @@
 
 INITFUNCPTR = lltype.Ptr(lltype.FuncType([rffi.VOIDPP], lltype.Void))
 
-
+@jit.dont_look_inside
 def load_cffi1_module(space, name, path, initptr):
 # This is called from pypy.module.cpyext.api.load_extension_module()
 from pypy.module._cffi_backend.call_python import get_ll_cffi_call_python
diff --git a/pypy/module/_cffi_backend/ctypeptr.py 
b/pypy/module/_cffi_backend/ctypeptr.py
--- a/pypy/module/_cffi_backend/ctypeptr.py
+++ b/pypy/module/_cffi_backend/ctypeptr.py
@@ -158,10 +158,11 @@
 
 class W_CTypePtrBase(W_CTypePtrOrArray):
 # base class for both pointers and pointers-to-functions
-_attrs_ = ['is_void_ptr', 'is_voidchar_ptr']
-_immutable_fields_ = ['is_void_ptr', 'is_voidchar_ptr']
+_attrs_ = ['is_void_ptr', 'is_voidchar_ptr', 'is_onebyte_ptr']
+_immutable_fields_ = ['is_void_ptr', 'is_voidchar_ptr', 'is_onebyte_ptr']
 is_void_ptr = False
 is_voidchar_ptr = False
+is_onebyte_ptr = False
 
 def convert_to_object(self, cdata):
 ptrdata = rffi.cast(rffi.CCHARPP, cdata)[0]
@@ -181,12 +182,20 @@
 if self.is_void_ptr or other.is_void_ptr:
 pass # cast from or to 'void *'
 elif self.is_voidchar_ptr or other.is_voidchar_ptr:
-space = self.space
-msg = ("implicit cast from '%s' to '%s' "
-"will be forbidden in the future (check that the types "
-"are as you expect; use an explicit ffi.cast() if they "
-"are correct)" % (other.name, self.name))
-space.warn(space.newtext(msg), space.w_UserWarning)
+# for backward compatibility, accept "char *" as either
+# source of target.  This is not what C does, though,
+# so emit a warning that will eventually turn into an
+# error.  The warning is turned off if both types are
+# pointers to single bytes.
+if self.is_onebyte_ptr and other.is_onebyte_ptr:
+pass   # no warning
+else:
+space = self.space
+msg = ("implicit cast from '%s' to '%s' "
+"will be forbidden in the future (check that the types 
"
+"are as you expect; use an 

[pypy-commit] pypy py3.5: hg merge default

2017-09-29 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92521:45380b7b402f
Date: 2017-09-30 00:42 +0200
http://bitbucket.org/pypy/pypy/changeset/45380b7b402f/

Log:hg merge default

diff --git a/pypy/doc/release-v5.9.0.rst b/pypy/doc/release-v5.9.0.rst
--- a/pypy/doc/release-v5.9.0.rst
+++ b/pypy/doc/release-v5.9.0.rst
@@ -148,8 +148,7 @@
   * Issue 2590_: fix the bounds in the GC when allocating a lot of objects 
with finalizers
   * Replace magical NOT RPYTHON comment with a decorator
   * Implement ``socket.sendmsg()``/``.recvmsg()`` for py3.5
-  * Reduce excessive ``memory_pressure`` for ``_SSLContext`` objects and add
-``memory_pressure`` for ``_SSLSocket`` objects
+  * Add ``memory_pressure`` for ``_SSLSocket`` objects
 
 * Degredations
 
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -669,6 +669,10 @@
 'PySlice_Type': 'space.gettypeobject(W_SliceObject.typedef)',
 'PyStaticMethod_Type': 'space.gettypeobject(StaticMethod.typedef)',
 'PyCFunction_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCFunctionObject.typedef)',
+'PyClassMethodDescr_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCClassMethodObject.typedef)',
+'PyGetSetDescr_Type': 
'space.gettypeobject(cpyext.typeobject.W_GetSetPropertyEx.typedef)',
+'PyMemberDescr_Type': 
'space.gettypeobject(cpyext.typeobject.W_MemberDescr.typedef)',
+'PyMethodDescr_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCMethodObject.typedef)',
 'PyWrapperDescr_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCWrapperObject.typedef)',
 'PyInstanceMethod_Type': 
'space.gettypeobject(cpyext.classobject.InstanceMethod.typedef)',
 }.items():
diff --git a/pypy/module/cpyext/test/test_typeobject.py 
b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -1362,6 +1362,11 @@
 
 assert B() == 42
 
+# a even more hackiness
+class C(A):
+pass
+C(42)   # assert is not aborting
+
 
 class AppTestHashable(AppTestCpythonExtensionBase):
 def test_unhashable(self):
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -682,14 +682,30 @@
 #   it can fail if self.__base__ happens not to be the first base.
 #
 from pypy.module.cpyext.methodobject import W_PyCFunctionObject
+
+if isinstance(w_newdescr, W_PyCFunctionObject):
+return self._really_hack_which_new_to_call(w_newtype, w_newdescr)
+else:
+return w_newtype, w_newdescr
+
+def _really_hack_which_new_to_call(self, w_newtype, w_newdescr):
+# This logic is moved in yet another helper function that
+# is recursive.  We call this only if we see a
+# W_PyCFunctionObject.  That's a performance optimization
+# because in the common case, we won't call any function that
+# contains the stack checks.
+from pypy.module.cpyext.methodobject import W_PyCFunctionObject
 from pypy.module.cpyext.typeobject import is_tp_new_wrapper
 
 if (isinstance(w_newdescr, W_PyCFunctionObject) and
+w_newtype is not self and
 is_tp_new_wrapper(self.space, w_newdescr.ml)):
 w_bestbase = find_best_base(self.bases_w)
-return w_bestbase.lookup_where('__new__')
-else:
-return w_newtype, w_newdescr
+if w_bestbase is not None:
+w_newtype, w_newdescr = w_bestbase.lookup_where('__new__')
+return w_bestbase._really_hack_which_new_to_call(w_newtype,
+ w_newdescr)
+return w_newtype, w_newdescr
 
 def descr_repr(self, space):
 w_mod = self.get_module()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-09-29 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92505:a0fe3f649ba8
Date: 2017-09-29 17:14 +0200
http://bitbucket.org/pypy/pypy/changeset/a0fe3f649ba8/

Log:hg merge default

diff --git a/pypy/module/cpyext/methodobject.py 
b/pypy/module/cpyext/methodobject.py
--- a/pypy/module/cpyext/methodobject.py
+++ b/pypy/module/cpyext/methodobject.py
@@ -10,7 +10,8 @@
 from pypy.module.cpyext.api import (
 CONST_STRING, METH_CLASS, METH_COEXIST, METH_KEYWORDS, METH_NOARGS, METH_O,
 METH_STATIC, METH_VARARGS, PyObject, bootstrap_function,
-cpython_api, generic_cpy_call, CANNOT_FAIL, slot_function, cts)
+cpython_api, generic_cpy_call, CANNOT_FAIL, slot_function, cts,
+build_type_checkers)
 from pypy.module.cpyext.pyobject import (
 Py_DecRef, from_ref, make_ref, as_pyobj, make_typedescr)
 
@@ -129,6 +130,10 @@
 ret = self.call(space, w_instance, w_args, w_kw)
 return ret
 
+# PyPy addition, for Cython
+_, _ = build_type_checkers("MethodDescr", W_PyCMethodObject)
+
+
 @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
 def PyCFunction_Check(space, w_obj):
 from pypy.interpreter.function import BuiltinFunction
@@ -155,6 +160,7 @@
 (self.name.decode('utf-8'), self.w_objclass.getname(self.space)))
 
 
+
 class W_PyCWrapperObject(W_Root):
 def __init__(self, space, pto, method_name, wrapper_func,
  wrapper_func_kwds, doc, func, offset=None):
diff --git a/pypy/module/cpyext/test/foo.c b/pypy/module/cpyext/test/foo.c
--- a/pypy/module/cpyext/test/foo.c
+++ b/pypy/module/cpyext/test/foo.c
@@ -83,19 +83,32 @@
 return cls;
 }
 
+// for CPython
+#ifndef PyMethodDescr_Check
+int PyMethodDescr_Check(PyObject* method)
+{
+PyObject *meth = PyObject_GetAttrString((PyObject*)_Type, "append");
+if (!meth) return 0;
+int res = PyObject_TypeCheck(method, meth->ob_type);
+Py_DECREF(meth);
+return res;
+}
+#endif
+
 PyObject* make_classmethod(PyObject* method)
 {
 // adapted from __Pyx_Method_ClassMethod
-if (PyObject_TypeCheck(method, _Type)) {
-return PyClassMethod_New(method);
+if (PyMethodDescr_Check(method)) {
+PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
+PyTypeObject *d_type = descr->d_common.d_type;
+return PyDescr_NewClassMethod(d_type, descr->d_method);
 }
 else if (PyMethod_Check(method)) {
 return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
 }
 else {
-PyMethodDescrObject *descr = (PyMethodDescrObject *)method;
-PyTypeObject *d_type = descr->d_common.d_type;
-return PyDescr_NewClassMethod(d_type, descr->d_method);
+PyErr_SetString(PyExc_TypeError, "unknown method kind");
+return NULL;
 }
 }
 
@@ -828,6 +841,8 @@
 
 fake_classmeth = PyDict_GetItemString((PyObject *)fooType.tp_dict, 
"fake_classmeth");
 classmeth = make_classmethod(fake_classmeth);
+if (classmeth == NULL)
+INITERROR;
 if (PyDict_SetItemString((PyObject *)fooType.tp_dict, "fake_classmeth", 
classmeth) < 0)
 INITERROR;
 
diff --git a/pypy/module/cpyext/test/test_typeobject.py 
b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -1321,6 +1321,47 @@
 assert Asize == Bsize
 assert Asize > basesize
 
+def test_multiple_inheritance_bug1(self):
+module = self.import_extension('foo', [
+   ("get_type", "METH_NOARGS",
+'''
+Py_INCREF(_Type);
+return (PyObject *)_Type;
+'''
+), ("forty_two", "METH_O",
+'''
+return PyLong_FromLong(42);
+'''
+)], prologue='''
+static PyTypeObject Foo_Type = {
+PyVarObject_HEAD_INIT(NULL, 0)
+"foo.foo",
+};
+static PyObject *dummy_new(PyTypeObject *t, PyObject *a,
+   PyObject *k)
+{
+abort();   /* never actually called in CPython */
+}
+''', more_init = '''
+Foo_Type.tp_base = (PyTypeObject *)PyExc_Exception;
+Foo_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
+Foo_Type.tp_new = dummy_new;
+if (PyType_Ready(_Type) < 0) INITERROR;
+''')
+Foo = module.get_type()
+class A(Foo, SyntaxError):
+pass
+assert A.__base__ is SyntaxError
+A(42)# assert is not aborting
+
+class Bar(Exception):
+__new__ = module.forty_two
+
+class B(Bar, SyntaxError):
+pass
+
+assert B() == 42
+
 
 class AppTestHashable(AppTestCpythonExtensionBase):
 def test_unhashable(self):
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ 

[pypy-commit] pypy py3.5: hg merge default

2017-09-28 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92495:9d4f0cdad713
Date: 2017-09-28 23:48 +0200
http://bitbucket.org/pypy/pypy/changeset/9d4f0cdad713/

Log:hg merge default

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -1338,17 +1338,20 @@
 for decl in FORWARD_DECLS:
 decls[pypy_decl].append("%s;" % (decl,))
 decls[pypy_decl].append("""
-/* hack for https://bugs.python.org/issue29943 */
-PyAPI_FUNC(int) %s(PySliceObject *arg0,
-   Signed arg1, Signed *arg2,
-   Signed *arg3, Signed *arg4, Signed *arg5);
-static int PySlice_GetIndicesEx(PySliceObject *arg0, Py_ssize_t arg1,
-Py_ssize_t *arg2, Py_ssize_t *arg3, Py_ssize_t *arg4,
-Py_ssize_t *arg5) {
-return %s(arg0, arg1, arg2, arg3,
-  arg4, arg5);
-}
-""" % ((mangle_name(prefix, 'PySlice_GetIndicesEx'),)*2))
+/* hack for https://bugs.python.org/issue29943 */
+
+PyAPI_FUNC(int) %s(PySliceObject *arg0,
+Signed arg1, Signed *arg2,
+Signed *arg3, Signed *arg4, Signed *arg5);
+#ifdef __GNUC__
+__attribute__((__unused__))
+#endif
+static int PySlice_GetIndicesEx(PySliceObject *arg0, Py_ssize_t arg1,
+Py_ssize_t *arg2, Py_ssize_t *arg3, Py_ssize_t *arg4,
+Py_ssize_t *arg5) {
+return %s(arg0, arg1, arg2, arg3,
+arg4, arg5);
+}""" % ((mangle_name(prefix, 'PySlice_GetIndicesEx'),)*2))
 
 for header_name, header_functions in FUNCTIONS_BY_HEADER.iteritems():
 header = decls[header_name]
diff --git a/pypy/module/cpyext/include/descrobject.h 
b/pypy/module/cpyext/include/descrobject.h
--- a/pypy/module/cpyext/include/descrobject.h
+++ b/pypy/module/cpyext/include/descrobject.h
@@ -1,34 +1,6 @@
 #ifndef Py_DESCROBJECT_H
 #define Py_DESCROBJECT_H
 
-#define PyDescr_COMMON \
-PyObject_HEAD \
-PyTypeObject *d_type; \
-PyObject *d_name
-
-typedef struct {
-PyDescr_COMMON;
-} PyDescrObject;
-
-typedef struct {
-PyDescr_COMMON;
-PyMethodDef *d_method;
-} PyMethodDescrObject;
-
-typedef struct {
-PyDescr_COMMON;
-struct PyMemberDef *d_member;
-} PyMemberDescrObject;
-
-typedef struct {
-PyDescr_COMMON;
-PyGetSetDef *d_getset;
-} PyGetSetDescrObject;
-
-typedef struct {
-PyDescr_COMMON;
-struct wrapperbase *d_base;
-void *d_wrapped; /* This can be any function pointer */
-} PyWrapperDescrObject;
+#include "cpyext_descrobject.h"
 
 #endif
diff --git a/pypy/module/cpyext/parse/cpyext_descrobject.h 
b/pypy/module/cpyext/parse/cpyext_descrobject.h
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/parse/cpyext_descrobject.h
@@ -0,0 +1,29 @@
+#define PyDescr_COMMON \
+PyObject_HEAD \
+PyTypeObject *d_type; \
+PyObject *d_name
+
+typedef struct {
+PyDescr_COMMON;
+} PyDescrObject;
+
+typedef struct {
+PyDescr_COMMON;
+PyMethodDef *d_method;
+} PyMethodDescrObject;
+
+typedef struct {
+PyDescr_COMMON;
+struct PyMemberDef *d_member;
+} PyMemberDescrObject;
+
+typedef struct {
+PyDescr_COMMON;
+PyGetSetDef *d_getset;
+} PyGetSetDescrObject;
+
+typedef struct {
+PyDescr_COMMON;
+struct wrapperbase *d_base;
+void *d_wrapped; /* This can be any function pointer */
+} PyWrapperDescrObject;
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -19,7 +19,8 @@
 Py_TPFLAGS_TUPLE_SUBCLASS, Py_TPFLAGS_UNICODE_SUBCLASS,
 Py_TPFLAGS_DICT_SUBCLASS, Py_TPFLAGS_BASE_EXC_SUBCLASS,
 Py_TPFLAGS_TYPE_SUBCLASS,
-Py_TPFLAGS_BYTES_SUBCLASS)
+Py_TPFLAGS_INT_SUBCLASS, Py_TPFLAGS_STRING_SUBCLASS, # change on py3
+)
 from pypy.module.cpyext.cparser import CTypeSpace
 from pypy.module.cpyext.methodobject import (W_PyCClassMethodObject,
 W_PyCWrapperObject, PyCFunction_NewEx, PyCFunction, PyMethodDef,
@@ -39,6 +40,8 @@
 from pypy.objspace.std.typeobject import W_TypeObject, find_best_base
 
 
+cts.parse_header(parse_dir / "cpyext_descrobject.h")
+
 #WARN_ABOUT_MISSING_SLOT_FUNCTIONS = False
 
 PyType_Check, PyType_CheckExact = build_type_checkers_flags("Type")
@@ -115,57 +118,24 @@
 )
 assert not W_MemberDescr.typedef.acceptable_as_base_class  # no __new__
 
-PyDescrObject = lltype.ForwardReference()
-PyDescrObjectPtr = lltype.Ptr(PyDescrObject)
-PyDescrObjectFields = PyObjectFields + (
-("d_type", PyTypeObjectPtr),
-("d_name", PyObject),
-)
-cpython_struct("PyDescrObject", PyDescrObjectFields,
-   PyDescrObject)
-
-PyMemberDescrObjectStruct = lltype.ForwardReference()
-PyMemberDescrObject = lltype.Ptr(PyMemberDescrObjectStruct)
-PyMemberDescrObjectFields = PyDescrObjectFields + (
-("d_member", lltype.Ptr(PyMemberDef)),
-)
-cpython_struct("PyMemberDescrObject", 

[pypy-commit] pypy py3.5: hg merge default

2017-09-28 Thread mjacob
Author: Manuel Jacob 
Branch: py3.5
Changeset: r92491:aee2981816b8
Date: 2017-09-28 21:48 +0200
http://bitbucket.org/pypy/pypy/changeset/aee2981816b8/

Log:hg merge default

diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -60,8 +60,8 @@
   Wim Lavrijsen
   Eric van Riet Paap
   Richard Emslie
+  Remi Meier
   Alexander Schremmer
-  Remi Meier
   Dan Villiom Podlaski Christiansen
   Lukas Diekmann
   Sven Hager
@@ -102,6 +102,7 @@
   Michael Foord
   Stephan Diehl
   Stefano Rivera
+  Jean-Paul Calderone
   Stefan Schwarzer
   Tomek Meka
   Valentino Volonghi
@@ -110,14 +111,13 @@
   Bob Ippolito
   Bruno Gola
   David Malcolm
-  Jean-Paul Calderone
   Squeaky
   Edd Barrett
   Timo Paulssen
   Marius Gedminas
+  Nicolas Truessel
   Alexandre Fayolle
   Simon Burton
-  Nicolas Truessel
   Martin Matusiak
   Laurence Tratt
   Wenzhu Man
@@ -156,6 +156,7 @@
   Stefan H. Muller
   Tim Felgentreff
   Eugene Oden
+  Dodan Mihai
   Jeff Terrace
   Henry Mason
   Vasily Kuznetsov
@@ -182,11 +183,13 @@
   Rocco Moretti
   Gintautas Miliauskas
   Lucian Branescu Mihaila
+  Mariano Anaya
   anatoly techtonik
-  Dodan Mihai
   Karl Bartel
+  Stefan Beyer
   Gabriel Lavoie
   Jared Grubb
+  Alecsandru Patrascu
   Olivier Dormond
   Wouter van Heyst
   Sebastian Pawlu
@@ -194,6 +197,7 @@
   Victor Stinner
   Andrews Medina
   Aaron Iles
+  p_ziesch...@yahoo.de
   Toby Watson
   Daniel Patrick
   Stuart Williams
@@ -204,6 +208,7 @@
   Michael Cheng
   Mikael Schnenberg
   Stanislaw Halik
+  Mihnea Saracin
   Berkin Ilbeyi
   Gasper Zejn
   Faye Zhao
@@ -214,14 +219,12 @@
   Jonathan David Riehl
   Beatrice During
   Alex Perry
-  p_ziesch...@yahoo.de
   Robert Zaremba
   Alan McIntyre
   Alexander Sedov
   Vaibhav Sood
   Reuben Cummings
   Attila Gobi
-  Alecsandru Patrascu
   Christopher Pope
   Tristan Arthur
   Christian Tismer 
@@ -243,7 +246,6 @@
   Jacek Generowicz
   Sylvain Thenault
   Jakub Stasiak
-  Stefan Beyer
   Andrew Dalke
   Alejandro J. Cura
   Vladimir Kryachko
@@ -275,6 +277,7 @@
   Christoph Gerum
   Miguel de Val Borro
   Artur Lisiecki
+  afteryu
   Toni Mattis
   Laurens Van Houtven
   Bobby Impollonia
@@ -305,6 +308,7 @@
   Anna Katrina Dominguez
   Kim Jin Su
   Amber Brown
+  Anthony Sottile
   Nate Bragg
   Ben Darnell
   Juan Francisco Cantero Hurtado
@@ -325,12 +329,14 @@
   Mike Bayer
   Rodrigo Arajo
   Daniil Yarancev
+  Min RK
   OlivierBlanvillain
   Jonas Pfannschmidt
   Zearin
   Andrey Churin
   Dan Crosta
   reub...@gmail.com
+  Stanisaw Halik
   Julien Phalip
   Roman Podoliaka
   Eli Stevens
diff --git a/lib-python/2.7/inspect.py b/lib-python/2.7/inspect.py
--- a/lib-python/2.7/inspect.py
+++ b/lib-python/2.7/inspect.py
@@ -203,7 +203,7 @@
 f_localslocal namespace seen by this frame
 f_restricted0 or 1 if frame is in restricted execution mode
 f_trace tracing function for this frame, or None"""
-return isinstance(object, types.FrameType)
+return isinstance(object, (types.FrameType, types.FakeFrameType))
 
 def iscode(object):
 """Return true if the object is a code object.
diff --git a/lib-python/2.7/types.py b/lib-python/2.7/types.py
--- a/lib-python/2.7/types.py
+++ b/lib-python/2.7/types.py
@@ -71,6 +71,12 @@
 FrameType = type(tb.tb_frame)
 del tb
 
+# PyPy extension
+try:
+FakeFrameType = type(next(sys._current_frames().itervalues()))
+except (AttributeError, StopIteration):
+FakeFrameType = FrameType
+
 SliceType = slice
 EllipsisType = type(Ellipsis)
 
diff --git a/lib_pypy/cffi.egg-info/PKG-INFO b/lib_pypy/cffi.egg-info/PKG-INFO
--- a/lib_pypy/cffi.egg-info/PKG-INFO
+++ b/lib_pypy/cffi.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: cffi
-Version: 1.11.0
+Version: 1.11.1
 Summary: Foreign Function Interface for Python calling C code.
 Home-page: http://cffi.readthedocs.org
 Author: Armin Rigo, Maciej Fijalkowski
diff --git a/lib_pypy/cffi/__init__.py b/lib_pypy/cffi/__init__.py
--- a/lib_pypy/cffi/__init__.py
+++ b/lib_pypy/cffi/__init__.py
@@ -4,8 +4,8 @@
 from .api import FFI
 from .error import CDefError, FFIError, VerificationError, VerificationMissing
 
-__version__ = "1.11.0"
-__version_info__ = (1, 11, 0)
+__version__ = "1.11.1"
+__version_info__ = (1, 11, 1)
 
 # The verifier module file names are based on the CRC32 of a string that
 # contains the following version number.  It may be older than __version__
diff --git a/lib_pypy/cffi/_embedding.h b/lib_pypy/cffi/_embedding.h
--- a/lib_pypy/cffi/_embedding.h
+++ b/lib_pypy/cffi/_embedding.h
@@ -247,7 +247,7 @@
 
 if (f != NULL && f != Py_None) {
 PyFile_WriteString("\nFrom: " _CFFI_MODULE_NAME
-   "\ncompiled with cffi version: 1.11.0"
+   "\ncompiled with cffi version: 1.11.1"
"\n_cffi_backend module: ", f);
 modules = PyImport_GetModuleDict();
 mod = 

[pypy-commit] pypy py3.5: hg merge default

2017-09-21 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92433:a42b82e1eb73
Date: 2017-09-21 19:32 +0100
http://bitbucket.org/pypy/pypy/changeset/a42b82e1eb73/

Log:hg merge default

diff --git a/lib-python/2.7/multiprocessing/heap.py 
b/lib-python/2.7/multiprocessing/heap.py
--- a/lib-python/2.7/multiprocessing/heap.py
+++ b/lib-python/2.7/multiprocessing/heap.py
@@ -62,7 +62,7 @@
 self.size = size
 self.name = 'pym-%d-%d' % (os.getpid(), Arena._counter.next())
 self.buffer = mmap.mmap(-1, self.size, tagname=self.name)
-assert win32.GetLastError() == 0, 'tagname already in use'
+#assert win32.GetLastError() == 0, 'tagname already in use'
 self._state = (self.size, self.name)
 
 def __getstate__(self):
@@ -72,7 +72,7 @@
 def __setstate__(self, state):
 self.size, self.name = self._state = state
 self.buffer = mmap.mmap(-1, self.size, tagname=self.name)
-assert win32.GetLastError() == win32.ERROR_ALREADY_EXISTS
+#assert win32.GetLastError() == win32.ERROR_ALREADY_EXISTS
 
 else:
 
diff --git a/lib-python/2.7/string.py b/lib-python/2.7/string.py
--- a/lib-python/2.7/string.py
+++ b/lib-python/2.7/string.py
@@ -75,7 +75,7 @@
 for i in range(256):
 buf[i] = i
 for i in range(n):
-buf[ord(fromstr[i])] = tostr[i]
+buf[ord(fromstr[i])] = ord(tostr[i])
 return str(buf)
 
 
diff --git a/pypy/doc/windows.rst b/pypy/doc/windows.rst
--- a/pypy/doc/windows.rst
+++ b/pypy/doc/windows.rst
@@ -120,7 +120,7 @@
 Download the versions of all the external packages from
 https://bitbucket.org/pypy/pypy/downloads/local_59.zip
 (for post-5.8 builds) with sha256 checksum
-``0f96c045db1f5f73ad0fae7857caa69c261324bd8e51f6d2ad1fa842c4a5f26f``
+``6344230e90ab7a9cb84efbae1ba22051cdeeb40a31823e0808545b705aba8911``
 https://bitbucket.org/pypy/pypy/downloads/local_5.8.zip
 (to reproduce 5.8 builds) with sha256 checksum 
 ``fbe769bf3a4ab6f5a8b0a05b61930fc7f37da2a9a85a8f609cf5a9bad06e2554`` or
diff --git a/pypy/interpreter/test/test_typedef.py 
b/pypy/interpreter/test/test_typedef.py
--- a/pypy/interpreter/test/test_typedef.py
+++ b/pypy/interpreter/test/test_typedef.py
@@ -419,3 +419,7 @@
 def f():
 return x
 assert f.__closure__[0].cell_contents is x
+
+def test_get_with_none_arg(self):
+raises(TypeError, type.__dict__['__mro__'].__get__, None)
+raises(TypeError, type.__dict__['__mro__'].__get__, None, None)
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -300,6 +300,8 @@
 if (space.is_w(w_obj, space.w_None)
 and not space.is_w(w_cls, space.type(space.w_None))):
 #print self, w_obj, w_cls
+if space.is_w(w_cls, space.w_None):
+raise oefmt(space.w_TypeError, "__get__(None, None) is 
invalid")
 return self
 else:
 try:
diff --git a/pypy/module/_multiprocessing/interp_win32.py 
b/pypy/module/_multiprocessing/interp_win32.py
--- a/pypy/module/_multiprocessing/interp_win32.py
+++ b/pypy/module/_multiprocessing/interp_win32.py
@@ -111,6 +111,7 @@
 raise wrap_oserror(space, rwin32.lastSavedWindowsError())
 
 def GetLastError(space):
+"""NOTE: don't use this.  See issue #2658"""
 return space.newint(rwin32.GetLastError_saved())
 
 # __
diff --git a/pypy/module/_vmprof/__init__.py b/pypy/module/_vmprof/__init__.py
--- a/pypy/module/_vmprof/__init__.py
+++ b/pypy/module/_vmprof/__init__.py
@@ -1,5 +1,7 @@
 from pypy.interpreter.mixedmodule import MixedModule
 from rpython.rlib.rvmprof import VMProfPlatformUnsupported
+from rpython.translator.platform import CompilationError
+
 
 class Module(MixedModule):
 """
@@ -29,3 +31,9 @@
 import pypy.module._vmprof.interp_vmprof
 except VMProfPlatformUnsupported as e:
 pass
+except CompilationError as e:
+import sys
+if sys.platform == 'win32':
+pass
+else:
+raise
diff --git a/pypy/module/_vmprof/conftest.py b/pypy/module/_vmprof/conftest.py
--- a/pypy/module/_vmprof/conftest.py
+++ b/pypy/module/_vmprof/conftest.py
@@ -1,6 +1,8 @@
-import py, platform
+import py, platform, sys
 
 def pytest_collect_directory(path, parent):
 if platform.machine() == 's390x':
-py.test.skip("zarch tests skipped")
+py.test.skip("_vmprof tests skipped")
+if sys.platform == 'win32':
+py.test.skip("_vmprof tests skipped")
 pytest_collect_file = pytest_collect_directory
diff --git a/pypy/module/cpyext/methodobject.py 
b/pypy/module/cpyext/methodobject.py
--- a/pypy/module/cpyext/methodobject.py
+++ b/pypy/module/cpyext/methodobject.py
@@ -102,21 +102,27 @@
 return self.space.unwrap(self.descr_method_repr())
 
 def descr_method_repr(self):
+w_objclass = 

[pypy-commit] pypy py3.5: hg merge default

2017-09-15 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92403:3d6ac44c6fff
Date: 2017-09-15 16:37 +0100
http://bitbucket.org/pypy/pypy/changeset/3d6ac44c6fff/

Log:hg 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
@@ -81,3 +81,7 @@
 .. branch: pycheck-macros
 
 Convert many Py*_Check cpyext functions into macros, like CPython.
+
+.. branch: py_ssize_t
+
+Explicitly use Py_ssize_t as the Signed type in pypy c-api
diff --git a/pypy/doc/windows.rst b/pypy/doc/windows.rst
--- a/pypy/doc/windows.rst
+++ b/pypy/doc/windows.rst
@@ -114,12 +114,15 @@
 INCLUDE, LIB and PATH (for DLLs) environment variables appropriately.
 
 
-Abridged method (for -Ojit builds using Visual Studio 2008)

+Abridged method (using Visual Studio 2008)
+--
 
 Download the versions of all the external packages from
+https://bitbucket.org/pypy/pypy/downloads/local_59.zip
+(for post-5.8 builds) with sha256 checksum
+``0f96c045db1f5f73ad0fae7857caa69c261324bd8e51f6d2ad1fa842c4a5f26f``
 https://bitbucket.org/pypy/pypy/downloads/local_5.8.zip
-(for post-5.7.1 builds) with sha256 checksum 
+(to reproduce 5.8 builds) with sha256 checksum 
 ``fbe769bf3a4ab6f5a8b0a05b61930fc7f37da2a9a85a8f609cf5a9bad06e2554`` or
 https://bitbucket.org/pypy/pypy/downloads/local_2.4.zip
 (for 2.4 release and later) or
@@ -135,8 +138,8 @@
 Now you should be good to go. If you choose this method, you do not need
 to download/build anything else. 
 
-Nonabrided method (building from scratch)
--
+Nonabridged method (building from scratch)
+--
 
 If you want to, you can rebuild everything from scratch by continuing.
 
@@ -209,17 +212,85 @@
 The expat XML parser
 
 
-Download the source code of expat on sourceforge:
-https://github.com/libexpat/libexpat/releases and extract it in the base 
directory.
-Version 2.1.1 is known to pass tests. Then open the project file ``expat.dsw``
-with Visual Studio; follow the instruction for converting the project files,
-switch to the "Release" configuration, use the ``expat_static`` project,
-reconfigure the runtime for Multi-threaded DLL (/MD) and build. Do the same for
-the ``expat`` project to build the ``expat.dll`` (for tests via ll2ctypes)
+CPython compiles expat from source as part of the build. PyPy uses the same
+code base, but expects to link to a static lib of expat. Here are instructions
+to reproduce the static lib in version 2.2.4.
 
-Then, copy the file ``win32\bin\release\libexpat.lib`` into
-LIB, and both ``lib\expat.h`` and ``lib\expat_external.h`` in
-INCLUDE, and ``win32\bin\release\libexpat.dll`` into PATH.
+Download the source code of expat: https://github.com/libexpat/libexpat. 
+``git checkout`` the proper tag, in this case ``R_2_2_4``. Run
+``vcvars.bat`` to set up the visual compiler tools, and CD into the source
+directory. Create a file ``stdbool.h`` with the content
+
+.. code-block:: c
+
+#pragma once
+
+#define false   0
+#define true1
+
+#define bool int
+
+and put it in a place on the ``INCLUDE`` path, or create it in the local
+directory and add ``.`` to the ``INCLUDE`` path::
+
+SET INCLUDE=%INCLUDE%;.
+
+Then compile all the ``*.c`` file into ``*.obj``::
+
+cl.exe /nologo /MD  /O2 *c /c
+rem for debug
+cl.exe /nologo /MD  /O0 /Ob0 /Zi *c /c
+
+You may need to move some variable declarations to the beginning of the
+function, to be compliant with C89 standard. Here is the diff for version 2.2.4
+
+.. code-block:: diff
+
+diff --git a/expat/lib/xmltok.c b/expat/lib/xmltok.c
+index 007aed0..a2dcaad 100644
+--- a/expat/lib/xmltok.c
++++ b/expat/lib/xmltok.c
+@@ -399,19 +399,21 @@ utf8_toUtf8(const ENCODING *UNUSED_P(enc),
+   /* Avoid copying partial characters (due to limited space). */
+   const ptrdiff_t bytesAvailable = fromLim - *fromP;
+   const ptrdiff_t bytesStorable = toLim - *toP;
++  const char * fromLimBefore;
++  ptrdiff_t bytesToCopy;
+   if (bytesAvailable > bytesStorable) {
+ fromLim = *fromP + bytesStorable;
+ output_exhausted = true;
+   }
+
+   /* Avoid copying partial characters (from incomplete input). */
+-  const char * const fromLimBefore = fromLim;
++  fromLimBefore = fromLim;
+   align_limit_to_full_utf8_characters(*fromP, );
+   if (fromLim < fromLimBefore) {
+ input_incomplete = true;
+   }
+
+-  const ptrdiff_t bytesToCopy = fromLim - *fromP;
++  bytesToCopy = fromLim - *fromP;
+   memcpy((void *)*toP, (const void *)*fromP, (size_t)bytesToCopy);
+   *fromP += bytesToCopy;
+   *toP += bytesToCopy;
+
+
+Create ``libexpat.lib`` (for translation) and ``libexpat.dll`` (for tests)::
+
+cl /LD *.obj libexpat.def 

[pypy-commit] pypy py3.5: hg merge default (fast PyUnicode_Check disabled for now)

2017-09-11 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92372:1f0dbee16f1f
Date: 2017-09-11 17:53 +0100
http://bitbucket.org/pypy/pypy/changeset/1f0dbee16f1f/

Log:hg merge default (fast PyUnicode_Check disabled for now)

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
@@ -73,3 +73,11 @@
 
 Add support for leakfinder in cpyext tests (disabled for now, due to too many
 failures).
+
+.. branch: pypy_swappedbytes
+
+Added ``_swappedbytes_`` support for ``ctypes.Structure``
+
+.. branch: pycheck-macros
+
+Convert many Py*_Check cpyext functions into macros, like CPython.
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1537,12 +1537,15 @@
 def text_or_none_w(self, w_obj):
 return None if self.is_none(w_obj) else self.text_w(w_obj)
 
+@specialize.argtype(1)
 def bytes_w(self, w_obj):
 """ Takes an application level :py:class:`bytes`
 (on PyPy2 this equals `str`) and returns a rpython byte string.
 """
+assert w_obj is not None
 return w_obj.bytes_w(self)
 
+@specialize.argtype(1)
 def text_w(self, w_obj):
 """ PyPy2 takes either a :py:class:`str` and returns a
 rpython byte string, or it takes an :py:class:`unicode`
@@ -1552,6 +1555,7 @@
 On PyPy3 it takes a :py:class:`str` and it will return
 an utf-8 encoded rpython string.
 """
+assert w_obj is not None
 return w_obj.text_w(self)
 
 @not_rpython# tests only; should be replaced with bytes_w or text_w
@@ -1601,6 +1605,7 @@
 raise oefmt(self.w_ValueError, "byte must be in range(0, 256)")
 return chr(value)
 
+@specialize.argtype(1)
 def int_w(self, w_obj, allow_conversion=True):
 """
 Unwrap an app-level int object into an interpret-level int.
@@ -1613,29 +1618,40 @@
 If allow_conversion=False, w_obj needs to be an app-level int or a
 subclass.
 """
+assert w_obj is not None
 return w_obj.int_w(self, allow_conversion)
 
+@specialize.argtype(1)
 def int(self, w_obj):
+assert w_obj is not None
 return w_obj.int(self)
 
+@specialize.argtype(1)
 def uint_w(self, w_obj):
+assert w_obj is not None
 return w_obj.uint_w(self)
 
+@specialize.argtype(1)
 def bigint_w(self, w_obj, allow_conversion=True):
 """
 Like int_w, but return a rlib.rbigint object and call __long__ if
 allow_conversion is True.
 """
+assert w_obj is not None
 return w_obj.bigint_w(self, allow_conversion)
 
+@specialize.argtype(1)
 def float_w(self, w_obj, allow_conversion=True):
 """
 Like int_w, but return an interp-level float and call __float__ if
 allow_conversion is True.
 """
+assert w_obj is not None
 return w_obj.float_w(self, allow_conversion)
 
+@specialize.argtype(1)
 def unicode_w(self, w_obj):
+assert w_obj is not None
 return w_obj.unicode_w(self)
 
 def unicode0_w(self, w_obj):
@@ -1690,7 +1706,9 @@
 # this, but the general is_true(),  accepting any object.
 return bool(self.int_w(w_obj))
 
+@specialize.argtype(1)
 def ord(self, w_obj):
+assert w_obj is not None
 return w_obj.ord(self)
 
 # This is all interface for gateway.py.
diff --git a/pypy/module/_csv/interp_csv.py b/pypy/module/_csv/interp_csv.py
--- a/pypy/module/_csv/interp_csv.py
+++ b/pypy/module/_csv/interp_csv.py
@@ -29,10 +29,15 @@
 return default
 return space.is_true(w_src)
 
-def _get_int(space, w_src, default):
+def _get_int(space, w_src, default, attrname):
 if w_src is None:
 return default
-return space.int_w(w_src)
+try:
+return space.int_w(w_src)
+except OperationError as e:
+if e.match(space, space.w_TypeError):
+raise oefmt(space.w_TypeError, '"%s" must be a string', attrname)
+raise
 
 def _get_str(space, w_src, default, attrname):
 if w_src is None:
@@ -100,7 +105,7 @@
 dialect.escapechar = _get_char(space, w_escapechar, u'\0', 'escapechar')
 dialect.lineterminator = _get_str(space, w_lineterminator, u'\r\n', 
'lineterminator')
 dialect.quotechar = _get_char(space, w_quotechar, u'"', 'quotechar')
-tmp_quoting = _get_int(space, w_quoting, QUOTE_MINIMAL)
+tmp_quoting = _get_int(space, w_quoting, QUOTE_MINIMAL, 'quoting')
 dialect.skipinitialspace = _get_bool(space, w_skipinitialspace, False)
 dialect.strict = _get_bool(space, w_strict, False)
 
diff --git a/pypy/module/_csv/test/test_dialect.py 
b/pypy/module/_csv/test/test_dialect.py
--- a/pypy/module/_csv/test/test_dialect.py
+++ b/pypy/module/_csv/test/test_dialect.py
@@ -65,7 +65,8 @@

[pypy-commit] pypy py3.5: hg merge default

2017-09-03 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92312:965ce7010d54
Date: 2017-09-03 16:44 +0100
http://bitbucket.org/pypy/pypy/changeset/965ce7010d54/

Log:hg merge default

diff --git a/lib-python/2.7/ctypes/test/test_byteswap.py 
b/lib-python/2.7/ctypes/test/test_byteswap.py
--- a/lib-python/2.7/ctypes/test/test_byteswap.py
+++ b/lib-python/2.7/ctypes/test/test_byteswap.py
@@ -23,7 +23,6 @@
 setattr(bits, "i%s" % i, 1)
 dump(bits)
 
-@xfail
 def test_endian_short(self):
 if sys.byteorder == "little":
 self.assertIs(c_short.__ctype_le__, c_short)
@@ -51,7 +50,6 @@
 self.assertEqual(bin(s), "3412")
 self.assertEqual(s.value, 0x1234)
 
-@xfail
 def test_endian_int(self):
 if sys.byteorder == "little":
 self.assertIs(c_int.__ctype_le__, c_int)
@@ -80,7 +78,6 @@
 self.assertEqual(bin(s), "78563412")
 self.assertEqual(s.value, 0x12345678)
 
-@xfail
 def test_endian_longlong(self):
 if sys.byteorder == "little":
 self.assertIs(c_longlong.__ctype_le__, c_longlong)
@@ -109,7 +106,6 @@
 self.assertEqual(bin(s), "EFCDAB9078563412")
 self.assertEqual(s.value, 0x1234567890ABCDEF)
 
-@xfail
 def test_endian_float(self):
 if sys.byteorder == "little":
 self.assertIs(c_float.__ctype_le__, c_float)
@@ -128,7 +124,6 @@
 self.assertAlmostEqual(s.value, math.pi, 6)
 self.assertEqual(bin(struct.pack(">f", math.pi)), bin(s))
 
-@xfail
 def test_endian_double(self):
 if sys.byteorder == "little":
 self.assertIs(c_double.__ctype_le__, c_double)
@@ -156,7 +151,6 @@
 self.assertIs(c_char.__ctype_le__, c_char)
 self.assertIs(c_char.__ctype_be__, c_char)
 
-@xfail
 def test_struct_fields_1(self):
 if sys.byteorder == "little":
 base = BigEndianStructure
@@ -192,7 +186,6 @@
 pass
 self.assertRaises(TypeError, setattr, T, "_fields_", [("x", typ)])
 
-@xfail
 def test_struct_struct(self):
 # nested structures with different byteorders
 
@@ -221,7 +214,6 @@
 self.assertEqual(s.point.x, 1)
 self.assertEqual(s.point.y, 2)
 
-@xfail
 def test_struct_fields_2(self):
 # standard packing in struct uses no alignment.
 # So, we have to align using pad bytes.
@@ -245,7 +237,6 @@
 s2 = struct.pack(fmt, 0x12, 0x1234, 0x12345678, 3.14)
 self.assertEqual(bin(s1), bin(s2))
 
-@xfail
 def test_unaligned_nonnative_struct_fields(self):
 if sys.byteorder == "little":
 base = BigEndianStructure
diff --git a/lib-python/2.7/ctypes/test/test_unaligned_structures.py 
b/lib-python/2.7/ctypes/test/test_unaligned_structures.py
--- a/lib-python/2.7/ctypes/test/test_unaligned_structures.py
+++ b/lib-python/2.7/ctypes/test/test_unaligned_structures.py
@@ -37,10 +37,7 @@
 for typ in byteswapped_structures:
 ##print >> sys.stderr, typ.value
 self.assertEqual(typ.value.offset, 1)
-try:
-o = typ()
-except NotImplementedError as e:
-self.skipTest(str(e))# for PyPy
+o = typ()
 o.value = 4
 self.assertEqual(o.value, 4)
 
diff --git a/lib_pypy/_ctypes/pointer.py b/lib_pypy/_ctypes/pointer.py
--- a/lib_pypy/_ctypes/pointer.py
+++ b/lib_pypy/_ctypes/pointer.py
@@ -141,6 +141,10 @@
 ptr._buffer = tp._ffiarray(1, autofree=True)
 ptr._buffer[0] = obj._buffer
 result = ptr
+elif isinstance(obj, bytes):
+result = tp()
+result._buffer[0] = buffer(obj)._pypy_raw_address()
+return result
 elif not (isinstance(obj, _CData) and type(obj)._is_pointer_like()):
 raise TypeError("cast() argument 1 must be a pointer, not %s"
 % (type(obj),))
diff --git a/lib_pypy/_ctypes/primitive.py b/lib_pypy/_ctypes/primitive.py
--- a/lib_pypy/_ctypes/primitive.py
+++ b/lib_pypy/_ctypes/primitive.py
@@ -61,6 +61,54 @@
 
 pyobj_container = GlobalPyobjContainer()
 
+def swap_bytes(value, sizeof, typeof, get_or_set):
+def swap_2():
+return ((value >> 8) & 0x00FF) | ((value << 8) & 0xFF00)
+
+def swap_4():
+return ((value & 0x00FF) << 24) | \
+   ((value & 0xFF00) << 8) | \
+   ((value & 0x00FF) >> 8) | \
+   ((value >> 24) & 0xFF)
+
+def swap_8():
+return ((value & 0x00FFL) << 56) | \
+   ((value & 0xFF00L) << 40) | \
+   ((value & 0x00FFL) << 24) | \
+   ((value & 0xFF00L) << 8) | \
+   ((value & 0x00FFL) >> 8) | \
+   ((value & 0xFF00L) >> 24) | \
+   ((value & 0x00FFL) >> 40) | \
+   ((value >> 56) & 0xFF)
+
+  

[pypy-commit] pypy py3.5: hg merge default

2017-08-23 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r92238:89b8fc097575
Date: 2017-08-23 19:05 +0200
http://bitbucket.org/pypy/pypy/changeset/89b8fc097575/

Log:hg merge default

diff --git a/pypy/module/cpyext/include/object.h 
b/pypy/module/cpyext/include/object.h
--- a/pypy/module/cpyext/include/object.h
+++ b/pypy/module/cpyext/include/object.h
@@ -269,6 +269,11 @@
 #define _PyGC_FINALIZED(o) 1
 #define PyType_IS_GC(tp) 1
 
+#define PyObject_GC_Track(o)  do { } while(0)
+#define PyObject_GC_UnTrack(o)do { } while(0)
+#define _PyObject_GC_TRACK(o) do { } while(0)
+#define _PyObject_GC_UNTRACK(o)   do { } while(0)
+
 /* Utility macro to help write tp_traverse functions.
  * To use this macro, the tp_traverse function must name its arguments
  * "visit" and "arg".  This is intended to keep tp_traverse functions
diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
--- a/pypy/module/cpyext/object.py
+++ b/pypy/module/cpyext/object.py
@@ -80,24 +80,6 @@
 def PyObject_GC_Del(space, obj):
 PyObject_Free(space, obj)
 
-@cpython_api([rffi.VOIDP], lltype.Void)
-def PyObject_GC_Track(space, op):
-"""Adds the object op to the set of container objects tracked by the
-collector.  The collector can run at unexpected times so objects must be
-valid while being tracked.  This should be called once all the fields
-followed by the tp_traverse handler become valid, usually near the
-end of the constructor."""
-pass
-
-@cpython_api([rffi.VOIDP], lltype.Void)
-def PyObject_GC_UnTrack(space, op):
-"""Remove the object op from the set of container objects tracked by the
-collector.  Note that PyObject_GC_Track() can be called again on
-this object to add it back to the set of tracked objects.  The deallocator
-(tp_dealloc handler) should call this for the object before any of
-the fields used by the tp_traverse handler become invalid."""
-pass
-
 @cpython_api([PyObject], PyObjectP, error=CANNOT_FAIL)
 def _PyObject_GetDictPtr(space, op):
 return lltype.nullptr(PyObjectP.TO)
diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py
--- a/pypy/module/cpyext/stubs.py
+++ b/pypy/module/cpyext/stubs.py
@@ -625,18 +625,6 @@
 resized object or NULL on failure."""
 raise NotImplementedError
 
-@cpython_api([PyObject], lltype.Void)
-def _PyObject_GC_TRACK(space, op):
-"""A macro version of PyObject_GC_Track().  It should not be used for
-extension modules."""
-raise NotImplementedError
-
-@cpython_api([PyObject], lltype.Void)
-def _PyObject_GC_UNTRACK(space, op):
-"""A macro version of PyObject_GC_UnTrack().  It should not be used for
-extension modules."""
-raise NotImplementedError
-
 @cpython_api([PyFrameObject], PyObject)
 def PyGen_New(space, frame):
 """Create and return a new generator object based on the frame object. A
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-08-23 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r92235:d4535b1f44cd
Date: 2017-08-23 18:55 +0200
http://bitbucket.org/pypy/pypy/changeset/d4535b1f44cd/

Log:hg merge default

diff --git a/lib-python/2.7/ctypes/__init__.py 
b/lib-python/2.7/ctypes/__init__.py
--- a/lib-python/2.7/ctypes/__init__.py
+++ b/lib-python/2.7/ctypes/__init__.py
@@ -364,7 +364,7 @@
 pypy_dll = _ffi.CDLL(name, mode)
 else:
 pypy_dll = _ffi.WinDLL(name, mode)
-self._pypy_dll = pypy_dll
+self.__pypy_dll__ = pypy_dll
 handle = int(pypy_dll)
 if _sys.maxint > 2 ** 32:
 handle = int(handle)   # long -> int
diff --git a/lib_pypy/_ctypes/basics.py b/lib_pypy/_ctypes/basics.py
--- a/lib_pypy/_ctypes/basics.py
+++ b/lib_pypy/_ctypes/basics.py
@@ -82,7 +82,7 @@
 return False
 
 def in_dll(self, dll, name):
-return self.from_address(dll._pypy_dll.getaddressindll(name))
+return self.from_address(dll.__pypy_dll__.getaddressindll(name))
 
 def from_buffer(self, obj, offset=0):
 size = self._sizeofinstances()
diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -430,7 +430,7 @@
 ffires = restype.get_ffi_argtype()
 return _ffi.FuncPtr.fromaddr(ptr, '', ffiargs, ffires, 
self._flags_)
 
-cdll = self.dll._pypy_dll
+cdll = self.dll.__pypy_dll__
 try:
 ffi_argtypes = [argtype.get_ffi_argtype() for argtype in argtypes]
 ffi_restype = restype.get_ffi_argtype()
diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
--- a/pypy/module/cpyext/object.py
+++ b/pypy/module/cpyext/object.py
@@ -311,7 +311,7 @@
 PyErr_BadInternalCall(space)
 
 @cpython_api([PyObject, PyObject, rffi.INT_real], rffi.INT_real, error=-1)
-def PyObject_RichCompareBool(space, ref1, ref2, opid_int):
+def PyObject_RichCompareBool(space, w_o1, w_o2, opid_int):
 """Compare the values of o1 and o2 using the operation specified by opid,
 which must be one of Py_LT, Py_LE, Py_EQ,
 Py_NE, Py_GT, or Py_GE, corresponding to <,
@@ -321,13 +321,13 @@
 opid."""
 # Quick result when objects are the same.
 # Guarantees that identity implies equality.
-if ref1 is ref2:
+if space.is_w(w_o1, w_o2):
 opid = rffi.cast(lltype.Signed, opid_int)
 if opid == Py_EQ:
 return 1
 if opid == Py_NE:
 return 0 
-w_res = PyObject_RichCompare(space, ref1, ref2, opid_int)
+w_res = PyObject_RichCompare(space, w_o1, w_o2, opid_int)
 return int(space.is_true(w_res))
 
 @cpython_api([PyObject], PyObject, result_is_ll=True)
diff --git a/pypy/module/cpyext/sequence.py b/pypy/module/cpyext/sequence.py
--- a/pypy/module/cpyext/sequence.py
+++ b/pypy/module/cpyext/sequence.py
@@ -294,6 +294,23 @@
 def getitems_fixedsize(self, w_list):
 return self.getitems_unroll(w_list)
 
+def copy_into(self, w_list, w_other):
+w_other.strategy = self
+w_other.lstorage = self.getstorage_copy(w_list)
+
+def clone(self, w_list):
+storage = self.getstorage_copy(w_list)
+w_clone = W_ListObject.from_storage_and_strategy(self.space, storage,
+ self)
+return w_clone
+
+def getitems_copy(self, w_list):
+return self.getitems(w_list) # getitems copies anyway
+
+def getstorage_copy(self, w_list):
+lst = self.getitems(w_list)
+return self.erase(CPyListStorage(w_list.space, lst))
+
 #--
 # all these methods fail or switch strategy and then call 
ListObjectStrategy's method
 
@@ -301,23 +318,9 @@
 w_list.switch_to_object_strategy()
 w_list.strategy.setslice(w_list, start, stop, step, length)
 
-def get_sizehint(self):
-return -1
-
 def init_from_list_w(self, w_list, list_w):
 raise NotImplementedError
 
-def clone(self, w_list):
-storage = w_list.lstorage  # lstorage is tuple, no need to clone
-w_clone = W_ListObject.from_storage_and_strategy(self.space, storage,
- self)
-w_clone.switch_to_object_strategy()
-return w_clone
-
-def copy_into(self, w_list, w_other):
-w_list.switch_to_object_strategy()
-w_list.strategy.copy_into(w_list, w_other)
-
 def _resize_hint(self, w_list, hint):
 pass
 
@@ -325,13 +328,6 @@
 w_list.switch_to_object_strategy()
 return w_list.strategy.find(w_list, w_item, start, stop)
 
-def getitems_copy(self, w_list):
-w_list.switch_to_object_strategy()
-return w_list.strategy.getitems_copy(w_list)
-
-def getstorage_copy(self, w_list):
-raise NotImplementedError
-
 def append(self, w_list, 

[pypy-commit] pypy py3.5: hg merge default

2017-08-18 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92166:90593ef2b17c
Date: 2017-08-18 16:28 +0200
http://bitbucket.org/pypy/pypy/changeset/90593ef2b17c/

Log:hg merge default

diff --git a/lib-python/2.7/ctypes/__init__.py 
b/lib-python/2.7/ctypes/__init__.py
--- a/lib-python/2.7/ctypes/__init__.py
+++ b/lib-python/2.7/ctypes/__init__.py
@@ -361,17 +361,20 @@
 
 if handle is None:
 if flags & _FUNCFLAG_CDECL:
-self._handle = _ffi.CDLL(name, mode)
+pypy_dll = _ffi.CDLL(name, mode)
 else:
-self._handle = _ffi.WinDLL(name, mode)
-else:
-self._handle = handle
+pypy_dll = _ffi.WinDLL(name, mode)
+self._pypy_dll = pypy_dll
+handle = int(pypy_dll)
+if _sys.maxint > 2 ** 32:
+handle = int(handle)   # long -> int
+self._handle = handle
 
 def __repr__(self):
-return "<%s '%s', handle %r at 0x%x>" % (
-self.__class__.__name__, self._name, self._handle,
-id(self) & (_sys.maxint * 2 + 1))
-
+return "<%s '%s', handle %x at %x>" % \
+   (self.__class__.__name__, self._name,
+(self._handle & (_sys.maxint*2 + 1)),
+id(self) & (_sys.maxint*2 + 1))
 
 def __getattr__(self, name):
 if name.startswith('__') and name.endswith('__'):
diff --git a/lib_pypy/_ctypes/basics.py b/lib_pypy/_ctypes/basics.py
--- a/lib_pypy/_ctypes/basics.py
+++ b/lib_pypy/_ctypes/basics.py
@@ -82,7 +82,7 @@
 return False
 
 def in_dll(self, dll, name):
-return self.from_address(dll._handle.getaddressindll(name))
+return self.from_address(dll._pypy_dll.getaddressindll(name))
 
 def from_buffer(self, obj, offset=0):
 size = self._sizeofinstances()
diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -430,7 +430,7 @@
 ffires = restype.get_ffi_argtype()
 return _ffi.FuncPtr.fromaddr(ptr, '', ffiargs, ffires, 
self._flags_)
 
-cdll = self.dll._handle
+cdll = self.dll._pypy_dll
 try:
 ffi_argtypes = [argtype.get_ffi_argtype() for argtype in argtypes]
 ffi_restype = restype.get_ffi_argtype()
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -1632,7 +1632,7 @@
 assert cpyext_glob_tid_ptr[0] == 0
 cpyext_glob_tid_ptr[0] = tid
 
-preexist_error = PyErr_Occurred(space) is not None
+preexist_error = PyErr_Occurred(space)
 try:
 # Call the function
 result = call_external_function(func, *boxed_args)
@@ -1656,17 +1656,20 @@
 has_result = ret is not None
 
 # Check for exception consistency
-has_error = PyErr_Occurred(space) is not None
-if not preexist_error:
-if has_error and has_result:
-raise oefmt(space.w_SystemError,
-"An exception was set, but function returned a 
"
-"value")
-elif not expect_null and not has_error and not has_result:
-raise oefmt(space.w_SystemError,
-"Function returned a NULL result without 
setting "
-"an exception")
-if has_error:
+# XXX best attempt, will miss preexisting error that is
+# overwritten with a new error of the same type
+error = PyErr_Occurred(space)
+has_new_error = (error is not None) and (error is not 
preexist_error)
+has_result = ret is not None
+if not expect_null and has_new_error and has_result:
+raise oefmt(space.w_SystemError,
+"An exception was set, but function returned a "
+"value")
+elif not expect_null and not has_new_error and not has_result:
+raise oefmt(space.w_SystemError,
+"Function returned a NULL result without setting "
+"an exception")
+elif has_new_error:
 state = space.fromcache(State)
 state.check_and_raise_exception()
 
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
@@ -24,6 +24,10 @@
 def PyPy_Crash2(space):
 1/0
 
+@api.cpython_api([api.PyObject], api.PyObject, result_is_ll=True)
+def PyPy_Noop(space, pyobj):
+return pyobj
+
 class TestApi:
 def test_signature(self):
 common_functions = api.FUNCTIONS_BY_HEADER[api.pypy_decl]
@@ -665,6 +669,7 @@
 body = """
 

[pypy-commit] pypy py3.5: hg merge default

2017-08-14 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92151:fee5f0e18b17
Date: 2017-08-14 20:52 +0200
http://bitbucket.org/pypy/pypy/changeset/fee5f0e18b17/

Log:hg merge default

diff --git a/pypy/module/cpyext/src/modsupport.c 
b/pypy/module/cpyext/src/modsupport.c
--- a/pypy/module/cpyext/src/modsupport.c
+++ b/pypy/module/cpyext/src/modsupport.c
@@ -523,12 +523,10 @@
 return res;
 }
 
-/* returns -1 in case of error, 0 if a new key was added, 1 if the key
-   was already there (and replaced) */
-static int
-_PyModule_AddObject_NoConsumeRef(PyObject *m, const char *name, PyObject *o)
+int
+PyModule_AddObject(PyObject *m, const char *name, PyObject *o)
 {
-PyObject *dict, *prev;
+PyObject *dict;
 if (!PyModule_Check(m)) {
 PyErr_SetString(PyExc_TypeError,
 "PyModule_AddObject() needs module as first arg");
@@ -548,49 +546,34 @@
  PyModule_GetName(m));
 return -1;
 }
-prev = PyDict_GetItemString(dict, name);
 if (PyDict_SetItemString(dict, name, o))
 return -1;
-return prev != NULL;
-}
-
-int
-PyModule_AddObject(PyObject *m, const char *name, PyObject *o)
-{
-int result = _PyModule_AddObject_NoConsumeRef(m, name, o);
-/* XXX WORKAROUND for a common misusage of PyModule_AddObject:
-   for the common case of adding a new key, we don't consume a
-   reference, but instead just leak it away.  The issue is that
-   people generally don't realize that this function consumes a
-   reference, because on CPython the reference is still stored
-   on the dictionary. */
-if (result != 0)
-Py_DECREF(o);
-return result < 0 ? -1 : 0;
+Py_DECREF(o);
+return 0;
 }
 
 int
 PyModule_AddIntConstant(PyObject *m, const char *name, long value)
 {
-int result;
 PyObject *o = PyLong_FromLong(value);
 if (!o)
 return -1;
-result = _PyModule_AddObject_NoConsumeRef(m, name, o);
+if (PyModule_AddObject(m, name, o) == 0)
+return 0;
 Py_DECREF(o);
-return result < 0 ? -1 : 0;
+return -1;
 }
 
 int
 PyModule_AddStringConstant(PyObject *m, const char *name, const char *value)
 {
-int result;
 PyObject *o = PyUnicode_FromString(value);
 if (!o)
 return -1;
-result = _PyModule_AddObject_NoConsumeRef(m, name, o);
+if (PyModule_AddObject(m, name, o) == 0)
+return 0;
 Py_DECREF(o);
-return result < 0 ? -1 : 0;
+return -1;
 }
 
 PyModuleDef*
diff --git a/pypy/module/cpyext/test/test_capsule.py 
b/pypy/module/cpyext/test/test_capsule.py
--- a/pypy/module/cpyext/test/test_capsule.py
+++ b/pypy/module/cpyext/test/test_capsule.py
@@ -12,9 +12,6 @@
  if (PyErr_Occurred()) return NULL;
  module = PyImport_ImportModule("foo");
  PyModule_AddObject(module, "_ptr", capsule);
- #ifdef PYPY_VERSION
-   Py_DECREF(capsule);  /* XXX <--- anti-workaround */
- #endif
  Py_DECREF(module);
  if (PyErr_Occurred()) return NULL;
  Py_RETURN_NONE;
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-08-14 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r92149:90985eb27be1
Date: 2017-08-14 19:23 +0200
http://bitbucket.org/pypy/pypy/changeset/90985eb27be1/

Log:hg merge default

diff --git a/pypy/module/__builtin__/descriptor.py 
b/pypy/module/__builtin__/descriptor.py
--- a/pypy/module/__builtin__/descriptor.py
+++ b/pypy/module/__builtin__/descriptor.py
@@ -21,24 +21,31 @@
 
 if space.is_none(w_obj_or_type):
 w_type = None  # unbound super object
-w_obj_or_type = space.w_None
+w_obj_or_type = None
 else:
 w_type = _super_check(space, w_starttype, w_obj_or_type)
 self.w_starttype = w_starttype
 self.w_objtype = w_type
-self.w_self = w_obj_or_type
+self.w_self = w_obj_or_type  # may be None
 
 def descr_repr(self, space):
 if self.w_objtype is not None:
 objtype_name = u"<%s object>" % self.w_objtype.getname(space)
 else:
 objtype_name = u'NULL'
+if self.w_starttype is not None:
+starttype_name = self.w_starttype.getname(space)
+else:
+starttype_name = u'NULL'
 return space.newunicode(u", %s>" % (
-self.w_starttype.getname(space), objtype_name))
+starttype_name, objtype_name))
 
 def get(self, space, w_obj, w_type=None):
-if self.w_self is None or space.is_w(w_obj, space.w_None):
+if self.w_self is not None or space.is_w(w_obj, space.w_None):
 return self
+if self.w_starttype is None:
+raise oefmt(space.w_TypeError,
+"__get__(x) is invalid on an uninitialized instance of 
'super'")
 else:
 # if type(self) is W_Super:
 # XXX write a fast path for this common case
@@ -50,6 +57,7 @@
 # only use a special logic for bound super objects and not for
 # getting the __class__ of the super object itself.
 if self.w_objtype is not None and name != '__class__':
+assert self.w_starttype is not None
 w_value = space.lookup_in_type_starting_at(self.w_objtype,
self.w_starttype,
name)
@@ -59,10 +67,9 @@
 return w_value
 # Only pass 'obj' param if this is instance-mode super
 # (see CPython sourceforge id #743627)
-if self.w_self is self.w_objtype:
+w_obj = self.w_self
+if w_obj is None or w_obj is self.w_objtype:
 w_obj = space.w_None
-else:
-w_obj = self.w_self
 return space.get_and_call_function(w_get, w_value,
w_obj, self.w_objtype)
 # fallback to object.__getattribute__()
@@ -160,7 +167,11 @@
 _immutable_fields_ = ["w_fget", "w_fset", "w_fdel"]
 
 def __init__(self, space):
-pass
+self.w_fget = space.w_None
+self.w_fset = space.w_None
+self.w_fdel = space.w_None
+self.w_doc = space.w_None
+self.getter_doc = False
 
 @unwrap_spec(w_fget=WrappedDefault(None),
  w_fset=WrappedDefault(None),
diff --git a/pypy/module/__builtin__/test/test_descriptor.py 
b/pypy/module/__builtin__/test/test_descriptor.py
--- a/pypy/module/__builtin__/test/test_descriptor.py
+++ b/pypy/module/__builtin__/test/test_descriptor.py
@@ -333,6 +333,22 @@
 assert repr(A()).endswith('>!')
 assert repr(super(A, A())) == ", >"
 
+def test_super_get_corner_case(self):
+class A(object):
+pass
+s1 = super(A, A())
+assert s1.__get__(42) is s1
+assert s1.__get__(42, int) is s1
+s2 = super(A)
+assert s2.__get__(None, "anything") is s2
+#
+assert s1.__get__(None, "anything") is s1
+raises(TypeError, s2.__get__, 42)
+raises(TypeError, s2.__get__, 42, int)
+a = A()
+assert s2.__get__(a).__self__ is a
+assert s1.__get__(a) is s1
+
 def test_property_docstring(self):
 assert property.__doc__.startswith('property')
 
@@ -520,3 +536,35 @@
 super()
 raises(RuntimeError, X().f)
 """
+
+def test_uninitialized_property(self):
+p = property.__new__(property)
+raises(AttributeError, p.__get__, 42)
+raises(AttributeError, p.__set__, 42, None)
+raises(AttributeError, p.__delete__, 42)
+assert repr(p).startswith("https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-08-12 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92136:02ab6e8e42e8
Date: 2017-08-12 20:35 +0200
http://bitbucket.org/pypy/pypy/changeset/02ab6e8e42e8/

Log:hg merge default

diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -73,6 +73,8 @@
 
 if "_cppyy" in working_modules:
 working_modules.remove("_cppyy")  # not tested on win32
+if "_vmprof" in working_modules:
+working_modules.remove("_vmprof")  # FIXME: missing details
 
 # The _locale module is needed by site.py on Windows
 default_modules.add("_locale")
diff --git a/rpython/translator/c/src/signals.c 
b/rpython/translator/c/src/signals.c
--- a/rpython/translator/c/src/signals.c
+++ b/rpython/translator/c/src/signals.c
@@ -74,6 +74,7 @@
 }
 
 #ifdef _WIN32
+#include 
 #define atomic_cas(ptr, oldv, newv)   (InterlockedCompareExchange(ptr, \
 newv, oldv) == (oldv))
 #else
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-08-11 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92123:ca42f6a90f18
Date: 2017-08-11 17:36 +0200
http://bitbucket.org/pypy/pypy/changeset/ca42f6a90f18/

Log:hg merge default

diff --git a/lib-python/2.7/distutils/sysconfig_pypy.py 
b/lib-python/2.7/distutils/sysconfig_pypy.py
--- a/lib-python/2.7/distutils/sysconfig_pypy.py
+++ b/lib-python/2.7/distutils/sysconfig_pypy.py
@@ -218,6 +218,10 @@
 
 compiler.shared_lib_extension = so_ext
 
+def get_config_h_filename():
+"""Returns the path of pyconfig.h."""
+inc_dir = get_python_inc(plat_specific=1)
+return os.path.join(inc_dir, 'pyconfig.h')
 
 from sysconfig_cpython import (
 parse_makefile, _variable_rx, expand_makefile_vars)
diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py
--- a/lib_pypy/_ctypes/structure.py
+++ b/lib_pypy/_ctypes/structure.py
@@ -40,6 +40,22 @@
 else:
 rawfields.append((f[0], f[1]._ffishape_))
 
+# hack for duplicate field names
+already_seen = set()
+names1 = names
+names = []
+for f in names1:
+if f not in already_seen:
+names.append(f)
+already_seen.add(f)
+already_seen = set()
+for i in reversed(range(len(rawfields))):
+if rawfields[i][0] in already_seen:
+rawfields[i] = (('$DUP%d$%s' % (i, rawfields[i][0]),)
++ rawfields[i][1:])
+already_seen.add(rawfields[i][0])
+# /hack
+
 _set_shape(self, rawfields, self._is_union)
 
 fields = {}
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
@@ -62,7 +62,7 @@
 throwing away information about them less eagerly.
 
 
-.. branch: getarrayitem-into-bridges:
+.. branch: getarrayitem-into-bridges
 
 More information is retained into a bridge: knowledge about the content of
 arrays (at fixed indices) is stored in guards (and thus available at the
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -1632,6 +1632,7 @@
 assert cpyext_glob_tid_ptr[0] == 0
 cpyext_glob_tid_ptr[0] = tid
 
+preexist_error = PyErr_Occurred(space) is not None
 try:
 # Call the function
 result = call_external_function(func, *boxed_args)
@@ -1656,15 +1657,15 @@
 
 # Check for exception consistency
 has_error = PyErr_Occurred(space) is not None
-if has_error and has_result:
-raise oefmt(space.w_SystemError,
-"An exception was set, but function returned a "
-"value")
-elif not expect_null and not has_error and not has_result:
-raise oefmt(space.w_SystemError,
-"Function returned a NULL result without setting "
-"an exception")
-
+if not preexist_error:
+if has_error and has_result:
+raise oefmt(space.w_SystemError,
+"An exception was set, but function returned a 
"
+"value")
+elif not expect_null and not has_error and not has_result:
+raise oefmt(space.w_SystemError,
+"Function returned a NULL result without 
setting "
+"an exception")
 if has_error:
 state = space.fromcache(State)
 state.check_and_raise_exception()
diff --git a/pypy/module/cpyext/methodobject.py 
b/pypy/module/cpyext/methodobject.py
--- a/pypy/module/cpyext/methodobject.py
+++ b/pypy/module/cpyext/methodobject.py
@@ -203,6 +203,10 @@
 def cmethod_descr_call(space, w_self, __args__):
 self = space.interp_w(W_PyCFunctionObject, w_self)
 args_w, kw_w = __args__.unpack()
+if len(args_w) < 1:
+raise oefmt(space.w_TypeError,
+"descriptor '%s' of '%s' object needs an argument",
+self.name, self.w_objclass.getname(space))
 w_instance = args_w[0] # XXX typecheck missing
 w_args = space.newtuple(args_w[1:])
 w_kw = space.newdict()
diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
--- a/pypy/module/cpyext/object.py
+++ b/pypy/module/cpyext/object.py
@@ -311,7 +311,7 @@
 PyErr_BadInternalCall(space)
 
 @cpython_api([PyObject, PyObject, rffi.INT_real], rffi.INT_real, error=-1)
-def PyObject_RichCompareBool(space, ref1, ref2, opid):
+def PyObject_RichCompareBool(space, ref1, ref2, opid_int):
 """Compare the values of o1 and o2 using the operation specified by opid,
 which must be one of Py_LT, Py_LE, Py_EQ,
 Py_NE, Py_GT, or Py_GE, corresponding to <,
@@ -319,7 +319,15 @@
 0 if the result is false, 1 otherwise. This is the equivalent of the
 Python expression o1 op o2, where op is the operator 

[pypy-commit] pypy py3.5: hg merge default

2017-08-06 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r92100:45907003511b
Date: 2017-08-06 15:37 +0100
http://bitbucket.org/pypy/pypy/changeset/45907003511b/

Log:hg 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
@@ -60,3 +60,16 @@
 
 Small improvement to optimize list accesses with constant indexes better by
 throwing away information about them less eagerly.
+
+
+.. branch: getarrayitem-into-bridges:
+
+More information is retained into a bridge: knowledge about the content of
+arrays (at fixed indices) is stored in guards (and thus available at the
+beginning of bridges). Also, some better feeding of information about known
+fields of constant objects into bridges.
+
+.. branch: cpyext-leakchecking
+
+Add support for leakfinder in cpyext tests (disabled for now, due to too many
+failures).
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1,4 +1,5 @@
 import sys
+import py
 
 from rpython.rlib.cache import Cache
 from rpython.tool.uid import HUGEVAL_BYTES
@@ -1271,8 +1272,22 @@
 self.setitem(w_globals, w_key, self.builtin)
 return statement.exec_code(self, w_globals, w_locals)
 
+@not_rpython
+def appdef(self, source):
+'''Create interp-level function object from app-level source.
+
+The source should be in the same format as for space.appexec():
+"""(foo, bar): return 'baz'"""
+'''
+source = source.lstrip()
+assert source.startswith('('), "incorrect header in:\n%s" % (source,)
+source = py.code.Source("def anonymous%s\n" % source)
+w_glob = self.newdict(module=True)
+self.exec_(str(source), w_glob, w_glob)
+return self.getitem(w_glob, self.newtext('anonymous'))
+
 @specialize.arg(2)
-def appexec(self, posargs_w, source):
+def appexec(self, posargs_w, source, cache=True):
 """ return value from executing given source at applevel.
 The source must look like
'''(x, y):
@@ -1280,7 +1295,11 @@
return result
'''
 """
-w_func = self.fromcache(AppExecCache).getorbuild(source)
+if cache:
+w_func = self.fromcache(AppExecCache).getorbuild(source)
+else:
+# NB: since appdef() is not-RPython, using cache=False also is.
+w_func = self.appdef(source)
 args = Arguments(self, list(posargs_w))
 return self.call_args(w_func, args)
 
@@ -1817,15 +1836,7 @@
 class AppExecCache(SpaceCache):
 @not_rpython
 def build(cache, source):
-space = cache.space
-# XXX will change once we have our own compiler
-import py
-source = source.lstrip()
-assert source.startswith('('), "incorrect header in:\n%s" % (source,)
-source = py.code.Source("def anonymous%s\n" % source)
-w_glob = space.newdict(module=True)
-space.exec_(str(source), w_glob, w_glob)
-return space.getitem(w_glob, space.newtext('anonymous'))
+return cache.space.appdef(source)
 
 
 # Table describing the regular part of the interface of object spaces,
diff --git a/pypy/module/cpyext/buffer.py b/pypy/module/cpyext/buffer.py
--- a/pypy/module/cpyext/buffer.py
+++ b/pypy/module/cpyext/buffer.py
@@ -84,22 +84,27 @@
 if self.needs_decref:
 if self.releasebufferproc:
 func_target = rffi.cast(releasebufferproc, 
self.releasebufferproc)
-with lltype.scoped_alloc(Py_buffer) as pybuf:
-pybuf.c_buf = self.ptr
-pybuf.c_len = self.size
-pybuf.c_ndim = cts.cast('int', self.ndim)
-pybuf.c_shape = cts.cast('Py_ssize_t*', pybuf.c__shape)
-pybuf.c_strides = cts.cast('Py_ssize_t*', 
pybuf.c__strides)
-for i in range(self.ndim):
-pybuf.c_shape[i] = self.shape[i]
-pybuf.c_strides[i] = self.strides[i]
-if self.format:
-pybuf.c_format = rffi.str2charp(self.format)
-else:
-pybuf.c_format = rffi.str2charp("B")
+size = rffi.sizeof(cts.gettype('Py_buffer'))
+pybuf = lltype.malloc(rffi.VOIDP.TO, size, flavor='raw', 
zero=True)
+pybuf = cts.cast('Py_buffer*', pybuf)
+pybuf.c_buf = self.ptr
+pybuf.c_len = self.size
+pybuf.c_ndim = cts.cast('int', self.ndim)
+pybuf.c_shape = cts.cast('Py_ssize_t*', pybuf.c__shape)
+pybuf.c_strides = cts.cast('Py_ssize_t*', pybuf.c__strides)
+ 

[pypy-commit] pypy py3.5: hg merge default

2017-07-31 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r91998:2ae11d0d2965
Date: 2017-07-31 14:13 +0200
http://bitbucket.org/pypy/pypy/changeset/2ae11d0d2965/

Log:hg 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
@@ -5,6 +5,14 @@
 .. this is a revision shortly after release-pypy2.7-v5.8.0
 .. startrev: 558bd00b3dd8
 
+In previous versions of PyPy, ``instance.method`` would return always
+the same bound method object, when gotten out of the same instance (as
+far as ``is`` and ``id()`` can tell).  CPython doesn't do that.  Now
+PyPy, like CPython, returns a different bound method object every time.
+For ``type.method``, PyPy2 still returns always the same *unbound*
+method object; CPython does it for built-in types but not for
+user-defined types.
+
 .. branch: cffi-complex
 .. branch: cffi-char16-char32
 
diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -2,8 +2,7 @@
 
 from rpython.rlib import jit
 from rpython.rlib.objectmodel import (
-compute_hash, compute_unique_id, import_from_mixin, newlist_hint,
-resizelist_hint)
+compute_hash, compute_unique_id, import_from_mixin)
 from rpython.rlib.rstring import StringBuilder
 
 from pypy.interpreter.baseobjspace import W_Root
@@ -751,14 +750,40 @@
 return _from_byte_sequence(space, w_source)
 
 
+def _get_printable_location(w_type):
+return ('bytearray_from_byte_sequence [w_type=%s]' %
+w_type.getname(w_type.space))
+
+_byteseq_jitdriver = jit.JitDriver(
+name='bytearray_from_byte_sequence',
+greens=['w_type'],
+reds=['w_iter', 'builder'],
+get_printable_location=_get_printable_location)
+
 def _from_byte_sequence(space, w_source):
 # Split off in a separate function for the JIT's benefit
-w_result = space.appexec([w_source], """(seq):
-result = bytearray()
-for i in seq:
-result.append(i)
-return result""")
-return ''.join(w_result.getdata())
+# and add a jitdriver with the type of w_iter as the green key
+w_iter = space.iter(w_source)
+length_hint = space.length_hint(w_source, 0)
+builder = StringBuilder(length_hint)
+#
+_from_byte_sequence_loop(space, w_iter, builder)
+#
+return builder.build()
+
+def _from_byte_sequence_loop(space, w_iter, builder):
+w_type = space.type(w_iter)
+while True:
+_byteseq_jitdriver.jit_merge_point(w_type=w_type,
+   w_iter=w_iter,
+   builder=builder)
+try:
+w_item = space.next(w_iter)
+except OperationError as e:
+if not e.match(space, space.w_StopIteration):
+raise
+break
+builder.append(space.byte_w(w_item))
 
 W_BytesObject.typedef = TypeDef(
 "bytes", None, None, "read",
diff --git a/pypy/objspace/std/test/test_bytearrayobject.py 
b/pypy/objspace/std/test/test_bytearrayobject.py
--- a/pypy/objspace/std/test/test_bytearrayobject.py
+++ b/pypy/objspace/std/test/test_bytearrayobject.py
@@ -466,6 +466,13 @@
 raises(TypeError, b.extend, [object()])
 raises(TypeError, b.extend, "unicode")
 
+def test_extend_calls_len_or_lengthhint(self):
+class BadLen(object):
+def __iter__(self): return iter(range(10))
+def __len__(self): raise RuntimeError('hello')
+b = bytearray()
+raises(RuntimeError, b.extend, BadLen())
+
 def test_setitem_from_front(self):
 b = bytearray(b'abcdefghij')
 b[:2] = b''
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
@@ -2308,6 +2308,7 @@
 ll_assert(not (self.probably_young_objects_with_finalizers
.non_empty()),
 "probably_young_objects_with_finalizers should be empty")
+self.kept_alive_by_finalizer = r_uint(0)
 if self.old_objects_with_finalizers.non_empty():
 self.deal_with_objects_with_finalizers()
 elif self.old_objects_with_weakrefs.non_empty():
@@ -2380,6 +2381,9 @@
 # we currently have -- but no more than 'max_delta' more than
 # we currently have.
 total_memory_used = float(self.get_total_memory_used())
+total_memory_used -= float(self.kept_alive_by_finalizer)
+if total_memory_used < 0:
+total_memory_used = 0
 bounded = self.set_major_threshold_from(
 min(total_memory_used * self.major_collection_threshold,
 total_memory_used + self.max_delta),
@@ -2418,7 +2422,7 @@
 

[pypy-commit] pypy py3.5: hg merge default

2017-07-28 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r91988:b4c040585955
Date: 2017-07-28 15:33 +0100
http://bitbucket.org/pypy/pypy/changeset/b4c040585955/

Log:hg merge default

diff too long, truncating to 2000 out of 19088 lines

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -27,16 +27,17 @@
 ^pypy/module/cpyext/test/.+\.manifest$
 ^pypy/module/test_lib_pypy/ctypes_tests/.+\.o$
 ^pypy/module/test_lib_pypy/ctypes_tests/_ctypes_test\.o$
-^pypy/module/cppyy/src/.+\.o$
-^pypy/module/cppyy/bench/.+\.so$
-^pypy/module/cppyy/bench/.+\.root$
-^pypy/module/cppyy/bench/.+\.d$
-^pypy/module/cppyy/src/.+\.errors$
-^pypy/module/cppyy/test/.+_rflx\.cpp$
-^pypy/module/cppyy/test/.+\.so$
-^pypy/module/cppyy/test/.+\.rootmap$
-^pypy/module/cppyy/test/.+\.exe$
-^pypy/module/cppyy/test/.+_cint.h$
+^pypy/module/_cppyy/src/.+\.o$
+^pypy/module/_cppyy/bench/.+\.so$
+^pypy/module/_cppyy/bench/.+\.root$
+^pypy/module/_cppyy/bench/.+\.d$
+^pypy/module/_cppyy/src/.+\.errors$
+^pypy/module/_cppyy/test/.+_rflx\.cpp$
+^pypy/module/_cppyy/test/.+\.so$
+^pypy/module/_cppyy/test/.+\.rootmap$
+^pypy/module/_cppyy/test/.+\.exe$
+^pypy/module/_cppyy/test/.+_cint.h$
+^pypy/module/_cppyy/.+/*\.pcm$
 ^pypy/module/test_lib_pypy/cffi_tests/__pycache__.+$
 ^pypy/doc/.+\.html$
 ^pypy/doc/config/.+\.rst$
@@ -93,6 +94,3 @@
 ^release/
 ^rpython/_cache$
 
-pypy/module/cppyy/.+/*\.pcm
-
-
diff --git a/lib_pypy/_tkinter/tklib_build.py b/lib_pypy/_tkinter/tklib_build.py
--- a/lib_pypy/_tkinter/tklib_build.py
+++ b/lib_pypy/_tkinter/tklib_build.py
@@ -22,12 +22,27 @@
 linklibs = ['tcl', 'tk']
 libdirs = []
 else:
-for _ver in ['', '8.6', '8.5', '']:
+# On some Linux distributions, the tcl and tk libraries are
+# stored in /usr/include, so we must check this case also
+libdirs = []
+found = False
+for _ver in ['', '8.6', '8.5']:
 incdirs = ['/usr/include/tcl' + _ver]
 linklibs = ['tcl' + _ver, 'tk' + _ver]
-libdirs = []
 if os.path.isdir(incdirs[0]):
+found = True
 break
+if not found:
+for _ver in ['8.6', '8.5', '']:
+incdirs = []
+linklibs = ['tcl' + _ver, 'tk' + _ver]
+if os.path.isfile(''.join(['/usr/lib/lib', linklibs[1], '.so'])):
+found = True
+break
+if not found:
+sys.stderr.write("*** TCL libraries not found!  Falling back...\n")
+incdirs = []
+linklibs = ['tcl', 'tk']
 
 config_ffi = FFI()
 config_ffi.cdef("""
diff --git a/lib_pypy/cffi/_cffi_include.h b/lib_pypy/cffi/_cffi_include.h
--- a/lib_pypy/cffi/_cffi_include.h
+++ b/lib_pypy/cffi/_cffi_include.h
@@ -95,6 +95,7 @@
 #define _cffi_from_c_ulong PyLong_FromUnsignedLong
 #define _cffi_from_c_longlong PyLong_FromLongLong
 #define _cffi_from_c_ulonglong PyLong_FromUnsignedLongLong
+#define _cffi_from_c__Bool PyBool_FromLong
 
 #define _cffi_to_c_double PyFloat_AsDouble
 #define _cffi_to_c_float PyFloat_AsDouble
diff --git a/lib_pypy/cffi/_embedding.h b/lib_pypy/cffi/_embedding.h
--- a/lib_pypy/cffi/_embedding.h
+++ b/lib_pypy/cffi/_embedding.h
@@ -1,7 +1,12 @@
 
 /* Support code for embedding */
 
-#if defined(_MSC_VER)
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+#if defined(_WIN32)
 #  define CFFI_DLLEXPORT  __declspec(dllexport)
 #elif defined(__GNUC__)
 #  define CFFI_DLLEXPORT  __attribute__((visibility("default")))
@@ -525,3 +530,7 @@
 #undef cffi_compare_and_swap
 #undef cffi_write_barrier
 #undef cffi_read_barrier
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/lib_pypy/cffi/recompiler.py b/lib_pypy/cffi/recompiler.py
--- a/lib_pypy/cffi/recompiler.py
+++ b/lib_pypy/cffi/recompiler.py
@@ -412,6 +412,9 @@
 prnt('}')
 prnt('p[0] = (const void *)0x%x;' % self._version)
 prnt('p[1] = &_cffi_type_context;')
+prnt('#if PY_MAJOR_VERSION >= 3')
+prnt('return NULL;')
+prnt('#endif')
 prnt('}')
 # on Windows, distutils insists on putting init_cffi_xyz in
 # 'export_symbols', so instead of fighting it, just give up and
@@ -578,7 +581,7 @@
 
 def _convert_expr_from_c(self, tp, var, context):
 if isinstance(tp, model.BasePrimitiveType):
-if tp.is_integer_type():
+if tp.is_integer_type() and tp.name != '_Bool':
 return '_cffi_from_c_int(%s, %s)' % (var, tp.name)
 elif isinstance(tp, model.UnknownFloatType):
 return '_cffi_from_c_double(%s)' % (var,)
diff --git a/lib_pypy/cffi/vengine_cpy.py b/lib_pypy/cffi/vengine_cpy.py
--- a/lib_pypy/cffi/vengine_cpy.py
+++ b/lib_pypy/cffi/vengine_cpy.py
@@ -296,7 +296,7 @@
 
 def _convert_expr_from_c(self, tp, var, context):
 if isinstance(tp, model.PrimitiveType):
-if tp.is_integer_type():
+if tp.is_integer_type() and tp.name != '_Bool':
 return '_cffi_from_c_int(%s, %s)' % (var, tp.name)
 

[pypy-commit] pypy py3.5: hg merge default

2017-07-19 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r91925:71fecdeaec70
Date: 2017-07-19 18:58 +0200
http://bitbucket.org/pypy/pypy/changeset/71fecdeaec70/

Log:hg merge default

diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py
--- a/rpython/translator/c/genc.py
+++ b/rpython/translator/c/genc.py
@@ -382,6 +382,80 @@
 if self.config.translation.profopt:
 if self.config.translation.profoptargs is None:
 raise Exception("No profoptargs specified, neither in the 
command line, nor in the target. If the target is not PyPy, please specify 
profoptargs")
+
+# Set the correct PGO params based on OS and CC
+profopt_gen_flag = ""
+profopt_use_flag = ""
+profopt_merger = ""
+profopt_file = ""
+llvm_profdata = ""
+
+cc = self.translator.platform.cc
+
+# Locate llvm-profdata
+if "clang" in cc:
+clang_bin = cc
+path = os.environ.get("PATH").split(":")
+profdata_found = False
+
+# Try to find it in $PATH (Darwin and Linux)
+for dir in path:
+bin = "%s/llvm-profdata" % dir
+if os.path.isfile(bin):
+llvm_profdata = bin
+profdata_found = True
+break
+
+# If not found, try to find it where clang is actually 
installed (Darwin and Linux)
+if not profdata_found:
+# If the full path is not given, find where clang is 
located
+if not os.path.isfile(clang_bin):
+for dir in path:
+bin = "%s/%s" % (dir, cc)
+if os.path.isfile(bin):
+clang_bin = bin
+break
+# Some systems install clang elsewhere as a symlink to the 
real path,
+# which is where the related llvm tools are located.
+if os.path.islink(clang_bin):
+clang_bin = os.path.realpath(clang_bin)  # the real 
clang binary
+# llvm-profdata must be in the same directory as clang
+llvm_profdata = "%s/llvm-profdata" % 
os.path.dirname(clang_bin)
+profdata_found = os.path.isfile(llvm_profdata)
+
+# If not found, and Darwin is used, try to find it in the 
development environment
+# More: https://apple.stackexchange.com/questions/197053/
+if not profdata_found and sys.platform == 'darwin':
+code = os.system("/usr/bin/xcrun -find llvm-profdata 
2>/dev/null")
+if code == 0:
+llvm_profdata = "/usr/bin/xcrun llvm-profdata"
+profdata_found = True
+
+# If everything failed, throw Exception, sorry
+if not profdata_found:
+raise Exception(
+"Error: Cannot perform profopt build because 
llvm-profdata was not found in PATH. "
+"Please add it to PATH and run the translation again.")
+
+# Set the PGO flags
+if "clang" in cc:
+# Any changes made here should be reflected in the GCC+Darwin 
case below
+profopt_gen_flag = "-fprofile-instr-generate"
+profopt_use_flag = "-fprofile-instr-use=code.profclangd"
+profopt_merger = "%s merge -output=code.profclangd 
*.profclangr" % llvm_profdata
+profopt_file = 'LLVM_PROFILE_FILE="code-%p.profclangr"'
+elif "gcc" in cc:
+if sys.platform == 'darwin':
+profopt_gen_flag = "-fprofile-instr-generate"
+profopt_use_flag = "-fprofile-instr-use=code.profclangd"
+profopt_merger = "%s merge -output=code.profclangd 
*.profclangr" % llvm_profdata
+profopt_file = 'LLVM_PROFILE_FILE="code-%p.profclangr"'
+else:
+profopt_gen_flag = "-fprofile-generate"
+profopt_use_flag = "-fprofile-use -fprofile-correction"
+profopt_merger = "true"
+profopt_file = ""
+
 if self.config.translation.shared:
 mk.rule('$(PROFOPT_TARGET)', '$(TARGET) main.o',
  '$(CC_LINK) $(LDFLAGS_LINK) main.o -L. 
-l$(SHARED_IMPORT_LIB) -o $@ $(RPATH_FLAGS) -lgcov')
@@ -390,10 +464,11 @@
 
 rules.append(
 ('profopt', '', [
-'$(MAKE) CFLAGS="-fprofile-generate -fPIC $(CFLAGS) 
-fno-lto"  LDFLAGS="-fprofile-generate $(LDFLAGS) -fno-lto" $(PROFOPT_TARGET)',
-'%s %s ' % (exe_name, self.config.translation.profoptargs),
+   

[pypy-commit] pypy py3.5: hg merge default

2017-07-16 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r91889:b58d747dcf74
Date: 2017-07-16 13:44 +0200
http://bitbucket.org/pypy/pypy/changeset/b58d747dcf74/

Log:hg merge default

diff --git a/lib-python/2.7/test/test_os.py b/lib-python/2.7/test/test_os.py
--- a/lib-python/2.7/test/test_os.py
+++ b/lib-python/2.7/test/test_os.py
@@ -580,6 +580,7 @@
  "getentropy() does not use a file descriptor")
 class URandomFDTests(unittest.TestCase):
 @unittest.skipUnless(resource, "test requires the resource module")
+@test_support.impl_detail(pypy=False)# on Linux, may use getrandom()
 def test_urandom_failure(self):
 # Check urandom() failing when it is not able to open /dev/random.
 # We spawn a new process to make the test more robust (if getrlimit()
diff --git a/pypy/interpreter/test/test_generator.py 
b/pypy/interpreter/test/test_generator.py
--- a/pypy/interpreter/test/test_generator.py
+++ b/pypy/interpreter/test/test_generator.py
@@ -531,6 +531,13 @@
 assert next(gen) is 1
 assert next(gen) is 2
 
+def test_multiple_invalid_sends(self):
+def mygen():
+yield 42
+g = mygen()
+raises(TypeError, g.send, 2)
+raises(TypeError, g.send, 2)
+
 
 def test_should_not_inline(space):
 from pypy.interpreter.generator import should_not_inline
diff --git a/pypy/module/cpyext/methodobject.py 
b/pypy/module/cpyext/methodobject.py
--- a/pypy/module/cpyext/methodobject.py
+++ b/pypy/module/cpyext/methodobject.py
@@ -10,7 +10,7 @@
 from pypy.module.cpyext.api import (
 CONST_STRING, METH_CLASS, METH_COEXIST, METH_KEYWORDS, METH_NOARGS, METH_O,
 METH_STATIC, METH_VARARGS, PyObject, bootstrap_function,
-build_type_checkers, cpython_api, generic_cpy_call,
+build_type_checkers, cpython_api, generic_cpy_call, CANNOT_FAIL,
 PyTypeObjectPtr, slot_function, cts)
 from pypy.module.cpyext.pyobject import (
 Py_DecRef, from_ref, make_ref, as_pyobj, make_typedescr)
@@ -106,8 +106,14 @@
 self.space, u"built-in method '%s' of '%s' object" %
 (self.name.decode('utf-8'), self.w_objclass.getname(self.space)))
 
-PyCFunction_Check, PyCFunction_CheckExact = build_type_checkers(
-"CFunction", W_PyCFunctionObject)
+@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
+def PyCFunction_Check(space, w_obj):
+from pypy.interpreter.function import BuiltinFunction
+if w_obj is None:
+return False
+if isinstance(w_obj, W_PyCFunctionObject):
+return True
+return isinstance(w_obj, BuiltinFunction)
 
 class W_PyCClassMethodObject(W_PyCFunctionObject):
 w_self = None
diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py
--- a/pypy/module/cpyext/object.py
+++ b/pypy/module/cpyext/object.py
@@ -442,15 +442,19 @@
 Py_PRINT_RAW = 1 # No string quotes etc.
 
 @cpython_api([PyObject, FILEP, rffi.INT_real], rffi.INT_real, error=-1)
-def PyObject_Print(space, w_obj, fp, flags):
+def PyObject_Print(space, pyobj, fp, flags):
 """Print an object o, on file fp.  Returns -1 on error.  The flags argument
 is used to enable certain printing options.  The only option currently
 supported is Py_PRINT_RAW; if given, the str() of the object is written
 instead of the repr()."""
-if rffi.cast(lltype.Signed, flags) & Py_PRINT_RAW:
-w_str = space.str(w_obj)
+if not pyobj:
+w_str = space.newtext("")
 else:
-w_str = space.repr(w_obj)
+w_obj = from_ref(space, pyobj)
+if rffi.cast(lltype.Signed, flags) & Py_PRINT_RAW:
+w_str = space.str(w_obj)
+else:
+w_str = space.repr(w_obj)
 
 count = space.len_w(w_str)
 data = space.text_w(w_str)
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -455,7 +455,7 @@
   ('tp_iter', '__iter__'),
   ]:
 if name == tp_name:
-slot_fn = w_type.getdictvalue(space, attr)
+slot_fn = w_type.lookup(attr)
 if slot_fn is None:
 return
 
@@ -470,7 +470,7 @@
   ('tp_as_mapping.c_mp_length', '__len__'),
  ]:
 if name == tp_name:
-slot_fn = w_type.getdictvalue(space, attr)
+slot_fn = w_type.lookup(attr)
 if slot_fn is None:
 return
 @slot_function([PyObject], lltype.Signed, error=-1)
@@ -497,7 +497,7 @@
   ('tp_as_mapping.c_mp_subscript', '__getitem__'),
   ]:
 if name == tp_name:
-slot_fn = w_type.getdictvalue(space, attr)
+slot_fn = w_type.lookup(attr)
 if slot_fn is None:
 return
 
@@ -514,7 +514,7 @@
   ('tp_as_sequence.c_sq_inplace_repeat', '__imul__'),
 

[pypy-commit] pypy py3.5: hg merge default

2017-07-08 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r91843:7888ede0c136
Date: 2017-07-08 17:11 +0200
http://bitbucket.org/pypy/pypy/changeset/7888ede0c136/

Log:hg merge default

diff --git a/pypy/module/__builtin__/test/test_functional.py 
b/pypy/module/__builtin__/test/test_functional.py
--- a/pypy/module/__builtin__/test/test_functional.py
+++ b/pypy/module/__builtin__/test/test_functional.py
@@ -539,6 +539,7 @@
 raises(TypeError, reversed, {})
 raises(TypeError, reversed, {2: 3})
 assert not hasattr(dict, '__reversed__')
+raises(TypeError, reversed, int.__dict__)
 
 def test_reversed_type_with_no_len(self):
 class X(object):
diff --git a/pypy/objspace/std/test/test_dictproxy.py 
b/pypy/objspace/std/test/test_dictproxy.py
--- a/pypy/objspace/std/test/test_dictproxy.py
+++ b/pypy/objspace/std/test/test_dictproxy.py
@@ -77,5 +77,6 @@
 #
 {}.update(proxy)
 
+
 class AppTestUserObjectMethodCache(AppTestUserObject):
 spaceconfig = {"objspace.std.withmethodcachecounter": True}
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-07-08 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r91841:94b78e58b886
Date: 2017-07-08 17:04 +0200
http://bitbucket.org/pypy/pypy/changeset/94b78e58b886/

Log:hg merge default

diff --git a/pypy/module/__builtin__/functional.py 
b/pypy/module/__builtin__/functional.py
--- a/pypy/module/__builtin__/functional.py
+++ b/pypy/module/__builtin__/functional.py
@@ -317,9 +317,9 @@
 
 def __init__(self, space, w_sequence):
 self.remaining = space.len_w(w_sequence) - 1
-if space.lookup(w_sequence, "__getitem__") is None:
+if not space.issequence_w(w_sequence):
 raise oefmt(space.w_TypeError,
-"reversed() argument must be a sequence")
+"argument to reversed() must be a sequence")
 self.w_sequence = w_sequence
 
 @staticmethod
@@ -328,9 +328,6 @@
 if w_reversed_descr is not None:
 w_reversed = space.get(w_reversed_descr, w_sequence)
 return space.call_function(w_reversed)
-if not space.issequence_w(w_sequence):
-raise oefmt(space.w_TypeError,
-"argument to reversed() must be a sequence")
 self = space.allocate_instance(W_ReversedIterator, w_subtype)
 self.__init__(space, w_sequence)
 return self
diff --git a/pypy/module/__builtin__/test/test_functional.py 
b/pypy/module/__builtin__/test/test_functional.py
--- a/pypy/module/__builtin__/test/test_functional.py
+++ b/pypy/module/__builtin__/test/test_functional.py
@@ -527,8 +527,24 @@
 assert list(reversed(list(reversed("hello" == ['h','e','l','l','o']
 raises(TypeError, reversed, reversed("hello"))
 
-def test_reversed_nonsequence(self):
+def test_reversed_user_type(self):
+class X(object):
+def __getitem__(self, index):
+return str(index)
+def __len__(self):
+return 5
+assert list(reversed(X())) == ["4", "3", "2", "1", "0"]
+
+def test_reversed_not_for_mapping(self):
 raises(TypeError, reversed, {})
+raises(TypeError, reversed, {2: 3})
+assert not hasattr(dict, '__reversed__')
+
+def test_reversed_type_with_no_len(self):
+class X(object):
+def __getitem__(self, key):
+raise ValueError
+raises(TypeError, reversed, X())
 
 def test_reversed_length_hint(self):
 lst = [1, 2, 3]
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-07-07 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r91837:920958a93997
Date: 2017-07-08 01:18 +0100
http://bitbucket.org/pypy/pypy/changeset/920958a93997/

Log:hg 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
@@ -21,3 +21,7 @@
 .. branch: issue-2592
 
 CPyext PyListObject.pop must return the value
+
+.. branch: cpyext-hash_notimpl
+
+If ``tp_hash`` is ``PyObject_HashNotImplemented``, set 
``obj.__dict__['__hash__']`` to None
diff --git a/pypy/module/cpyext/pyerrors.py b/pypy/module/cpyext/pyerrors.py
--- a/pypy/module/cpyext/pyerrors.py
+++ b/pypy/module/cpyext/pyerrors.py
@@ -125,8 +125,18 @@
 not an instance of the  same class.  This function can be used to 
instantiate
 the class in that case.  If the values are already normalized, nothing 
happens.
 The delayed normalization is implemented to improve performance."""
-operr = OperationError(from_ref(space, exc_p[0]),
-   from_ref(space, val_p[0]))
+if exc_p[0]:
+w_etype = from_ref(space, exc_p[0])
+else:
+# There is no exception, so nothing to do
+return
+if val_p[0]:
+w_evalue = from_ref(space, val_p[0])
+else:
+# On CPython, PyErr_SetNone actually sets val to NULL.
+# Sensible code should probably never trigger this path on PyPy, but...
+w_evalue = space.w_None
+operr = OperationError(w_etype, w_evalue)
 operr.normalize_exception(space)
 Py_DecRef(space, exc_p[0])
 Py_DecRef(space, val_p[0])
diff --git a/pypy/module/cpyext/test/test_pyerrors.py 
b/pypy/module/cpyext/test/test_pyerrors.py
--- a/pypy/module/cpyext/test/test_pyerrors.py
+++ b/pypy/module/cpyext/test/test_pyerrors.py
@@ -174,6 +174,23 @@
 ])
 assert module.check_error()
 
+def test_normalize_no_exception(self):
+module = self.import_extension('foo', [
+("check_error", "METH_NOARGS",
+ '''
+ PyObject *type, *val, *tb;
+ PyErr_Fetch(, , );
+ if (type != NULL)
+ Py_RETURN_FALSE;
+ if (val != NULL)
+ Py_RETURN_FALSE;
+ PyErr_NormalizeException(, , );
+ Py_RETURN_TRUE;
+ '''
+ ),
+])
+assert module.check_error()
+
 def test_SetFromErrno(self):
 import sys
 if sys.platform != 'win32':
diff --git a/pypy/module/cpyext/test/test_typeobject.py 
b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -1301,3 +1301,33 @@
 Bsize = module.get_basicsize(B)
 assert Asize == Bsize
 assert Asize > basesize
+
+
+class AppTestHashable(AppTestCpythonExtensionBase):
+def test_unhashable(self):
+if not self.runappdirect:
+skip('pointer to function equality available'
+ ' only after translation')
+module = self.import_extension('foo', [
+   ("new_obj", "METH_NOARGS",
+'''
+PyObject *obj;
+obj = PyObject_New(PyObject, _Type);
+return obj;
+'''
+)], prologue='''
+static PyTypeObject Foo_Type = {
+PyVarObject_HEAD_INIT(NULL, 0)
+"foo.foo",
+};
+''', more_init = '''
+Foo_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+Foo_Type.tp_hash = PyObject_HashNotImplemented;
+if (PyType_Ready(_Type) < 0) INITERROR;
+''')
+obj = module.new_obj()
+raises(TypeError, hash, obj)
+assert type(obj).__dict__['__hash__'] is None
+# this is equivalent to
+from collections import Hashable
+assert not isinstance(obj, Hashable)
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -337,13 +337,19 @@
 setattr(struct, slot_names[1], slot_func_helper)
 
 def add_operators(space, dict_w, pto):
-# XXX support PyObject_HashNotImplemented
+from pypy.module.cpyext.object import PyObject_HashNotImplemented
+hash_not_impl = PyObject_HashNotImplemented.api_func.get_llhelper(space)
 for method_name, slot_names, wrapper_func, wrapper_func_kwds, doc in 
slotdefs_for_wrappers:
 if method_name in dict_w:
 continue
 offset = [rffi.offsetof(lltype.typeOf(pto).TO, slot_names[0])]
 if len(slot_names) == 1:
 func = getattr(pto, slot_names[0])
+if slot_names[0] == 'c_tp_hash':
+if hash_not_impl == func:
+# special case for tp_hash == PyObject_HashNotImplemented
+dict_w[method_name] = space.w_None
+continue
 

[pypy-commit] pypy py3.5: hg merge default

2017-07-04 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r91686:33527bb8058e
Date: 2017-07-04 22:00 +0100
http://bitbucket.org/pypy/pypy/changeset/33527bb8058e/

Log:hg merge default

diff --git a/rpython/rlib/rvmprof/cintf.py b/rpython/rlib/rvmprof/cintf.py
--- a/rpython/rlib/rvmprof/cintf.py
+++ b/rpython/rlib/rvmprof/cintf.py
@@ -58,6 +58,7 @@
 SHARED.join('compat.c'),
 SHARED.join('machine.c'),
 SHARED.join('vmp_stack.c'),
+SHARED.join('vmprof_main.c'),
 # symbol table already in separate_module_files
 ] + separate_module_files,
 post_include_bits=[],
diff --git a/rpython/rlib/rvmprof/src/shared/vmprof_main.c 
b/rpython/rlib/rvmprof/src/shared/vmprof_main.c
new file mode 100644
--- /dev/null
+++ b/rpython/rlib/rvmprof/src/shared/vmprof_main.c
@@ -0,0 +1,30 @@
+#ifdef VMPROF_UNIX
+
+#include 
+/* value: LSB bit is 1 if signals must be ignored; all other bits
+   are a counter for how many threads are currently in a signal handler */
+static long volatile signal_handler_value = 1;
+
+void vmprof_ignore_signals(int ignored)
+{
+if (!ignored) {
+__sync_fetch_and_and(_handler_value, ~1L);
+} else {
+/* set the last bit, and wait until concurrently-running signal
+   handlers finish */
+while (__sync_or_and_fetch(_handler_value, 1L) != 1L) {
+usleep(1);
+}
+}
+}
+
+long vmprof_enter_signal(void)
+{
+return __sync_fetch_and_add(_handler_value, 2L);
+}
+
+long vmprof_exit_signal(void)
+{
+return __sync_sub_and_fetch(_handler_value, 2L);
+}
+#endif
diff --git a/rpython/rlib/rvmprof/src/shared/vmprof_main.h 
b/rpython/rlib/rvmprof/src/shared/vmprof_main.h
--- a/rpython/rlib/rvmprof/src/shared/vmprof_main.h
+++ b/rpython/rlib/rvmprof/src/shared/vmprof_main.h
@@ -60,25 +60,9 @@
 
 //
 
-/* value: last bit is 1 if signals must be ignored; all other bits
-   are a counter for how many threads are currently in a signal handler */
-static long volatile signal_handler_value = 1;
-
-RPY_EXTERN
-void vmprof_ignore_signals(int ignored)
-{
-if (!ignored) {
-__sync_fetch_and_and(_handler_value, ~1L);
-}
-else {
-/* set the last bit, and wait until concurrently-running signal
-   handlers finish */
-while (__sync_or_and_fetch(_handler_value, 1L) != 1L) {
-usleep(1);
-}
-}
-}
-
+RPY_EXTERN void vmprof_ignore_signals(int ignored);
+RPY_EXTERN long vmprof_enter_signal(void);
+RPY_EXTERN long vmprof_exit_signal(void);
 
 /* *
  * functions to write a profile file compatible with gperftools
@@ -276,7 +260,7 @@
 __sync_lock_release();
 #endif
 
-long val = __sync_fetch_and_add(_handler_value, 2L);
+long val = vmprof_enter_signal();
 
 if ((val & 1) == 0) {
 int saved_errno = errno;
@@ -307,7 +291,7 @@
 errno = saved_errno;
 }
 
-__sync_sub_and_fetch(_handler_value, 2L);
+vmprof_exit_signal();
 }
 
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-07-03 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r91673:e8077e1b4dd0
Date: 2017-07-03 22:32 +0100
http://bitbucket.org/pypy/pypy/changeset/e8077e1b4dd0/

Log:hg merge default

diff --git a/pypy/module/cpyext/parse/cpyext_memoryobject.h 
b/pypy/module/cpyext/parse/cpyext_memoryobject.h
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/parse/cpyext_memoryobject.h
@@ -0,0 +1,7 @@
+/* The struct is declared here but it shouldn't
+   be considered public. Don't access those fields directly,
+   use the functions instead! */
+typedef struct {
+PyObject_HEAD
+Py_buffer view;
+} PyMemoryViewObject;
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-07-03 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r91671:d5cde34e0278
Date: 2017-07-03 18:49 +0100
http://bitbucket.org/pypy/pypy/changeset/d5cde34e0278/

Log:hg merge default

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -459,13 +459,15 @@
 return decorate
 
 def api_func_from_cdef(func, cdef, cts,
-error=_NOT_SPECIFIED, header=DEFAULT_HEADER):
+error=_NOT_SPECIFIED, header=DEFAULT_HEADER,
+result_is_ll=False):
 func._always_inline_ = 'try'
 cdecl = cts.parse_func(cdef)
 RESULT = cdecl.get_llresult(cts)
 api_function = ApiFunction(
 cdecl.get_llargs(cts), RESULT, func,
-error=_compute_error(error, RESULT), cdecl=cdecl)
+error=_compute_error(error, RESULT), cdecl=cdecl,
+result_is_ll=result_is_ll)
 FUNCTIONS_BY_HEADER[header][cdecl.name] = api_function
 unwrapper = api_function.get_unwrapper()
 unwrapper.func = func
@@ -670,10 +672,12 @@
 
 
 class CpyextTypeSpace(CTypeSpace):
-def decl(self, cdef, error=_NOT_SPECIFIED, header=DEFAULT_HEADER):
+def decl(self, cdef, error=_NOT_SPECIFIED, header=DEFAULT_HEADER,
+result_is_ll=False):
 def decorate(func):
 return api_func_from_cdef(
-func, cdef, self, error=error, header=header)
+func, cdef, self, error=error, header=header,
+result_is_ll=result_is_ll)
 return decorate
 
 
diff --git a/pypy/module/cpyext/include/memoryobject.h 
b/pypy/module/cpyext/include/memoryobject.h
--- a/pypy/module/cpyext/include/memoryobject.h
+++ b/pypy/module/cpyext/include/memoryobject.h
@@ -5,14 +5,7 @@
 extern "C" {
 #endif
 
-/* The struct is declared here but it shouldn't
-   be considered public. Don't access those fields directly,
-   use the functions instead! */
-typedef struct {
-PyObject_HEAD
-Py_buffer view;
-} PyMemoryViewObject;
-
+#include "cpyext_memoryobject.h"
 
 /* Get a pointer to the memoryview's private copy of the exporter's buffer. */
 #define PyMemoryView_GET_BUFFER(op) (&((PyMemoryViewObject *)(op))->view)
diff --git a/pypy/module/cpyext/memoryobject.py 
b/pypy/module/cpyext/memoryobject.py
--- a/pypy/module/cpyext/memoryobject.py
+++ b/pypy/module/cpyext/memoryobject.py
@@ -1,11 +1,8 @@
-from rpython.rlib.objectmodel import keepalive_until_here
-from pypy.interpreter.error import oefmt
 from pypy.module.cpyext.api import (
-cpython_api, Py_buffer, CANNOT_FAIL, Py_MAX_FMT, Py_MAX_NDIMS,
-build_type_checkers, Py_ssize_tP, PyObjectFields, cpython_struct,
-bootstrap_function, Py_bufferP, slot_function, generic_cpy_call)
+cpython_api, CANNOT_FAIL, Py_MAX_FMT, Py_MAX_NDIMS, build_type_checkers,
+Py_ssize_tP, cts, parse_dir, bootstrap_function, Py_bufferP, slot_function)
 from pypy.module.cpyext.pyobject import (
-PyObject, make_ref, as_pyobj, decref, from_ref, make_typedescr,
+PyObject, make_ref, decref, from_ref, make_typedescr,
 get_typedescr, track_reference)
 from rpython.rtyper.lltypesystem import lltype, rffi
 from rpython.rlib.rarithmetic import widen
@@ -14,17 +11,12 @@
 from pypy.module.cpyext.object import _dealloc
 from pypy.module.cpyext.import_ import PyImport_Import
 
+cts.parse_header(parse_dir / 'cpyext_memoryobject.h')
+PyMemoryViewObject = cts.gettype('PyMemoryViewObject*')
+
 PyMemoryView_Check, PyMemoryView_CheckExact = build_type_checkers("MemoryView")
 
 
-PyMemoryViewObjectStruct = lltype.ForwardReference()
-PyMemoryViewObject = lltype.Ptr(PyMemoryViewObjectStruct)
-PyMemoryViewObjectFields = PyObjectFields + \
-(("view", Py_buffer),)
-cpython_struct(
-"PyMemoryViewObject", PyMemoryViewObjectFields, PyMemoryViewObjectStruct,
-level=2)
-
 @bootstrap_function
 def init_memoryobject(space):
 "Type description of PyDictObject"
@@ -33,7 +25,7 @@
attach=memory_attach,
dealloc=memory_dealloc,
realize=memory_realize,
-  )
+   )
 
 def memory_attach(space, py_obj, w_obj, w_userdata=None):
 """
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-06-30 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r91662:96e56ffe7aa7
Date: 2017-06-30 23:25 +0100
http://bitbucket.org/pypy/pypy/changeset/96e56ffe7aa7/

Log:hg merge default

diff too long, truncating to 2000 out of 2002 lines

diff --git a/lib_pypy/stackless.py b/lib_pypy/stackless.py
--- a/lib_pypy/stackless.py
+++ b/lib_pypy/stackless.py
@@ -268,12 +268,22 @@
 assert abs(d) == 1
 source = getcurrent()
 source.tempval = arg
-if d > 0:
-cando = self.balance < 0
-dir = d
-else:
-cando = self.balance > 0
-dir = 0
+while True:
+if d > 0:
+cando = self.balance < 0
+dir = d
+else:
+cando = self.balance > 0
+dir = 0
+
+if cando and self.queue[0]._tasklet_killed:
+# issue #2595: the tasklet was killed while waiting.
+# drop that tasklet from consideration and try again.
+self.balance += d
+self.queue.popleft()
+else:
+# normal path
+break
 
 if _channel_callback is not None:
 _channel_callback(self, source, dir, not cando)
@@ -348,6 +358,8 @@
 module.
 """
 tempval = None
+_tasklet_killed = False
+
 def __new__(cls, func=None, label=''):
 res = coroutine.__new__(cls)
 res.label = label
@@ -395,6 +407,7 @@
 If the exception passes the toplevel frame of the tasklet,
 the tasklet will silently die.
 """
+self._tasklet_killed = True
 if not self.is_zombie:
 # Killing the tasklet by throwing TaskletExit exception.
 coroutine.kill(self)
diff --git a/pypy/module/cppyy/backend/create_cppyy_package.py 
b/pypy/module/cppyy/backend/create_cppyy_package.py
new file mode 100755
--- /dev/null
+++ b/pypy/module/cppyy/backend/create_cppyy_package.py
@@ -0,0 +1,649 @@
+#!/usr/bin/env python
+from __future__ import print_function
+
+import os, sys
+import argparse, re, shutil, tarfile, urllib2
+
+
+DEBUG_TESTBUILD = False
+
+TARBALL_CACHE_DIR = 'releases'
+
+ROOT_KEEP = ['build', 'cmake', 'config', 'core', 'etc', 'interpreter',
+ 'io', 'LICENSE', 'net', 'Makefile', 'CMakeLists.txt', 'math',
+ 'main'] # main only needed in more recent root b/c of rootcling
+ROOT_CORE_KEEP = ['CMakeLists.txt', 'base', 'clib', 'clingutils', 'cont',
+  'dictgen', 'foundation', 'lzma', 'macosx', 'meta',
+  'metacling', 'metautils', 'rootcling_stage1', 'textinput',
+  'thread', 'unix', 'utils', 'winnt', 'zip']
+ROOT_IO_KEEP = ['CMakeLists.txt', 'io', 'rootpcm']
+ROOT_NET_KEEP = ['CMakeLists.txt', 'net']
+ROOT_MATH_KEEP = ['CMakeLists.txt', 'mathcore']
+ROOT_ETC_KEEP = ['Makefile.arch', 'class.rules', 'cmake', 'dictpch',
+ 'gdb-backtrace.sh', 'gitinfo.txt', 'helgrind-root.supp',
+ 'hostcert.conf', 'system.plugins-ios',
+ 'valgrind-root-python.supp', 'valgrind-root.supp', 'vmc']
+
+ROOT_EXPLICIT_REMOVE = ['core/base/v7', 'math/mathcore/v7', 'io/io/v7']
+
+
+ERR_RELEASE_NOT_FOUND = 2
+
+
+#
+## CLI arguments
+#
+class ReleaseValidation(argparse.Action):
+def __call__(self, parser, namespace, value, option_string=None):
+if not re.match(r'6\.\d\d\.\d\d', value):
+raise argparse.ArgumentTypeError(
+"release number should of the form '6.dd.dd'")
+setattr(namespace, self.dest, value)
+return value
+
+parser = argparse.ArgumentParser(
+description='Build PyPi package for cppyy containing the minimum of ROOT')
+parser.add_argument('-r', '--release', type=str, nargs='?',
+action=ReleaseValidation, help='ROOT release to use')
+
+args = parser.parse_args()
+
+
+#
+## ROOT source pull and cleansing
+#
+def clean_directory(directory, keeplist, trim_cmake=True):
+removed_entries = []
+for entry in os.listdir(directory):
+if entry[0] == '.' or entry in keeplist:
+continue
+removed_entries.append(entry)
+entry = os.path.join(directory, entry)
+print('now removing', entry)
+if os.path.isdir(entry):
+shutil.rmtree(entry)
+else:
+os.remove(entry)
+
+if not trim_cmake:
+return
+
+# now take the removed entries out of the CMakeLists.txt
+if removed_entries:
+inp = os.path.join(directory, 'CMakeLists.txt')
+print('trimming', inp)
+outp = inp+'.new'
+new_cml = open(outp, 'w')
+for line in open(inp).readlines():
+if ('add_subdirectory' in line) or\
+   ('COMMAND' in line and 'copy' in line) or\
+   ('ROOT_ADD_TEST_SUBDIRECTORY' in line) or\
+   ('install(DIRECTORY' in line):
+for sub in removed_entries:
+if 

[pypy-commit] pypy py3.5: hg merge default

2017-06-22 Thread mattip
Author: Matti Picus 
Branch: py3.5
Changeset: r91636:c378444b2cf5
Date: 2017-06-22 23:14 +0300
http://bitbucket.org/pypy/pypy/changeset/c378444b2cf5/

Log:hg merge default

diff --git a/lib_pypy/cffi/_cffi_errors.h b/lib_pypy/cffi/_cffi_errors.h
--- a/lib_pypy/cffi/_cffi_errors.h
+++ b/lib_pypy/cffi/_cffi_errors.h
@@ -36,7 +36,11 @@
 if (result == NULL)
 goto error;
 
+#if PY_MAJOR_VERSION >= 3
+bi = PyImport_ImportModule("builtins");
+#else
 bi = PyImport_ImportModule("__builtin__");
+#endif
 if (bi == NULL)
 goto error;
 PyDict_SetItemString(result, "__builtins__", bi);
diff --git a/lib_pypy/cffi/api.py b/lib_pypy/cffi/api.py
--- a/lib_pypy/cffi/api.py
+++ b/lib_pypy/cffi/api.py
@@ -765,7 +765,7 @@
 if sys.platform != "win32":
 return backend.load_library(None, flags)
 name = "c"# Windows: load_library(None) fails, but this works
-  # (backward compatibility hack only)
+  # on Python 2 (backward compatibility hack only)
 first_error = None
 if '.' in name or '/' in name or os.sep in name:
 try:
@@ -775,6 +775,9 @@
 import ctypes.util
 path = ctypes.util.find_library(name)
 if path is None:
+if name == "c" and sys.platform == "win32" and sys.version_info >= 
(3,):
+raise OSError("dlopen(None) cannot work on Windows for Python 3 "
+  "(see http://bugs.python.org/issue23606)")
 msg = ("ctypes.util.find_library() did not manage "
"to locate a library called %r" % (name,))
 if first_error is not None:
diff --git a/pypy/doc/project-ideas.rst b/pypy/doc/project-ideas.rst
--- a/pypy/doc/project-ideas.rst
+++ b/pypy/doc/project-ideas.rst
@@ -238,18 +238,17 @@
 using more pypy-friendly technologies, e.g. cffi. Here is a partial list of
 good work that needs to be finished:
 
-**matplotlib** https://github.com/mattip/matplotlib
+**matplotlib** https://github.com/matplotlib/matplotlib
 
-Status: the repo is an older version of matplotlib adapted to pypy and 
cpyext
+TODO: the tkagg backend does not work, which makes tests fail on downstream
+projects like Pandas, SciPy. It uses id(obj) as a c-pointer to obj in 
+tkagg.py, which requires refactoring
 
-TODO: A suggested first step would be to merge the differences into 
-matplotlib/HEAD. The major problem is the use of a generic view into a
-numpy ndarray. The int* fields would need to be converted into 
int[MAX_DIMS]
-c-arrays and filled in.
+**wxPython** https://bitbucket.org/amauryfa/wxpython-cffi
 
-**wxPython** https://bitbucket.org/waedt/wxpython_cffi
+Status: A project by a PyPy developer to adapt the Phoenix sip build 
system to cffi
 
-Status: A GSOC 2013 project to adapt the Phoenix sip build system to cffi
+The project is a continuation of a 2013 GSOC 
https://bitbucket.org/waedt/wxpython_cffi
 
 TODO: Merge the latest version of the wrappers and finish the sip 
conversion
 
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
@@ -17,3 +17,7 @@
 .. branch: vmprof-0.4.8
 
 Improve and fix issues with vmprof
+
+.. branch: issue-2592
+
+CPyext PyListObject.pop must return the value
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py 
b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -50,6 +50,10 @@
 path = None
 else:
 path = ctypes.util.find_library(name)
+if path is None and name == 'c':
+assert sys.platform == 'win32'
+assert sys.version_info >= (3,)
+py.test.skip("dlopen(None) cannot work on Windows with Python 3")
 return load_library(path, flags)
 
 def test_load_library():
diff --git a/pypy/module/cpyext/dictobject.py b/pypy/module/cpyext/dictobject.py
--- a/pypy/module/cpyext/dictobject.py
+++ b/pypy/module/cpyext/dictobject.py
@@ -286,6 +286,7 @@
 pvalue[0] = as_pyobj(space, w_value)
 return 1
 
+_frozendict_cache[space].flag_map_or_seq = 'M'
 @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
 def _PyDict_HasOnlyStringKeys(space, w_dict):
 keys_w = space.unpackiterable(w_dict)
diff --git a/pypy/module/cpyext/sequence.py b/pypy/module/cpyext/sequence.py
--- a/pypy/module/cpyext/sequence.py
+++ b/pypy/module/cpyext/sequence.py
@@ -346,11 +346,11 @@
 
 def pop(self, w_list, index):
 w_list.switch_to_object_strategy()
-w_list.strategy.pop(w_list, index)
+return w_list.strategy.pop(w_list, index)
 
 def pop_end(self, w_list):
 w_list.switch_to_object_strategy()
-w_list.strategy.pop_end(w_list)
+return w_list.strategy.pop_end(w_list)
 
 def insert(self, w_list, index, w_item):
 

[pypy-commit] pypy py3.5: hg merge default

2017-06-19 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r91625:be1dadf96ba4
Date: 2017-06-19 09:59 +0200
http://bitbucket.org/pypy/pypy/changeset/be1dadf96ba4/

Log:hg merge default

also attempt to write the Python3 version of cffi's errorbox.py on
Windows, but not tested so far

diff --git a/lib_pypy/cffi/_cffi_errors.h b/lib_pypy/cffi/_cffi_errors.h
new file mode 100644
--- /dev/null
+++ b/lib_pypy/cffi/_cffi_errors.h
@@ -0,0 +1,141 @@
+#ifndef CFFI_MESSAGEBOX
+# ifdef _MSC_VER
+#  define CFFI_MESSAGEBOX  1
+# else
+#  define CFFI_MESSAGEBOX  0
+# endif
+#endif
+
+
+#if CFFI_MESSAGEBOX
+/* Windows only: logic to take the Python-CFFI embedding logic
+   initialization errors and display them in a background thread
+   with MessageBox.  The idea is that if the whole program closes
+   as a result of this problem, then likely it is already a console
+   program and you can read the stderr output in the console too.
+   If it is not a console program, then it will likely show its own
+   dialog to complain, or generally not abruptly close, and for this
+   case the background thread should stay alive.
+*/
+static void *volatile _cffi_bootstrap_text;
+
+static PyObject *_cffi_start_error_capture(void)
+{
+PyObject *result = NULL;
+PyObject *x, *m, *bi;
+
+if (InterlockedCompareExchangePointer(&_cffi_bootstrap_text,
+(void *)1, NULL) != NULL)
+return (PyObject *)1;
+
+m = PyImport_AddModule("_cffi_error_capture");
+if (m == NULL)
+goto error;
+
+result = PyModule_GetDict(m);
+if (result == NULL)
+goto error;
+
+bi = PyImport_ImportModule("__builtin__");
+if (bi == NULL)
+goto error;
+PyDict_SetItemString(result, "__builtins__", bi);
+Py_DECREF(bi);
+
+x = PyRun_String(
+"import sys\n"
+"class FileLike:\n"
+"  def write(self, x):\n"
+"of.write(x)\n"
+"self.buf += x\n"
+"fl = FileLike()\n"
+"fl.buf = ''\n"
+"of = sys.stderr\n"
+"sys.stderr = fl\n"
+"def done():\n"
+"  sys.stderr = of\n"
+"  return fl.buf\n",   /* make sure the returned value stays alive */
+Py_file_input,
+result, result);
+Py_XDECREF(x);
+
+ error:
+if (PyErr_Occurred())
+{
+PyErr_WriteUnraisable(Py_None);
+PyErr_Clear();
+}
+return result;
+}
+
+#pragma comment(lib, "user32.lib")
+
+static DWORD WINAPI _cffi_bootstrap_dialog(LPVOID ignored)
+{
+Sleep(666);/* may be interrupted if the whole process is closing */
+#if PY_MAJOR_VERSION >= 3
+MessageBoxW(NULL, (wchar_t *)_cffi_bootstrap_text,
+L"Python-CFFI error",
+MB_OK | MB_ICONERROR);
+#else
+MessageBoxA(NULL, (char *)_cffi_bootstrap_text,
+"Python-CFFI error",
+MB_OK | MB_ICONERROR);
+#endif
+_cffi_bootstrap_text = NULL;
+return 0;
+}
+
+static void _cffi_stop_error_capture(PyObject *ecap)
+{
+PyObject *s;
+void *text;
+
+if (ecap == (PyObject *)1)
+return;
+
+if (ecap == NULL)
+goto error;
+
+s = PyRun_String("done()", Py_eval_input, ecap, ecap);
+if (s == NULL)
+goto error;
+
+/* Show a dialog box, but in a background thread, and
+   never show multiple dialog boxes at once. */
+#if PY_MAJOR_VERSION >= 3
+text = PyUnicode_AsWideCharString(s, NULL);
+#else
+text = PyString_AsString(s);
+#endif
+
+_cffi_bootstrap_text = text;
+
+if (text != NULL)
+{
+HANDLE h;
+h = CreateThread(NULL, 0, _cffi_bootstrap_dialog,
+ NULL, 0, NULL);
+if (h != NULL)
+CloseHandle(h);
+}
+/* decref the string, but it should stay alive as 'fl.buf'
+   in the small module above.  It will really be freed only if
+   we later get another similar error.  So it's a leak of at
+   most one copy of the small module.  That's fine for this
+   situation which is usually a "fatal error" anyway. */
+Py_DECREF(s);
+PyErr_Clear();
+return;
+
+  error:
+_cffi_bootstrap_text = NULL;
+PyErr_Clear();
+}
+
+#else
+
+static PyObject *_cffi_start_error_capture(void) { return NULL; }
+static void _cffi_stop_error_capture(PyObject *ecap) { }
+
+#endif
diff --git a/lib_pypy/cffi/_embedding.h b/lib_pypy/cffi/_embedding.h
--- a/lib_pypy/cffi/_embedding.h
+++ b/lib_pypy/cffi/_embedding.h
@@ -109,6 +109,8 @@
 /**  CPython-specific section  **/
 #ifndef PYPY_VERSION
 
+#include "_cffi_errors.h"
+
 
 #define _cffi_call_python_org  _cffi_exports[_CFFI_CPIDX]
 
@@ -220,8 +222,16 @@
 /* Print as much information as potentially useful.
Debugging load-time failures with embedding is not fun
 */
+PyObject *ecap;
 PyObject *exception, *v, *tb, *f, *modules, *mod;
 PyErr_Fetch(, , );
+ecap = _cffi_start_error_capture();
+f = 

[pypy-commit] pypy py3.5: hg merge default

2017-06-17 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r91622:d7d9692a9f74
Date: 2017-06-17 18:32 +0200
http://bitbucket.org/pypy/pypy/changeset/d7d9692a9f74/

Log:hg merge default

diff --git a/.hgignore b/.hgignore
--- a/.hgignore
+++ b/.hgignore
@@ -1,6 +1,6 @@
 syntax: glob
 *.py[co]
-*.sw[po]
+*.sw[pon]
 *~
 .*.swp
 .idea
@@ -10,6 +10,8 @@
 .venv
 .cache
 
+.cache/
+.gdb_history
 syntax: regexp
 ^testresult$
 ^site-packages$
@@ -90,7 +92,6 @@
 .hypothesis/
 ^release/
 ^rpython/_cache$
-^\.cache$
 
 pypy/module/cppyy/.+/*\.pcm
 
diff --git a/pypy/doc/build.rst b/pypy/doc/build.rst
--- a/pypy/doc/build.rst
+++ b/pypy/doc/build.rst
@@ -93,7 +93,8 @@
 libsqlite3
 
 curses
-libncurses
+libncurses-dev   (for PyPy2)
+libncursesw-dev  (for PyPy3)
 
 gdbm
 libgdbm-dev
@@ -106,12 +107,13 @@
 
 To run untranslated tests, you need the Boehm garbage collector libgc.
 
-On Debian, this is the command to install all build-time dependencies::
+On Debian and Ubuntu, this is the command to install all build-time
+dependencies::
 
 apt-get install gcc make libffi-dev pkg-config libz-dev libbz2-dev \
 libsqlite3-dev libncurses-dev libexpat1-dev libssl-dev libgdbm-dev \
 tk-dev libgc-dev python-cffi \
-liblzma-dev  # For lzma on PyPy3.
+liblzma-dev libncursesw-dev  # these two only needed on PyPy3
 
 On Fedora::
 
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
@@ -9,3 +9,11 @@
 .. branch: cffi-char16-char32
 
 The two ``cffi-*`` branches are part of the upgrade to cffi 1.11.
+
+.. branch: ctypes_char_indexing
+
+Indexing into char* behaves differently than CPython
+
+.. branch: vmprof-0.4.8
+
+Improve and fix issues with vmprof
diff --git a/pypy/module/cpyext/setobject.py b/pypy/module/cpyext/setobject.py
--- a/pypy/module/cpyext/setobject.py
+++ b/pypy/module/cpyext/setobject.py
@@ -9,6 +9,7 @@
 
 
 PySet_Check, PySet_CheckExact = build_type_checkers("Set")
+PyFrozenSet_Check, PyFrozenSet_CheckExact = build_type_checkers("FrozenSet")
 
 @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
 def PyAnySet_Check(space, w_obj):
@@ -91,7 +92,7 @@
 """Return the length of a set or frozenset object. Equivalent to
 len(anyset).  Raises a PyExc_SystemError if anyset is not a set, frozenset,
 or an instance of a subtype."""
-if not PySet_Check(space, ref):
+if not PyAnySet_Check(space, ref):
 raise oefmt(space.w_TypeError, "expected set object")
 return PySet_GET_SIZE(space, ref)
 
@@ -104,3 +105,20 @@
 set, frozenset, or an instance of a subtype."""
 w_res = space.contains(w_obj, w_key)
 return space.int_w(w_res)
+
+@cpython_api([PyObject], PyObject)
+def PyFrozenSet_New(space, w_iterable):
+"""Return a new frozenset containing objects returned by the iterable.
+The iterable may be NULL to create a new empty frozenset.  Return the new
+set on success or NULL on failure.  Raise TypeError if iterable is
+not actually iterable.
+
+Now guaranteed to return a brand-new frozenset.  Formerly,
+frozensets of zero-length were a singleton.  This got in the way of
+building-up new frozensets with PySet_Add()."""
+if w_iterable is None:
+return space.call_function(space.w_frozenset)
+else:
+return space.call_function(space.w_frozenset, w_iterable)
+
+
diff --git a/pypy/module/cpyext/stubs.py b/pypy/module/cpyext/stubs.py
--- a/pypy/module/cpyext/stubs.py
+++ b/pypy/module/cpyext/stubs.py
@@ -1408,26 +1408,6 @@
 equivalent to the Python expression o.count(value)."""
 raise NotImplementedError
 
-@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
-def PyFrozenSet_Check(space, p):
-"""Return true if p is a frozenset object or an instance of a
-subtype."""
-raise NotImplementedError
-
-@cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL)
-def PyFrozenSet_CheckExact(space, p):
-"""Return true if p is a frozenset object but not an instance of a
-subtype."""
-raise NotImplementedError
-
-@cpython_api([PyObject], PyObject)
-def PyFrozenSet_New(space, iterable):
-"""Return a new frozenset containing objects returned by the iterable.
-The iterable may be NULL to create a new empty frozenset.  Return the new
-set on success or NULL on failure.  Raise TypeError if iterable is
-not actually iterable."""
-raise NotImplementedError
-
 @cpython_api([FILE, rffi.CCHARP], rffi.INT_real, error=-1)
 def Py_FdIsInteractive(space, fp, filename):
 """Return true (nonzero) if the standard I/O file fp with name filename is
diff --git a/pypy/module/cpyext/test/test_setobject.py 
b/pypy/module/cpyext/test/test_setobject.py
--- a/pypy/module/cpyext/test/test_setobject.py
+++ b/pypy/module/cpyext/test/test_setobject.py
@@ -9,9 +9,11 @@
 class TestTupleObject(BaseApiTest):
 def test_setobj(self, space, api):
 assert not api.PySet_Check(space.w_None)
+ 

[pypy-commit] pypy py3.5: hg merge default

2017-06-11 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r91588:c3f3e2469a13
Date: 2017-06-12 07:34 +0200
http://bitbucket.org/pypy/pypy/changeset/c3f3e2469a13/

Log:hg merge default

diff --git a/lib_pypy/_curses.py b/lib_pypy/_curses.py
--- a/lib_pypy/_curses.py
+++ b/lib_pypy/_curses.py
@@ -8,6 +8,9 @@
 
 from _curses_cffi import ffi, lib
 
+version = b"2.2"
+__version__ = b"2.2"
+
 def _copy_to_globals(name):
 globals()[name] = getattr(lib, name)
 
@@ -60,10 +63,6 @@
 
 _setup()
 
-# Do we want this?
-# version = "2.2"
-# __version__ = "2.2"
-
 
 # 
 
@@ -919,101 +918,29 @@
 return None
 
 
-# XXX: Do something about the following?
-# /* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES
-#  * and _curses.COLS */
-# #if defined(HAVE_CURSES_RESIZETERM) || defined(HAVE_CURSES_RESIZE_TERM)
-# static int
-# update_lines_cols(void)
-# {
-# PyObject *o;
-# PyObject *m = PyImport_ImportModuleNoBlock("curses");
+# Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES
+# and _curses.COLS
+def update_lines_cols():
+globals()["LINES"] = lib.LINES
+globals()["COLS"] = lib.COLS
+try:
+m = sys.modules["curses"]
+m.LINES = lib.LINES
+m.COLS = lib.COLS
+except (KeyError, AttributeError):
+pass
 
-# if (!m)
-# return 0;
 
-# o = PyInt_FromLong(LINES);
-# if (!o) {
-# Py_DECREF(m);
-# return 0;
-# }
-# if (PyObject_SetAttrString(m, "LINES", o)) {
-# Py_DECREF(m);
-# Py_DECREF(o);
-# return 0;
-# }
-# if (PyDict_SetItemString(ModDict, "LINES", o)) {
-# Py_DECREF(m);
-# Py_DECREF(o);
-# return 0;
-# }
-# Py_DECREF(o);
-# o = PyInt_FromLong(COLS);
-# if (!o) {
-# Py_DECREF(m);
-# return 0;
-# }
-# if (PyObject_SetAttrString(m, "COLS", o)) {
-# Py_DECREF(m);
-# Py_DECREF(o);
-# return 0;
-# }
-# if (PyDict_SetItemString(ModDict, "COLS", o)) {
-# Py_DECREF(m);
-# Py_DECREF(o);
-# return 0;
-# }
-# Py_DECREF(o);
-# Py_DECREF(m);
-# return 1;
-# }
-# #endif
+def resizeterm(lines, columns):
+_ensure_initialised()
+_check_ERR(lib.resizeterm(lines, columns), "resizeterm")
+update_lines_cols()
 
-# #ifdef HAVE_CURSES_RESIZETERM
-# static PyObject *
-# PyCurses_ResizeTerm(PyObject *self, PyObject *args)
-# {
-# int lines;
-# int columns;
-# PyObject *result;
 
-# PyCursesInitialised;
-
-# if (!PyArg_ParseTuple(args,"ii:resizeterm", , ))
-# return NULL;
-
-# result = PyCursesCheckERR(resizeterm(lines, columns), "resizeterm");
-# if (!result)
-# return NULL;
-# if (!update_lines_cols())
-# return NULL;
-# return result;
-# }
-
-# #endif
-
-# #ifdef HAVE_CURSES_RESIZE_TERM
-# static PyObject *
-# PyCurses_Resize_Term(PyObject *self, PyObject *args)
-# {
-# int lines;
-# int columns;
-
-# PyObject *result;
-
-# PyCursesInitialised;
-
-# if (!PyArg_ParseTuple(args,"ii:resize_term", , ))
-# return NULL;
-
-# result = PyCursesCheckERR(resize_term(lines, columns), "resize_term");
-# if (!result)
-# return NULL;
-# if (!update_lines_cols())
-# return NULL;
-# return result;
-# }
-# #endif /* HAVE_CURSES_RESIZE_TERM */
+def resize_term(lines, columns):
+_ensure_initialised()
+_check_ERR(lib.resize_term(lines, columns), "resize_term")
+update_lines_cols()
 
 
 def setsyx(y, x):
diff --git a/lib_pypy/_curses_build.py b/lib_pypy/_curses_build.py
--- a/lib_pypy/_curses_build.py
+++ b/lib_pypy/_curses_build.py
@@ -105,6 +105,13 @@
 static const chtype A_CHARTEXT;
 static const chtype A_COLOR;
 
+static const chtype A_HORIZONTAL;
+static const chtype A_LEFT;
+static const chtype A_LOW;
+static const chtype A_RIGHT;
+static const chtype A_TOP;
+static const chtype A_VERTICAL;
+
 static const int BUTTON1_RELEASED;
 static const int BUTTON1_PRESSED;
 static const int BUTTON1_CLICKED;
@@ -220,6 +227,8 @@
 int resetty(void);
 int reset_prog_mode(void);
 int reset_shell_mode(void);
+int resizeterm(int, int);
+int resize_term(int, int);
 int savetty(void);
 int scroll(WINDOW *);
 int scrollok(WINDOW *, bool);
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-06-11 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r91582:fd48d2029916
Date: 2017-06-11 23:43 +0200
http://bitbucket.org/pypy/pypy/changeset/fd48d2029916/

Log:hg merge default

diff --git a/rpython/rlib/rposix_stat.py b/rpython/rlib/rposix_stat.py
--- a/rpython/rlib/rposix_stat.py
+++ b/rpython/rlib/rposix_stat.py
@@ -710,7 +710,7 @@
 return win32_attribute_data_to_stat(win32traits, data)
 
 with lltype.scoped_alloc(
-win32traits.BY_HANDLE_FILE_INFORMATION) as data:
+win32traits.BY_HANDLE_FILE_INFORMATION, zero=True) as data:
 res = win32traits.GetFileInformationByHandle(hFile, data)
 errcode = rwin32.GetLastError_saved()
 rwin32.CloseHandle(hFile)
diff --git a/rpython/rlib/rwin32file.py b/rpython/rlib/rwin32file.py
--- a/rpython/rlib/rwin32file.py
+++ b/rpython/rlib/rwin32file.py
@@ -8,29 +8,14 @@
 from rpython.rlib.objectmodel import specialize
 from rpython.rlib.rarithmetic import intmask
 
-@specialize.memo()
-def make_win32_traits(traits):
+
+def GetCConfigGlobal():
 from rpython.rlib import rwin32
 
-if traits.str is unicode:
-suffix = 'W'
-else:
-suffix = 'A'
-
-class CConfig:
+class CConfigGlobal:
 _compilation_info_ = ExternalCompilationInfo(
 includes = ['windows.h', 'winbase.h', 'sys/stat.h'],
 )
-WIN32_FIND_DATA = platform.Struct(
-'struct _WIN32_FIND_DATA' + suffix,
-# Only interesting fields
-[('dwFileAttributes', rwin32.DWORD),
- ('nFileSizeHigh', rwin32.DWORD),
- ('nFileSizeLow', rwin32.DWORD),
- ('ftCreationTime', rwin32.FILETIME),
- ('ftLastAccessTime', rwin32.FILETIME),
- ('ftLastWriteTime', rwin32.FILETIME),
- ('cFileName', lltype.FixedSizeArray(traits.CHAR, 250))])
 ERROR_FILE_NOT_FOUND = platform.ConstantInteger(
 'ERROR_FILE_NOT_FOUND')
 ERROR_NO_MORE_FILES = platform.ConstantInteger(
@@ -93,7 +78,40 @@
  ('nFileIndexHigh', rwin32.DWORD),
  ('nFileIndexLow', rwin32.DWORD)])
 
-config = platform.configure(CConfig)
+return CConfigGlobal
+
+config_global = None
+
+
+@specialize.memo()
+def make_win32_traits(traits):
+from rpython.rlib import rwin32
+global config_global
+
+if traits.str is unicode:
+suffix = 'W'
+else:
+suffix = 'A'
+
+class CConfig:
+_compilation_info_ = ExternalCompilationInfo(
+includes = ['windows.h', 'winbase.h', 'sys/stat.h'],
+)
+WIN32_FIND_DATA = platform.Struct(
+'struct _WIN32_FIND_DATA' + suffix,
+# Only interesting fields
+[('dwFileAttributes', rwin32.DWORD),
+ ('nFileSizeHigh', rwin32.DWORD),
+ ('nFileSizeLow', rwin32.DWORD),
+ ('ftCreationTime', rwin32.FILETIME),
+ ('ftLastAccessTime', rwin32.FILETIME),
+ ('ftLastWriteTime', rwin32.FILETIME),
+ ('cFileName', lltype.FixedSizeArray(traits.CHAR, 250))])
+
+if config_global is None:
+config_global = platform.configure(GetCConfigGlobal())
+config = config_global.copy()
+config.update(platform.configure(CConfig))
 
 def external(*args, **kwargs):
 kwargs['compilation_info'] = CConfig._compilation_info_
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-06-11 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r91584:c58d210eb947
Date: 2017-06-12 00:06 +0200
http://bitbucket.org/pypy/pypy/changeset/c58d210eb947/

Log:hg merge default

diff --git a/rpython/rlib/rposix_stat.py b/rpython/rlib/rposix_stat.py
--- a/rpython/rlib/rposix_stat.py
+++ b/rpython/rlib/rposix_stat.py
@@ -748,6 +748,7 @@
 
 return make_stat_result(result)
 
+@specialize.arg(0)
 def win32_by_handle_info_to_stat(win32traits, info):
 # similar to the one above
 st_mode = win32_attributes_to_mode(win32traits, 
info.c_dwFileAttributes)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge default

2017-06-11 Thread arigo
Author: Armin Rigo 
Branch: py3.5
Changeset: r91579:6e54776fdedf
Date: 2017-06-11 23:21 +0200
http://bitbucket.org/pypy/pypy/changeset/6e54776fdedf/

Log:hg merge default

diff too long, truncating to 2000 out of 4581 lines

diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -38,3 +38,5 @@
 b16a4363e930f6401bceb499b9520955504c6cb0 release-pypy3.5-v5.7.0
 1aa2d8e03cdfab54b7121e93fda7e98ea88a30bf release-pypy2.7-v5.7.1
 2875f328eae2216a87f3d6f335092832eb031f56 release-pypy3.5-v5.7.1
+c925e73810367cd960a32592dd7f728f436c125c release-pypy2.7-v5.8.0
+a37ecfe5f142bc971a86d17305cc5d1d70abec64 release-pypy3.5-v5.8.0
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -39,11 +39,11 @@
 
   Armin Rigo
   Maciej Fijalkowski
-  Carl Friedrich Bolz
+  Carl Friedrich Bolz-Tereick
   Amaury Forgeot d'Arc
   Antonio Cuni
+  Matti Picus
   Samuele Pedroni
-  Matti Picus
   Ronan Lamy
   Alex Gaynor
   Philip Jenvey
@@ -101,28 +101,28 @@
   Vincent Legoll
   Michael Foord
   Stephan Diehl
+  Stefano Rivera
   Stefan Schwarzer
   Tomek Meka
   Valentino Volonghi
-  Stefano Rivera
   Patrick Maupin
   Devin Jeanpierre
   Bob Ippolito
   Bruno Gola
   David Malcolm
   Jean-Paul Calderone
+  Squeaky
   Edd Barrett
-  Squeaky
   Timo Paulssen
   Marius Gedminas
   Alexandre Fayolle
   Simon Burton
   Nicolas Truessel
   Martin Matusiak
+  Laurence Tratt
   Wenzhu Man
   Konstantin Lopuhin
   John Witulski
-  Laurence Tratt
   Greg Price
   Ivan Sichmann Freitas
   Dario Bertini
@@ -149,13 +149,13 @@
   Stian Andreassen
   Wanja Saatkamp
   Mike Blume
+  Joannah Nanjekye
   Gerald Klix
   Oscar Nierstrasz
   Rami Chowdhury
   Stefan H. Muller
-  Joannah Nanjekye
+  Tim Felgentreff
   Eugene Oden
-  Tim Felgentreff
   Jeff Terrace
   Henry Mason
   Vasily Kuznetsov
@@ -164,11 +164,11 @@
   Dusty Phillips
   Lukas Renggli
   Guenter Jantzen
+  Jasper Schulz
   Ned Batchelder
   Amit Regmi
   Anton Gulenko
   Sergey Matyunin
-  Jasper Schulz
   Andrew Chambers
   Nicolas Chauvat
   Andrew Durdin
@@ -183,6 +183,7 @@
   Gintautas Miliauskas
   Lucian Branescu Mihaila
   anatoly techtonik
+  Dodan Mihai
   Karl Bartel
   Gabriel Lavoie
   Jared Grubb
@@ -220,12 +221,14 @@
   Vaibhav Sood
   Reuben Cummings
   Attila Gobi
+  Alecsandru Patrascu
   Christopher Pope
   Tristan Arthur
   Christian Tismer 
   Dan Stromberg
   Carl Meyer
   Florin Papa
+  Jens-Uwe Mager
   Valentina Mukhamedzhanova
   Stefano Parmesan
   touilleMan
@@ -264,7 +267,6 @@
   Dan Buch
   Lene Wagner
   Tomo Cocoa
-  Alecsandru Patrascu
   David Lievens
   Neil Blakey-Milner
   Henrik Vendelbo
@@ -303,6 +305,7 @@
   Anna Katrina Dominguez
   Kim Jin Su
   Amber Brown
+  Nate Bragg
   Ben Darnell
   Juan Francisco Cantero Hurtado
   Godefroid Chappelle
@@ -340,11 +343,13 @@
   Jim Hunziker
   shoma hosaka
   Buck Golemon
+  Iraklis D.
   JohnDoe
   yrttyr
   Michael Chermside
   Anna Ravencroft
   remarkablerocket
+  Petre Vijiac
   Berker Peksag
   Christian Muirhead
   soareschen
diff --git a/lib-python/2.7/warnings.py b/lib-python/2.7/warnings.py
--- a/lib-python/2.7/warnings.py
+++ b/lib-python/2.7/warnings.py
@@ -309,9 +309,12 @@
 
 def __init__(self, message, category, filename, lineno, file=None,
 line=None):
-local_values = locals()
-for attr in self._WARNING_DETAILS:
-setattr(self, attr, local_values[attr])
+self.message = message
+self.category = category
+self.filename = filename
+self.lineno = lineno
+self.file = file
+self.line = line
 self._category_name = category.__name__ if category else None
 
 def __str__(self):
diff --git a/lib_pypy/_ctypes/array.py b/lib_pypy/_ctypes/array.py
--- a/lib_pypy/_ctypes/array.py
+++ b/lib_pypy/_ctypes/array.py
@@ -74,12 +74,16 @@
 return self._type_._alignmentofinstances()
 
 def _CData_output(self, resarray, base=None, index=-1):
-# this seems to be a string if we're array of char, surprise!
-from ctypes import c_char, c_wchar
-if self._type_ is c_char:
-return _rawffi.charp2string(resarray.buffer, self._length_)
-if self._type_ is c_wchar:
-return _rawffi.wcharp2unicode(resarray.buffer, self._length_)
+from _rawffi.alt import types
+# If a char_p or unichar_p is received, skip the string interpretation
+if base._ffiargtype != types.Pointer(types.char_p) and \
+   base._ffiargtype != types.Pointer(types.unichar_p):
+# this seems to be a string if we're array of char, surprise!
+from ctypes import c_char, c_wchar
+if self._type_ is c_char:
+return _rawffi.charp2string(resarray.buffer, self._length_)
+if self._type_ is c_wchar:
+return _rawffi.wcharp2unicode(resarray.buffer, self._length_)
 res = self.__new__(self)
 ffiarray = self._ffiarray.fromaddress(resarray.buffer, 

[pypy-commit] pypy py3.5: hg merge default

2017-06-04 Thread mjacob
Author: Manuel Jacob 
Branch: py3.5
Changeset: r91510:2bc0ce15d8d0
Date: 2017-06-04 14:39 +0200
http://bitbucket.org/pypy/pypy/changeset/2bc0ce15d8d0/

Log:hg merge default

diff --git a/pypy/doc/release-v5.8.0.rst b/pypy/doc/release-v5.8.0.rst
--- a/pypy/doc/release-v5.8.0.rst
+++ b/pypy/doc/release-v5.8.0.rst
@@ -8,25 +8,23 @@
 the dual release.  Note that PyPy3.5 supports Linux 64bit only for now. 
 
 This new PyPy2.7 release includes the upstream stdlib version 2.7.13, and
-PyPy3.5 (our first in the 3.5 series) includes the upstream stdlib version
-3.5.3.
+PyPy3.5 includes the upstream stdlib version 3.5.3.
 
-We continue to make incremental improvements to our C-API
-compatibility layer (cpyext). PyPy2 can now import and run many C-extension
-packages, among the most notable are Numpy, Cython, and Pandas. Performance may
-be slower than CPython, especially for frequently-called short C functions.
+This release enables `profile guided optimization` of the base interpreter,
+which may make unjitted code run faster.
+
 Please let us know if your use case is slow, we have ideas how to make things
 faster but need real-world examples (not micro-benchmarks) of problematic code.
 
 Work proceeds at a good pace on the PyPy3.5
-version due to a grant_ from the Mozilla Foundation, hence our first 3.5.3 beta
+version due to a grant_ from the Mozilla Foundation, hence our 3.5.3 beta
 release. Thanks Mozilla !!! While we do not pass all tests yet, asyncio works 
and
 as `these benchmarks show`_ it already gives a nice speed bump.
 We also backported the ``f""`` formatting from 3.6 (as an exception; otherwise
 "PyPy3.5" supports the Python 3.5 language).
 
-CFFI_ has been updated to 1.10, improving an already great package for
-interfacing with C.
+CFFI_, which is part of the PyPy release, has been updated to an unreleased 
1.10.1,
+improving an already great package for interfacing with C.
 
 As always, this release fixed many issues and bugs raised by the
 growing community of PyPy users. We strongly recommend updating.
@@ -44,6 +42,7 @@
 improvements, tweaking popular `modules`_ to run on pypy, or general `help`_
 with making RPython's JIT even better.
 
+.. _`profile guided optimization`: 
https://pythonfiles.wordpress.com/2017/05/12/enabling-profile-guided-optimizations-for-pypy
 .. _CFFI: https://cffi.readthedocs.io/en/latest/whatsnew.html
 .. _grant: 
https://morepypy.blogspot.com/2016/08/pypy-gets-funding-from-mozilla-for.html
 .. _`PyPy`: index.html
@@ -81,28 +80,52 @@
 
 See also issues that were resolved_
 
+Note that these are also merged into PyPy 3.5
+
 * New features and cleanups
 
-  * Implement PyModule_New, 
+  * Implement PyModule_New, Py_GetRecursionLimit, Py_SetRecursionLimit,
+Py_EnterRecursiveCall, Py_LeaveRecursiveCall, populate tp_descr_get and
+tp_descr_set slots,
+add conversions of ``__len__``, ``__setitem__``, ``__delitem__`` to
+appropriate C-API slots
   * Fix for multiple inheritance in app-level for C-API defined classes
   * Revert a change that removed tp_getattr (Part of the 5.7.1 bugfix release)
   * Document more differences with CPython here_
   * Add native PyPy support to profile frames in vmprof
   * Fix an issue with Exception order on failed import
   * Fix for a corner case of __future__ imports
+  * Update packaged Windows zlib, sqlite, expat and OpenSSL to versions used
+by CPython
+  * Allow windows builds to use ``jom.exe`` for compiling in parallel
+  * Rewrite ``itertools.groupby()``, following CPython
+  * Backport changes from PyPy 3.5 to minimize the code differences
+  * Improve support for BSD using patches contributed by downstream
+  * Support profile-guided optimization, enabled with --profopt, , and
+specify training data ``profoptpath``
 
-* Bug Fixes
+* Bug Fixes 
 
   * Correctly handle dict.pop where the popping key is not the same type as the
 dict's and pop is called with a default (Part of the 5.7.1 bugfix release)
   * Improve our file's universal newline .readline implementation for
 ``\n``, ``\r`` confusion
+  * Tweak issue where ctype array ``_base`` was set on empty arrays, now it
+is closer to the implementation in CPython
+  * Fix critical bugs in shadowstack that crashed multithreaded programs and
+very rarely showed up even in single threaded programs
+  * Remove flaky fastpath function call from ctypes
+  * Support passing a buffersize of 0 to socket.getsockopt
+  * Avoid hash() returning -1 in cpyext
 
 * Performance improvements:
 
   * Tweaks made to improve performance by reducing the number of guards
 inserted in jitted code, based on feedback from users
   * Add garbage collector memory pressure to some c-level allocations
+  * Speed up struck.pack, struck.pack_into
+  * Performance tweaks to round(x, n) for the case n == 0
+  * Improve zipfile performance by not doing repeated string concatenation
 
 * RPython improvements
 
@@ -119,6 +142,11 @@
 blocks are 

[pypy-commit] pypy py3.5: hg merge default

2017-05-31 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r91477:776f5fd5d727
Date: 2017-05-31 22:32 +0100
http://bitbucket.org/pypy/pypy/changeset/776f5fd5d727/

Log:hg merge default

diff too long, truncating to 2000 out of 2270 lines

diff --git a/lib-python/2.7/ctypes/test/test_unaligned_structures.py 
b/lib-python/2.7/ctypes/test/test_unaligned_structures.py
--- a/lib-python/2.7/ctypes/test/test_unaligned_structures.py
+++ b/lib-python/2.7/ctypes/test/test_unaligned_structures.py
@@ -37,7 +37,10 @@
 for typ in byteswapped_structures:
 ##print >> sys.stderr, typ.value
 self.assertEqual(typ.value.offset, 1)
-o = typ()
+try:
+o = typ()
+except NotImplementedError as e:
+self.skipTest(str(e))# for PyPy
 o.value = 4
 self.assertEqual(o.value, 4)
 
diff --git a/lib-python/2.7/zipfile.py b/lib-python/2.7/zipfile.py
--- a/lib-python/2.7/zipfile.py
+++ b/lib-python/2.7/zipfile.py
@@ -622,19 +622,23 @@
 """Read and return up to n bytes.
 If the argument is omitted, None, or negative, data is read and 
returned until EOF is reached..
 """
-buf = ''
+# PyPy modification: don't do repeated string concatenation
+buf = []
+lenbuf = 0
 if n is None:
 n = -1
 while True:
 if n < 0:
 data = self.read1(n)
-elif n > len(buf):
-data = self.read1(n - len(buf))
+elif n > lenbuf:
+data = self.read1(n - lenbuf)
 else:
-return buf
+break
 if len(data) == 0:
-return buf
-buf += data
+break
+lenbuf += len(data)
+buf.append(data)
+return "".join(buf)
 
 def _update_crc(self, newdata, eof):
 # Update the CRC using the given data.
diff --git a/lib_pypy/cffi.egg-info/PKG-INFO b/lib_pypy/cffi.egg-info/PKG-INFO
--- a/lib_pypy/cffi.egg-info/PKG-INFO
+++ b/lib_pypy/cffi.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: cffi
-Version: 1.10.0
+Version: 1.11.0
 Summary: Foreign Function Interface for Python calling C code.
 Home-page: http://cffi.readthedocs.org
 Author: Armin Rigo, Maciej Fijalkowski
diff --git a/lib_pypy/cffi/__init__.py b/lib_pypy/cffi/__init__.py
--- a/lib_pypy/cffi/__init__.py
+++ b/lib_pypy/cffi/__init__.py
@@ -4,8 +4,8 @@
 from .api import FFI
 from .error import CDefError, FFIError, VerificationError, VerificationMissing
 
-__version__ = "1.10.0"
-__version_info__ = (1, 10, 0)
+__version__ = "1.11.0"
+__version_info__ = (1, 11, 0)
 
 # The verifier module file names are based on the CRC32 of a string that
 # contains the following version number.  It may be older than __version__
diff --git a/lib_pypy/cffi/_cffi_include.h b/lib_pypy/cffi/_cffi_include.h
--- a/lib_pypy/cffi/_cffi_include.h
+++ b/lib_pypy/cffi/_cffi_include.h
@@ -8,7 +8,7 @@
the same works for the other two macros.  Py_DEBUG implies them,
but not the other way around.
 */
-#ifndef _CFFI_USE_EMBEDDING
+#if !defined(_CFFI_USE_EMBEDDING) && !defined(Py_LIMITED_API)
 #  include 
 #  if !defined(Py_DEBUG) && !defined(Py_TRACE_REFS) && !defined(Py_REF_DEBUG)
 #define Py_LIMITED_API
diff --git a/lib_pypy/cffi/_embedding.h b/lib_pypy/cffi/_embedding.h
--- a/lib_pypy/cffi/_embedding.h
+++ b/lib_pypy/cffi/_embedding.h
@@ -233,7 +233,7 @@
 f = PySys_GetObject((char *)"stderr");
 if (f != NULL && f != Py_None) {
 PyFile_WriteString("\nFrom: " _CFFI_MODULE_NAME
-   "\ncompiled with cffi version: 1.10.0"
+   "\ncompiled with cffi version: 1.11.0"
"\n_cffi_backend module: ", f);
 modules = PyImport_GetModuleDict();
 mod = PyDict_GetItemString(modules, "_cffi_backend");
diff --git a/lib_pypy/cffi/cffi_opcode.py b/lib_pypy/cffi/cffi_opcode.py
--- a/lib_pypy/cffi/cffi_opcode.py
+++ b/lib_pypy/cffi/cffi_opcode.py
@@ -105,8 +105,11 @@
 PRIM_UINT_FAST64   = 45
 PRIM_INTMAX= 46
 PRIM_UINTMAX   = 47
+PRIM_FLOATCOMPLEX  = 48
+PRIM_DOUBLECOMPLEX = 49
 
-_NUM_PRIM  = 48
+
+_NUM_PRIM  = 50
 _UNKNOWN_PRIM  = -1
 _UNKNOWN_FLOAT_PRIM= -2
 _UNKNOWN_LONG_DOUBLE   = -3
@@ -128,6 +131,8 @@
 'float':  PRIM_FLOAT,
 'double': PRIM_DOUBLE,
 'long double':PRIM_LONGDOUBLE,
+'float _Complex': PRIM_FLOATCOMPLEX,
+'double _Complex':PRIM_DOUBLECOMPLEX,
 '_Bool':  PRIM_BOOL,
 'wchar_t':PRIM_WCHAR,
 'int8_t': PRIM_INT8,
diff --git a/lib_pypy/cffi/cparser.py b/lib_pypy/cffi/cparser.py
--- a/lib_pypy/cffi/cparser.py
+++ b/lib_pypy/cffi/cparser.py
@@ -16,6 +16,7 @@
 except ImportError:
 lock = None
 
+CDEF_SOURCE_STRING = ""
 _r_comment = 

[pypy-commit] pypy py3.5: hg merge default

2017-05-25 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r91412:a76798b64382
Date: 2017-05-26 02:08 +0100
http://bitbucket.org/pypy/pypy/changeset/a76798b64382/

Log:hg merge default

diff --git a/pypy/goal/targetpypystandalone.py 
b/pypy/goal/targetpypystandalone.py
--- a/pypy/goal/targetpypystandalone.py
+++ b/pypy/goal/targetpypystandalone.py
@@ -278,11 +278,14 @@
 raise Exception("Cannot use the --output option with PyPy "
 "when --shared is on (it is by default). "
 "See issue #1971.")
-if (config.translation.profopt is not None
-and not config.translation.noprofopt):
-raise Exception("Cannot use the --profopt option "
-"when --shared is on (it is by default). "
-"See issue #2398.")
+
+# if both profopt and profoptpath are specified then we keep them as 
they are with no other changes
+if config.translation.profopt:
+if config.translation.profoptargs is None:
+config.translation.profoptargs = 
"$(RPYDIR)/../lib-python/2.7/test/regrtest.py --pgo -x test_asyncore test_gdb 
test_multiprocessing test_subprocess || true"
+elif config.translation.profoptargs is not None:
+raise Exception("Cannot use --profoptargs without specifying 
--profopt as well")
+
 if sys.platform == 'win32':
 libdir = thisdir.join('..', '..', 'libs')
 libdir.ensure(dir=1)
diff --git a/pypy/interpreter/app_main.py b/pypy/interpreter/app_main.py
--- a/pypy/interpreter/app_main.py
+++ b/pypy/interpreter/app_main.py
@@ -830,6 +830,11 @@
 executable = sys.pypy_find_executable(executable)
 stdlib_path = sys.pypy_find_stdlib(executable)
 if stdlib_path is None:
+for lib_path in sys.path:
+stdlib_path = sys.pypy_find_stdlib(lib_path)
+if stdlib_path is not None:
+break
+if stdlib_path is None:
 initstdio()
 print(STDLIB_WARNING, file=sys.stderr)
 else:
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -390,6 +390,9 @@
 for i in range(len(string)):
 self.ptr[start + i] = string[i]
 
+def as_str(self):
+return CBuffer(self).as_str()
+
 def as_readbuf(self):
 return CBuffer(self)
 
diff --git a/pypy/module/cpyext/test/test_arraymodule.py 
b/pypy/module/cpyext/test/test_arraymodule.py
--- a/pypy/module/cpyext/test/test_arraymodule.py
+++ b/pypy/module/cpyext/test/test_arraymodule.py
@@ -25,27 +25,27 @@
 
 def test_index(self):
 module = self.import_module(name='array')
-arr = module.array('i', [1,2,3,4])
+arr = module.array('i', [1, 2, 3, 4])
 assert arr[3] == 4
 raises(IndexError, arr.__getitem__, 10)
 del arr[2]
-assert arr.tolist() == [1,2,4]
+assert arr.tolist() == [1, 2, 4]
 arr[2] = 99
-assert arr.tolist() == [1,2,99]
+assert arr.tolist() == [1, 2, 99]
 
 def test_slice_get(self):
 module = self.import_module(name='array')
-arr = module.array('i', [1,2,3,4])
-assert arr[:].tolist() == [1,2,3,4]
-assert arr[1:].tolist() == [2,3,4]
-assert arr[:2].tolist() == [1,2]
-assert arr[1:3].tolist() == [2,3]
+arr = module.array('i', [1, 2, 3, 4])
+assert arr[:].tolist() == [1, 2, 3, 4]
+assert arr[1:].tolist() == [2, 3, 4]
+assert arr[:2].tolist() == [1, 2]
+assert arr[1:3].tolist() == [2, 3]
 
 def test_slice_object(self):
 module = self.import_module(name='array')
-arr = module.array('i', [1,2,3,4])
-assert arr[slice(1,3)].tolist() == [2,3]
-arr[slice(1,3)] = module.array('i', [21, 22, 23])
+arr = module.array('i', [1, 2, 3, 4])
+assert arr[slice(1, 3)].tolist() == [2,3]
+arr[slice(1, 3)] = module.array('i', [21, 22, 23])
 assert arr.tolist() == [1, 21, 22, 23, 4]
 del arr[slice(1, 3)]
 assert arr.tolist() == [1, 23, 4]
@@ -54,20 +54,15 @@
 def test_buffer(self):
 import sys
 module = self.import_module(name='array')
-arr = module.array('i', [1,2,3,4])
+arr = module.array('i', [1, 2, 3, 4])
 buf = memoryview(arr)
 exc = raises(TypeError, "buf[1] = 1")
 assert str(exc.value) == "cannot modify read-only memory"
 if sys.byteorder == 'big':
-assert bytes(buf) == (b'\0\0\0\x01'
-b'\0\0\0\x02'
-b'\0\0\0\x03'
-b'\0\0\0\x04')
+expected = b'\0\0\0\x01\0\0\0\x02\0\0\0\x03\0\0\0\x04'
 else:
-assert bytes(buf) == (b'\x01\0\0\0'
-

[pypy-commit] pypy py3.5: hg merge default

2017-05-24 Thread rlamy
Author: Ronan Lamy 
Branch: py3.5
Changeset: r91408:66108bb2353d
Date: 2017-05-24 17:35 +0100
http://bitbucket.org/pypy/pypy/changeset/66108bb2353d/

Log:hg merge default

diff too long, truncating to 2000 out of 4286 lines

diff --git a/pypy/doc/test/test_whatsnew.py b/pypy/doc/test/test_whatsnew.py
--- a/pypy/doc/test/test_whatsnew.py
+++ b/pypy/doc/test/test_whatsnew.py
@@ -102,6 +102,8 @@
 assert not not_documented
 if branch == 'py3k':
 assert not not_merged
+else:
+assert branch in documented, 'Please document this branch before 
merging: %s' % branch
 
 def test_startrev_on_default():
 doc = ROOT.join('pypy', 'doc')
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
@@ -56,3 +56,15 @@
 
 Remove faulty fastpath from ctypes
 
+.. branch: sockopt_zero
+
+Passing a buffersize of 0 to socket.getsockopt
+
+.. branch: better-test-whatsnew
+
+.. branch: faster-rstruct-2
+
+Improve the performance of struct.pack and struct.pack_into by using raw_store
+or gc_store_indexed whenever possible. Moreover, enable the existing
+struct.unpack fast path to all the existing buffer types, whereas previously
+it was enabled only for strings
diff --git a/pypy/doc/windows.rst b/pypy/doc/windows.rst
--- a/pypy/doc/windows.rst
+++ b/pypy/doc/windows.rst
@@ -23,7 +23,7 @@
 Installing Visual Compiler v9 (for Python 2.7)
 --
 
-This compiler, while the standard one for Python 2.7, is depricated. Microsoft 
has
+This compiler, while the standard one for Python 2.7, is deprecated. Microsoft 
has
 made it available as the `Microsoft Visual C++ Compiler for Python 2.7`_ (the 
link
 was checked in Nov 2016). Note that the compiler suite will be installed in
 ``C:\Users\\AppData\Local\Programs\Common\Microsoft\Visual C++ for 
Python``.
diff --git a/pypy/interpreter/buffer.py b/pypy/interpreter/buffer.py
--- a/pypy/interpreter/buffer.py
+++ b/pypy/interpreter/buffer.py
@@ -1,5 +1,6 @@
 from rpython.rlib.rstruct.error import StructError
 from rpython.rlib.buffer import StringBuffer, SubBuffer
+from rpython.rlib.mutbuffer import MutableStringBuffer
 
 from pypy.interpreter.error import oefmt
 
@@ -72,14 +73,15 @@
 def bytes_from_value(self, space, w_val):
 from pypy.module.struct.formatiterator import PackFormatIterator
 itemsize = self.getitemsize()
-fmtiter = PackFormatIterator(space, [w_val], itemsize)
+buf = MutableStringBuffer(itemsize)
+fmtiter = PackFormatIterator(space, buf, [w_val])
 try:
 fmtiter.interpret(self.getformat())
 except StructError as e:
 raise oefmt(space.w_TypeError,
 "memoryview: invalid type for format '%s'",
 self.getformat())
-return fmtiter.result.build()
+return buf.finish()
 
 def _copy_buffer(self):
 if self.getndim() == 0:
diff --git a/pypy/module/_cffi_backend/cbuffer.py 
b/pypy/module/_cffi_backend/cbuffer.py
--- a/pypy/module/_cffi_backend/cbuffer.py
+++ b/pypy/module/_cffi_backend/cbuffer.py
@@ -6,13 +6,13 @@
 from pypy.module._cffi_backend import ctypestruct
 from pypy.interpreter.buffer import SimpleView
 
-from rpython.rlib.buffer import Buffer
+from rpython.rlib.buffer import RawBuffer
 from rpython.rtyper.annlowlevel import llstr
 from rpython.rtyper.lltypesystem import rffi
 from rpython.rtyper.lltypesystem.rstr import copy_string_to_raw
 
 
-class LLBuffer(Buffer):
+class LLBuffer(RawBuffer):
 _immutable_ = True
 
 def __init__(self, raw_cdata, size):
@@ -35,7 +35,7 @@
 def getslice(self, start, stop, step, size):
 if step == 1:
 return rffi.charpsize2str(rffi.ptradd(self.raw_cdata, start), size)
-return Buffer.getslice(self, start, stop, step, size)
+return RawBuffer.getslice(self, start, stop, step, size)
 
 def setslice(self, start, string):
 raw_cdata = rffi.ptradd(self.raw_cdata, start)
diff --git a/pypy/module/_rawffi/buffer.py b/pypy/module/_rawffi/buffer.py
--- a/pypy/module/_rawffi/buffer.py
+++ b/pypy/module/_rawffi/buffer.py
@@ -1,11 +1,10 @@
 from rpython.rtyper.lltypesystem import rffi
-
-from rpython.rlib.buffer import Buffer
+from rpython.rlib.buffer import RawBuffer
 
 # XXX not the most efficient implementation
 
 
-class RawFFIBuffer(Buffer):
+class RawFFIBuffer(RawBuffer):
 _immutable_ = True
 
 def __init__(self, datainstance):
diff --git a/pypy/module/_socket/interp_socket.py 
b/pypy/module/_socket/interp_socket.py
--- a/pypy/module/_socket/interp_socket.py
+++ b/pypy/module/_socket/interp_socket.py
@@ -367,20 +367,19 @@
 except SocketError as e:
 raise converted_error(space, e)
 
-@unwrap_spec(level=int, optname=int)
-def getsockopt_w(self, space, level, optname, w_buflen=None):
+@unwrap_spec(level=int, optname=int, buflen=int)
+

  1   2   3   >