Skip to content
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
Address Erlend's review
* Change Sphinx formatting
* Don't change PyWeakref_GetObject() exception
  • Loading branch information
vstinner committed Jun 20, 2023
commit 59bb298fa97d77071b3449d58f0e38b9fc8bd914
4 changes: 2 additions & 2 deletions Doc/c-api/weakref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ as much as it can.

.. c:function:: int PyWeakref_GetRef(PyObject *ref, PyObject **pobj)

Get the referenced object from a weak reference, *ref*, into ``*pobj``.
Get 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.
If the referent is no longer live, set *\*pobj* to ``NULL`` and return 0.

.. 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 @@ -3432,7 +3432,7 @@ check_weakref_capi(PyObject *self, PyObject *factory)
PyErr_Clear();

assert(PyWeakref_GetObject(invalid_weakref) == NULL);
assert(PyErr_ExceptionMatches(PyExc_TypeError));
assert(PyErr_ExceptionMatches(PyExc_SystemError));
PyErr_Clear();

Py_RETURN_NONE;
Expand Down
6 changes: 1 addition & 5 deletions Objects/weakrefobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,14 +915,10 @@ PyWeakref_GetRef(PyObject *ref, PyObject **pobj)
PyObject *
PyWeakref_GetObject(PyObject *ref)
{
if (ref == NULL) {
if (ref == NULL || !PyWeakref_Check(ref)) {
PyErr_BadInternalCall();
return NULL;
}
if (!PyWeakref_Check(ref)) {
PyErr_SetString(PyExc_TypeError, "expected a weakref");
return NULL;
}
return PyWeakref_GET_OBJECT(ref);
}

Expand Down