10000 gh-105927: PyWeakref_GetRef() returns 1 on success by vstinner · Pull Request #106561 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-105927: PyWeakref_GetRef() returns 1 on success #106561

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 2 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions Doc/c-api/weakref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ as much as it can.

Get a :term:`strong reference` to the referenced object from a weak
reference, *ref*, into *\*pobj*.
Return 0 on success. Raise an exception and return -1 on error.

If the referent is no longer live, set *\*pobj* to ``NULL`` and return 0.
* On success, set *\*pobj* to a new :term:`strong reference` to the
referenced object and return 1.
* If the reference is dead, set *\*pobj* to ``NULL`` and return 0.
* On error, raise an exception and return -1.

.. versionadded:: 3.13

Expand Down
2 changes: 1 addition & 1 deletion Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3376,7 +3376,7 @@ test_weakref_capi(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))

// test PyWeakref_GetRef(), reference is alive
PyObject *ref = Py_True; // marker to check that value was set
assert(PyWeakref_GetRef(weakref, &ref) == 0);
assert(PyWeakref_GetRef(weakref, &ref) == 1);
assert(ref == obj);
assert(Py_REFCNT(obj) == (refcnt + 1));
Py_DECREF(ref);
Expand Down
2 changes: 1 addition & 1 deletion Objects/weakrefobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ PyWeakref_GetRef(PyObject *ref, PyObject **pobj)
return -1;
}
*pobj = _PyWeakref_GET_REF(ref);
return 0;
return (*pobj != NULL);
}


Expand Down
0