Skip to content

Commit

Permalink
Merge pull request #3280 from davidhewitt/option-to-tz
Browse files Browse the repository at this point in the history
clarify ownership of opt_to_pyobj helper function
  • Loading branch information
davidhewitt committed Jun 28, 2023
2 parents b7a3a8b + b7d391d commit 135535e
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/types/datetime.rs
Expand Up @@ -257,7 +257,7 @@ impl PyDateTime {
c_int::from(minute),
c_int::from(second),
microsecond as c_int,
opt_to_pyobj(py, tzinfo),
opt_to_pyobj(tzinfo),
api.DateTimeType,
);
py.from_owned_ptr_or_err(ptr)
Expand Down Expand Up @@ -294,7 +294,7 @@ impl PyDateTime {
c_int::from(minute),
c_int::from(second),
microsecond as c_int,
opt_to_pyobj(py, tzinfo),
opt_to_pyobj(tzinfo),
c_int::from(fold),
api.DateTimeType,
);
Expand Down Expand Up @@ -399,7 +399,7 @@ impl PyTime {
c_int::from(minute),
c_int::from(second),
microsecond as c_int,
opt_to_pyobj(py, tzinfo),
opt_to_pyobj(tzinfo),
api.TimeType,
);
py.from_owned_ptr_or_err(ptr)
Expand All @@ -423,7 +423,7 @@ impl PyTime {
c_int::from(minute),
c_int::from(second),
microsecond as c_int,
opt_to_pyobj(py, tzinfo),
opt_to_pyobj(tzinfo),
fold as c_int,
api.TimeType,
);
Expand Down Expand Up @@ -535,12 +535,12 @@ impl PyDeltaAccess for PyDelta {
}
}

// Utility function
fn opt_to_pyobj(py: Python<'_>, opt: Option<&PyTzInfo>) -> *mut ffi::PyObject {
// Convenience function for unpacking Options to either an Object or None
// Utility function which returns a borrowed reference to either
// the underlying tzinfo or None.
fn opt_to_pyobj(opt: Option<&PyTzInfo>) -> *mut ffi::PyObject {
match opt {
Some(tzi) => tzi.as_ptr(),
None => py.None().as_ptr(),
None => unsafe { ffi::Py_None() },
}
}

Expand Down

0 comments on commit 135535e

Please sign in to comment.