Skip to content

Commit 026f396

Browse files
committed
Use std::os::raw::c_* instead of libc::c_* for wasm compat
1 parent 59169aa commit 026f396

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

vm/src/stdlib/array.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::VirtualMachine;
2121
use crossbeam_utils::atomic::AtomicCell;
2222
use itertools::Itertools;
2323
use std::cmp::Ordering;
24-
use std::fmt;
24+
use std::{fmt, os::raw};
2525

2626
struct ArrayTypeSpecifierError {
2727
_priv: (),
@@ -397,14 +397,14 @@ def_array_enum!(
397397
(SignedByte, i8, 'b'),
398398
(UnsignedByte, u8, 'B'),
399399
// TODO: support unicode char
400-
(SignedShort, libc::c_short, 'h'),
401-
(UnsignedShort, libc::c_ushort, 'H'),
402-
(SignedInt, libc::c_int, 'i'),
403-
(UnsignedInt, libc::c_uint, 'I'),
404-
(SignedLong, libc::c_long, 'l'),
405-
(UnsignedLong, libc::c_ulong, 'L'),
406-
(SignedLongLong, libc::c_longlong, 'q'),
407-
(UnsignedLongLong, libc::c_ulonglong, 'Q'),
400+
(SignedShort, raw::c_short, 'h'),
401+
(UnsignedShort, raw::c_ushort, 'H'),
402+
(SignedInt, raw::c_int, 'i'),
403+
(UnsignedInt, raw::c_uint, 'I'),
404+
(SignedLong, raw::c_long, 'l'),
405+
(UnsignedLong, raw::c_ulong, 'L'),
406+
(SignedLongLong, raw::c_longlong, 'q'),
407+
(UnsignedLongLong, raw::c_ulonglong, 'Q'),
408408
(Float, f32, 'f'),
409409
(Double, f64, 'd'),
410410
);

vm/src/stdlib/pystruct.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(crate) mod _struct {
2222
use std::convert::TryFrom;
2323
use std::io::{Cursor, Read, Write};
2424
use std::iter::Peekable;
25-
use std::{fmt, mem};
25+
use std::{fmt, mem, os::raw};
2626

2727
use crate::builtins::{
2828
bytes::PyBytesRef, float::IntoPyFloat, int::try_to_primitive, pybool::IntoPyBool,
@@ -83,11 +83,14 @@ pub(crate) mod _struct {
8383
}
8484
}
8585

86+
type PackFunc = fn(&VirtualMachine, &PyObjectRef, &mut dyn Write) -> PyResult<()>;
87+
type UnpackFunc = fn(&VirtualMachine, &mut dyn Read) -> PyResult;
88+
8689
struct FormatInfo {
8790
size: usize,
8891
align: usize,
89-
pack: Option<fn(&VirtualMachine, &PyObjectRef, &mut dyn Write) -> PyResult<()>>,
90-
unpack: Option<fn(&VirtualMachine, &mut dyn Read) -> PyResult>,
92+
pack: Option<PackFunc>,
93+
unpack: Option<UnpackFunc>,
9194
}
9295
impl fmt::Debug for FormatInfo {
9396
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -155,33 +158,33 @@ pub(crate) mod _struct {
155158
match e {
156159
Endianness::Native => match self {
157160
Pad | Str | Pascal => &FormatInfo {
158-
size: size_of::<libc::c_char>(),
161+
size: size_of::<raw::c_char>(),
159162
align: 0,
160163
pack: None,
161164
unpack: None,
162165
},
163-
SByte => native_info!(libc::c_schar),
164-
UByte => native_info!(libc::c_uchar),
166+
SByte => native_info!(raw::c_schar),
167+
UByte => native_info!(raw::c_uchar),
165168
Char => &FormatInfo {
166-
size: size_of::<libc::c_char>(),
169+
size: size_of::<raw::c_char>(),
167170
align: 0,
168171
pack: Some(pack_char),
169172
unpack: Some(unpack_char),
170173
},
171-
Short => native_info!(libc::c_short),
172-
UShort => native_info!(libc::c_ushort),
173-
Int => native_info!(libc::c_int),
174-
UInt => native_info!(libc::c_uint),
175-
Long => native_info!(libc::c_long),
176-
ULong => native_info!(libc::c_ulong),
177-
SSizeT => native_info!(libc::ssize_t),
178-
SizeT => native_info!(libc::size_t),
179-
LongLong => native_info!(libc::c_longlong),
180-
ULongLong => native_info!(libc::c_ulonglong),
174+
Short => native_info!(raw::c_short),
175+
UShort => native_info!(raw::c_ushort),
176+
Int => native_info!(raw::c_int),
177+
UInt => native_info!(raw::c_uint),
178+
Long => native_info!(raw::c_long),
179+
ULong => native_info!(raw::c_ulong),
180+
SSizeT => native_info!(isize), // ssize_t == isize
181+
SizeT => native_info!(usize), // size_t == usize
182+
LongLong => native_info!(raw::c_longlong),
183+
ULongLong => native_info!(raw::c_ulonglong),
181184
Bool => native_info!(bool),
182-
Float => native_info!(libc::c_float),
183-
Double => native_info!(libc::c_double),
184-
VoidP => native_info!(*mut libc::c_void),
185+
Float => native_info!(raw::c_float),
186+
Double => native_info!(raw::c_double),
187+
VoidP => native_info!(*mut raw::c_void),
185188
},
186189
Endianness::Big => match_nonnative!(self, byteorder::BigEndian),
187190
Endianness::Little => match_nonnative!(self, byteorder::LittleEndian),
@@ -564,7 +567,7 @@ pub(crate) mod _struct {
564567
make_pack_with_endianess!(f32, get_float);
565568
make_pack_with_endianess!(f64, get_float);
566569

567-
impl Packable for *mut libc::c_void {
570+
impl Packable for *mut raw::c_void {
568571
fn pack<Endianness: ByteOrder>(
569572
vm: &VirtualMachine,
570573
arg: &PyObjectRef,

0 commit comments

Comments
 (0)