Skip to content

curses: remove ncurses assumptions from the module and its tests #154934

Description

@serhiy-storchaka

Bug report

The curses module and its tests assume in several places that the library behind them is ncurses.

PyCurses_ConvertToChtype() and PyCurses_ConvertToCchar_t() parse the integer forms of addch() and friends through a signed long, and attr_converter() through an unsigned long. The width of a chtype is up to the library: with a 64-bit one, addch(ord('A') | curses.color_pair(589823)) fails with OverflowError. Parsing as unsigned long long fixes it and changes nothing for a narrower chtype.

test_curses decides what a cell can hold by probing for a function, and assumes throughout that the integer form of a character is its locale byte and that inch() returns that byte. Exposing whether the module was built for wide characters (_curses._wide_character_support) lets it ask directly.

Textbox._decode() masks an integer keystroke with A_CHARTEXT, which is the character field of a cell rather than a byte, and _printable_key() calls anything up to 0xff printable although key codes need not start above a byte.

None of this changes behaviour on ncurses, where chtype is 32 bits, A_CHARTEXT is 0xff and KEY_MIN is above a byte. It is the part of gh-85796 that is not specific to PDCurses.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions