-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CPyCppyy] Don't use deprecated Py_GetProgramName #16785
Conversation
The `Py_GetProgramName` function in the Python C API was deprecated in Python 3.13 and will be removed in Python 3.15. However, it seems behavior is unchanged by just passing an empty string instead.
Test Results 17 files 17 suites 3d 14h 52m 26s ⏱️ Results for commit 7452d97. |
// The first element of the PyWideStringList can be arbitray, which | ||
// you can seen by running the following: | ||
// | ||
// Content of test.py | ||
// ```python | ||
// print(sys.executable) # will print the executable, e.g. "python" or "root" | ||
// print(sys.argv) # will print ['test.py', '1', '2', '3'] in this example | ||
// ``` | ||
// | ||
// ```c++ | ||
// CPyCppyy::ExecScript("test.py", sizeof(argv)/sizeof(argv[0]), argv); | ||
// ``` | ||
WideStringListAppendHelper(&fConfig.argv, std::wstring{}.c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I trust this is what happens, by reading the docs at https://docs.python.org/3/c-api/init.html#c.Py_GetProgramName it looks to me that the more appropriate string to pass would be fConfig.program_name
member
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that's a pretty good idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it doesn't work, because we never set fConfig.program_name
. So it's a nullptr
, and then there is a segfault down the line.
I think I was simply trying to evolve the existing Python 2 code existing at the time, there is no sophisticated strategy behind. If the usage of the deprecated function can be avoided, great. |
Superseeded by #16851. |
The
Py_GetProgramName
function in the Python C API was deprecated in Python 3.13 and will be removed in Python 3.15.However, it seems behavior is unchanged by just passing an empty string instead.
This avoids a warning when building CPyCppyy.