[Python-Dev] [Python-checkins] cpython: _PyImport_LoadDynamicModule() encodes the module name explicitly to ASCII

Victor Stinner victor.stinner at haypocalc.com
Tue May 10 10:03:29 CEST 2011

Le lundi 09 mai 2011 à 22:18 -0500, Michael Urman a écrit :
> On Mon, May 9, 2011 at 20:08, Neil Hodgson <nyamatongwe at gmail.com> wrote:
> >   Yes, Windows will use UTF-16 as it does for almost everything. From
> > a user's point of view, these should both just be seen as Unicode.
> I'm not convinced this is correct for this case. GetProcAddress takes
> an "ANSI" string, meaning while it could theoretically use UTF-8, in
> practice I doubt it uses anything outside of ASCII safely.

If GetProcAddress() expects a byte string encoded to the ANSI code page,
my patch is correct because the function used the UTF-8 encoding, not
the ANSI code page. We can maybe use GetProcAddressW() to pass a Unicode
string. I don't know which encoding is used by GetProcAddressW()...

I already patched _PyImport_GetDynLoadFunc() for Windows: the path is
now a Unicode object instead of a byte string encoded to the filesystem
encoding. _PyImport_GetDynLoadWindows() uses GetFullPathNameW() and
LoadLibraryExW(). The work to be fully Unicode compliant (for the path
field, not for the name) is not completly done... but I have a pending
patch, see:

But this patch is huge and creates many functions. I am not sure that we
need it, I will work on this later.


More information about the Python-Dev mailing list