我如何使用valgrind与Python C ++扩展? [英] How can I use valgrind with Python C++ extensions?

查看:201
本文介绍了我如何使用valgrind与Python C ++扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C ++类上实现了Python扩展。我没有一个C ++目标来运行valgrind。我想使用valgrind内存检查。

I have Python extensions implemented on C++ classes. I don't have a C++ target to run valgrind with. I want to use valgrind for memory check.

我可以使用valgrind与Python吗?

Can I use valgrind with Python?

推荐答案

可以使用 valgrind 。你只需要使用由Python开发人员提供的valgrind抑制文件,所以你不会因为Python的自定义内存分配/重新分配函数而产生一系列的误报。

Yes, you can use valgrind with Python. You just need to use the valgrind suppression file provided by the Python developers, so you don't get a bunch of false positives due to Python's custom memory allocation/reallocation functions.

可以在此处找到valgrind抑制文件: http://svn.python.org/项目/ python / trunk / Misc / valgrind-python.supp

The valgrind suppression file can be found here: http://svn.python.org/projects/python/trunk/Misc/valgrind-python.supp

重要信息:您需要取消注释PyObject_Free在压缩文件中的PyObject_Realloc *。

IMPORTANT: You need to uncomment the lines for PyObject_Free and PyObject_Realloc in the suppression file*.

推荐的使用语法是:

$ valgrind --tool=memcheck --suppressions=valgrind-python.supp \
                                          python -E -tt ./my_python_script.py

另请参阅Python SVN仓库中的此README文件,其中描述了使用valgrind使用Python的不同方法:
http://svn.python.org/projects/python/trunk/Misc/README.valgrind

See also this README file from the Python SVN repo which describes the different ways of using Python with valgrind: http://svn.python.org/projects/python/trunk/Misc/README.valgrind

* - 或者,您可以重新编译Python,并禁用PyMalloc,这允许您捕获更多的内存泄漏,如果您只是抑制PyMalloc,将不会显示。

* - Alternatively, you can recompile Python with PyMalloc disabled, which allows you to catch more memory leaks that won't show up if you just suppress PyMalloc.

这篇关于我如何使用valgrind与Python C ++扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆