vm.initialize
let mut vm = python::VirtualMachine::new(setting);
// ensure that only files to which we have the capabilities can be opened, by removing
// the standard open wrapper, and substituting our own.
{
let open_wrapper = crate::stdlib::io::io_open_with_capabilities(self.cap.clone().fs);
vm.set_attr(&vm.builtins, "open", open_wrapper)?;
}
Ok(Vm{vm, cap: self.cap.clone()})
open_wrapper
using IntoPyNativeFunc::into_func(open_fn)
open_wrapper
? You can do something like let open_wrapper: () = ...
to get an error message with the full type
pub fn io_open_with_capabilities(capabilities: Privilege<HashSet<Capability>>) -> PyNativeFunc {
let open_fn = |file: PyObjectRef, mode: OptionalArg<PyStringRef>, opts: OpenArgs, vm: &VirtualMachine| {
match &capabilities {
Privilege::None => return Err(vm.new_value_error("Filesystem capabilities are not enabled.".to_owned())),
Privilege::Total => {
let mode = mode.as_ref().into_option().map(|s| s.as_str());
return python::stdlib::io::io_open(file, mode, opts, vm)
},
Privilege::Limited(caps) => {
todo!("check if the file should be opened based on the capabilities.");
let mode = mode.as_ref().into_option().map(|s| s.as_str());
python::stdlib::io::io_open(file, mode, opts, vm)
}
}
};
IntoPyNativeFunc::into_func(open_fn)
}
error[E0308]: mismatched types
--> src/vm.rs:89:36
|
89 | let open_wrapper: () = crate::stdlib::io::io_open_with_capabilities(self.cap.clone().fs);
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found struct `smallbox::smallbox::SmallBox`
| |
| expected due to this
|
= note: expected unit type `()`
found struct `smallbox::smallbox::SmallBox<(dyn for<'r> std::ops::Fn(&'r rustpython_vm::vm::VirtualMachine, rustpython_vm::function::PyFuncArgs) -> std::result::Result<std::sync::Arc<rustpython_vm::pyobject::PyObject<(dyn rustpython_vm::pyobject::PyObjectPayload + 'static)>>, rustpython_vm::pyobject::PyRef<rustpython_vm::exceptions::PyBaseException>> + std::marker::Send + std::marker::Sync + 'static), smallbox::space::S1>`
error: could not compile `psammophis`.
couldn't init zipimport
panic, originating from a ModuleNotFoundError: No module named 'io'
in the initialize method of vm. I've copied the root level Lib from rustpython; and set the env variable RUSTPYTHONPATH=/path/to/lib
error[E0658]: custom attributes cannot be applied to modules
rustup update
will work when you used rustup
cargo run Lib/test/test_whatever.py
will run a whole file which takes a while
test_pickle.py
and friends into the project
Hi everyone, I have the following error, do you know if this can run on a Raspberry Pi/ARM processor ?
error[E0277]: the trait bound i32: std::convert::From<u32>
is not satisfied
--> vm/src/stdlib/time_module.rs:23:37
|
23 | tv_nsec: dur.subsec_nanos().into(),
| ^^^^ the trait std::convert::From<u32>
is not implemented for i32
|
= help: the following implementations were found:
<i32 as std::convert::From<bool>>
<i32 as std::convert::From<dns_lookup::types::AddrFamily>>
<i32 as std::convert::From<dns_lookup::types::Protocol>>
<i32 as std::convert::From<dns_lookup::types::SockType>>
and 9 others
= note: required because of the requirements on the impl of std::convert::Into<i32>
for u32
error: aborting due to previous error
For more information about this error, try rustc --explain E0277
.
error: could not compile rustpython-vm
.
isize
is 32 bit, which maybe implies the processor is 32-bit, which probably won't work...
tv_nsec: dur.subsec_nanos() as i32
and it doesn't show that error but it just crashes every time I try to build (if you guys have tips on how to access some logs that would be cool). Right now I'm running with a 32 bit architecture, I'll try to find a 64 bit OS (I have a RPi3 so it should be compatible) and I'll try via wasmer