[ABRT PATCH 1/2] created python binding for notify_new_path - closes #677
Denys Vlasenko
dvlasenk at redhat.com
Mon Aug 12 11:55:48 UTC 2013
On 08/09/2013 03:58 PM, Jiri Moskovcak wrote:
> Signed-off-by: Jiri Moskovcak <jmoskovc at redhat.com>
Applied both patches, thanks!
There may be a problem with our handling of filenames
in our Python wrappers. We use
PyArg_ParseTuple(args, "s", &path)
to convert Python strings to char*, __with Unicode conversion__.
The problem is, in Linux a NUL-terminated byte sequence
is a valid filename even if it isn't a valid UTF-8.
Does this mean that some paths (ones which aren't valid UTF-8,
such as "\xff\xff") will not be handle-able via Python?
Apparently Python people are aware of this problem, see the
"Note" in this doc:
http://docs.python.org/dev/c-api/arg.html says:
s (str) [const char *]
Convert a Unicode object to a C pointer to a character string.
A pointer to an existing string is stored in the character pointer
variable whose address you pass. The C string is NUL-terminated.
The Python string must not contain embedded NUL bytes; if it does,
a TypeError exception is raised. Unicode objects are converted to
C strings using 'utf-8' encoding. If this conversion fails, a UnicodeError is raised.
Note
This format does not accept bytes-like objects. If you want to accept
filesystem paths and convert them to C character strings,
it is preferable to use the O& format with PyUnicode_FSConverter() as converter.
More information about the Crash-catcher
mailing list