Skip to content

Commit 48dc5c9

Browse files
committed
PyStrKind
1 parent c064118 commit 48dc5c9

Some content is hidden

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

46 files changed

+536
-421
lines changed

benches/microbenchmarks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ fn bench_rustpy_code(group: &mut BenchmarkGroup<WallTime>, bench: &MicroBenchmar
132132
if let Some(idx) = iterations {
133133
scope
134134
.locals
135-
.set_item(vm.ctx.new_str("ITERATIONS"), vm.ctx.new_int(idx), vm)
135+
.set_item(vm.ctx.new_ascii_str(b"ITERATIONS"), vm.ctx.new_int(idx), vm)
136136
.expect("Error adding ITERATIONS local variable");
137137
}
138138
let setup_result = vm.run_code_obj(setup_code.clone(), scope.clone());

derive/src/pymodule.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl ModuleItem for FunctionItem {
268268
vm.ctx.make_funcdef(#py_name, #ident)
269269
#doc
270270
.into_function()
271-
.with_module(vm.ctx.new_str(#module.to_owned()))
271+
.with_module(vm.ctx.new_utf8_str(#module.to_owned()))
272272
.build(&vm.ctx)
273273
);
274274
quote! {
@@ -324,7 +324,7 @@ impl ModuleItem for ClassItem {
324324
);
325325
let item = quote! {
326326
let new_class = #new_class;
327-
new_class.set_str_attr("__module__", vm.ctx.new_str(#module_name));
327+
new_class.set_str_attr("__module__", vm.ctx.new_utf8_str(#module_name));
328328
vm.__module_set_attr(&module, #py_name, new_class).unwrap();
329329
};
330330

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ fn _run_string(vm: &VirtualMachine, scope: Scope, source: &str, source_path: Str
588588
// trace!("Code object: {:?}", code_obj.borrow());
589589
scope
590590
.globals
591-
.set_item("__file__", vm.ctx.new_str(source_path), vm)?;
591+
.set_item("__file__", vm.ctx.new_utf8_str(source_path), vm)?;
592592
vm.run_code_obj(code_obj, scope)
593593
}
594594

vm/src/builtins/code.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl ConstantBag for PyObjBag<'_> {
8888
bytecode::ConstantData::Str { value } if value.len() <= 20 => {
8989
vm.intern_string(value).into_object()
9090
}
91-
bytecode::ConstantData::Str { value } => vm.ctx.new_str(value),
91+
bytecode::ConstantData::Str { value } => vm.ctx.new_utf8_str(value),
9292
bytecode::ConstantData::Bytes { value } => ctx.new_bytes(value.to_vec()),
9393
bytecode::ConstantData::Boolean { value } => ctx.new_bool(value),
9494
bytecode::ConstantData::Code { code } => {
@@ -116,7 +116,7 @@ impl ConstantBag for PyObjBag<'_> {
116116
bytecode::BorrowedConstant::Str { value } if value.len() <= 20 => {
117117
vm.intern_string(value).into_object()
118118
}
119-
bytecode::BorrowedConstant::Str { value } => vm.ctx.new_str(value),
119+
bytecode::BorrowedConstant::Str { value } => vm.ctx.new_utf8_str(value),
120120
bytecode::BorrowedConstant::Bytes { value } => ctx.new_bytes(value.to_vec()),
121121
bytecode::BorrowedConstant::Boolean { value } => ctx.new_bool(value),
122122
bytecode::BorrowedConstant::Code { code } => {

vm/src/builtins/dict.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl PyDict {
113113
}
114114

115115
for (key, value) in kwargs.into_iter() {
116-
dict.insert(vm, vm.ctx.new_str(key), value)?;
116+
dict.insert(vm, vm.ctx.new_utf8_str(key), value)?;
117117
}
118118
Ok(())
119119
}
@@ -364,7 +364,7 @@ impl PyDict {
364364
if let Some((key, value)) = self.entries.pop_back() {
365365
Ok(vm.ctx.new_tuple(vec![key, value]))
366366
} else {
367-
let err_msg = vm.ctx.new_str("popitem(): dictionary is empty");
367+
let err_msg = vm.ctx.new_ascii_str(b"popitem(): dictionary is empty");
368368
Err(vm.new_key_error(err_msg))
369369
}
370370
}
@@ -373,7 +373,7 @@ impl PyDict {
373373
let dict = DictContentType::default();
374374

375375
for (key, value) in attrs {
376-
dict.insert(vm, vm.ctx.new_str(key), value)?;
376+
dict.insert(vm, vm.ctx.new_utf8_str(key), value)?;
377377
}
378378

379379
Ok(PyDict { entries: dict })

vm/src/builtins/function.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ impl PyBoundMethod {
545545
// is the only instance of `builtin_function_or_method_type`.
546546
let obj_name = vm.get_attribute_opt(self.object.clone(), "__qualname__")?;
547547
let obj_name: Option<PyStrRef> = obj_name.and_then(|o| o.downcast().ok());
548-
return Ok(vm.ctx.new_str(format!(
548+
return Ok(vm.ctx.new_utf8_str(format!(
549549
"{}.__new__",
550550
obj_name.as_ref().map_or("?", |s| s.as_str())
551551
)));

vm/src/builtins/make_module.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ mod decl {
382382
let prompt = prompt.as_ref().map_or("", |s| s.as_str());
383383
let mut readline = Readline::new(());
384384
match readline.readline(prompt) {
385-
ReadlineResult::Line(s) => Ok(vm.ctx.new_str(s)),
385+
ReadlineResult::Line(s) => Ok(vm.ctx.new_utf8_str(s)),
386386
ReadlineResult::Eof => {
387387
Err(vm.new_exception_empty(vm.ctx.exceptions.eof_error.clone()))
388388
}
@@ -535,7 +535,7 @@ mod decl {
535535
format!("0o{:o}", n)
536536
};
537537

538-
Ok(vm.ctx.new_str(s))
538+
Ok(vm.ctx.new_utf8_str(s))
539539
}
540540

541541
#[pyfunction]
@@ -812,7 +812,7 @@ mod decl {
812812
vm: &VirtualMachine,
813813
) -> PyResult {
814814
let name = qualified_name.as_str().split('.').next_back().unwrap();
815-
let name_obj = vm.ctx.new_str(name);
815+
let name_obj = vm.ctx.new_utf8_str(name);
816816

817817
let mut metaclass = if let Some(metaclass) = kwargs.pop_kwarg("metaclass") {
818818
PyTypeRef::try_from_object(vm, metaclass)?

0 commit comments

Comments
 (0)