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-117142: Slightly hacky fix for memory leak of StgInfo by encukou · Pull Request #119424 · python/cpython

Conversation

@encukou

@encukou encukou commented May 22, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Add a function that inlines PyObject_GetTypeData and skips type-checking, so it doesn't need access to the CType_Type object. This will break if the memory layout changes, but should be an acceptable solution to enable ctypes in subinterpreters in Python 3.13.

This is a less invasive version of #118139.

>python_d -X showrefcount -c "import ctypes"
[188 refs, 132 blocks]  # before
[0 refs, 0 blocks]      # after
  • Issue: Convert _ctypes extension module to multi-phase init #117142

Sorry, something went wrong.

Uh oh!

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

All reactions
@encukou
pythongh-117142: Slightliy hacky fix for memory leak of StgInfo
c3fdc38
Add a funciton that inlines PyObject_GetTypeData and skips
type-checking, so it doesn't need access to the CType_Type object.
This will break if the memory layout changes, but should
be an acceptable solution to enable ctypes in subinterpreters in
Python 3.13.
@bedevere-app bedevere-app Bot added the awaiting core review label May 22, 2024
@bedevere-app bedevere-app Bot mentioned this pull request May 22, 2024
Convert _ctypes extension module to multi-phase init #117142
Closed
2 tasks done
@encukou encukou changed the title gh-117142: Slightliy hacky fix for memory leak of StgInfo gh-117142: Slightly hacky fix for memory leak of StgInfo May 22, 2024
@encukou
encukou requested a review from ericsnowcurrently May 22, 2024 18:24
@encukou encukou added the skip news label May 22, 2024
@encukou
Mark _ctypes as safe for multiple interpreters
6aa0075
ericsnowcurrently
ericsnowcurrently approved these changes May 22, 2024
View reviewed changes

@ericsnowcurrently ericsnowcurrently left a comment

Copy link
Copy Markdown
Member

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.

LGTM

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels May 22, 2024
@neonene

neonene commented May 22, 2024

Copy link
Copy Markdown
Contributor

get_module_state_by_def_final function can be removed from ctypes.h.

encukou reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@encukou
Remove get_module_state_by_def_final
d535ff2
@encukou
encukou enabled auto-merge (squash) May 22, 2024 19:21
@encukou
encukou disabled auto-merge May 22, 2024 19:21
@encukou
encukou enabled auto-merge (squash) May 22, 2024 19:21
@encukou

encukou commented May 22, 2024

Copy link
Copy Markdown
Member Author

It can! Thank you!

All reactions

Sorry, something went wrong.

Uh oh!

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

@encukou encukou mentioned this pull request May 22, 2024
gh-117142: ctypes: Fix memory leak of StgInfo #118139
Closed
@encukou encukou added the needs backport to 3.13 only security fixes label May 22, 2024
@neonene

neonene commented May 23, 2024

Copy link
Copy Markdown
Contributor

Regarding the CI failure on Windows (free-threading x86 debug), PyType_Type.tp_basicsize is 476, whereas it is 464 with the GIL enabled (success).

encukou reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@encukou
Align PyType_Type.tp_basicsize up
c73d0be
@encukou
encukou merged commit a192547 into python:main May 23, 2024
@miss-islington-app

miss-islington-app Bot commented May 23, 2024

Copy link
Copy Markdown

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label May 23, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 23, 2024
@encukou @neonene @miss-islington
pythongh-117142: Slightly hacky fix for memory leak of StgInfo (pytho…
934f329
…nGH-119424)

Add a funciton that inlines PyObject_GetTypeData and skips
type-checking, so it doesn't need access to the CType_Type object.
This will break if the memory layout changes, but should
be an acceptable solution to enable ctypes in subinterpreters in
Python 3.13.

Mark _ctypes as safe for multiple interpreters

(cherry picked from commit a192547)

Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: neonene <[email protected]>
@bedevere-app

bedevere-app Bot commented May 23, 2024

Copy link
Copy Markdown

GH-119468 is a backport of this pull request to the 3.13 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label May 23, 2024
@encukou
encukou deleted the ctypes-stginfo-hack branch May 23, 2024 16:02
encukou added a commit that referenced this pull request May 30, 2024
@miss-islington @encukou @neonene
[3.13] gh-117142: Slightly hacky fix for memory leak of StgInfo (GH-1…
322e0ad
…19424) (GH-119468)

gh-117142: Slightly hacky fix for memory leak of StgInfo (GH-119424)

Add a funciton that inlines PyObject_GetTypeData and skips
type-checking, so it doesn't need access to the CType_Type object.
This will break if the memory layout changes, but should
be an acceptable solution to enable ctypes in subinterpreters in
Python 3.13.

Mark _ctypes as safe for multiple interpreters

(cherry picked from commit a192547)

Co-authored-by: Petr Viktorin <[email protected]>
Co-authored-by: neonene <[email protected]>
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
@encukou @neonene @estyxx
pythongh-117142: Slightly hacky fix for memory leak of StgInfo (pytho…
afde92e
…nGH-119424)

Add a funciton that inlines PyObject_GetTypeData and skips
type-checking, so it doesn't need access to the CType_Type object.
This will break if the memory layout changes, but should
be an acceptable solution to enable ctypes in subinterpreters in
Python 3.13.

Mark _ctypes as safe for multiple interpreters

Co-authored-by: neonene <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ericsnowcurrently ericsnowcurrently ericsnowcurrently approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

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

3 participants

@encukou @neonene @ericsnowcurrently
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.