annotate rust/hg-cpython/src/utils.rs @ 43425:ed50f2c31a4c

rust-cpython: allow mutation unless leaked reference is borrowed In other words, mutation is allowed while a Python iterator holding PyLeaked exists. The iterator will be invalidated instead. We still need a borrow_count to prevent mutation while leaked data is dereferenced in Rust world, but most leak_count business is superseded by the generation counter. decrease_leak_count(py, true) will be removed soon.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 12 Oct 2019 20:26:38 +0900
parents 970978975574
children d738b7a18438
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43251
970978975574 rust-utils: introduce a debug util to print the python stack trace
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
1 use cpython::{PyDict, PyObject, PyResult, PyTuple, Python};
970978975574 rust-utils: introduce a debug util to print the python stack trace
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
2
970978975574 rust-utils: introduce a debug util to print the python stack trace
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
3 #[allow(unused)]
970978975574 rust-utils: introduce a debug util to print the python stack trace
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
4 pub fn print_python_trace(py: Python) -> PyResult<PyObject> {
970978975574 rust-utils: introduce a debug util to print the python stack trace
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
5 eprintln!("===============================");
970978975574 rust-utils: introduce a debug util to print the python stack trace
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
6 eprintln!("Printing Python stack from Rust");
970978975574 rust-utils: introduce a debug util to print the python stack trace
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
7 eprintln!("===============================");
970978975574 rust-utils: introduce a debug util to print the python stack trace
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
8 let traceback = py.import("traceback")?;
970978975574 rust-utils: introduce a debug util to print the python stack trace
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
9 let sys = py.import("sys")?;
970978975574 rust-utils: introduce a debug util to print the python stack trace
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
10 let kwargs = PyDict::new(py);
970978975574 rust-utils: introduce a debug util to print the python stack trace
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
11 kwargs.set_item(py, "file", sys.get(py, "stderr")?)?;
970978975574 rust-utils: introduce a debug util to print the python stack trace
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
12 traceback.call(py, "print_stack", PyTuple::new(py, &[]), Some(&kwargs))
970978975574 rust-utils: introduce a debug util to print the python stack trace
Rapha?l Gom?s <rgomes@octobus.net>
parents:
diff changeset
13 }