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-157649: Restore safe C++ refcount macro temporaries by sankalpsthakur · Pull Request #157718 · python/cpython

Conversation

@sankalpsthakur

@sankalpsthakur sankalpsthakur commented Sep 18, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Fixes #157649.

Use the existing memcpy() implementations of Py_CLEAR, Py_SETREF and Py_XSETREF for C++, as suggested in the issue discussion. decltype() can bind their temporary to an array element or reference, so overwriting the destination decrements the wrong pointer. The C paths are unchanged.

The C++ regression exercises all three macros with array elements, references, NULL destinations, single evaluation and concrete object pointers. Py_CLEAR() also runs in the limited-API build. Thanks to Lucas Colley for the report/bisection and Victor Stinner for the fallback approach.

Validation

Original before/after run, Ubuntu x86-64, GCC/g++ 13.3, debug CPython 3.16 built from 8542958:

  • Test-only C++11 regression fails on unchanged headers with the old-object refcount assertion after Py_SETREF.
  • Fixed test_cppext and test_cext: 14 passed, 1 Windows-only C++14 skip. Covers C++03/C++11, limited API, C99/C11 and strict compiler flags.
  • git diff --check passes.

That fork run covered only the extension suites. Subsequently, upstream Tests run 35367131812 completed successfully on head a66a922; lint and label checks also pass. The follow-up commit changes only the requested source comment. No NumPy rebuild is claimed.

AI assistance: ChatGPT assisted with implementation and validation.

  • Issue: Py_CLEAR/Py_SETREF() regression on the main branch with C++: SEGV with simple numpy program #157649

Sorry, something went wrong.

Uh oh!

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

All reactions
@sankalpsthakur
pythongh-157649: Restore safe C++ refcount macro temporaries
f7d703b
Use the existing memcpy fallback for C++ and test array items, references, single evaluation and concrete object pointers.

AI assistance: ChatGPT assisted with implementation and validation. The regression and fallback approach follow the issue discussion.
@python-cla-bot

python-cla-bot Bot commented Sep 18, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot mentioned this pull request Sep 18, 2026
Py_CLEAR/Py_SETREF() regression on the main branch with C++: SEGV with simple numpy program #157649
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Sep 18, 2026
vstinner
vstinner reviewed Sep 18, 2026
View reviewed changes
Comment thread Lib/test/test_cppext/extension.cpp Resolved

Uh oh!

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

Comment thread Lib/test/test_cppext/extension.cpp Resolved

Uh oh!

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

@sankalpsthakur
sankalpsthakur force-pushed the fix/gh157649-cpp-refcount-lvalues branch from 05dd746 to f7d703b Compare September 18, 2026 15:42
@cursor
cursor Bot force-pushed the fix/gh157649-cpp-refcount-lvalues branch from 968de3e to c2d26be Compare September 18, 2026 16:11
@sankalpsthakur
pythongh-157649: name Py_SETREF/Py_XSETREF/Py_CLEAR in regression com…
a66a922
…ment

Address Victor Stinner review: mention the tested macros in the source comment above test_refcount_lvalues().
@cursor
cursor Bot force-pushed the fix/gh157649-cpp-refcount-lvalues branch from c2d26be to a66a922 Compare September 18, 2026 16:12
@picnixz picnixz closed this Sep 18, 2026
@picnixz

picnixz commented Sep 18, 2026

Copy link
Copy Markdown
Member

The AI is not just an assistance.It is writjng everything. I am not considering this a human PR enough and this does exceed the realm of acceptable use.

All reactions

Sorry, something went wrong.

Uh oh!

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

@sankalpsthakur

sankalpsthakur commented Sep 19, 2026

Copy link
Copy Markdown
Author

The AI is not just an assistance.It is writjng everything. I am not considering this a human PR enough and this does exceed the realm of acceptable use.

That is not true but your call

All reactions

Sorry, something went wrong.

Uh oh!

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

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

Reviewers

@vstinner vstinner vstinner left review comments

Uh oh!

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

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Py_CLEAR/Py_SETREF() regression on the main branch with C++: SEGV with simple numpy program

Uh oh!

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

3 participants

@sankalpsthakur @picnixz @vstinner
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.