GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ctypes: cover Windows pip truststore · RustPython/RustPython@9b3ae9d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .github/workflows
    • ci.yaml
  • crates/vm/src/stdlib/_ctypes
    • array.rs
  • extra_tests/snippets
    • stdlib_ctypes.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.github/workflows/ci.yaml‎

Copy file name to clipboardExpand all lines: .github/workflows/ci.yaml
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,17 @@ jobs:
438438
target/release/rustpython -m ensurepip
439439
target/release/rustpython -c "import pip"
440440
441+
- if: runner.os == 'Windows'
442+
name: Check pip HTTPS with the Windows trust store
443+
run: >-
444+
target/release/rustpython -m pip download
445+
--disable-pip-version-check
446+
--no-cache-dir
447+
--no-deps
448+
--only-binary=:all:
449+
--dest "$env:RUNNER_TEMP\rustpython-pip-smoke"
450+
six
451+
441452
- if: runner.os != 'Windows'
442453
name: Check if pip inside venv is functional
443454
run: |
@@ -829,4 +840,3 @@ jobs:
829840
830841
- name: cargo doc
831842
run: cargo doc --locked
832-
Collapse file

‎crates/vm/src/stdlib/_ctypes/array.rs‎

Copy file name to clipboardExpand all lines: crates/vm/src/stdlib/_ctypes/array.rs
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,14 @@ impl PyCArray {
641641
let (kept_alive, ptr) = super::base::ensure_z_null_terminated(bytes, vm);
642642
zelf.0.keep_alive(index, kept_alive);
643643
(ptr, Some(value.to_owned()))
644+
} else if let Some(simple) = value.downcast_ref::<super::PyCSimple>()
645+
&& value.class().type_code(vm).as_deref() == Some("z")
646+
{
647+
let buffer = simple.0.buffer.read();
648+
(
649+
rustpython_host_env::ctypes::read_pointer_from_buffer(&buffer),
650+
None,
651+
)
644652
} else if let Ok(int_val) = value.try_index(vm) {
645653
(int_val.as_bigint().to_usize().unwrap_or(0), None)
646654
} else {
@@ -667,6 +675,14 @@ impl PyCArray {
667675
} else if let Some(s) = value.downcast_ref::<PyStr>() {
668676
let (holder, ptr) = super::base::str_to_wchar_bytes(s.as_wtf8(), vm);
669677
(ptr, Some(holder))
678+
} else if let Some(simple) = value.downcast_ref::<super::PyCSimple>()
679+
&& value.class().type_code(vm).as_deref() == Some("Z")
680+
{
681+
let buffer = simple.0.buffer.read();
682+
(
683+
rustpython_host_env::ctypes::read_pointer_from_buffer(&buffer),
684+
None,
685+
)
670686
} else if let Ok(int_val) = value.try_index(vm) {
671687
(int_val.as_bigint().to_usize().unwrap_or(0), None)
672688
} else {
Collapse file

‎extra_tests/snippets/stdlib_ctypes.py‎

Copy file name to clipboardExpand all lines: extra_tests/snippets/stdlib_ctypes.py
+29-2Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ def __repr__(self):
190190

191191
_check_size(c_char_p, "P")
192192

193+
char_pointer = c_char_p(b"1.3.6.1.5.5.7.3.1")
194+
char_pointer_array = (c_char_p * 1)(char_pointer)
195+
assert char_pointer_array[0] == b"1.3.6.1.5.5.7.3.1"
196+
193197

194198
class c_void_p(_SimpleCData):
195199
_type_ = "P"
@@ -344,7 +348,9 @@ def LoadLibrary(self, name):
344348
# print(libc.srand(i))
345349
# print(test_byte_array)
346350
else:
351+
import ctypes
347352
import os
353+
from ctypes import wintypes
348354

349355
libc = cdll.msvcrt
350356
libc.rand()
@@ -356,6 +362,29 @@ def LoadLibrary(self, name):
356362
# print("start printf")
357363
# libc.printf(test_byte_array)
358364

365+
kernel32 = ctypes.WinDLL("kernel32", use_last_error=True)
366+
get_current_process = kernel32.GetCurrentProcess
367+
get_current_process.argtypes = ()
368+
get_current_process.restype = ctypes.c_void_p
369+
370+
def preserve_result(_result, _func, args):
371+
return args
372+
373+
get_current_process.errcheck = preserve_result
374+
process_handle = get_current_process()
375+
assert isinstance(process_handle, int)
376+
377+
get_process_id = kernel32.GetProcessId
378+
get_process_id.argtypes = (ctypes.c_void_p,)
379+
get_process_id.restype = wintypes.DWORD
380+
assert get_process_id(process_handle) == os.getpid()
381+
382+
def replace_result(_result, _func, _args):
383+
return "replacement"
384+
385+
get_current_process.errcheck = replace_result
386+
assert get_current_process() == "replacement"
387+
359388
# windows pip support
360389

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

367-
import ctypes # noqa: PLC0415
368-
369396
csidl_const = {
370397
"CSIDL_APPDATA": 26,
371398
"CSIDL_COMMON_APPDATA": 35,

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.