Author: Philip Jenvey <[email protected]>
Branch: py3k-stdlib-2.7.6-merge
Changeset: r69873:41b16b2d6913
Date: 2014-03-11 13:21 -0700
http://bitbucket.org/pypy/pypy/changeset/41b16b2d6913/

Log:    merge default

diff --git a/lib-python/2.7/test/test_zipfile.py 
b/lib-python/2.7/test/test_zipfile.py
--- a/lib-python/2.7/test/test_zipfile.py
+++ b/lib-python/2.7/test/test_zipfile.py
@@ -19,7 +19,7 @@
 from unittest import skipUnless
 
 from test.test_support import TESTFN, TESTFN_UNICODE, TESTFN_ENCODING, \
-                              run_unittest, findfile, unlink
+                              run_unittest, findfile, unlink, rmtree
 try:
     TESTFN_UNICODE.encode(TESTFN_ENCODING)
 except (UnicodeError, TypeError):
@@ -365,7 +365,8 @@
         produces the expected result."""
         with zipfile.ZipFile(TESTFN2, "w") as zipfp:
             zipfp.write(TESTFN)
-            self.assertEqual(zipfp.read(TESTFN), open(TESTFN).read())
+            with open(TESTFN,'r') as fid:
+                self.assertEqual(zipfp.read(TESTFN), fid.read())
 
     @skipUnless(zlib, "requires zlib")
     def test_per_file_compression(self):
@@ -404,11 +405,12 @@
                 self.assertEqual(writtenfile, correctfile)
 
                 # make sure correct data is in correct file
-                self.assertEqual(fdata, open(writtenfile, "rb").read())
+                with open(writtenfile, "rb") as fid:
+                    self.assertEqual(fdata, fid.read())
                 os.remove(writtenfile)
 
         # remove the test file subdirectories
-        shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
+        rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
 
     def test_extract_all(self):
         with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
@@ -420,11 +422,12 @@
             for fpath, fdata in SMALL_TEST_DATA:
                 outfile = os.path.join(os.getcwd(), fpath)
 
-                self.assertEqual(fdata, open(outfile, "rb").read())
+                with open(outfile, "rb") as fid:
+                    self.assertEqual(fdata, fid.read())
                 os.remove(outfile)
 
         # remove the test file subdirectories
-        shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
+        rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
 
     def check_file(self, filename, content):
         self.assertTrue(os.path.isfile(filename))
@@ -509,12 +512,12 @@
                 self.assertEqual(writtenfile, correctfile,
                                  msg="extract %r" % arcname)
             self.check_file(correctfile, content)
-            shutil.rmtree('target')
+            rmtree('target')
 
             with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
                 zipfp.extractall(targetpath)
             self.check_file(correctfile, content)
-            shutil.rmtree('target')
+            rmtree('target')
 
             correctfile = os.path.join(os.getcwd(), *fixedname.split('/'))
 
@@ -523,12 +526,12 @@
                 self.assertEqual(writtenfile, correctfile,
                                  msg="extract %r" % arcname)
             self.check_file(correctfile, content)
-            shutil.rmtree(fixedname.split('/')[0])
+            rmtree(fixedname.split('/')[0])
 
             with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
                 zipfp.extractall()
             self.check_file(correctfile, content)
-            shutil.rmtree(fixedname.split('/')[0])
+            rmtree(fixedname.split('/')[0])
 
             os.remove(TESTFN2)
 
@@ -773,11 +776,12 @@
             self.assertNotIn('mod2.txt', names)
 
         finally:
-            shutil.rmtree(TESTFN2)
+            rmtree(TESTFN2)
 
     def test_write_non_pyfile(self):
         with zipfile.PyZipFile(TemporaryFile(), "w") as zipfp:
-            open(TESTFN, 'w').write('most definitely not a python file')
+            with open(TESTFN, 'w') as fid:
+                fid.write('most definitely not a python file')
             self.assertRaises(RuntimeError, zipfp.writepy, TESTFN)
             os.remove(TESTFN)
 
@@ -940,8 +944,9 @@
         self.assertRaises(RuntimeError, zipf.open, "foo.txt")
         self.assertRaises(RuntimeError, zipf.testzip)
         self.assertRaises(RuntimeError, zipf.writestr, "bogus.txt", "bogus")
-        open(TESTFN, 'w').write('zipfile test data')
-        self.assertRaises(RuntimeError, zipf.write, TESTFN)
+        with open(TESTFN, 'w') as fid:
+            fid.write('zipfile test data')
+            self.assertRaises(RuntimeError, zipf.write, TESTFN)
 
     def test_bad_constructor_mode(self):
         """Check that bad modes passed to ZipFile constructor are caught."""
@@ -1126,6 +1131,7 @@
             pass
         try:
             zipf = zipfile.ZipFile(TESTFN, mode="r")
+            zipf.close()
         except zipfile.BadZipfile:
             self.fail("Unable to create empty ZIP file in 'w' mode")
 
@@ -1133,6 +1139,7 @@
             pass
         try:
             zipf = zipfile.ZipFile(TESTFN, mode="r")
+            zipf.close()
         except:
             self.fail("Unable to create empty ZIP file in 'a' mode")
 
@@ -1329,12 +1336,11 @@
         # Verify that (when the ZipFile is in control of creating file objects)
         # multiple open() calls can be made without interfering with each 
other.
         with zipfile.ZipFile(TESTFN2, mode="r") as zipf:
-            zopen1 = zipf.open('ones')
-            zopen2 = zipf.open('ones')
-            data1 = zopen1.read(500)
-            data2 = zopen2.read(500)
-            data1 += zopen1.read(500)
-            data2 += zopen2.read(500)
+            with zipf.open('ones') as zopen1, zipf.open('ones') as zopen2:
+                data1 = zopen1.read(500)
+                data2 = zopen2.read(500)
+                data1 += zopen1.read(500)
+                data2 += zopen2.read(500)
             self.assertEqual(data1, data2)
 
     def test_different_file(self):
@@ -1369,8 +1375,8 @@
                 zipf.read('ones')
                 with zipf.open('ones') as zopen1:
                     pass
-        for x in range(10):
-            self.assertLess(open('/dev/null').fileno(), 100)
+        with open(os.devnull) as f:
+            self.assertLess(f.fileno(), 100)
 
     def tearDown(self):
         unlink(TESTFN2)
@@ -1394,12 +1400,12 @@
 
     def test_store_dir(self):
         os.mkdir(os.path.join(TESTFN2, "x"))
-        zipf = zipfile.ZipFile(TESTFN, "w")
-        zipf.write(os.path.join(TESTFN2, "x"), "x")
-        self.assertTrue(zipf.filelist[0].filename.endswith("x/"))
+        with zipfile.ZipFile(TESTFN, "w") as zipf:
+            zipf.write(os.path.join(TESTFN2, "x"), "x")
+            self.assertTrue(zipf.filelist[0].filename.endswith("x/"))
 
     def tearDown(self):
-        shutil.rmtree(TESTFN2)
+        rmtree(TESTFN2)
         if os.path.exists(TESTFN):
             unlink(TESTFN)
 
@@ -1413,7 +1419,8 @@
         for n, s in enumerate(self.seps):
             self.arcdata[s] = s.join(self.line_gen) + s
             self.arcfiles[s] = '%s-%d' % (TESTFN, n)
-            open(self.arcfiles[s], "wb").write(self.arcdata[s])
+            with open(self.arcfiles[s], "wb") as fid:
+                fid.write(self.arcdata[s])
 
     def make_test_archive(self, f, compression):
         # Create the ZIP archive
@@ -1482,8 +1489,9 @@
         # Read the ZIP archive
         with zipfile.ZipFile(f, "r") as zipfp:
             for sep, fn in self.arcfiles.items():
-                for line, zipline in zip(self.line_gen, zipfp.open(fn, "rU")):
-                    self.assertEqual(zipline, line + '\n')
+                with zipfp.open(fn, "rU") as fid:
+                    for line, zipline in zip(self.line_gen, fid):
+                        self.assertEqual(zipline, line + '\n')
 
     def test_read_stored(self):
         for f in (TESTFN2, TemporaryFile(), StringIO()):
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
@@ -328,17 +328,16 @@
                 raise ValueError(
                     "native COM method call without 'this' parameter"
                     )
-            thisvalue = args.pop(0)
+            thisvalue = args[0]
             thisarg = cast(thisvalue, POINTER(POINTER(c_void_p)))
             keepalives, newargs, argtypes, outargs, errcheckargs = (
-                        self._convert_args(argtypes, args, kwargs))
-            args.insert(0, thisvalue)
+                self._convert_args(argtypes, args[1:], kwargs))
             newargs.insert(0, thisvalue.value)
             argtypes.insert(0, c_void_p)
         else:
             thisarg = None
             keepalives, newargs, argtypes, outargs, errcheckargs = (
-                        self._convert_args(argtypes, args, kwargs))
+                self._convert_args(argtypes, args, kwargs))
 
         funcptr = self._getfuncptr(argtypes, self._restype_, thisarg)
         result = self._call_funcptr(funcptr, *newargs)
diff --git a/pypy/module/__builtin__/test/test_builtin.py 
b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -489,24 +489,24 @@
     def test_compile_error_message(self):
         import re
         compile('# -*- coding: iso-8859-15 -*-\n', 'dummy', 'exec')
-        compile('\xef\xbb\xbf\n', 'dummy', 'exec')
-        compile('\xef\xbb\xbf# -*- coding: utf-8 -*-\n', 'dummy', 'exec')
+        compile(b'\xef\xbb\xbf\n', 'dummy', 'exec')
+        compile(b'\xef\xbb\xbf# -*- coding: utf-8 -*-\n', 'dummy', 'exec')
         exc = raises(SyntaxError, compile,
-            '# -*- coding: fake -*-\n', 'dummy', 'exec')
-        assert 'fake' in exc.value[0]
+            b'# -*- coding: fake -*-\n', 'dummy', 'exec')
+        assert 'fake' in str(exc.value)
         exc = raises(SyntaxError, compile,
-            '\xef\xbb\xbf# -*- coding: iso-8859-15 -*-\n', 'dummy', 'exec')
-        assert 'iso-8859-15' in exc.value[0]
-        assert 'BOM' in exc.value[0]
+            b'\xef\xbb\xbf# -*- coding: iso-8859-15 -*-\n', 'dummy', 'exec')
+        assert 'iso-8859-15' in str(exc.value), str(exc.value)
+        assert 'BOM' in str(exc.value)
         exc = raises(SyntaxError, compile,
-            '\xef\xbb\xbf# -*- coding: fake -*-\n', 'dummy', 'exec')
-        assert 'fake' in exc.value[0]
-        assert 'BOM' in exc.value[0]
+            b'\xef\xbb\xbf# -*- coding: fake -*-\n', 'dummy', 'exec')
+        assert 'fake' in str(exc.value)
+        assert 'BOM' in str(exc.value)
 
     def test_unicode_compile(self):
         try:
             compile(u'-', '?', 'eval')
-        except SyntaxError, e:
+        except SyntaxError as e:
             assert e.lineno == 1
 
     def test_unicode_encoding_compile(self):
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
@@ -1,7 +1,7 @@
 from rpython.rlib import jit
 from rpython.rlib.objectmodel import we_are_translated
 from rpython.rlib.rstring import UnicodeBuilder
-from rpython.rlib.runicode import UNICHR
+from rpython.rlib.runicode import code_to_unichr, MAXUNICODE
 
 from pypy.interpreter.error import OperationError, oefmt
 from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
@@ -247,9 +247,15 @@
         builder = UnicodeBuilder()
         pos = start
         while pos < end:
-            ch = obj[pos]
+            code = ord(obj[pos])
+            if (MAXUNICODE == 0xffff and 0xD800 <= code <= 0xDBFF and
+                       pos + 1 < end and 0xDC00 <= ord(obj[pos+1]) <= 0xDFFF):
+                code = (code & 0x03FF) << 10
+                code |= ord(obj[pos+1]) & 0x03FF
+                code += 0x10000
+                pos += 1
             builder.append(u"&#")
-            builder.append(unicode(str(ord(ch))))
+            builder.append(unicode(str(code)))
             builder.append(u";")
             pos += 1
         return space.newtuple([space.wrap(builder.build()), w_end])
@@ -658,7 +664,7 @@
             if not 0 <= x <= 0x10FFFF:
                 raise oefmt(space.w_TypeError,
                     "character mapping must be in range(0x110000)")
-            return UNICHR(x)
+            return code_to_unichr(x)
         elif space.is_w(w_ch, space.w_None):
             # Charmap may return None
             return errorchar
diff --git a/pypy/module/_io/test/test_textio.py 
b/pypy/module/_io/test/test_textio.py
--- a/pypy/module/_io/test/test_textio.py
+++ b/pypy/module/_io/test/test_textio.py
@@ -339,7 +339,7 @@
 
     def test_flush_error_on_close(self):
         import _io
-        txt = _io.TextIOWrapper(_io.BytesIO(""), encoding="ascii")
+        txt = _io.TextIOWrapper(_io.BytesIO(b""), encoding="ascii")
         def bad_flush():
             raise IOError()
         txt.flush = bad_flush
diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -449,6 +449,11 @@
 
 def build_exported_objects():
     # Standard exceptions
+    # PyExc_BaseException, PyExc_Exception, PyExc_ValueError, PyExc_KeyError,
+    # PyExc_IndexError, PyExc_IOError, PyExc_OSError, PyExc_TypeError,
+    # PyExc_AttributeError, PyExc_OverflowError, PyExc_ImportError,
+    # PyExc_NameError, PyExc_MemoryError, PyExc_RuntimeError,
+    # PyExc_UnicodeEncodeError, PyExc_UnicodeDecodeError, ...
     for exc_name in exceptions.Module.interpleveldefs.keys():
         GLOBALS['PyExc_' + exc_name] = (
             'PyTypeObject*',
@@ -456,39 +461,40 @@
 
     # Common types with their own struct
     for cpyname, pypyexpr in {
-        "Type": "space.w_type",
-        "String": "space.w_str",
-        "Unicode": "space.w_unicode",
-        "Dict": "space.w_dict",
-        "Tuple": "space.w_tuple",
-        "List": "space.w_list",
-        "Set": "space.w_set",
-        "FrozenSet": "space.w_frozenset",
-        "Int": "space.w_int",
-        "Bool": "space.w_bool",
-        "Float": "space.w_float",
-        "Long": "space.w_int",
-        "Complex": "space.w_complex",
-        "ByteArray": "space.w_bytearray",
-        "MemoryView": "space.gettypeobject(W_MemoryView.typedef)",
-        "Array": "space.gettypeobject(W_NDimArray.typedef)",
-        "BaseObject": "space.w_object",
-        'None': 'space.type(space.w_None)',
-        'NotImplemented': 'space.type(space.w_NotImplemented)',
-        'Cell': 'space.gettypeobject(Cell.typedef)',
-        'Module': 'space.gettypeobject(Module.typedef)',
-        'Property': 'space.gettypeobject(W_Property.typedef)',
-        'Slice': 'space.gettypeobject(W_SliceObject.typedef)',
-        'StaticMethod': 'space.gettypeobject(StaticMethod.typedef)',
-        'CFunction': 
'space.gettypeobject(cpyext.methodobject.W_PyCFunctionObject.typedef)',
-        'WrapperDescr': 
'space.gettypeobject(cpyext.methodobject.W_PyCMethodObject.typedef)',
-        'InstanceMethod': 
'space.gettypeobject(cpyext.classobject.InstanceMethod.typedef)',
+        "PyType_Type": "space.w_type",
+        "PyString_Type": "space.w_str",
+        "PyUnicode_Type": "space.w_unicode",
+        "PyDict_Type": "space.w_dict",
+        "PyTuple_Type": "space.w_tuple",
+        "PyList_Type": "space.w_list",
+        "PySet_Type": "space.w_set",
+        "PyFrozenSet_Type": "space.w_frozenset",
+        "PyInt_Type": "space.w_int",
+        "PyBool_Type": "space.w_bool",
+        "PyFloat_Type": "space.w_float",
+        "PyLong_Type": "space.w_int",
+        "PyComplex_Type": "space.w_complex",
+        "PyByteArray_Type": "space.w_bytearray",
+        "PyMemoryView_Type": "space.gettypeobject(W_MemoryView.typedef)",
+        "PyArray_Type": "space.gettypeobject(W_NDimArray.typedef)",
+        "PyBaseObject_Type": "space.w_object",
+        'PyNone_Type': 'space.type(space.w_None)',
+        'PyNotImplemented_Type': 'space.type(space.w_NotImplemented)',
+        'PyCell_Type': 'space.gettypeobject(Cell.typedef)',
+        'PyModule_Type': 'space.gettypeobject(Module.typedef)',
+        'PyProperty_Type': 'space.gettypeobject(W_Property.typedef)',
+        'PySlice_Type': 'space.gettypeobject(W_SliceObject.typedef)',
+        'PyStaticMethod_Type': 'space.gettypeobject(StaticMethod.typedef)',
+        'PyCFunction_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCFunctionObject.typedef)',
+        'PyWrapperDescr_Type': 
'space.gettypeobject(cpyext.methodobject.W_PyCMethodObject.typedef)'
+        'PyInstanceMethod_Type': 
'space.gettypeobject(cpyext.classobject.InstanceMethod.typedef)',
         }.items():
-        GLOBALS['Py%s_Type#' % (cpyname, )] = ('PyTypeObject*', pypyexpr)
+        GLOBALS['%s#' % (cpyname, )] = ('PyTypeObject*', pypyexpr)
 
-    for cpyname in 'Method List Long Dict Tuple'.split():
-        FORWARD_DECLS.append('typedef struct { PyObject_HEAD } '
-                             'Py%sObject' % (cpyname, ))
+    for cpyname in '''PyMethodObject PyListObject PyLongObject
+                      PyDictObject PyTupleObject'''.split():
+        FORWARD_DECLS.append('typedef struct { PyObject_HEAD } %s'
+                             % (cpyname, ))
 build_exported_objects()
 
 def get_structtype_for_ctype(ctype):
diff --git a/pypy/module/cpyext/test/foo3.c b/pypy/module/cpyext/test/foo3.c
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/test/foo3.c
@@ -0,0 +1,73 @@
+#include <Python.h>
+#include <stdio.h>
+
+PyObject* foo3type_tp_new(PyTypeObject* metatype, PyObject* args, PyObject* 
kwds)
+{
+    printf("in foo3type_tp_new, preprocessing...\n");
+    PyObject* newType = PyType_Type.tp_new(metatype, args, kwds);
+    printf("in foo3type_tp_new, postprocessing...\n");
+    return newType;
+}
+
+PyTypeObject Foo3Type_Type = {
+    PyVarObject_HEAD_INIT(0, 0)
+    /*tp_name*/             "Foo3.Type",
+    /*tp_basicsize*/        sizeof(PyTypeObject),
+    /*tp_itemsize*/         0,
+    /*tp_dealloc*/          0,
+    /*tp_print*/            0,
+    /*tp_getattr*/          0,
+    /*tp_setattr*/          0,
+    /*tp_compare*/          0,
+    /*tp_repr*/             0,
+    /*tp_as_number*/        0,
+    /*tp_as_sequence*/      0,
+    /*tp_as_mapping*/       0,
+    /*tp_hash*/             0,
+    /*tp_call*/             0,
+    /*tp_str*/              0,
+    /*tp_getattro*/         0,
+    /*tp_setattro*/         0,
+    /*tp_as_buffer*/        0,
+    /*tp_flags*/            Py_TPFLAGS_DEFAULT,
+    /*tp_doc*/              0,
+    /*tp_traverse*/         0,
+    /*tp_clear*/            0,
+    /*tp_richcompare*/      0,
+    /*tp_weaklistoffset*/   0,
+    /*tp_iter*/             0,
+    /*tp_iternext*/         0,
+    /*tp_methods*/          0,
+    /*tp_members*/          0,
+    /*tp_getset*/           0,
+    /*tp_base*/             0,         //  set to &PyType_Type in module init 
function (why can it not be done here?)
+    /*tp_dict*/             0,
+    /*tp_descr_get*/        0,
+    /*tp_descr_set*/        0,
+    /*tp_dictoffset*/       0,
+    /*tp_init*/             0,
+    /*tp_alloc*/            0,
+    /*tp_new*/              foo3type_tp_new,
+    /*tp_free*/             0,
+    /*tp_is_gc*/            0,
+    /*tp_bases*/            0,
+    /*tp_mro*/              0,
+    /*tp_cache*/            0,
+    /*tp_subclasses*/       0,
+    /*tp_weaklist*/         0
+};
+
+static PyMethodDef sbkMethods[] = {{NULL, NULL, 0, NULL}};
+
+#ifdef _WIN32
+       __declspec(dllexport) void              // PyModINIT_FUNC is broken on 
PyPy/Windows
+#else
+       PyMODINIT_FUNC
+#endif
+initfoo3(void)
+{
+       PyObject* mod = Py_InitModule("Foo3", sbkMethods);
+       Foo3Type_Type.tp_base = &PyType_Type;
+       PyType_Ready(&Foo3Type_Type);
+       PyModule_AddObject(mod, "Type", (PyObject*)&Foo3Type_Type);
+}
diff --git a/pypy/module/cpyext/test/test_typeobject.py 
b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -580,3 +580,9 @@
         assert bool(module.newInt(1))
         assert bool(module.newInt(-1))
         raises(ValueError, bool, module.newInt(-42))
+
+    def test_tp_new_in_subclass_of_type(self):
+        skip("BROKEN")
+        module = self.import_module(name='foo3')
+        print 'calling module.Type()...'
+        module.Type("X", (object,), {})
diff --git a/pypy/module/fcntl/test/test_fcntl.py 
b/pypy/module/fcntl/test/test_fcntl.py
--- a/pypy/module/fcntl/test/test_fcntl.py
+++ b/pypy/module/fcntl/test/test_fcntl.py
@@ -36,15 +36,15 @@
         raises(TypeError, fcntl.fcntl, "foo")
         raises(TypeError, fcntl.fcntl, f, "foo")
         exc = raises(TypeError, fcntl.fcntl, F("foo"), 1)
-        assert exc.value[0] == 'fileno() returned a non-integer'
+        assert str(exc.value) == 'fileno() returned a non-integer'
         exc = raises(ValueError, fcntl.fcntl, 2147483647 + 1, 1, 0)
-        assert exc.value[0] == 'file descriptor cannot be a negative integer 
(-1)'
+        assert str(exc.value) == 'file descriptor cannot be a negative integer 
(-1)'
         exc = raises(ValueError, fcntl.fcntl, F(2147483647 + 1), 1, 0)
-        assert exc.value[0] == 'file descriptor cannot be a negative integer 
(-1)'
+        assert str(exc.value) == 'file descriptor cannot be a negative integer 
(-1)'
         exc = raises(ValueError, fcntl.fcntl, -2147483648 - 1, 1, 0)
-        assert exc.value[0] == 'file descriptor cannot be a negative integer 
(-1)'
+        assert str(exc.value) == 'file descriptor cannot be a negative integer 
(-1)'
         exc = raises(ValueError, fcntl.fcntl, F(-2147483648 - 1), 1, 0)
-        assert exc.value[0] == 'file descriptor cannot be a negative integer 
(-1)'
+        assert str(exc.value) == 'file descriptor cannot be a negative integer 
(-1)'
         raises(ValueError, fcntl.fcntl, -1, 1, 0)
         raises(ValueError, fcntl.fcntl, F(-1), 1, 0)
         raises(ValueError, fcntl.fcntl, F(int(-1)), 1, 0)
diff --git a/pypy/module/micronumpy/sort.py b/pypy/module/micronumpy/sort.py
--- a/pypy/module/micronumpy/sort.py
+++ b/pypy/module/micronumpy/sort.py
@@ -1,4 +1,4 @@
-from pypy.interpreter.error import OperationError, oefmt
+from pypy.interpreter.error import oefmt
 from rpython.rlib.listsort import make_timsort_class
 from rpython.rlib.objectmodel import specialize
 from rpython.rlib.rarithmetic import widen
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1738,7 +1738,10 @@
             self._store(storage, i, offset, box, width)
 
 class UnicodeType(FlexibleType):
-    T = lltype.UniChar
+    T = lltype.Char
+
+    def get_element_size(self):
+        return 4  # always UTF-32
 
     @jit.unroll_safe
     def coerce(self, space, dtype, w_item):
diff --git a/pypy/module/mmap/test/test_mmap.py 
b/pypy/module/mmap/test/test_mmap.py
--- a/pypy/module/mmap/test/test_mmap.py
+++ b/pypy/module/mmap/test/test_mmap.py
@@ -837,6 +837,6 @@
                 m.close()
                 assert False, "should not have been able to mmap empty file"
             except ValueError as e:
-                assert e.message == "cannot mmap an empty file"
+                assert str(e) == "cannot mmap an empty file"
             except BaseException as e:
                 assert False, "unexpected exception: " + str(e)
diff --git a/pypy/module/pwd/test/test_pwd.py b/pypy/module/pwd/test/test_pwd.py
--- a/pypy/module/pwd/test/test_pwd.py
+++ b/pypy/module/pwd/test/test_pwd.py
@@ -24,7 +24,7 @@
         assert type(pw.pw_gid) is int
         raises(TypeError, pwd.getpwuid)
         raises(TypeError, pwd.getpwuid, 3.14)
-        raises(KeyError, pwd.getpwuid, sys.maxint)
+        raises(KeyError, pwd.getpwuid, sys.maxsize)
         # -1 is allowed, cast to uid_t
         exc = raises(KeyError, pwd.getpwuid, -1)
         m = re.match('getpwuid\(\): uid not found: ([0-9]+)', exc.value[0])
diff --git a/pypy/module/rctime/interp_time.py 
b/pypy/module/rctime/interp_time.py
--- a/pypy/module/rctime/interp_time.py
+++ b/pypy/module/rctime/interp_time.py
@@ -356,14 +356,16 @@
         seconds = pytime.time()
     else:
         seconds = space.float_w(w_seconds)
-    try:
-        seconds = ovfcheck_float_to_int(seconds)
-        t = rffi.r_time_t(seconds)
-        if rffi.cast(lltype.Signed, t) != seconds:
-            raise OverflowError
-    except OverflowError:
+    #
+    t = rffi.cast(rffi.TIME_T, seconds)
+    #
+    # Logic from CPython: How much info did we lose?  We assume that
+    # time_t is an integral type.  If we lost a second or more, the
+    # input doesn't fit in a time_t; call it an error.
+    diff = seconds - rffi.cast(lltype.Float, t)
+    if diff <= -1.0 or diff >= 1.0:
         raise OperationError(space.w_ValueError,
-                             space.wrap("time argument too large"))
+                      space.wrap("timestamp out of range for platform time_t"))
     return t
 
 def _tm_to_tuple(space, t):
diff --git a/pypy/module/rctime/test/test_rctime.py 
b/pypy/module/rctime/test/test_rctime.py
--- a/pypy/module/rctime/test/test_rctime.py
+++ b/pypy/module/rctime/test/test_rctime.py
@@ -68,6 +68,8 @@
         assert 0 <= (t1 - t0) < 1.2
         t = rctime.time()
         assert rctime.gmtime(t) == rctime.gmtime(t)
+        raises(ValueError, rctime.gmtime, 2**64)
+        raises(ValueError, rctime.gmtime, -2**64)
 
     def test_localtime(self):
         import time as rctime
diff --git a/pypy/module/select/test/test_select.py 
b/pypy/module/select/test/test_select.py
--- a/pypy/module/select/test/test_select.py
+++ b/pypy/module/select/test/test_select.py
@@ -219,15 +219,15 @@
         pollster = select.poll()
         pollster.register(1)
         exc = raises(OverflowError, pollster.register, 0, 32768) # SHRT_MAX + 1
-        assert exc.value[0] == 'signed short integer is greater than maximum'
+        assert str(exc.value) == 'signed short integer is greater than maximum'
         exc = raises(OverflowError, pollster.register, 0, -32768 - 1)
-        assert exc.value[0] == 'signed short integer is less than minimum'
+        assert str(exc.value) == 'signed short integer is less than minimum'
         raises(OverflowError, pollster.register, 0, 65535) # USHRT_MAX + 1
         raises(OverflowError, pollster.poll, 2147483648) # INT_MAX +  1
         raises(OverflowError, pollster.poll, -2147483648 - 1)
         raises(OverflowError, pollster.poll, 4294967296) # UINT_MAX + 1
         exc = raises(TypeError, pollster.poll, '123')
-        assert exc.value[0] == 'timeout must be an integer or None'
+        assert str(exc.value) == 'timeout must be an integer or None'
 
 
 class AppTestSelectWithPipes(_AppTestSelect):
@@ -277,7 +277,7 @@
                     pollster.unregister(fd)
                 pollster.register(w, select.POLLOUT)
                 exc = raises(RuntimeError, pollster.poll)
-                assert exc.value[0] == 'concurrent poll() invocation'
+                assert str(exc.value) == 'concurrent poll() invocation'
             finally:
                 # and make the call to poll() from the thread return
                 os.write(w, b'spam')
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
@@ -36,11 +36,13 @@
         return self._value
 
 lib_m = 'm'
+has_sinf = True
 if sys.platform == 'win32':
     #there is a small chance this fails on Mingw via environ $CC
     import distutils.ccompiler
     if distutils.ccompiler.get_default_compiler() == 'msvc':
         lib_m = 'msvcrt'
+        has_sinf = False
 
 class TestFunction(object):
     Backend = CTypesBackend
@@ -55,6 +57,8 @@
         assert x == math.sin(1.23)
 
     def test_sinf(self):
+        if not has_sinf:
+            py.test.skip("sinf not available")
         ffi = FFI(backend=self.Backend())
         ffi.cdef("""
             float sinf(float x);
diff --git a/pypy/module/test_lib_pypy/test_sqlite3.py 
b/pypy/module/test_lib_pypy/test_sqlite3.py
--- a/pypy/module/test_lib_pypy/test_sqlite3.py
+++ b/pypy/module/test_lib_pypy/test_sqlite3.py
@@ -236,8 +236,14 @@
         return 42
     con.set_authorizer(authorizer_cb)
     with pytest.raises(_sqlite3.OperationalError) as e:
-        con.execute('select 42')
-    assert str(e.value) == 'authorizer malfunction'
+        con.execute('select 123')
+    major, minor, micro = _sqlite3.sqlite_version.split('.')[:3]
+    if (int(major), int(minor), int(micro)) >= (3, 6, 14):
+        assert str(e.value) == 'authorizer malfunction'
+    else:
+        assert str(e.value) == \
+            ("illegal return value (1) from the authorization function - "
+             "should be SQLITE_OK, SQLITE_IGNORE, or SQLITE_DENY")
 
 
 def test_issue1573(con):
diff --git a/pypy/module/zlib/test/test_zlib.py 
b/pypy/module/zlib/test/test_zlib.py
--- a/pypy/module/zlib/test/test_zlib.py
+++ b/pypy/module/zlib/test/test_zlib.py
@@ -153,9 +153,9 @@
         raises(ValueError, zlib.decompressobj().flush, -1)
         raises(TypeError, zlib.decompressobj().flush, None)
         raises(OverflowError, zlib.decompressobj().flush, 2**31)
-        raises(ValueError, zlib.decompressobj().decompress, 'abc', -1)
-        raises(TypeError, zlib.decompressobj().decompress, 'abc', None)
-        raises(OverflowError, zlib.decompressobj().decompress, 'abc', 2**31)
+        raises(ValueError, zlib.decompressobj().decompress, b'abc', -1)
+        raises(TypeError, zlib.decompressobj().decompress, b'abc', None)
+        raises(OverflowError, zlib.decompressobj().decompress, b'abc', 2**31)
         raises(TypeError, self.zlib.decompress, self.compressed, None)
         raises(OverflowError, self.zlib.decompress, self.compressed, 2**31)
 
@@ -164,21 +164,21 @@
         co = zlib.compressobj(zlib.Z_BEST_COMPRESSION)
         assert co.flush()  # Returns a zlib header
         dco = zlib.decompressobj()
-        assert dco.flush() == ""
+        assert dco.flush() == b""
 
     def test_decompress_incomplete_stream(self):
         import zlib
         # This is 'foo', deflated
-        x = 'x\x9cK\xcb\xcf\x07\x00\x02\x82\x01E'
+        x = b'x\x9cK\xcb\xcf\x07\x00\x02\x82\x01E'
         # For the record
-        assert zlib.decompress(x) == 'foo'
+        assert zlib.decompress(x) == b'foo'
         raises(zlib.error, zlib.decompress, x[:-5])
         # Omitting the stream end works with decompressor objects
         # (see issue #8672).
         dco = zlib.decompressobj()
         y = dco.decompress(x[:-5])
         y += dco.flush()
-        assert y == 'foo'
+        assert y == b'foo'
 
     def test_unused_data(self):
         """
@@ -243,13 +243,13 @@
     def test_flush_with_freed_input(self):
         # Issue #16411: decompressor accesses input to last decompress() call
         # in flush(), even if this object has been freed in the meanwhile.
-        input1 = 'abcdefghijklmnopqrstuvwxyz'
-        input2 = 'QWERTYUIOPASDFGHJKLZXCVBNM'
+        input1 = b'abcdefghijklmnopqrstuvwxyz'
+        input2 = b'QWERTYUIOPASDFGHJKLZXCVBNM'
         data = self.zlib.compress(input1)
         dco = self.zlib.decompressobj()
         dco.decompress(data, 1)
         del data
         data = self.zlib.compress(input2)
         assert dco.flush(1) == input1[1:]
-        assert dco.unused_data == ''
-        assert dco.unconsumed_tail == ''
+        assert dco.unused_data == b''
+        assert dco.unconsumed_tail == b''
diff --git a/rpython/jit/metainterp/counter.py 
b/rpython/jit/metainterp/counter.py
--- a/rpython/jit/metainterp/counter.py
+++ b/rpython/jit/metainterp/counter.py
@@ -188,7 +188,8 @@
 # this function is written directly in C; gcc will optimize it using SSE
 eci = ExternalCompilationInfo(post_include_bits=["""
 static void pypy__decay_jit_counters(char *data, double f1, long size) {
-    struct { float times[5]; unsigned short subhashes[5]; } *p = data;
+    struct rpy_jitcnt { float times[5]; unsigned short subhashes[5]; };
+    struct rpy_jitcnt *p = (struct rpy_jitcnt *)data;
     float f = (float)f1;
     long i;
     for (i=0; i<size; i++) {
diff --git a/rpython/jit/metainterp/test/test_ajit.py 
b/rpython/jit/metainterp/test/test_ajit.py
--- a/rpython/jit/metainterp/test/test_ajit.py
+++ b/rpython/jit/metainterp/test/test_ajit.py
@@ -3970,3 +3970,12 @@
             return a.x
         res = self.interp_operations(f, [42])
         assert res == 0
+
+    def test_conditions_without_guards(self):
+        def f(n):
+            if (n == 1) | (n == 3) | (n == 17):
+                return 42
+            return 5
+        res = self.interp_operations(f, [17])
+        assert res == 42
+        self.check_operations_history(guard_true=1, guard_false=0)
diff --git a/rpython/jit/metainterp/test/test_longlong.py 
b/rpython/jit/metainterp/test/test_longlong.py
--- a/rpython/jit/metainterp/test/test_longlong.py
+++ b/rpython/jit/metainterp/test/test_longlong.py
@@ -138,6 +138,15 @@
         res = self.interp_operations(f, [1000000000])
         assert res == 12350000000000000000.0
 
+    def test_float_to_longlong(self):
+        from rpython.rtyper.lltypesystem import lltype, rffi
+        def f(x):
+            compare(r_longlong(x), 0x12, 0x34567800)
+            compare(rffi.cast(lltype.SignedLongLong, x), 0x12, 0x34567800)
+            return 1
+        res = self.interp_operations(f, [0x12345678 * 256.0])
+        assert res == 1
+
     def test_unsigned_compare_ops(self):
         def f(n1, n2):
             # n == 30002000000000
diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -432,7 +432,11 @@
     costly depending on the garbage collector.  To remind you of this
     fact, we don't support id(x) directly.
     """
-    return id(x)      # XXX need to return r_longlong on some platforms
+    # The assumption with RPython is that a regular integer is wide enough
+    # to store a pointer.  The following intmask() should not loose any
+    # information.
+    from rpython.rlib.rarithmetic import intmask
+    return intmask(id(x))
 
 def current_object_addr_as_int(x):
     """A cheap version of id(x).
diff --git a/rpython/rlib/rsocket.py b/rpython/rlib/rsocket.py
--- a/rpython/rlib/rsocket.py
+++ b/rpython/rlib/rsocket.py
@@ -1148,6 +1148,9 @@
                 address_to_fill=None):
     # port_or_service is a string, not an int (but try str(port_number)).
     assert port_or_service is None or isinstance(port_or_service, str)
+    if _c._MACOSX:
+        if port_or_service is None or port_or_service == '0':
+            port_or_service = '00'
     hints = lltype.malloc(_c.addrinfo, flavor='raw', zero=True)
     rffi.setintfield(hints, 'c_ai_family',   family)
     rffi.setintfield(hints, 'c_ai_socktype', socktype)
diff --git a/rpython/rlib/test/test_objectmodel.py 
b/rpython/rlib/test/test_objectmodel.py
--- a/rpython/rlib/test/test_objectmodel.py
+++ b/rpython/rlib/test/test_objectmodel.py
@@ -177,10 +177,13 @@
     assert h == getattr(foo, '__precomputed_identity_hash')
 
 def test_compute_unique_id():
+    from rpython.rlib.rarithmetic import intmask
     class Foo(object):
         pass
     foo = Foo()
-    assert compute_unique_id(foo) == id(foo)
+    x = compute_unique_id(foo)
+    assert type(x) is int
+    assert x == intmask(id(foo))
 
 def test_current_object_addr_as_int():
     from rpython.rlib.rarithmetic import intmask
diff --git a/rpython/rlib/test/test_rsocket.py 
b/rpython/rlib/test/test_rsocket.py
--- a/rpython/rlib/test/test_rsocket.py
+++ b/rpython/rlib/test/test_rsocket.py
@@ -328,6 +328,11 @@
             found = True
     assert found, lst
 
+def test_getaddrinfo_osx_crash():
+    # see CPython issue17269
+    for port in [None, '0', '00']:
+        getaddrinfo('localhost', port, 0, 0, 0, AI_NUMERICSERV)
+
 def test_connect_ex():
     s = RSocket()
     err = s.connect_ex(INETAddress('0.0.0.0', 0))   # should not work
diff --git a/rpython/rtyper/rtuple.py b/rpython/rtyper/rtuple.py
--- a/rpython/rtyper/rtuple.py
+++ b/rpython/rtyper/rtuple.py
@@ -290,20 +290,23 @@
         if not s_tup.is_constant():
             raise TyperError("contains() on non-const tuple")
         t = s_tup.const
-        typ = type(t[0])
-        for x in t[1:]:
-            if type(x) is not typ:
-                raise TyperError("contains() on mixed-type tuple "
-                                 "constant %r" % (t,))
-        d = {}
+        if len(t) == 0:
+            hop.exception_cannot_occur()
+            return hop.inputconst(Bool, False)
+        r_item = hop.args_r[1]
+        v_arg = hop.inputarg(r_item, arg=1)
+        ll_eq = r_item.get_ll_eq_function() or _ll_equal
+        v_result = None
         for x in t:
-            d[x] = None
-        hop2 = hop.copy()
-        _, _ = hop2.r_s_popfirstarg()
-        v_dict = Constant(d)
-        s_dict = hop.rtyper.annotator.bookkeeper.immutablevalue(d)
-        hop2.v_s_insertfirstarg(v_dict, s_dict)
-        return hop2.dispatch()
+            c_tuple_item = hop.inputconst(r_item, x)
+            v_equal = hop.gendirectcall(ll_eq, v_arg, c_tuple_item)
+            if v_result is None:
+                v_result = v_equal
+            else:
+                v_result = hop.genop("int_or", [v_result, v_equal],
+                                     resulttype = Bool)
+        hop.exception_cannot_occur()
+        return v_result or hop.inputconst(Bool, False)
 
 class __extend__(pairtype(TupleRepr, TupleRepr)):
 
@@ -400,3 +403,6 @@
         return t.item0
     else:
         raise StopIteration
+
+def _ll_equal(x, y):
+    return x == y
diff --git a/rpython/rtyper/test/test_rtuple.py 
b/rpython/rtyper/test/test_rtuple.py
--- a/rpython/rtyper/test/test_rtuple.py
+++ b/rpython/rtyper/test/test_rtuple.py
@@ -73,6 +73,20 @@
         res = self.interpret(f, [0])
         assert res is False
 
+    def test_constant_tuple_contains3(self):
+        def f(i):
+            return i in ()
+        res = self.interpret(f, [3])
+        assert res is False
+
+    def test_constant_tuple_contains4(self):
+        def f(i):
+            return i in (3,)
+        res = self.interpret(f, [3])
+        assert res is True
+        res = self.interpret(f, [4])
+        assert res is False
+
     def test_constant_unichar_tuple_contains(self):
         def f(i):
             return unichr(i) in (u'1', u'9')
diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py
--- a/rpython/translator/c/genc.py
+++ b/rpython/translator/c/genc.py
@@ -405,7 +405,7 @@
             ('linuxmemchk', '', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -DRPY_ASSERT 
-DPYPY_USE_LINUXMEMCHK" debug_target'),
             ('llsafer', '', '$(MAKE) CFLAGS="-O2 -DRPY_LL_ASSERT" $(TARGET)'),
             ('lldebug', '', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -DRPY_ASSERT 
-DRPY_LL_ASSERT" debug_target'),
-            ('lldebug0','', '$(MAKE) CFLAGS="-O0 $(DEBUGFLAGS) -DRPY_ASSERT 
-DRPY_LL_ASSERT" debug_target'),
+            ('lldebug0','', '$(MAKE) CFLAGS="$(DEBUGFLAGS) -O0 -DRPY_ASSERT 
-DRPY_LL_ASSERT" debug_target'),
             ('profile', '', '$(MAKE) CFLAGS="-g -O1 -pg $(CFLAGS) 
-fno-omit-frame-pointer" LDFLAGS="-pg $(LDFLAGS)" $(TARGET)'),
             ]
         if self.has_profopt():
diff --git a/rpython/translator/platform/windows.py 
b/rpython/translator/platform/windows.py
--- a/rpython/translator/platform/windows.py
+++ b/rpython/translator/platform/windows.py
@@ -113,8 +113,6 @@
         if msvc_compiler_environ:
             self.c_environ = os.environ.copy()
             self.c_environ.update(msvc_compiler_environ)
-            # XXX passing an environment to subprocess is not enough. Why?
-            os.environ.update(msvc_compiler_environ)
 
         # detect version of current compiler
         returncode, stdout, stderr = _run_subprocess(self.cc, '',
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to