Skip to content

Commit

Permalink
add error checking for PyCapsule_Import call
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoldbaum committed Oct 19, 2024
1 parent 011364e commit 8e02786
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pyo3-ffi/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@ pub unsafe fn PyDateTime_IMPORT() {
let py_datetime_c_api =
PyCapsule_Import(PyDateTime_CAPSULE_NAME.as_ptr(), 1) as *mut PyDateTime_CAPI;

if py_datetime_c_api.is_null() {
return;
}

// Protect against race conditions when the datetime API is concurrently
// initialized in multiple threads. UnsafeCell.get() cannot panic so this
// won't panic either.
Expand Down

0 comments on commit 8e02786

Please sign in to comment.