From d44d7f381ba0173521cb788ba3adb12e261e5c96 Mon Sep 17 00:00:00 2001 From: "Thomas E. Dickey" Date: Sun, 24 Feb 2008 01:25:21 +0000 Subject: [PATCH] ncurses 5.6 - patch 20080223 + fix a size-difference in _nc_globals which caused hanging of mutex lock/unlock when termlib was built separately. + avoid using nanosleep() in threaded configuration since that often is implemented to suspend the entire process. --- NEWS | 10 +++++++++- dist.mk | 4 ++-- man/terminfo.tail | 6 ++++-- ncurses/base/lib_newwin.c | 12 +++--------- ncurses/curses.priv.h | 19 ++++++++++++++----- ncurses/tinfo/lib_data.c | 22 +++++++++++++++------- test/demo_menus.c | 10 +++++----- test/hashtest.c | 12 ++---------- test/ncurses.c | 12 ++++++------ test/test.priv.h | 9 ++++++++- test/worm.c | 6 +++++- 11 files changed, 73 insertions(+), 49 deletions(-) diff --git a/NEWS b/NEWS index d71eaf8a..5634dbc3 100644 --- a/NEWS +++ b/NEWS @@ -25,7 +25,7 @@ -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------- --- $Id: NEWS,v 1.1206 2008/02/09 23:49:39 tom Exp $ +-- $Id: NEWS,v 1.1208 2008/02/23 21:26:58 tom Exp $ ------------------------------------------------------------------------------- This is a log of changes that ncurses has gone through since Zeyd started @@ -45,6 +45,14 @@ See the AUTHORS file for the corresponding full names. Changes through 1.9.9e did not credit all contributions; it is not possible to add this information. +20080223 + + fix a size-difference in _nc_globals which caused hanging of mutex + lock/unlock when termlib was built separately. + +20080216 + + avoid using nanosleep() in threaded configuration since that often + is implemented to suspend the entire process. + 20080209 + update test programs to build/work with various UNIX curses for comparisons. This was to reinvestigate statement in X/Open curses diff --git a/dist.mk b/dist.mk index 0141b05e..4bc5ab05 100644 --- a/dist.mk +++ b/dist.mk @@ -25,7 +25,7 @@ # use or other dealings in this Software without prior written # # authorization. # ############################################################################## -# $Id: dist.mk,v 1.629 2008/02/09 15:32:57 tom Exp $ +# $Id: dist.mk,v 1.631 2008/02/23 14:51:29 tom Exp $ # Makefile for creating ncurses distributions. # # This only needs to be used directly as a makefile by developers, but @@ -37,7 +37,7 @@ SHELL = /bin/sh # These define the major/minor/patch versions of ncurses. NCURSES_MAJOR = 5 NCURSES_MINOR = 6 -NCURSES_PATCH = 20080209 +NCURSES_PATCH = 20080223 # We don't append the patch to the version, since this only applies to releases VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR) diff --git a/man/terminfo.tail b/man/terminfo.tail index 60d0b70d..d06d3a96 100644 --- a/man/terminfo.tail +++ b/man/terminfo.tail @@ -1,4 +1,4 @@ -.\" $Id: terminfo.tail,v 1.48 2007/06/02 20:30:40 tom Exp $ +.\" $Id: terminfo.tail,v 1.49 2008/02/16 20:57:43 tom Exp $ .\" Beginning of terminfo.tail file .\" This file is part of ncurses. .\" See "terminfo.head" for copyright. @@ -325,7 +325,9 @@ The \fB%\fR encodings have the following meanings: outputs `%' .TP %\fI[[\fP:\fI]flags][width[.precision]][\fPdoxXs\fI]\fP -as in \fBprintf\fP, flags are [-+#] and space +as in \fBprintf\fP, flags are [-+#] and space. +Use a `:' to allow the next character to be a `-' flag, +avoiding interpreting "%-" as an operator. .TP %c print pop() like %c in \fBprintf\fP diff --git a/ncurses/base/lib_newwin.c b/ncurses/base/lib_newwin.c index 21ba95f3..835bb0bc 100644 --- a/ncurses/base/lib_newwin.c +++ b/ncurses/base/lib_newwin.c @@ -40,8 +40,9 @@ */ #include +#include -MODULE_ID("$Id: lib_newwin.c,v 1.44 2008/01/13 00:28:13 tom Exp $") +MODULE_ID("$Id: lib_newwin.c,v 1.45 2008/02/23 20:57:58 tom Exp $") static WINDOW * remove_window_from_screen(WINDOW *win) @@ -230,14 +231,7 @@ _nc_makenew(int num_lines, int num_columns, int begy, int begx, int flags) if ((wp = typeCalloc(WINDOWLIST, 1)) == 0) returnWin(0); -#ifdef USE_PTHREADS - { - pthread_mutexattr_t recattr; - memset(&recattr, 0, sizeof(recattr)); - pthread_mutexattr_settype(&recattr, PTHREAD_MUTEX_NORMAL); - pthread_mutex_init(&(wp->mutex_use_window), &recattr); - } -#endif + _nc_mutex_init(&(wp->mutex_use_window)); win = &(wp->win); diff --git a/ncurses/curses.priv.h b/ncurses/curses.priv.h index 1e748eec..ddf15a8a 100644 --- a/ncurses/curses.priv.h +++ b/ncurses/curses.priv.h @@ -34,7 +34,7 @@ /* - * $Id: curses.priv.h,v 1.357 2008/01/13 00:33:10 tom Exp $ + * $Id: curses.priv.h,v 1.359 2008/02/23 21:19:56 tom Exp $ * * curses.priv.h * @@ -312,8 +312,10 @@ color_t; #define TR_GLOBAL_MUTEX(name) TR_MUTEX(_nc_globals.mutex_##name) #ifdef USE_PTHREADS + #if USE_REENTRANT #include +extern NCURSES_EXPORT(void) _nc_mutex_init(pthread_mutex_t *); extern NCURSES_EXPORT(int) _nc_mutex_lock(pthread_mutex_t *); extern NCURSES_EXPORT(int) _nc_mutex_trylock(pthread_mutex_t *); extern NCURSES_EXPORT(int) _nc_mutex_unlock(pthread_mutex_t *); @@ -327,7 +329,16 @@ extern NCURSES_EXPORT(void) _nc_unlock_window(WINDOW *); #else #error POSIX threads requires --enable-reentrant option #endif -#else + +#if HAVE_NANOSLEEP +#undef HAVE_NANOSLEEP +#define HAVE_NANOSLEEP 0 /* nanosleep suspends all threads */ +#endif + +#else /* !USE_PTHREADS */ + +#define _nc_mutex_init(obj) /* nothing */ + #define _nc_lock_global(name) /* nothing */ #define _nc_try_global(name) 0 #define _nc_unlock_global(name) /* nothing */ @@ -335,7 +346,7 @@ extern NCURSES_EXPORT(void) _nc_unlock_window(WINDOW *); #define _nc_lock_window(name) (void) TRUE #define _nc_unlock_window(name) /* nothing */ -#endif +#endif /* USE_PTHREADS */ #define _nc_lock_screen(name) /* nothing */ #define _nc_unlock_screen(name) /* nothing */ @@ -583,11 +594,9 @@ typedef struct { unsigned char *tracetry_buf; size_t tracetry_used; -#ifndef USE_TERMLIB char traceatr_color_buf[2][80]; int traceatr_color_sel; int traceatr_color_last; -#endif /* USE_TERMLIB */ #endif /* TRACE */ diff --git a/ncurses/tinfo/lib_data.c b/ncurses/tinfo/lib_data.c index 21b854b9..e3affe40 100644 --- a/ncurses/tinfo/lib_data.c +++ b/ncurses/tinfo/lib_data.c @@ -41,7 +41,7 @@ #include -MODULE_ID("$Id: lib_data.c,v 1.39 2008/01/13 01:21:59 tom Exp $") +MODULE_ID("$Id: lib_data.c,v 1.40 2008/02/23 21:23:44 tom Exp $") /* * OS/2's native linker complains if we don't initialize public data when @@ -109,7 +109,7 @@ NCURSES_EXPORT_VAR(SCREEN *) SP = NULL; /* Some linkers require initialized data #define CHARS_0s { '\0' } #define TGETENT_0 { 0L, FALSE, NULL, NULL, NULL } -#define TGETENT_0s { TGETENT_0, TGETENT_0, TGETENT_0, TGETENT_0 } +#define TGETENT_0s { TGETENT_0, TGETENT_0, TGETENT_0, TGETENT_0 } NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals = { 0, /* have_sigwinch */ @@ -171,11 +171,9 @@ NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals = { NULL, /* tracetry_buf */ 0, /* tracetry_used */ -#ifndef USE_TERMLIB { CHARS_0s, CHARS_0s }, /* traceatr_color_buf */ 0, /* traceatr_color_sel */ -1, /* traceatr_color_last */ -#endif /* USE_TERMLIB */ #endif /* TRACE */ #ifdef USE_PTHREADS @@ -236,20 +234,30 @@ NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen = { /******************************************************************************/ #ifdef USE_PTHREADS +NCURSES_EXPORT(void) +_nc_mutex_init(pthread_mutex_t * obj) +{ + pthread_mutexattr_t recattr; + + memset(&recattr, 0, sizeof(recattr)); + pthread_mutexattr_settype(&recattr, PTHREAD_MUTEX_NORMAL); + pthread_mutex_init(obj, &recattr); +} + NCURSES_EXPORT(int) -_nc_mutex_lock(pthread_mutex_t *obj) +_nc_mutex_lock(pthread_mutex_t * obj) { return pthread_mutex_lock(obj); } NCURSES_EXPORT(int) -_nc_mutex_trylock(pthread_mutex_t *obj) +_nc_mutex_trylock(pthread_mutex_t * obj) { return pthread_mutex_trylock(obj); } NCURSES_EXPORT(int) -_nc_mutex_unlock(pthread_mutex_t *obj) +_nc_mutex_unlock(pthread_mutex_t * obj) { return pthread_mutex_unlock(obj); } diff --git a/test/demo_menus.c b/test/demo_menus.c index 84322eb4..d572b2d1 100644 --- a/test/demo_menus.c +++ b/test/demo_menus.c @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: demo_menus.c,v 1.22 2008/02/09 18:09:26 tom Exp $ + * $Id: demo_menus.c,v 1.23 2008/02/23 23:06:49 tom Exp $ * * Demonstrate a variety of functions from the menu library. * Thomas Dickey - 2005/4/9 @@ -130,14 +130,14 @@ wGetchar(WINDOW *win) while ((c = wgetch(win)) == CTRL('T')) { if (_nc_tracing) { save_trace = _nc_tracing; - _tracef("TOGGLE-TRACING OFF"); + Trace(("TOGGLE-TRACING OFF")); _nc_tracing = 0; } else { _nc_tracing = save_trace; } trace(_nc_tracing); if (_nc_tracing) - _tracef("TOGGLE-TRACING ON"); + Trace(("TOGGLE-TRACING ON")); } #else c = wgetch(win); @@ -270,7 +270,7 @@ menu_destroy(MENU * m) #if 0 if (count > 0) { while (*ip) { - _tracef("freeing item %d:%d", ip - menu_items(m), count); + Trace(("freeing item %d:%d", ip - menu_items(m), count)); free_item(*ip++); } } @@ -524,7 +524,7 @@ perform_trace_menu(int cmd) newtrace |= t_tbl[item_index(*ip)].mask; } trace(newtrace); - _tracef("trace level interactively set to %s", tracetrace(_nc_tracing)); + Trace(("trace level interactively set to %s", tracetrace(_nc_tracing))); (void) mvprintw(LINES - 2, 0, "Trace level is %s\n", tracetrace(_nc_tracing)); diff --git a/test/hashtest.c b/test/hashtest.c index 85248c81..737731ea 100644 --- a/test/hashtest.c +++ b/test/hashtest.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -30,17 +30,9 @@ * * Generate timing statistics for vertical-motion optimization. * - * $Id: hashtest.c,v 1.27 2007/07/21 17:45:09 tom Exp $ + * $Id: hashtest.c,v 1.28 2008/02/23 23:02:41 tom Exp $ */ -#ifdef TRACE -#define Trace(p) _tracef p -#define USE_TRACE 1 -#else -#define Trace(p) /* nothing */ -#define USE_TRACE 0 -#endif - #include #define LO_CHAR ' ' diff --git a/test/ncurses.c b/test/ncurses.c index aa1c9703..0e724a65 100644 --- a/test/ncurses.c +++ b/test/ncurses.c @@ -40,7 +40,7 @@ AUTHOR Author: Eric S. Raymond 1993 Thomas E. Dickey (beginning revision 1.27 in 1996). -$Id: ncurses.c,v 1.301 2008/02/09 17:19:55 tom Exp $ +$Id: ncurses.c,v 1.302 2008/02/23 23:07:28 tom Exp $ ***************************************************************************/ @@ -183,14 +183,14 @@ wGetchar(WINDOW *win) while ((c = wgetch(win)) == CTRL('T')) { if (_nc_tracing) { save_trace = _nc_tracing; - _tracef("TOGGLE-TRACING OFF"); + Trace(("TOGGLE-TRACING OFF")); _nc_tracing = 0; } else { _nc_tracing = save_trace; } trace(_nc_tracing); if (_nc_tracing) - _tracef("TOGGLE-TRACING ON"); + Trace(("TOGGLE-TRACING ON")); } #else c = wgetch(win); @@ -276,14 +276,14 @@ wGet_wchar(WINDOW *win, wint_t *result) while ((c = wget_wch(win, result)) == CTRL('T')) { if (_nc_tracing) { save_trace = _nc_tracing; - _tracef("TOGGLE-TRACING OFF"); + Trace(("TOGGLE-TRACING OFF")); _nc_tracing = 0; } else { _nc_tracing = save_trace; } trace(_nc_tracing); if (_nc_tracing) - _tracef("TOGGLE-TRACING ON"); + Trace(("TOGGLE-TRACING ON")); } #else c = wget_wch(win, result); @@ -5079,7 +5079,7 @@ trace_set(void) if (item_value(*ip)) newtrace |= t_tbl[item_index(*ip)].mask; trace(newtrace); - _tracef("trace level interactively set to %s", tracetrace(_nc_tracing)); + Trace(("trace level interactively set to %s", tracetrace(_nc_tracing))); (void) mvprintw(LINES - 2, 0, "Trace level is %s\n", tracetrace(_nc_tracing)); diff --git a/test/test.priv.h b/test/test.priv.h index fb5f203f..0eabbcc7 100644 --- a/test/test.priv.h +++ b/test/test.priv.h @@ -29,7 +29,7 @@ /**************************************************************************** * Author: Thomas E. Dickey 1996-on * ****************************************************************************/ -/* $Id: test.priv.h,v 1.73 2008/02/10 00:12:55 tom Exp $ */ +/* $Id: test.priv.h,v 1.74 2008/02/23 23:02:41 tom Exp $ */ #ifndef __TEST_PRIV_H #define __TEST_PRIV_H 1 @@ -547,5 +547,12 @@ use_window(WINDOW *win, int (*func) (WINDOW *, void *), void *data) \ #define USING_WINDOW(w,func) func(w) #endif +#ifdef TRACE +#define Trace(p) _tracef p +#define USE_TRACE 1 +#else +#define Trace(p) /* nothing */ +#define USE_TRACE 0 +#endif #endif /* __TEST_PRIV_H */ diff --git a/test/worm.c b/test/worm.c index 23b0ef4a..d78f9b96 100644 --- a/test/worm.c +++ b/test/worm.c @@ -61,7 +61,7 @@ Options: traces will be dumped. The program stops and waits for one character of input at the beginning and end of the interval. - $Id: worm.c,v 1.55 2008/01/26 22:07:57 tom Exp $ + $Id: worm.c,v 1.56 2008/02/23 23:08:57 tom Exp $ */ #include @@ -321,12 +321,14 @@ static void * start_worm(void *arg) { unsigned long compare = 0; + Trace(("start_worm")); while (!quit_worm()) { while (compare < sequence) { ++compare; use_window(stdscr, draw_worm, arg); } } + Trace(("...start_worm (done)")); return NULL; } #endif @@ -576,6 +578,7 @@ main(int argc, char *argv[]) USING_WINDOW(stdscr, wrefresh); } + Trace(("Cleanup")); cleanup(); #ifdef NO_LEAKS for (y = 0; y < LINES; y++) { @@ -591,6 +594,7 @@ main(int argc, char *argv[]) /* * Do this just in case one of the threads did not really exit. */ + Trace(("join all threads")); for (n = 0; n < number; n++) { pthread_join(worm[n].thread, NULL); } -- 2.44.0