[pypy-svn] r73192 - in pypy/branch/cpython-extension: . dotviewer lib-python pypy pypy/doc pypy/interpreter pypy/interpreter/pyparser pypy/interpreter/pyparser/test pypy/interpreter/test pypy/jit/backend/cli/test pypy/jit/backend/llsupport pypy/jit/backend/llsupport/test pypy/jit/backend/llvm/test pypy/jit/backend/x86 pypy/jit/backend/x86/test pypy/jit/backend/x86/tool pypy/jit/metainterp pypy/lib pypy/lib/_ctypes pypy/lib/app_test pypy/lib/app_test/ctypes_tests pypy/module/__pypy__ pypy/module/_file pypy/module/_minimal_curses pypy/module/_socket pypy/module/_socket/test pypy/module/_sre pypy/module/_weakref pypy/module/_weakref/test pypy/module/exceptions pypy/module/imp pypy/module/mmap pypy/module/posix pypy/module/posix/test pypy/module/pyexpat/test pypy/module/pypyjit pypy/module/rctime pypy/module/rctime/test pypy/module/readline/test pypy/module/zipimport pypy/module/zipimport/test pypy/objspace pypy/objspace/flow pypy/objspace/std pypy/objspace/std/test pypy/objspace/test pypy/rlib pypy/rlib/test pypy/rpython pypy/rpython/lltypesystem pypy/rpython/lltypesystem/test pypy/rpython/memory/gc pypy/rpython/memory/gc/test pypy/rpython/memory/test pypy/rpython/test pypy/rpython/tool pypy/rpython/tool/test pypy/tool pypy/tool/test pypy/translator pypy/translator/c pypy/translator/c/gcc/test pypy/translator/c/src pypy/translator/c/test pypy/translator/c/winproj pypy/translator/goal pypy/translator/jvm/test pypy/translator/platform pypy/translator/platform/test pypy/translator/stackless
benjamin at codespeak.net
benjamin at codespeak.net
Wed Mar 31 00:17:19 CEST 2010
Author: benjamin
Date: Wed Mar 31 00:17:06 2010
New Revision: 73192
Added:
pypy/branch/cpython-extension/pypy/jit/backend/llsupport/support.py
- copied unchanged from r73191, pypy/trunk/pypy/jit/backend/llsupport/support.py
pypy/branch/cpython-extension/pypy/objspace/std/frame.py
- copied unchanged from r73191, pypy/trunk/pypy/objspace/std/frame.py
pypy/branch/cpython-extension/pypy/rlib/rstackovf.py
- copied unchanged from r73191, pypy/trunk/pypy/rlib/rstackovf.py
pypy/branch/cpython-extension/pypy/rlib/test/test_rstackovf.py
- copied unchanged from r73191, pypy/trunk/pypy/rlib/test/test_rstackovf.py
pypy/branch/cpython-extension/pypy/tool/runsubprocess.py
- copied unchanged from r73191, pypy/trunk/pypy/tool/runsubprocess.py
pypy/branch/cpython-extension/pypy/tool/test/test_runsubprocess.py
- copied unchanged from r73191, pypy/trunk/pypy/tool/test/test_runsubprocess.py
pypy/branch/cpython-extension/pypy/translator/c/src/winstuff.c
- copied unchanged from r73191, pypy/trunk/pypy/translator/c/src/winstuff.c
Removed:
pypy/branch/cpython-extension/pypy/lib/functional.py
pypy/branch/cpython-extension/pypy/objspace/std/mro.py
pypy/branch/cpython-extension/pypy/translator/c/winproj/
Modified:
pypy/branch/cpython-extension/ (props changed)
pypy/branch/cpython-extension/dotviewer/ (props changed)
pypy/branch/cpython-extension/lib-python/ (props changed)
pypy/branch/cpython-extension/lib-python/conftest.py
pypy/branch/cpython-extension/pypy/ (props changed)
pypy/branch/cpython-extension/pypy/doc/coding-guide.txt
pypy/branch/cpython-extension/pypy/doc/getting-started-python.txt
pypy/branch/cpython-extension/pypy/interpreter/baseobjspace.py
pypy/branch/cpython-extension/pypy/interpreter/error.py
pypy/branch/cpython-extension/pypy/interpreter/executioncontext.py
pypy/branch/cpython-extension/pypy/interpreter/gateway.py
pypy/branch/cpython-extension/pypy/interpreter/nestedscope.py
pypy/branch/cpython-extension/pypy/interpreter/pyframe.py
pypy/branch/cpython-extension/pypy/interpreter/pyopcode.py
pypy/branch/cpython-extension/pypy/interpreter/pyparser/future.py
pypy/branch/cpython-extension/pypy/interpreter/pyparser/test/test_futureautomaton.py
pypy/branch/cpython-extension/pypy/interpreter/test/test_executioncontext.py
pypy/branch/cpython-extension/pypy/interpreter/test/test_gateway.py
pypy/branch/cpython-extension/pypy/interpreter/test/test_interpreter.py
pypy/branch/cpython-extension/pypy/interpreter/test/test_syntax.py
pypy/branch/cpython-extension/pypy/interpreter/test/test_zpy.py
pypy/branch/cpython-extension/pypy/jit/backend/cli/test/conftest.py (props changed)
pypy/branch/cpython-extension/pypy/jit/backend/llsupport/descr.py
pypy/branch/cpython-extension/pypy/jit/backend/llsupport/gc.py
pypy/branch/cpython-extension/pypy/jit/backend/llsupport/llmodel.py
pypy/branch/cpython-extension/pypy/jit/backend/llsupport/test/test_descr.py
pypy/branch/cpython-extension/pypy/jit/backend/llsupport/test/test_gc.py
pypy/branch/cpython-extension/pypy/jit/backend/llvm/test/conftest.py (props changed)
pypy/branch/cpython-extension/pypy/jit/backend/x86/assembler.py
pypy/branch/cpython-extension/pypy/jit/backend/x86/runner.py
pypy/branch/cpython-extension/pypy/jit/backend/x86/test/conftest.py
pypy/branch/cpython-extension/pypy/jit/backend/x86/test/test_gc_integration.py (props changed)
pypy/branch/cpython-extension/pypy/jit/backend/x86/test/test_ztranslation.py
pypy/branch/cpython-extension/pypy/jit/backend/x86/tool/viewcode.py
pypy/branch/cpython-extension/pypy/jit/metainterp/logger.py (props changed)
pypy/branch/cpython-extension/pypy/lib/_ctypes/function.py
pypy/branch/cpython-extension/pypy/lib/app_test/ctypes_tests/test_cast.py
pypy/branch/cpython-extension/pypy/lib/app_test/ctypes_tests/test_funcptr.py
pypy/branch/cpython-extension/pypy/lib/app_test/test_dbm_extra.py
pypy/branch/cpython-extension/pypy/lib/resource.py
pypy/branch/cpython-extension/pypy/module/__pypy__/interp_magic.py
pypy/branch/cpython-extension/pypy/module/_file/__init__.py
pypy/branch/cpython-extension/pypy/module/_minimal_curses/__init__.py
pypy/branch/cpython-extension/pypy/module/_socket/interp_func.py
pypy/branch/cpython-extension/pypy/module/_socket/test/test_sock_app.py
pypy/branch/cpython-extension/pypy/module/_sre/interp_sre.py
pypy/branch/cpython-extension/pypy/module/_weakref/interp__weakref.py
pypy/branch/cpython-extension/pypy/module/_weakref/test/test_weakref.py
pypy/branch/cpython-extension/pypy/module/exceptions/ (props changed)
pypy/branch/cpython-extension/pypy/module/imp/importing.py
pypy/branch/cpython-extension/pypy/module/mmap/interp_mmap.py
pypy/branch/cpython-extension/pypy/module/posix/interp_posix.py
pypy/branch/cpython-extension/pypy/module/posix/test/test_posix2.py
pypy/branch/cpython-extension/pypy/module/pyexpat/test/test_build.py
pypy/branch/cpython-extension/pypy/module/pypyjit/interp_jit.py
pypy/branch/cpython-extension/pypy/module/rctime/interp_time.py
pypy/branch/cpython-extension/pypy/module/rctime/test/test_rctime.py
pypy/branch/cpython-extension/pypy/module/readline/test/test_c_readline.py
pypy/branch/cpython-extension/pypy/module/readline/test/test_with_pypy.py
pypy/branch/cpython-extension/pypy/module/zipimport/interp_zipimport.py
pypy/branch/cpython-extension/pypy/module/zipimport/test/test_zipimport.py
pypy/branch/cpython-extension/pypy/objspace/descroperation.py
pypy/branch/cpython-extension/pypy/objspace/flow/model.py
pypy/branch/cpython-extension/pypy/objspace/flow/objspace.py
pypy/branch/cpython-extension/pypy/objspace/std/__init__.py
pypy/branch/cpython-extension/pypy/objspace/std/boolobject.py
pypy/branch/cpython-extension/pypy/objspace/std/booltype.py
pypy/branch/cpython-extension/pypy/objspace/std/complexobject.py
pypy/branch/cpython-extension/pypy/objspace/std/complextype.py
pypy/branch/cpython-extension/pypy/objspace/std/default.py
pypy/branch/cpython-extension/pypy/objspace/std/dictmultiobject.py
pypy/branch/cpython-extension/pypy/objspace/std/dictproxyobject.py
pypy/branch/cpython-extension/pypy/objspace/std/dictproxytype.py
pypy/branch/cpython-extension/pypy/objspace/std/dicttype.py
pypy/branch/cpython-extension/pypy/objspace/std/floatobject.py
pypy/branch/cpython-extension/pypy/objspace/std/floattype.py
pypy/branch/cpython-extension/pypy/objspace/std/frozensettype.py
pypy/branch/cpython-extension/pypy/objspace/std/intobject.py
pypy/branch/cpython-extension/pypy/objspace/std/inttype.py
pypy/branch/cpython-extension/pypy/objspace/std/iterobject.py
pypy/branch/cpython-extension/pypy/objspace/std/itertype.py
pypy/branch/cpython-extension/pypy/objspace/std/listobject.py
pypy/branch/cpython-extension/pypy/objspace/std/listtype.py
pypy/branch/cpython-extension/pypy/objspace/std/longobject.py
pypy/branch/cpython-extension/pypy/objspace/std/longtype.py
pypy/branch/cpython-extension/pypy/objspace/std/marshal_impl.py
pypy/branch/cpython-extension/pypy/objspace/std/model.py
pypy/branch/cpython-extension/pypy/objspace/std/noneobject.py
pypy/branch/cpython-extension/pypy/objspace/std/nonetype.py
pypy/branch/cpython-extension/pypy/objspace/std/objectobject.py
pypy/branch/cpython-extension/pypy/objspace/std/objecttype.py
pypy/branch/cpython-extension/pypy/objspace/std/objspace.py
pypy/branch/cpython-extension/pypy/objspace/std/proxyobject.py
pypy/branch/cpython-extension/pypy/objspace/std/rangeobject.py
pypy/branch/cpython-extension/pypy/objspace/std/register_all.py
pypy/branch/cpython-extension/pypy/objspace/std/ropeobject.py
pypy/branch/cpython-extension/pypy/objspace/std/ropeunicodeobject.py
pypy/branch/cpython-extension/pypy/objspace/std/setobject.py
pypy/branch/cpython-extension/pypy/objspace/std/settype.py
pypy/branch/cpython-extension/pypy/objspace/std/sliceobject.py
pypy/branch/cpython-extension/pypy/objspace/std/slicetype.py
pypy/branch/cpython-extension/pypy/objspace/std/smallintobject.py
pypy/branch/cpython-extension/pypy/objspace/std/stdtypedef.py
pypy/branch/cpython-extension/pypy/objspace/std/stringobject.py
pypy/branch/cpython-extension/pypy/objspace/std/stringtype.py
pypy/branch/cpython-extension/pypy/objspace/std/strjoinobject.py
pypy/branch/cpython-extension/pypy/objspace/std/strsliceobject.py
pypy/branch/cpython-extension/pypy/objspace/std/test/test_complexobject.py
pypy/branch/cpython-extension/pypy/objspace/std/test/test_dictmultiobject.py
pypy/branch/cpython-extension/pypy/objspace/std/test/test_floatobject.py
pypy/branch/cpython-extension/pypy/objspace/std/test/test_intobject.py
pypy/branch/cpython-extension/pypy/objspace/std/test/test_listobject.py
pypy/branch/cpython-extension/pypy/objspace/std/test/test_longobject.py
pypy/branch/cpython-extension/pypy/objspace/std/test/test_setobject.py (props changed)
pypy/branch/cpython-extension/pypy/objspace/std/test/test_smallintobject.py
pypy/branch/cpython-extension/pypy/objspace/std/test/test_typeobject.py
pypy/branch/cpython-extension/pypy/objspace/std/transparent.py
pypy/branch/cpython-extension/pypy/objspace/std/tupleobject.py
pypy/branch/cpython-extension/pypy/objspace/std/tupletype.py
pypy/branch/cpython-extension/pypy/objspace/std/typeobject.py
pypy/branch/cpython-extension/pypy/objspace/std/typetype.py
pypy/branch/cpython-extension/pypy/objspace/std/unicodeobject.py
pypy/branch/cpython-extension/pypy/objspace/std/unicodetype.py
pypy/branch/cpython-extension/pypy/objspace/test/test_descroperation.py
pypy/branch/cpython-extension/pypy/rlib/_rsocket_rffi.py
pypy/branch/cpython-extension/pypy/rlib/rarithmetic.py
pypy/branch/cpython-extension/pypy/rlib/rbigint.py
pypy/branch/cpython-extension/pypy/rlib/rmarshal.py
pypy/branch/cpython-extension/pypy/rlib/rsocket.py
pypy/branch/cpython-extension/pypy/rlib/rstack.py
pypy/branch/cpython-extension/pypy/rlib/rzipfile.py
pypy/branch/cpython-extension/pypy/rlib/test/test_rarithmetic.py
pypy/branch/cpython-extension/pypy/rlib/test/test_rbigint.py
pypy/branch/cpython-extension/pypy/rlib/test/test_rcoroutine.py (props changed)
pypy/branch/cpython-extension/pypy/rlib/test/test_rmarshal.py
pypy/branch/cpython-extension/pypy/rlib/test/test_rsocket.py
pypy/branch/cpython-extension/pypy/rlib/test/test_rstruct.py
pypy/branch/cpython-extension/pypy/rpython/exceptiondata.py
pypy/branch/cpython-extension/pypy/rpython/llinterp.py
pypy/branch/cpython-extension/pypy/rpython/lltypesystem/llgroup.py
pypy/branch/cpython-extension/pypy/rpython/lltypesystem/lltype.py
pypy/branch/cpython-extension/pypy/rpython/lltypesystem/opimpl.py
pypy/branch/cpython-extension/pypy/rpython/lltypesystem/rffi.py
pypy/branch/cpython-extension/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
pypy/branch/cpython-extension/pypy/rpython/lltypesystem/test/test_llgroup.py
pypy/branch/cpython-extension/pypy/rpython/memory/gc/generation.py
pypy/branch/cpython-extension/pypy/rpython/memory/gc/hybrid.py
pypy/branch/cpython-extension/pypy/rpython/memory/gc/test/test_direct.py
pypy/branch/cpython-extension/pypy/rpython/memory/test/test_gc.py
pypy/branch/cpython-extension/pypy/rpython/memory/test/test_transformed_gc.py
pypy/branch/cpython-extension/pypy/rpython/test/test_rbuiltin.py
pypy/branch/cpython-extension/pypy/rpython/test/test_rdict.py
pypy/branch/cpython-extension/pypy/rpython/test/test_rint.py
pypy/branch/cpython-extension/pypy/rpython/tool/rffi_platform.py
pypy/branch/cpython-extension/pypy/rpython/tool/rfficache.py
pypy/branch/cpython-extension/pypy/rpython/tool/test/test_rffi_platform.py
pypy/branch/cpython-extension/pypy/tool/terminal.py
pypy/branch/cpython-extension/pypy/translator/c/gcc/test/conftest.py
pypy/branch/cpython-extension/pypy/translator/c/genc.py
pypy/branch/cpython-extension/pypy/translator/c/node.py
pypy/branch/cpython-extension/pypy/translator/c/primitive.py
pypy/branch/cpython-extension/pypy/translator/c/src/commondefs.h
pypy/branch/cpython-extension/pypy/translator/c/src/exception.h
pypy/branch/cpython-extension/pypy/translator/c/src/llgroup.h
pypy/branch/cpython-extension/pypy/translator/c/src/main.h
pypy/branch/cpython-extension/pypy/translator/c/test/test_exception.py
pypy/branch/cpython-extension/pypy/translator/c/test/test_lltyped.py
pypy/branch/cpython-extension/pypy/translator/c/test/test_newgc.py
pypy/branch/cpython-extension/pypy/translator/c/test/test_refcount.py (props changed)
pypy/branch/cpython-extension/pypy/translator/c/test/test_standalone.py
pypy/branch/cpython-extension/pypy/translator/c/test/test_typed.py
pypy/branch/cpython-extension/pypy/translator/exceptiontransform.py
pypy/branch/cpython-extension/pypy/translator/goal/translate.py
pypy/branch/cpython-extension/pypy/translator/jvm/test/test_backendopt.py
pypy/branch/cpython-extension/pypy/translator/jvm/test/test_rarithmetic.py
pypy/branch/cpython-extension/pypy/translator/platform/__init__.py
pypy/branch/cpython-extension/pypy/translator/platform/linux.py
pypy/branch/cpython-extension/pypy/translator/platform/maemo.py
pypy/branch/cpython-extension/pypy/translator/platform/posix.py
pypy/branch/cpython-extension/pypy/translator/platform/test/test_maemo.py
pypy/branch/cpython-extension/pypy/translator/platform/test/test_makefile.py
pypy/branch/cpython-extension/pypy/translator/stackless/code.py
Log:
merge from trunk
Modified: pypy/branch/cpython-extension/lib-python/conftest.py
==============================================================================
--- pypy/branch/cpython-extension/lib-python/conftest.py (original)
+++ pypy/branch/cpython-extension/lib-python/conftest.py Wed Mar 31 00:17:06 2010
@@ -282,7 +282,7 @@
RegrTest('test_largefile.py'),
RegrTest('test_linuxaudiodev.py', skip="unsupported extension module"),
RegrTest('test_list.py', core=True),
- RegrTest('test_locale.py'),
+ RegrTest('test_locale.py', usemodules="_locale"),
RegrTest('test_logging.py', usemodules='thread'),
RegrTest('test_long.py', core=True),
RegrTest('test_long_future.py', core=True),
@@ -479,7 +479,7 @@
RegrTest('test_pep352.py'),
RegrTest('test_platform.py'),
RegrTest('test_runpy.py'),
- RegrTest('test_sqlite.py', usemodules="thread"),
+ RegrTest('test_sqlite.py', usemodules="thread _rawffi zlib"),
RegrTest('test_startfile.py', skip="bogus test"),
RegrTest('test_structmembers.py', skip="depends on _testcapi"),
RegrTest('test_urllib2_localnet.py', usemodules="thread"),
Modified: pypy/branch/cpython-extension/pypy/doc/coding-guide.txt
==============================================================================
--- pypy/branch/cpython-extension/pypy/doc/coding-guide.txt (original)
+++ pypy/branch/cpython-extension/pypy/doc/coding-guide.txt Wed Mar 31 00:17:06 2010
@@ -241,11 +241,17 @@
We are using
-**integer, float, string, boolean**
+**integer, float, boolean**
- a lot of, but not all string methods are supported. When slicing a string
- it is necessary to prove that the slice start and stop indexes are
- non-negative.
+ works.
+
+**strings**
+
+ a lot of, but not all string methods are supported. Indexes can be
+ negative. In case they are not, then you get slightly more efficient
+ code if the translator can prove that they are non-negative. When
+ slicing a string it is necessary to prove that the slice start and
+ stop indexes are non-negative.
**tuples**
Modified: pypy/branch/cpython-extension/pypy/doc/getting-started-python.txt
==============================================================================
--- pypy/branch/cpython-extension/pypy/doc/getting-started-python.txt (original)
+++ pypy/branch/cpython-extension/pypy/doc/getting-started-python.txt Wed Mar 31 00:17:06 2010
@@ -42,6 +42,7 @@
* ``python-dev``
* ``python-ctypes`` if you are still using Python2.4
* ``libffi-dev``
+ * ``pkg-config`` (to help us locate libffi files)
* ``libz-dev`` (for the optional ``zlib`` module)
* ``libbz2-dev`` (for the optional ``bz2`` module)
* ``libncurses-dev`` (for the optional ``_minimal_curses`` module)
Modified: pypy/branch/cpython-extension/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/baseobjspace.py (original)
+++ pypy/branch/cpython-extension/pypy/interpreter/baseobjspace.py Wed Mar 31 00:17:06 2010
@@ -1,3 +1,5 @@
+import itertools
+import pypy
from pypy.interpreter.executioncontext import ExecutionContext, ActionFlag
from pypy.interpreter.executioncontext import UserDelAction, FrameTraceAction
from pypy.interpreter.error import OperationError, operationerrfmt
@@ -9,11 +11,14 @@
from pypy.rlib.objectmodel import we_are_translated
from pypy.rlib.debug import make_sure_not_resized
from pypy.rlib.timer import DummyTimer, Timer
+from pypy.rlib.rarithmetic import r_uint
from pypy.rlib import jit
import os, sys
__all__ = ['ObjSpace', 'OperationError', 'Wrappable', 'W_Root']
+UINT_MAX_32_BITS = r_uint(4294967295)
+
class W_Root(object):
"""This is the abstract root class of all wrapped objects that live
@@ -402,7 +407,6 @@
if ('time2' in modules or 'rctime' in modules) and 'time' in modules:
modules.remove('time')
- import pypy
if not self.config.objspace.nofaking:
for modname in self.ALL_BUILTIN_MODULES:
if not (os.path.exists(
@@ -445,19 +449,18 @@
self.builtin_modules['__builtin__'] = self.wrap(w_builtin)
self.setitem(self.builtin.w_dict, self.wrap('__builtins__'), w_builtin)
- bootstrap_modules = ['sys', 'imp', '__builtin__', 'exceptions']
- installed_builtin_modules = bootstrap_modules[:]
+ bootstrap_modules = set(('sys', 'imp', '__builtin__', 'exceptions'))
+ installed_builtin_modules = list(bootstrap_modules)
- self.export_builtin_exceptions()
+ exception_types_w = self.export_builtin_exceptions()
# initialize with "bootstrap types" from objspace (e.g. w_None)
- for name, value in self.__dict__.items():
- if name.startswith('w_') and not name.endswith('Type'):
- name = name[2:]
- #print "setitem: space instance %-20s into builtins" % name
- self.setitem(self.builtin.w_dict, self.wrap(name), value)
+ types_w = itertools.chain(self.get_builtin_types().iteritems(),
+ exception_types_w.iteritems())
+ for name, w_type in types_w:
+ self.setitem(self.builtin.w_dict, self.wrap(name), w_type)
- # install mixed and faked modules and set builtin_module_names on sys
+ # install mixed and faked modules
for mixedname in self.get_builtinmodule_to_install():
if (mixedname not in bootstrap_modules
and not mixedname.startswith('faked+')):
@@ -475,17 +478,28 @@
self.setitem(self.sys.w_dict, self.wrap('builtin_module_names'),
w_builtin_module_names)
+ def get_builtin_types(self):
+ """Get a dictionary mapping the names of builtin types to the type
+ objects."""
+ raise NotImplementedError
+
def export_builtin_exceptions(self):
"""NOT_RPYTHON"""
w_dic = self.exceptions_module.getdict()
- names_w = self.unpackiterable(self.call_function(self.getattr(w_dic, self.wrap("keys"))))
-
- for w_name in names_w:
+ w_keys = self.call_method(w_dic, "keys")
+ exc_types_w = {}
+ for w_name in self.unpackiterable(w_keys):
name = self.str_w(w_name)
if not name.startswith('__'):
excname = name
w_exc = self.getitem(w_dic, w_name)
- setattr(self, "w_"+excname, w_exc)
+ exc_types_w[name] = w_exc
+ setattr(self, "w_" + excname, w_exc)
+ # Make a prebuilt recursion error
+ w_msg = self.wrap("maximum recursion depth exceeded")
+ self.prebuilt_recursion_error = OperationError(self.w_RuntimeError,
+ w_msg)
+ return exc_types_w
def install_mixedmodule(self, mixedname, installed_builtin_modules):
"""NOT_RPYTHON"""
@@ -1095,6 +1109,37 @@
self.wrap("expected a non-negative integer"))
return value
+ def c_int_w(self, w_obj):
+ # Like space.int_w(), but raises an app-level OverflowError if
+ # the integer does not fit in 32 bits. Mostly here for gateway.py.
+ value = self.int_w(w_obj)
+ if value < -2147483647-1 or value > 2147483647:
+ raise OperationError(self.w_OverflowError,
+ self.wrap("expected a 32-bit integer"))
+ return value
+
+ def c_uint_w(self, w_obj):
+ # Like space.uint_w(), but raises an app-level OverflowError if
+ # the integer does not fit in 32 bits. Mostly here for gateway.py.
+ value = self.uint_w(w_obj)
+ if value > UINT_MAX_32_BITS:
+ raise OperationError(self.w_OverflowError,
+ self.wrap("expected an unsigned 32-bit integer"))
+ return value
+
+ def c_nonnegint_w(self, w_obj):
+ # Like space.int_w(), but raises an app-level ValueError if
+ # the integer is negative or does not fit in 32 bits. Mostly here
+ # for gateway.py.
+ value = self.int_w(w_obj)
+ if value < 0:
+ raise OperationError(self.w_ValueError,
+ self.wrap("expected a non-negative integer"))
+ if value > 2147483647:
+ raise OperationError(self.w_OverflowError,
+ self.wrap("expected a 32-bit integer"))
+ return value
+
def warn(self, msg, w_warningcls):
self.appexec([self.wrap(msg), w_warningcls], """(msg, warningcls):
import warnings
Modified: pypy/branch/cpython-extension/pypy/interpreter/error.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/error.py (original)
+++ pypy/branch/cpython-extension/pypy/interpreter/error.py Wed Mar 31 00:17:06 2010
@@ -344,7 +344,7 @@
else:
_WINDOWS = True
- def wrap_windowserror(space, e):
+ def wrap_windowserror(space, e, filename=None):
from pypy.rlib import rwin32
winerror = e.winerror
@@ -353,16 +353,19 @@
except ValueError:
msg = 'Windows Error %d' % winerror
exc = space.w_WindowsError
- w_error = space.call_function(exc,
- space.wrap(winerror),
- space.wrap(msg))
+ if filename is not None:
+ w_error = space.call_function(exc, space.wrap(winerror),
+ space.wrap(msg), space.wrap(filename))
+ else:
+ w_error = space.call_function(exc, space.wrap(winerror),
+ space.wrap(msg))
return OperationError(exc, w_error)
-def wrap_oserror(space, e, exception_name='w_OSError'):
- assert isinstance(e, OSError)
+def wrap_oserror(space, e, filename=None, exception_name='w_OSError'):
+ assert isinstance(e, OSError)
if _WINDOWS and isinstance(e, WindowsError):
- return wrap_windowserror(space, e)
+ return wrap_windowserror(space, e, filename)
errno = e.errno
try:
@@ -370,8 +373,10 @@
except ValueError:
msg = 'error %d' % errno
exc = getattr(space, exception_name)
- w_error = space.call_function(exc,
- space.wrap(errno),
- space.wrap(msg))
+ if filename is not None:
+ w_error = space.call_function(exc, space.wrap(errno),
+ space.wrap(msg), space.wrap(filename))
+ else:
+ w_error = space.call_function(exc, space.wrap(errno), space.wrap(msg))
return OperationError(exc, w_error)
-wrap_oserror._annspecialcase_ = 'specialize:arg(2)'
+wrap_oserror._annspecialcase_ = 'specialize:arg(3)'
Modified: pypy/branch/cpython-extension/pypy/interpreter/executioncontext.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/executioncontext.py (original)
+++ pypy/branch/cpython-extension/pypy/interpreter/executioncontext.py Wed Mar 31 00:17:06 2010
@@ -478,12 +478,17 @@
def __init__(self, space):
AsyncAction.__init__(self, space)
self.dying_objects_w = []
+ self.weakrefs_w = []
self.finalizers_lock_count = 0
def register_dying_object(self, w_obj):
self.dying_objects_w.append(w_obj)
self.fire()
+ def register_weakref_callback(self, w_ref):
+ self.weakrefs_w.append(w_ref)
+ self.fire()
+
def perform(self, executioncontext, frame):
if self.finalizers_lock_count > 0:
return
@@ -505,8 +510,12 @@
# finally, this calls the interp-level destructor for the
# cases where there is both an app-level and a built-in __del__.
w_obj._call_builtin_destructor()
-
-
+ pending_w = self.weakrefs_w
+ self.weakrefs_w = []
+ for i in range(len(pending_w)):
+ w_ref = pending_w[i]
+ w_ref.activate_callback()
+
class FrameTraceAction(AsyncAction):
"""An action that calls the local trace functions (w_f_trace)."""
Modified: pypy/branch/cpython-extension/pypy/interpreter/gateway.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/gateway.py (original)
+++ pypy/branch/cpython-extension/pypy/interpreter/gateway.py Wed Mar 31 00:17:06 2010
@@ -22,6 +22,8 @@
from pypy.interpreter.argument import Arguments, Signature
from pypy.tool.sourcetools import NiceCompile, compile2
from pypy.rlib.rarithmetic import r_longlong, r_int, r_ulonglong, r_uint
+from pypy.rlib import rstackovf
+from pypy.rlib.objectmodel import we_are_translated
# internal non-translatable parts:
import py
@@ -126,6 +128,15 @@
def visit_nonnegint(self, el, app_sig):
self.checked_space_method(el, app_sig)
+ def visit_c_int(self, el, app_sig):
+ self.checked_space_method(el, app_sig)
+
+ def visit_c_uint(self, el, app_sig):
+ self.checked_space_method(el, app_sig)
+
+ def visit_c_nonnegint(self, el, app_sig):
+ self.checked_space_method(el, app_sig)
+
def visit__Wrappable(self, el, app_sig):
name = el.__name__
argname = self.orig_arg()
@@ -230,6 +241,15 @@
def visit_nonnegint(self, typ):
self.run_args.append("space.nonnegint_w(%s)" % (self.scopenext(),))
+ def visit_c_int(self, typ):
+ self.run_args.append("space.c_int_w(%s)" % (self.scopenext(),))
+
+ def visit_c_uint(self, typ):
+ self.run_args.append("space.c_uint_w(%s)" % (self.scopenext(),))
+
+ def visit_c_nonnegint(self, typ):
+ self.run_args.append("space.c_nonnegint_w(%s)" % (self.scopenext(),))
+
def _make_unwrap_activation_class(self, unwrap_spec, cache={}):
try:
key = tuple(unwrap_spec)
@@ -348,6 +368,15 @@
def visit_nonnegint(self, typ):
self.unwrap.append("space.nonnegint_w(%s)" % (self.nextarg(),))
+ def visit_c_int(self, typ):
+ self.unwrap.append("space.c_int_w(%s)" % (self.nextarg(),))
+
+ def visit_c_uint(self, typ):
+ self.unwrap.append("space.c_uint_w(%s)" % (self.nextarg(),))
+
+ def visit_c_nonnegint(self, typ):
+ self.unwrap.append("space.c_nonnegint_w(%s)" % (self.nextarg(),))
+
def make_fastfunc(unwrap_spec, func):
unwrap_info = UnwrapSpec_FastFunc_Unwrap()
unwrap_info.apply_over(unwrap_spec)
@@ -521,27 +550,33 @@
func.defs_w, self.minargs)
try:
w_result = activation._run(space, scope_w)
- except KeyboardInterrupt:
- raise OperationError(space.w_KeyboardInterrupt,
- space.w_None)
- except MemoryError:
- raise OperationError(space.w_MemoryError, space.w_None)
- except NotImplementedError, e:
- raise
- except RuntimeError, e:
- raise OperationError(space.w_RuntimeError,
- space.wrap("internal error: " + str(e)))
- except DescrMismatch, e:
+ except DescrMismatch:
if w_obj is not None:
args = args.prepend(w_obj)
return scope_w[0].descr_call_mismatch(space,
self.descrmismatch_op,
self.descr_reqcls,
args)
+ except Exception, e:
+ raise self.handle_exception(space, e)
if w_result is None:
w_result = space.w_None
return w_result
+ def handle_exception(self, space, e):
+ try:
+ if not we_are_translated():
+ raise
+ raise e
+ except KeyboardInterrupt:
+ raise OperationError(space.w_KeyboardInterrupt,
+ space.w_None)
+ except MemoryError:
+ raise OperationError(space.w_MemoryError, space.w_None)
+ except rstackovf.StackOverflow, e:
+ rstackovf.check_stack_overflow()
+ raise space.prebuilt_recursion_error
+
# (verbose) performance hack below
class BuiltinCodePassThroughArguments0(BuiltinCode):
@@ -551,20 +586,13 @@
space = func.space
try:
w_result = self.func__args__(space, args)
- except KeyboardInterrupt:
- raise OperationError(space.w_KeyboardInterrupt, space.w_None)
- except MemoryError:
- raise OperationError(space.w_MemoryError, space.w_None)
- except NotImplementedError, e:
- raise
- except RuntimeError, e:
- raise OperationError(space.w_RuntimeError,
- space.wrap("internal error: " + str(e)))
- except DescrMismatch, e:
+ except DescrMismatch:
return args.firstarg().descr_call_mismatch(space,
self.descrmismatch_op,
self.descr_reqcls,
args)
+ except Exception, e:
+ raise self.handle_exception(space, e)
if w_result is None:
w_result = space.w_None
return w_result
@@ -577,20 +605,13 @@
space = func.space
try:
w_result = self.func__args__(space, w_obj, args)
- except KeyboardInterrupt:
- raise OperationError(space.w_KeyboardInterrupt, space.w_None)
- except MemoryError:
- raise OperationError(space.w_MemoryError, space.w_None)
- except NotImplementedError, e:
- raise
- except RuntimeError, e:
- raise OperationError(space.w_RuntimeError,
- space.wrap("internal error: " + str(e)))
- except DescrMismatch, e:
+ except DescrMismatch:
return args.firstarg().descr_call_mismatch(space,
self.descrmismatch_op,
self.descr_reqcls,
args.prepend(w_obj))
+ except Exception, e:
+ raise self.handle_exception(space, e)
if w_result is None:
w_result = space.w_None
return w_result
@@ -602,15 +623,11 @@
def fastcall_0(self, space, w_func):
try:
w_result = self.fastfunc_0(space)
- except KeyboardInterrupt:
- raise OperationError(space.w_KeyboardInterrupt, space.w_None)
- except MemoryError:
- raise OperationError(space.w_MemoryError, space.w_None)
- except NotImplementedError, e:
- raise
- except (RuntimeError, DescrMismatch), e:
- raise OperationError(space.w_RuntimeError,
- space.wrap("internal error: " + str(e)))
+ except DescrMismatch:
+ raise OperationError(space.w_SystemError,
+ space.wrap("unexpected DescrMismatch error"))
+ except Exception, e:
+ raise self.handle_exception(space, e)
if w_result is None:
w_result = space.w_None
return w_result
@@ -622,20 +639,13 @@
def fastcall_1(self, space, w_func, w1):
try:
w_result = self.fastfunc_1(space, w1)
- except KeyboardInterrupt:
- raise OperationError(space.w_KeyboardInterrupt, space.w_None)
- except MemoryError:
- raise OperationError(space.w_MemoryError, space.w_None)
- except NotImplementedError, e:
- raise
- except RuntimeError, e:
- raise OperationError(space.w_RuntimeError,
- space.wrap("internal error: " + str(e)))
- except DescrMismatch, e:
+ except DescrMismatch:
return w1.descr_call_mismatch(space,
self.descrmismatch_op,
self.descr_reqcls,
Arguments(space, [w1]))
+ except Exception, e:
+ raise self.handle_exception(space, e)
if w_result is None:
w_result = space.w_None
return w_result
@@ -647,20 +657,13 @@
def fastcall_2(self, space, w_func, w1, w2):
try:
w_result = self.fastfunc_2(space, w1, w2)
- except KeyboardInterrupt:
- raise OperationError(space.w_KeyboardInterrupt, space.w_None)
- except MemoryError:
- raise OperationError(space.w_MemoryError, space.w_None)
- except NotImplementedError, e:
- raise
- except RuntimeError, e:
- raise OperationError(space.w_RuntimeError,
- space.wrap("internal error: " + str(e)))
- except DescrMismatch, e:
+ except DescrMismatch:
return w1.descr_call_mismatch(space,
self.descrmismatch_op,
self.descr_reqcls,
Arguments(space, [w1, w2]))
+ except Exception, e:
+ raise self.handle_exception(space, e)
if w_result is None:
w_result = space.w_None
return w_result
@@ -672,20 +675,13 @@
def fastcall_3(self, space, func, w1, w2, w3):
try:
w_result = self.fastfunc_3(space, w1, w2, w3)
- except KeyboardInterrupt:
- raise OperationError(space.w_KeyboardInterrupt, space.w_None)
- except MemoryError:
- raise OperationError(space.w_MemoryError, space.w_None)
- except NotImplementedError, e:
- raise
- except RuntimeError, e:
- raise OperationError(space.w_RuntimeError,
- space.wrap("internal error: " + str(e)))
- except DescrMismatch, e:
+ except DescrMismatch:
return w1.descr_call_mismatch(space,
self.descrmismatch_op,
self.descr_reqcls,
Arguments(space, [w1, w2, w3]))
+ except Exception, e:
+ raise self.handle_exception(space, e)
if w_result is None:
w_result = space.w_None
return w_result
@@ -697,21 +693,14 @@
def fastcall_4(self, space, func, w1, w2, w3, w4):
try:
w_result = self.fastfunc_4(space, w1, w2, w3, w4)
- except KeyboardInterrupt:
- raise OperationError(space.w_KeyboardInterrupt, space.w_None)
- except MemoryError:
- raise OperationError(space.w_MemoryError, space.w_None)
- except NotImplementedError, e:
- raise
- except RuntimeError, e:
- raise OperationError(space.w_RuntimeError,
- space.wrap("internal error: " + str(e)))
- except DescrMismatch, e:
+ except DescrMismatch:
return w1.descr_call_mismatch(space,
self.descrmismatch_op,
self.descr_reqcls,
Arguments(space,
[w1, w2, w3, w4]))
+ except Exception, e:
+ raise self.handle_exception(space, e)
if w_result is None:
w_result = space.w_None
return w_result
Modified: pypy/branch/cpython-extension/pypy/interpreter/nestedscope.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/nestedscope.py (original)
+++ pypy/branch/cpython-extension/pypy/interpreter/nestedscope.py Wed Mar 31 00:17:06 2010
@@ -169,51 +169,51 @@
### extra opcodes ###
- def LOAD_CLOSURE(f, varindex, *ignored):
+ def LOAD_CLOSURE(self, varindex, next_instr):
# nested scopes: access the cell object
- cell = f.cells[varindex]
- w_value = f.space.wrap(cell)
- f.pushvalue(w_value)
+ cell = self.cells[varindex]
+ w_value = self.space.wrap(cell)
+ self.pushvalue(w_value)
- def LOAD_DEREF(f, varindex, *ignored):
+ def LOAD_DEREF(self, varindex, next_instr):
# nested scopes: access a variable through its cell object
- cell = f.cells[varindex]
+ cell = self.cells[varindex]
try:
w_value = cell.get()
except ValueError:
- varname = f.getfreevarname(varindex)
- if f.iscellvar(varindex):
+ varname = self.getfreevarname(varindex)
+ if self.iscellvar(varindex):
message = "local variable '%s' referenced before assignment"%varname
- w_exc_type = f.space.w_UnboundLocalError
+ w_exc_type = self.space.w_UnboundLocalError
else:
message = ("free variable '%s' referenced before assignment"
" in enclosing scope"%varname)
- w_exc_type = f.space.w_NameError
- raise OperationError(w_exc_type, f.space.wrap(message))
+ w_exc_type = self.space.w_NameError
+ raise OperationError(w_exc_type, self.space.wrap(message))
else:
- f.pushvalue(w_value)
+ self.pushvalue(w_value)
- def STORE_DEREF(f, varindex, *ignored):
+ def STORE_DEREF(self, varindex, next_instr):
# nested scopes: access a variable through its cell object
- w_newvalue = f.popvalue()
- cell = f.cells[varindex]
+ w_newvalue = self.popvalue()
+ cell = self.cells[varindex]
cell.set(w_newvalue)
@jit.unroll_safe
- def MAKE_CLOSURE(f, numdefaults, *ignored):
- w_codeobj = f.popvalue()
- codeobj = f.space.interp_w(pycode.PyCode, w_codeobj)
+ def MAKE_CLOSURE(self, numdefaults, next_instr):
+ w_codeobj = self.popvalue()
+ codeobj = self.space.interp_w(pycode.PyCode, w_codeobj)
if codeobj.magic >= 0xa0df281: # CPython 2.5 AST branch merge
- w_freevarstuple = f.popvalue()
- freevars = [f.space.interp_w(Cell, cell)
- for cell in f.space.fixedview(w_freevarstuple)]
+ w_freevarstuple = self.popvalue()
+ freevars = [self.space.interp_w(Cell, cell)
+ for cell in self.space.fixedview(w_freevarstuple)]
else:
nfreevars = len(codeobj.co_freevars)
- freevars = [f.space.interp_w(Cell, f.popvalue())
+ freevars = [self.space.interp_w(Cell, self.popvalue())
for i in range(nfreevars)]
freevars.reverse()
- defaultarguments = [f.popvalue() for i in range(numdefaults)]
+ defaultarguments = [self.popvalue() for i in range(numdefaults)]
defaultarguments.reverse()
- fn = function.Function(f.space, codeobj, f.w_globals,
+ fn = function.Function(self.space, codeobj, self.w_globals,
defaultarguments, freevars)
- f.pushvalue(f.space.wrap(fn))
+ self.pushvalue(self.space.wrap(fn))
Modified: pypy/branch/cpython-extension/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/pyframe.py (original)
+++ pypy/branch/cpython-extension/pypy/interpreter/pyframe.py Wed Mar 31 00:17:06 2010
@@ -64,6 +64,8 @@
self.fastlocals_w = [None]*self.numlocals
make_sure_not_resized(self.fastlocals_w)
self.f_lineno = code.co_firstlineno
+ # Keep from having to call space.wrap in a RuntimeError
+ self._recursion_error = space.wrap("maximum recursion depth exceeded")
def append_block(self, block):
block.previous = self.lastblock
Modified: pypy/branch/cpython-extension/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/pyopcode.py (original)
+++ pypy/branch/cpython-extension/pypy/interpreter/pyopcode.py Wed Mar 31 00:17:06 2010
@@ -18,26 +18,27 @@
from pypy.tool.stdlib_opcode import unrolling_opcode_descs
from pypy.tool.stdlib_opcode import opcode_method_names
from pypy.rlib.unroll import unrolling_iterable
+from pypy.rlib import rstackovf
def unaryoperation(operationname):
"""NOT_RPYTHON"""
- def opimpl(f, *ignored):
- operation = getattr(f.space, operationname)
- w_1 = f.popvalue()
+ def opimpl(self, *ignored):
+ operation = getattr(self.space, operationname)
+ w_1 = self.popvalue()
w_result = operation(w_1)
- f.pushvalue(w_result)
+ self.pushvalue(w_result)
opimpl.unaryop = operationname
return func_with_new_name(opimpl, "opcode_impl_for_%s" % operationname)
def binaryoperation(operationname):
- """NOT_RPYTHON"""
- def opimpl(f, *ignored):
- operation = getattr(f.space, operationname)
- w_2 = f.popvalue()
- w_1 = f.popvalue()
+ """NOT_RPYTHON"""
+ def opimpl(self, *ignored):
+ operation = getattr(self.space, operationname)
+ w_2 = self.popvalue()
+ w_1 = self.popvalue()
w_result = operation(w_1, w_2)
- f.pushvalue(w_result)
+ self.pushvalue(w_result)
opimpl.binop = operationname
return func_with_new_name(opimpl, "opcode_impl_for_%s" % operationname)
@@ -63,10 +64,10 @@
class __extend__(pyframe.PyFrame):
"""A PyFrame that knows about interpretation of standard Python opcodes
minus the ones related to nested scopes."""
-
+
# for logbytecode:
last_opcode = -1
-
+
### opcode dispatch ###
def dispatch(self, pycode, next_instr, ec):
@@ -106,20 +107,12 @@
except MemoryError:
next_instr = self.handle_asynchronous_error(ec,
self.space.w_MemoryError)
- except NotImplementedError:
- raise
- except RuntimeError, e:
- if we_are_translated():
- # stack overflows should be the only kind of RuntimeErrors
- # in translated PyPy
- msg = "internal error (stack overflow?)"
- else:
- msg = str(e)
- next_instr = self.handle_asynchronous_error(ec,
- self.space.w_RuntimeError,
- self.space.wrap(msg))
+ except rstackovf.StackOverflow, e:
+ rstackovf.check_stack_overflow()
+ w_err = self.space.prebuilt_recursion_error
+ next_instr = self.handle_operation_error(ec, w_err)
return next_instr
-
+
def handle_asynchronous_error(self, ec, w_type, w_value=None):
# catch asynchronous exceptions and turn them
# into OperationErrors
@@ -235,7 +228,7 @@
return next_instr
if opcode == opcodedesc.JUMP_ABSOLUTE.index:
- return self.JUMP_ABSOLUTE(oparg, next_instr, ec)
+ return self.jump_absolute(oparg, next_instr, ec)
if we_are_translated():
from pypy.rlib import rstack # for resume points
@@ -245,7 +238,7 @@
if not opdesc.is_enabled(space):
continue
if not hasattr(pyframe.PyFrame, opdesc.methodname):
- continue # e.g. for JUMP_FORWARD, implemented above
+ continue # e.g. for JUMP_ABSOLUTE, implemented above
if opcode == opdesc.index:
# dispatch to the opcode method
@@ -307,78 +300,66 @@
## See also nestedscope.py for the rest.
##
- # the 'self' argument of opcode implementations is called 'f'
- # for historical reasons
-
- def NOP(f, *ignored):
+ def NOP(self, oparg, next_instr):
pass
- def LOAD_FAST(f, varindex, *ignored):
+ def LOAD_FAST(self, varindex, next_instr):
# access a local variable directly
- w_value = f.fastlocals_w[varindex]
+ w_value = self.fastlocals_w[varindex]
if w_value is None:
- f._load_fast_failed(varindex)
- f.pushvalue(w_value)
+ self._load_fast_failed(varindex)
+ self.pushvalue(w_value)
LOAD_FAST._always_inline_ = True
- def _load_fast_failed(f, varindex):
- varname = f.getlocalvarname(varindex)
+ def _load_fast_failed(self, varindex):
+ varname = self.getlocalvarname(varindex)
message = "local variable '%s' referenced before assignment"
- raise operationerrfmt(f.space.w_UnboundLocalError, message, varname)
+ raise operationerrfmt(self.space.w_UnboundLocalError, message, varname)
_load_fast_failed._dont_inline_ = True
- def LOAD_CONST(f, constindex, *ignored):
- w_const = f.getconstant_w(constindex)
- f.pushvalue(w_const)
+ def LOAD_CONST(self, constindex, next_instr):
+ w_const = self.getconstant_w(constindex)
+ self.pushvalue(w_const)
- def STORE_FAST(f, varindex, *ignored):
- w_newvalue = f.popvalue()
+ def STORE_FAST(self, varindex, next_instr):
+ w_newvalue = self.popvalue()
assert w_newvalue is not None
- f.fastlocals_w[varindex] = w_newvalue
- #except:
- # print "exception: got index error"
- # print " varindex:", varindex
- # print " len(locals_w)", len(f.locals_w)
- # import dis
- # print dis.dis(f.pycode)
- # print "co_varnames", f.pycode.co_varnames
- # print "co_nlocals", f.pycode.co_nlocals
- # raise
-
- def POP_TOP(f, *ignored):
- f.popvalue()
-
- def ROT_TWO(f, *ignored):
- w_1 = f.popvalue()
- w_2 = f.popvalue()
- f.pushvalue(w_1)
- f.pushvalue(w_2)
-
- def ROT_THREE(f, *ignored):
- w_1 = f.popvalue()
- w_2 = f.popvalue()
- w_3 = f.popvalue()
- f.pushvalue(w_1)
- f.pushvalue(w_3)
- f.pushvalue(w_2)
-
- def ROT_FOUR(f, *ignored):
- w_1 = f.popvalue()
- w_2 = f.popvalue()
- w_3 = f.popvalue()
- w_4 = f.popvalue()
- f.pushvalue(w_1)
- f.pushvalue(w_4)
- f.pushvalue(w_3)
- f.pushvalue(w_2)
-
- def DUP_TOP(f, *ignored):
- w_1 = f.peekvalue()
- f.pushvalue(w_1)
+ self.fastlocals_w[varindex] = w_newvalue
+
+ def POP_TOP(self, oparg, next_instr):
+ self.popvalue()
+
+ def ROT_TWO(self, oparg, next_instr):
+ w_1 = self.popvalue()
+ w_2 = self.popvalue()
+ self.pushvalue(w_1)
+ self.pushvalue(w_2)
+
+ def ROT_THREE(self, oparg, next_instr):
+ w_1 = self.popvalue()
+ w_2 = self.popvalue()
+ w_3 = self.popvalue()
+ self.pushvalue(w_1)
+ self.pushvalue(w_3)
+ self.pushvalue(w_2)
+
+ def ROT_FOUR(self, oparg, next_instr):
+ w_1 = self.popvalue()
+ w_2 = self.popvalue()
+ w_3 = self.popvalue()
+ w_4 = self.popvalue()
+ self.pushvalue(w_1)
+ self.pushvalue(w_4)
+ self.pushvalue(w_3)
+ self.pushvalue(w_2)
+
+ def DUP_TOP(self, oparg, next_instr):
+ w_1 = self.peekvalue()
+ self.pushvalue(w_1)
- def DUP_TOPX(f, itemcount, *ignored):
+ def DUP_TOPX(self, itemcount, next_instr):
assert 1 <= itemcount <= 5, "limitation of the current interpreter"
- f.dupvalues(itemcount)
+ self.dupvalues(itemcount)
UNARY_POSITIVE = unaryoperation("pos")
UNARY_NEGATIVE = unaryoperation("neg")
@@ -386,11 +367,11 @@
UNARY_CONVERT = unaryoperation("repr")
UNARY_INVERT = unaryoperation("invert")
- def BINARY_POWER(f, *ignored):
- w_2 = f.popvalue()
- w_1 = f.popvalue()
- w_result = f.space.pow(w_1, w_2, f.space.w_None)
- f.pushvalue(w_result)
+ def BINARY_POWER(self, oparg, next_instr):
+ w_2 = self.popvalue()
+ w_1 = self.popvalue()
+ w_result = self.space.pow(w_1, w_2, self.space.w_None)
+ self.pushvalue(w_result)
BINARY_MULTIPLY = binaryoperation("mul")
BINARY_TRUE_DIVIDE = binaryoperation("truediv")
@@ -407,11 +388,11 @@
BINARY_XOR = binaryoperation("xor")
BINARY_OR = binaryoperation("or_")
- def INPLACE_POWER(f, *ignored):
- w_2 = f.popvalue()
- w_1 = f.popvalue()
- w_result = f.space.inplace_pow(w_1, w_2)
- f.pushvalue(w_result)
+ def INPLACE_POWER(self, oparg, next_instr):
+ w_2 = self.popvalue()
+ w_1 = self.popvalue()
+ w_result = self.space.inplace_pow(w_1, w_2)
+ self.pushvalue(w_result)
INPLACE_MULTIPLY = binaryoperation("inplace_mul")
INPLACE_TRUE_DIVIDE = binaryoperation("inplace_truediv")
@@ -427,129 +408,130 @@
INPLACE_XOR = binaryoperation("inplace_xor")
INPLACE_OR = binaryoperation("inplace_or")
- def slice(f, w_start, w_end):
- w_obj = f.popvalue()
- w_result = f.space.getslice(w_obj, w_start, w_end)
- f.pushvalue(w_result)
-
- def SLICE_0(f, *ignored):
- f.slice(f.space.w_None, f.space.w_None)
-
- def SLICE_1(f, *ignored):
- w_start = f.popvalue()
- f.slice(w_start, f.space.w_None)
-
- def SLICE_2(f, *ignored):
- w_end = f.popvalue()
- f.slice(f.space.w_None, w_end)
-
- def SLICE_3(f, *ignored):
- w_end = f.popvalue()
- w_start = f.popvalue()
- f.slice(w_start, w_end)
-
- def storeslice(f, w_start, w_end):
- w_obj = f.popvalue()
- w_newvalue = f.popvalue()
- f.space.setslice(w_obj, w_start, w_end, w_newvalue)
-
- def STORE_SLICE_0(f, *ignored):
- f.storeslice(f.space.w_None, f.space.w_None)
-
- def STORE_SLICE_1(f, *ignored):
- w_start = f.popvalue()
- f.storeslice(w_start, f.space.w_None)
-
- def STORE_SLICE_2(f, *ignored):
- w_end = f.popvalue()
- f.storeslice(f.space.w_None, w_end)
-
- def STORE_SLICE_3(f, *ignored):
- w_end = f.popvalue()
- w_start = f.popvalue()
- f.storeslice(w_start, w_end)
-
- def deleteslice(f, w_start, w_end):
- w_obj = f.popvalue()
- f.space.delslice(w_obj, w_start, w_end)
-
- def DELETE_SLICE_0(f, *ignored):
- f.deleteslice(f.space.w_None, f.space.w_None)
-
- def DELETE_SLICE_1(f, *ignored):
- w_start = f.popvalue()
- f.deleteslice(w_start, f.space.w_None)
-
- def DELETE_SLICE_2(f, *ignored):
- w_end = f.popvalue()
- f.deleteslice(f.space.w_None, w_end)
-
- def DELETE_SLICE_3(f, *ignored):
- w_end = f.popvalue()
- w_start = f.popvalue()
- f.deleteslice(w_start, w_end)
+ def slice(self, w_start, w_end):
+ w_obj = self.popvalue()
+ w_result = self.space.getslice(w_obj, w_start, w_end)
+ self.pushvalue(w_result)
+
+ def SLICE_0(self, oparg, next_instr):
+ self.slice(self.space.w_None, self.space.w_None)
+
+ def SLICE_1(self, oparg, next_instr):
+ w_start = self.popvalue()
+ self.slice(w_start, self.space.w_None)
+
+ def SLICE_2(self, oparg, next_instr):
+ w_end = self.popvalue()
+ self.slice(self.space.w_None, w_end)
+
+ def SLICE_3(self, oparg, next_instr):
+ w_end = self.popvalue()
+ w_start = self.popvalue()
+ self.slice(w_start, w_end)
+
+ def storeslice(self, w_start, w_end):
+ w_obj = self.popvalue()
+ w_newvalue = self.popvalue()
+ self.space.setslice(w_obj, w_start, w_end, w_newvalue)
+
+ def STORE_SLICE_0(self, oparg, next_instr):
+ self.storeslice(self.space.w_None, self.space.w_None)
+
+ def STORE_SLICE_1(self, oparg, next_instr):
+ w_start = self.popvalue()
+ self.storeslice(w_start, self.space.w_None)
+
+ def STORE_SLICE_2(self, oparg, next_instr):
+ w_end = self.popvalue()
+ self.storeslice(self.space.w_None, w_end)
+
+ def STORE_SLICE_3(self, oparg, next_instr):
+ w_end = self.popvalue()
+ w_start = self.popvalue()
+ self.storeslice(w_start, w_end)
+
+ def deleteslice(self, w_start, w_end):
+ w_obj = self.popvalue()
+ self.space.delslice(w_obj, w_start, w_end)
+
+ def DELETE_SLICE_0(self, oparg, next_instr):
+ self.deleteslice(self.space.w_None, self.space.w_None)
+
+ def DELETE_SLICE_1(self, oparg, next_instr):
+ w_start = self.popvalue()
+ self.deleteslice(w_start, self.space.w_None)
+
+ def DELETE_SLICE_2(self, oparg, next_instr):
+ w_end = self.popvalue()
+ self.deleteslice(self.space.w_None, w_end)
+
+ def DELETE_SLICE_3(self, oparg, next_instr):
+ w_end = self.popvalue()
+ w_start = self.popvalue()
+ self.deleteslice(w_start, w_end)
- def STORE_SUBSCR(f, *ignored):
+ def STORE_SUBSCR(self, oparg, next_instr):
"obj[subscr] = newvalue"
- w_subscr = f.popvalue()
- w_obj = f.popvalue()
- w_newvalue = f.popvalue()
- f.space.setitem(w_obj, w_subscr, w_newvalue)
+ w_subscr = self.popvalue()
+ w_obj = self.popvalue()
+ w_newvalue = self.popvalue()
+ self.space.setitem(w_obj, w_subscr, w_newvalue)
- def DELETE_SUBSCR(f, *ignored):
+ def DELETE_SUBSCR(self, oparg, next_instr):
"del obj[subscr]"
- w_subscr = f.popvalue()
- w_obj = f.popvalue()
- f.space.delitem(w_obj, w_subscr)
-
- def PRINT_EXPR(f, *ignored):
- w_expr = f.popvalue()
- print_expr(f.space, w_expr)
-
- def PRINT_ITEM_TO(f, *ignored):
- w_stream = f.popvalue()
- w_item = f.popvalue()
- if f.space.is_w(w_stream, f.space.w_None):
- w_stream = sys_stdout(f.space) # grumble grumble special cases
- print_item_to(f.space, w_item, w_stream)
-
- def PRINT_ITEM(f, *ignored):
- w_item = f.popvalue()
- print_item(f.space, w_item)
-
- def PRINT_NEWLINE_TO(f, *ignored):
- w_stream = f.popvalue()
- if f.space.is_w(w_stream, f.space.w_None):
- w_stream = sys_stdout(f.space) # grumble grumble special cases
- print_newline_to(f.space, w_stream)
+ w_subscr = self.popvalue()
+ w_obj = self.popvalue()
+ self.space.delitem(w_obj, w_subscr)
+
+ def PRINT_EXPR(self, oparg, next_instr):
+ w_expr = self.popvalue()
+ print_expr(self.space, w_expr)
+
+ def PRINT_ITEM_TO(self, oparg, next_instr):
+ w_stream = self.popvalue()
+ w_item = self.popvalue()
+ if self.space.is_w(w_stream, self.space.w_None):
+ w_stream = sys_stdout(self.space) # grumble grumble special cases
+ print_item_to(self.space, w_item, w_stream)
+
+ def PRINT_ITEM(self, oparg, next_instr):
+ w_item = self.popvalue()
+ print_item(self.space, w_item)
+
+ def PRINT_NEWLINE_TO(self, oparg, next_instr):
+ w_stream = self.popvalue()
+ if self.space.is_w(w_stream, self.space.w_None):
+ w_stream = sys_stdout(self.space) # grumble grumble special cases
+ print_newline_to(self.space, w_stream)
- def PRINT_NEWLINE(f, *ignored):
- print_newline(f.space)
+ def PRINT_NEWLINE(self, oparg, next_instr):
+ print_newline(self.space)
- def BREAK_LOOP(f, *ignored):
- next_instr = f.unrollstack_and_jump(SBreakLoop.singleton)
- return next_instr
+ def BREAK_LOOP(self, oparg, next_instr):
+ return self.unrollstack_and_jump(SBreakLoop.singleton)
- def CONTINUE_LOOP(f, startofloop, *ignored):
+ def CONTINUE_LOOP(self, startofloop, next_instr):
unroller = SContinueLoop(startofloop)
- next_instr = f.unrollstack_and_jump(unroller)
- return next_instr
+ return self.unrollstack_and_jump(unroller)
- def RAISE_VARARGS(f, nbargs, *ignored):
- space = f.space
+ def RAISE_VARARGS(self, nbargs, next_instr):
+ space = self.space
if nbargs == 0:
operror = space.getexecutioncontext().sys_exc_info()
if operror is None:
raise OperationError(space.w_TypeError,
space.wrap("raise: no active exception to re-raise"))
# re-raise, no new traceback obj will be attached
- f.last_exception = operror
+ self.last_exception = operror
raise Reraise
w_value = w_traceback = space.w_None
- if nbargs >= 3: w_traceback = f.popvalue()
- if nbargs >= 2: w_value = f.popvalue()
- if 1: w_type = f.popvalue()
+ if nbargs >= 3:
+ w_traceback = self.popvalue()
+ if nbargs >= 2:
+ w_value = self.popvalue()
+ if 1:
+ w_type = self.popvalue()
operror = OperationError(w_type, w_value)
operror.normalize_exception(space)
if not space.full_exceptions or space.is_w(w_traceback, space.w_None):
@@ -563,151 +545,154 @@
# special 3-arguments raise, no new traceback obj will be attached
raise RaiseWithExplicitTraceback(operror)
- def LOAD_LOCALS(f, *ignored):
- f.pushvalue(f.w_locals)
+ def LOAD_LOCALS(self, oparg, next_instr):
+ self.pushvalue(self.w_locals)
- def EXEC_STMT(f, *ignored):
- w_locals = f.popvalue()
- w_globals = f.popvalue()
- w_prog = f.popvalue()
- flags = f.space.getexecutioncontext().compiler.getcodeflags(f.pycode)
- w_compile_flags = f.space.wrap(flags)
- w_resulttuple = prepare_exec(f.space, f.space.wrap(f), w_prog,
+ def EXEC_STMT(self, oparg, next_instr):
+ w_locals = self.popvalue()
+ w_globals = self.popvalue()
+ w_prog = self.popvalue()
+ ec = self.space.getexecutioncontext()
+ flags = ec.compiler.getcodeflags(self.pycode)
+ w_compile_flags = self.space.wrap(flags)
+ w_resulttuple = prepare_exec(self.space, self.space.wrap(self), w_prog,
w_globals, w_locals,
w_compile_flags,
- f.space.wrap(f.get_builtin()),
- f.space.gettypeobject(PyCode.typedef))
- w_prog, w_globals, w_locals = f.space.fixedview(w_resulttuple, 3)
+ self.space.wrap(self.get_builtin()),
+ self.space.gettypeobject(PyCode.typedef))
+ w_prog, w_globals, w_locals = self.space.fixedview(w_resulttuple, 3)
- plain = f.w_locals is not None and f.space.is_w(w_locals, f.w_locals)
+ plain = (self.w_locals is not None and
+ self.space.is_w(w_locals, self.w_locals))
if plain:
- w_locals = f.getdictscope()
- co = f.space.interp_w(eval.Code, w_prog)
- co.exec_code(f.space, w_globals, w_locals)
+ w_locals = self.getdictscope()
+ co = self.space.interp_w(eval.Code, w_prog)
+ co.exec_code(self.space, w_globals, w_locals)
if plain:
- f.setdictscope(w_locals)
+ self.setdictscope(w_locals)
- def POP_BLOCK(f, *ignored):
- block = f.pop_block()
- block.cleanup(f) # the block knows how to clean up the value stack
+ def POP_BLOCK(self, oparg, next_instr):
+ block = self.pop_block()
+ block.cleanup(self) # the block knows how to clean up the value stack
- def end_finally(f):
+ def end_finally(self):
# unlike CPython, when we reach this opcode the value stack has
# always been set up as follows (topmost first):
# [exception type or None]
# [exception value or None]
# [wrapped stack unroller ]
- f.popvalue() # ignore the exception type
- f.popvalue() # ignore the exception value
- w_unroller = f.popvalue()
- unroller = f.space.interpclass_w(w_unroller)
+ self.popvalue() # ignore the exception type
+ self.popvalue() # ignore the exception value
+ w_unroller = self.popvalue()
+ unroller = self.space.interpclass_w(w_unroller)
return unroller
- def BUILD_CLASS(f, *ignored):
- w_methodsdict = f.popvalue()
- w_bases = f.popvalue()
- w_name = f.popvalue()
- w_metaclass = find_metaclass(f.space, w_bases,
- w_methodsdict, f.w_globals,
- f.space.wrap(f.get_builtin()))
- w_newclass = f.space.call_function(w_metaclass, w_name,
- w_bases, w_methodsdict)
- f.pushvalue(w_newclass)
-
- def STORE_NAME(f, varindex, *ignored):
- varname = f.getname_u(varindex)
- w_newvalue = f.popvalue()
- f.space.set_str_keyed_item(f.w_locals, varname, w_newvalue)
+ def BUILD_CLASS(self, oparg, next_instr):
+ w_methodsdict = self.popvalue()
+ w_bases = self.popvalue()
+ w_name = self.popvalue()
+ w_metaclass = find_metaclass(self.space, w_bases,
+ w_methodsdict, self.w_globals,
+ self.space.wrap(self.get_builtin()))
+ w_newclass = self.space.call_function(w_metaclass, w_name,
+ w_bases, w_methodsdict)
+ self.pushvalue(w_newclass)
+
+ def STORE_NAME(self, varindex, next_instr):
+ varname = self.getname_u(varindex)
+ w_newvalue = self.popvalue()
+ self.space.set_str_keyed_item(self.w_locals, varname, w_newvalue)
- def DELETE_NAME(f, varindex, *ignored):
- w_varname = f.getname_w(varindex)
+ def DELETE_NAME(self, varindex, next_instr):
+ w_varname = self.getname_w(varindex)
try:
- f.space.delitem(f.w_locals, w_varname)
+ self.space.delitem(self.w_locals, w_varname)
except OperationError, e:
# catch KeyErrors and turn them into NameErrors
- if not e.match(f.space, f.space.w_KeyError):
+ if not e.match(self.space, self.space.w_KeyError):
raise
message = "name '%s' is not defined"
- raise operationerrfmt(f.space.w_NameError, message,
- f.space.str_w(w_varname))
+ raise operationerrfmt(self.space.w_NameError, message,
+ self.space.str_w(w_varname))
- def UNPACK_SEQUENCE(f, itemcount, *ignored):
- w_iterable = f.popvalue()
+ def UNPACK_SEQUENCE(self, itemcount, next_instr):
+ w_iterable = self.popvalue()
try:
- items = f.space.fixedview(w_iterable, itemcount)
+ items = self.space.fixedview(w_iterable, itemcount)
except UnpackValueError, e:
- raise OperationError(f.space.w_ValueError, f.space.wrap(e.msg))
- f.pushrevvalues(itemcount, items)
+ w_msg = self.space.wrap(e.msg)
+ raise OperationError(self.space.w_ValueError, w_msg)
+ self.pushrevvalues(itemcount, items)
- def STORE_ATTR(f, nameindex, *ignored):
+ def STORE_ATTR(self, nameindex, next_instr):
"obj.attributename = newvalue"
- w_attributename = f.getname_w(nameindex)
- w_obj = f.popvalue()
- w_newvalue = f.popvalue()
- f.space.setattr(w_obj, w_attributename, w_newvalue)
+ w_attributename = self.getname_w(nameindex)
+ w_obj = self.popvalue()
+ w_newvalue = self.popvalue()
+ self.space.setattr(w_obj, w_attributename, w_newvalue)
- def DELETE_ATTR(f, nameindex, *ignored):
+ def DELETE_ATTR(self, nameindex, next_instr):
"del obj.attributename"
- w_attributename = f.getname_w(nameindex)
- w_obj = f.popvalue()
- f.space.delattr(w_obj, w_attributename)
-
- def STORE_GLOBAL(f, nameindex, *ignored):
- varname = f.getname_u(nameindex)
- w_newvalue = f.popvalue()
- f.space.set_str_keyed_item(f.w_globals, varname, w_newvalue)
-
- def DELETE_GLOBAL(f, nameindex, *ignored):
- w_varname = f.getname_w(nameindex)
- f.space.delitem(f.w_globals, w_varname)
-
- def LOAD_NAME(f, nameindex, *ignored):
- if f.w_locals is not f.w_globals:
- w_varname = f.getname_w(nameindex)
- w_value = f.space.finditem(f.w_locals, w_varname)
+ w_attributename = self.getname_w(nameindex)
+ w_obj = self.popvalue()
+ self.space.delattr(w_obj, w_attributename)
+
+ def STORE_GLOBAL(self, nameindex, next_instr):
+ varname = self.getname_u(nameindex)
+ w_newvalue = self.popvalue()
+ self.space.set_str_keyed_item(self.w_globals, varname, w_newvalue)
+
+ def DELETE_GLOBAL(self, nameindex, next_instr):
+ w_varname = self.getname_w(nameindex)
+ self.space.delitem(self.w_globals, w_varname)
+
+ def LOAD_NAME(self, nameindex, next_instr):
+ if self.w_locals is not self.w_globals:
+ w_varname = self.getname_w(nameindex)
+ w_value = self.space.finditem(self.w_locals, w_varname)
if w_value is not None:
- f.pushvalue(w_value)
+ self.pushvalue(w_value)
return
- f.LOAD_GLOBAL(nameindex) # fall-back
+ self.LOAD_GLOBAL(nameindex, next_instr) # fall-back
- def _load_global(f, varname):
- w_value = f.space.finditem_str(f.w_globals, varname)
+ def _load_global(self, varname):
+ w_value = self.space.finditem_str(self.w_globals, varname)
if w_value is None:
# not in the globals, now look in the built-ins
- w_value = f.get_builtin().getdictvalue(f.space, varname)
+ w_value = self.get_builtin().getdictvalue(self.space, varname)
if w_value is None:
- f._load_global_failed(varname)
+ self._load_global_failed(varname)
return w_value
_load_global._always_inline_ = True
- def _load_global_failed(f, varname):
+ def _load_global_failed(self, varname):
message = "global name '%s' is not defined"
- raise operationerrfmt(f.space.w_NameError, message, varname)
+ raise operationerrfmt(self.space.w_NameError, message, varname)
_load_global_failed._dont_inline_ = True
- def LOAD_GLOBAL(f, nameindex, *ignored):
- f.pushvalue(f._load_global(f.getname_u(nameindex)))
+ def LOAD_GLOBAL(self, nameindex, next_instr):
+ self.pushvalue(self._load_global(self.getname_u(nameindex)))
LOAD_GLOBAL._always_inline_ = True
- def DELETE_FAST(f, varindex, *ignored):
- if f.fastlocals_w[varindex] is None:
- varname = f.getlocalvarname(varindex)
+ def DELETE_FAST(self, varindex, next_instr):
+ if self.fastlocals_w[varindex] is None:
+ varname = self.getlocalvarname(varindex)
message = "local variable '%s' referenced before assignment"
- raise operationerrfmt(f.space.w_UnboundLocalError, message, varname)
- f.fastlocals_w[varindex] = None
-
-
- def BUILD_TUPLE(f, itemcount, *ignored):
- items = f.popvalues(itemcount)
- w_tuple = f.space.newtuple(items)
- f.pushvalue(w_tuple)
-
- def BUILD_LIST(f, itemcount, *ignored):
- items = f.popvalues_mutable(itemcount)
- w_list = f.space.newlist(items)
- f.pushvalue(w_list)
+ raise operationerrfmt(self.space.w_UnboundLocalError, message,
+ varname)
+ self.fastlocals_w[varindex] = None
+
+ def BUILD_TUPLE(self, itemcount, next_instr):
+ items = self.popvalues(itemcount)
+ w_tuple = self.space.newtuple(items)
+ self.pushvalue(w_tuple)
+
+ def BUILD_LIST(self, itemcount, next_instr):
+ items = self.popvalues_mutable(itemcount)
+ w_list = self.space.newlist(items)
+ self.pushvalue(w_list)
- def BUILD_MAP(f, itemcount, *ignored):
+ def BUILD_MAP(self, itemcount, next_instr):
if not we_are_translated() and sys.version_info >= (2, 6):
# We could pre-allocate a dict here
# but for the moment this code is not translated.
@@ -715,77 +700,92 @@
else:
if itemcount != 0:
raise BytecodeCorruption
- w_dict = f.space.newdict()
- f.pushvalue(w_dict)
+ w_dict = self.space.newdict()
+ self.pushvalue(w_dict)
- def STORE_MAP(f, zero, *ignored):
+ def STORE_MAP(self, zero, next_instr):
if not we_are_translated() and sys.version_info >= (2, 6):
- w_key = f.popvalue()
- w_value = f.popvalue()
- w_dict = f.peekvalue()
- f.space.setitem(w_dict, w_key, w_value)
+ w_key = self.popvalue()
+ w_value = self.popvalue()
+ w_dict = self.peekvalue()
+ self.space.setitem(w_dict, w_key, w_value)
else:
raise BytecodeCorruption
- def LOAD_ATTR(f, nameindex, *ignored):
+ def LOAD_ATTR(self, nameindex, next_instr):
"obj.attributename"
- w_attributename = f.getname_w(nameindex)
- w_obj = f.popvalue()
- w_value = f.space.getattr(w_obj, w_attributename)
- f.pushvalue(w_value)
+ w_attributename = self.getname_w(nameindex)
+ w_obj = self.popvalue()
+ w_value = self.space.getattr(w_obj, w_attributename)
+ self.pushvalue(w_value)
LOAD_ATTR._always_inline_ = True
- def cmp_lt(f, w_1, w_2): return f.space.lt(w_1, w_2)
- def cmp_le(f, w_1, w_2): return f.space.le(w_1, w_2)
- def cmp_eq(f, w_1, w_2): return f.space.eq(w_1, w_2)
- def cmp_ne(f, w_1, w_2): return f.space.ne(w_1, w_2)
- def cmp_gt(f, w_1, w_2): return f.space.gt(w_1, w_2)
- def cmp_ge(f, w_1, w_2): return f.space.ge(w_1, w_2)
-
- def cmp_in(f, w_1, w_2):
- return f.space.contains(w_2, w_1)
- def cmp_not_in(f, w_1, w_2):
- return f.space.not_(f.space.contains(w_2, w_1))
- def cmp_is(f, w_1, w_2):
- return f.space.is_(w_1, w_2)
- def cmp_is_not(f, w_1, w_2):
- return f.space.not_(f.space.is_(w_1, w_2))
- def cmp_exc_match(f, w_1, w_2):
- return f.space.newbool(f.space.exception_match(w_1, w_2))
-
- def COMPARE_OP(f, testnum, *ignored):
- w_2 = f.popvalue()
- w_1 = f.popvalue()
+ def cmp_lt(self, w_1, w_2):
+ return self.space.lt(w_1, w_2)
+
+ def cmp_le(self, w_1, w_2):
+ return self.space.le(w_1, w_2)
+
+ def cmp_eq(self, w_1, w_2):
+ return self.space.eq(w_1, w_2)
+
+ def cmp_ne(self, w_1, w_2):
+ return self.space.ne(w_1, w_2)
+
+ def cmp_gt(self, w_1, w_2):
+ return self.space.gt(w_1, w_2)
+
+ def cmp_ge(self, w_1, w_2):
+ return self.space.ge(w_1, w_2)
+
+ def cmp_in(self, w_1, w_2):
+ return self.space.contains(w_2, w_1)
+
+ def cmp_not_in(self, w_1, w_2):
+ return self.space.not_(self.space.contains(w_2, w_1))
+
+ def cmp_is(self, w_1, w_2):
+ return self.space.is_(w_1, w_2)
+
+ def cmp_is_not(self, w_1, w_2):
+ return self.space.not_(self.space.is_(w_1, w_2))
+
+ def cmp_exc_match(self, w_1, w_2):
+ return self.space.newbool(self.space.exception_match(w_1, w_2))
+
+ def COMPARE_OP(self, testnum, next_instr):
+ w_2 = self.popvalue()
+ w_1 = self.popvalue()
w_result = None
for i, attr in unrolling_compare_dispatch_table:
if i == testnum:
- w_result = getattr(f, attr)(w_1, w_2)
+ w_result = getattr(self, attr)(w_1, w_2)
break
else:
raise BytecodeCorruption, "bad COMPARE_OP oparg"
- f.pushvalue(w_result)
+ self.pushvalue(w_result)
- def IMPORT_NAME(f, nameindex, *ignored):
- space = f.space
- w_modulename = f.getname_w(nameindex)
- modulename = f.space.str_w(w_modulename)
- w_fromlist = f.popvalue()
+ def IMPORT_NAME(self, nameindex, next_instr):
+ space = self.space
+ w_modulename = self.getname_w(nameindex)
+ modulename = self.space.str_w(w_modulename)
+ w_fromlist = self.popvalue()
# CPython 2.5 adds an extra argument consumed by this opcode
- if f.pycode.magic >= 0xa0df294:
- w_flag = f.popvalue()
+ if self.pycode.magic >= 0xa0df294:
+ w_flag = self.popvalue()
else:
w_flag = None
- w_import = f.get_builtin().getdictvalue(f.space, '__import__')
+ w_import = self.get_builtin().getdictvalue(space, '__import__')
if w_import is None:
raise OperationError(space.w_ImportError,
space.wrap("__import__ not found"))
- w_locals = f.w_locals
+ w_locals = self.w_locals
if w_locals is None: # CPython does this
w_locals = space.w_None
w_modulename = space.wrap(modulename)
- w_globals = f.w_globals
+ w_globals = self.w_globals
if w_flag is None:
w_obj = space.call_function(w_import, w_modulename, w_globals,
w_locals, w_fromlist)
@@ -793,105 +793,105 @@
w_obj = space.call_function(w_import, w_modulename, w_globals,
w_locals, w_fromlist, w_flag)
- f.pushvalue(w_obj)
+ self.pushvalue(w_obj)
- def IMPORT_STAR(f, *ignored):
- w_module = f.popvalue()
- w_locals = f.getdictscope()
- import_all_from(f.space, w_module, w_locals)
- f.setdictscope(w_locals)
-
- def IMPORT_FROM(f, nameindex, *ignored):
- w_name = f.getname_w(nameindex)
- w_module = f.peekvalue()
+ def IMPORT_STAR(self, oparg, next_instr):
+ w_module = self.popvalue()
+ w_locals = self.getdictscope()
+ import_all_from(self.space, w_module, w_locals)
+ self.setdictscope(w_locals)
+
+ def IMPORT_FROM(self, nameindex, next_instr):
+ w_name = self.getname_w(nameindex)
+ w_module = self.peekvalue()
try:
- w_obj = f.space.getattr(w_module, w_name)
+ w_obj = self.space.getattr(w_module, w_name)
except OperationError, e:
- if not e.match(f.space, f.space.w_AttributeError):
+ if not e.match(self.space, self.space.w_AttributeError):
raise
- raise operationerrfmt(f.space.w_ImportError,
+ raise operationerrfmt(self.space.w_ImportError,
"cannot import name '%s'",
- f.space.str_w(w_name))
- f.pushvalue(w_obj)
+ self.space.str_w(w_name))
+ self.pushvalue(w_obj)
- def JUMP_FORWARD(f, jumpby, next_instr, *ignored):
+ def jump_absolute(self, jumpto, next_instr, ec):
+ return jumpto
+
+ def JUMP_FORWARD(self, jumpby, next_instr):
next_instr += jumpby
return next_instr
- def JUMP_IF_FALSE(f, stepby, next_instr, *ignored):
- w_cond = f.peekvalue()
- if not f.space.is_true(w_cond):
+ def JUMP_IF_FALSE(self, stepby, next_instr):
+ w_cond = self.peekvalue()
+ if not self.space.is_true(w_cond):
next_instr += stepby
return next_instr
- def JUMP_IF_TRUE(f, stepby, next_instr, *ignored):
- w_cond = f.peekvalue()
- if f.space.is_true(w_cond):
+ def JUMP_IF_TRUE(self, stepby, next_instr):
+ w_cond = self.peekvalue()
+ if self.space.is_true(w_cond):
next_instr += stepby
return next_instr
- def JUMP_ABSOLUTE(f, jumpto, next_instr, *ignored):
- return jumpto
+ def GET_ITER(self, oparg, next_instr):
+ w_iterable = self.popvalue()
+ w_iterator = self.space.iter(w_iterable)
+ self.pushvalue(w_iterator)
- def GET_ITER(f, *ignored):
- w_iterable = f.popvalue()
- w_iterator = f.space.iter(w_iterable)
- f.pushvalue(w_iterator)
-
- def FOR_ITER(f, jumpby, next_instr, *ignored):
- w_iterator = f.peekvalue()
+ def FOR_ITER(self, jumpby, next_instr):
+ w_iterator = self.peekvalue()
try:
- w_nextitem = f.space.next(w_iterator)
+ w_nextitem = self.space.next(w_iterator)
except OperationError, e:
- if not e.match(f.space, f.space.w_StopIteration):
- raise
+ if not e.match(self.space, self.space.w_StopIteration):
+ raise
# iterator exhausted
- f.popvalue()
+ self.popvalue()
next_instr += jumpby
else:
- f.pushvalue(w_nextitem)
+ self.pushvalue(w_nextitem)
return next_instr
- def FOR_LOOP(f, oparg, *ignored):
+ def FOR_LOOP(self, oparg, next_instr):
raise BytecodeCorruption, "old opcode, no longer in use"
- def SETUP_LOOP(f, offsettoend, next_instr, *ignored):
- block = LoopBlock(f, next_instr + offsettoend)
- f.append_block(block)
-
- def SETUP_EXCEPT(f, offsettoend, next_instr, *ignored):
- block = ExceptBlock(f, next_instr + offsettoend)
- f.append_block(block)
-
- def SETUP_FINALLY(f, offsettoend, next_instr, *ignored):
- block = FinallyBlock(f, next_instr + offsettoend)
- f.append_block(block)
+ def SETUP_LOOP(self, offsettoend, next_instr):
+ block = LoopBlock(self, next_instr + offsettoend)
+ self.append_block(block)
+
+ def SETUP_EXCEPT(self, offsettoend, next_instr):
+ block = ExceptBlock(self, next_instr + offsettoend)
+ self.append_block(block)
+
+ def SETUP_FINALLY(self, offsettoend, next_instr):
+ block = FinallyBlock(self, next_instr + offsettoend)
+ self.append_block(block)
- def WITH_CLEANUP(f, *ignored):
+ def WITH_CLEANUP(self, oparg, next_instr):
# see comment in END_FINALLY for stack state
- w_exitfunc = f.popvalue()
- w_unroller = f.peekvalue(2)
- unroller = f.space.interpclass_w(w_unroller)
+ w_exitfunc = self.popvalue()
+ w_unroller = self.peekvalue(2)
+ unroller = self.space.interpclass_w(w_unroller)
if isinstance(unroller, SApplicationException):
operr = unroller.operr
- w_result = f.space.call_function(w_exitfunc,
- operr.w_type,
- operr.get_w_value(f.space),
- operr.application_traceback)
- if f.space.is_true(w_result):
+ w_result = self.space.call_function(w_exitfunc,
+ operr.w_type,
+ operr.get_w_value(self.space),
+ operr.application_traceback)
+ if self.space.is_true(w_result):
# __exit__() returned True -> Swallow the exception.
- f.settopvalue(f.space.w_None, 2)
+ self.settopvalue(self.space.w_None, 2)
else:
- f.space.call_function(w_exitfunc,
- f.space.w_None,
- f.space.w_None,
- f.space.w_None)
-
+ self.space.call_function(w_exitfunc,
+ self.space.w_None,
+ self.space.w_None,
+ self.space.w_None)
+
@jit.unroll_safe
- def call_function(f, oparg, w_star=None, w_starstar=None):
+ def call_function(self, oparg, w_star=None, w_starstar=None):
from pypy.rlib import rstack # for resume points
from pypy.interpreter.function import is_builtin_code
-
+
n_arguments = oparg & 0xff
n_keywords = (oparg>>8) & 0xff
if n_keywords:
@@ -901,126 +901,121 @@
n_keywords -= 1
if n_keywords < 0:
break
- w_value = f.popvalue()
- w_key = f.popvalue()
- key = f.space.str_w(w_key)
+ w_value = self.popvalue()
+ w_key = self.popvalue()
+ key = self.space.str_w(w_key)
keywords[n_keywords] = key
keywords_w[n_keywords] = w_value
else:
keywords = None
keywords_w = None
- arguments = f.popvalues(n_arguments)
- args = f.argument_factory(arguments, keywords, keywords_w, w_star, w_starstar)
- w_function = f.popvalue()
- if f.is_being_profiled and is_builtin_code(w_function):
- w_result = f.space.call_args_and_c_profile(f, w_function, args)
+ arguments = self.popvalues(n_arguments)
+ args = self.argument_factory(arguments, keywords, keywords_w, w_star,
+ w_starstar)
+ w_function = self.popvalue()
+ if self.is_being_profiled and is_builtin_code(w_function):
+ w_result = self.space.call_args_and_c_profile(self, w_function,
+ args)
else:
- w_result = f.space.call_args(w_function, args)
- rstack.resume_point("call_function", f, returns=w_result)
- f.pushvalue(w_result)
-
- def CALL_FUNCTION(f, oparg, *ignored):
+ w_result = self.space.call_args(w_function, args)
+ rstack.resume_point("call_function", self, returns=w_result)
+ self.pushvalue(w_result)
+
+ def CALL_FUNCTION(self, oparg, next_instr):
from pypy.rlib import rstack # for resume points
# XXX start of hack for performance
if (oparg >> 8) & 0xff == 0:
# Only positional arguments
nargs = oparg & 0xff
- w_function = f.peekvalue(nargs)
+ w_function = self.peekvalue(nargs)
try:
- w_result = f.space.call_valuestack(w_function, nargs, f)
- rstack.resume_point("CALL_FUNCTION", f, nargs, returns=w_result)
+ w_result = self.space.call_valuestack(w_function, nargs, self)
+ rstack.resume_point("CALL_FUNCTION", self, nargs,
+ returns=w_result)
finally:
- f.dropvalues(nargs + 1)
- f.pushvalue(w_result)
+ self.dropvalues(nargs + 1)
+ self.pushvalue(w_result)
# XXX end of hack for performance
else:
# general case
- f.call_function(oparg)
+ self.call_function(oparg)
- def CALL_FUNCTION_VAR(f, oparg, *ignored):
- w_varargs = f.popvalue()
- f.call_function(oparg, w_varargs)
-
- def CALL_FUNCTION_KW(f, oparg, *ignored):
- w_varkw = f.popvalue()
- f.call_function(oparg, None, w_varkw)
-
- def CALL_FUNCTION_VAR_KW(f, oparg, *ignored):
- w_varkw = f.popvalue()
- w_varargs = f.popvalue()
- f.call_function(oparg, w_varargs, w_varkw)
-
- def MAKE_FUNCTION(f, numdefaults, *ignored):
- w_codeobj = f.popvalue()
- codeobj = f.space.interp_w(PyCode, w_codeobj)
- defaultarguments = f.popvalues(numdefaults)
- fn = function.Function(f.space, codeobj, f.w_globals, defaultarguments)
- f.pushvalue(f.space.wrap(fn))
+ def CALL_FUNCTION_VAR(self, oparg, next_instr):
+ w_varargs = self.popvalue()
+ self.call_function(oparg, w_varargs)
+
+ def CALL_FUNCTION_KW(self, oparg, next_instr):
+ w_varkw = self.popvalue()
+ self.call_function(oparg, None, w_varkw)
+
+ def CALL_FUNCTION_VAR_KW(self, oparg, next_instr):
+ w_varkw = self.popvalue()
+ w_varargs = self.popvalue()
+ self.call_function(oparg, w_varargs, w_varkw)
+
+ def MAKE_FUNCTION(self, numdefaults, next_instr):
+ w_codeobj = self.popvalue()
+ codeobj = self.space.interp_w(PyCode, w_codeobj)
+ defaultarguments = self.popvalues(numdefaults)
+ fn = function.Function(self.space, codeobj, self.w_globals,
+ defaultarguments)
+ self.pushvalue(self.space.wrap(fn))
- def BUILD_SLICE(f, numargs, *ignored):
+ def BUILD_SLICE(self, numargs, next_instr):
if numargs == 3:
- w_step = f.popvalue()
+ w_step = self.popvalue()
elif numargs == 2:
- w_step = f.space.w_None
+ w_step = self.space.w_None
else:
raise BytecodeCorruption
- w_end = f.popvalue()
- w_start = f.popvalue()
- w_slice = f.space.newslice(w_start, w_end, w_step)
- f.pushvalue(w_slice)
-
- def LIST_APPEND(f, *ignored):
- w = f.popvalue()
- v = f.popvalue()
- f.space.call_method(v, 'append', w)
+ w_end = self.popvalue()
+ w_start = self.popvalue()
+ w_slice = self.space.newslice(w_start, w_end, w_step)
+ self.pushvalue(w_slice)
+
+ def LIST_APPEND(self, oparg, next_instr):
+ w = self.popvalue()
+ v = self.popvalue()
+ self.space.call_method(v, 'append', w)
- def SET_LINENO(f, lineno, *ignored):
+ def SET_LINENO(self, lineno, next_instr):
pass
- def CALL_LIKELY_BUILTIN(f, oparg, *ignored):
+ def CALL_LIKELY_BUILTIN(self, oparg, next_instr):
# overridden by faster version in the standard object space.
from pypy.module.__builtin__ import OPTIMIZED_BUILTINS
varname = OPTIMIZED_BUILTINS[oparg >> 8]
- w_function = f._load_global(varname)
+ w_function = self._load_global(varname)
nargs = oparg&0xFF
try:
- w_result = f.space.call_valuestack(w_function, nargs, f)
+ w_result = self.space.call_valuestack(w_function, nargs, self)
finally:
- f.dropvalues(nargs)
- f.pushvalue(w_result)
+ self.dropvalues(nargs)
+ self.pushvalue(w_result)
- def LOOKUP_METHOD(f, nameindex, *ignored):
+ def LOOKUP_METHOD(self, nameindex, next_instr):
# overridden by faster version in the standard object space.
- space = f.space
- w_obj = f.popvalue()
- w_name = f.getname_w(nameindex)
+ space = self.space
+ w_obj = self.popvalue()
+ w_name = self.getname_w(nameindex)
w_value = space.getattr(w_obj, w_name)
- f.pushvalue(w_value)
- #f.pushvalue(None)
+ self.pushvalue(w_value)
- def CALL_METHOD(f, nargs, *ignored):
+ def CALL_METHOD(self, nargs, next_instr):
# overridden by faster version in the standard object space.
# 'nargs' is the argument count excluding the implicit 'self'
- w_callable = f.peekvalue(nargs)
+ w_callable = self.peekvalue(nargs)
try:
- w_result = f.space.call_valuestack(w_callable, nargs, f)
+ w_result = self.space.call_valuestack(w_callable, nargs, self)
finally:
- f.dropvalues(nargs + 1)
- f.pushvalue(w_result)
-
-## def EXTENDED_ARG(f, oparg, *ignored):
-## opcode = f.nextop()
-## oparg = oparg<<16 | f.nextarg()
-## fn = f.dispatch_table_w_arg[opcode]
-## if fn is None:
-## raise BytecodeCorruption
-## fn(f, oparg)
+ self.dropvalues(nargs + 1)
+ self.pushvalue(w_result)
- def MISSING_OPCODE(f, oparg, next_instr, *ignored):
+ def MISSING_OPCODE(self, oparg, next_instr):
ofs = next_instr - 1
- c = f.pycode.co_code[ofs]
- name = f.pycode.co_name
+ c = self.pycode.co_code[ofs]
+ name = self.pycode.co_name
raise BytecodeCorruption("unknown opcode, ofs=%d, code=%d, name=%s" %
(ofs, ord(c), name) )
@@ -1259,9 +1254,9 @@
""" applevel implementation of certain system properties, imports
and other helpers"""
import sys
-
+
def sys_stdout():
- try:
+ try:
return sys.stdout
except AttributeError:
raise RuntimeError("lost sys.stdout")
@@ -1281,7 +1276,7 @@
# add a softspace unless we just printed a string which ends in a '\t'
# or '\n' -- or more generally any whitespace character but ' '
if isinstance(x, str) and x and x[-1].isspace() and x[-1]!=' ':
- return
+ return
# XXX add unicode handling
file_softspace(stream, True)
print_item_to._annspecialcase_ = "specialize:argtype(0)"
@@ -1330,10 +1325,10 @@
return type(base)
elif '__metaclass__' in globals:
return globals['__metaclass__']
- else:
- try:
- return builtin.__metaclass__
- except AttributeError:
+ else:
+ try:
+ return builtin.__metaclass__
+ except AttributeError:
return type
''', filename=__file__)
Modified: pypy/branch/cpython-extension/pypy/interpreter/pyparser/future.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/pyparser/future.py (original)
+++ pypy/branch/cpython-extension/pypy/interpreter/pyparser/future.py Wed Mar 31 00:17:06 2010
@@ -62,7 +62,7 @@
not recognized as a valid future statement or something that may
precede a future statement.
"""
-
+
def __init__(self, future_flags, string):
self.future_flags = future_flags
self.s = string
@@ -83,7 +83,7 @@
def start(self):
c = self.getc()
- if c in ["'", '"'] and not self.docstring_consumed:
+ if c in ("'", '"', "r", "u") and not self.docstring_consumed:
self.consume_docstring()
elif c in whitespace_or_newline:
self.consume_empty_line()
@@ -100,6 +100,10 @@
def consume_docstring(self):
self.docstring_consumed = True
+ if self.getc() == "r":
+ self.pos += 1
+ if self.getc() == "u":
+ self.pos += 1
endchar = self.getc()
if (self.getc() == self.getc(+1) and
self.getc() == self.getc(+2)):
Modified: pypy/branch/cpython-extension/pypy/interpreter/pyparser/test/test_futureautomaton.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/pyparser/test/test_futureautomaton.py (original)
+++ pypy/branch/cpython-extension/pypy/interpreter/pyparser/test/test_futureautomaton.py Wed Mar 31 00:17:06 2010
@@ -150,3 +150,20 @@
assert f.flags == fut.CO_FUTURE_ABSOLUTE_IMPORT
+def test_raw_doc():
+ s = 'r"Doc"\nfrom __future__ import with_statement\n'
+ f = run(s)
+ assert f.pos == len(s)
+ assert f.flags == fut.CO_FUTURE_WITH_STATEMENT
+
+def test_unicode_doc():
+ s = 'u"Doc"\nfrom __future__ import with_statement\n'
+ f = run(s)
+ assert f.pos == len(s)
+ assert f.flags == fut.CO_FUTURE_WITH_STATEMENT
+
+def test_raw_unicode_doc():
+ s = 'ru"Doc"\nfrom __future__ import with_statement\n'
+ f = run(s)
+ assert f.pos == len(s)
+ assert f.flags == fut.CO_FUTURE_WITH_STATEMENT
Modified: pypy/branch/cpython-extension/pypy/interpreter/test/test_executioncontext.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/test/test_executioncontext.py (original)
+++ pypy/branch/cpython-extension/pypy/interpreter/test/test_executioncontext.py Wed Mar 31 00:17:06 2010
@@ -271,7 +271,11 @@
# would be called
import os, sys
print sys.executable, self.tmpfile
- g = os.popen('"%s" "%s"' % (sys.executable, self.tmpfile), 'r')
+ if sys.platform == "win32":
+ cmdformat = '""%s" "%s""' # excellent! tons of "!
+ else:
+ cmdformat = "'%s' '%s'"
+ g = os.popen(cmdformat % (sys.executable, self.tmpfile), 'r')
data = g.read()
g.close()
assert 'Called 1' in data
Modified: pypy/branch/cpython-extension/pypy/interpreter/test/test_gateway.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/test/test_gateway.py (original)
+++ pypy/branch/cpython-extension/pypy/interpreter/test/test_gateway.py Wed Mar 31 00:17:06 2010
@@ -197,6 +197,51 @@
space.raises_w(space.w_ValueError,
space.call_function, w_app_g, space.wrap(-1))
+ def test_interp2app_unwrap_spec_c_int(self):
+ from pypy.rlib.rarithmetic import r_longlong
+ space = self.space
+ w = space.wrap
+ def g(space, x):
+ return space.wrap(x + 6)
+ app_g = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace,
+ 'c_int'])
+ app_ug = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace,
+ 'c_uint'])
+ app_ng = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace,
+ 'c_nonnegint'])
+ assert app_ug is not app_g
+ w_app_g = space.wrap(app_g)
+ w_app_ug = space.wrap(app_ug)
+ w_app_ng = space.wrap(app_ng)
+ #
+ assert self.space.eq_w(space.call_function(w_app_g, space.wrap(7)),
+ space.wrap(13))
+ space.raises_w(space.w_OverflowError,
+ space.call_function, w_app_g,
+ space.wrap(r_longlong(0x80000000)))
+ space.raises_w(space.w_OverflowError,
+ space.call_function, w_app_g,
+ space.wrap(r_longlong(-0x80000001)))
+ #
+ assert self.space.eq_w(space.call_function(w_app_ug, space.wrap(7)),
+ space.wrap(13))
+ assert self.space.eq_w(space.call_function(w_app_ug,
+ space.wrap(0x7FFFFFFF)),
+ space.wrap(r_longlong(0x7FFFFFFF+6)))
+ space.raises_w(space.w_ValueError,
+ space.call_function, w_app_ug, space.wrap(-1))
+ space.raises_w(space.w_OverflowError,
+ space.call_function, w_app_ug,
+ space.wrap(r_longlong(0x100000000)))
+ #
+ assert self.space.eq_w(space.call_function(w_app_ng, space.wrap(7)),
+ space.wrap(13))
+ space.raises_w(space.w_OverflowError,
+ space.call_function, w_app_ng,
+ space.wrap(r_longlong(0x80000000)))
+ space.raises_w(space.w_ValueError,
+ space.call_function, w_app_ng, space.wrap(-1))
+
def test_interp2app_unwrap_spec_args_w(self):
space = self.space
w = space.wrap
Modified: pypy/branch/cpython-extension/pypy/interpreter/test/test_interpreter.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/test/test_interpreter.py (original)
+++ pypy/branch/cpython-extension/pypy/interpreter/test/test_interpreter.py Wed Mar 31 00:17:06 2010
@@ -263,3 +263,12 @@
def test_identity(self):
def f(x): return x
assert f(666) == 666
+
+ def test_raise_recursion(self):
+ def f(): f()
+ try:
+ f()
+ except RuntimeError, e:
+ assert str(e) == "maximum recursion depth exceeded"
+ else:
+ assert 0, "should have raised!"
Modified: pypy/branch/cpython-extension/pypy/interpreter/test/test_syntax.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/test/test_syntax.py (original)
+++ pypy/branch/cpython-extension/pypy/interpreter/test/test_syntax.py Wed Mar 31 00:17:06 2010
@@ -359,6 +359,22 @@
exec s
assert acontext.calls == '__enter__ __exit__'.split()
+ def test_raw_doc_string(self):
+ s = """r'doc'
+from __future__ import with_statement
+class Context(object):
+ def __enter__(self):
+ global enter
+ enter = True
+ def __exit__(self, *exc):
+ global exit
+ exit = True
+with Context() as w:
+ pass"""
+ exec s
+ assert enter
+ assert exit
+
def test_with_as_var(self):
s = """from __future__ import with_statement
Modified: pypy/branch/cpython-extension/pypy/interpreter/test/test_zpy.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/interpreter/test/test_zpy.py (original)
+++ pypy/branch/cpython-extension/pypy/interpreter/test/test_zpy.py Wed Mar 31 00:17:06 2010
@@ -6,17 +6,23 @@
pypypath = py.path.local(pypy.__file__).dirpath("bin", "py.py")
+def cmdexec(s):
+ if sys.platform == 'win32':
+ s = '"%s"' % s # double double quotes
+ return py.process.cmdexec(s)
+
+
def test_executable():
"""Ensures sys.executable points to the py.py script"""
# TODO : watch out for spaces/special chars in pypypath
- output = py.process.cmdexec( '''"%s" "%s" -c "import sys;print sys.executable" ''' %
- (sys.executable, pypypath) )
+ output = cmdexec( '''"%s" "%s" -c "import sys;print sys.executable" ''' %
+ (sys.executable, pypypath) )
assert output.splitlines()[-1] == pypypath
def test_special_names():
"""Test the __name__ and __file__ special global names"""
cmd = "print __name__; print '__file__' in globals()"
- output = py.process.cmdexec( '''"%s" "%s" -c "%s" ''' %
+ output = cmdexec( '''"%s" "%s" -c "%s" ''' %
(sys.executable, pypypath, cmd) )
assert output.splitlines()[-2] == '__main__'
assert output.splitlines()[-1] == 'False'
@@ -26,7 +32,7 @@
tmpfile.write("print __name__; print __file__\n")
tmpfile.close()
- output = py.process.cmdexec( '''"%s" "%s" "%s" ''' %
+ output = cmdexec( '''"%s" "%s" "%s" ''' %
(sys.executable, pypypath, tmpfilepath) )
assert output.splitlines()[-2] == '__main__'
assert output.splitlines()[-1] == str(tmpfilepath)
@@ -34,17 +40,17 @@
def test_argv_command():
"""Some tests on argv"""
# test 1 : no arguments
- output = py.process.cmdexec( '''"%s" "%s" -c "import sys;print sys.argv" ''' %
+ output = cmdexec( '''"%s" "%s" -c "import sys;print sys.argv" ''' %
(sys.executable, pypypath) )
assert output.splitlines()[-1] == str(['-c'])
# test 2 : some arguments after
- output = py.process.cmdexec( '''"%s" "%s" -c "import sys;print sys.argv" hello''' %
+ output = cmdexec( '''"%s" "%s" -c "import sys;print sys.argv" hello''' %
(sys.executable, pypypath) )
assert output.splitlines()[-1] == str(['-c','hello'])
# test 3 : additionnal pypy parameters
- output = py.process.cmdexec( '''"%s" "%s" -O -c "import sys;print sys.argv" hello''' %
+ output = cmdexec( '''"%s" "%s" -O -c "import sys;print sys.argv" hello''' %
(sys.executable, pypypath) )
assert output.splitlines()[-1] == str(['-c','hello'])
@@ -59,17 +65,17 @@
tmpfile.close()
# test 1 : no arguments
- output = py.process.cmdexec( '''"%s" "%s" "%s" ''' %
+ output = cmdexec( '''"%s" "%s" "%s" ''' %
(sys.executable, pypypath, tmpfilepath) )
assert output.splitlines()[-1] == str([tmpfilepath])
# test 2 : some arguments after
- output = py.process.cmdexec( '''"%s" "%s" "%s" hello''' %
+ output = cmdexec( '''"%s" "%s" "%s" hello''' %
(sys.executable, pypypath, tmpfilepath) )
assert output.splitlines()[-1] == str([tmpfilepath,'hello'])
# test 3 : additionnal pypy parameters
- output = py.process.cmdexec( '''"%s" "%s" -O "%s" hello''' %
+ output = cmdexec( '''"%s" "%s" -O "%s" hello''' %
(sys.executable, pypypath, tmpfilepath) )
assert output.splitlines()[-1] == str([tmpfilepath,'hello'])
@@ -94,7 +100,7 @@
e = None
try:
- output = py.process.cmdexec( '''"%s" "%s" "%s" ''' %
+ output = cmdexec( '''"%s" "%s" "%s" ''' %
(sys.executable, pypypath, tmpfilepath) )
except py.process.cmdexec.Error, e:
pass
Modified: pypy/branch/cpython-extension/pypy/jit/backend/llsupport/descr.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/jit/backend/llsupport/descr.py (original)
+++ pypy/branch/cpython-extension/pypy/jit/backend/llsupport/descr.py Wed Mar 31 00:17:06 2010
@@ -1,7 +1,9 @@
-from pypy.rpython.lltypesystem import lltype
-from pypy.jit.backend.llsupport import symbolic
+import py
+from pypy.rpython.lltypesystem import lltype, rffi, llmemory
+from pypy.jit.backend.llsupport import symbolic, support
from pypy.jit.metainterp.history import AbstractDescr, getkind, BoxInt, BoxPtr
from pypy.jit.metainterp.history import BasicFailDescr, LoopToken, BoxFloat
+from pypy.jit.metainterp import history
from pypy.jit.metainterp.resoperation import ResOperation, rop
# The point of the class organization in this file is to make instances
@@ -11,8 +13,9 @@
class GcCache(object):
- def __init__(self, translate_support_code):
+ def __init__(self, translate_support_code, rtyper=None):
self.translate_support_code = translate_support_code
+ self.rtyper = rtyper
self._cache_size = {}
self._cache_field = {}
self._cache_array = {}
@@ -176,6 +179,7 @@
# CallDescrs
class BaseCallDescr(AbstractDescr):
+ empty_box = BoxInt(0)
_clsname = ''
loop_token = None
arg_classes = '' # <-- annotation hack
@@ -187,17 +191,9 @@
def get_extra_info(self):
return self.extrainfo
- def instantiate_arg_classes(self):
- result = []
- for c in self.arg_classes:
- if c == 'i': box = BoxInt()
- elif c == 'f': box = BoxFloat()
- else: box = BoxPtr()
- result.append(box)
- return result
-
_returns_a_pointer = False # unless overridden by GcPtrCallDescr
_returns_a_float = False # unless overridden by FloatCallDescr
+ _returns_a_void = False # unless overridden by VoidCallDescr
def returns_a_pointer(self):
return self._returns_a_pointer
@@ -205,39 +201,59 @@
def returns_a_float(self):
return self._returns_a_float
+ def returns_a_void(self):
+ return self._returns_a_void
+
def get_result_size(self, translate_support_code):
raise NotImplementedError
- def get_token_for_call(self, cpu):
- if self.loop_token is not None:
- return self.loop_token
- args = [BoxInt()] + self.instantiate_arg_classes()
- if self.get_result_size(cpu.translate_support_code) == 0:
- result = None
- result_list = []
- else:
- if self.returns_a_pointer():
- result = BoxPtr()
- elif self.returns_a_float():
- result = BoxFloat()
+ def get_call_stub(self):
+ return self.call_stub
+
+ def create_call_stub(self, rtyper, RESULT):
+ def process(no, c):
+ if c == 'i':
+ return 'args[%d].getint()' % (no,)
+ elif c == 'f':
+ return 'args[%d].getfloat()' % (no,)
+ elif c == 'r':
+ return 'args[%d].getref_base()' % (no,)
else:
- result = BoxInt()
- result_list = [result]
- operations = [
- ResOperation(rop.CALL, args[:], result, self),
- ResOperation(rop.GUARD_NO_EXCEPTION, [], None,
- descr=BasicFailDescr()),
- ResOperation(rop.FINISH, result_list, None,
- descr=BasicFailDescr())]
- operations[1].fail_args = []
- loop_token = LoopToken()
- # note: the 'args' that we pass below is not the same object as the
- # 'args[:]' that was passed above to ResOperation, because we want
- # the argument to ResOperation to be non-resizable, but the argument
- # to compile_loop to be resizable.
- cpu.compile_loop(args, operations, loop_token)
- self.loop_token = loop_token
- return loop_token
+ raise Exception("Unknown type %s for type %s" % (c, TP))
+
+ def TYPE(arg):
+ if arg == 'i':
+ return lltype.Signed
+ elif arg == 'f':
+ return lltype.Float
+ elif arg == 'r':
+ return llmemory.GCREF
+ elif arg == 'v':
+ return lltype.Void
+
+ args = ", ".join([process(i + 1, c) for i, c in
+ enumerate(self.arg_classes)])
+
+ if self.returns_a_pointer():
+ result = 'history.BoxPtr(lltype.cast_opaque_ptr(llmemory.GCREF, res))'
+ elif self.returns_a_float():
+ result = 'history.BoxFloat(res)'
+ elif self.returns_a_void():
+ result = 'None'
+ else:
+ result = 'history.BoxInt(rffi.cast(lltype.Signed, res))'
+ source = py.code.Source("""
+ def call_stub(args):
+ fnptr = rffi.cast(lltype.Ptr(FUNC), args[0].getint())
+ res = support.maybe_on_top_of_llinterp(rtyper, fnptr)(%(args)s)
+ return %(result)s
+ """ % locals())
+ ARGS = [TYPE(arg) for arg in self.arg_classes]
+ FUNC = lltype.FuncType(ARGS, RESULT)
+ d = locals().copy()
+ d.update(globals())
+ exec source.compile() in d
+ self.call_stub = d['call_stub']
def repr_of_descr(self):
return '<%s>' % self._clsname
@@ -245,15 +261,20 @@
class NonGcPtrCallDescr(BaseCallDescr):
_clsname = 'NonGcPtrCallDescr'
+
def get_result_size(self, translate_support_code):
return symbolic.get_size_of_ptr(translate_support_code)
class GcPtrCallDescr(NonGcPtrCallDescr):
+ empty_box = BoxPtr(lltype.nullptr(llmemory.GCREF.TO))
_clsname = 'GcPtrCallDescr'
_returns_a_pointer = True
class VoidCallDescr(NonGcPtrCallDescr):
+ empty_box = None
_clsname = 'VoidCallDescr'
+ _returns_a_void = True
+
def get_result_size(self, translate_support_code):
return 0
@@ -281,6 +302,7 @@
return cache[key]
except KeyError:
calldescr = cls(arg_classes, extrainfo)
+ calldescr.create_call_stub(gccache.rtyper, RESULT)
cache[key] = calldescr
return calldescr
@@ -308,6 +330,7 @@
#
if TYPE is lltype.Float:
setattr(Descr, floatattrname, True)
+ Descr.empty_box = BoxFloat(0.0)
#
_cache[nameprefix, TYPE] = Descr
return Descr
Modified: pypy/branch/cpython-extension/pypy/jit/backend/llsupport/gc.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/jit/backend/llsupport/gc.py (original)
+++ pypy/branch/cpython-extension/pypy/jit/backend/llsupport/gc.py Wed Mar 31 00:17:06 2010
@@ -2,6 +2,7 @@
from pypy.rlib.objectmodel import we_are_translated
from pypy.rlib.debug import fatalerror
from pypy.rpython.lltypesystem import lltype, llmemory, rffi, rclass, rstr
+from pypy.rpython.lltypesystem import llgroup
from pypy.rpython.lltypesystem.lloperation import llop
from pypy.rpython.annlowlevel import llhelper
from pypy.translator.tool.cbuild import ExternalCompilationInfo
@@ -18,8 +19,8 @@
# ____________________________________________________________
class GcLLDescription(GcCache):
- def __init__(self, gcdescr, translator=None):
- GcCache.__init__(self, translator is not None)
+ def __init__(self, gcdescr, translator=None, rtyper=None):
+ GcCache.__init__(self, translator is not None, rtyper)
self.gcdescr = gcdescr
def _freeze_(self):
return True
@@ -40,8 +41,8 @@
moving_gc = False
gcrootmap = None
- def __init__(self, gcdescr, translator):
- GcLLDescription.__init__(self, gcdescr, translator)
+ def __init__(self, gcdescr, translator, rtyper):
+ GcLLDescription.__init__(self, gcdescr, translator, rtyper)
# grab a pointer to the Boehm 'malloc' function
from pypy.rpython.tool import rffi_platform
compilation_info = rffi_platform.configure_boehm()
@@ -309,7 +310,7 @@
# if convenient for the backend, we also compute the info about
# the flag as (byte-offset, single-byte-flag).
import struct
- value = struct.pack("i", self.jit_wb_if_flag)
+ value = struct.pack("l", self.jit_wb_if_flag)
assert value.count('\x00') == len(value) - 1 # only one byte is != 0
i = 0
while value[i] == '\x00': i += 1
@@ -326,11 +327,11 @@
class GcLLDescr_framework(GcLLDescription):
DEBUG = False # forced to True by x86/test/test_zrpy_gc.py
- def __init__(self, gcdescr, translator, llop1=llop):
+ def __init__(self, gcdescr, translator, rtyper, llop1=llop):
from pypy.rpython.memory.gctypelayout import _check_typeid
from pypy.rpython.memory.gcheader import GCHeaderBuilder
from pypy.rpython.memory.gctransform import framework
- GcLLDescription.__init__(self, gcdescr, translator)
+ GcLLDescription.__init__(self, gcdescr, translator, rtyper)
assert self.translate_support_code, "required with the framework GC"
self.translator = translator
self.llop1 = llop1
@@ -372,8 +373,8 @@
# make a malloc function, with three arguments
def malloc_basic(size, tid):
- type_id = llop.extract_ushort(rffi.USHORT, tid)
- has_finalizer = bool(tid & (1<<16))
+ type_id = llop.extract_ushort(llgroup.HALFWORD, tid)
+ has_finalizer = bool(tid & (1<<llgroup.HALFSHIFT))
_check_typeid(type_id)
try:
res = llop1.do_malloc_fixedsize_clear(llmemory.GCREF,
@@ -393,7 +394,7 @@
self.write_barrier_descr = WriteBarrierDescr(self)
#
def malloc_array(itemsize, tid, num_elem):
- type_id = llop.extract_ushort(rffi.USHORT, tid)
+ type_id = llop.extract_ushort(llgroup.HALFWORD, tid)
_check_typeid(type_id)
try:
return llop1.do_malloc_varsize_clear(
@@ -483,7 +484,7 @@
type_id = self.layoutbuilder.get_type_id(S)
assert not self.layoutbuilder.is_weakref(type_id)
has_finalizer = bool(self.layoutbuilder.has_finalizer(S))
- flags = int(has_finalizer) << 16
+ flags = int(has_finalizer) << llgroup.HALFSHIFT
descr.tid = llop.combine_ushort(lltype.Signed, type_id, flags)
def init_array_descr(self, A, descr):
@@ -599,7 +600,7 @@
def can_inline_malloc(self, descr):
assert isinstance(descr, BaseSizeDescr)
if descr.size < self.max_size_of_young_obj:
- has_finalizer = bool(descr.tid & (1<<16))
+ has_finalizer = bool(descr.tid & (1<<llgroup.HALFSHIFT))
if has_finalizer:
return False
return True
@@ -610,7 +611,7 @@
# ____________________________________________________________
-def get_ll_description(gcdescr, translator=None):
+def get_ll_description(gcdescr, translator=None, rtyper=None):
# translator is None if translate_support_code is False.
if gcdescr is not None:
name = gcdescr.config.translation.gctransformer
@@ -621,4 +622,4 @@
except KeyError:
raise NotImplementedError("GC transformer %r not supported by "
"the JIT backend" % (name,))
- return cls(gcdescr, translator)
+ return cls(gcdescr, translator, rtyper)
Modified: pypy/branch/cpython-extension/pypy/jit/backend/llsupport/llmodel.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/jit/backend/llsupport/llmodel.py (original)
+++ pypy/branch/cpython-extension/pypy/jit/backend/llsupport/llmodel.py Wed Mar 31 00:17:06 2010
@@ -1,7 +1,7 @@
import sys
from pypy.rpython.lltypesystem import lltype, llmemory, rffi, rclass, rstr
from pypy.rpython.lltypesystem.lloperation import llop
-from pypy.rpython.llinterp import LLInterpreter
+from pypy.rpython.llinterp import LLInterpreter, LLException
from pypy.rpython.annlowlevel import llhelper
from pypy.rlib.objectmodel import we_are_translated, specialize
from pypy.jit.metainterp.history import BoxInt, BoxPtr, set_future_values,\
@@ -13,6 +13,9 @@
from pypy.jit.backend.llsupport.descr import get_field_descr, BaseFieldDescr
from pypy.jit.backend.llsupport.descr import get_array_descr, BaseArrayDescr
from pypy.jit.backend.llsupport.descr import get_call_descr, BaseCallDescr
+from pypy.rpython.annlowlevel import cast_instance_to_base_ptr
+
+empty_int_box = BoxInt(0)
class AbstractLLCPU(AbstractCPU):
from pypy.jit.metainterp.typesystem import llhelper as ts
@@ -31,7 +34,7 @@
translator = rtyper.annotator.translator
else:
translator = None
- self.gc_ll_descr = get_ll_description(gcdescr, translator)
+ self.gc_ll_descr = get_ll_description(gcdescr, translator, rtyper)
if translator and translator.config.translation.gcremovetypeptr:
self.vtable_offset = None
else:
@@ -474,20 +477,23 @@
if not we_are_translated():
assert (list(calldescr.arg_classes) ==
[arg.type for arg in args[1:]])
- loop_token = calldescr.get_token_for_call(self)
- set_future_values(self, args)
- self.execute_token(loop_token)
- # Note: if an exception is set, the rest of the code does a bit of
- # nonsense but nothing wrong (the return value should be ignored)
- if calldescr.returns_a_pointer():
- return BoxPtr(self.get_latest_value_ref(0))
- elif calldescr.returns_a_float():
- return BoxFloat(self.get_latest_value_float(0))
- elif calldescr.get_result_size(self.translate_support_code) > 0:
- return BoxInt(self.get_latest_value_int(0))
- else:
- return None
-
+ callstub = calldescr.get_call_stub()
+ try:
+ return callstub(args)
+ except Exception, e:
+ if not we_are_translated():
+ if not type(e) is LLException:
+ raise
+ self.saved_exc_value = lltype.cast_opaque_ptr(llmemory.GCREF,
+ e.args[1])
+ self.saved_exception = rffi.cast(lltype.Signed, e.args[0])
+ else:
+ ptr = cast_instance_to_base_ptr(e)
+ self.saved_exc_value = lltype.cast_opaque_ptr(llmemory.GCREF,
+ ptr)
+ self.saved_exception = rffi.cast(lltype.Signed, ptr.typeptr)
+ return calldescr.empty_box
+
def do_cast_ptr_to_int(self, ptrbox):
return BoxInt(self.cast_gcref_to_int(ptrbox.getref_base()))
Modified: pypy/branch/cpython-extension/pypy/jit/backend/llsupport/test/test_descr.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/jit/backend/llsupport/test/test_descr.py (original)
+++ pypy/branch/cpython-extension/pypy/jit/backend/llsupport/test/test_descr.py Wed Mar 31 00:17:06 2010
@@ -2,7 +2,8 @@
from pypy.jit.backend.llsupport.descr import *
from pypy.jit.backend.llsupport import symbolic
from pypy.rlib.objectmodel import Symbolic
-
+from pypy.rpython.annlowlevel import llhelper
+from pypy.jit.metainterp.history import BoxInt, BoxFloat, BoxPtr
def test_get_size_descr():
c0 = GcCache(False)
@@ -147,6 +148,7 @@
assert not descr1.returns_a_pointer()
assert not descr1.returns_a_float()
assert descr1.arg_classes == "ii"
+ assert isinstance(descr1.empty_box, BoxInt)
#
T = lltype.GcStruct('T')
descr2 = get_call_descr(c0, [lltype.Ptr(T)], lltype.Ptr(T))
@@ -154,15 +156,22 @@
assert descr2.returns_a_pointer()
assert not descr2.returns_a_float()
assert descr2.arg_classes == "r"
+ assert isinstance(descr2.empty_box, BoxPtr)
#
U = lltype.GcStruct('U', ('x', lltype.Signed))
assert descr2 == get_call_descr(c0, [lltype.Ptr(U)], lltype.Ptr(U))
#
+ V = lltype.Struct('V', ('x', lltype.Signed))
+ assert isinstance(get_call_descr(c0, [], lltype.Ptr(V)).empty_box, BoxInt)
+ #
+ assert get_call_descr(c0, [], lltype.Void).empty_box is None
+ #
descr4 = get_call_descr(c0, [lltype.Float, lltype.Float], lltype.Float)
assert descr4.get_result_size(False) == rffi.sizeof(lltype.Float)
assert not descr4.returns_a_pointer()
assert descr4.returns_a_float()
assert descr4.arg_classes == "ff"
+ assert isinstance(descr4.empty_box, BoxFloat)
def test_get_call_descr_translated():
c1 = GcCache(True)
@@ -227,3 +236,34 @@
#
descr4f = get_call_descr(c0, [lltype.Char, lltype.Ptr(S)], lltype.Float)
assert 'FloatCallDescr' in descr4f.repr_of_descr()
+
+def test_call_stubs():
+ c0 = GcCache(False)
+ ARGS = [lltype.Char, lltype.Signed]
+ RES = lltype.Char
+ descr1 = get_call_descr(c0, ARGS, RES)
+ def f(a, b):
+ return 'c'
+
+ call_stub = descr1.get_call_stub()
+ fnptr = llhelper(lltype.Ptr(lltype.FuncType(ARGS, RES)), f)
+
+ res = call_stub([BoxInt(rffi.cast(lltype.Signed, fnptr)),
+ BoxInt(1), BoxInt(2)])
+ assert res.getint() == ord('c')
+
+ ARRAY = lltype.GcArray(lltype.Signed)
+ ARGS = [lltype.Float, lltype.Ptr(ARRAY)]
+ RES = lltype.Float
+
+ def f(a, b):
+ return float(b[0]) + a
+
+ fnptr = llhelper(lltype.Ptr(lltype.FuncType(ARGS, RES)), f)
+ descr2 = get_call_descr(c0, ARGS, RES)
+ a = lltype.malloc(ARRAY, 3)
+ opaquea = lltype.cast_opaque_ptr(llmemory.GCREF, a)
+ a[0] = 1
+ res = descr2.get_call_stub()([BoxInt(rffi.cast(lltype.Signed, fnptr)),
+ BoxFloat(3.5), BoxPtr(opaquea)])
+ assert res.getfloat() == 4.5
Modified: pypy/branch/cpython-extension/pypy/jit/backend/llsupport/test/test_gc.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/jit/backend/llsupport/test/test_gc.py (original)
+++ pypy/branch/cpython-extension/pypy/jit/backend/llsupport/test/test_gc.py Wed Mar 31 00:17:06 2010
@@ -9,7 +9,7 @@
def test_boehm():
- gc_ll_descr = GcLLDescr_boehm(None, None)
+ gc_ll_descr = GcLLDescr_boehm(None, None, None)
#
record = []
prev_funcptr_for_new = gc_ll_descr.funcptr_for_new
@@ -167,7 +167,8 @@
gcdescr = get_description(config_)
translator = FakeTranslator()
llop1 = FakeLLOp()
- gc_ll_descr = GcLLDescr_framework(gcdescr, FakeTranslator(), llop1)
+ gc_ll_descr = GcLLDescr_framework(gcdescr, FakeTranslator(), None,
+ llop1)
gc_ll_descr.initialize()
self.llop1 = llop1
self.gc_ll_descr = gc_ll_descr
Modified: pypy/branch/cpython-extension/pypy/jit/backend/x86/assembler.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/jit/backend/x86/assembler.py (original)
+++ pypy/branch/cpython-extension/pypy/jit/backend/x86/assembler.py Wed Mar 31 00:17:06 2010
@@ -1000,15 +1000,18 @@
# we use the following algorithm:
# - read the typeid from mem(locs[0]), i.e. at offset 0
# - keep the lower 16 bits read there
- # - multiply by 4 and use it as an offset in type_info_group.
+ # - multiply by 4 and use it as an offset in type_info_group
+ # - add 16 bytes, to go past the TYPE_INFO structure
loc = locs[1]
assert isinstance(loc, IMM32)
classptr = loc.value
# here, we have to go back from 'classptr' to the value expected
# from reading the 16 bits in the object header
+ from pypy.rpython.memory.gctypelayout import GCData
+ sizeof_ti = rffi.sizeof(GCData.TYPE_INFO)
type_info_group = llop.gc_get_type_info_group(llmemory.Address)
type_info_group = rffi.cast(lltype.Signed, type_info_group)
- expected_typeid = (classptr - type_info_group) >> 2
+ expected_typeid = (classptr - sizeof_ti - type_info_group) >> 2
mc.CMP16(mem(locs[0], 0), imm32(expected_typeid))
def genop_guard_guard_class(self, ign_1, guard_op, addr, locs, ign_2):
Modified: pypy/branch/cpython-extension/pypy/jit/backend/x86/runner.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/jit/backend/x86/runner.py (original)
+++ pypy/branch/cpython-extension/pypy/jit/backend/x86/runner.py Wed Mar 31 00:17:06 2010
@@ -1,6 +1,3 @@
-import sys
-import ctypes
-import py
from pypy.rpython.lltypesystem import lltype, llmemory, rffi
from pypy.rpython.llinterp import LLInterpreter
from pypy.rlib.objectmodel import we_are_translated
Modified: pypy/branch/cpython-extension/pypy/jit/backend/x86/test/conftest.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/jit/backend/x86/test/conftest.py (original)
+++ pypy/branch/cpython-extension/pypy/jit/backend/x86/test/conftest.py Wed Mar 31 00:17:06 2010
@@ -1,9 +1,9 @@
import py
from pypy.jit.backend import detect_cpu
-class Directory(py.test.collect.Directory):
+class Module(py.test.collect.Module):
def collect(self):
cpu = detect_cpu.autodetect()
if cpu != 'x86':
py.test.skip("x86 directory skipped: cpu is %r" % (cpu,))
- return super(Directory, self).collect()
+ return super(Module, self).collect()
Modified: pypy/branch/cpython-extension/pypy/jit/backend/x86/test/test_ztranslation.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/jit/backend/x86/test/test_ztranslation.py (original)
+++ pypy/branch/cpython-extension/pypy/jit/backend/x86/test/test_ztranslation.py Wed Mar 31 00:17:06 2010
@@ -1,10 +1,12 @@
-import py
+import py, os
+from pypy.tool.udir import udir
from pypy.rlib.jit import JitDriver, OPTIMIZER_FULL, unroll_parameters
from pypy.rlib.jit import PARAMETERS, dont_look_inside
from pypy.jit.metainterp.jitprof import Profiler
from pypy.jit.backend.x86.runner import CPU386
from pypy.jit.backend.test.support import CCompiledMixin
from pypy.jit.metainterp.policy import StopAtXPolicy
+from pypy.translator.translator import TranslationContext
class TestTranslationX86(CCompiledMixin):
CPUClass = CPU386
@@ -62,40 +64,6 @@
res = self.meta_interp(f, [40, -49])
assert res == f(40, -49)
- def test_external_exception_handling_translates(self):
- jitdriver = JitDriver(greens = [], reds = ['n', 'total'])
-
- @dont_look_inside
- def f(x):
- if x > 20:
- return 2
- raise ValueError
- @dont_look_inside
- def g(x):
- if x > 15:
- raise ValueError
- return 2
- def main(i):
- jitdriver.set_param("threshold", 3)
- jitdriver.set_param("trace_eagerness", 2)
- total = 0
- n = i
- while n > 3:
- jitdriver.can_enter_jit(n=n, total=total)
- jitdriver.jit_merge_point(n=n, total=total)
- try:
- total += f(n)
- except ValueError:
- total += 1
- try:
- total += g(n)
- except ValueError:
- total -= 1
- n -= 1
- return total * 10
- res = self.meta_interp(main, [40])
- assert res == main(40)
-
def test_direct_assembler_call_translates(self):
class Thing(object):
def __init__(self, val):
@@ -144,3 +112,75 @@
policy=StopAtXPolicy(change))
assert res == main(0)
+
+class TestTranslationRemoveTypePtrX86(CCompiledMixin):
+ CPUClass = CPU386
+
+ def _get_TranslationContext(self):
+ t = TranslationContext()
+ t.config.translation.gc = 'hybrid'
+ t.config.translation.gcrootfinder = 'asmgcc'
+ t.config.translation.list_comprehension_operations = True
+ t.config.translation.gcremovetypeptr = True
+ return t
+
+ def test_external_exception_handling_translates(self):
+ jitdriver = JitDriver(greens = [], reds = ['n', 'total'])
+
+ @dont_look_inside
+ def f(x):
+ if x > 20:
+ return 2
+ raise ValueError
+ @dont_look_inside
+ def g(x):
+ if x > 15:
+ raise ValueError
+ return 2
+ class Base:
+ def meth(self):
+ return 2
+ class Sub(Base):
+ def meth(self):
+ return 1
+ @dont_look_inside
+ def h(x):
+ if x < 2000:
+ return Sub()
+ else:
+ return Base()
+ def main(i):
+ jitdriver.set_param("threshold", 3)
+ jitdriver.set_param("trace_eagerness", 2)
+ total = 0
+ n = i
+ while n > 3:
+ jitdriver.can_enter_jit(n=n, total=total)
+ jitdriver.jit_merge_point(n=n, total=total)
+ try:
+ total += f(n)
+ except ValueError:
+ total += 1
+ try:
+ total += g(n)
+ except ValueError:
+ total -= 1
+ n -= h(n).meth() # this is to force a GUARD_CLASS
+ return total * 10
+
+ # XXX custom fishing, depends on the exact env var and format
+ logfile = udir.join('test_ztranslation.log')
+ os.environ['PYPYLOG'] = 'jit-log-opt:%s' % (logfile,)
+ try:
+ res = self.meta_interp(main, [40])
+ assert res == main(40)
+ finally:
+ del os.environ['PYPYLOG']
+
+ guard_class = 0
+ for line in open(str(logfile)):
+ if 'guard_class' in line:
+ guard_class += 1
+ # if we get many more guard_classes, it means that we generate
+ # guards that always fail
+ assert 0 < guard_class <= 4
Modified: pypy/branch/cpython-extension/pypy/jit/backend/x86/tool/viewcode.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/jit/backend/x86/tool/viewcode.py (original)
+++ pypy/branch/cpython-extension/pypy/jit/backend/x86/tool/viewcode.py Wed Mar 31 00:17:06 2010
@@ -34,7 +34,8 @@
def machine_code_dump(data, originaddr):
# the disassembler to use. 'objdump' writes GNU-style instructions.
# 'ndisasm' would use Intel syntax, but you need to fix the output parsing.
- objdump = 'objdump -b binary -m i386 --adjust-vma=%(origin)d -D %(file)s'
+ objdump = ('objdump -M intel -b binary -m i386 '
+ '--adjust-vma=%(origin)d -D %(file)s')
#
f = open(tmpfile, 'wb')
f.write(data)
Modified: pypy/branch/cpython-extension/pypy/lib/_ctypes/function.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/lib/_ctypes/function.py (original)
+++ pypy/branch/cpython-extension/pypy/lib/_ctypes/function.py Wed Mar 31 00:17:06 2010
@@ -359,6 +359,9 @@
# No output parameter, return the actual function result.
return retval
+ def __nonzero__(self):
+ return bool(self._buffer[0])
+
def __del__(self):
if self._needs_free:
# XXX we need to find a bad guy here
Modified: pypy/branch/cpython-extension/pypy/lib/app_test/ctypes_tests/test_cast.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/lib/app_test/ctypes_tests/test_cast.py (original)
+++ pypy/branch/cpython-extension/pypy/lib/app_test/ctypes_tests/test_cast.py Wed Mar 31 00:17:06 2010
@@ -84,4 +84,6 @@
my_sqrt = lib.my_sqrt
sqrt = cast(cast(my_sqrt, c_void_p), CFUNCTYPE(c_double, c_double))
assert sqrt(4.0) == 2.0
+ assert not cast(0, CFUNCTYPE(c_int))
+
Modified: pypy/branch/cpython-extension/pypy/lib/app_test/ctypes_tests/test_funcptr.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/lib/app_test/ctypes_tests/test_funcptr.py (original)
+++ pypy/branch/cpython-extension/pypy/lib/app_test/ctypes_tests/test_funcptr.py Wed Mar 31 00:17:06 2010
@@ -131,6 +131,8 @@
assert strtok(None, "\n") == None
def test_from_address(self):
+ py.test.skip("This test needs mmap to make sure the"
+ " code is executable, please rewrite me")
def make_function():
proto = CFUNCTYPE(c_int)
a=create_string_buffer(
Modified: pypy/branch/cpython-extension/pypy/lib/app_test/test_dbm_extra.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/lib/app_test/test_dbm_extra.py (original)
+++ pypy/branch/cpython-extension/pypy/lib/app_test/test_dbm_extra.py Wed Mar 31 00:17:06 2010
@@ -1,6 +1,9 @@
import py
-from pypy.lib import dbm
from pypy.tool.udir import udir
+try:
+ from pypy.lib import dbm
+except ImportError, e:
+ py.test.skip(e)
def test_get():
path = str(udir.join('test_dbm_extra.test_get'))
Modified: pypy/branch/cpython-extension/pypy/lib/resource.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/lib/resource.py (original)
+++ pypy/branch/cpython-extension/pypy/lib/resource.py Wed Mar 31 00:17:06 2010
@@ -28,8 +28,8 @@
class timeval(Structure):
_fields_ = (
- ("tv_sec", c_int),
- ("tv_usec", c_int),
+ ("tv_sec", c_long),
+ ("tv_usec", c_long),
)
def __str__(self):
return "(%s, %s)" % (self.tv_sec, self.tv_usec)
Modified: pypy/branch/cpython-extension/pypy/module/__pypy__/interp_magic.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/__pypy__/interp_magic.py (original)
+++ pypy/branch/cpython-extension/pypy/module/__pypy__/interp_magic.py Wed Mar 31 00:17:06 2010
@@ -1,6 +1,7 @@
from pypy.interpreter.error import OperationError
from pypy.interpreter.gateway import ObjSpace
from pypy.rlib.objectmodel import we_are_translated
+from pypy.objspace.std.typeobject import MethodCache
def internal_repr(space, w_object):
return space.wrap('%r' % (w_object,))
@@ -24,13 +25,15 @@
"""Return a tuple (method_cache_hits, method_cache_misses) for calls to
methods with the name."""
assert space.config.objspace.std.withmethodcachecounter
- return space.newtuple([space.newint(space.method_cache_hits.get(name, 0)),
- space.newint(space.method_cache_misses.get(name, 0)),])
+ cache = space.fromcache(MethodCache)
+ return space.newtuple([space.newint(cache.hits.get(name, 0)),
+ space.newint(cache.misses.get(name, 0))])
method_cache_counter.unwrap_spec = [ObjSpace, str]
def reset_method_cache_counter(space):
"""Reset the method cache counter to zero for all method names."""
assert space.config.objspace.std.withmethodcachecounter
- space.method_cache_misses = {}
- space.method_cache_hits = {}
+ cache = space.fromcache(MethodCache)
+ cache.misses = {}
+ cache.hits = {}
Modified: pypy/branch/cpython-extension/pypy/module/_file/__init__.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_file/__init__.py (original)
+++ pypy/branch/cpython-extension/pypy/module/_file/__init__.py Wed Mar 31 00:17:06 2010
@@ -24,8 +24,8 @@
MixedModule.__init__(self, space, *args)
def shutdown(self, space):
- # at shutdown, flush all open streams
- from pypy.module._file.interp_file import getopenstreams
+ # at shutdown, flush all open streams. Ignore I/O errors.
+ from pypy.module._file.interp_file import getopenstreams, StreamErrors
openstreams = getopenstreams(space)
while openstreams:
for stream in openstreams.keys():
@@ -34,7 +34,10 @@
except KeyError:
pass # key was removed in the meantime
else:
- stream.flush()
+ try:
+ stream.flush()
+ except StreamErrors:
+ pass
def setup_after_space_initialization(self):
from pypy.module._file.interp_file import W_File
Modified: pypy/branch/cpython-extension/pypy/module/_minimal_curses/__init__.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_minimal_curses/__init__.py (original)
+++ pypy/branch/cpython-extension/pypy/module/_minimal_curses/__init__.py Wed Mar 31 00:17:06 2010
@@ -1,7 +1,10 @@
try:
import _curses
except ImportError:
- import _minimal_curses as _curses # when running on top of pypy-c
+ try:
+ import _minimal_curses as _curses # when running on top of pypy-c
+ except ImportError:
+ import py; py.test.skip("no _curses module") # no _curses at all
from pypy.interpreter.mixedmodule import MixedModule
from pypy.module._minimal_curses import fficurses
Modified: pypy/branch/cpython-extension/pypy/module/_socket/interp_func.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_socket/interp_func.py (original)
+++ pypy/branch/cpython-extension/pypy/module/_socket/interp_func.py Wed Mar 31 00:17:06 2010
@@ -2,6 +2,7 @@
from pypy.module._socket.interp_socket import converted_error, W_RSocket
from pypy.rlib import rsocket
from pypy.rlib.rsocket import SocketError
+from pypy.rlib.rarithmetic import r_uint
from pypy.interpreter.error import OperationError, operationerrfmt
def gethostname(space):
@@ -152,30 +153,24 @@
return space.newtuple([space.wrap(sock1), space.wrap(sock2)])
socketpair.unwrap_spec = [ObjSpace, int, int, int]
+# The following 4 functions refuse all negative numbers, like CPython 2.6.
+# They could also check that the argument is not too large, but CPython 2.6
+# is not doing that consistently.
def ntohs(space, x):
"""ntohs(integer) -> integer
Convert a 16-bit integer from network to host byte order.
"""
return space.wrap(rsocket.ntohs(x))
-ntohs.unwrap_spec = [ObjSpace, int]
+ntohs.unwrap_spec = [ObjSpace, r_uint]
-def ntohl(space, w_x):
+def ntohl(space, x):
"""ntohl(integer) -> integer
Convert a 32-bit integer from network to host byte order.
"""
- if space.is_true(space.isinstance(w_x, space.w_int)):
- x = space.int_w(w_x)
- elif space.is_true(space.isinstance(w_x, space.w_long)):
- x = space.uint_w(w_x)
- else:
- raise operationerrfmt(space.w_TypeError,
- "expected int/long, %s found",
- space.type(w_x).getname(space, "?"))
-
return space.wrap(rsocket.ntohl(x))
-ntohl.unwrap_spec = [ObjSpace, W_Root]
+ntohl.unwrap_spec = [ObjSpace, r_uint]
def htons(space, x):
"""htons(integer) -> integer
@@ -183,24 +178,15 @@
Convert a 16-bit integer from host to network byte order.
"""
return space.wrap(rsocket.htons(x))
-htons.unwrap_spec = [ObjSpace, int]
+htons.unwrap_spec = [ObjSpace, r_uint]
-def htonl(space, w_x):
+def htonl(space, x):
"""htonl(integer) -> integer
Convert a 32-bit integer from host to network byte order.
"""
- if space.is_true(space.isinstance(w_x, space.w_int)):
- x = space.int_w(w_x)
- elif space.is_true(space.isinstance(w_x, space.w_long)):
- x = space.uint_w(w_x)
- else:
- raise operationerrfmt(space.w_TypeError,
- "expected int/long, %s found",
- space.type(w_x).getname(space, "?"))
-
return space.wrap(rsocket.htonl(x))
-htonl.unwrap_spec = [ObjSpace, W_Root]
+htonl.unwrap_spec = [ObjSpace, r_uint]
def inet_aton(space, ip):
"""inet_aton(string) -> packed 32-bit IP representation
Modified: pypy/branch/cpython-extension/pypy/module/_socket/test/test_sock_app.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_socket/test/test_sock_app.py (original)
+++ pypy/branch/cpython-extension/pypy/module/_socket/test/test_sock_app.py Wed Mar 31 00:17:06 2010
@@ -32,13 +32,17 @@
def test_gethostbyaddr():
host = "localhost"
+ expected = socket.gethostbyaddr(host)
+ expecteds = (expected, expected[:2]+(['0.0.0.0'],))
ip = space.appexec([w_socket, space.wrap(host)],
"(_socket, host): return _socket.gethostbyaddr(host)")
- assert space.unwrap(ip) == socket.gethostbyaddr(host)
+ assert space.unwrap(ip) in expecteds
host = "127.0.0.1"
+ expected = socket.gethostbyaddr(host)
+ expecteds = (expected, expected[:2]+(['0.0.0.0'],))
ip = space.appexec([w_socket, space.wrap(host)],
"(_socket, host): return _socket.gethostbyaddr(host)")
- assert space.unwrap(ip) == socket.gethostbyaddr(host)
+ assert space.unwrap(ip) in expecteds
def test_getservbyname():
name = "smtp"
@@ -108,6 +112,9 @@
w_n = space.appexec([w_socket, space.wrap(125)],
"(_socket, x): return _socket.ntohl(x)")
assert space.unwrap(w_n) == socket.ntohl(125)
+ w_n = space.appexec([w_socket, space.wrap(0x89abcdef)],
+ "(_socket, x): return _socket.ntohl(x)")
+ assert space.unwrap(w_n) in (0x89abcdef, 0xefcdab89)
def test_htons():
w_n = space.appexec([w_socket, space.wrap(125)],
@@ -118,6 +125,9 @@
w_n = space.appexec([w_socket, space.wrap(125)],
"(_socket, x): return _socket.htonl(x)")
assert space.unwrap(w_n) == socket.htonl(125)
+ w_n = space.appexec([w_socket, space.wrap(0x89abcdef)],
+ "(_socket, x): return _socket.htonl(x)")
+ assert space.unwrap(w_n) in (0x89abcdef, 0xefcdab89)
def test_aton_ntoa():
ip = '123.45.67.89'
@@ -314,9 +324,12 @@
import _socket, os
s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM, 0)
# XXX temporarily we use codespeak to test, will have more robust tests in
- # the absence of a network connection later when mroe parts of the socket
- # API are implemented.
- s.connect(("codespeak.net", 80))
+ # the absence of a network connection later when more parts of the socket
+ # API are implemented. currently skip the test if there is no connection.
+ try:
+ s.connect(("codespeak.net", 80))
+ except _socket.gaierror, ex:
+ skip("GAIError - probably no connection: %s" % str(ex.args))
name = s.getpeername() # Will raise socket.error if not connected
assert name[1] == 80
s.close()
@@ -335,6 +348,7 @@
s.close()
def test_NtoH(self):
+ import sys
import _socket as socket
# This just checks that htons etc. are their own inverse,
# when looking at the lower 16 or 32 bits.
@@ -348,7 +362,28 @@
swapped = func(mask)
assert swapped & mask == mask
try:
- func(1L<<34)
+ func(-1)
+ except (OverflowError, ValueError):
+ pass
+ else:
+ assert False
+ try:
+ func(sys.maxint*2+2)
+ except OverflowError:
+ pass
+ else:
+ assert False
+
+ def test_NtoH_overflow(self):
+ skip("we are not checking for overflowing values yet")
+ import _socket as socket
+ # Checks that we cannot give too large values to htons etc.
+ # Skipped for now; CPython 2.6 is also not consistent.
+ sizes = {socket.htonl: 32, socket.ntohl: 32,
+ socket.htons: 16, socket.ntohs: 16}
+ for func, size in sizes.items():
+ try:
+ func(1L << size)
except OverflowError:
pass
else:
@@ -399,9 +434,12 @@
import _socket, os
s = _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM, 0)
# XXX temporarily we use codespeak to test, will have more robust tests in
- # the absence of a network connection later when mroe parts of the socket
- # API are implemented.
- s.connect(("codespeak.net", 80))
+ # the absence of a network connection later when more parts of the socket
+ # API are implemented. currently skip the test if there is no connection.
+ try:
+ s.connect(("codespeak.net", 80))
+ except _socket.gaierror, ex:
+ skip("GAIError - probably no connection: %s" % str(ex.args))
s.send(buffer(''))
s.sendall(buffer(''))
s.send(u'')
Modified: pypy/branch/cpython-extension/pypy/module/_sre/interp_sre.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_sre/interp_sre.py (original)
+++ pypy/branch/cpython-extension/pypy/module/_sre/interp_sre.py Wed Mar 31 00:17:06 2010
@@ -177,10 +177,20 @@
state = space.interp_w(W_State, w_state)
pattern_codes = [intmask(space.uint_w(code)) for code
in space.unpackiterable(w_pattern_codes)]
- return space.newbool(state.search(pattern_codes))
+ try:
+ res = state.search(pattern_codes)
+ except RuntimeError:
+ raise OperationError(space.w_RuntimeError,
+ space.wrap("Internal re error"))
+ return space.newbool(res)
def w_match(space, w_state, w_pattern_codes):
state = space.interp_w(W_State, w_state)
pattern_codes = [intmask(space.uint_w(code)) for code
in space.unpackiterable(w_pattern_codes)]
- return space.newbool(state.match(pattern_codes))
+ try:
+ res = state.match(pattern_codes)
+ except RuntimeError:
+ raise OperationError(space.w_RuntimeError,
+ space.wrap("Internal re error"))
+ return space.newbool(res)
Modified: pypy/branch/cpython-extension/pypy/module/_weakref/interp__weakref.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_weakref/interp__weakref.py (original)
+++ pypy/branch/cpython-extension/pypy/module/_weakref/interp__weakref.py Wed Mar 31 00:17:06 2010
@@ -23,7 +23,7 @@
for i in range(len(self.refs_weak) - 1, -1, -1):
w_ref = self.refs_weak[i]()
if w_ref is not None:
- w_ref.activate_callback()
+ self.space.user_del_action.register_weakref_callback(w_ref)
def clear_all_weakrefs(self):
"""Clear all weakrefs. This is called when an app-level object has
Modified: pypy/branch/cpython-extension/pypy/module/_weakref/test/test_weakref.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/_weakref/test/test_weakref.py (original)
+++ pypy/branch/cpython-extension/pypy/module/_weakref/test/test_weakref.py Wed Mar 31 00:17:06 2010
@@ -411,3 +411,15 @@
a = A()
assert _weakref.ref(a) == a
+
+ def test_callback_raises(self):
+ import _weakref, gc
+ class A(object):
+ pass
+ a1 = A()
+ def callback(ref):
+ explode
+ ref1 = _weakref.ref(a1, callback)
+ del a1
+ gc.collect()
+ assert ref1() is None
Modified: pypy/branch/cpython-extension/pypy/module/imp/importing.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/imp/importing.py (original)
+++ pypy/branch/cpython-extension/pypy/module/imp/importing.py Wed Mar 31 00:17:06 2010
@@ -324,6 +324,7 @@
modtype, suffix, filemode = find_modtype(space, filepart)
try:
if modtype in (PY_SOURCE, PY_COMPILED):
+ assert suffix is not None
filename = filepart + suffix
stream = streamio.open_file_as_stream(filename, filemode)
try:
Modified: pypy/branch/cpython-extension/pypy/module/mmap/interp_mmap.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/mmap/interp_mmap.py (original)
+++ pypy/branch/cpython-extension/pypy/module/mmap/interp_mmap.py Wed Mar 31 00:17:06 2010
@@ -57,7 +57,8 @@
try:
return self.space.wrap(self.mmap.file_size())
except OSError, e:
- raise wrap_oserror(self.space, e, 'w_EnvironmentError')
+ raise wrap_oserror(self.space, e,
+ exception_name='w_EnvironmentError')
descr_size.unwrap_spec = ['self']
def write(self, data):
@@ -87,7 +88,8 @@
raise OperationError(self.space.w_ValueError,
self.space.wrap(v.message))
except OSError, e:
- raise wrap_oserror(self.space, e, 'w_EnvironmentError')
+ raise wrap_oserror(self.space, e,
+ exception_name='w_EnvironmentError')
flush.unwrap_spec = ['self', int, int]
def move(self, dest, src, count):
@@ -104,7 +106,8 @@
try:
self.mmap.resize(newsize)
except OSError, e:
- raise wrap_oserror(self.space, e, 'w_EnvironmentError')
+ raise wrap_oserror(self.space, e,
+ exception_name='w_EnvironmentError')
resize.unwrap_spec = ['self', int]
def __len__(self):
@@ -224,7 +227,7 @@
return space.wrap(W_MMap(space, rmmap.mmap(fileno, length,
flags, prot, access)))
except OSError, e:
- raise wrap_oserror(space, e, 'w_EnvironmentError')
+ raise wrap_oserror(space, e, exception_name='w_EnvironmentError')
except RValueError, e:
raise OperationError(space.w_ValueError, space.wrap(e.message))
except RTypeError, e:
@@ -238,7 +241,7 @@
return space.wrap(W_MMap(space, rmmap.mmap(fileno, length,
tagname, access)))
except OSError, e:
- raise wrap_oserror(space, e, 'w_EnvironmentError')
+ raise wrap_oserror(space, e, exception_name='w_EnvironmentError')
except RValueError, e:
raise OperationError(space.w_ValueError, space.wrap(e.message))
except RTypeError, e:
Modified: pypy/branch/cpython-extension/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/posix/interp_posix.py (original)
+++ pypy/branch/cpython-extension/pypy/module/posix/interp_posix.py Wed Mar 31 00:17:06 2010
@@ -18,9 +18,9 @@
try:
fd = os.open(fname, flag, mode)
except OSError, e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror(space, e, fname)
return space.wrap(fd)
-open.unwrap_spec = [ObjSpace, str, int, int]
+open.unwrap_spec = [ObjSpace, str, "c_int", "c_int"]
def lseek(space, fd, pos, how):
"""Set the current position of a file descriptor. Return the new position.
@@ -32,7 +32,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(pos)
-lseek.unwrap_spec = [ObjSpace, int, r_longlong, int]
+lseek.unwrap_spec = [ObjSpace, "c_int", r_longlong, "c_int"]
def isatty(space, fd):
"""Return True if 'fd' is an open file descriptor connected to the
@@ -43,7 +43,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(res)
-isatty.unwrap_spec = [ObjSpace, int]
+isatty.unwrap_spec = [ObjSpace, "c_int"]
def read(space, fd, buffersize):
"""Read data from a file descriptor."""
@@ -53,7 +53,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(s)
-read.unwrap_spec = [ObjSpace, int, int]
+read.unwrap_spec = [ObjSpace, "c_int", int]
def write(space, fd, data):
"""Write a string to a file descriptor. Return the number of bytes
@@ -64,7 +64,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(res)
-write.unwrap_spec = [ObjSpace, int, 'bufferstr']
+write.unwrap_spec = [ObjSpace, "c_int", 'bufferstr']
def close(space, fd):
"""Close a file descriptor (for low level IO)."""
@@ -72,12 +72,12 @@
os.close(fd)
except OSError, e:
raise wrap_oserror(space, e)
-close.unwrap_spec = [ObjSpace, int]
+close.unwrap_spec = [ObjSpace, "c_int"]
def closerange(fd_low, fd_high):
"""Closes all file descriptors in [fd_low, fd_high), ignoring errors."""
rposix.closerange(fd_low, fd_high)
-closerange.unwrap_spec = [int, int]
+closerange.unwrap_spec = ["c_int", "c_int"]
def ftruncate(space, fd, length):
"""Truncate a file to a specified length."""
@@ -85,21 +85,21 @@
os.ftruncate(fd, length)
except OSError, e:
raise wrap_oserror(space, e)
-ftruncate.unwrap_spec = [ObjSpace, int, r_longlong]
+ftruncate.unwrap_spec = [ObjSpace, "c_int", r_longlong]
def fsync(space, fd):
try:
os.fsync(fd)
except OSError, e:
raise wrap_oserror(space, e)
-fsync.unwrap_spec = [ObjSpace, int]
+fsync.unwrap_spec = [ObjSpace, "c_int"]
def fdatasync(space, fd):
try:
os.fdatasync(fd)
except OSError, e:
raise wrap_oserror(space, e)
-fdatasync.unwrap_spec = [ObjSpace, int]
+fdatasync.unwrap_spec = [ObjSpace, "c_int"]
# ____________________________________________________________
@@ -157,7 +157,7 @@
raise wrap_oserror(space, e)
else:
return build_stat_result(space, st)
-fstat.unwrap_spec = [ObjSpace, int]
+fstat.unwrap_spec = [ObjSpace, "c_int"]
def stat(space, path):
"""Perform a stat system call on the given path. Return an object
@@ -177,7 +177,7 @@
try:
st = os.stat(path)
except OSError, e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror(space, e, path)
else:
return build_stat_result(space, st)
stat.unwrap_spec = [ObjSpace, str]
@@ -187,7 +187,7 @@
try:
st = os.lstat(path)
except OSError, e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror(space, e, path)
else:
return build_stat_result(space, st)
lstat.unwrap_spec = [ObjSpace, str]
@@ -221,7 +221,7 @@
raise wrap_oserror(space, e)
else:
return space.wrap(newfd)
-dup.unwrap_spec = [ObjSpace, int]
+dup.unwrap_spec = [ObjSpace, "c_int"]
def dup2(space, old_fd, new_fd):
"""Duplicate a file descriptor."""
@@ -229,7 +229,7 @@
os.dup2(old_fd, new_fd)
except OSError, e:
raise wrap_oserror(space, e)
-dup2.unwrap_spec = [ObjSpace, int, int]
+dup2.unwrap_spec = [ObjSpace, "c_int", "c_int"]
def access(space, path, mode):
"""
@@ -244,10 +244,10 @@
try:
ok = os.access(path, mode)
except OSError, e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror(space, e, path)
else:
return space.wrap(ok)
-access.unwrap_spec = [ObjSpace, str, int]
+access.unwrap_spec = [ObjSpace, str, "c_int"]
def times(space):
@@ -283,7 +283,7 @@
try:
os.unlink(path)
except OSError, e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror(space, e, path)
unlink.unwrap_spec = [ObjSpace, str]
def remove(space, path):
@@ -291,7 +291,7 @@
try:
os.unlink(path)
except OSError, e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror(space, e, path)
remove.unwrap_spec = [ObjSpace, str]
def _getfullpathname(space, path):
@@ -300,7 +300,7 @@
try:
fullpath = posix._getfullpathname(path)
except OSError, e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror(space, e, path)
else:
return space.wrap(fullpath)
_getfullpathname.unwrap_spec = [ObjSpace, str]
@@ -326,7 +326,7 @@
try:
os.chdir(path)
except OSError, e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror(space, e, path)
chdir.unwrap_spec = [ObjSpace, str]
def mkdir(space, path, mode=0777):
@@ -334,15 +334,15 @@
try:
os.mkdir(path, mode)
except OSError, e:
- raise wrap_oserror(space, e)
-mkdir.unwrap_spec = [ObjSpace, str, int]
+ raise wrap_oserror(space, e, path)
+mkdir.unwrap_spec = [ObjSpace, str, "c_int"]
def rmdir(space, path):
"""Remove a directory."""
try:
os.rmdir(path)
except OSError, e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror(space, e, path)
rmdir.unwrap_spec = [ObjSpace, str]
def strerror(space, errno):
@@ -353,7 +353,7 @@
raise OperationError(space.w_ValueError,
space.wrap("strerror() argument out of range"))
return space.wrap(text)
-strerror.unwrap_spec = [ObjSpace, int]
+strerror.unwrap_spec = [ObjSpace, "c_int"]
# ____________________________________________________________
@@ -420,7 +420,7 @@
try:
result = os.listdir(dirname)
except OSError, e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror(space, e, dirname)
result_w = [space.wrap(s) for s in result]
return space.newlist(result_w)
listdir.unwrap_spec = [ObjSpace, str]
@@ -439,8 +439,8 @@
try:
os.chmod(path, mode)
except OSError, e:
- raise wrap_oserror(space, e)
-chmod.unwrap_spec = [ObjSpace, str, int]
+ raise wrap_oserror(space, e, path)
+chmod.unwrap_spec = [ObjSpace, str, "c_int"]
def rename(space, old, new):
"Rename a file or directory."
@@ -454,7 +454,7 @@
"Set the current numeric umask and return the previous umask."
prevmask = os.umask(mask)
return space.wrap(prevmask)
-umask.unwrap_spec = [ObjSpace, int]
+umask.unwrap_spec = [ObjSpace, "c_int"]
def getpid(space):
"Return the current process id."
@@ -471,7 +471,7 @@
os.kill(pid, sig)
except OSError, e:
raise wrap_oserror(space, e)
-kill.unwrap_spec = [ObjSpace, int, int]
+kill.unwrap_spec = [ObjSpace, "c_int", "c_int"]
def abort(space):
"""Abort the interpreter immediately. This 'dumps core' or otherwise fails
@@ -501,12 +501,11 @@
try:
result = os.readlink(path)
except OSError, e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror(space, e, path)
return space.wrap(result)
readlink.unwrap_spec = [ObjSpace, str]
def fork(space):
-
try:
pid = os.fork()
except OSError, e:
@@ -531,11 +530,11 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.newtuple([space.wrap(pid), space.wrap(status)])
-waitpid.unwrap_spec = [ObjSpace, int, int]
+waitpid.unwrap_spec = [ObjSpace, "c_int", "c_int"]
def _exit(space, status):
os._exit(status)
-_exit.unwrap_spec = [ObjSpace, int]
+_exit.unwrap_spec = [ObjSpace, "c_int"]
def execv(space, command, w_args):
""" execv(path, args)
@@ -589,7 +588,7 @@
os.utime(path, None)
return
except OSError, e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror(space, e, path)
try:
msg = "utime() arg 2 must be a tuple (atime, mtime) or None"
args_w = space.fixedview(w_tuple)
@@ -599,7 +598,7 @@
modtime = space.float_w(args_w[1])
os.utime(path, (actime, modtime))
except OSError, e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror(space, e, path)
except OperationError, e:
if not e.match(space, space.w_TypeError):
raise
@@ -649,7 +648,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-setuid.unwrap_spec = [ObjSpace, int]
+setuid.unwrap_spec = [ObjSpace, "c_nonnegint"]
def seteuid(space, arg):
""" seteuid(uid)
@@ -661,7 +660,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-seteuid.unwrap_spec = [ObjSpace, int]
+seteuid.unwrap_spec = [ObjSpace, "c_nonnegint"]
def setgid(space, arg):
""" setgid(gid)
@@ -673,7 +672,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-setgid.unwrap_spec = [ObjSpace, int]
+setgid.unwrap_spec = [ObjSpace, "c_nonnegint"]
def setegid(space, arg):
""" setegid(gid)
@@ -685,7 +684,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-setegid.unwrap_spec = [ObjSpace, int]
+setegid.unwrap_spec = [ObjSpace, "c_nonnegint"]
def chroot(space, path):
""" chroot(path)
@@ -695,7 +694,7 @@
try:
os.chroot(path)
except OSError, e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror(space, e, path)
return space.w_None
chroot.unwrap_spec = [ObjSpace, str]
@@ -761,7 +760,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.wrap(pgid)
-getpgid.unwrap_spec = [ObjSpace, int]
+getpgid.unwrap_spec = [ObjSpace, "c_int"]
def setpgid(space, pid, pgrp):
""" setpgid(pid, pgrp)
@@ -773,7 +772,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-setpgid.unwrap_spec = [ObjSpace, int, int]
+setpgid.unwrap_spec = [ObjSpace, "c_int", "c_int"]
def setreuid(space, ruid, euid):
""" setreuid(ruid, euid)
@@ -785,7 +784,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-setreuid.unwrap_spec = [ObjSpace, int, int]
+setreuid.unwrap_spec = [ObjSpace, "c_nonnegint", "c_nonnegint"]
def setregid(space, rgid, egid):
""" setregid(rgid, egid)
@@ -797,7 +796,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.w_None
-setregid.unwrap_spec = [ObjSpace, int, int]
+setregid.unwrap_spec = [ObjSpace, "c_nonnegint", "c_nonnegint"]
def getsid(space, pid):
""" getsid(pid) -> sid
@@ -809,7 +808,7 @@
except OSError, e:
raise wrap_oserror(space, e)
return space.wrap(sid)
-getsid.unwrap_spec = [ObjSpace, int]
+getsid.unwrap_spec = [ObjSpace, "c_int"]
def setsid(space):
""" setsid()
@@ -831,7 +830,7 @@
def WSTAR(space, status):
return space.newbool(getattr(os, name)(status))
WSTAR.__doc__ = getattr(os, name).__doc__
- WSTAR.unwrap_spec = [ObjSpace, int]
+ WSTAR.unwrap_spec = [ObjSpace, "c_int"]
WSTAR.func_name = name
return WSTAR
@@ -845,7 +844,7 @@
return space.wrap(os.ttyname(fd))
except OSError, e:
raise wrap_oserror(space, e)
-ttyname.unwrap_spec = [ObjSpace, int]
+ttyname.unwrap_spec = [ObjSpace, "c_int"]
def sysconf(space, w_num_or_name):
# XXX slightly non-nice, reuses the sysconf of the underlying os module
@@ -864,9 +863,9 @@
try:
os.chown(path, uid, gid)
except OSError, e:
- raise wrap_oserror(space, e)
+ raise wrap_oserror(space, e, path)
return space.w_None
-chown.unwrap_spec = [ObjSpace, str, int, int]
+chown.unwrap_spec = [ObjSpace, str, "c_nonnegint", "c_nonnegint"]
if _WIN:
from pypy.rlib import rwin32
Modified: pypy/branch/cpython-extension/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/posix/test/test_posix2.py (original)
+++ pypy/branch/cpython-extension/pypy/module/posix/test/test_posix2.py Wed Mar 31 00:17:06 2010
@@ -133,18 +133,27 @@
assert st.st_mtime == 42.1
assert st.st_ctime == 43
+ def test_stat_lstat(self):
+ import stat
+ st = self.posix.stat(".")
+ assert stat.S_ISDIR(st.st_mode)
+ st = self.posix.lstat(".")
+ assert stat.S_ISDIR(st.st_mode)
+
def test_stat_exception(self):
import sys, errno
- try:
- self.posix.stat("nonexistentdir/nonexistentfile")
- except OSError, e:
- assert e.errno == errno.ENOENT
- # On Windows, when the parent directory does not exist,
- # the winerror is 3 (cannot find the path specified)
- # instead of 2 (cannot find the file specified)
- if sys.platform == 'win32':
- assert isinstance(e, WindowsError)
- assert e.winerror == 3
+ for fn in [self.posix.stat, self.posix.lstat]:
+ try:
+ fn("nonexistentdir/nonexistentfile")
+ except OSError, e:
+ assert e.errno == errno.ENOENT
+ assert e.filename == "nonexistentdir/nonexistentfile"
+ # On Windows, when the parent directory does not exist,
+ # the winerror is 3 (cannot find the path specified)
+ # instead of 2 (cannot find the file specified)
+ if sys.platform == 'win32':
+ assert isinstance(e, WindowsError)
+ assert e.winerror == 3
def test_pickle(self):
import pickle, os
@@ -160,11 +169,48 @@
posix = self.posix
try:
posix.open('qowieuqwoeiu', 0, 0)
- except OSError:
- pass
+ except OSError, e:
+ assert e.filename == 'qowieuqwoeiu'
else:
assert 0
+ def test_filename_exception(self):
+ for fn in [self.posix.unlink, self.posix.remove,
+ self.posix.chdir, self.posix.mkdir, self.posix.rmdir,
+ self.posix.listdir, self.posix.readlink,
+ self.posix.chroot]:
+ try:
+ fn('qowieuqw/oeiu')
+ except OSError, e:
+ assert e.filename == 'qowieuqw/oeiu'
+ else:
+ assert 0
+
+ def test_chmod_exception(self):
+ try:
+ self.posix.chmod('qowieuqw/oeiu', 0)
+ except OSError, e:
+ assert e.filename == 'qowieuqw/oeiu'
+ else:
+ assert 0
+
+ def test_chown_exception(self):
+ try:
+ self.posix.chown('qowieuqw/oeiu', 0, 0)
+ except OSError, e:
+ assert e.filename == 'qowieuqw/oeiu'
+ else:
+ assert 0
+
+ def test_utime_exception(self):
+ for arg in [None, (0, 0)]:
+ try:
+ self.posix.utime('qowieuqw/oeiu', arg)
+ except OSError, e:
+ assert e.filename == 'qowieuqw/oeiu'
+ else:
+ assert 0
+
def test_functions_raise_error(self):
def ex(func, *args):
try:
@@ -309,7 +355,8 @@
os = self.posix
for i in range(5):
stream = os.popen('echo 1')
- assert stream.read() == '1\n'
+ res = stream.read()
+ assert res == '1\n'
stream.close()
if hasattr(__import__(os.name), '_getfullpathname'):
@@ -380,7 +427,7 @@
if hasattr(os, 'setuid'):
def test_os_setuid_error(self):
os = self.posix
- raises(OSError, os.setuid, -100000)
+ raises((OSError, ValueError, OverflowError), os.setuid, -100000)
if hasattr(os, 'getgid'):
def test_os_getgid(self):
@@ -396,13 +443,13 @@
if hasattr(os, 'setgid'):
def test_os_setgid_error(self):
os = self.posix
- raises(OSError, os.setgid, -100000)
+ raises((OSError, ValueError, OverflowError), os.setgid, -100000)
if hasattr(os, 'getsid'):
def test_os_getsid(self):
os = self.posix
assert os.getsid(0) == self.getsid0
- raises(OSError, os.getsid, -100000)
+ raises((OSError, ValueError, OverflowError), os.getsid, -100000)
if hasattr(os, 'sysconf'):
def test_os_sysconf(self):
Modified: pypy/branch/cpython-extension/pypy/module/pyexpat/test/test_build.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/pyexpat/test/test_build.py (original)
+++ pypy/branch/cpython-extension/pypy/module/pyexpat/test/test_build.py Wed Mar 31 00:17:06 2010
@@ -4,8 +4,12 @@
from pypy.rpython.lltypesystem import rffi, lltype
from pypy.rpython.tool.rffi_platform import CompilationError
-import os, pyexpat
+import os
import py
+try:
+ import pyexpat
+except ImportError:
+ py.test.skip("No module expat")
try:
from pypy.module.pyexpat import interp_pyexpat
Modified: pypy/branch/cpython-extension/pypy/module/pypyjit/interp_jit.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/pypyjit/interp_jit.py (original)
+++ pypy/branch/cpython-extension/pypy/module/pypyjit/interp_jit.py Wed Mar 31 00:17:06 2010
@@ -78,13 +78,13 @@
except ExitFrame:
return self.popvalue()
- def JUMP_ABSOLUTE(f, jumpto, _, ec=None):
+ def jump_absolute(self, jumpto, _, ec=None):
if we_are_jitted():
- f.last_instr = intmask(jumpto)
- ec.bytecode_trace(f)
- jumpto = r_uint(f.last_instr)
- pypyjitdriver.can_enter_jit(frame=f, ec=ec, next_instr=jumpto,
- pycode=f.getcode())
+ self.last_instr = intmask(jumpto)
+ ec.bytecode_trace(self)
+ jumpto = r_uint(self.last_instr)
+ pypyjitdriver.can_enter_jit(frame=self, ec=ec, next_instr=jumpto,
+ pycode=self.getcode())
return jumpto
Modified: pypy/branch/cpython-extension/pypy/module/rctime/interp_time.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/rctime/interp_time.py (original)
+++ pypy/branch/cpython-extension/pypy/module/rctime/interp_time.py Wed Mar 31 00:17:06 2010
@@ -452,20 +452,18 @@
i = 1024
while True:
- outbuf = lltype.malloc(rffi.CCHARP.TO, i + 1, flavor='raw')
- buflen = c_strftime(outbuf, i, format, buf_value)
-
- if buflen > 0 or i >= 256 * len(format):
- # if the buffer is 256 times as long as the format,
- # it's probably not failing for lack of room!
- # More likely, the format yields an empty result,
- # e.g. an empty format, or %Z when the timezone
- # is unknown.
- if buflen < 0: buflen = 0 # should not occur
- outbuf[buflen] = '\x00'
- result = rffi.charp2str(outbuf)
+ outbuf = lltype.malloc(rffi.CCHARP.TO, i, flavor='raw')
+ try:
+ buflen = c_strftime(outbuf, i, format, buf_value)
+ if buflen > 0 or i >= 256 * len(format):
+ # if the buffer is 256 times as long as the format,
+ # it's probably not failing for lack of room!
+ # More likely, the format yields an empty result,
+ # e.g. an empty format, or %Z when the timezone
+ # is unknown.
+ result = rffi.charp2strn(outbuf, buflen)
+ return space.wrap(result)
+ finally:
lltype.free(outbuf, flavor='raw')
- return space.wrap(result)
-
i += i
strftime.unwrap_spec = [ObjSpace, str, W_Root]
Modified: pypy/branch/cpython-extension/pypy/module/rctime/test/test_rctime.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/rctime/test/test_rctime.py (original)
+++ pypy/branch/cpython-extension/pypy/module/rctime/test/test_rctime.py Wed Mar 31 00:17:06 2010
@@ -220,6 +220,14 @@
exp = '2000 01 01 00 00 00 1 001'
assert rctime.strftime("%Y %m %d %H %M %S %w %j", (0,)*9) == exp
+ def test_strftime_ext(self):
+ import time as rctime
+
+ tt = rctime.gmtime()
+ result = rctime.strftime('%D', tt)
+ if result != '': # else format not supported and we got ''
+ assert result == rctime.strftime('%m/%d/%y', tt)
+
def test_strftime_bounds_checking(self):
import time as rctime
Modified: pypy/branch/cpython-extension/pypy/module/readline/test/test_c_readline.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/readline/test/test_c_readline.py (original)
+++ pypy/branch/cpython-extension/pypy/module/readline/test/test_c_readline.py Wed Mar 31 00:17:06 2010
@@ -2,8 +2,14 @@
Directly test the basic ctypes wrappers.
"""
+import py
from pypy import conftest; conftest.translation_test_so_skip_if_appdirect()
-from pypy.module.readline import c_readline
+from pypy.rpython.tool import rffi_platform as platform
+
+try:
+ from pypy.module.readline import c_readline
+except platform.CompilationError, e:
+ py.test.skip(e)
def test_basic_import():
Modified: pypy/branch/cpython-extension/pypy/module/readline/test/test_with_pypy.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/readline/test/test_with_pypy.py (original)
+++ pypy/branch/cpython-extension/pypy/module/readline/test/test_with_pypy.py Wed Mar 31 00:17:06 2010
@@ -3,7 +3,14 @@
in the PyPy interpreter, itself running on top of CPython
"""
+import py
from pypy.conftest import gettestobjspace
+from pypy.rpython.tool import rffi_platform as platform
+
+try:
+ from pypy.module.readline import c_readline
+except platform.CompilationError, e:
+ py.test.skip(e)
class AppTestReadline:
Modified: pypy/branch/cpython-extension/pypy/module/zipimport/interp_zipimport.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/zipimport/interp_zipimport.py (original)
+++ pypy/branch/cpython-extension/pypy/module/zipimport/interp_zipimport.py Wed Mar 31 00:17:06 2010
@@ -1,7 +1,7 @@
from pypy.interpreter.baseobjspace import W_Root, ObjSpace, Wrappable, \
Arguments
-from pypy.interpreter.error import OperationError, wrap_oserror, operationerrfmt
+from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter.gateway import interp2app
from pypy.interpreter.typedef import TypeDef, GetSetProperty
from pypy.interpreter.module import Module
@@ -131,7 +131,7 @@
def _find_relative_path(self, filename):
if filename.startswith(self.filename):
filename = filename[len(self.filename):]
- if filename.startswith(os.sep):
+ if filename.startswith(os.path.sep) or filename.startswith(ZIPSEP):
filename = filename[1:]
if ZIPSEP != os.path.sep:
filename = filename.replace(os.path.sep, ZIPSEP)
@@ -326,10 +326,12 @@
w_ZipImportError = space.getattr(space.getbuiltinmodule('zipimport'),
w('ZipImportError'))
ok = False
- parts = name.split(os.path.sep)
+ parts_ends = [i for i in range(0, len(name))
+ if name[i] == os.path.sep or name[i] == ZIPSEP]
+ parts_ends.append(len(name))
filename = "" # make annotator happy
- for i in range(1, len(parts) + 1):
- filename = os.path.sep.join(parts[:i])
+ for i in parts_ends:
+ filename = name[:i]
if not filename:
filename = os.path.sep
try:
@@ -359,7 +361,7 @@
"%s seems not to be a zipfile", filename)
zip_file.close()
prefix = name[len(filename):]
- if prefix.startswith(os.sep):
+ if prefix.startswith(os.path.sep) or prefix.startswith(ZIPSEP):
prefix = prefix[1:]
w_result = space.wrap(W_ZipImporter(space, name, filename,
zip_file.NameToInfo, prefix))
Modified: pypy/branch/cpython-extension/pypy/module/zipimport/test/test_zipimport.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/module/zipimport/test/test_zipimport.py (original)
+++ pypy/branch/cpython-extension/pypy/module/zipimport/test/test_zipimport.py Wed Mar 31 00:17:06 2010
@@ -239,10 +239,11 @@
# value. Not sure why it doesn't the assertion uses import.archive
# directly. -exarkun
archive = importer.archive
+ realprefix = importer.prefix
allbutlast = self.zipfile.split(os.path.sep)[:-1]
prefix = 'directory'
assert archive == self.zipfile
- assert importer.prefix == prefix
+ assert realprefix == prefix
def test_zip_directory_cache(self):
""" Check full dictionary interface
Modified: pypy/branch/cpython-extension/pypy/objspace/descroperation.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/descroperation.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/descroperation.py Wed Mar 31 00:17:06 2010
@@ -5,6 +5,7 @@
from pypy.interpreter.argument import Arguments
from pypy.interpreter.typedef import default_identity_hash
from pypy.tool.sourcetools import compile2, func_with_new_name
+from pypy.module.__builtin__.interp_classobj import W_InstanceObject
def object_getattribute(space):
"Utility that returns the app-level descriptor object.__getattribute__."
@@ -32,6 +33,17 @@
"'%s' object attribute '%s' is read-only",
typename, name)
+# Helpers for old-style and mix-style mixup
+
+def _same_class_w(space, w_obj1, w_obj2, w_typ1, w_typ2):
+ if (space.is_oldstyle_instance(w_obj1) and
+ space.is_oldstyle_instance(w_obj2)):
+ assert isinstance(w_obj1, W_InstanceObject)
+ assert isinstance(w_obj2, W_InstanceObject)
+ return space.is_w(w_obj1.w_class, w_obj2.w_class)
+ return space.is_w(w_typ1, w_typ2)
+
+
class Object:
def descr__getattribute__(space, w_obj, w_name):
name = space.str_w(w_name)
@@ -297,7 +309,7 @@
w_typ1 = space.type(w_obj1)
w_typ2 = space.type(w_obj2)
w_left_src, w_left_impl = space.lookup_in_type_where(w_typ1, '__pow__')
- if space.is_w(w_typ1, w_typ2):
+ if _same_class_w(space, w_obj1, w_obj2, w_typ1, w_typ2):
w_right_impl = None
else:
w_right_src, w_right_impl = space.lookup_in_type_where(w_typ2, '__rpow__')
@@ -581,7 +593,7 @@
w_typ1 = space.type(w_obj1)
w_typ2 = space.type(w_obj2)
w_left_src, w_left_impl = space.lookup_in_type_where(w_typ1, left)
- if space.is_w(w_typ1, w_typ2):
+ if _same_class_w(space, w_obj1, w_obj2, w_typ1, w_typ2):
w_right_impl = None
else:
w_right_src, w_right_impl = space.lookup_in_type_where(w_typ2, right)
@@ -604,8 +616,8 @@
# -- end of bug compatibility
if space.is_true(space.issubtype(w_typ2, w_typ1)):
if (w_left_src and w_right_src and
- not space.abstract_issubclass_w(w_left_src, w_right_src) and
- not space.abstract_issubclass_w(w_typ1, w_right_src)):
+ not space.abstract_issubclass_w(w_left_src, w_right_src) and
+ not space.abstract_issubclass_w(w_typ1, w_right_src)):
w_obj1, w_obj2 = w_obj2, w_obj1
w_left_impl, w_right_impl = w_right_impl, w_left_impl
@@ -632,8 +644,8 @@
w_left_src, w_left_impl = space.lookup_in_type_where(w_typ1, left)
w_first = w_obj1
w_second = w_obj2
-
- if space.is_w(w_typ1, w_typ2):
+
+ if _same_class_w(space, w_obj1, w_obj2, w_typ1, w_typ2):
w_right_impl = None
else:
w_right_src, w_right_impl = space.lookup_in_type_where(w_typ2, right)
Modified: pypy/branch/cpython-extension/pypy/objspace/flow/model.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/flow/model.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/flow/model.py Wed Mar 31 00:17:06 2010
@@ -206,16 +206,10 @@
txt = "%s(%s)" % (txt, self.exitswitch)
return txt
- def reallyalloperations(self):
- """Iterate over all operations, including cleanup sub-operations.
- XXX remove!"""
- for op in self.operations:
- yield op
-
def getvariables(self):
"Return all variables mentioned in this Block."
result = self.inputargs[:]
- for op in self.reallyalloperations():
+ for op in self.operations:
result += op.args
result.append(op.result)
return uniqueitems([w for w in result if isinstance(w, Variable)])
@@ -223,7 +217,7 @@
def getconstants(self):
"Return all constants mentioned in this Block."
result = self.inputargs[:]
- for op in self.reallyalloperations():
+ for op in self.operations:
result += op.args
return uniqueitems([w for w in result if isinstance(w, Constant)])
@@ -231,7 +225,7 @@
for a in mapping:
assert isinstance(a, Variable), a
self.inputargs = [mapping.get(a, a) for a in self.inputargs]
- for op in self.reallyalloperations():
+ for op in self.operations:
op.args = [mapping.get(a, a) for a in op.args]
op.result = mapping.get(op.result, op.result)
self.exitswitch = mapping.get(self.exitswitch, self.exitswitch)
Modified: pypy/branch/cpython-extension/pypy/objspace/flow/objspace.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/flow/objspace.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/flow/objspace.py Wed Mar 31 00:17:06 2010
@@ -8,6 +8,7 @@
from pypy.objspace.flow import flowcontext
from pypy.objspace.flow.operation import FunctionByName
from pypy.rlib.unroll import unrolling_iterable, _unroller
+from pypy.rlib import rstackovf
debug = 0
@@ -201,9 +202,13 @@
if not isinstance(check_class, tuple):
# the simple case
return ObjSpace.exception_match(self, w_exc_type, w_check_class)
+ # special case for StackOverflow (see rlib/rstackovf.py)
+ if check_class == rstackovf.StackOverflow:
+ w_real_class = self.wrap(rstackovf._StackOverflow)
+ return ObjSpace.exception_match(self, w_exc_type, w_real_class)
# checking a tuple of classes
for w_klass in self.fixedview(w_check_class):
- if ObjSpace.exception_match(self, w_exc_type, w_klass):
+ if self.exception_match(w_exc_type, w_klass):
return True
return False
@@ -230,9 +235,7 @@
if func.func_closure is None:
closure = None
else:
- closure = [extract_cell_content(c, name, func)
- for c, name in zip(func.func_closure,
- func.func_code.co_freevars)]
+ closure = [extract_cell_content(c) for c in func.func_closure]
# CallableFactory.pycall may add class_ to functions that are methods
name = func.func_name
class_ = getattr(func, 'class_', None)
@@ -513,23 +516,17 @@
lis.append(OverflowError)
implicit_exceptions[name+"_ovf"] = lis
-#for _err in IndexError, KeyError:
-# _add_exceptions("""getitem setitem delitem""", _err)
for _name in 'getattr', 'delattr':
_add_exceptions(_name, AttributeError)
for _name in 'iter', 'coerce':
_add_exceptions(_name, TypeError)
-del _name#, _err
+del _name
_add_exceptions("""div mod divmod truediv floordiv pow
inplace_div inplace_mod inplace_divmod inplace_truediv
inplace_floordiv inplace_pow""", ZeroDivisionError)
_add_exceptions("""pow inplace_pow lshift inplace_lshift rshift
inplace_rshift""", ValueError)
-##_add_exceptions("""add sub mul truediv floordiv div mod divmod pow
-## inplace_add inplace_sub inplace_mul inplace_truediv
-## inplace_floordiv inplace_div inplace_mod inplace_divmod
-## inplace_pow""", FloatingPointError)
_add_exceptions("""truediv divmod
inplace_add inplace_sub inplace_mul inplace_truediv
inplace_floordiv inplace_div inplace_mod inplace_pow
@@ -540,25 +537,27 @@
OverflowError) # for the float case
del _add_exceptions, _add_except_ovf
-def extract_cell_content(c, varname='?', func='?'):
+def extract_cell_content(c):
"""Get the value contained in a CPython 'cell', as read through
the func_closure of a function object."""
- # yuk! this is all I could come up with that works in Python 2.2 too
- class X(object):
- def __cmp__(self, other):
- self.other = other
- return 0
- def __eq__(self, other):
- self.other = other
- return True
- x = X()
- x_cell, = (lambda: x).func_closure
- x_cell == c
try:
- return x.other # crashes if the cell is actually empty
+ # This is simple on 2.5
+ return getattr(c, "cell_contents")
except AttributeError:
- raise Exception("in %r, the free variable %r has no value" % (
- func, varname))
+ class X(object):
+ def __cmp__(self, other):
+ self.other = other
+ return 0
+ def __eq__(self, other):
+ self.other = other
+ return True
+ x = X()
+ x_cell, = (lambda: x).func_closure
+ x_cell == c
+ try:
+ return x.other # crashes if the cell is actually empty
+ except AttributeError:
+ raise ValueError("empty cell")
def make_op(name, symbol, arity, specialnames):
if hasattr(FlowObjSpace, name):
Modified: pypy/branch/cpython-extension/pypy/objspace/std/__init__.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/__init__.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/__init__.py Wed Mar 31 00:17:06 2010
@@ -1,2 +1,2 @@
-from objspace import StdObjSpace
+from pypy.objspace.std.objspace import StdObjSpace
Space = StdObjSpace
Modified: pypy/branch/cpython-extension/pypy/objspace/std/boolobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/boolobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/boolobject.py Wed Mar 31 00:17:06 2010
@@ -1,4 +1,5 @@
-from pypy.objspace.std.objspace import *
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.intobject import W_IntObject
Modified: pypy/branch/cpython-extension/pypy/objspace/std/booltype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/booltype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/booltype.py Wed Mar 31 00:17:06 2010
@@ -1,4 +1,5 @@
-from pypy.objspace.std.stdtypedef import *
+from pypy.interpreter import gateway
+from pypy.objspace.std.stdtypedef import StdTypeDef
from pypy.objspace.std.inttype import int_typedef
def descr__new__(space, w_booltype, w_obj=None):
@@ -16,6 +17,6 @@
Returns True when the argument x is true, False otherwise.
The builtins True and False are the only two instances of the class bool.
The class bool is a subclass of the class int, and cannot be subclassed.''',
- __new__ = newmethod(descr__new__),
+ __new__ = gateway.interp2app(descr__new__),
)
bool_typedef.acceptable_as_base_class = False
Modified: pypy/branch/cpython-extension/pypy/objspace/std/complexobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/complexobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/complexobject.py Wed Mar 31 00:17:06 2010
@@ -1,6 +1,7 @@
from pypy.interpreter import gateway
-from pypy.objspace.std.objspace import W_Object, OperationError
-from pypy.objspace.std.objspace import registerimplementation, register_all
+from pypy.interpreter.error import OperationError
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.floatobject import W_FloatObject, _hash_float
import math
Modified: pypy/branch/cpython-extension/pypy/objspace/std/complextype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/complextype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/complextype.py Wed Mar 31 00:17:06 2010
@@ -1,9 +1,9 @@
-from pypy.interpreter.error import OperationError
from pypy.interpreter import gateway
+from pypy.interpreter.error import OperationError
+from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.strutil import interp_string_to_float, ParseStringError
-from pypy.objspace.std.objspace import register_all
from pypy.objspace.std.noneobject import W_NoneObject
-from pypy.objspace.std.stdtypedef import GetSetProperty, StdTypeDef, newmethod
+from pypy.objspace.std.stdtypedef import GetSetProperty, StdTypeDef
from pypy.objspace.std.stdtypedef import StdObjSpaceMultiMethod
# ERRORCODES
@@ -36,7 +36,7 @@
# extract first number
realstart = i
pc = s[i]
- while i < slen and s[i] != ' ':
+ while i < slen and s[i] != ' ':
if s[i] in ('+','-') and pc not in ('e','E') and i != realstart:
break
pc = s[i]
@@ -136,8 +136,9 @@
except ParseStringError:
raise OperationError(space.w_ValueError, space.wrap(ERR_MALFORMED))
else:
- #check for overflow
- if abs(realval) == OVERFLOWED_FLOAT or abs(imagval) == OVERFLOWED_FLOAT:
+ # check for overflow
+ if (abs(realval) == OVERFLOWED_FLOAT or
+ abs(imagval) == OVERFLOWED_FLOAT):
raise OperationError(space.w_ValueError,space.wrap(
"complex() literal too large to convert"))
@@ -156,8 +157,8 @@
w_real = space.call_function(w_method)
# __complex__() could return a string, which space.float()
# could accept below... Let's catch this case.
- if space.is_true(space.isinstance(w_imag, space.w_str)) or \
- space.is_true(space.isinstance(w_imag, space.w_unicode)):
+ if (space.is_true(space.isinstance(w_imag, space.w_str)) or
+ space.is_true(space.isinstance(w_imag, space.w_unicode))):
raise OperationError(space.w_TypeError,
space.wrap("__complex__() cannot return"
" a string"))
@@ -205,19 +206,19 @@
space.wrap("descriptor is for 'complex'"))
return space.newfloat(getattr(w_obj, name))
return GetSetProperty(fget)
-
+
def descr___getnewargs__(space, w_self):
from pypy.objspace.std.complexobject import W_ComplexObject
assert isinstance(w_self, W_ComplexObject)
- return space.newtuple([space.newcomplex(w_self.realval,w_self.imagval)])
-
+ return space.newtuple([space.newcomplex(w_self.realval,w_self.imagval)])
+
complex_typedef = StdTypeDef("complex",
__doc__ = """complex(real[, imag]) -> complex number
-
+
Create a complex number from a real part and an optional imaginary part.
This is equivalent to (real + imag*1j) where imag defaults to 0.""",
- __new__ = newmethod(descr__new__),
- __getnewargs__ = newmethod(descr___getnewargs__),
+ __new__ = gateway.interp2app(descr__new__),
+ __getnewargs__ = gateway.interp2app(descr___getnewargs__),
real = complexwprop('realval'),
imag = complexwprop('imagval'),
)
Modified: pypy/branch/cpython-extension/pypy/objspace/std/default.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/default.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/default.py Wed Mar 31 00:17:06 2010
@@ -1,6 +1,7 @@
"""Default implementation for some operation."""
-from pypy.objspace.std.objspace import *
+from pypy.interpreter.error import OperationError
+from pypy.objspace.std.register_all import register_all
from pypy.rlib import objectmodel
Modified: pypy/branch/cpython-extension/pypy/objspace/std/dictmultiobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/dictmultiobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/dictmultiobject.py Wed Mar 31 00:17:06 2010
@@ -1,6 +1,6 @@
import py, sys
-from pypy.objspace.std.objspace import register_all, W_Object
-from pypy.objspace.std.objspace import registerimplementation
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
from pypy.interpreter import gateway
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter.argument import Signature
Modified: pypy/branch/cpython-extension/pypy/objspace/std/dictproxyobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/dictproxyobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/dictproxyobject.py Wed Mar 31 00:17:06 2010
@@ -1,11 +1,12 @@
-from pypy.objspace.std.objspace import *
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
def descr_get_dictproxy(space, w_obj):
return W_DictProxyObject(w_obj.getdict())
class W_DictProxyObject(W_Object):
from pypy.objspace.std.dictproxytype import dictproxy_typedef as typedef
-
+
def __init__(w_self, w_dict):
w_self.w_dict = w_dict
Modified: pypy/branch/cpython-extension/pypy/objspace/std/dictproxytype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/dictproxytype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/dictproxytype.py Wed Mar 31 00:17:06 2010
@@ -1,5 +1,7 @@
-from pypy.objspace.std.stdtypedef import *
+from pypy.interpreter import gateway
+from pypy.interpreter.typedef import GetSetProperty
from pypy.interpreter.error import OperationError
+from pypy.objspace.std.stdtypedef import StdTypeDef
# ____________________________________________________________
Modified: pypy/branch/cpython-extension/pypy/objspace/std/dicttype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/dicttype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/dicttype.py Wed Mar 31 00:17:06 2010
@@ -1,5 +1,8 @@
+from pypy.interpreter.baseobjspace import ObjSpace, W_Root
+from pypy.interpreter.error import OperationError
+from pypy.interpreter.mixedmodule import MixedModule
from pypy.interpreter import gateway
-from pypy.objspace.std.stdtypedef import *
+from pypy.objspace.std.stdtypedef import StdTypeDef, SMM, no_hash_descr
from pypy.objspace.std.register_all import register_all
from pypy.interpreter.error import OperationError
@@ -124,7 +127,6 @@
def itervalues(d):
return iter(dict.values(d))
''', filename=__file__)
-#XXX what about dict.fromkeys()?
dict_update__ANY = app.interphook("update")
dict_popitem__ANY = app.interphook("popitem")
@@ -138,6 +140,23 @@
register_all(vars(), globals())
+ at gateway.unwrap_spec(ObjSpace, W_Root, W_Root, W_Root)
+def descr_fromkeys(space, w_type, w_keys, w_fill=None):
+ if w_fill is None:
+ w_fill = space.w_None
+ w_dict = space.call_function(w_type)
+ w_iter = space.iter(w_keys)
+ while True:
+ try:
+ w_key = space.next(w_iter)
+ except OperationError, e:
+ if not e.match(space, space.w_StopIteration):
+ raise
+ break
+ space.setitem(w_dict, w_key, w_fill)
+ return w_dict
+
+
# ____________________________________________________________
def descr__new__(space, w_dicttype, __args__):
@@ -157,9 +176,12 @@
d[k] = v
dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)''',
- __new__ = newmethod(descr__new__,
- unwrap_spec=[gateway.ObjSpace,gateway.W_Root,gateway.Arguments]),
+ __new__ = gateway.interp2app(descr__new__,
+ unwrap_spec=
+ [gateway.ObjSpace,
+ gateway.W_Root,gateway.Arguments]),
__hash__ = no_hash_descr,
+ fromkeys = gateway.interp2app(descr_fromkeys, as_classmethod=True),
)
dict_typedef.registermethods(globals())
@@ -180,18 +202,16 @@
XXX to do: remove this __reduce__ method and do
a registration with copy_reg, instead.
"""
- from pypy.interpreter.mixedmodule import MixedModule
w_mod = space.getbuiltinmodule('_pickle_support')
mod = space.interp_w(MixedModule, w_mod)
new_inst = mod.get('dictiter_surrogate_new')
w_typeobj = space.gettypeobject(dictiter_typedef)
-
- from pypy.interpreter.mixedmodule import MixedModule
+
raise OperationError(
space.w_RuntimeError,
space.wrap("cannot pickle dictiters with multidicts"))
# XXXXXX get that working again
-
+
# we cannot call __init__ since we don't have the original dict
if isinstance(w_self, W_DictIter_Keys):
w_clone = space.allocate_instance(W_DictIter_Keys, w_typeobj)
@@ -217,7 +237,7 @@
w_res
]
w_ret = space.newtuple([new_inst, space.newtuple(tup)])
- return w_ret
+ return w_ret
# ____________________________________________________________
Modified: pypy/branch/cpython-extension/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/floatobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/floatobject.py Wed Mar 31 00:17:06 2010
@@ -1,15 +1,22 @@
-from pypy.objspace.std.objspace import *
+import operator, new
from pypy.interpreter import gateway
+from pypy.interpreter.error import OperationError
+from pypy.objspace.std import model
+from pypy.objspace.std.multimethod import FailedToImplementArgs
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.objspace.std.longobject import W_LongObject
from pypy.rlib.rarithmetic import ovfcheck_float_to_int, intmask, isinf, isnan
-from pypy.rlib.rarithmetic import formatd
+from pypy.rlib.rarithmetic import formatd, LONG_BIT
+from pypy.rlib.rbigint import rbigint
+from pypy.tool.sourcetools import func_with_new_name
import math
from pypy.objspace.std.intobject import W_IntObject
class W_FloatObject(W_Object):
- """This is a reimplementation of the CPython "PyFloatObject"
+ """This is a reimplementation of the CPython "PyFloatObject"
it is assumed that the constructor takes a real Python float as
an argument"""
from pypy.objspace.std.floattype import float_typedef as typedef
@@ -88,82 +95,115 @@
s = formatd("%.12g", x)
return space.wrap(should_not_look_like_an_int(s))
+# ____________________________________________________________
+# A mess to handle all cases of float comparison without relying
+# on delegation, which can unfortunately loose precision when
+# casting an int or a long to a float.
+
+def list_compare_funcs(declarator):
+ for op in ['lt', 'le', 'eq', 'ne', 'gt', 'ge']:
+ func, name = declarator(op)
+ globals()[name] = func_with_new_name(func, name)
+
+def _reverse(opname):
+ if opname[0] == 'l': return 'g' + opname[1:]
+ elif opname[0] == 'g': return 'l' + opname[1:]
+ else: return opname
-def declare_new_float_comparison(opname):
- import operator
- from pypy.tool.sourcetools import func_with_new_name
- op = getattr(operator, opname)
- def f(space, w_int1, w_int2):
- i = w_int1.floatval
- j = w_int2.floatval
- return space.newbool(op(i, j))
- name = opname + "__Float_Float"
- return func_with_new_name(f, name), name
-
-for op in ['lt', 'le', 'eq', 'ne', 'gt', 'ge']:
- func, name = declare_new_float_comparison(op)
- globals()[name] = func
-
-# for overflowing comparisons between longs and floats
-# XXX we might have to worry (later) about eq__Float_Int, for the case
-# where int->float conversion may lose precision :-(
-def eq__Float_Long(space, w_float1, w_long2):
- # XXX naive implementation
- x = w_float1.floatval
- if isinf(x) or math.floor(x) != x:
- return space.w_False
- try:
- w_long1 = W_LongObject.fromfloat(x)
- except OverflowError:
- return space.w_False
- return space.eq(w_long1, w_long2)
-
-def eq__Long_Float(space, w_long1, w_float2):
- return eq__Float_Long(space, w_float2, w_long1)
-def ne__Float_Long(space, w_float1, w_long2):
- return space.not_(eq__Float_Long(space, w_float1, w_long2))
-
-def ne__Long_Float(space, w_long1, w_float2):
- return space.not_(eq__Float_Long(space, w_float2, w_long1))
-
-def lt__Float_Long(space, w_float1, w_long2):
- # XXX naive implementation
- x = w_float1.floatval
- if isinf(x):
- return space.newbool(x < 0.0)
- x_floor = math.floor(x)
- try:
- w_long1 = W_LongObject.fromfloat(x_floor)
- except OverflowError:
- return space.newbool(x < 0.0)
- return space.lt(w_long1, w_long2)
-
-def lt__Long_Float(space, w_long1, w_float2):
- return space.not_(le__Float_Long(space, w_float2, w_long1))
-
-def le__Float_Long(space, w_float1, w_long2):
- # XXX it's naive anyway
- if space.is_true(space.lt(w_float1, w_long2)):
- return space.w_True
+def declare_compare_bigint(opname):
+ """Return a helper function that implements a float-bigint comparison."""
+ op = getattr(operator, opname)
+ #
+ if opname == 'eq' or opname == 'ne':
+ def do_compare_bigint(f1, b2):
+ """f1 is a float. b2 is a bigint."""
+ if isinf(f1) or isnan(f1) or math.floor(f1) != f1:
+ return opname == 'ne'
+ b1 = rbigint.fromfloat(f1)
+ res = b1.eq(b2)
+ if opname == 'ne':
+ res = not res
+ return res
else:
- return space.eq(w_float1, w_long2)
+ def do_compare_bigint(f1, b2):
+ """f1 is a float. b2 is a bigint."""
+ if isinf(f1) or isnan(f1):
+ return op(f1, 0.0)
+ if opname == 'gt' or opname == 'le':
+ # 'float > long' <==> 'ceil(float) > long'
+ # 'float <= long' <==> 'ceil(float) <= long'
+ f1 = math.ceil(f1)
+ else:
+ # 'float < long' <==> 'floor(float) < long'
+ # 'float >= long' <==> 'floor(float) >= long'
+ f1 = math.floor(f1)
+ b1 = rbigint.fromfloat(f1)
+ return getattr(b1, opname)(b2)
+ #
+ return do_compare_bigint, 'compare_bigint_' + opname
+list_compare_funcs(declare_compare_bigint)
-def le__Long_Float(space, w_long1, w_float2):
- return space.not_(lt__Float_Long(space, w_float2, w_long1))
-def gt__Float_Long(space, w_float1, w_long2):
- return space.not_(le__Float_Long(space, w_float1, w_long2))
+def declare_cmp_float_float(opname):
+ op = getattr(operator, opname)
+ def f(space, w_float1, w_float2):
+ f1 = w_float1.floatval
+ f2 = w_float2.floatval
+ return space.newbool(op(f1, f2))
+ return f, opname + "__Float_Float"
+list_compare_funcs(declare_cmp_float_float)
-def gt__Long_Float(space, w_long1, w_float2):
- return lt__Float_Long(space, w_float2, w_long1)
+def declare_cmp_float_int(opname):
+ op = getattr(operator, opname)
+ compare = globals()['compare_bigint_' + opname]
+ def f(space, w_float1, w_int2):
+ f1 = w_float1.floatval
+ i2 = w_int2.intval
+ f2 = float(i2)
+ if LONG_BIT > 32 and int(f2) != i2:
+ res = compare(f1, rbigint.fromint(i2))
+ else:
+ res = op(f1, f2)
+ return space.newbool(res)
+ return f, opname + "__Float_Int"
+list_compare_funcs(declare_cmp_float_int)
+
+def declare_cmp_float_long(opname):
+ compare = globals()['compare_bigint_' + opname]
+ def f(space, w_float1, w_long2):
+ f1 = w_float1.floatval
+ b2 = w_long2.num
+ return space.newbool(compare(f1, b2))
+ return f, opname + "__Float_Long"
+list_compare_funcs(declare_cmp_float_long)
-def ge__Float_Long(space, w_float1, w_long2):
- return space.not_(lt__Float_Long(space, w_float1, w_long2))
+def declare_cmp_int_float(opname):
+ op = getattr(operator, opname)
+ revcompare = globals()['compare_bigint_' + _reverse(opname)]
+ def f(space, w_int1, w_float2):
+ f2 = w_float2.floatval
+ i1 = w_int1.intval
+ f1 = float(i1)
+ if LONG_BIT > 32 and int(f1) != i1:
+ res = revcompare(f2, rbigint.fromint(i1))
+ else:
+ res = op(f1, f2)
+ return space.newbool(res)
+ return f, opname + "__Int_Float"
+list_compare_funcs(declare_cmp_int_float)
+
+def declare_cmp_long_float(opname):
+ revcompare = globals()['compare_bigint_' + _reverse(opname)]
+ def f(space, w_long1, w_float2):
+ f2 = w_float2.floatval
+ b1 = w_long1.num
+ return space.newbool(revcompare(f2, b1))
+ return f, opname + "__Long_Float"
+list_compare_funcs(declare_cmp_long_float)
-def ge__Long_Float(space, w_long1, w_float2):
- return le__Float_Long(space, w_float2, w_long1)
+# ____________________________________________________________
def hash__Float(space, w_value):
return space.wrap(_hash_float(space, w_value.floatval))
@@ -318,7 +358,20 @@
raise FailedToImplementArgs(space.w_OverflowError,
space.wrap("float power"))
except ValueError:
- if x == 0.0 and y < 0.0:
+ # special case: "(-1.0) ** bignum" should not raise ValueError,
+ # unlike "math.pow(-1.0, bignum)". See http://mail.python.org/
+ # - pipermail/python-bugs-list/2003-March/016795.html
+ if x < 0.0:
+ if math.floor(y) != y:
+ raise OperationError(space.w_ValueError,
+ space.wrap("negative number cannot be "
+ "raised to a fractional power"))
+ if x == -1.0:
+ if math.floor(y * 0.5) * 2.0 == y:
+ return space.wrap(1.0)
+ else:
+ return space.wrap( -1.0)
+ elif x == 0.0 and y < 0.0:
raise OperationError(space.w_ZeroDivisionError,
space.wrap("0.0 cannot be raised to a negative power"))
raise OperationError(space.w_ValueError,
@@ -349,11 +402,13 @@
w_float2 = delegate_Long2Float(space, w_int2)
return pow__Float_Float_ANY(space, w_float1, w_float2, thirdarg)
-StdObjSpace.MM.pow.register(pow_neg__Long_Long_None, W_LongObject, W_LongObject, W_NoneObject, order=1)
+model.MM.pow.register(pow_neg__Long_Long_None, W_LongObject, W_LongObject,
+ W_NoneObject, order=1)
def pow_neg__Int_Int_None(space, w_int1, w_int2, thirdarg):
w_float1 = delegate_Int2Float(space, w_int1)
w_float2 = delegate_Int2Float(space, w_int2)
return pow__Float_Float_ANY(space, w_float1, w_float2, thirdarg)
-StdObjSpace.MM.pow.register(pow_neg__Int_Int_None, W_IntObject, W_IntObject, W_NoneObject, order=2)
+model.MM.pow.register(pow_neg__Int_Int_None, W_IntObject, W_IntObject,
+ W_NoneObject, order=2)
Modified: pypy/branch/cpython-extension/pypy/objspace/std/floattype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/floattype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/floattype.py Wed Mar 31 00:17:06 2010
@@ -1,5 +1,6 @@
-from pypy.objspace.std.stdtypedef import *
+from pypy.interpreter import gateway
from pypy.interpreter.error import OperationError
+from pypy.objspace.std.stdtypedef import StdTypeDef
from pypy.objspace.std.strutil import string_to_float, ParseStringError
from pypy.objspace.std.strutil import interp_string_to_float
@@ -48,5 +49,5 @@
__doc__ = '''float(x) -> floating point number
Convert a string or number to a floating point number, if possible.''',
- __new__ = newmethod(descr__new__),
+ __new__ = gateway.interp2app(descr__new__),
)
Modified: pypy/branch/cpython-extension/pypy/objspace/std/frozensettype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/frozensettype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/frozensettype.py Wed Mar 31 00:17:06 2010
@@ -1,9 +1,8 @@
-from pypy.interpreter.error import OperationError
-from pypy.objspace.std.objspace import register_all
-from pypy.objspace.std.stdtypedef import StdTypeDef, newmethod
-from pypy.objspace.std.stdtypedef import SMM
-from pypy.interpreter.gateway import NoneNotWrapped
from pypy.interpreter import gateway
+from pypy.interpreter.error import OperationError
+from pypy.objspace.std.register_all import register_all
+from pypy.objspace.std.stdtypedef import StdTypeDef, SMM
+
frozenset_copy = SMM('copy', 1,
doc='Return a shallow copy of a set.')
@@ -37,7 +36,8 @@
register_all(vars(), globals())
-def descr__frozenset__new__(space, w_frozensettype, w_iterable=NoneNotWrapped):
+def descr__frozenset__new__(space, w_frozensettype,
+ w_iterable=gateway.NoneNotWrapped):
from pypy.objspace.std.setobject import W_FrozensetObject
from pypy.objspace.std.setobject import _is_frozenset_exact
if (space.is_w(w_frozensettype, space.w_frozenset) and
@@ -52,7 +52,7 @@
__doc__ = """frozenset(iterable) --> frozenset object
Build an immutable unordered collection.""",
- __new__ = newmethod(descr__frozenset__new__),
+ __new__ = gateway.interp2app(descr__frozenset__new__),
)
frozenset_typedef.registermethods(globals())
Modified: pypy/branch/cpython-extension/pypy/objspace/std/intobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/intobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/intobject.py Wed Mar 31 00:17:06 2010
@@ -1,4 +1,7 @@
-from pypy.objspace.std.objspace import *
+from pypy.interpreter.error import OperationError
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
+from pypy.objspace.std.multimethod import FailedToImplementArgs
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.rlib.rarithmetic import ovfcheck, ovfcheck_lshift, LONG_BIT, r_uint
from pypy.rlib.rbigint import rbigint
Modified: pypy/branch/cpython-extension/pypy/objspace/std/inttype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/inttype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/inttype.py Wed Mar 31 00:17:06 2010
@@ -1,7 +1,9 @@
-from pypy.objspace.std.stdtypedef import *
-from pypy.objspace.std.strutil import string_to_int, string_to_w_long, ParseStringError, ParseStringOverflowError
+from pypy.interpreter import gateway
from pypy.interpreter.error import OperationError
-from pypy.interpreter.gateway import NoneNotWrapped
+from pypy.objspace.std.stdtypedef import StdTypeDef
+from pypy.objspace.std.strutil import (string_to_int, string_to_w_long,
+ ParseStringError,
+ ParseStringOverflowError)
from pypy.rlib.rarithmetic import r_uint
from pypy.rlib.objectmodel import instantiate
@@ -47,8 +49,8 @@
except ParseStringError, e:
raise OperationError(space.w_ValueError,
space.wrap(e.msg))
-
-def descr__new__(space, w_inttype, w_x=0, w_base=NoneNotWrapped):
+
+def descr__new__(space, w_inttype, w_x=0, w_base=gateway.NoneNotWrapped):
from pypy.objspace.std.intobject import W_IntObject
w_longval = None
w_value = w_x # 'x' is the keyword argument name in CPython
@@ -64,7 +66,7 @@
raise OperationError(space.w_ValueError,
space.wrap(e.msg))
except ParseStringOverflowError, e:
- w_longval = retry_to_w_long(space, e.parser)
+ w_longval = retry_to_w_long(space, e.parser)
elif space.is_true(space.isinstance(w_value, space.w_unicode)):
if space.config.objspace.std.withropeunicode:
from pypy.objspace.std.ropeunicodeobject import unicode_to_decimal_w
@@ -77,7 +79,7 @@
raise OperationError(space.w_ValueError,
space.wrap(e.msg))
except ParseStringOverflowError, e:
- w_longval = retry_to_w_long(space, e.parser)
+ w_longval = retry_to_w_long(space, e.parser)
else:
# otherwise, use the __int__() method
w_obj = space.int(w_value)
@@ -116,13 +118,13 @@
raise OperationError(space.w_ValueError,
space.wrap(e.msg))
except ParseStringOverflowError, e:
- w_longval = retry_to_w_long(space, e.parser, base)
+ w_longval = retry_to_w_long(space, e.parser, base)
if w_longval is not None:
if not space.is_w(w_inttype, space.w_int):
raise OperationError(space.w_OverflowError,
space.wrap(
- "long int too large to convert to int"))
+ "long int too large to convert to int"))
return w_longval
elif space.is_w(w_inttype, space.w_int):
# common case
@@ -143,5 +145,5 @@
the optional base. It is an error to supply a base when converting a
non-string. If the argument is outside the integer range a long object
will be returned instead.''',
- __new__ = newmethod(descr__new__),
+ __new__ = gateway.interp2app(descr__new__),
)
Modified: pypy/branch/cpython-extension/pypy/objspace/std/iterobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/iterobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/iterobject.py Wed Mar 31 00:17:06 2010
@@ -1,15 +1,12 @@
-"""
-Reviewed 03-06-22
-Sequence-iteration is correctly implemented, thoroughly
-tested, and complete. The only missing feature is support
-for function-iteration.
-"""
-from pypy.objspace.std.objspace import *
+"""Generic iterator implementations"""
+from pypy.interpreter.error import OperationError
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
class W_AbstractSeqIterObject(W_Object):
from pypy.objspace.std.itertype import iter_typedef as typedef
-
+
def __init__(w_self, w_seq, index=0):
if index < 0:
index = 0
Modified: pypy/branch/cpython-extension/pypy/objspace/std/itertype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/itertype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/itertype.py Wed Mar 31 00:17:06 2010
@@ -1,4 +1,5 @@
-from pypy.objspace.std.stdtypedef import *
+from pypy.interpreter import gateway
+from pypy.objspace.std.stdtypedef import StdTypeDef
# ____________________________________________________________
Modified: pypy/branch/cpython-extension/pypy/objspace/std/listobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/listobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/listobject.py Wed Mar 31 00:17:06 2010
@@ -1,5 +1,5 @@
-from pypy.objspace.std.objspace import register_all, W_Object
-from pypy.objspace.std.objspace import registerimplementation
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.multimethod import FailedToImplement
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.objspace.std.inttype import wrapint
Modified: pypy/branch/cpython-extension/pypy/objspace/std/listtype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/listtype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/listtype.py Wed Mar 31 00:17:06 2010
@@ -1,6 +1,6 @@
from pypy.interpreter import gateway
from pypy.interpreter.error import OperationError
-from pypy.objspace.std.stdtypedef import *
+from pypy.objspace.std.stdtypedef import StdTypeDef, SMM, no_hash_descr
from pypy.objspace.std.register_all import register_all
from sys import maxint
@@ -24,7 +24,8 @@
' occurrences of value')
list_reverse = SMM('reverse',1,
doc='L.reverse() -- reverse *IN PLACE*')
-list_sort = SMM('sort', 4, defaults=(None, None, False), argnames=['cmp', 'key', 'reverse'],
+list_sort = SMM('sort', 4, defaults=(None, None, False),
+ argnames=['cmp', 'key', 'reverse'],
doc='L.sort(cmp=None, key=None, reverse=False) -- stable'
' sort *IN PLACE*;\ncmp(x, y) -> -1, 0, 1')
list_reversed = SMM('__reversed__', 1,
@@ -50,9 +51,9 @@
list_typedef = StdTypeDef("list",
__doc__ = '''list() -> new list
list(sequence) -> new list initialized from sequence's items''',
- __new__ = newmethod(descr__new__, unwrap_spec=[gateway.ObjSpace,
- gateway.W_Root,
- gateway.Arguments]),
+ __new__ = gateway.interp2app(descr__new__, unwrap_spec=[gateway.ObjSpace,
+ gateway.W_Root,
+ gateway.Arguments]),
__hash__ = no_hash_descr,
)
list_typedef.registermethods(globals())
Modified: pypy/branch/cpython-extension/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/longobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/longobject.py Wed Mar 31 00:17:06 2010
@@ -1,5 +1,9 @@
import sys
-from pypy.objspace.std.objspace import *
+from pypy.interpreter.error import OperationError
+from pypy.objspace.std import model
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
+from pypy.objspace.std.multimethod import FailedToImplementArgs
from pypy.objspace.std.intobject import W_IntObject
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.rlib.rbigint import rbigint, SHIFT
@@ -120,11 +124,46 @@
def str__Long(space, w_long):
return space.wrap(w_long.num.str())
-def eq__Long_Long(space, w_long1, w_long2):
- return space.newbool(w_long1.num.eq(w_long2.num))
def lt__Long_Long(space, w_long1, w_long2):
return space.newbool(w_long1.num.lt(w_long2.num))
+def le__Long_Long(space, w_long1, w_long2):
+ return space.newbool(w_long1.num.le(w_long2.num))
+def eq__Long_Long(space, w_long1, w_long2):
+ return space.newbool(w_long1.num.eq(w_long2.num))
+def ne__Long_Long(space, w_long1, w_long2):
+ return space.newbool(w_long1.num.ne(w_long2.num))
+def gt__Long_Long(space, w_long1, w_long2):
+ return space.newbool(w_long1.num.gt(w_long2.num))
+def ge__Long_Long(space, w_long1, w_long2):
+ return space.newbool(w_long1.num.ge(w_long2.num))
+
+def lt__Long_Int(space, w_long1, w_int2):
+ return space.newbool(w_long1.num.lt(rbigint.fromint(w_int2.intval)))
+def le__Long_Int(space, w_long1, w_int2):
+ return space.newbool(w_long1.num.le(rbigint.fromint(w_int2.intval)))
+def eq__Long_Int(space, w_long1, w_int2):
+ return space.newbool(w_long1.num.eq(rbigint.fromint(w_int2.intval)))
+def ne__Long_Int(space, w_long1, w_int2):
+ return space.newbool(w_long1.num.ne(rbigint.fromint(w_int2.intval)))
+def gt__Long_Int(space, w_long1, w_int2):
+ return space.newbool(w_long1.num.gt(rbigint.fromint(w_int2.intval)))
+def ge__Long_Int(space, w_long1, w_int2):
+ return space.newbool(w_long1.num.ge(rbigint.fromint(w_int2.intval)))
+
+def lt__Int_Long(space, w_int1, w_long2):
+ return space.newbool(rbigint.fromint(w_int1.intval).lt(w_long2.num))
+def le__Int_Long(space, w_int1, w_long2):
+ return space.newbool(rbigint.fromint(w_int1.intval).le(w_long2.num))
+def eq__Int_Long(space, w_int1, w_long2):
+ return space.newbool(rbigint.fromint(w_int1.intval).eq(w_long2.num))
+def ne__Int_Long(space, w_int1, w_long2):
+ return space.newbool(rbigint.fromint(w_int1.intval).ne(w_long2.num))
+def gt__Int_Long(space, w_int1, w_long2):
+ return space.newbool(rbigint.fromint(w_int1.intval).gt(w_long2.num))
+def ge__Int_Long(space, w_int1, w_long2):
+ return space.newbool(rbigint.fromint(w_int1.intval).ge(w_long2.num))
+
def hash__Long(space, w_value):
return space.wrap(w_value.num.hash())
@@ -270,7 +309,8 @@
return %(opname)s__Long_Long(space, w_long1, w_long2)
""" % {'opname': opname}, '', 'exec')
- getattr(StdObjSpace.MM, opname).register(globals()['%s_ovr__Int_Int' % opname], W_IntObject, W_IntObject, order=1)
+ getattr(model.MM, opname).register(globals()['%s_ovr__Int_Int' % opname],
+ W_IntObject, W_IntObject, order=1)
# unary ops
for opname in ['neg', 'abs']:
@@ -280,7 +320,8 @@
return %(opname)s__Long(space, w_long1)
""" % {'opname': opname}
- getattr(StdObjSpace.MM, opname).register(globals()['%s_ovr__Int' % opname], W_IntObject, order=1)
+ getattr(model.MM, opname).register(globals()['%s_ovr__Int' % opname],
+ W_IntObject, order=1)
# pow
def pow_ovr__Int_Int_None(space, w_int1, w_int2, w_none3):
@@ -293,7 +334,9 @@
w_long2 = delegate_Int2Long(space, w_int2)
return pow__Long_Long_Long(space, w_long1, w_long2, w_long3)
-StdObjSpace.MM.pow.register(pow_ovr__Int_Int_None, W_IntObject, W_IntObject, W_NoneObject, order=1)
-StdObjSpace.MM.pow.register(pow_ovr__Int_Int_Long, W_IntObject, W_IntObject, W_LongObject, order=1)
+model.MM.pow.register(pow_ovr__Int_Int_None, W_IntObject, W_IntObject,
+ W_NoneObject, order=1)
+model.MM.pow.register(pow_ovr__Int_Int_Long, W_IntObject, W_IntObject,
+ W_LongObject, order=1)
Modified: pypy/branch/cpython-extension/pypy/objspace/std/longtype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/longtype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/longtype.py Wed Mar 31 00:17:06 2010
@@ -1,9 +1,9 @@
-from pypy.objspace.std.stdtypedef import *
-from pypy.objspace.std.strutil import string_to_w_long, ParseStringError
from pypy.interpreter.error import OperationError
-from pypy.interpreter.gateway import NoneNotWrapped
+from pypy.interpreter import gateway
+from pypy.objspace.std.stdtypedef import StdTypeDef
+from pypy.objspace.std.strutil import string_to_w_long, ParseStringError
-def descr__new__(space, w_longtype, w_x=0, w_base=NoneNotWrapped):
+def descr__new__(space, w_longtype, w_x=0, w_base=gateway.NoneNotWrapped):
from pypy.objspace.std.longobject import W_LongObject
w_value = w_x # 'x' is the keyword argument name in CPython
if w_base is None:
@@ -75,5 +75,5 @@
string representation of a floating point number!) When converting a
string, use the optional base. It is an error to supply a base when
converting a non-string.''',
- __new__ = newmethod(descr__new__),
+ __new__ = gateway.interp2app(descr__new__),
)
Modified: pypy/branch/cpython-extension/pypy/objspace/std/marshal_impl.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/marshal_impl.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/marshal_impl.py Wed Mar 31 00:17:06 2010
@@ -11,8 +11,8 @@
from pypy.interpreter.error import OperationError
from pypy.objspace.std.register_all import register_all
from pypy.rlib.rarithmetic import LONG_BIT
+from pypy.objspace.std import longobject, model
from pypy.objspace.std.longobject import SHIFT as long_bits
-from pypy.objspace.std.objspace import StdObjSpace
from pypy.interpreter.special import Ellipsis
from pypy.interpreter.pycode import PyCode
from pypy.interpreter import gateway, unicodehelper
@@ -32,8 +32,6 @@
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.objspace.std.unicodeobject import W_UnicodeObject
-import longobject
-
from pypy.module.marshal.interp_marshal import register
TYPE_NULL = '0'
@@ -125,7 +123,7 @@
def marshal_w_Ellipsis(space, w_ellipsis, m):
m.atom(TYPE_ELLIPSIS)
-StdObjSpace.MM.marshal_w.register(marshal_w_Ellipsis, Ellipsis)
+model.MM.marshal_w.register(marshal_w_Ellipsis, Ellipsis)
def unmarshal_Ellipsis(space, u, tc):
return space.w_Ellipsis
@@ -399,7 +397,7 @@
m.put_int(x.co_firstlineno)
m.atom_str(TYPE_STRING, x.co_lnotab)
-StdObjSpace.MM.marshal_w.register(marshal_w_pycode, PyCode)
+model.MM.marshal_w.register(marshal_w_pycode, PyCode)
# helper for unmarshalling string lists of code objects.
# unfortunately they now can be interned or referenced,
Modified: pypy/branch/cpython-extension/pypy/objspace/std/model.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/model.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/model.py Wed Mar 31 00:17:06 2010
@@ -8,6 +8,12 @@
import pypy.interpreter.pycode
import pypy.interpreter.special
+_registered_implementations = set()
+def registerimplementation(implcls):
+ """Hint to objspace.std.model to register the implementation class."""
+ assert issubclass(implcls, W_Object)
+ _registered_implementations.add(implcls)
+
option_to_typename = {
"withsmallint" : ["smallintobject.W_SmallIntObject"],
"withstrslice" : ["strsliceobject.W_StringSliceObject"],
@@ -132,8 +138,7 @@
if config.objspace.std.withrope:
del self.typeorder[stringobject.W_StringObject]
- #check if we missed implementations
- from pypy.objspace.std.objspace import _registered_implementations
+ # check if we missed implementations
for implcls in _registered_implementations:
assert (implcls in self.typeorder or
implcls in self.imported_but_not_registered), (
@@ -146,7 +151,7 @@
# register the order in which types are converted into each others
# when trying to dispatch multimethods.
# XXX build these lists a bit more automatically later
-
+
if config.objspace.std.withsmallint:
self.typeorder[boolobject.W_BoolObject] += [
(smallintobject.W_SmallIntObject, boolobject.delegate_Bool2SmallInt),
@@ -171,11 +176,11 @@
]
self.typeorder[longobject.W_LongObject] += [
(floatobject.W_FloatObject, floatobject.delegate_Long2Float),
- (complexobject.W_ComplexObject,
+ (complexobject.W_ComplexObject,
complexobject.delegate_Long2Complex),
]
self.typeorder[floatobject.W_FloatObject] += [
- (complexobject.W_ComplexObject,
+ (complexobject.W_ComplexObject,
complexobject.delegate_Float2Complex),
]
self.typeorder[setobject.W_SetObject] += [
@@ -265,6 +270,60 @@
self._typeorder_with_empty_usersubcls = result
return self._typeorder_with_empty_usersubcls
+def _op_negated(function):
+ def op(space, w_1, w_2):
+ return space.not_(function(space, w_1, w_2))
+ return op
+
+def _op_swapped(function):
+ def op(space, w_1, w_2):
+ return function(space, w_2, w_1)
+ return op
+
+def _op_swapped_negated(function):
+ def op(space, w_1, w_2):
+ return space.not_(function(space, w_2, w_1))
+ return op
+
+OPERATORS = ['lt', 'le', 'eq', 'ne', 'gt', 'ge']
+OP_CORRESPONDANCES = [
+ ('eq', 'ne', _op_negated),
+ ('lt', 'gt', _op_swapped),
+ ('le', 'ge', _op_swapped),
+ ('lt', 'ge', _op_negated),
+ ('le', 'gt', _op_negated),
+ ('lt', 'le', _op_swapped_negated),
+ ('gt', 'ge', _op_swapped_negated),
+ ]
+for op1, op2, value in OP_CORRESPONDANCES[:]:
+ i = OP_CORRESPONDANCES.index((op1, op2, value))
+ OP_CORRESPONDANCES.insert(i+1, (op2, op1, value))
+
+def add_extra_comparisons():
+ """
+ Add the missing comparison operators if they were not explicitly
+ defined: eq <-> ne and lt <-> le <-> gt <-> ge.
+ We try to add them in the order defined by the OP_CORRESPONDANCES
+ table, thus favouring swapping the arguments over negating the result.
+ """
+ originalentries = {}
+ for op in OPERATORS:
+ originalentries[op] = getattr(MM, op).signatures()
+
+ for op1, op2, correspondance in OP_CORRESPONDANCES:
+ mirrorfunc = getattr(MM, op2)
+ for types in originalentries[op1]:
+ t1, t2 = types
+ if t1 is t2:
+ if not mirrorfunc.has_signature(types):
+ functions = getattr(MM, op1).getfunctions(types)
+ assert len(functions) == 1, ('Automatic'
+ ' registration of comparison functions'
+ ' only work when there is a single method for'
+ ' the operation.')
+ mirrorfunc.register(correspondance(functions[0]), *types)
+
+
# ____________________________________________________________
W_ANY = W_Root
@@ -276,11 +335,7 @@
__slots__ = ()
def __repr__(self):
- s = '%s(%s)' % (
- self.__class__.__name__,
- #', '.join(['%s=%r' % keyvalue for keyvalue in self.__dict__.items()])
- getattr(self, 'name', '')
- )
+ s = '%s(%s)' % (self.__class__.__name__, getattr(self, 'name', ''))
w_cls = getattr(self, 'w__class__', None)
if w_cls is not None and w_cls is not self:
s += ' instance of %s' % self.w__class__
@@ -313,13 +368,13 @@
break
else:
self.name = operatorsymbol
-
+
if extras.get('general__args__', False):
self.argnames_after = ['__args__']
if extras.get('w_varargs', False):
self.argnames_after = ['w_args']
if extras.get('varargs_w', False):
- self.argnames_after = ['args_w']
+ self.argnames_after = ['args_w']
self.argnames_after += extras.get('extra_args', [])
def install_not_sliced(self, typeorder, baked_perform_call=True):
@@ -352,3 +407,32 @@
#
mm.dispatch_tree = merge(self.dispatch_tree, other.dispatch_tree)
return mm
+
+
+class MM:
+ """StdObjSpace multimethods"""
+
+ call = StdObjSpaceMultiMethod('call', 1, ['__call__'],
+ general__args__=True)
+ init = StdObjSpaceMultiMethod('__init__', 1, general__args__=True)
+ getnewargs = StdObjSpaceMultiMethod('__getnewargs__', 1)
+ # special visible multimethods
+ int_w = StdObjSpaceMultiMethod('int_w', 1, []) # returns an unwrapped int
+ str_w = StdObjSpaceMultiMethod('str_w', 1, []) # returns an unwrapped string
+ float_w = StdObjSpaceMultiMethod('float_w', 1, []) # returns an unwrapped float
+ uint_w = StdObjSpaceMultiMethod('uint_w', 1, []) # returns an unwrapped unsigned int (r_uint)
+ unicode_w = StdObjSpaceMultiMethod('unicode_w', 1, []) # returns an unwrapped list of unicode characters
+ bigint_w = StdObjSpaceMultiMethod('bigint_w', 1, []) # returns an unwrapped rbigint
+ # NOTE: when adding more sometype_w() methods, you need to write a
+ # stub in default.py to raise a space.w_TypeError
+ marshal_w = StdObjSpaceMultiMethod('marshal_w', 1, [], extra_args=['marshaller'])
+ log = StdObjSpaceMultiMethod('log', 1, [], extra_args=['base'])
+
+ # add all regular multimethods here
+ for _name, _symbol, _arity, _specialnames in ObjSpace.MethodTable:
+ if _name not in locals():
+ mm = StdObjSpaceMultiMethod(_symbol, _arity, _specialnames)
+ locals()[_name] = mm
+ del mm
+
+ pow.extras['defaults'] = (None,)
Modified: pypy/branch/cpython-extension/pypy/objspace/std/noneobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/noneobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/noneobject.py Wed Mar 31 00:17:06 2010
@@ -2,9 +2,10 @@
None Object implementation
ok and tested
-"""
+"""
-from pypy.objspace.std.objspace import *
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
class W_NoneObject(W_Object):
from pypy.objspace.std.nonetype import none_typedef as typedef
Modified: pypy/branch/cpython-extension/pypy/objspace/std/nonetype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/nonetype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/nonetype.py Wed Mar 31 00:17:06 2010
@@ -1,4 +1,4 @@
-from pypy.objspace.std.stdtypedef import *
+from pypy.objspace.std.stdtypedef import StdTypeDef
# ____________________________________________________________
Modified: pypy/branch/cpython-extension/pypy/objspace/std/objectobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/objectobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/objectobject.py Wed Mar 31 00:17:06 2010
@@ -1,4 +1,5 @@
-from pypy.objspace.std.objspace import W_Object, register_all
+from pypy.objspace.std.model import W_Object
+from pypy.objspace.std.register_all import register_all
class W_ObjectObject(W_Object):
Modified: pypy/branch/cpython-extension/pypy/objspace/std/objecttype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/objecttype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/objecttype.py Wed Mar 31 00:17:06 2010
@@ -1,10 +1,9 @@
from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.objspace.descroperation import Object
+from pypy.interpreter.typedef import GetSetProperty, default_identity_hash
from pypy.interpreter import gateway
-from pypy.interpreter.typedef import default_identity_hash
-from pypy.objspace.std.stdtypedef import *
+from pypy.objspace.descroperation import Object
+from pypy.objspace.std.stdtypedef import StdTypeDef, no_hash_descr
from pypy.objspace.std.register_all import register_all
-from pypy.objspace.std.objspace import StdObjSpace
def descr__repr__(space, w_obj):
@@ -171,8 +170,8 @@
__repr__ = gateway.interp2app(descr__repr__),
__class__ = GetSetProperty(descr__class__, descr_set___class__),
__doc__ = '''The most base type''',
- __new__ = newmethod(descr__new__,
- unwrap_spec = [gateway.ObjSpace,gateway.W_Root,gateway.Arguments]),
+ __new__ = gateway.interp2app(descr__new__,
+ unwrap_spec = [gateway.ObjSpace,gateway.W_Root,gateway.Arguments]),
__hash__ = gateway.interp2app(default_identity_hash),
__reduce_ex__ = gateway.interp2app(descr__reduce_ex__,
unwrap_spec=[gateway.ObjSpace,gateway.W_Root,int]),
Modified: pypy/branch/cpython-extension/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/objspace.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/objspace.py Wed Mar 31 00:17:06 2010
@@ -1,304 +1,76 @@
-from pypy.objspace.std.register_all import register_all
+import __builtin__
+import types
+from pypy.interpreter import pyframe, function, special
from pypy.interpreter.baseobjspace import ObjSpace, Wrappable, UnpackValueError
-from pypy.interpreter.error import OperationError, operationerrfmt, debug_print
+from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter.typedef import get_unique_interplevel_subclass
-from pypy.interpreter import pyframe
-from pypy.interpreter import function
-from pypy.interpreter.pyopcode import unrolling_compare_dispatch_table, \
- BytecodeCorruption
+from pypy.objspace.std import (builtinshortcut, stdtypedef, frame, model,
+ transparent, callmethod, proxyobject)
+from pypy.objspace.descroperation import DescrOperation, raiseattrerror
from pypy.rlib.objectmodel import instantiate, r_dict
from pypy.rlib.debug import make_sure_not_resized
-from pypy.interpreter.gateway import PyPyCacheDir
-from pypy.tool.cache import Cache
-from pypy.tool.sourcetools import func_with_new_name
-from pypy.objspace.std.model import W_Object, UnwrapError
-from pypy.objspace.std.model import W_ANY, StdObjSpaceMultiMethod, StdTypeModel
-from pypy.objspace.std.multimethod import FailedToImplement, FailedToImplementArgs
-from pypy.objspace.descroperation import DescrOperation, raiseattrerror
-from pypy.objspace.std import stdtypedef
from pypy.rlib.rarithmetic import base_int
from pypy.rlib.objectmodel import we_are_translated
from pypy.rlib.jit import hint
-from pypy.rlib.unroll import unrolling_iterable
-import sys
-import os
-import __builtin__
-
-_registered_implementations = {}
-def registerimplementation(implcls):
- # hint to objspace.std.model to register the implementation class
- assert issubclass(implcls, W_Object)
- _registered_implementations[implcls] = True
-
-
-compare_table = [
- "lt", # "<"
- "le", # "<="
- "eq", # "=="
- "ne", # "!="
- "gt", # ">"
- "ge", # ">="
- ]
+from pypy.tool.sourcetools import func_with_new_name
-unrolling_compare_ops = unrolling_iterable(
- enumerate(compare_table))
+# Object imports
+from pypy.objspace.std.boolobject import W_BoolObject
+from pypy.objspace.std.complexobject import W_ComplexObject
+from pypy.objspace.std.dictmultiobject import W_DictMultiObject
+from pypy.objspace.std.floatobject import W_FloatObject
+from pypy.objspace.std.intobject import W_IntObject
+from pypy.objspace.std.listobject import W_ListObject
+from pypy.objspace.std.longobject import W_LongObject
+from pypy.objspace.std.noneobject import W_NoneObject
+from pypy.objspace.std.ropeobject import W_RopeObject
+from pypy.objspace.std.iterobject import W_SeqIterObject
+from pypy.objspace.std.setobject import W_SetObject, W_FrozensetObject
+from pypy.objspace.std.sliceobject import W_SliceObject
+from pypy.objspace.std.smallintobject import W_SmallIntObject
+from pypy.objspace.std.stringobject import W_StringObject
+from pypy.objspace.std.tupleobject import W_TupleObject
+from pypy.objspace.std.typeobject import W_TypeObject
+
+# types
+from pypy.objspace.std.inttype import wrapint
+from pypy.objspace.std.stringtype import wrapstr
+from pypy.objspace.std.unicodetype import wrapunicode
-##################################################################
class StdObjSpace(ObjSpace, DescrOperation):
"""The standard object space, implementing a general-purpose object
library in Restricted Python."""
- PACKAGE_PATH = 'objspace.std'
-
def initialize(self):
"NOT_RPYTHON: only for initializing the space."
- self._typecache = Cache()
-
- # Import all the object types and implementations
- self.model = StdTypeModel(self.config)
-
+ # setup all the object types and implementations
+ self.model = model.StdTypeModel(self.config)
- class StdObjSpaceFrame(pyframe.PyFrame):
- if self.config.objspace.std.optimized_int_add:
- if self.config.objspace.std.withsmallint:
- def BINARY_ADD(f, oparg, *ignored):
- from pypy.objspace.std.smallintobject import \
- W_SmallIntObject, add__SmallInt_SmallInt
- w_2 = f.popvalue()
- w_1 = f.popvalue()
- if type(w_1) is W_SmallIntObject and type(w_2) is W_SmallIntObject:
- try:
- w_result = add__SmallInt_SmallInt(f.space, w_1, w_2)
- except FailedToImplement:
- w_result = f.space.add(w_1, w_2)
- else:
- w_result = f.space.add(w_1, w_2)
- f.pushvalue(w_result)
- else:
- def BINARY_ADD(f, oparg, *ignored):
- from pypy.objspace.std.intobject import \
- W_IntObject, add__Int_Int
- w_2 = f.popvalue()
- w_1 = f.popvalue()
- if type(w_1) is W_IntObject and type(w_2) is W_IntObject:
- try:
- w_result = add__Int_Int(f.space, w_1, w_2)
- except FailedToImplement:
- w_result = f.space.add(w_1, w_2)
- else:
- w_result = f.space.add(w_1, w_2)
- f.pushvalue(w_result)
-
- if self.config.objspace.std.optimized_list_getitem:
- def BINARY_SUBSCR(f, *ignored):
- w_2 = f.popvalue()
- w_1 = f.popvalue()
- if type(w_1) is W_ListObject and type(w_2) is W_IntObject:
- try:
- w_result = w_1.wrappeditems[w_2.intval]
- except IndexError:
- raise OperationError(f.space.w_IndexError,
- f.space.wrap("list index out of range"))
- else:
- w_result = f.space.getitem(w_1, w_2)
- f.pushvalue(w_result)
-
- def LIST_APPEND(f, *ignored):
- w = f.popvalue()
- v = f.popvalue()
- if type(v) is W_ListObject:
- v.append(w)
- else:
- f.space.call_method(v, 'append', w)
+ self.FrameClass = frame.build_frame(self)
- if self.config.objspace.opcodes.CALL_LIKELY_BUILTIN:
- def CALL_LIKELY_BUILTIN(f, oparg, *ignored):
- from pypy.module.__builtin__ import OPTIMIZED_BUILTINS, Module
- from pypy.objspace.std.dictmultiobject import W_DictMultiObject
- w_globals = f.w_globals
- num = oparg >> 8
- assert isinstance(w_globals, W_DictMultiObject)
- w_value = w_globals.get_builtin_indexed(num)
- if w_value is None:
- builtins = f.get_builtin()
- assert isinstance(builtins, Module)
- w_builtin_dict = builtins.w_dict
- assert isinstance(w_builtin_dict, W_DictMultiObject)
- w_value = w_builtin_dict.get_builtin_indexed(num)
- ## if w_value is not None:
- ## print "CALL_LIKELY_BUILTIN fast"
- if w_value is None:
- varname = OPTIMIZED_BUILTINS[num]
- message = "global name '%s' is not defined"
- raise operationerrfmt(f.space.w_NameError,
- message, varname)
- nargs = oparg & 0xff
- w_function = w_value
- try:
- w_result = f.call_likely_builtin(w_function, nargs)
- # XXX XXX fix the problem of resume points!
- #rstack.resume_point("CALL_FUNCTION", f, nargs, returns=w_result)
- finally:
- f.dropvalues(nargs)
- f.pushvalue(w_result)
-
- def call_likely_builtin(f, w_function, nargs):
- if isinstance(w_function, function.Function):
- executioncontext = self.getexecutioncontext()
- executioncontext.c_call_trace(f, w_function)
- res = w_function.funccall_valuestack(nargs, f)
- executioncontext.c_return_trace(f, w_function)
- return res
- args = f.make_arguments(nargs)
- return f.space.call_args(w_function, args)
-
- if self.config.objspace.opcodes.CALL_METHOD:
- # def LOOKUP_METHOD(...):
- from pypy.objspace.std.callmethod import LOOKUP_METHOD
- # def CALL_METHOD(...):
- from pypy.objspace.std.callmethod import CALL_METHOD
-
- if self.config.objspace.std.optimized_comparison_op:
- def COMPARE_OP(f, testnum, *ignored):
- import operator
- w_2 = f.popvalue()
- w_1 = f.popvalue()
- w_result = None
- if (type(w_2) is W_IntObject and type(w_1) is W_IntObject
- and testnum < len(compare_table)):
- for i, attr in unrolling_compare_ops:
- if i == testnum:
- op = getattr(operator, attr)
- w_result = f.space.newbool(op(w_1.intval,
- w_2.intval))
- break
- else:
- for i, attr in unrolling_compare_dispatch_table:
- if i == testnum:
- w_result = getattr(f, attr)(w_1, w_2)
- break
- else:
- raise BytecodeCorruption, "bad COMPARE_OP oparg"
- f.pushvalue(w_result)
-
- if self.config.objspace.std.logspaceoptypes:
- _space_op_types = []
- for name, func in pyframe.PyFrame.__dict__.iteritems():
- if hasattr(func, 'binop'):
- operationname = func.binop
- def make_opimpl(operationname):
- def opimpl(f, *ignored):
- operation = getattr(f.space, operationname)
- w_2 = f.popvalue()
- w_1 = f.popvalue()
- if we_are_translated():
- s = operationname + ' ' + str(w_1) + ' ' + str(w_2)
- else:
- s = operationname + ' ' + w_1.__class__.__name__ + ' ' + w_2.__class__.__name__
- f._space_op_types.append(s)
- w_result = operation(w_1, w_2)
- f.pushvalue(w_result)
- return func_with_new_name(opimpl, "opcode_impl_for_%s" % operationname)
- locals()[name] = make_opimpl(operationname)
- elif hasattr(func, 'unaryop'):
- operationname = func.unaryop
- def make_opimpl(operationname):
- def opimpl(f, *ignored):
- operation = getattr(f.space, operationname)
- w_1 = f.popvalue()
- if we_are_translated():
- s = operationname + ' ' + str(w_1)
- else:
- s = operationname + ' ' + w_1.__class__.__name__
- f._space_op_types.append(s)
- w_result = operation(w_1)
- f.pushvalue(w_result)
- return func_with_new_name(opimpl, "opcode_impl_for_%s" % operationname)
- locals()[name] = make_opimpl(operationname)
-
- self.FrameClass = StdObjSpaceFrame
-
- # store the dict class on the space to access it in various places
- from pypy.objspace.std import dictmultiobject
- self.DictObjectCls = dictmultiobject.W_DictMultiObject
-
- from pypy.objspace.std import tupleobject
- self.TupleObjectCls = tupleobject.W_TupleObject
-
- if not self.config.objspace.std.withrope:
- from pypy.objspace.std import stringobject
- self.StringObjectCls = stringobject.W_StringObject
- else:
- from pypy.objspace.std import ropeobject
- self.StringObjectCls = ropeobject.W_RopeObject
- assert self.StringObjectCls in self.model.typeorder
-
- # install all the MultiMethods into the space instance
- for name, mm in self.MM.__dict__.items():
- if not isinstance(mm, StdObjSpaceMultiMethod):
- continue
- if not hasattr(self, name):
- if name.endswith('_w'): # int_w, str_w...: these do not return a wrapped object
- func = mm.install_not_sliced(self.model.typeorder, baked_perform_call=True)
- else:
- exprargs, expr, miniglobals, fallback = (
- mm.install_not_sliced(self.model.typeorder, baked_perform_call=False))
-
- func = stdtypedef.make_perform_trampoline('__mm_'+name,
- exprargs, expr, miniglobals,
- mm)
-
- # e.g. add(space, w_x, w_y)
- def make_boundmethod(func=func):
- def boundmethod(*args):
- return func(self, *args)
- return func_with_new_name(boundmethod, 'boundmethod_'+name)
- boundmethod = make_boundmethod()
- setattr(self, name, boundmethod) # store into 'space' instance
- elif self.config.objspace.std.builtinshortcut:
- from pypy.objspace.std import builtinshortcut
- if name.startswith('inplace_'):
- fallback_name = name[len('inplace_'):]
- if fallback_name in ('or', 'and'):
- fallback_name += '_'
- fallback_mm = self.MM.__dict__[fallback_name]
- else:
- fallback_mm = None
- builtinshortcut.install(self, mm, fallback_mm)
-
- if self.config.objspace.std.builtinshortcut:
- from pypy.objspace.std import builtinshortcut
- builtinshortcut.install_is_true(self, self.MM.nonzero, self.MM.len)
+ if self.config.objspace.std.withrope:
+ self.StringObjectCls = W_RopeObject
+ else:
+ self.StringObjectCls = W_StringObject
- # set up the method cache
- if self.config.objspace.std.withmethodcache:
- SIZE = 1 << self.config.objspace.std.methodcachesizeexp
- self.method_cache_versions = [None] * SIZE
- self.method_cache_names = [None] * SIZE
- self.method_cache_lookup_where = [(None, None)] * SIZE
- if self.config.objspace.std.withmethodcachecounter:
- self.method_cache_hits = {}
- self.method_cache_misses = {}
-
- # hack to avoid imports in the time-critical functions below
- for cls in self.model.typeorder:
- globals()[cls.__name__] = cls
- for cls in self.model.imported_but_not_registered:
- globals()[cls.__name__] = cls
+ self._install_multimethods()
# singletons
- self.w_None = W_NoneObject.w_None
+ self.w_None = W_NoneObject.w_None
self.w_False = W_BoolObject.w_False
- self.w_True = W_BoolObject.w_True
- from pypy.interpreter.special import NotImplemented, Ellipsis
- self.w_NotImplemented = self.wrap(NotImplemented(self))
- self.w_Ellipsis = self.wrap(Ellipsis(self))
+ self.w_True = W_BoolObject.w_True
+ self.w_NotImplemented = self.wrap(special.NotImplemented(self))
+ self.w_Ellipsis = self.wrap(special.Ellipsis(self))
# types
+ self.builtin_types = {}
for typedef in self.model.pythontypes:
w_type = self.gettypeobject(typedef)
+ self.builtin_types[typedef.name] = w_type
setattr(self, 'w_' + typedef.name, w_type)
+ self.builtin_types["NotImplemented"] = self.w_NotImplemented
+ self.builtin_types["Ellipsis"] = self.w_Ellipsis
# exceptions & builtins
self.make_builtins()
@@ -306,34 +78,48 @@
# the type of old-style classes
self.w_classobj = self.builtin.get('__metaclass__')
- # fix up a problem where multimethods apparently don't
- # like to define this at interp-level
- # HACK HACK HACK
- from pypy.objspace.std.typeobject import _HEAPTYPE
- old_flags = self.w_dict.__flags__
- self.w_dict.__flags__ |= _HEAPTYPE
- self.appexec([self.w_dict], """
- (dict):
- def fromkeys(cls, seq, value=None):
- r = cls()
- for s in seq:
- r[s] = value
- return r
- dict.fromkeys = classmethod(fromkeys)
- """)
- self.w_dict.__flags__ = old_flags
-
# final setup
self.setup_builtin_modules()
# Adding transparent proxy call
if self.config.objspace.std.withtproxy:
- w___pypy__ = self.getbuiltinmodule("__pypy__")
- from pypy.objspace.std.transparent import app_proxy, app_proxy_controller
-
- self.setattr(w___pypy__, self.wrap('tproxy'),
- self.wrap(app_proxy))
- self.setattr(w___pypy__, self.wrap('get_tproxy_controller'),
- self.wrap(app_proxy_controller))
+ transparent.setup(self)
+
+ def get_builtin_types(self):
+ return self.builtin_types
+
+ def _install_multimethods(self):
+ """Install all the MultiMethods into the space instance."""
+ model.add_extra_comparisons()
+ for name, mm in model.MM.__dict__.items():
+ if not isinstance(mm, model.StdObjSpaceMultiMethod):
+ continue
+ if not hasattr(self, name):
+ # int_w, str_w...: these do not return a wrapped object
+ if name.endswith('_w'):
+ func = mm.install_not_sliced(self.model.typeorder,
+ baked_perform_call=True)
+ else:
+ unsliced = mm.install_not_sliced(self.model.typeorder,
+ baked_perform_call=False)
+ exprargs, expr, miniglobals, fallback = unsliced
+ func = stdtypedef.make_perform_trampoline('__mm_'+name,
+ exprargs, expr,
+ miniglobals, mm)
+
+ boundmethod = types.MethodType(func, self, self.__class__)
+ setattr(self, name, boundmethod) # store into 'space' instance
+ elif self.config.objspace.std.builtinshortcut:
+ if name.startswith('inplace_'):
+ fallback_name = name[len('inplace_'):]
+ if fallback_name in ('or', 'and'):
+ fallback_name += '_'
+ fallback_mm = model.MM.__dict__[fallback_name]
+ else:
+ fallback_mm = None
+ builtinshortcut.install(self, mm, fallback_mm)
+ if self.config.objspace.std.builtinshortcut:
+ builtinshortcut.install_is_true(self, model.MM.nonzero,
+ model.MM.len)
def createexecutioncontext(self):
# add space specific fields to execution context
@@ -369,7 +155,7 @@
# annotation (see pypy/annotation/builtin.py)
if x is None:
return self.w_None
- if isinstance(x, W_Object):
+ if isinstance(x, model.W_Object):
raise TypeError, "attempt to wrap already wrapped object: %s"%(x,)
if isinstance(x, OperationError):
raise TypeError, ("attempt to wrap already wrapped exception: %s"%
@@ -380,10 +166,8 @@
else:
return self.newint(x)
if isinstance(x, str):
- from pypy.objspace.std.stringtype import wrapstr
return wrapstr(self, x)
if isinstance(x, unicode):
- from pypy.objspace.std.unicodetype import wrapunicode
return wrapunicode(self, x)
if isinstance(x, float):
return W_FloatObject(x)
@@ -448,7 +232,6 @@
w_result = self.wrap_exception_cls(x)
if w_result is not None:
return w_result
- #print "fake-wrapping", x
from fake import fake_object
return fake_object(self, x)
@@ -457,23 +240,22 @@
def wrap_exception_cls(self, x):
"""NOT_RPYTHON"""
if hasattr(self, 'w_' + x.__name__):
- w_result = getattr(self, 'w_' + x.__name__)
+ w_result = getattr(self, 'w_' + x.__name__)
return w_result
return None
wrap_exception_cls._annspecialcase_ = "override:wrap_exception_cls"
-
+
def unwrap(self, w_obj):
if isinstance(w_obj, Wrappable):
return w_obj
- if isinstance(w_obj, W_Object):
+ if isinstance(w_obj, model.W_Object):
return w_obj.unwrap(self)
- raise UnwrapError, "cannot unwrap: %r" % w_obj
+ raise model.UnwrapError, "cannot unwrap: %r" % w_obj
def newint(self, intval):
# this time-critical and circular-imports-funny method was stored
# on 'self' by initialize()
# not sure how bad this is:
- from pypy.objspace.std.inttype import wrapint
return wrapint(self, intval)
def newfloat(self, floatval):
@@ -486,18 +268,15 @@
return W_LongObject.fromint(self, val)
def newtuple(self, list_w):
- from pypy.objspace.std.tupletype import wraptuple
assert isinstance(list_w, list)
make_sure_not_resized(list_w)
- return wraptuple(self, list_w)
+ return W_TupleObject(list_w)
def newlist(self, list_w):
- from pypy.objspace.std.listobject import W_ListObject
return W_ListObject(list_w)
def newdict(self, module=False, instance=False, classofinstance=None,
from_strdict_shared=None, strdict=False):
- from pypy.objspace.std.dictmultiobject import W_DictMultiObject
return W_DictMultiObject.allocate_and_init_instance(
self, module=module, instance=instance,
classofinstance=classofinstance,
@@ -675,21 +454,21 @@
def finditem_str(self, w_obj, key):
# performance shortcut to avoid creating the OperationError(KeyError)
- if (isinstance(w_obj, self.DictObjectCls) and
+ if (isinstance(w_obj, W_DictMultiObject) and
not w_obj.user_overridden_class):
return w_obj.getitem_str(key)
return ObjSpace.finditem_str(self, w_obj, key)
def finditem(self, w_obj, w_key):
# performance shortcut to avoid creating the OperationError(KeyError)
- if (isinstance(w_obj, self.DictObjectCls) and
+ if (isinstance(w_obj, W_DictMultiObject) and
not w_obj.user_overridden_class):
return w_obj.getitem(w_key)
return ObjSpace.finditem(self, w_obj, w_key)
def set_str_keyed_item(self, w_obj, key, w_value, shadows_type=True):
# performance shortcut to avoid creating the OperationError(KeyError)
- if (isinstance(w_obj, self.DictObjectCls) and
+ if (isinstance(w_obj, W_DictMultiObject) and
not w_obj.user_overridden_class):
w_obj.set_str_keyed_item(key, w_value, shadows_type)
else:
@@ -710,37 +489,10 @@
def call_method(self, w_obj, methname, *arg_w):
if self.config.objspace.opcodes.CALL_METHOD:
- from pypy.objspace.std.callmethod import call_method_opt
- return call_method_opt(self, w_obj, methname, *arg_w)
+ return callmethod.call_method_opt(self, w_obj, methname, *arg_w)
else:
return ObjSpace.call_method(self, w_obj, methname, *arg_w)
def raise_key_error(self, w_key):
e = self.call_function(self.w_KeyError, w_key)
raise OperationError(self.w_KeyError, e)
-
- class MM:
- "Container for multimethods."
- call = StdObjSpaceMultiMethod('call', 1, ['__call__'], general__args__=True)
- init = StdObjSpaceMultiMethod('__init__', 1, general__args__=True)
- getnewargs = StdObjSpaceMultiMethod('__getnewargs__', 1)
- # special visible multimethods
- int_w = StdObjSpaceMultiMethod('int_w', 1, []) # returns an unwrapped int
- str_w = StdObjSpaceMultiMethod('str_w', 1, []) # returns an unwrapped string
- float_w = StdObjSpaceMultiMethod('float_w', 1, []) # returns an unwrapped float
- uint_w = StdObjSpaceMultiMethod('uint_w', 1, []) # returns an unwrapped unsigned int (r_uint)
- unicode_w = StdObjSpaceMultiMethod('unicode_w', 1, []) # returns an unwrapped list of unicode characters
- bigint_w = StdObjSpaceMultiMethod('bigint_w', 1, []) # returns an unwrapped rbigint
- # NOTE: when adding more sometype_w() methods, you need to write a
- # stub in default.py to raise a space.w_TypeError
- marshal_w = StdObjSpaceMultiMethod('marshal_w', 1, [], extra_args=['marshaller'])
- log = StdObjSpaceMultiMethod('log', 1, [], extra_args=['base'])
-
- # add all regular multimethods here
- for _name, _symbol, _arity, _specialnames in ObjSpace.MethodTable:
- if _name not in locals():
- mm = StdObjSpaceMultiMethod(_symbol, _arity, _specialnames)
- locals()[_name] = mm
- del mm
-
- pow.extras['defaults'] = (None,)
Modified: pypy/branch/cpython-extension/pypy/objspace/std/proxyobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/proxyobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/proxyobject.py Wed Mar 31 00:17:06 2010
@@ -2,7 +2,7 @@
""" transparent list implementation
"""
-from pypy.objspace.std.objspace import *
+from pypy.objspace.std.model import registerimplementation, W_Object
from pypy.objspace.std.proxy_helpers import register_type
from pypy.interpreter.error import OperationError
from pypy.interpreter import baseobjspace, argument
@@ -73,7 +73,7 @@
W_Transparent.__name__ = name
return W_Transparent
-W_Transparent = transparent_class('W_Transparent', Wrappable)
+W_Transparent = transparent_class('W_Transparent', baseobjspace.Wrappable)
W_TransparentObject = transparent_class('W_TransparentObject', W_Object)
from pypy.objspace.std.objecttype import object_typedef
Modified: pypy/branch/cpython-extension/pypy/objspace/std/rangeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/rangeobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/rangeobject.py Wed Mar 31 00:17:06 2010
@@ -1,12 +1,12 @@
-from pypy.objspace.std.objspace import *
+from pypy.interpreter.error import OperationError
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
+from pypy.objspace.std.multimethod import FailedToImplement
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.objspace.std.inttype import wrapint
from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
from pypy.objspace.std.listobject import W_ListObject
-from pypy.objspace.std import listtype
-from pypy.objspace.std import iterobject
-
-from pypy.objspace.std import slicetype
+from pypy.objspace.std import listtype, iterobject, slicetype
from pypy.interpreter import gateway, baseobjspace
def length(start, stop, step):
Modified: pypy/branch/cpython-extension/pypy/objspace/std/register_all.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/register_all.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/register_all.py Wed Mar 31 00:17:06 2010
@@ -1,60 +1,49 @@
+from pypy.objspace.std import model, stdtypedef
_name_mappings = {
'and': 'and_',
'or': 'or_',
}
-
+
def register_all(module_dict, *alt_ns):
- """register implementations for multimethods.
+ """register implementations for multimethods.
By default a (name, object) pair of the given module dictionary
is registered on the multimethod 'name' of StdObjSpace.
If the name doesn't exist then the alternative namespace is tried
- for registration.
+ for registration.
"""
- from pypy.objspace.std.objspace import StdObjSpace
- from pypy.objspace.std.model import W_ANY, W_Object
- from pypy.objspace.std.stdtypedef import StdTypeDef
- namespaces = list(alt_ns) + [StdObjSpace.MM, StdObjSpace]
+ namespaces = list(alt_ns) + [model.MM]
for name, obj in module_dict.items():
- if name.startswith('app_'):
- print "%s: direct app definitions deprecated" % name
+ if name.startswith('app_'):
+ print "%s: direct app definitions deprecated" % name
if name.find('__')<1 or name.startswith('app_'):
continue
funcname, sig = name.split('__')
l=[]
for i in sig.split('_'):
if i == 'ANY': # just in case W_ANY is not in module_dict
- icls = W_ANY
+ icls = model.W_ANY
elif i == 'Object': # just in case W_Object is not in module_dict
- icls = W_Object
+ icls = model.W_Object
else:
icls = (module_dict.get('W_%s' % i) or
module_dict.get('W_%sObject' % i))
if icls is None:
x = module_dict.get(i)
- if isinstance(x, StdTypeDef):
+ if isinstance(x, stdtypedef.StdTypeDef):
icls = x.any
if icls is None:
raise ValueError, \
"no W_%s or W_%sObject for the definition of %s" % (
i, i, name)
l.append(icls)
-
- #XXX trying to be too clever at the moment for userobject.SpecialMethod
- #if len(l) != obj.func_code.co_argcount-1:
- # raise ValueError, \
- # "function name %s doesn't specify exactly %d arguments" % (
- # repr(name), obj.func_code.co_argcount-1)
-
funcname = _name_mappings.get(funcname, funcname)
func = hack_func_by_name(funcname, namespaces)
func.register(obj, *l)
- add_extra_comparisons()
-
def hack_func_by_name(funcname, namespaces):
for ns in namespaces:
@@ -64,76 +53,5 @@
else:
if hasattr(ns, funcname):
return getattr(ns, funcname)
- #import typetype
- #try:
- # return getattr(typetype.W_TypeType, funcname)
- #except AttributeError:
- # pass # catches not only the getattr() but the typetype.W_TypeType
- # # in case it is not fully imported yet :-((((
- from pypy.objspace.std import objecttype
- try:
- return getattr(objecttype, funcname)
- except AttributeError:
- pass
raise NameError, ("trying hard but not finding a multimethod named %s" %
funcname)
-
-
-def op_negated(function):
- def op(space, w_1, w_2):
- return space.not_(function(space, w_1, w_2))
- return op
-
-def op_swapped(function):
- def op(space, w_1, w_2):
- return function(space, w_2, w_1)
- return op
-
-def op_swapped_negated(function):
- def op(space, w_1, w_2):
- return space.not_(function(space, w_2, w_1))
- return op
-
-OPERATORS = ['lt', 'le', 'eq', 'ne', 'gt', 'ge']
-OP_CORRESPONDANCES = [
- ('eq', 'ne', op_negated),
- ('lt', 'gt', op_swapped),
- ('le', 'ge', op_swapped),
- ('lt', 'ge', op_negated),
- ('le', 'gt', op_negated),
- ('lt', 'le', op_swapped_negated),
- ('gt', 'ge', op_swapped_negated),
- ]
-for op1, op2, value in OP_CORRESPONDANCES[:]:
- i = OP_CORRESPONDANCES.index((op1, op2, value))
- OP_CORRESPONDANCES.insert(i+1, (op2, op1, value))
-
-def add_extra_comparisons():
- """
- Add the missing comparison operators if they were not explicitly
- defined: eq <-> ne and lt <-> le <-> gt <-> ge.
- We try to add them in the order defined by the OP_CORRESPONDANCES
- table, thus favouring swapping the arguments over negating the result.
- """
- from pypy.objspace.std.objspace import StdObjSpace
- originalentries = {}
- for op in OPERATORS:
- originalentries[op] = getattr(StdObjSpace.MM, op).signatures()
-
- for op1, op2, correspondance in OP_CORRESPONDANCES:
- mirrorfunc = getattr(StdObjSpace.MM, op2)
- for types in originalentries[op1]:
- t1, t2 = types
- if t1 is t2:
- if not mirrorfunc.has_signature(types):
- functions = getattr(StdObjSpace.MM, op1).getfunctions(types)
- assert len(functions) == 1, ('Automatic'
- ' registration of comparison functions'
- ' only work when there is a single method for'
- ' the operation.')
- #print 'adding %s <<<%s>>> %s as %s(%s)' % (
- # t1, op2, t2,
- # correspondance.func_name, functions[0].func_name)
- mirrorfunc.register(
- correspondance(functions[0]),
- *types)
Modified: pypy/branch/cpython-extension/pypy/objspace/std/ropeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/ropeobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/ropeobject.py Wed Mar 31 00:17:06 2010
@@ -1,5 +1,5 @@
-from pypy.objspace.std.objspace import register_all, W_Object
-from pypy.objspace.std.objspace import registerimplementation
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.multimethod import FailedToImplement
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter import gateway
Modified: pypy/branch/cpython-extension/pypy/objspace/std/ropeunicodeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/ropeunicodeobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/ropeunicodeobject.py Wed Mar 31 00:17:06 2010
@@ -1,5 +1,5 @@
-from pypy.objspace.std.objspace import register_all, W_Object
-from pypy.objspace.std.objspace import registerimplementation
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.multimethod import FailedToImplement
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter import gateway
Modified: pypy/branch/cpython-extension/pypy/objspace/std/setobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/setobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/setobject.py Wed Mar 31 00:17:06 2010
@@ -1,7 +1,8 @@
-from pypy.objspace.std.objspace import W_Object, OperationError
-from pypy.objspace.std.objspace import registerimplementation, register_all
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
from pypy.rlib.objectmodel import r_dict
from pypy.rlib.rarithmetic import intmask, r_uint
+from pypy.interpreter.error import OperationError
from pypy.interpreter import gateway
from pypy.interpreter.argument import Signature
from pypy.objspace.std.settype import set_typedef as settypedef
Modified: pypy/branch/cpython-extension/pypy/objspace/std/settype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/settype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/settype.py Wed Mar 31 00:17:06 2010
@@ -1,8 +1,7 @@
from pypy.interpreter.error import OperationError
-from pypy.objspace.std.objspace import register_all
-from pypy.objspace.std.stdtypedef import StdTypeDef, newmethod, no_hash_descr
-from pypy.objspace.std.stdtypedef import SMM
-from pypy.interpreter.gateway import NoneNotWrapped
+from pypy.interpreter import gateway
+from pypy.objspace.std.register_all import register_all
+from pypy.objspace.std.stdtypedef import StdTypeDef, no_hash_descr, SMM
from pypy.interpreter import gateway
set_add = SMM('add', 2,
@@ -77,9 +76,9 @@
__doc__ = """set(iterable) --> set object
Build an unordered collection.""",
- __new__ = newmethod(descr__new__, unwrap_spec=[gateway.ObjSpace,
- gateway.W_Root,
- gateway.Arguments]),
+ __new__ = gateway.interp2app(descr__new__, unwrap_spec=[gateway.ObjSpace,
+ gateway.W_Root,
+ gateway.Arguments]),
__hash__ = no_hash_descr,
)
Modified: pypy/branch/cpython-extension/pypy/objspace/std/sliceobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/sliceobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/sliceobject.py Wed Mar 31 00:17:06 2010
@@ -1,12 +1,9 @@
-"""
-Reviewed 03-06-21
+"""Slice object"""
-slice object construction tested, OK
-indices method tested, OK
-"""
-
-from pypy.objspace.std.objspace import *
+from pypy.interpreter.error import OperationError
from pypy.interpreter import gateway
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.slicetype import _Eval_SliceIndex
Modified: pypy/branch/cpython-extension/pypy/objspace/std/slicetype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/slicetype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/slicetype.py Wed Mar 31 00:17:06 2010
@@ -1,6 +1,6 @@
-import sys
-from pypy.interpreter import baseobjspace
-from pypy.objspace.std.stdtypedef import *
+from pypy.interpreter import baseobjspace, gateway
+from pypy.interpreter.typedef import GetSetProperty
+from pypy.objspace.std.stdtypedef import StdTypeDef, SMM, no_hash_descr
from pypy.objspace.std.register_all import register_all
from pypy.interpreter.error import OperationError
@@ -88,7 +88,7 @@
__doc__ = '''slice([start,] stop[, step])
Create a slice object. This is used for extended slicing (e.g. a[0:10:2]).''',
- __new__ = newmethod(descr__new__),
+ __new__ = gateway.interp2app(descr__new__),
__hash__ = no_hash_descr,
start = slicewprop('w_start'),
stop = slicewprop('w_stop'),
Modified: pypy/branch/cpython-extension/pypy/objspace/std/smallintobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/smallintobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/smallintobject.py Wed Mar 31 00:17:06 2010
@@ -2,7 +2,10 @@
Implementation of small ints, stored as odd-valued pointers in the
translated PyPy. To enable them, see inttype.py.
"""
-from pypy.objspace.std.objspace import *
+from pypy.interpreter.error import OperationError
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
+from pypy.objspace.std.multimethod import FailedToImplementArgs
from pypy.objspace.std.noneobject import W_NoneObject
from pypy.rlib.rarithmetic import ovfcheck, ovfcheck_lshift, LONG_BIT, r_uint
from pypy.objspace.std.inttype import wrapint
Modified: pypy/branch/cpython-extension/pypy/objspace/std/stdtypedef.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/stdtypedef.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/stdtypedef.py Wed Mar 31 00:17:06 2010
@@ -4,14 +4,13 @@
from pypy.interpreter.typedef import descr_get_dict, descr_set_dict
from pypy.interpreter.typedef import no_hash_descr, descr_del_dict
from pypy.interpreter.baseobjspace import SpaceCache
+from pypy.objspace.std import model
from pypy.objspace.std.model import StdObjSpaceMultiMethod
from pypy.objspace.std.multimethod import FailedToImplement
from pypy.rlib import jit
from pypy.tool.sourcetools import compile2
-__all__ = ['StdTypeDef', 'newmethod', 'gateway',
- 'GetSetProperty', 'Member',
- 'SMM', 'descr_get_dict', 'no_hash_descr']
+__all__ = ['StdTypeDef', 'SMM', 'no_hash_descr']
SMM = StdObjSpaceMultiMethod
@@ -42,11 +41,6 @@
std_dict_descr = GetSetProperty(descr_get_dict, descr_set_dict, descr_del_dict)
std_dict_descr.name = '__dict__'
-def newmethod(descr_new, unwrap_spec=None):
- "NOT_RPYTHON: initialization-time only."
- # this is turned into a static method by the constructor of W_TypeObject.
- return gateway.interp2app(descr_new, unwrap_spec=unwrap_spec)
-
# ____________________________________________________________
#
# All the code below fishes from the multimethod registration tables
@@ -288,8 +282,8 @@
def slicemultimethods(space, typedef):
"""NOT_RPYTHON"""
result = {}
- # import and slice all multimethods of the space.MM container
- for multimethod in hack_out_multimethods(space.MM.__dict__):
+ # import and slice all multimethods of the MM container
+ for multimethod in hack_out_multimethods(model.MM.__dict__):
slicemultimethod(space, multimethod, typedef, result)
# import all multimethods defined directly on the type without slicing
for multimethod in typedef.local_multimethods:
@@ -301,9 +295,8 @@
multimethods that have an implementation whose first typed argument
is 'cls'.
"""
- from pypy.objspace.std.objspace import StdObjSpace # XXX for now
typedef = cls.typedef
- for multimethod in hack_out_multimethods(StdObjSpace.MM.__dict__):
+ for multimethod in hack_out_multimethods(model.MM.__dict__):
if cls in multimethod.dispatch_tree:
yield multimethod, False
for multimethod in typedef.local_multimethods:
Modified: pypy/branch/cpython-extension/pypy/objspace/std/stringobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/stringobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/stringobject.py Wed Mar 31 00:17:06 2010
@@ -1,5 +1,5 @@
-from pypy.objspace.std.objspace import register_all, W_Object
-from pypy.objspace.std.objspace import registerimplementation
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.multimethod import FailedToImplement
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter import gateway
Modified: pypy/branch/cpython-extension/pypy/objspace/std/stringtype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/stringtype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/stringtype.py Wed Mar 31 00:17:06 2010
@@ -1,4 +1,5 @@
-from pypy.objspace.std.stdtypedef import *
+from pypy.interpreter import gateway
+from pypy.objspace.std.stdtypedef import StdTypeDef, SMM
from pypy.objspace.std.basestringtype import basestring_typedef
from sys import maxint
@@ -42,7 +43,7 @@
def sliced(space, s, start, stop, orig_obj):
assert start >= 0
- assert stop >= 0
+ assert stop >= 0
assert not space.config.objspace.std.withrope
if start == 0 and stop == len(s) and space.is_w(space.type(orig_obj), space.w_str):
return orig_obj
@@ -294,7 +295,7 @@
# ____________________________________________________________
str_typedef = StdTypeDef("str", basestring_typedef,
- __new__ = newmethod(descr__new__),
+ __new__ = gateway.interp2app(descr__new__),
__doc__ = '''str(object) -> string
Return a nice string representation of the object.
@@ -326,4 +327,3 @@
if u_self[start+i] != prefix[i]:
return False
return True
-
Modified: pypy/branch/cpython-extension/pypy/objspace/std/strjoinobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/strjoinobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/strjoinobject.py Wed Mar 31 00:17:06 2010
@@ -1,4 +1,5 @@
-from pypy.objspace.std.objspace import *
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.stringobject import W_StringObject
from pypy.objspace.std.unicodeobject import delegate_String2Unicode
Modified: pypy/branch/cpython-extension/pypy/objspace/std/strsliceobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/strsliceobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/strsliceobject.py Wed Mar 31 00:17:06 2010
@@ -1,4 +1,6 @@
-from pypy.objspace.std.objspace import *
+from pypy.interpreter.error import OperationError
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.stringobject import W_StringObject
from pypy.objspace.std.unicodeobject import delegate_String2Unicode
from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
Modified: pypy/branch/cpython-extension/pypy/objspace/std/test/test_complexobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/test/test_complexobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/test/test_complexobject.py Wed Mar 31 00:17:06 2010
@@ -1,7 +1,7 @@
import py
from pypy.objspace.std import complexobject as cobj
from pypy.objspace.std import complextype as cobjtype
-from pypy.objspace.std.objspace import FailedToImplement
+from pypy.objspace.std.multimethod import FailedToImplement
from pypy.objspace.std.stringobject import W_StringObject
from pypy.objspace.std import StdObjSpace
Modified: pypy/branch/cpython-extension/pypy/objspace/std/test/test_dictmultiobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/test/test_dictmultiobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/test/test_dictmultiobject.py Wed Mar 31 00:17:06 2010
@@ -372,6 +372,12 @@
assert {}.fromkeys([]) == {}
assert {1: 0, 2: 0, 3: 0}.fromkeys([1, '1'], 'j') == (
{1: 'j', '1': 'j'})
+ class D(dict):
+ def __new__(cls):
+ return E()
+ class E(dict):
+ pass
+ assert isinstance(D.fromkeys([1, 2]), E)
def test_str_uses_repr(self):
class D(dict):
Modified: pypy/branch/cpython-extension/pypy/objspace/std/test/test_floatobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/test/test_floatobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/test/test_floatobject.py Wed Mar 31 00:17:06 2010
@@ -1,5 +1,5 @@
from pypy.objspace.std import floatobject as fobj
-from pypy.objspace.std.objspace import FailedToImplement
+from pypy.objspace.std.multimethod import FailedToImplement
import py
class TestW_FloatObject:
@@ -146,8 +146,7 @@
raises(ValueError, pw, -1.0, 0.5)
assert pw(-1.0, 2.0) == 1.0
assert pw(-1.0, 3.0) == -1.0
- #assert pw(-1.0, 1e200) == 1.0 -- either 1.0, or ValueError, are
- # -- acceptable answers IMHO
+ assert pw(-1.0, 1e200) == 1.0
def test_pow_neg_base(self):
def pw(x, y):
@@ -213,6 +212,8 @@
assert 13 <= 13.01
def test_comparison_more(self):
+ import sys
+ is_pypy = '__pypy__' in sys.builtin_module_names
infinity = 1e200*1e200
nan = infinity/infinity
for x in (123, 1 << 30,
@@ -240,12 +241,27 @@
assert ((x + 1) > float(x))
assert not ((x + 1) < float(x))
#
- #assert not (x == nan)
- #assert not (x >= nan)
- #assert not (x <= nan)
- #assert (x != nan)
- #assert not (x > nan)
- #assert not (x < nan)
+ assert not (x == infinity)
+ assert not (x >= infinity)
+ assert (x <= infinity)
+ assert (x != infinity)
+ assert not (x > infinity)
+ assert (x < infinity)
+ #
+ assert not (x == -infinity)
+ assert (x >= -infinity)
+ assert not (x <= -infinity)
+ assert (x != -infinity)
+ assert (x > -infinity)
+ assert not (x < -infinity)
+ #
+ if is_pypy:
+ assert not (x == nan)
+ assert not (x >= nan)
+ assert not (x <= nan)
+ assert (x != nan)
+ assert not (x > nan)
+ assert not (x < nan)
#
assert (float(x) == x)
assert (float(x) <= x)
@@ -268,19 +284,35 @@
assert (float(x) < (x + 1))
assert not (float(x) > (x + 1))
#
- #assert not (nan == x)
- #assert not (nan <= x)
- #assert not (nan >= x)
- #assert (nan != x)
- #assert not (nan < x)
- #assert not (nan > x)
+ assert not (infinity == x)
+ assert (infinity >= x)
+ assert not (infinity <= x)
+ assert (infinity != x)
+ assert (infinity > x)
+ assert not (infinity < x)
+ #
+ assert not (-infinity == x)
+ assert not (-infinity >= x)
+ assert (-infinity <= x)
+ assert (-infinity != x)
+ assert not (-infinity > x)
+ assert (-infinity < x)
+ #
+ if is_pypy:
+ assert not (nan == x)
+ assert not (nan <= x)
+ assert not (nan >= x)
+ assert (nan != x)
+ assert not (nan < x)
+ assert not (nan > x)
def test_multimethod_slice(self):
assert 5 .__add__(3.14) is NotImplemented
assert 3.25 .__add__(5) == 8.25
- if hasattr(int, '__eq__'): # for py.test -A: CPython is inconsistent
- assert 5 .__eq__(3.14) is NotImplemented
- assert 3.14 .__eq__(5) is False
+ # xxx we are also a bit inconsistent about the following
+ #if hasattr(int, '__eq__'): # for py.test -A: CPython is inconsistent
+ # assert 5 .__eq__(3.14) is NotImplemented
+ # assert 3.14 .__eq__(5) is False
#if hasattr(long, '__eq__'): # for py.test -A: CPython is inconsistent
# assert 5L .__eq__(3.14) is NotImplemented
# assert 3.14 .__eq__(5L) is False
Modified: pypy/branch/cpython-extension/pypy/objspace/std/test/test_intobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/test/test_intobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/test/test_intobject.py Wed Mar 31 00:17:06 2010
@@ -1,7 +1,7 @@
import py
import sys
from pypy.objspace.std import intobject as iobj
-from pypy.objspace.std.objspace import FailedToImplement
+from pypy.objspace.std.multimethod import FailedToImplement
from pypy.rlib.rarithmetic import r_uint
from pypy.rlib.rbigint import rbigint
Modified: pypy/branch/cpython-extension/pypy/objspace/std/test/test_listobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/test/test_listobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/test/test_listobject.py Wed Mar 31 00:17:06 2010
@@ -2,6 +2,7 @@
from pypy.objspace.std.listobject import W_ListObject
from pypy.interpreter.error import OperationError
+from pypy.conftest import gettestobjspace
class TestW_ListObject:
@@ -769,3 +770,18 @@
l = [1,2,3,4]
l.__delslice__(0, 2)
assert l == [3, 4]
+
+
+class AppTestListFastSubscr:
+
+ def setup_class(cls):
+ cls.space = gettestobjspace(**{"objspace.std.optimized_list_getitem" :
+ True})
+
+ def test_getitem(self):
+ import operator
+ l = [0, 1, 2, 3, 4]
+ for i in xrange(5):
+ assert l[i] == i
+ assert l[3:] == [3, 4]
+ raises(TypeError, operator.getitem, l, "str")
Modified: pypy/branch/cpython-extension/pypy/objspace/std/test/test_longobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/test/test_longobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/test/test_longobject.py Wed Mar 31 00:17:06 2010
@@ -1,7 +1,7 @@
import py
import sys
from pypy.objspace.std import longobject as lobj
-from pypy.objspace.std.objspace import FailedToImplement
+from pypy.objspace.std.multimethod import FailedToImplement
from pypy.interpreter.error import OperationError
from pypy.rlib.rarithmetic import r_uint
from pypy.rlib.rbigint import rbigint
@@ -60,37 +60,79 @@
assert a == 3L
def test_compare(self):
- BIG = 1L << 9999
- assert 0 == 0L
- assert not (0 != 0L)
- assert 0L == 0
- assert not (0L != 0)
- assert not (0 == BIG)
- assert 0 != BIG
- assert not (BIG == 0)
- assert BIG != 0
- assert not (0L == BIG)
- assert 0L != BIG
- assert 0 <= 0L
- assert not (0 < 0L)
- assert 0 <= BIG
- assert 0 < BIG
- assert not (BIG <= 0)
- assert not (BIG < 0)
- assert 0L <= 0L
- assert not (0L < 0L)
- assert 0L <= BIG
- assert 0L < BIG
- assert not (BIG <= 0L)
- assert not (BIG < 0L)
- assert not (0 <= -BIG)
- assert not (0 < -BIG)
- assert -BIG <= 0
- assert -BIG < 0
- assert not (0L <= -BIG)
- assert not (0L < -BIG)
- assert -BIG <= 0L
- assert -BIG < 0L
+ for BIG in (1L, 1L << 62, 1L << 9999):
+ assert 0 == 0L
+ assert not (0 != 0L)
+ assert 0L == 0
+ assert not (0L != 0)
+ assert not (0 == BIG)
+ assert 0 != BIG
+ assert not (BIG == 0)
+ assert BIG != 0
+ assert not (0L == BIG)
+ assert 0L != BIG
+ assert 0 <= 0L
+ assert not (0 < 0L)
+ assert 0 <= BIG
+ assert 0 < BIG
+ assert not (BIG <= 0)
+ assert not (BIG < 0)
+ assert 0L <= 0L
+ assert not (0L < 0L)
+ assert 0L <= BIG
+ assert 0L < BIG
+ assert not (BIG <= 0L)
+ assert not (BIG < 0L)
+ assert not (0 <= -BIG)
+ assert not (0 < -BIG)
+ assert -BIG <= 0
+ assert -BIG < 0
+ assert not (0L <= -BIG)
+ assert not (0L < -BIG)
+ assert -BIG <= 0L
+ assert -BIG < 0L
+ #
+ assert not (BIG < int(BIG))
+ assert (BIG <= int(BIG))
+ assert (BIG == int(BIG))
+ assert not (BIG != int(BIG))
+ assert not (BIG > int(BIG))
+ assert (BIG >= int(BIG))
+ #
+ assert (BIG < int(BIG)+1)
+ assert (BIG <= int(BIG)+1)
+ assert not (BIG == int(BIG)+1)
+ assert (BIG != int(BIG)+1)
+ assert not (BIG > int(BIG)+1)
+ assert not (BIG >= int(BIG)+1)
+ #
+ assert not (BIG < int(BIG)-1)
+ assert not (BIG <= int(BIG)-1)
+ assert not (BIG == int(BIG)-1)
+ assert (BIG != int(BIG)-1)
+ assert (BIG > int(BIG)-1)
+ assert (BIG >= int(BIG)-1)
+ #
+ assert not (int(BIG) < BIG)
+ assert (int(BIG) <= BIG)
+ assert (int(BIG) == BIG)
+ assert not (int(BIG) != BIG)
+ assert not (int(BIG) > BIG)
+ assert (int(BIG) >= BIG)
+ #
+ assert not (int(BIG)+1 < BIG)
+ assert not (int(BIG)+1 <= BIG)
+ assert not (int(BIG)+1 == BIG)
+ assert (int(BIG)+1 != BIG)
+ assert (int(BIG)+1 > BIG)
+ assert (int(BIG)+1 >= BIG)
+ #
+ assert (int(BIG)-1 < BIG)
+ assert (int(BIG)-1 <= BIG)
+ assert not (int(BIG)-1 == BIG)
+ assert (int(BIG)-1 != BIG)
+ assert not (int(BIG)-1 > BIG)
+ assert not (int(BIG)-1 >= BIG)
def test_conversion(self):
class long2(long):
Modified: pypy/branch/cpython-extension/pypy/objspace/std/test/test_smallintobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/test/test_smallintobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/test/test_smallintobject.py Wed Mar 31 00:17:06 2010
@@ -5,9 +5,10 @@
# py.test.skip("WITHSMALLINT is not enabled")
from pypy.objspace.std.inttype import wrapint
-from pypy.objspace.std.objspace import FailedToImplement
+from pypy.objspace.std.multimethod import FailedToImplement
from pypy.rlib.rarithmetic import r_uint
+from pypy.objspace.std.test.test_intobject import AppTestInt
from pypy.conftest import gettestobjspace
class TestW_IntObject:
@@ -223,3 +224,10 @@
f1 = wrapint(self.space, x)
result = self.space.hex(f1)
assert self.space.unwrap(result) == hex(x)
+
+
+class AppTestSmallInt(AppTestInt):
+
+ def setup_class(cls):
+ cls.space = gettestobjspace(**{"objspace.std.optimized_int_add" : True,
+ "objspace.std.withsmallint" : True})
Modified: pypy/branch/cpython-extension/pypy/objspace/std/test/test_typeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/test/test_typeobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/test/test_typeobject.py Wed Mar 31 00:17:06 2010
@@ -1,5 +1,5 @@
-from pypy.objspace.std.objspace import *
-from pypy.objspace.std.stdtypedef import *
+from pypy.objspace.std.model import W_Object
+from pypy.objspace.std.stdtypedef import StdTypeDef
from pypy.conftest import gettestobjspace
from pypy.objspace.std.typeobject import W_TypeObject
@@ -15,7 +15,7 @@
def descr__new__(space, w_subtype):
return space.allocate_instance(W_Stuff, w_subtype)
W_Stuff.typedef = StdTypeDef("stuff",
- __new__ = newmethod(descr__new__))
+ __new__ = interp2app(descr__new__))
W_Stuff.typedef.acceptable_as_base_class = False
w_stufftype = space.gettypeobject(W_Stuff.typedef)
space.appexec([w_stufftype], """(stufftype):
Modified: pypy/branch/cpython-extension/pypy/objspace/std/transparent.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/transparent.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/transparent.py Wed Mar 31 00:17:06 2010
@@ -20,6 +20,16 @@
type_cache = TypeCache()
+
+def setup(space):
+ """Add proxy functions to the __pypy__ module."""
+ w___pypy__ = space.getbuiltinmodule("__pypy__")
+ space.setattr(w___pypy__, space.wrap('tproxy'), space.wrap(app_proxy))
+ space.setattr(w___pypy__, space.wrap('get_tproxy_controller'),
+ space.wrap(app_proxy_controller))
+
+
+
def proxy(space, w_type, w_controller):
"""tproxy(typ, controller) -> obj
Return something that looks like it is of type typ. Its behaviour is
Modified: pypy/branch/cpython-extension/pypy/objspace/std/tupleobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/tupleobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/tupleobject.py Wed Mar 31 00:17:06 2010
@@ -1,5 +1,8 @@
-from pypy.objspace.std.objspace import *
+from pypy.interpreter.error import OperationError
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.inttype import wrapint
+from pypy.objspace.std.multimethod import FailedToImplement
from pypy.rlib.rarithmetic import intmask
from pypy.objspace.std.sliceobject import W_SliceObject, normalize_simple_slice
from pypy.interpreter import gateway
@@ -8,7 +11,7 @@
class W_TupleObject(W_Object):
from pypy.objspace.std.tupletype import tuple_typedef as typedef
_immutable_ = True
-
+
def __init__(w_self, wrappeditems):
make_sure_not_resized(wrappeditems)
w_self.wrappeditems = wrappeditems # a list of wrapped values
Modified: pypy/branch/cpython-extension/pypy/objspace/std/tupletype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/tupletype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/tupletype.py Wed Mar 31 00:17:06 2010
@@ -1,11 +1,7 @@
-from pypy.objspace.std.stdtypedef import *
-from pypy.interpreter.gateway import NoneNotWrapped
+from pypy.interpreter import gateway
+from pypy.objspace.std.stdtypedef import StdTypeDef
-def wraptuple(space, list_w):
- from pypy.objspace.std.tupleobject import W_TupleObject
- return W_TupleObject(list_w)
-
-def descr__new__(space, w_tupletype, w_sequence=NoneNotWrapped):
+def descr__new__(space, w_tupletype, w_sequence=gateway.NoneNotWrapped):
from pypy.objspace.std.tupleobject import W_TupleObject
if w_sequence is None:
tuple_w = []
@@ -14,8 +10,8 @@
return w_sequence
else:
tuple_w = space.fixedview(w_sequence)
- w_obj = space.allocate_instance(space.TupleObjectCls, w_tupletype)
- space.TupleObjectCls.__init__(w_obj, tuple_w)
+ w_obj = space.allocate_instance(W_TupleObject, w_tupletype)
+ W_TupleObject.__init__(w_obj, tuple_w)
return w_obj
# ____________________________________________________________
@@ -25,5 +21,5 @@
tuple(sequence) -> tuple initialized from sequence's items
If the argument is a tuple, the return value is the same object.''',
- __new__ = newmethod(descr__new__),
+ __new__ = gateway.interp2app(descr__new__),
)
Modified: pypy/branch/cpython-extension/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/typeobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/typeobject.py Wed Mar 31 00:17:06 2010
@@ -1,4 +1,5 @@
-from pypy.objspace.std.objspace import register_all, W_Object
+from pypy.objspace.std.model import W_Object
+from pypy.objspace.std.register_all import register_all
from pypy.interpreter.function import Function, StaticMethod
from pypy.interpreter import gateway
from pypy.interpreter.error import OperationError, operationerrfmt
@@ -47,6 +48,19 @@
class VersionTag(object):
pass
+class MethodCache(object):
+
+ def __init__(self, space):
+ assert space.config.objspace.std.withmethodcache
+ SIZE = 1 << space.config.objspace.std.methodcachesizeexp
+ self.versions = [None] * SIZE
+ self.names = [None] * SIZE
+ self.lookup_where = [(None, None)] * SIZE
+ if space.config.objspace.std.withmethodcachecounter:
+ self.hits = {}
+ self.misses = {}
+
+
class W_TypeObject(W_Object):
from pypy.objspace.std.typetype import type_typedef as typedef
@@ -265,7 +279,9 @@
@purefunction
def _pure_lookup_where_with_method_cache(w_self, name, version_tag):
space = w_self.space
- SHIFT = r_uint.BITS - space.config.objspace.std.methodcachesizeexp
+ cache = space.fromcache(MethodCache)
+ SHIFT2 = r_uint.BITS - space.config.objspace.std.methodcachesizeexp
+ SHIFT1 = SHIFT2 - 5
version_tag_as_int = current_object_addr_as_int(version_tag)
# ^^^Note: if the version_tag object is moved by a moving GC, the
# existing method cache entries won't be found any more; new
@@ -274,24 +290,27 @@
# the time - so using the fast current_object_addr_as_int() instead
# of a slower solution like hash() is still a good trade-off.
hash_name = compute_hash(name)
- method_hash = r_uint(intmask(version_tag_as_int * hash_name)) >> SHIFT
- cached_version_tag = space.method_cache_versions[method_hash]
+ product = intmask(version_tag_as_int * hash_name)
+ method_hash = (r_uint(product) ^ (r_uint(product) << SHIFT1)) >> SHIFT2
+ # ^^^Note2: we used to just take product>>SHIFT2, but on 64-bit
+ # platforms SHIFT2 is really large, and we loose too much information
+ # that way (as shown by failures of the tests that typically have
+ # method names like 'f' who hash to a number that has only ~33 bits).
+ cached_version_tag = cache.versions[method_hash]
if cached_version_tag is version_tag:
- cached_name = space.method_cache_names[method_hash]
+ cached_name = cache.names[method_hash]
if cached_name is name:
- tup = space.method_cache_lookup_where[method_hash]
+ tup = cache.lookup_where[method_hash]
if space.config.objspace.std.withmethodcachecounter:
- space.method_cache_hits[name] = \
- space.method_cache_hits.get(name, 0) + 1
+ cache.hits[name] = cache.hits.get(name, 0) + 1
# print "hit", w_self, name
return tup
tup = w_self._lookup_where_all_typeobjects(name)
- space.method_cache_versions[method_hash] = version_tag
- space.method_cache_names[method_hash] = name
- space.method_cache_lookup_where[method_hash] = tup
+ cache.versions[method_hash] = version_tag
+ cache.names[method_hash] = name
+ cache.lookup_where[method_hash] = tup
if space.config.objspace.std.withmethodcachecounter:
- space.method_cache_misses[name] = \
- space.method_cache_misses.get(name, 0) + 1
+ cache.misses[name] = cache.misses.get(name, 0) + 1
# print "miss", w_self, name
return tup
Modified: pypy/branch/cpython-extension/pypy/objspace/std/typetype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/typetype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/typetype.py Wed Mar 31 00:17:06 2010
@@ -1,8 +1,9 @@
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter import gateway
from pypy.interpreter.argument import Arguments
-from pypy.interpreter.typedef import weakref_descr
-from pypy.objspace.std.stdtypedef import *
+from pypy.interpreter.typedef import (GetSetProperty, descr_get_dict,
+ weakref_descr)
+from pypy.objspace.std.stdtypedef import StdTypeDef
def descr__new__(space, w_typetype, w_name, w_bases, w_dict):
"This is used to create user-defined classes only."
@@ -10,7 +11,7 @@
# XXX check types
w_typetype = _precheck_for_new(space, w_typetype)
-
+
bases_w = space.fixedview(w_bases)
w_winner = w_typetype
@@ -34,7 +35,7 @@
if not space.is_w(newfunc, space.getattr(space.w_type, space.wrap('__new__'))):
return space.call_function(newfunc, w_winner, w_name, w_bases, w_dict)
w_typetype = w_winner
-
+
name = space.str_w(w_name)
assert isinstance(name, str)
dict_w = {}
@@ -187,7 +188,7 @@
return space.get(w_result, space.w_None, w_type)
def descr__flags(space, w_type):
- w_type = _check(space, w_type)
+ w_type = _check(space, w_type)
return space.wrap(w_type.__flags__)
def descr_get__module(space, w_type):
@@ -195,9 +196,9 @@
return w_type.get_module()
def descr_set__module(space, w_type, w_value):
- w_type = _check(space, w_type)
+ w_type = _check(space, w_type)
if not w_type.is_heaptype():
- raise operationerrfmt(space.w_TypeError,
+ raise operationerrfmt(space.w_TypeError,
"can't set %s.__module__",
w_type.name)
w_type.mutated()
@@ -211,7 +212,7 @@
# ____________________________________________________________
type_typedef = StdTypeDef("type",
- __new__ = newmethod(descr__new__),
+ __new__ = gateway.interp2app(descr__new__),
__name__ = GetSetProperty(descr_get__name__, descr_set__name__),
__bases__ = GetSetProperty(descr_get__bases__, descr_set__bases__),
__base__ = GetSetProperty(descr__base),
Modified: pypy/branch/cpython-extension/pypy/objspace/std/unicodeobject.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/unicodeobject.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/unicodeobject.py Wed Mar 31 00:17:06 2010
@@ -1,5 +1,5 @@
-from pypy.objspace.std.objspace import register_all, W_Object
-from pypy.objspace.std.objspace import registerimplementation
+from pypy.objspace.std.model import registerimplementation, W_Object
+from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.multimethod import FailedToImplement
from pypy.interpreter import gateway
from pypy.interpreter.error import OperationError, operationerrfmt
Modified: pypy/branch/cpython-extension/pypy/objspace/std/unicodetype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/std/unicodetype.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/std/unicodetype.py Wed Mar 31 00:17:06 2010
@@ -1,8 +1,8 @@
+from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter import gateway
-from pypy.objspace.std.stdtypedef import *
+from pypy.objspace.std.stdtypedef import StdTypeDef, SMM
from pypy.objspace.std.register_all import register_all
from pypy.objspace.std.basestringtype import basestring_typedef
-from pypy.interpreter.error import OperationError, operationerrfmt
from sys import maxint
@@ -286,7 +286,7 @@
# ____________________________________________________________
unicode_typedef = StdTypeDef("unicode", basestring_typedef,
- __new__ = newmethod(descr_new_),
+ __new__ = gateway.interp2app(descr_new_),
__doc__ = '''unicode(string [, encoding[, errors]]) -> object
Create a new Unicode object from the given encoded string.
Modified: pypy/branch/cpython-extension/pypy/objspace/test/test_descroperation.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/objspace/test/test_descroperation.py (original)
+++ pypy/branch/cpython-extension/pypy/objspace/test/test_descroperation.py Wed Mar 31 00:17:06 2010
@@ -22,82 +22,92 @@
cls.space = conftest.gettestobjspace(**cls.OPTIONS)
def test_special_methods(self):
- class A(object):
- def __lt__(self, other):
- return "lt"
- def __imul__(self, other):
- return "imul"
- def __sub__(self, other):
- return "sub"
- def __rsub__(self, other):
- return "rsub"
- def __pow__(self, other):
- return "pow"
- def __rpow__(self, other):
- return "rpow"
- def __neg__(self):
- return "neg"
- a = A()
- assert (a < 5) == "lt"
- assert (object() > a) == "lt"
- a1 = a
- a1 *= 4
- assert a1 == "imul"
- assert a - 2 == "sub"
- assert a - object() == "sub"
- assert 2 - a == "rsub"
- assert object() - a == "rsub"
- assert a ** 2 == "pow"
- assert a ** object() == "pow"
- assert 2 ** a == "rpow"
- assert object() ** a == "rpow"
- assert -a == "neg"
-
- class B(A):
- def __lt__(self, other):
- return "B's lt"
- def __imul__(self, other):
- return "B's imul"
- def __sub__(self, other):
- return "B's sub"
- def __rsub__(self, other):
- return "B's rsub"
- def __pow__(self, other):
- return "B's pow"
- def __rpow__(self, other):
- return "B's rpow"
- def __neg__(self):
- return "B's neg"
-
- b = B()
- assert (a < b) == "lt"
- assert (b > a) == "lt"
- b1 = b
- b1 *= a
- assert b1 == "B's imul"
- a1 = a
- a1 *= b
- assert a1 == "imul"
- assert a - b == "B's rsub"
- assert b - a == "B's sub"
- assert b - b == "B's sub"
- assert a ** b == "B's rpow"
- assert b ** a == "B's pow"
- assert b ** b == "B's pow"
- assert -b == "B's neg"
-
- class C(B):
+ class OldStyle:
pass
- c = C()
- assert c - 1 == "B's sub"
- assert 1 - c == "B's rsub"
- assert c - b == "B's sub"
- assert b - c == "B's sub"
-
- assert c ** 1 == "B's pow"
- assert 1 ** c == "B's rpow"
- assert c ** b == "B's pow"
- assert b ** c == "B's pow"
+ for base in (object, OldStyle,):
+ class A(base):
+ def __lt__(self, other):
+ return "lt"
+ def __imul__(self, other):
+ return "imul"
+ def __sub__(self, other):
+ return "sub"
+ def __rsub__(self, other):
+ return "rsub"
+ def __pow__(self, other):
+ return "pow"
+ def __rpow__(self, other):
+ return "rpow"
+ def __neg__(self):
+ return "neg"
+ a = A()
+ assert (a < 5) == "lt"
+ assert (object() > a) == "lt"
+ a1 = a
+ a1 *= 4
+ assert a1 == "imul"
+ assert a - 2 == "sub"
+ assert a - object() == "sub"
+ assert 2 - a == "rsub"
+ assert object() - a == "rsub"
+ assert a ** 2 == "pow"
+ assert a ** object() == "pow"
+ assert 2 ** a == "rpow"
+ assert object() ** a == "rpow"
+ assert -a == "neg"
+
+ class B(A):
+ def __lt__(self, other):
+ return "B's lt"
+ def __imul__(self, other):
+ return "B's imul"
+ def __sub__(self, other):
+ return "B's sub"
+ def __rsub__(self, other):
+ return "B's rsub"
+ def __pow__(self, other):
+ return "B's pow"
+ def __rpow__(self, other):
+ return "B's rpow"
+ def __neg__(self):
+ return "B's neg"
+
+ b = B()
+ assert (a < b) == "lt"
+ assert (b > a) == "lt"
+ b1 = b
+ b1 *= a
+ assert b1 == "B's imul"
+ a1 = a
+ a1 *= b
+ assert a1 == "imul"
+
+ if base is object:
+ assert a - b == "B's rsub"
+ else:
+ assert a - b == "sub"
+ assert b - a == "B's sub"
+ assert b - b == "B's sub"
+ if base is object:
+ assert a ** b == "B's rpow"
+ else:
+ assert a ** b == "pow"
+ assert b ** a == "B's pow"
+ assert b ** b == "B's pow"
+ assert -b == "B's neg"
+
+ class C(B):
+ pass
+ c = C()
+ assert c - 1 == "B's sub"
+ assert 1 - c == "B's rsub"
+ assert c - b == "B's sub"
+ assert b - c == "B's sub"
+
+ assert c ** 1 == "B's pow"
+ assert 1 ** c == "B's rpow"
+ assert c ** b == "B's pow"
+ assert b ** c == "B's pow"
def test_getslice(self):
class Sq(object):
@@ -371,6 +381,74 @@
A() < B()
assert l == [B, A, A, B]
+ def test_rich_comparison(self):
+ # Old-style
+ class A:
+ def __init__(self, a):
+ self.a = a
+ def __eq__(self, other):
+ return self.a == other.a
+ class B:
+ def __init__(self, a):
+ self.a = a
+ # New-style
+ class C(object):
+ def __init__(self, a):
+ self.a = a
+ def __eq__(self, other):
+ return self.a == other.a
+ class D(object):
+ def __init__(self, a):
+ self.a = a
+
+ assert A(1) == B(1)
+ assert B(1) == A(1)
+ assert A(1) == C(1)
+ assert C(1) == A(1)
+ assert A(1) == D(1)
+ assert D(1) == A(1)
+ assert C(1) == D(1)
+ assert D(1) == C(1)
+ assert not(A(1) == B(2))
+ assert not(B(1) == A(2))
+ assert not(A(1) == C(2))
+ assert not(C(1) == A(2))
+ assert not(A(1) == D(2))
+ assert not(D(1) == A(2))
+ assert not(C(1) == D(2))
+ assert not(D(1) == C(2))
+
+ def test_addition(self):
+ # Old-style
+ class A:
+ def __init__(self, a):
+ self.a = a
+ def __add__(self, other):
+ return self.a + other.a
+ __radd__ = __add__
+ class B:
+ def __init__(self, a):
+ self.a = a
+ # New-style
+ class C(object):
+ def __init__(self, a):
+ self.a = a
+ def __add__(self, other):
+ return self.a + other.a
+ __radd__ = __add__
+ class D(object):
+ def __init__(self, a):
+ self.a = a
+
+ assert A(1) + B(2) == 3
+ assert B(1) + A(2) == 3
+ assert A(1) + C(2) == 3
+ assert C(1) + A(2) == 3
+ assert A(1) + D(2) == 3
+ assert D(1) + A(2) == 3
+ assert C(1) + D(2) == 3
+ assert D(1) + C(2) == 3
+
def test_mod_failure(self):
try:
[] % 3
Modified: pypy/branch/cpython-extension/pypy/rlib/_rsocket_rffi.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rlib/_rsocket_rffi.py (original)
+++ pypy/branch/cpython-extension/pypy/rlib/_rsocket_rffi.py Wed Mar 31 00:17:06 2010
@@ -259,8 +259,8 @@
CConfig.sockaddr_in6 = platform.Struct('struct sockaddr_in6',
[('sin6_family', rffi.INT),
('sin6_port', rffi.USHORT),
- ('sin6_addr', CConfig.in6_addr),
('sin6_flowinfo', rffi.INT),
+ ('sin6_addr', CConfig.in6_addr),
('sin6_scope_id', rffi.INT)])
CConfig.sockaddr_un = platform.Struct('struct sockaddr_un',
Modified: pypy/branch/cpython-extension/pypy/rlib/rarithmetic.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rlib/rarithmetic.py (original)
+++ pypy/branch/cpython-extension/pypy/rlib/rarithmetic.py Wed Mar 31 00:17:06 2010
@@ -307,7 +307,7 @@
if val > klass.MASK>>1 or val < -(klass.MASK>>1)-1:
raise OverflowError("%s does not fit in signed %d-bit integer"%(val, klass.BITS))
if val < 0:
- val = - ((-val) & klass.MASK)
+ val = ~ ((~val) & klass.MASK)
return super(signed_int, klass).__new__(klass, val)
typemap = {}
Modified: pypy/branch/cpython-extension/pypy/rlib/rbigint.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rlib/rbigint.py (original)
+++ pypy/branch/cpython-extension/pypy/rlib/rbigint.py Wed Mar 31 00:17:06 2010
@@ -49,6 +49,7 @@
class rbigint(object):
"""This is a reimplementation of longs using a list of digits."""
+ # XXX relace the list of ints with a list of rffi.INTs, maybe
def __init__(self, digits=None, sign=0):
if digits is None or len(digits) == 0:
@@ -272,13 +273,13 @@
return False
def le(self, other):
- return self.lt(other) or self.eq(other)
+ return not other.lt(self)
def gt(self, other):
- return other.le(self)
+ return other.lt(self)
def ge(self, other):
- return other.lt(self)
+ return not self.lt(other)
def hash(self):
return _hash(self)
Modified: pypy/branch/cpython-extension/pypy/rlib/rmarshal.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rlib/rmarshal.py (original)
+++ pypy/branch/cpython-extension/pypy/rlib/rmarshal.py Wed Mar 31 00:17:06 2010
@@ -6,7 +6,7 @@
from pypy.annotation.signature import annotation
from pypy.annotation.listdef import ListDef, TooLateForChange
from pypy.tool.pairtype import pair, pairtype
-from pypy.rlib.rarithmetic import formatd, r_longlong, intmask
+from pypy.rlib.rarithmetic import formatd, r_longlong, intmask, LONG_BIT
from pypy.rlib.rarithmetic import break_up_float, parts_to_float
from pypy.rlib.unroll import unrolling_iterable
@@ -151,8 +151,12 @@
add_loader(annmodel.s_Bool, load_bool)
def dump_int(buf, x):
- buf.append(TYPE_INT)
- w_long(buf, x)
+ # only use TYPE_INT on 32-bit platforms
+ if LONG_BIT > 32:
+ dump_longlong(buf, r_longlong(x))
+ else:
+ buf.append(TYPE_INT)
+ w_long(buf, x)
add_dumper(annmodel.SomeInteger(), dump_int)
def load_int_nonneg(loader):
@@ -163,9 +167,14 @@
add_loader(annmodel.SomeInteger(nonneg=True), load_int_nonneg)
def load_int(loader):
- if readchr(loader) != TYPE_INT:
- raise ValueError("expected an int")
- return readlong(loader)
+ r = readchr(loader)
+ if LONG_BIT > 32 and r == TYPE_INT64:
+ x = readlong(loader) & 0xFFFFFFFF
+ x |= readlong(loader) << 32
+ return x
+ if r == TYPE_INT:
+ return readlong(loader)
+ raise ValueError("expected an int")
add_loader(annmodel.SomeInteger(), load_int)
def dump_longlong(buf, x):
Modified: pypy/branch/cpython-extension/pypy/rlib/rsocket.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rlib/rsocket.py (original)
+++ pypy/branch/cpython-extension/pypy/rlib/rsocket.py Wed Mar 31 00:17:06 2010
@@ -42,13 +42,15 @@
return rffi.cast(lltype.Signed, _c.ntohs(x))
def ntohl(x):
- return rffi.cast(lltype.Signed, _c.ntohl(x))
+ # accepts and returns an Unsigned
+ return rffi.cast(lltype.Unsigned, _c.ntohl(x))
def htons(x):
return rffi.cast(lltype.Signed, _c.htons(x))
def htonl(x):
- return rffi.cast(lltype.Signed, _c.htonl(x))
+ # accepts and returns an Unsigned
+ return rffi.cast(lltype.Unsigned, _c.htonl(x))
_FAMILIES = {}
@@ -504,6 +506,10 @@
klass = familyclass(family)
result = instantiate(klass)
buf = lltype.malloc(rffi.CCHARP.TO, klass.maxlen, flavor='raw', zero=True)
+ # Initialize the family to the correct value. Avoids surprizes on
+ # Windows when calling a function that unexpectedly does not set
+ # the output address (e.g. recvfrom() on a connected IPv4 socket).
+ rffi.setintfield(rffi.cast(_c.sockaddr_ptr, buf), 'c_sa_family', family)
result.setdata(buf, 0)
return result, klass.maxlen
Modified: pypy/branch/cpython-extension/pypy/rlib/rstack.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rlib/rstack.py (original)
+++ pypy/branch/cpython-extension/pypy/rlib/rstack.py Wed Mar 31 00:17:06 2010
@@ -38,8 +38,9 @@
stack_too_big = rffi.llexternal('LL_stack_too_big', [], rffi.INT,
compilation_info=compilation_info,
_nowrapper=True,
- _callable=lambda: 0,
+ _callable=lambda: _zero,
sandboxsafe=True)
+_zero = rffi.cast(rffi.INT, 0)
def stack_check():
if rffi.cast(lltype.Signed, stack_too_big()):
Modified: pypy/branch/cpython-extension/pypy/rlib/rzipfile.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rlib/rzipfile.py (original)
+++ pypy/branch/cpython-extension/pypy/rlib/rzipfile.py Wed Mar 31 00:17:06 2010
@@ -217,7 +217,7 @@
+ fheader[_FH_EXTRA_FIELD_LENGTH])
fname = fp.read(fheader[_FH_FILENAME_LENGTH])
if fname != data.orig_filename:
- raise RuntimeError, \
+ raise BadZipfile, \
'File name in directory "%s" and header "%s" differ.' % (
data.orig_filename, fname)
fp.seek(self.start_dir, 0)
Modified: pypy/branch/cpython-extension/pypy/rlib/test/test_rarithmetic.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rlib/test/test_rarithmetic.py (original)
+++ pypy/branch/cpython-extension/pypy/rlib/test/test_rarithmetic.py Wed Mar 31 00:17:06 2010
@@ -197,6 +197,10 @@
x = intmask(tp(5))
assert (type(x), x) == (int, 5)
+def test_bug_creating_r_int():
+ minint = -sys.maxint-1
+ assert r_int(r_int(minint)) == minint
+
def test_ovfcheck():
one = 1
x = sys.maxint
Modified: pypy/branch/cpython-extension/pypy/rlib/test/test_rbigint.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rlib/test/test_rbigint.py (original)
+++ pypy/branch/cpython-extension/pypy/rlib/test/test_rbigint.py Wed Mar 31 00:17:06 2010
@@ -106,7 +106,7 @@
assert rbigint.fromrarith_int(r_uint(17)).eq(rbigint([17], 1))
assert rbigint.fromrarith_int(r_uint(BASE-1)).eq(rbigint([intmask(BASE-1)], 1))
assert rbigint.fromrarith_int(r_uint(BASE)).eq(rbigint([0, 1], 1))
- assert rbigint.fromrarith_int(r_uint(BASE**2)).eq(rbigint([0], 0))
+ #assert rbigint.fromrarith_int(r_uint(BASE**2)).eq(rbigint([0], 0))
assert rbigint.fromrarith_int(r_uint(sys.maxint)).eq(
rbigint.fromint(sys.maxint))
assert rbigint.fromrarith_int(r_uint(sys.maxint+1)).eq(
@@ -193,6 +193,14 @@
f2 = rbigint.fromlong(y)
assert (x < y) == f1.lt(f2)
+ def test_order(self):
+ f6 = rbigint.fromint(6)
+ f7 = rbigint.fromint(7)
+ assert (f6.lt(f6), f6.lt(f7), f7.lt(f6)) == (0,1,0)
+ assert (f6.le(f6), f6.le(f7), f7.le(f6)) == (1,1,0)
+ assert (f6.gt(f6), f6.gt(f7), f7.gt(f6)) == (0,0,1)
+ assert (f6.ge(f6), f6.ge(f7), f7.ge(f6)) == (1,0,1)
+
def test_int_conversion(self):
f1 = rbigint.fromlong(12332)
f2 = rbigint.fromint(12332)
@@ -465,9 +473,12 @@
def test_args_from_rarith_int(self):
from pypy.rpython.tool.rfficache import platform
+ from pypy.rlib.rarithmetic import r_int
classlist = platform.numbertype_to_rclass.values()
fnlist = []
for r in classlist:
+ if r is r_int: # and also r_longlong on 64-bit
+ continue
if r is int:
mask = sys.maxint*2+1
signed = True
Modified: pypy/branch/cpython-extension/pypy/rlib/test/test_rmarshal.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rlib/test/test_rmarshal.py (original)
+++ pypy/branch/cpython-extension/pypy/rlib/test/test_rmarshal.py Wed Mar 31 00:17:06 2010
@@ -2,7 +2,7 @@
import marshal
from pypy.rlib.rmarshal import *
from pypy.annotation import model as annmodel
-from pypy.rlib.rarithmetic import formatd
+from pypy.rlib.rarithmetic import formatd, LONG_BIT
types_that_can_be_none = [
[int],
@@ -17,6 +17,10 @@
assert marshal.loads(''.join(buf)) == 5
buf = []
+ get_marshaller(int)(buf, -555)
+ assert marshal.loads(''.join(buf)) == -555
+
+ buf = []
get_marshaller(float)(buf, 3.25)
assert marshal.loads(''.join(buf)) == 3.25
@@ -37,6 +41,15 @@
assert marshal.loads(''.join(buf)) == 0x12380000007
buf = []
+ get_marshaller(r_longlong)(buf, r_longlong(-0x12380000007))
+ assert marshal.loads(''.join(buf)) == -0x12380000007
+
+ if LONG_BIT > 32:
+ buf = []
+ get_marshaller(int)(buf, -0x12340000007)
+ assert marshal.loads(''.join(buf)) == -0x12340000007
+
+ buf = []
get_marshaller([int])(buf, [2, 5, -7])
assert marshal.loads(''.join(buf)) == [2, 5, -7]
@@ -54,6 +67,9 @@
buf = 'i\x05\x00\x00\x00'
assert get_unmarshaller(int)(buf) == 5
+ buf = 'i\x00\xf0\xff\xff'
+ assert get_unmarshaller(int)(buf) == -4096
+
buf = 'f\x043.25'
assert get_unmarshaller(float)(buf) == 3.25
@@ -75,6 +91,16 @@
buf = 'I\x07\x00\x00\x80\x23\x01\x00\x00'
assert get_unmarshaller(r_longlong)(buf) == 0x12380000007
+ buf = 'I\x00\x00\x01\x83\x80\x00\x00\x97'
+ assert get_unmarshaller(r_longlong)(buf) == -7566046822028738560L
+
+ if LONG_BIT > 32:
+ buf = 'I\x07\x00\x00\x80\x23\x01\x00\x00'
+ assert get_unmarshaller(int)(buf) == 0x12380000007
+
+ buf = 'I\x00\x00\x01\x83\x80\x00\x00\x97'
+ assert get_unmarshaller(int)(buf) == -7566046822028738560
+
buf = ('[\x03\x00\x00\x00i\x02\x00\x00\x00i\x05\x00\x00\x00'
'i\xf9\xff\xff\xff')
assert get_unmarshaller([int])(buf) == [2, 5, -7]
@@ -98,10 +124,18 @@
return ''.join(buf)
res = interpret(f, [])
res = ''.join(res.chars)
- assert res == ('[\x02\x00\x00\x00(\x03\x00\x00\x00i\x05\x00\x00\x00'
- 's\x05\x00\x00\x00hellof\x04-0.5(\x03\x00\x00\x00'
- 'i\x07\x00\x00\x00s\x05\x00\x00\x00world'
- 'f\x061e+100')
+ if LONG_BIT == 32:
+ assert res == ('[\x02\x00\x00\x00(\x03\x00\x00\x00i\x05\x00\x00\x00'
+ 's\x05\x00\x00\x00hellof\x04-0.5(\x03\x00\x00\x00'
+ 'i\x07\x00\x00\x00s\x05\x00\x00\x00world'
+ 'f\x061e+100')
+ else:
+ assert res == ('[\x02\x00\x00\x00(\x03\x00\x00\x00'
+ 'I\x05\x00\x00\x00\x00\x00\x00\x00'
+ 's\x05\x00\x00\x00hellof\x04-0.5(\x03\x00\x00\x00'
+ 'I\x07\x00\x00\x00\x00\x00\x00\x00'
+ 's\x05\x00\x00\x00world'
+ 'f\x061e+100')
def test_llinterp_unmarshal():
from pypy.rpython.test.test_llinterp import interpret
Modified: pypy/branch/cpython-extension/pypy/rlib/test/test_rsocket.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rlib/test/test_rsocket.py (original)
+++ pypy/branch/cpython-extension/pypy/rlib/test/test_rsocket.py Wed Mar 31 00:17:06 2010
@@ -78,6 +78,19 @@
py.test.fail("could not find the 127.0.0.1 IPv4 address in %r"
% (address_list,))
+ name, aliases, address_list = gethostbyaddr('localhost')
+ allnames = [name] + aliases
+ for n in allnames:
+ assert isinstance(n, str)
+ if sys.platform != 'win32':
+ assert 'localhost' in allnames
+ for a in address_list:
+ if isinstance(a, INET6Address) and a.get_host() == "::1":
+ break # ok
+ else:
+ py.test.fail("could not find the ::1 IPv6 address in %r"
+ % (address_list,))
+
def test_getservbyname():
assert getservbyname('http') == 80
assert getservbyname('http', 'tcp') == 80
Modified: pypy/branch/cpython-extension/pypy/rlib/test/test_rstruct.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rlib/test/test_rstruct.py (original)
+++ pypy/branch/cpython-extension/pypy/rlib/test/test_rstruct.py Wed Mar 31 00:17:06 2010
@@ -1,12 +1,14 @@
from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
from pypy.rlib.rstruct.runpack import runpack
+from pypy.rlib.rarithmetic import LONG_BIT
import struct
class BaseTestRStruct(BaseRtypingTest):
def test_unpack(self):
+ pad = '\x00' * (LONG_BIT//8-1) # 3 or 7 null bytes
def fn():
- return runpack('sll', 'a\x00\x00\x00\x03\x00\x00\x00\x04\x00\x00\x00')[1]
+ return runpack('sll', 'a'+pad+'\x03'+pad+'\x04'+pad)[1]
assert fn() == 3
assert self.interpret(fn, []) == 3
Modified: pypy/branch/cpython-extension/pypy/rpython/exceptiondata.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/exceptiondata.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/exceptiondata.py Wed Mar 31 00:17:06 2010
@@ -1,5 +1,6 @@
from pypy.rpython import rclass
from pypy.annotation import model as annmodel
+from pypy.rlib import rstackovf
# the exceptions that can be implicitely raised by some operations
@@ -19,6 +20,7 @@
UnicodeDecodeError: True,
UnicodeEncodeError: True,
NotImplementedError: True,
+ rstackovf._StackOverflow: True,
}
Modified: pypy/branch/cpython-extension/pypy/rpython/llinterp.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/llinterp.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/llinterp.py Wed Mar 31 00:17:06 2010
@@ -5,6 +5,7 @@
from pypy.rpython.lltypesystem import rclass
from pypy.rpython.ootypesystem import ootype
from pypy.rlib.objectmodel import ComputedIntSymbolic, CDefinedIntSymbolic
+from pypy.rlib import rstackovf
import sys, os
import math
@@ -321,6 +322,18 @@
except LLException, e:
if not (catch_exception and op is block.operations[-1]):
raise
+ except RuntimeError, e:
+ rstackovf.check_stack_overflow()
+ # xxx fish fish fish for proper etype and evalue to use
+ rtyper = self.llinterpreter.typer
+ bk = rtyper.annotator.bookkeeper
+ classdef = bk.getuniqueclassdef(rstackovf._StackOverflow)
+ exdata = rtyper.getexceptiondata()
+ evalue = exdata.get_standard_ll_exc_instance(rtyper, classdef)
+ etype = exdata.fn_type_of_exc_inst(evalue)
+ e = LLException(etype, evalue)
+ if not (catch_exception and op is block.operations[-1]):
+ raise e
# determine nextblock and/or return value
if len(block.exits) == 0:
Modified: pypy/branch/cpython-extension/pypy/rpython/lltypesystem/llgroup.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/lltypesystem/llgroup.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/lltypesystem/llgroup.py Wed Mar 31 00:17:06 2010
@@ -50,9 +50,11 @@
if LONG_BIT == 32:
+ HALFSHIFT = 16
HALFWORD = rffi.USHORT
r_halfword = rffi.r_ushort
else:
+ HALFSHIFT = 32
HALFWORD = rffi.UINT
r_halfword = rffi.r_uint
@@ -97,7 +99,7 @@
'&~0xFFFF' or with a direct masking like '&0x10000' (resp. on 64-bit
platform, with '&~0xFFFFFFFF' or '&0x100000000').
"""
- MASK = (1<<(LONG_BIT//2))-1 # 0xFFFF or 0xFFFFFFFF
+ MASK = (1<<HALFSHIFT)-1 # 0xFFFF or 0xFFFFFFFF
def annotation(self):
from pypy.annotation import model
Modified: pypy/branch/cpython-extension/pypy/rpython/lltypesystem/lltype.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/lltypesystem/lltype.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/lltypesystem/lltype.py Wed Mar 31 00:17:06 2010
@@ -1494,8 +1494,13 @@
if n < 0:
raise ValueError, "negative array length"
_parentable.__init__(self, TYPE)
- self.items = [TYPE.OF._allocate(initialization=initialization, parent=self, parentindex=j)
- for j in range(n)]
+ try:
+ myrange = range(n)
+ except OverflowError:
+ raise MemoryError("definitely too many items")
+ self.items = [TYPE.OF._allocate(initialization=initialization,
+ parent=self, parentindex=j)
+ for j in myrange]
if parent is not None:
self._setparentstructure(parent, parentindex)
Modified: pypy/branch/cpython-extension/pypy/rpython/lltypesystem/opimpl.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/lltypesystem/opimpl.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/lltypesystem/opimpl.py Wed Mar 31 00:17:06 2010
@@ -18,13 +18,20 @@
# global synonyms for some types
from pypy.rlib.rarithmetic import intmask
-from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
+from pypy.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong
-type_by_name = {
+if r_longlong is r_int:
+ r_longlong_arg = (r_longlong, int)
+ r_longlong_result = int
+else:
+ r_longlong_arg = r_longlong
+ r_longlong_result = r_longlong
+
+argtype_by_name = {
'int': int,
'float': float,
'uint': r_uint,
- 'llong': r_longlong,
+ 'llong': r_longlong_arg,
'ullong': r_ulonglong,
}
@@ -56,9 +63,9 @@
adjust_result = intmask
else:
adjust_result = no_op
- assert typname in type_by_name, "%s: not a primitive op" % (
+ assert typname in argtype_by_name, "%s: not a primitive op" % (
fullopname,)
- argtype = type_by_name[typname]
+ argtype = argtype_by_name[typname]
if opname in ops_unary:
def op_function(x):
@@ -226,16 +233,16 @@
return r
def op_llong_floordiv(x, y):
- assert isinstance(x, r_longlong)
- assert isinstance(y, r_longlong)
+ assert isinstance(x, r_longlong_arg)
+ assert isinstance(y, r_longlong_arg)
r = x//y
if x^y < 0 and x%y != 0:
r += 1
return r
def op_llong_mod(x, y):
- assert isinstance(x, r_longlong)
- assert isinstance(y, r_longlong)
+ assert isinstance(x, r_longlong_arg)
+ assert isinstance(y, r_longlong_arg)
r = x%y
if x^y < 0 and x%y != 0:
r -= y
@@ -258,7 +265,7 @@
return float(u)
def op_cast_longlong_to_float(i):
- assert type(i) is r_longlong
+ assert isinstance(i, r_longlong_arg)
# take first 31 bits
li = float(int(i & r_longlong(0x7fffffff)))
ui = float(int(i >> 31)) * float(0x80000000)
@@ -290,7 +297,7 @@
small = f / r
high = int(small)
truncated = int((small - high) * r)
- return r_longlong(high) * 0x100000000 + truncated
+ return r_longlong_result(high) * 0x100000000 + truncated
def op_cast_char_to_int(b):
assert type(b) is str and len(b) == 1
@@ -314,10 +321,10 @@
def op_cast_int_to_longlong(b):
assert type(b) is int
- return r_longlong(b)
+ return r_longlong_result(b)
def op_truncate_longlong_to_int(b):
- assert type(b) is r_longlong
+ assert isinstance(b, r_longlong_arg)
return intmask(b)
def op_cast_pointer(RESTYPE, obj):
Modified: pypy/branch/cpython-extension/pypy/rpython/lltypesystem/rffi.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/lltypesystem/rffi.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/lltypesystem/rffi.py Wed Mar 31 00:17:06 2010
@@ -356,10 +356,9 @@
MODE_T = lltype.Signed
PID_T = lltype.Signed
-def setup():
- """ creates necessary c-level types
- """
- result = []
+def populate_inttypes():
+ names = []
+ populatelist = []
for name in TYPES:
c_name = name
if name.startswith('unsigned'):
@@ -368,7 +367,18 @@
else:
signed = (name != 'size_t')
name = name.replace(' ', '')
- tp = platform.inttype(name.upper(), c_name, signed)
+ names.append(name)
+ populatelist.append((name.upper(), c_name, signed))
+ platform.populate_inttypes(populatelist)
+ return names
+
+def setup():
+ """ creates necessary c-level types
+ """
+ names = populate_inttypes()
+ result = []
+ for name in names:
+ tp = platform.types[name.upper()]
globals()['r_' + name] = platform.numbertype_to_rclass[tp]
globals()[name.upper()] = tp
tpp = lltype.Ptr(lltype.Array(tp, hints={'nolength': True}))
Modified: pypy/branch/cpython-extension/pypy/rpython/lltypesystem/test/test_ll2ctypes.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/lltypesystem/test/test_ll2ctypes.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/lltypesystem/test/test_ll2ctypes.py Wed Mar 31 00:17:06 2010
@@ -1041,6 +1041,10 @@
#assert lltype.cast_ptr_to_int(ref1) == intval
+ def test_ptr_truth(self):
+ abc = rffi.cast(lltype.Ptr(lltype.FuncType([], lltype.Void)), 0)
+ assert not abc
+
def test_mixed_gcref_comparison(self):
NODE = lltype.GcStruct('NODE')
node = lltype.malloc(NODE)
Modified: pypy/branch/cpython-extension/pypy/rpython/lltypesystem/test/test_llgroup.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/lltypesystem/test/test_llgroup.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/lltypesystem/test/test_llgroup.py Wed Mar 31 00:17:06 2010
@@ -67,10 +67,11 @@
test.build()
grpptr = test.grpptr
g1x = [test.g1a, test.g1b]
- cs1 = CombinedSymbolic(test.g1b, 0x450000)
- cs2 = CombinedSymbolic(test.g1b, 0x410000)
- assert llop.extract_ushort(rffi.USHORT, cs1) is test.g1b
- assert cs1 & ~0xFFFF == 0x450000
+ MASK = CombinedSymbolic.MASK
+ cs1 = CombinedSymbolic(test.g1b, 0x45 << HALFSHIFT)
+ cs2 = CombinedSymbolic(test.g1b, 0x41 << HALFSHIFT)
+ assert llop.extract_ushort(HALFWORD, cs1) is test.g1b
+ assert cs1 & ~MASK == 0x45 << HALFSHIFT
cslist = [cs1, cs2]
#
def f():
@@ -99,11 +100,11 @@
assert p.x == expected[i]
#
for i in range(2):
- s = llop.extract_ushort(rffi.USHORT, cslist[i])
+ s = llop.extract_ushort(HALFWORD, cslist[i])
p = llop.get_group_member(lltype.Ptr(test.S1), grpptr, s)
assert p == test.p1b
- assert cslist[0] & ~0xFFFF == 0x450000
- assert cslist[1] & ~0xFFFF == 0x410000
+ assert cslist[0] & ~MASK == 0x45 << HALFSHIFT
+ assert cslist[1] & ~MASK == 0x41 << HALFSHIFT
#
return 42
return f
Modified: pypy/branch/cpython-extension/pypy/rpython/memory/gc/generation.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/memory/gc/generation.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/memory/gc/generation.py Wed Mar 31 00:17:06 2010
@@ -8,9 +8,11 @@
from pypy.rlib.objectmodel import free_non_gc_object
from pypy.rlib.debug import ll_assert
from pypy.rlib.debug import debug_print, debug_start, debug_stop
-from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.rarithmetic import intmask, LONG_BIT
from pypy.rpython.lltypesystem.lloperation import llop
+WORD = LONG_BIT // 8
+
# The following flag is never set on young objects, i.e. the ones living
# in the nursery. It is initially set on all prebuilt and old objects,
# and gets cleared by the write_barrier() when we write in them a
@@ -47,10 +49,10 @@
nursery_hash_base = -1
def __init__(self, config, chunk_size=DEFAULT_CHUNK_SIZE,
- nursery_size=128,
- min_nursery_size=128,
+ nursery_size=32*WORD,
+ min_nursery_size=32*WORD,
auto_nursery_size=False,
- space_size=4096,
+ space_size=1024*WORD,
max_space_size=sys.maxint//2+1):
SemiSpaceGC.__init__(self, config, chunk_size = chunk_size,
space_size = space_size,
Modified: pypy/branch/cpython-extension/pypy/rpython/memory/gc/hybrid.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/memory/gc/hybrid.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/memory/gc/hybrid.py Wed Mar 31 00:17:06 2010
@@ -1,6 +1,6 @@
import sys
from pypy.rpython.memory.gc.semispace import SemiSpaceGC
-from pypy.rpython.memory.gc.generation import GenerationGC
+from pypy.rpython.memory.gc.generation import GenerationGC, WORD
from pypy.rpython.memory.gc.semispace import GCFLAG_EXTERNAL, GCFLAG_FORWARDED
from pypy.rpython.memory.gc.semispace import GCFLAG_HASHMASK
from pypy.rpython.memory.gc.generation import GCFLAG_NO_YOUNG_PTRS
@@ -89,8 +89,8 @@
# condition: large_object <= large_object_gcptrs < min_nursery_size/4
def __init__(self, *args, **kwds):
- large_object = kwds.pop('large_object', 24)
- large_object_gcptrs = kwds.pop('large_object_gcptrs', 32)
+ large_object = kwds.pop('large_object', 6*WORD)
+ large_object_gcptrs = kwds.pop('large_object_gcptrs', 8*WORD)
self.generation3_collect_threshold = kwds.pop(
'generation3_collect_threshold', GENERATION3_COLLECT_THRESHOLD)
GenerationGC.__init__(self, *args, **kwds)
Modified: pypy/branch/cpython-extension/pypy/rpython/memory/gc/test/test_direct.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/memory/gc/test/test_direct.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/memory/gc/test/test_direct.py Wed Mar 31 00:17:06 2010
@@ -9,6 +9,9 @@
import py
from pypy.rpython.lltypesystem import lltype, llmemory
from pypy.rpython.memory.gctypelayout import TypeLayoutBuilder
+from pypy.rlib.rarithmetic import LONG_BIT
+
+WORD = LONG_BIT // 8
ADDR_ARRAY = lltype.Array(llmemory.Address)
S = lltype.GcForwardReference()
@@ -378,11 +381,11 @@
class TestHybridGC(TestGenerationGC):
from pypy.rpython.memory.gc.hybrid import HybridGC as GCClass
- GC_PARAMS = {'space_size': 192,
- 'min_nursery_size': 48,
- 'nursery_size': 48,
- 'large_object': 12,
- 'large_object_gcptrs': 12,
+ GC_PARAMS = {'space_size': 48*WORD,
+ 'min_nursery_size': 12*WORD,
+ 'nursery_size': 12*WORD,
+ 'large_object': 3*WORD,
+ 'large_object_gcptrs': 3*WORD,
'generation3_collect_threshold': 5,
}
Modified: pypy/branch/cpython-extension/pypy/rpython/memory/test/test_gc.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/memory/test/test_gc.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/memory/test/test_gc.py Wed Mar 31 00:17:06 2010
@@ -1,7 +1,6 @@
import py
import sys
-#from pypy.rpython.memory.support import INT_SIZE
from pypy.rpython.memory import gcwrapper
from pypy.rpython.memory.test import snippet
from pypy.rpython.test.test_llinterp import get_interpreter
@@ -12,6 +11,10 @@
from pypy.rlib.objectmodel import compute_unique_id, keepalive_until_here
from pypy.rlib import rgc
from pypy.rlib.rstring import StringBuilder
+from pypy.rlib.rarithmetic import LONG_BIT
+
+WORD = LONG_BIT // 8
+
def stdout_ignore_ll_functions(msg):
strmsg = str(msg)
@@ -629,7 +632,7 @@
GC_CAN_SHRINK_ARRAY = True
class TestGrowingSemiSpaceGC(TestSemiSpaceGC):
- GC_PARAMS = {'space_size': 64}
+ GC_PARAMS = {'space_size': 16*WORD}
class TestGenerationalGC(TestSemiSpaceGC):
from pypy.rpython.memory.gc.generation import GenerationGC as GCClass
@@ -641,7 +644,7 @@
py.test.skip("Not implemented yet")
class TestMarkCompactGCGrowing(TestMarkCompactGC):
- GC_PARAMS = {'space_size': 64}
+ GC_PARAMS = {'space_size': 16*WORD}
class TestHybridGC(TestGenerationalGC):
from pypy.rpython.memory.gc.hybrid import HybridGC as GCClass
@@ -716,11 +719,11 @@
GC_CAN_MOVE = False # with this size of heap, stuff gets allocated
# in 3rd gen.
GC_CANNOT_MALLOC_NONMOVABLE = False
- GC_PARAMS = {'space_size': 192,
- 'min_nursery_size': 48,
- 'nursery_size': 48,
- 'large_object': 12,
- 'large_object_gcptrs': 12,
+ GC_PARAMS = {'space_size': 48*WORD,
+ 'min_nursery_size': 12*WORD,
+ 'nursery_size': 12*WORD,
+ 'large_object': 3*WORD,
+ 'large_object_gcptrs': 3*WORD,
'generation3_collect_threshold': 5,
}
Modified: pypy/branch/cpython-extension/pypy/rpython/memory/test/test_transformed_gc.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/memory/test/test_transformed_gc.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/memory/test/test_transformed_gc.py Wed Mar 31 00:17:06 2010
@@ -1,10 +1,10 @@
import py
import sys
-import struct, inspect
+import inspect
from pypy.translator.c import gc
from pypy.annotation import model as annmodel
from pypy.annotation import policy as annpolicy
-from pypy.rpython.lltypesystem import lltype, llmemory, llarena, rffi
+from pypy.rpython.lltypesystem import lltype, llmemory, llarena, rffi, llgroup
from pypy.rpython.memory.gctransform import framework
from pypy.rpython.lltypesystem.lloperation import llop, void
from pypy.rpython.memory.gc.marksweep import X_CLONE, X_POOL, X_POOL_PTR
@@ -14,8 +14,9 @@
from pypy import conftest
from pypy.rlib.rstring import StringBuilder
from pypy.rlib.objectmodel import keepalive_until_here
+from pypy.rlib.rarithmetic import LONG_BIT
-INT_SIZE = struct.calcsize("i") # only for estimates
+WORD = LONG_BIT // 8
def rtype(func, inputtypes, specialize=True, gcname='ref', stacklessgc=False,
@@ -219,7 +220,7 @@
run, statistics = self.runner("llinterp_lists", statistics=True)
run([])
heap_size = self.heap_usage(statistics)
- assert heap_size < 16000 * INT_SIZE / 4 # xxx
+ assert heap_size < 16000 * WORD / 4 # xxx
def define_llinterp_tuples(cls):
def malloc_a_lot():
@@ -239,7 +240,7 @@
run, statistics = self.runner("llinterp_tuples", statistics=True)
run([])
heap_size = self.heap_usage(statistics)
- assert heap_size < 16000 * INT_SIZE / 4 # xxx
+ assert heap_size < 16000 * WORD / 4 # xxx
def skipdefine_global_list(cls):
gl = []
@@ -275,7 +276,7 @@
res = run([100, 0])
assert res == len(''.join([str(x) for x in range(100)]))
heap_size = self.heap_usage(statistics)
- assert heap_size < 16000 * INT_SIZE / 4 # xxx
+ assert heap_size < 16000 * WORD / 4 # xxx
def define_nongc_static_root(cls):
T1 = lltype.GcStruct("C", ('x', lltype.Signed))
@@ -687,7 +688,7 @@
def f():
from pypy.rpython.lltypesystem import rffi
alist = [A() for i in range(50)]
- idarray = lltype.malloc(rffi.INTP.TO, len(alist), flavor='raw')
+ idarray = lltype.malloc(rffi.LONGP.TO, len(alist), flavor='raw')
# Compute the id of all the elements of the list. The goal is
# to not allocate memory, so that if the GC needs memory to
# remember the ids, it will trigger some collections itself
@@ -753,7 +754,7 @@
graph = graphof(translator, g)
for op in graph.startblock.operations:
if op.opname == 'do_malloc_fixedsize_clear':
- op.args = [Constant(type_id, rffi.USHORT),
+ op.args = [Constant(type_id, llgroup.HALFWORD),
Constant(llmemory.sizeof(P), lltype.Signed),
Constant(True, lltype.Bool), # can_collect
Constant(False, lltype.Bool), # has_finalizer
@@ -790,7 +791,7 @@
graph = graphof(translator, g)
for op in graph.startblock.operations:
if op.opname == 'do_malloc_fixedsize_clear':
- op.args = [Constant(type_id, rffi.USHORT),
+ op.args = [Constant(type_id, llgroup.HALFWORD),
Constant(llmemory.sizeof(P), lltype.Signed),
Constant(True, lltype.Bool), # can_collect
Constant(False, lltype.Bool), # has_finalizer
@@ -883,7 +884,7 @@
gcname = "marksweep"
class gcpolicy(gc.FrameworkGcPolicy):
class transformerclass(framework.FrameworkGCTransformer):
- GC_PARAMS = {'start_heap_size': 4096 }
+ GC_PARAMS = {'start_heap_size': 1024*WORD }
root_stack_depth = 200
@@ -1121,7 +1122,7 @@
class gcpolicy(gc.FrameworkGcPolicy):
class transformerclass(framework.FrameworkGCTransformer):
from pypy.rpython.memory.gc.marksweep import PrintingMarkSweepGC as GCClass
- GC_PARAMS = {'start_heap_size': 4096 }
+ GC_PARAMS = {'start_heap_size': 1024*WORD }
root_stack_depth = 200
class TestSemiSpaceGC(GenericMovingGCTests):
@@ -1131,7 +1132,7 @@
class gcpolicy(gc.FrameworkGcPolicy):
class transformerclass(framework.FrameworkGCTransformer):
from pypy.rpython.memory.gc.semispace import SemiSpaceGC as GCClass
- GC_PARAMS = {'space_size': 2048}
+ GC_PARAMS = {'space_size': 512*WORD}
root_stack_depth = 200
class TestMarkCompactGC(GenericMovingGCTests):
@@ -1143,7 +1144,7 @@
class gcpolicy(gc.FrameworkGcPolicy):
class transformerclass(framework.FrameworkGCTransformer):
from pypy.rpython.memory.gc.markcompact import MarkCompactGC as GCClass
- GC_PARAMS = {'space_size': 2048}
+ GC_PARAMS = {'space_size': 512*WORD}
root_stack_depth = 200
class TestGenerationGC(GenericMovingGCTests):
@@ -1154,8 +1155,8 @@
class transformerclass(framework.FrameworkGCTransformer):
from pypy.rpython.memory.gc.generation import GenerationGC as \
GCClass
- GC_PARAMS = {'space_size': 2048,
- 'nursery_size': 128}
+ GC_PARAMS = {'space_size': 512*WORD,
+ 'nursery_size': 32*WORD}
root_stack_depth = 200
def define_weakref_across_minor_collection(cls):
@@ -1351,8 +1352,8 @@
self.__ready = False # collecting here is expected
GenerationGC._teardown(self)
- GC_PARAMS = {'space_size': 2048,
- 'nursery_size': 512}
+ GC_PARAMS = {'space_size': 512*WORD,
+ 'nursery_size': 128*WORD}
root_stack_depth = 200
def define_working_nursery(cls):
@@ -1382,9 +1383,9 @@
class gcpolicy(gc.FrameworkGcPolicy):
class transformerclass(framework.FrameworkGCTransformer):
from pypy.rpython.memory.gc.hybrid import HybridGC as GCClass
- GC_PARAMS = {'space_size': 2048,
- 'nursery_size': 128,
- 'large_object': 32}
+ GC_PARAMS = {'space_size': 512*WORD,
+ 'nursery_size': 32*WORD,
+ 'large_object': 8*WORD}
root_stack_depth = 200
def define_ref_from_rawmalloced_to_regular(cls):
@@ -1522,7 +1523,7 @@
gcname = "marksweep"
class gcpolicy(gc.FrameworkGcPolicy):
class transformerclass(framework.FrameworkGCTransformer):
- GC_PARAMS = {'start_heap_size': 4096 }
+ GC_PARAMS = {'start_heap_size': 1024*WORD }
root_stack_depth = 200
class TestHybridTaggedPointerGC(TaggedPointerGCTests):
@@ -1532,6 +1533,6 @@
class transformerclass(framework.FrameworkGCTransformer):
from pypy.rpython.memory.gc.generation import GenerationGC as \
GCClass
- GC_PARAMS = {'space_size': 2048,
- 'nursery_size': 128}
+ GC_PARAMS = {'space_size': 512*WORD,
+ 'nursery_size': 32*WORD}
root_stack_depth = 200
Modified: pypy/branch/cpython-extension/pypy/rpython/test/test_rbuiltin.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/test/test_rbuiltin.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/test/test_rbuiltin.py Wed Mar 31 00:17:06 2010
@@ -5,7 +5,8 @@
from pypy.rlib.debug import llinterpcall
from pypy.rpython.lltypesystem import lltype
from pypy.tool import udir
-from pypy.rlib.rarithmetic import r_uint, intmask, r_longlong, r_ulonglong
+from pypy.rlib.rarithmetic import intmask
+from pypy.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong
from pypy.annotation.builtin import *
from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
from pypy.rpython.lltypesystem import rffi
@@ -526,11 +527,21 @@
return rffi.cast(rffi.VOIDP, v)
res = self.interpret(llfn, [r_ulonglong(0)])
assert res == lltype.nullptr(rffi.VOIDP.TO)
+ #
def llfn(v):
return rffi.cast(rffi.LONGLONG, v)
res = self.interpret(llfn, [lltype.nullptr(rffi.VOIDP.TO)])
assert res == 0
- assert isinstance(res, r_longlong)
+ if r_longlong is not r_int:
+ assert isinstance(res, r_longlong)
+ else:
+ assert isinstance(res, int)
+ #
+ def llfn(v):
+ return rffi.cast(rffi.ULONGLONG, v)
+ res = self.interpret(llfn, [lltype.nullptr(rffi.VOIDP.TO)])
+ assert res == 0
+ assert isinstance(res, r_ulonglong)
class TestOOtype(BaseTestRbuiltin, OORtypeMixin):
Modified: pypy/branch/cpython-extension/pypy/rpython/test/test_rdict.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/test/test_rdict.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/test/test_rdict.py Wed Mar 31 00:17:06 2010
@@ -4,7 +4,7 @@
from pypy.rpython.lltypesystem import rdict, rstr
from pypy.rpython.test.tool import BaseRtypingTest, LLRtypeMixin, OORtypeMixin
from pypy.rlib.objectmodel import r_dict
-from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
+from pypy.rlib.rarithmetic import r_int, r_uint, r_longlong, r_ulonglong
import py
py.log.setconsumer("rtyper", py.log.STDOUT)
@@ -567,6 +567,8 @@
def test_dict_of_r_uint(self):
for r_t in [r_uint, r_longlong, r_ulonglong]:
+ if r_t is r_int:
+ continue # for 64-bit platforms: skip r_longlong
d = {r_t(2): 3, r_t(4): 5}
def fn(x, y):
d[r_t(x)] = 123
Modified: pypy/branch/cpython-extension/pypy/rpython/test/test_rint.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/test/test_rint.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/test/test_rint.py Wed Mar 31 00:17:06 2010
@@ -110,10 +110,10 @@
def f(i):
return str(i)
- res = self.interpret(f, [r_longlong(0)])
+ res = self.interpret(f, [int64(0)])
assert self.ll_to_string(res) == '0'
- res = self.interpret(f, [r_longlong(413974738222117)])
+ res = self.interpret(f, [int64(413974738222117)])
assert self.ll_to_string(res) == '413974738222117'
def test_unsigned(self):
@@ -135,7 +135,7 @@
f._annspecialcase_ = "specialize:argtype(0)"
def g(n):
if n > 0:
- return f(r_longlong(0))
+ return f(int64(0))
else:
return f(0)
res = self.interpret(g, [0])
@@ -147,7 +147,7 @@
def test_downcast_int(self):
def f(i):
return int(i)
- res = self.interpret(f, [r_longlong(0)])
+ res = self.interpret(f, [int64(0)])
assert res == 0
def test_isinstance_vs_int_types(self):
Modified: pypy/branch/cpython-extension/pypy/rpython/tool/rffi_platform.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/tool/rffi_platform.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/tool/rffi_platform.py Wed Mar 31 00:17:06 2010
@@ -299,11 +299,16 @@
fieldoffsets.append(offset)
seen[cell] = True
+ allfields = tuple(['c_' + name for name, _ in fields])
+ padfields = tuple(padfields)
name = self.name
+ padding_drop = PaddingDrop(name, allfields, padfields,
+ config_result.CConfig._compilation_info_)
hints = {'align': info['align'],
'size': info['size'],
'fieldoffsets': tuple(fieldoffsets),
- 'padding': tuple(padfields)}
+ 'padding': padfields,
+ 'get_padding_drop': padding_drop}
if name.startswith('struct '):
name = name[7:]
else:
@@ -477,6 +482,89 @@
return info['size']
# ____________________________________________________________
+
+class PaddingDrop(object):
+ # Compute (lazily) the padding_drop for a structure.
+ # See test_generate_padding for more information.
+ cache = None
+
+ def __init__(self, name, allfields, padfields, eci):
+ self.name = name
+ self.allfields = allfields
+ self.padfields = padfields
+ self.eci = eci
+
+ def __call__(self, types):
+ if self.cache is None:
+ self.compute_now(types)
+ return self.cache
+
+ def compute_now(self, types):
+ # Some simplifying assumptions there. We assume that all fields
+ # are either integers or pointers, so can be written in C as '0'.
+ # We also assume that the C backend gives us in 'types' a dictionary
+ # mapping non-padding field names to their C type (without '@').
+ drops = []
+ staticfields = []
+ consecutive_pads = []
+ for fieldname in self.allfields:
+ if fieldname in self.padfields:
+ consecutive_pads.append(fieldname)
+ continue
+ staticfields.append(types[fieldname])
+ if consecutive_pads:
+ # In that case we have to ask: how many of these pads are
+ # really needed? The correct answer might be between none
+ # and all of the pads listed in 'consecutive_pads'.
+ for i in range(len(consecutive_pads)+1):
+ class CConfig:
+ _compilation_info_ = self.eci
+ FIELDLOOKUP = _PaddingDropFieldLookup(self.name,
+ staticfields,
+ fieldname)
+ try:
+ got = configure(CConfig)['FIELDLOOKUP']
+ if got == 1:
+ break # found
+ except CompilationError:
+ pass
+ staticfields.insert(-1, None)
+ else:
+ raise Exception("could not determine the detailed field"
+ " layout of %r" % (self.name,))
+ # succeeded with 'i' pads. Drop all pads beyond that.
+ drops += consecutive_pads[i:]
+ consecutive_pads = []
+ drops += consecutive_pads # drop the final pads too
+ self.cache = drops
+
+class _PaddingDropFieldLookup(CConfigEntry):
+ def __init__(self, name, staticfields, fieldname):
+ self.name = name
+ self.staticfields = staticfields
+ self.fieldname = fieldname
+
+ def prepare_code(self):
+ yield 'typedef %s platcheck_t;' % (self.name,)
+ yield 'static platcheck_t s = {'
+ for i, type in enumerate(self.staticfields):
+ if i == len(self.staticfields)-1:
+ value = -1
+ else:
+ value = 0
+ if type:
+ yield '\t(%s)%s,' % (type, value)
+ else:
+ yield '\t%s,' % (value,)
+ yield '};'
+ fieldname = self.fieldname
+ assert fieldname.startswith('c_')
+ yield 'dump("fieldlookup", s.%s != 0);' % (fieldname[2:],)
+
+ def build_result(self, info, config_result):
+ return info['fieldlookup']
+
+# ____________________________________________________________
#
# internal helpers
Modified: pypy/branch/cpython-extension/pypy/rpython/tool/rfficache.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/tool/rfficache.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/tool/rfficache.py Wed Mar 31 00:17:06 2010
@@ -13,7 +13,7 @@
from pypy.tool.gcc_cache import build_executable_cache
def ask_gcc(question, add_source=""):
- includes = ['stdlib.h', 'sys/types.h']
+ includes = ['stdlib.h', 'stdio.h', 'sys/types.h']
include_string = "\n".join(["#include <%s>" % i for i in includes])
c_source = py.code.Source('''
// includes
@@ -34,12 +34,22 @@
return build_executable_cache([c_file], eci)
def sizeof_c_type(c_typename, **kwds):
- question = 'printf("sizeof %s=%%d", sizeof(%s));' % (c_typename,
- c_typename)
- answer = ask_gcc(question, **kwds).split('=')
- assert answer[0] == "sizeof " + c_typename, "wrong program: " \
- "sizeof %s expected, got %s" % (c_typename, answer[0])
- return int(answer[1])
+ return sizeof_c_types([c_typename], **kwds)[0]
+
+def sizeof_c_types(typenames_c, **kwds):
+ lines = ['printf("sizeof %s=%%ld\\n", (long)sizeof(%s));' % (c_typename,
+ c_typename)
+ for c_typename in typenames_c]
+ question = '\n\t'.join(lines)
+ answer = ask_gcc(question, **kwds)
+ lines = answer.splitlines()
+ assert len(lines) == len(typenames_c)
+ result = []
+ for line, c_typename in zip(lines, typenames_c):
+ answer = line.split('=')
+ assert answer[0] == "sizeof " + c_typename
+ result.append(int(answer[1]))
+ return result
class Platform:
def __init__(self):
@@ -50,11 +60,28 @@
try:
return self.types[name]
except KeyError:
- bits = sizeof_c_type(c_name, **kwds) * 8
- inttype = rarithmetic.build_int('r_' + name, signed, bits)
- tp = lltype.build_number(name, inttype)
- self.numbertype_to_rclass[tp] = inttype
- self.types[name] = tp
- return tp
+ size = sizeof_c_type(c_name, **kwds)
+ return self._make_type(name, signed, size)
+
+ def _make_type(self, name, signed, size):
+ inttype = rarithmetic.build_int('r_' + name, signed, size*8)
+ tp = lltype.build_number(name, inttype)
+ self.numbertype_to_rclass[tp] = inttype
+ self.types[name] = tp
+ return tp
+
+ def populate_inttypes(self, list, **kwds):
+ """'list' is a list of (name, c_name, signed)."""
+ missing = []
+ names_c = []
+ for name, c_name, signed in list:
+ if name not in self.types:
+ missing.append((name, signed))
+ names_c.append(c_name)
+ if names_c:
+ sizes = sizeof_c_types(names_c, **kwds)
+ assert len(sizes) == len(missing)
+ for (name, signed), size in zip(missing, sizes):
+ self._make_type(name, signed, size)
platform = Platform()
Modified: pypy/branch/cpython-extension/pypy/rpython/tool/test/test_rffi_platform.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/rpython/tool/test/test_rffi_platform.py (original)
+++ pypy/branch/cpython-extension/pypy/rpython/tool/test/test_rffi_platform.py Wed Mar 31 00:17:06 2010
@@ -256,3 +256,104 @@
library_dirs = [str(tmpdir)]
)
rffi_platform.verify_eci(eci)
+
+def test_generate_padding():
+ # 'padding_drop' is a bit strange, but is what we need to write C code
+ # that defines prebuilt structures of that type. Normally, the C
+ # backend would generate '0' entries for every field c__pad#. That's
+ # usually much more than the number of real fields in the real structure
+ # definition. So 'padding_drop' allows a quick fix: it lists fields
+ # that should be ignored by the C backend. It should only be used in
+ # that situation because it lists some of the c__pad# fields a bit
+ # randomly -- to the effect that writing '0' for the other fields gives
+ # the right amount of '0's.
+ S = rffi_platform.getstruct("foobar_t", """
+ typedef struct {
+ char c1; /* followed by one byte of padding */
+ short s1;
+ } foobar_t;
+ """, [("c1", lltype.Signed),
+ ("s1", lltype.Signed)])
+ assert S._hints['padding'] == ('c__pad0',)
+ d = {'c_c1': 'char', 'c_s1': 'short'}
+ assert S._hints['get_padding_drop'](d) == ['c__pad0']
+ #
+ S = rffi_platform.getstruct("foobar_t", """
+ typedef struct {
+ char c1;
+ char c2; /* _pad0 */
+ short s1;
+ } foobar_t;
+ """, [("c1", lltype.Signed),
+ ("s1", lltype.Signed)])
+ assert S._hints['padding'] == ('c__pad0',)
+ d = {'c_c1': 'char', 'c_s1': 'short'}
+ assert S._hints['get_padding_drop'](d) == []
+ #
+ S = rffi_platform.getstruct("foobar_t", """
+ typedef struct {
+ char c1;
+ char c2; /* _pad0 */
+ /* _pad1, _pad2 */
+ int i1;
+ } foobar_t;
+ """, [("c1", lltype.Signed),
+ ("i1", lltype.Signed)])
+ assert S._hints['padding'] == ('c__pad0', 'c__pad1', 'c__pad2')
+ d = {'c_c1': 'char', 'c_i1': 'int'}
+ assert S._hints['get_padding_drop'](d) == ['c__pad1', 'c__pad2']
+ #
+ S = rffi_platform.getstruct("foobar_t", """
+ typedef struct {
+ char c1;
+ char c2; /* _pad0 */
+ char c3; /* _pad1 */
+ /* _pad2 */
+ int i1;
+ } foobar_t;
+ """, [("c1", lltype.Signed),
+ ("i1", lltype.Signed)])
+ assert S._hints['padding'] == ('c__pad0', 'c__pad1', 'c__pad2')
+ d = {'c_c1': 'char', 'c_i1': 'int'}
+ assert S._hints['get_padding_drop'](d) == ['c__pad2']
+ #
+ S = rffi_platform.getstruct("foobar_t", """
+ typedef struct {
+ char c1;
+ /* _pad0 */
+ short s1; /* _pad1, _pad2 */
+ int i1;
+ } foobar_t;
+ """, [("c1", lltype.Signed),
+ ("i1", lltype.Signed)])
+ assert S._hints['padding'] == ('c__pad0', 'c__pad1', 'c__pad2')
+ d = {'c_c1': 'char', 'c_i1': 'int'}
+ assert S._hints['get_padding_drop'](d) == ['c__pad1', 'c__pad2']
+ #
+ S = rffi_platform.getstruct("foobar_t", """
+ typedef struct {
+ char c1;
+ char c2; /* _pad0 */
+ /* _pad1, _pad2 */
+ int i1;
+ char c3; /* _pad3 */
+ /* _pad4 */
+ short s1;
+ } foobar_t;
+ """, [("c1", lltype.Signed),
+ ("i1", lltype.Signed),
+ ("s1", lltype.Signed)])
+ assert S._hints['padding'] == ('c__pad0', 'c__pad1', 'c__pad2',
+ 'c__pad3', 'c__pad4')
+ d = {'c_c1': 'char', 'c_i1': 'int', 'c_s1': 'short'}
+ assert S._hints['get_padding_drop'](d) == ['c__pad1', 'c__pad2', 'c__pad4']
+ #
+ S = rffi_platform.getstruct("foobar_t", """
+ typedef struct {
+ char c1;
+ long l2; /* some number of _pads */
+ } foobar_t;
+ """, [("c1", lltype.Signed)])
+ padding = list(S._hints['padding'])
+ d = {'c_c1': 'char'}
+ assert S._hints['get_padding_drop'](d) == padding
Modified: pypy/branch/cpython-extension/pypy/tool/terminal.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/tool/terminal.py (original)
+++ pypy/branch/cpython-extension/pypy/tool/terminal.py Wed Mar 31 00:17:06 2010
@@ -25,8 +25,8 @@
# List of numeric capabilities
VALUES = {
- 'COLUMNS':'cols', # Width of the terminal (None for unknown)
- 'LINES':'lines', # Height of the terminal (None for unknown)
+ 'COLUMNS':'cols', # Width of the terminal (80 for unknown)
+ 'LINES':'lines', # Height of the terminal (25 for unknown)
'MAX_COLORS': 'colors',
}
@@ -37,8 +37,9 @@
setattr(MODULE, 'BG_%s' % color, '')
for control in CONTROLS:
setattr(MODULE, control, '')
- for value in VALUES:
- setattr(MODULE, value, None)
+ MODULE.COLUMNS = 80
+ MODULE.LINES = 25
+ MODULE.MAX_COLORS = 1
def setup():
"""Set the terminal control strings"""
Modified: pypy/branch/cpython-extension/pypy/translator/c/gcc/test/conftest.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/gcc/test/conftest.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/gcc/test/conftest.py Wed Mar 31 00:17:06 2010
@@ -1,9 +1,9 @@
import py
from pypy.jit.backend import detect_cpu
-class Directory(py.test.collect.Directory):
+class Module(py.test.collect.Module):
def collect(self):
cpu = detect_cpu.autodetect()
if cpu != 'x86':
py.test.skip("x86 directory skipped: cpu is %r" % (cpu,))
- return super(Directory, self).collect()
+ return super(Module, self).collect()
Modified: pypy/branch/cpython-extension/pypy/translator/c/genc.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/genc.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/genc.py Wed Mar 31 00:17:06 2010
@@ -174,16 +174,19 @@
have___thread = None
+ def merge_eci(self, *ecis):
+ self.eci = self.eci.merge(*ecis)
+
def collect_compilation_info(self, db):
# we need a concrete gcpolicy to do this
- self.eci = self.eci.merge(db.gcpolicy.compilation_info())
+ self.merge_eci(db.gcpolicy.compilation_info())
all = []
for node in self.db.globalcontainers():
eci = getattr(node, 'compilation_info', None)
if eci:
all.append(eci)
- self.eci = self.eci.merge(*all)
+ self.merge_eci(*all)
def get_gcpolicyclass(self):
if self.gcpolicy is None:
Modified: pypy/branch/cpython-extension/pypy/translator/c/node.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/node.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/node.py Wed Mar 31 00:17:06 2010
@@ -11,6 +11,7 @@
from pypy.translator.c.support import c_char_array_constant, barebonearray
from pypy.translator.c.primitive import PrimitiveType, name_signed
from pypy.rlib.rarithmetic import isinf, isnan
+from pypy.rlib.rstackovf import _StackOverflow
from pypy.translator.c import extfunc
from pypy.translator.tool.cbuild import ExternalCompilationInfo
from py.builtin import BaseException
@@ -37,6 +38,8 @@
class StructDefNode:
typetag = 'struct'
+ extra_union_for_varlength = True
+
def __init__(self, db, STRUCT, varlength=1):
self.db = db
self.STRUCT = STRUCT
@@ -82,7 +85,8 @@
self.fields = []
db = self.db
STRUCT = self.STRUCT
- varlength = self.varlength
+ if self.varlength != 1:
+ self.normalizedtypename = db.gettype(STRUCT, who_asks=self)
if needs_gcheader(self.STRUCT):
for fname, T in db.gcpolicy.struct_gcheader_definition(self):
self.fields.append((fname, db.gettype(T, who_asks=self)))
@@ -151,6 +155,12 @@
if is_empty:
yield '\t' + 'char _dummy; /* this struct is empty */'
yield '};'
+ if self.varlength != 1:
+ assert self.typetag == 'struct'
+ yield 'union %su {' % self.name
+ yield ' struct %s a;' % self.name
+ yield ' %s;' % cdecl(self.normalizedtypename, 'b')
+ yield '};'
def visitor_lines(self, prefix, on_field):
for name in self.fieldnames:
@@ -162,6 +172,7 @@
def debug_offsets(self):
# generate number exprs giving the offset of the elements in the struct
+ assert self.varlength == 1
for name in self.fieldnames:
FIELD_T = self.c_struct_field_type(name)
if FIELD_T is Void:
@@ -178,15 +189,15 @@
class ArrayDefNode:
typetag = 'struct'
+ extra_union_for_varlength = True
def __init__(self, db, ARRAY, varlength=1):
self.db = db
self.ARRAY = ARRAY
self.LLTYPE = ARRAY
- original_varlength = varlength
self.gcfields = []
self.varlength = varlength
- if original_varlength == 1:
+ if varlength == 1:
basename = 'array'
with_number = True
else:
@@ -204,6 +215,8 @@
db = self.db
ARRAY = self.ARRAY
self.gcinfo # force it to be computed
+ if self.varlength != 1:
+ self.normalizedtypename = db.gettype(ARRAY, who_asks=self)
if needs_gcheader(ARRAY):
for fname, T in db.gcpolicy.array_gcheader_definition(self):
self.gcfields.append((fname, db.gettype(T, who_asks=self)))
@@ -227,7 +240,7 @@
return '%s.items[%s]' % (baseexpr, index)
access_expr_varindex = access_expr
- def ptr_access_expr(self, baseexpr, index):
+ def ptr_access_expr(self, baseexpr, index, dummy=False):
assert 0 <= index <= sys.maxint, "invalid constant index %r" % (index,)
return self.itemindex_access_expr(baseexpr, index)
@@ -251,8 +264,14 @@
line = 'char _dummy; ' + line
yield '\t' + line
yield '};'
+ if self.varlength != 1:
+ yield 'union %su {' % self.name
+ yield ' struct %s a;' % self.name
+ yield ' %s;' % cdecl(self.normalizedtypename, 'b')
+ yield '};'
def visitor_lines(self, prefix, on_item):
+ assert self.varlength == 1
ARRAY = self.ARRAY
# we need a unique name for this C variable, or at least one that does
# not collide with the expression in 'prefix'
@@ -279,6 +298,7 @@
def debug_offsets(self):
# generate three offsets for debugging inspection
+ assert self.varlength == 1
if not self.ARRAY._hints.get('nolength', False):
yield 'offsetof(struct %s, length)' % (self.name,)
else:
@@ -299,6 +319,7 @@
gcinfo = None
name = None
forward_decl = None
+ extra_union_for_varlength = False
def __init__(self, db, ARRAY, varlength=1):
self.db = db
@@ -325,7 +346,7 @@
return '%s[%d]' % (baseexpr, index)
access_expr_varindex = access_expr
- def ptr_access_expr(self, baseexpr, index):
+ def ptr_access_expr(self, baseexpr, index, dummy=False):
assert 0 <= index <= sys.maxint, "invalid constant index %r" % (index,)
return self.itemindex_access_expr(baseexpr, index)
@@ -349,6 +370,7 @@
gcinfo = None
name = None
typetag = 'struct'
+ extra_union_for_varlength = False
def __init__(self, db, FIXEDARRAY):
self.db = db
@@ -368,7 +390,7 @@
def getptrtype(self):
return self.itemtypename.replace('@', '*@')
- def access_expr(self, baseexpr, index):
+ def access_expr(self, baseexpr, index, dummy=False):
if not isinstance(index, int):
assert index.startswith('item')
index = int(index[4:])
@@ -461,28 +483,42 @@
parentnode = db.getcontainernode(parent)
defnode = db.gettypedefnode(parentnode.T)
self.name = defnode.access_expr(parentnode.name, parentindex)
- self.ptrname = '(&%s)' % self.name
if self.typename != self.implementationtypename:
- ptrtypename = db.gettype(Ptr(T))
- self.ptrname = '((%s)(void*)%s)' % (cdecl(ptrtypename, ''),
- self.ptrname)
+ if db.gettypedefnode(T).extra_union_for_varlength:
+ self.name += '.b'
+ self.ptrname = '(&%s)' % self.name
def is_thread_local(self):
return hasattr(self.T, "_hints") and self.T._hints.get('thread_local')
+ def get_declaration(self):
+ if self.name[-2:] == '.b':
+ # xxx fish fish
+ assert self.implementationtypename.startswith('struct ')
+ assert self.implementationtypename.endswith(' @')
+ uniontypename = 'union %su @' % self.implementationtypename[7:-2]
+ return uniontypename, self.name[:-2]
+ else:
+ return self.implementationtypename, self.name
+
def forward_declaration(self):
if llgroup.member_of_group(self.obj):
return
+ type, name = self.get_declaration()
yield '%s;' % (
- forward_cdecl(self.implementationtypename,
- self.name, self.db.standalone, self.is_thread_local()))
+ forward_cdecl(type, name, self.db.standalone,
+ self.is_thread_local()))
def implementation(self):
if llgroup.member_of_group(self.obj):
return []
lines = list(self.initializationexpr())
+ type, name = self.get_declaration()
+ if name != self.name:
+ lines[0] = '{ ' + lines[0] # extra braces around the 'a' part
+ lines[-1] += ' }' # of the union
lines[0] = '%s = %s' % (
- cdecl(self.implementationtypename, self.name, self.is_thread_local()),
+ cdecl(type, name, self.is_thread_local()),
lines[0])
lines[-1] += ';'
return lines
@@ -536,7 +572,19 @@
if hasattr(self.T, "_hints") and self.T._hints.get('union'):
data = data[0:1]
+ if 'get_padding_drop' in self.T._hints:
+ d = {}
+ for name, _ in data:
+ T = defnode.c_struct_field_type(name)
+ typename = self.db.gettype(T)
+ d[name] = cdecl(typename, '')
+ padding_drop = self.T._hints['get_padding_drop'](d)
+ else:
+ padding_drop = []
+
for name, value in data:
+ if name in padding_drop:
+ continue
c_expr = defnode.access_expr(self.name, name)
lines = generic_initializationexpr(self.db, value, c_expr,
decoration + name)
@@ -560,6 +608,7 @@
return 'struct _hashT_%s @' % self.name
def forward_declaration(self):
+ assert self.typename == self.implementationtypename # no array part
hash_typename = self.get_hash_typename()
hash_offset = self.db.gctransformer.get_hash_offset(self.T)
yield '%s {' % cdecl(hash_typename, '')
@@ -675,6 +724,7 @@
return 1 # not variable-sized!
def initializationexpr(self, decoration=''):
+ assert self.typename == self.implementationtypename # not var-sized
is_empty = True
yield '{'
# _names == ['item0', 'item1', ...]
@@ -928,9 +978,12 @@
import types, py
if isinstance(value, (type, types.ClassType)):
if (issubclass(value, BaseException) and
- (value.__module__ == 'exceptions'
- or value is py.code._AssertionError)):
+ value.__module__ == 'exceptions'):
return 'PyExc_' + value.__name__
+ if value is py.code._AssertionError:
+ return 'PyExc_AssertionError'
+ if value is _StackOverflow:
+ return 'PyExc_RuntimeError'
raise Exception("don't know how to simply render py object: %r" %
(value, ))
@@ -991,18 +1044,13 @@
forward_cdecl(ctype, self.name, self.db.standalone,
self.is_thread_local()))
yield '#include "src/llgroup.h"'
+ yield 'PYPY_GROUP_CHECK_SIZE(%s)' % (self.name,)
for i, member in enumerate(self.obj.members):
structnode = self.db.getcontainernode(member)
yield '#define %s %s.member%d' % (structnode.name,
self.name, i)
yield ''
- def startupcode(self):
- count = len(self.obj.members)
- if count == 0:
- return []
- return ['PYPY_GROUP_CHECK_SIZE(%s, member%d);' % (self.name, count-1)]
-
def initializationexpr(self):
self._fix_members()
lines = ['{']
Modified: pypy/branch/cpython-extension/pypy/translator/c/primitive.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/primitive.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/primitive.py Wed Mar 31 00:17:06 2010
@@ -148,9 +148,8 @@
if isinstance(value, Symbolic):
if isinstance(value, llgroup.GroupMemberOffset):
groupnode = db.getcontainernode(value.grpptr._as_obj())
- return 'GROUP_MEMBER_OFFSET(%s, %s, member%s)' % (
+ return 'GROUP_MEMBER_OFFSET(%s, member%s)' % (
cdecl(groupnode.implementationtypename, ''),
- groupnode.name,
value.index,
)
else:
Modified: pypy/branch/cpython-extension/pypy/translator/c/src/commondefs.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/src/commondefs.h (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/src/commondefs.h Wed Mar 31 00:17:06 2010
@@ -76,3 +76,7 @@
#define HAVE_LONG_LONG 1
#define Py_HUGE_VAL HUGE_VAL
+
+#ifdef _WIN32
+# define MS_WINDOWS /* a synonym */
+#endif
Modified: pypy/branch/cpython-extension/pypy/translator/c/src/exception.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/src/exception.h (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/src/exception.h Wed Mar 31 00:17:06 2010
@@ -99,14 +99,21 @@
assert(RPyExceptionOccurred());
assert(!PyErr_Occurred());
clsname = RPyFetchExceptionType()->ov_name->items;
- pycls = PyDict_GetItemString(PyEval_GetBuiltins(), clsname);
- if (pycls != NULL && PyExceptionClass_Check(pycls) &&
- PyObject_IsSubclass(pycls, PyExc_Exception)) {
- v = NULL;
+ v = NULL;
+ if (strcmp(clsname, "AssertionError") == 0) {
+ /* workaround against the py lib's BuiltinAssertionError */
+ pycls = PyExc_AssertionError;
+ }
+ else if (strcmp(clsname, "StackOverflow") == 0) {
+ pycls = PyExc_RuntimeError;
}
else {
- pycls = PyExc_Exception; /* XXX RPythonError */
- v = PyString_FromString(clsname);
+ pycls = PyDict_GetItemString(PyEval_GetBuiltins(), clsname);
+ if (pycls == NULL || !PyExceptionClass_Check(pycls) ||
+ !PyObject_IsSubclass(pycls, PyExc_Exception)) {
+ pycls = PyExc_Exception; /* XXX RPythonError */
+ v = PyString_FromString(clsname);
+ }
}
Py_INCREF(pycls);
tb = NULL;
Modified: pypy/branch/cpython-extension/pypy/translator/c/src/llgroup.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/src/llgroup.h (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/src/llgroup.h Wed Mar 31 00:17:06 2010
@@ -11,7 +11,7 @@
typedef unsigned short pypy_halfword_t;
-#define GROUP_MEMBER_OFFSET(grouptype, groupname, membername) \
+#define GROUP_MEMBER_OFFSET(grouptype, membername) \
((unsigned short)(((long)&((grouptype*)NULL)->membername) / 4))
#define _OP_GET_GROUP_MEMBER(groupptr, compactoffset) \
@@ -22,33 +22,31 @@
/* A macro to crash at compile-time if sizeof(group) is too large.
Uses a hack that I've found on some random forum. Haaaaaaaaaackish. */
-#define PYPY_GROUP_CHECK_SIZE(groupname, lastname) \
- { typedef char group_##groupname##_is_too_large[ \
- 2*(sizeof(groupname) <= 65536*4)-1]; }
+#define PYPY_GROUP_CHECK_SIZE(groupname) \
+ typedef char group_##groupname##_is_too_large[ \
+ 2*(sizeof(groupname) <= 65536*4)-1];
#else /******************************************************/
/* On 64-bit platforms, a CombinedSymbolic is two UINTs, and the lower
- one stores a real pointer to the group memeber. The limitation is
- that this pointer must fit inside 32-bit, i.e. the whole group must
- be located in the first 32 bits of address space. */
+ one is an 32-bit offset from the start of the group. */
typedef unsigned int pypy_halfword_t;
-#define GROUP_MEMBER_OFFSET(grouptype, groupname, membername) \
- ((long)(&groupname.membername))
+#define GROUP_MEMBER_OFFSET(grouptype, membername) \
+ offsetof(grouptype, membername)
#define _OP_GET_GROUP_MEMBER(groupptr, compactoffset) \
- ((long)compactoffset)
+ (((char*)groupptr) + (long)compactoffset)
#define _OP_GET_NEXT_GROUP_MEMBER(groupptr, compactoffset, skipoffset) \
- ((long)compactoffset + skipoffset)
+ (((char*)groupptr) + skipoffset + (long)compactoffset)
-/* A macro to check at run-time if the group is below the 32-bit limit. */
-#define PYPY_GROUP_CHECK_SIZE(groupname, lastname) \
- if ((unsigned long)(&groupname.lastname) > 0xFFFFFFFF) \
- error = "group " #groupname " is not located in the " \
- "initial 32 bits of address space"
+/* A macro to crash at compile-time if sizeof(group) is too large.
+ Uses a hack that I've found on some random forum. Haaaaaaaaaackish. */
+#define PYPY_GROUP_CHECK_SIZE(groupname) \
+ typedef char group_##groupname##_is_too_large[ \
+ 2*(sizeof(groupname) <= 4294967296L)-1];
#endif /*****************************************************/
Modified: pypy/branch/cpython-extension/pypy/translator/c/src/main.h
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/src/main.h (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/src/main.h Wed Mar 31 00:17:06 2010
@@ -15,6 +15,10 @@
#ifndef PYPY_NOT_MAIN_FILE
+#ifdef MS_WINDOWS
+#include "src/winstuff.c"
+#endif
+
int main(int argc, char *argv[])
{
char *errmsg;
@@ -29,6 +33,10 @@
goto error;
}
+#ifdef MS_WINDOWS
+ pypy_Windows_startup();
+#endif
+
errmsg = RPython_StartupCode();
if (errmsg) goto error;
Modified: pypy/branch/cpython-extension/pypy/translator/c/test/test_exception.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/test/test_exception.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/test/test_exception.py Wed Mar 31 00:17:06 2010
@@ -121,30 +121,16 @@
def testfn(n):
assert n >= 0
- # big confusion with py.test's AssertionError handling here...
- # some hacks to try to disable it for the current test.
- saved = no_magic()
- try:
- f1 = getcompiled(testfn, [int])
- res = f1(0)
- assert res is None, repr(res)
- res = f1(42)
- assert res is None, repr(res)
- py.test.raises(AssertionError, f1, -2)
- finally:
- restore_magic(saved)
-
-def no_magic():
- import __builtin__
- try:
- py.magic.revert(__builtin__, 'AssertionError')
- return True
- except ValueError:
- return False
-
-def restore_magic(saved):
- if saved:
- py.magic.invoke(assertion=True)
+ f1 = getcompiled(testfn, [int])
+ res = f1(0)
+ assert res is None, repr(res)
+ res = f1(42)
+ assert res is None, repr(res)
+ e = py.test.raises(Exception, f1, -2)
+ assert e.type.__name__ == 'AssertionError'
+ # ^^^ indirection, because we really want
+ # the original AssertionError and not the
+ # one patched by the py lib
def test_reraise_exception():
Modified: pypy/branch/cpython-extension/pypy/translator/c/test/test_lltyped.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/test/test_lltyped.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/test/test_lltyped.py Wed Mar 31 00:17:06 2010
@@ -732,14 +732,17 @@
('z4', Signed), ('u4', Signed))
goffsets = []
for i in range(4096 + toobig):
- goffsets.append(grp.add_member(malloc(S1, immortal=True)))
+ ofs = grp.add_member(malloc(S1, immortal=True))
+ goffsets.append(llgroup.CombinedSymbolic(ofs, 0))
grpptr = grp._as_ptr()
def f(n):
- p = llop.get_group_member(Ptr(S1), grpptr, goffsets[n])
+ o = llop.extract_ushort(llgroup.HALFWORD, goffsets[n])
+ p = llop.get_group_member(Ptr(S1), grpptr, o)
p.x = 5
for i in range(len(goffsets)):
if i != n:
- q = llop.get_group_member(Ptr(S1), grpptr, goffsets[i])
+ o = llop.extract_ushort(llgroup.HALFWORD, goffsets[i])
+ q = llop.get_group_member(Ptr(S1), grpptr, o)
q.x = 666
return p.x
if toobig:
@@ -779,3 +782,48 @@
fn = self.getcompiled(f, [])
res = fn()
assert res == 42
+
+ def test_padding_in_prebuilt_struct(self):
+ from pypy.rpython.lltypesystem import rffi
+ from pypy.rpython.tool import rffi_platform
+ eci = rffi_platform.eci_from_header("""
+ typedef struct {
+ char c1; /* followed by one byte of padding */
+ short s1;
+ char c2; /* followed by 3 bytes of padding */
+ int i2;
+ char c3; /* followed by 3 or 7 bytes of padding */
+ long l3;
+ char c4;
+ } foobar_t;
+ """)
+ class CConfig:
+ _compilation_info_ = eci
+ STRUCT = rffi_platform.Struct("foobar_t",
+ [("c1", Signed),
+ ("s1", Signed),
+ ("l3", Signed)])
+ S = rffi_platform.configure(CConfig)['STRUCT']
+ assert 'get_padding_drop' in S._hints
+ s1 = malloc(S, immortal=True)
+ s1.c_c1 = rffi.cast(S.c_c1, -12)
+ s1.c_s1 = rffi.cast(S.c_s1, -7843)
+ s1.c_l3 = -98765432
+ s2 = malloc(S, immortal=True)
+ s2.c_c1 = rffi.cast(S.c_c1, -123)
+ s2.c_s1 = rffi.cast(S.c_s1, -789)
+ s2.c_l3 = -9999999
+ #
+ def f(n):
+ if n > 5:
+ s = s1
+ else:
+ s = s2
+ return s.c_l3
+ #
+ self.include_also_eci = eci
+ fn = self.getcompiled(f, [int])
+ res = fn(10)
+ assert res == -98765432
+ res = fn(1)
+ assert res == -9999999
Modified: pypy/branch/cpython-extension/pypy/translator/c/test/test_newgc.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/test/test_newgc.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/test/test_newgc.py Wed Mar 31 00:17:06 2010
@@ -653,8 +653,8 @@
to_sort[2] = 1
to_sort[3] = 2
qsort.push_arg(rffi.cast(rffi.VOIDP, to_sort))
- qsort.push_arg(rffi.cast(rffi.SIZE_T, rffi.sizeof(rffi.LONG)))
qsort.push_arg(rffi.cast(rffi.SIZE_T, 4))
+ qsort.push_arg(rffi.cast(rffi.SIZE_T, rffi.sizeof(rffi.LONG)))
qsort.push_arg(rffi.cast(rffi.VOIDP, ptr.ll_closure))
qsort.call(lltype.Void)
result = [to_sort[i] for i in range(4)] == [1,2,3,4]
Modified: pypy/branch/cpython-extension/pypy/translator/c/test/test_standalone.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/test/test_standalone.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/test/test_standalone.py Wed Mar 31 00:17:06 2010
@@ -590,6 +590,7 @@
class TestMaemo(TestStandalone):
def setup_class(cls):
+ py.test.skip("TestMaemo: tests skipped for now")
from pypy.translator.platform.maemo import check_scratchbox
check_scratchbox()
from pypy.config.pypyoption import get_pypy_config
Modified: pypy/branch/cpython-extension/pypy/translator/c/test/test_typed.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/c/test/test_typed.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/c/test/test_typed.py Wed Mar 31 00:17:06 2010
@@ -28,6 +28,8 @@
def compilefunc(self, t, func):
from pypy.translator.c import genc
self.builder = builder = genc.CExtModuleBuilder(t, func, config=t.config)
+ if hasattr(self, 'include_also_eci'):
+ builder.merge_eci(self.include_also_eci)
builder.generate_source()
builder.compile()
return builder.get_entry_point()
Modified: pypy/branch/cpython-extension/pypy/translator/exceptiontransform.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/exceptiontransform.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/exceptiontransform.py Wed Mar 31 00:17:06 2010
@@ -13,6 +13,7 @@
from pypy.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
from pypy.rlib.rarithmetic import r_singlefloat
from pypy.rlib.debug import ll_assert
+from pypy.rlib.rstackovf import _StackOverflow
from pypy.annotation import model as annmodel
from pypy.rpython.annlowlevel import MixLevelHelperAnnotator
from pypy.tool.sourcetools import func_with_new_name
@@ -60,8 +61,8 @@
exc_data, null_type, null_value = self.setup_excdata()
rclass = translator.rtyper.type_system.rclass
- (runtime_error_ll_exc_type,
- runtime_error_ll_exc) = self.get_builtin_exception(RuntimeError)
+ (stackovf_ll_exc_type,
+ stackovf_ll_exc) = self.get_builtin_exception(_StackOverflow)
(assertion_error_ll_exc_type,
assertion_error_ll_exc) = self.get_builtin_exception(AssertionError)
(n_i_error_ll_exc_type,
@@ -114,8 +115,8 @@
exc_data.exc_type = rclass.ll_inst_type(evalue)
exc_data.exc_value = evalue
- def rpyexc_raise_runtime_error():
- rpyexc_raise(runtime_error_ll_exc_type, runtime_error_ll_exc)
+ def rpyexc_raise_stack_overflow():
+ rpyexc_raise(stackovf_ll_exc_type, stackovf_ll_exc)
self.rpyexc_occured_ptr = self.build_func(
"RPyExceptionOccurred",
@@ -151,9 +152,9 @@
lltype.Void,
jitcallkind='rpyexc_raise') # for the JIT
- self.rpyexc_raise_runtime_error_ptr = self.build_func(
- "RPyRaiseRuntimeError",
- self.noinline(rpyexc_raise_runtime_error),
+ self.rpyexc_raise_stack_overflow_ptr = self.build_func(
+ "RPyRaiseStackOverflow",
+ self.noinline(rpyexc_raise_stack_overflow),
[], lltype.Void)
self.rpyexc_fetch_exception_ptr = self.build_func(
@@ -237,10 +238,10 @@
if block.operations[i].opname == 'stack_unwind':
# if there are stack_unwind ops left,
# the graph was not stackless-transformed
- # so we need to raise a RuntimeError in any
+ # so we need to raise a StackOverflow in any
# case
block.operations[i].opname = "direct_call"
- block.operations[i].args = [self.rpyexc_raise_runtime_error_ptr]
+ block.operations[i].args = [self.rpyexc_raise_stack_overflow_ptr]
def replace_fetch_restore_operations(self, block):
# the gctransformer will create these operations. It looks as if the
Modified: pypy/branch/cpython-extension/pypy/translator/goal/translate.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/goal/translate.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/goal/translate.py Wed Mar 31 00:17:06 2010
@@ -7,6 +7,12 @@
import sys, os, new
import autopath
+import py
+# clean up early pypy/_cache
+try:
+ py.path.local(autopath.pypydir).join('_cache').remove()
+except Exception:
+ pass
from pypy.config.config import to_optparse, OptionDescription, BoolOption, \
ArbitraryOption, StrOption, IntOption, Config, \
@@ -82,7 +88,6 @@
'translation.debug': False,
}
-import py
# we want 2.4 expand_default functionality
import optparse
from pypy.tool.ansi_print import ansi_log
Modified: pypy/branch/cpython-extension/pypy/translator/jvm/test/test_backendopt.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/jvm/test/test_backendopt.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/jvm/test/test_backendopt.py Wed Mar 31 00:17:06 2010
@@ -1,9 +1,11 @@
import py
from pypy.translator.jvm.test.runtest import JvmTest
+from pypy.translator.jvm.genjvm import detect_missing_support_programs
from pypy.translator.oosupport.test_template.backendopt import BaseTestOptimizedSwitch
class TestOptimizedSwitch(BaseTestOptimizedSwitch):
def getcompiled(self, fn, annotation):
+ detect_missing_support_programs()
t = JvmTest()
return t.compile(fn, None, annotation, backendopt=True)
Modified: pypy/branch/cpython-extension/pypy/translator/jvm/test/test_rarithmetic.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/jvm/test/test_rarithmetic.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/jvm/test/test_rarithmetic.py Wed Mar 31 00:17:06 2010
@@ -1,5 +1,6 @@
import py
from pypy.translator.jvm.test.runtest import JvmTest
+from pypy.translator.jvm.genjvm import detect_missing_support_programs
from pypy.rlib.test.test_rarithmetic import Test_r_uint as BaseTest_r_uint
from pypy.rlib.test.test_rarithmetic import Test_r_int as BaseTest_r_int
from pypy.rlib.test.test_rarithmetic import test_ovfcheck as base_test_ovfcheck
@@ -8,6 +9,7 @@
class BaseAdaptedTest(JvmTest):
def unary_test(self, f):
+ detect_missing_support_programs()
cache = {}
def new_func(x):
xtype = type(x)
@@ -20,6 +22,7 @@
super(BaseAdaptedTest,self).unary_test(new_func)
def binary_test(self, f, rargs = None):
+ detect_missing_support_programs()
cache = {}
def new_func(x, y):
if type(x) == self.RTYPE or type(y) == self.RTYPE:
Modified: pypy/branch/cpython-extension/pypy/translator/platform/__init__.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/platform/__init__.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/platform/__init__.py Wed Mar 31 00:17:06 2010
@@ -10,21 +10,7 @@
log = py.log.Producer("platform")
py.log.setconsumer("platform", ansi_log)
-from subprocess import PIPE, Popen
-
-def _run_subprocess(executable, args, env=None):
- if isinstance(args, str):
- args = str(executable) + ' ' + args
- shell = True
- else:
- if args is None:
- args = [str(executable)]
- else:
- args = [str(executable)] + args
- shell = False
- pipe = Popen(args, stdout=PIPE, stderr=PIPE, shell=shell, env=env)
- stdout, stderr = pipe.communicate()
- return pipe.returncode, stdout, stderr
+from pypy.tool.runsubprocess import run_subprocess as _run_subprocess
class CompilationError(Exception):
def __init__(self, out, err):
@@ -108,9 +94,10 @@
# some helpers which seem to be cross-platform enough
- def _execute_c_compiler(self, cc, args, outname):
+ def _execute_c_compiler(self, cc, args, outname, cwd=None):
log.execute(cc + ' ' + ' '.join(args))
- returncode, stdout, stderr = _run_subprocess(cc, args, self.c_environ)
+ returncode, stdout, stderr = _run_subprocess(cc, args, self.c_environ,
+ cwd)
self._handle_error(returncode, stderr, stdout, outname)
def _handle_error(self, returncode, stderr, stdout, outname):
Modified: pypy/branch/cpython-extension/pypy/translator/platform/linux.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/platform/linux.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/platform/linux.py Wed Mar 31 00:17:06 2010
@@ -1,9 +1,7 @@
import py, os
-from pypy.translator.platform import Platform, CompilationError, ExecutionResult
-from pypy.translator.platform import log, _run_subprocess
-from pypy.tool import autopath
-from pypy.translator.platform.posix import GnuMakefile, BasePosix
+from pypy.translator.platform import _run_subprocess
+from pypy.translator.platform.posix import BasePosix
class Linux(BasePosix):
name = "linux"
@@ -19,10 +17,12 @@
return ['-shared'] + args
def include_dirs_for_libffi(self):
- return ['/usr/include/libffi']
+ return self._pkg_config("libffi", "--cflags-only-I",
+ ['/usr/include/libffi'])
def library_dirs_for_libffi(self):
- return ['/usr/lib/libffi']
+ return self._pkg_config("libffi", "--libs-only-L",
+ ['/usr/lib/libffi'])
def library_dirs_for_libffi_a(self):
# places where we need to look for libffi.a
Modified: pypy/branch/cpython-extension/pypy/translator/platform/maemo.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/platform/maemo.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/platform/maemo.py Wed Mar 31 00:17:06 2010
@@ -1,5 +1,6 @@
import py, os
-from pypy.translator.platform.linux import Linux, _run_subprocess, GnuMakefile
+from pypy.translator.platform.linux import Linux
+from pypy.translator.platform.posix import _run_subprocess, GnuMakefile
from pypy.translator.platform import ExecutionResult, log
from pypy.tool.udir import udir
from pypy.tool import autopath
Modified: pypy/branch/cpython-extension/pypy/translator/platform/posix.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/platform/posix.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/platform/posix.py Wed Mar 31 00:17:06 2010
@@ -32,7 +32,8 @@
def _compile_c_file(self, cc, cfile, compile_args):
oname = cfile.new(ext='o')
args = ['-c'] + compile_args + [str(cfile), '-o', str(oname)]
- self._execute_c_compiler(cc, args, oname)
+ self._execute_c_compiler(cc, args, oname,
+ cwd=str(cfile.dirpath()))
return oname
def _link(self, cc, ofiles, link_args, standalone, exe_name):
@@ -40,13 +41,24 @@
args += ['-o', str(exe_name)]
if not standalone:
args = self._args_for_shared(args)
- self._execute_c_compiler(cc, args, exe_name)
+ self._execute_c_compiler(cc, args, exe_name,
+ cwd=str(exe_name.dirpath()))
return exe_name
def _preprocess_dirs(self, include_dirs):
# hook for maemo
return include_dirs
+ def _pkg_config(self, lib, opt, default):
+ try:
+ ret, out, err = _run_subprocess("pkg-config", [lib, opt])
+ except OSError:
+ ret = 1
+ if ret:
+ return default
+ # strip compiler flags
+ return [entry[2:] for entry in out.split()]
+
def gen_makefile(self, cfiles, eci, exe_name=None, path=None):
cfiles = [py.path.local(f) for f in cfiles]
cfiles += [py.path.local(f) for f in eci.separate_module_files]
Modified: pypy/branch/cpython-extension/pypy/translator/platform/test/test_maemo.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/platform/test/test_maemo.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/platform/test/test_maemo.py Wed Mar 31 00:17:06 2010
@@ -13,6 +13,7 @@
strict_on_stderr = False
def setup_class(cls):
+ py.test.skip("TestMaemo: tests skipped for now")
check_scratchbox()
def test_includes_outside_scratchbox(self):
Modified: pypy/branch/cpython-extension/pypy/translator/platform/test/test_makefile.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/platform/test/test_makefile.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/platform/test/test_makefile.py Wed Mar 31 00:17:06 2010
@@ -1,5 +1,5 @@
-from pypy.translator.platform.linux import GnuMakefile as Makefile
+from pypy.translator.platform.posix import GnuMakefile as Makefile
from StringIO import StringIO
import re
Modified: pypy/branch/cpython-extension/pypy/translator/stackless/code.py
==============================================================================
--- pypy/branch/cpython-extension/pypy/translator/stackless/code.py (original)
+++ pypy/branch/cpython-extension/pypy/translator/stackless/code.py Wed Mar 31 00:17:06 2010
@@ -1,7 +1,7 @@
import sys
from pypy.rpython.lltypesystem import lltype, llmemory, lloperation
from pypy.tool.sourcetools import func_with_new_name
-from pypy.rlib import rarithmetic, objectmodel
+from pypy.rlib import rarithmetic, objectmodel, rstackovf
from pypy.translator.stackless import frame
from pypy.translator.stackless.frame import STATE_HEADER, SAVED_REFERENCE, STORAGE_TYPES_AND_FIELDS
@@ -382,7 +382,7 @@
# uncommon case: exceed the limit
pending = pending.f_back
pending.f_depth = depth - 1
- e = RuntimeError()
+ e = rstackovf._StackOverflow()
if not pending:
raise e
global_state.exception = e
More information about the Pypy-commit
mailing list