Commit 73521046 authored by da-woods's avatar da-woods Committed by GitHub

Fix windows linkage error for unicode modules by providing a dummy function (GH-4125)

A bug in distutils means that it tries to export a slightly incorrectly named PyInitU function. The fix in https://bugs.python.org/issue39432 wasn't quite right (`"_name".encode("punycode") != "name".encode("punycode")`) and thus the "unicode_imports" test is failing on Windows 3.8+ when distutils explicitly tries to export a non-existing symbol.

We now create a dummy function with that alternative name so that the export doesn't fail.
parent b28ca334
......@@ -2757,6 +2757,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
code.putln("__Pyx_PyMODINIT_FUNC PyInit___init__(void) { return %s(); }" % (
self.mod_init_func_cname('PyInit', env)))
code.putln("#endif")
# Hack for a distutils bug - https://bugs.python.org/issue39432
# distutils attempts to make visible a slightly wrong PyInitU module name. Just create a dummy
# function to keep it quiet
wrong_punycode_module_name = self.wrong_punycode_module_name(env.module_name)
if wrong_punycode_module_name:
code.putln("#if !defined(CYTHON_NO_PYINIT_EXPORT) && (defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS))")
code.putln("void %s(void) {} /* workaround for https://bugs.python.org/issue39432 */" % wrong_punycode_module_name)
code.putln("#endif")
code.putln(header3)
# CPython 3.5+ supports multi-phase module initialisation (gives access to __spec__, __file__, etc.)
......@@ -3193,6 +3201,14 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
name = 'U_' + name.encode('punycode').replace(b'-', b'_').decode('ascii')
return "%s%s" % (prefix, name)
def wrong_punycode_module_name(self, name):
# to work around a distutils bug by also generating an incorrect symbol...
try:
name.encode("ascii")
return None # workaround is not needed
except UnicodeEncodeError:
return "PyInitU" + (u"_"+name).encode('punycode').replace(b'-', b'_').decode('ascii')
def mod_init_func_cname(self, prefix, env):
# from PEP483
return self.punycode_module_name(prefix, env.module_name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment