[pypy-commit] pypy default: hg merge cffi-char16-char32
Author: Armin Rigo Branch: Changeset: r91518:6a4af0b6b51c Date: 2017-06-05 08:24 +0200 http://bitbucket.org/pypy/pypy/changeset/6a4af0b6b51c/ Log:hg merge cffi-char16-char32 Support the char16_t and char32_t types in cffi. This means reintroducing some surrogate handling in one of the two directions, depending on the size of unichar. diff --git a/lib_pypy/cffi/_cffi_include.h b/lib_pypy/cffi/_cffi_include.h --- a/lib_pypy/cffi/_cffi_include.h +++ b/lib_pypy/cffi/_cffi_include.h @@ -159,9 +159,9 @@ #define _cffi_from_c_struct \ ((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[18]) #define _cffi_to_c_wchar_t \ -((wchar_t(*)(PyObject *))_cffi_exports[19]) +((_cffi_wchar_t(*)(PyObject *))_cffi_exports[19]) #define _cffi_from_c_wchar_t \ -((PyObject *(*)(wchar_t))_cffi_exports[20]) +((PyObject *(*)(_cffi_wchar_t))_cffi_exports[20]) #define _cffi_to_c_long_double \ ((long double(*)(PyObject *))_cffi_exports[21]) #define _cffi_to_c__Bool \ @@ -174,7 +174,11 @@ #define _CFFI_CPIDX 25 #define _cffi_call_python\ ((void(*)(struct _cffi_externpy_s *, char *))_cffi_exports[_CFFI_CPIDX]) -#define _CFFI_NUM_EXPORTS 26 +#define _cffi_to_c_wchar3216_t \ +((int(*)(PyObject *))_cffi_exports[26]) +#define _cffi_from_c_wchar3216_t \ +((PyObject *(*)(int))_cffi_exports[27]) +#define _CFFI_NUM_EXPORTS 28 struct _cffi_ctypedescr; @@ -215,6 +219,46 @@ return NULL; } + +#ifdef HAVE_WCHAR_H +typedef wchar_t _cffi_wchar_t; +#else +typedef uint16_t _cffi_wchar_t; /* same random pick as _cffi_backend.c */ +#endif + +_CFFI_UNUSED_FN static uint16_t _cffi_to_c_char16_t(PyObject *o) +{ +if (sizeof(_cffi_wchar_t) == 2) +return (uint16_t)_cffi_to_c_wchar_t(o); +else +return (uint16_t)_cffi_to_c_wchar3216_t(o); +} + +_CFFI_UNUSED_FN static PyObject *_cffi_from_c_char16_t(uint16_t x) +{ +if (sizeof(_cffi_wchar_t) == 2) +return _cffi_from_c_wchar_t(x); +else +return _cffi_from_c_wchar3216_t(x); +} + +_CFFI_UNUSED_FN static int _cffi_to_c_char32_t(PyObject *o) +{ +if (sizeof(_cffi_wchar_t) == 4) +return (int)_cffi_to_c_wchar_t(o); +else +return (int)_cffi_to_c_wchar3216_t(o); +} + +_CFFI_UNUSED_FN static PyObject *_cffi_from_c_char32_t(int x) +{ +if (sizeof(_cffi_wchar_t) == 4) +return _cffi_from_c_wchar_t(x); +else +return _cffi_from_c_wchar3216_t(x); +} + + /** end CPython-specific section **/ #else _CFFI_UNUSED_FN diff --git a/lib_pypy/cffi/cffi_opcode.py b/lib_pypy/cffi/cffi_opcode.py --- a/lib_pypy/cffi/cffi_opcode.py +++ b/lib_pypy/cffi/cffi_opcode.py @@ -107,9 +107,10 @@ PRIM_UINTMAX = 47 PRIM_FLOATCOMPLEX = 48 PRIM_DOUBLECOMPLEX = 49 +PRIM_CHAR16= 50 +PRIM_CHAR32= 51 - -_NUM_PRIM = 50 +_NUM_PRIM = 52 _UNKNOWN_PRIM = -1 _UNKNOWN_FLOAT_PRIM= -2 _UNKNOWN_LONG_DOUBLE = -3 @@ -135,6 +136,8 @@ 'double _Complex':PRIM_DOUBLECOMPLEX, '_Bool': PRIM_BOOL, 'wchar_t':PRIM_WCHAR, +'char16_t': PRIM_CHAR16, +'char32_t': PRIM_CHAR32, 'int8_t': PRIM_INT8, 'uint8_t':PRIM_UINT8, 'int16_t':PRIM_INT16, diff --git a/lib_pypy/cffi/model.py b/lib_pypy/cffi/model.py --- a/lib_pypy/cffi/model.py +++ b/lib_pypy/cffi/model.py @@ -122,6 +122,8 @@ '_Bool': 'i', # the following types are not primitive in the C sense 'wchar_t':'c', +'char16_t': 'c', +'char32_t': 'c', 'int8_t': 'i', 'uint8_t':'i', 'int16_t':'i', diff --git a/lib_pypy/cffi/parse_c_type.h b/lib_pypy/cffi/parse_c_type.h --- a/lib_pypy/cffi/parse_c_type.h +++ b/lib_pypy/cffi/parse_c_type.h @@ -81,8 +81,10 @@ #define _CFFI_PRIM_UINTMAX 47 #define _CFFI_PRIM_FLOATCOMPLEX 48 #define _CFFI_PRIM_DOUBLECOMPLEX 49 +#define _CFFI_PRIM_CHAR16 50 +#define _CFFI_PRIM_CHAR32 51 -#define _CFFI__NUM_PRIM 50 +#define _CFFI__NUM_PRIM 52 #define _CFFI__UNKNOWN_PRIM (-1) #define _CFFI__UNKNOWN_FLOAT_PRIM (-2) #define _CFFI__UNKNOWN_LONG_DOUBLE(-3) diff --git a/lib_pypy/cffi/recompiler.py b/lib_pypy/cffi/recompiler.py --- a/lib_pypy/cffi/recompiler.py +++ b/lib_pypy/cffi/recompiler.py @@ -3,8 +3,9 @@ from .error import VerificationError from .cffi_opcode import * -VERSION = "0x2601" -VERSION_EMBEDDED = "0x2701" +VERSION_BASE = 0x2601 +VERSION_EMBEDDED = 0x2701
[pypy-commit] pypy cffi-char16-char32: ready to merge
Author: Armin Rigo Branch: cffi-char16-char32 Changeset: r91517:0f1cd402bb00 Date: 2017-06-05 08:23 +0200 http://bitbucket.org/pypy/pypy/changeset/0f1cd402bb00/ Log:ready to merge diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst --- a/pypy/doc/whatsnew-head.rst +++ b/pypy/doc/whatsnew-head.rst @@ -6,5 +6,6 @@ .. startrev: 558bd00b3dd8 .. branch: cffi-complex +.. branch: cffi-char16-char32 -Part of the upgrade to cffi 1.11 +The two ``cffi-*`` branches are part of the upgrade to cffi 1.11. ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy cffi-char16-char32: import cffi/e7063ce4bdf8
Author: Armin Rigo Branch: cffi-char16-char32 Changeset: r91516:35878bce885d Date: 2017-06-04 23:43 +0200 http://bitbucket.org/pypy/pypy/changeset/35878bce885d/ Log:import cffi/e7063ce4bdf8 diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py --- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py +++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py @@ -2011,7 +2011,7 @@ lib = verify(ffi, "test_function_returns_float_complex", """ #include static float _Complex f1(float a, float b) { return a + I*2.0*b; } -""") +""", no_cpp=True)# fails on some systems with C++ result = lib.f1(1.25, 5.1) assert type(result) == complex assert result.real == 1.25 # exact @@ -2025,7 +2025,7 @@ lib = verify(ffi, "test_function_returns_double_complex", """ #include static double _Complex f1(double a, double b) { return a + I*2.0*b; } -""") +""", no_cpp=True)# fails on some systems with C++ result = lib.f1(1.25, 5.1) assert type(result) == complex assert result.real == 1.25 # exact @@ -2039,7 +2039,7 @@ lib = verify(ffi, "test_function_argument_float_complex", """ #include static float f1(float _Complex x) { return cabsf(x); } -""") +""", no_cpp=True)# fails on some systems with C++ x = complex(12.34, 56.78) result = lib.f1(x) assert abs(result - abs(x)) < 1e-5 @@ -2052,7 +2052,7 @@ lib = verify(ffi, "test_function_argument_double_complex", """ #include static double f1(double _Complex x) { return cabs(x); } -""") +""", no_cpp=True)# fails on some systems with C++ x = complex(12.34, 56.78) result = lib.f1(x) assert abs(result - abs(x)) < 1e-11 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] cffi default: including fails on some systems with C++
Author: Armin Rigo Branch: Changeset: r2976:e7063ce4bdf8 Date: 2017-06-04 23:43 +0200 http://bitbucket.org/cffi/cffi/changeset/e7063ce4bdf8/ Log:including fails on some systems with C++ diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py --- a/testing/cffi1/test_recompiler.py +++ b/testing/cffi1/test_recompiler.py @@ -2010,7 +2010,7 @@ lib = verify(ffi, "test_function_returns_float_complex", """ #include static float _Complex f1(float a, float b) { return a + I*2.0*b; } -""") +""", no_cpp=True)# fails on some systems with C++ result = lib.f1(1.25, 5.1) assert type(result) == complex assert result.real == 1.25 # exact @@ -2024,7 +2024,7 @@ lib = verify(ffi, "test_function_returns_double_complex", """ #include static double _Complex f1(double a, double b) { return a + I*2.0*b; } -""") +""", no_cpp=True)# fails on some systems with C++ result = lib.f1(1.25, 5.1) assert type(result) == complex assert result.real == 1.25 # exact @@ -2038,7 +2038,7 @@ lib = verify(ffi, "test_function_argument_float_complex", """ #include static float f1(float _Complex x) { return cabsf(x); } -""") +""", no_cpp=True)# fails on some systems with C++ x = complex(12.34, 56.78) result = lib.f1(x) assert abs(result - abs(x)) < 1e-5 @@ -2051,7 +2051,7 @@ lib = verify(ffi, "test_function_argument_double_complex", """ #include static double f1(double _Complex x) { return cabs(x); } -""") +""", no_cpp=True)# fails on some systems with C++ x = complex(12.34, 56.78) result = lib.f1(x) assert abs(result - abs(x)) < 1e-11 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy cffi-char16-char32: Copy failing test from the CPython cffi test suite; fix it (for 16-bit
Author: Armin Rigo Branch: cffi-char16-char32 Changeset: r91515:35d3643b476a Date: 2017-06-04 23:38 +0200 http://bitbucket.org/pypy/pypy/changeset/35d3643b476a/ Log:Copy failing test from the CPython cffi test suite; fix it (for 16-bit unicode chars) diff --git a/pypy/module/_cffi_backend/test/test_ffi_obj.py b/pypy/module/_cffi_backend/test/test_ffi_obj.py --- a/pypy/module/_cffi_backend/test/test_ffi_obj.py +++ b/pypy/module/_cffi_backend/test/test_ffi_obj.py @@ -555,3 +555,11 @@ import _cffi_backend as _cffi1_backend ffi = _cffi1_backend.FFI() raises(ffi.error, ffi.cast, "int[-5]", 0) + +def test_char32_t(self): +import _cffi_backend as _cffi1_backend +ffi = _cffi1_backend.FFI() +z = ffi.new("char32_t[]", u'\U00012345') +assert len(z) == 2 +assert ffi.cast("int *", z)[0] == 0x12345 +assert list(z) == [u'\U00012345', u'\x00'] # maybe a 2-unichars str diff --git a/pypy/module/_cffi_backend/wchar_helper.py b/pypy/module/_cffi_backend/wchar_helper.py --- a/pypy/module/_cffi_backend/wchar_helper.py +++ b/pypy/module/_cffi_backend/wchar_helper.py @@ -153,8 +153,9 @@ # we assume here that target_length == unicode_size_as_char32(u). ptr = rffi.cast(rffi.UINTP, target_ptr) src_index = 0 +last_surrogate_pos = len(u) - 2 for i in range(target_length): -if i < target_length - 1 and is_surrogate(u, src_index): +if src_index <= last_surrogate_pos and is_surrogate(u, src_index): ordinal = as_surrogate(u, src_index) src_index += 2 else: ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy release-pypy3.5-5.x: pypy3 manpage
Author: Stefano Rivera Branch: release-pypy3.5-5.x Changeset: r91513:ed6022df8666 Date: 2017-06-04 23:05 +0300 http://bitbucket.org/pypy/pypy/changeset/ed6022df8666/ Log:pypy3 manpage (grafted from e00caafaf849ac80d2aeb16b3fc6803f6526719c) diff --git a/pypy/doc/conf.py b/pypy/doc/conf.py --- a/pypy/doc/conf.py +++ b/pypy/doc/conf.py @@ -222,8 +222,8 @@ # -- Options for manpage output- man_pages = [ - ('man/pypy.1', 'pypy', - u'fast, compliant alternative implementation of the Python language', + ('man/pypy3.1', 'pypy3', + u'fast, compliant alternative implementation of the Python 3 language', u'The PyPy Project', 1) ] diff --git a/pypy/doc/man/pypy.1.rst b/pypy/doc/man/pypy3.1.rst copy from pypy/doc/man/pypy.1.rst copy to pypy/doc/man/pypy3.1.rst --- a/pypy/doc/man/pypy.1.rst +++ b/pypy/doc/man/pypy3.1.rst @@ -1,14 +1,14 @@ -== - pypy -== +=== + pypy3 +=== -.. note: this is turned into a regular man page "pypy.1" by +.. note: this is turned into a regular man page "pypy3.1" by doing "make man" in pypy/doc/ SYNOPSIS -``pypy`` [*options*] +``pypy3`` [*options*] [``-c`` *cmd*\ \|\ ``-m`` *mod*\ \|\ *file.py*\ \|\ ``-``\ ] [*arg*\ ...] @@ -69,7 +69,7 @@ === ``PYTHONPATH`` -Add directories to pypy's module search path. +Add directories to pypy3's module search path. The format is the same as shell's ``PATH``. ``PYTHONSTARTUP`` @@ -132,4 +132,4 @@ SEE ALSO -**python**\ (1) +**python3**\ (1) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy release-pypy3.5-5.x: Expose SOABI in sysconfig in pypy3 too
Author: Stefano Rivera Branch: release-pypy3.5-5.x Changeset: r91514:81df83380eea Date: 2017-06-04 23:05 +0300 http://bitbucket.org/pypy/pypy/changeset/81df83380eea/ Log:Expose SOABI in sysconfig in pypy3 too (grafted from 228f8b4206aea43feb6621ed1df7db94d0507ebf) diff --git a/lib_pypy/_sysconfigdata.py b/lib_pypy/_sysconfigdata.py --- a/lib_pypy/_sysconfigdata.py +++ b/lib_pypy/_sysconfigdata.py @@ -5,5 +5,6 @@ build_time_vars = { "EXT_SUFFIX": so_ext, "SHLIB_SUFFIX": so_ext, +"SOABI": '-'.join(so_ext.split('.')[1].split('-')[:2]), "SO": so_ext # deprecated in Python 3, for backward compatibility } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy default: Backport 5de3a64179bafcd440b32849b1129ed1fea47b85 from CPython.
Author: Alex Gaynor Branch: Changeset: r91512:71f3e458447f Date: 2017-06-04 15:45 -0400 http://bitbucket.org/pypy/pypy/changeset/71f3e458447f/ Log:Backport 5de3a64179bafcd440b32849b1129ed1fea47b85 from CPython. This will speed up usage of the warning module considerably diff --git a/lib-python/2.7/warnings.py b/lib-python/2.7/warnings.py --- a/lib-python/2.7/warnings.py +++ b/lib-python/2.7/warnings.py @@ -309,9 +309,12 @@ def __init__(self, message, category, filename, lineno, file=None, line=None): -local_values = locals() -for attr in self._WARNING_DETAILS: -setattr(self, attr, local_values[attr]) +self.message = message +self.category = category +self.filename = filename +self.lineno = lineno +self.file = file +self.line = line self._category_name = category.__name__ if category else None def __str__(self): ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy cffi-char16-char32: import cffi/5f90dcd1ce55
Author: Armin Rigo Branch: cffi-char16-char32 Changeset: r91511:c7b24a4c9b2d Date: 2017-06-04 16:20 +0200 http://bitbucket.org/pypy/pypy/changeset/c7b24a4c9b2d/ Log:import cffi/5f90dcd1ce55 diff --git a/lib_pypy/cffi/_cffi_include.h b/lib_pypy/cffi/_cffi_include.h --- a/lib_pypy/cffi/_cffi_include.h +++ b/lib_pypy/cffi/_cffi_include.h @@ -62,16 +62,11 @@ typedef unsigned char _Bool; # endif # endif -# if _MSC_VER < 1900 || !defined(__cplusplus) /* MSVC < 2015, or plain C */ -typedef uint16_t char16_t; -typedef uint32_t char32_t; -# endif #else # include # if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux) # include # endif -# include #endif #ifdef __GNUC__ diff --git a/lib_pypy/cffi/vengine_cpy.py b/lib_pypy/cffi/vengine_cpy.py --- a/lib_pypy/cffi/vengine_cpy.py +++ b/lib_pypy/cffi/vengine_cpy.py @@ -808,7 +808,8 @@ #include /* this block of #ifs should be kept exactly identical between - c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py */ + c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py + and cffi/_cffi_include.h */ #if defined(_MSC_VER) # include/* for alloca() */ # if _MSC_VER < 1600 /* MSVC < 2010 */ @@ -842,11 +843,13 @@ # include # endif # if _MSC_VER < 1800 /* MSVC < 2013 */ - typedef unsigned char _Bool; +# ifndef __cplusplus +typedef unsigned char _Bool; +# endif # endif #else # include -# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) +# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux) # include # endif #endif diff --git a/lib_pypy/cffi/vengine_gen.py b/lib_pypy/cffi/vengine_gen.py --- a/lib_pypy/cffi/vengine_gen.py +++ b/lib_pypy/cffi/vengine_gen.py @@ -627,7 +627,8 @@ #include/* XXX for ssize_t on some platforms */ /* this block of #ifs should be kept exactly identical between - c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py */ + c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py + and cffi/_cffi_include.h */ #if defined(_MSC_VER) # include/* for alloca() */ # if _MSC_VER < 1600 /* MSVC < 2010 */ @@ -661,11 +662,13 @@ # include # endif # if _MSC_VER < 1800 /* MSVC < 2013 */ - typedef unsigned char _Bool; +# ifndef __cplusplus +typedef unsigned char _Bool; +# endif # endif #else # include -# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) +# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux) # include # endif #endif diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py --- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py +++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py @@ -2266,6 +2266,11 @@ char32_t foo_4bytes(char32_t); """) lib = verify(ffi, "test_char16_char32_type" + no_cpp * "_nocpp", """ +#if !defined(__cplusplus) || __cplusplus < 201103L +typedef uint_least16_t char16_t; +typedef uint_least32_t char32_t; +#endif + char16_t foo_2bytes(char16_t a) { return (char16_t)(a + 42); } char32_t foo_4bytes(char32_t a) { return (char32_t)(a + 42); } """, no_cpp=no_cpp) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] cffi default: Didn't figure out how to cleanly define charN_t inside _cffi_include.h.
Author: Armin Rigo Branch: Changeset: r2975:5f90dcd1ce55 Date: 2017-06-04 16:18 +0200 http://bitbucket.org/cffi/cffi/changeset/5f90dcd1ce55/ Log:Didn't figure out how to cleanly define charN_t inside _cffi_include.h. So for now, don't. diff --git a/cffi/_cffi_include.h b/cffi/_cffi_include.h --- a/cffi/_cffi_include.h +++ b/cffi/_cffi_include.h @@ -62,16 +62,11 @@ typedef unsigned char _Bool; # endif # endif -# if _MSC_VER < 1900 || !defined(__cplusplus) /* MSVC < 2015, or plain C */ -typedef uint16_t char16_t; -typedef uint32_t char32_t; -# endif #else # include # if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux) # include # endif -# include #endif #ifdef __GNUC__ diff --git a/cffi/vengine_cpy.py b/cffi/vengine_cpy.py --- a/cffi/vengine_cpy.py +++ b/cffi/vengine_cpy.py @@ -808,7 +808,8 @@ #include /* this block of #ifs should be kept exactly identical between - c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py */ + c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py + and cffi/_cffi_include.h */ #if defined(_MSC_VER) # include/* for alloca() */ # if _MSC_VER < 1600 /* MSVC < 2010 */ @@ -842,11 +843,13 @@ # include # endif # if _MSC_VER < 1800 /* MSVC < 2013 */ - typedef unsigned char _Bool; +# ifndef __cplusplus +typedef unsigned char _Bool; +# endif # endif #else # include -# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) +# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux) # include # endif #endif diff --git a/cffi/vengine_gen.py b/cffi/vengine_gen.py --- a/cffi/vengine_gen.py +++ b/cffi/vengine_gen.py @@ -627,7 +627,8 @@ #include/* XXX for ssize_t on some platforms */ /* this block of #ifs should be kept exactly identical between - c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py */ + c/_cffi_backend.c, cffi/vengine_cpy.py, cffi/vengine_gen.py + and cffi/_cffi_include.h */ #if defined(_MSC_VER) # include/* for alloca() */ # if _MSC_VER < 1600 /* MSVC < 2010 */ @@ -661,11 +662,13 @@ # include # endif # if _MSC_VER < 1800 /* MSVC < 2013 */ - typedef unsigned char _Bool; +# ifndef __cplusplus +typedef unsigned char _Bool; +# endif # endif #else # include -# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) +# if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux) # include # endif #endif diff --git a/doc/source/ref.rst b/doc/source/ref.rst --- a/doc/source/ref.rst +++ b/doc/source/ref.rst @@ -629,9 +629,9 @@ | | or another | length 1 | ``<`` | +---++--++ | ``wchar_t``, | a unicode of length 1 | a unicode of || -| ``char16_t``, | (or maybe 2 if | length 1 | int() `[8]`, | +| ``char16_t``, | (or maybe 2 if | length 1 | int(), | | ``char32_t`` | surrogates) or | (or maybe 2 if | bool(), ``<`` | -| | another similar | surrogates) || +| `[8]` | another similar | surrogates) || +---++--++ | ``float``, | a float or anything on | a Python float | float(), int(),| | ``double`` | which float() works| | bool(), ``<`` | @@ -774,12 +774,22 @@ take directly as argument types or return type a complex type cannot be called by CFFI, unless they are directly using the API mode. -`[8]` sign of ``wchar_t``, ``char16_t`` and ``char32_t`` +`[8]` ``wchar_t``, ``char16_t`` and ``char32_t`` The ``wchar_t`` type has the same signedness as the underlying platform's. For example, on Linux, it is a signed 32-bit integer. However, the types ``char16_t`` and ``char32_t`` (*new in version - 1.11*) are always unsigned. + 1.11*) are always unsigned. **Warning:** for now, if you use + ``char16_t`` and ``char32_t`` with ``cdef()`` and ``set_source()``, + you have to make sure yourself that the types are declared by the C + source you provide to ``set_source()``. They would be declared if + you ``#include`` a library that explicitly uses them, for example, + or when using C++11. Otherwise, you need ``#include `` on + Linux, or more generally something like ``typedef uint_least16_t + char16_t;``. This is not done automatically by CFFI because + ``uchar.h`` is not standard across platforms, and writing a + ``typedef`` like above would crash if the type happens to be + already defined. .. _file: diff --git a/doc/source/whatsnew.rst b/doc/source/whatsnew.rst --- a/doc/source/whatsnew.rst +++ b/doc/source/whatsnew.rst @@ -11,7 +11,9 @@ when used as ``charN_t *`` or ``charN_t[]`` they represent a unicode string. The difference with ``wchar_t`` is that they have a known, fixed size. The
[pypy-commit] cffi default: Another missing Py_DECREF
Author: Armin Rigo Branch: Changeset: r2974:19e44e15058a Date: 2017-06-04 15:37 +0200 http://bitbucket.org/cffi/cffi/changeset/19e44e15058a/ Log:Another missing Py_DECREF diff --git a/c/realize_c_type.c b/c/realize_c_type.c --- a/c/realize_c_type.c +++ b/c/realize_c_type.c @@ -269,8 +269,11 @@ PyObject *x = realize_c_type_or_func(builder, opcodes, index); if (x == NULL || CTypeDescr_Check(x)) return (CTypeDescrObject *)x; -else -return unexpected_fn_type(x); +else { +unexpected_fn_type(x); +Py_DECREF(x); +return NULL; +} } static void _realize_name(char *target, const char *prefix, const char *srcname) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] cffi default: Figured out a memory leak in an error case
Author: Armin Rigo Branch: Changeset: r2973:6e1b6c8e1d79 Date: 2017-06-04 15:06 +0200 http://bitbucket.org/cffi/cffi/changeset/6e1b6c8e1d79/ Log:Figured out a memory leak in an error case diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c --- a/c/_cffi_backend.c +++ b/c/_cffi_backend.c @@ -4137,7 +4137,10 @@ assert(x->ct_unique_key == NULL); x->ct_unique_key = key; /* the key will be freed in ctypedescr_dealloc() */ -Py_DECREF(x); /* the 'value' in unique_cache doesn't count as 1 */ +/* the 'value' in unique_cache doesn't count as 1, but don't use + Py_DECREF(x) here because it will confuse debug builds into thinking + there was an extra DECREF in total. */ +((PyObject *)x)->ob_refcnt--; return (PyObject *)x; error: @@ -6231,6 +6234,7 @@ src = cd->c_data; itemsize = ctitem->ct_size; if (itemsize < 0) { +Py_DECREF(result); PyErr_Format(PyExc_ValueError, "'%s' points to items of unknown size", cd->c_type->ct_name); return NULL; ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy py3.5: hg merge default
Author: Manuel Jacob Branch: py3.5 Changeset: r91510:2bc0ce15d8d0 Date: 2017-06-04 14:39 +0200 http://bitbucket.org/pypy/pypy/changeset/2bc0ce15d8d0/ Log:hg merge default diff --git a/pypy/doc/release-v5.8.0.rst b/pypy/doc/release-v5.8.0.rst --- a/pypy/doc/release-v5.8.0.rst +++ b/pypy/doc/release-v5.8.0.rst @@ -8,25 +8,23 @@ the dual release. Note that PyPy3.5 supports Linux 64bit only for now. This new PyPy2.7 release includes the upstream stdlib version 2.7.13, and -PyPy3.5 (our first in the 3.5 series) includes the upstream stdlib version -3.5.3. +PyPy3.5 includes the upstream stdlib version 3.5.3. -We continue to make incremental improvements to our C-API -compatibility layer (cpyext). PyPy2 can now import and run many C-extension -packages, among the most notable are Numpy, Cython, and Pandas. Performance may -be slower than CPython, especially for frequently-called short C functions. +This release enables `profile guided optimization` of the base interpreter, +which may make unjitted code run faster. + Please let us know if your use case is slow, we have ideas how to make things faster but need real-world examples (not micro-benchmarks) of problematic code. Work proceeds at a good pace on the PyPy3.5 -version due to a grant_ from the Mozilla Foundation, hence our first 3.5.3 beta +version due to a grant_ from the Mozilla Foundation, hence our 3.5.3 beta release. Thanks Mozilla !!! While we do not pass all tests yet, asyncio works and as `these benchmarks show`_ it already gives a nice speed bump. We also backported the ``f""`` formatting from 3.6 (as an exception; otherwise "PyPy3.5" supports the Python 3.5 language). -CFFI_ has been updated to 1.10, improving an already great package for -interfacing with C. +CFFI_, which is part of the PyPy release, has been updated to an unreleased 1.10.1, +improving an already great package for interfacing with C. As always, this release fixed many issues and bugs raised by the growing community of PyPy users. We strongly recommend updating. @@ -44,6 +42,7 @@ improvements, tweaking popular `modules`_ to run on pypy, or general `help`_ with making RPython's JIT even better. +.. _`profile guided optimization`: https://pythonfiles.wordpress.com/2017/05/12/enabling-profile-guided-optimizations-for-pypy .. _CFFI: https://cffi.readthedocs.io/en/latest/whatsnew.html .. _grant: https://morepypy.blogspot.com/2016/08/pypy-gets-funding-from-mozilla-for.html .. _`PyPy`: index.html @@ -81,28 +80,52 @@ See also issues that were resolved_ +Note that these are also merged into PyPy 3.5 + * New features and cleanups - * Implement PyModule_New, + * Implement PyModule_New, Py_GetRecursionLimit, Py_SetRecursionLimit, +Py_EnterRecursiveCall, Py_LeaveRecursiveCall, populate tp_descr_get and +tp_descr_set slots, +add conversions of ``__len__``, ``__setitem__``, ``__delitem__`` to +appropriate C-API slots * Fix for multiple inheritance in app-level for C-API defined classes * Revert a change that removed tp_getattr (Part of the 5.7.1 bugfix release) * Document more differences with CPython here_ * Add native PyPy support to profile frames in vmprof * Fix an issue with Exception order on failed import * Fix for a corner case of __future__ imports + * Update packaged Windows zlib, sqlite, expat and OpenSSL to versions used +by CPython + * Allow windows builds to use ``jom.exe`` for compiling in parallel + * Rewrite ``itertools.groupby()``, following CPython + * Backport changes from PyPy 3.5 to minimize the code differences + * Improve support for BSD using patches contributed by downstream + * Support profile-guided optimization, enabled with --profopt, , and +specify training data ``profoptpath`` -* Bug Fixes +* Bug Fixes * Correctly handle dict.pop where the popping key is not the same type as the dict's and pop is called with a default (Part of the 5.7.1 bugfix release) * Improve our file's universal newline .readline implementation for ``\n``, ``\r`` confusion + * Tweak issue where ctype array ``_base`` was set on empty arrays, now it +is closer to the implementation in CPython + * Fix critical bugs in shadowstack that crashed multithreaded programs and +very rarely showed up even in single threaded programs + * Remove flaky fastpath function call from ctypes + * Support passing a buffersize of 0 to socket.getsockopt + * Avoid hash() returning -1 in cpyext * Performance improvements: * Tweaks made to improve performance by reducing the number of guards inserted in jitted code, based on feedback from users * Add garbage collector memory pressure to some c-level allocations + * Speed up struck.pack, struck.pack_into + * Performance tweaks to round(x, n) for the case n == 0 + * Improve zipfile performance by not doing repeated string concatenation * RPython improvements @@ -119,6 +142,11 @@ blocks are moved off-line. Also, t
[pypy-commit] pypy cffi-char16-char32: Detect and complain about unicode "characters" that are greater than
Author: Armin Rigo Branch: cffi-char16-char32 Changeset: r91509:649a8f742c90 Date: 2017-06-04 14:25 +0200 http://bitbucket.org/pypy/pypy/changeset/649a8f742c90/ Log:Detect and complain about unicode "characters" that are greater than 0x10 when attempting to convert to a pair of surrogates diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py --- a/pypy/module/_cffi_backend/ctypeprim.py +++ b/pypy/module/_cffi_backend/ctypeprim.py @@ -179,7 +179,12 @@ return self.space.newunicode(unichardata[0]) else: value = misc.read_raw_ulong_data(cdata, self.size) # r_uint -u = wchar_helper.ordinal_to_unicode(value) +try: +u = wchar_helper.ordinal_to_unicode(value) +except wchar_helper.OutOfRange as e: +raise oefmt(self.space.w_ValueError, +"char32_t out of range for " +"conversion to unicode: %s", hex(e.ordinal)) return self.space.newunicode(u) def string(self, cdataobj, maxlen): diff --git a/pypy/module/_cffi_backend/ctypeptr.py b/pypy/module/_cffi_backend/ctypeptr.py --- a/pypy/module/_cffi_backend/ctypeptr.py +++ b/pypy/module/_cffi_backend/ctypeptr.py @@ -102,7 +102,12 @@ "(got %d characters)", self.name, n) add_final_zero = (n != self.length) if self.ctitem.size == 2: -wchar_helper.unicode_to_char16(s, cdata, n, add_final_zero) +try: +wchar_helper.unicode_to_char16(s, cdata, n, add_final_zero) +except wchar_helper.OutOfRange as e: +raise oefmt(self.space.w_ValueError, +"unicode character ouf of range for " +"conversion to char16_t: %s", hex(e.ordinal)) else: wchar_helper.unicode_to_char32(s, cdata, n, add_final_zero) else: diff --git a/pypy/module/_cffi_backend/wchar_helper.py b/pypy/module/_cffi_backend/wchar_helper.py --- a/pypy/module/_cffi_backend/wchar_helper.py +++ b/pypy/module/_cffi_backend/wchar_helper.py @@ -14,10 +14,12 @@ def ordinal_to_unicode(ordinal):# 'ordinal' is a r_uint if ordinal <= 0x: return unichr(intmask(ordinal)) -else: +elif ordinal <= 0x10: ordinal = intmask(ordinal - 0x1) return (unichr(0xD800 | (ordinal >> 10)) + unichr(0xDC00 | (ordinal & 0x3FF))) +else: +raise OutOfRange(ordinal) def is_surrogate(u, index): return (unichr(0xD800) <= u[index + 0] <= unichr(0xDBFF) and @@ -174,8 +176,8 @@ for uc in u: ordinal = ord(uc) if ordinal > 0x: -# NB. like CPython, ignore the problem of unicode string -# objects containing characters greater than sys.maxunicode +if ordinal > 0x10: +raise OutOfRange(ordinal) ordinal -= 0x1 ptr[0] = rffi.cast(rffi.USHORT, 0xD800 | (ordinal >> 10)) ptr[1] = rffi.cast(rffi.USHORT, 0xDC00 | (ordinal & 0x3FF)) ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] cffi default: Detect and complain when trying to convert a char32_t to unicode if
Author: Armin Rigo Branch: Changeset: r2972:0300a91f7fb4 Date: 2017-06-04 14:24 +0200 http://bitbucket.org/cffi/cffi/changeset/0300a91f7fb4/ Log:Detect and complain when trying to convert a char32_t to unicode if the unicode uses 16-bit chars and the original char32_t is out of range even for surrogates diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c --- a/c/_cffi_backend.c +++ b/c/_cffi_backend.c @@ -1390,10 +1390,9 @@ if (n != ct->ct_length) n++; if (ctitem->ct_size == 4) -_my_PyUnicode_AsChar32(init, (cffi_char32_t *)data, n); +return _my_PyUnicode_AsChar32(init, (cffi_char32_t *)data, n); else -_my_PyUnicode_AsChar16(init, (cffi_char16_t *)data, n); -return 0; +return _my_PyUnicode_AsChar16(init, (cffi_char16_t *)data, n); } } else { diff --git a/c/wchar_helper.h b/c/wchar_helper.h --- a/c/wchar_helper.h +++ b/c/wchar_helper.h @@ -195,9 +195,9 @@ return result; } -static void _my_PyUnicode_AsChar16(PyObject *unicode, - cffi_char16_t *result, - Py_ssize_t resultlen) +static int _my_PyUnicode_AsChar16(PyObject *unicode, + cffi_char16_t *result, + Py_ssize_t resultlen) { Py_ssize_t len = PyUnicode_GET_SIZE(unicode); Py_UNICODE *u = PyUnicode_AS_UNICODE(unicode); @@ -208,9 +208,12 @@ #else cffi_char32_t ordinal = u[i]; if (ordinal > 0x) { -/* NB. like CPython, ignore the problem of unicode string objects - * containing characters greater than sys.maxunicode. It is - * easier to not add exception handling here */ +if (ordinal > 0x10) { +PyErr_Format(PyExc_ValueError, + "unicode character out of range for " + "conversion to char16_t: 0x%x", (int)ordinal); +return -1; +} ordinal -= 0x1; *result++ = 0xD800 | (ordinal >> 10); *result++ = 0xDC00 | (ordinal & 0x3FF); @@ -219,11 +222,12 @@ #endif *result++ = ordinal; } +return 0; } -static void _my_PyUnicode_AsChar32(PyObject *unicode, - cffi_char32_t *result, - Py_ssize_t resultlen) +static int _my_PyUnicode_AsChar32(PyObject *unicode, + cffi_char32_t *result, + Py_ssize_t resultlen) { Py_UNICODE *u = PyUnicode_AS_UNICODE(unicode); Py_ssize_t i; @@ -238,4 +242,5 @@ result[i] = ordinal; u++; } +return 0; } ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] cffi default: extra test
Author: Armin Rigo Branch: Changeset: r2971:a5114b7d3887 Date: 2017-06-04 13:28 +0200 http://bitbucket.org/cffi/cffi/changeset/a5114b7d3887/ Log:extra test diff --git a/c/test_c.py b/c/test_c.py --- a/c/test_c.py +++ b/c/test_c.py @@ -2265,6 +2265,11 @@ py.test.raises(TypeError, newp, BChar16A, [x]) x = cast(BChar16, 'A') py.test.raises(TypeError, newp, BChar32A, [x]) +# +a = newp(BChar16A, u+'\U00012345') +assert len(a) == 3 +a = newp(BChar32A, u+'\U00012345') +assert len(a) == 2 # even if the Python unicode string above is 2 chars def test_keepalive_struct(): # exception to the no-keepalive rule: p=newp(BStructPtr) returns a ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy cffi-char16-char32: Bump the internal version max
Author: Armin Rigo Branch: cffi-char16-char32 Changeset: r91508:113befadf44a Date: 2017-06-04 12:33 +0200 http://bitbucket.org/pypy/pypy/changeset/113befadf44a/ Log:Bump the internal version max diff --git a/pypy/module/_cffi_backend/cffi1_module.py b/pypy/module/_cffi_backend/cffi1_module.py --- a/pypy/module/_cffi_backend/cffi1_module.py +++ b/pypy/module/_cffi_backend/cffi1_module.py @@ -9,7 +9,7 @@ VERSION_MIN= 0x2601 -VERSION_MAX= 0x27FF +VERSION_MAX= 0x28FF VERSION_EXPORT = 0x0A03 ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy cffi-char16-char32: import cffi/6c465c147687
Author: Armin Rigo Branch: cffi-char16-char32 Changeset: r91507:b061a2e969ec Date: 2017-06-04 10:29 +0200 http://bitbucket.org/pypy/pypy/changeset/b061a2e969ec/ Log:import cffi/6c465c147687 diff --git a/lib_pypy/cffi/_cffi_include.h b/lib_pypy/cffi/_cffi_include.h --- a/lib_pypy/cffi/_cffi_include.h +++ b/lib_pypy/cffi/_cffi_include.h @@ -62,11 +62,16 @@ typedef unsigned char _Bool; # endif # endif +# if _MSC_VER < 1900 || !defined(__cplusplus) /* MSVC < 2015, or plain C */ +typedef uint16_t char16_t; +typedef uint32_t char32_t; +# endif #else # include # if (defined (__SVR4) && defined (__sun)) || defined(_AIX) || defined(__hpux) # include # endif +# include #endif #ifdef __GNUC__ @@ -159,9 +164,9 @@ #define _cffi_from_c_struct \ ((PyObject *(*)(char *, struct _cffi_ctypedescr *))_cffi_exports[18]) #define _cffi_to_c_wchar_t \ -((wchar_t(*)(PyObject *))_cffi_exports[19]) +((_cffi_wchar_t(*)(PyObject *))_cffi_exports[19]) #define _cffi_from_c_wchar_t \ -((PyObject *(*)(wchar_t))_cffi_exports[20]) +((PyObject *(*)(_cffi_wchar_t))_cffi_exports[20]) #define _cffi_to_c_long_double \ ((long double(*)(PyObject *))_cffi_exports[21]) #define _cffi_to_c__Bool \ @@ -174,7 +179,11 @@ #define _CFFI_CPIDX 25 #define _cffi_call_python\ ((void(*)(struct _cffi_externpy_s *, char *))_cffi_exports[_CFFI_CPIDX]) -#define _CFFI_NUM_EXPORTS 26 +#define _cffi_to_c_wchar3216_t \ +((int(*)(PyObject *))_cffi_exports[26]) +#define _cffi_from_c_wchar3216_t \ +((PyObject *(*)(int))_cffi_exports[27]) +#define _CFFI_NUM_EXPORTS 28 struct _cffi_ctypedescr; @@ -215,6 +224,46 @@ return NULL; } + +#ifdef HAVE_WCHAR_H +typedef wchar_t _cffi_wchar_t; +#else +typedef uint16_t _cffi_wchar_t; /* same random pick as _cffi_backend.c */ +#endif + +_CFFI_UNUSED_FN static uint16_t _cffi_to_c_char16_t(PyObject *o) +{ +if (sizeof(_cffi_wchar_t) == 2) +return (uint16_t)_cffi_to_c_wchar_t(o); +else +return (uint16_t)_cffi_to_c_wchar3216_t(o); +} + +_CFFI_UNUSED_FN static PyObject *_cffi_from_c_char16_t(uint16_t x) +{ +if (sizeof(_cffi_wchar_t) == 2) +return _cffi_from_c_wchar_t(x); +else +return _cffi_from_c_wchar3216_t(x); +} + +_CFFI_UNUSED_FN static int _cffi_to_c_char32_t(PyObject *o) +{ +if (sizeof(_cffi_wchar_t) == 4) +return (int)_cffi_to_c_wchar_t(o); +else +return (int)_cffi_to_c_wchar3216_t(o); +} + +_CFFI_UNUSED_FN static PyObject *_cffi_from_c_char32_t(int x) +{ +if (sizeof(_cffi_wchar_t) == 4) +return _cffi_from_c_wchar_t(x); +else +return _cffi_from_c_wchar3216_t(x); +} + + /** end CPython-specific section **/ #else _CFFI_UNUSED_FN diff --git a/lib_pypy/cffi/cffi_opcode.py b/lib_pypy/cffi/cffi_opcode.py --- a/lib_pypy/cffi/cffi_opcode.py +++ b/lib_pypy/cffi/cffi_opcode.py @@ -107,9 +107,10 @@ PRIM_UINTMAX = 47 PRIM_FLOATCOMPLEX = 48 PRIM_DOUBLECOMPLEX = 49 +PRIM_CHAR16= 50 +PRIM_CHAR32= 51 - -_NUM_PRIM = 50 +_NUM_PRIM = 52 _UNKNOWN_PRIM = -1 _UNKNOWN_FLOAT_PRIM= -2 _UNKNOWN_LONG_DOUBLE = -3 @@ -135,6 +136,8 @@ 'double _Complex':PRIM_DOUBLECOMPLEX, '_Bool': PRIM_BOOL, 'wchar_t':PRIM_WCHAR, +'char16_t': PRIM_CHAR16, +'char32_t': PRIM_CHAR32, 'int8_t': PRIM_INT8, 'uint8_t':PRIM_UINT8, 'int16_t':PRIM_INT16, diff --git a/lib_pypy/cffi/model.py b/lib_pypy/cffi/model.py --- a/lib_pypy/cffi/model.py +++ b/lib_pypy/cffi/model.py @@ -122,6 +122,8 @@ '_Bool': 'i', # the following types are not primitive in the C sense 'wchar_t':'c', +'char16_t': 'c', +'char32_t': 'c', 'int8_t': 'i', 'uint8_t':'i', 'int16_t':'i', diff --git a/lib_pypy/cffi/parse_c_type.h b/lib_pypy/cffi/parse_c_type.h --- a/lib_pypy/cffi/parse_c_type.h +++ b/lib_pypy/cffi/parse_c_type.h @@ -81,8 +81,10 @@ #define _CFFI_PRIM_UINTMAX 47 #define _CFFI_PRIM_FLOATCOMPLEX 48 #define _CFFI_PRIM_DOUBLECOMPLEX 49 +#define _CFFI_PRIM_CHAR16 50 +#define _CFFI_PRIM_CHAR32 51 -#define _CFFI__NUM_PRIM 50 +#define _CFFI__NUM_PRIM 52 #define _CFFI__UNKNOWN_PRIM (-1) #define _CFFI__UNKNOWN_FLOAT_PRIM (-2) #define _CFFI__UNKNOWN_LONG_DOUBLE(-3) diff --git a/lib_pypy/cffi/recompiler.py b/lib_pypy/cffi/recompiler.py --- a/lib_pypy/cffi/recompiler.py +++
[pypy-commit] pypy default: Fix test on 32-bit
Author: Armin Rigo Branch: Changeset: r91506:e2ba7d32b791 Date: 2017-06-04 10:27 +0200 http://bitbucket.org/pypy/pypy/changeset/e2ba7d32b791/ Log:Fix test on 32-bit diff --git a/rpython/jit/backend/x86/test/test_runner.py b/rpython/jit/backend/x86/test/test_runner.py --- a/rpython/jit/backend/x86/test/test_runner.py +++ b/rpython/jit/backend/x86/test/test_runner.py @@ -33,7 +33,7 @@ add_loop_instructions = ('mov; ' 'lea; '# a nop, for the label 'add; test; je; jmp;') # plus some padding -bridge_loop_instructions = 'cmp; jge; mov; mov; call; jmp;' +bridge_loop_instructions = 'cmp; jl; jmp;' else: add_loop_instructions = ('mov; ' 'nop; '# for the label ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy cffi-char16-char32: Translation fixes
Author: Armin Rigo Branch: cffi-char16-char32 Changeset: r91505:abfa8aff51d7 Date: 2017-06-04 10:06 +0200 http://bitbucket.org/pypy/pypy/changeset/abfa8aff51d7/ Log:Translation fixes diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py --- a/pypy/module/_cffi_backend/ctypeprim.py +++ b/pypy/module/_cffi_backend/ctypeprim.py @@ -218,7 +218,7 @@ else: try: u = wchar_helper.unicode_from_char32(ptr, length) -except OutOfRange as e: +except wchar_helper.OutOfRange as e: raise oefmt(self.space.w_ValueError, "char32_t out of range for " "conversion to unicode: %s", hex(e.ordinal)) diff --git a/pypy/module/_cffi_backend/wchar_helper.py b/pypy/module/_cffi_backend/wchar_helper.py --- a/pypy/module/_cffi_backend/wchar_helper.py +++ b/pypy/module/_cffi_backend/wchar_helper.py @@ -39,6 +39,8 @@ class OutOfRange(Exception): +ordinal = 0 + def __init__(self, ordinal): ordinal = intmask(rffi.cast(rffi.INT, ordinal)) self.ordinal = ordinal ___ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit
[pypy-commit] pypy cffi-char16-char32: in-progress
Author: Armin Rigo Branch: cffi-char16-char32 Changeset: r91504:8bc39f008ba8 Date: 2017-06-04 09:58 +0200 http://bitbucket.org/pypy/pypy/changeset/8bc39f008ba8/ Log:in-progress diff --git a/pypy/module/_cffi_backend/ctypearray.py b/pypy/module/_cffi_backend/ctypearray.py --- a/pypy/module/_cffi_backend/ctypearray.py +++ b/pypy/module/_cffi_backend/ctypearray.py @@ -36,8 +36,7 @@ datasize = self.size # if datasize < 0: -from pypy.module._cffi_backend import misc -w_init, length = misc.get_new_array_length(space, w_init) +w_init, length = self.get_new_array_length(w_init) try: datasize = ovfcheck(length * self.ctitem.size) except OverflowError: @@ -53,6 +52,29 @@ self.convert_from_object(ptr, w_init) return cdata +def get_new_array_length(self, w_value): +space = self.space +if (space.isinstance_w(w_value, space.w_list) or +space.isinstance_w(w_value, space.w_tuple)): +return (w_value, space.int_w(space.len(w_value))) +elif space.isinstance_w(w_value, space.w_bytes): +# from a string, we add the null terminator +s = space.bytes_w(w_value) +return (w_value, len(s) + 1) +elif space.isinstance_w(w_value, space.w_unicode): +from pypy.module._cffi_backend import wchar_helper +u = space.unicode_w(w_value) +if self.ctitem.size == 2: +length = wchar_helper.unicode_size_as_char16(u) +else: +length = wchar_helper.unicode_size_as_char32(u) +return (w_value, length + 1) +else: +explicitlength = space.getindex_w(w_value, space.w_OverflowError) +if explicitlength < 0: +raise oefmt(space.w_ValueError, "negative array length") +return (space.w_None, explicitlength) + def _check_subscript_index(self, w_cdata, i): space = self.space if i < 0: diff --git a/pypy/module/_cffi_backend/ctypeprim.py b/pypy/module/_cffi_backend/ctypeprim.py --- a/pypy/module/_cffi_backend/ctypeprim.py +++ b/pypy/module/_cffi_backend/ctypeprim.py @@ -42,12 +42,13 @@ def cast_unicode(self, w_ob): space = self.space s = space.unicode_w(w_ob) -XX -if len(s) != 1: +try: +ordinal = wchar_helper.unicode_to_ordinal(s) +except ValueError: raise oefmt(space.w_TypeError, "cannot cast unicode string of length %d to ctype '%s'", len(s), self.name) -return ord(s[0]) +return intmask(ordinal) def cast(self, w_ob): from pypy.module._cffi_backend import ctypeptr diff --git a/pypy/module/_cffi_backend/ctypeptr.py b/pypy/module/_cffi_backend/ctypeptr.py --- a/pypy/module/_cffi_backend/ctypeptr.py +++ b/pypy/module/_cffi_backend/ctypeptr.py @@ -4,9 +4,9 @@ from rpython.rlib import rposix from rpython.rlib.rarithmetic import ovfcheck -from rpython.rtyper.annlowlevel import llstr, llunicode +from rpython.rtyper.annlowlevel import llstr from rpython.rtyper.lltypesystem import lltype, rffi -from rpython.rtyper.lltypesystem.rstr import copy_string_to_raw, copy_unicode_to_raw +from rpython.rtyper.lltypesystem.rstr import copy_string_to_raw from pypy.interpreter.error import OperationError, oefmt, wrap_oserror from pypy.module._cffi_backend import cdataobj, misc, ctypeprim, ctypevoid @@ -88,31 +88,23 @@ if n != self.length: cdata[n] = '\x00' elif isinstance(self.ctitem, ctypeprim.W_CTypePrimitiveUniChar): +from pypy.module._cffi_backend import wchar_helper if not space.isinstance_w(w_ob, space.w_unicode): raise self._convert_error("unicode or list or tuple", w_ob) s = space.unicode_w(w_ob) -XXX -n = len(s) +if self.ctitem.size == 2: +n = wchar_helper.unicode_size_as_char16(s) +else: +n = wchar_helper.unicode_size_as_char32(s) if self.length >= 0 and n > self.length: raise oefmt(space.w_IndexError, "initializer unicode string is too long for '%s' " "(got %d characters)", self.name, n) - - - - +add_final_zero = (n != self.length) if self.ctitem.size == 2: -length = wchar_helper.measure_length_16(ptr, length) +wchar_helper.unicode_to_char16(s, cdata, n, add_final_zero) else: -length = wchar_helper.measure_length_32(ptr, length) - - - - -unichardata = rffi.cast(rffi.CWCHARP, cdata) -copy_unicode_to_raw(llunicode(s), unichardata, 0, n) -if n != self.length: -unichardata[n]