mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/curses/curses.c: Many functions of module Curses could cause a crash if the ncurses library was not properly initialized.
Fix pointed out by Alexander Beisig [ruby-core:22592] Functions fixed: attroff, attron, attrset, bkgd, bkgdset, can_change_color, close_screen, closed, color_content, curs_set, def_prog_mode, delch, deleteln, getmouse, getstr, has_colors, init_color, init_pair, insertln, keyname, mouseinterval, mousemask, pair_content, pair_number, reset_prog_mode, resizeterm, scrl, setscrreg, standend, standout, start_color, timeout, ungetmouse, use_default_colors git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25267 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4b62641c13
commit
f0cdcf6f4e
2 changed files with 47 additions and 0 deletions
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
Fri Oct 9 02:12:02 2009 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||
|
||||
* ext/curses/curses.c: Many functions of module Curses could cause a
|
||||
crash if the ncurses library was not properly initialized.
|
||||
Fix pointed out by Alexander Beisig [ruby-core:22592]
|
||||
Functions fixed: attroff, attron, attrset, bkgd, bkgdset,
|
||||
can_change_color, close_screen, closed, color_content, curs_set,
|
||||
def_prog_mode, delch, deleteln, getmouse, getstr, has_colors,
|
||||
init_color, init_pair, insertln, keyname, mouseinterval, mousemask,
|
||||
pair_content, pair_number, reset_prog_mode, resizeterm, scrl,
|
||||
setscrreg, standend, standout, start_color, timeout, ungetmouse,
|
||||
use_default_colors
|
||||
|
||||
Fri Oct 9 01:07:34 2009 Yusuke Endoh <mame@tsg.ne.jp>
|
||||
|
||||
* compile.c (ADD_TRACE): fire coverage event in ensure clause.
|
||||
|
|
|
@ -138,6 +138,7 @@ curses_init_screen(void)
|
|||
static VALUE
|
||||
curses_close_screen(void)
|
||||
{
|
||||
curses_stdscr();
|
||||
#ifdef HAVE_ISENDWIN
|
||||
if (!isendwin())
|
||||
#endif
|
||||
|
@ -164,6 +165,7 @@ curses_finalize(VALUE dummy)
|
|||
static VALUE
|
||||
curses_closed(void)
|
||||
{
|
||||
curses_stdscr();
|
||||
if (isendwin()) {
|
||||
return Qtrue;
|
||||
}
|
||||
|
@ -355,6 +357,7 @@ curses_setpos(VALUE obj, VALUE y, VALUE x)
|
|||
static VALUE
|
||||
curses_standout(VALUE obj)
|
||||
{
|
||||
curses_stdscr();
|
||||
standout();
|
||||
return Qnil;
|
||||
}
|
||||
|
@ -363,6 +366,7 @@ curses_standout(VALUE obj)
|
|||
static VALUE
|
||||
curses_standend(VALUE obj)
|
||||
{
|
||||
curses_stdscr();
|
||||
standend();
|
||||
return Qnil;
|
||||
}
|
||||
|
@ -430,6 +434,7 @@ curses_getstr(VALUE obj)
|
|||
{
|
||||
char rtn[1024]; /* This should be big enough.. I hope */
|
||||
|
||||
curses_stdscr();
|
||||
rb_read_check(stdin);
|
||||
#if defined(HAVE_GETNSTR)
|
||||
getnstr(rtn,1023);
|
||||
|
@ -443,6 +448,7 @@ curses_getstr(VALUE obj)
|
|||
static VALUE
|
||||
curses_delch(VALUE obj)
|
||||
{
|
||||
curses_stdscr();
|
||||
delch();
|
||||
return Qnil;
|
||||
}
|
||||
|
@ -451,6 +457,7 @@ curses_delch(VALUE obj)
|
|||
static VALUE
|
||||
curses_deleteln(VALUE obj)
|
||||
{
|
||||
curses_stdscr();
|
||||
#if defined(HAVE_DELETELN) || defined(deleteln)
|
||||
deleteln();
|
||||
#endif
|
||||
|
@ -461,6 +468,7 @@ curses_deleteln(VALUE obj)
|
|||
static VALUE
|
||||
curses_insertln(VALUE obj)
|
||||
{
|
||||
curses_stdscr();
|
||||
#if defined(HAVE_INSERTLN) || defined(insertln)
|
||||
insertln();
|
||||
#endif
|
||||
|
@ -475,6 +483,7 @@ curses_keyname(VALUE obj, VALUE c)
|
|||
int cc = curses_char(c);
|
||||
const char *name;
|
||||
|
||||
curses_stdscr();
|
||||
name = keyname(cc);
|
||||
if (name) {
|
||||
return rb_str_new_cstr(name);
|
||||
|
@ -510,6 +519,7 @@ curses_curs_set(VALUE obj, VALUE visibility)
|
|||
{
|
||||
#ifdef HAVE_CURS_SET
|
||||
int n;
|
||||
curses_stdscr();
|
||||
return (n = curs_set(NUM2INT(visibility)) != ERR) ? INT2FIX(n) : Qnil;
|
||||
#else
|
||||
return Qnil;
|
||||
|
@ -521,6 +531,7 @@ curses_scrl(VALUE obj, VALUE n)
|
|||
{
|
||||
/* may have to raise exception on ERR */
|
||||
#ifdef HAVE_SCRL
|
||||
curses_stdscr();
|
||||
return (scrl(NUM2INT(n)) == OK) ? Qtrue : Qfalse;
|
||||
#else
|
||||
return Qfalse;
|
||||
|
@ -532,6 +543,7 @@ curses_setscrreg(VALUE obj, VALUE top, VALUE bottom)
|
|||
{
|
||||
/* may have to raise exception on ERR */
|
||||
#ifdef HAVE_SETSCRREG
|
||||
curses_stdscr();
|
||||
return (setscrreg(NUM2INT(top), NUM2INT(bottom)) == OK) ? Qtrue : Qfalse;
|
||||
#else
|
||||
return Qfalse;
|
||||
|
@ -541,6 +553,7 @@ curses_setscrreg(VALUE obj, VALUE top, VALUE bottom)
|
|||
static VALUE
|
||||
curses_attroff(VALUE obj, VALUE attrs)
|
||||
{
|
||||
curses_stdscr();
|
||||
return window_attroff(rb_stdscr,attrs);
|
||||
/* return INT2FIX(attroff(NUM2INT(attrs))); */
|
||||
}
|
||||
|
@ -548,6 +561,7 @@ curses_attroff(VALUE obj, VALUE attrs)
|
|||
static VALUE
|
||||
curses_attron(VALUE obj, VALUE attrs)
|
||||
{
|
||||
curses_stdscr();
|
||||
return window_attron(rb_stdscr,attrs);
|
||||
/* return INT2FIX(attroff(NUM2INT(attrs))); */
|
||||
}
|
||||
|
@ -555,6 +569,7 @@ curses_attron(VALUE obj, VALUE attrs)
|
|||
static VALUE
|
||||
curses_attrset(VALUE obj, VALUE attrs)
|
||||
{
|
||||
curses_stdscr();
|
||||
return window_attrset(rb_stdscr,attrs);
|
||||
/* return INT2FIX(attroff(NUM2INT(attrs))); */
|
||||
}
|
||||
|
@ -563,6 +578,7 @@ static VALUE
|
|||
curses_bkgdset(VALUE obj, VALUE ch)
|
||||
{
|
||||
#ifdef HAVE_BKGDSET
|
||||
curses_stdscr();
|
||||
bkgdset(NUM2CH(ch));
|
||||
#endif
|
||||
return Qnil;
|
||||
|
@ -572,6 +588,7 @@ static VALUE
|
|||
curses_bkgd(VALUE obj, VALUE ch)
|
||||
{
|
||||
#ifdef HAVE_BKGD
|
||||
curses_stdscr();
|
||||
return (bkgd(NUM2CH(ch)) == OK) ? Qtrue : Qfalse;
|
||||
#else
|
||||
return Qfalse;
|
||||
|
@ -582,6 +599,7 @@ curses_bkgd(VALUE obj, VALUE ch)
|
|||
static VALUE
|
||||
curses_use_default_colors(VALUE obj)
|
||||
{
|
||||
curses_stdscr();
|
||||
use_default_colors();
|
||||
return Qnil;
|
||||
}
|
||||
|
@ -635,6 +653,7 @@ static VALUE
|
|||
curses_resizeterm(VALUE obj, VALUE lin, VALUE col)
|
||||
{
|
||||
#if defined(HAVE_RESIZETERM)
|
||||
curses_stdscr();
|
||||
return (resizeterm(NUM2INT(lin),NUM2INT(col)) == OK) ? Qtrue : Qfalse;
|
||||
#else
|
||||
return Qnil;
|
||||
|
@ -646,6 +665,7 @@ static VALUE
|
|||
curses_start_color(VALUE obj)
|
||||
{
|
||||
/* may have to raise exception on ERR */
|
||||
curses_stdscr();
|
||||
return (start_color() == OK) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
|
@ -653,6 +673,7 @@ static VALUE
|
|||
curses_init_pair(VALUE obj, VALUE pair, VALUE f, VALUE b)
|
||||
{
|
||||
/* may have to raise exception on ERR */
|
||||
curses_stdscr();
|
||||
return (init_pair(NUM2INT(pair),NUM2INT(f),NUM2INT(b)) == OK) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
|
@ -660,6 +681,7 @@ static VALUE
|
|||
curses_init_color(VALUE obj, VALUE color, VALUE r, VALUE g, VALUE b)
|
||||
{
|
||||
/* may have to raise exception on ERR */
|
||||
curses_stdscr();
|
||||
return (init_color(NUM2INT(color),NUM2INT(r),
|
||||
NUM2INT(g),NUM2INT(b)) == OK) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
@ -667,12 +689,14 @@ curses_init_color(VALUE obj, VALUE color, VALUE r, VALUE g, VALUE b)
|
|||
static VALUE
|
||||
curses_has_colors(VALUE obj)
|
||||
{
|
||||
curses_stdscr();
|
||||
return has_colors() ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
curses_can_change_color(VALUE obj)
|
||||
{
|
||||
curses_stdscr();
|
||||
return can_change_color() ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
|
@ -691,6 +715,7 @@ curses_color_content(VALUE obj, VALUE color)
|
|||
{
|
||||
short r,g,b;
|
||||
|
||||
curses_stdscr();
|
||||
color_content(NUM2INT(color),&r,&g,&b);
|
||||
return rb_ary_new3(3,INT2FIX(r),INT2FIX(g),INT2FIX(b));
|
||||
}
|
||||
|
@ -711,6 +736,7 @@ curses_pair_content(VALUE obj, VALUE pair)
|
|||
{
|
||||
short f,b;
|
||||
|
||||
curses_stdscr();
|
||||
pair_content(NUM2INT(pair),&f,&b);
|
||||
return rb_ary_new3(2,INT2FIX(f),INT2FIX(b));
|
||||
}
|
||||
|
@ -724,6 +750,7 @@ curses_color_pair(VALUE obj, VALUE attrs)
|
|||
static VALUE
|
||||
curses_pair_number(VALUE obj, VALUE attrs)
|
||||
{
|
||||
curses_stdscr();
|
||||
return INT2FIX(PAIR_NUMBER(NUM2INT(attrs)));
|
||||
}
|
||||
#endif /* USE_COLOR */
|
||||
|
@ -759,6 +786,7 @@ curses_getmouse(VALUE obj)
|
|||
struct mousedata *mdata;
|
||||
VALUE val;
|
||||
|
||||
curses_stdscr();
|
||||
val = Data_Make_Struct(cMouseEvent,struct mousedata,
|
||||
0,curses_mousedata_free,mdata);
|
||||
mdata->mevent = (MEVENT*)xmalloc(sizeof(MEVENT));
|
||||
|
@ -770,6 +798,7 @@ curses_ungetmouse(VALUE obj, VALUE mevent)
|
|||
{
|
||||
struct mousedata *mdata;
|
||||
|
||||
curses_stdscr();
|
||||
GetMOUSE(mevent,mdata);
|
||||
return (ungetmouse(mdata->mevent) == OK) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
@ -777,12 +806,14 @@ curses_ungetmouse(VALUE obj, VALUE mevent)
|
|||
static VALUE
|
||||
curses_mouseinterval(VALUE obj, VALUE interval)
|
||||
{
|
||||
curses_stdscr();
|
||||
return mouseinterval(NUM2INT(interval)) ? Qtrue : Qfalse;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
curses_mousemask(VALUE obj, VALUE mask)
|
||||
{
|
||||
curses_stdscr();
|
||||
return INT2NUM(mousemask(NUM2UINT(mask),NULL));
|
||||
}
|
||||
|
||||
|
@ -806,6 +837,7 @@ DEFINE_MOUSE_GET_MEMBER(curs_mouse_bstate, bstate)
|
|||
static VALUE
|
||||
curses_timeout(VALUE obj, VALUE delay)
|
||||
{
|
||||
curses_stdscr();
|
||||
timeout(NUM2INT(delay));
|
||||
return Qnil;
|
||||
}
|
||||
|
@ -817,6 +849,7 @@ curses_timeout(VALUE obj, VALUE delay)
|
|||
static VALUE
|
||||
curses_def_prog_mode(VALUE obj)
|
||||
{
|
||||
curses_stdscr();
|
||||
return def_prog_mode() == OK ? Qtrue : Qfalse;
|
||||
}
|
||||
#else
|
||||
|
@ -827,6 +860,7 @@ curses_def_prog_mode(VALUE obj)
|
|||
static VALUE
|
||||
curses_reset_prog_mode(VALUE obj)
|
||||
{
|
||||
curses_stdscr();
|
||||
return reset_prog_mode() == OK ? Qtrue : Qfalse;
|
||||
}
|
||||
#else
|
||||
|
|
Loading…
Reference in a new issue