Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Make mergeable
  • Loading branch information
youknowone committed Nov 28, 2025
commit 8af105fc4ff5f5eb8e9a534b826b27ec47a6a576
1 change: 0 additions & 1 deletion crates/vm/src/stdlib/ctypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub(crate) mod pointer;
pub(crate) mod structure;
pub(crate) mod thunk;
pub(crate) mod union;
pub(crate) mod util;

use crate::builtins::PyModule;
use crate::class::PyClassImpl;
Expand Down
11 changes: 1 addition & 10 deletions crates/vm/src/stdlib/ctypes/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{Py, PyResult, VirtualMachine};
#[pyclass(name = "PyCFieldType", base = PyType, module = "_ctypes")]
#[derive(PyPayload, Debug)]
pub struct PyCFieldType {
#[allow(dead_code)]
pub(super) inner: PyCField,
}

Expand Down Expand Up @@ -122,13 +123,3 @@ impl PyCField {
self.bit_offset
}
}

#[inline(always)]
pub const fn low_bit(offset: usize) -> usize {
offset & 0xFFFF
}

#[inline(always)]
pub const fn high_bit(offset: usize) -> usize {
offset >> 16
}
2 changes: 2 additions & 0 deletions crates/vm/src/stdlib/ctypes/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,12 @@ impl ReturnType for PyNone {
pub struct PyCFuncPtr {
pub name: PyRwLock<Option<String>>,
pub ptr: PyRwLock<Option<CodePtr>>,
#[allow(dead_code)]
pub needs_free: AtomicCell<bool>,
pub arg_types: PyRwLock<Option<Vec<PyTypeRef>>>,
pub res_type: PyRwLock<Option<PyObjectRef>>,
pub _flags_: AtomicCell<i32>,
#[allow(dead_code)]
pub handler: PyObjectRef,
}

Expand Down
3 changes: 2 additions & 1 deletion crates/vm/src/stdlib/ctypes/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::{PyObjectRef, PyResult};
#[pyclass(name = "PyCPointerType", base = PyType, module = "_ctypes")]
#[derive(PyPayload, Debug)]
pub struct PyCPointerType {
pub inner: PyCPointer,
#[allow(dead_code)]
pub(crate) inner: PyCPointer,
}

#[pyclass]
Expand Down
24 changes: 0 additions & 24 deletions crates/vm/src/stdlib/ctypes/util.rs

This file was deleted.

12 changes: 6 additions & 6 deletions extra_tests/snippets/stdlib_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,19 +338,19 @@ def LoadLibrary(self, name):
libc = cdll.LoadLibrary("libc.dylib")
libc.rand()
i = c_int(1)
print("start srand")
print(libc.srand(i))
print(test_byte_array)
# print("start srand")
# print(libc.srand(i))
# print(test_byte_array)
else:
import os

libc = cdll.msvcrt
libc.rand()
i = c_int(1)
print("start srand")
print(libc.srand(i))
print(test_byte_array)
print(test_byte_array._type_)
# print(libc.srand(i))
# print(test_byte_array)
# print(test_byte_array._type_)
# print("start printf")
# libc.printf(test_byte_array)

Comment on lines +336 to 356
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Non-Darwin POSIX platforms (Linux, etc.) have no libc test coverage.

The restructured conditionals mean that when _os.name == "posix" but _sys.platform != "darwin", no code executes for libc testing. The else at line 344 only triggers for non-POSIX systems (Windows).

This appears to drop test coverage for Linux and other POSIX platforms. If intentional, consider adding a comment explaining why; if not, the logic should be adjusted:

 if _os.name == "posix":
     if _sys.platform == "darwin":
         libc = cdll.LoadLibrary("libc.dylib")
         libc.rand()
         i = c_int(1)
         # print("start srand")
         # print(libc.srand(i))
         # print(test_byte_array)
+    else:
+        # Linux and other POSIX platforms
+        libc = cdll.LoadLibrary("libc.so.6")
+        libc.rand()
+        i = c_int(1)
 else:
     import os
🤖 Prompt for AI Agents
In extra_tests/snippets/stdlib_ctypes.py around lines 336-356, the current
if/else structure causes the POSIX branch to only run for Darwin and the else
branch to run only on non-POSIX (Windows), leaving non-Darwin POSIX systems
(e.g., Linux) untested; change the branching so POSIX platforms always exercise
libc testing: keep the _os.name == "posix" block but add an inner branch for
_sys.platform == "darwin" and a separate branch for other POSIX platforms that
loads the appropriate libc (e.g., libc.so.6 or using cdll.LoadLibrary(None)) and
runs the same rand/srand checks, while keeping the Windows-specific branch as an
explicit elif _os.name != "posix" (or elif _os.name == "nt") so Linux/other
POSIX are covered.

Expand Down
Loading