Skip to content
15 changes: 11 additions & 4 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,11 +755,18 @@ impl RawBuffer {

impl Drop for PyUntypedBuffer {
fn drop(&mut self) {
if Python::try_attach(|_| unsafe { self.0.release() }).is_none()
&& crate::internal::state::is_in_gc_traversal()
{
eprintln!("Warning: PyBuffer dropped while in GC traversal, this is a bug and will leak memory.");
#[cfg_attr(not(wip_feature_std), expect(unused_variables))]
let released = Python::try_attach(|_| unsafe {
self.0.release();
})
.is_some();

// TODO remove once implementing GC traversal is unsafe
#[cfg(wip_feature_std)]
if !released && crate::internal::state::is_in_gc_traversal() {
std::eprintln!("Warning: PyBuffer dropped while in GC traversal, this is a bug and will leak memory.");
}

// If `try_attach` failed and `is_in_gc_traversal()` is false, then probably the interpreter has
// already finalized and we can just assume that the underlying memory has already been freed.
//
Expand Down
4 changes: 0 additions & 4 deletions src/conversions/jiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,10 +781,6 @@ mod tests {
|name: &'static str, year, month, day, hour, minute, second, ms, py_ms| {
let offset = Offset::from_seconds(3600).unwrap();
let datetime = DateTime::new(year, month, day, hour, minute, second, ms * 1000)
.map_err(|e| {
Comment thread
Person-93 marked this conversation as resolved.
eprintln!("{name}: {e}");
e
})
.unwrap()
.to_zoned(offset.to_time_zone())
.unwrap();
Expand Down
6 changes: 4 additions & 2 deletions src/err/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,10 @@ impl PyErr {
.map(|py_str| py_str.to_string_lossy().into())
.unwrap_or_else(|_| String::from("Unwrapped panic from Python code"));

eprintln!("--- PyO3 is resuming a panic after fetching a PanicException from Python. ---");
eprintln!("Python stack trace below:");
std::eprintln!(
"--- PyO3 is resuming a panic after fetching a PanicException from Python. ---"
);
std::eprintln!("Python stack trace below:");

PyErrState::normalized(state).restore(py);

Expand Down
1 change: 1 addition & 0 deletions src/internal/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ pub fn register_decref(obj: Py<PyAny>) {

/// Private helper function to check if we are currently in a GC traversal (as detected by PyO3).
#[cfg(any(not(Py_LIMITED_API), Py_3_11))]
#[cfg_attr(not(wip_feature_std), expect(dead_code))] // keep code if not used to minimize refactoring friction
pub(crate) fn is_in_gc_traversal() -> bool {
ATTACH_COUNT
.try_with(|c| c.get() == ATTACH_FORBIDDEN_DURING_TRAVERSE)
Expand Down
3 changes: 0 additions & 3 deletions src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ pub(crate) mod prelude {
string::{String, ToString},
vec::Vec,
};

// TODO find a `no_std` replacement for eprintln
pub use std::eprintln;
}

pub mod sync;
Expand Down
Loading