René's URL Explorer Experiment


Title: gh-128182: Add per-object memory access synchronization to `ctypes` by ZeroIntensity · Pull Request #128490 · python/cpython · GitHub

Open Graph Title: gh-128182: Add per-object memory access synchronization to `ctypes` by ZeroIntensity · Pull Request #128490 · python/cpython

X Title: gh-128182: Add per-object memory access synchronization to `ctypes` by ZeroIntensity · Pull Request #128490 · python/cpython

Description: I say "per-object" as in, using a single ctypes object is thread-safe if that's the only object accessing the memory. IMO, access to arbitrary memory across different pointer objects shouldn't (or can't?) be thread safe--ctypes should remain pretty low level, and that kind of synchronization might do bad things to applications that don't want it. I've clarified this in the docs. That said, I could see use in some sort of wrapper that ensures only one thread accesses memory using a table of addresses, but that should go to DPO first. A few notes about the implementation here: I'm making some assumptions about ctypes casting getfunc and setfunc functions being non-reentrant. In practice, they really shouldn't be, but of course I'm not absolutely certain. We might want to go with a recursive mutex if that turns out to be an issue. I'm also assuming that the PyFoo_FromBar functions don't have a chance to re-enter. The cases I could think of that could maybe cause re-entrancy are: an embedder could hijack the allocator and run the interpreter from it, or audit events. (Let me know if this is a deal-breaker!) Issue: gh-128182 📚 Documentation preview 📚: https://cpython-previews--128490.org.readthedocs.build/en/128490/library/ctypes.html#thread-safety-without-the-gil

Open Graph Description: I say "per-object" as in, using a single ctypes object is thread-safe if that's the only object accessing the memory. IMO, access to arbitrary memory across different pointer objects ...

X Description: I say "per-object" as in, using a single ctypes object is thread-safe if that's the only object accessing the memory. IMO, access to arbitrary memory across different poin...

Opengraph URL: https://github.com/python/cpython/pull/128490

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:5c9440d0-30e3-9cd8-421c-fbef1755bae9
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idDA36:382318:EA8A67:125FB6F:6B0236A1
html-safe-nonceaf0859038ba6c241643ae4d62fbf5148bc3d063eac63ff73409bf7a634b37975
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTM2OjM4MjMxODpFQThBNjc6MTI1RkI2Rjo2QjAyMzZBMSIsInZpc2l0b3JfaWQiOiI2MTQxNzcyNDU3MzM5NjY0MDMzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacc83476ce00361fdadc7df59b42e3dbef88f807e2ef7e77173886a96983cc0be0
hovercard-subject-tagpull_request:2260474994
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/128490/files
twitter:imagehttps://avatars.githubusercontent.com/u/49501366?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/49501366?s=400&v=4
og:image:altI say "per-object" as in, using a single ctypes object is thread-safe if that's the only object accessing the memory. IMO, access to arbitrary memory across different pointer objects ...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/128490/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F128490%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F128490%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/128490/files
Reloadhttps://github.com/python/cpython/pull/128490/files
Reloadhttps://github.com/python/cpython/pull/128490/files
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
encukouhttps://github.com/encukou
python:mainhttps://github.com/python/cpython/tree/main
ZeroIntensity:ctypes-b-ptrhttps://github.com/ZeroIntensity/cpython/tree/ctypes-b-ptr
Conversation 50 https://github.com/python/cpython/pull/128490
Commits 24 https://github.com/python/cpython/pull/128490/commits
Checks 0 https://github.com/python/cpython/pull/128490/checks
Files changed https://github.com/python/cpython/pull/128490/files
Please reload this pagehttps://github.com/python/cpython/pull/128490/files
gh-128182: Add per-object memory access synchronization to ctypes https://github.com/python/cpython/pull/128490/files#top
Show all changes 24 commits https://github.com/python/cpython/pull/128490/files
3bb21ff Lock pointer reads and writes in ctypes. ZeroIntensity Jan 4, 2025 https://github.com/python/cpython/pull/128490/commits/3bb21fff034fb071124b78eb9b45c0d32783d3f9
8c4c49a Add a test. ZeroIntensity Jan 4, 2025 https://github.com/python/cpython/pull/128490/commits/8c4c49a4c1862274b66c620fbbd72f8e807e42ef
da293c1 Fix the test. ZeroIntensity Jan 4, 2025 https://github.com/python/cpython/pull/128490/commits/da293c14262a946b00c08fa45aa3ea7dd2551fda
d01b757 Add blurb. ZeroIntensity Jan 4, 2025 https://github.com/python/cpython/pull/128490/commits/d01b757f596d97987f64e73d413fdf551b7c43fd
8bb980f Add a lock for generic helper functions. ZeroIntensity Jan 4, 2025 https://github.com/python/cpython/pull/128490/commits/8bb980f519854417ebb28c1550dd8c57e0b0f4a3
d60f2e2 Add documentation note. ZeroIntensity Jan 4, 2025 https://github.com/python/cpython/pull/128490/commits/d60f2e237d4f8ee4265c873186e3dbfb6c93a29b
de4c4ea Fix compiler warning on GIL-ful builds. ZeroIntensity Jan 4, 2025 https://github.com/python/cpython/pull/128490/commits/de4c4eabe421b688cf3d50d10fd14f163500a28a
23d8e21 Fix MSVC compiler warnings. ZeroIntensity Jan 4, 2025 https://github.com/python/cpython/pull/128490/commits/23d8e21f7c716d164a71dbe39dd1f51cc86a8bea
bdee2b2 Fix MSVC compiler warnings (actually this time) ZeroIntensity Jan 4, 2025 https://github.com/python/cpython/pull/128490/commits/bdee2b253527dfd2a3407a4349d10ab0c545473b
9f272d9 Apply suggestions from code review ZeroIntensity Jan 6, 2025 https://github.com/python/cpython/pull/128490/commits/9f272d94a848ab109322477e2a82cfeb5bd5ac2f
32a885f Fix Sphinx code block. ZeroIntensity Jan 6, 2025 https://github.com/python/cpython/pull/128490/commits/32a885feee29c3a4b4397a50016d3c186478e119
1c92b4b Flatten call to PyUnicode_AsWideChar ZeroIntensity Jan 6, 2025 https://github.com/python/cpython/pull/128490/commits/1c92b4bacaabff63539ad09cb2f882f87075080e
ff34cc2 Fix lock. ZeroIntensity Jan 6, 2025 https://github.com/python/cpython/pull/128490/commits/ff34cc2c49e26e18b31c7f4c0a934b33214f9c52
804f1b6 Fix indentation. ZeroIntensity Jan 6, 2025 https://github.com/python/cpython/pull/128490/commits/804f1b65304767059bf645a5b6e9bcb19f756e79
bae3c5b Revert "Flatten call to PyUnicode_AsWideChar" ZeroIntensity Jan 6, 2025 https://github.com/python/cpython/pull/128490/commits/bae3c5bb27f54f077cf0d2afa5931fb1a7d86552
d720d9a Properly flatten call to PyUnicode_AsWideChar ZeroIntensity Jan 6, 2025 https://github.com/python/cpython/pull/128490/commits/d720d9ab18dc506f2bb36fee3ea5b5145483159b
04b3252 Fix indentation. ZeroIntensity Jan 6, 2025 https://github.com/python/cpython/pull/128490/commits/04b32527c45cb1fb32d10fa175814606ad5f20e4
6401bbc Clarify comment ZeroIntensity Jan 6, 2025 https://github.com/python/cpython/pull/128490/commits/6401bbcecfc204ff2984a41e59122b5abb8efbca
9d35e86 Switch to critical sections. ZeroIntensity Jan 8, 2025 https://github.com/python/cpython/pull/128490/commits/9d35e86f68fc8d4fbccb2660ea9899d875e5c8e8
ce94234 Update test_arrays.py ZeroIntensity Jan 9, 2025 https://github.com/python/cpython/pull/128490/commits/ce942340bd905a6493200d673ce43151bd90f40f
d6a4bc8 Update Doc/library/ctypes.rst ZeroIntensity Jan 9, 2025 https://github.com/python/cpython/pull/128490/commits/d6a4bc846a5932632c40643863c4d651b79ad4ce
5a4c1d6 Update Modules/_ctypes/_ctypes.c ZeroIntensity Jan 9, 2025 https://github.com/python/cpython/pull/128490/commits/5a4c1d69263411bbcbea9a8513aba3ea1cfe9155
774a6ec Update Modules/_ctypes/_ctypes.c ZeroIntensity Jan 9, 2025 https://github.com/python/cpython/pull/128490/commits/774a6ec19b259888b8254f56419f36622545eb8a
c8f2cd3 Remove silly seealso. ZeroIntensity Jan 10, 2025 https://github.com/python/cpython/pull/128490/commits/c8f2cd3e3d65987af50d4bbe418dd411b67c6921
Clear filters https://github.com/python/cpython/pull/128490/files
Please reload this pagehttps://github.com/python/cpython/pull/128490/files
Please reload this pagehttps://github.com/python/cpython/pull/128490/files
ctypes.rst https://github.com/python/cpython/pull/128490/files#diff-13b210c267218100dc49e485ac4735e44224ae266e36c35f1ac6bf774f59e60d
test_arrays.py https://github.com/python/cpython/pull/128490/files#diff-d13e55d9a263d0a00ab95cf8098b581526a9e7cda4076a1704bde347033a41fa
2025-01-04-11-32-46.gh-issue-128182.SJ2Zsa.rst https://github.com/python/cpython/pull/128490/files#diff-cce9e9aabb7fe6d4a2010285828af862015decc918e34d0a868bb8385a024a75
_ctypes.c https://github.com/python/cpython/pull/128490/files#diff-402bc51df93eaaca2e2f2551ec0206d8af190722ae4703c178554b565d7c14b4
ctypes.h https://github.com/python/cpython/pull/128490/files#diff-53f61eb1ad6b25b3aff25b54b4df5004a1f1137ca1d2aae4c7e31fc00ec6e9f8
Doc/library/ctypes.rsthttps://github.com/python/cpython/pull/128490/files#diff-13b210c267218100dc49e485ac4735e44224ae266e36c35f1ac6bf774f59e60d
View file https://github.com/ZeroIntensity/cpython/blob/c8f2cd3e3d65987af50d4bbe418dd411b67c6921/Doc/library/ctypes.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/128490/{{ revealButtonHref }}
https://github.com/python/cpython/pull/128490/files#diff-13b210c267218100dc49e485ac4735e44224ae266e36c35f1ac6bf774f59e60d
picnixzhttps://github.com/picnixz
Jan 6, 2025https://github.com/python/cpython/pull/128490/files#r1904004430
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/128490/files
ZeroIntensityhttps://github.com/ZeroIntensity
Jan 6, 2025https://github.com/python/cpython/pull/128490/files#r1904244602
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/128490/files
https://github.com/python/cpython/pull/128490/files#diff-13b210c267218100dc49e485ac4735e44224ae266e36c35f1ac6bf774f59e60d
Lib/test/test_ctypes/test_arrays.pyhttps://github.com/python/cpython/pull/128490/files#diff-d13e55d9a263d0a00ab95cf8098b581526a9e7cda4076a1704bde347033a41fa
View file https://github.com/ZeroIntensity/cpython/blob/c8f2cd3e3d65987af50d4bbe418dd411b67c6921/Lib/test/test_ctypes/test_arrays.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/128490/{{ revealButtonHref }}
https://github.com/python/cpython/pull/128490/files#diff-d13e55d9a263d0a00ab95cf8098b581526a9e7cda4076a1704bde347033a41fa
https://github.com/python/cpython/pull/128490/files#diff-d13e55d9a263d0a00ab95cf8098b581526a9e7cda4076a1704bde347033a41fa
https://github.com/python/cpython/pull/128490/files#diff-d13e55d9a263d0a00ab95cf8098b581526a9e7cda4076a1704bde347033a41fa
Please reload this pagehttps://github.com/python/cpython/pull/128490/files
Misc/NEWS.d/next/Library/2025-01-04-11-32-46.gh-issue-128182.SJ2Zsa.rsthttps://github.com/python/cpython/pull/128490/files#diff-cce9e9aabb7fe6d4a2010285828af862015decc918e34d0a868bb8385a024a75
View file https://github.com/ZeroIntensity/cpython/blob/c8f2cd3e3d65987af50d4bbe418dd411b67c6921/Misc/NEWS.d/next/Library/2025-01-04-11-32-46.gh-issue-128182.SJ2Zsa.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/128490/{{ revealButtonHref }}
Please reload this pagehttps://github.com/python/cpython/pull/128490/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.