[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug in start_color() affecting extended_pair_content() in version 6.

From: Jeffrey Kintscher
Subject: Re: bug in start_color() affecting extended_pair_content() in version 6.1
Date: Mon, 20 May 2019 14:47:56 -0700
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

I initially tested with ncurses 6.1 installed by brew. I switched to the source code distribution for more detailed debugging.

jfoo:poc jeff$ brew info ncurses
ncurses: stable 6.1 (bottled) [keg-only]
Text-based UI library
/usr/local/Cellar/ncurses/6.1 (3,869 files, 8.3MB)
  Poured from bottle on 2019-05-17 at 14:15:14
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/ncurses.rb
==> Dependencies
Build: pkg-config ✔
==> Caveats
ncurses is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ncurses first in your PATH run:
  echo 'export PATH="/usr/local/opt/ncurses/bin:$PATH"' >> ~/.bash_profile

For compilers to find ncurses you may need to set:
  export LDFLAGS="-L/usr/local/opt/ncurses/lib"
  export CPPFLAGS="-I/usr/local/opt/ncurses/include"

For pkg-config to find ncurses you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/ncurses/lib/pkgconfig"

==> Analytics
install: 73,233 (30 days), 222,817 (90 days), 471,355 (365 days)
install_on_request: 1,618 (30 days), 5,713 (90 days), 18,007 (365 days)
build_error: 0 (30 days)

On 5/20/19 2:34 PM, Jeffrey Kintscher wrote:
Sorry for leaving the system details out.

5:0:9    6.0    20180127

downloaded May 18 from:

configure command line (run in "build" subdirectory):
../configure --prefix=${HOME}/src/ncurses-6.1/inst --enable-ext-colors --with-debug --enable-ext-funcs  --with-shared --enable-widec

make command line:
make -j 7

uname -a:
Darwin jfoo.local 18.5.0 Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64

macOS Mojave 10.14.4

gcc --version:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

test program compile line:
clang -pipe -o bbpo-36630 bbpo-36630.c -lncursesw_g -g -O0 -I${HOME}/src/ncurses-6.1/inst/include/ncursesw -I${HOME}/src/ncurses-6.1/inst/include -L${HOME}/src/ncurses-6.1/inst/


On 5/20/19 1:09 AM, Thomas Dickey wrote:
On Sun, May 19, 2019 at 06:48:49PM -0700, Jeffrey Kintscher wrote:
I was working on adding the new extended color functions to Python when I
encountered a problem with extended_pair_content(COLOR_PAIRS-1, &f, &b)
returning -1 when using the terminal "xterm-256color". Here is example code
highlighting the problem:
there's no version/patch information here, nor the system (which would let
me guess how ncurses is built).
#include <ncurses.h>
#include <stdio.h>

int main(int argc, char **argv, char **env)
    int b, f;

    printf("init_extended_pair(COLOR_PAIRS-1, 1, 1): %d\n",
init_extended_pair(COLOR_PAIRS-1, 1, 1));
    printf("COLOR_PAIRS: %d\n", COLOR_PAIRS);
    printf("extended_pair_content(COLOR_PAIRS-1, &f, &b): %d\n",
extended_pair_content(COLOR_PAIRS-1, &f, &b));
    printf("f: %d\nb: %d\n", f, b);
    return 0;

extended_pair_content() eventually calls _nc_pair_content() which invokes
the macro ValidPair(sp, pair). ValidPair() evaluates to false because the
check (pair < sp->_pair_limit) fails. According to the debugger, pair ==
65535 and sp->_pair_limit == 32767.
If sp->pair_limit is 32767, that's likely an ABI 5 configuration.
sp->_pair_limit gets set in start_color() (in ncurses/base/libcolor.c):

    if (maxpairs > 0 && maxcolors > 0) {
        SP_PARM->_pair_limit = maxpairs;
        SP_PARM->_pair_limit += (1 + (2 * maxcolors));
        SP_PARM->_pair_limit = limit_PAIRS(SP_PARM->_pair_limit);

SP_PARM->_pair_limit is set to 65536, increased to 66049, then clamped at
32767. This is because the limit_PAIRS() macro clamps the value it is passed
to within the limits for type NCURSES_PAIRS_T, which is defined as short. 
NCURSES_PAIRS_T is always short...

but the quoted code is in the ABI 5 part (see lib_color.c around line 400):

	     * If using default colors, allocate extra space in table to
	     * allow for default-color as a component of a color-pair.
	    SP_PARM->_pair_limit += (1 + (2 * maxcolors));
	    SP_PARM->_pair_limit = limit_PAIRS(SP_PARM->_pair_limit);
#endif /* NCURSES_EXT_FUNCS */

So, SP_PARM->_pair_limit gets set to 32767 which causes ValidPair(sp,
COLOR_PAIRS-1) to fail.
You may find a bug in the extended colors, but almost all of the reports
will be for ABI 5 versus ABI 6.

>From there to here, from here to there,
funny things are everywhere.
           -- Theodore Geisel

>From there to here, from here to there,
funny things are everywhere.
           -- Theodore Geisel

reply via email to

[Prev in Thread] Current Thread [Next in Thread]