Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

guitargeek
Copy link
Contributor

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.

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.
@guitargeek
Copy link
Contributor Author

@dpiparo, since you wrote this code last year:
#13532

You have any idea why Py_GetProgramName was necessary?

Copy link

Test Results

    17 files      17 suites   3d 14h 52m 26s ⏱️
 2 663 tests  2 663 ✅ 0 💤 0 ❌
43 549 runs  43 549 ✅ 0 💤 0 ❌

Results for commit 7452d97.

Comment on lines +417 to +429
// 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());
Copy link
Member

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

Copy link
Contributor Author

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!

Copy link
Contributor Author

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.

@dpiparo
Copy link
Member

dpiparo commented Oct 30, 2024

@dpiparo, since you wrote this code last year: #13532

You have any idea why Py_GetProgramName was necessary?

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.

@guitargeek
Copy link
Contributor Author

Superseeded by #16851.

@guitargeek guitargeek closed this Nov 7, 2024
@guitargeek guitargeek deleted the Py_GetProgramName branch November 7, 2024 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants