[pypy-commit] pypy default: merge heads

arigo pypy.commits at gmail.com
Mon May 16 17:12:40 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r84497:d4c0f70dde1c
Date: 2016-05-16 23:12 +0200
http://bitbucket.org/pypy/pypy/changeset/d4c0f70dde1c/

Log:	merge heads

diff --git a/pypy/module/cpyext/pyfile.py b/pypy/module/cpyext/pyfile.py
--- a/pypy/module/cpyext/pyfile.py
+++ b/pypy/module/cpyext/pyfile.py
@@ -1,10 +1,10 @@
 from rpython.rtyper.lltypesystem import rffi, lltype
 from pypy.module.cpyext.api import (
-    cpython_api, CANNOT_FAIL, CONST_STRING, FILEP, build_type_checkers, fdopen,
-    fileno)
+    cpython_api, CANNOT_FAIL, CONST_STRING, FILEP, build_type_checkers, fdopen)
 from pypy.module.cpyext.pyobject import PyObject
 from pypy.module.cpyext.object import Py_PRINT_RAW
-from pypy.interpreter.error import OperationError, oefmt
+from pypy.interpreter.error import (OperationError, oefmt, 
+    exception_from_saved_errno)
 from pypy.module._file.interp_file import W_File
 
 PyFile_Check, PyFile_CheckExact = build_type_checkers("File", W_File)
@@ -45,16 +45,29 @@
     w_mode = space.wrap(rffi.charp2str(mode))
     return space.call_method(space.builtin, 'file', w_filename, w_mode)
 
- at cpython_api([PyObject], FILEP, error=CANNOT_FAIL)
+ at cpython_api([PyObject], FILEP, error=lltype.nullptr(FILEP.TO))
 def PyFile_AsFile(space, w_p):
     """Return the file object associated with p as a FILE*.
     
     If the caller will ever use the returned FILE* object while
     the GIL is released it must also call the PyFile_IncUseCount() and
     PyFile_DecUseCount() functions as appropriate."""
+    if not PyFile_Check(space, w_p):
+        raise oefmt(space.w_IOError, 'first argument must be an open file')
     assert isinstance(w_p, W_File)
-    return fdopen(space.int_w(space.call_method(w_p, 'fileno')), 
-                     w_p.mode)
+    try:
+        fd = space.int_w(space.call_method(w_p, 'fileno'))
+        mode = w_p.mode
+    except OperationError as e:
+        raise oefmt(space.w_IOError, 'could not call fileno') 
+    if (fd < 0 or not mode or mode[0] not in ['r', 'w', 'a', 'U'] or
+        ('U' in mode and ('w' in mode or 'a' in mode))):
+        raise oefmt(space.w_IOError, 'invalid fileno or mode') 
+    ret = fdopen(fd, mode)
+    if not ret:
+        raise exception_from_saved_errno(space, space.w_IOError)
+    return ret
+        
 
 @cpython_api([FILEP, CONST_STRING, CONST_STRING, rffi.VOIDP], PyObject)
 def PyFile_FromFile(space, fp, name, mode, close):
diff --git a/pypy/module/cpyext/test/test_datetime.py b/pypy/module/cpyext/test/test_datetime.py
--- a/pypy/module/cpyext/test/test_datetime.py
+++ b/pypy/module/cpyext/test/test_datetime.py
@@ -122,13 +122,15 @@
         module = self.import_extension('foo', [
             ("test_date_macros", "METH_NOARGS",
              """
+                 PyObject* obj;
+                 PyDateTime_Date* d;
                  PyDateTime_IMPORT;
                  if (!PyDateTimeAPI) {
                      PyErr_SetString(PyExc_RuntimeError, "No PyDateTimeAPI");
                      return NULL;
                  }
-                 PyObject* obj = PyDate_FromDate(2000, 6, 6);
-                 PyDateTime_Date* d = (PyDateTime_Date*)obj;
+                 obj = PyDate_FromDate(2000, 6, 6);
+                 d = (PyDateTime_Date*)obj;
 
                  PyDateTime_GET_YEAR(obj);
                  PyDateTime_GET_YEAR(d);
diff --git a/pypy/module/cpyext/test/test_sequence.py b/pypy/module/cpyext/test/test_sequence.py
--- a/pypy/module/cpyext/test/test_sequence.py
+++ b/pypy/module/cpyext/test/test_sequence.py
@@ -160,9 +160,10 @@
         module = self.import_extension('foo', [
             ("test_macro_cast", "METH_NOARGS",
              """
-             PyObject* o = PyList_New(0);
+             PyObject *o = PyList_New(0);
+             PyListObject* l;
              PyList_Append(o, o);
-             PyListObject* l = (PyListObject*)o;
+             l = (PyListObject*)o;
 
              PySequence_Fast_GET_ITEM(o, 0);
              PySequence_Fast_GET_ITEM(l, 0);
diff --git a/pypy/module/cpyext/test/test_weakref.py b/pypy/module/cpyext/test/test_weakref.py
--- a/pypy/module/cpyext/test/test_weakref.py
+++ b/pypy/module/cpyext/test/test_weakref.py
@@ -42,10 +42,11 @@
             ("test_macro_cast", "METH_NOARGS",
              """
              // PyExc_Warning is some weak-reffable PyObject*.
+             char* dumb_pointer;
              PyObject* weakref_obj = PyWeakref_NewRef(PyExc_Warning, NULL);
              if (!weakref_obj) return weakref_obj;
              // No public PyWeakReference type.
-             char* dumb_pointer = (char*) weakref_obj;
+             dumb_pointer = (char*) weakref_obj;
 
              PyWeakref_GET_OBJECT(weakref_obj);
              PyWeakref_GET_OBJECT(dumb_pointer);
diff --git a/pypy/module/imp/test/test_import.py b/pypy/module/imp/test/test_import.py
--- a/pypy/module/imp/test/test_import.py
+++ b/pypy/module/imp/test/test_import.py
@@ -20,15 +20,13 @@
     if pkgname:
         p = p.join(*pkgname.split('.'))
     p.ensure(dir=1)
-    f = p.join("__init__.py").open('w')
-    print >> f, "# package"
-    f.close()
+    with p.join("__init__.py").open('w') as f:
+        print >> f, "# package"
     for filename, content in entries.items():
         filename += '.py'
-        f = p.join(filename).open('w')
-        print >> f, '#', filename
-        print >> f, content
-        f.close()
+        with p.join(filename).open('w') as f:
+            print >> f, '#', filename
+            print >> f, content
     return p
 
 def setup_directory_structure(space):
@@ -535,9 +533,8 @@
         import time
         time.sleep(1)
 
-        f = open(test_reload.__file__, "w")
-        f.write("def test():\n    raise NotImplementedError\n")
-        f.close()
+        with open(test_reload.__file__, "w") as f:
+            f.write("def test():\n    raise NotImplementedError\n")
         reload(test_reload)
         try:
             test_reload.test()
@@ -553,9 +550,8 @@
         import test_reload
         import time
         time.sleep(1)
-        f = open(test_reload.__file__, "w")
-        f.write("a = 10 // 0\n")
-        f.close()
+        with open(test_reload.__file__, "w") as f:
+            f.write("a = 10 // 0\n")
 
         # A failing reload should leave the previous module in sys.modules
         raises(ZeroDivisionError, reload, test_reload)
@@ -687,7 +683,8 @@
         import pkg
         import os
         pathname = os.path.join(os.path.dirname(pkg.__file__), 'a.py')
-        module = imp.load_module('a', open(pathname),
+        with open(pathname) as fid:
+            module = imp.load_module('a', fid,
                                  'invalid_path_name', ('.py', 'r', imp.PY_SOURCE))
         assert module.__name__ == 'a'
         assert module.__file__ == 'invalid_path_name'
@@ -851,8 +848,8 @@
         assert ret is None
 
         # check for empty .pyc file
-        f = open(cpathname, 'wb')
-        f.close()
+        with open(cpathname, 'wb') as f:
+            pass
         ret = importing.check_compiled_module(space,
                                               cpathname,
                                               mtime)
@@ -1391,7 +1388,8 @@
         assert importer is None
         # an existing file
         path = os.path.join(self.udir, 'test_getimporter')
-        open(path, 'w').close()
+        with open(path, 'w') as f:
+            pass
         importer = imp._getimporter(path)
         assert isinstance(importer, imp.NullImporter)
         # a non-existing path
@@ -1400,8 +1398,8 @@
         assert isinstance(importer, imp.NullImporter)
         # a mostly-empty zip file
         path = os.path.join(self.udir, 'test_getimporter.zip')
-        f = open(path, 'wb')
-        f.write('PK\x03\x04\n\x00\x00\x00\x00\x00P\x9eN>\x00\x00\x00\x00\x00'
+        with open(path, 'wb') as f:
+            f.write('PK\x03\x04\n\x00\x00\x00\x00\x00P\x9eN>\x00\x00\x00\x00\x00'
                 '\x00\x00\x00\x00\x00\x00\x00\x05\x00\x15\x00emptyUT\t\x00'
                 '\x03wyYMwyYMUx\x04\x00\xf4\x01d\x00PK\x01\x02\x17\x03\n\x00'
                 '\x00\x00\x00\x00P\x9eN>\x00\x00\x00\x00\x00\x00\x00\x00\x00'
@@ -1409,7 +1407,6 @@
                 '\xa4\x81\x00\x00\x00\x00emptyUT\x05\x00\x03wyYMUx\x00\x00PK'
                 '\x05\x06\x00\x00\x00\x00\x01\x00\x01\x00@\x00\x00\x008\x00'
                 '\x00\x00\x00\x00')
-        f.close()
         importer = imp._getimporter(path)
         import zipimport
         assert isinstance(importer, zipimport.zipimporter)
diff --git a/pypy/tool/release/repackage.sh b/pypy/tool/release/repackage.sh
--- a/pypy/tool/release/repackage.sh
+++ b/pypy/tool/release/repackage.sh
@@ -1,26 +1,33 @@
 # Edit these appropriately before running this script
 maj=5
 min=1
-rev=1
+rev=2
 branchname=release-$maj.x  # ==OR== release-$maj.$min.x
 tagname=release-$maj.$min.$rev  # ==OR== release-$maj.$min
 
+echo checking hg log -r $branchname
 hg log -r $branchname || exit 1
+echo checking hg log -r $tagname
 hg log -r $tagname || exit 1
 
 # This script will download latest builds from the buildmaster, rename the top
 # level directory, and repackage ready to be uploaded to bitbucket. It will also
 # download source, assuming a tag for the release already exists, and repackage them.
 # The script should be run in an empty directory, i.e. /tmp/release_xxx
-
 for plat in linux linux64 linux-armhf-raspbian linux-armhf-raring linux-armel osx64 s390x
   do
+    echo downloading package for $plat
     wget http://buildbot.pypy.org/nightly/$branchname/pypy-c-jit-latest-$plat.tar.bz2
     tar -xf pypy-c-jit-latest-$plat.tar.bz2
     rm pypy-c-jit-latest-$plat.tar.bz2
-    mv pypy-c-jit-*-$plat pypy-$maj.$min.$rev-$plat
-    tar --owner=root --group=root --numeric-owner -cvjf pypy-$maj.$min.$rev-$plat.tar.bz2 pypy-$maj.$min.$rev-$plat
-    rm -rf pypy-$maj.$min.$rev-$plat
+    plat_final=$plat
+    if [ $plat = linux ]; then
+        plat_final=linux32
+    fi
+    mv pypy-c-jit-*-$plat pypy-$maj.$min.$rev-$plat_final
+    echo packaging $plat_final
+    tar --owner=root --group=root --numeric-owner -cvjf pypy-$maj.$min.$rev-$plat_final.tar.bz2 pypy-$maj.$min.$rev-$plat_final
+    rm -rf pypy-$maj.$min.$rev-$plat_final
   done
 
 plat=win32


More information about the pypy-commit mailing list