-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ralf W. Grosse-Kunstleve
committed
Nov 17, 2022
1 parent
3cbbeeb
commit 0e7ebbd
Showing
4 changed files
with
1,162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#! /usr/bin/bash | ||
set -e | ||
set -x | ||
MAIN=initialize_finalize_loop | ||
clang++ -o $MAIN.o -c -std=c++17 -O0 -g -Wall -Wextra -Wconversion -Wcast-qual -Wdeprecated -Wnon-virtual-dtor -Wunused-result -Werror -DPYBIND11_STRICT_ASSERTS_CLASS_HOLDER_VS_TYPE_CASTER_MIX -DPYBIND11_ENABLE_TYPE_CASTER_ODR_GUARD_IF_AVAILABLE -I$HOME/forked/pybind11/include -I/usr/include/python3.10 $MAIN.cpp | ||
clang++ -o $MAIN -rdynamic -O0 -g $MAIN.o -lpython3.10 -lpthread -ldl -lutil |
34 changes: 34 additions & 0 deletions
34
pybind11/initialize_finalize_loop/initialize_finalize_loop.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* ./build.sh | ||
./initialize_finalize_loop | ||
top -p `pgrep initialize_fina` -b # NO leaking with Python 3.10.7 | ||
# Output in top_no_wrap_class.txt | ||
./initialize_finalize_loop wrap_class | ||
top -p `pgrep initialize_fina` -b # Leaking even with Pytyhon 3.10.7 | ||
# Output in top_wrap_class.txt | ||
*/ | ||
|
||
#include <pybind11/embed.h> | ||
#include <pybind11/pybind11.h> | ||
|
||
namespace py = pybind11; | ||
|
||
int main(int argc, char *[]) { | ||
bool wrap_class = (argc > 1); | ||
while (true) { | ||
py::initialize_interpreter(); | ||
{ | ||
auto imom = py::reinterpret_steal<py::object>(PyModule_New("in_memory_only_module")); | ||
if (!imom) { | ||
throw py::error_already_set(); | ||
} | ||
if (wrap_class) { | ||
struct empty {}; | ||
py::class_<empty>(imom, "empty"); | ||
} | ||
} | ||
py::finalize_interpreter(); | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.