diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2013-11-06 07:36:03 +0100 |
---|---|---|
committer | Stefan Behnel <stefan_ml@behnel.de> | 2013-11-06 07:36:03 +0100 |
commit | 8524b21fc885c2bbef582bc5b893be4bf3a677b0 (patch) | |
tree | cf78e4c50ce00b6b05ccd4dbe1c2befd393f6ba9 /Cython/Compiler/ModuleNode.py | |
parent | 1bd61835cd48b93bd84c12898bef80289f161ed8 (diff) | |
download | cython-8524b21fc885c2bbef582bc5b893be4bf3a677b0.tar.gz |
support bytearray as auto encoding string type
--HG--
rename : tests/run/str_ascii_auto_encoding.pyx => tests/run/bytearray_ascii_auto_encoding.pyx
rename : tests/run/str_default_auto_encoding.pyx => tests/run/bytearray_default_auto_encoding.pyx
Diffstat (limited to 'Cython/Compiler/ModuleNode.py')
-rw-r--r-- | Cython/Compiler/ModuleNode.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index c45c444c8..2370bbac8 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -580,16 +580,20 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): c_string_type = env.directives['c_string_type'] c_string_encoding = env.directives['c_string_encoding'] - if c_string_type != 'bytes' and not c_string_encoding: - error(self.pos, "a default encoding must be provided if c_string_type != bytes") + 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')) 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 "%s"' % c_string_encoding) - code.putln('#define __Pyx_PyObject_FromString __Pyx_Py%s_FromString' % c_string_type.title()) - code.putln('#define __Pyx_PyObject_FromStringAndSize __Pyx_Py%s_FromStringAndSize' % c_string_type.title()) + if c_string_type == 'bytearray': + c_string_func_name = 'ByteArray' + else: + c_string_func_name = c_string_type.title() + code.putln('#define __Pyx_PyObject_FromString __Pyx_Py%s_FromString' % c_string_func_name) + code.putln('#define __Pyx_PyObject_FromStringAndSize __Pyx_Py%s_FromStringAndSize' % c_string_func_name) code.put(UtilityCode.load_as_string("TypeConversions", "TypeConversion.c")[0]) # These utility functions are assumed to exist and used elsewhere. |