Skip to content

interfaces/python: remove use of deprecated method '_Py_fopen_obj'#27567

Merged
fuzzard merged 1 commit into
xbmc:masterfrom
lrusak:python-deprecated-fix
Dec 10, 2025
Merged

interfaces/python: remove use of deprecated method '_Py_fopen_obj'#27567
fuzzard merged 1 commit into
xbmc:masterfrom
lrusak:python-deprecated-fix

Conversation

@lrusak
Copy link
Copy Markdown
Contributor

@lrusak lrusak commented Dec 9, 2025

this fixes the following warning:

xbmc/interfaces/python/PythonInvoker.cpp:310:31: warning: ‘FILE* _Py_fopen_obj(PyObject*, const char*)’ is deprecated [-Wdeprecated-declarations]
310 | FILE* fp = _Py_fopen_obj(pyRealFilename, rb);
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~

Description

Motivation and context

How has this been tested?

What is the effect on users?

Screenshots (if appropriate):

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • Student submission (PR was done for educational purposes and will be treated as such)
  • None of the above (please explain below)

Checklist:

  • My code follows the Code Guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the Contributing document
  • I have added tests to cover my change
  • All new and existing tests passed

@lrusak lrusak added Type: Fix non-breaking change which fixes an issue Component: Python v22 Piers labels Dec 9, 2025
@lrusak lrusak added this to the Piers 22.0 Alpha 3 milestone Dec 9, 2025
@lrusak lrusak self-assigned this Dec 9, 2025
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 9, 2025

Critical

Incorrect function signature (xbmc/interfaces/python/PythonInvoker.cpp:310)
The replacement function Py_fopen has a different signature than _Py_fopen_obj:

  • _Py_fopen_obj(PyObject* path, const char* mode) - takes PyObject* for path
  • Py_fopen(const char* pathname, const char* mode) - takes const char* for path

The code passes pyRealFilename (PyObject*) to Py_fopen which expects const char*. This causes undefined behavior.

Suggested fix:
(1) Use realFilename.c_str() directly: FILE* fp = Py_fopen(realFilename.c_str(), "rb");
(2) Remove the now-unnecessary pyRealFilename PyObject creation and DECREF
(3) This also simplifies the code since the PyObject wrapper is no longer needed

Comment thread xbmc/interfaces/python/PythonInvoker.cpp
@bkuhls
Copy link
Copy Markdown
Contributor

bkuhls commented Dec 9, 2025

A different fix for the problem is included in #27391

@sundermann
Copy link
Copy Markdown
Contributor

Isn't Py_fopen only available from 3.14+? https://docs.python.org/3/c-api/sys.html#c.Py_fopen. But as mentioned the fix is already in #27391 but could be cherry picked from there

@lrusak
Copy link
Copy Markdown
Contributor Author

lrusak commented Dec 9, 2025

Isn't Py_fopen only available from 3.14+? https://docs.python.org/3/c-api/sys.html#c.Py_fopen. But as mentioned the fix is already in #27391 but could be cherry picked from there

Yep, I missed that.

No worries. I only noticed because fedora 43 ships with python 3.14

$ rpm -qa | grep -E 'python3-[0-9].*' 

python3-3.14.0-2.fc43.x86_64

So it's probably worth getting that fix for the warning in. I can just cherry-pick your commit if desired.

@sundermann
Copy link
Copy Markdown
Contributor

Sure, just cherry pick the commit from my PR, saves me one rebase

this fixes the following warning:

xbmc/interfaces/python/PythonInvoker.cpp:310:31: warning: ‘FILE* _Py_fopen_obj(PyObject*, const char*)’ is deprecated [-Wdeprecated-declarations]
  310 |       FILE* fp = _Py_fopen_obj(pyRealFilename, rb);
      |                  ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Lukas Rusak <lorusak@gmail.com>
@lrusak lrusak force-pushed the python-deprecated-fix branch from 3011ec8 to 5835d13 Compare December 9, 2025 18:41
@lrusak
Copy link
Copy Markdown
Contributor Author

lrusak commented Dec 9, 2025

Sure, just cherry pick the commit from my PR, saves me one rebase

Done, I just updated the commit message a little bit.

@fuzzard fuzzard merged commit e809879 into xbmc:master Dec 10, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Python Type: Fix non-breaking change which fixes an issue v22 Piers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants