Movatterモバイル変換
[0]ホーム
[Python-Dev] Encoding of PyFrameObject members
Maciej Fijalkowskifijall at gmail.com
Fri Feb 6 08:24:31 CET 2015
Hi FrancisI don't think it's safe to assume f_code is properly filled by thetime you might read it, depending a bit where you find the frameobject. 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 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>> _______________________________________________> 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>
More information about the Python-Devmailing list
[8]ページ先頭