Skip to content

Commit be9aaf7

Browse files
committed
Move _struct module to stdlib
1 parent c64b044 commit be9aaf7

5 files changed

Lines changed: 13 additions & 10 deletions

File tree

stdlib/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ mod json;
1717
mod math;
1818
mod platform;
1919
mod pyexpat;
20+
mod pystruct;
2021
mod random;
2122
// TODO: maybe make this an extension module, if we ever get those
2223
// mod re;
@@ -87,6 +88,7 @@ pub fn get_module_inits() -> impl Iterator<Item = (Cow<'static, str>, StdlibInit
8788
"_platform" => platform::make_module,
8889
"_random" => random::make_module,
8990
"_statistics" => statistics::make_module,
91+
"_struct" => pystruct::make_module,
9092
"unicodedata" => unicodedata::make_module,
9193
"zlib" => zlib::make_module,
9294
// crate::vm::sysmodule::sysconfigdata_name() => sysconfigdata::make_module,
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
//! https://docs.rs/byteorder/1.2.6/byteorder/
77
88
pub(crate) use _struct::make_module;
9+
910
#[pymodule]
1011
pub(crate) mod _struct {
11-
use crate::{
12+
use crate::vm::{
1213
buffer::{new_struct_error, struct_error_type, FormatSpec},
1314
builtins::{PyBytes, PyStr, PyStrRef, PyTupleRef, PyTypeRef},
1415
function::{ArgBytesLike, ArgMemoryBuffer, PosArgs},
16+
match_class,
1517
protocol::PyIterReturn,
1618
types::{Constructor, IterNext, IterNextIterable},
17-
PyObjectRef, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
19+
PyObjectRef, PyObjectView, PyResult, PyValue, TryFromObject, TypeProtocol, VirtualMachine,
1820
};
1921
use crossbeam_utils::atomic::AtomicCell;
2022

@@ -204,7 +206,7 @@ pub(crate) mod _struct {
204206
}
205207
impl IterNextIterable for UnpackIterator {}
206208
impl IterNext for UnpackIterator {
207-
fn next(zelf: &crate::PyObjectView<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
209+
fn next(zelf: &PyObjectView<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
208210
let size = zelf.format_spec.size;
209211
let offset = zelf.offset.fetch_add(size);
210212
zelf.buffer.with_ref(|buf| {

vm/src/buffer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ pub struct FormatSpec {
309309
#[allow(dead_code)]
310310
pub(crate) endianness: Endianness,
311311
pub(crate) codes: Vec<FormatCode>,
312-
pub(crate) size: usize,
313-
pub(crate) arg_count: usize,
312+
pub size: usize,
313+
pub arg_count: usize,
314314
}
315315

316316
impl FormatSpec {

vm/src/builtins/pystr.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl Constructor for PyStr {
322322
}
323323

324324
impl PyStr {
325-
/// SAFETY: Given 'bytes' must be valid data for given 'kind'
325+
/// # Safety: Given `bytes` must be valid data for given `kind`
326326
pub(crate) unsafe fn new_str_unchecked(bytes: Vec<u8>, kind: PyStrKind) -> Self {
327327
let s = Self {
328328
bytes: bytes.into_boxed_slice(),
@@ -333,8 +333,9 @@ impl PyStr {
333333
s
334334
}
335335

336-
/// SAFETY: Given 'bytes' must be ascii
337-
pub(crate) unsafe fn new_ascii_unchecked(bytes: Vec<u8>) -> Self {
336+
/// # Safety
337+
/// Given `bytes` must be ascii
338+
pub unsafe fn new_ascii_unchecked(bytes: Vec<u8>) -> Self {
338339
Self::new_str_unchecked(bytes, PyStrKind::Ascii)
339340
}
340341

vm/src/stdlib/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub mod io;
1111
mod itertools;
1212
mod marshal;
1313
mod operator;
14-
pub(crate) mod pystruct;
1514
// TODO: maybe make this an extension module, if we ever get those
1615
// mod re;
1716
mod sre;
@@ -85,7 +84,6 @@ pub fn get_module_inits() -> StdlibMap {
8584
"_operator" => operator::make_module,
8685
"_sre" => sre::make_module,
8786
"_string" => string::make_module,
88-
"_struct" => pystruct::make_module,
8987
"time" => time::make_module,
9088
"_weakref" => weakref::make_module,
9189
"_imp" => imp::make_module,

0 commit comments

Comments
 (0)