[pypy-commit] pypy default: merge to keep updated

wenzhuman noreply at buildbot.pypy.org
Wed May 28 22:05:30 CEST 2014


Author: wenzhuman <manwenzhu at gamil.com>
Branch: 
Changeset: r71758:6bfc4df6ee95
Date: 2014-03-19 22:24 -0400
http://bitbucket.org/pypy/pypy/changeset/6bfc4df6ee95/

Log:	merge to keep updated

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -440,10 +440,11 @@
 
         return name
 
-    def getbuiltinmodule(self, name, force_init=False):
+    def getbuiltinmodule(self, name, force_init=False, reuse=True):
         w_name = self.wrap(name)
         w_modules = self.sys.get('modules')
         if not force_init:
+            assert reuse is True
             try:
                 return self.getitem(w_modules, w_name)
             except OperationError, e:
@@ -459,10 +460,18 @@
                         "getbuiltinmodule() called with non-builtin module %s",
                         name)
         else:
-            # And initialize it
+            # Initialize the module
             from pypy.interpreter.module import Module
             if isinstance(w_mod, Module):
-                w_mod.init(self)
+                if not reuse and w_mod.startup_called:
+                    # Create a copy of the module
+                    w_mod.getdict(self)  # unlazy w_initialdict
+                    w_new = self.wrap(Module(self, w_name))
+                    self.call_method(w_new.getdict(self), 'update',
+                                     w_mod.w_initialdict)
+                    w_mod = w_new
+                else:
+                    w_mod.init(self)
 
             # Add the module to sys.modules
             self.setitem(w_modules, w_name, w_mod)
diff --git a/pypy/module/cpyext/include/pystate.h b/pypy/module/cpyext/include/pystate.h
--- a/pypy/module/cpyext/include/pystate.h
+++ b/pypy/module/cpyext/include/pystate.h
@@ -21,9 +21,8 @@
 #define Py_END_ALLOW_THREADS	PyEval_RestoreThread(_save); \
 		 }
 
-typedef
-    enum {PyGILState_LOCKED, PyGILState_UNLOCKED}
-        PyGILState_STATE;
+enum {PyGILState_LOCKED, PyGILState_UNLOCKED};
+typedef int PyGILState_STATE;
 
 #define PyThreadState_GET() PyThreadState_Get()
 
diff --git a/pypy/module/cpyext/pystate.py b/pypy/module/cpyext/pystate.py
--- a/pypy/module/cpyext/pystate.py
+++ b/pypy/module/cpyext/pystate.py
@@ -204,16 +204,14 @@
         # Before external call is after running Python
         rffi.aroundstate.before()
 
-PyGILState_STATE = rffi.COpaquePtr('PyGILState_STATE',
-                                   typedef='PyGILState_STATE',
-                                   compilation_info=CConfig._compilation_info_)
+PyGILState_STATE = rffi.INT
 
 @cpython_api([], PyGILState_STATE, error=CANNOT_FAIL)
 def PyGILState_Ensure(space):
     if rffi.aroundstate.after:
         # After external call is before entering Python
         rffi.aroundstate.after()
-    return lltype.nullptr(PyGILState_STATE.TO)
+    return rffi.cast(PyGILState_STATE, 0)
 
 @cpython_api([PyGILState_STATE], lltype.Void)
 def PyGILState_Release(space, state):
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -579,7 +579,8 @@
         return space.call_method(find_info.w_loader, "load_module", w_modulename)
 
     if find_info.modtype == C_BUILTIN:
-        return space.getbuiltinmodule(find_info.filename, force_init=True)
+        return space.getbuiltinmodule(find_info.filename, force_init=True,
+                                      reuse=reuse)
 
     if find_info.modtype in (PY_SOURCE, PY_COMPILED, C_EXTENSION, PKG_DIRECTORY):
         w_mod = None
diff --git a/pypy/module/imp/test/test_app.py b/pypy/module/imp/test/test_app.py
--- a/pypy/module/imp/test/test_app.py
+++ b/pypy/module/imp/test/test_app.py
@@ -203,7 +203,6 @@
 
     def test_builtin_reimport(self):
         # from https://bugs.pypy.org/issue1514
-        skip("fix me")
         import sys, marshal
 
         old = marshal.loads
@@ -223,7 +222,6 @@
         # taken from https://bugs.pypy.org/issue1514, with extra cases
         # that show a difference with CPython: we can get on CPython
         # several module objects for the same built-in module :-(
-        skip("several built-in module objects: not supported by pypy")
         import sys, marshal
 
         old = marshal.loads
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
@@ -578,7 +578,6 @@
         assert hasattr(time, 'clock')
 
     def test_reimport_builtin_simple_case_2(self):
-        skip("fix me")
         import sys, time
         time.foo = "bar"
         del sys.modules['time']
@@ -586,7 +585,6 @@
         assert not hasattr(time, 'foo')
 
     def test_reimport_builtin(self):
-        skip("fix me")
         import sys, time
         oldpath = sys.path
         time.tzset = "<test_reimport_builtin removed this>"
diff --git a/pypy/module/marshal/interp_marshal.py b/pypy/module/marshal/interp_marshal.py
--- a/pypy/module/marshal/interp_marshal.py
+++ b/pypy/module/marshal/interp_marshal.py
@@ -7,7 +7,7 @@
 
 Py_MARSHAL_VERSION = 2
 
- at unwrap_spec(w_version = WrappedDefault(Py_MARSHAL_VERSION))
+ at unwrap_spec(w_version=WrappedDefault(Py_MARSHAL_VERSION))
 def dump(space, w_data, w_f, w_version):
     """Write the 'data' object into the open file 'f'."""
     # special case real files for performance
@@ -24,7 +24,7 @@
     finally:
         writer.finished()
 
- at unwrap_spec(w_version = WrappedDefault(Py_MARSHAL_VERSION))
+ at unwrap_spec(w_version=WrappedDefault(Py_MARSHAL_VERSION))
 def dumps(space, w_data, w_version):
     """Return the string that would have been written to a file
 by dump(data, file)."""
@@ -217,6 +217,16 @@
         self.space.marshal_w(w_obj, self)
 
     def dump_w_obj(self, w_obj):
+        space = self.space
+        if space.type(w_obj).is_heaptype():
+            try:
+                buf = space.buffer_w(w_obj)
+            except OperationError as e:
+                if not e.match(space, space.w_TypeError):
+                    raise
+                self.raise_exc("unmarshallable object")
+            else:
+                w_obj = space.newbuffer(buf)
         try:
             self.put_w_obj(w_obj)
         except rstackovf.StackOverflow:
diff --git a/pypy/module/marshal/test/test_marshal.py b/pypy/module/marshal/test/test_marshal.py
--- a/pypy/module/marshal/test/test_marshal.py
+++ b/pypy/module/marshal/test/test_marshal.py
@@ -11,7 +11,7 @@
     def w_marshal_check(self, case):
         import marshal, StringIO
         s = marshal.dumps(case)
-        print repr(s)
+        print(repr(s))
         x = marshal.loads(s)
         assert x == case and type(x) is type(case)
         f = StringIO.StringIO()
@@ -173,10 +173,13 @@
         import marshal
         types = (float, complex, int, long, tuple, list, dict, set, frozenset)
         for cls in types:
+            print(cls)
             class subtype(cls):
                 pass
             exc = raises(ValueError, marshal.dumps, subtype)
             assert str(exc.value) == 'unmarshallable object'
+            exc = raises(ValueError, marshal.dumps, subtype())
+            assert str(exc.value) == 'unmarshallable object'
 
     def test_valid_subtypes(self):
         import marshal
diff --git a/pypy/objspace/std/memoryview.py b/pypy/objspace/std/memoryview.py
--- a/pypy/objspace/std/memoryview.py
+++ b/pypy/objspace/std/memoryview.py
@@ -176,6 +176,14 @@
         self.buf = buf
 
     def buffer_w(self, space):
+        """
+        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 self.buf
 
     @staticmethod
@@ -229,17 +237,6 @@
             buf = buffer.SubBuffer(buf, start, size)
         return W_MemoryView(buf)
 
-    def descr_buffer(self, space):
-        """
-        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):
         return space.wrap(self.as_str())
 
diff --git a/rpython/rlib/rfile.py b/rpython/rlib/rfile.py
--- a/rpython/rlib/rfile.py
+++ b/rpython/rlib/rfile.py
@@ -14,6 +14,11 @@
 includes = ['stdio.h', 'sys/types.h']
 if os.name == "posix":
     includes += ['unistd.h']
+    ftruncate = 'ftruncate'
+    fileno = 'fileno'
+else:
+    ftruncate = '_chsize'
+    fileno = '_fileno'
 eci = ExternalCompilationInfo(includes=includes)
 
 def llexternal(*args, **kwargs):
@@ -41,10 +46,10 @@
 c_fseek = llexternal('fseek', [lltype.Ptr(FILE), rffi.LONG, rffi.INT],
                      rffi.INT)
 c_tmpfile = llexternal('tmpfile', [], lltype.Ptr(FILE))
-c_fileno = llexternal('fileno', [lltype.Ptr(FILE)], rffi.INT)
+c_fileno = llexternal(fileno, [lltype.Ptr(FILE)], rffi.INT)
 c_ftell = llexternal('ftell', [lltype.Ptr(FILE)], rffi.LONG)
 c_fflush = llexternal('fflush', [lltype.Ptr(FILE)], rffi.INT)
-c_ftruncate = llexternal('ftruncate', [rffi.INT, OFF_T], rffi.INT, macro=True)
+c_ftruncate = llexternal(ftruncate, [rffi.INT, OFF_T], rffi.INT, macro=True)
 
 c_fgets = llexternal('fgets', [rffi.CCHARP, rffi.INT, lltype.Ptr(FILE)],
                      rffi.CCHARP)


More information about the pypy-commit mailing list