Skip to content

Commit 7b99df6

Browse files
committed
PyPayload::class takes ctx instead of vm
1 parent 70fb78d commit 7b99df6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+372
-353
lines changed

derive-impl/src/pyclass.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ pub(crate) fn impl_define_exception(exc_def: PyExceptionDef) -> Result<TokenStre
482482

483483
// We need this to make extend mechanism work:
484484
impl ::rustpython_vm::PyPayload for #class_name {
485-
fn class(vm: &::rustpython_vm::VirtualMachine) -> &'static ::rustpython_vm::Py<::rustpython_vm::builtins::PyType> {
486-
vm.ctx.exceptions.#ctx_name
485+
fn class(ctx: &::rustpython_vm::vm::Context) -> &'static ::rustpython_vm::Py<::rustpython_vm::builtins::PyType> {
486+
ctx.exceptions.#ctx_name
487487
}
488488
}
489489

derive-impl/src/pypayload.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(crate) fn impl_pypayload(input: DeriveInput) -> Result<TokenStream> {
77

88
let ret = quote! {
99
impl ::rustpython_vm::PyPayload for #ty {
10-
fn class(_vm: &::rustpython_vm::VirtualMachine) -> &'static rustpython_vm::Py<::rustpython_vm::builtins::PyType> {
10+
fn class(_ctx: &::rustpython_vm::vm::Context) -> &'static rustpython_vm::Py<::rustpython_vm::builtins::PyType> {
1111
<Self as ::rustpython_vm::class::StaticType>::static_type()
1212
}
1313
}

stdlib/src/array.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ mod array {
671671
)
672672
})?;
673673

674-
if cls.is(PyArray::class(vm)) && !kwargs.is_empty() {
674+
if cls.is(PyArray::class(&vm.ctx)) && !kwargs.is_empty() {
675675
return Err(
676676
vm.new_type_error("array.array() takes no keyword arguments".to_owned())
677677
);
@@ -952,7 +952,7 @@ mod array {
952952
let bytes = bytes.get_bytes();
953953

954954
for b in bytes.chunks(BLOCKSIZE) {
955-
let b = PyBytes::from(b.to_vec()).into_ref(vm);
955+
let b = PyBytes::from(b.to_vec()).into_ref(&vm.ctx);
956956
vm.call_method(&f, "write", (b,))?;
957957
}
958958
Ok(())
@@ -1072,7 +1072,7 @@ mod array {
10721072
if let Some(other) = other.payload::<PyArray>() {
10731073
self.read()
10741074
.add(&other.read(), vm)
1075-
.map(|array| PyArray::from(array).into_ref(vm))
1075+
.map(|array| PyArray::from(array).into_ref(&vm.ctx))
10761076
} else {
10771077
Err(vm.new_type_error(format!(
10781078
"can only append array (not \"{}\") to array",
@@ -1105,7 +1105,7 @@ mod array {
11051105
fn mul(&self, value: isize, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
11061106
self.read()
11071107
.mul(value, vm)
1108-
.map(|x| Self::from(x).into_ref(vm))
1108+
.map(|x| Self::from(x).into_ref(&vm.ctx))
11091109
}
11101110

11111111
#[pymethod(magic)]
@@ -1565,7 +1565,7 @@ mod array {
15651565
}
15661566

15671567
fn check_array_type(typ: PyTypeRef, vm: &VirtualMachine) -> PyResult<PyTypeRef> {
1568-
if !typ.fast_issubclass(PyArray::class(vm)) {
1568+
if !typ.fast_issubclass(PyArray::class(&vm.ctx)) {
15691569
return Err(
15701570
vm.new_type_error(format!("{} is not a subtype of array.array", typ.name()))
15711571
);

stdlib/src/mmap.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ mod mmap {
742742
MmapObj::Write(mmap) => mmap[pos..end_pos].to_vec(),
743743
};
744744

745-
let result = PyBytes::from(bytes).into_ref(vm);
745+
let result = PyBytes::from(bytes).into_ref(&vm.ctx);
746746

747747
self.advance_pos(num_bytes);
748748

@@ -763,7 +763,7 @@ mod mmap {
763763

764764
self.advance_pos(1);
765765

766-
Ok(PyInt::from(b).into_ref(vm))
766+
Ok(PyInt::from(b).into_ref(&vm.ctx))
767767
}
768768

769769
#[pymethod]
@@ -773,7 +773,7 @@ mod mmap {
773773

774774
let remaining = self.len().saturating_sub(pos);
775775
if remaining == 0 {
776-
return Ok(PyBytes::from(vec![]).into_ref(vm));
776+
return Ok(PyBytes::from(vec![]).into_ref(&vm.ctx));
777777
}
778778

779779
let eof = match mmap.as_ref().unwrap() {
@@ -794,7 +794,7 @@ mod mmap {
794794
MmapObj::Write(mmap) => mmap[pos..end_pos].to_vec(),
795795
};
796796

797-
let result = PyBytes::from(bytes).into_ref(vm);
797+
let result = PyBytes::from(bytes).into_ref(&vm.ctx);
798798

799799
self.advance_pos(end_pos - pos);
800800

@@ -856,7 +856,7 @@ mod mmap {
856856
Err(e) => return Err(vm.new_os_error(e.to_string())),
857857
};
858858

859-
Ok(PyInt::from(file_len).into_ref(vm))
859+
Ok(PyInt::from(file_len).into_ref(&vm.ctx))
860860
}
861861

862862
#[pymethod]
@@ -884,7 +884,7 @@ mod mmap {
884884

885885
self.advance_pos(len);
886886

887-
Ok(PyInt::from(len).into_ref(vm))
887+
Ok(PyInt::from(len).into_ref(&vm.ctx))
888888
}
889889

890890
#[pymethod]
@@ -945,7 +945,7 @@ mod mmap {
945945
MmapObj::Write(mmap) => mmap[i],
946946
};
947947

948-
Ok(PyInt::from(b).into_ref(vm).into())
948+
Ok(PyInt::from(b).into_ref(&vm.ctx).into())
949949
}
950950

951951
fn getitem_by_slice(
@@ -958,13 +958,13 @@ mod mmap {
958958
let mmap = self.check_valid(vm)?;
959959

960960
if slice_len == 0 {
961-
return Ok(PyBytes::from(vec![]).into_ref(vm).into());
961+
return Ok(PyBytes::from(vec![]).into_ref(&vm.ctx).into());
962962
} else if step == 1 {
963963
let bytes = match mmap.deref().as_ref().unwrap() {
964964
MmapObj::Read(mmap) => &mmap[range],
965965
MmapObj::Write(mmap) => &mmap[range],
966966
};
967-
return Ok(PyBytes::from(bytes.to_vec()).into_ref(vm).into());
967+
return Ok(PyBytes::from(bytes.to_vec()).into_ref(&vm.ctx).into());
968968
}
969969

970970
let mut result_buf = Vec::with_capacity(slice_len);
@@ -985,7 +985,7 @@ mod mmap {
985985
result_buf.push(b);
986986
}
987987
}
988-
Ok(PyBytes::from(result_buf).into_ref(vm).into())
988+
Ok(PyBytes::from(result_buf).into_ref(&vm.ctx).into())
989989
}
990990

991991
fn _getitem(&self, needle: &PyObject, vm: &VirtualMachine) -> PyResult<PyObjectRef> {

stdlib/src/pyexpat.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ mod _pyexpat {
7272
entity_decl: MutableObject::new(vm.ctx.none()),
7373
buffer_text: MutableObject::new(vm.ctx.new_bool(false).into()),
7474
}
75-
.into_ref(vm))
75+
.into_ref(&vm.ctx))
7676
}
7777

7878
#[extend_class]
@@ -118,15 +118,15 @@ mod _pyexpat {
118118
.unwrap();
119119
}
120120

121-
let name_str = PyStr::from(name.local_name).into_ref(vm);
121+
let name_str = PyStr::from(name.local_name).into_ref(&vm.ctx);
122122
invoke_handler(vm, &self.start_element, (name_str, dict));
123123
}
124124
Ok(XmlEvent::EndElement { name, .. }) => {
125-
let name_str = PyStr::from(name.local_name).into_ref(vm);
125+
let name_str = PyStr::from(name.local_name).into_ref(&vm.ctx);
126126
invoke_handler(vm, &self.end_element, (name_str,));
127127
}
128128
Ok(XmlEvent::Characters(chars)) => {
129-
let str = PyStr::from(chars).into_ref(vm);
129+
let str = PyStr::from(chars).into_ref(&vm.ctx);
130130
invoke_handler(vm, &self.character_data, (str,));
131131
}
132132
_ => {}

stdlib/src/pystruct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub(crate) mod _struct {
3636
b @ PyBytes => if b.is_ascii() {
3737
Some(unsafe {
3838
PyStr::new_ascii_unchecked(b.as_bytes().to_vec())
39-
}.into_ref(vm))
39+
}.into_ref(&vm.ctx))
4040
} else {
4141
None
4242
},

stdlib/src/sqlite.rs

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ mod _sqlite {
302302
isolation_level: Option<PyStrRef>,
303303
#[pyarg(any, default = "true")]
304304
check_same_thread: bool,
305-
#[pyarg(any, default = "Connection::class(vm).to_owned()")]
305+
#[pyarg(any, default = "Connection::class(&vm.ctx).to_owned()")]
306306
factory: PyTypeRef,
307307
// TODO: cache statements
308308
#[allow(dead_code)]
@@ -640,14 +640,14 @@ mod _sqlite {
640640

641641
#[pyfunction]
642642
fn register_adapter(typ: PyTypeRef, adapter: ArgCallable, vm: &VirtualMachine) -> PyResult<()> {
643-
if typ.is(PyInt::class(vm))
644-
|| typ.is(PyFloat::class(vm))
645-
|| typ.is(PyStr::class(vm))
646-
|| typ.is(PyByteArray::class(vm))
643+
if typ.is(PyInt::class(&vm.ctx))
644+
|| typ.is(PyFloat::class(&vm.ctx))
645+
|| typ.is(PyStr::class(&vm.ctx))
646+
|| typ.is(PyByteArray::class(&vm.ctx))
647647
{
648648
let _ = BASE_TYPE_ADAPTED.set(());
649649
}
650-
let protocol = PrepareProtocol::class(vm).to_owned();
650+
let protocol = PrepareProtocol::class(&vm.ctx).to_owned();
651651
let key = vm.ctx.new_tuple(vec![typ.into(), protocol.into()]);
652652
adapters().set_item(key.as_object(), adapter.into(), vm)
653653
}
@@ -708,7 +708,7 @@ mod _sqlite {
708708
// TODO: None proto
709709
let proto = proto
710710
.flatten()
711-
.unwrap_or_else(|| PrepareProtocol::class(vm).to_owned());
711+
.unwrap_or_else(|| PrepareProtocol::class(&vm.ctx).to_owned());
712712

713713
_adapt(
714714
&obj,
@@ -818,7 +818,7 @@ mod _sqlite {
818818

819819
fn call(zelf: &Py<Self>, args: Self::Args, vm: &VirtualMachine) -> PyResult {
820820
if let Some(stmt) = Statement::new(zelf, &args.0, vm)? {
821-
Ok(stmt.into_ref(vm).into())
821+
Ok(stmt.into_ref(&vm.ctx).into())
822822
} else {
823823
Ok(vm.ctx.none())
824824
}
@@ -835,7 +835,7 @@ mod _sqlite {
835835
if let Some(isolation_level) = &args.isolation_level {
836836
begin_statement_ptr_from_isolation_level(isolation_level, vm)?;
837837
}
838-
let text_factory = PyStr::class(vm).to_owned().into_object();
838+
let text_factory = PyStr::class(&vm.ctx).to_owned().into_object();
839839

840840
Ok(Self {
841841
db: PyMutex::new(Some(db)),
@@ -884,7 +884,7 @@ mod _sqlite {
884884
cursor
885885
} else {
886886
let row_factory = zelf.row_factory.to_owned();
887-
Cursor::new(zelf, row_factory, vm).into_ref(vm)
887+
Cursor::new(zelf, row_factory, vm).into_ref(&vm.ctx)
888888
};
889889
Ok(cursor)
890890
}
@@ -921,7 +921,7 @@ mod _sqlite {
921921
connection: zelf,
922922
inner: PyMutex::new(Some(BlobInner { blob, offset: 0 })),
923923
};
924-
Ok(blob.into_ref(vm))
924+
Ok(blob.into_ref(&vm.ctx))
925925
}
926926

927927
#[pymethod]
@@ -954,7 +954,7 @@ mod _sqlite {
954954
vm: &VirtualMachine,
955955
) -> PyResult<PyRef<Cursor>> {
956956
let row_factory = zelf.row_factory.to_owned();
957-
let cursor = Cursor::new(zelf, row_factory, vm).into_ref(vm);
957+
let cursor = Cursor::new(zelf, row_factory, vm).into_ref(&vm.ctx);
958958
Cursor::execute(cursor, sql, parameters, vm)
959959
}
960960

@@ -966,7 +966,7 @@ mod _sqlite {
966966
vm: &VirtualMachine,
967967
) -> PyResult<PyRef<Cursor>> {
968968
let row_factory = zelf.row_factory.to_owned();
969-
let cursor = Cursor::new(zelf, row_factory, vm).into_ref(vm);
969+
let cursor = Cursor::new(zelf, row_factory, vm).into_ref(&vm.ctx);
970970
Cursor::executemany(cursor, sql, seq_of_params, vm)
971971
}
972972

@@ -977,7 +977,11 @@ mod _sqlite {
977977
vm: &VirtualMachine,
978978
) -> PyResult<PyRef<Cursor>> {
979979
let row_factory = zelf.row_factory.to_owned();
980-
Cursor::executescript(Cursor::new(zelf, row_factory, vm).into_ref(vm), script, vm)
980+
Cursor::executescript(
981+
Cursor::new(zelf, row_factory, vm).into_ref(&vm.ctx),
982+
script,
983+
vm,
984+
)
981985
}
982986

983987
#[pymethod]
@@ -1403,7 +1407,7 @@ mod _sqlite {
14031407
drop(inner);
14041408
return Ok(zelf);
14051409
};
1406-
let stmt = stmt.into_ref(vm);
1410+
let stmt = stmt.into_ref(&vm.ctx);
14071411

14081412
inner.rowcount = if stmt.is_dml { 0 } else { -1 };
14091413

@@ -1472,7 +1476,7 @@ mod _sqlite {
14721476
drop(inner);
14731477
return Ok(zelf);
14741478
};
1475-
let stmt = stmt.into_ref(vm);
1479+
let stmt = stmt.into_ref(&vm.ctx);
14761480

14771481
let st = stmt.lock();
14781482

@@ -1724,15 +1728,15 @@ mod _sqlite {
17241728

17251729
let text_factory = zelf.connection.text_factory.to_owned();
17261730

1727-
if text_factory.is(PyStr::class(vm)) {
1731+
if text_factory.is(PyStr::class(&vm.ctx)) {
17281732
let text = String::from_utf8(text).map_err(|_| {
17291733
new_operational_error(vm, "not valid UTF-8".to_owned())
17301734
})?;
17311735
vm.ctx.new_str(text).into()
1732-
} else if text_factory.is(PyBytes::class(vm)) {
1736+
} else if text_factory.is(PyBytes::class(&vm.ctx)) {
17331737
vm.ctx.new_bytes(text).into()
1734-
} else if text_factory.is(PyByteArray::class(vm)) {
1735-
PyByteArray::from(text).into_ref(vm).into()
1738+
} else if text_factory.is(PyByteArray::class(&vm.ctx)) {
1739+
PyByteArray::from(text).into_ref(&vm.ctx).into()
17361740
} else {
17371741
let bytes = vm.ctx.new_bytes(text);
17381742
text_factory.call((bytes,), vm)?
@@ -2531,7 +2535,7 @@ mod _sqlite {
25312535
let obj = if need_adapt(parameter, vm) {
25322536
adapted = _adapt(
25332537
parameter,
2534-
PrepareProtocol::class(vm).to_owned(),
2538+
PrepareProtocol::class(&vm.ctx).to_owned(),
25352539
|x| Ok(x.to_owned()),
25362540
vm,
25372541
)?;

stdlib/src/ssl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ mod windows {
14581458
oids.into_iter().map(|oid| vm.ctx.new_str(oid).into()),
14591459
)
14601460
.unwrap()
1461-
.into_ref(vm)
1461+
.into_ref(&vm.ctx)
14621462
.into(),
14631463
};
14641464
Ok(vm.new_tuple((cert, enc_type, usage)).into())

stdlib/src/syslog.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ mod syslog {
3333
Some(value) => &argv[value..],
3434
None => argv,
3535
})
36-
.into_ref(vm),
36+
.into_ref(&vm.ctx),
3737
);
3838
}
3939
}

stdlib/src/unicodedata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
1313
let module = unicodedata::make_module(vm);
1414

1515
let ucd: PyObjectRef = unicodedata::Ucd::new(unic_ucd_age::UNICODE_VERSION)
16-
.into_ref(vm)
16+
.into_ref(&vm.ctx)
1717
.into();
1818

1919
for attr in [
@@ -208,7 +208,7 @@ mod unicodedata {
208208
micro: 0,
209209
},
210210
}
211-
.into_ref(vm)
211+
.into_ref(&vm.ctx)
212212
}
213213

214214
#[pyattr]

0 commit comments

Comments
 (0)