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

Skip to content

Commit feb751d

Browse files
committed
more intern_static_str adaption
1 parent 97cef36 commit feb751d

File tree

8 files changed

+16
-16
lines changed

8 files changed

+16
-16
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
@@ -1278,7 +1278,7 @@ impl PyStr {
12781278
#[pyclass]
12791279
impl PyRef<PyStr> {
12801280
#[pymethod(magic)]
1281-
fn str(self, vm: &VirtualMachine) -> PyRefExact<PyStr> {
1281+
pub fn str(self, vm: &VirtualMachine) -> PyRefExact<PyStr> {
12821282
self.into_exact_or(&vm.ctx, |zelf| unsafe {
12831283
// Creating a copy with same kind is safe
12841284
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/builtins/type.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,11 @@ impl PyType {
297297
// This is used for class initialisation where the vm is not yet available.
298298
pub fn set_str_attr<V: Into<PyObjectRef>>(
299299
&self,
300-
attr_name: &str,
300+
attr_name: &'static str,
301301
value: V,
302302
ctx: impl AsRef<Context>,
303303
) {
304-
let attr_name = ctx.as_ref().intern_str(attr_name);
304+
let attr_name = ctx.as_ref().intern_static_str(attr_name);
305305
self.set_attr(attr_name, value.into())
306306
}
307307

vm/src/stdlib/builtins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ mod builtins {
370370
fn breakpoint(args: FuncArgs, vm: &VirtualMachine) -> PyResult {
371371
match vm
372372
.sys_module
373-
.get_attr(vm.ctx.intern_str("breakpointhook"), vm)
373+
.get_attr(vm.ctx.intern_static_str("breakpointhook"), vm)
374374
{
375375
Ok(hook) => hook.as_ref().call(args, vm),
376376
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)