Skip to content

Commit 2952f6e

Browse files
committed
extract wchar_t definition to rustpython-common
1 parent 3a0c2bb commit 2952f6e

5 files changed

Lines changed: 11 additions & 9 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ siphasher = "0.3"
2121
rand = "0.8"
2222
volatile = "0.3"
2323
radium = "0.6"
24+
libc = "0.2.101"

common/src/str.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
use std::ops::{Bound, RangeBounds};
22

3+
#[cfg(not(target_arch = "wasm32"))]
4+
#[allow(non_camel_case_types)]
5+
pub type wchar_t = libc::wchar_t;
6+
#[cfg(target_arch = "wasm32")]
7+
#[allow(non_camel_case_types)]
8+
pub type wchar_t = u32;
9+
310
pub fn try_get_chars(s: &str, range: impl RangeBounds<usize>) -> Option<&str> {
411
let mut chars = s.chars();
512
let start = match range.start_bound() {

vm/src/stdlib/array.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
pub(crate) use array::make_module;
22

3-
#[cfg(not(target_arch = "wasm32"))]
4-
#[allow(non_camel_case_types)]
5-
pub type wchar_t = libc::wchar_t;
6-
#[cfg(target_arch = "wasm32")]
7-
#[allow(non_camel_case_types)]
8-
pub type wchar_t = u32;
9-
103
#[pymodule(name = "array")]
114
mod array {
125
use crate::buffer::{BufferOptions, PyBuffer, PyBufferInternal, ResizeGuard};
@@ -22,12 +15,12 @@ mod array {
2215
PyMappedRwLockReadGuard, PyMappedRwLockWriteGuard, PyRwLock, PyRwLockReadGuard,
2316
PyRwLockWriteGuard,
2417
};
18+
use crate::common::str::wchar_t;
2519
use crate::function::OptionalArg;
2620
use crate::sliceable::{
2721
saturate_index, PySliceableSequence, PySliceableSequenceMut, SequenceIndex,
2822
};
2923
use crate::slots::{AsBuffer, Comparable, Iterable, PyComparisonOp, PyIter, SlotConstructor};
30-
use crate::stdlib::array::wchar_t;
3124
use crate::{
3225
IdProtocol, IntoPyObject, PyComparisonValue, PyIterable, PyObjectRef, PyRef, PyResult,
3326
PyValue, StaticType, TryFromObject, TypeProtocol,

vm/src/stdlib/pystruct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ pub(crate) mod _struct {
2424
pystr::PyStrRef, pytype::PyTypeRef, tuple::PyTupleRef,
2525
};
2626
use crate::byteslike::{ArgBytesLike, ArgMemoryBuffer};
27+
use crate::common::str::wchar_t;
2728
use crate::exceptions::PyBaseExceptionRef;
2829
use crate::function::Args;
2930
use crate::slots::{PyIter, SlotConstructor};
30-
use crate::stdlib::array::wchar_t;
3131
use crate::utils::Either;
3232
use crate::VirtualMachine;
3333
use crate::{IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject};

0 commit comments

Comments
 (0)