mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
44
vm/src/stdlib/faulthandler.rs
Normal file
44
vm/src/stdlib/faulthandler.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use crate::frame::FrameRef;
|
||||
use crate::function::OptionalArg;
|
||||
use crate::pyobject::PyObjectRef;
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
fn dump_frame(frame: &FrameRef) {
|
||||
eprintln!(
|
||||
" File \"{}\", line {} in {}",
|
||||
frame.code.source_path,
|
||||
frame.get_lineno().row(),
|
||||
frame.code.obj_name
|
||||
)
|
||||
}
|
||||
|
||||
fn dump_traceback(_file: OptionalArg<i64>, _all_threads: OptionalArg<bool>, vm: &VirtualMachine) {
|
||||
eprintln!("Stack (most recent call first):");
|
||||
|
||||
for frame in vm.frames.borrow().iter() {
|
||||
dump_frame(frame);
|
||||
}
|
||||
}
|
||||
|
||||
fn enable(_file: OptionalArg<i64>, _all_threads: OptionalArg<bool>, _vm: &VirtualMachine) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn register(
|
||||
_signum: i64,
|
||||
_file: OptionalArg<i64>,
|
||||
_all_threads: OptionalArg<bool>,
|
||||
_chain: OptionalArg<bool>,
|
||||
_vm: &VirtualMachine,
|
||||
) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
let ctx = &vm.ctx;
|
||||
py_module!(vm, "faulthandler", {
|
||||
"dump_traceback" => ctx.new_rustfunc(dump_traceback),
|
||||
"enable" => ctx.new_rustfunc(enable),
|
||||
"register" => ctx.new_rustfunc(register),
|
||||
})
|
||||
}
|
||||
@@ -35,7 +35,8 @@ mod weakref;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::vm::VirtualMachine;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
mod faulthandler;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
mod multiprocessing;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
@@ -116,6 +117,10 @@ pub fn get_module_inits() -> HashMap<String, StdlibInitFunc> {
|
||||
modules.insert("select".to_string(), Box::new(select::make_module));
|
||||
modules.insert("_subprocess".to_string(), Box::new(subprocess::make_module));
|
||||
modules.insert("zlib".to_string(), Box::new(zlib::make_module));
|
||||
modules.insert(
|
||||
"faulthandler".to_string(),
|
||||
Box::new(faulthandler::make_module),
|
||||
);
|
||||
}
|
||||
|
||||
// Unix-only
|
||||
|
||||
@@ -382,7 +382,12 @@ fn os_remove(path: PyStringRef, dir_fd: DirFd, vm: &VirtualMachine) -> PyResult<
|
||||
fs::remove_file(path.as_str()).map_err(|err| convert_io_error(vm, err))
|
||||
}
|
||||
|
||||
fn os_mkdir(path: PyStringRef, dir_fd: DirFd, vm: &VirtualMachine) -> PyResult<()> {
|
||||
fn os_mkdir(
|
||||
path: PyStringRef,
|
||||
_mode: OptionalArg<PyIntRef>,
|
||||
dir_fd: DirFd,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<()> {
|
||||
let path = make_path(vm, path, &dir_fd);
|
||||
fs::create_dir(path.as_str()).map_err(|err| convert_io_error(vm, err))
|
||||
}
|
||||
|
||||
@@ -264,6 +264,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
"strptime" => ctx.new_rustfunc(time_strptime),
|
||||
"sleep" => ctx.new_rustfunc(time_sleep),
|
||||
"struct_time" => struct_time_type,
|
||||
"time" => ctx.new_rustfunc(time_time)
|
||||
"time" => ctx.new_rustfunc(time_time),
|
||||
"perf_counter" => ctx.new_rustfunc(time_time), // TODO: fix
|
||||
})
|
||||
}
|
||||
|
||||
@@ -386,6 +386,7 @@ settrace() -- set the global debug tracing function
|
||||
"exec_prefix" => ctx.new_str(exec_prefix.to_string()),
|
||||
"base_exec_prefix" => ctx.new_str(base_exec_prefix.to_string()),
|
||||
"exit" => ctx.new_rustfunc(sys_exit),
|
||||
"abiflags" => ctx.new_str("".to_string()),
|
||||
});
|
||||
|
||||
modules.set_item("sys", module.clone(), vm).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user