Skip to content

Commit c6dc3d2

Browse files
committed
x
1 parent 98d3090 commit c6dc3d2

File tree

3 files changed

+25
-36
lines changed

3 files changed

+25
-36
lines changed

crates/common/src/crt_fd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use alloc::fmt;
55
use core::cmp;
66
use std::{ffi, io};
77

8-
#[cfg(not(windows))]
9-
use std::os::fd::{AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
108
#[cfg(unix)]
119
use std::os::fd::AsFd;
10+
#[cfg(not(windows))]
11+
use std::os::fd::{AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
1212
#[cfg(windows)]
1313
use std::os::windows::io::BorrowedHandle;
1414

crates/vm/src/stdlib/os.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ pub(super) mod _os {
149149
use super::{DirFd, FollowSymlinks, SupportFunc};
150150
#[cfg(windows)]
151151
use crate::common::windows::ToWideString;
152+
#[cfg(any(unix, windows))]
153+
use crate::utils::ToCString;
152154
use crate::{
153155
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
154156
builtins::{
@@ -170,8 +172,6 @@ pub(super) mod _os {
170172
types::{IterNext, Iterable, PyStructSequence, Representable, SelfIter},
171173
vm::VirtualMachine,
172174
};
173-
#[cfg(any(unix, windows))]
174-
use crate::utils::ToCString;
175175
use core::time::Duration;
176176
use crossbeam_utils::atomic::AtomicCell;
177177
use itertools::Itertools;

crates/vm/src/vm/interpreter.rs

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ type InitFunc = Box<dyn FnOnce(&mut VirtualMachine)>;
1616
/// ```
1717
/// use rustpython_vm::Interpreter;
1818
///
19-
/// let interp = Interpreter::builder()
20-
/// .settings(Default::default())
21-
/// .add_modules(rustpython_stdlib::stdlib_module_defs())
22-
/// .build();
19+
/// let builder = Interpreter::builder(Default::default());
20+
/// // In practice, add stdlib: builder.add_native_modules(&stdlib_module_defs(&builder.ctx))
21+
/// let interp = builder.build();
2322
/// ```
2423
pub struct InterpreterBuilder {
2524
settings: Settings,
@@ -165,17 +164,13 @@ impl InterpreterBuilder {
165164
///
166165
/// # Example
167166
/// ```
168-
/// use rustpython_vm::Interpreter;
167+
/// use rustpython_vm::{Interpreter, builtins::PyModuleDef};
169168
///
170-
/// let interp = Interpreter::builder()
171-
/// .init_hook(|vm| {
172-
/// let def = mymodule::module_def(&vm.ctx);
173-
/// rustpython_vm::common::rc::PyRc::get_mut(&mut vm.state)
174-
/// .unwrap()
175-
/// .module_defs
176-
/// .insert(def.name.as_str(), def);
177-
/// })
178-
/// .build();
169+
/// let builder = Interpreter::builder(Default::default());
170+
/// // Note: In practice, use module_def from your #[pymodule]
171+
/// // let def = mymodule::module_def(&builder.ctx);
172+
/// // let interp = builder.add_native_module(def).build();
173+
/// let interp = builder.build();
179174
/// ```
180175
pub fn add_native_module(self, def: &'static builtins::PyModuleDef) -> Self {
181176
self.add_native_modules(&[def])
@@ -187,9 +182,11 @@ impl InterpreterBuilder {
187182
/// ```
188183
/// use rustpython_vm::Interpreter;
189184
///
190-
/// let builder = Interpreter::builder();
191-
/// let defs = rustpython_stdlib::stdlib_module_defs(&builder.ctx);
192-
/// let interp = builder.add_native_modules(&defs).build();
185+
/// let builder = Interpreter::builder(Default::default());
186+
/// // In practice, use module_defs from rustpython_stdlib:
187+
/// // let defs = rustpython_stdlib::stdlib_module_defs(&builder.ctx);
188+
/// // let interp = builder.add_native_modules(&defs).build();
189+
/// let interp = builder.build();
193190
/// ```
194191
pub fn add_native_modules(mut self, defs: &[&'static builtins::PyModuleDef]) -> Self {
195192
self.module_defs.extend_from_slice(defs);
@@ -206,7 +203,7 @@ impl InterpreterBuilder {
206203
/// ```
207204
/// use rustpython_vm::Interpreter;
208205
///
209-
/// let interp = Interpreter::builder()
206+
/// let interp = Interpreter::builder(Default::default())
210207
/// .init_hook(|vm| {
211208
/// // Custom initialization
212209
/// })
@@ -229,8 +226,8 @@ impl InterpreterBuilder {
229226
/// ```
230227
/// use rustpython_vm::Interpreter;
231228
///
232-
/// let interp = Interpreter::builder()
233-
/// .with_frozen(rustpython_pylib::FROZEN_STDLIB)
229+
/// let interp = Interpreter::builder(Default::default())
230+
/// // In practice: .with_frozen(rustpython_pylib::FROZEN_STDLIB)
234231
/// .build();
235232
/// ```
236233
pub fn with_frozen<I>(self, frozen: I) -> Self
@@ -298,9 +295,9 @@ impl Interpreter {
298295
/// ```
299296
/// use rustpython_vm::Interpreter;
300297
///
301-
/// let interp = Interpreter::builder(Default::default())
302-
/// .add_native_modules(rustpython_stdlib::stdlib_module_defs())
303-
/// .build();
298+
/// let builder = Interpreter::builder(Default::default());
299+
/// // In practice, add stdlib: builder.add_native_modules(&stdlib_module_defs(&builder.ctx))
300+
/// let interp = builder.build();
304301
/// ```
305302
pub fn builder(settings: Settings) -> InterpreterBuilder {
306303
InterpreterBuilder::new().settings(settings)
@@ -316,15 +313,7 @@ impl Interpreter {
316313

317314
/// Create with initialize function taking mutable vm reference.
318315
///
319-
/// Note: This is a legacy API. To add stdlib, use `Interpreter::builder()` instead:
320-
/// ```
321-
/// use rustpython_vm::Interpreter;
322-
/// let builder = Interpreter::builder(Default::default());
323-
/// let defs = rustpython_stdlib::stdlib_module_defs(&builder.ctx);
324-
/// builder.add_native_modules(&defs).build().enter(|vm| {
325-
/// vm.run_code_string(vm.new_scope_with_builtins(), "print(1)", "<...>".to_owned());
326-
/// });
327-
/// ```
316+
/// Note: This is a legacy API. To add stdlib, use `Interpreter::builder()` instead.
328317
pub fn with_init<F>(settings: Settings, init: F) -> Self
329318
where
330319
F: FnOnce(&mut VirtualMachine),

0 commit comments

Comments
 (0)