From 82a809e2dbaa3eddfc1d933c8e1b7cc7d891ec9f Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Thu, 23 Sep 2021 09:53:38 +0200 Subject: [PATCH] Check for tputs type via cmake Instead of testing for ncurses and netbsd. Fixes #8087. --- cmake/ConfigureChecks.cmake | 19 ++++++++++++++++++- config_cmake.h.in | 3 +++ src/fallback.h | 7 +++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/cmake/ConfigureChecks.cmake b/cmake/ConfigureChecks.cmake index c8d139738..559566234 100644 --- a/cmake/ConfigureChecks.cmake +++ b/cmake/ConfigureChecks.cmake @@ -168,9 +168,9 @@ elseif(HAVE_NCURSES_TERM_H) set(TPARM_INCLUDES "${TPARM_INCLUDES}#include \n") endif() -# Solaris and X/Open-conforming systems have a fixed-args tparm cmake_push_check_state() list(APPEND CMAKE_REQUIRED_LIBRARIES ${CURSES_LIBRARY}) +# Solaris and X/Open-conforming systems have a fixed-args tparm check_cxx_source_compiles(" #define TPARM_VARARGS ${TPARM_INCLUDES} @@ -182,6 +182,23 @@ int main () { TPARM_TAKES_VARARGS ) + +# Check if tputs needs a function reading an int or char. +# The only curses I can find that needs a char is OpenIndiana. +check_cxx_source_compiles(" +#include +#include + +static int writer(int b) { + return b; +} + +int main() { + return tputs(\"foo\", 5, writer); +}" +TPUTS_USES_INT_ARG +) + if(TPARM_TAKES_VARARGS) set(TPARM_VARARGS 1) else() diff --git a/config_cmake.h.in b/config_cmake.h.in index 568f8712c..533659c1a 100644 --- a/config_cmake.h.in +++ b/config_cmake.h.in @@ -148,6 +148,9 @@ /* Use a variadic tparm on NetBSD curses. */ #cmakedefine TPARM_VARARGS 1 +/* The parameter type for the last tputs parameter */ +#cmakedefine TPUTS_USES_INT_ARG 1 + /* Define to 1 if tparm accepts a fixed amount of parameters. */ #cmakedefine TPARM_SOLARIS_KLUDGE 1 diff --git a/src/fallback.h b/src/fallback.h index e6f0743c0..3d3ed771e 100644 --- a/src/fallback.h +++ b/src/fallback.h @@ -50,10 +50,9 @@ int fish_mkstemp_cloexec(char *); #define WCHAR_MAX INT_MAX #endif -/// Under curses, tputs expects an int (*func)(char) as its last parameter, but in ncurses, tputs -/// expects a int (*func)(int) as its last parameter. tputs_arg_t is defined to always be what tputs -/// expects. Hopefully. -#if defined(NCURSES_VERSION) || defined(__NetBSD__) +/// Both ncurses and NetBSD curses expect an int (*func)(int) as the last parameter for tputs. +/// Apparently OpenIndiana's curses still uses int (*func)(char) here. +#if TPUTS_USES_INT_ARG using tputs_arg_t = int; #else using tputs_arg_t = char;