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
Next Next commit
ctypes: cover Windows pip truststore
  • Loading branch information
youknowone committed Jul 19, 2026
commit 7eed565146dcf23c2aed27c0a6d77d8196bd5aa2
12 changes: 11 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,17 @@ jobs:
target/release/rustpython -m ensurepip
target/release/rustpython -c "import pip"

- if: runner.os == 'Windows'
name: Check pip HTTPS with the Windows trust store
run: >-
target/release/rustpython -m pip download
--disable-pip-version-check
--no-cache-dir
--no-deps
--only-binary=:all:
--dest "$env:RUNNER_TEMP\rustpython-pip-smoke"
six

- if: runner.os != 'Windows'
name: Check if pip inside venv is functional
run: |
Expand Down Expand Up @@ -829,4 +840,3 @@ jobs:

- name: cargo doc
run: cargo doc --locked

16 changes: 16 additions & 0 deletions crates/vm/src/stdlib/_ctypes/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,14 @@ impl PyCArray {
let (kept_alive, ptr) = super::base::ensure_z_null_terminated(bytes, vm);
zelf.0.keep_alive(index, kept_alive);
(ptr, Some(value.to_owned()))
} else if let Some(simple) = value.downcast_ref::<super::PyCSimple>()
&& value.class().type_code(vm).as_deref() == Some("z")
{
let buffer = simple.0.buffer.read();
(
rustpython_host_env::ctypes::read_pointer_from_buffer(&buffer),
None,
)
} else if let Ok(int_val) = value.try_index(vm) {
(int_val.as_bigint().to_usize().unwrap_or(0), None)
} else {
Expand All @@ -667,6 +675,14 @@ impl PyCArray {
} else if let Some(s) = value.downcast_ref::<PyStr>() {
let (holder, ptr) = super::base::str_to_wchar_bytes(s.as_wtf8(), vm);
(ptr, Some(holder))
} else if let Some(simple) = value.downcast_ref::<super::PyCSimple>()
&& value.class().type_code(vm).as_deref() == Some("Z")
{
let buffer = simple.0.buffer.read();
(
rustpython_host_env::ctypes::read_pointer_from_buffer(&buffer),
None,
)
} else if let Ok(int_val) = value.try_index(vm) {
(int_val.as_bigint().to_usize().unwrap_or(0), None)
} else {
Expand Down
31 changes: 29 additions & 2 deletions extra_tests/snippets/stdlib_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ def __repr__(self):

_check_size(c_char_p, "P")

char_pointer = c_char_p(b"1.3.6.1.5.5.7.3.1")
char_pointer_array = (c_char_p * 1)(char_pointer)
assert char_pointer_array[0] == b"1.3.6.1.5.5.7.3.1"


class c_void_p(_SimpleCData):
_type_ = "P"
Expand Down Expand Up @@ -344,7 +348,9 @@ def LoadLibrary(self, name):
# print(libc.srand(i))
# print(test_byte_array)
else:
import ctypes
import os
from ctypes import wintypes

libc = cdll.msvcrt
libc.rand()
Expand All @@ -356,6 +362,29 @@ def LoadLibrary(self, name):
# print("start printf")
# libc.printf(test_byte_array)

kernel32 = ctypes.WinDLL("kernel32", use_last_error=True)
get_current_process = kernel32.GetCurrentProcess
get_current_process.argtypes = ()
get_current_process.restype = ctypes.c_void_p

def preserve_result(_result, _func, args):
return args

get_current_process.errcheck = preserve_result
process_handle = get_current_process()
assert isinstance(process_handle, int)

get_process_id = kernel32.GetProcessId
get_process_id.argtypes = (ctypes.c_void_p,)
get_process_id.restype = wintypes.DWORD
assert get_process_id(process_handle) == os.getpid()

def replace_result(_result, _func, _args):
return "replacement"

get_current_process.errcheck = replace_result
assert get_current_process() == "replacement"

# windows pip support

def get_win_folder_via_ctypes(csidl_name: str) -> str:
Expand All @@ -364,8 +393,6 @@ def get_win_folder_via_ctypes(csidl_name: str) -> str:
# Use 'CSIDL_PROFILE' (40) and append the default folder 'Downloads' instead.
# https://learn.microsoft.com/en-us/windows/win32/shell/knownfolderid

import ctypes # noqa: PLC0415

csidl_const = {
"CSIDL_APPDATA": 26,
"CSIDL_COMMON_APPDATA": 35,
Expand Down
Loading