-
-
Notifications
You must be signed in to change notification settings - Fork 176
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
base: main
Are you sure you want to change the base?
Conversation
if (PyModule_AddObject(module, "BufferProxy", | ||
(PyObject *)&pgBufferProxy_Type)) { | ||
Py_DECREF(&pgBufferProxy_Type); | ||
if (PyModule_AddObjectRef(module, "BufferProxy", |
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.
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.
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, 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?
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 |
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
