Title: curses: detect optional functions with configure probes instead of assuming ncurses · Issue #152502 · python/cpython · GitHub
Open Graph Title: curses: detect optional functions with configure probes instead of assuming ncurses · Issue #152502 · python/cpython
X Title: curses: detect optional functions with configure probes instead of assuming ncurses · Issue #152502 · python/cpython
Description: Several functions in Modules/_cursesmodule.c are called unconditionally or gated only by the ncurses-specific NCURSES_EXT_FUNCS macro. Both break building or using the module against curses implementations other than ncursesw — narrow (n...
Open Graph Description: Several functions in Modules/_cursesmodule.c are called unconditionally or gated only by the ncurses-specific NCURSES_EXT_FUNCS macro. Both break building or using the module against curses impleme...
X Description: Several functions in Modules/_cursesmodule.c are called unconditionally or gated only by the ncurses-specific NCURSES_EXT_FUNCS macro. Both break building or using the module against curses impleme...
Opengraph URL: https://github.com/python/cpython/issues/152502
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"curses: detect optional functions with configure probes instead of assuming ncurses","articleBody":"Several functions in `Modules/_cursesmodule.c` are called unconditionally or gated only by the ncurses-specific `NCURSES_EXT_FUNCS` macro. Both break building or using the module against curses implementations other than ncursesw — narrow (non-wide) ncurses, and third-party curses such as NetBSD curses — even when the library provides the function.\n\n**Unconditionally-called functions that aren't universally present** (no `HAVE_CURSES_*` guard, so a library lacking them fails to link):\n\n- `scr_dump`/`scr_restore`/`scr_init`/`scr_set` — the whole family is absent from NetBSD curses.\n- `key_defined` — absent from NetBSD curses (which has `define_key`/`keyok`).\n- `term_attrs` — the X/Open *wide* attribute query, present only in `libncursesw`, so missing from a narrow `-lncurses` build.\n\n**Functions gated by `NCURSES_EXT_FUNCS`** that NetBSD implements without defining that macro, so the module silently drops them:\n\n- `define_key`, `keyok`, `set_escdelay`, `set_tabsize`, `get_escdelay`, `get_tabsize`.\n\n**Proposed change:** detect each with a configure capability probe and gate on `HAVE_CURSES_*`.\n\n- `PY_CHECK_CURSES_FUNC` probes for `scr_dump` (one probe gates the inseparable family), `key_defined`, `term_attrs`, `define_key`, `keyok`, `set_escdelay`, `set_tabsize`.\n- `get_escdelay`/`get_tabsize` read the `ESCDELAY`/`TABSIZE` *variables*, which some libraries declare as `extern int` rather than macros, so a function probe doesn't fit. Add a small `PY_CHECK_CURSES_VAR` macro (tests that `int x = ESCDELAY;` compiles) and gate the getters on `HAVE_CURSES_ESCDELAY`/`HAVE_CURSES_TABSIZE`.\n\nNone of these are in X/Open Curses; they are ncurses extensions (NetBSD provides compatible ones), so capability-gating is the correct treatment, and a probe is more portable than conditioning on `NCURSES_VERSION`.\n\nNo behaviour change on standard ncursesw (all macros defined). `test_curses` passes and is refleak-clean on ncursesw, narrow ncurses, and NetBSD curses, under UTF-8 and 8-bit locales. `test_env_queries` calls `curses.term_attrs()` unconditionally and needs a `hasattr` guard for the narrow case.\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-152504\n* gh-152589\n* gh-152602\n* gh-152603\n* gh-152705\n* gh-152707\n* gh-152734\n* gh-152735\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/serhiy-storchaka","@type":"Person","name":"serhiy-storchaka"},"datePublished":"2026-06-28T16:14:54.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/152502/cpython/issues/152502"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5e3f7d46-18f0-2205-60b7-9fca24f8ffa4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E4EC:EBB89:278112:35E6DA:6A513FD4 |
| html-safe-nonce | 26ba215d6ecccb79e38f3033f5aed4e1fc65d01da4d6876793b5baa9c21d41bc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNEVDOkVCQjg5OjI3ODExMjozNUU2REE6NkE1MTNGRDQiLCJ2aXNpdG9yX2lkIjoiNjM4NTIxMjA2MjY1ODgwNTcxNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 59b8bb26b1b5920a8f88fd39b6c28486bf92480c33c2df386e58b4ae0f2b490c |
| hovercard-subject-tag | issue:4762836516 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/152502/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6d51d41b097e682d72fa251fc684b4010a17bed5a1c39ff1c353437dc3ee60a7/python/cpython/issues/152502 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6d51d41b097e682d72fa251fc684b4010a17bed5a1c39ff1c353437dc3ee60a7/python/cpython/issues/152502 |
| og:image:alt | Several functions in Modules/_cursesmodule.c are called unconditionally or gated only by the ncurses-specific NCURSES_EXT_FUNCS macro. Both break building or using the module against curses impleme... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | serhiy-storchaka |
| hostname | github.com |
| expected-hostname | github.com |
| None | e840f405b2718e8f2d55aafa9ff27dbce17e29d0c253011d05ea0fea3c78baff |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e876f00c5723f6080b9d294e4958fd4d506e6faf |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width