Skip to content

Commit

Permalink
remove AWS_FATAL_ASSERT
Browse files Browse the repository at this point in the history
I'm worried about introducing crashes
  • Loading branch information
graebm committed Sep 24, 2024
1 parent 4b68a14 commit af82781
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
8 changes: 4 additions & 4 deletions source/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ PyObject *aws_py_weakref_get_ref(PyObject *ref) {
PyObject *obj = NULL;
if (PyWeakref_GetRef(ref, &obj) == -1) {
PyErr_WriteUnraisable(PyErr_Occurred());
AWS_FATAL_ASSERT(0 && "expected a weakref");
AWS_ASSERT(0 && "expected a weakref");
}
return obj;

Expand All @@ -538,14 +538,14 @@ PyObject *aws_py_weakref_get_ref(PyObject *ref) {
PyObject *obj = PyWeakref_GetObject(ref); /* borrowed reference */
if (obj == NULL) {
PyErr_WriteUnraisable(PyErr_Occurred());
AWS_FATAL_ASSERT(0 && "expected a weakref");
AWS_ASSERT(0 && "expected a weakref");
} else if (obj == Py_None) {
return NULL;
obj = NULL;
} else {
/* Be like PyWeakref_GetRef() and make it new strong reference */
Py_INCREF(obj);
return obj;
}
return obj;
#endif
}

Expand Down
11 changes: 6 additions & 5 deletions source/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,17 @@ PyObject *aws_py_memory_view_from_byte_buffer(struct aws_byte_buf *buf);
* Given a weak reference, returns a NEW strong reference to the referenced object,
* or NULL if the reference is dead (this function NEVER raises a python exception or AWS Error).
*
* You MUST NOT call this if ref came from a user, or ref is NULL.
*
* This is a simplified version of PyWeakref_GetRef() / PyWeakref_GetObject().
* Simpler because:
* - Python 3.13 adds PyWeakref_GetRef() and deprecates PyWeakref_GetObject().
* This function calls the appropriate one.
*
* - This will AWS_FATAL_ASSERT if ref is not a weak reference,
* So you only need to handle 2 outcomes instead of 3
* (the 3rd being a Python exception for calling it incorrectly).
* But this means it's only safe to call if we created the ref ourselves.
* Do not call if ref could have come from the user.
* - This functions has 2 outcomes instead of 3:
* The 3rd being a Python exception for calling it incorrectly.
* If that happens, this function calls PyErr_WriteUnraisable() to clear the exception,
* which is what you would have done anyway.
*/
PyObject *aws_py_weakref_get_ref(PyObject *ref);

Expand Down

0 comments on commit af82781

Please sign in to comment.