Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions ext/curses/curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@
# define USE_MOUSE 1
#endif

#if defined(NCURSES_EXT_COLORS) && defined(NCURSES_EXT_FUNCS)
# define SUPPORT_EXTENDED_COLORS 1
#else
# define SUPPORT_EXTENDED_COLORS 0
#endif
Comment on lines +85 to +89
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

SUPPORT_EXTENDED_COLORS is derived only from NCURSES_EXT_COLORS/NCURSES_EXT_FUNCS (header-level macros) and no longer incorporates the extconf feature probes (HAVE_INIT_EXTENDED_PAIR, HAVE_INIT_EXTENDED_COLOR, etc.). That can make builds less robust in header/library mismatch scenarios (e.g., headers advertise extended support but the linked curses library lacks one of the extended_* symbols), leading to compile/link failures. Consider defining SUPPORT_EXTENDED_COLORS to also require the relevant HAVE_* macros (or keeping the per-call #ifdef HAVE_... guards) so we only call extended APIs when extconf verified they exist in the linked library.

Copilot uses AI. Check for mistakes.

#define OBJ2CHTYPE rb_obj2chtype_inline

static inline chtype
Expand Down Expand Up @@ -1321,7 +1327,7 @@ curses_init_pair(VALUE obj, VALUE pair, VALUE f, VALUE b)
{
/* may have to raise exception on ERR */
curses_stdscr();
#ifdef HAVE_INIT_EXTENDED_PAIR
#if SUPPORT_EXTENDED_COLORS
return (init_extended_pair(NUM2INT(pair), NUM2INT(f), NUM2INT(b)) == OK) ? Qtrue : Qfalse;
#else
return (init_pair(NUM2INT(pair),NUM2INT(f),NUM2INT(b)) == OK) ? Qtrue : Qfalse;
Expand Down Expand Up @@ -1349,7 +1355,7 @@ curses_init_color(VALUE obj, VALUE color, VALUE r, VALUE g, VALUE b)
{
/* may have to raise exception on ERR */
curses_stdscr();
#ifdef HAVE_INIT_EXTENDED_COLOR
#if SUPPORT_EXTENDED_COLORS
return (init_extended_color(NUM2INT(color), NUM2INT(r),
NUM2INT(g), NUM2INT(b)) == OK) ? Qtrue : Qfalse;
#else
Expand Down Expand Up @@ -1407,7 +1413,7 @@ static VALUE
curses_color_content(VALUE obj, VALUE color)
{
curses_stdscr();
#ifdef HAVE_EXTENDED_COLOR_CONTENT
#if SUPPORT_EXTENDED_COLORS
{
int r, g, b;
if (extended_color_content(NUM2INT(color), &r, &g, &b) == ERR)
Expand Down Expand Up @@ -1451,7 +1457,7 @@ static VALUE
curses_pair_content(VALUE obj, VALUE pair)
{
curses_stdscr();
#ifdef HAVE_EXTENDED_PAIR_CONTENT
#if SUPPORT_EXTENDED_COLORS
{
int f, b;
if (extended_pair_content(NUM2INT(pair), &f, &b) == ERR)
Expand Down Expand Up @@ -1501,14 +1507,12 @@ curses_pair_number(VALUE obj, VALUE attrs)
* Document-method: Curses.support_extended_colors?
*
* Returns +true+ if the ncurses library was compiled with extended color
* support (i.e., init_extended_pair, init_extended_color, etc. are available),
* +false+ otherwise.
* support, +false+ otherwise.
*/
static VALUE
curses_support_extended_colors(VALUE obj)
{
#if defined(HAVE_INIT_EXTENDED_PAIR) && defined(HAVE_INIT_EXTENDED_COLOR) && \
defined(HAVE_EXTENDED_COLOR_CONTENT) && defined(HAVE_EXTENDED_PAIR_CONTENT)
#if SUPPORT_EXTENDED_COLORS
return Qtrue;
#else
return Qfalse;
Expand Down
Loading