Skip to content

gh-134989: Fix Py_RETURN_NONE in the limited C API #135165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jun 5, 2025

Fix Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE macros in the limited C API 3.11 and older: don't treat Py_None, Py_True and Py_False as immortal.

@vstinner
Copy link
Member Author

vstinner commented Jun 5, 2025

Fix Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE macros in the
limited C API 3.11 and older: don't treat Py_None, Py_True and
Py_False as immortal.
@encukou encukou merged commit 9258f3d into python:main Jun 5, 2025
43 checks passed
@encukou encukou added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jun 5, 2025
@miss-islington-app
Copy link

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

@miss-islington-app
Copy link

Thanks @vstinner for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@encukou
Copy link
Member

encukou commented Jun 5, 2025

Thank you!

@miss-islington-app
Copy link

Sorry, @vstinner and @encukou, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 9258f3da9175134d03f2c8c7c7eed223802ad945 3.13

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 5, 2025
…5165)

Fix Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE macros in the
limited C API 3.11 and older:
Don't treat Py_None, Py_True and Py_False as immortal.
(cherry picked from commit 9258f3d)

Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-app
Copy link

bedevere-app bot commented Jun 5, 2025

GH-135178 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Jun 5, 2025
@vstinner vstinner deleted the return_none branch June 5, 2025 13:35
vstinner added a commit that referenced this pull request Jun 5, 2025
…#135178)

gh-134989: Fix Py_RETURN_NONE in the limited C API (GH-135165)

Fix Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE macros in the
limited C API 3.11 and older:
Don't treat Py_None, Py_True and Py_False as immortal.
(cherry picked from commit 9258f3d)

Co-authored-by: Victor Stinner <vstinner@python.org>
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot s390x RHEL8 Refleaks 3.x (tier-3) has failed when building commit 9258f3d.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/75/builds/2811) and take a look at the build logs.
  4. Check if the failure is related to this commit (9258f3d) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/75/builds/2811

Failed tests:

  • test.test_multiprocessing_fork.test_processes

Failed subtests:

  • test_interrupt - test.test_multiprocessing_fork.test_processes.WithProcessesTestProcess.test_interrupt

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/test/_test_multiprocessing.py", line 588, in test_interrupt
    exitcode = self._kill_process(multiprocessing.Process.interrupt)
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/test/_test_multiprocessing.py", line 570, in _kill_process
    self.assertEqual(join(), None)
                     ~~~~^^
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/test/_test_multiprocessing.py", line 250, in __call__
    return self.func(*args, **kwds)
           ~~~~~~~~~^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/multiprocessing/process.py", line 156, in join
    res = self._popen.wait(timeout)
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/multiprocessing/popen_fork.py", line 44, in wait
    return self.poll(os.WNOHANG if timeout == 0.0 else 0)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/multiprocessing/popen_fork.py", line 28, in poll
    pid, sts = os.waitpid(self.pid, flag)
               ~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/test/_test_multiprocessing.py", line 566, in handler
    raise RuntimeError('join took too long: %s' % p)
RuntimeError: join took too long: <Process name='Process-1' pid=3071468 parent=3071466 started daemon>


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/multiprocessing/process.py", line 320, in _bootstrap
    self.run()
    ~~~~~~~~^^
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/test/_test_multiprocessing.py", line 518, in _sleep_some_event
    time.sleep(100)
    ~~~~~~~~~~^^^^^
KeyboardInterrupt
k


Traceback (most recent call last):
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/test/_test_multiprocessing.py", line 588, in test_interrupt
    exitcode = self._kill_process(multiprocessing.Process.interrupt)
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/test/_test_multiprocessing.py", line 570, in _kill_process
    self.assertEqual(join(), None)
                     ~~~~^^
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/test/_test_multiprocessing.py", line 250, in __call__
    return self.func(*args, **kwds)
           ~~~~~~~~~^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/multiprocessing/process.py", line 156, in join
    res = self._popen.wait(timeout)
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/multiprocessing/popen_fork.py", line 44, in wait
    return self.poll(os.WNOHANG if timeout == 0.0 else 0)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/multiprocessing/popen_fork.py", line 28, in poll
    pid, sts = os.waitpid(self.pid, flag)
               ~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/home/buildbot/buildarea/3.x.cstratak-rhel8-s390x.refleak/build/Lib/test/_test_multiprocessing.py", line 566, in handler
    raise RuntimeError('join took too long: %s' % p)
RuntimeError: join took too long: <Process name='Process-1318' pid=2971578 parent=2961969 started daemon>

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot iOS ARM64 Simulator 3.14 (tier-3) has failed when building commit e11d4a1.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1722/builds/221) and take a look at the build logs.
  4. Check if the failure is related to this commit (e11d4a1) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1722/builds/221

Failed tests:

  • test.test_concurrent_futures.test_as_completed

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/Users/buildbot/Library/Developer/XCTestDevices/C2B3D85E-C07E-4770-A9ED-90BBDD9550C4/data/Containers/Bundle/Application/173B69A2-D274-49E9-83D1-CD70E88F4078/iOSTestbed.app/python/lib/python3.14/concurrent/futures/thread.py", line 99, in _worker
    ctx.initialize()
    ~~~~~~~~~~~~~~^^
  File "/Users/buildbot/Library/Developer/XCTestDevices/C2B3D85E-C07E-4770-A9ED-90BBDD9550C4/data/Containers/Bundle/Application/173B69A2-D274-49E9-83D1-CD70E88F4078/iOSTestbed.app/python/lib/python3.14/concurrent/futures/interpreter.py", line 115, in initialize
    self.interpid = _interpreters.create(reqrefs=True)
                    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
interpreters.InterpreterError: interpreter creation failed


Traceback (most recent call last):
  File "/Users/buildbot/Library/Developer/XCTestDevices/C2B3D85E-C07E-4770-A9ED-90BBDD9550C4/data/Containers/Bundle/Application/173B69A2-D274-49E9-83D1-CD70E88F4078/iOSTestbed.app/python/lib/python3.14/test/test_concurrent_futures/test_as_completed.py", line 63, in test_future_times_out
    self.assertEqual(completed_futures, already_completed)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Items in the first set but not the second:
<Future at 0x10ca99890 state=finished raised BrokenInterpreterPool>

vstinner added a commit to vstinner/cpython that referenced this pull request Jun 5, 2025
…5165)

Fix Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE macros in the
limited C API 3.11 and older:
Don't treat Py_None, Py_True and Py_False as immortal.

(cherry picked from commit 9258f3d)
@bedevere-app
Copy link

bedevere-app bot commented Jun 5, 2025

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

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Jun 5, 2025
vstinner added a commit that referenced this pull request Jun 5, 2025
…#135182)

gh-134989: Fix Py_RETURN_NONE in the limited C API (GH-135165)

Fix Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE macros in the
limited C API 3.11 and older:
Don't treat Py_None, Py_True and Py_False as immortal.

(cherry picked from commit 9258f3d)
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Windows10 3.13 (tier-1) has failed when building commit 922dc2c.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1501/builds/1150) and take a look at the build logs.
  4. Check if the failure is related to this commit (922dc2c) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1501/builds/1150

Failed tests:

  • test_sysconfig

Failed subtests:

  • test_config_vars_depend_on_site_initialization - test.test_sysconfig.TestSysConfig.test_config_vars_depend_on_site_initialization
  • testZip64LargeFile - test.test_zipimport.UncompressedZipImportTestCase.testZip64LargeFile

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (test.test_zipimport.UncompressedZipImportTestCase.testTraceback) ... ok


Traceback (test.test_zipimport.CompressedZipImportTestCase.testTraceback) ... ok


Traceback (most recent call last):
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\test\test_sysconfig.py", line 605, in test_config_vars_depend_on_site_initialization
    with self.venv() as venv:
         ~~~~~~~~~^^
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\contextlib.py", line 148, in __exit__
    next(self.gen)
    ~~~~^^^^^^^^^^
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\test\support\venv.py", line 27, in from_tmpdir
    with tempfile.TemporaryDirectory(prefix=prefix, dir=dir, delete=delete) as tmpdir:
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\tempfile.py", line 950, in __exit__
    self.cleanup()
    ~~~~~~~~~~~~^^
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\tempfile.py", line 954, in cleanup
    self._rmtree(self.name, ignore_errors=self._ignore_cleanup_errors)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\tempfile.py", line 934, in _rmtree
    _shutil.rmtree(name, onexc=onexc)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\shutil.py", line 790, in rmtree
    return _rmtree_unsafe(path, onexc)
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\shutil.py", line 629, in _rmtree_unsafe
    onexc(os.unlink, fullname, err)
    ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\tempfile.py", line 909, in onexc
    _os.unlink(path)
    ~~~~~~~~~~^^^^^^
PermissionError: [WinError 5] Access is denied: 'd:\\temp\\test_python_2724mgmb\\test.test_sysconfig.TestSysConfig.test_config_vars_depend_on_site_initialization-venv-eceau010\\Scripts\\python_d.exe'


Traceback (most recent call last):
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\test\test_zipimport.py", line 891, in testZip64LargeFile
    with open(TEMP_ZIP, "wb") as f:
         ~~~~^^^^^^^^^^^^^^^^
OSError: [Errno 28] No space left on device


Traceback (most recent call last):
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\test\test_sysconfig.py", line 605, in test_config_vars_depend_on_site_initialization
    with self.venv() as venv:
         ~~~~~~~~~^^
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\contextlib.py", line 148, in __exit__
    next(self.gen)
    ~~~~^^^^^^^^^^
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\test\support\venv.py", line 27, in from_tmpdir
    with tempfile.TemporaryDirectory(prefix=prefix, dir=dir, delete=delete) as tmpdir:
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\tempfile.py", line 950, in __exit__
    self.cleanup()
    ~~~~~~~~~~~~^^
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\tempfile.py", line 954, in cleanup
    self._rmtree(self.name, ignore_errors=self._ignore_cleanup_errors)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\tempfile.py", line 934, in _rmtree
    _shutil.rmtree(name, onexc=onexc)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\shutil.py", line 790, in rmtree
    return _rmtree_unsafe(path, onexc)
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\shutil.py", line 629, in _rmtree_unsafe
    onexc(os.unlink, fullname, err)
    ~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\tempfile.py", line 909, in onexc
    _os.unlink(path)
    ~~~~~~~~~~^^^^^^
PermissionError: [WinError 5] Access is denied: 'd:\\temp\\test_python_dc777d6u\\test.test_sysconfig.TestSysConfig.test_config_vars_depend_on_site_initialization-venv-4x1wzsmp\\Scripts\\python_d.exe'


Traceback (most recent call last):
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\shutil.py", line 625, in _rmtree_unsafe
    os.unlink(fullname)
    ~~~~~~~~~^^^^^^^^^^
PermissionError: [WinError 5] Access is denied: 'd:\\temp\\test_python_dc777d6u\\test.test_sysconfig.TestSysConfig.test_config_vars_depend_on_site_initialization-venv-4x1wzsmp\\Scripts\\python_d.exe'


Traceback (most recent call last):
  File "D:\buildarea\3.13.bolen-windows10\build\Lib\shutil.py", line 625, in _rmtree_unsafe
    os.unlink(fullname)
    ~~~~~~~~~^^^^^^^^^^
PermissionError: [WinError 5] Access is denied: 'd:\\temp\\test_python_2724mgmb\\test.test_sysconfig.TestSysConfig.test_config_vars_depend_on_site_initialization-venv-eceau010\\Scripts\\python_d.exe'

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.

4 participants