8000 fix platform related issues · RustPython/RustPython@06dbae4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 06dbae4

Browse files
committed
fix platform related issues
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
1 parent d0044ae commit 06dbae4

File tree

4 files changed

+85
-61
lines changed

4 files changed

+85
-61
lines changed

extra_tests/snippets/builtins_ctypes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ class c_bool(_SimpleCData):
155155
if _os.name == "nt":
156156
from _ctypes import LoadLibrary as _dlopen
157157
from _ctypes import FUNCFLAG_STDCALL as _FUNCFLAG_STDCALL
158+
elif _os.name == "posix":
159+
from _ctypes import dlopen as _dlopen
158160

159161
class CDLL(object):
160162
"""An instance of this class represents a loaded dll/shared
@@ -258,7 +260,7 @@ def LoadLibrary(self, name):
258260

259261
cdll = LibraryLoader(CDLL)
260262

261-
if _os.name == "posix" and _sys.platform == "darwin":
263+
if _os.name == "posix" or _sys.platform == "darwin":
262264
pass
263265
else:
264266
libc = cdll.msvcrt

vm/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ uname = "0.1.1"
100100
rustyline = { workspace = true }
101101
which = "6"
102102
errno = "0.3"
103+
widestring = { workspace = true }
104+
105+
[target.'cfg(all(any(target_os = "linux", target_os = "macos", target_os = "windows"), not(any(target_env = "musl", target_env = "sgx"))))'.dependencies]
103106
libffi = "3.2"
104107
libloading = "0.8"
105-
widestring = { workspace = true }
106108

107109
[target.'cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))'.dependencies]
108110
num_cpus = "1.13.1"

vm/src/stdlib/ctypes.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,21 @@ pub(crate) mod _ctypes {
180180
}
181181

182182
#[pyfunction(name = "LoadLibrary")]
183-
fn load_library(
183+
fn load_library_windows(
184+
name: String,
185+
_load_flags: OptionalArg<i32>,
186+
vm: &VirtualMachine,
187+
) -> PyResult<usize> {
188+
// TODO: audit functions first
189+
// TODO: load_flags
190+
let cache = library::libcache();
191+
let mut cache_write = cache.write();
192+
let (id, _) = cache_write.get_or_insert_lib(&name, vm).unwrap();
193+
Ok(id)
194+
}
195+
196+
#[pyfunction(name = "dlopen")]
197+
fn load_library_unix(
184198
name: String,
185199
_load_flags: OptionalArg<i32>,
186200
vm: &VirtualMachine,

vm/src/stdlib/mod.rs

Lines changed: 64 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ pub mod posix;
3737
#[path = "posix_compat.rs"]
3838
pub mod posix;
3939

40-
#[cfg(any(target_family = "unix", target_family = "windows"))]
40+
#[cfg(all(
41+
any(target_os = "linux", target_os = "macos", target_os = "windows"),
42+
not(any(target_env = "musl", target_env = "sgx"))
43+
))]
4144
mod ctypes;
4245
#[cfg(windows)]
4346
pub(crate) mod msvcrt;
@@ -73,62 +76,65 @@ pub fn get_module_inits() -> StdlibMap {
7376
}};
7477
}
7578
modules! {
76-
#[cfg(all())]
77-
{
78-
"atexit" => atexit::make_module,
79-
"_codecs" => codecs::make_module,
80-
"_collections" => collections::make_module,
81-
"errno" => errno::make_module,
82-
"_functools" => functools::make_module,
83-
"itertools" => itertools::make_module,
84-
"_io" => io::make_module,
85-
"marshal" => marshal::make_module,
86-
"_operator" => operator::make_module,
87-
"_signal" => signal::make_module,
88-
"_sre" => sre::make_module,
89-
"_string" => string::make_module,
90-
"time" => time::make_module,
91-
"_typing" => typing::make_module,
92-
"_weakref" => weakref::make_module,
93-
"_imp" => imp::make_module,
94-
"_warnings" => warnings::make_module,
95-
sys::sysconfigdata_name() => sysconfigdata::make_module,
96-
}
97-
// parser related modules:
98-
#[cfg(feature = "rustpython-ast")]
99-
{
100-
"_ast" => ast::make_module,
101-
}
102-
// compiler related modules:
103-
#[cfg(feature = "rustpython-compiler")]
104-
{
105-
"symtable" => symtable::make_module,
106-
}
107-
#[cfg(any(unix, target_os = "wasi"))]
108-
{
109-
"posix" => posix::make_module,
110-
// "fcntl" => fcntl::make_module,
111-
}
112-
#[cfg(feature = "threading")]
113-
{
114-
"_thread" => thread::make_module,
115-
}
116-
// Unix-only
117-
#[cfg(all(unix, not(any(target_os = "android", target_os = "redox"))))]
118-
{
119-
"pwd" => pwd::make_module,
120-
}
121-
// Windows-only
122-
#[cfg(windows)]
123-
{
124-
"nt" => nt::make_module,
125-
"msvcrt" => msvcrt::make_module,
126-
"_winapi" => winapi::make_module,
127-
"winreg" => winreg::make_module,
128-
}
129-
#[cfg(any(target_family = "unix", target_family = "windows"))]
130-
{
131-
"_ctypes" => ctypes::make_module,
132-
}
79+
#[cfg(all())]
80+
{
81+
"atexit" => atexit::make_module,
82+
"_codecs" => codecs::make_module,
83+
"_collections" => collections::make_module,
84+
"errno" => errno::make_module,
85+
"_functools" => functools::make_module,
86+
"itertools" => itertools::make_module,
87+
"_io" => io::make_module,
88+
"marshal" => marshal::make_module,
89+
"_operator" => operator::make_module,
90+
"_signal" => signal::make_module,
91+
"_sre" => sre::make_module,
92+
"_string" => string::make_module,
93+
"time" => time::make_module,
94+
"_typing" => typing::make_module,
95+
"_weakref" => weakref::make_module,
96+
"_imp" => imp::make_module,
97+
"_warnings" => warnings::make_module,
98+
sys::sysconfigdata_name() => sysconfigdata::make_module,
99+
}
100+
// parser related modules:
101+
#[cfg(feature = "rustpython-ast")]
102+
{
103+
"_ast" => ast::make_module,
104+
}
105+
// compiler related modules:
106+
#[cfg(feature = "rustpython-compiler")]
107+
{
108+
"symtable" => symtable::make_module,
109+
}
110+
#[cfg(any(unix, target_os = "wasi"))]
111+
{
112+
"posix" => posix::make_module,
113+
// "fcntl" => fcntl::make_module,
114+
}
115+
#[cfg(feature = "threading")]
116+
{
117+
"_thread" => thread::make_module,
118+
}
119+
// Unix-only
120+
#[cfg(all(unix, not(any(target_os = "android", target_os = "redox"))))]
121+
{
122+
"pwd" => pwd::make_module,
123+
}
124+
// Windows-only
125+
#[cfg(windows)]
126+
{
127+
"nt" => nt::make_module,
128+
"msvcrt" => msvcrt::make_module,
129+
"_winapi" => winapi::make_module,
130+
"winreg" => winreg::make_module,
131+
}
132+
#[cfg(all(
133+
any(target_os = "linux", target_os = "macos", target_os = "windows"),
134+
not(any(target_env = "musl", target_env = "sgx"))
135+
))]
136+
{
137+
"_ctypes" => ctypes::make_module,
138+
}
133139
}
134140
}

0 commit comments

Comments
 (0)
0