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 — gh-127945: fix thread safety of creating instances of ctypes structures by kumaraditya303 · Pull Request #131716 · python/cpython

Conversation

@kumaraditya303

@kumaraditya303 kumaraditya303 commented Mar 25, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
  • Issue: ctypes thread safety auditing (and fixing) #127945

In free-threading, concurrent mutations to StgInfo is not thread safe. Therefore to make it thread safe, when modifying StgInfo, this PR adds STGINFO_LOCK and STGINFO_UNLOCK macros which are used to acquire critical section of the StgInfo. The critical section is write only and is acquired when modifying the StgInfo fields and while setting the dict_final bit. Once the dict_final is set, StgInfo is treated as read only and no further modifications are allowed. This allows to avoid acquiring the critical section for most read operations when dict_final is set (general case).

Fixes #128567
Fixes #128570

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
kumaraditya303 added 9 commits March 25, 2025 10:15
@kumaraditya303
make instance creation thread safe
504e741
@kumaraditya303
add tests
a05195e
@kumaraditya303
Merge branch 'main' of https://github.com/python/cpython into critica…
d515a09
…l-ctypes
@kumaraditya303
fmt
f3ef75e
@kumaraditya303
wip
e3bec70
@kumaraditya303
fix clearing of final bit
fd5ad20
@kumaraditya303
move setting bit to earlier
ee47298
@kumaraditya303
add comment
4db3e36
@kumaraditya303
improve comments
b0e06a0
@kumaraditya303 kumaraditya303 added skip news topic-ctypes topic-free-threading labels Mar 25, 2025
@bedevere-app bedevere-app Bot added the awaiting core review label Mar 25, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Mar 25, 2025
ctypes thread safety auditing (and fixing) #127945
Closed
@kumaraditya303
kumaraditya303 requested a review from colesbury March 25, 2025 13:36
@kumaraditya303 kumaraditya303 added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Mar 25, 2025
@bedevere-bot

bedevere-bot commented Mar 25, 2025

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @kumaraditya303 for commit b0e06a0 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F131716%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Mar 25, 2025
colesbury
colesbury approved these changes Mar 27, 2025
View reviewed changes

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks great! A few minor comments.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Modules/_ctypes/stgdict.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/_ctypes/ctypes.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/_ctypes/ctypes.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_ctypes/test_free_threading.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/_ctypes/_ctypes.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Mar 27, 2025
@colesbury
colesbury requested a review from encukou March 27, 2025 23:27
kumaraditya303 added 2 commits March 28, 2025 20:06
@kumaraditya303
Merge branch 'main' of https://github.com/python/cpython into critica…
bfd7c21
…l-ctypes
@kumaraditya303
code review
ef9ba7a
encukou
encukou reviewed Mar 30, 2025
View reviewed changes
Comment thread Modules/_ctypes/ctypes.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

@kumaraditya303
use uint8_t
2a05687
@kumaraditya303
kumaraditya303 merged commit bc5a028 into python:main Mar 30, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label Mar 30, 2025
@kumaraditya303
kumaraditya303 deleted the critical-ctypes branch March 30, 2025 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@encukou encukou encukou left review comments
@colesbury colesbury colesbury approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news topic-ctypes topic-free-threading

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Race in stgdict PyCStructUnionType_update_stginfo under free-threading Race in ctypes PyCFuncPtr_new under free-threading

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@kumaraditya303 @bedevere-bot @encukou @colesbury
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — 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.