Python扩展上的Valgrind:块中的字节可能丢失 我一直试图在PybDn11 C++ Python扩展中识别内存问题。虽然以前需要编译禁用PyMalloc的Python调试版本,但就我所知,对于Python3.6和更高版本,设置PYTHONMALLOC=malloc(参见示例)就足够了。然而,即使这样,我也看到大量的错误,形式是N个字节(M个块)可能在丢失记录X或Y中丢失
我可以用一个简单的例子来重现这一点Python扩展上的Valgrind:块中的字节可能丢失 我一直试图在PybDn11 C++ Python扩展中识别内存问题。虽然以前需要编译禁用PyMalloc的Python调试版本,但就我所知,对于Python3.6和更高版本,设置PYTHONMALLOC=malloc(参见示例)就足够了。然而,即使这样,我也看到大量的错误,形式是N个字节(M个块)可能在丢失记录X或Y中丢失,python,valgrind,pybind11,Python,Valgrind,Pybind11,我可以用一个简单的例子来重现这一点 // demo.cpp #include <iostream> #include <pybind11/pybind11.h> namespace py = pybind11; void run() { std::cout << "Hello, World!\n"; } PYBIND11_MODULE(pydemo, m) { m.def("run"
// demo.cpp
#include <iostream>
#include <pybind11/pybind11.h>
namespace py = pybind11;
void run() {
std::cout << "Hello, World!\n";
}
PYBIND11_MODULE(pydemo, m)
{
m.def("run", &run);
}
# demo.py
import pydemo
pydemo.run()
我做错什么了吗?即使Python使用malloc,我仍然需要使用抑制文件吗?基于上面链接的CPython文档文件,它听起来像是禁用PyMalloc的替代文件
我正在WSL2上运行Ubuntu20.04 LTS:
$ python --version
Python 3.8.5
$ g++ --version
g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ python --version
Python 3.8.5
$ g++ --version
g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.