[Python-Dev] Encoding of PyFrameObject members (original) (raw)
Maciej Fijalkowski fijall at gmail.com
Fri Feb 6 08:24:31 CET 2015
- Previous message: [Python-Dev] Encoding of PyFrameObject members
- Next message: [Python-Dev] Encoding of PyFrameObject members
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi Francis
I don't think it's safe to assume f_code is properly filled by the time you might read it, depending a bit where you find the frame object. Are you sure it's not full of garbage?
Besides, are you writing a profiler, or what exactly are you doing?
On Fri, Feb 6, 2015 at 1:27 AM, Francis Giraldeau <francis.giraldeau at gmail.com> wrote:
I need to access frame members from within a signal handler for tracing purpose. My first attempt to access cofilename was like this (omitting error checking):
PyFrameObject *frame = PyEvalGetFrame(); PyObject *ob = PyUnicodeAsUTF8String(frame->fcode->cofilename) char *str = PyBytesAsString(ob) However, the function PyUnicodeAsUTF8String() calls PyObjectMalloc(), which is not reentrant. If the signal handler nest over PyObjectMalloc(), it causes a segfault, and it could also deadlock. Instead, I access members directly: char *str = PyUnicodeDATA(frame->fcode->cofilename); sizet len = PyUnicodeGETDATASIZE(frame->fcode->cofilename); Is it safe to assume that unicode objects cofilename and coname are always UTF-8 data for loaded code? I looked at the PyTokenizerFromString() and it seems to convert everything to UTF-8 upfront, and I would like to make sure this assumption is valid. Thanks! Francis
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/fijall%40gmail.com
- Previous message: [Python-Dev] Encoding of PyFrameObject members
- Next message: [Python-Dev] Encoding of PyFrameObject members
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]