msg103108 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2010-04-14 01:16 |
The PEP 383 introduces filename using surrogates. ctypes.dlopen() support them. ctypes.cdll.LoadLibrary('libc\uDCff.so.6') fails with: UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 4: surrogates not allowed Attached patch fixes this issue. TODO: Remove the assert(PyBytes_Check(name2)). I don't know if PyUnicode_FSConverter() does always return a PyBytes object or not. |
|
|
msg103115 - (view) |
Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) *  |
Date: 2010-04-14 09:08 |
PyUnicode_FSConverter returns bytes and bytearray objects unchanged; otherwise it always return bytes. Your patch should handle the case when name2 is a bytearray. |
|
|
msg103272 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2010-04-15 23:10 |
amaury> Your patch should handle the case when name2 is a bytearray. Ok, fixed. I also tested None: Python does segfault :-) New patch rejects None value. |
|
|
msg103273 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2010-04-15 23:11 |
(oops, my patch included unrelated changes about trailing spaces) |
|
|
msg103458 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2010-04-18 00:03 |
Fixed: r80159 (py3k), r80160 (3.1). I commited a different version of my patch to support None. |
|
|
msg103564 - (view) |
Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) *  |
Date: 2010-04-19 09:05 |
It does not work on Windows: >>> ctypes.CDLL(b'kernel32') Traceback (most recent call last): File "", line 1, in File "D:\afa\python\py3k-1\lib\ctypes\__init__.py", line 350, in __init__ self._handle = _dlopen(self._name, mode) TypeError: bad argument type for built-in operation |
|
|
msg103566 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2010-04-19 09:13 |
load_library() uses LoadLibraryW() which use a WCHAR*. To support bytes, we can use LoadLibraryA() and TCHAR*. |
|
|
msg103569 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2010-04-19 09:23 |
I only fixed UNIX/BSD versions of subprocess/ctypes.dlopen() because it's not possible to open some files with an undecodable filename. On Windows, the file system and Python3 use Unicode, and so there is no such corner case. On Windows, should we encourage people migrating from byte to character string? Or should we support byte string for backward compatibility or because there is really a corner case where it's not possible to open a file with an unicode string? See also my (Issue #8393, subprocess), |
|
|
msg103570 - (view) |
Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) *  |
Date: 2010-04-19 09:25 |
yes, except that TCHAR* depends on compilation settings (it resolves to wchar_t when UNICODE is #defined); simply use char*. |
|
|
msg103746 - (view) |
Author: Martin v. Löwis (loewis) *  |
Date: 2010-04-20 20:20 |
Amaury, I'm closing this for the same reason I explained in |
|
|