Skip to content

Preserve Win32 last-error in winproxy - #95

Merged
hakril merged 2 commits into
hakril:masterfrom
conioh:conioh-preserve-win32-last-error
Nov 12, 2026
Merged

hakril merged 2 commits into
hakril:masterfrom
conioh:conioh-preserve-win32-last-error

Conversation

@conioh

@conioh conioh commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

BEEP BOOP! I am Copilot working on Alex's behalf:

Summary

  • Generate Win32 API prototypes with ctypes use_last_error=True, capturing the native last-error value at the call boundary.
  • Have WinproxyError use the captured value when no explicit error code is supplied; explicit result-based codes and existing failure checks remain unchanged.
  • Add a GIL-contention regression test and document the capture behavior.

Verification

  • On unmodified upstream source, the standalone reproducer returned winerror=0 on its first contended call instead of 122.
  • With this change, 100,000 contended calls all reported 122.
  • tests/test_winproxy.py, tests/test_token.py, and tests/test_generated_def.py: 33 passed.

Fixes #94

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@hakril

hakril commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Prout Prout ! I am a human !

Nice bug & fix. It should land on main once the tests pass on Python2.7 as I have an obligation for compatibility.
As 'getswitchinterval' do not exists on 2.7, another method to trigger the bug and test the fix should be used.

Maybe sleeping or waiting ?

@conioh

conioh commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

I'll ask my bot to do that. Honestly I'm not sure the test is really that important. We understand the issue and adding the use_last_error=True was the important part. If we won't manage to create a good reproduction for the test for 2.7 I think you could still merge it without the test.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@conioh

conioh commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

BEEP BOOP! I am Copilot working on Alex's behalf:

Thanks! I updated the contention test to use getcheckinterval/setcheckinterval on Python 2.7 and the switch interval APIs on Python 3, restoring the original setting afterward. I also added a deterministic regression: it overwrites native last-error inside an error checker after the API fails, then checks that the wrapper still reports 122. This fails against unpatched upstream (reports 0) and passes with the fix on Python 2.7 and 3.13.

Locally, the targeted winproxy, token, and generated-definition tests passed on Python 2.7.18 x86 and x64 (34 each), and Python 3.13 x64 (34). The latest commit changes tests only; the production fix is unchanged.

@conioh

conioh commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

BEEP BOOP! I am Copilot working on Alex's behalf:

The new workflow run is waiting for approval (action_required), so the upstream CI matrix has not run yet: https://github.com/hakril/PythonForWindows/actions/runs/43196377935. Could you approve the run when convenient?

@hakril
hakril merged commit e6b5168 into hakril:master Nov 12, 2026
25 of 26 checks passed
@hakril

hakril commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thank you for the PR !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve Win32 last-error across GIL contention

2 participants