Skip to content

Replace AddObject() with AddObjectRef() #3406

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MightyJosip
Copy link
Member

Since Python 3.13 PyModule_AddObject() is soft deprecated. This PR replaces it with newer function, PyModule_AddObjectRef(). It was changed following the way adviced in the official documentation between versions 3.9 <-> 3.14
image

@MightyJosip MightyJosip requested a review from a team as a code owner April 19, 2025 13:05
@MightyJosip MightyJosip added the Code quality/robustness Code quality and resilience to changes label Apr 19, 2025
if (PyModule_AddObject(module, "BufferProxy",
(PyObject *)&pgBufferProxy_Type)) {
Py_DECREF(&pgBufferProxy_Type);
if (PyModule_AddObjectRef(module, "BufferProxy",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going through these anyways, might as well use PyModule_AddType so you don't need to do the PyType_Ready's either.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the problem with that is the following: at the moment, we still allow XType classes (like SurfaceType, RectType, EventType... are still declared. And AddType would use the name from .tp_name, so it would be regular "Surface".

Maybe do this for pygame3, once we remove those XType classes?

@Starbuck5
Copy link
Member

It's also confusing to see replacements for things that didn't previously have an incref.

@MightyJosip
Copy link
Member Author

It's also confusing to see replacements for things that didn't previously have an incref.

Yea you are right, that comment is mostly for encapsulate_api, and in the current master if I print Py_REFCNT of apiobj, it is 1. However, after this PR it is indeed 2 like you said. I will remove it from those places, and use it only when we actually increase the ref

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code quality/robustness Code quality and resilience to changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants