1. Pypy
  2. Untitled project
  3. pypy

Commits

Philip Jenvey  committed 7d3b266 Merge

merge default

  • Participants
  • Parent commits 383f13f, 58a5238
  • Branches py3k

Comments (0)

Files changed (175)

File _pytest/pdb.py

  • Ignore whitespace
File contents unchanged.

File lib-python/2/distutils/sysconfig_pypy.py

View file
  • Ignore whitespace
     if prefix is None:
         prefix = PREFIX
     if standard_lib:
-        return os.path.join(prefix, "lib-python", get_python_version())
+        return os.path.join(prefix, "lib-python", sys.version[0])
     return os.path.join(prefix, 'site-packages')
 
 
     g['SO'] = _get_so_extension() or ".so"
     g['SOABI'] = g['SO'].rsplit('.')[0]
     g['LIBDIR'] = os.path.join(sys.prefix, 'lib')
+    g['CC'] = "gcc -pthread" # -pthread might not be valid on OS/X, check
 
     global _config_vars
     _config_vars = g

File lib-python/2/pickle.py

View file
  • Ignore whitespace
 import struct
 import re
 
+from __pypy__.builders import StringBuilder
+
 __all__ = ["PickleError", "PicklingError", "UnpicklingError", "Pickler",
            "Unpickler", "dump", "dumps", "load", "loads"]
 
 except ImportError:
     from StringIO import StringIO
 
+
+class StringBuilderFile(object):
+    ''' pickle uses only file.write - provide this method, 
+    use StringBuilder for speed
+    '''
+    def __init__(self):
+        self.builder = StringBuilder()
+        self.write = self.builder.append
+
+    def getvalue(self):
+        return self.builder.build()
+
+
 def dump(obj, file, protocol=None):
     Pickler(file, protocol).dump(obj)
 
 def dumps(obj, protocol=None):
-    file = StringIO()
+    file = StringBuilderFile()
     Pickler(file, protocol).dump(obj)
     return file.getvalue()
 

File lib-python/2/sysconfig.py

View file
  • Ignore whitespace
         'data'   : '{base}',
         },
     'pypy': {
-        'stdlib': '{base}/lib-python/{py_version_short}',
-        'platstdlib': '{base}/lib-python/{py_version_short}',
-        'purelib': '{base}/lib-python/{py_version_short}',
-        'platlib': '{base}/lib-python/{py_version_short}',
+        'stdlib': '{base}/lib-python/{py_version}',
+        'platstdlib': '{base}/lib-python/{py_version}',
+        'purelib': '{base}/lib-python/{py_version}',
+        'platlib': '{base}/lib-python/{py_version}',
         'include': '{base}/include',
         'platinclude': '{base}/include',
         'scripts': '{base}/bin',

File lib_pypy/_marshal.py

View file
  • Ignore whitespace
 # the "sandboxed" process.  It must work for Python2 as well.
 
 import types
-from _codecs import utf_8_decode, utf_8_encode
 
 try:
     intern
 
     def dump_unicode(self, x):
         self._write(TYPE_UNICODE)
-        #s = x.encode('utf8')
-        s, len_s = utf_8_encode(x)
-        self.w_long(len_s)
+        s = x.encode('utf8')
+        self.w_long(len(s))
         self._write(s)
     try:
         unicode
     def load_unicode(self):
         n = self.r_long()
         s = self._read(n)
-        #ret = s.decode('utf8')
-        ret, len_ret = utf_8_decode(s)
+        ret = s.decode('utf8')
         return ret
     dispatch[TYPE_UNICODE] = load_unicode
 

File lib_pypy/_sqlite3.py

View file
  • Ignore whitespace
         self._in_transaction = False
         self.isolation_level = isolation_level
 
-        self._cursors = []
+        self.__cursors = []
+        self.__cursors_counter = 0
         self.__statements = []
-        self.__statement_counter = 0
+        self.__statements_counter = 0
         self._statement_cache = _StatementCache(self, cached_statements)
 
         self.__func_cache = {}
     def close(self):
         self._check_thread()
 
-        for statement in self.__statements:
-            obj = statement()
-            if obj is not None:
-                obj._finalize()
+        self.__do_all_statements(Statement._finalize, True)
 
         if self._db:
             ret = _lib.sqlite3_close(self._db)
         exc.error_code = error_code
         return exc
 
+    def _remember_cursor(self, cursor):
+        self.__cursors.append(weakref.ref(cursor))
+        self.__cursors_counter += 1
+        if self.__cursors_counter < 200:
+            return
+        self.__cursors_counter = 0
+        self.__cursors = [r for r in self.__cursors if r() is not None]
+
     def _remember_statement(self, statement):
         self.__statements.append(weakref.ref(statement))
-        self.__statement_counter += 1
+        self.__statements_counter += 1
+        if self.__statements_counter < 200:
+            return
+        self.__statements_counter = 0
+        self.__statements = [r for r in self.__statements if r() is not None]
 
-        if self.__statement_counter % 100 == 0:
-            self.__statements = [ref for ref in self.__statements
-                                 if ref() is not None]
+    def __do_all_statements(self, action, reset_cursors):
+        for weakref in self.__statements:
+            statement = weakref()
+            if statement is not None:
+                action(statement)
+
+        if reset_cursors:
+            for weakref in self.__cursors:
+                cursor = weakref()
+                if cursor is not None:
+                    cursor._reset = True
 
     @_check_thread_wrap
     @_check_closed_wrap
         if not self._in_transaction:
             return
 
-        for statement in self.__statements:
-            obj = statement()
-            if obj is not None:
-                obj._reset()
+        self.__do_all_statements(Statement._reset, False)
 
         statement = c_void_p()
         ret = _lib.sqlite3_prepare_v2(self._db, b"COMMIT", -1,
         if not self._in_transaction:
             return
 
-        for statement in self.__statements:
-            obj = statement()
-            if obj is not None:
-                obj._reset()
-
-        for cursor_ref in self._cursors:
-            cursor = cursor_ref()
-            if cursor:
-                cursor._reset = True
+        self.__do_all_statements(Statement._reset, True)
 
         statement = c_void_p()
         ret = _lib.sqlite3_prepare_v2(self._db, b"ROLLBACK", -1,
     __statement = None
 
     def __init__(self, con):
-        self.__initialized = True
-        self.__connection = con
-
         if not isinstance(con, Connection):
             raise TypeError
-        con._check_thread()
-        con._check_closed()
-        con._cursors.append(weakref.ref(self))
+        self.__connection = con
 
         self.arraysize = 1
         self.row_factory = None
         self.__description = None
         self.__rowcount = -1
 
+        con._check_thread()
+        con._remember_cursor(self)
+
+        self.__initialized = True
+
     def __del__(self):
-        try:
-            self.__connection._cursors.remove(weakref.ref(self))
-        except (AttributeError, ValueError):
-            pass
         if self.__statement:
             self.__statement._reset()
 
                 if self.__statement._kind == Statement._DQL and ret == _lib.SQLITE_ROW:
                     self.__statement._build_row_cast_map()
                     self.__statement._readahead(self)
-                else:
-                    self.__statement._item = None
-                    self.__statement._exhausted = True
 
                 if self.__statement._kind == Statement._DML:
                     if self.__rowcount == -1:
                     self.__rowcount += _lib.sqlite3_changes(self.__connection._db)
         finally:
             self.__locked = False
-
         return self
 
     @__check_cursor_wrap
             if rc != _lib.SQLITE_DONE:
                 _lib.sqlite3_finalize(statement)
                 if rc == _lib.SQLITE_OK:
-                    return self
+                    break
                 else:
                     raise self.__connection._get_exception(rc)
+
             rc = _lib.sqlite3_finalize(statement)
             if rc != _lib.SQLITE_OK:
                 raise self.__connection._get_exception(rc)
 
     def __init__(self, connection, sql):
         self.__con = connection
+        self.__con._remember_statement(self)
 
         if not isinstance(sql, basestring):
             raise Warning("SQL is of wrong type. Must be string or unicode.")
             self._kind = Statement._DDL
 
         self._in_use = False
-        self._exhausted = False
         self._row_factory = None
 
         if isinstance(sql, unicode):
             ret = _lib.sqlite3_prepare_v2(self.__con._db, sql, -1,
                                           byref(self._statement), byref(sql))
             self._kind = Statement._DQL
-
         if ret != _lib.SQLITE_OK:
             raise self.__con._get_exception(ret)
-        self.__con._remember_statement(self)
+
         sql = sql.value.decode('utf-8')
         if _check_remaining_sql(sql):
             raise Warning("You can only execute one statement at a time.")
         if self._in_use and self._statement:
             _lib.sqlite3_reset(self._statement)
             self._in_use = False
-        self._exhausted = False
 
     if sys.version_info[0] < 3:
         def __check_decodable(self, param):
         self._item = row
 
     def _next(self, cursor):
-        if self._exhausted:
+        try:
+            item = self._item
+        except AttributeError:
             raise StopIteration
-        item = self._item
+        del self._item
 
         ret = _lib.sqlite3_step(self._statement)
-        if ret == _lib.SQLITE_DONE:
-            self._exhausted = True
-            self._item = None
-        elif ret != _lib.SQLITE_ROW:
-            exc = self.__con._get_exception(ret)
+        if ret not in (_lib.SQLITE_DONE, _lib.SQLITE_ROW):
             _lib.sqlite3_reset(self._statement)
-            raise exc
+            raise self.__con._get_exception(ret)
+        elif ret == _lib.SQLITE_ROW:
+            self._readahead(cursor)
 
-        self._readahead(cursor)
         return item
 
     def _get_description(self):

File lib_pypy/numpypy/core/numeric.py

View file
  • Ignore whitespace
            'array_repr', 'array_str', 'set_string_function',
            'array_equal', 'outer', 'vdot', 'identity', 'little_endian',
            'Inf', 'inf', 'infty', 'Infinity', 'nan', 'NaN', 'False_', 'True_',
+           'seterr',
           ]
 
 import sys

File pypy/TODO

View file
  • Ignore whitespace
+
+* ARM

File pypy/doc/whatsnew-head.rst

View file
  • Ignore whitespace
 .. branch: numpy-unify-methods
 .. branch: fix-version-tool
 .. branch: popen2-removal
+.. branch: pickle-dumps
 
 .. branch: release-2.0-beta1
 
 
 .. branch: vendor-rename
 Remove minor verison number from lib-python dirs to simplify stdlib upgrades.
+
+.. branch: jitframe-on-heap
+Moves optimized JIT frames from stack to heap. As a side effect it enables
+stackless to work well with the JIT on PyPy. Also removes a bunch of code from
+the GC which fixes cannot find gc roots.

File pypy/goal/getnightly.py

View file
  • Ignore whitespace
+#!/usr/bin/env python
+
+import sys
+import os
+import py
+
+if sys.platform.startswith('linux'):
+    arch = 'linux'
+else:
+    print 'Cannot determine the platform, please update this scrip'
+    sys.exit(1)
+
+if sys.maxint == 2**63 - 1:
+    arch += '64'
+
+filename = 'pypy-c-jit-latest-%s.tar.bz2' % arch
+url = 'http://buildbot.pypy.org/nightly/trunk/%s' % filename
+tmp = py.path.local.mkdtemp()
+mydir = tmp.chdir()
+print 'Downloading pypy to', tmp
+if os.system('wget "%s"' % url) != 0:
+    sys.exit(1)
+
+print 'Extracting pypy binary'
+mydir.chdir()
+os.system("tar -x -v --wildcards --strip-components=2 -f %s '*/bin/pypy'" % tmp.join(filename))
+

File pypy/interpreter/error.py

View file
  • Ignore whitespace
-import os, sys
+import cStringIO
 import itertools
+import os
+import sys
+import traceback
+from errno import EINTR
+
 from rpython.rlib import jit
 from rpython.rlib.objectmodel import we_are_translated
-from errno import EINTR
+
+from pypy.interpreter import debug
+
 
 AUTO_DEBUG = os.getenv('PYPY_DEBUG')
 RECORD_INTERPLEVEL_TRACEBACK = True
         if space is None:
             # this part NOT_RPYTHON
             exc_typename = str(self.w_type)
-            exc_value    = str(w_value)
+            exc_value = str(w_value)
         else:
             w = space.wrap
             if space.is_w(space.type(self.w_type), space.w_text):
 
     def print_application_traceback(self, space, file=None):
         "NOT_RPYTHON: Dump a standard application-level traceback."
-        if file is None: file = sys.stderr
+        if file is None:
+            file = sys.stderr
         self.print_app_tb_only(file)
         print >> file, self.errorstr(space)
 
     def print_detailed_traceback(self, space=None, file=None):
         """NOT_RPYTHON: Dump a nice detailed interpreter- and
         application-level traceback, useful to debug the interpreter."""
-        import traceback, cStringIO
-        if file is None: file = sys.stderr
+        if file is None:
+            file = sys.stderr
         f = cStringIO.StringIO()
         for i in range(len(self.debug_excs)-1, -1, -1):
             print >> f, "Traceback (interpreter-level):"
         self.print_app_tb_only(file)
         print >> file, '(application-level)', self.errorstr(space)
         if AUTO_DEBUG:
-            import debug
             debug.fire(self)
 
     @jit.unroll_safe
         #  (Class, x)                 (Class, Class(x))               no
         #  (inst, None)               (inst.__class__, inst)          no
         #
-        w_type  = self.w_type
+        w_type = self.w_type
         w_value = self.get_w_value(space)
 
         if space.exception_is_valid_obj_as_class_w(w_type):
             w_value = w_inst
             w_type = w_instclass
 
-        self.w_type   = w_type
+        self.w_type = w_type
         self._w_value = w_value
 
     def _exception_getclass(self, space, w_inst, what="exceptions"):
         from rpython.rlib.unroll import unrolling_iterable
         attrs = ['x%d' % i for i in range(len(formats))]
         entries = unrolling_iterable(zip(itertools.count(), formats, attrs))
-        #
+
         class OpErrFmt(OperationError):
             def __init__(self, w_type, strings, *args):
                 assert len(args) == len(strings) - 1
                     setattr(self, attr, args[i])
                 assert w_type is not None
                 self.setup(w_type)
+
             def _compute_value(self):
                 lst = [None] * (len(formats) + len(formats) + 1)
                 for i, fmt, attr in entries:

File pypy/interpreter/nestedscope.py

View file
  • Ignore whitespace
-from pypy.interpreter.error import OperationError
-from pypy.interpreter import function, pycode, pyframe
-from pypy.interpreter.baseobjspace import Wrappable
-from pypy.interpreter.mixedmodule import MixedModule
-from pypy.interpreter.astcompiler import consts
 from rpython.rlib import jit
 from rpython.tool.uid import uid
 
+from pypy.interpreter import function, pycode, pyframe
+from pypy.interpreter.astcompiler import consts
+from pypy.interpreter.baseobjspace import Wrappable
+from pypy.interpreter.error import OperationError
+from pypy.interpreter.mixedmodule import MixedModule
+
+
 class Cell(Wrappable):
     "A simple container for a wrapped value."
 
 
     def get(self):
         if self.w_value is None:
-            raise ValueError, "get() from an empty cell"
+            raise ValueError("get() from an empty cell")
         return self.w_value
 
     def set(self, w_value):
 
     def delete(self):
         if self.w_value is None:
-            raise ValueError, "delete() on an empty cell"
+            raise ValueError("delete() on an empty cell")
         self.w_value = None
 
     def descr__lt__(self, space, w_other):
         return space.eq(self.w_value, other.w_value)
 
     def descr__reduce__(self, space):
-        w_mod    = space.getbuiltinmodule('_pickle_support')
-        mod      = space.interp_w(MixedModule, w_mod)
+        w_mod = space.getbuiltinmodule('_pickle_support')
+        mod = space.interp_w(MixedModule, w_mod)
         new_inst = mod.get('cell_new')
-        if self.w_value is None:    #when would this happen?
+        if self.w_value is None:    # when would this happen?
             return space.newtuple([new_inst, space.newtuple([])])
         tup = [self.w_value]
         return space.newtuple([new_inst, space.newtuple([]),
 
     def descr__setstate__(self, space, w_state):
         self.w_value = space.getitem(w_state, space.wrap(0))
-        
+
     def __repr__(self):
         """ representation for debugging purposes """
         if self.w_value is None:
             raise OperationError(space.w_ValueError, space.wrap("Cell is empty"))
 
 
-
 super_initialize_frame_scopes = pyframe.PyFrame.initialize_frame_scopes
-super_fast2locals             = pyframe.PyFrame.fast2locals
-super_locals2fast             = pyframe.PyFrame.locals2fast
+super_fast2locals = pyframe.PyFrame.fast2locals
+super_locals2fast = pyframe.PyFrame.locals2fast
 
 
 class __extend__(pyframe.PyFrame):
     def fast2locals(self):
         super_fast2locals(self)
         # cellvars are values exported to inner scopes
-        # freevars are values coming from outer scopes 
+        # freevars are values coming from outer scopes
         freevarnames = list(self.pycode.co_cellvars)
         if self.pycode.co_flags & consts.CO_OPTIMIZED:
             freevarnames.extend(self.pycode.co_freevars)

File pypy/module/_continuation/interp_continuation.py

View file
  • Ignore whitespace
         #  - normal:      self.sthread != None, not is_empty_handle(self.h)
         #  - finished:    self.sthread != None, is_empty_handle(self.h)
 
-    def __del__(self):
-        sthread = self.sthread
-        if sthread is not None and not sthread.is_empty_handle(self.h):
-            sthread.destroy(self.h)
-
     def check_sthread(self):
         ec = self.space.getexecutioncontext()
         if ec.stacklet_thread is not self.sthread:
         if self.sthread is not None:
             raise geterror(self.space, "continulet already __init__ialized")
         sthread = build_sthread(self.space)
-        workaround_disable_jit(sthread)
         #
         # hackish: build the frame "by hand", passing it the correct arguments
         space = self.space
                 global_state.clear()
                 raise geterror(self.space, "continulet already finished")
         self.check_sthread()
-        workaround_disable_jit(self.sthread)
-        #
+
         global_state.origin = self
         if to is None:
             # simple switch: going to self.h
         sthread = ec.stacklet_thread = SThread(space, ec)
     return sthread
 
-def workaround_disable_jit(sthread):
-    # A bad workaround to kill the JIT anywhere in this thread.
-    # This forces all the frames.  It's a bad workaround because
-    # it takes O(depth) time, and it will cause some "abort:
-    # vable escape" in the JIT.  The goal is to prevent any frame
-    # from being still virtuals, because the JIT generates code
-    # to un-virtualizable them "on demand" by loading values based
-    # on FORCE_TOKEN, which is an address in the stack.
-    sthread.ec.force_all_frames()
-
 # ____________________________________________________________
 
 def permute(space, args_w):

File pypy/module/_io/interp_iobase.py

View file
  • Ignore whitespace
     def remove(self, w_iobase):
         holder = w_iobase.streamholder
         if holder is not None:
-            del self.streams[holder]
+            try:
+                del self.streams[holder]
+            except KeyError:
+                # this can happen in daemon threads
+                pass
 
     def flush_all(self, space):
         while self.streams:

File pypy/module/cppyy/capi/reflex_capi.py

View file
  • Ignore whitespace
 srcpath = pkgpath.join("src")
 incpath = pkgpath.join("include")
 
+import commands
+(config_stat, incdir) = commands.getstatusoutput("root-config --incdir")
+
 if os.environ.get("ROOTSYS"):
-    import commands
-    (stat, incdir) = commands.getstatusoutput("root-config --incdir")
-    if stat != 0:        # presumably Reflex-only
+    if config_stat != 0:     # presumably Reflex-only
         rootincpath = [os.path.join(os.environ["ROOTSYS"], "include")]
         rootlibpath = [os.path.join(os.environ["ROOTSYS"], "lib64"), os.path.join(os.environ["ROOTSYS"], "lib")]
     else:
         rootincpath = [incdir]
         rootlibpath = commands.getoutput("root-config --libdir").split()
 else:
-    rootincpath = []
-    rootlibpath = []
+    if config_stat == 0:
+        rootincpath = [incdir]
+        rootlibpath = commands.getoutput("root-config --libdir").split()
+    else:
+        rootincpath = []
+        rootlibpath = []
 
 def identify():
     return 'Reflex'

File pypy/module/cppyy/test/Makefile

View file
  • Ignore whitespace
 
 ifeq ($(ROOTSYS),)
   genreflex=genreflex
-  cppflags=
+  cppflags=-I$(shell root-config --incdir) -L$(shell root-config --libdir)
 else
   genreflex=$(ROOTSYS)/bin/genreflex
   ifeq ($(wildcard $(ROOTSYS)/include),)     # standard locations used?

File pypy/module/cppyy/test/test_crossing.py

View file
  • Ignore whitespace
 import py, os, sys
+from pypy.interpreter.gateway import interp2app, unwrap_spec
+from rpython.translator.tool.cbuild import ExternalCompilationInfo
+from rpython.translator import platform
+from rpython.translator.gensupp import uniquemodulename
+from rpython.tool.udir import udir
+
+from pypy.module.cpyext import api
+from pypy.module.cpyext.state import State
+
 from pypy.module.cpyext.test.test_cpyext import AppTestCpythonExtensionBase
 
+
 currpath = py.path.local(__file__).dirpath()
 test_dct = str(currpath.join("crossingDict.so"))
 
     if err:
         raise OSError("'make' failed (see stderr)")
 
+# from pypy/module/cpyext/test/test_cpyext.py; modified to accept more external
+# symbols and called directly instead of import_module
+def compile_extension_module(space, modname, symbols, **kwds):
+    """
+    Build an extension module and return the filename of the resulting native
+    code file.
+
+    modname is the name of the module, possibly including dots if it is a module
+    inside a package.
+
+    Any extra keyword arguments are passed on to ExternalCompilationInfo to
+    build the module (so specify your source with one of those).
+    """
+    state = space.fromcache(State)
+    api_library = state.api_lib
+    if sys.platform == 'win32':
+        kwds["libraries"] = [api_library]
+        # '%s' undefined; assuming extern returning int
+        kwds["compile_extra"] = ["/we4013"]
+    elif sys.platform == 'darwin':
+        kwds["link_files"] = [str(api_library + '.dylib')]
+    else:
+        kwds["link_files"] = [str(api_library + '.so')]
+        if sys.platform.startswith('linux'):
+            kwds["compile_extra"]=["-Werror=implicit-function-declaration"]
+
+    modname = modname.split('.')[-1]
+    eci = ExternalCompilationInfo(
+        export_symbols=['init%s' % (modname,)]+symbols,
+        include_dirs=api.include_dirs,
+        **kwds
+        )
+    eci = eci.convert_sources_to_files()
+    dirname = (udir/uniquemodulename('module')).ensure(dir=1)
+    soname = platform.platform.compile(
+        [], eci,
+        outputfilename=str(dirname/modname),
+        standalone=False)
+    from pypy.module.imp.importing import get_so_extension
+    pydname = soname.new(purebasename=modname, ext=get_so_extension(space))
+    soname.rename(pydname)
+    return str(pydname)
 
 class AppTestCrossing(AppTestCpythonExtensionBase):
     spaceconfig = dict(usemodules=['cpyext', 'cppyy', 'thread', '_rawffi', '_ffi',
                                    'array', 'itertools', 'rctime', 'binascii'])
 
     def setup_class(cls):
-        # following from AppTestCpythonExtensionBase, with cppyy added
-        cls.space.getbuiltinmodule("cpyext")
-        from pypy.module.imp.importing import importhook
-        importhook(cls.space, "os") # warm up reference counts
-        from pypy.module.cpyext.pyobject import RefcountState
-        state = cls.space.fromcache(RefcountState)
-        state.non_heaptypes_w[:] = []
-
-        # cppyy specific additions (not that the test_dct is loaded late
+        AppTestCpythonExtensionBase.setup_class.im_func(cls)
+        # cppyy specific additions (note that test_dct is loaded late
         # to allow the generated extension module be loaded first)
         cls.w_test_dct    = cls.space.wrap(test_dct)
         cls.w_pre_imports = cls.space.appexec([], """():
             import cppyy, ctypes""")    # prevents leak-checking complaints on ctypes
-        from pypy.module.imp.importing import get_so_extension
-        cls.w_soext = cls.space.wrap(get_so_extension(cls.space))
+
+    def setup_method(self, func):
+        AppTestCpythonExtensionBase.setup_method.im_func(self, func)
+
+        @unwrap_spec(name=str, init=str, body=str)
+        def load_cdll(space, name, init, body, w_symbols):
+            # the following is loosely from test_cpyext.py import_module; it
+            # is copied here to be able to tweak the call to
+            # compile_extension_module and to get a different return result
+            # than in that function
+            code = """
+            #include <Python.h>
+            %(body)s
+
+            void init%(name)s(void) {
+            %(init)s
+            }
+            """ % dict(name=name, init=init, body=body)
+            kwds = dict(separate_module_sources=[code])
+            symbols = [space.str_w(w_item) for w_item in space.fixedview(w_symbols)]
+            mod = compile_extension_module(space, name, symbols, **kwds)
+
+            # explicitly load the module as a CDLL rather than as a module
+            import ctypes
+            from pypy.module.imp.importing import get_so_extension
+            fullmodname = os.path.join(
+                os.path.dirname(mod), name + get_so_extension(space))
+            return ctypes.CDLL(fullmodname, ctypes.RTLD_GLOBAL)
+
+        self.w_load_cdll = self.space.wrap(interp2app(load_cdll))
 
     def test00_base_class(self):
         """Test from cpyext; only here to see whether the imported class works"""
 
         import os, ctypes
 
+        name = 'bar'
+
         init = """
         if (Py_IsInitialized())
             Py_InitModule("bar", methods);
         """
+
         # note: only the symbols are needed for C, none for python
         body = """
         long bar_unwrap(PyObject* arg)
             { NULL }
         };
         """
+        # explicitly load the module as a CDLL rather than as a module
+#        dirname = space.wrap(os.path.dirname(mod))
 
-        dirname = self.import_module(name='bar', init=init, body=body, load_it=False)
-        fullmodname = os.path.join(dirname, 'bar' + self.soext)
-        self.cmodule = ctypes.CDLL(fullmodname, ctypes.RTLD_GLOBAL)
+#        dirname = self.import_module(name='bar', init=init, body=body, load_it=False)
+#        fullmodname = os.path.join(dirname, name + self.soext)
+        self.cmodule = self.load_cdll(name, init, body, ['bar_unwrap', 'bar_wrap'])#ctypes.CDLL(fullmodname, ctypes.RTLD_GLOBAL)
 
     def test02_crossing_dict(self):
         """Test availability of all needed classes in the dict"""

File pypy/module/cppyy/test/test_pythonify.py

View file
  • Ignore whitespace
 test_dct = str(currpath.join("example01Dict.so"))
 
 def setup_module(mod):
+    # force removal of ROOTSYS for this one test, which serves as a test itself
+    if os.getenv("ROOTSYS"):
+        os.unsetenv("ROOTSYS")
     if sys.platform == 'win32':
         py.test.skip("win32 not supported so far")
     err = os.system("cd '%s' && make example01Dict.so" % currpath)

File pypy/module/micronumpy/interp_arrayops.py

View file
  • Ignore whitespace
     _axis = axis
     if axis < 0:
         _axis = len(shape) + axis
-    if _axis < 0 or len(shape) <= _axis:
-        raise operationerrfmt(space.w_IndexError, "axis %d out of bounds [0, %d)", axis, len(shape))
     for arr in args_w[1:]:
-        dtype = interp_ufuncs.find_binop_result_dtype(space, dtype,
-                                                      arr.get_dtype())
-        if _axis < 0 or len(arr.get_shape()) <= _axis:
-            raise operationerrfmt(space.w_IndexError, "axis %d out of bounds [0, %d)", axis, len(shape))
         for i, axis_size in enumerate(arr.get_shape()):
             if len(arr.get_shape()) != len(shape) or (i != _axis and axis_size != shape[i]):
                 raise OperationError(space.w_ValueError, space.wrap(
                     "all the input arrays must have same number of dimensions"))
             elif i == _axis:
                 shape[i] += axis_size
+        dtype = interp_ufuncs.find_binop_result_dtype(space, dtype,
+                                                      arr.get_dtype())
+        if _axis < 0 or len(arr.get_shape()) <= _axis:
+            raise operationerrfmt(space.w_IndexError, "axis %d out of bounds [0, %d)", axis, len(shape))
+    if _axis < 0 or len(shape) <= _axis:
+        raise operationerrfmt(space.w_IndexError, "axis %d out of bounds [0, %d)", axis, len(shape))
     res = W_NDimArray.from_shape(shape, dtype, 'C')
     chunks = [Chunk(0, i, 1, i) for i in shape]
     axis_start = 0

File pypy/module/micronumpy/interp_numarray.py

View file
  • Ignore whitespace
     def getitem_array_int(self, space, w_index):
         prefix, res_shape, iter_shape, indexes = \
                 self._prepare_array_index(space, w_index)
+        if iter_shape is None:
+            # w_index is a list of slices, return a view
+            chunks = self.implementation._prepare_slice_args(space, w_index)
+            return chunks.apply(self)
         shape = res_shape + self.get_shape()[len(indexes):]
         res = W_NDimArray.from_shape(shape, self.get_dtype(), self.get_order())
         if not res.get_size():
         val_arr = convert_to_array(space, w_value)
         prefix, _, iter_shape, indexes = \
                 self._prepare_array_index(space, w_index)
-        return loop.setitem_array_int(space, self, iter_shape, indexes, val_arr,
-                                      prefix)
+        if iter_shape is None:
+            # w_index is a list of slices
+            w_value = convert_to_array(space, w_value)
+            chunks = self.implementation._prepare_slice_args(space, w_index)
+            view = chunks.apply(self)
+            view.implementation.setslice(space, w_value)
+            return
+        loop.setitem_array_int(space, self, iter_shape, indexes, val_arr,
+                               prefix)
 
     def descr_getitem(self, space, w_idx):
         if (isinstance(w_idx, W_NDimArray) and
 
     def descr_setitem(self, space, w_idx, w_value):
         if (isinstance(w_idx, W_NDimArray) and
-            w_idx.get_dtype().is_bool_type()):
-            return self.setitem_filter(space, w_idx,
-                                       convert_to_array(space, w_value))
+                w_idx.get_dtype().is_bool_type()):
+            self.setitem_filter(space, w_idx, convert_to_array(space, w_value))
+            return
         try:
             self.implementation.descr_setitem(space, self, w_idx, w_value)
         except ArrayArgumentException:

File pypy/module/micronumpy/test/test_numarray.py

View file
  • Ignore whitespace
         assert str(exc.value) == \
                 "all the input arrays must have same number of dimensions"
 
-        if 0: # XXX too pedantic
-            g1 = array([0,1,2])
-            g2 = array([[3,4,5]])
-            exc = raises(ValueError, concatenate, (g1, g2), axis=2)
-            assert str(exc.value) == \
-                    "all the input arrays must have same number of dimensions"
+        g1 = array([0,1,2])
+        g2 = array([[3,4,5]])
+        exc = raises(ValueError, concatenate, (g1, g2), axis=2)
+        assert str(exc.value) == \
+                "all the input arrays must have same number of dimensions"
 
         a = array([1, 2, 3, 4, 5, 6])
         a = (a + a)[::2]
         a[array([0, 2]), slice(0, 2)] = [[10, 11], [12, 13]]
         assert (a == [[10, 11], [3, 4], [12, 13]]).all()
 
+    def test_slice_vector_index(self):
+        from numpypy import arange
+        b = arange(145)
+        a = b[slice(25, 125, None)]
+        assert (a == range(25, 125)).all()
+        a = b[[slice(25, 125, None)]]
+        assert a.shape == (100,)
+        # a is a view into b
+        a[10] = 200
+        assert b[35] == 200
+        b[[slice(25, 30)]] = range(5)
+        assert all(a[:5] == range(5))
+        raises(TypeError, 'b[[[slice(25, 125)]]]')
+
     def test_cumsum(self):
         from numpypy import arange
         a = arange(6).reshape(3, 2)

File pypy/module/pypyjit/interp_jit.py

View file
  • Ignore whitespace
                             'lastblock',
                             'is_being_profiled',
                             'w_globals',
+                            'w_f_trace',
                             ]
 
 JUMP_ABSOLUTE = opmap['JUMP_ABSOLUTE']
 def set_jitcell_at(newcell, next_instr, is_being_profiled, bytecode):
     bytecode.jit_cells[next_instr, is_being_profiled] = newcell
 
-def confirm_enter_jit(next_instr, is_being_profiled, bytecode, frame, ec):
-    return (frame.w_f_trace is None and
-            ec.w_tracefunc is None)
 
 def can_never_inline(next_instr, is_being_profiled, bytecode):
     return False
 pypyjitdriver = PyPyJitDriver(get_printable_location = get_printable_location,
                               get_jitcell_at = get_jitcell_at,
                               set_jitcell_at = set_jitcell_at,
-                              confirm_enter_jit = confirm_enter_jit,
                               can_never_inline = can_never_inline,
                               should_unroll_one_iteration =
                               should_unroll_one_iteration,

File pypy/module/pypyjit/interp_resop.py

View file
  • Ignore whitespace
 from pypy.interpreter.gateway import unwrap_spec, interp2app
 from pypy.interpreter.pycode import PyCode
 from pypy.interpreter.error import OperationError
-from rpython.rtyper.lltypesystem import lltype, llmemory
+from rpython.rtyper.lltypesystem import lltype
 from rpython.rtyper.annlowlevel import cast_base_ptr_to_instance, hlstr
 from rpython.rtyper.lltypesystem.rclass import OBJECT
-from rpython.jit.metainterp.resoperation import rop, AbstractResOp
+from rpython.jit.metainterp.resoperation import rop
 from rpython.rlib.nonconst import NonConstant
 from rpython.rlib import jit_hooks
 from rpython.rlib.jit import Counters
-from rpython.rlib.rarithmetic import r_uint
+from rpython.rlib.objectmodel import compute_unique_id
 from pypy.module.pypyjit.interp_jit import pypyjitdriver
 
 class Cache(object):
         self.jd_name = debug_info.get_jitdriver().name
         self.type = debug_info.type
         if is_bridge:
-            self.bridge_no = debug_info.fail_descr_no
+            self.bridge_no = compute_unique_id(debug_info.fail_descr)
+            #self.bridge_no = debug_info.fail_descr_no
             self.w_green_key = space.w_None
         else:
             self.w_green_key = wrap_greenkey(space,

File pypy/module/pypyjit/policy.py

View file
  • Ignore whitespace
                        'posix', '_socket', '_sre', '_lsprof', '_weakref',
                        '__pypy__', 'cStringIO', '_collections', 'struct',
                        'mmap', 'marshal', '_codecs', 'rctime', 'cppyy',
-                       '_cffi_backend', 'pyexpat']:
+                       '_cffi_backend', 'pyexpat', '_continuation']:
             if modname == 'pypyjit' and 'interp_resop' in rest:
                 return False
             return True

File pypy/module/pypyjit/test/test_jit_hook.py

View file
  • Ignore whitespace
 import py
 from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.pycode import PyCode
-from rpython.jit.metainterp.history import JitCellToken, ConstInt, ConstPtr
+from rpython.jit.metainterp.history import JitCellToken, ConstInt, ConstPtr,\
+     BasicFailDescr
 from rpython.jit.metainterp.resoperation import rop
 from rpython.jit.metainterp.logger import Logger
 from rpython.rtyper.annlowlevel import (cast_instance_to_base_ptr,
                                         oplist, 'loop', greenkey)
         di_loop.asminfo = AsmInfo(offset, 0, 0)
         di_bridge = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(),
-                                 oplist, 'bridge', fail_descr_no=0)
+                                 oplist, 'bridge', fail_descr=BasicFailDescr())
         di_bridge.asminfo = AsmInfo(offset, 0, 0)
 
         def interp_on_compile():

File pypy/module/test_lib_pypy/test_marshal_extra.py

View file
  • Ignore whitespace
 def test_load_truncated_string():
     s = '(\x02\x00\x00\x00i\x03\x00\x00\x00sB\xf9\x00\x00\nabcd'
     py.test.raises(EOFError, marshal.loads, s)
+
+def test_dump_unicode_length():
+    s = b'123\xe9'.decode('latin-1')
+    r = marshal.dumps(s)
+    assert r == b'u\x05\x00\x00\x00123\xc3\xa9'

File pypy/module/test_lib_pypy/test_sqlite3.py

View file
  • Ignore whitespace
     cur = con.cursor()
     with pytest.raises(StopIteration):
         next(cur)
-    cur = con.execute('select 1')
+
+    cur.execute('select 1')
     next(cur)
     with pytest.raises(StopIteration):
         next(cur)
 
+    cur.execute('select 1')
+    con.commit()
+    next(cur)
+    with pytest.raises(StopIteration):
+        next(cur)
+
+    with pytest.raises(_sqlite3.ProgrammingError):
+        cur.executemany('select 1', [])
+    with pytest.raises(StopIteration):
+        next(cur)
+
+    cur.execute('select 1')
+    cur.execute('create table test(ing)')
+    with pytest.raises(StopIteration):
+        next(cur)
+
+    cur.execute('select 1')
+    cur.execute('insert into test values(1)')
+    con.commit()
+    with pytest.raises(StopIteration):
+        next(cur)
+
 def test_cursor_after_close():
      con = _sqlite3.connect(':memory:')
      cur = con.execute('select 1')
         con.commit()
     except _sqlite3.OperationalError:
         pytest.fail("_sqlite3 knew nothing about the implicit ROLLBACK")
+    con.close()
 
 def test_statement_arg_checking():
     con = _sqlite3.connect(':memory:')
     with pytest.raises(ValueError) as e:
         con.execute('insert into foo(x) values (?)', 2)
     assert str(e.value) == 'parameters are of unsupported type'
+    con.close()

File pypy/objspace/std/dictmultiobject.py

View file
  • Ignore whitespace
         for w_k, w_v in list_pairs_w:
             w_self.setitem(w_k, w_v)
 
-    def view_as_kwargs(self):
-        return self.strategy.view_as_kwargs(self)
-
 def _add_indirections():
     dict_methods = "setitem setitem_str getitem \
                     getitem_str delitem length \
                     clear w_keys values \
                     items iterkeys itervalues iteritems setdefault \
-                    popitem listview_str listview_unicode listview_int".split()
+                    popitem listview_str listview_unicode listview_int \
+                    view_as_kwargs".split()
 
     def make_method(method):
         def f(self, *args):
         f.func_name = method
         return f
 
-    def view_as_kwargs(self):
-        return self.strategy.view_as_kwargs(self)
-
     for method in dict_methods:
         setattr(W_DictMultiObject, method, make_method(method))
 
     def w_keys(self, w_dict):
         return self.space.newlist(self.unerase(w_dict.dstorage).keys())
 
+    def setitem_str(self, w_dict, s, w_value):
+        self.setitem(w_dict, self.space.wrap(s), w_value)
+
+    def switch_to_object_strategy(self, w_dict):
+        assert 0, "should be unreachable"
+
 create_iterator_classes(ObjectDictStrategy)
 
 class StringDictStrategy(AbstractTypedStrategy, DictStrategy):

File pypy/tool/jitlogparser/parser.py

View file
  • Ignore whitespace
         self.descr = descr
         self._is_guard = name.startswith('guard_')
         if self._is_guard:
-            self.guard_no = int(self.descr[len('<Guard'):-1])
+            self.guard_no = int(self.descr[len('<Guard'):-1], 16)
 
     def setfailargs(self, failargs):
         self.failargs = failargs
     i = 0
     while i < len(ops):
         op = ops[i]
-        if op.is_guard() and bridges.get('loop-' + str(op.guard_no), None):
+        if op.is_guard() and bridges.get('loop-' + hex(op.guard_no)[2:], None):
             res.append(op)
             i = 0
             if hasattr(op.bridge, 'force_asm'):
             m = re.search('has address ([-\da-f]+)', entry)
             addr = int(m.group(1), 16)
             entry = entry.lower()
-            m = re.search('guard \d+', entry)
+            m = re.search('guard [\da-f]+', entry)
             name = m.group(0)
         else:
             name = entry[:entry.find('(') - 1].lower()
         comm = loop.comment
         comm = comm.lower()
         if comm.startswith('# bridge'):
-            m = re.search('guard \d+', comm)
-            name = m.group(0)
+            m = re.search('guard (\d+)', comm)
+            name = 'guard ' + hex(int(m.group(1)))[2:]
         elif "(" in comm:
             name = comm[2:comm.find('(')-1]
         else:
 def split_trace(trace):
     labels = [0]
     if trace.comment and 'Guard' in trace.comment:
-        descrs = ['bridge ' + re.search('Guard (\d+)', trace.comment).group(1)]
+        descrs = ['bridge ' + re.search('Guard ([\da-f]+)', trace.comment).group(1)]
     else:
         descrs = ['entry ' + re.search('Loop (\d+)', trace.comment).group(1)]
     for i, op in enumerate(trace.operations):
         if line:
             num, count = line.split(':', 2)
             mapping[num].count = int(count)
+
+if __name__ == '__main__':
+    import_log(sys.argv[1])
+    

File pypy/tool/jitlogparser/storage.py

View file
  • Ignore whitespace
         for loop_no, loop in enumerate(loops):
             for op in loop.operations:
                 if op.name.startswith('guard_'):
-                    guard_dict[int(op.descr[len('<Guard'):-1])] = (op, loop)
+                    guard_dict[int(op.descr[len('<Guard'):-1], 16)] = (op, loop)
         for loop in loops:
             if loop.comment:
                 comment = loop.comment.strip()
                 if 'entry bridge' in comment:
                     pass
                 elif comment.startswith('# bridge out of'):
-                    no = int(comment[len('# bridge out of Guard '):].split(' ', 1)[0])
+                    no = int(comment[len('# bridge out of Guard '):].split(' ', 1)[0], 16)
                     op, parent = guard_dict[no]
                     op.bridge = loop
                     op.percentage = ((getattr(loop, 'count', 1) * 100) /

File pypy/tool/jitlogparser/test/test_parser.py

View file
  • Ignore whitespace
     loops = LoopStorage().reconnect_loops([main, bridge, entry_bridge])
     assert len(loops) == 2
     assert len(loops[0].operations[0].bridge.operations) == 1
-    assert loops[0].operations[0].bridge.no == 18
+    assert loops[0].operations[0].bridge.no == 0x18
     assert loops[0].operations[0].percentage == 30
 
 def test_adjust_bridges():
     main = parse('''
     [v0]
-    guard_false(v0, descr=<Guard13>)
+    guard_false(v0, descr=<Guard1a>)
     guard_true(v0, descr=<Guard5>)
     ''')
     bridge = parse('''
-    # bridge out of Guard 13
+    # bridge out of Guard 1a
     []
     int_add(0, 1)
     ''')
     LoopStorage().reconnect_loops([main, bridge])
     assert adjust_bridges(main, {})[1].name == 'guard_true'
-    assert adjust_bridges(main, {'loop-13': True})[1].name == 'int_add'
+    assert adjust_bridges(main, {'loop-1a': True})[1].name == 'int_add'
 
 def test_parsing_strliteral():
     loop = parse("""
 +348: i32 = int_is_true(i31)
 +360: i33 = int_or(i27, i32)
 +364: i34 = int_is_true(i33)
-guard_false(i34, descr=<Guard89>) [i1, i22, p2]
+guard_false(i34, descr=<Guard8a>) [i1, i22, p2]
 +372: i35 = int_add(i22, 1)
 debug_merge_point(0, 're StrMatchIn at 92 [17. 4. 0. 20. 393237. 21. 0. 29. 9. 1. 65535. 15. 4. 9. 3. 0. 1. 21. 1. 29. 9. 1. 65535. 15. 4. 9. 2. 0. 1. 1...')
 +376: jump(i35, i1, p2, p4, descr=TargetToken(1081858656))
     [i7]
     i9 = int_lt(i7, 1003)
     label(i9, descr=grrr)
-    guard_true(i9, descr=<Guard2>) []
+    guard_true(i9, descr=<Guardaf>) []
     i13 = getfield_raw(151937600, descr=<SignedFieldDescr pypysig_long_struct.c_value 0>)
     label(i13, descr=asb)
     i19 = int_lt(i13, 1003)
     i0 = int_lt(1, 2)
     finish(i0)
     ''')
-    bridge.comment = 'bridge out of Guard 2 with 1 ops'
+    bridge.comment = 'bridge out of Guard af with 1 ops'
     loop.comment = 'Loop 0'
     loops = split_trace(loop) + split_trace(bridge)
-    input = ['grrr:123\nasb:12\nbridge 2:1234']
+    input = ['grrr:123\nasb:12\nbridge af:1234']
     parse_log_counts(input, loops)
     assert loops[-1].count == 1234
     assert loops[1].count == 123

File rpython/annotator/binaryop.py

View file
  • Ignore whitespace
         # XXX HACK HACK HACK
         bk = getbookkeeper()
         if bk is not None: # for testing
+            op = bk._find_current_op("is_", 2)
             knowntypedata = {}
-            fn, block, i = bk.position_key
-
             annotator = bk.annotator
-            op = block.operations[i]
-            assert op.opname == "is_" 
-            assert len(op.args) == 2                
 
             def bind(src_obj, tgt_obj, tgt_arg):
                 if hasattr(tgt_obj, 'is_type_of') and src_obj.is_constant():
                 rarithmetic.signedtype(int2.knowntype)):
             return r
         knowntypedata = {}
-        # XXX HACK HACK HACK
-        fn, block, i = getbookkeeper().position_key
-        op = block.operations[i]
-        assert op.opname == opname
-        assert len(op.args) == 2
+        op = getbookkeeper()._find_current_op(opname=opname, arity=2)
         def tointtype(int0):
             if int0.knowntype is bool:
                 return int

File rpython/annotator/bookkeeper.py

View file
  • Ignore whitespace
             if emulate_enter:
                 self.leave()
 
+    def _find_current_op(self, opname=None, arity=None, pos=None, s_type=None):
+        """ Find operation that is currently being annotated. Do some
+        sanity checks to see whether the correct op was found."""
+        # XXX XXX HACK HACK HACK
+        fn, block, i = self.position_key
+        op = block.operations[i]
+        if opname is not None:
+            assert op.opname == opname or op.opname in opname
+        if arity is not None:
+            assert len(op.args) == arity
+        if pos is not None:
+            assert self.annotator.binding(op.args[pos]) == s_type
+        return op
+
     def build_args(self, op, args_s):
         space = RPythonCallsSpace()
         if op == "simple_call":

File rpython/annotator/builtin.py

View file
  • Ignore whitespace
                                                    # from bool to int, notice that isinstance( , bool|int)
                                                    # is quite border case for RPython
                 r.const = False
-        # XXX HACK HACK HACK
-        # XXX HACK HACK HACK
-        # XXX HACK HACK HACK
         bk = getbookkeeper()
         if variables is None:
-            fn, block, i = bk.position_key
-            op = block.operations[i]
-            assert op.opname == "simple_call" 
-            assert len(op.args) == 3
+            op = bk._find_current_op("simple_call", 3)
             assert op.args[0] == Constant(isinstance)
             variables = [op.args[1]]
         for variable in variables:

File rpython/annotator/description.py

View file
  • Ignore whitespace
             result = schedule(graph, inputcells)
             signature = getattr(self.pyobj, '_signature_', None)
             if signature:
-                result = enforce_signature_return(self, signature[1], result)
-                self.bookkeeper.annotator.addpendingblock(graph, graph.returnblock, [result])
+                sigresult = enforce_signature_return(self, signature[1], result)
+                if sigresult is not None:
+                    self.bookkeeper.annotator.addpendingblock(graph, graph.returnblock, [sigresult])
+                    result = sigresult
         # Some specializations may break the invariant of returning
         # annotations that are always more general than the previous time.
         # We restore it here:

File rpython/annotator/model.py

View file
  • Ignore whitespace
     def nonnoneify(self):
         return self.__class__(can_be_None=False, no_nul=self.no_nul)
 
+    def nonnulify(self):
+        return self.__class__(can_be_None=self.can_be_None, no_nul=True)
+
 class SomeString(SomeStringOrUnicode):
     "Stands for an object which is known to be a string."
     knowntype = str

File rpython/annotator/signature.py

View file
  • Ignore whitespace
         inputcells[:] = args_s
 
 def finish_type(paramtype, bookkeeper, func):
-    from rpython.rlib.types import SelfTypeMarker
+    from rpython.rlib.types import SelfTypeMarker, AnyTypeMarker
     if isinstance(paramtype, SomeObject):
         return paramtype
     elif isinstance(paramtype, SelfTypeMarker):
         raise Exception("%r argument declared as annotation.types.self(); class needs decorator rlib.signature.finishsigs()" % (func,))
+    elif isinstance(paramtype, AnyTypeMarker):
+        return None
     else:
         return paramtype(bookkeeper)
 
     assert len(paramtypes) == len(actualtypes)
     params_s = [finish_type(paramtype, funcdesc.bookkeeper, funcdesc.pyobj) for paramtype in paramtypes]
     for i, (s_param, s_actual) in enumerate(zip(params_s, actualtypes)):
+        if s_param is None: # can be anything
+            continue
         if not s_param.contains(s_actual):
             raise Exception("%r argument %d:\n"
                             "expected %s,\n"
                             "     got %s" % (funcdesc, i+1, s_param, s_actual))
-    actualtypes[:] = params_s
+    for i, s_param in enumerate(params_s):
+        if s_param is None:
+            continue
+        actualtypes[i] = s_param
 
 def enforce_signature_return(funcdesc, sigtype, inferredtype):
     s_sigret = finish_type(sigtype, funcdesc.bookkeeper, funcdesc.pyobj)
-    if not s_sigret.contains(inferredtype):
+    if s_sigret is not None and not s_sigret.contains(inferredtype):
         raise Exception("%r return value:\n"
                         "expected %s,\n"
                         "     got %s" % (funcdesc, s_sigret, inferredtype))

File rpython/annotator/test/test_annrpython.py

View file
  • Ignore whitespace
         s_item = s.listdef.listitem.s_value
         assert s_item.no_nul
 
+    def test_str_split_nul(self):
+        def f(n):
+            return n.split('\0')[0]
+        a = self.RPythonAnnotator()
+        a.translator.config.translation.check_str_without_nul = True
+        s = a.build_types(f, [annmodel.SomeString(no_nul=False, can_be_None=False)])
+        assert isinstance(s, annmodel.SomeString)
+        assert not s.can_be_None
+        assert s.no_nul
+
+        def g(n):
+            return n.split('\0', 1)[0]
+        a = self.RPythonAnnotator()
+        a.translator.config.translation.check_str_without_nul = True
+        s = a.build_types(g, [annmodel.SomeString(no_nul=False, can_be_None=False)])
+        assert isinstance(s, annmodel.SomeString)
+        assert not s.can_be_None
+        assert not s.no_nul
+
     def test_str_splitlines(self):
         a = self.RPythonAnnotator()
         def f(a_str):
         assert isinstance(s, annmodel.SomeString)
         assert not s.can_be_None
 
+    def test_contains_no_nul(self):
+        def f(i):
+            if "\0" in i:
+                return None
+            else:
+                return i
+        a = self.RPythonAnnotator()
+        a.translator.config.translation.check_str_without_nul = True
+        s = a.build_types(f, [annmodel.SomeString(no_nul=False)])
+        assert isinstance(s, annmodel.SomeString)
+        assert s.can_be_None
+        assert s.no_nul
+
     def test_no___call__(self):
         class X(object):
             def __call__(self):

File rpython/annotator/unaryop.py

View file
  • Ignore whitespace
             raise Exception, 'type() called with more than one argument'
         r = SomeType()
         bk = getbookkeeper()
-        fn, block, i = bk.position_key
-        annotator = bk.annotator
-        op = block.operations[i]
-        assert op.opname == "type"
-        assert len(op.args) == 1
-        assert annotator.binding(op.args[0]) == obj
+        op = bk._find_current_op(opname="type", arity=1, pos=0, s_type=obj)
         r.is_type_of = [op.args[0]]
         return r
 
 
         bk = getbookkeeper()
         knowntypedata = {}
-        fn, block, i = bk.position_key
-        op = block.operations[i]
-        assert op.opname == "is_true" or op.opname == "nonzero"
-        assert len(op.args) == 1
+        op = bk._find_current_op(opname=("is_true", "nonzero"), arity=1)
         arg = op.args[0]
         s_nonnone_obj = s_obj
         if s_obj.can_be_none():
 
     def method_split(str, patt, max=-1):
         getbookkeeper().count("str_split", str, patt)
-        s_item = str.basestringclass(no_nul=str.no_nul)
+        if max == -1 and patt.is_constant() and patt.const == "\0":
+            no_nul = True
+        else:
+            no_nul = str.no_nul
+        s_item = str.basestringclass(no_nul=no_nul)
         return getbookkeeper().newlist(s_item)
 
     def method_rsplit(str, patt, max=-1):
         result = str.basestringclass(no_nul=str.no_nul)
         return result
 
+    def op_contains(str, s_element):
+        if s_element.is_constant() and s_element.const == "\0":
+            r = SomeBool()
+            bk = getbookkeeper()
+            op = bk._find_current_op(opname="contains", arity=2, pos=0, s_type=str)
+            knowntypedata = {}
+            add_knowntypedata(knowntypedata, False, [op.args[0]], str.nonnulify())
+            r.set_knowntypedata(knowntypedata)
+            return r
+        else:
+            return SomeObject.op_contains(str, s_element)
+    op_contains.can_only_throw = []
+
+
 class __extend__(SomeUnicodeString):
     def method_encode(uni, s_enc):
         if not s_enc.is_constant():

File rpython/jit/backend/arm/arch.py

View file
  • Ignore whitespace
-from rpython.rtyper.lltypesystem import lltype, rffi
-from rpython.rlib.rarithmetic import r_uint
-
-
 FUNC_ALIGN = 8
 WORD = 4
 DOUBLE_WORD = 8
 PC_OFFSET = 8
 FORCE_INDEX_OFS = 0
 
-from rpython.translator.tool.cbuild import ExternalCompilationInfo
-eci = ExternalCompilationInfo(post_include_bits=["""
-static int pypy__arm_int_div(int a, int b) {
-    return a/b;
-}
-static unsigned int pypy__arm_uint_div(unsigned int a, unsigned int b) {
-    return a/b;
-}
-static int pypy__arm_int_mod(int a, int b) {
-    return a % b;
-}
-"""])
-
-
-def arm_int_div_emulator(a, b):
-    return int(a / float(b))
-arm_int_div_sign = lltype.Ptr(
-        lltype.FuncType([lltype.Signed, lltype.Signed], lltype.Signed))
-arm_int_div = rffi.llexternal(
-    "pypy__arm_int_div", [lltype.Signed, lltype.Signed], lltype.Signed,
-                        _callable=arm_int_div_emulator,
-                        compilation_info=eci,
-                        _nowrapper=True, elidable_function=True)
-
-
-def arm_uint_div_emulator(a, b):
-    return r_uint(a) / r_uint(b)
-arm_uint_div_sign = lltype.Ptr(
-        lltype.FuncType([lltype.Unsigned, lltype.Unsigned], lltype.Unsigned))
-arm_uint_div = rffi.llexternal(
-    "pypy__arm_uint_div", [lltype.Unsigned, lltype.Unsigned], lltype.Unsigned,
-                        _callable=arm_uint_div_emulator,
-                        compilation_info=eci,
-                        _nowrapper=True, elidable_function=True)
-
-
-def arm_int_mod_emulator(a, b):
-    sign = 1
-    if a < 0:
-        a = -1 * a
-        sign = -1
-    if b < 0:
-        b = -1 * b
-    res = a % b
-    return sign * res
-arm_int_mod_sign = arm_int_div_sign
-arm_int_mod = rffi.llexternal(
-    "pypy__arm_int_mod", [lltype.Signed, lltype.Signed], lltype.Signed,
-                        _callable=arm_int_mod_emulator,
-                        compilation_info=eci,
-                        _nowrapper=True, elidable_function=True)
+# The stack contains the force_index and the, callee saved registers and
+# ABI required information
+# All the rest of the data is in a GC-managed variable-size "frame".
+# This jitframe object's address is always stored in the register FP
+# A jitframe is a jit.backend.llsupport.llmodel.jitframe.JITFRAME
+# Stack frame fixed area
+# Currently only the force_index
+JITFRAME_FIXED_SIZE = 11 + 16 * 2 + 1
+# 11 GPR + 16 VFP Regs (64bit) + 1 word for alignment

File rpython/jit/backend/arm/assembler.py

View file
  • Ignore whitespace
 from __future__ import with_statement
+
 import os
+