(Boost.Python) 在导入 boost python 模块后退出 Python 3 时出现分段错误

(Boost.Python) Segmentation fault when quitting Python 3 after importing a boost python module

我目前在测试 Boost Python 模块时遇到问题。 它是 C++ class 的基本包装器,我可以在 Python 中使用它而没有任何问题(实例、访问其属性等)但是当我退出 Python 环境时,我得到了一个"Segmentation fault"。以下是 gdb 对错误的描述:

Program received signal SIGSEGV, Segmentation fault.
malloc_consolidate (av=av@entry=0x7ffff7bb5760 <main_arena>) at malloc.c:4151
4151    malloc.c: No such file or directory.

我正在使用 Boost 1.55.0,python 3.4.

你们对这类问题有什么想法吗?

编辑:

这是来自 gdb 的回溯:

#0  malloc_consolidate (av=av@entry=0x7ffff7bb5760 <main_arena>) at malloc.c:4151
#1  0x00007ffff787656d in _int_free (av=0x7ffff7bb5760 <main_arena>, p=<optimized out>, have_lock=0) at malloc.c:4057
#2  0x00007ffff0bfc1b5 in Poco::MemoryPool::~MemoryPool() () from /usr/local/share/EikeoTools/libs/poco/lib/libPocoFoundation.so.16
#3  0x00007ffff7833259 in __run_exit_handlers (status=0, listp=0x7ffff7bb56c8 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true) at exit.c:82
#4  0x00007ffff78332a5 in __GI_exit (status=<optimized out>) at exit.c:104
#5  0x00007ffff7818ecc in __libc_start_main (main=0x47dae0 <main>, argc=3, argv=0x7fffffffe458, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe448) at libc-start.c:321
#6  0x0000000000576225 in _start ()

我无法显示代码,但根据回溯,由于 poco 模块存在段错误。(参见 #2)。问题是我什至没有在当前项目中使用这个库,它只是我需要在我的项目中使用的框架的一部分。那么,可能是编译项目时出现了link问题?

编辑 2:

这是我尝试导入我的库时 Valgrind 给我的信息:

  File "***********************/Test.py", line 4, in <module>
==12275== Invalid read of size 4
==12275==    at 0x55BF21: PyObject_Free (in /usr/bin/python3.4)
==12275==    by 0x52EF09: _PyUnicodeWriter_PrepareInternal (in /usr/bin/python3.4)
==12275==    by 0x52F00E: ??? (in /usr/bin/python3.4)
==12275==    by 0x54FBF1: PyUnicode_DecodeUTF8Stateful (in /usr/bin/python3.4)
==12275==    by 0x4AB3B9: ??? (in /usr/bin/python3.4)
==12275==    by 0x518544: PyEval_EvalFrameEx (in /usr/bin/python3.4)
==12275==    by 0x4879BE: ??? (in /usr/bin/python3.4)
==12275==    by 0x4C05AC: ??? (in /usr/bin/python3.4)
==12275==    by 0x4C4DC5: PyObject_CallMethodObjArgs (in /usr/bin/python3.4)
==12275==    by 0x4CB345: _PyIncrementalNewlineDecoder_decode (in /usr/bin/python3.4)
==12275==    by 0x597A4B: ??? (in /usr/bin/python3.4)
==12275==    by 0x4A89CE: ??? (in /usr/bin/python3.4)
==12275==  Address 0x663d020 is 8,032 bytes inside a block of size 8,225 free'd
==12275==    at 0x4C2CE8E: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==12275==    by 0x558CE1: _PyBytes_Resize (in /usr/bin/python3.4)
==12275==    by 0x57D651: ??? (in /usr/bin/python3.4)
==12275==    by 0x4C4DC5: PyObject_CallMethodObjArgs (in /usr/bin/python3.4)
==12275==    by 0x5979EA: ??? (in /usr/bin/python3.4)
==12275==    by 0x4A89CE: ??? (in /usr/bin/python3.4)
==12275==    by 0x493C8F: ??? (in /usr/bin/python3.4)
==12275==    by 0x4EBD09: PyObject_Call (in /usr/bin/python3.4)
==12275==    by 0x552694: _Py_DisplaySourceLine (in /usr/bin/python3.4)
==12275==    by 0x475586: PyTraceBack_Print (in /usr/bin/python3.4)
==12275==    by 0x448414: ??? (in /usr/bin/python3.4)
==12275==    by 0x43A859: PyErr_Display (in /usr/bin/python3.4)

好的,我对我的代码进行了更深入的研究,问题似乎来自未得到很好使用的 PyObject。我关闭这个线程。 我将 post 一个更具体的新问题。

谢谢!