summaryrefslogtreecommitdiffstats
path: root/Modules/_cursesmodule.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-129813, PEP 782: Use PyBytesWriter in _curses (#138920)Victor Stinner2025-09-151-14/+10
| | | | Replace PyBytes_FromStringAndSize(NULL, size) and _PyBytes_Resize() with the new public PyBytesWriter API.
* gh-137920: Fix semantically relevant typo in `curses.window.attron` (#137940)vict-Yang2025-08-221-2/+2
|
* GH-137623: Use an AC decorator for docstring line length enforcement (#137690)Adam Turner2025-08-181-28/+56
|
* gh-108512: Add and use new replacements for PySys_GetObject() (GH-111035)Serhiy Storchaka2025-05-281-2/+1
| | | | | Add functions PySys_GetAttr(), PySys_GetAttrString(), PySys_GetOptionalAttr() and PySys_GetOptionalAttrString().
* gh-133579: consistently report C curses function failures (#134327)Bénédikt Tran2025-05-271-73/+167
| | | | | | | | | | | | | | | | Some curses module-level functions and window methods now raise a `curses.error` when a call to a C curses function fails: - Module-level functions: assume_default_colors, baudrate, cbreak, echo, longname, initscr, nl, raw, termattrs, termname, and unctrl. - Window methods: addch, addnstr, addstr, border, box, chgat, getbkgd, inch, insstr, and insnstr. In addition, `curses.window.refresh` and `curses.window.noutrefresh` now raise a `TypeError` instead of a `curses.error` when called with an incorrect number of arguments for pads. See also ee36db550076e5a9185444ffbc53eaf8157ef04c for similar changes.
* gh-134210: refactor signal handling in `_curses.window.{get_wch,getkey}` ↵Bénédikt Tran2025-05-271-15/+20
| | | | (#134646)
* gh-134210: handle signals in `_curses.window.getch` (#134326)Bénédikt Tran2025-05-271-4/+14
|
* gh-134208: remove dead AC directives for ↵Bénédikt Tran2025-05-261-173/+148
| | | | `_curses.window.{chgat,getstr,instr}` (#134325)
* gh-134209: use heap-allocated memory in `_curses.window.{instr,getstr}` ↵tigerding2025-05-201-33/+69
| | | | | | | | | | | | | | | | | | | | | | | (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` --------- 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>
* gh-125843: fix `test_curses.test_attributes` on x86-64 macOS (#134252)Bénédikt Tran2025-05-201-6/+4
| | | | | | While some `libcurses` functions are meant to return OK on success, this is not always the case for all implementations. As such, we relax the checks on the return values and allow any non-ERR value to be considered equivalent to OK.
* gh-125843: indicate which C function caused a `curses.error` (#125844)Bénédikt Tran2025-05-191-180/+355
| | | | | - Rename error helpers with a `curses_set_error_*` prefix instead of `PyCurses*`. - Cleanly report both NULL and ERR cases. - Raise `curses.error` in `is_linetouched` instead of a `TypeError`.
* bpo-44172: Keep reference to original window in curses subwindow objects ↵Michael Forney2025-05-041-8/+14
| | | | | | | | | | | | | | | | | | (GH-26226) The X/Open curses specification[0] and ncurses documentation[1] both state that subwindows must be deleted before the main window. Deleting the windows in the wrong order causes a double-free with NetBSD's curses implementation. To fix this, keep track of the original window object in the subwindow object, and keep a reference to the original for the lifetime of the subwindow. [0] https://pubs.opengroup.org/onlinepubs/7908799/xcurses/delwin.html [1] https://invisible-island.net/ncurses/man/curs_window.3x.html Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* gh-133139: Add curses.assume_default_colors() (GH-133145)Serhiy Storchaka2025-05-031-5/+36
| | | | | This is a refinement of the curses.use_default_colors() function which allows to change the color pair 0.
* gh-111178: remove redundant casts for functions with correct signatures ↵Bénédikt Tran2025-04-011-1/+1
| | | | (#131673)
* GH-131238: Core header refactor (GH-131250)Mark Shannon2025-03-171-0/+1
| | | | | * Moves most structs in pycore_ header files into pycore_structs.h and pycore_runtime_structs.h * Removes many cross-header dependencies
* gh-111178: Change Argument Clinic signature for METH_O (#130682)Victor Stinner2025-03-111-2/+2
| | | Use "PyObject*" for METH_O functions to fix an undefined behavior.
* gh-130163: Fix crashes related to PySys_GetObject() (GH-130503)Serhiy Storchaka2025-02-251-2/+6
| | | | | | | | The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed reference, has been replaced by using one of the following functions, which return a strong reference and distinguish a missing attribute from an error: _PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(), _PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString().
* gh-128911: Add PyImport_ImportModuleAttr() function (#128912)Victor Stinner2025-01-301-1/+1
| | | | | | | | | | | Add PyImport_ImportModuleAttr() and PyImport_ImportModuleAttrString() functions. * Add unit tests. * Replace _PyImport_GetModuleAttr() with PyImport_ImportModuleAttr(). * Replace _PyImport_GetModuleAttrString() with PyImport_ImportModuleAttrString(). * Remove "pycore_import.h" includes, no longer needed.
* gh-111178: fix UBSan failures in `Modules/curses*.c` (GH-128244)Bénédikt Tran2025-01-031-69/+109
| | | | | * fix UBSan failures in `_cursesmodule.c` * fix UBSan failures in `_curses_panel.c` * suppress an unused return value
* gh-123925: Fix building curses on platforms without libncursesw (GH-128405)Serhiy Storchaka2025-01-021-1/+1
|
* gh-126313: Fix a crash in curses.napms() due to incorrect error handling ↵Bénédikt Tran2024-11-031-2/+5
| | | | (GH-126351)
* gh-123961: Convert _curses to a multi-phase init module (PEP-489) (#124965)Bénédikt Tran2024-10-081-79/+113
|
* gh-123961: Convert `curses.window` static type into a heap type (#124934)Bénédikt Tran2024-10-041-69/+112
|
* gh-123961: Clean up curses C API/capsule (#124907)Bénédikt Tran2024-10-031-50/+77
|
* gh-120378: Fix crash caused by integer overflow in `curses` (#124555)Peter Bierma2024-10-021-8/+8
| | | | | | | | | This is actually an upstream problem in curses, and has been reported to them already: https://lists.gnu.org/archive/html/bug-ncurses/2024-09/msg00101.html This is a nice workaround in the meantime to prevent the segfault. Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
* gh-123961: Add a global state to _curses (#124729)Bénédikt Tran2024-09-291-175/+271
|
* gh-123290: Fix decref in _curses update_lines_cols() (#124767)Bénédikt Tran2024-09-291-1/+1
|
* gh-123961: Add `curses` prefix to global variables in `_cursesmodule.c` ↵Bénédikt Tran2024-09-131-14/+14
| | | | | (#124047) Use the `const char*` type instead of a `const *` for the encoding name.
* gh-124044: protect macros expansions in `_cursesmodules.c` using `do { ... } ↵Bénédikt Tran2024-09-131-19/+28
| | | | while (0)` (#124045)
* gh-123961: Remove global variable `ModDict` in `_cursesmodule.c` (#123962)Bénédikt Tran2024-09-131-35/+44
|
* gh-123290: fix reference leaks in the error-branches of `_cursesmodule.c` ↵Bénédikt Tran2024-09-111-147/+211
| | | | (#123953)
* gh-113565: Improve and harden detection of curses dependencies (#119816)Erlend E. Aasland2024-07-011-1/+1
| | | | | | | | | | | | | | 1. Use pkg-config to check for ncursesw/panelw. If that fails, use pkg-config to check for ncurses/panel. 2. Regardless of pkg-config output, search for curses/panel headers, so we're sure we have all defines in pyconfig.h. 3. Regardless of pkg-config output, check if libncurses or libncursesw contains the 'initscr' symbol; if it does _and_ pkg-config failed earlier, add the resulting -llib linker option to CURSES_LIBS. Ditto for 'update_panels' and PANEL_LIBS. 4. Wrap the rest of the checks with WITH_SAVE_ENV and make sure we're using updated LIBS and CPPFLAGS for those. Add the PY_CHECK_CURSES convenience macro.
* gh-117557: Improve error messages when a string, bytes or bytearray of ↵Serhiy Storchaka2024-05-281-9/+23
| | | | length 1 are expected (GH-117631)
* gh-116322: Rename PyModule_ExperimentalSetGIL to PyUnstable_Module_SetGIL ↵Petr Viktorin2024-05-061-1/+1
| | | | (GH-118645)
* gh-109617: fix ncurses incompatibility on macOS with Xcode 15 (#111258)Davide Rizzo2024-05-041-4/+13
| | | | Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* gh-116322: Add Py_mod_gil module slot (#116882)Brett Simmers2024-05-031-0/+3
| | | | | | | | | | | | | | This PR adds the ability to enable the GIL if it was disabled at interpreter startup, and modifies the multi-phase module initialization path to enable the GIL when loading a module, unless that module's spec includes a slot indicating it can run safely without the GIL. PEP 703 called the constant for the slot `Py_mod_gil_not_used`; I went with `Py_MOD_GIL_NOT_USED` for consistency with gh-104148. A warning will be issued up to once per interpreter for the first GIL-using module that is loaded. If `-v` is given, a shorter message will be printed to stderr every time a GIL-using module is loaded (including the first one that issues a warning).
* gh-110093: Replace trivial Py_BuildValue() with direct C API call (GH-110094)Serhiy Storchaka2023-10-201-4/+4
|
* gh-107913: Fix possible losses of OSError error codes (GH-107930)Serhiy Storchaka2023-08-261-1/+1
| | | | | | Functions like PyErr_SetFromErrno() and SetFromWindowsErr() should be called immediately after using the C API which sets errno or the Windows error code.
* gh-104922: remove PY_SSIZE_T_CLEAN (#106315)Inada Naoki2023-07-021-2/+0
|
* bpo-15999: Accept arbitrary values for boolean parameters. (#15609)Serhiy Storchaka2022-12-031-18/+18
| | | builtins and extension module functions and methods that expect boolean values for parameters now accept any Python object rather than just a bool or int type. This is more consistent with how native Python code itself behaves.
* gh-99300: Use Py_NewRef() in Modules/ directory (#99466)Victor Stinner2022-11-141-2/+1
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in test C files of the Modules/ directory.
* GH-90699: Remove `_Py_IDENTIFIER` usage from `_curses` module (GH-98957)Kumar Aditya2022-11-021-12/+6
|
* GH-94644: fix test_curses ref leak (GH-94647)Kumar Aditya2022-07-071-0/+1
|
* bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized ↵Eric Snow2022-02-081-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | global objects. (gh-30928) We're no longer using _Py_IDENTIFIER() (or _Py_static_string()) in any core CPython code. It is still used in a number of non-builtin stdlib modules. The replacement is: PyUnicodeObject (not pointer) fields under _PyRuntimeState, statically initialized as part of _PyRuntime. A new _Py_GET_GLOBAL_IDENTIFIER() macro facilitates lookup of the fields (along with _Py_GET_GLOBAL_STRING() for non-identifier strings). https://bugs.python.org/issue46541#msg411799 explains the rationale for this change. The core of the change is in: * (new) Include/internal/pycore_global_strings.h - the declarations for the global strings, along with the macros * Include/internal/pycore_runtime_init.h - added the static initializers for the global strings * Include/internal/pycore_global_objects.h - where the struct in pycore_global_strings.h is hooked into _PyRuntimeState * Tools/scripts/generate_global_objects.py - added generation of the global string declarations and static initializers I've also added a --check flag to generate_global_objects.py (along with make check-global-objects) to check for unused global strings. That check is added to the PR CI config. The remainder of this change updates the core code to use _Py_GET_GLOBAL_IDENTIFIER() instead of _Py_IDENTIFIER() and the related _Py*Id functions (likewise for _Py_GET_GLOBAL_STRING() instead of _Py_static_string()). This includes adding a few functions where there wasn't already an alternative to _Py*Id(), replacing the _Py_Identifier * parameter with PyObject *. The following are not changed (yet): * stop using _Py_IDENTIFIER() in the stdlib modules * (maybe) get rid of _Py_IDENTIFIER(), etc. entirely -- this may not be doable as at least one package on PyPI using this (private) API * (maybe) intern the strings during runtime init https://bugs.python.org/issue46541
* bpo-46417: _curses uses PyStructSequence_NewType() (GH-30736)Victor Stinner2022-01-211-12/+10
| | | | | | | | The _curses module now creates its ncurses_version type as a heap type using PyStructSequence_NewType(), rather than using a static type. * Move _PyStructSequence_FiniType() definition to pycore_structseq.h. * test.pythoninfo: log curses.ncurses_version.
* bpo-45855: Replaced deprecated `PyImport_ImportModuleNoBlock` with ↵Kumar Aditya2021-12-121-1/+1
| | | | PyImport_ImportModule (GH-30046)
* bpo-46000: Improve NetBSD curses compatibility (GH-29947)Thomas Klausner2021-12-101-2/+2
|
* bpo-43974: Move Py_BUILD_CORE_MODULE into module code (GH-29157)Christian Heimes2021-10-221-0/+4
| | | | | | | | | | | | | | setup.py no longer defines Py_BUILD_CORE_MODULE. Instead every module defines the macro before #include "Python.h" unless Py_BUILD_CORE_BUILTIN is already defined. Py_BUILD_CORE_BUILTIN is defined for every module that is built by Modules/Setup. The PR also simplifies Modules/Setup. Makefile and makesetup already define Py_BUILD_CORE_BUILTIN and include Modules/internal for us. Signed-off-by: Christian Heimes <christian@python.org>
* bpo-45067 - Verify the version of ncurses for extended color support feature ↵Senthil Kumaran2021-09-091-2/+2
| | | | | | | | | | | | | | usage. (GH-28260) * issue45067 - Fix _curses compilation in CentOS 7. Verify the version of ncurses for extended color support feature usage. The function extended_color_content was introduced in 2017. The ncurses-devel package in CentOS 7 had a older version ncurses resulted in compilation error. For compiling ncurses with extended color support, we verify the version of the ncurses library. Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* Update URLs in comments and metadata to use HTTPS (GH-27458)Noah Kantrowitz2021-07-301-1/+1
|