Issue 8394: ctypes.dlopen() doesn't support surrogates (original) (raw)

Created on 2010-04-14 01:16 by vstinner, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ctypes_dlopen_surrogates-2.patch vstinner,2010-04-15 23:11
Messages (10)
msg103108 - (view) Author: STINNER Victor (vstinner) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) Date: 2010-04-15 23:11
(oops, my patch included unrelated changes about trailing spaces)
msg103458 - (view) Author: STINNER Victor (vstinner) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) Date: 2010-04-20 20:20
Amaury, I'm closing this for the same reason I explained in
History
Date User Action Args
2022-04-11 14:56:59 admin set github: 52641
2010-04-20 20:20:24 loewis set status: open -> closednosy: + loewismessages: + resolution: fixed
2010-04-19 09:25:28 amaury.forgeotdarc set messages: +
2010-04-19 09:23:33 vstinner set messages: +
2010-04-19 09:13:17 vstinner set messages: +
2010-04-19 09:05:28 amaury.forgeotdarc set status: closed -> openresolution: fixed -> (no value)messages: +
2010-04-18 00:03:55 vstinner set status: open -> closedresolution: fixedmessages: +
2010-04-15 23:11:49 vstinner set files: + ctypes_dlopen_surrogates-2.patchmessages: +
2010-04-15 23:11:21 vstinner set files: - ctypes_dlopen_surrogates-2.patch
2010-04-15 23:10:55 vstinner set files: - ctypes_dlopen_surrogates.patch
2010-04-15 23:10:44 vstinner set files: + ctypes_dlopen_surrogates-2.patchmessages: +
2010-04-14 09:08:22 amaury.forgeotdarc set nosy: + amaury.forgeotdarcmessages: +
2010-04-14 03:20:42 brian.curtin set nosy: + thellerassignee: thellercomponents: + ctypestype: behaviorstage: test needed
2010-04-14 01:16:36 vstinner link issue8242 dependencies
2010-04-14 01:16:19 vstinner create