[pypy-commit] pypy default: test, fix indexing ndarray with scalar, single boolean array

2016-02-19 Thread mattip
Author: mattip 
Branch: 
Changeset: r82336:d77888929462
Date: 2016-02-19 16:29 +0200
http://bitbucket.org/pypy/pypy/changeset/d77888929462/

Log:test, fix indexing ndarray with scalar, single boolean array

diff --git a/pypy/module/micronumpy/concrete.py 
b/pypy/module/micronumpy/concrete.py
--- a/pypy/module/micronumpy/concrete.py
+++ b/pypy/module/micronumpy/concrete.py
@@ -12,8 +12,8 @@
 ArrayArgumentException, W_NumpyObject
 from pypy.module.micronumpy.iterators import ArrayIter
 from pypy.module.micronumpy.strides import (
-IntegerChunk, SliceChunk, NewAxisChunk, EllipsisChunk, new_view,
-calc_strides, calc_new_strides, shape_agreement,
+IntegerChunk, SliceChunk, NewAxisChunk, EllipsisChunk, BooleanChunk,
+new_view, calc_strides, calc_new_strides, shape_agreement,
 calculate_broadcast_strides, calc_backstrides, calc_start, is_c_contiguous,
 is_f_contiguous)
 from rpython.rlib.objectmodel import keepalive_until_here
@@ -236,6 +236,8 @@
 
 @jit.unroll_safe
 def _prepare_slice_args(self, space, w_idx):
+print '_prepare_slice_args', w_idx
+from pypy.module.micronumpy import boxes
 if space.isinstance_w(w_idx, space.w_str):
 raise oefmt(space.w_IndexError, "only integers, slices (`:`), "
 "ellipsis (`...`), numpy.newaxis (`None`) and integer or "
@@ -258,6 +260,7 @@
 result = []
 i = 0
 has_ellipsis = False
+has_filter = False
 for w_item in space.fixedview(w_idx):
 if space.is_w(w_item, space.w_Ellipsis):
 if has_ellipsis:
@@ -272,6 +275,16 @@
 elif space.isinstance_w(w_item, space.w_slice):
 result.append(SliceChunk(w_item))
 i += 1
+elif isinstance(w_item, W_NDimArray) and 
w_item.get_dtype().is_bool():
+if has_filter:
+# in CNumPy, the support for this is incomplete
+raise oefmt(space.w_ValueError,
+"an index can only have a single boolean mask; "
+"use np.take or create a sinlge mask array")
+has_filter = True
+result.append(BooleanChunk(w_item))
+elif isinstance(w_item, boxes.W_GenericBox):
+result.append(IntegerChunk(w_item.descr_int(space)))
 else:
 result.append(IntegerChunk(w_item))
 i += 1
@@ -280,11 +293,14 @@
 return result
 
 def descr_getitem(self, space, orig_arr, w_index):
+print 'concrete descr_gettiem %s' % str(w_index)[:35]
 try:
 item = self._single_item_index(space, w_index)
+print 'concrete descr_gettiem _single_item_index succeeded'
 return self.getitem(item)
 except IndexError:
 # not a single result
+print 'concrete descr_gettiem _single_item_index failed'
 chunks = self._prepare_slice_args(space, w_index)
 return new_view(space, orig_arr, chunks)
 
diff --git a/pypy/module/micronumpy/ndarray.py 
b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -107,8 +107,9 @@
 arr = W_NDimArray(self.implementation.transpose(self, None))
 return space.wrap(loop.tostring(space, arr))
 
-def getitem_filter(self, space, arr):
-if arr.ndims() > 1 and arr.get_shape() != self.get_shape():
+def getitem_filter(self, space, arr, axis=0):
+shape = self.get_shape()
+if arr.ndims() > 1 and arr.get_shape() != shape:
 raise OperationError(space.w_IndexError, space.wrap(
 "boolean index array should have 1 dimension"))
 if arr.get_size() > self.get_size():
@@ -116,14 +117,14 @@
 "index out of range for array"))
 size = loop.count_all_true(arr)
 if arr.ndims() == 1:
-if self.ndims() > 1 and arr.get_shape()[0] != self.get_shape()[0]:
+if self.ndims() > 1 and arr.get_shape()[0] != shape[axis]:
 msg = ("boolean index did not match indexed array along"
-  " dimension 0; dimension is %d but corresponding"
-  " boolean dimension is %d" % (self.get_shape()[0],
+  " dimension %d; dimension is %d but corresponding"
+  " boolean dimension is %d" % (axis, shape[axis],
   arr.get_shape()[0]))
 #warning = 
space.gettypefor(support.W_VisibleDeprecationWarning)
 space.warn(space.wrap(msg), space.w_VisibleDeprecationWarning)
-res_shape = [size] + self.get_shape()[1:]
+res_shape = shape[:axis] + [size] + shape[axis+1:]
 else:
 res_shape = [size]
 w_res = W_NDimArray.from_shape(space, res_shape, self.get_dtype(),
@@ -149,6 +150,8 @@
 def 

[pypy-commit] pypy default: remove debug cruft

2016-02-19 Thread mattip
Author: mattip 
Branch: 
Changeset: r82337:39fb9fc4c967
Date: 2016-02-19 16:31 +0200
http://bitbucket.org/pypy/pypy/changeset/39fb9fc4c967/

Log:remove debug cruft

diff --git a/pypy/module/micronumpy/concrete.py 
b/pypy/module/micronumpy/concrete.py
--- a/pypy/module/micronumpy/concrete.py
+++ b/pypy/module/micronumpy/concrete.py
@@ -236,7 +236,6 @@
 
 @jit.unroll_safe
 def _prepare_slice_args(self, space, w_idx):
-print '_prepare_slice_args', w_idx
 from pypy.module.micronumpy import boxes
 if space.isinstance_w(w_idx, space.w_str):
 raise oefmt(space.w_IndexError, "only integers, slices (`:`), "
@@ -293,14 +292,11 @@
 return result
 
 def descr_getitem(self, space, orig_arr, w_index):
-print 'concrete descr_gettiem %s' % str(w_index)[:35]
 try:
 item = self._single_item_index(space, w_index)
-print 'concrete descr_gettiem _single_item_index succeeded'
 return self.getitem(item)
 except IndexError:
 # not a single result
-print 'concrete descr_gettiem _single_item_index failed'
 chunks = self._prepare_slice_args(space, w_index)
 return new_view(space, orig_arr, chunks)
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: Fix test by pleasing sanity check.

2016-02-19 Thread mjacob
Author: Manuel Jacob 
Branch: py3.3
Changeset: r82335:99af7e9c0c5f
Date: 2016-02-19 23:36 +0100
http://bitbucket.org/pypy/pypy/changeset/99af7e9c0c5f/

Log:Fix test by pleasing sanity check.

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
@@ -487,6 +487,7 @@
 import imp
 pkg = imp.new_module('newpkg')
 sys.modules['newpkg'] = pkg
+sys.modules['newpkg.foo'] = imp.new_module('newpkg.foo')
 mydict = {'__name__': 'newpkg.foo', '__path__': '/some/path'}
 res = __import__('', mydict, None, ['bar'], 2)
 assert res is pkg
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: Check for SystemError instead of ValueError.

2016-02-19 Thread mjacob
Author: Manuel Jacob 
Branch: py3.3
Changeset: r82334:8ed10a343cd5
Date: 2016-02-19 23:11 +0100
http://bitbucket.org/pypy/pypy/changeset/8ed10a343cd5/

Log:Check for SystemError instead of ValueError.

SystemError is raised here on CPython as well, although this is
"wrong" and was fixed to be ImportError in CPython's 3.6 branch.

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
@@ -458,14 +458,14 @@
 print('__name__ =', __name__)
 from .struct import inpackage
 """, ns)
-raises(ValueError, ns['imp'])
+raises(SystemError, ns['imp'])
 
 def test_future_relative_import_error_when_in_non_package2(self):
 ns = {'__name__': __name__}
 exec("""def imp():
 from .. import inpackage
 """, ns)
-raises(ValueError, ns['imp'])
+raises(SystemError, ns['imp'])
 
 def test_relative_import_with___name__(self):
 import sys
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: Backport patch from CPython Issue 26367.

2016-02-19 Thread mjacob
Author: Manuel Jacob 
Branch: py3.3
Changeset: r82333:01b8a2d215a6
Date: 2016-02-19 22:40 +0100
http://bitbucket.org/pypy/pypy/changeset/01b8a2d215a6/

Log:Backport patch from CPython Issue 26367.

diff --git a/lib-python/3/importlib/_bootstrap.py 
b/lib-python/3/importlib/_bootstrap.py
--- a/lib-python/3/importlib/_bootstrap.py
+++ b/lib-python/3/importlib/_bootstrap.py
@@ -1496,7 +1496,7 @@
 raise TypeError("module name must be str, not {}".format(type(name)))
 if level < 0:
 raise ValueError('level must be >= 0')
-if package:
+if level > 0:
 if not isinstance(package, str):
 raise TypeError("__package__ not set to a string")
 elif package not in sys.modules:
diff --git a/lib-python/3/test/test_importlib/import_/test_relative_imports.py 
b/lib-python/3/test/test_importlib/import_/test_relative_imports.py
--- a/lib-python/3/test/test_importlib/import_/test_relative_imports.py
+++ b/lib-python/3/test/test_importlib/import_/test_relative_imports.py
@@ -208,6 +208,11 @@
 with self.assertRaises(KeyError):
 import_util.import_('sys', level=1)
 
+def test_relative_import_no_package_exists_absolute(self):
+with self.assertRaises(SystemError):
+self.__import__('sys', {'__package__': '', '__spec__': None},
+level=1)
+
 
 def test_main():
 from test.support import run_unittest
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: hg merge py3k

2016-02-19 Thread mjacob
Author: Manuel Jacob 
Branch: py3.3
Changeset: r82332:58f595f70a58
Date: 2016-02-19 22:26 +0100
http://bitbucket.org/pypy/pypy/changeset/58f595f70a58/

Log:hg merge py3k

diff --git a/lib-python/2.7/distutils/command/build_ext.py 
b/lib-python/2.7/distutils/command/build_ext.py
--- a/lib-python/2.7/distutils/command/build_ext.py
+++ b/lib-python/2.7/distutils/command/build_ext.py
@@ -188,7 +188,7 @@
 # the 'libs' directory is for binary installs - we assume that
 # must be the *native* platform.  But we don't really support
 # cross-compiling via a binary install anyway, so we let it go.
-self.library_dirs.append(os.path.join(sys.exec_prefix, 'include'))
+self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
 if self.debug:
 self.build_temp = os.path.join(self.build_temp, "Debug")
 else:
diff --git a/lib_pypy/_pypy_testcapi.py b/lib_pypy/_pypy_testcapi.py
--- a/lib_pypy/_pypy_testcapi.py
+++ b/lib_pypy/_pypy_testcapi.py
@@ -62,7 +62,7 @@
 if sys.platform == 'win32':
 # XXX pyconfig.h uses a pragma to link to the import library,
 # which is currently python3.lib
-library = os.path.join(thisdir, '..', 'include', 'python32')
+library = os.path.join(thisdir, '..', 'libs', 'python32')
 if not os.path.exists(library + '.lib'):
 # For a local translation or nightly build
 library = os.path.join(thisdir, '..', 'pypy', 'goal', 'python32')
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.5.1
+Version: 1.5.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, CDefError, FFIError
 from .ffiplatform import VerificationError, VerificationMissing
 
-__version__ = "1.5.1"
-__version_info__ = (1, 5, 1)
+__version__ = "1.5.2"
+__version_info__ = (1, 5, 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/_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.5.1"
+   "\ncompiled with cffi version: 1.5.2"
"\n_cffi_backend module: ", f);
 modules = PyImport_GetModuleDict();
 mod = PyDict_GetItemString(modules, "_cffi_backend");
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
@@ -1,4 +1,4 @@
-import sys, sysconfig, types
+import sys, types
 from .lock import allocate_lock
 
 try:
@@ -550,16 +550,34 @@
 lst.append(value)
 #
 if '__pypy__' in sys.builtin_module_names:
+import os
+if sys.platform == "win32":
+# we need 'libpypy-c.lib'.  Current distributions of
+# pypy (>= 4.1) contain it as 'libs/python27.lib'.
+pythonlib = "python27"
+if hasattr(sys, 'prefix'):
+ensure('library_dirs', os.path.join(sys.prefix, 'libs'))
+else:
+# we need 'libpypy-c.{so,dylib}', which should be by
+# default located in 'sys.prefix/bin' for installed
+# systems.
+pythonlib = "pypy-c"
+if hasattr(sys, 'prefix'):
+ensure('library_dirs', os.path.join(sys.prefix, 'bin'))
+# On uninstalled pypy's, the libpypy-c is typically found in
+# .../pypy/goal/.
 if hasattr(sys, 'prefix'):
-import os
-ensure('library_dirs', os.path.join(sys.prefix, 'bin'))
-pythonlib = "pypy-c"
+ensure('library_dirs', os.path.join(sys.prefix, 'pypy', 
'goal'))
 else:
 if sys.platform == "win32":
 template = "python%d%d"
 if hasattr(sys, 'gettotalrefcount'):
 template += '_d'
 else:
+try:
+import sysconfig
+except ImportError:# 2.6
+from distutils import sysconfig
 template = "python%d.%d"
 if sysconfig.get_config_var('DEBUG_EXT'):
 template += 

[pypy-commit] pypy py3k: Add exec() workaround for running on top of old CPython 2.7 versions.

2016-02-19 Thread mjacob
Author: Manuel Jacob 
Branch: py3k
Changeset: r82330:1bf2ad223b9c
Date: 2016-02-19 20:58 +0100
http://bitbucket.org/pypy/pypy/changeset/1bf2ad223b9c/

Log:Add exec() workaround for running on top of old CPython 2.7
versions.

diff --git a/pypy/module/__pypy__/test/test_magic.py 
b/pypy/module/__pypy__/test/test_magic.py
--- a/pypy/module/__pypy__/test/test_magic.py
+++ b/pypy/module/__pypy__/test/test_magic.py
@@ -15,6 +15,10 @@
 __pypy__.save_module_content_for_future_reload(sys)
 
 def test_new_code_hook(self):
+# workaround for running on top of old CPython 2.7 versions
+def exec_(code, d):
+exec(code, d)
+
 l = []
 
 def callable(code):
@@ -24,7 +28,7 @@
 __pypy__.set_code_callback(callable)
 d = {}
 try:
-exec("""
+exec_("""
 def f():
 pass
 """, d)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: Fix _imp module direct app tests.

2016-02-19 Thread mjacob
Author: Manuel Jacob 
Branch: py3.3
Changeset: r82331:7aac73fa16ed
Date: 2016-02-19 21:52 +0100
http://bitbucket.org/pypy/pypy/changeset/7aac73fa16ed/

Log:Fix _imp module direct app tests.

diff --git a/pypy/module/imp/test/test_app.py b/pypy/module/imp/test/test_app.py
--- a/pypy/module/imp/test/test_app.py
+++ b/pypy/module/imp/test/test_app.py
@@ -8,7 +8,6 @@
 }
 
 def setup_class(cls):
-cls.w_imp = cls.space.getbuiltinmodule('_imp')
 cls.w_file_module = cls.space.wrap(__file__)
 latin1 = udir.join('latin1.py')
 latin1.write("# -*- coding: iso-8859-1 -*\n")
@@ -75,7 +74,8 @@
 assert type == 'rb'
 
 def test_ext_suffixes(self):
-for suffix in self.imp.extension_suffixes():
+import _imp
+for suffix in _imp.extension_suffixes():
 assert suffix.endswith(('.pyd', '.so'))
 
 def test_obscure_functions(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: hg merge default

2016-02-19 Thread mjacob
Author: Manuel Jacob 
Branch: py3k
Changeset: r82329:4634d8e8bf6e
Date: 2016-02-19 19:04 +0100
http://bitbucket.org/pypy/pypy/changeset/4634d8e8bf6e/

Log:hg merge default

diff --git a/lib-python/2.7/distutils/command/build_ext.py 
b/lib-python/2.7/distutils/command/build_ext.py
--- a/lib-python/2.7/distutils/command/build_ext.py
+++ b/lib-python/2.7/distutils/command/build_ext.py
@@ -188,7 +188,7 @@
 # the 'libs' directory is for binary installs - we assume that
 # must be the *native* platform.  But we don't really support
 # cross-compiling via a binary install anyway, so we let it go.
-self.library_dirs.append(os.path.join(sys.exec_prefix, 'include'))
+self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
 if self.debug:
 self.build_temp = os.path.join(self.build_temp, "Debug")
 else:
diff --git a/lib_pypy/_pypy_testcapi.py b/lib_pypy/_pypy_testcapi.py
--- a/lib_pypy/_pypy_testcapi.py
+++ b/lib_pypy/_pypy_testcapi.py
@@ -62,7 +62,7 @@
 if sys.platform == 'win32':
 # XXX pyconfig.h uses a pragma to link to the import library,
 # which is currently python3.lib
-library = os.path.join(thisdir, '..', 'include', 'python32')
+library = os.path.join(thisdir, '..', 'libs', 'python32')
 if not os.path.exists(library + '.lib'):
 # For a local translation or nightly build
 library = os.path.join(thisdir, '..', 'pypy', 'goal', 'python32')
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.5.1
+Version: 1.5.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, CDefError, FFIError
 from .ffiplatform import VerificationError, VerificationMissing
 
-__version__ = "1.5.1"
-__version_info__ = (1, 5, 1)
+__version__ = "1.5.2"
+__version_info__ = (1, 5, 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/_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.5.1"
+   "\ncompiled with cffi version: 1.5.2"
"\n_cffi_backend module: ", f);
 modules = PyImport_GetModuleDict();
 mod = PyDict_GetItemString(modules, "_cffi_backend");
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
@@ -1,4 +1,4 @@
-import sys, sysconfig, types
+import sys, types
 from .lock import allocate_lock
 
 try:
@@ -550,16 +550,34 @@
 lst.append(value)
 #
 if '__pypy__' in sys.builtin_module_names:
+import os
+if sys.platform == "win32":
+# we need 'libpypy-c.lib'.  Current distributions of
+# pypy (>= 4.1) contain it as 'libs/python27.lib'.
+pythonlib = "python27"
+if hasattr(sys, 'prefix'):
+ensure('library_dirs', os.path.join(sys.prefix, 'libs'))
+else:
+# we need 'libpypy-c.{so,dylib}', which should be by
+# default located in 'sys.prefix/bin' for installed
+# systems.
+pythonlib = "pypy-c"
+if hasattr(sys, 'prefix'):
+ensure('library_dirs', os.path.join(sys.prefix, 'bin'))
+# On uninstalled pypy's, the libpypy-c is typically found in
+# .../pypy/goal/.
 if hasattr(sys, 'prefix'):
-import os
-ensure('library_dirs', os.path.join(sys.prefix, 'bin'))
-pythonlib = "pypy-c"
+ensure('library_dirs', os.path.join(sys.prefix, 'pypy', 
'goal'))
 else:
 if sys.platform == "win32":
 template = "python%d%d"
 if hasattr(sys, 'gettotalrefcount'):
 template += '_d'
 else:
+try:
+import sysconfig
+except ImportError:# 2.6
+from distutils import sysconfig
 template = "python%d.%d"
 if sysconfig.get_config_var('DEBUG_EXT'):
 template += 

[pypy-commit] pypy llvm-translation-backend: Use GCTransformer's get_prebuilt_hash() method.

2016-02-19 Thread mjacob
Author: Manuel Jacob 
Branch: llvm-translation-backend
Changeset: r82328:ee28a2e5145b
Date: 2016-02-17 00:56 +0100
http://bitbucket.org/pypy/pypy/changeset/ee28a2e5145b/

Log:Use GCTransformer's get_prebuilt_hash() method.

diff --git a/rpython/translator/llvm/genllvm.py 
b/rpython/translator/llvm/genllvm.py
--- a/rpython/translator/llvm/genllvm.py
+++ b/rpython/translator/llvm/genllvm.py
@@ -98,7 +98,7 @@
 else:
 global_attrs += 'global'
 
-hash_ = database.genllvm.gcpolicy.get_prebuilt_hash(obj)
+hash_ = database.genllvm.gcpolicy.gctransformer.get_prebuilt_hash(obj)
 if hash_ is None:
 if self.varsize:
 extra_len = self.get_extra_len(obj)
@@ -1653,9 +1653,6 @@
 def get_gc_fields(self):
 return [(database.get_type(self.gctransformer.HDR), '_gc_header')]
 
-def get_prebuilt_hash(self, obj):
-pass
-
 def finish(self):
 genllvm = self.genllvm
 while self.delayed_ptrs:
@@ -1696,23 +1693,10 @@
 
 def get_gc_field_values(self, obj):
 obj = lltype.top_container(obj)
-needs_hash = self.get_prebuilt_hash(obj) is not None
+needs_hash = self.gctransformer.get_prebuilt_hash(obj) is not None
 hdr = self.gctransformer.gc_header_for(obj, needs_hash)
 return [hdr._obj]
 
-# from c backend
-def get_prebuilt_hash(self, obj):
-# for prebuilt objects that need to have their hash stored and
-# restored.  Note that only structures that are StructNodes all
-# the way have their hash stored (and not e.g. structs with var-
-# sized arrays at the end).  'obj' must be the top_container.
-TYPE = lltype.typeOf(obj)
-if not isinstance(TYPE, lltype.GcStruct):
-return None
-if TYPE._is_varsize():
-return None
-return getattr(obj, '_hash_cache_', None)
-
 
 class RefcountGCPolicy(GCPolicy):
 class RttiType(FuncType):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy desc-specialize: Extract method init_specializer()

2016-02-19 Thread rlamy
Author: Ronan Lamy 
Branch: desc-specialize
Changeset: r82326:0b89e9760cd8
Date: 2016-02-18 05:23 +
http://bitbucket.org/pypy/pypy/changeset/0b89e9760cd8/

Log:Extract method init_specializer()

diff --git a/rpython/annotator/description.py b/rpython/annotator/description.py
--- a/rpython/annotator/description.py
+++ b/rpython/annotator/description.py
@@ -283,17 +283,20 @@
 (self.name, e.getmsg()))
 return inputcells
 
-def specialize(self, inputcells, op=None):
-if (op is None and
-getattr(self.bookkeeper, "position_key", None) is not None):
-_, block, i = self.bookkeeper.position_key
-op = block.operations[i]
+def init_specializer(self):
 if self.specializer is None:
 # get the specializer based on the tag of the 'pyobj'
 # (if any), according to the current policy
 tag = getattr(self.pyobj, '_annspecialcase_', None)
 policy = self.bookkeeper.annotator.policy
 self.specializer = policy.get_specializer(tag)
+
+def specialize(self, inputcells, op=None):
+if (op is None and
+getattr(self.bookkeeper, "position_key", None) is not None):
+_, block, i = self.bookkeeper.position_key
+op = block.operations[i]
+self.init_specializer()
 enforceargs = getattr(self.pyobj, '_annenforceargs_', None)
 signature = getattr(self.pyobj, '_signature_', None)
 if enforceargs and signature:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy desc-specialize: Create annotator.using_policy() context manager

2016-02-19 Thread rlamy
Author: Ronan Lamy 
Branch: desc-specialize
Changeset: r82327:f979a9068595
Date: 2016-02-19 17:16 +
http://bitbucket.org/pypy/pypy/changeset/f979a9068595/

Log:Create annotator.using_policy() context manager

diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -2,6 +2,7 @@
 
 import types
 from collections import defaultdict
+from contextlib import contextmanager
 
 from rpython.tool.ansi_print import ansi_log
 from rpython.tool.pairtype import pair
@@ -89,14 +90,9 @@
 
 def get_call_parameters(self, function, args_s, policy):
 desc = self.bookkeeper.getdesc(function)
-prevpolicy = self.policy
-self.policy = policy
-self.bookkeeper.enter(None)
-try:
-return desc.get_call_parameters(args_s)
-finally:
-self.bookkeeper.leave()
-self.policy = prevpolicy
+with self.using_policy(policy):
+with self.bookkeeper.at_position(None):
+return desc.get_call_parameters(args_s)
 
 def annotate_helper(self, function, args_s, policy=None):
 if policy is None:
@@ -111,15 +107,23 @@
 return graph
 
 def complete_helpers(self, policy):
-saved = self.policy, self.added_blocks
+saved = self.added_blocks
+self.added_blocks = {}
+with self.using_policy(policy):
+try:
+self.complete()
+# invoke annotation simplifications for the new blocks
+self.simplify(block_subset=self.added_blocks)
+finally:
+self.added_blocks = saved
+
+@contextmanager
+def using_policy(self, policy):
+"""A context manager that temporarily replaces the annotator policy"""
+old_policy = self.policy
 self.policy = policy
-try:
-self.added_blocks = {}
-self.complete()
-# invoke annotation simplifications for the new blocks
-self.simplify(block_subset=self.added_blocks)
-finally:
-self.policy, self.added_blocks = saved
+yield
+self.policy = old_policy
 
 def build_graph_types(self, flowgraph, inputcells, complete_now=True):
 checkgraph(flowgraph)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy.org extradoc: update the values

2016-02-19 Thread arigo
Author: Armin Rigo 
Branch: extradoc
Changeset: r703:61c91eaec11c
Date: 2016-02-19 18:11 +0100
http://bitbucket.org/pypy/pypy.org/changeset/61c91eaec11c/

Log:update the values

diff --git a/don1.html b/don1.html
--- a/don1.html
+++ b/don1.html
@@ -15,7 +15,7 @@
 
 

-   $62855 of $105000 (59.9%)
+   $62898 of $105000 (59.9%)


 
@@ -23,7 +23,7 @@
   
   This donation goes towards supporting Python 3 in 
PyPy.
   Current status:
-we have $8020 left
+we have $8059 left
   in the account. Read proposal
   
   
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy cpyext-gc-support-2: Test and fix for immortal objects on which we attach a pyobj

2016-02-19 Thread arigo
Author: Armin Rigo 
Branch: cpyext-gc-support-2
Changeset: r82325:1f5a3c24e736
Date: 2016-02-19 18:08 +0100
http://bitbucket.org/pypy/pypy/changeset/1f5a3c24e736/

Log:Test and fix for immortal objects on which we attach a pyobj

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
@@ -2973,9 +2973,13 @@
 self.rrc_o_list_old = new_o_list
 
 def _rrc_major_free(self, pyobject, surviving_list, surviving_dict):
+# The pyobject survives if the corresponding obj survives.
+# This is true if the obj has one of the following two flags:
+#  * GCFLAG_VISITED: was seen during tracing
+#  * GCFLAG_NO_HEAP_PTRS: immortal object never traced (so far)
 intobj = self._pyobj(pyobject).ob_pypy_link
 obj = llmemory.cast_int_to_adr(intobj)
-if self.header(obj).tid & GCFLAG_VISITED:
+if self.header(obj).tid & (GCFLAG_VISITED | GCFLAG_NO_HEAP_PTRS):
 surviving_list.append(pyobject)
 if surviving_dict:
 surviving_dict.insertclean(obj, pyobject)
diff --git a/rpython/memory/gc/test/test_rawrefcount.py 
b/rpython/memory/gc/test/test_rawrefcount.py
--- a/rpython/memory/gc/test/test_rawrefcount.py
+++ b/rpython/memory/gc/test/test_rawrefcount.py
@@ -29,7 +29,7 @@
 assert count2 - count1 == expected_trigger
 
 def _rawrefcount_pair(self, intval, is_light=False, is_pyobj=False,
-  create_old=False):
+  create_old=False, create_immortal=False):
 if is_light:
 rc = REFCNT_FROM_PYPY_LIGHT
 else:
@@ -37,14 +37,19 @@
 self.trigger = []
 self.gc.rawrefcount_init(lambda: self.trigger.append(1))
 #
-p1 = self.malloc(S)
+if create_immortal:
+p1 = lltype.malloc(S, immortal=True)
+else:
+p1 = self.malloc(S)
 p1.x = intval
-if create_old:
+if create_immortal:
+self.consider_constant(p1)
+elif create_old:
 self.stackroots.append(p1)
 self._collect(major=False)
 p1 = self.stackroots.pop()
 p1ref = lltype.cast_opaque_ptr(llmemory.GCREF, p1)
-r1 = lltype.malloc(PYOBJ_HDR, flavor='raw')
+r1 = lltype.malloc(PYOBJ_HDR, flavor='raw', immortal=create_immortal)
 r1.ob_refcnt = rc
 r1.ob_pypy_link = 0
 r1addr = llmemory.cast_ptr_to_adr(r1)
@@ -268,3 +273,10 @@
 self.test_pyobject_dies(old=True)
 def test_pyobject_survives_from_obj_old(self):
 self.test_pyobject_survives_from_obj(old=True)
+
+def test_pyobject_attached_to_prebuilt_obj(self):
+p1, p1ref, r1, r1addr, check_alive = (
+self._rawrefcount_pair(42, create_immortal=True))
+check_alive(0)
+self._collect(major=True)
+check_alive(0)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: update

2016-02-19 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2644:5d4960993342
Date: 2016-02-19 16:27 +0100
http://bitbucket.org/cffi/cffi/changeset/5d4960993342/

Log:update

diff --git a/doc/source/embedding.rst b/doc/source/embedding.rst
--- a/doc/source/embedding.rst
+++ b/doc/source/embedding.rst
@@ -303,8 +303,8 @@
   -Wl,-rpath=/path/to/libmyplugin``, possibly with ``$ORIGIN``.  The
   ``$`` in ``$ORIGIN`` causes various shell problems on its own: if
   using a common shell you need to say ``gcc
-  -Wl,-rpath=\$ORIGIN/../venv/bin``.  From a Makefile, you need to say
-  something like ``gcc -Wl,-rpath=\$$ORIGIN/../venv/bin``.
+  -Wl,-rpath=\$ORIGIN``.  From a Makefile, you need to say
+  something like ``gcc -Wl,-rpath=\$$ORIGIN``.
 
 
 Using multiple CFFI-made DLLs
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: A dump of my experiences with rpaths and $ORIGIN messes

2016-02-19 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2643:96df07b3e9ba
Date: 2016-02-19 16:22 +0100
http://bitbucket.org/cffi/cffi/changeset/96df07b3e9ba/

Log:A dump of my experiences with rpaths and $ORIGIN messes

diff --git a/doc/source/embedding.rst b/doc/source/embedding.rst
--- a/doc/source/embedding.rst
+++ b/doc/source/embedding.rst
@@ -76,7 +76,10 @@
 library.  It is a file with the extension ``.dll`` on Windows,
 ``.dylib`` on Mac OS/X, or ``.so`` on other platforms.  As usual, it
 is produced by generating some intermediate ``.c`` code and then
-calling the regular platform-specific C compiler.
+calling the regular platform-specific C compiler.  See below__ for
+some pointers to C-level issues with using the probuced library.
+
+.. __: `Issues about using the .so`_
 
 Here are some details about the methods used above:
 
@@ -231,6 +234,79 @@
 than 1.5.  CFFI 1.5 or newer must be installed in the running Python.
 
 
+Issues about using the .so
+--
+
+This paragraph describes issues that are not necessarily specific to
+CFFI.  It assumes that you have obtained the ``.so/.dylib/.dll`` file as
+described above, but that you have troubles using it.  (In summary: it
+is a mess.  This is my own experience, slowly built by using Google and
+by listening to reports from various platforms.  Please report any
+inaccuracies in this paragraph or better ways to do things.)
+
+* The file produced by CFFI should follow this naming pattern:
+  ``libmy_plugin.so`` on Linux, ``libmy_plugin.dylib`` on Mac, or
+  ``my_plugin.dll`` on Windows (no ``lib`` prefix on Windows).
+
+* First note that this file does not contain the Python interpreter
+  nor the standard library of Python.  You still need it to be
+  somewhere.  There are ways to compact it to a smaller number of files,
+  but this is outside the scope of CFFI (please report if you used some
+  of these ways successfully so that I can add some links here).
+
+* In what we'll call the "main program", the ``.so`` can be either
+  used dynamically (e.g. by calling ``dlopen()`` or ``LoadLibrary()``
+  inside the main program), or at compile-time (e.g. by compiling it
+  with ``gcc -lmy_plugin``).  The former case is always used if you're
+  building a plugin for a program, and the program itself doesn't need
+  to be recompiled.  The latter case is for making a CFFI library that
+  is more tightly integrated inside the main program.
+
+* In the case of compile-time usage: you can add the gcc
+  option ``-Lsome/path/`` before ``-lmy_plugin`` to describe where the
+  ``libmy_plugin.so`` is.  On some platforms, notably Linux, ``gcc``
+  will complain if it can find ``libmy_plugin.so`` but not
+  ``libpython27.so`` or ``libpypy-c.so``.  To fix it, you need to call
+  ``LD_LIBRARY_PATH=/some/path/to/libpypy gcc``.
+
+* When actually executing the main program, it needs to find the
+  ``libmy_plugin.so`` but also ``libpython27.so`` or ``libpypy-c.so``.
+  For PyPy, unpack a PyPy distribution and you get a full directory
+  structure with ``libpypy-c.so`` inside a ``bin`` subdirectory, or on
+  Windows ``pypy-c.dll`` inside the top directory; you must not move
+  this file around, but just point to it.  One way to point to it is by
+  running the main program with some environment variable:
+  ``LD_LIBRARY_PATH=/some/path/to/libpypy`` on Linux,
+  ``DYLD_LIBRARY_PATH=/some/path/to/libpypy`` on OS/X.
+
+* You can avoid the ``LD_LIBRARY_PATH`` issue if you compile
+  ``libmy_plugin.so`` with the path hard-coded inside in the first
+  place.  On Linux, this is done by ``gcc -Wl,-rpath=/some/path``.  You
+  would put this option in ``ffi.set_source("my_plugin", ...,
+  extra_link_args=['-Wl,-rpath=/some/path/to/libpypy'])``.  The path can
+  start with ``$ORIGIN`` to mean "the directory where
+  ``libmy_plugin.so`` is".  You can then specify a path relative to that
+  place, like ``extra_link_args=['-Wl,-rpath=$ORIGIN/../venv/bin']``.
+  Use ``ldd libmy_plugin.so`` to look at what path is currently compiled
+  in after the expansion of ``$ORIGIN``.)
+
+  After this, you don't need ``LD_LIBRARY_PATH`` any more to locate
+  ``libpython27.so`` or ``libpypy-c.so`` at runtime.  In theory it
+  should also cover the call to ``gcc`` for the main program.  I wasn't
+  able to make ``gcc`` happy without ``LD_LIBRARY_PATH`` on Linux if
+  the rpath starts with ``$ORIGIN``, though.
+
+* The same rpath trick might be used to let the main program find
+  ``libmy_plugin.so`` in the first place without ``LD_LIBRARY_PATH``.
+  (This doesn't apply if the main program uses ``dlopen()`` to load it
+  as a dynamic plugin.)  You'd make the main program with ``gcc
+  -Wl,-rpath=/path/to/libmyplugin``, possibly with ``$ORIGIN``.  The
+  ``$`` in ``$ORIGIN`` causes various shell problems on its own: if
+  using a common shell you need to say ``gcc
+  -Wl,-rpath=\$ORIGIN/../venv/bin``.  From a Makefile, you need to say
+  something like ``gcc 

[pypy-commit] cffi default: merge heads

2016-02-19 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2642:d2a90d323791
Date: 2016-02-19 10:38 +0100
http://bitbucket.org/cffi/cffi/changeset/d2a90d323791/

Log:merge heads

diff --git a/testing/cffi0/test_zintegration.py 
b/testing/cffi0/test_zintegration.py
--- a/testing/cffi0/test_zintegration.py
+++ b/testing/cffi0/test_zintegration.py
@@ -11,7 +11,7 @@
 def create_venv(name):
 tmpdir = udir.join(name)
 try:
-subprocess.check_call(['virtualenv', '--distribute',
+subprocess.check_call(['virtualenv', '--never-download',
'-p', os.path.abspath(sys.executable),
str(tmpdir)])
 except OSError as e:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] cffi default: more pypy tweaks

2016-02-19 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r2641:b4991ae7ce3a
Date: 2016-02-19 10:37 +0100
http://bitbucket.org/cffi/cffi/changeset/b4991ae7ce3a/

Log:more pypy tweaks

diff --git a/cffi/api.py b/cffi/api.py
--- a/cffi/api.py
+++ b/cffi/api.py
@@ -550,6 +550,7 @@
 lst.append(value)
 #
 if '__pypy__' in sys.builtin_module_names:
+import os
 if sys.platform == "win32":
 # we need 'libpypy-c.lib'.  Current distributions of
 # pypy (>= 4.1) contain it as 'libs/python27.lib'.
@@ -558,11 +559,15 @@
 ensure('library_dirs', os.path.join(sys.prefix, 'libs'))
 else:
 # we need 'libpypy-c.{so,dylib}', which should be by
-# default located in 'sys.prefix/bin'
+# default located in 'sys.prefix/bin' for installed
+# systems.
 pythonlib = "pypy-c"
 if hasattr(sys, 'prefix'):
-import os
 ensure('library_dirs', os.path.join(sys.prefix, 'bin'))
+# On uninstalled pypy's, the libpypy-c is typically found in
+# .../pypy/goal/.
+if hasattr(sys, 'prefix'):
+ensure('library_dirs', os.path.join(sys.prefix, 'pypy', 
'goal'))
 else:
 if sys.platform == "win32":
 template = "python%d%d"
diff --git a/testing/embedding/test_basic.py b/testing/embedding/test_basic.py
--- a/testing/embedding/test_basic.py
+++ b/testing/embedding/test_basic.py
@@ -27,11 +27,14 @@
 
 def prefix_pythonpath():
 cffi_base = os.path.dirname(os.path.dirname(local_dir))
-pythonpath = os.environ.get('PYTHONPATH', '').split(os.pathsep)
+pythonpath = org_env.get('PYTHONPATH', '').split(os.pathsep)
 if cffi_base not in pythonpath:
 pythonpath.insert(0, cffi_base)
 return os.pathsep.join(pythonpath)
 
+def setup_module(mod):
+mod.org_env = os.environ.copy()
+
 
 class EmbeddingTests:
 _compiled_modules = {}
@@ -45,14 +48,12 @@
 def get_path(self):
 return str(self._path.ensure(dir=1))
 
-def _run_base(self, args, env_extra={}, **kwds):
-print('RUNNING:', args, env_extra, kwds)
-env = os.environ.copy()
-env.update(env_extra)
-return subprocess.Popen(args, env=env, **kwds)
+def _run_base(self, args, **kwds):
+print('RUNNING:', args, kwds)
+return subprocess.Popen(args, **kwds)
 
-def _run(self, args, env_extra={}):
-popen = self._run_base(args, env_extra, cwd=self.get_path(),
+def _run(self, args):
+popen = self._run_base(args, cwd=self.get_path(),
  stdout=subprocess.PIPE,
  universal_newlines=True)
 output = popen.stdout.read()
@@ -64,6 +65,7 @@
 return output
 
 def prepare_module(self, name):
+self.patch_environment()
 if name not in self._compiled_modules:
 path = self.get_path()
 filename = '%s.py' % name
@@ -73,9 +75,8 @@
 # find a solution to that: we could hack sys.path inside the
 # script run here, but we can't hack it in the same way in
 # execute().
-env_extra = {'PYTHONPATH': prefix_pythonpath()}
-output = self._run([sys.executable, os.path.join(local_dir, 
filename)],
-   env_extra=env_extra)
+output = self._run([sys.executable,
+os.path.join(local_dir, filename)])
 match = re.compile(r"\bFILENAME: (.+)").search(output)
 assert match
 dynamic_lib_name = match.group(1)
@@ -119,28 +120,35 @@
 finally:
 os.chdir(curdir)
 
+def patch_environment(self):
+path = self.get_path()
+# for libpypy-c.dll or Python27.dll
+path = os.path.split(sys.executable)[0] + os.path.pathsep + path
+env_extra = {'PYTHONPATH': prefix_pythonpath()}
+if sys.platform == 'win32':
+envname = 'PATH'
+else:
+envname = 'LD_LIBRARY_PATH'
+libpath = org_env.get(envname)
+if libpath:
+libpath = path + os.path.pathsep + libpath
+else:
+libpath = path
+env_extra[envname] = libpath
+for key, value in sorted(env_extra.items()):
+if os.environ.get(key) != value:
+print '* setting env var %r to %r' % (key, value)
+os.environ[key] = value
+
 def execute(self, name):
 path = self.get_path()
-env_extra = {'PYTHONPATH': prefix_pythonpath()}
-if sys.platform == 'win32':
-_path = os.environ.get('PATH')
-# for libpypy-c.dll or Python27.dll
-_path = os.path.split(sys.executable)[0] + ';' + _path
-env_extra['PATH'] = _path
-else:
-libpath = 

[pypy-commit] pypy default: import cffi/b4991ae7ce3a

2016-02-19 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r82324:e79f457ab18f
Date: 2016-02-19 10:37 +0100
http://bitbucket.org/pypy/pypy/changeset/e79f457ab18f/

Log:import cffi/b4991ae7ce3a

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
@@ -550,6 +550,7 @@
 lst.append(value)
 #
 if '__pypy__' in sys.builtin_module_names:
+import os
 if sys.platform == "win32":
 # we need 'libpypy-c.lib'.  Current distributions of
 # pypy (>= 4.1) contain it as 'libs/python27.lib'.
@@ -558,11 +559,15 @@
 ensure('library_dirs', os.path.join(sys.prefix, 'libs'))
 else:
 # we need 'libpypy-c.{so,dylib}', which should be by
-# default located in 'sys.prefix/bin'
+# default located in 'sys.prefix/bin' for installed
+# systems.
 pythonlib = "pypy-c"
 if hasattr(sys, 'prefix'):
-import os
 ensure('library_dirs', os.path.join(sys.prefix, 'bin'))
+# On uninstalled pypy's, the libpypy-c is typically found in
+# .../pypy/goal/.
+if hasattr(sys, 'prefix'):
+ensure('library_dirs', os.path.join(sys.prefix, 'pypy', 
'goal'))
 else:
 if sys.platform == "win32":
 template = "python%d%d"
diff --git a/pypy/module/test_lib_pypy/cffi_tests/embedding/test_basic.py 
b/pypy/module/test_lib_pypy/cffi_tests/embedding/test_basic.py
--- a/pypy/module/test_lib_pypy/cffi_tests/embedding/test_basic.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/embedding/test_basic.py
@@ -28,11 +28,14 @@
 
 def prefix_pythonpath():
 cffi_base = os.path.dirname(os.path.dirname(local_dir))
-pythonpath = os.environ.get('PYTHONPATH', '').split(os.pathsep)
+pythonpath = org_env.get('PYTHONPATH', '').split(os.pathsep)
 if cffi_base not in pythonpath:
 pythonpath.insert(0, cffi_base)
 return os.pathsep.join(pythonpath)
 
+def setup_module(mod):
+mod.org_env = os.environ.copy()
+
 
 class EmbeddingTests:
 _compiled_modules = {}
@@ -46,14 +49,12 @@
 def get_path(self):
 return str(self._path.ensure(dir=1))
 
-def _run_base(self, args, env_extra={}, **kwds):
-print('RUNNING:', args, env_extra, kwds)
-env = os.environ.copy()
-env.update(env_extra)
-return subprocess.Popen(args, env=env, **kwds)
+def _run_base(self, args, **kwds):
+print('RUNNING:', args, kwds)
+return subprocess.Popen(args, **kwds)
 
-def _run(self, args, env_extra={}):
-popen = self._run_base(args, env_extra, cwd=self.get_path(),
+def _run(self, args):
+popen = self._run_base(args, cwd=self.get_path(),
  stdout=subprocess.PIPE,
  universal_newlines=True)
 output = popen.stdout.read()
@@ -65,6 +66,7 @@
 return output
 
 def prepare_module(self, name):
+self.patch_environment()
 if name not in self._compiled_modules:
 path = self.get_path()
 filename = '%s.py' % name
@@ -74,9 +76,8 @@
 # find a solution to that: we could hack sys.path inside the
 # script run here, but we can't hack it in the same way in
 # execute().
-env_extra = {'PYTHONPATH': prefix_pythonpath()}
-output = self._run([sys.executable, os.path.join(local_dir, 
filename)],
-   env_extra=env_extra)
+output = self._run([sys.executable,
+os.path.join(local_dir, filename)])
 match = re.compile(r"\bFILENAME: (.+)").search(output)
 assert match
 dynamic_lib_name = match.group(1)
@@ -120,28 +121,35 @@
 finally:
 os.chdir(curdir)
 
+def patch_environment(self):
+path = self.get_path()
+# for libpypy-c.dll or Python27.dll
+path = os.path.split(sys.executable)[0] + os.path.pathsep + path
+env_extra = {'PYTHONPATH': prefix_pythonpath()}
+if sys.platform == 'win32':
+envname = 'PATH'
+else:
+envname = 'LD_LIBRARY_PATH'
+libpath = org_env.get(envname)
+if libpath:
+libpath = path + os.path.pathsep + libpath
+else:
+libpath = path
+env_extra[envname] = libpath
+for key, value in sorted(env_extra.items()):
+if os.environ.get(key) != value:
+print '* setting env var %r to %r' % (key, value)
+os.environ[key] = value
+
 def execute(self, name):
 path = self.get_path()
-env_extra = {'PYTHONPATH': prefix_pythonpath()}
-if sys.platform == 'win32':
-_path = os.environ.get('PATH')
-# for libpypy-c.dll or 

[pypy-commit] pypy default: Document branches

2016-02-19 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r82323:fa47de37ef9b
Date: 2016-02-19 09:56 +0100
http://bitbucket.org/pypy/pypy/changeset/fa47de37ef9b/

Log:Document branches

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
@@ -158,3 +158,8 @@
 Refactor register_external(), remove running_on_llinterp mechanism and
 apply sandbox transform on externals at the end of annotation.
 
+.. branch: cffi-embedding-win32
+
+.. branch: windows-vmprof-support
+
+vmprof should work on Windows.
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: issue #2241: oops

2016-02-19 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r82322:eb4764c87513
Date: 2016-02-19 09:39 +0100
http://bitbucket.org/pypy/pypy/changeset/eb4764c87513/

Log:issue #2241: oops

diff --git a/pypy/module/_cffi_backend/embedding.py 
b/pypy/module/_cffi_backend/embedding.py
--- a/pypy/module/_cffi_backend/embedding.py
+++ b/pypy/module/_cffi_backend/embedding.py
@@ -57,7 +57,7 @@
 # pypy_init_embedded_cffi_module().
 if not glob.patched_sys:
 space.appexec([], """():
-import os
+import os, sys
 sys.stdin  = sys.__stdin__  = os.fdopen(0, 'rb', 0)
 sys.stdout = sys.__stdout__ = os.fdopen(1, 'wb', 0)
 sys.stderr = sys.__stderr__ = os.fdopen(2, 'wb', 0)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit