8000 gh-134209: use heap-allocated memory in `_curses.window.{instr,getstr}` by zydtiger · Pull Request #134283 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-134209: use heap-allocated memory in _curses.window.{instr,getstr} #134283

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 34 commits into from
May 20, 2025

Conversation

zydtiger
Copy link
Contributor
@zydtiger zydtiger commented May 19, 2025

Allocated curses buffer on heap and modified documentation to show this change.


📚 Documentation preview 📚: https://cpython-previews--134283.org.readthedocs.build/

@python-cla-bot
Copy link
python-cla-bot bot commented May 19, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link
bedevere-app bot commented May 19, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@gpshead gpshead added the sprint label May 19, 2025
@gpshead gpshead self-assigned this May 19, 2025
< 10000 /details-collapsible>
@picnixz picnixz changed the title gh-134209: Allocating curses buffer on heap gh-134209: use heap-allocated memory in _curses.window.{instr,getstr} May 20, 2025
@picnixz
Copy link
Member
picnixz commented May 20, 2025

Ha. As I feared:

Traceback (most recent call last):
  File "/Users/runner/work/cpython/cpython/Lib/test/test_curses.py", line 379, in test_getstr
    self.assertEqual(win.getstr(3, 1, 2), b'Lo')
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: b'' != b'Lo'

I suspect that the value being returned is not reliable for some reason. Unfortunately, we'll need to use strlen I think. That's one thing I hate with libcurses, namely most of the return values semantics are implementation-defined -_-

zydtiger and others added 6 commits May 20, 2025 10:40
add version changed message

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
add version changed message

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…nhTcF.rst

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@picnixz
Copy link
Member
picnixz commented May 20, 2025

By the way, no need to hit the "update branch" button if the CI is green. Usually it's only to pull newest (infra-related) changes and/or patches for tests that were already failin 8000 g.

Copy link
Member
@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

Final nitpick. Since I'll be re-changing the logic a bit in #134325, I think this one is good. After the commit, I'll run the build bots.

@picnixz picnixz added 🔨 test-with-buildbots Test PR w/ buildbots; report in status section 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section labels May 20, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @picnixz for commit 6510d09 🤖

Results will be shown at:

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

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

@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @picnixz for commit 6510d09 🤖

Results will be shown at:

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

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

@bedevere-bot bedevere-bot removed 🔨 test-with-refleak-buildbots Test PR w/ refleak buildbots; report in status section 🔨 test-with-buildbots Test PR w/ buildbots; report in status section labels May 20, 2025
@picnixz
Copy link
Member
picnixz commented May 20, 2025

Now, do NOT commit anything until all build bots are done (so don't hit "update branch") otherwise the report will be lost on GH.

Thanks for your first contribution!

@zydtiger
Copy link
Contributor Author

Thank you so much to guide me through the process! Glad that I'm able to contribute.

@gpshead gpshead enabled auto-merge (squash) May 20, 2025 20:14
@gpshead gpshead added the needs backport to 3.14 bugs and security fixes label May 20, 2025
@gpshead gpshead merged commit aadda87 into python:main May 20, 2025
41 checks passed
@miss-islington-app
Copy link

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 20, 2025
…getstr}` (pythonGH-134283)

* made curses buffer heap allocated instead of stack
* change docs to explicitly mention the max buffer size
* changing GetStr() function to behave similarly too
* Update Doc/library/curses.rst
* Update instr with proper return error handling
* Update Modules/_cursesmodule.c
* change to strlen and better memory safety
* change from const int to Py_ssize_t
* add mem allocation guard
* update versionchanged to mention it was an increase.
* explicitly use versionchanged 3.14 as that is its own branch now.

TESTED: `python -m test -u curses test_curses`

---------
(cherry picked from commit aadda87)

Co-authored-by: tigerding <43339228+zydtiger@users.noreply.github.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@bedevere-app
Copy link
bedevere-app bot commented May 20, 2025

GH-134391 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 May 20, 2025
gpshead added a commit that referenced this pull request May 20, 2025
…,getstr}` (GH-134283) (#134391)

gh-134209: use heap-allocated memory in `_curses.window.{instr,getstr}` (GH-134283)

* made curses buffer heap allocated instead of stack
* change docs to explicitly mention the max buffer size
* changing GetStr() function to behave similarly too
* Update Doc/library/curses.rst
* Update instr with proper return error handling
* Update Modules/_cursesmodule.c
* change to strlen and better memory safety
* change from const int to Py_ssize_t
* add mem allocation guard
* update versionchanged to mention it was an increase.
* explicitly use versionchanged 3.14 as that is its own branch now.

TESTED: `python -m test -u curses test_curses`

---------
(cherry picked from commit aadda87)

Co-authored-by: tigerding <43339228+zydtiger@users.noreply.github.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@picnixz
Copy link
Member
picnixz commented May 22, 2025

Oh so you treated it as a bug fix for 3.14/3.15 only? I'm ok although I would have considered this a feature but since it's scope is really small, it's fine IMO.

lkollar pushed a commit to lkollar/cpython that referenced this pull request May 26, 2025
…getstr}` (pythonGH-134283)

* made curses buffer heap allocated instead of stack
* change docs to explicitly mention the max buffer size
* changing GetStr() function to behave similarly too
* Update Doc/library/curses.rst
* Update instr with proper return error handling
* Update Modules/_cursesmodule.c
* change to strlen and better memory safety
* change from const int to Py_ssize_t
* add mem allocation guard
* update versionchanged to mention it was an increase.
* explicitly use versionchanged 3.14 as that is its own branch now.

TESTED: `python -m test -u curses test_curses`

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0