Author: Philip Jenvey <pjen...@underboss.org>
Branch: py3k
Changeset: r63181:74807be9d93d
Date: 2013-04-09 16:31 -0700
http://bitbucket.org/pypy/pypy/changeset/74807be9d93d/

Log:    merge default

diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -258,6 +258,7 @@
     """)
     libname = 'sqlite3'
     if sys.platform == 'win32':
+        import os
         _libname = os.path.join(os.path.dirname(sys.executable), libname)
         if os.path.exists(_libname + '.dll'):
             libname = _libname
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
@@ -91,7 +91,7 @@
             bufq = len(buf)
         assert 0 <= bufp <= bufq
         substr = buf[bufp:bufq]
-        v = unicodehelper.PyUnicode_DecodeUnicodeEscape(space, substr)
+        v = unicodehelper.decode_unicode_escape(space, substr)
         return space.wrap(v)
 
     assert 0 <= ps <= q
@@ -108,7 +108,7 @@
         if not unicode_literal:
             return space.wrapbytes(substr)
         else:
-            v = unicodehelper.PyUnicode_DecodeUTF8(space, substr)
+            v = unicodehelper.decode_utf8(space, substr)
             return space.wrap(v)
 
     v = PyString_DecodeEscape(space, substr, encoding)
@@ -218,8 +218,8 @@
     # while (s < end && *s != '\\') s++; */ /* inefficient for u".."
     while ps < end and ord(s[ps]) & 0x80:
         ps += 1
-    w_u = space.wrap(unicodehelper.PyUnicode_DecodeUTF8(space, s[pt:ps]))
-    w_v = unicodehelper.PyUnicode_AsEncodedString(space, w_u, 
space.wrap(encoding))
+    w_u = space.wrap(unicodehelper.decode_utf8(space, s[pt:ps]))
+    w_v = unicodehelper.encode(space, w_u, encoding)
     v = space.bytes_w(w_v)
     return v, ps
 
diff --git a/pypy/interpreter/unicodehelper.py 
b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -91,11 +91,12 @@
                                  space.wrap('surrogateescape'))
     return space.wrapbytes(bytes)
 
-def PyUnicode_AsEncodedString(space, w_data, w_encoding):
-    return interp_codecs.encode(space, w_data, w_encoding)
+def encode(space, w_data, encoding=None, errors='strict'):
+    from pypy.objspace.std.unicodetype import encode_object
+    return encode_object(space, w_data, encoding, errors)
 
 # These functions take and return unwrapped rpython strings and unicodes
-def PyUnicode_DecodeUnicodeEscape(space, string):
+def decode_unicode_escape(space, string):
     state = space.fromcache(interp_codecs.CodecState)
     unicodedata_handler = state.get_unicodedata_handler(space)
     result, consumed = runicode.str_decode_unicode_escape(
@@ -104,20 +105,20 @@
         unicodedata_handler=unicodedata_handler)
     return result
 
-def PyUnicode_DecodeRawUnicodeEscape(space, string):
+def decode_raw_unicode_escape(space, string):
     result, consumed = runicode.str_decode_raw_unicode_escape(
         string, len(string), "strict",
         final=True, errorhandler=decode_error_handler(space))
     return result
 
-def PyUnicode_DecodeUTF8(space, string, allow_surrogates=False):
+def decode_utf8(space, string, allow_surrogates=False):
     result, consumed = runicode.str_decode_utf_8(
         string, len(string), "strict",
         final=True, errorhandler=decode_error_handler(space),
         allow_surrogates=allow_surrogates)
     return result
 
-def PyUnicode_EncodeUTF8(space, uni, allow_surrogates=False):
+def encode_utf8(space, uni, allow_surrogates=False):
     return runicode.unicode_encode_utf_8(
         uni, len(uni), "strict",
         errorhandler=encode_error_handler(space),
diff --git a/pypy/module/pyexpat/interp_pyexpat.py 
b/pypy/module/pyexpat/interp_pyexpat.py
--- a/pypy/module/pyexpat/interp_pyexpat.py
+++ b/pypy/module/pyexpat/interp_pyexpat.py
@@ -473,8 +473,8 @@
     # Handlers management
 
     def w_convert(self, space, s):
-        from pypy.interpreter.unicodehelper import PyUnicode_DecodeUTF8
-        return space.wrap(PyUnicode_DecodeUTF8(space, s))
+        from pypy.interpreter.unicodehelper import decode_utf8
+        return space.wrap(decode_utf8(space, s))
 
     def w_convert_charp(self, space, data):
         if data:
diff --git a/pypy/module/test_lib_pypy/cffi_tests/test_function.py 
b/pypy/module/test_lib_pypy/cffi_tests/test_function.py
--- a/pypy/module/test_lib_pypy/cffi_tests/test_function.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/test_function.py
@@ -16,7 +16,7 @@
     """xxx limited to capture at most 512 bytes of output, according
     to the Posix manual."""
 
-    def __init__(self, capture_fd=1):   # stdout, by default
+    def __init__(self, capture_fd):
         self.capture_fd = capture_fd
 
     def __enter__(self):
@@ -109,80 +109,66 @@
         y = lib.TlsFree(x)
         assert y != 0
 
-    def test_puts(self):
+    def test_fputs(self):
+        if not sys.platform.startswith('linux'):
+            py.test.skip("probably no symbol 'stderr' in the lib")
         ffi = FFI(backend=self.Backend())
         ffi.cdef("""
-            int puts(const char *);
-            int fflush(void *);
+            int fputs(const char *, void *);
+            void *stderr;
         """)
         ffi.C = ffi.dlopen(None)
-        ffi.C.puts   # fetch before capturing, for easier debugging
-        with FdWriteCapture() as fd:
-            ffi.C.puts(b"hello")
-            ffi.C.puts(b"  world")
-            ffi.C.fflush(ffi.NULL)
+        ffi.C.fputs   # fetch before capturing, for easier debugging
+        with FdWriteCapture(2) as fd:
+            ffi.C.fputs(b"hello\n", ffi.C.stderr)
+            ffi.C.fputs(b"  world\n", ffi.C.stderr)
         res = fd.getvalue()
         assert res == b'hello\n  world\n'
 
-    def test_puts_without_const(self):
+    def test_fputs_without_const(self):
+        if not sys.platform.startswith('linux'):
+            py.test.skip("probably no symbol 'stderr' in the lib")
         ffi = FFI(backend=self.Backend())
         ffi.cdef("""
-            int puts(char *);
-            int fflush(void *);
+            int fputs(char *, void *);
+            void *stderr;
         """)
         ffi.C = ffi.dlopen(None)
-        ffi.C.puts   # fetch before capturing, for easier debugging
-        with FdWriteCapture() as fd:
-            ffi.C.puts(b"hello")
-            ffi.C.puts(b"  world")
-            ffi.C.fflush(ffi.NULL)
+        ffi.C.fputs   # fetch before capturing, for easier debugging
+        with FdWriteCapture(2) as fd:
+            ffi.C.fputs(b"hello\n", ffi.C.stderr)
+            ffi.C.fputs(b"  world\n", ffi.C.stderr)
         res = fd.getvalue()
         assert res == b'hello\n  world\n'
 
-    def test_fputs(self):
+    def test_vararg(self):
         if not sys.platform.startswith('linux'):
-            py.test.skip("probably no symbol 'stdout' in the lib")
+            py.test.skip("probably no symbol 'stderr' in the lib")
         ffi = FFI(backend=self.Backend())
         ffi.cdef("""
-            int fputs(const char *, void *);
-            void *stdout, *stderr;
+           int fprintf(void *, const char *format, ...);
+           void *stderr;
         """)
         ffi.C = ffi.dlopen(None)
         with FdWriteCapture(2) as fd:
-            ffi.C.fputs(b"hello from stderr\n", ffi.C.stderr)
+            ffi.C.fprintf(ffi.C.stderr, b"hello with no arguments\n")
+            ffi.C.fprintf(ffi.C.stderr,
+                          b"hello, %s!\n", ffi.new("char[]", b"world"))
+            ffi.C.fprintf(ffi.C.stderr,
+                          ffi.new("char[]", b"hello, %s!\n"),
+                          ffi.new("char[]", b"world2"))
+            ffi.C.fprintf(ffi.C.stderr,
+                          b"hello int %d long %ld long long %lld\n",
+                          ffi.cast("int", 42),
+                          ffi.cast("long", 84),
+                          ffi.cast("long long", 168))
+            ffi.C.fprintf(ffi.C.stderr, b"hello %p\n", ffi.NULL)
         res = fd.getvalue()
-        assert res == b'hello from stderr\n'
-
-    def test_vararg(self):
-        ffi = FFI(backend=self.Backend())
-        ffi.cdef("""
-           int printf(const char *format, ...);
-           int fflush(void *);
-        """)
-        ffi.C = ffi.dlopen(None)
-        with FdWriteCapture() as fd:
-            ffi.C.printf(b"hello with no arguments\n")
-            ffi.C.printf(b"hello, %s!\n", ffi.new("char[]", b"world"))
-            ffi.C.printf(ffi.new("char[]", b"hello, %s!\n"),
-                         ffi.new("char[]", b"world2"))
-            ffi.C.printf(b"hello int %d long %ld long long %lld\n",
-                         ffi.cast("int", 42),
-                         ffi.cast("long", 84),
-                         ffi.cast("long long", 168))
-            ffi.C.printf(b"hello %p\n", ffi.NULL)
-            ffi.C.fflush(ffi.NULL)
-        res = fd.getvalue()
-        if sys.platform == 'win32':
-            NIL = b"00000000"
-        elif sys.platform.startswith(('linux', 'gnu')):
-            NIL = b"(nil)"
-        else:
-            NIL = b"0x0"    # OS/X at least
         assert res == (b"hello with no arguments\n"
                        b"hello, world!\n"
                        b"hello, world2!\n"
                        b"hello int 42 long 84 long long 168\n"
-                       b"hello " + NIL + b"\n")
+                       b"hello (nil)\n")
 
     def test_must_specify_type_of_vararg(self):
         ffi = FFI(backend=self.Backend())
@@ -216,17 +202,18 @@
         res = fptr(b"Hello")
         assert res == 42
         #
+        if not sys.platform.startswith('linux'):
+            py.test.skip("probably no symbol 'stderr' in the lib")
         ffi.cdef("""
-            int puts(const char *);
-            int fflush(void *);
+            int fputs(const char *, void *);
+            void *stderr;
         """)
         ffi.C = ffi.dlopen(None)
-        fptr = ffi.cast("int(*)(const char *txt)", ffi.C.puts)
-        assert fptr == ffi.C.puts
-        assert repr(fptr).startswith("<cdata 'int(*)(char *)' 0x")
-        with FdWriteCapture() as fd:
-            fptr(b"world")
-            ffi.C.fflush(ffi.NULL)
+        fptr = ffi.cast("int(*)(const char *txt, void *)", ffi.C.fputs)
+        assert fptr == ffi.C.fputs
+        assert repr(fptr).startswith("<cdata 'int(*)(char *, void *)' 0x")
+        with FdWriteCapture(2) as fd:
+            fptr(b"world\n", ffi.C.stderr)
         res = fd.getvalue()
         assert res == b'world\n'
 
diff --git a/pypy/objspace/std/marshal_impl.py 
b/pypy/objspace/std/marshal_impl.py
--- a/pypy/objspace/std/marshal_impl.py
+++ b/pypy/objspace/std/marshal_impl.py
@@ -387,14 +387,13 @@
 register(TYPE_CODE, unmarshal_pycode)
 
 def marshal_w__Unicode(space, w_unicode, m):
-    s = unicodehelper.PyUnicode_EncodeUTF8(space, space.unicode_w(w_unicode),
-                                           allow_surrogates=True)
+    s = unicodehelper.encode_utf8(space, space.unicode_w(w_unicode),
+                                  allow_surrogates=True)
     m.atom_str(TYPE_UNICODE, s)
 
 def unmarshal_Unicode(space, u, tc):
     return space.wrap(
-        unicodehelper.PyUnicode_DecodeUTF8(space, u.get_str(),
-                                           allow_surrogates=True))
+        unicodehelper.decode_utf8(space, u.get_str(), allow_surrogates=True))
 register(TYPE_UNICODE, unmarshal_Unicode)
 
 app = gateway.applevel(r'''
diff --git a/rpython/jit/backend/arm/test/test_regalloc_mov.py 
b/rpython/jit/backend/arm/test/test_regalloc_mov.py
--- a/rpython/jit/backend/arm/test/test_regalloc_mov.py
+++ b/rpython/jit/backend/arm/test/test_regalloc_mov.py
@@ -174,8 +174,11 @@
         s = stack(8191)
         r6 = r(6)
         expected = [
-                    mi('gen_load_int', 'helper', s.value, cond=AL),
-                    mi('LDR_rr', r6.value, fp.value, 'helper', cond=AL)]
+                   mi('PUSH', [lr.value], cond=AL),
+                   mi('gen_load_int', lr.value, 32940, cond=AL),
+                   mi('LDR_rr', r6.value, fp.value, lr.value, cond=AL),
+                   mi('POP', [lr.value], cond=AL),
+        ]
         self.mov(s, r6, expected)
 
     def test_mov_float_imm_to_vfp_reg(self):
@@ -422,8 +425,11 @@
 
     def test_push_big_stack(self):
         s = stack(1025)
-        e = [mi('gen_load_int', 'helper', s.value, cond=AL),
-            mi('LDR_rr', ip.value, fp.value, 'helper', cond=AL),
+        e = [
+            mi('PUSH', [lr.value], cond=AL),
+            mi('gen_load_int', lr.value, s.value, cond=AL),
+            mi('LDR_rr', ip.value, fp.value, lr.value, cond=AL),
+            mi('POP', [lr.value], cond=AL),
             mi('PUSH', [ip.value], cond=AL)
             ]
         self.push(s, e)
@@ -444,9 +450,11 @@
     def test_push_large_stackfloat(self):
         sf = stack_float(100)
         e = [
-            mi('gen_load_int', 'helper', sf.value, cond=AL),
-            mi('ADD_rr', 'helper', fp.value, 'helper', cond=AL),
-            mi('VLDR', vfp_ip.value, 'helper', cond=AL),
+            mi('PUSH', [ip.value], cond=AL),
+            mi('gen_load_int', ip.value, sf.value, cond=AL),
+            mi('ADD_rr', ip.value, fp.value, ip.value, cond=AL),
+            mi('VLDR', vfp_ip.value, ip.value, cond=AL),
+            mi('POP', [ip.value], cond=AL),
             mi('VPUSH', [vfp_ip.value], cond=AL),
         ]
         self.push(sf, e)
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to