X Tutup
Skip to content
Draft

Ci venv #6474

Show file tree
Hide file tree
Changes from all commits
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
8 changes: 3 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ jobs:
target/release/rustpython -m test -j 1 --slowest --fail-env-changed -v -x ${{ env.PLATFORM_INDEPENDENT_TESTS }} ${{ env.WINDOWS_SKIPS }}
timeout-minutes: 45

- if: runner.os != 'Windows'
name: check that --install-pip succeeds
- name: check that --install-pip succeeds
run: |
mkdir site-packages
target/release/rustpython --install-pip ensurepip --user
Expand All @@ -309,11 +308,10 @@ jobs:
run: |
target/release/rustpython -m ensurepip
target/release/rustpython -c "import pip"
- if: runner.os != 'Windows'
name: Check if pip inside venv is functional
- name: Check if pip inside venv is functional
run: |
target/release/rustpython -m venv testvenv
testvenv/bin/rustpython -m pip install wheel
testvenv/bin/rustpython -m pip install flask
- name: Check whats_left is not broken
run: python -I whats_left.py

Expand Down
11 changes: 10 additions & 1 deletion crates/vm/src/stdlib/ctypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,9 @@ pub(crate) mod _ctypes {
vm: &VirtualMachine,
) -> PyResult<usize> {
// Default mode: RTLD_NOW | RTLD_LOCAL, always force RTLD_NOW
let mode = load_flags.unwrap_or(libc::RTLD_NOW | libc::RTLD_LOCAL) | libc::RTLD_NOW;
let mode = load_flags
.map(|m| m | libc::RTLD_NOW)
.unwrap_or(libc::RTLD_NOW | libc::RTLD_LOCAL);

match name {
Some(name) => {
Expand Down Expand Up @@ -641,6 +643,13 @@ pub(crate) mod _ctypes {
name: crate::builtins::PyStrRef,
vm: &VirtualMachine,
) -> PyResult<usize> {
// Validate the handle exists in the library cache before calling dlsym
let cache = library::libcache().read();
if cache.get_lib(handle).is_none() {
return Err(vm.new_os_error("invalid library handle"));
}
drop(cache);

let symbol_name = std::ffi::CString::new(name.as_str())
.map_err(|_| vm.new_value_error("symbol name contains null byte"))?;

Expand Down
42 changes: 32 additions & 10 deletions crates/vm/src/stdlib/ctypes/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use std::ffi::OsStr;
use std::fmt;

#[cfg(unix)]
use libloading::os::unix::Library as UnixLibrary;
use libloading::os::unix::Library as OsLibrary;
#[cfg(windows)]
use libloading::os::windows::Library as OsLibrary;

pub struct SharedLibrary {
pub(crate) lib: PyMutex<Option<Library>>,
Expand All @@ -33,7 +35,7 @@ impl SharedLibrary {
) -> Result<SharedLibrary, libloading::Error> {
Ok(SharedLibrary {
lib: PyMutex::new(Some(unsafe {
UnixLibrary::open(Some(name.as_ref()), mode)?.into()
OsLibrary::open(Some(name.as_ref()), mode)?.into()
})),
})
}
Expand All @@ -42,19 +44,39 @@ impl SharedLibrary {
#[cfg(unix)]
pub fn from_raw_handle(handle: *mut libc::c_void) -> SharedLibrary {
SharedLibrary {
lib: PyMutex::new(Some(unsafe { UnixLibrary::from_raw(handle).into() })),
lib: PyMutex::new(Some(unsafe { OsLibrary::from_raw(handle).into() })),
}
}

/// Get the underlying OS handle (HMODULE on Windows, dlopen handle on Unix)
#[cfg(unix)]
pub fn get_pointer(&self) -> usize {
let lib_lock = self.lib.lock();
if let Some(l) = &*lib_lock {
// libloading::Library internally stores the OS handle directly
// On Windows: HMODULE (*mut c_void)
// On Unix: *mut c_void from dlopen
// We use transmute_copy to read the handle without consuming the Library
unsafe { std::mem::transmute_copy::<Library, usize>(l) }
let mut lib_lock = self.lib.lock();
if let Some(lib) = lib_lock.take() {
// Use official libloading API: convert to platform-specific type,
// extract raw handle, then reconstruct
let unix_lib: OsLibrary = lib.into();
let handle = unix_lib.into_raw();
// Reconstruct the library from the raw handle and put it back
*lib_lock = Some(unsafe { OsLibrary::from_raw(handle) }.into());
handle as usize
} else {
0
}
}

/// Get the underlying OS handle (HMODULE on Windows, dlopen handle on Unix)
#[cfg(windows)]
pub fn get_pointer(&self) -> usize {
let mut lib_lock = self.lib.lock();
if let Some(lib) = lib_lock.take() {
// Use official libloading API: convert to platform-specific type,
// extract raw handle, then reconstruct
let win_lib: OsLibrary = lib.into();
let handle = win_lib.into_raw();
// Reconstruct the library from the raw handle and put it back
*lib_lock = Some(unsafe { OsLibrary::from_raw(handle) }.into());
handle as usize
} else {
0
}
Expand Down
Loading
X Tutup