Skip to content

Explicitly decref py::object in ConcretePyObjectHolder and PythonFunctionGuard#38364

Closed
mrshenli wants to merge 4 commits intogh/mrshenli/173/basefrom
gh/mrshenli/173/head
Closed

Explicitly decref py::object in ConcretePyObjectHolder and PythonFunctionGuard#38364
mrshenli wants to merge 4 commits intogh/mrshenli/173/basefrom
gh/mrshenli/173/head

Conversation

@mrshenli
Copy link
Copy Markdown
Contributor

@mrshenli mrshenli commented May 12, 2020

Stack from ghstack:

Differential Revision: D21537611

@mrshenli mrshenli requested a review from apaszke as a code owner May 12, 2020 22:58
@mrshenli mrshenli mentioned this pull request May 12, 2020
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label May 12, 2020
Copy link
Copy Markdown
Collaborator

@wanchaol wanchaol left a comment

Choose a reason for hiding this comment

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

looks good.

py_obj_ = py::none();
py_obj_.dec_ref();
py_obj_.ptr() = nullptr;
}
Copy link
Copy Markdown
Contributor

@xush6528 xush6528 May 12, 2020

Choose a reason for hiding this comment

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

How about adding detailed explanation as well for this PR.

2 points

  • Why py_obj_ = py::none(); does not work. Because we also need to acquire GIL when destructing py::object of None that de-references None.

https://docs.python.org/3/c-api/none.html#c.Py_RETURN_NONE

https://stackoverflow.com/questions/15287590/why-should-py-increfpy-none-be-required-before-returning-py-none-in-c

  • Why we need to call dec_ref() explicitly. Because py::object of nullptr, on destruction, effectively does nothing because of it calls Py_XDECREF(NULL) underlying.

https://docs.python.org/3/c-api/refcounting.html#c.Py_XDECREF

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for writing this down. Will add this to the PR.

@mrshenli mrshenli changed the title Explicitly decref py::object in ConcretePyObjectHolder Explicitly decref py::object in ConcretePyObjectHolder and PythonFunctionGuard May 13, 2020
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@mrshenli merged this pull request in 2e9d6d9.

@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented May 13, 2020

💊 CI failures summary and remediations

As of commit fcab23d (more details on the Dr. CI page):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-CircleCI failure(s)

ci.pytorch.org: 1 failed


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker.

See how this bot performed.

This comment has been revised 1 time.

laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
…tionGuard (pytorch#38364)

Summary: Pull Request resolved: pytorch#38364

Test Plan: Imported from OSS

Differential Revision: D21537611

Pulled By: mrshenli

fbshipit-source-id: e22d1f1360cf71bec526841b5014013b11316f8d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants