Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 572f3ba

Browse filesBrowse files
committed
initial _ctypes implementation with _CData, get_errno, and set_errno
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
1 parent 6e35e20 commit 572f3ba
Copy full SHA for 572f3ba

File tree

4 files changed

+44
-2
lines changed
Filter options

4 files changed

+44
-2
lines changed

‎Cargo.lock

Copy file name to clipboardExpand all lines: Cargo.lock
+3-2Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vm/Cargo.toml

Copy file name to clipboardExpand all lines: vm/Cargo.toml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ uname = "0.1.1"
9999
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
100100
rustyline = { workspace = true }
101101
which = "6"
102+
errno = "0.3"
102103

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

‎vm/src/stdlib/ctypes.rs

Copy file name to clipboard
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
pub(crate) use _ctypes::make_module;
2+
3+
#[pymodule]
4+
mod _ctypes {
5+
use crate::{common::lock::PyRwLock, PyObjectRef};
6+
use crossbeam_utils::atomic::AtomicCell;
7+
8+
pub struct RawBuffer {
9+
#[allow(dead_code)]
10+
pub inner: Box<[u8]>,
11+
#[allow(dead_code)]
12+
pub size: usize,
13+
}
14+
15+
#[pyattr]
16+
#[pyclass(name = "_CData")]
17+
pub struct PyCData {
18+
_objects: AtomicCell<Vec<PyObjectRef>>,
19+
_buffer: PyRwLock<RawBuffer>,
20+
}
21+
22+
#[pyclass]
23+
impl PyCData {}
24+
25+
#[pyfunction]
26+
fn get_errno() -> i32 {
27+
errno::errno().0
28+
}
29+
30+
#[pyfunction]
31+
fn set_errno(value: i32) {
32+
errno::set_errno(errno::Errno(value));
33+
}
34+
}

‎vm/src/stdlib/mod.rs

Copy file name to clipboardExpand all lines: vm/src/stdlib/mod.rs
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub mod posix;
3737
#[path = "posix_compat.rs"]
3838
pub mod posix;
3939

40+
#[cfg(any(target_family = "unix", target_family = "windows"))]
41+
mod ctypes;
4042
#[cfg(windows)]
4143
pub(crate) mod msvcrt;
4244
#[cfg(all(unix, not(any(target_os = "android", target_os = "redox"))))]
@@ -124,5 +126,9 @@ pub fn get_module_inits() -> StdlibMap {
124126
"_winapi" => winapi::make_module,
125127
"winreg" => winreg::make_module,
126128
}
129+
#[cfg(any(target_family = "unix", target_family = "windows"))]
130+
{
131+
"_ctypes" => ctypes::make_module,
132+
}
127133
}
128134
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.