[pypy-commit] pypy py3.5: hg merge default

rlamy pypy.commits at gmail.com
Tue Jan 17 21:33:13 EST 2017


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.5
Changeset: r89652:bf8056bf0d0b
Date: 2017-01-18 02:32 +0000
http://bitbucket.org/pypy/pypy/changeset/bf8056bf0d0b/

Log:	hg merge default

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -662,6 +662,11 @@
 
     def setup_builtin_modules(self):
         "NOT_RPYTHON: only for initializing the space."
+        if self.config.objspace.usemodules.cpyext:
+            # Special-case this to have state.install_dll() called early, which
+            # is required to initialise sys on Windows.
+            from pypy.module.cpyext.state import State
+            self.fromcache(State).build_api()
         self.getbuiltinmodule('sys')
         self.getbuiltinmodule('_imp')
         self.getbuiltinmodule('_frozen_importlib')
diff --git a/pypy/module/cppyy/src/clingcwrapper.cxx b/pypy/module/cppyy/src/clingcwrapper.cxx
--- a/pypy/module/cppyy/src/clingcwrapper.cxx
+++ b/pypy/module/cppyy/src/clingcwrapper.cxx
@@ -522,7 +522,7 @@
    if ( FastCall( method, args, self, (void*)cppresult ) ) {
 	  cstr = cppstring_to_cstring( *cppresult );
       *length = cppresult->size();
-      cppresult->std::string::~string();
+      cppresult->std::string::~basic_string();
    } else
       *length = 0;
    free( (void*)cppresult ); 
@@ -712,7 +712,7 @@
          msg << "failed offset calculation between " << cb->GetName() << " and " << cd->GetName();
          // TODO: propagate this warning to caller w/o use of Python C-API
          // PyErr_Warn( PyExc_RuntimeWarning, const_cast<char*>( msg.str().c_str() ) );
-         std::cerr << "Warning: " << msg << '\n';
+         std::cerr << "Warning: " << msg.str() << '\n';
       }
 
    // return -1 to signal caller NOT to apply offset
diff --git a/pypy/module/cpyext/__init__.py b/pypy/module/cpyext/__init__.py
--- a/pypy/module/cpyext/__init__.py
+++ b/pypy/module/cpyext/__init__.py
@@ -12,11 +12,6 @@
 
     atexit_funcs = []
 
-    def setup_after_space_initialization(self):
-        state = self.space.fromcache(State)
-        state.setup_rawrefcount()
-        state.build_api()
-
     def startup(self, space):
         space.fromcache(State).startup(space)
         method = pypy.module.cpyext.typeobject.get_new_method_def(space)
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
@@ -674,7 +674,7 @@
                              % (cpyname, ))
 build_exported_objects()
 
-cts = CTypeSpace(headers=['sys/types.h', 'stdarg.h', 'stdio.h'])
+cts = CTypeSpace(headers=['sys/types.h', 'stdarg.h', 'stdio.h', 'stddef.h'])
 cts.parse_header(parse_dir / 'cpyext_object.h')
 
 Py_ssize_t = cts.gettype('Py_ssize_t')
diff --git a/pypy/module/cpyext/cparser.py b/pypy/module/cpyext/cparser.py
--- a/pypy/module/cpyext/cparser.py
+++ b/pypy/module/cpyext/cparser.py
@@ -1,3 +1,4 @@
+import sys
 from collections import OrderedDict
 from cffi import api, model
 from cffi.commontypes import COMMON_TYPES, resolve_common_type
@@ -664,6 +665,9 @@
 
 add_inttypes()
 CNAME_TO_LLTYPE['int'] = rffi.INT_real
+CNAME_TO_LLTYPE['wchar_t'] = lltype.UniChar
+if 'ssize_t' not in CNAME_TO_LLTYPE:  # on Windows
+    CNAME_TO_LLTYPE['ssize_t'] = CNAME_TO_LLTYPE['long']
 
 def cname_to_lltype(name):
     return CNAME_TO_LLTYPE[name]
@@ -772,8 +776,13 @@
             for hdr in x.headers:
                 if hdr not in all_headers:
                     all_headers.append(hdr)
+        if sys.platform == 'win32':
+            compile_extra = ['-Dssize_t=long']
+        else:
+            compile_extra = []
         return ExternalCompilationInfo(
-            post_include_bits=all_sources, includes=all_headers)
+            post_include_bits=all_sources, includes=all_headers,
+            compile_extra=compile_extra)
 
     def configure_types(self):
         for name, (obj, quals) in self.ctx._declarations.iteritems():
diff --git a/pypy/module/cpyext/include/Python.h b/pypy/module/cpyext/include/Python.h
--- a/pypy/module/cpyext/include/Python.h
+++ b/pypy/module/cpyext/include/Python.h
@@ -57,13 +57,6 @@
 #endif
 #include <stdlib.h>
 
-#ifndef _WIN32
-typedef intptr_t Py_ssize_t;
-#else
-typedef long Py_ssize_t;
-#endif
-#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
-#define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
 #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
 
 #define Py_USING_UNICODE
diff --git a/pypy/module/cpyext/include/object.h b/pypy/module/cpyext/include/object.h
--- a/pypy/module/cpyext/include/object.h
+++ b/pypy/module/cpyext/include/object.h
@@ -7,10 +7,20 @@
 extern "C" {
 #endif
 
+/* Hack: MSVC doesn't support ssize_t */
+#ifdef _WIN32
+#define ssize_t long
+#endif
+#include <cpyext_object.h>
+#ifdef _WIN32
+#undef ssize_t
+#endif
+
+#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
+#define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
+
 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
 
-#include <cpyext_object.h>
-
 /*
 CPython has this for backwards compatibility with really old extensions, and now
 we have it for compatibility with CPython.
@@ -78,7 +88,6 @@
 #define Py_GT 4
 #define Py_GE 5
 
-
 /* Py3k buffer interface, adapted for PyPy */
     /* Flags for getting buffers */
 #define PyBUF_SIMPLE 0
diff --git a/pypy/module/cpyext/include/unicodeobject.h b/pypy/module/cpyext/include/unicodeobject.h
--- a/pypy/module/cpyext/include/unicodeobject.h
+++ b/pypy/module/cpyext/include/unicodeobject.h
@@ -5,26 +5,7 @@
 extern "C" {
 #endif
 
-
-typedef unsigned int Py_UCS4;
-#ifdef HAVE_USABLE_WCHAR_T
-#define PY_UNICODE_TYPE wchar_t
-#elif Py_UNICODE_SIZE == 4
-#define PY_UNICODE_TYPE Py_UCS4
-#else
-#define PY_UNICODE_TYPE unsigned short
-#endif
-typedef PY_UNICODE_TYPE Py_UNICODE;
-
-#define Py_UNICODE_REPLACEMENT_CHARACTER ((Py_UNICODE) 0xFFFD)
-
-typedef struct {
-    PyObject_HEAD
-    Py_UNICODE *buffer;
-    Py_ssize_t length;
-    char *utf8buffer;
-} PyUnicodeObject;
-
+#include <cpyext_unicodeobject.h>
 
 PyAPI_FUNC(PyObject *) PyUnicode_FromFormatV(const char *format, va_list vargs);
 PyAPI_FUNC(PyObject *) PyUnicode_FromFormat(const char *format, ...);
diff --git a/pypy/module/cpyext/parse/cpyext_unicodeobject.h b/pypy/module/cpyext/parse/cpyext_unicodeobject.h
new file mode 100644
--- /dev/null
+++ b/pypy/module/cpyext/parse/cpyext_unicodeobject.h
@@ -0,0 +1,13 @@
+typedef unsigned int Py_UCS4;
+/* On PyPy, Py_UNICODE is always wchar_t */
+#define PY_UNICODE_TYPE wchar_t
+typedef PY_UNICODE_TYPE Py_UNICODE;
+
+#define Py_UNICODE_REPLACEMENT_CHARACTER ((Py_UNICODE) 0xFFFD)
+
+typedef struct {
+    PyObject_HEAD
+    Py_UNICODE *buffer;
+    Py_ssize_t length;
+    char *utf8buffer;
+} PyUnicodeObject;
diff --git a/pypy/module/cpyext/state.py b/pypy/module/cpyext/state.py
--- a/pypy/module/cpyext/state.py
+++ b/pypy/module/cpyext/state.py
@@ -83,6 +83,7 @@
         This function is called when at object space creation,
         and drives the compilation of the cpyext library
         """
+        self.setup_rawrefcount()
         from pypy.module.cpyext import api
         if not self.space.config.translating:
             self.api_lib = str(api.build_bridge(self.space))
diff --git a/pypy/module/cpyext/test/test_cparser.py b/pypy/module/cpyext/test/test_cparser.py
--- a/pypy/module/cpyext/test/test_cparser.py
+++ b/pypy/module/cpyext/test/test_cparser.py
@@ -190,6 +190,17 @@
     assert FUNC.RESULT == cts.gettype('func_t')
     assert FUNC.ARGS == (cts.gettype('TestFloatObject *'),)
 
+def test_wchar_t():
+    cdef = """
+    typedef struct { wchar_t* x; } test;
+    """
+    cts = parse_source(cdef, headers=['stddef.h'])
+    obj = lltype.malloc(cts.gettype('test'), flavor='raw')
+    obj.c_x = cts.cast('wchar_t*', 0)
+    obj.c_x =  lltype.nullptr(rffi.CWCHARP.TO)
+    lltype.free(obj, flavor='raw')
+
+
 def test_translate_cast():
     cdef = "typedef ssize_t Py_ssize_t;"
     cts = parse_source(cdef)
diff --git a/pypy/module/cpyext/unicodeobject.py b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -3,8 +3,8 @@
 from pypy.module.unicodedata import unicodedb
 from pypy.module.cpyext.api import (
     CANNOT_FAIL, Py_ssize_t, build_type_checkers, cpython_api,
-    bootstrap_function, PyObjectFields, cpython_struct, CONST_STRING,
-    CONST_WSTRING, Py_CLEANUP_SUPPORTED, slot_function)
+    bootstrap_function, CONST_STRING,
+    CONST_WSTRING, Py_CLEANUP_SUPPORTED, slot_function, cts, parse_dir)
 from pypy.module.cpyext.pyerrors import PyErr_BadArgument
 from pypy.module.cpyext.pyobject import (
     PyObject, PyObjectP, Py_DecRef, make_ref, from_ref, track_reference,
@@ -18,12 +18,9 @@
 
 ## See comment in bytesobject.py.
 
-PyUnicodeObjectStruct = lltype.ForwardReference()
-PyUnicodeObject = lltype.Ptr(PyUnicodeObjectStruct)
-PyUnicodeObjectFields = (PyObjectFields +
-    (("buffer", rffi.CWCHARP), ("length", Py_ssize_t),
-     ("utf8buffer", rffi.CCHARP)))
-cpython_struct("PyUnicodeObject", PyUnicodeObjectFields, PyUnicodeObjectStruct)
+cts.parse_header(parse_dir / 'cpyext_unicodeobject.h')
+PyUnicodeObject = cts.gettype('PyUnicodeObject*')
+Py_UNICODE = cts.gettype('Py_UNICODE')
 
 @bootstrap_function
 def init_unicodeobject(space):
@@ -40,7 +37,6 @@
 
 PyUnicode_Check, PyUnicode_CheckExact = build_type_checkers("Unicode", "w_unicode")
 
-Py_UNICODE = lltype.UniChar
 
 def new_empty_unicode(space, length):
     """
@@ -195,7 +191,7 @@
 def PyUnicode_GET_DATA_SIZE(space, w_obj):
     """Return the size of the object's internal buffer in bytes.  o has to be a
     PyUnicodeObject (not checked)."""
-    return rffi.sizeof(lltype.UniChar) * PyUnicode_GET_SIZE(space, w_obj)
+    return rffi.sizeof(Py_UNICODE) * PyUnicode_GET_SIZE(space, w_obj)
 
 @cpython_api([rffi.VOIDP], Py_ssize_t, error=CANNOT_FAIL)
 def PyUnicode_GET_SIZE(space, w_obj):


More information about the pypy-commit mailing list