Skip to content

Commit 40095e5

Browse files
committed
Use full paths for thread-only types in pyexpat
Assisted-by: Grok:4.6
1 parent 90d1611 commit 40095e5

1 file changed

Lines changed: 22 additions & 30 deletions

File tree

‎crates/stdlib/src/pyexpat.rs‎

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,10 @@ mod _pyexpat {
175175
};
176176
use alloc::collections::VecDeque;
177177
use alloc::rc::Rc;
178-
#[cfg(not(target_arch = "wasm32"))]
179-
use alloc::sync::Arc;
180178
use core::cell::RefCell;
181-
#[cfg(not(target_arch = "wasm32"))]
182-
use core::mem::ManuallyDrop;
183179
use core::sync::atomic::{AtomicBool, Ordering};
184180
use rustpython_common::lock::PyRwLock;
185-
#[cfg(not(target_arch = "wasm32"))]
186-
use std::io::BufReader;
187181
use std::io::Read;
188-
#[cfg(not(target_arch = "wasm32"))]
189-
use std::sync::mpsc::{self, Receiver, Sender};
190-
#[cfg(not(target_arch = "wasm32"))]
191-
use std::sync::{Condvar, Mutex};
192-
#[cfg(not(target_arch = "wasm32"))]
193-
use std::thread::JoinHandle;
194182
use xml::common::Position;
195183
use xml::reader::XmlEvent;
196184

@@ -459,21 +447,21 @@ mod _pyexpat {
459447

460448
#[cfg(not(target_arch = "wasm32"))]
461449
struct FeedBuffer {
462-
inner: Mutex<FeedInner>,
463-
cv: Condvar,
450+
inner: std::sync::Mutex<FeedInner>,
451+
cv: std::sync::Condvar,
464452
}
465453

466454
#[cfg(not(target_arch = "wasm32"))]
467455
impl FeedBuffer {
468456
fn new() -> Self {
469457
Self {
470-
inner: Mutex::new(FeedInner {
458+
inner: std::sync::Mutex::new(FeedInner {
471459
data: VecDeque::new(),
472460
closed: false,
473461
stopped: false,
474462
pushes: 0,
475463
}),
476-
cv: Condvar::new(),
464+
cv: std::sync::Condvar::new(),
477465
}
478466
}
479467

@@ -503,9 +491,9 @@ mod _pyexpat {
503491
/// nor stopped. Runs entirely on the parser thread.
504492
#[cfg(not(target_arch = "wasm32"))]
505493
struct FeedReader {
506-
buf: Arc<FeedBuffer>,
494+
buf: alloc::sync::Arc<FeedBuffer>,
507495
tracker: Rc<RefCell<LineTracker>>,
508-
events_tx: Sender<ParserMsg>,
496+
events_tx: std::sync::mpsc::Sender<ParserMsg>,
509497
}
510498

511499
#[cfg(not(target_arch = "wasm32"))]
@@ -616,9 +604,9 @@ mod _pyexpat {
616604
// mutex/condvar/channel that may look held by a thread that no
617605
// longer exists) when this stream predates a fork. See the module
618606
// doc comment.
619-
buf: ManuallyDrop<Arc<FeedBuffer>>,
620-
rx: ManuallyDrop<Mutex<Receiver<ParserMsg>>>,
621-
thread: Option<JoinHandle<()>>,
607+
buf: core::mem::ManuallyDrop<alloc::sync::Arc<FeedBuffer>>,
608+
rx: core::mem::ManuallyDrop<std::sync::Mutex<std::sync::mpsc::Receiver<ParserMsg>>>,
609+
thread: Option<std::thread::JoinHandle<()>>,
622610
}
623611

624612
#[cfg(not(target_arch = "wasm32"))]
@@ -644,16 +632,16 @@ mod _pyexpat {
644632
if post_fork_child() {
645633
return None;
646634
}
647-
let buf = Arc::new(FeedBuffer::new());
648-
let (tx, rx) = mpsc::channel();
649-
let thread_buf = Arc::clone(&buf);
635+
let buf = alloc::sync::Arc::new(FeedBuffer::new());
636+
let (tx, rx) = std::sync::mpsc::channel();
637+
let thread_buf = alloc::sync::Arc::clone(&buf);
650638
let thread = std::thread::Builder::new()
651639
.name("pyexpat-parser".into())
652640
.spawn(move || run_parser_thread(config, thread_buf, tx))
653641
.ok()?;
654642
Some(Self {
655-
buf: ManuallyDrop::new(buf),
656-
rx: ManuallyDrop::new(Mutex::new(rx)),
643+
buf: core::mem::ManuallyDrop::new(buf),
644+
rx: core::mem::ManuallyDrop::new(std::sync::Mutex::new(rx)),
657645
thread: Some(thread),
658646
})
659647
}
@@ -690,8 +678,8 @@ mod _pyexpat {
690678
// Safety: not reached on the post-fork leak path above, and
691679
// `drop` runs at most once, so these are never touched again.
692680
unsafe {
693-
ManuallyDrop::drop(&mut self.rx);
694-
ManuallyDrop::drop(&mut self.buf);
681+
core::mem::ManuallyDrop::drop(&mut self.rx);
682+
core::mem::ManuallyDrop::drop(&mut self.buf);
695683
}
696684
}
697685
}
@@ -703,14 +691,18 @@ mod _pyexpat {
703691
/// thread from the messages sent here, exactly as the module doc
704692
/// comment requires.
705693
#[cfg(not(target_arch = "wasm32"))]
706-
fn run_parser_thread(config: xml::ParserConfig, buf: Arc<FeedBuffer>, tx: Sender<ParserMsg>) {
694+
fn run_parser_thread(
695+
config: xml::ParserConfig,
696+
buf: alloc::sync::Arc<FeedBuffer>,
697+
tx: std::sync::mpsc::Sender<ParserMsg>,
698+
) {
707699
let tracker = Rc::new(RefCell::new(LineTracker::new()));
708700
let reader = FeedReader {
709701
buf,
710702
tracker: Rc::clone(&tracker),
711703
events_tx: tx.clone(),
712704
};
713-
let mut parser = config.create_reader(BufReader::new(reader));
705+
let mut parser = config.create_reader(std::io::BufReader::new(reader));
714706
loop {
715707
match parser.next() {
716708
Ok(XmlEvent::EndDocument) => {

0 commit comments

Comments
 (0)