[pypy-commit] pypy remove-intlong-smm: merge default
pjenvey
noreply at buildbot.pypy.org
Mon Feb 3 05:19:39 CET 2014
Author: Philip Jenvey <pjenvey at underboss.org>
Branch: remove-intlong-smm
Changeset: r69048:0e80c730535a
Date: 2014-02-02 14:51 -0800
http://bitbucket.org/pypy/pypy/changeset/0e80c730535a/
Log: merge default
diff too long, truncating to 2000 out of 23372 lines
diff --git a/lib-python/2.7/test/test_memoryview.py b/lib-python/2.7/test/test_memoryview.py
--- a/lib-python/2.7/test/test_memoryview.py
+++ b/lib-python/2.7/test/test_memoryview.py
@@ -166,11 +166,18 @@
self.assertTrue(m[0:6] == m[:])
self.assertFalse(m[0:5] == m)
- # Comparison with objects which don't support the buffer API
- self.assertFalse(m == u"abcdef")
- self.assertTrue(m != u"abcdef")
- self.assertFalse(u"abcdef" == m)
- self.assertTrue(u"abcdef" != m)
+ if test_support.check_impl_detail(cpython=True):
+ # what is supported and what is not supported by memoryview is
+ # very inconsisten on CPython. In PyPy, memoryview supports
+ # the buffer interface, and thus the following comparison
+ # succeeds. See also the comment in
+ # pypy.modules.__builtin__.interp_memoryview.W_MemoryView.descr_buffer
+ #
+ # Comparison with objects which don't support the buffer API
+ self.assertFalse(m == u"abcdef", "%s %s" % (self, tp))
+ self.assertTrue(m != u"abcdef")
+ self.assertFalse(u"abcdef" == m)
+ self.assertTrue(u"abcdef" != m)
# Unordered comparisons are unimplemented, and therefore give
# arbitrary results (they raise a TypeError in py3k)
diff --git a/lib-python/2.7/test/test_ssl.py b/lib-python/2.7/test/test_ssl.py
--- a/lib-python/2.7/test/test_ssl.py
+++ b/lib-python/2.7/test/test_ssl.py
@@ -993,7 +993,7 @@
try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv2, True)
try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv2, True, ssl.CERT_OPTIONAL)
try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv2, True, ssl.CERT_REQUIRED)
- try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv23, True)
+ try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv23, False)
try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv3, False)
try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_TLSv1, False)
diff --git a/lib-python/conftest.py b/lib-python/conftest.py
--- a/lib-python/conftest.py
+++ b/lib-python/conftest.py
@@ -109,7 +109,7 @@
RegrTest('test_asynchat.py', usemodules='select fcntl'),
RegrTest('test_asyncore.py', usemodules='select fcntl'),
RegrTest('test_atexit.py', core=True),
- RegrTest('test_audioop.py', skip="unsupported extension module"),
+ RegrTest('test_audioop.py', skip="incomplete module"),
RegrTest('test_augassign.py', core=True),
RegrTest('test_base64.py', usemodules='struct'),
RegrTest('test_bastion.py'),
diff --git a/lib_pypy/_ctypes/array.py b/lib_pypy/_ctypes/array.py
--- a/lib_pypy/_ctypes/array.py
+++ b/lib_pypy/_ctypes/array.py
@@ -1,4 +1,4 @@
-import _ffi
+from _rawffi import alt as _ffi
import _rawffi
from _ctypes.basics import _CData, cdata_from_address, _CDataMeta, sizeof
@@ -20,10 +20,13 @@
# we don't want to have buffers here
if len(val) > self._length_:
raise ValueError("%r too long" % (val,))
- for i in range(len(val)):
- self[i] = val[i]
+ if isinstance(val, str):
+ _rawffi.rawstring2charp(self._buffer.buffer, val)
+ else:
+ for i in range(len(val)):
+ self[i] = val[i]
if len(val) < self._length_:
- self[len(val)] = '\x00'
+ self._buffer[len(val)] = '\x00'
res.value = property(getvalue, setvalue)
def getraw(self):
@@ -33,8 +36,7 @@
def setraw(self, buffer):
if len(buffer) > self._length_:
raise ValueError("%r too long" % (buffer,))
- for i in range(len(buffer)):
- self[i] = buffer[i]
+ _rawffi.rawstring2charp(self._buffer.buffer, buffer)
res.raw = property(getraw, setraw)
elif subletter == 'u':
def getvalue(self):
@@ -45,10 +47,14 @@
# we don't want to have buffers here
if len(val) > self._length_:
raise ValueError("%r too long" % (val,))
+ if isinstance(val, unicode):
+ target = self._buffer
+ else:
+ target = self
for i in range(len(val)):
- self[i] = val[i]
+ target[i] = val[i]
if len(val) < self._length_:
- self[len(val)] = '\x00'
+ target[len(val)] = u'\x00'
res.value = property(getvalue, setvalue)
if '_length_' in typedict:
diff --git a/lib_pypy/_ctypes/basics.py b/lib_pypy/_ctypes/basics.py
--- a/lib_pypy/_ctypes/basics.py
+++ b/lib_pypy/_ctypes/basics.py
@@ -1,6 +1,6 @@
import _rawffi
-import _ffi
+from _rawffi import alt as _ffi
import sys
try: from __pypy__ import builtinify
diff --git a/lib_pypy/_ctypes/function.py b/lib_pypy/_ctypes/function.py
--- a/lib_pypy/_ctypes/function.py
+++ b/lib_pypy/_ctypes/function.py
@@ -5,7 +5,7 @@
from _ctypes.basics import is_struct_shape
from _ctypes.builtin import get_errno, set_errno, get_last_error, set_last_error
import _rawffi
-import _ffi
+from _rawffi import alt as _ffi
import sys
import traceback
diff --git a/lib_pypy/_ctypes/pointer.py b/lib_pypy/_ctypes/pointer.py
--- a/lib_pypy/_ctypes/pointer.py
+++ b/lib_pypy/_ctypes/pointer.py
@@ -1,6 +1,6 @@
import _rawffi
-import _ffi
+from _rawffi import alt as _ffi
from _ctypes.basics import _CData, _CDataMeta, cdata_from_address, ArgumentError
from _ctypes.basics import keepalive_key, store_reference, ensure_objects
from _ctypes.basics import sizeof, byref, as_ffi_pointer
diff --git a/lib_pypy/_ctypes/primitive.py b/lib_pypy/_ctypes/primitive.py
--- a/lib_pypy/_ctypes/primitive.py
+++ b/lib_pypy/_ctypes/primitive.py
@@ -1,4 +1,4 @@
-import _ffi
+from _rawffi import alt as _ffi
import _rawffi
import weakref
import sys
diff --git a/lib_pypy/_ctypes/structure.py b/lib_pypy/_ctypes/structure.py
--- a/lib_pypy/_ctypes/structure.py
+++ b/lib_pypy/_ctypes/structure.py
@@ -2,6 +2,8 @@
import _rawffi
from _ctypes.basics import _CData, _CDataMeta, keepalive_key,\
store_reference, ensure_objects, CArgObject
+from _ctypes.array import Array
+from _ctypes.pointer import _Pointer
import inspect
def names_and_fields(self, _fields_, superclass, anonymous_fields=None):
@@ -104,8 +106,11 @@
def __set__(self, obj, value):
fieldtype = self.ctype
cobj = fieldtype.from_param(value)
- if ensure_objects(cobj) is not None:
- key = keepalive_key(self.num)
+ key = keepalive_key(self.num)
+ if issubclass(fieldtype, _Pointer) and isinstance(cobj, Array):
+ # if our value is an Array we need the whole thing alive
+ store_reference(obj, key, cobj)
+ elif ensure_objects(cobj) is not None:
store_reference(obj, key, cobj._objects)
arg = cobj._get_buffer_value()
if fieldtype._fficompositesize is not None:
diff --git a/lib_pypy/_ffi.py b/lib_pypy/_ffi.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/_ffi.py
@@ -0,0 +1,2 @@
+# Backward compatibility hack
+from _rawffi.alt import *
diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -330,6 +330,14 @@
# SQLite version information
sqlite_version = str(_ffi.string(_lib.sqlite3_libversion()).decode('ascii'))
+_STMT_TYPE_UPDATE = 0
+_STMT_TYPE_DELETE = 1
+_STMT_TYPE_INSERT = 2
+_STMT_TYPE_REPLACE = 3
+_STMT_TYPE_OTHER = 4
+_STMT_TYPE_SELECT = 5
+_STMT_TYPE_INVALID = 6
+
class Error(StandardError):
pass
@@ -992,13 +1000,18 @@
self.__statement = self.__connection._statement_cache.get(sql)
if self.__connection._isolation_level is not None:
- if self.__statement._type in ("UPDATE", "DELETE", "INSERT", "REPLACE"):
+ if self.__statement._type in (
+ _STMT_TYPE_UPDATE,
+ _STMT_TYPE_DELETE,
+ _STMT_TYPE_INSERT,
+ _STMT_TYPE_REPLACE
+ ):
if not self.__connection._in_transaction:
self.__connection._begin()
- elif self.__statement._type == "OTHER":
+ elif self.__statement._type == _STMT_TYPE_OTHER:
if self.__connection._in_transaction:
self.__connection.commit()
- elif self.__statement._type == "SELECT":
+ elif self.__statement._type == _STMT_TYPE_SELECT:
if multiple:
raise ProgrammingError("You cannot execute SELECT "
"statements in executemany().")
@@ -1021,12 +1034,17 @@
self.__statement._reset()
raise self.__connection._get_exception(ret)
- if self.__statement._type in ("UPDATE", "DELETE", "INSERT", "REPLACE"):
+ if self.__statement._type in (
+ _STMT_TYPE_UPDATE,
+ _STMT_TYPE_DELETE,
+ _STMT_TYPE_INSERT,
+ _STMT_TYPE_REPLACE
+ ):
if self.__rowcount == -1:
self.__rowcount = 0
self.__rowcount += _lib.sqlite3_changes(self.__connection._db)
- if not multiple and self.__statement._type == "INSERT":
+ if not multiple and self.__statement._type == _STMT_TYPE_INSERT:
self.__lastrowid = _lib.sqlite3_last_insert_rowid(self.__connection._db)
else:
self.__lastrowid = None
@@ -1176,11 +1194,19 @@
first_word = sql.lstrip().split(" ")[0].upper()
if first_word == "":
- self._type = "INVALID"
- elif first_word in ("SELECT", "INSERT", "UPDATE", "DELETE", "REPLACE"):
- self._type = first_word
+ self._type = _STMT_TYPE_INVALID
+ elif first_word == "SELECT":
+ self._type = _STMT_TYPE_SELECT
+ elif first_word == "INSERT":
+ self._type = _STMT_TYPE_INSERT
+ elif first_word == "UPDATE":
+ self._type = _STMT_TYPE_UPDATE
+ elif first_word == "DELETE":
+ self._type = _STMT_TYPE_DELETE
+ elif first_word == "REPLACE":
+ self._type = _STMT_TYPE_REPLACE
else:
- self._type = "OTHER"
+ self._type = _STMT_TYPE_OTHER
if isinstance(sql, unicode):
sql = sql.encode('utf-8')
@@ -1193,7 +1219,7 @@
if ret == _lib.SQLITE_OK and not self._statement:
# an empty statement, work around that, as it's the least trouble
- self._type = "SELECT"
+ self._type = _STMT_TYPE_SELECT
c_sql = _ffi.new("char[]", b"select 42")
ret = _lib.sqlite3_prepare_v2(self.__con._db, c_sql, -1,
statement_star, next_char)
@@ -1312,7 +1338,12 @@
raise ValueError("parameters are of unsupported type")
def _get_description(self):
- if self._type in ("INSERT", "UPDATE", "DELETE", "REPLACE"):
+ if self._type in (
+ _STMT_TYPE_INSERT,
+ _STMT_TYPE_UPDATE,
+ _STMT_TYPE_DELETE,
+ _STMT_TYPE_REPLACE
+ ):
return None
desc = []
for i in xrange(_lib.sqlite3_column_count(self._statement)):
diff --git a/lib_pypy/audioop.py b/lib_pypy/audioop.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/audioop.py
@@ -0,0 +1,29 @@
+
+import struct
+
+
+class error(Exception):
+ pass
+
+
+def _check_size(size):
+ if size != 1 and size != 2 and size != 4:
+ raise error("Size should be 1, 2 or 4")
+
+
+def _check_params(length, size):
+ _check_size(size)
+ if length % size != 0:
+ raise error("not a whole number of frames")
+
+
+def getsample(cp, size, i):
+ _check_params(len(cp), size)
+ if not (0 <= i < len(cp) / size):
+ raise error("Index out of range")
+ if size == 1:
+ return struct.unpack_from("B", buffer(cp)[i:])[0]
+ elif size == 2:
+ return struct.unpack_from("H", buffer(cp)[i * 2:])[0]
+ elif size == 4:
+ return struct.unpack_from("I", buffer(cp)[i * 4:])[0]
diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -34,14 +34,14 @@
"struct", "_hashlib", "_md5", "_sha", "_minimal_curses", "cStringIO",
"thread", "itertools", "pyexpat", "_ssl", "cpyext", "array",
"binascii", "_multiprocessing", '_warnings',
- "_collections", "_multibytecodec", "micronumpy", "_ffi",
+ "_collections", "_multibytecodec", "micronumpy",
"_continuation", "_cffi_backend", "_csv", "cppyy", "_pypyjson"]
))
translation_modules = default_modules.copy()
translation_modules.update(dict.fromkeys(
["fcntl", "rctime", "select", "signal", "_rawffi", "zlib",
- "struct", "_md5", "cStringIO", "array", "_ffi",
+ "struct", "_md5", "cStringIO", "array",
"binascii",
# the following are needed for pyrepl (and hence for the
# interactive prompt/pdb)
@@ -96,7 +96,6 @@
# no _rawffi if importing rpython.rlib.clibffi raises ImportError
# or CompilationError or py.test.skip.Exception
"_rawffi" : ["rpython.rlib.clibffi"],
- "_ffi" : ["rpython.rlib.clibffi"],
"zlib" : ["rpython.rlib.rzlib"],
"bz2" : ["pypy.module.bz2.interp_bz2"],
diff --git a/pypy/doc/_ref.txt b/pypy/doc/_ref.txt
--- a/pypy/doc/_ref.txt
+++ b/pypy/doc/_ref.txt
@@ -109,6 +109,4 @@
.. _`rpython/translator/c/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/
.. _`rpython/translator/c/src/stacklet/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/src/stacklet/
.. _`rpython/translator/c/src/stacklet/stacklet.h`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/c/src/stacklet/stacklet.h
-.. _`rpython/translator/cli/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/cli/
-.. _`rpython/translator/jvm/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/jvm/
.. _`rpython/translator/tool/`: https://bitbucket.org/pypy/pypy/src/default/rpython/translator/tool/
diff --git a/pypy/doc/config/translation.lldebug0.txt b/pypy/doc/config/translation.lldebug0.txt
new file mode 100644
--- /dev/null
+++ b/pypy/doc/config/translation.lldebug0.txt
@@ -0,0 +1,1 @@
+Like lldebug, but in addition compile C files with -O0
diff --git a/pypy/doc/faq.rst b/pypy/doc/faq.rst
--- a/pypy/doc/faq.rst
+++ b/pypy/doc/faq.rst
@@ -426,25 +426,12 @@
Could we use LLVM?
------------------
-In theory yes. But we tried to use it 5 or 6 times already, as a
-translation backend or as a JIT backend --- and failed each time.
+There is a (static) translation backend using LLVM in the branch
+``llvm-translation-backend``. It can translate PyPy with or without the JIT on
+Linux.
-In more details: using LLVM as a (static) translation backend is
-pointless nowadays because you can generate C code and compile it with
-clang. (Note that compiling PyPy with clang gives a result that is not
-faster than compiling it with gcc.) We might in theory get extra
-benefits from LLVM's GC integration, but this requires more work on the
-LLVM side before it would be remotely useful. Anyway, it could be
-interfaced via a custom primitive in the C code.
-
-On the other hand, using LLVM as our JIT backend looks interesting as
-well --- but again we made an attempt, and it failed: LLVM has no way to
-patch the generated machine code.
-
-So the position of the core PyPy developers is that if anyone wants to
-make an N+1'th attempt with LLVM, they are welcome, and will be happy to
-provide help in the IRC channel, but they are left with the burden of proof
-that (a) it works and (b) it gives important benefits.
+Using LLVM as our JIT backend looks interesting as well -- we made an attempt,
+but it failed: LLVM has no way to patch the generated machine code.
----------------------
How do I compile PyPy?
diff --git a/pypy/doc/garbage_collection.rst b/pypy/doc/garbage_collection.rst
--- a/pypy/doc/garbage_collection.rst
+++ b/pypy/doc/garbage_collection.rst
@@ -210,4 +210,12 @@
are preserved. If the object dies then the pre-reserved location
becomes free garbage, to be collected at the next major collection.
+The exact name of this GC is either `minimark` or `incminimark`. The
+latter is a version that does major collections incrementally (i.e. one
+major collection is split along some number of minor collections, rather
+than being done all at once after a specific minor collection). The
+default is `incminimark`, as it seems to have a very minimal impact on
+performance and memory usage at the benefit of avoiding the long pauses
+of `minimark`.
+
.. include:: _ref.txt
diff --git a/pypy/doc/gc_info.rst b/pypy/doc/gc_info.rst
--- a/pypy/doc/gc_info.rst
+++ b/pypy/doc/gc_info.rst
@@ -6,7 +6,7 @@
Minimark
--------
-PyPy's default ``minimark`` garbage collector is configurable through
+PyPy's default ``incminimark`` garbage collector is configurable through
several environment variables:
``PYPY_GC_NURSERY``
@@ -14,6 +14,17 @@
Defaults to 1/2 of your cache or ``4M``.
Small values (like 1 or 1KB) are useful for debugging.
+``PYPY_GC_NURSERY_CLEANUP``
+ The interval at which nursery is cleaned up. Must
+ be smaller than the nursery size and bigger than the
+ biggest object we can allotate in the nursery.
+
+``PYPY_GC_INCREMENT_STEP``
+ The size of memory marked during the marking step. Default is size of
+ nursery times 2. If you mark it too high your GC is not incremental at
+ all. The minimum is set to size that survives minor collection times
+ 1.5 so we reclaim anything all the time.
+
``PYPY_GC_MAJOR_COLLECT``
Major collection memory factor.
Default is ``1.82``, which means trigger a major collection when the
diff --git a/pypy/doc/project-ideas.rst b/pypy/doc/project-ideas.rst
--- a/pypy/doc/project-ideas.rst
+++ b/pypy/doc/project-ideas.rst
@@ -74,6 +74,10 @@
The actual details would be rather differen in PyPy, but we would like to have
the same optimization implemented.
+Or maybe not. We can also play around with the idea of using a single
+representation: as a byte string in utf-8. (This idea needs some extra logic
+for efficient indexing, like a cache.)
+
.. _`optimized unicode representation`: http://www.python.org/dev/peps/pep-0393/
Translation Toolchain
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -41,3 +41,19 @@
Fix 3 broken links on PyPy published papers in docs.
.. branch: jit-ordereddict
+
+.. branch: refactor-str-types
+Remove multimethods on str/unicode/bytearray and make the implementations share code.
+
+.. branch: remove-del-from-generatoriterator
+Speed up generators that don't yield inside try or wait blocks by skipping
+unnecessary cleanup.
+
+.. branch: annotator
+Remove FlowObjSpace.
+Improve cohesion between rpython.flowspace and rpython.annotator.
+
+.. branch: detect-immutable-fields
+mapdicts keep track of whether or not an attribute is every assigned to
+multiple times. If it's only assigned once then an elidable lookup is used when
+possible.
diff --git a/pypy/goal/getnightly.py b/pypy/goal/getnightly.py
--- a/pypy/goal/getnightly.py
+++ b/pypy/goal/getnightly.py
@@ -26,7 +26,12 @@
if branch == 'default':
branch = 'trunk'
-filename = 'pypy-c-jit-latest-%s.tar.bz2' % arch
+if '--nojit' in sys.argv:
+ kind = 'nojit'
+else:
+ kind = 'jit'
+
+filename = 'pypy-c-%s-latest-%s.tar.bz2' % (kind, arch)
url = 'http://buildbot.pypy.org/nightly/%s/%s' % (branch, filename)
tmp = py.path.local.mkdtemp()
mydir = tmp.chdir()
diff --git a/pypy/interpreter/astcompiler/codegen.py b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -1234,6 +1234,8 @@
flags |= consts.CO_NESTED
if scope.is_generator:
flags |= consts.CO_GENERATOR
+ if scope.has_yield_inside_try:
+ flags |= consts.CO_YIELD_INSIDE_TRY
if scope.has_variable_arg:
flags |= consts.CO_VARARGS
if scope.has_keywords_arg:
diff --git a/pypy/interpreter/astcompiler/consts.py b/pypy/interpreter/astcompiler/consts.py
--- a/pypy/interpreter/astcompiler/consts.py
+++ b/pypy/interpreter/astcompiler/consts.py
@@ -17,6 +17,7 @@
CO_FUTURE_UNICODE_LITERALS = 0x20000
#pypy specific:
CO_KILL_DOCSTRING = 0x100000
+CO_YIELD_INSIDE_TRY = 0x200000
PyCF_SOURCE_IS_UTF8 = 0x0100
PyCF_DONT_IMPLY_DEDENT = 0x0200
diff --git a/pypy/interpreter/astcompiler/symtable.py b/pypy/interpreter/astcompiler/symtable.py
--- a/pypy/interpreter/astcompiler/symtable.py
+++ b/pypy/interpreter/astcompiler/symtable.py
@@ -43,6 +43,7 @@
self.child_has_free = False
self.nested = False
self.doc_removable = False
+ self._in_try_body_depth = 0
def lookup(self, name):
"""Find the scope of identifier 'name'."""
@@ -75,6 +76,14 @@
self.varnames.append(mangled)
return mangled
+ def note_try_start(self, try_node):
+ """Called when a try is found, before visiting the body."""
+ self._in_try_body_depth += 1
+
+ def note_try_end(self, try_node):
+ """Called after visiting a try body."""
+ self._in_try_body_depth -= 1
+
def note_yield(self, yield_node):
"""Called when a yield is found."""
raise SyntaxError("'yield' outside function", yield_node.lineno,
@@ -210,6 +219,7 @@
self.has_variable_arg = False
self.has_keywords_arg = False
self.is_generator = False
+ self.has_yield_inside_try = False
self.optimized = True
self.return_with_value = False
self.import_star = None
@@ -220,6 +230,8 @@
raise SyntaxError("'return' with argument inside generator",
self.ret.lineno, self.ret.col_offset)
self.is_generator = True
+ if self._in_try_body_depth > 0:
+ self.has_yield_inside_try = True
def note_return(self, ret):
if ret.value:
@@ -463,7 +475,12 @@
self.scope.new_temporary_name()
if wih.optional_vars:
self.scope.new_temporary_name()
- ast.GenericASTVisitor.visit_With(self, wih)
+ wih.context_expr.walkabout(self)
+ if wih.optional_vars:
+ wih.optional_vars.walkabout(self)
+ self.scope.note_try_start(wih)
+ self.visit_sequence(wih.body)
+ self.scope.note_try_end(wih)
def visit_arguments(self, arguments):
scope = self.scope
@@ -505,3 +522,16 @@
else:
role = SYM_ASSIGNED
self.note_symbol(name.id, role)
+
+ def visit_TryExcept(self, node):
+ self.scope.note_try_start(node)
+ self.visit_sequence(node.body)
+ self.scope.note_try_end(node)
+ self.visit_sequence(node.handlers)
+ self.visit_sequence(node.orelse)
+
+ def visit_TryFinally(self, node):
+ self.scope.note_try_start(node)
+ self.visit_sequence(node.body)
+ self.scope.note_try_end(node)
+ self.visit_sequence(node.finalbody)
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -1,4 +1,4 @@
-import py
+import py, sys
from pypy.interpreter.astcompiler import codegen, astbuilder, symtable, optimize
from pypy.interpreter.pyparser import pyparse
from pypy.interpreter.pyparser.test import expressions
@@ -867,6 +867,9 @@
class AppTestCompiler:
+ def setup_class(cls):
+ cls.w_maxunicode = cls.space.wrap(sys.maxunicode)
+
def test_docstring_not_loaded(self):
import StringIO, dis, sys
ns = {}
@@ -911,7 +914,17 @@
l = [a for a in Foo()]
assert hint_called[0]
assert l == list(range(5))
-
+
+ def test_unicode_in_source(self):
+ import sys
+ d = {}
+ exec '# -*- coding: utf-8 -*-\n\nu = u"\xf0\x9f\x92\x8b"' in d
+ if sys.maxunicode > 65535 and self.maxunicode > 65535:
+ expected_length = 1
+ else:
+ expected_length = 2
+ assert len(d['u']) == expected_length
+
class TestOptimizations:
def count_instructions(self, source):
diff --git a/pypy/interpreter/astcompiler/test/test_symtable.py b/pypy/interpreter/astcompiler/test/test_symtable.py
--- a/pypy/interpreter/astcompiler/test/test_symtable.py
+++ b/pypy/interpreter/astcompiler/test/test_symtable.py
@@ -346,6 +346,25 @@
assert exc.msg == "'return' with argument inside generator"
scp = self.func_scope("def f():\n return\n yield x")
+ def test_yield_inside_try(self):
+ scp = self.func_scope("def f(): yield x")
+ assert not scp.has_yield_inside_try
+ scp = self.func_scope("def f():\n try:\n yield x\n except: pass")
+ assert scp.has_yield_inside_try
+ scp = self.func_scope("def f():\n try:\n yield x\n finally: pass")
+ assert scp.has_yield_inside_try
+ scp = self.func_scope("def f():\n with x: yield y")
+ assert scp.has_yield_inside_try
+
+ def test_yield_outside_try(self):
+ for input in ("try: pass\n except: pass",
+ "try: pass\n except: yield y",
+ "try: pass\n finally: pass",
+ "try: pass\n finally: yield y",
+ "with x: pass"):
+ input = "def f():\n yield y\n %s\n yield y" % (input,)
+ assert not self.func_scope(input).has_yield_inside_try
+
def test_return(self):
for input in ("class x: return", "return"):
exc = py.test.raises(SyntaxError, self.func_scope, input).value
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -231,6 +231,10 @@
msg = "__int__ returned non-int (type '%T')"
raise operationerrfmt(space.w_TypeError, msg, w_result)
+ def ord(self, space):
+ msg = "ord() expected string of length 1, but %T found"
+ raise operationerrfmt(space.w_TypeError, msg, self)
+
def __spacebind__(self, space):
return self
@@ -905,7 +909,7 @@
"""
return self.unpackiterable(w_iterable, expected_length)
- def listview_str(self, w_list):
+ def listview_bytes(self, w_list):
""" Return a list of unwrapped strings out of a list of strings. If the
argument is not a list or does not contain only strings, return None.
May return None anyway.
@@ -939,7 +943,7 @@
"""
return (None, None)
- def newlist_str(self, list_s):
+ def newlist_bytes(self, list_s):
return self.newlist([self.wrap(s) for s in list_s])
def newlist_unicode(self, list_u):
@@ -1396,6 +1400,9 @@
# This is here mostly just for gateway.int_unwrapping_space_method().
return bool(self.int_w(w_obj))
+ def ord(self, w_obj):
+ return w_obj.ord(self)
+
# This is all interface for gateway.py.
def gateway_int_w(self, w_obj):
if self.isinstance_w(w_obj, self.w_float):
diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -6,7 +6,7 @@
from errno import EINTR
from rpython.rlib import jit
-from rpython.rlib.objectmodel import we_are_translated
+from rpython.rlib.objectmodel import we_are_translated, specialize
from pypy.interpreter import debug
@@ -40,12 +40,11 @@
self.debug_excs = []
def clear(self, space):
- # for sys.exc_clear()
- self.w_type = space.w_None
- self._w_value = space.w_None
- self._application_traceback = None
- if not we_are_translated():
- del self.debug_excs[:]
+ # XXX remove this method. The point is that we cannot always
+ # hack at 'self' to clear w_type and _w_value, because in some
+ # corner cases the OperationError will be used again: see
+ # test_interpreter.py:test_with_statement_and_sys_clear.
+ pass
def match(self, space, w_check_class):
"Check if this application-level exception matches 'w_check_class'."
@@ -300,6 +299,10 @@
"""
self._application_traceback = traceback
+ at specialize.memo()
+def get_cleared_operation_error(space):
+ return OperationError(space.w_None, space.w_None)
+
# ____________________________________________________________
# optimization only: avoid the slowest operation -- the string
# formatting with '%' -- in the common case were we don't
@@ -371,8 +374,8 @@
class OpErrFmtNoArgs(OperationError):
def __init__(self, w_type, value):
+ self._value = value
self.setup(w_type)
- self._value = value
def get_w_value(self, space):
w_value = self._w_value
diff --git a/pypy/interpreter/executioncontext.py b/pypy/interpreter/executioncontext.py
--- a/pypy/interpreter/executioncontext.py
+++ b/pypy/interpreter/executioncontext.py
@@ -1,5 +1,5 @@
import sys
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, get_cleared_operation_error
from rpython.rlib.unroll import unrolling_iterable
from rpython.rlib import jit
@@ -217,6 +217,17 @@
if frame: # else, the exception goes nowhere and is lost
frame.last_exception = operror
+ def clear_sys_exc_info(self):
+ # Find the frame out of which sys_exc_info() would return its result,
+ # and hack this frame's last_exception to become the cleared
+ # OperationError (which is different from None!).
+ frame = self.gettopframe_nohidden()
+ while frame:
+ if frame.last_exception is not None:
+ frame.last_exception = get_cleared_operation_error(self.space)
+ break
+ frame = self.getnextframe_nohidden(frame)
+
@jit.dont_look_inside
def settrace(self, w_func):
"""Set the global trace function."""
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -520,12 +520,13 @@
# When a BuiltinCode is stored in a Function object,
# you get the functionality of CPython's built-in function type.
- def __init__(self, func, unwrap_spec=None, self_type=None, descrmismatch=None):
+ def __init__(self, func, unwrap_spec=None, self_type=None,
+ descrmismatch=None, doc=None):
"NOT_RPYTHON"
# 'implfunc' is the interpreter-level function.
# Note that this uses a lot of (construction-time) introspection.
Code.__init__(self, func.__name__)
- self.docstring = func.__doc__
+ self.docstring = doc or func.__doc__
self.identifier = "%s-%s-%s" % (func.__module__, func.__name__,
getattr(self_type, '__name__', '*'))
@@ -832,7 +833,7 @@
instancecache = {}
def __new__(cls, f, app_name=None, unwrap_spec=None, descrmismatch=None,
- as_classmethod=False):
+ as_classmethod=False, doc=None):
"NOT_RPYTHON"
# f must be a function whose name does NOT start with 'app_'
@@ -861,7 +862,8 @@
cls.instancecache[key] = self
self._code = BuiltinCode(f, unwrap_spec=unwrap_spec,
self_type=self_type,
- descrmismatch=descrmismatch)
+ descrmismatch=descrmismatch,
+ doc=doc)
self.__name__ = f.func_name
self.name = app_name
self.as_classmethod = as_classmethod
diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py
--- a/pypy/interpreter/generator.py
+++ b/pypy/interpreter/generator.py
@@ -155,20 +155,6 @@
code_name = self.pycode.co_name
return space.wrap(code_name)
- def __del__(self):
- # Only bother enqueuing self to raise an exception if the frame is
- # still not finished and finally or except blocks are present.
- self.clear_all_weakrefs()
- if self.frame is not None:
- block = self.frame.lastblock
- while block is not None:
- if not isinstance(block, LoopBlock):
- self.enqueue_for_destruction(self.space,
- GeneratorIterator.descr_close,
- "interrupting generator of ")
- break
- block = block.previous
-
# Results can be either an RPython list of W_Root, or it can be an
# app-level W_ListObject, which also has an append() method, that's why we
# generate 2 versions of the function and 2 jit drivers.
@@ -211,3 +197,20 @@
return unpack_into
unpack_into = _create_unpack_into()
unpack_into_w = _create_unpack_into()
+
+
+class GeneratorIteratorWithDel(GeneratorIterator):
+
+ def __del__(self):
+ # Only bother enqueuing self to raise an exception if the frame is
+ # still not finished and finally or except blocks are present.
+ self.clear_all_weakrefs()
+ if self.frame is not None:
+ block = self.frame.lastblock
+ while block is not None:
+ if not isinstance(block, LoopBlock):
+ self.enqueue_for_destruction(self.space,
+ GeneratorIterator.descr_close,
+ "interrupting generator of ")
+ break
+ block = block.previous
diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -12,7 +12,7 @@
from pypy.interpreter.gateway import unwrap_spec
from pypy.interpreter.astcompiler.consts import (
CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS, CO_NESTED,
- CO_GENERATOR, CO_KILL_DOCSTRING)
+ CO_GENERATOR, CO_KILL_DOCSTRING, CO_YIELD_INSIDE_TRY)
from pypy.tool.stdlib_opcode import opcodedesc, HAVE_ARGUMENT
from rpython.rlib.rarithmetic import intmask
from rpython.rlib.objectmodel import compute_hash
@@ -31,7 +31,7 @@
# Magic numbers for the bytecode version in code objects.
# See comments in pypy/module/imp/importing.
cpython_magic, = struct.unpack("<i", imp.get_magic()) # host magic number
-default_magic = (0xf303 + 6) | 0x0a0d0000 # this PyPy's magic
+default_magic = (0xf303 + 7) | 0x0a0d0000 # this PyPy's magic
# (from CPython 2.7.0)
# cpython_code_signature helper
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -167,8 +167,12 @@
def run(self):
"""Start this frame's execution."""
if self.getcode().co_flags & pycode.CO_GENERATOR:
- from pypy.interpreter.generator import GeneratorIterator
- return self.space.wrap(GeneratorIterator(self))
+ if self.getcode().co_flags & pycode.CO_YIELD_INSIDE_TRY:
+ from pypy.interpreter.generator import GeneratorIteratorWithDel
+ return self.space.wrap(GeneratorIteratorWithDel(self))
+ else:
+ from pypy.interpreter.generator import GeneratorIterator
+ return self.space.wrap(GeneratorIterator(self))
else:
return self.execute_frame()
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -744,6 +744,9 @@
else:
raise OperationError(space.w_TypeError,
space.wrap("raise: no active exception to re-raise"))
+ if operror.w_type is space.w_None:
+ raise OperationError(space.w_TypeError,
+ space.wrap("raise: the exception to re-raise was cleared"))
# re-raise, no new traceback obj will be attached
self.last_exception = operror
raise RaiseWithExplicitTraceback(operror)
diff --git a/pypy/interpreter/pyparser/parsestring.py b/pypy/interpreter/pyparser/parsestring.py
--- a/pypy/interpreter/pyparser/parsestring.py
+++ b/pypy/interpreter/pyparser/parsestring.py
@@ -15,7 +15,6 @@
Yes, it's very inefficient.
Yes, CPython has very similar code.
"""
-
# we use ps as "pointer to s"
# q is the virtual last char index of the string
ps = 0
@@ -54,42 +53,10 @@
if unicode_literal: # XXX Py_UnicodeFlag is ignored for now
if encoding is None or encoding == "iso-8859-1":
# 'unicode_escape' expects latin-1 bytes, string is ready.
- buf = s
- bufp = ps
- bufq = q
- u = None
+ assert 0 <= ps <= q
+ substr = s[ps:q]
else:
- # String is utf8-encoded, but 'unicode_escape' expects
- # latin-1; So multibyte sequences must be escaped.
- lis = [] # using a list to assemble the value
- end = q
- # Worst case: "\XX" may become "\u005c\uHHLL" (12 bytes)
- while ps < end:
- if s[ps] == '\\':
- lis.append(s[ps])
- ps += 1
- if ord(s[ps]) & 0x80:
- # A multibyte sequence will follow, it will be
- # escaped like \u1234. To avoid confusion with
- # the backslash we just wrote, we emit "\u005c"
- # instead.
- lis.append("u005c")
- if ord(s[ps]) & 0x80: # XXX inefficient
- w, ps = decode_utf8(space, s, ps, end, "utf-16-be")
- rn = len(w)
- assert rn % 2 == 0
- for i in range(0, rn, 2):
- lis.append('\\u')
- lis.append(hexbyte(ord(w[i])))
- lis.append(hexbyte(ord(w[i+1])))
- else:
- lis.append(s[ps])
- ps += 1
- buf = ''.join(lis)
- bufp = 0
- bufq = len(buf)
- assert 0 <= bufp <= bufq
- substr = buf[bufp:bufq]
+ substr = decode_unicode_utf8(space, s, ps, q)
if rawmode:
v = unicodehelper.decode_raw_unicode_escape(space, substr)
else:
@@ -121,6 +88,39 @@
result = "0" + result
return result
+def decode_unicode_utf8(space, s, ps, q):
+ # ****The Python 2.7 version, producing UTF-32 escapes****
+ # String is utf8-encoded, but 'unicode_escape' expects
+ # latin-1; So multibyte sequences must be escaped.
+ lis = [] # using a list to assemble the value
+ end = q
+ # Worst case:
+ # "<92><195><164>" may become "\u005c\U000000E4" (16 bytes)
+ while ps < end:
+ if s[ps] == '\\':
+ lis.append(s[ps])
+ ps += 1
+ if ord(s[ps]) & 0x80:
+ # A multibyte sequence will follow, it will be
+ # escaped like \u1234. To avoid confusion with
+ # the backslash we just wrote, we emit "\u005c"
+ # instead.
+ lis.append("u005c")
+ if ord(s[ps]) & 0x80: # XXX inefficient
+ w, ps = decode_utf8(space, s, ps, end, "utf-32-be")
+ rn = len(w)
+ assert rn % 4 == 0
+ for i in range(0, rn, 4):
+ lis.append('\\U')
+ lis.append(hexbyte(ord(w[i])))
+ lis.append(hexbyte(ord(w[i+1])))
+ lis.append(hexbyte(ord(w[i+2])))
+ lis.append(hexbyte(ord(w[i+3])))
+ else:
+ lis.append(s[ps])
+ ps += 1
+ return ''.join(lis)
+
def PyString_DecodeEscape(space, s, recode_encoding):
"""
Unescape a backslash-escaped string. If recode_encoding is non-zero,
diff --git a/pypy/interpreter/pyparser/test/test_parsestring.py b/pypy/interpreter/pyparser/test/test_parsestring.py
--- a/pypy/interpreter/pyparser/test/test_parsestring.py
+++ b/pypy/interpreter/pyparser/test/test_parsestring.py
@@ -1,10 +1,10 @@
from pypy.interpreter.pyparser import parsestring
-import py
+import py, sys
class TestParsetring:
- def parse_and_compare(self, literal, value):
+ def parse_and_compare(self, literal, value, encoding=None):
space = self.space
- w_ret = parsestring.parsestr(space, None, literal)
+ w_ret = parsestring.parsestr(space, encoding, literal)
if isinstance(value, str):
assert space.type(w_ret) == space.w_str
assert space.str_w(w_ret) == value
@@ -91,3 +91,18 @@
input = ["'", 'x', ' ', chr(0xc3), chr(0xa9), ' ', chr(92), 'n', "'"]
w_ret = parsestring.parsestr(space, 'utf8', ''.join(input))
assert space.str_w(w_ret) == ''.join(expected)
+
+ def test_wide_unicode_in_source(self):
+ if sys.maxunicode == 65535:
+ py.test.skip("requires a wide-unicode host")
+ self.parse_and_compare('u"\xf0\x9f\x92\x8b"',
+ unichr(0x1f48b),
+ encoding='utf-8')
+
+ def test_decode_unicode_utf8(self):
+ buf = parsestring.decode_unicode_utf8(self.space,
+ 'u"\xf0\x9f\x92\x8b"', 2, 6)
+ if sys.maxunicode == 65535:
+ assert buf == r"\U0000d83d\U0000dc8b"
+ else:
+ assert buf == r"\U0001f48b"
diff --git a/pypy/interpreter/test/test_gateway.py b/pypy/interpreter/test/test_gateway.py
--- a/pypy/interpreter/test/test_gateway.py
+++ b/pypy/interpreter/test/test_gateway.py
@@ -708,6 +708,18 @@
never_called
py.test.raises(AssertionError, space.wrap, gateway.interp2app_temp(g))
+ def test_interp2app_doc(self):
+ space = self.space
+ def f(space, w_x):
+ """foo"""
+ w_f = space.wrap(gateway.interp2app_temp(f))
+ assert space.unwrap(space.getattr(w_f, space.wrap('__doc__'))) == 'foo'
+ #
+ def g(space, w_x):
+ never_called
+ w_g = space.wrap(gateway.interp2app_temp(g, doc='bar'))
+ assert space.unwrap(space.getattr(w_g, space.wrap('__doc__'))) == 'bar'
+
class AppTestPyTestMark:
@py.test.mark.unlikely_to_exist
diff --git a/pypy/interpreter/test/test_interpreter.py b/pypy/interpreter/test/test_interpreter.py
--- a/pypy/interpreter/test/test_interpreter.py
+++ b/pypy/interpreter/test/test_interpreter.py
@@ -311,3 +311,73 @@
assert str(e) == "maximum recursion depth exceeded"
else:
assert 0, "should have raised!"
+
+ def test_with_statement_and_sys_clear(self):
+ import sys
+ class CM(object):
+ def __enter__(self):
+ return self
+ def __exit__(self, exc_type, exc_value, tb):
+ sys.exc_clear()
+ try:
+ with CM():
+ 1 / 0
+ raise AssertionError("should not be reached")
+ except ZeroDivisionError:
+ pass
+
+ def test_sys_clear_while_handling_exception(self):
+ import sys
+ def f():
+ try:
+ some_missing_name
+ except NameError:
+ g()
+ assert sys.exc_info()[0] is NameError
+ def g():
+ assert sys.exc_info()[0] is NameError
+ try:
+ 1 / 0
+ except ZeroDivisionError:
+ assert sys.exc_info()[0] is ZeroDivisionError
+ sys.exc_clear()
+ assert sys.exc_info()[0] is None
+ h()
+ assert sys.exc_info()[0] is None
+ def h():
+ assert sys.exc_info()[0] is None
+ f()
+
+ def test_sys_clear_while_handling_exception_nested(self):
+ import sys
+ def f():
+ try:
+ some_missing_name
+ except NameError:
+ g()
+ assert sys.exc_info()[0] is NameError
+ def g():
+ assert sys.exc_info()[0] is NameError
+ try:
+ 1 / 0
+ except ZeroDivisionError:
+ assert sys.exc_info()[0] is ZeroDivisionError
+ h1()
+ assert sys.exc_info()[0] is None
+ h()
+ assert sys.exc_info()[0] is None
+ def h():
+ assert sys.exc_info()[0] is None
+ def h1():
+ sys.exc_clear()
+ f()
+
+ def test_sys_clear_reraise(self):
+ import sys
+ def f():
+ try:
+ 1 / 0
+ except ZeroDivisionError:
+ sys.exc_clear()
+ raise
+ raises(TypeError, f)
diff --git a/pypy/interpreter/unicodehelper.py b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -30,7 +30,7 @@
# ____________________________________________________________
def encode(space, w_data, encoding=None, errors='strict'):
- from pypy.objspace.std.unicodetype import encode_object
+ from pypy.objspace.std.unicodeobject import encode_object
return encode_object(space, w_data, encoding, errors)
# These functions take and return unwrapped rpython strings and unicodes
diff --git a/pypy/module/__builtin__/interp_memoryview.py b/pypy/module/__builtin__/interp_memoryview.py
--- a/pypy/module/__builtin__/interp_memoryview.py
+++ b/pypy/module/__builtin__/interp_memoryview.py
@@ -68,10 +68,14 @@
return W_MemoryView(buf)
def descr_buffer(self, space):
- """Note that memoryview() objects in PyPy support buffer(), whereas
- not in CPython; but CPython supports passing memoryview() to most
- built-in functions that accept buffers, with the notable exception
- of the buffer() built-in."""
+ """
+ Note that memoryview() is very inconsistent in CPython: it does not
+ support the buffer interface but does support the new buffer
+ interface: as a result, it is possible to pass memoryview to
+ e.g. socket.send() but not to file.write(). For simplicity and
+ consistency, in PyPy memoryview DOES support buffer(), which means
+ that it is accepted in more places than CPython.
+ """
return space.wrap(self.buf)
def descr_tobytes(self, space):
diff --git a/pypy/module/__builtin__/test/test_classobj.py b/pypy/module/__builtin__/test/test_classobj.py
--- a/pypy/module/__builtin__/test/test_classobj.py
+++ b/pypy/module/__builtin__/test/test_classobj.py
@@ -1061,14 +1061,14 @@
assert (D() >= A()) == 'D:A.ge'
-class AppTestOldStyleClassStrDict(object):
+class AppTestOldStyleClassBytesDict(object):
def setup_class(cls):
if cls.runappdirect:
py.test.skip("can only be run on py.py")
def is_strdict(space, w_class):
- from pypy.objspace.std.dictmultiobject import StringDictStrategy
+ from pypy.objspace.std.dictmultiobject import BytesDictStrategy
w_d = w_class.getdict(space)
- return space.wrap(isinstance(w_d.strategy, StringDictStrategy))
+ return space.wrap(isinstance(w_d.strategy, BytesDictStrategy))
cls.w_is_strdict = cls.space.wrap(gateway.interp2app(is_strdict))
diff --git a/pypy/module/__pypy__/interp_magic.py b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -3,7 +3,7 @@
from rpython.rlib.objectmodel import we_are_translated
from pypy.objspace.std.listobject import W_ListObject
from pypy.objspace.std.typeobject import MethodCache
-from pypy.objspace.std.mapdict import IndexCache
+from pypy.objspace.std.mapdict import MapAttrCache
from rpython.rlib import rposix, rgc
@@ -35,7 +35,7 @@
cache.misses = {}
cache.hits = {}
if space.config.objspace.std.withmapdict:
- cache = space.fromcache(IndexCache)
+ cache = space.fromcache(MapAttrCache)
cache.misses = {}
cache.hits = {}
@@ -45,7 +45,7 @@
in the mapdict cache with the given attribute name."""
assert space.config.objspace.std.withmethodcachecounter
assert space.config.objspace.std.withmapdict
- cache = space.fromcache(IndexCache)
+ cache = space.fromcache(MapAttrCache)
return space.newtuple([space.newint(cache.hits.get(name, 0)),
space.newint(cache.misses.get(name, 0))])
diff --git a/pypy/module/__pypy__/test/test_special.py b/pypy/module/__pypy__/test/test_special.py
--- a/pypy/module/__pypy__/test/test_special.py
+++ b/pypy/module/__pypy__/test/test_special.py
@@ -51,7 +51,9 @@
l = [1, 2, 3]
assert list_strategy(l) == "int"
l = ["a", "b", "c"]
- assert list_strategy(l) == "str"
+ assert list_strategy(l) == "bytes"
+ l = [u"a", u"b", u"c"]
+ assert list_strategy(l) == "unicode"
l = [1.1, 2.2, 3.3]
assert list_strategy(l) == "float"
l = range(3)
diff --git a/pypy/module/_cffi_backend/cdataobj.py b/pypy/module/_cffi_backend/cdataobj.py
--- a/pypy/module/_cffi_backend/cdataobj.py
+++ b/pypy/module/_cffi_backend/cdataobj.py
@@ -5,7 +5,7 @@
from pypy.interpreter.gateway import interp2app
from pypy.interpreter.typedef import TypeDef, make_weakref_descr
-from rpython.rlib import objectmodel, rgc
+from rpython.rlib import rgc
from rpython.rlib.objectmodel import keepalive_until_here, specialize
from rpython.rtyper.lltypesystem import lltype, rffi
from rpython.tool.sourcetools import func_with_new_name
diff --git a/pypy/module/_cffi_backend/ctypestruct.py b/pypy/module/_cffi_backend/ctypestruct.py
--- a/pypy/module/_cffi_backend/ctypestruct.py
+++ b/pypy/module/_cffi_backend/ctypestruct.py
@@ -33,7 +33,7 @@
if self.fields_dict is None:
space = self.space
raise operationerrfmt(w_errorcls or space.w_TypeError,
- "'%s' is not completed yet", self.name)
+ "'%s' is opaque or not completed yet", self.name)
def _alignof(self):
self.check_complete(w_errorcls=self.space.w_ValueError)
diff --git a/pypy/module/_cffi_backend/handle.py b/pypy/module/_cffi_backend/handle.py
--- a/pypy/module/_cffi_backend/handle.py
+++ b/pypy/module/_cffi_backend/handle.py
@@ -2,58 +2,13 @@
from pypy.interpreter.error import OperationError, operationerrfmt
from pypy.interpreter.gateway import unwrap_spec
from pypy.module._cffi_backend import ctypeobj, ctypeptr, cdataobj
-from pypy.module._weakref.interp__weakref import dead_ref
from rpython.rtyper.lltypesystem import lltype, rffi
+from rpython.rlib import rweaklist
-def reduced_value(s):
- while True:
- divide = s & 1
- s >>= 1
- if not divide:
- return s
-
-# ____________________________________________________________
-
-
-class CffiHandles:
+class CffiHandles(rweaklist.RWeakListMixin):
def __init__(self, space):
- self.handles = []
- self.look_distance = 0
-
- def reserve_next_handle_index(self):
- # The reservation ordering done here is tweaked for pypy's
- # memory allocator. We look from index 'look_distance'.
- # Look_distance increases from 0. But we also look at
- # "look_distance/2" or "/4" or "/8", etc. If we find that one
- # of these secondary locations is free, we assume it's because
- # there was recently a minor collection; so we reset
- # look_distance to 0 and start again from the lowest locations.
- length = len(self.handles)
- for d in range(self.look_distance, length):
- if self.handles[d]() is None:
- self.look_distance = d + 1
- return d
- s = reduced_value(d)
- if self.handles[s]() is None:
- break
- # restart from the beginning
- for d in range(0, length):
- if self.handles[d]() is None:
- self.look_distance = d + 1
- return d
- # full! extend, but don't use '+=' here
- self.handles = self.handles + [dead_ref] * (length // 3 + 5)
- self.look_distance = length + 1
- return length
-
- def store_handle(self, index, content):
- self.handles[index] = weakref.ref(content)
-
- def fetch_handle(self, index):
- if 0 <= index < len(self.handles):
- return self.handles[index]()
- return None
+ self.initialize()
def get(space):
return space.fromcache(CffiHandles)
diff --git a/pypy/module/_cffi_backend/newtype.py b/pypy/module/_cffi_backend/newtype.py
--- a/pypy/module/_cffi_backend/newtype.py
+++ b/pypy/module/_cffi_backend/newtype.py
@@ -118,6 +118,7 @@
SF_MSVC_BITFIELDS = 1
SF_GCC_ARM_BITFIELDS = 2
SF_GCC_BIG_ENDIAN = 4
+SF_PACKED = 8
if sys.platform == 'win32':
DEFAULT_SFLAGS = SF_MSVC_BITFIELDS
@@ -190,8 +191,8 @@
boffset = 0 # reset each field at offset 0
#
# update the total alignment requirement, but skip it if the
- # field is an anonymous bitfield
- falign = ftype.alignof()
+ # field is an anonymous bitfield or if SF_PACKED
+ falign = 1 if sflags & SF_PACKED else ftype.alignof()
do_align = True
if (sflags & SF_GCC_ARM_BITFIELDS) == 0 and fbitsize >= 0:
if (sflags & SF_MSVC_BITFIELDS) == 0:
@@ -305,6 +306,12 @@
if bits_already_occupied + fbitsize > 8 * ftype.size:
# it would not fit, we need to start at the next
# allowed position
+ if ((sflags & SF_PACKED) != 0 and
+ (bits_already_occupied & 7) != 0):
+ raise operationerrfmt(space.w_NotImplementedError,
+ "with 'packed', gcc would compile field "
+ "'%s.%s' to reuse some bits in the previous "
+ "field", w_ctype.name, fname)
field_offset_bytes += falign
assert boffset < field_offset_bytes * 8
boffset = field_offset_bytes * 8
diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -3137,6 +3137,44 @@
p = newp(BArray, None)
assert sizeof(p[2:9]) == 7 * sizeof(BInt)
+def test_packed():
+ BLong = new_primitive_type("long")
+ BChar = new_primitive_type("char")
+ BShort = new_primitive_type("short")
+ BStruct = new_struct_type("struct foo")
+ complete_struct_or_union(BStruct, [('a1', BLong, -1),
+ ('a2', BChar, -1),
+ ('a3', BShort, -1)],
+ None, -1, -1, 8) # SF_PACKED==8
+ d = BStruct.fields
+ assert len(d) == 3
+ assert d[0][0] == 'a1'
+ assert d[0][1].type is BLong
+ assert d[0][1].offset == 0
+ assert d[0][1].bitshift == -1
+ assert d[0][1].bitsize == -1
+ assert d[1][0] == 'a2'
+ assert d[1][1].type is BChar
+ assert d[1][1].offset == sizeof(BLong)
+ assert d[1][1].bitshift == -1
+ assert d[1][1].bitsize == -1
+ assert d[2][0] == 'a3'
+ assert d[2][1].type is BShort
+ assert d[2][1].offset == sizeof(BLong) + sizeof(BChar)
+ assert d[2][1].bitshift == -1
+ assert d[2][1].bitsize == -1
+ assert sizeof(BStruct) == sizeof(BLong) + sizeof(BChar) + sizeof(BShort)
+ assert alignof(BStruct) == 1
+
+def test_packed_with_bitfields():
+ BLong = new_primitive_type("long")
+ BChar = new_primitive_type("char")
+ BStruct = new_struct_type("struct foo")
+ py.test.raises(NotImplementedError,
+ complete_struct_or_union,
+ BStruct, [('a1', BLong, 30),
+ ('a2', BChar, 5)],
+ None, -1, -1, 8) # SF_PACKED==8
def test_version():
# this test is here mostly for PyPy
diff --git a/pypy/module/_cffi_backend/test/test_handle.py b/pypy/module/_cffi_backend/test/test_handle.py
--- a/pypy/module/_cffi_backend/test/test_handle.py
+++ b/pypy/module/_cffi_backend/test/test_handle.py
@@ -1,20 +1,5 @@
import random
-from pypy.module._cffi_backend.handle import CffiHandles, reduced_value
-
-
-def test_reduced_value():
- assert reduced_value(0) == 0
- assert reduced_value(1) == 0
- assert reduced_value(2) == 1
- assert reduced_value(3) == 0
- assert reduced_value(4) == 2
- assert reduced_value(5) == 1
- assert reduced_value(6) == 3
- assert reduced_value(7) == 0
- assert reduced_value(8) == 4
- assert reduced_value(9) == 2
- assert reduced_value(10) == 5
- assert reduced_value(11) == 1
+from pypy.module._cffi_backend.handle import CffiHandles
class PseudoWeakRef(object):
diff --git a/pypy/module/_codecs/interp_codecs.py b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -709,7 +709,7 @@
@unwrap_spec(data=str, errors='str_or_None')
def escape_encode(space, data, errors='strict'):
- from pypy.objspace.std.stringobject import string_escape_encode
+ from pypy.objspace.std.bytesobject import string_escape_encode
result = string_escape_encode(data, quote="'")
start = 1
end = len(result) - 1
diff --git a/pypy/module/_csv/interp_reader.py b/pypy/module/_csv/interp_reader.py
--- a/pypy/module/_csv/interp_reader.py
+++ b/pypy/module/_csv/interp_reader.py
@@ -39,6 +39,7 @@
field_builder.append(c)
def save_field(self, field_builder):
+ space = self.space
field = field_builder.build()
if self.numeric_field:
from rpython.rlib.rstring import ParseStringError
@@ -46,12 +47,12 @@
self.numeric_field = False
try:
ff = string_to_float(field)
- except ParseStringError, e:
- raise OperationError(self.space.w_ValueError,
- self.space.wrap(e.msg))
- w_obj = self.space.wrap(ff)
+ except ParseStringError as e:
+ from pypy.objspace.std.intobject import wrap_parsestringerror
+ raise wrap_parsestringerror(space, e, space.wrap(field))
+ w_obj = space.wrap(ff)
else:
- w_obj = self.space.wrap(field)
+ w_obj = space.wrap(field)
self.fields_w.append(w_obj)
def next_w(self):
diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py
--- a/pypy/module/_io/interp_bytesio.py
+++ b/pypy/module/_io/interp_bytesio.py
@@ -11,7 +11,7 @@
class W_BytesIO(RStringIO, W_BufferedIOBase):
def __init__(self, space):
- W_BufferedIOBase.__init__(self, space)
+ W_BufferedIOBase.__init__(self, space, add_to_autoflusher=False)
self.init()
def descr_init(self, space, w_initial_bytes=None):
diff --git a/pypy/module/_io/interp_iobase.py b/pypy/module/_io/interp_iobase.py
--- a/pypy/module/_io/interp_iobase.py
+++ b/pypy/module/_io/interp_iobase.py
@@ -5,7 +5,7 @@
from pypy.interpreter.gateway import interp2app
from pypy.interpreter.error import OperationError, operationerrfmt
from rpython.rlib.rstring import StringBuilder
-from rpython.rlib import rweakref
+from rpython.rlib import rweakref, rweaklist
DEFAULT_BUFFER_SIZE = 8192
@@ -44,15 +44,15 @@
class W_IOBase(W_Root):
- def __init__(self, space):
+ def __init__(self, space, add_to_autoflusher=True):
# XXX: IOBase thinks it has to maintain its own internal state in
# `__IOBase_closed` and call flush() by itself, but it is redundant
# with whatever behaviour a non-trivial derived class will implement.
self.space = space
self.w_dict = space.newdict()
self.__IOBase_closed = False
- self.streamholder = None # needed by AutoFlusher
- get_autoflusher(space).add(self)
+ if add_to_autoflusher:
+ get_autoflusher(space).add(self)
def getdict(self, space):
return self.w_dict
@@ -114,7 +114,6 @@
space.call_method(self, "flush")
finally:
self.__IOBase_closed = True
- get_autoflusher(space).remove(self)
def flush_w(self, space):
if self._CLOSED():
@@ -338,55 +337,35 @@
# functions to make sure that all streams are flushed on exit
# ------------------------------------------------------------
-class StreamHolder(object):
- def __init__(self, w_iobase):
- self.w_iobase_ref = rweakref.ref(w_iobase)
- w_iobase.autoflusher = self
- def autoflush(self, space):
- w_iobase = self.w_iobase_ref()
- if w_iobase is not None:
- try:
- space.call_method(w_iobase, 'flush')
- except OperationError:
- # Silencing all errors is bad, but getting randomly
- # interrupted here is equally as bad, and potentially
- # more frequent (because of shutdown issues).
- pass
-
-
-class AutoFlusher(object):
+class AutoFlusher(rweaklist.RWeakListMixin):
def __init__(self, space):
- self.streams = {}
+ self.initialize()
def add(self, w_iobase):
- assert w_iobase.streamholder is None
if rweakref.has_weakref_support():
- holder = StreamHolder(w_iobase)
- w_iobase.streamholder = holder
- self.streams[holder] = None
+ self.add_handle(w_iobase)
#else:
# no support for weakrefs, so ignore and we
# will not get autoflushing
- def remove(self, w_iobase):
- holder = w_iobase.streamholder
- if holder is not None:
- try:
- del self.streams[holder]
- except KeyError:
- # this can happen in daemon threads
- pass
-
def flush_all(self, space):
- while self.streams:
- for streamholder in self.streams.keys():
+ while True:
+ handles = self.get_all_handles()
+ if len(handles) == 0:
+ break
+ self.initialize() # reset the state here
+ for wr in handles:
+ w_iobase = wr()
+ if w_iobase is None:
+ continue
try:
- del self.streams[streamholder]
- except KeyError:
- pass # key was removed in the meantime
- else:
- streamholder.autoflush(space)
+ space.call_method(w_iobase, 'flush')
+ except OperationError:
+ # Silencing all errors is bad, but getting randomly
+ # interrupted here is equally as bad, and potentially
+ # more frequent (because of shutdown issues).
+ pass
def get_autoflusher(space):
return space.fromcache(AutoFlusher)
diff --git a/pypy/module/_multiprocessing/test/test_memory.py b/pypy/module/_multiprocessing/test/test_memory.py
--- a/pypy/module/_multiprocessing/test/test_memory.py
+++ b/pypy/module/_multiprocessing/test/test_memory.py
@@ -1,6 +1,6 @@
class AppTestMemory:
spaceconfig = dict(usemodules=('_multiprocessing', 'mmap',
- '_rawffi', '_ffi', 'itertools'))
+ '_rawffi', 'itertools'))
def test_address_of(self):
import _multiprocessing
diff --git a/pypy/module/_pickle_support/maker.py b/pypy/module/_pickle_support/maker.py
--- a/pypy/module/_pickle_support/maker.py
+++ b/pypy/module/_pickle_support/maker.py
@@ -5,7 +5,7 @@
from pypy.interpreter.module import Module
from pypy.interpreter.pyframe import PyFrame
from pypy.interpreter.pytraceback import PyTraceback
-from pypy.interpreter.generator import GeneratorIterator
+from pypy.interpreter.generator import GeneratorIteratorWithDel
from rpython.rlib.objectmodel import instantiate
from pypy.interpreter.gateway import unwrap_spec
from pypy.objspace.std.iterobject import W_SeqIterObject, W_ReverseSeqIterObject
@@ -60,7 +60,7 @@
return space.wrap(tb)
def generator_new(space):
- new_generator = instantiate(GeneratorIterator)
+ new_generator = instantiate(GeneratorIteratorWithDel)
return space.wrap(new_generator)
@unwrap_spec(current=int, remaining=int, step=int)
diff --git a/pypy/module/_rawffi/__init__.py b/pypy/module/_rawffi/__init__.py
--- a/pypy/module/_rawffi/__init__.py
+++ b/pypy/module/_rawffi/__init__.py
@@ -2,6 +2,7 @@
"""
from pypy.interpreter.mixedmodule import MixedModule
+from pypy.module._rawffi import alt
class Module(MixedModule):
interpleveldefs = {
@@ -19,6 +20,7 @@
'wcharp2unicode' : 'interp_rawffi.wcharp2unicode',
'charp2rawstring' : 'interp_rawffi.charp2rawstring',
'wcharp2rawunicode' : 'interp_rawffi.wcharp2rawunicode',
+ 'rawstring2charp' : 'interp_rawffi.rawstring2charp',
'CallbackPtr' : 'callback.W_CallbackPtr',
'_num_of_allocated_objects' : 'tracker.num_of_allocated_objects',
'get_libc' : 'interp_rawffi.get_libc',
@@ -32,6 +34,10 @@
appleveldefs = {
}
+ submodules = {
+ 'alt': alt.Module,
+ }
+
def buildloaders(cls):
from pypy.module._rawffi import interp_rawffi
diff --git a/pypy/module/_ffi/__init__.py b/pypy/module/_rawffi/alt/__init__.py
rename from pypy/module/_ffi/__init__.py
rename to pypy/module/_rawffi/alt/__init__.py
diff --git a/pypy/module/_ffi/app_struct.py b/pypy/module/_rawffi/alt/app_struct.py
rename from pypy/module/_ffi/app_struct.py
rename to pypy/module/_rawffi/alt/app_struct.py
--- a/pypy/module/_ffi/app_struct.py
+++ b/pypy/module/_rawffi/alt/app_struct.py
@@ -1,4 +1,4 @@
-import _ffi
+from _rawffi import alt
class MetaStructure(type):
@@ -11,7 +11,7 @@
fields = dic.get('_fields_')
if fields is None:
return
- struct_descr = _ffi._StructDescr(name, fields)
+ struct_descr = alt._StructDescr(name, fields)
for field in fields:
dic[field.name] = field
dic['_struct_'] = struct_descr
diff --git a/pypy/module/_ffi/interp_ffitype.py b/pypy/module/_rawffi/alt/interp_ffitype.py
rename from pypy/module/_ffi/interp_ffitype.py
rename to pypy/module/_rawffi/alt/interp_ffitype.py
--- a/pypy/module/_ffi/interp_ffitype.py
+++ b/pypy/module/_rawffi/alt/interp_ffitype.py
@@ -116,7 +116,7 @@
types = [
# note: most of the type name directly come from the C equivalent,
# with the exception of bytes: in C, ubyte and char are equivalent,
- # but for _ffi the first expects a number while the second a 1-length
+ # but for here the first expects a number while the second a 1-length
# string
W_FFIType('slong', libffi.types.slong),
W_FFIType('sint', libffi.types.sint),
diff --git a/pypy/module/_ffi/interp_funcptr.py b/pypy/module/_rawffi/alt/interp_funcptr.py
rename from pypy/module/_ffi/interp_funcptr.py
rename to pypy/module/_rawffi/alt/interp_funcptr.py
--- a/pypy/module/_ffi/interp_funcptr.py
+++ b/pypy/module/_rawffi/alt/interp_funcptr.py
@@ -3,7 +3,7 @@
operationerrfmt
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.typedef import TypeDef
-from pypy.module._ffi.interp_ffitype import W_FFIType
+from pypy.module._rawffi.alt.interp_ffitype import W_FFIType
#
from rpython.rtyper.lltypesystem import lltype, rffi
#
@@ -13,7 +13,7 @@
from rpython.rlib.rdynload import DLOpenError
from rpython.rlib.rarithmetic import r_uint
from rpython.rlib.objectmodel import we_are_translated
-from pypy.module._ffi.type_converter import FromAppLevelConverter, ToAppLevelConverter
+from pypy.module._rawffi.alt.type_converter import FromAppLevelConverter, ToAppLevelConverter
from pypy.module._rawffi.interp_rawffi import got_libffi_error, wrap_dlopenerror
import os
@@ -302,7 +302,7 @@
W_FuncPtr.typedef = TypeDef(
- '_ffi.FuncPtr',
+ '_rawffi.alt.FuncPtr',
__call__ = interp2app(W_FuncPtr.call),
getaddr = interp2app(W_FuncPtr.getaddr),
free_temp_buffers = interp2app(W_FuncPtr.free_temp_buffers),
@@ -346,7 +346,7 @@
W_CDLL.typedef = TypeDef(
- '_ffi.CDLL',
+ '_rawffi.alt.CDLL',
__new__ = interp2app(descr_new_cdll),
getfunc = interp2app(W_CDLL.getfunc),
getaddressindll = interp2app(W_CDLL.getaddressindll),
@@ -363,7 +363,7 @@
W_WinDLL.typedef = TypeDef(
- '_ffi.WinDLL',
+ '_rawffi.alt.WinDLL',
__new__ = interp2app(descr_new_windll),
getfunc = interp2app(W_WinDLL.getfunc),
getaddressindll = interp2app(W_WinDLL.getaddressindll),
diff --git a/pypy/module/_ffi/interp_struct.py b/pypy/module/_rawffi/alt/interp_struct.py
rename from pypy/module/_ffi/interp_struct.py
rename to pypy/module/_rawffi/alt/interp_struct.py
--- a/pypy/module/_ffi/interp_struct.py
+++ b/pypy/module/_rawffi/alt/interp_struct.py
@@ -8,8 +8,8 @@
from pypy.interpreter.typedef import TypeDef, interp_attrproperty
from pypy.interpreter.gateway import interp2app, unwrap_spec
from pypy.interpreter.error import operationerrfmt
-from pypy.module._ffi.interp_ffitype import W_FFIType
-from pypy.module._ffi.type_converter import FromAppLevelConverter, ToAppLevelConverter
+from pypy.module._rawffi.alt.interp_ffitype import W_FFIType
+from pypy.module._rawffi.alt.type_converter import FromAppLevelConverter, ToAppLevelConverter
class W_Field(W_Root):
diff --git a/pypy/module/_ffi/test/__init__.py b/pypy/module/_rawffi/alt/test/__init__.py
rename from pypy/module/_ffi/test/__init__.py
rename to pypy/module/_rawffi/alt/test/__init__.py
diff --git a/pypy/module/_ffi/test/test_ffitype.py b/pypy/module/_rawffi/alt/test/test_ffitype.py
rename from pypy/module/_ffi/test/test_ffitype.py
rename to pypy/module/_rawffi/alt/test/test_ffitype.py
--- a/pypy/module/_ffi/test/test_ffitype.py
+++ b/pypy/module/_rawffi/alt/test/test_ffitype.py
@@ -1,21 +1,21 @@
-from pypy.module._ffi.test.test_funcptr import BaseAppTestFFI
+from pypy.module._rawffi.alt.test.test_funcptr import BaseAppTestFFI
class AppTestFFIType(BaseAppTestFFI):
def test_simple_types(self):
- from _ffi import types
+ from _rawffi.alt import types
assert str(types.sint) == "<ffi type sint>"
assert str(types.uint) == "<ffi type uint>"
assert types.sint.name == 'sint'
assert types.uint.name == 'uint'
def test_sizeof(self):
- from _ffi import types
+ from _rawffi.alt import types
assert types.sbyte.sizeof() == 1
assert types.sint.sizeof() == 4
def test_typed_pointer(self):
- from _ffi import types
+ from _rawffi.alt import types
intptr = types.Pointer(types.sint) # create a typed pointer to sint
assert intptr.deref_pointer() is types.sint
assert str(intptr) == '<ffi type (pointer to sint)>'
@@ -23,7 +23,7 @@
raises(TypeError, "types.Pointer(42)")
def test_pointer_identity(self):
- from _ffi import types
+ from _rawffi.alt import types
x = types.Pointer(types.slong)
y = types.Pointer(types.slong)
z = types.Pointer(types.char)
@@ -31,7 +31,7 @@
assert x is not z
def test_char_p_cached(self):
- from _ffi import types
+ from _rawffi.alt import types
x = types.Pointer(types.char)
assert x is types.char_p
x = types.Pointer(types.unichar)
diff --git a/pypy/module/_ffi/test/test_funcptr.py b/pypy/module/_rawffi/alt/test/test_funcptr.py
rename from pypy/module/_ffi/test/test_funcptr.py
rename to pypy/module/_rawffi/alt/test/test_funcptr.py
--- a/pypy/module/_ffi/test/test_funcptr.py
+++ b/pypy/module/_rawffi/alt/test/test_funcptr.py
@@ -7,7 +7,7 @@
import sys, py
class BaseAppTestFFI(object):
- spaceconfig = dict(usemodules=('_ffi', '_rawffi'))
+ spaceconfig = dict(usemodules=('_rawffi',))
@classmethod
def prepare_c_example(cls):
@@ -62,17 +62,17 @@
cls.w_f_12_34_plus_56_78 = space.wrap(f_result)
def test_libload(self):
- import _ffi
- _ffi.CDLL(self.libc_name)
+ import _rawffi.alt
+ _rawffi.alt.CDLL(self.libc_name)
def test_libload_fail(self):
- import _ffi
- raises(OSError, _ffi.CDLL, "xxxxx_this_name_does_not_exist_xxxxx")
+ import _rawffi.alt
+ raises(OSError, _rawffi.alt.CDLL, "xxxxx_this_name_does_not_exist_xxxxx")
def test_libload_None(self):
if self.iswin32:
skip("unix specific")
- from _ffi import CDLL, types
+ from _rawffi.alt import CDLL, types
# this should return *all* loaded libs, dlopen(NULL)
dll = CDLL(None)
# libm should be loaded
@@ -80,20 +80,20 @@
assert res == 1.0
def test_callfunc(self):
- from _ffi import CDLL, types
+ from _rawffi.alt import CDLL, types
libm = CDLL(self.libm_name)
pow = libm.getfunc('pow', [types.double, types.double], types.double)
assert pow(2, 3) == 8
def test_getaddr(self):
- from _ffi import CDLL, types
+ from _rawffi.alt import CDLL, types
libm = CDLL(self.libm_name)
pow = libm.getfunc('pow', [types.double, types.double], types.double)
assert pow.getaddr() == self.pow_addr
def test_getaddressindll(self):
import sys
- from _ffi import CDLL
+ from _rawffi.alt import CDLL
libm = CDLL(self.libm_name)
pow_addr = libm.getaddressindll('pow')
fff = sys.maxint*2-1
@@ -102,7 +102,7 @@
assert pow_addr == self.pow_addr & fff
def test_func_fromaddr(self):
- from _ffi import CDLL, types, FuncPtr
+ from _rawffi.alt import CDLL, types, FuncPtr
libm = CDLL(self.libm_name)
pow_addr = libm.getaddressindll('pow')
pow = FuncPtr.fromaddr(pow_addr, 'pow', [types.double, types.double],
@@ -117,7 +117,7 @@
}
"""
import sys
- from _ffi import CDLL, types
+ from _rawffi.alt import CDLL, types
libfoo = CDLL(self.libfoo_name)
sum_xy = libfoo.getfunc('sum_xy', [types.sint, types.sint], types.sint)
assert sum_xy(30, 12) == 42
@@ -129,7 +129,7 @@
DLLEXPORT void set_dummy(int val) { dummy = val; }
DLLEXPORT int get_dummy() { return dummy; }
"""
- from _ffi import CDLL, types
+ from _rawffi.alt import CDLL, types
libfoo = CDLL(self.libfoo_name)
set_dummy = libfoo.getfunc('set_dummy', [types.sint], types.void)
get_dummy = libfoo.getfunc('get_dummy', [], types.sint)
@@ -144,7 +144,7 @@
DLLEXPORT int* get_dummy_ptr() { return &dummy; }
DLLEXPORT void set_val_to_ptr(int* ptr, int val) { *ptr = val; }
"""
- from _ffi import CDLL, types
+ from _rawffi.alt import CDLL, types
libfoo = CDLL(self.libfoo_name)
get_dummy = libfoo.getfunc('get_dummy', [], types.sint)
get_dummy_ptr = libfoo.getfunc('get_dummy_ptr', [], types.void_p)
@@ -163,7 +163,7 @@
DLLEXPORT int* get_dummy_ptr(); // defined in test_pointer_args
DLLEXPORT void set_val_to_ptr(int* ptr, int val); // ditto
"""
- from _ffi import CDLL, types
+ from _rawffi.alt import CDLL, types
class MyPointerWrapper(object):
def __init__(self, value):
@@ -197,7 +197,7 @@
return len;
}
"""
- from _ffi import CDLL, types
+ from _rawffi.alt import CDLL, types
import _rawffi
libfoo = CDLL(self.libfoo_name)
mystrlen = libfoo.getfunc('mystrlen', [types.char_p], types.slong)
@@ -223,7 +223,7 @@
return len;
}
"""
- from _ffi import CDLL, types
+ from _rawffi.alt import CDLL, types
import _rawffi
libfoo = CDLL(self.libfoo_name)
mystrlen = libfoo.getfunc('mystrlen_u', [types.unichar_p], types.slong)
@@ -247,7 +247,7 @@
return s;
}
"""
- from _ffi import CDLL, types
+ from _rawffi.alt import CDLL, types
import _rawffi
libfoo = CDLL(self.libfoo_name)
do_nothing = libfoo.getfunc('do_nothing', [types.char_p], types.char_p)
@@ -264,7 +264,7 @@
DLLEXPORT int* get_dummy_ptr(); // defined in test_pointer_args
DLLEXPORT void set_val_to_ptr(int* ptr, int val); // ditto
"""
- from _ffi import CDLL, types
+ from _rawffi.alt import CDLL, types
libfoo = CDLL(self.libfoo_name)
intptr = types.Pointer(types.sint)
@@ -283,7 +283,7 @@
DLLEXPORT long is_null_ptr(void* ptr) { return ptr == NULL; }
"""
import sys
- from _ffi import CDLL, types
+ from _rawffi.alt import CDLL, types
libfoo = CDLL(self.libfoo_name)
is_null_ptr = libfoo.getfunc('is_null_ptr', [types.void_p], types.ulong)
assert not is_null_ptr(sys.maxint+1)
@@ -296,7 +296,7 @@
}
"""
import sys
- from _ffi import CDLL, types
+ from _rawffi.alt import CDLL, types
libfoo = CDLL(self.libfoo_name)
sum_xy = libfoo.getfunc('sum_xy_ul', [types.ulong, types.ulong],
types.ulong)
@@ -313,7 +313,7 @@
return x+y;
}
"""
- from _ffi import CDLL, types
+ from _rawffi.alt import CDLL, types
libfoo = CDLL(self.libfoo_name)
sum_xy = libfoo.getfunc('sum_xy_us', [types.ushort, types.ushort],
types.ushort)
@@ -327,7 +327,7 @@
More information about the pypy-commit
mailing list