Skip to content

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commented Jul 18, 2023

If PyModule_AddObjectRef() followed by Py_DECREF() of the added value, the code can be simplified by using PyModule_Add() which was designed specially for such cases.

Copy link
Member

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

LGTM

intrc=PyModule_AddObjectRef(mod, "WITH_PYMALLOC", v);
Py_DECREF(v);
if (rc<0){
if (PyModule_AddObjectRef(mod, "WITH_PYMALLOC", v) <0){
Copy link
Member

Choose a reason for hiding this comment

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

Was this purposefully not converted to PyModule_Add()?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Yes, PyModule_AddObjectRef() is more fitting here. But the old code was complicated without need.

@serhiy-storchakaserhiy-storchaka merged commit a293fa5 into python:mainJul 18, 2023
@serhiy-storchakaserhiy-storchaka deleted the use-PyModule_Add2 branch July 18, 2023 20:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@serhiy-storchaka@brettcannon@vstinner@bedevere-bot