PHP segfaults if ncurses_refresh is called before ncurses_init...
Index: ncurses_functions.c =================================================================== RCS file: /repository/php4/ext/ncurses/ncurses_functions.c,v retrieving revision 1.18 diff -u -r1.18 ncurses_functions.c --- ncurses_functions.c 28 Feb 2002 08:26:27 -0000 1.18 +++ ncurses_functions.c 27 Mar 2002 13:59:30 -0000 @@ -81,6 +81,8 @@ Stops using ncurses, clean up the screen */ PHP_FUNCTION(ncurses_end) { + keypad(stdscr, FALSE); /* disable keyboard mapping */ + php_ncurses_init_called(0); /* set call_status to 0 */ RETURN_LONG(endwin()); /* endialize the curses library */ } /* }}} */ @@ -108,9 +110,24 @@ initscr(); /* initialize the curses library */ keypad(stdscr, TRUE); /* enable keyboard mapping */ (void) nonl(); /* tell curses not to do NL->CR/NL on output */ - (void) cbreak(); /* take input chars one at a time, no wait for \n */} + (void) cbreak(); /* take input chars one at a time, no wait for \n */ + php_ncurses_init_called(1); +} /* }}} */ +int php_ncurses_init_called(int do_this) { + static int call_status = 0; + switch(do_this) { + case 0: + case 1: + call_status = do_this; + break; + default: + return call_status; + break; + } +} + /* {{{ proto int ncurses_init_pair(int pair, int fg, int bg) Allocates a color pair */ PHP_FUNCTION(ncurses_init_pair) @@ -160,11 +177,15 @@ } /* }}} */ -/* {{{ proto int ncurses_refresh(int ch) +/* {{{ proto int ncurses_refresh(void) Refresh screen */ PHP_FUNCTION(ncurses_refresh) { - RETURN_LONG(refresh()); + if(php_ncurses_init_called(NULL)) { + RETURN_LONG(refresh()); + } else { + php_error(E_WARNING, "ncurses_refresh: called before ncurses_init"); + } } /* }}} */
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php