Author: Ronan Lamy <ronan.l...@gmail.com> Branch: rawrefcount-review Changeset: r83011:ac298f2c6197 Date: 2016-03-13 16:26 +0000 http://bitbucket.org/pypy/pypy/changeset/ac298f2c6197/
Log: hg merge default diff too long, truncating to 2000 out of 14492 lines diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -74,5 +74,6 @@ ^rpython/doc/_build/.*$ ^compiled ^.git/ +^.hypothesis/ ^release/ ^rpython/_cache$ diff --git a/.hgtags b/.hgtags --- a/.hgtags +++ b/.hgtags @@ -18,3 +18,4 @@ f3ad1e1e1d6215e20d34bb65ab85ff9188c9f559 release-2.6.1 850edf14b2c75573720f59e95767335fb1affe55 release-4.0.0 5f8302b8bf9f53056e40426f10c72151564e5b19 release-4.0.1 +246c9cf22037b11dc0e8c29ce3f291d3b8c5935a release-5.0 diff --git a/LICENSE b/LICENSE --- a/LICENSE +++ b/LICENSE @@ -240,6 +240,7 @@ Kristjan Valur Jonsson David Lievens Neil Blakey-Milner + Sergey Matyunin Lutz Paelike Lucio Torre Lars Wassermann @@ -271,6 +272,7 @@ Aaron Tubbs Ben Darnell Roberto De Ioris + Logan Chien Juan Francisco Cantero Hurtado Ruochen Huang Jeong YunWon diff --git a/lib-python/2.7/xml/etree/ElementTree.py b/lib-python/2.7/xml/etree/ElementTree.py --- a/lib-python/2.7/xml/etree/ElementTree.py +++ b/lib-python/2.7/xml/etree/ElementTree.py @@ -1606,7 +1606,17 @@ pubid = pubid[1:-1] if hasattr(self.target, "doctype"): self.target.doctype(name, pubid, system[1:-1]) - elif self.doctype is not self._XMLParser__doctype: + elif 1: # XXX PyPy fix, used to be + # elif self.doctype is not self._XMLParser__doctype: + # but that condition is always True on CPython, as far + # as I can tell: self._XMLParser__doctype always + # returns a fresh unbound method object. + # On PyPy, unbound and bound methods have stronger + # unicity guarantees: self._XMLParser__doctype + # can return the same unbound method object, in + # some cases making the test above incorrectly False. + # (My guess would be that the line above is a backport + # from Python 3.) # warn about deprecated call self._XMLParser__doctype(name, pubid, system[1:-1]) self.doctype(name, pubid, system[1:-1]) diff --git a/lib_pypy/ctypes_config_cache/rebuild.py b/lib_pypy/ctypes_config_cache/rebuild.py --- a/lib_pypy/ctypes_config_cache/rebuild.py +++ b/lib_pypy/ctypes_config_cache/rebuild.py @@ -9,9 +9,8 @@ _dirpath = os.path.dirname(__file__) or os.curdir -from rpython.tool.ansi_print import ansi_log -log = py.log.Producer("ctypes_config_cache") -py.log.setconsumer("ctypes_config_cache", ansi_log) +from rpython.tool.ansi_print import AnsiLogger +log = AnsiLogger("ctypes_config_cache") def rebuild_one(name): diff --git a/pypy/doc/conf.py b/pypy/doc/conf.py --- a/pypy/doc/conf.py +++ b/pypy/doc/conf.py @@ -123,7 +123,7 @@ # The name for this set of Sphinx documents. If None, it defaults to # "<project> v<release> documentation". -#html_title = None +html_title = 'PyPy documentation' # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None diff --git a/pypy/doc/contributor.rst b/pypy/doc/contributor.rst --- a/pypy/doc/contributor.rst +++ b/pypy/doc/contributor.rst @@ -210,6 +210,7 @@ Kristjan Valur Jonsson David Lievens Neil Blakey-Milner + Sergey Matyunin Lutz Paelike Lucio Torre Lars Wassermann @@ -241,6 +242,7 @@ Aaron Tubbs Ben Darnell Roberto De Ioris + Logan Chien Juan Francisco Cantero Hurtado Ruochen Huang Jeong YunWon 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 @@ -265,7 +265,7 @@ return False def evil(y): - d = {x(): 1} + d = {X(): 1} X.__eq__ = __evil_eq__ d[y] # might trigger a call to __eq__? 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 @@ -76,5 +76,4 @@ * add a tag on the pypy/jitviewer repo that corresponds to pypy release * add a tag on the codespeed web site that corresponds to pypy release -* update the version number in {rpython,pypy}/doc/conf.py. * revise versioning at https://readthedocs.org/projects/pypy 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 @@ -167,22 +167,13 @@ * `hg` -Embedding PyPy and improving CFFI ---------------------------------- - -PyPy has some basic :doc:`embedding infrastructure <embedding>`. The idea would be to improve -upon that with cffi hacks that can automatically generate embeddable .so/.dll -library - - Optimising cpyext (CPython C-API compatibility layer) ----------------------------------------------------- A lot of work has gone into PyPy's implementation of CPython's C-API over the last years to let it reach a practical level of compatibility, so that C extensions for CPython work on PyPy without major rewrites. However, -there are still many edges and corner cases where it misbehaves, and it has -not received any substantial optimisation so far. +there are still many edges and corner cases where it misbehaves. The objective of this project is to fix bugs in cpyext and to optimise several performance critical parts of it, such as the reference counting diff --git a/pypy/doc/release-5.0.0.rst b/pypy/doc/release-5.0.0.rst --- a/pypy/doc/release-5.0.0.rst +++ b/pypy/doc/release-5.0.0.rst @@ -1,96 +1,226 @@ -========== -PyPy 5.0.0 -========== +======== +PyPy 5.0 +======== -We have released PyPy 5.0.0, about three months after PyPy 4.0.0. -We encourage all users of PyPy to update to this version. There are -bug fixes and a major upgrade to our c-api layer (cpyext) +We have released PyPy 5.0, about three months after PyPy 4.0.1. +We encourage all users of PyPy to update to this version. Apart from the usual +bug fixes, there is an ongoing effort to improve the warmup time and memory +usage of JIT-related metadata. The exact effects depend vastly on the program +you're running and can range from insignificant to warmup being up to 30% +faster and memory dropping by about 30%. -You can download the PyPy 5.0.0 release here: +We also merged a major upgrade to our C-API layer (cpyext), simplifying the +interaction between c-level objects and PyPy interpreter level objects. As a +result, lxml (prerelease) with its cython compiled component +`passes all tests`_ on PyPy. The new cpyext is also much faster. + +vmprof_ has been a go-to profiler for PyPy on linux for a few releases +and we're happy to announce that thanks to the cooperation with jetbrains, +vmprof now works on Linux, OS X and Windows on both PyPy and CPython. + +You can download the PyPy 5.0 release here: http://pypy.org/download.html We would like to thank our donors for the continued support of the PyPy project. -We would also like to thank our contributors and +We would also like to thank our contributors and encourage new people to join the project. PyPy has many layers and we need help with all of them: `PyPy`_ and `RPython`_ documentation -improvements, tweaking popular `modules`_ to run on pypy, or general `help`_ -with making RPython's JIT even better. +improvements, tweaking popular `modules`_ to run on pypy, or general `help`_ +with making RPython's JIT even better. CFFI ==== While not applicable only to PyPy, `cffi`_ is arguably our most significant -contribution to the python ecosystem. PyPy 5.0.0 ships with -`cffi-1.5.2`_ which now allows embedding PyPy (or cpython) in a c program. +contribution to the python ecosystem. PyPy 5.0 ships with +`cffi-1.5.2`_ which now allows embedding PyPy (or cpython) in a C program. -.. _`PyPy`: http://doc.pypy.org +.. _`PyPy`: http://doc.pypy.org .. _`RPython`: https://rpython.readthedocs.org .. _`cffi`: https://cffi.readthedocs.org .. _`cffi-1.5.2`: http://cffi.readthedocs.org/en/latest/whatsnew.html#v1-5-2 .. _`modules`: http://doc.pypy.org/en/latest/project-ideas.html#make-more-python-modules-pypy-friendly .. _`help`: http://doc.pypy.org/en/latest/project-ideas.html .. _`numpy`: https://bitbucket.org/pypy/numpy +.. _`passes all tests`: https://bitbucket.org/pypy/compatibility/wiki/lxml +.. _vmprof: http://vmprof.readthedocs.org What is PyPy? ============= PyPy is a very compliant Python interpreter, almost a drop-in replacement for -CPython 2.7. It's fast (`pypy and cpython 2.7.x`_ performance comparison) +CPython 2.7. It's fast (`PyPy and CPython 2.7.x`_ performance comparison) due to its integrated tracing JIT compiler. We also welcome developers of other `dynamic languages`_ to see what RPython can do for them. This release supports **x86** machines on most common operating systems -(Linux 32/64, Mac OS X 64, Windows 32, OpenBSD, freebsd), +(Linux 32/64, Mac OS X 64, Windows 32, OpenBSD, FreeBSD), newer **ARM** hardware (ARMv6 or ARMv7, with VFPv3) running Linux, and the -big- and little-endian variants of **ppc64** running Linux. +big- and little-endian variants of **PPC64** running Linux. -.. _`pypy and cpython 2.7.x`: http://speed.pypy.org +.. _`PyPy and CPython 2.7.x`: http://speed.pypy.org .. _`dynamic languages`: http://pypyjs.org Other Highlights (since 4.0.1 released in November 2015) -======================================================= +========================================================= + +* New features: + + * Support embedding PyPy in a C-program via cffi and static callbacks in cffi. + This deprecates the old method of embedding PyPy + + * Refactor vmprof to work cross-operating-system, deprecate using buggy + libunwind on Linux platforms. Vmprof even works on Windows now. + + * Support more of the C-API type slots, like tp_getattro, and fix C-API + macros, functions, and structs such as _PyLong_FromByteArray(), + PyString_GET_SIZE, f_locals in PyFrameObject, Py_NAN, co_filename in + PyCodeObject + + * Use a more stable approach for allocating PyObjects in cpyext. (see + `blog post`_). Once the PyObject corresponding to a PyPy object is created, + it stays around at the same location until the death of the PyPy object. + Done with a little bit of custom GC support. It allows us to kill the + notion of "borrowing" inside cpyext, reduces 4 dictionaries down to 1, and + significantly simplifies the whole approach (which is why it is a new + feature while technically a refactoring) and allows PyPy to support the + populart lxml module (as of the *next* release) with no PyPy specific + patches needed + + * Make the default filesystem encoding ASCII, like CPython + + * Use `hypothesis`_ in test creation, which is great for randomizing tests * Bug Fixes - * + * Backport always using os.urandom for uuid4 from cpython and fix the JIT as well + (issue #2202) - * + * More completely support datetime, optimize timedelta creation - * + * Fix for issue #2185 which caused an inconsistent list of operations to be + generated by the unroller, appeared in a complicated DJango app + + * Fix an elusive issue with stacklets on shadowstack which showed up when + forgetting stacklets without resuming them + + * Fix entrypoint() which now acquires the GIL + + * Fix direct_ffi_call() so failure does not bail out before setting CALL_MAY_FORCE + + * Fix (de)pickling long values by simplifying the implementation + + * Fix RPython rthread so that objects stored as threadlocal do not force minor + GC collection and are kept alive automatically. This improves perfomance of + short-running Python callbacks and prevents resetting such object between + calls + + * Support floats as parameters to itertools.isslice() + + * Check for the existence of CODESET, ignoring it should have prevented PyPy + from working on FreeBSD + + * Fix for corner case (likely shown by Krakatau) for consecutive guards with + interdependencies + + * Fix applevel bare class method comparisons which should fix pretty printing + in IPython * Issues reported with our previous release were resolved_ after reports from users on our issue tracker at https://bitbucket.org/pypy/pypy/issues or on IRC at #pypy -* New features: - - * - - * - - * - * Numpy: - * + * Updates to numpy 1.10.2 (incompatibilities and not-implemented features + still exist) - * + * Support dtype=(('O', spec)) union while disallowing record arrays with + mixed object, non-object values + * Remove all traces of micronumpy from cpyext if --withoutmod-micronumpy option used -* Performance improvements and refactorings: + * Support indexing filtering with a boolean ndarray - * + * Support partition() as an app-level function, together with a cffi wrapper + in pypy/numpy, this now provides partial support for partition() - * +* Performance improvements: - * + * Optimize global lookups + + * Improve the memory signature of numbering instances in the JIT. This should + massively decrease the amount of memory consumed by the JIT, which is + significant for most programs. Also compress the numberings using variable- + size encoding + + * Optimize string concatenation + + * Use INT_LSHIFT instead of INT_MUL when possible + + * Improve struct.unpack by casting directly from the underlying buffer. + Unpacking floats and doubles is about 15 times faster, and integer types + about 50% faster (on 64 bit integers). This was then subsequently + improved further in optimizeopt.py. + + * Optimize two-tuple lookups in mapdict, which improves warmup of instance + variable access somewhat + + * Reduce all guards from int_floordiv_ovf if one of the arguments is constant + + * Identify permutations of attributes at instance creation, reducing the + number of bridges created + + * Greatly improve re.sub() performance + + +* Internal refactorings: + + * Refactor and improve exception analysis in the annotator + + * Remove unnecessary special handling of space.wrap(). + + * Support list-resizing setslice operations in RPython + + * Tweak the trace-too-long heuristic for multiple jit drivers + + * Refactor bookkeeping (such a cool word - three double letters) in the + annotater + + * Refactor wrappers for OS functions from rtyper to rlib and simplify them + + * Simplify backend loading instructions to only use four variants + + * Simplify GIL handling in non-jitted code + + * Refactor naming in optimizeopt + + * Change GraphAnalyzer to use a more precise way to recognize external + functions and fix null pointer handling, generally clean up external + function handling + + * Remove pure variants of ``getfield_gc_*`` operations from the JIT by + determining purity while tracing + + * Refactor databasing + + * Simplify bootstrapping in cpyext + + * Refactor rtyper debug code into python.rtyper.debug + + * Seperate structmember.h from Python.h Also enhance creating api functions + to specify which header file they appear in (previously only pypy_decl.h) + + * Fix tokenizer to enforce universal newlines, needed for Python 3 support .. _resolved: http://doc.pypy.org/en/latest/whatsnew-5.0.0.html +.. _`hypothesis`: http://hypothesis.readthedocs.org +.. _`blog post`: http://morepypy.blogspot.com/2016/02/c-api-support-update.html Please update, and continue to help us make PyPy better. diff --git a/pypy/doc/whatsnew-5.0.0.rst b/pypy/doc/whatsnew-5.0.0.rst --- a/pypy/doc/whatsnew-5.0.0.rst +++ b/pypy/doc/whatsnew-5.0.0.rst @@ -1,6 +1,6 @@ -======================== -What's new in PyPy 5.0.0 -======================== +====================== +What's new in PyPy 5.0 +====================== .. this is a revision shortly after release-4.0.1 .. startrev: 4b5c840d0da2 @@ -191,3 +191,7 @@ Fix boolean-array indexing in micronumpy +.. branch: numpy_partition +Support ndarray.partition() as an app-level function numpy.core._partition_use, +provided as a cffi wrapper to upstream's implementation in the pypy/numpy repo + 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,7 +2,12 @@ What's new in PyPy 5.0.+ ========================= -.. this is a revision shortly after release-5.0.0 -.. startrev: 6d13e55b962a +.. this is a revision shortly after release-5.0 +.. startrev: b238b48f9138 +.. branch: s390x-backend +The jit compiler backend implementation for the s390x architecutre. +The backend manages 64-bit values in the literal pool of the assembly instead of loading them as immediates. +It includes a simplification for the operation 'zero_array'. Start and length parameters are bytes instead of size. + diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py --- a/pypy/interpreter/function.py +++ b/pypy/interpreter/function.py @@ -13,6 +13,9 @@ from pypy.interpreter.argument import Arguments from rpython.rlib import jit +from rpython.rlib.rarithmetic import LONG_BIT +from rpython.rlib.rbigint import rbigint + funccallunrolling = unrolling_iterable(range(4)) @@ -557,6 +560,26 @@ return space.w_False return space.eq(self.w_function, w_other.w_function) + def is_w(self, space, other): + if not isinstance(other, Method): + return False + return (self.w_instance is other.w_instance and + self.w_function is other.w_function and + self.w_class is other.w_class) + + def immutable_unique_id(self, space): + from pypy.objspace.std.util import IDTAG_METHOD as tag + from pypy.objspace.std.util import IDTAG_SHIFT + if self.w_instance is not None: + id = space.bigint_w(space.id(self.w_instance)) + id = id.lshift(LONG_BIT) + else: + id = rbigint.fromint(0) + id = id.or_(space.bigint_w(space.id(self.w_function))) + id = id.lshift(LONG_BIT).or_(space.bigint_w(space.id(self.w_class))) + id = id.lshift(IDTAG_SHIFT).int_or_(tag) + return space.newlong_from_rbigint(id) + def descr_method_hash(self): space = self.space w_result = space.hash(self.w_function) diff --git a/pypy/interpreter/mixedmodule.py b/pypy/interpreter/mixedmodule.py --- a/pypy/interpreter/mixedmodule.py +++ b/pypy/interpreter/mixedmodule.py @@ -3,7 +3,7 @@ from pypy.interpreter import gateway from pypy.interpreter.error import OperationError from pypy.interpreter.baseobjspace import W_Root -import os, sys +import sys class MixedModule(Module): applevel_name = None @@ -60,7 +60,7 @@ def save_module_content_for_future_reload(self): self.w_initialdict = self.space.call_method(self.w_dict, 'items') - + @classmethod def get_applevel_name(cls): """ NOT_RPYTHON """ if cls.applevel_name is not None: @@ -68,7 +68,6 @@ else: pkgroot = cls.__module__ return pkgroot.split('.')[-1] - get_applevel_name = classmethod(get_applevel_name) def get(self, name): space = self.space @@ -103,7 +102,7 @@ # be normal Functions to get the correct binding behaviour func = w_value if (isinstance(func, Function) and - type(func) is not BuiltinFunction): + type(func) is not BuiltinFunction): try: bltin = func._builtinversion_ except AttributeError: @@ -115,7 +114,6 @@ space.setitem(self.w_dict, w_name, w_value) return w_value - def getdict(self, space): if self.lazy: for name in self.loaders: @@ -131,6 +129,7 @@ self.startup_called = False self._frozen = True + @classmethod def buildloaders(cls): """ NOT_RPYTHON """ if not hasattr(cls, 'loaders'): @@ -149,8 +148,6 @@ if '__doc__' not in loaders: loaders['__doc__'] = cls.get__doc__ - buildloaders = classmethod(buildloaders) - def extra_interpdef(self, name, spec): cls = self.__class__ pkgroot = cls.__module__ @@ -159,21 +156,21 @@ w_obj = loader(space) space.setattr(space.wrap(self), space.wrap(name), w_obj) + @classmethod def get__doc__(cls, space): return space.wrap(cls.__doc__) - get__doc__ = classmethod(get__doc__) def getinterpevalloader(pkgroot, spec): """ NOT_RPYTHON """ def ifileloader(space): - d = {'space' : space} + d = {'space':space} # EVIL HACK (but it works, and this is not RPython :-) while 1: try: value = eval(spec, d) except NameError, ex: - name = ex.args[0].split("'")[1] # super-Evil + name = ex.args[0].split("'")[1] # super-Evil if name in d: raise # propagate the NameError try: diff --git a/pypy/interpreter/test/test_app_main.py b/pypy/interpreter/test/test_app_main.py --- a/pypy/interpreter/test/test_app_main.py +++ b/pypy/interpreter/test/test_app_main.py @@ -9,6 +9,11 @@ from pypy.conftest import pypydir from lib_pypy._pypy_interact import irc_header +try: + import __pypy__ +except ImportError: + __pypy__ = None + banner = sys.version.splitlines()[0] app_main = os.path.join(os.path.realpath(os.path.dirname(__file__)), os.pardir, 'app_main.py') @@ -106,6 +111,8 @@ sys.argv[:] = saved_sys_argv sys.stdout = saved_sys_stdout sys.stderr = saved_sys_stderr + if __pypy__: + __pypy__.set_debug(True) def test_all_combinations_I_can_think_of(self): self.check([], {}, sys_argv=[''], run_stdin=True) @@ -601,9 +608,7 @@ def run_with_status_code(self, cmdline, senddata='', expect_prompt=False, expect_banner=False, python_flags='', env=None): if os.name == 'nt': - try: - import __pypy__ - except: + if __pypy__ is None: py.test.skip('app_main cannot run on non-pypy for windows') cmdline = '%s %s "%s" %s' % (sys.executable, python_flags, app_main, cmdline) diff --git a/pypy/interpreter/test/test_function.py b/pypy/interpreter/test/test_function.py --- a/pypy/interpreter/test/test_function.py +++ b/pypy/interpreter/test/test_function.py @@ -1,5 +1,4 @@ - -import unittest +import pytest from pypy.interpreter import eval from pypy.interpreter.function import Function, Method, descr_function_get from pypy.interpreter.pycode import PyCode @@ -187,6 +186,7 @@ raises( TypeError, func, 42, {'arg1': 23}) + @pytest.mark.skipif("config.option.runappdirect") def test_kwargs_nondict_mapping(self): class Mapping: def keys(self): @@ -257,6 +257,14 @@ meth = func.__get__(obj, object) assert meth() == obj + def test_none_get_interaction(self): + skip("XXX issue #2083") + assert type(None).__repr__(None) == 'None' + + def test_none_get_interaction_2(self): + f = None.__repr__ + assert f() == 'None' + def test_no_get_builtin(self): assert not hasattr(dir, '__get__') class A(object): @@ -284,6 +292,7 @@ raises(TypeError, len, s, some_unknown_keyword=s) raises(TypeError, len, s, s, some_unknown_keyword=s) + @pytest.mark.skipif("config.option.runappdirect") def test_call_error_message(self): try: len() @@ -325,6 +334,7 @@ f = lambda: 42 assert f.func_doc is None + @pytest.mark.skipif("config.option.runappdirect") def test_setstate_called_with_wrong_args(self): f = lambda: 42 # not sure what it should raise, since CPython doesn't have setstate @@ -550,6 +560,37 @@ assert A().m == X() assert X() == A().m + @pytest.mark.skipif("config.option.runappdirect") + def test_method_identity(self): + class A(object): + def m(self): + pass + def n(self): + pass + + class B(A): + pass + + class X(object): + def __eq__(self, other): + return True + + a = A() + a2 = A() + assert a.m is a.m + assert id(a.m) == id(a.m) + assert a.m is not a.n + assert id(a.m) != id(a.n) + assert a.m is not a2.m + assert id(a.m) != id(a2.m) + + assert A.m is A.m + assert id(A.m) == id(A.m) + assert A.m is not A.n + assert id(A.m) != id(A.n) + assert A.m is not B.m + assert id(A.m) != id(B.m) + class TestMethod: def setup_method(self, method): 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 @@ -79,6 +79,7 @@ W_Super.typedef = TypeDef( 'super', __new__ = interp2app(descr_new_super), + __thisclass__ = interp_attrproperty_w("w_starttype", W_Super), __getattribute__ = interp2app(W_Super.getattribute), __get__ = interp2app(W_Super.get), __doc__ = """super(type) -> unbound super object 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 @@ -214,7 +214,7 @@ c = C() assert C.goo(1) == (C, 1) assert c.goo(1) == (C, 1) - + assert c.foo(1) == (c, 1) class D(C): pass @@ -238,6 +238,17 @@ meth = classmethod(1).__get__(1) raises(TypeError, meth) + def test_super_thisclass(self): + class A(object): + pass + + assert super(A, A()).__thisclass__ is A + + class B(A): + pass + + assert super(B, B()).__thisclass__ is B + assert super(A, B()).__thisclass__ is A def test_property_docstring(self): assert property.__doc__.startswith('property') diff --git a/pypy/module/__pypy__/test/test_signal.py b/pypy/module/__pypy__/test/test_signal.py --- a/pypy/module/__pypy__/test/test_signal.py +++ b/pypy/module/__pypy__/test/test_signal.py @@ -2,7 +2,6 @@ from pypy.module.thread.test.support import GenericTestThread - class AppTestMinimal: spaceconfig = dict(usemodules=['__pypy__']) 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 @@ -353,10 +353,11 @@ # ____________________________________________________________ -rffi_fdopen = rffi.llexternal("fdopen", [rffi.INT, rffi.CCHARP], rffi.CCHARP, +FILEP = rffi.COpaquePtr("FILE") +rffi_fdopen = rffi.llexternal("fdopen", [rffi.INT, rffi.CCHARP], FILEP, save_err=rffi.RFFI_SAVE_ERRNO) -rffi_setbuf = rffi.llexternal("setbuf", [rffi.CCHARP, rffi.CCHARP], lltype.Void) -rffi_fclose = rffi.llexternal("fclose", [rffi.CCHARP], rffi.INT) +rffi_setbuf = rffi.llexternal("setbuf", [FILEP, rffi.CCHARP], lltype.Void) +rffi_fclose = rffi.llexternal("fclose", [FILEP], rffi.INT) class CffiFileObj(object): _immutable_ = True @@ -382,4 +383,4 @@ fileobj.cffi_fileobj = CffiFileObj(fd, fileobj.mode) except OSError, e: raise wrap_oserror(space, e) - return fileobj.cffi_fileobj.llf + return rffi.cast(rffi.CCHARP, fileobj.cffi_fileobj.llf) diff --git a/pypy/module/_collections/app_defaultdict.py b/pypy/module/_collections/app_defaultdict.py --- a/pypy/module/_collections/app_defaultdict.py +++ b/pypy/module/_collections/app_defaultdict.py @@ -12,6 +12,7 @@ class defaultdict(dict): __slots__ = ['default_factory'] + __module__ = 'collections' def __init__(self, *args, **kwds): if len(args) > 0: diff --git a/pypy/module/_collections/test/test_defaultdict.py b/pypy/module/_collections/test/test_defaultdict.py --- a/pypy/module/_collections/test/test_defaultdict.py +++ b/pypy/module/_collections/test/test_defaultdict.py @@ -14,6 +14,12 @@ d[5].append(44) assert l == [42, 43] and l2 == [44] + def test_module(self): + from _collections import defaultdict + assert repr(defaultdict) in ( + "<class 'collections.defaultdict'>", # on PyPy + "<type 'collections.defaultdict'>") # on CPython + def test_keyerror_without_factory(self): from _collections import defaultdict for d1 in [defaultdict(), defaultdict(None)]: diff --git a/pypy/module/_file/test/test_file_extra.py b/pypy/module/_file/test/test_file_extra.py --- a/pypy/module/_file/test/test_file_extra.py +++ b/pypy/module/_file/test/test_file_extra.py @@ -389,6 +389,7 @@ def test_writelines(self): import array + import sys fn = self.temptestfile with file(fn, 'w') as f: f.writelines(['abc']) @@ -406,7 +407,10 @@ exc = raises(TypeError, f.writelines, [memoryview('jkl')]) assert str(exc.value) == "writelines() argument must be a sequence of strings" out = open(fn, 'rb').readlines()[0] - assert out[0:5] == 'abcd\x00' + if sys.byteorder == 'big': + assert out[0:7] == 'abc\x00\x00\x00d' + else: + assert out[0:5] == 'abcd\x00' assert out[-3:] == 'ghi' with file(fn, 'wb') as f: diff --git a/pypy/module/_rawffi/callback.py b/pypy/module/_rawffi/callback.py --- a/pypy/module/_rawffi/callback.py +++ b/pypy/module/_rawffi/callback.py @@ -1,17 +1,23 @@ - +import sys from pypy.interpreter.gateway import interp2app, unwrap_spec from pypy.interpreter.typedef import TypeDef, GetSetProperty from rpython.rtyper.lltypesystem import lltype, rffi from pypy.module._rawffi.interp_rawffi import write_ptr from pypy.module._rawffi.structure import W_Structure from pypy.module._rawffi.interp_rawffi import (W_DataInstance, letter2tp, - unwrap_value, unpack_argshapes, got_libffi_error) + unwrap_value, unpack_argshapes, got_libffi_error, is_narrow_integer_type, + LL_TYPEMAP, NARROW_INTEGER_TYPES) from rpython.rlib.clibffi import USERDATA_P, CallbackFuncPtr, FUNCFLAG_CDECL from rpython.rlib.clibffi import ffi_type_void, LibFFIError from rpython.rlib import rweakref from pypy.module._rawffi.tracker import tracker from pypy.interpreter.error import OperationError from pypy.interpreter import gateway +from rpython.rlib.unroll import unrolling_iterable + +BIGENDIAN = sys.byteorder == 'big' + +unroll_narrow_integer_types = unrolling_iterable(NARROW_INTEGER_TYPES) app = gateway.applevel(''' def tbprint(tb, err): @@ -42,8 +48,17 @@ args_w[i] = space.wrap(rffi.cast(rffi.ULONG, ll_args[i])) w_res = space.call(w_callable, space.newtuple(args_w)) if callback_ptr.result is not None: # don't return void - unwrap_value(space, write_ptr, ll_res, 0, - callback_ptr.result, w_res) + ptr = ll_res + letter = callback_ptr.result + if BIGENDIAN: + # take care of narrow integers! + for int_type in unroll_narrow_integer_types: + if int_type == letter: + T = LL_TYPEMAP[int_type] + n = rffi.sizeof(lltype.Signed) - rffi.sizeof(T) + ptr = rffi.ptradd(ptr, n) + break + unwrap_value(space, write_ptr, ptr, 0, letter, w_res) except OperationError, e: tbprint(space, space.wrap(e.get_traceback()), space.wrap(e.errorstr(space))) diff --git a/pypy/module/_rawffi/interp_rawffi.py b/pypy/module/_rawffi/interp_rawffi.py --- a/pypy/module/_rawffi/interp_rawffi.py +++ b/pypy/module/_rawffi/interp_rawffi.py @@ -1,3 +1,4 @@ +import sys from pypy.interpreter.baseobjspace import W_Root from pypy.interpreter.error import OperationError, oefmt, wrap_oserror from pypy.interpreter.gateway import interp2app, unwrap_spec @@ -19,6 +20,8 @@ from pypy.module._rawffi.buffer import RawFFIBuffer from pypy.module._rawffi.tracker import tracker +BIGENDIAN = sys.byteorder == 'big' + TYPEMAP = { # XXX A mess with unsigned/signed/normal chars :-/ 'c' : ffi_type_uchar, @@ -331,10 +334,14 @@ if tracker.DO_TRACING: ll_buf = rffi.cast(lltype.Signed, self.ll_buffer) tracker.trace_allocation(ll_buf, self) + self._ll_buffer = self.ll_buffer def getbuffer(self, space): return space.wrap(rffi.cast(lltype.Unsigned, self.ll_buffer)) + def buffer_advance(self, n): + self.ll_buffer = rffi.ptradd(self.ll_buffer, n) + def byptr(self, space): from pypy.module._rawffi.array import ARRAY_OF_PTRS array = ARRAY_OF_PTRS.allocate(space, 1) @@ -342,16 +349,17 @@ return space.wrap(array) def free(self, space): - if not self.ll_buffer: + if not self._ll_buffer: raise segfault_exception(space, "freeing NULL pointer") self._free() def _free(self): if tracker.DO_TRACING: - ll_buf = rffi.cast(lltype.Signed, self.ll_buffer) + ll_buf = rffi.cast(lltype.Signed, self._ll_buffer) tracker.trace_free(ll_buf) - lltype.free(self.ll_buffer, flavor='raw') + lltype.free(self._ll_buffer, flavor='raw') self.ll_buffer = lltype.nullptr(rffi.VOIDP.TO) + self._ll_buffer = self.ll_buffer def buffer_w(self, space, flags): return RawFFIBuffer(self) @@ -432,12 +440,19 @@ space.wrap("cannot directly read value")) wrap_value._annspecialcase_ = 'specialize:arg(1)' +NARROW_INTEGER_TYPES = 'cbhiBIH?' + +def is_narrow_integer_type(letter): + return letter in NARROW_INTEGER_TYPES class W_FuncPtr(W_Root): def __init__(self, space, ptr, argshapes, resshape): self.ptr = ptr self.argshapes = argshapes self.resshape = resshape + self.narrow_integer = False + if resshape is not None: + self.narrow_integer = is_narrow_integer_type(resshape.itemcode.lower()) def getbuffer(self, space): return space.wrap(rffi.cast(lltype.Unsigned, self.ptr.funcsym)) @@ -497,6 +512,10 @@ result = self.resshape.allocate(space, 1, autofree=True) # adjust_return_size() was used here on result.ll_buffer self.ptr.call(args_ll, result.ll_buffer) + if BIGENDIAN and self.narrow_integer: + # we get a 8 byte value in big endian + n = rffi.sizeof(lltype.Signed) - result.shape.size + result.buffer_advance(n) return space.wrap(result) else: self.ptr.call(args_ll, lltype.nullptr(rffi.VOIDP.TO)) diff --git a/pypy/module/_rawffi/structure.py b/pypy/module/_rawffi/structure.py --- a/pypy/module/_rawffi/structure.py +++ b/pypy/module/_rawffi/structure.py @@ -18,6 +18,9 @@ from rpython.rlib.rarithmetic import intmask, signedtype, r_uint, \ r_ulonglong from rpython.rtyper.lltypesystem import lltype, rffi +import sys + +IS_BIG_ENDIAN = sys.byteorder == 'big' @@ -114,20 +117,32 @@ size += intmask(fieldsize) bitsizes.append(fieldsize) elif field_type == NEW_BITFIELD: - bitsizes.append((bitsize << 16) + bitoffset) + if IS_BIG_ENDIAN: + off = last_size - bitoffset - bitsize + else: + off = bitoffset + bitsizes.append((bitsize << 16) + off) bitoffset = bitsize size = round_up(size, fieldalignment) pos.append(size) size += fieldsize elif field_type == CONT_BITFIELD: - bitsizes.append((bitsize << 16) + bitoffset) + if IS_BIG_ENDIAN: + off = last_size - bitoffset - bitsize + else: + off = bitoffset + bitsizes.append((bitsize << 16) + off) bitoffset += bitsize # offset is already updated for the NEXT field pos.append(size - fieldsize) elif field_type == EXPAND_BITFIELD: size += fieldsize - last_size / 8 last_size = fieldsize * 8 - bitsizes.append((bitsize << 16) + bitoffset) + if IS_BIG_ENDIAN: + off = last_size - bitoffset - bitsize + else: + off = bitoffset + bitsizes.append((bitsize << 16) + off) bitoffset += bitsize # offset is already updated for the NEXT field pos.append(size - fieldsize) diff --git a/pypy/module/_rawffi/test/test__rawffi.py b/pypy/module/_rawffi/test/test__rawffi.py --- a/pypy/module/_rawffi/test/test__rawffi.py +++ b/pypy/module/_rawffi/test/test__rawffi.py @@ -704,7 +704,6 @@ def compare(a, b): a1 = _rawffi.Array('i').fromaddress(_rawffi.Array('P').fromaddress(a, 1)[0], 1) a2 = _rawffi.Array('i').fromaddress(_rawffi.Array('P').fromaddress(b, 1)[0], 1) - print "comparing", a1[0], "with", a2[0] if a1[0] not in [1,2,3,4] or a2[0] not in [1,2,3,4]: bogus_args.append((a1[0], a2[0])) if a1[0] > a2[0]: @@ -715,7 +714,7 @@ a2[0] = len(ll_to_sort) a3 = _rawffi.Array('l')(1) a3[0] = struct.calcsize('i') - cb = _rawffi.CallbackPtr(compare, ['P', 'P'], 'i') + cb = _rawffi.CallbackPtr(compare, ['P', 'P'], 'l') a4 = cb.byptr() qsort(a1, a2, a3, a4) res = [ll_to_sort[i] for i in range(len(ll_to_sort))] @@ -896,11 +895,21 @@ b = _rawffi.Array('c').fromaddress(a.buffer, 38) if sys.maxunicode > 65535: # UCS4 build - assert b[0] == 'x' - assert b[1] == '\x00' - assert b[2] == '\x00' - assert b[3] == '\x00' - assert b[4] == 'y' + if sys.byteorder == 'big': + assert b[0] == '\x00' + assert b[1] == '\x00' + assert b[2] == '\x00' + assert b[3] == 'x' + assert b[4] == '\x00' + assert b[5] == '\x00' + assert b[6] == '\x00' + assert b[7] == 'y' + else: + assert b[0] == 'x' + assert b[1] == '\x00' + assert b[2] == '\x00' + assert b[3] == '\x00' + assert b[4] == 'y' else: # UCS2 build assert b[0] == 'x' diff --git a/pypy/module/_rawffi/test/test_struct.py b/pypy/module/_rawffi/test/test_struct.py --- a/pypy/module/_rawffi/test/test_struct.py +++ b/pypy/module/_rawffi/test/test_struct.py @@ -1,4 +1,4 @@ - +import sys from pypy.module._rawffi.structure import size_alignment_pos from pypy.module._rawffi.interp_rawffi import TYPEMAP, letter2tp @@ -63,4 +63,7 @@ for (name, t, size) in fields]) assert size == 8 assert pos == [0, 0, 0] - assert bitsizes == [0x10000, 0x3e0001, 0x1003f] + if sys.byteorder == 'little': + assert bitsizes == [0x10000, 0x3e0001, 0x1003f] + else: + assert bitsizes == [0x1003f, 0x3e0001, 0x10000] diff --git a/pypy/module/_sre/interp_sre.py b/pypy/module/_sre/interp_sre.py --- a/pypy/module/_sre/interp_sre.py +++ b/pypy/module/_sre/interp_sre.py @@ -7,6 +7,7 @@ from pypy.interpreter.error import OperationError from rpython.rlib.rarithmetic import intmask from rpython.rlib import jit +from rpython.rlib.rstring import StringBuilder, UnicodeBuilder # ____________________________________________________________ # @@ -36,6 +37,8 @@ if 0 <= start <= end: if isinstance(ctx, rsre_core.BufMatchContext): return space.wrap(ctx._buffer.getslice(start, end, 1, end-start)) + if isinstance(ctx, rsre_core.StrMatchContext): + return space.wrap(ctx._string[start:end]) elif isinstance(ctx, rsre_core.UnicodeMatchContext): return space.wrap(ctx._unicodestr[start:end]) else: @@ -98,8 +101,8 @@ space.wrap("cannot copy this pattern object")) def make_ctx(self, w_string, pos=0, endpos=sys.maxint): - """Make a BufMatchContext or a UnicodeMatchContext for searching - in the given w_string object.""" + """Make a StrMatchContext, BufMatchContext or a UnicodeMatchContext for + searching in the given w_string object.""" space = self.space if pos < 0: pos = 0 @@ -113,6 +116,14 @@ endpos = len(unicodestr) return rsre_core.UnicodeMatchContext(self.code, unicodestr, pos, endpos, self.flags) + elif space.isinstance_w(w_string, space.w_str): + str = space.str_w(w_string) + if pos > len(str): + pos = len(str) + if endpos > len(str): + endpos = len(str) + return rsre_core.StrMatchContext(self.code, str, + pos, endpos, self.flags) else: buf = space.readbuf_w(w_string) size = buf.getlength() @@ -216,6 +227,11 @@ def subx(self, w_ptemplate, w_string, count): space = self.space + # use a (much faster) string/unicode builder if w_ptemplate and + # w_string are both string or both unicode objects, and if w_ptemplate + # is a literal + use_builder = False + filter_as_unicode = filter_as_string = None if space.is_true(space.callable(w_ptemplate)): w_filter = w_ptemplate filter_is_callable = True @@ -223,6 +239,8 @@ if space.isinstance_w(w_ptemplate, space.w_unicode): filter_as_unicode = space.unicode_w(w_ptemplate) literal = u'\\' not in filter_as_unicode + use_builder = ( + space.isinstance_w(w_string, space.w_unicode) and literal) else: try: filter_as_string = space.str_w(w_ptemplate) @@ -232,6 +250,8 @@ literal = False else: literal = '\\' not in filter_as_string + use_builder = ( + space.isinstance_w(w_string, space.w_str) and literal) if literal: w_filter = w_ptemplate filter_is_callable = False @@ -242,19 +262,44 @@ space.wrap(self), w_ptemplate) filter_is_callable = space.is_true(space.callable(w_filter)) # + # XXX this is a bit of a mess, but it improves performance a lot ctx = self.make_ctx(w_string) - sublist_w = [] + sublist_w = strbuilder = unicodebuilder = None + if use_builder: + if filter_as_unicode is not None: + unicodebuilder = UnicodeBuilder(ctx.end) + else: + assert filter_as_string is not None + strbuilder = StringBuilder(ctx.end) + else: + sublist_w = [] n = last_pos = 0 while not count or n < count: + sub_jitdriver.jit_merge_point( + self=self, + use_builder=use_builder, + filter_is_callable=filter_is_callable, + filter_type=type(w_filter), + ctx=ctx, + w_filter=w_filter, + strbuilder=strbuilder, + unicodebuilder=unicodebuilder, + filter_as_string=filter_as_string, + filter_as_unicode=filter_as_unicode, + count=count, + w_string=w_string, + n=n, last_pos=last_pos, sublist_w=sublist_w + ) + space = self.space if not searchcontext(space, ctx): break if last_pos < ctx.match_start: - sublist_w.append(slice_w(space, ctx, last_pos, - ctx.match_start, space.w_None)) + _sub_append_slice( + ctx, space, use_builder, sublist_w, + strbuilder, unicodebuilder, last_pos, ctx.match_start) start = ctx.match_end if start == ctx.match_start: start += 1 - nextctx = ctx.fresh_copy(start) if not (last_pos == ctx.match_start == ctx.match_end and n > 0): # the above ignores empty matches on latest position @@ -262,28 +307,71 @@ w_match = self.getmatch(ctx, True) w_piece = space.call_function(w_filter, w_match) if not space.is_w(w_piece, space.w_None): + assert strbuilder is None and unicodebuilder is None + assert not use_builder sublist_w.append(w_piece) else: - sublist_w.append(w_filter) + if use_builder: + if strbuilder is not None: + assert filter_as_string is not None + strbuilder.append(filter_as_string) + else: + assert unicodebuilder is not None + assert filter_as_unicode is not None + unicodebuilder.append(filter_as_unicode) + else: + sublist_w.append(w_filter) last_pos = ctx.match_end n += 1 elif last_pos >= ctx.end: break # empty match at the end: finished - ctx = nextctx + ctx.reset(start) if last_pos < ctx.end: - sublist_w.append(slice_w(space, ctx, last_pos, ctx.end, - space.w_None)) + _sub_append_slice(ctx, space, use_builder, sublist_w, + strbuilder, unicodebuilder, last_pos, ctx.end) + if use_builder: + if strbuilder is not None: + return space.wrap(strbuilder.build()), n + else: + assert unicodebuilder is not None + return space.wrap(unicodebuilder.build()), n + else: + if space.isinstance_w(w_string, space.w_unicode): + w_emptystr = space.wrap(u'') + else: + w_emptystr = space.wrap('') + w_item = space.call_method(w_emptystr, 'join', + space.newlist(sublist_w)) + return w_item, n - if space.isinstance_w(w_string, space.w_unicode): - w_emptystr = space.wrap(u'') - else: - w_emptystr = space.wrap('') - w_item = space.call_method(w_emptystr, 'join', - space.newlist(sublist_w)) - return w_item, n +sub_jitdriver = jit.JitDriver( + reds="""count n last_pos + ctx w_filter + strbuilder unicodebuilder + filter_as_string + filter_as_unicode + w_string sublist_w + self""".split(), + greens=["filter_is_callable", "use_builder", "filter_type", "ctx.pattern"]) +def _sub_append_slice(ctx, space, use_builder, sublist_w, + strbuilder, unicodebuilder, start, end): + if use_builder: + if isinstance(ctx, rsre_core.BufMatchContext): + assert strbuilder is not None + return strbuilder.append(ctx._buffer.getslice(start, end, 1, end-start)) + if isinstance(ctx, rsre_core.StrMatchContext): + assert strbuilder is not None + return strbuilder.append_slice(ctx._string, start, end) + elif isinstance(ctx, rsre_core.UnicodeMatchContext): + assert unicodebuilder is not None + return unicodebuilder.append_slice(ctx._unicodestr, start, end) + assert 0, "unreachable" + else: + sublist_w.append(slice_w(space, ctx, start, end, space.w_None)) + @unwrap_spec(flags=int, groups=int, w_groupindex=WrappedDefault(None), w_indexgroup=WrappedDefault(None)) def SRE_Pattern__new__(space, w_subtype, w_pattern, flags, w_code, @@ -482,6 +570,8 @@ ctx = self.ctx if isinstance(ctx, rsre_core.BufMatchContext): return space.wrap(ctx._buffer.as_str()) + elif isinstance(ctx, rsre_core.StrMatchContext): + return space.wrap(ctx._string) elif isinstance(ctx, rsre_core.UnicodeMatchContext): return space.wrap(ctx._unicodestr) else: diff --git a/pypy/module/_vmprof/conftest.py b/pypy/module/_vmprof/conftest.py new file mode 100644 --- /dev/null +++ b/pypy/module/_vmprof/conftest.py @@ -0,0 +1,6 @@ +import py, platform + +def pytest_collect_directory(path, parent): + if platform.machine() == 's390x': + py.test.skip("zarch tests skipped") +pytest_collect_file = pytest_collect_directory diff --git a/pypy/module/_vmprof/interp_vmprof.py b/pypy/module/_vmprof/interp_vmprof.py --- a/pypy/module/_vmprof/interp_vmprof.py +++ b/pypy/module/_vmprof/interp_vmprof.py @@ -60,10 +60,10 @@ Must be smaller than 1.0 """ w_modules = space.sys.get('modules') - if space.contains_w(w_modules, space.wrap('_continuation')): - space.warn(space.wrap("Using _continuation/greenlet/stacklet together " - "with vmprof will crash"), - space.w_RuntimeWarning) + #if space.contains_w(w_modules, space.wrap('_continuation')): + # space.warn(space.wrap("Using _continuation/greenlet/stacklet together " + # "with vmprof will crash"), + # space.w_RuntimeWarning) try: rvmprof.enable(fileno, period) except rvmprof.VMProfError, e: diff --git a/pypy/module/cppyy/src/dummy_backend.cxx b/pypy/module/cppyy/src/dummy_backend.cxx --- a/pypy/module/cppyy/src/dummy_backend.cxx +++ b/pypy/module/cppyy/src/dummy_backend.cxx @@ -390,7 +390,7 @@ ((dummy::cppyy_test_data*)self)->destroy_arrays(); } else if (idx == s_methods["cppyy_test_data::set_bool"]) { assert(self && nargs == 1); - ((dummy::cppyy_test_data*)self)->set_bool((bool)((CPPYY_G__value*)args)[0].obj.in); + ((dummy::cppyy_test_data*)self)->set_bool((bool)((CPPYY_G__value*)args)[0].obj.i); } else if (idx == s_methods["cppyy_test_data::set_char"]) { assert(self && nargs == 1); ((dummy::cppyy_test_data*)self)->set_char(((CPPYY_G__value*)args)[0].obj.ch); 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 @@ -51,13 +51,19 @@ assert arr.tolist() == [1, 23, 4] def test_buffer(self): + import sys module = self.import_module(name='array') arr = module.array('i', [1,2,3,4]) buf = buffer(arr) exc = raises(TypeError, "buf[1] = '1'") assert str(exc.value) == "buffer is read-only" - # XXX big-endian - assert str(buf) == ('\x01\0\0\0' - '\x02\0\0\0' - '\x03\0\0\0' - '\x04\0\0\0') + if sys.byteorder == 'big': + assert str(buf) == ('\0\0\0\x01' + '\0\0\0\x02' + '\0\0\0\x03' + '\0\0\0\x04') + else: + assert str(buf) == ('\x01\0\0\0' + '\x02\0\0\0' + '\x03\0\0\0' + '\x04\0\0\0') 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 @@ -606,7 +606,7 @@ long intval; PyObject *name; - if (!PyArg_ParseTuple(args, "i", &intval)) + if (!PyArg_ParseTuple(args, "l", &intval)) return NULL; IntLike_Type.tp_as_number = &intlike_as_number; 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 @@ -386,11 +386,11 @@ lltype.free(pendian, flavor='raw') test("\x61\x00\x62\x00\x63\x00\x64\x00", -1) - - test("\x61\x00\x62\x00\x63\x00\x64\x00", None) - + if sys.byteorder == 'big': + test("\x00\x61\x00\x62\x00\x63\x00\x64", None) + else: + test("\x61\x00\x62\x00\x63\x00\x64\x00", None) test("\x00\x61\x00\x62\x00\x63\x00\x64", 1) - test("\xFE\xFF\x00\x61\x00\x62\x00\x63\x00\x64", 0, 1) test("\xFF\xFE\x61\x00\x62\x00\x63\x00\x64\x00", 0, -1) @@ -423,7 +423,10 @@ test("\x61\x00\x00\x00\x62\x00\x00\x00", -1) - test("\x61\x00\x00\x00\x62\x00\x00\x00", None) + if sys.byteorder == 'big': + test("\x00\x00\x00\x61\x00\x00\x00\x62", None) + else: + test("\x61\x00\x00\x00\x62\x00\x00\x00", None) test("\x00\x00\x00\x61\x00\x00\x00\x62", 1) diff --git a/pypy/module/marshal/test/test_marshalimpl.py b/pypy/module/marshal/test/test_marshalimpl.py --- a/pypy/module/marshal/test/test_marshalimpl.py +++ b/pypy/module/marshal/test/test_marshalimpl.py @@ -64,14 +64,17 @@ import marshal, struct class FakeM: + # NOTE: marshal is platform independent, running this test must assume + # that self.seen gets values from the endianess of the marshal module. + # (which is little endian!) def __init__(self): self.seen = [] def start(self, code): self.seen.append(code) def put_int(self, value): - self.seen.append(struct.pack("i", value)) + self.seen.append(struct.pack("<i", value)) def put_short(self, value): - self.seen.append(struct.pack("h", value)) + self.seen.append(struct.pack("<h", value)) def _marshal_check(x): expected = marshal.dumps(long(x)) diff --git a/pypy/module/micronumpy/appbridge.py b/pypy/module/micronumpy/appbridge.py --- a/pypy/module/micronumpy/appbridge.py +++ b/pypy/module/micronumpy/appbridge.py @@ -9,6 +9,7 @@ w_array_repr = None w_array_str = None w__usefields = None + w_partition = None def __init__(self, space): pass 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 @@ -557,8 +557,12 @@ return self.get_scalar_value().item(space) l_w = [] for i in range(self.get_shape()[0]): - l_w.append(space.call_method(self.descr_getitem(space, - space.wrap(i)), "tolist")) + item_w = self.descr_getitem(space, space.wrap(i)) + if (isinstance(item_w, W_NDimArray) or + isinstance(item_w, boxes.W_GenericBox)): + l_w.append(space.call_method(item_w, "tolist")) + else: + l_w.append(item_w) return space.newlist(l_w) def descr_ravel(self, space, w_order=None): @@ -934,6 +938,10 @@ return return self.implementation.sort(space, w_axis, w_order) + def descr_partition(self, space, __args__): + return get_appbridge_cache(space).call_method( + space, 'numpy.core._partition_use', 'partition', __args__.prepend(self)) + def descr_squeeze(self, space, w_axis=None): cur_shape = self.get_shape() if not space.is_none(w_axis): @@ -1658,6 +1666,7 @@ argsort = interp2app(W_NDimArray.descr_argsort), sort = interp2app(W_NDimArray.descr_sort), + partition = interp2app(W_NDimArray.descr_partition), astype = interp2app(W_NDimArray.descr_astype), base = GetSetProperty(W_NDimArray.descr_get_base), byteswap = interp2app(W_NDimArray.descr_byteswap), diff --git a/pypy/module/micronumpy/test/test_dtypes.py b/pypy/module/micronumpy/test/test_dtypes.py --- a/pypy/module/micronumpy/test/test_dtypes.py +++ b/pypy/module/micronumpy/test/test_dtypes.py @@ -351,7 +351,10 @@ assert np.dtype(xyz).name == 'xyz' # another obscure API, used in numpy record.py a = np.dtype((xyz, [('x', 'int32'), ('y', 'float32')])) - assert "[('x', '<i4'), ('y', '<f4')]" in repr(a) + if sys.byteorder == 'big': + assert "[('x', '>i4'), ('y', '>f4')]" in repr(a) + else: + assert "[('x', '<i4'), ('y', '<f4')]" in repr(a) assert 'xyz' in repr(a) data = [(1, 'a'), (2, 'bbb')] b = np.dtype((xyz, [('a', int), ('b', object)])) @@ -361,7 +364,10 @@ arr = np.array(data, dtype=b) assert arr[0][0] == 1 assert arr[0][1] == 'a' - b = np.dtype((xyz, [("col1", "<i4"), ("col2", "<i4"), ("col3", "<i4")])) + # NOTE if micronumpy is completed, we might extend this test to check both + # "<i4" and ">i4" + E = '<' if sys.byteorder == 'little' else '>' + b = np.dtype((xyz, [("col1", E+"i4"), ("col2", E+"i4"), ("col3", E+"i4")])) data = [(1, 2,3), (4, 5, 6)] a = np.array(data, dtype=b) x = pickle.loads(pickle.dumps(a)) @@ -423,18 +429,20 @@ assert hash(t5) != hash(t6) def test_pickle(self): + import sys import numpy as np from numpy import array, dtype from cPickle import loads, dumps a = array([1,2,3]) + E = '<' if sys.byteorder == 'little' else '>' if self.ptr_size == 8: - assert a.dtype.__reduce__() == (dtype, ('i8', 0, 1), (3, '<', None, None, None, -1, -1, 0)) + assert a.dtype.__reduce__() == (dtype, ('i8', 0, 1), (3, E, None, None, None, -1, -1, 0)) else: - assert a.dtype.__reduce__() == (dtype, ('i4', 0, 1), (3, '<', None, None, None, -1, -1, 0)) + assert a.dtype.__reduce__() == (dtype, ('i4', 0, 1), (3, E, None, None, None, -1, -1, 0)) assert loads(dumps(a.dtype)) == a.dtype assert np.dtype('bool').__reduce__() == (dtype, ('b1', 0, 1), (3, '|', None, None, None, -1, -1, 0)) assert np.dtype('|V16').__reduce__() == (dtype, ('V16', 0, 1), (3, '|', None, None, None, 16, 1, 0)) - assert np.dtype(('<f8', 2)).__reduce__() == (dtype, ('V16', 0, 1), (3, '|', (dtype('float64'), (2,)), None, None, 16, 8, 0)) + assert np.dtype((E+'f8', 2)).__reduce__() == (dtype, ('V16', 0, 1), (3, '|', (dtype('float64'), (2,)), None, None, 16, 8, 0)) def test_newbyteorder(self): import numpy as np @@ -916,6 +924,7 @@ def test_dtype_str(self): from numpy import dtype + import sys byteorder = self.native_prefix assert dtype('i8').str == byteorder + 'i8' assert dtype('<i8').str == '<i8' @@ -937,7 +946,8 @@ assert dtype('unicode').str == byteorder + 'U0' assert dtype(('string', 7)).str == '|S7' assert dtype('=S5').str == '|S5' - assert dtype(('unicode', 7)).str == '<U7' + assert dtype(('unicode', 7)).str == \ + ('<' if sys.byteorder == 'little' else '>')+'U7' assert dtype([('', 'f8')]).str == "|V8" assert dtype(('f8', 2)).str == "|V16" @@ -968,8 +978,12 @@ def test_isnative(self): from numpy import dtype + import sys assert dtype('i4').isnative == True - assert dtype('>i8').isnative == False + if sys.byteorder == 'big': + assert dtype('<i8').isnative == False + else: + assert dtype('>i8').isnative == False def test_any_all_nonzero(self): import numpy @@ -1185,6 +1199,7 @@ def test_setstate(self): import numpy as np import sys + E = '<' if sys.byteorder == 'little' else '>' d = np.dtype('f8') d.__setstate__((3, '|', (np.dtype('float64'), (2,)), None, None, 20, 1, 0)) assert d.str == ('<' if sys.byteorder == 'little' else '>') + 'f8' @@ -1201,7 +1216,7 @@ assert d.shape == (2,) assert d.itemsize == 8 assert d.subdtype is not None - assert repr(d) == "dtype(('<f8', (2,)))" + assert repr(d) == "dtype(('{E}f8', (2,)))".format(E=E) d = np.dtype(('<f8', 2)) assert d.fields is None @@ -1216,7 +1231,7 @@ assert d.shape == (2,) assert d.itemsize == 20 assert d.subdtype is not None - assert repr(d) == "dtype(('<f8', (2,)))" + assert repr(d) == "dtype(('{E}f8', (2,)))".format(E=E) d = np.dtype(('<f8', 2)) d.__setstate__((3, '|', (np.dtype('float64'), 2), None, None, 20, 1, 0)) @@ -1224,7 +1239,7 @@ assert d.shape == (2,) assert d.itemsize == 20 assert d.subdtype is not None - assert repr(d) == "dtype(('<f8', (2,)))" + assert repr(d) == "dtype(('{E}f8', (2,)))".format(E=E) d = np.dtype(('<f8', 2)) exc = raises(ValueError, "d.__setstate__((3, '|', None, ('f0', 'f1'), None, 16, 1, 0))") @@ -1256,14 +1271,14 @@ assert d.fields is not None assert d.shape == (2,) assert d.subdtype is not None - assert repr(d) == "dtype([('f0', '<f8'), ('f1', '<f8')])" + assert repr(d) == "dtype([('f0', '{E}f8'), ('f1', '{E}f8')])".format(E=E) d = np.dtype(('<f8', 2)) d.__setstate__((3, '|', None, ('f0', 'f1'), {'f0': (np.dtype('float64'), 0), 'f1': (np.dtype('float64'), 8)}, 16, 1, 0)) assert d.fields is not None assert d.shape == () assert d.subdtype is None - assert repr(d) == "dtype([('f0', '<f8'), ('f1', '<f8')])" + assert repr(d) == "dtype([('f0', '{E}f8'), ('f1', '{E}f8')])".format(E=E) d = np.dtype(('<f8', 2)) d.__setstate__((3, '|', None, ('f0', 'f1'), {'f0': (np.dtype('float64'), 0), 'f1': (np.dtype('float64'), 8)}, 16, 1, 0)) @@ -1271,7 +1286,7 @@ assert d.fields is not None assert d.shape == (2,) assert d.subdtype is not None - assert repr(d) == "dtype([('f0', '<f8'), ('f1', '<f8')])" + assert repr(d) == "dtype([('f0', '{E}f8'), ('f1', '{E}f8')])".format(E=E) def test_pickle_record(self): from numpy import array, dtype @@ -1317,6 +1332,7 @@ raises(ValueError, np.dtype, [('a', 'f4', (-1, -1))]) def test_aligned_size(self): + import sys import numpy as np if self.test_for_core_internal: try: @@ -1335,9 +1351,10 @@ dt = np.dtype({'f0': ('i4', 0), 'f1':('u1', 4)}, align=True) assert dt.itemsize == 8 assert dt.alignment == 4 - assert str(dt) == "{'names':['f0','f1'], 'formats':['<i4','u1'], 'offsets':[0,4], 'itemsize':8, 'aligned':True}" + E = '<' if sys.byteorder == 'little' else '>' + assert str(dt) == "{'names':['f0','f1'], 'formats':['%si4','u1'], 'offsets':[0,4], 'itemsize':8, 'aligned':True}" % E dt = np.dtype([('f1', 'u1'), ('f0', 'i4')], align=True) - assert str(dt) == "{'names':['f1','f0'], 'formats':['u1','<i4'], 'offsets':[0,4], 'itemsize':8, 'aligned':True}" + assert str(dt) == "{'names':['f1','f0'], 'formats':['u1','%si4'], 'offsets':[0,4], 'itemsize':8, 'aligned':True}" % E # Nesting should preserve that alignment dt1 = np.dtype([('f0', 'i4'), ('f1', [('f1', 'i1'), ('f2', 'i4'), ('f3', 'i1')]), @@ -1357,12 +1374,12 @@ assert dt3.itemsize == 20 assert dt1 == dt2 answer = "{'names':['f0','f1','f2'], " + \ - "'formats':['<i4',{'names':['f1','f2','f3'], " + \ - "'formats':['i1','<i4','i1'], " + \ + "'formats':['%si4',{'names':['f1','f2','f3'], " + \ + "'formats':['i1','%si4','i1'], " + \ "'offsets':[0,4,8], 'itemsize':12}," + \ "'i1'], " + \ "'offsets':[0,4,16], 'itemsize':20, 'aligned':True}" - assert str(dt3) == answer + assert str(dt3) == answer % (E,E) assert dt2 == dt3 # Nesting should preserve packing dt1 = np.dtype([('f0', 'i4'), diff --git a/pypy/module/micronumpy/test/test_ndarray.py b/pypy/module/micronumpy/test/test_ndarray.py --- a/pypy/module/micronumpy/test/test_ndarray.py +++ b/pypy/module/micronumpy/test/test_ndarray.py @@ -1791,6 +1791,7 @@ def test_scalar_view(self): from numpy import array + import sys a = array(3, dtype='int32') b = a.view(dtype='float32') assert b.shape == () @@ -1799,17 +1800,27 @@ assert exc.value[0] == "new type not compatible with array." exc = raises(TypeError, a.view, 'string') assert exc.value[0] == "data-type must not be 0-sized" - assert a.view('S4') == '\x03' + if sys.byteorder == 'big': + assert a.view('S4') == '\x00\x00\x00\x03' + else: + assert a.view('S4') == '\x03' a = array('abc1', dtype='c') assert (a == ['a', 'b', 'c', '1']).all() assert a.view('S4') == 'abc1' b = a.view([('a', 'i2'), ('b', 'i2')]) assert b.shape == (1,) - assert b[0][0] == 25185 - assert b[0][1] == 12643 + if sys.byteorder == 'big': + assert b[0][0] == 0x6162 + assert b[0][1] == 0x6331 + else: + assert b[0][0] == 25185 + assert b[0][1] == 12643 a = array([(1, 2)], dtype=[('a', 'int64'), ('b', 'int64')])[0] assert a.shape == () - assert a.view('S16') == '\x01' + '\x00' * 7 + '\x02' + if sys.byteorder == 'big': + assert a.view('S16') == '\x00' * 7 + '\x01' + '\x00' * 7 + '\x02' + else: + assert a.view('S16') == '\x01' + '\x00' * 7 + '\x02' a = array(2, dtype='<i8') b = a.view('<c8') assert 0 < b.real < 1 @@ -1818,15 +1829,23 @@ def test_array_view(self): from numpy import array, dtype + import sys x = array((1, 2), dtype='int8') assert x.shape == (2,) y = x.view(dtype='int16') assert x.shape == (2,) - assert y[0] == 513 + if sys.byteorder == 'big': + assert y[0] == 0x0102 + else: + assert y[0] == 513 == 0x0201 assert y.dtype == dtype('int16') y[0] = 670 - assert x[0] == -98 - assert x[1] == 2 + if sys.byteorder == 'little': + assert x[0] == -98 + assert x[1] == 2 + else: + assert x[0] == 2 + assert x[1] == -98 f = array([1000, -1234], dtype='i4') nnp = self.non_native_prefix d = f.view(dtype=nnp + 'i4') @@ -1847,7 +1866,10 @@ assert x.view('S4')[0] == 'abc' assert x.view('S4')[1] == 'defg' a = array([(1, 2)], dtype=[('a', 'int64'), ('b', 'int64')]) - assert a.view('S16')[0] == '\x01' + '\x00' * 7 + '\x02' + if sys.byteorder == 'big': + assert a.view('S16')[0] == '\x00' * 7 + '\x01' + '\x00' * 7 + '\x02' + else: + assert a.view('S16')[0] == '\x01' + '\x00' * 7 + '\x02' def test_half_conversions(self): from numpy import array, arange @@ -1936,6 +1958,22 @@ a = array([[1, 2], [3, 4]]) assert (a + a).tolist() == [[2, 4], [6, 8]] + def test_tolist_object(self): + from numpy import array + a = array([0], dtype=object) + assert a.tolist() == [0] + + def test_tolist_object_slice(self): + from numpy import array + list_expected = [slice(0, 1), 0] + a = array(list_expected, dtype=object) + assert a.tolist() == list_expected + + def test_tolist_object_slice_2d(self): + from numpy import array + a = array([(slice(0, 1), 1), (0, 1)], dtype=object) + assert a.tolist() == [[slice(0, 1, None), 1], [0, 1]] + def test_tolist_slice(self): from numpy import array a = array([[17.1, 27.2], [40.3, 50.3]]) @@ -2409,11 +2447,16 @@ from numpy import array import sys a = array([1, 2, 3, 4], dtype='i4') - assert a.data[0] == '\x01' + assert a.data[0] == ('\x01' if sys.byteorder == 'little' else '\x00') assert a.data[1] == '\x00' - assert a.data[4] == '\x02' - a.data[4] = '\xff' - assert a[1] == 0xff + assert a.data[3] == ('\x00' if sys.byteorder == 'little' else '\x01') + assert a.data[4] == ('\x02' if sys.byteorder == 'little' else '\x00') + a.data[4] = '\x7f' + if sys.byteorder == 'big': + a.data[7] = '\x00' # make sure 0x02 is reset to 0 + assert a[1] == (0x7f000000) + else: + assert a[1] == 0x7f assert len(a.data) == 16 assert type(a.data) is buffer if '__pypy__' in sys.builtin_module_names: @@ -2485,12 +2528,17 @@ def test__reduce__(self): from numpy import array, dtype from cPickle import loads, dumps + import sys a = array([1, 2], dtype="int64") data = a.__reduce__() - assert data[2][4] == '\x01\x00\x00\x00\x00\x00\x00\x00' \ - '\x02\x00\x00\x00\x00\x00\x00\x00' + if sys.byteorder == 'big': + assert data[2][4] == '\x00\x00\x00\x00\x00\x00\x00\x01' \ + '\x00\x00\x00\x00\x00\x00\x00\x02' + else: + assert data[2][4] == '\x01\x00\x00\x00\x00\x00\x00\x00' \ + '\x02\x00\x00\x00\x00\x00\x00\x00' pickled_data = dumps(a) assert (loads(pickled_data) == a).all() @@ -2623,12 +2671,16 @@ def test_ndarray_from_buffer(self): import numpy as np import array + import sys buf = array.array('c', ['\x00']*2*3) a = np.ndarray((3,), buffer=buf, dtype='i2') a[0] = ord('b') a[1] = ord('a') a[2] = ord('r') - assert list(buf) == ['b', '\x00', 'a', '\x00', 'r', '\x00'] + if sys.byteorder == 'big': + assert list(buf) == ['\x00', 'b', '\x00', 'a', '\x00', 'r'] + else: + assert list(buf) == ['b', '\x00', 'a', '\x00', 'r', '\x00'] assert a.base is buf def test_ndarray_subclass_from_buffer(self): @@ -2643,13 +2695,17 @@ def test_ndarray_from_buffer_and_offset(self): import numpy as np import array + import sys buf = array.array('c', ['\x00']*7) buf[0] = 'X' a = np.ndarray((3,), buffer=buf, offset=1, dtype='i2') a[0] = ord('b') a[1] = ord('a') a[2] = ord('r') - assert list(buf) == ['X', 'b', '\x00', 'a', '\x00', 'r', '\x00'] + if sys.byteorder == 'big': + assert list(buf) == ['X', '\x00', 'b', '\x00', 'a', '\x00', 'r'] + else: + assert list(buf) == ['X', 'b', '\x00', 'a', '\x00', 'r', '\x00'] def test_ndarray_from_buffer_out_of_bounds(self): import numpy as np @@ -3485,7 +3541,11 @@ BaseNumpyAppTest.setup_class.im_func(cls) cls.w_data = cls.space.wrap(struct.pack('dddd', 1, 2, 3, 4)) cls.w_fdata = cls.space.wrap(struct.pack('f', 2.3)) - cls.w_float16val = cls.space.wrap('\x00E') # 5.0 in float16 + import sys + if sys.byteorder == 'big': + cls.w_float16val = cls.space.wrap('E\x00') # 5.0 in float16 + else: + cls.w_float16val = cls.space.wrap('\x00E') # 5.0 in float16 cls.w_float32val = cls.space.wrap(struct.pack('f', 5.2)) cls.w_float64val = cls.space.wrap(struct.pack('d', 300.4)) cls.w_ulongval = cls.space.wrap(struct.pack('L', 12)) @@ -3593,9 +3653,15 @@ assert (t == []).all() u = fromstring("\x01\x00\x00\x00\x00\x00\x00\x00", dtype=int) if sys.maxint > 2 ** 31 - 1: - assert (u == [1]).all() + if sys.byteorder == 'big': + assert (u == [0x0100000000000000]).all() + else: + assert (u == [1]).all() else: - assert (u == [1, 0]).all() + if sys.byteorder == 'big': + assert (u == [0x01000000, 0]).all() + else: + assert (u == [1, 0]).all() v = fromstring("abcd", dtype="|S2") assert v[0] == "ab" assert v[1] == "cd" @@ -3652,9 +3718,15 @@ k = fromstring(self.float16val, dtype='float16') assert k[0] == dtype('float16').type(5.) dt = array([5], dtype='longfloat').dtype + print(dt.itemsize) if dt.itemsize == 8: - m = fromstring('\x00\x00\x00\x00\x00\x00\x14@', - dtype='float64') + import sys + if sys.byteorder == 'big': + m = fromstring('@\x14\x00\x00\x00\x00\x00\x00', + dtype='float64') + else: + m = fromstring('\x00\x00\x00\x00\x00\x00\x14@', + dtype='float64') elif dt.itemsize == 12: m = fromstring('\x00\x00\x00\x00\x00\x00\x00\xa0\x01@\x00\x00', dtype='float96') @@ -3676,8 +3748,13 @@ def test_tostring(self): from numpy import array - assert array([1, 2, 3], 'i2').tostring() == '\x01\x00\x02\x00\x03\x00' - assert array([1, 2, 3], 'i2')[::2].tostring() == '\x01\x00\x03\x00' + import sys + if sys.byteorder == 'big': + assert array([1, 2, 3], 'i2').tostring() == '\x00\x01\x00\x02\x00\x03' + assert array([1, 2, 3], 'i2')[::2].tostring() == '\x00\x01\x00\x03' + else: + assert array([1, 2, 3], 'i2').tostring() == '\x01\x00\x02\x00\x03\x00' + assert array([1, 2, 3], 'i2')[::2].tostring() == '\x01\x00\x03\x00' assert array([1, 2, 3], '<i2')[::2].tostring() == '\x01\x00\x03\x00' assert array([1, 2, 3], '>i2')[::2].tostring() == '\x00\x01\x00\x03' assert array(0, dtype='i2').tostring() == '\x00\x00' @@ -4173,7 +4250,11 @@ v = a.view(('float32', 4)) assert v.dtype == np.dtype('float32') assert v.shape == (10, 4) - assert v[0][-1] == 2.53125 + import sys + if sys.byteorder == 'big': + assert v[0][-2] == 2.53125 + else: + assert v[0][-1] == 2.53125 exc = raises(ValueError, "a.view(('float32', 2))") assert exc.value[0] == 'new type not compatible with array.' diff --git a/pypy/module/micronumpy/test/test_scalar.py b/pypy/module/micronumpy/test/test_scalar.py --- a/pypy/module/micronumpy/test/test_scalar.py +++ b/pypy/module/micronumpy/test/test_scalar.py @@ -109,6 +109,7 @@ def test_pickle(self): from numpy import dtype, zeros + import sys try: from numpy.core.multiarray import scalar except ImportError: @@ -119,9 +120,11 @@ f = dtype('float64').type(13.37) c = dtype('complex128').type(13 + 37.j) - assert i.__reduce__() == (scalar, (dtype('int32'), '9\x05\x00\x00')) - assert f.__reduce__() == (scalar, (dtype('float64'), '=\n\xd7\xa3p\xbd*@')) - assert c.__reduce__() == (scalar, (dtype('complex128'), '\x00\x00\x00\x00\x00\x00*@\x00\x00\x00\x00\x00\x80B@')) + swap = lambda s: (''.join(reversed(s))) if sys.byteorder == 'big' else s + assert i.__reduce__() == (scalar, (dtype('int32'), swap('9\x05\x00\x00'))) + assert f.__reduce__() == (scalar, (dtype('float64'), swap('=\n\xd7\xa3p\xbd*@'))) + assert c.__reduce__() == (scalar, (dtype('complex128'), swap('\x00\x00\x00\x00\x00\x00*@') + \ + swap('\x00\x00\x00\x00\x00\x80B@'))) assert loads(dumps(i)) == i assert loads(dumps(f)) == f @@ -256,13 +259,20 @@ assert t < 7e-323 t = s.view('complex64') assert type(t) is np.complex64 - assert 0 < t.real < 1 - assert t.imag == 0 + if sys.byteorder == 'big': + assert 0 < t.imag < 1 + assert t.real == 0 + else: + assert 0 < t.real < 1 + assert t.imag == 0 exc = raises(TypeError, s.view, 'string') assert exc.value[0] == "data-type must not be 0-sized" t = s.view('S8') assert type(t) is np.string_ - assert t == '\x0c' + if sys.byteorder == 'big': + assert t == '\x00' * 7 + '\x0c' + else: + assert t == '\x0c' s = np.dtype('string').type('abc1') assert s.view('S4') == 'abc1' if '__pypy__' in sys.builtin_module_names: diff --git a/pypy/module/micronumpy/test/test_selection.py b/pypy/module/micronumpy/test/test_selection.py --- a/pypy/module/micronumpy/test/test_selection.py +++ b/pypy/module/micronumpy/test/test_selection.py @@ -327,10 +327,15 @@ # tests from numpy/core/tests/test_regression.py def test_sort_bigendian(self): from numpy import array, dtype - a = array(range(11), dtype='float64') - c = a.astype(dtype('<f8')) - c.sort() - assert max(abs(a-c)) < 1e-32 + import sys + + # little endian sorting for big endian machine + # is not yet supported! IMPL ME + if sys.byteorder == 'little': + a = array(range(11), dtype='float64') + c = a.astype(dtype('<f8')) + c.sort() + assert max(abs(a-c)) < 1e-32 def test_string_argsort_with_zeros(self): import numpy as np diff --git a/pypy/module/micronumpy/test/test_subtype.py b/pypy/module/micronumpy/test/test_subtype.py --- a/pypy/module/micronumpy/test/test_subtype.py +++ b/pypy/module/micronumpy/test/test_subtype.py @@ -478,6 +478,7 @@ (version, shp, typ, isf, raw) = state _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit