Skip to content

PYTHON-5033 Use PyModule_Add on >= 3.13 #2332

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

Merged
merged 6 commits into from
May 8, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bson/_cbsonmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3227,11 +3227,19 @@ _cbson_exec(PyObject *m)
INITERROR;
}

#if PY_VERSION_HEX >= 0x030D0000
if (PyModule_Add(m, "_C_API", c_api_object) < 0) {
Py_DECREF(c_api_object);
Copy link
Member

Choose a reason for hiding this comment

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

We need to remove this decref, the new API always steals the reference: https://docs.python.org/3/c-api/module.html#c.PyModule_Add

Copy link
Member

Choose a reason for hiding this comment

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

You removed the wrong line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😂

Copy link
Member

Choose a reason for hiding this comment

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

Once again, you removed the wrong line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤦 In 75233bb I only added two DECREFs … identical to the DECREFs in the else clause. Are you saying we need to remove a DECREF from somewhere else, unrelated to this PR?

Copy link
Member

Choose a reason for hiding this comment

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

We need to decref m here, not c_api_object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK but that was already done in 9c768f5 and you said that I removed the wrong one … 🤔

Copy link
Member

Choose a reason for hiding this comment

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

No it was not done in 9c768f5 .

That commit removes code in a completely unrelated code block.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah! Sorry about that, thanks

Copy link
Member

Choose a reason for hiding this comment

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

Thanks. FYI you should only resolve your own comments, not other people's. That way the reviewers can double check their comment is resolved.

Py_DECREF(m);
INITERROR;
}
# else
if (PyModule_AddObject(m, "_C_API", c_api_object) < 0) {
Py_DECREF(c_api_object);
Py_DECREF(m);
INITERROR;
}
#endif

return 0;
}
Expand Down
Loading