diff options
author | Robert Bradshaw <robertwb@gmail.com> | 2019-02-03 01:08:14 +0100 |
---|---|---|
committer | Robert Bradshaw <robertwb@gmail.com> | 2019-02-03 01:15:03 +0100 |
commit | 901cfed4a7ba5cc64e5d55757ad92eb007006084 (patch) | |
tree | d057d0088333c46c4b5a846142109fca78de3640 /Cython/Compiler/ModuleNode.py | |
parent | b00fd6ae6a90fa483c89dd3e70de432b178c3e01 (diff) | |
download | cython-901cfed4a7ba5cc64e5d55757ad92eb007006084.tar.gz |
Recognize that the default encoding is always utf-8 in Python 3.
This fixes Github issue #2819.
Diffstat (limited to 'Cython/Compiler/ModuleNode.py')
-rw-r--r-- | Cython/Compiler/ModuleNode.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index e9f56f0d9..d5742de71 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -693,10 +693,13 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): if c_string_type not in ('bytes', 'bytearray') and not c_string_encoding: error(self.pos, "a default encoding must be provided if c_string_type is not a byte type") code.putln('#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII %s' % int(c_string_encoding == 'ascii')) + code.putln('#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 %s' % + int(c_string_encoding.replace('-', '').lower() == 'utf8')) if c_string_encoding == 'default': code.putln('#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 1') else: - code.putln('#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT 0') + code.putln('#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT ' + '(PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8)') code.putln('#define __PYX_DEFAULT_STRING_ENCODING "%s"' % c_string_encoding) if c_string_type == 'bytearray': c_string_func_name = 'ByteArray' |