A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2015-February/138050.html below:

[Python-Dev] Encoding of PyFrameObject members

[Python-Dev] Encoding of PyFrameObject members [Python-Dev] Encoding of PyFrameObject membersFrancis Giraldeau francis.giraldeau at gmail.com
Fri Feb 6 00:27:24 CET 2015
I need to access frame members from within a signal handler for tracing
purpose. My first attempt to access co_filename was like this (omitting
 error checking):

PyFrameObject *frame = PyEval_GetFrame();
PyObject *ob = PyUnicode_AsUTF8String(frame->f_code->co_filename)
char *str = PyBytes_AsString(ob)

However, the function PyUnicode_AsUTF8String() calls PyObject_Malloc(),
which is not reentrant. If the signal handler nest over PyObject_Malloc(),
it causes a segfault, and it could also deadlock.

Instead, I access members directly:
char *str = PyUnicode_DATA(frame->f_code->co_filename);
size_t len = PyUnicode_GET_DATA_SIZE(frame->f_code->co_filename);

Is it safe to assume that unicode objects co_filename and co_name are
always UTF-8 data for loaded code? I looked at the PyTokenizer_FromString()
and it seems to convert everything to UTF-8 upfront, and I would like to
make sure this assumption is valid.

Thanks!

Francis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20150205/ede56d14/attachment.html>
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4