Skip to content
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

configure doesn't disable ncurses extended_pair_content() if ncursesw is not available #123925

Open
madscientist opened this issue Sep 10, 2024 · 2 comments
Labels
build The build process and cross-build extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@madscientist
Copy link

madscientist commented Sep 10, 2024

Bug report

Bug description:

On a system I'm trying to build Python for, I have libncurses.so available but not libncursesw.so.

Unfortunately, although this is not documented directly anywhere I can find, the ncurses extended_pair_content() and extended_color_content() functions (and the init_extended_*() functions) are not available in libncurses, they are only available in libncursesw. This causes the compilation of Python to fail:

checking for curses.h... yes
checking for ncurses.h... yes
checking for ncursesw... no
checking for initscr in -lncursesw... no
checking for ncurses... no
checking for initscr in -lncurses... yes
checking curses module flags... ncurses (CFLAGS: , LIBS: -lncurses)
checking for panel.h... yes
checking for panel... no
checking for update_panels in -lpanel... yes
checking panel flags... panel (CFLAGS: , LIBS: -lpanel)
checking for term.h... yes
checking whether mvwdelch is an expression... yes
checking whether WINDOW has _flags... yes
checking for curses function is_pad... yes
checking for curses function is_term_resized... yes
checking for curses function resize_term... yes
checking for curses function resizeterm... yes
checking for curses function immedok... yes
checking for curses function syncok... yes
checking for curses function wchgat... yes
checking for curses function filter... yes
checking for curses function has_key... yes
checking for curses function typeahead... yes
checking for curses function use_env... yes
  ...
checking for stdlib extension module _curses... yes
checking for stdlib extension module _curses_panel... yes
  ...
86_64-rl84-linux-gnu-gcc -pthread -shared      Modules/_cursesmodule.o -lncurses  -o Modules/_curses.cpython-312-x86_64-linux-gnu.so
  ...
./python -E -c 'import sys ; from sysconfig import get_platform ; print("%s-%d.%
d" % (get_platform(), *sys.version_info[:2]))' >platform
[ERROR] _curses failed to import: /data/src/python3/Linux-Release-make/bld.python3/build/lib.linux-x86_64-3.12/_curses.cpython-312-x86_64-linux-gnu.so: undefined symbol: extended_pair_content

If I try a simple program:

#include <ncurses.h>
#include <stdio.h>

int main(void)
{
    initscr();
    start_color();
    {
        int f, b;
        int r = extended_pair_content(1, &f, &b);

        printf("r=%d f=%d b=%d\n", r, f, b);
    }
    endwin();
    return 0;
}

then it works if I link with -lncursesw:

$ gcc -o /tmp/foo /tmp/foo.c -lncursesw
$

But fails if I only link with -lncurses:

$ gcc -o /tmp/foo /tmp/foo.c -lncurses
/bin/ld: /tmp/cccHNZsN.o: in function `main':
foo.c:(.text+0x85): undefined reference to `extended_pair_content'
/bin/ld: foo.c:(.text+0x107): undefined reference to `extended_color_content'
collect2: error: ld returned 1 exit status
$

I believe this patch will fix it:

--- a/Modules/_cursesmodule.c   2024-09-06 15:03:47.000000000 -0400
+++ b/Modules/_cursesmodule.c   2024-09-10 17:41:55.124440110 -0400
@@ -139,7 +139,7 @@
 #define STRICT_SYSV_CURSES
 #endif

-#if NCURSES_EXT_FUNCS+0 >= 20170401 && NCURSES_EXT_COLORS+0 >= 20170401
+#if HAVE_NCURSESW && NCURSES_EXT_FUNCS+0 >= 20170401 && NCURSES_EXT_COLORS+0 >\
= 20170401
 #define _NCURSES_EXTENDED_COLOR_FUNCS   1
 #else
 #define _NCURSES_EXTENDED_COLOR_FUNCS   0

CPython versions tested on:

3.12

Operating systems tested on:

Linux

@madscientist madscientist added the type-bug An unexpected behavior, bug, or error label Sep 10, 2024
@serhiy-storchaka
Copy link
Member

What is the value of NCURSES_EXT_FUNCS and NCURSES_EXT_COLORS? How is extended_pair_content defined in the header file on your system (if it is)?

@picnixz picnixz added extension-modules C modules in the Modules dir build The build process and cross-build labels Sep 11, 2024
@madscientist
Copy link
Author

The definition of these in curses.h appears thusly:

#if 1
#undef NCURSES_EXT_COLORS
#define NCURSES_EXT_COLORS 20180224
    int         ext_color;      /* color pair, must be more than 16-bits */
#endif
  ...
/*
 * These functions are extensions - not in X/Open Curses.
 */
#if 1
#undef  NCURSES_EXT_FUNCS
#define NCURSES_EXT_FUNCS 20180224
  ...
extern NCURSES_EXPORT(int) extended_color_content(int, int *, int *, int *);
extern NCURSES_EXPORT(int) extended_pair_content(int, int *, int *);
  ...
extern NCURSES_EXPORT(int) init_extended_color(int, int, int, int);
extern NCURSES_EXPORT(int) init_extended_pair(int, int, int);

Just to note, this is by no means some bizarre custom version of Linux. This is Red Hat Enterprise Linux 8.6. The only unusual thing is that the ncursesw library is not present.

Also I see the same problem on Ubuntu 20.04, which has this version:

#define NCURSES_EXT_COLORS 20200212
#define NCURSES_EXT_FUNCS 20200212

Right now I don't have a newer system but I can try at home later with Ubuntu 24.04 LTS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build The build process and cross-build extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
Projects
Status: No status
Development

No branches or pull requests

3 participants