Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a7a8444

Browse files
committed
more intern_static_str adaption
1 parent 308a2d4 commit a7a8444

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

vm/src/builtins/module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl Initializer for PyModule {
121121
.flags
122122
.has_feature(crate::types::PyTypeFlags::HAS_DICT));
123123
zelf.init_module_dict(
124-
vm.ctx.intern_str(args.name.as_str()),
124+
vm.ctx.intern_str(args.name.str(vm)),
125125
args.doc.to_pyobject(vm),
126126
vm,
127127
);

vm/src/builtins/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ impl PyStr {
12691269
#[pyclass]
12701270
impl PyRef<PyStr> {
12711271
#[pymethod(magic)]
1272-
fn str(self, vm: &VirtualMachine) -> PyRefExact<PyStr> {
1272+
pub fn str(self, vm: &VirtualMachine) -> PyRefExact<PyStr> {
12731273
self.into_exact_or(&vm.ctx, |zelf| unsafe {
12741274
// Creating a copy with same kind is safe
12751275
PyStr::new_str_unchecked(zelf.bytes.to_vec(), zelf.kind.kind()).into_exact_ref(&vm.ctx)

vm/src/builtins/tuple.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ impl Representable for PyTuple {
401401
#[inline]
402402
fn repr(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyStrRef> {
403403
let s = if zelf.len() == 0 {
404-
vm.ctx.intern_str("()").to_owned()
404+
vm.ctx.intern_static_str("()").to_owned()
405405
} else if let Some(_guard) = ReprGuard::enter(vm, zelf.as_object()) {
406406
let s = if zelf.len() == 1 {
407407
format!("({},)", zelf.elements[0].repr(vm)?)
@@ -410,7 +410,7 @@ impl Representable for PyTuple {
410410
};
411411
vm.ctx.new_str(s)
412412
} else {
413-
vm.ctx.intern_str("(...)").to_owned()
413+
vm.ctx.intern_static_str("(...)").to_owned()
414414
};
415415
Ok(s)
416416
}

vm/src/stdlib/builtins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ mod builtins {
351351
fn breakpoint(args: FuncArgs, vm: &VirtualMachine) -> PyResult {
352352
match vm
353353
.sys_module
354-
.get_attr(vm.ctx.intern_str("breakpointhook"), vm)
354+
.get_attr(vm.ctx.intern_static_str("breakpointhook"), vm)
355355
{
356356
Ok(hook) => hook.as_ref().call(args, vm),
357357
Err(_) => Err(vm.new_runtime_error("lost sys.breakpointhook".to_owned())),

vm/src/stdlib/errno.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
1111
"errorcode" => errorcode.clone(),
1212
});
1313
for (name, code) in ERROR_CODES {
14-
let name = vm.ctx.intern_str(*name);
14+
let name = vm.ctx.intern_static_str(*name);
1515
let code = vm.new_pyobj(*code);
1616
errorcode
1717
.set_item(&*code, name.to_owned().into(), vm)

vm/src/stdlib/sys.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ mod sys {
135135
fn byteorder(vm: &VirtualMachine) -> PyStrRef {
136136
// https://doc.rust-lang.org/reference/conditional-compilation.html#target_endian
137137
vm.ctx
138-
.intern_str(if cfg!(target_endian = "little") {
138+
.intern_static_str(if cfg!(target_endian = "little") {
139139
"little"
140140
} else if cfg!(target_endian = "big") {
141141
"big"

vm/src/vm/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ impl VirtualMachine {
194194
PyRc::get_mut(&mut vm.state).unwrap().frozen = frozen;
195195

196196
vm.builtins
197-
.init_module_dict(vm.ctx.intern_str("builtins"), vm.ctx.none(), &vm);
197+
.init_module_dict(vm.ctx.intern_static_str("builtins"), vm.ctx.none(), &vm);
198198
vm.sys_module
199-
.init_module_dict(vm.ctx.intern_str("sys"), vm.ctx.none(), &vm);
199+
.init_module_dict(vm.ctx.intern_static_str("sys"), vm.ctx.none(), &vm);
200200

201201
vm
202202
}
@@ -263,14 +263,14 @@ impl VirtualMachine {
263263
// builtins.open to io.OpenWrapper, but this is easier, since it doesn't
264264
// require the Python stdlib to be present
265265
let io = import::import_builtin(self, "_io")?;
266-
let set_stdio = |name, fd, mode: &str| {
266+
let set_stdio = |name, dunder_name, fd, mode: &str| {
267267
let stdio = crate::stdlib::io::open(
268268
self.ctx.new_int(fd).into(),
269269
Some(mode),
270270
Default::default(),
271271
self,
272272
)?;
273-
let dunder_name = self.ctx.intern_str(format!("__{name}__"));
273+
let dunder_name = self.ctx.intern_static_str(dunder_name);
274274
self.sys_module.set_attr(
275275
dunder_name, // e.g. __stdin__
276276
stdio.clone(),
@@ -279,9 +279,9 @@ impl VirtualMachine {
279279
self.sys_module.set_attr(name, stdio, self)?;
280280
Ok(())
281281
};
282-
set_stdio("stdin", 0, "r")?;
283-
set_stdio("stdout", 1, "w")?;
284-
set_stdio("stderr", 2, "w")?;
282+
set_stdio("stdin", "__stdin__", 0, "r")?;
283+
set_stdio("stdout", "__stdout__", 1, "w")?;
284+
set_stdio("stderr", "__stderr__", 2, "w")?;
285285

286286
let io_open = io.get_attr("open", self)?;
287287
self.builtins.set_attr("open", io_open, self)?;

0 commit comments

Comments
 (0)