const char *cls::func(void)
{
return "abc"; // static: caller must not free
}
and const char *cls::func(void)
{
return strdup("abc"); // caller must free
}
Edit: I see: designed for large scale programs in high performance computing that use modern C++.Modern C++ meaning, no pointers anywhere.
So you handle it like any other ctypes pointer, ie. `libc = ctypes.CDLL(find_library("c")); libc.free(ptr)`
Which is not fun in Python. So yeah, better avoid raw pointers.
Even so this will be awesome for unit testing. I really like the testing interface pytest provides, along with its parametrized tests.
Anyone else using python to test the logic their C/C++ code? I can't think of how I would test the memory allocation and freeing portion. Anyone think it's a bad idea?
But one can test the interface to the program nicely from python (i.e. text or socket i/o).
[1] https://www.benfrederickson.com/writing-python-extensions-in...
IIUC, this tool does the opposite i.e., generate C++/other language bindings from Python
Nice.
If you want to / can share your header files, cppyy is a very convenient way of being able to call your C++ code from Python. I'm not sure if there is a way to use it without headers.
2001 vintage