classification
Title: ctypes.FormatError raises when the string to return contains non-ascii characters
Type: crash Stage: patch review
Components: ctypes Versions: Python 3.0
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: theller Nosy List: amaury.forgeotdarc, theller, vstinner
Priority: release blocker Keywords: patch

Created on 2008-11-25 12:43 by theller, last changed 2008-11-26 08:46 by theller. This issue is now closed.

Files
File name Uploaded Description Edit
ctypes-simple.patch theller, 2008-11-25 12:44 Use 'y' format char instead of 's'
ctypes-better.patch theller, 2008-11-25 12:48 Use widestring function to avoid conversion
Messages (5)
msg76411 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2008-11-25 12:43
ctypes raises UnicodeDecodeError in german windows (it should print
'Unzulässige Funktion'):

>>> from ctypes import FormatError
[46681 refs]
>>> FormatError(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 5-7:
invalid data
[46742 refs]
>>>
msg76412 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2008-11-25 12:44
The simple patch (ctypes-simple.patch) uses the 'y' format tag for
PyBuild_Value to build a bytes object as error message.
msg76413 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2008-11-25 12:48
The 'better' patch changes the internal FormatError function to return a
wide string; so conversion from ascii to unicode by Python functions is
not needed and it returns strings to the caller:

>>> from ctypes import FormatError
[46681 refs]
>>> FormatError(1)
'Unzulässige Funktion.'
[46698 refs]
>>>
msg76433 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-11-25 21:43
The "better" patch is good to me. It is indeed better to always use the 
"Wide" Win32 API.
msg76452 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2008-11-26 08:46
Thanks for the review.  I commited the 'better' patch plus a NEWS entry
as svn rev. 67391.
History
Date User Action Args
2008-11-26 08:46:59thellersetstatus: open -> closed
type: crash
resolution: fixed
messages: + msg76452
2008-11-25 21:43:46amaury.forgeotdarcsetkeywords: - needs review
nosy: + amaury.forgeotdarc
messages: + msg76433
2008-11-25 12:50:31vstinnersetnosy: + vstinner
stage: patch review
2008-11-25 12:49:16thellersetkeywords: + needs review
2008-11-25 12:48:32thellersetfiles: + ctypes-better.patch
messages: + msg76413
2008-11-25 12:44:47thellersetkeywords: + patch
files: + ctypes-simple.patch
messages: + msg76412
2008-11-25 12:43:05thellercreate