forked from Rust-related/RustPython
PyPayload::class takes ctx instead of vm
This commit is contained in:
@@ -482,8 +482,8 @@ pub(crate) fn impl_define_exception(exc_def: PyExceptionDef) -> Result<TokenStre
|
||||
|
||||
// We need this to make extend mechanism work:
|
||||
impl ::rustpython_vm::PyPayload for #class_name {
|
||||
fn class(vm: &::rustpython_vm::VirtualMachine) -> &'static ::rustpython_vm::Py<::rustpython_vm::builtins::PyType> {
|
||||
vm.ctx.exceptions.#ctx_name
|
||||
fn class(ctx: &::rustpython_vm::vm::Context) -> &'static ::rustpython_vm::Py<::rustpython_vm::builtins::PyType> {
|
||||
ctx.exceptions.#ctx_name
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ pub(crate) fn impl_pypayload(input: DeriveInput) -> Result<TokenStream> {
|
||||
|
||||
let ret = quote! {
|
||||
impl ::rustpython_vm::PyPayload for #ty {
|
||||
fn class(_vm: &::rustpython_vm::VirtualMachine) -> &'static rustpython_vm::Py<::rustpython_vm::builtins::PyType> {
|
||||
fn class(_ctx: &::rustpython_vm::vm::Context) -> &'static rustpython_vm::Py<::rustpython_vm::builtins::PyType> {
|
||||
<Self as ::rustpython_vm::class::StaticType>::static_type()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -671,7 +671,7 @@ mod array {
|
||||
)
|
||||
})?;
|
||||
|
||||
if cls.is(PyArray::class(vm)) && !kwargs.is_empty() {
|
||||
if cls.is(PyArray::class(&vm.ctx)) && !kwargs.is_empty() {
|
||||
return Err(
|
||||
vm.new_type_error("array.array() takes no keyword arguments".to_owned())
|
||||
);
|
||||
@@ -952,7 +952,7 @@ mod array {
|
||||
let bytes = bytes.get_bytes();
|
||||
|
||||
for b in bytes.chunks(BLOCKSIZE) {
|
||||
let b = PyBytes::from(b.to_vec()).into_ref(vm);
|
||||
let b = PyBytes::from(b.to_vec()).into_ref(&vm.ctx);
|
||||
vm.call_method(&f, "write", (b,))?;
|
||||
}
|
||||
Ok(())
|
||||
@@ -1072,7 +1072,7 @@ mod array {
|
||||
if let Some(other) = other.payload::<PyArray>() {
|
||||
self.read()
|
||||
.add(&other.read(), vm)
|
||||
.map(|array| PyArray::from(array).into_ref(vm))
|
||||
.map(|array| PyArray::from(array).into_ref(&vm.ctx))
|
||||
} else {
|
||||
Err(vm.new_type_error(format!(
|
||||
"can only append array (not \"{}\") to array",
|
||||
@@ -1105,7 +1105,7 @@ mod array {
|
||||
fn mul(&self, value: isize, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
|
||||
self.read()
|
||||
.mul(value, vm)
|
||||
.map(|x| Self::from(x).into_ref(vm))
|
||||
.map(|x| Self::from(x).into_ref(&vm.ctx))
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
@@ -1565,7 +1565,7 @@ mod array {
|
||||
}
|
||||
|
||||
fn check_array_type(typ: PyTypeRef, vm: &VirtualMachine) -> PyResult<PyTypeRef> {
|
||||
if !typ.fast_issubclass(PyArray::class(vm)) {
|
||||
if !typ.fast_issubclass(PyArray::class(&vm.ctx)) {
|
||||
return Err(
|
||||
vm.new_type_error(format!("{} is not a subtype of array.array", typ.name()))
|
||||
);
|
||||
|
||||
@@ -742,7 +742,7 @@ mod mmap {
|
||||
MmapObj::Write(mmap) => mmap[pos..end_pos].to_vec(),
|
||||
};
|
||||
|
||||
let result = PyBytes::from(bytes).into_ref(vm);
|
||||
let result = PyBytes::from(bytes).into_ref(&vm.ctx);
|
||||
|
||||
self.advance_pos(num_bytes);
|
||||
|
||||
@@ -763,7 +763,7 @@ mod mmap {
|
||||
|
||||
self.advance_pos(1);
|
||||
|
||||
Ok(PyInt::from(b).into_ref(vm))
|
||||
Ok(PyInt::from(b).into_ref(&vm.ctx))
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
@@ -773,7 +773,7 @@ mod mmap {
|
||||
|
||||
let remaining = self.len().saturating_sub(pos);
|
||||
if remaining == 0 {
|
||||
return Ok(PyBytes::from(vec![]).into_ref(vm));
|
||||
return Ok(PyBytes::from(vec![]).into_ref(&vm.ctx));
|
||||
}
|
||||
|
||||
let eof = match mmap.as_ref().unwrap() {
|
||||
@@ -794,7 +794,7 @@ mod mmap {
|
||||
MmapObj::Write(mmap) => mmap[pos..end_pos].to_vec(),
|
||||
};
|
||||
|
||||
let result = PyBytes::from(bytes).into_ref(vm);
|
||||
let result = PyBytes::from(bytes).into_ref(&vm.ctx);
|
||||
|
||||
self.advance_pos(end_pos - pos);
|
||||
|
||||
@@ -856,7 +856,7 @@ mod mmap {
|
||||
Err(e) => return Err(vm.new_os_error(e.to_string())),
|
||||
};
|
||||
|
||||
Ok(PyInt::from(file_len).into_ref(vm))
|
||||
Ok(PyInt::from(file_len).into_ref(&vm.ctx))
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
@@ -884,7 +884,7 @@ mod mmap {
|
||||
|
||||
self.advance_pos(len);
|
||||
|
||||
Ok(PyInt::from(len).into_ref(vm))
|
||||
Ok(PyInt::from(len).into_ref(&vm.ctx))
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
@@ -945,7 +945,7 @@ mod mmap {
|
||||
MmapObj::Write(mmap) => mmap[i],
|
||||
};
|
||||
|
||||
Ok(PyInt::from(b).into_ref(vm).into())
|
||||
Ok(PyInt::from(b).into_ref(&vm.ctx).into())
|
||||
}
|
||||
|
||||
fn getitem_by_slice(
|
||||
@@ -958,13 +958,13 @@ mod mmap {
|
||||
let mmap = self.check_valid(vm)?;
|
||||
|
||||
if slice_len == 0 {
|
||||
return Ok(PyBytes::from(vec![]).into_ref(vm).into());
|
||||
return Ok(PyBytes::from(vec![]).into_ref(&vm.ctx).into());
|
||||
} else if step == 1 {
|
||||
let bytes = match mmap.deref().as_ref().unwrap() {
|
||||
MmapObj::Read(mmap) => &mmap[range],
|
||||
MmapObj::Write(mmap) => &mmap[range],
|
||||
};
|
||||
return Ok(PyBytes::from(bytes.to_vec()).into_ref(vm).into());
|
||||
return Ok(PyBytes::from(bytes.to_vec()).into_ref(&vm.ctx).into());
|
||||
}
|
||||
|
||||
let mut result_buf = Vec::with_capacity(slice_len);
|
||||
@@ -985,7 +985,7 @@ mod mmap {
|
||||
result_buf.push(b);
|
||||
}
|
||||
}
|
||||
Ok(PyBytes::from(result_buf).into_ref(vm).into())
|
||||
Ok(PyBytes::from(result_buf).into_ref(&vm.ctx).into())
|
||||
}
|
||||
|
||||
fn _getitem(&self, needle: &PyObject, vm: &VirtualMachine) -> PyResult<PyObjectRef> {
|
||||
|
||||
@@ -72,7 +72,7 @@ mod _pyexpat {
|
||||
entity_decl: MutableObject::new(vm.ctx.none()),
|
||||
buffer_text: MutableObject::new(vm.ctx.new_bool(false).into()),
|
||||
}
|
||||
.into_ref(vm))
|
||||
.into_ref(&vm.ctx))
|
||||
}
|
||||
|
||||
#[extend_class]
|
||||
@@ -118,15 +118,15 @@ mod _pyexpat {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let name_str = PyStr::from(name.local_name).into_ref(vm);
|
||||
let name_str = PyStr::from(name.local_name).into_ref(&vm.ctx);
|
||||
invoke_handler(vm, &self.start_element, (name_str, dict));
|
||||
}
|
||||
Ok(XmlEvent::EndElement { name, .. }) => {
|
||||
let name_str = PyStr::from(name.local_name).into_ref(vm);
|
||||
let name_str = PyStr::from(name.local_name).into_ref(&vm.ctx);
|
||||
invoke_handler(vm, &self.end_element, (name_str,));
|
||||
}
|
||||
Ok(XmlEvent::Characters(chars)) => {
|
||||
let str = PyStr::from(chars).into_ref(vm);
|
||||
let str = PyStr::from(chars).into_ref(&vm.ctx);
|
||||
invoke_handler(vm, &self.character_data, (str,));
|
||||
}
|
||||
_ => {}
|
||||
|
||||
@@ -36,7 +36,7 @@ pub(crate) mod _struct {
|
||||
b @ PyBytes => if b.is_ascii() {
|
||||
Some(unsafe {
|
||||
PyStr::new_ascii_unchecked(b.as_bytes().to_vec())
|
||||
}.into_ref(vm))
|
||||
}.into_ref(&vm.ctx))
|
||||
} else {
|
||||
None
|
||||
},
|
||||
|
||||
@@ -302,7 +302,7 @@ mod _sqlite {
|
||||
isolation_level: Option<PyStrRef>,
|
||||
#[pyarg(any, default = "true")]
|
||||
check_same_thread: bool,
|
||||
#[pyarg(any, default = "Connection::class(vm).to_owned()")]
|
||||
#[pyarg(any, default = "Connection::class(&vm.ctx).to_owned()")]
|
||||
factory: PyTypeRef,
|
||||
// TODO: cache statements
|
||||
#[allow(dead_code)]
|
||||
@@ -640,14 +640,14 @@ mod _sqlite {
|
||||
|
||||
#[pyfunction]
|
||||
fn register_adapter(typ: PyTypeRef, adapter: ArgCallable, vm: &VirtualMachine) -> PyResult<()> {
|
||||
if typ.is(PyInt::class(vm))
|
||||
|| typ.is(PyFloat::class(vm))
|
||||
|| typ.is(PyStr::class(vm))
|
||||
|| typ.is(PyByteArray::class(vm))
|
||||
if typ.is(PyInt::class(&vm.ctx))
|
||||
|| typ.is(PyFloat::class(&vm.ctx))
|
||||
|| typ.is(PyStr::class(&vm.ctx))
|
||||
|| typ.is(PyByteArray::class(&vm.ctx))
|
||||
{
|
||||
let _ = BASE_TYPE_ADAPTED.set(());
|
||||
}
|
||||
let protocol = PrepareProtocol::class(vm).to_owned();
|
||||
let protocol = PrepareProtocol::class(&vm.ctx).to_owned();
|
||||
let key = vm.ctx.new_tuple(vec![typ.into(), protocol.into()]);
|
||||
adapters().set_item(key.as_object(), adapter.into(), vm)
|
||||
}
|
||||
@@ -708,7 +708,7 @@ mod _sqlite {
|
||||
// TODO: None proto
|
||||
let proto = proto
|
||||
.flatten()
|
||||
.unwrap_or_else(|| PrepareProtocol::class(vm).to_owned());
|
||||
.unwrap_or_else(|| PrepareProtocol::class(&vm.ctx).to_owned());
|
||||
|
||||
_adapt(
|
||||
&obj,
|
||||
@@ -818,7 +818,7 @@ mod _sqlite {
|
||||
|
||||
fn call(zelf: &Py<Self>, args: Self::Args, vm: &VirtualMachine) -> PyResult {
|
||||
if let Some(stmt) = Statement::new(zelf, &args.0, vm)? {
|
||||
Ok(stmt.into_ref(vm).into())
|
||||
Ok(stmt.into_ref(&vm.ctx).into())
|
||||
} else {
|
||||
Ok(vm.ctx.none())
|
||||
}
|
||||
@@ -835,7 +835,7 @@ mod _sqlite {
|
||||
if let Some(isolation_level) = &args.isolation_level {
|
||||
begin_statement_ptr_from_isolation_level(isolation_level, vm)?;
|
||||
}
|
||||
let text_factory = PyStr::class(vm).to_owned().into_object();
|
||||
let text_factory = PyStr::class(&vm.ctx).to_owned().into_object();
|
||||
|
||||
Ok(Self {
|
||||
db: PyMutex::new(Some(db)),
|
||||
@@ -884,7 +884,7 @@ mod _sqlite {
|
||||
cursor
|
||||
} else {
|
||||
let row_factory = zelf.row_factory.to_owned();
|
||||
Cursor::new(zelf, row_factory, vm).into_ref(vm)
|
||||
Cursor::new(zelf, row_factory, vm).into_ref(&vm.ctx)
|
||||
};
|
||||
Ok(cursor)
|
||||
}
|
||||
@@ -921,7 +921,7 @@ mod _sqlite {
|
||||
connection: zelf,
|
||||
inner: PyMutex::new(Some(BlobInner { blob, offset: 0 })),
|
||||
};
|
||||
Ok(blob.into_ref(vm))
|
||||
Ok(blob.into_ref(&vm.ctx))
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
@@ -954,7 +954,7 @@ mod _sqlite {
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<PyRef<Cursor>> {
|
||||
let row_factory = zelf.row_factory.to_owned();
|
||||
let cursor = Cursor::new(zelf, row_factory, vm).into_ref(vm);
|
||||
let cursor = Cursor::new(zelf, row_factory, vm).into_ref(&vm.ctx);
|
||||
Cursor::execute(cursor, sql, parameters, vm)
|
||||
}
|
||||
|
||||
@@ -966,7 +966,7 @@ mod _sqlite {
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<PyRef<Cursor>> {
|
||||
let row_factory = zelf.row_factory.to_owned();
|
||||
let cursor = Cursor::new(zelf, row_factory, vm).into_ref(vm);
|
||||
let cursor = Cursor::new(zelf, row_factory, vm).into_ref(&vm.ctx);
|
||||
Cursor::executemany(cursor, sql, seq_of_params, vm)
|
||||
}
|
||||
|
||||
@@ -977,7 +977,11 @@ mod _sqlite {
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<PyRef<Cursor>> {
|
||||
let row_factory = zelf.row_factory.to_owned();
|
||||
Cursor::executescript(Cursor::new(zelf, row_factory, vm).into_ref(vm), script, vm)
|
||||
Cursor::executescript(
|
||||
Cursor::new(zelf, row_factory, vm).into_ref(&vm.ctx),
|
||||
script,
|
||||
vm,
|
||||
)
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
@@ -1403,7 +1407,7 @@ mod _sqlite {
|
||||
drop(inner);
|
||||
return Ok(zelf);
|
||||
};
|
||||
let stmt = stmt.into_ref(vm);
|
||||
let stmt = stmt.into_ref(&vm.ctx);
|
||||
|
||||
inner.rowcount = if stmt.is_dml { 0 } else { -1 };
|
||||
|
||||
@@ -1472,7 +1476,7 @@ mod _sqlite {
|
||||
drop(inner);
|
||||
return Ok(zelf);
|
||||
};
|
||||
let stmt = stmt.into_ref(vm);
|
||||
let stmt = stmt.into_ref(&vm.ctx);
|
||||
|
||||
let st = stmt.lock();
|
||||
|
||||
@@ -1724,15 +1728,15 @@ mod _sqlite {
|
||||
|
||||
let text_factory = zelf.connection.text_factory.to_owned();
|
||||
|
||||
if text_factory.is(PyStr::class(vm)) {
|
||||
if text_factory.is(PyStr::class(&vm.ctx)) {
|
||||
let text = String::from_utf8(text).map_err(|_| {
|
||||
new_operational_error(vm, "not valid UTF-8".to_owned())
|
||||
})?;
|
||||
vm.ctx.new_str(text).into()
|
||||
} else if text_factory.is(PyBytes::class(vm)) {
|
||||
} else if text_factory.is(PyBytes::class(&vm.ctx)) {
|
||||
vm.ctx.new_bytes(text).into()
|
||||
} else if text_factory.is(PyByteArray::class(vm)) {
|
||||
PyByteArray::from(text).into_ref(vm).into()
|
||||
} else if text_factory.is(PyByteArray::class(&vm.ctx)) {
|
||||
PyByteArray::from(text).into_ref(&vm.ctx).into()
|
||||
} else {
|
||||
let bytes = vm.ctx.new_bytes(text);
|
||||
text_factory.call((bytes,), vm)?
|
||||
@@ -2531,7 +2535,7 @@ mod _sqlite {
|
||||
let obj = if need_adapt(parameter, vm) {
|
||||
adapted = _adapt(
|
||||
parameter,
|
||||
PrepareProtocol::class(vm).to_owned(),
|
||||
PrepareProtocol::class(&vm.ctx).to_owned(),
|
||||
|x| Ok(x.to_owned()),
|
||||
vm,
|
||||
)?;
|
||||
|
||||
@@ -1458,7 +1458,7 @@ mod windows {
|
||||
oids.into_iter().map(|oid| vm.ctx.new_str(oid).into()),
|
||||
)
|
||||
.unwrap()
|
||||
.into_ref(vm)
|
||||
.into_ref(&vm.ctx)
|
||||
.into(),
|
||||
};
|
||||
Ok(vm.new_tuple((cert, enc_type, usage)).into())
|
||||
|
||||
@@ -33,7 +33,7 @@ mod syslog {
|
||||
Some(value) => &argv[value..],
|
||||
None => argv,
|
||||
})
|
||||
.into_ref(vm),
|
||||
.into_ref(&vm.ctx),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
let module = unicodedata::make_module(vm);
|
||||
|
||||
let ucd: PyObjectRef = unicodedata::Ucd::new(unic_ucd_age::UNICODE_VERSION)
|
||||
.into_ref(vm)
|
||||
.into_ref(&vm.ctx)
|
||||
.into();
|
||||
|
||||
for attr in [
|
||||
@@ -208,7 +208,7 @@ mod unicodedata {
|
||||
micro: 0,
|
||||
},
|
||||
}
|
||||
.into_ref(vm)
|
||||
.into_ref(&vm.ctx)
|
||||
}
|
||||
|
||||
#[pyattr]
|
||||
|
||||
@@ -280,8 +280,8 @@ mod zlib {
|
||||
Ok(PyDecompress {
|
||||
decompress: PyMutex::new(decompress),
|
||||
eof: AtomicCell::new(false),
|
||||
unused_data: PyMutex::new(PyBytes::from(vec![]).into_ref(vm)),
|
||||
unconsumed_tail: PyMutex::new(PyBytes::from(vec![]).into_ref(vm)),
|
||||
unused_data: PyMutex::new(PyBytes::from(vec![]).into_ref(&vm.ctx)),
|
||||
unconsumed_tail: PyMutex::new(PyBytes::from(vec![]).into_ref(&vm.ctx)),
|
||||
})
|
||||
}
|
||||
#[pyattr]
|
||||
@@ -326,7 +326,7 @@ mod zlib {
|
||||
.chain(leftover)
|
||||
.copied()
|
||||
.collect();
|
||||
*unused_data = vm.new_pyref(unused);
|
||||
*unused_data = vm.ctx.new_pyref(unused);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,7 +359,7 @@ mod zlib {
|
||||
|
||||
let mut unconsumed_tail = self.unconsumed_tail.lock();
|
||||
if !leftover.is_empty() || !unconsumed_tail.is_empty() {
|
||||
*unconsumed_tail = PyBytes::from(leftover.to_owned()).into_ref(vm);
|
||||
*unconsumed_tail = PyBytes::from(leftover.to_owned()).into_ref(&vm.ctx);
|
||||
}
|
||||
|
||||
ret
|
||||
@@ -392,7 +392,7 @@ mod zlib {
|
||||
};
|
||||
self.save_unused_input(&mut d, &data, stream_end, orig_in, vm);
|
||||
|
||||
*data = PyBytes::from(Vec::new()).into_ref(vm);
|
||||
*data = PyBytes::from(Vec::new()).into_ref(&vm.ctx);
|
||||
|
||||
// TODO: drop the inner decompressor, somehow
|
||||
// if stream_end {
|
||||
|
||||
@@ -21,8 +21,8 @@ pub struct PyAsyncGen {
|
||||
type PyAsyncGenRef = PyRef<PyAsyncGen>;
|
||||
|
||||
impl PyPayload for PyAsyncGen {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.async_generator
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.async_generator
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,8 +141,8 @@ impl Unconstructible for PyAsyncGen {}
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct PyAsyncGenWrappedValue(pub PyObjectRef);
|
||||
impl PyPayload for PyAsyncGenWrappedValue {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.async_generator_wrapped_value
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.async_generator_wrapped_value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,8 +190,8 @@ pub(crate) struct PyAsyncGenASend {
|
||||
}
|
||||
|
||||
impl PyPayload for PyAsyncGenASend {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.async_generator_asend
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.async_generator_asend
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,8 +285,8 @@ pub(crate) struct PyAsyncGenAThrow {
|
||||
}
|
||||
|
||||
impl PyPayload for PyAsyncGenAThrow {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.async_generator_athrow
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.async_generator_athrow
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -80,8 +80,8 @@ impl PyObjectRef {
|
||||
pub struct PyBool;
|
||||
|
||||
impl PyPayload for PyBool {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.bool_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.bool_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,8 +67,8 @@ pub struct PyBuiltinFunction {
|
||||
}
|
||||
|
||||
impl PyPayload for PyBuiltinFunction {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.builtin_function_or_method_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.builtin_function_or_method_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,8 +176,8 @@ pub struct PyBuiltinMethod {
|
||||
}
|
||||
|
||||
impl PyPayload for PyBuiltinMethod {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.method_descriptor_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.method_descriptor_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,8 +61,8 @@ impl From<Vec<u8>> for PyByteArray {
|
||||
}
|
||||
|
||||
impl PyPayload for PyByteArray {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.bytearray_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.bytearray_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -668,7 +668,7 @@ impl PyRef<PyByteArray> {
|
||||
drop(inner);
|
||||
self
|
||||
} else {
|
||||
vm.new_pyref(PyByteArray::from(stripped.to_vec()))
|
||||
vm.ctx.new_pyref(PyByteArray::from(stripped.to_vec()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -685,7 +685,7 @@ impl PyRef<PyByteArray> {
|
||||
drop(inner);
|
||||
self
|
||||
} else {
|
||||
vm.new_pyref(PyByteArray::from(stripped.to_vec()))
|
||||
vm.ctx.new_pyref(PyByteArray::from(stripped.to_vec()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -885,8 +885,8 @@ pub struct PyByteArrayIterator {
|
||||
}
|
||||
|
||||
impl PyPayload for PyByteArrayIterator {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.bytearray_iterator_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.bytearray_iterator_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,8 +78,8 @@ impl AsRef<[u8]> for PyBytesRef {
|
||||
}
|
||||
|
||||
impl PyPayload for PyBytes {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.bytes_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.bytes_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ impl PyRef<PyBytes> {
|
||||
}
|
||||
self.inner
|
||||
.mul(count, vm)
|
||||
.map(|x| PyBytes::from(x).into_ref(vm))
|
||||
.map(|x| PyBytes::from(x).into_ref(&vm.ctx))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -511,7 +511,7 @@ impl PyRef<PyBytes> {
|
||||
if self.is(vm.ctx.types.bytes_type) {
|
||||
self
|
||||
} else {
|
||||
PyBytes::from(self.inner.clone()).into_ref(vm)
|
||||
PyBytes::from(self.inner.clone()).into_ref(&vm.ctx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -683,8 +683,8 @@ pub struct PyBytesIterator {
|
||||
}
|
||||
|
||||
impl PyPayload for PyBytesIterator {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.bytes_iterator_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.bytes_iterator_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ impl From<PyObjectRef> for PyClassMethod {
|
||||
}
|
||||
|
||||
impl PyPayload for PyClassMethod {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.classmethod_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.classmethod_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ impl Representable for PyClassMethod {
|
||||
#[inline]
|
||||
fn repr_str(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<String> {
|
||||
let callable = zelf.callable.lock().repr(vm).unwrap();
|
||||
let class = Self::class(vm);
|
||||
let class = Self::class(&vm.ctx);
|
||||
|
||||
let repr = match (
|
||||
class
|
||||
|
||||
@@ -211,8 +211,8 @@ impl fmt::Debug for PyCode {
|
||||
}
|
||||
|
||||
impl PyPayload for PyCode {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.code_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.code_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,8 @@ impl PyComplex {
|
||||
}
|
||||
|
||||
impl PyPayload for PyComplex {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.complex_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.complex_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ impl PyComplex {
|
||||
if zelf.is(vm.ctx.types.complex_type) {
|
||||
zelf
|
||||
} else {
|
||||
PyComplex::from(zelf.value).into_ref(vm)
|
||||
PyComplex::from(zelf.value).into_ref(&vm.ctx)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ pub struct PyCoroutine {
|
||||
}
|
||||
|
||||
impl PyPayload for PyCoroutine {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.coroutine_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.coroutine_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,8 +123,8 @@ pub struct PyCoroutineWrapper {
|
||||
}
|
||||
|
||||
impl PyPayload for PyCoroutineWrapper {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.coroutine_wrapper_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.coroutine_wrapper_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,8 +82,8 @@ pub struct MemberDescrObject {
|
||||
}
|
||||
|
||||
impl PyPayload for MemberDescrObject {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.member_descriptor_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.member_descriptor_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,8 @@ impl fmt::Debug for PyDict {
|
||||
}
|
||||
|
||||
impl PyPayload for PyDict {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.dict_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.dict_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -798,8 +798,8 @@ macro_rules! dict_view {
|
||||
}
|
||||
|
||||
impl PyPayload for $name {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.$class
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.$class
|
||||
}
|
||||
}
|
||||
|
||||
@@ -834,8 +834,8 @@ macro_rules! dict_view {
|
||||
}
|
||||
|
||||
impl PyPayload for $iter_name {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.$iter_class
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.$iter_class
|
||||
}
|
||||
}
|
||||
|
||||
@@ -907,8 +907,8 @@ macro_rules! dict_view {
|
||||
}
|
||||
|
||||
impl PyPayload for $reverse_iter_name {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.$reverse_iter_class
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.$reverse_iter_class
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ pub struct PyEnumerate {
|
||||
}
|
||||
|
||||
impl PyPayload for PyEnumerate {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.enumerate_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.enumerate_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,8 +91,8 @@ pub struct PyReverseSequenceIterator {
|
||||
}
|
||||
|
||||
impl PyPayload for PyReverseSequenceIterator {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.reverse_iter_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.reverse_iter_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ pub struct PyFilter {
|
||||
}
|
||||
|
||||
impl PyPayload for PyFilter {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.filter_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.filter_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ impl PyFloat {
|
||||
}
|
||||
|
||||
impl PyPayload for PyFloat {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.float_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.float_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -312,7 +312,7 @@ impl PyFunction {
|
||||
self.closure.as_ref().map_or(&[], |c| c.as_slice()),
|
||||
vm,
|
||||
)
|
||||
.into_ref(vm);
|
||||
.into_ref(&vm.ctx);
|
||||
|
||||
self.fill_locals_from_args(&frame, func_args, vm)?;
|
||||
|
||||
@@ -334,8 +334,8 @@ impl PyFunction {
|
||||
}
|
||||
|
||||
impl PyPayload for PyFunction {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.function_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.function_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -623,8 +623,8 @@ impl PyBoundMethod {
|
||||
}
|
||||
|
||||
impl PyPayload for PyBoundMethod {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.bound_method_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.bound_method_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -636,8 +636,8 @@ pub(crate) struct PyCell {
|
||||
pub(crate) type PyCellRef = PyRef<PyCell>;
|
||||
|
||||
impl PyPayload for PyCell {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.cell_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.cell_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ pub struct PyGenerator {
|
||||
}
|
||||
|
||||
impl PyPayload for PyGenerator {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.generator_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.generator_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ impl fmt::Debug for PyGenericAlias {
|
||||
}
|
||||
|
||||
impl PyPayload for PyGenericAlias {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.generic_alias_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.generic_alias_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,8 @@ impl std::fmt::Debug for PyGetSet {
|
||||
}
|
||||
|
||||
impl PyPayload for PyGetSet {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.getset_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.getset_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ impl GetDescriptor for PyGetSet {
|
||||
Err(vm.new_attribute_error(format!(
|
||||
"attribute '{}' of '{}' objects is not readable",
|
||||
zelf.name,
|
||||
Self::class(vm).name()
|
||||
Self::class(&vm.ctx).name()
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ where
|
||||
}
|
||||
|
||||
impl PyPayload for PyInt {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.int_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.int_type
|
||||
}
|
||||
|
||||
fn into_pyobject(self, vm: &VirtualMachine) -> PyObjectRef {
|
||||
|
||||
@@ -167,8 +167,8 @@ pub struct PySequenceIterator {
|
||||
}
|
||||
|
||||
impl PyPayload for PySequenceIterator {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.iter_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.iter_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,8 +230,8 @@ pub struct PyCallableIterator {
|
||||
}
|
||||
|
||||
impl PyPayload for PyCallableIterator {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.callable_iterator
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.callable_iterator
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +50,8 @@ impl FromIterator<PyObjectRef> for PyList {
|
||||
}
|
||||
|
||||
impl PyPayload for PyList {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.list_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.list_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ impl PyList {
|
||||
let other = other.payload_if_subclass::<PyList>(vm).ok_or_else(|| {
|
||||
vm.new_type_error(format!(
|
||||
"Cannot add {} and {}",
|
||||
Self::class(vm).name(),
|
||||
Self::class(&vm.ctx).name(),
|
||||
other.class().name()
|
||||
))
|
||||
})?;
|
||||
@@ -537,8 +537,8 @@ pub struct PyListIterator {
|
||||
}
|
||||
|
||||
impl PyPayload for PyListIterator {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.list_iterator_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.list_iterator_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -582,8 +582,8 @@ pub struct PyListReverseIterator {
|
||||
}
|
||||
|
||||
impl PyPayload for PyListReverseIterator {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.list_reverseiterator_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.list_reverseiterator_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ pub struct PyMap {
|
||||
}
|
||||
|
||||
impl PyPayload for PyMap {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.map_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.map_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ enum MappingProxyInner {
|
||||
}
|
||||
|
||||
impl PyPayload for PyMappingProxy {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.mappingproxy_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.mappingproxy_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ impl PyMappingProxy {
|
||||
fn ior(&self, _args: PyObjectRef, vm: &VirtualMachine) -> PyResult {
|
||||
Err(vm.new_type_error(format!(
|
||||
"\"'|=' is not supported by {}; use '|' instead\"",
|
||||
Self::class(vm)
|
||||
Self::class(&vm.ctx)
|
||||
)))
|
||||
}
|
||||
|
||||
|
||||
@@ -161,7 +161,7 @@ impl PyMemoryView {
|
||||
other.init_slice(slice, 0, vm)?;
|
||||
other.init_len();
|
||||
|
||||
Ok(other.into_ref(vm).into())
|
||||
Ok(other.into_ref(&vm.ctx).into())
|
||||
}
|
||||
|
||||
fn getitem_by_multi_idx(&self, indexes: &[isize], vm: &VirtualMachine) -> PyResult {
|
||||
@@ -461,7 +461,7 @@ impl PyMemoryView {
|
||||
|
||||
if self.desc.ndim() == 0 {
|
||||
return VecBuffer::from(data)
|
||||
.into_ref(vm)
|
||||
.into_ref(&vm.ctx)
|
||||
.into_pybuffer_with_descriptor(self.desc.clone());
|
||||
}
|
||||
|
||||
@@ -482,7 +482,7 @@ impl PyMemoryView {
|
||||
};
|
||||
|
||||
VecBuffer::from(data)
|
||||
.into_ref(vm)
|
||||
.into_ref(&vm.ctx)
|
||||
.into_pybuffer_with_descriptor(desc)
|
||||
}
|
||||
}
|
||||
@@ -703,7 +703,7 @@ impl PyMemoryView {
|
||||
self.try_not_released(vm)?;
|
||||
let mut v = vec![];
|
||||
self.append_to(&mut v);
|
||||
Ok(PyBytes::from(v).into_ref(vm))
|
||||
Ok(PyBytes::from(v).into_ref(&vm.ctx))
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
@@ -725,7 +725,7 @@ impl PyMemoryView {
|
||||
self.try_not_released(vm)?;
|
||||
let mut other = self.new_view();
|
||||
other.desc.readonly = true;
|
||||
Ok(other.into_ref(vm))
|
||||
Ok(other.into_ref(&vm.ctx))
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
@@ -812,7 +812,7 @@ impl PyMemoryView {
|
||||
if shape_ndim == 0 {
|
||||
other.desc.dim_desc = vec![];
|
||||
other.desc.len = itemsize;
|
||||
return Ok(other.into_ref(vm));
|
||||
return Ok(other.into_ref(&vm.ctx));
|
||||
}
|
||||
|
||||
let mut product_shape = itemsize;
|
||||
@@ -843,9 +843,9 @@ impl PyMemoryView {
|
||||
|
||||
other.desc.dim_desc = dim_descriptor;
|
||||
|
||||
Ok(other.into_ref(vm))
|
||||
Ok(other.into_ref(&vm.ctx))
|
||||
} else {
|
||||
Ok(self.cast_to_1d(format, vm)?.into_ref(vm))
|
||||
Ok(self.cast_to_1d(format, vm)?.into_ref(&vm.ctx))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1052,8 +1052,8 @@ impl Hashable for PyMemoryView {
|
||||
}
|
||||
|
||||
impl PyPayload for PyMemoryView {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.memoryview_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.memoryview_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1132,8 +1132,8 @@ pub struct PyMemoryViewIterator {
|
||||
}
|
||||
|
||||
impl PyPayload for PyMemoryViewIterator {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.memoryviewiterator_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.memoryviewiterator_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@ use crate::{
|
||||
pub struct PyModule {}
|
||||
|
||||
impl PyPayload for PyModule {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.module_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.module_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ use crate::{
|
||||
pub struct PyNamespace {}
|
||||
|
||||
impl PyPayload for PyNamespace {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.namespace_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.namespace_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ use crate::{
|
||||
pub struct PyBaseObject;
|
||||
|
||||
impl PyPayload for PyBaseObject {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.object_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.object_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,13 +204,13 @@ impl PyBaseObject {
|
||||
qualname,
|
||||
zelf.get_id()
|
||||
))
|
||||
.into_ref(vm)),
|
||||
.into_ref(&vm.ctx)),
|
||||
_ => Ok(PyStr::from(format!(
|
||||
"<{} object at {:#x}>",
|
||||
class.slot_name(),
|
||||
zelf.get_id()
|
||||
))
|
||||
.into_ref(vm)),
|
||||
.into_ref(&vm.ctx)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ impl PyBaseObject {
|
||||
pub fn dir(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyList> {
|
||||
let attributes = obj.class().get_attributes();
|
||||
|
||||
let dict = PyDict::from_attributes(attributes, vm)?.into_ref(vm);
|
||||
let dict = PyDict::from_attributes(attributes, vm)?.into_ref(&vm.ctx);
|
||||
|
||||
// Get instance attributes:
|
||||
if let Some(object_dict) = obj.dict() {
|
||||
|
||||
@@ -21,8 +21,8 @@ pub struct PyProperty {
|
||||
}
|
||||
|
||||
impl PyPayload for PyProperty {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.property_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.property_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,8 +70,8 @@ pub struct PyRange {
|
||||
}
|
||||
|
||||
impl PyPayload for PyRange {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.range_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.range_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,9 +178,9 @@ pub fn init(context: &Context) {
|
||||
impl PyRange {
|
||||
fn new(cls: PyTypeRef, stop: ArgIndex, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
|
||||
PyRange {
|
||||
start: vm.new_pyref(0),
|
||||
start: vm.ctx.new_pyref(0),
|
||||
stop: stop.into(),
|
||||
step: vm.new_pyref(1),
|
||||
step: vm.ctx.new_pyref(1),
|
||||
}
|
||||
.into_ref_with_type(vm, cls)
|
||||
}
|
||||
@@ -346,11 +346,11 @@ impl PyRange {
|
||||
sub_stop = (sub_stop * range_step.as_bigint()) + range_start.as_bigint();
|
||||
|
||||
Ok(PyRange {
|
||||
start: vm.new_pyref(sub_start),
|
||||
stop: vm.new_pyref(sub_stop),
|
||||
step: vm.new_pyref(sub_step),
|
||||
start: vm.ctx.new_pyref(sub_start),
|
||||
stop: vm.ctx.new_pyref(sub_stop),
|
||||
step: vm.ctx.new_pyref(sub_step),
|
||||
}
|
||||
.into_ref(vm)
|
||||
.into_ref(&vm.ctx)
|
||||
.into())
|
||||
}
|
||||
RangeIndex::Int(index) => match self.get(index.as_bigint()) {
|
||||
@@ -404,7 +404,7 @@ impl AsSequence for PyRange {
|
||||
item: atomic_func!(|seq, i, vm| {
|
||||
PyRange::sequence_downcast(seq)
|
||||
.get(&i.into())
|
||||
.map(|x| PyInt::from(x).into_ref(vm).into())
|
||||
.map(|x| PyInt::from(x).into_ref(&vm.ctx).into())
|
||||
.ok_or_else(|| vm.new_index_error("index out of range".to_owned()))
|
||||
}),
|
||||
contains: atomic_func!(|seq, needle, vm| {
|
||||
@@ -532,8 +532,8 @@ pub struct PyLongRangeIterator {
|
||||
}
|
||||
|
||||
impl PyPayload for PyLongRangeIterator {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.long_range_iterator_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.long_range_iterator_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -597,8 +597,8 @@ pub struct PyRangeIterator {
|
||||
}
|
||||
|
||||
impl PyPayload for PyRangeIterator {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.range_iterator_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.range_iterator_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,9 +661,9 @@ fn range_iter_reduce(
|
||||
let iter = builtins_iter(vm).to_owned();
|
||||
let stop = start.clone() + length * step.clone();
|
||||
let range = PyRange {
|
||||
start: PyInt::from(start).into_ref(vm),
|
||||
stop: PyInt::from(stop).into_ref(vm),
|
||||
step: PyInt::from(step).into_ref(vm),
|
||||
start: PyInt::from(start).into_ref(&vm.ctx),
|
||||
stop: PyInt::from(stop).into_ref(&vm.ctx),
|
||||
step: PyInt::from(step).into_ref(&vm.ctx),
|
||||
};
|
||||
Ok(vm.new_tuple((iter, (range,), index)))
|
||||
}
|
||||
|
||||
@@ -135,14 +135,14 @@ impl fmt::Debug for PyFrozenSet {
|
||||
}
|
||||
|
||||
impl PyPayload for PySet {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.set_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.set_type
|
||||
}
|
||||
}
|
||||
|
||||
impl PyPayload for PyFrozenSet {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.frozenset_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.frozenset_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -957,7 +957,7 @@ impl PyFrozenSet {
|
||||
Self {
|
||||
inner: zelf.inner.copy(),
|
||||
}
|
||||
.into_ref(vm)
|
||||
.into_ref(&vm.ctx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1236,8 +1236,8 @@ impl fmt::Debug for PySetIterator {
|
||||
}
|
||||
|
||||
impl PyPayload for PySetIterator {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.set_iterator_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.set_iterator_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ use crate::{
|
||||
pub struct PyNone;
|
||||
|
||||
impl PyPayload for PyNone {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.none_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.none_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,8 +77,8 @@ impl AsNumber for PyNone {
|
||||
pub struct PyNotImplemented;
|
||||
|
||||
impl PyPayload for PyNotImplemented {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.not_implemented_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.not_implemented_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ pub struct PySlice {
|
||||
}
|
||||
|
||||
impl PyPayload for PySlice {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.slice_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.slice_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,8 +265,8 @@ impl Representable for PySlice {
|
||||
pub struct PyEllipsis;
|
||||
|
||||
impl PyPayload for PyEllipsis {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.ellipsis_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.ellipsis_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ pub struct PyStaticMethod {
|
||||
}
|
||||
|
||||
impl PyPayload for PyStaticMethod {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.staticmethod_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.staticmethod_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ impl Callable for PyStaticMethod {
|
||||
impl Representable for PyStaticMethod {
|
||||
fn repr_str(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<String> {
|
||||
let callable = zelf.callable.lock().repr(vm).unwrap();
|
||||
let class = Self::class(vm);
|
||||
let class = Self::class(&vm.ctx);
|
||||
|
||||
match (
|
||||
class
|
||||
|
||||
@@ -186,8 +186,8 @@ pub struct PyStrIterator {
|
||||
}
|
||||
|
||||
impl PyPayload for PyStrIterator {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.str_iterator_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.str_iterator_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,7 +357,7 @@ impl PyStr {
|
||||
zelf.as_str()
|
||||
.as_bytes()
|
||||
.mul(vm, value)
|
||||
.map(|x| Self::from(unsafe { String::from_utf8_unchecked(x) }).into_ref(vm))
|
||||
.map(|x| Self::from(unsafe { String::from_utf8_unchecked(x) }).into_ref(&vm.ctx))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,7 +422,7 @@ impl PyStr {
|
||||
SequenceIndex::Int(i) => self.getitem_by_index(vm, i).map(|x| x.to_string()),
|
||||
SequenceIndex::Slice(slice) => self.getitem_by_slice(vm, slice),
|
||||
}
|
||||
.map(|x| self.new_substr(x).into_ref(vm).into())
|
||||
.map(|x| self.new_substr(x).into_ref(&vm.ctx).into())
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
@@ -1279,7 +1279,7 @@ impl PyStrRef {
|
||||
let mut s = String::with_capacity(self.byte_len() + other.len());
|
||||
s.push_str(self.as_ref());
|
||||
s.push_str(other);
|
||||
*self = PyStr::from(s).into_ref(vm);
|
||||
*self = PyStr::from(s).into_ref(&vm.ctx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1365,7 +1365,7 @@ impl AsSequence for PyStr {
|
||||
item: atomic_func!(|seq, i, vm| {
|
||||
let zelf = PyStr::sequence_downcast(seq);
|
||||
zelf.getitem_by_index(vm, i)
|
||||
.map(|x| zelf.new_substr(x.to_string()).into_ref(vm).into())
|
||||
.map(|x| zelf.new_substr(x.to_string()).into_ref(&vm.ctx).into())
|
||||
}),
|
||||
contains: atomic_func!(
|
||||
|seq, needle, vm| PyStr::sequence_downcast(seq)._contains(needle, vm)
|
||||
@@ -1397,8 +1397,8 @@ pub(crate) fn encode_string(
|
||||
}
|
||||
|
||||
impl PyPayload for PyStr {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.str_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.str_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ pub struct PySuper {
|
||||
}
|
||||
|
||||
impl PyPayload for PySuper {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.super_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.super_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use rustpython_common::lock::PyMutex;
|
||||
|
||||
use super::PyType;
|
||||
use crate::{class::PyClassImpl, frame::FrameRef, Context, Py, PyPayload, PyRef, VirtualMachine};
|
||||
use crate::{class::PyClassImpl, frame::FrameRef, Context, Py, PyPayload, PyRef};
|
||||
|
||||
#[pyclass(module = false, name = "traceback")]
|
||||
#[derive(Debug)]
|
||||
@@ -15,8 +15,8 @@ pub struct PyTraceback {
|
||||
pub type PyTracebackRef = PyRef<PyTraceback>;
|
||||
|
||||
impl PyPayload for PyTraceback {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.traceback_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.traceback_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ impl fmt::Debug for PyTuple {
|
||||
}
|
||||
|
||||
impl PyPayload for PyTuple {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.tuple_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.tuple_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ impl PyTuple {
|
||||
} else {
|
||||
let v = zelf.elements.mul(vm, value)?;
|
||||
let elements = v.into_boxed_slice();
|
||||
Self { elements }.into_ref(vm)
|
||||
Self { elements }.into_ref(&vm.ctx)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -216,7 +216,7 @@ impl PyTuple {
|
||||
.chain(other.as_slice())
|
||||
.cloned()
|
||||
.collect::<Box<[_]>>();
|
||||
Self { elements }.into_ref(vm)
|
||||
Self { elements }.into_ref(&vm.ctx)
|
||||
}
|
||||
});
|
||||
PyArithmeticValue::from_option(added.ok())
|
||||
@@ -428,8 +428,8 @@ pub(crate) struct PyTupleIterator {
|
||||
}
|
||||
|
||||
impl PyPayload for PyTupleIterator {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.tuple_iterator_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.tuple_iterator_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -114,8 +114,8 @@ impl fmt::Debug for PyType {
|
||||
}
|
||||
|
||||
impl PyPayload for PyType {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.type_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.type_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -793,14 +793,15 @@ impl PyType {
|
||||
setter: MemberSetter::Offset(offset),
|
||||
doc: None,
|
||||
};
|
||||
let member_descriptor: PyRef<MemberDescrObject> = vm.new_pyref(MemberDescrObject {
|
||||
common: DescrObject {
|
||||
typ: typ.to_owned(),
|
||||
name: member.to_string(),
|
||||
qualname: PyRwLock::new(None),
|
||||
},
|
||||
member: member_def,
|
||||
});
|
||||
let member_descriptor: PyRef<MemberDescrObject> =
|
||||
vm.ctx.new_pyref(MemberDescrObject {
|
||||
common: DescrObject {
|
||||
typ: typ.to_owned(),
|
||||
name: member.to_string(),
|
||||
qualname: PyRwLock::new(None),
|
||||
},
|
||||
member: member_def,
|
||||
});
|
||||
|
||||
let attr_name = vm.ctx.intern_str(member.to_string());
|
||||
if !typ.has_attr(attr_name) {
|
||||
|
||||
@@ -29,8 +29,8 @@ impl fmt::Debug for PyUnion {
|
||||
}
|
||||
|
||||
impl PyPayload for PyUnion {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.union_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.union_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ impl Hashable for PyUnion {
|
||||
#[inline]
|
||||
fn hash(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<hash::PyHash> {
|
||||
let set = PyFrozenSet::from_iter(vm, zelf.args.into_iter().cloned())?;
|
||||
PyFrozenSet::hash(&set.into_ref(vm), vm)
|
||||
PyFrozenSet::hash(&set.into_ref(&vm.ctx), vm)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ pub struct PyWeakProxy {
|
||||
}
|
||||
|
||||
impl PyPayload for PyWeakProxy {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.weakproxy_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.weakproxy_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,8 @@ pub struct WeakNewArgs {
|
||||
}
|
||||
|
||||
impl PyPayload for PyWeak {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.weakref_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.weakref_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ pub struct PyZip {
|
||||
}
|
||||
|
||||
impl PyPayload for PyZip {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.zip_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.zip_type
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ impl ByteInnerNewOptions {
|
||||
(OptionalArg::Present(obj), OptionalArg::Missing, OptionalArg::Missing) => {
|
||||
let obj = obj.clone();
|
||||
// construct an exact bytes from an exact bytes do not clone
|
||||
let obj = if cls.is(PyBytes::class(vm)) {
|
||||
let obj = if cls.is(PyBytes::class(&vm.ctx)) {
|
||||
match obj.downcast_exact::<PyBytes>(vm) {
|
||||
Ok(b) => return Ok(b.into_pyref()),
|
||||
Err(obj) => obj,
|
||||
@@ -91,7 +91,7 @@ impl ByteInnerNewOptions {
|
||||
// construct an exact bytes from __bytes__ slot.
|
||||
// if __bytes__ return a bytes, use the bytes object except we are the subclass of the bytes
|
||||
let bytes = bytes_method?.call((), vm)?;
|
||||
let bytes = if cls.is(PyBytes::class(vm)) {
|
||||
let bytes = if cls.is(PyBytes::class(&vm.ctx)) {
|
||||
match bytes.downcast::<PyBytes>() {
|
||||
Ok(b) => return Ok(b),
|
||||
Err(bytes) => bytes,
|
||||
|
||||
@@ -228,7 +228,7 @@ impl CodecsRegistry {
|
||||
}
|
||||
inner.search_path.clone()
|
||||
};
|
||||
let encoding = PyStr::from(encoding.into_owned()).into_ref(vm);
|
||||
let encoding = PyStr::from(encoding.into_owned()).into_ref(&vm.ctx);
|
||||
for func in search_path {
|
||||
let res = func.call((encoding.clone(),), vm)?;
|
||||
let res: Option<PyCodec> = res.try_into_value(vm)?;
|
||||
|
||||
@@ -15,7 +15,7 @@ pub unsafe trait TransmuteFromObject: Sized {
|
||||
|
||||
unsafe impl<T: PyPayload> TransmuteFromObject for PyRef<T> {
|
||||
fn check(vm: &VirtualMachine, obj: &PyObject) -> PyResult<()> {
|
||||
let class = T::class(vm);
|
||||
let class = T::class(&vm.ctx);
|
||||
if obj.fast_isinstance(class) {
|
||||
if obj.payload_is::<T>() {
|
||||
Ok(())
|
||||
|
||||
@@ -43,7 +43,7 @@ impl PyObject {
|
||||
T: PyPayload,
|
||||
F: Fn(&T) -> PyResult<R>,
|
||||
{
|
||||
let class = T::class(vm);
|
||||
let class = T::class(&vm.ctx);
|
||||
let py_ref = if self.fast_isinstance(class) {
|
||||
self.downcast_ref()
|
||||
.ok_or_else(|| vm.new_downcast_runtime_error(class, self))?
|
||||
@@ -69,7 +69,7 @@ where
|
||||
{
|
||||
#[inline]
|
||||
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
|
||||
let class = T::class(vm);
|
||||
let class = T::class(&vm.ctx);
|
||||
if obj.fast_isinstance(class) {
|
||||
obj.downcast()
|
||||
.map_err(|obj| vm.new_downcast_runtime_error(class, &obj))
|
||||
@@ -104,7 +104,7 @@ impl<'a, T: 'a + TryFromObject> TryFromBorrowedObject<'a> for Vec<T> {
|
||||
|
||||
impl<'a, T: PyPayload> TryFromBorrowedObject<'a> for &'a Py<T> {
|
||||
fn try_from_borrowed_object(vm: &VirtualMachine, obj: &'a PyObject) -> PyResult<Self> {
|
||||
let class = T::class(vm);
|
||||
let class = T::class(&vm.ctx);
|
||||
if obj.fast_isinstance(class) {
|
||||
obj.downcast_ref()
|
||||
.ok_or_else(|| vm.new_downcast_runtime_error(class, &obj))
|
||||
|
||||
@@ -29,8 +29,8 @@ impl std::fmt::Debug for PyBaseException {
|
||||
}
|
||||
|
||||
impl PyPayload for PyBaseException {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.exceptions.base_exception_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.exceptions.base_exception_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,20 +159,20 @@ impl VirtualMachine {
|
||||
let args0_repr = if str_single {
|
||||
varargs[0]
|
||||
.str(vm)
|
||||
.unwrap_or_else(|_| PyStr::from("<element str() failed>").into_ref(vm))
|
||||
.unwrap_or_else(|_| PyStr::from("<element str() failed>").into_ref(&vm.ctx))
|
||||
} else {
|
||||
varargs[0]
|
||||
.repr(vm)
|
||||
.unwrap_or_else(|_| PyStr::from("<element repr() failed>").into_ref(vm))
|
||||
varargs[0].repr(vm).unwrap_or_else(|_| {
|
||||
PyStr::from("<element repr() failed>").into_ref(&vm.ctx)
|
||||
})
|
||||
};
|
||||
vec![args0_repr]
|
||||
}
|
||||
_ => varargs
|
||||
.iter()
|
||||
.map(|vararg| {
|
||||
vararg
|
||||
.repr(vm)
|
||||
.unwrap_or_else(|_| PyStr::from("<element repr() failed>").into_ref(vm))
|
||||
vararg.repr(vm).unwrap_or_else(|_| {
|
||||
PyStr::from("<element repr() failed>").into_ref(&vm.ctx)
|
||||
})
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
@@ -498,7 +498,7 @@ impl PyBaseException {
|
||||
match str_args.into_iter().exactly_one() {
|
||||
Err(i) if i.len() == 0 => vm.ctx.empty_str.clone(),
|
||||
Ok(s) => s,
|
||||
Err(i) => PyStr::from(format!("({})", i.format(", "))).into_ref(vm),
|
||||
Err(i) => PyStr::from(format!("({})", i.format(", "))).into_ref(&vm.ctx),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ use crate::{
|
||||
protocol::{PyIter, PyIterReturn},
|
||||
scope::Scope,
|
||||
stdlib::builtins,
|
||||
vm::PyMethod,
|
||||
vm::{Context, PyMethod},
|
||||
AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, VirtualMachine,
|
||||
};
|
||||
use indexmap::IndexMap;
|
||||
@@ -116,8 +116,8 @@ pub struct Frame {
|
||||
}
|
||||
|
||||
impl PyPayload for Frame {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType> {
|
||||
vm.ctx.types.frame_type
|
||||
fn class(ctx: &Context) -> &'static Py<PyType> {
|
||||
ctx.types.frame_type
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ impl Frame {
|
||||
closure: &[PyCellRef],
|
||||
vm: &VirtualMachine,
|
||||
) -> Frame {
|
||||
let cells_frees = std::iter::repeat_with(|| PyCell::default().into_ref(vm))
|
||||
let cells_frees = std::iter::repeat_with(|| PyCell::default().into_ref(&vm.ctx))
|
||||
.take(code.cellvars.len())
|
||||
.chain(closure.iter().cloned())
|
||||
.collect();
|
||||
@@ -383,7 +383,7 @@ impl ExecutingFrame<'_> {
|
||||
loc.row(),
|
||||
);
|
||||
vm_trace!("Adding to traceback: {:?} {:?}", new_traceback, loc.row());
|
||||
exception.set_traceback(Some(new_traceback.into_ref(vm)));
|
||||
exception.set_traceback(Some(new_traceback.into_ref(&vm.ctx)));
|
||||
|
||||
vm.contextualize_exception(&exception);
|
||||
|
||||
@@ -1333,7 +1333,7 @@ impl ExecutingFrame<'_> {
|
||||
stop,
|
||||
step,
|
||||
}
|
||||
.into_ref(vm);
|
||||
.into_ref(&vm.ctx);
|
||||
self.push_value(obj.into());
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ fn remove_importlib_frames_inner(
|
||||
traceback.lasti,
|
||||
traceback.lineno,
|
||||
)
|
||||
.into_ref(vm),
|
||||
.into_ref(&vm.ctx),
|
||||
),
|
||||
now_in_importlib,
|
||||
)
|
||||
|
||||
@@ -565,7 +565,7 @@ impl PyObjectRef {
|
||||
self,
|
||||
vm: &VirtualMachine,
|
||||
) -> Result<PyRefExact<T>, Self> {
|
||||
if self.class().is(T::class(vm)) {
|
||||
if self.class().is(T::class(&vm.ctx)) {
|
||||
// TODO: is this always true?
|
||||
assert!(
|
||||
self.payload_is::<T>(),
|
||||
@@ -663,7 +663,7 @@ impl PyObject {
|
||||
&self,
|
||||
vm: &VirtualMachine,
|
||||
) -> Option<&T> {
|
||||
if self.class().is(T::class(vm)) {
|
||||
if self.class().is(T::class(&vm.ctx)) {
|
||||
self.payload()
|
||||
} else {
|
||||
None
|
||||
@@ -694,7 +694,7 @@ impl PyObject {
|
||||
|
||||
#[inline(always)]
|
||||
pub fn payload_if_subclass<T: crate::PyPayload>(&self, vm: &VirtualMachine) -> Option<&T> {
|
||||
if self.class().fast_issubclass(T::class(vm)) {
|
||||
if self.class().fast_issubclass(T::class(&vm.ctx)) {
|
||||
self.payload()
|
||||
} else {
|
||||
None
|
||||
@@ -718,7 +718,7 @@ impl PyObject {
|
||||
vm: &VirtualMachine,
|
||||
) -> Option<&Py<T>> {
|
||||
self.class()
|
||||
.is(T::class(vm))
|
||||
.is(T::class(&vm.ctx))
|
||||
.then(|| unsafe { self.downcast_unchecked_ref::<T>() })
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ impl<T: PyObjectPayload> Clone for PyRefExact<T> {
|
||||
|
||||
impl<T: PyPayload> TryFromObject for PyRefExact<T> {
|
||||
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
|
||||
let target_cls = T::class(vm);
|
||||
let target_cls = T::class(&vm.ctx);
|
||||
let cls = obj.class();
|
||||
if cls.is(target_cls) {
|
||||
let obj = obj
|
||||
|
||||
@@ -2,7 +2,8 @@ use super::{Py, PyObjectRef, PyRef, PyResult};
|
||||
use crate::{
|
||||
builtins::{PyBaseExceptionRef, PyType, PyTypeRef},
|
||||
types::PyTypeFlags,
|
||||
vm::VirtualMachine,
|
||||
vm::{Context, VirtualMachine},
|
||||
PyRefExact,
|
||||
};
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
@@ -16,17 +17,17 @@ cfg_if::cfg_if! {
|
||||
}
|
||||
|
||||
pub trait PyPayload: std::fmt::Debug + PyThreadingConstraint + Sized + 'static {
|
||||
fn class(vm: &VirtualMachine) -> &'static Py<PyType>;
|
||||
fn class(ctx: &Context) -> &'static Py<PyType>;
|
||||
|
||||
#[inline]
|
||||
fn into_pyobject(self, vm: &VirtualMachine) -> PyObjectRef {
|
||||
self.into_ref(vm).into()
|
||||
self.into_ref(&vm.ctx).into()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn _into_ref(self, cls: PyTypeRef, vm: &VirtualMachine) -> PyRef<Self> {
|
||||
fn _into_ref(self, cls: PyTypeRef, ctx: &Context) -> PyRef<Self> {
|
||||
let dict = if cls.slots.flags.has_feature(PyTypeFlags::HAS_DICT) {
|
||||
Some(vm.ctx.new_dict())
|
||||
Some(ctx.new_dict())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
@@ -34,16 +35,24 @@ pub trait PyPayload: std::fmt::Debug + PyThreadingConstraint + Sized + 'static {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn into_ref(self, vm: &VirtualMachine) -> PyRef<Self> {
|
||||
let cls = Self::class(vm);
|
||||
self._into_ref(cls.to_owned(), vm)
|
||||
fn into_exact_ref(self, ctx: &Context) -> PyRefExact<Self> {
|
||||
unsafe {
|
||||
// Self::into_ref() always returns exact typed PyRef
|
||||
PyRefExact::new_unchecked(self.into_ref(ctx))
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn into_ref(self, ctx: &Context) -> PyRef<Self> {
|
||||
let cls = Self::class(ctx);
|
||||
self._into_ref(cls.to_owned(), ctx)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn into_ref_with_type(self, vm: &VirtualMachine, cls: PyTypeRef) -> PyResult<PyRef<Self>> {
|
||||
let exact_class = Self::class(vm);
|
||||
let exact_class = Self::class(&vm.ctx);
|
||||
if cls.fast_issubclass(exact_class) {
|
||||
Ok(self._into_ref(cls, vm))
|
||||
Ok(self._into_ref(cls, &vm.ctx))
|
||||
} else {
|
||||
#[cold]
|
||||
#[inline(never)]
|
||||
|
||||
@@ -51,7 +51,7 @@ impl PyObject {
|
||||
base, repr,
|
||||
))
|
||||
})?;
|
||||
Ok(PyInt::from(i).into_ref(vm))
|
||||
Ok(PyInt::from(i).into_ref(&vm.ctx))
|
||||
}
|
||||
|
||||
if let Some(i) = self.downcast_ref_if_exact::<PyInt>(vm) {
|
||||
@@ -303,7 +303,7 @@ impl PyNumber<'_> {
|
||||
pub fn int(self, vm: &VirtualMachine) -> Option<PyResult<PyIntRef>> {
|
||||
self.obj.class().slots.number.int.load().map(|f| {
|
||||
let ret = f(self, vm)?;
|
||||
let value = if !ret.class().is(PyInt::class(vm)) {
|
||||
let value = if !ret.class().is(PyInt::class(&vm.ctx)) {
|
||||
warnings::warn(
|
||||
vm.ctx.exceptions.deprecation_warning,
|
||||
format!(
|
||||
@@ -327,7 +327,7 @@ impl PyNumber<'_> {
|
||||
pub fn index(self, vm: &VirtualMachine) -> Option<PyResult<PyIntRef>> {
|
||||
self.obj.class().slots.number.index.load().map(|f| {
|
||||
let ret = f(self, vm)?;
|
||||
let value = if !ret.class().is(PyInt::class(vm)) {
|
||||
let value = if !ret.class().is(PyInt::class(&vm.ctx)) {
|
||||
warnings::warn(
|
||||
vm.ctx.exceptions.deprecation_warning,
|
||||
format!(
|
||||
@@ -351,7 +351,7 @@ impl PyNumber<'_> {
|
||||
pub fn float(self, vm: &VirtualMachine) -> Option<PyResult<PyRef<PyFloat>>> {
|
||||
self.obj.class().slots.number.float.load().map(|f| {
|
||||
let ret = f(self, vm)?;
|
||||
let value = if !ret.class().is(PyFloat::class(vm)) {
|
||||
let value = if !ret.class().is(PyFloat::class(&vm.ctx)) {
|
||||
warnings::warn(
|
||||
vm.ctx.exceptions.deprecation_warning,
|
||||
format!(
|
||||
|
||||
@@ -427,7 +427,7 @@ mod builtins {
|
||||
if let OptionalArg::Present(sentinel) = sentinel {
|
||||
let callable = ArgCallable::try_from_object(vm, iter_target)?;
|
||||
let iterator = PyCallableIterator::new(callable, sentinel)
|
||||
.into_ref(vm)
|
||||
.into_ref(&vm.ctx)
|
||||
.into();
|
||||
Ok(PyIter::new(iterator))
|
||||
} else {
|
||||
@@ -664,7 +664,9 @@ mod builtins {
|
||||
};
|
||||
let write = |obj: PyStrRef| vm.call_method(&file, "write", (obj,));
|
||||
|
||||
let sep = options.sep.unwrap_or_else(|| PyStr::from(" ").into_ref(vm));
|
||||
let sep = options
|
||||
.sep
|
||||
.unwrap_or_else(|| PyStr::from(" ").into_ref(&vm.ctx));
|
||||
|
||||
let mut first = true;
|
||||
for object in objects {
|
||||
@@ -679,7 +681,7 @@ mod builtins {
|
||||
|
||||
let end = options
|
||||
.end
|
||||
.unwrap_or_else(|| PyStr::from("\n").into_ref(vm));
|
||||
.unwrap_or_else(|| PyStr::from("\n").into_ref(&vm.ctx));
|
||||
write(end)?;
|
||||
|
||||
if *options.flush {
|
||||
|
||||
@@ -521,12 +521,12 @@ mod _collections {
|
||||
concat: atomic_func!(|seq, other, vm| {
|
||||
PyDeque::sequence_downcast(seq)
|
||||
.concat(other, vm)
|
||||
.map(|x| x.into_ref(vm).into())
|
||||
.map(|x| x.into_ref(&vm.ctx).into())
|
||||
}),
|
||||
repeat: atomic_func!(|seq, n, vm| {
|
||||
PyDeque::sequence_downcast(seq)
|
||||
.mul(n, vm)
|
||||
.map(|x| x.into_ref(vm).into())
|
||||
.map(|x| x.into_ref(&vm.ctx).into())
|
||||
}),
|
||||
item: atomic_func!(|seq, i, vm| PyDeque::sequence_downcast(seq).getitem(i, vm)),
|
||||
ass_item: atomic_func!(|seq, i, value, vm| {
|
||||
@@ -636,7 +636,7 @@ mod _collections {
|
||||
let internal = zelf.internal.lock();
|
||||
let deque = match &internal.status {
|
||||
Active(obj) => obj.clone(),
|
||||
Exhausted => PyDeque::default().into_ref(vm),
|
||||
Exhausted => PyDeque::default().into_ref(&vm.ctx),
|
||||
};
|
||||
(
|
||||
zelf.class().to_owned(),
|
||||
@@ -702,7 +702,7 @@ mod _collections {
|
||||
let internal = zelf.internal.lock();
|
||||
let deque = match &internal.status {
|
||||
Active(obj) => obj.clone(),
|
||||
Exhausted => PyDeque::default().into_ref(vm),
|
||||
Exhausted => PyDeque::default().into_ref(&vm.ctx),
|
||||
};
|
||||
Ok((
|
||||
zelf.class().to_owned(),
|
||||
|
||||
@@ -595,7 +595,7 @@ mod _io {
|
||||
fn read(instance: PyObjectRef, size: OptionalSize, vm: &VirtualMachine) -> PyResult {
|
||||
if let Some(size) = size.to_usize() {
|
||||
// FIXME: unnecessary zero-init
|
||||
let b = PyByteArray::from(vec![0; size]).into_ref(vm);
|
||||
let b = PyByteArray::from(vec![0; size]).into_ref(&vm.ctx);
|
||||
let n = <Option<usize>>::try_from_object(
|
||||
vm,
|
||||
vm.call_method(&instance, "readinto", (b.clone(),))?,
|
||||
@@ -920,13 +920,13 @@ mod _io {
|
||||
vm.call_method(self.raw.as_ref().unwrap(), "write", (memobj,))?
|
||||
} else {
|
||||
let v = std::mem::take(&mut self.buffer);
|
||||
let writebuf = VecBuffer::from(v).into_ref(vm);
|
||||
let writebuf = VecBuffer::from(v).into_ref(&vm.ctx);
|
||||
let memobj = PyMemoryView::from_buffer_range(
|
||||
writebuf.clone().into_pybuffer(true),
|
||||
buf_range,
|
||||
vm,
|
||||
)?
|
||||
.into_ref(vm);
|
||||
.into_ref(&vm.ctx);
|
||||
|
||||
// TODO: loop if write() raises an interrupt
|
||||
let res = vm.call_method(self.raw.as_ref().unwrap(), "write", (memobj.clone(),));
|
||||
@@ -1144,13 +1144,13 @@ mod _io {
|
||||
let res = match v {
|
||||
Either::A(v) => {
|
||||
let v = v.unwrap_or(&mut self.buffer);
|
||||
let readbuf = VecBuffer::from(std::mem::take(v)).into_ref(vm);
|
||||
let readbuf = VecBuffer::from(std::mem::take(v)).into_ref(&vm.ctx);
|
||||
let memobj = PyMemoryView::from_buffer_range(
|
||||
readbuf.clone().into_pybuffer(false),
|
||||
buf_range,
|
||||
vm,
|
||||
)?
|
||||
.into_ref(vm);
|
||||
.into_ref(&vm.ctx);
|
||||
|
||||
// TODO: loop if readinto() raises an interrupt
|
||||
let res =
|
||||
@@ -1207,7 +1207,7 @@ mod _io {
|
||||
if let Some(bytes) = res {
|
||||
data.extend_from_slice(bytes.as_bytes());
|
||||
}
|
||||
Some(PyBytes::from(data).into_ref(vm))
|
||||
Some(PyBytes::from(data).into_ref(&vm.ctx))
|
||||
} else {
|
||||
res
|
||||
};
|
||||
@@ -1239,7 +1239,7 @@ mod _io {
|
||||
for bytes in &chunks {
|
||||
data.extend_from_slice(bytes.as_bytes())
|
||||
}
|
||||
Some(PyBytes::from(data).into_ref(vm))
|
||||
Some(PyBytes::from(data).into_ref(&vm.ctx))
|
||||
};
|
||||
break Ok(ret);
|
||||
}
|
||||
@@ -1606,7 +1606,7 @@ mod _io {
|
||||
match n.to_usize() {
|
||||
Some(n) => data
|
||||
.read_generic(n, vm)
|
||||
.map(|x| x.map(|b| PyBytes::from(b).into_ref(vm))),
|
||||
.map(|x| x.map(|b| PyBytes::from(b).into_ref(&vm.ctx))),
|
||||
None => data.read_all(vm),
|
||||
}
|
||||
}
|
||||
@@ -2096,7 +2096,7 @@ mod _io {
|
||||
};
|
||||
let mut buf = Vec::with_capacity(num_bytes);
|
||||
writes_iter.for_each(|chunk| buf.extend_from_slice(chunk.as_bytes()));
|
||||
PyBytes::from(buf).into_ref(vm)
|
||||
PyBytes::from(buf).into_ref(&vm.ctx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2205,13 +2205,13 @@ mod _io {
|
||||
Some(enc) => enc,
|
||||
None => {
|
||||
// TODO: try os.device_encoding(fileno) and then locale.getpreferredencoding()
|
||||
PyStr::from(crate::codecs::DEFAULT_ENCODING).into_ref(vm)
|
||||
PyStr::from(crate::codecs::DEFAULT_ENCODING).into_ref(&vm.ctx)
|
||||
}
|
||||
};
|
||||
|
||||
let errors = args
|
||||
.errors
|
||||
.unwrap_or_else(|| PyStr::from("strict").into_ref(vm));
|
||||
.unwrap_or_else(|| PyStr::from("strict").into_ref(&vm.ctx));
|
||||
|
||||
let buffer = args.buffer;
|
||||
|
||||
@@ -2446,7 +2446,7 @@ mod _io {
|
||||
}
|
||||
textio.decoded_chars_used = cookie.num_to_skip();
|
||||
} else {
|
||||
textio.snapshot = Some((cookie.dec_flags, PyBytes::from(vec![]).into_ref(vm)))
|
||||
textio.snapshot = Some((cookie.dec_flags, PyBytes::from(vec![]).into_ref(&vm.ctx)))
|
||||
}
|
||||
if let Some((encoder, _)) = &textio.encoder {
|
||||
let start_of_stream = cookie.start_pos == 0 && cookie.dec_flags == 0;
|
||||
@@ -2622,7 +2622,7 @@ mod _io {
|
||||
for chunk in chunks {
|
||||
ret.push_str(chunk.as_str())
|
||||
}
|
||||
PyStr::from(ret).into_ref(vm)
|
||||
PyStr::from(ret).into_ref(&vm.ctx)
|
||||
}
|
||||
} else {
|
||||
let bytes = vm.call_method(&textio.buffer, "read", ())?;
|
||||
@@ -2662,7 +2662,7 @@ mod _io {
|
||||
let flush = textio.line_buffering && (has_lf || data.contains('\r'));
|
||||
let chunk = if let Some(replace_nl) = replace_nl {
|
||||
if has_lf {
|
||||
PyStr::from(data.replace('\n', replace_nl)).into_ref(vm)
|
||||
PyStr::from(data.replace('\n', replace_nl)).into_ref(&vm.ctx)
|
||||
} else {
|
||||
obj
|
||||
}
|
||||
@@ -2756,7 +2756,7 @@ mod _io {
|
||||
self.0
|
||||
} else {
|
||||
// TODO: try to use Arc::get_mut() on the str?
|
||||
PyStr::from(self.slice()).into_ref(vm)
|
||||
PyStr::from(self.slice()).into_ref(&vm.ctx)
|
||||
}
|
||||
}
|
||||
fn utf8_len(&self) -> Utf8size {
|
||||
@@ -2810,7 +2810,7 @@ mod _io {
|
||||
String::with_capacity(remaining.len() + decoded_chars.len());
|
||||
s.push_str(remaining);
|
||||
s.push_str(decoded_chars);
|
||||
PyStr::from(s).into_ref(vm)
|
||||
PyStr::from(s).into_ref(&vm.ctx)
|
||||
};
|
||||
start = Utf8size::default();
|
||||
line
|
||||
@@ -2872,7 +2872,7 @@ mod _io {
|
||||
for chunk in chunks {
|
||||
s.push_str(chunk.slice())
|
||||
}
|
||||
PyStr::from(s).into_ref(vm)
|
||||
PyStr::from(s).into_ref(&vm.ctx)
|
||||
} else if let Some(cur_line) = cur_line {
|
||||
cur_line.slice_pystr(vm)
|
||||
} else {
|
||||
@@ -2984,7 +2984,7 @@ mod _io {
|
||||
// TODO: inplace append to bytes when refcount == 1
|
||||
let mut next_input = dec_buffer.as_bytes().to_vec();
|
||||
next_input.extend_from_slice(&buf.borrow_buf());
|
||||
self.snapshot = Some((dec_flags, PyBytes::from(next_input).into_ref(vm)));
|
||||
self.snapshot = Some((dec_flags, PyBytes::from(next_input).into_ref(&vm.ctx)));
|
||||
}
|
||||
|
||||
Ok(eof)
|
||||
@@ -3014,11 +3014,11 @@ mod _io {
|
||||
if self.decoded_chars_used.bytes == 0 {
|
||||
(decoded_chars.clone(), avail_chars)
|
||||
} else {
|
||||
(PyStr::from(avail).into_ref(vm), avail_chars)
|
||||
(PyStr::from(avail).into_ref(&vm.ctx), avail_chars)
|
||||
}
|
||||
} else {
|
||||
let s = crate::common::str::get_chars(avail, 0..n);
|
||||
(PyStr::from(s).into_ref(vm), n)
|
||||
(PyStr::from(s).into_ref(&vm.ctx), n)
|
||||
};
|
||||
self.decoded_chars_used += Utf8size {
|
||||
bytes: chars.byte_len(),
|
||||
@@ -3053,7 +3053,7 @@ mod _io {
|
||||
if let Some(append) = append {
|
||||
s.push_str(append.as_str())
|
||||
}
|
||||
PyStr::from(s).into_ref(vm)
|
||||
PyStr::from(s).into_ref(&vm.ctx)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3858,7 +3858,9 @@ mod fileio {
|
||||
type Args = FileIOArgs;
|
||||
|
||||
fn init(zelf: PyRef<Self>, args: Self::Args, vm: &VirtualMachine) -> PyResult<()> {
|
||||
let mode_obj = args.mode.unwrap_or_else(|| PyStr::from("rb").into_ref(vm));
|
||||
let mode_obj = args
|
||||
.mode
|
||||
.unwrap_or_else(|| PyStr::from("rb").into_ref(&vm.ctx));
|
||||
let mode_str = mode_obj.as_str();
|
||||
let name = args.name;
|
||||
let (mode, flags) =
|
||||
|
||||
@@ -775,7 +775,7 @@ mod decl {
|
||||
let grouper = PyItertoolsGrouper {
|
||||
groupby: zelf.to_owned(),
|
||||
}
|
||||
.into_ref(vm);
|
||||
.into_ref(&vm.ctx);
|
||||
|
||||
state.grouper = Some(grouper.downgrade(None, vm).unwrap());
|
||||
Ok(PyIterReturn::Return(
|
||||
@@ -1202,8 +1202,8 @@ mod decl {
|
||||
#[pyclass(with(IterNext, Constructor))]
|
||||
impl PyItertoolsTee {
|
||||
fn from_iter(iterator: PyIter, vm: &VirtualMachine) -> PyResult {
|
||||
let class = PyItertoolsTee::class(vm);
|
||||
if iterator.class().is(PyItertoolsTee::class(vm)) {
|
||||
let class = PyItertoolsTee::class(&vm.ctx);
|
||||
if iterator.class().is(PyItertoolsTee::class(&vm.ctx)) {
|
||||
return vm.call_special_method(iterator.into(), identifier!(vm, __copy__), ());
|
||||
}
|
||||
Ok(PyItertoolsTee {
|
||||
|
||||
@@ -923,7 +923,7 @@ pub(super) mod _os {
|
||||
stat: OnceCell::new(),
|
||||
ino: AtomicCell::new(ino),
|
||||
}
|
||||
.into_ref(vm)
|
||||
.into_ref(&vm.ctx)
|
||||
.into(),
|
||||
))
|
||||
}
|
||||
@@ -946,7 +946,7 @@ pub(super) mod _os {
|
||||
entries: PyRwLock::new(Some(entries)),
|
||||
mode: path.mode,
|
||||
}
|
||||
.into_ref(vm)
|
||||
.into_ref(&vm.ctx)
|
||||
.into())
|
||||
}
|
||||
|
||||
@@ -1010,13 +1010,13 @@ pub(super) mod _os {
|
||||
let to_f64 = |(s, ns)| (s as f64) + (ns as f64) / (NANOS_PER_SEC as f64);
|
||||
let to_ns = |(s, ns)| s as i128 * NANOS_PER_SEC as i128 + ns as i128;
|
||||
StatResult {
|
||||
st_mode: vm.new_pyref(stat.st_mode),
|
||||
st_ino: vm.new_pyref(stat.st_ino),
|
||||
st_dev: vm.new_pyref(stat.st_dev),
|
||||
st_nlink: vm.new_pyref(stat.st_nlink),
|
||||
st_uid: vm.new_pyref(stat.st_uid),
|
||||
st_gid: vm.new_pyref(stat.st_gid),
|
||||
st_size: vm.new_pyref(stat.st_size),
|
||||
st_mode: vm.ctx.new_pyref(stat.st_mode),
|
||||
st_ino: vm.ctx.new_pyref(stat.st_ino),
|
||||
st_dev: vm.ctx.new_pyref(stat.st_dev),
|
||||
st_nlink: vm.ctx.new_pyref(stat.st_nlink),
|
||||
st_uid: vm.ctx.new_pyref(stat.st_uid),
|
||||
st_gid: vm.ctx.new_pyref(stat.st_gid),
|
||||
st_size: vm.ctx.new_pyref(stat.st_size),
|
||||
__st_atime_int: atime.0,
|
||||
__st_mtime_int: mtime.0,
|
||||
__st_ctime_int: ctime.0,
|
||||
@@ -1799,9 +1799,9 @@ pub fn extend_module(vm: &VirtualMachine, module: &PyObject) {
|
||||
_os::extend_module(vm, module);
|
||||
|
||||
let support_funcs = _os::support_funcs();
|
||||
let supports_fd = PySet::default().into_ref(vm);
|
||||
let supports_dir_fd = PySet::default().into_ref(vm);
|
||||
let supports_follow_symlinks = PySet::default().into_ref(vm);
|
||||
let supports_fd = PySet::default().into_ref(&vm.ctx);
|
||||
let supports_dir_fd = PySet::default().into_ref(&vm.ctx);
|
||||
let supports_follow_symlinks = PySet::default().into_ref(&vm.ctx);
|
||||
for support in support_funcs {
|
||||
let func_obj = module.to_owned().get_attr(support.name, vm).unwrap();
|
||||
if support.fd.unwrap_or(false) {
|
||||
|
||||
@@ -187,7 +187,7 @@ mod _sre {
|
||||
state.pymatch(req);
|
||||
Ok(state
|
||||
.has_matched
|
||||
.then(|| Match::new(&state, zelf.clone(), string).into_ref(vm)))
|
||||
.then(|| Match::new(&state, zelf.clone(), string).into_ref(&vm.ctx)))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -202,9 +202,9 @@ mod _sre {
|
||||
req.match_all = true;
|
||||
let mut state = State::default();
|
||||
state.pymatch(req);
|
||||
Ok(state
|
||||
.has_matched
|
||||
.then(|| Match::new(&state, zelf.clone(), string_args.string).into_ref(vm)))
|
||||
Ok(state.has_matched.then(|| {
|
||||
Match::new(&state, zelf.clone(), string_args.string).into_ref(&vm.ctx)
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -218,9 +218,9 @@ mod _sre {
|
||||
let req = x.create_request(&zelf, string_args.pos, string_args.endpos);
|
||||
let mut state = State::default();
|
||||
state.search(req);
|
||||
Ok(state
|
||||
.has_matched
|
||||
.then(|| Match::new(&state, zelf.clone(), string_args.string).into_ref(vm)))
|
||||
Ok(state.has_matched.then(|| {
|
||||
Match::new(&state, zelf.clone(), string_args.string).into_ref(&vm.ctx)
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ mod _sre {
|
||||
end: string_args.endpos,
|
||||
must_advance: AtomicCell::new(false),
|
||||
}
|
||||
.into_ref(vm);
|
||||
.into_ref(&vm.ctx);
|
||||
let search = vm.get_str_method(scanner.into(), "search").unwrap()?;
|
||||
let search = ArgCallable::try_from_object(vm, search)?;
|
||||
let iterator = PyCallableIterator::new(search, vm.ctx.none());
|
||||
@@ -287,7 +287,7 @@ mod _sre {
|
||||
end: string_args.endpos,
|
||||
must_advance: AtomicCell::new(false),
|
||||
}
|
||||
.into_ref(vm)
|
||||
.into_ref(&vm.ctx)
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
@@ -444,7 +444,7 @@ mod _sre {
|
||||
|
||||
if is_callable {
|
||||
let m = Match::new(&iter.state, zelf.clone(), string.clone());
|
||||
let ret = filter.call((m.into_ref(vm),), vm)?;
|
||||
let ret = filter.call((m.into_ref(&vm.ctx),), vm)?;
|
||||
sublist.push(ret);
|
||||
} else {
|
||||
sublist.push(filter.clone());
|
||||
@@ -799,7 +799,7 @@ mod _sre {
|
||||
self.start.store(state.string_position);
|
||||
|
||||
Ok(state.has_matched.then(|| {
|
||||
Match::new(&state, self.pattern.clone(), self.string.clone()).into_ref(vm)
|
||||
Match::new(&state, self.pattern.clone(), self.string.clone()).into_ref(&vm.ctx)
|
||||
}))
|
||||
})
|
||||
}
|
||||
@@ -821,7 +821,7 @@ mod _sre {
|
||||
self.start.store(state.string_position);
|
||||
|
||||
Ok(state.has_matched.then(|| {
|
||||
Match::new(&state, self.pattern.clone(), self.string.clone()).into_ref(vm)
|
||||
Match::new(&state, self.pattern.clone(), self.string.clone()).into_ref(&vm.ctx)
|
||||
}))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ mod symtable {
|
||||
.map_err(|err| vm.new_syntax_error(&err))?;
|
||||
|
||||
let py_symbol_table = to_py_symbol_table(symtable);
|
||||
Ok(py_symbol_table.into_ref(vm))
|
||||
Ok(py_symbol_table.into_ref(&vm.ctx))
|
||||
}
|
||||
|
||||
fn to_py_symbol_table(symtable: SymbolTable) -> PySymbolTable {
|
||||
@@ -91,7 +91,7 @@ mod symtable {
|
||||
.collect(),
|
||||
is_top_scope: self.symtable.name == "top",
|
||||
}
|
||||
.into_ref(vm))
|
||||
.into_ref(&vm.ctx))
|
||||
} else {
|
||||
Err(vm.new_key_error(vm.ctx.new_str(format!("lookup {name} failed")).into()))
|
||||
}
|
||||
@@ -126,7 +126,7 @@ mod symtable {
|
||||
.collect(),
|
||||
is_top_scope: self.symtable.name == "top",
|
||||
})
|
||||
.into_ref(vm)
|
||||
.into_ref(&vm.ctx)
|
||||
.into()
|
||||
})
|
||||
.collect();
|
||||
@@ -251,7 +251,7 @@ mod symtable {
|
||||
);
|
||||
}
|
||||
Ok(to_py_symbol_table(self.namespaces.first().unwrap().clone())
|
||||
.into_ref(vm)
|
||||
.into_ref(&vm.ctx)
|
||||
.into())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,7 +319,7 @@ pub(crate) mod _thread {
|
||||
|
||||
#[pyfunction]
|
||||
fn _set_sentinel(vm: &VirtualMachine) -> PyRef<Lock> {
|
||||
let lock = Lock { mu: RawMutex::INIT }.into_ref(vm);
|
||||
let lock = Lock { mu: RawMutex::INIT }.into_ref(&vm.ctx);
|
||||
SENTINELS.with(|sents| sents.borrow_mut().push(lock.clone()));
|
||||
lock
|
||||
}
|
||||
|
||||
@@ -346,6 +346,15 @@ impl Context {
|
||||
self.not_implemented.clone().into()
|
||||
}
|
||||
|
||||
// universal pyref constructor
|
||||
pub fn new_pyref<T, P>(&self, value: T) -> PyRef<P>
|
||||
where
|
||||
T: Into<P>,
|
||||
P: PyPayload,
|
||||
{
|
||||
value.into().into_ref(self)
|
||||
}
|
||||
|
||||
// shortcuts for common type
|
||||
|
||||
#[inline]
|
||||
|
||||
@@ -343,7 +343,7 @@ impl VirtualMachine {
|
||||
}
|
||||
|
||||
pub fn run_code_obj(&self, code: PyRef<PyCode>, scope: Scope) -> PyResult {
|
||||
let frame = Frame::new(code, scope, self.builtins.dict(), &[], self).into_ref(self);
|
||||
let frame = Frame::new(code, scope, self.builtins.dict(), &[], self).into_ref(&self.ctx);
|
||||
self.run_frame(frame)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::{
|
||||
convert::ToPyObject,
|
||||
scope::Scope,
|
||||
vm::VirtualMachine,
|
||||
AsObject, Py, PyObject, PyObjectRef, PyPayload, PyRef,
|
||||
AsObject, Py, PyObject, PyObjectRef, PyRef,
|
||||
};
|
||||
|
||||
/// Collection of object creation helpers
|
||||
@@ -16,14 +16,6 @@ impl VirtualMachine {
|
||||
value.to_pyobject(self)
|
||||
}
|
||||
|
||||
pub fn new_pyref<T, P>(&self, value: T) -> PyRef<P>
|
||||
where
|
||||
T: Into<P>,
|
||||
P: PyPayload,
|
||||
{
|
||||
value.into().into_ref(self)
|
||||
}
|
||||
|
||||
pub fn new_tuple(&self, value: impl IntoPyTuple) -> PyTupleRef {
|
||||
value.into_pytuple(self)
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ pub fn js_to_py(vm: &VirtualMachine, js_val: JsValue) -> PyObjectRef {
|
||||
// the browser module might not be injected
|
||||
if vm.try_class("browser", "Promise").is_ok() {
|
||||
return js_module::PyPromise::new(promise.clone())
|
||||
.into_ref(vm)
|
||||
.into_ref(&vm.ctx)
|
||||
.into();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ mod _js {
|
||||
} else {
|
||||
Closure::once(Box::new(f))
|
||||
};
|
||||
let wrapped = PyJsValue::new(wrap_closure(closure.as_ref())).into_ref(vm);
|
||||
let wrapped = PyJsValue::new(wrap_closure(closure.as_ref())).into_ref(&vm.ctx);
|
||||
Ok(JsClosure {
|
||||
closure: Some((closure, wrapped)).into(),
|
||||
destroyed: false.into(),
|
||||
|
||||
@@ -30,7 +30,7 @@ fn init_window_module(vm: &VirtualMachine) -> PyObjectRef {
|
||||
let module = _window::make_module(vm);
|
||||
|
||||
extend_module!(vm, module, {
|
||||
"window" => js_module::PyJsValue::new(wasm_builtins::window()).into_ref(vm),
|
||||
"window" => js_module::PyJsValue::new(wasm_builtins::window()).into_ref(&vm.ctx),
|
||||
});
|
||||
|
||||
module
|
||||
|
||||
Reference in New Issue
Block a user