diff options
Diffstat (limited to 'Cython/Compiler/ModuleNode.py')
-rw-r--r-- | Cython/Compiler/ModuleNode.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index f431a70de..645c34748 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -556,7 +556,17 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln("#endif") code.putln("") code.put(UtilityCode.load_as_string("UtilityFunctionPredeclarations", "ModuleSetupCode.c")[0]) + + 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") + code.putln('#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII %s' % int(c_string_encoding == 'ascii')) + 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()) code.put(UtilityCode.load_as_string("TypeConversions", "TypeConversion.c")[0]) + code.put(Nodes.branch_prediction_macros) code.putln('') code.putln('static PyObject *%s;' % env.module_cname) @@ -1888,6 +1898,10 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln("/*--- Initialize various global constants etc. ---*/") code.putln(code.error_goto_if_neg("__Pyx_InitGlobals()", self.pos)) + code.putln("#ifdef __PYX_DEFAULT_STRING_ENCODING_IS_ASCII") + code.putln("if (__Pyx_init_sys_getdefaultencoding_not_ascii() < 0) %s" % code.error_goto(self.pos)) + code.putln("#endif") + __main__name = code.globalstate.get_py_string_const( EncodedString("__main__"), identifier=True) code.putln("if (%s%s) {" % (Naming.module_is_main, self.full_module_name.replace('.', '__'))) |