From 2952f6e7c6e7bafc5db1cc581ce5be03c2100eee Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Wed, 22 Sep 2021 02:28:19 +0900 Subject: [PATCH] extract wchar_t definition to rustpython-common --- Cargo.lock | 1 + common/Cargo.toml | 1 + common/src/str.rs | 7 +++++++ vm/src/stdlib/array.rs | 9 +-------- vm/src/stdlib/pystruct.rs | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c15eed1a5..1a4e6b37e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1793,6 +1793,7 @@ dependencies = [ "cfg-if 1.0.0", "hexf-parse", "lexical-core", + "libc", "lock_api", "num-bigint", "num-complex", diff --git a/common/Cargo.toml b/common/Cargo.toml index bacd386af..de991b8a0 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -21,3 +21,4 @@ siphasher = "0.3" rand = "0.8" volatile = "0.3" radium = "0.6" +libc = "0.2.101" diff --git a/common/src/str.rs b/common/src/str.rs index dcc3cba5a..15ed05475 100644 --- a/common/src/str.rs +++ b/common/src/str.rs @@ -1,5 +1,12 @@ use std::ops::{Bound, RangeBounds}; +#[cfg(not(target_arch = "wasm32"))] +#[allow(non_camel_case_types)] +pub type wchar_t = libc::wchar_t; +#[cfg(target_arch = "wasm32")] +#[allow(non_camel_case_types)] +pub type wchar_t = u32; + pub fn try_get_chars(s: &str, range: impl RangeBounds) -> Option<&str> { let mut chars = s.chars(); let start = match range.start_bound() { diff --git a/vm/src/stdlib/array.rs b/vm/src/stdlib/array.rs index ac0f9fd58..8dc19a827 100644 --- a/vm/src/stdlib/array.rs +++ b/vm/src/stdlib/array.rs @@ -1,12 +1,5 @@ pub(crate) use array::make_module; -#[cfg(not(target_arch = "wasm32"))] -#[allow(non_camel_case_types)] -pub type wchar_t = libc::wchar_t; -#[cfg(target_arch = "wasm32")] -#[allow(non_camel_case_types)] -pub type wchar_t = u32; - #[pymodule(name = "array")] mod array { use crate::buffer::{BufferOptions, PyBuffer, PyBufferInternal, ResizeGuard}; @@ -22,12 +15,12 @@ mod array { PyMappedRwLockReadGuard, PyMappedRwLockWriteGuard, PyRwLock, PyRwLockReadGuard, PyRwLockWriteGuard, }; + use crate::common::str::wchar_t; use crate::function::OptionalArg; use crate::sliceable::{ saturate_index, PySliceableSequence, PySliceableSequenceMut, SequenceIndex, }; use crate::slots::{AsBuffer, Comparable, Iterable, PyComparisonOp, PyIter, SlotConstructor}; - use crate::stdlib::array::wchar_t; use crate::{ IdProtocol, IntoPyObject, PyComparisonValue, PyIterable, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject, TypeProtocol, diff --git a/vm/src/stdlib/pystruct.rs b/vm/src/stdlib/pystruct.rs index b71f72162..d081bc2b7 100644 --- a/vm/src/stdlib/pystruct.rs +++ b/vm/src/stdlib/pystruct.rs @@ -24,10 +24,10 @@ pub(crate) mod _struct { pystr::PyStrRef, pytype::PyTypeRef, tuple::PyTupleRef, }; use crate::byteslike::{ArgBytesLike, ArgMemoryBuffer}; + use crate::common::str::wchar_t; use crate::exceptions::PyBaseExceptionRef; use crate::function::Args; use crate::slots::{PyIter, SlotConstructor}; - use crate::stdlib::array::wchar_t; use crate::utils::Either; use crate::VirtualMachine; use crate::{IntoPyObject, PyObjectRef, PyRef, PyResult, PyValue, StaticType, TryFromObject};