~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to ext/readline/readline.c

  • Committer: Package Import Robot
  • Author(s): Antonio Terceiro, Lucas Nussbaum, Daigo Moriwaki, James Healy, Antonio Terceiro
  • Date: 2012-06-02 07:42:28 UTC
  • mfrom: (21.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20120602074228-09t2jgg1ozrsnnfo
Tags: 1.9.3.194-1
[ Lucas Nussbaum ]
* Add hurd-path-max.diff. Fixes FTBFS on Hurd. (Closes: #648055)

[ Daigo Moriwaki ]
* Removed debian/patches/debian/patches/sparc-continuations.diff,
  which the upstream has applied.
* debian/rules:
  - Bumped up tcltk_ver to 8.5.
  - Used chrpath for tcltklib.so to fix a lintian error,
    binary-or-shlib-defines-rpath.
* debian/control:
  - Suggests ruby-switch. (Closes: #654312)
  - Build-Depends: chrpath.
* debian/libruby1.9.1.symbols: Added a new symbol for
  rb_str_modify_expand@Base.
* debian/run-test-suites.bash:
  - Corrected options for test-all.
  - Enabled timeout to allow hang tests to be aborted.

[ James Healy ]
* New upstream release: 1.9.3p194 (Closes: #669582)
  + This release includes a fix for CVE-2011-0188 (Closes: #628451)
  + This release also does not segfault when running the test suite under
    amd64 (Closes: #674347)
* Enable hardened build flags (Closes: #667964)
* debian/control:
  - depend on specific version on coreutils
  - update policy version (no changes)

[ Antonio Terceiro ]
* debian/ruby1.9.1.postinst:
  + bump alternatives priority for `ruby` to 51 so that Ruby 1.9 has a
    higher priority than Ruby 1.8 (50).
  + bump alternatives priority for `gem` to 181 so that the Rubygems
    provided by Ruby 1.9 has priority over the one provided by the rubygems
    package.
* debian/control: added myself to Uploaders:
* debian/libruby1.9.1.symbols: update with new symbols added in 1.9.3p194
  upstream release.
* debian/manpages/*: fix references to command names with s/1.9/1.9.1/
* debian/rules: skip running DRB tests, since they seem to make the build
  hang. This should close #647296, but let's way and see. Also, with this do
  not need to timeout the test suite anymore.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
  readline.c - GNU Readline module
4
4
 
5
 
  $Author: drbrain $
 
5
  $Author: nobu $
6
6
  created at: Wed Jan 20 13:59:32 JST 1999
7
7
 
8
8
  Copyright (C) 1997-2008  Shugo Maeda
9
9
  Copyright (C) 2008-2009  TAKAO Kouji
10
10
 
11
 
  $Id: readline.c 32613 2011-07-22 04:54:09Z drbrain $
 
11
  $Id: readline.c 34505 2012-02-09 03:25:07Z nobu $
12
12
 
13
13
  Contact:
14
14
   - TAKAO Kouji <kouji at takao7 dot net> (current maintainer)
40
40
#include <unistd.h>
41
41
#endif
42
42
 
 
43
#ifdef HAVE_SYS_STAT_H
 
44
#include <sys/stat.h>
 
45
#endif
 
46
 
43
47
static VALUE mReadline;
44
48
 
45
49
#define EDIT_LINE_LIBRARY_VERSION "EditLine wrapper"
69
73
#endif
70
74
 
71
75
static int (*history_get_offset_func)(int);
 
76
static int (*history_replace_offset_func)(int);
 
77
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
 
78
static int readline_completion_append_character;
 
79
#endif
72
80
 
73
81
static char **readline_attempted_completion_function(const char *text,
74
82
                                                     int start, int end);
158
166
            }
159
167
        }
160
168
    }
161
 
#endif    
 
169
#endif
162
170
    c = rb_funcall(readline_instream, id_getbyte, 0, 0);
163
171
    if (NIL_P(c)) return EOF;
164
172
    return NUM2CHR(c);
257
265
static VALUE
258
266
readline_get(VALUE prompt)
259
267
{
 
268
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
 
269
    readline_completion_append_character = rl_completion_append_character;
 
270
#endif
260
271
    return (VALUE)readline((char *)prompt);
261
272
}
262
273
 
365
376
    }
366
377
 
367
378
    if (!isatty(fileno(rl_instream)) && errno == EBADF) rb_raise(rb_eIOError, "closed stdin");
 
379
    if (rl_outstream) {
 
380
        struct stat stbuf;
 
381
        int fd = fileno(rl_outstream);
 
382
        if (fd < 0 || fstat(fd, &stbuf) != 0) {
 
383
            rb_raise(rb_eIOError, "closed stdout");
 
384
        }
 
385
    }
368
386
 
369
387
#ifdef _WIN32
370
388
    rl_prep_terminal(1);
637
655
    char **result;
638
656
    int case_fold;
639
657
    long i, matches;
 
658
    rb_encoding *enc;
 
659
    VALUE encobj;
640
660
 
641
661
    proc = rb_attr_get(mReadline, completion_proc);
642
662
    if (NIL_P(proc))
643
663
        return NULL;
 
664
#ifdef HAVE_RL_COMPLETION_APPEND_CHARACTER
 
665
    rl_completion_append_character = readline_completion_append_character;
 
666
#endif
644
667
#ifdef HAVE_RL_ATTEMPTED_COMPLETION_OVER
645
668
    rl_attempted_completion_over = 1;
646
669
#endif
647
670
    case_fold = RTEST(rb_attr_get(mReadline, completion_case_fold));
648
671
    ary = rb_funcall(proc, rb_intern("call"), 1, rb_locale_str_new_cstr(text));
649
 
    if (TYPE(ary) != T_ARRAY)
 
672
    if (!RB_TYPE_P(ary, T_ARRAY))
650
673
        ary = rb_Array(ary);
651
674
    matches = RARRAY_LEN(ary);
652
 
    if (matches == 0)
653
 
        return NULL;
654
 
    result = ALLOC_N(char *, matches + 2);
 
675
    if (matches == 0) return NULL;
 
676
    result = (char**)malloc((matches + 2)*sizeof(char*));
 
677
    if (result == NULL) rb_raise(rb_eNoMemError, "failed to allocate memory");
 
678
    enc = rb_locale_encoding();
 
679
    encobj = rb_enc_from_encoding(enc);
655
680
    for (i = 0; i < matches; i++) {
656
681
        temp = rb_obj_as_string(RARRAY_PTR(ary)[i]);
657
 
        result[i + 1] = ALLOC_N(char, RSTRING_LEN(temp) + 1);
 
682
        StringValueCStr(temp);  /* must be NUL-terminated */
 
683
        rb_enc_check(encobj, temp);
 
684
        result[i + 1] = (char*)malloc(RSTRING_LEN(temp) + 1);
 
685
        if (result[i + 1]  == NULL) rb_memerror();
658
686
        strcpy(result[i + 1], RSTRING_PTR(temp));
659
687
    }
660
688
    result[matches + 1] = NULL;
663
691
        result[0] = strdup(result[1]);
664
692
    }
665
693
    else {
666
 
        register int i = 1;
667
 
        int low = 100000;
668
 
 
669
 
        while (i < matches) {
670
 
            register int c1, c2, si;
671
 
 
672
 
            if (case_fold) {
673
 
                for (si = 0;
674
 
                     (c1 = TOLOWER(result[i][si])) &&
675
 
                         (c2 = TOLOWER(result[i + 1][si]));
676
 
                     si++)
677
 
                    if (c1 != c2) break;
678
 
            } else {
679
 
                for (si = 0;
680
 
                     (c1 = result[i][si]) &&
681
 
                         (c2 = result[i + 1][si]);
682
 
                     si++)
683
 
                    if (c1 != c2) break;
 
694
        const char *result1 = result[1];
 
695
        long low = strlen(result1);
 
696
 
 
697
        for (i = 1; i < matches; ++i) {
 
698
            register int c1, c2;
 
699
            long i1, i2, l2;
 
700
            int n1, n2;
 
701
            const char *p2 = result[i + 1];
 
702
 
 
703
            l2 = strlen(p2);
 
704
            for (i1 = i2 = 0; i1 < low && i2 < l2; i1 += n1, i2 += n2) {
 
705
                c1 = rb_enc_codepoint_len(result1 + i1, result1 + low, &n1, enc);
 
706
                c2 = rb_enc_codepoint_len(p2 + i2, p2 + l2, &n2, enc);
 
707
                if (case_fold) {
 
708
                    c1 = rb_tolower(c1);
 
709
                    c2 = rb_tolower(c2);
 
710
                }
 
711
                if (c1 != c2) break;
684
712
            }
685
713
 
686
 
            if (low > si) low = si;
687
 
            i++;
 
714
            low = i1;
688
715
        }
689
716
        result[0] = ALLOC_N(char, low + 1);
690
717
        strncpy(result[0], result[1], low);
1299
1326
        i += history_length;
1300
1327
    }
1301
1328
    if (i >= 0) {
1302
 
        entry = replace_history_entry(i, RSTRING_PTR(str), NULL);
 
1329
        entry = replace_history_entry(history_replace_offset_func(i), RSTRING_PTR(str), NULL);
1303
1330
    }
1304
1331
    if (entry == NULL) {
1305
1332
        rb_raise(rb_eIndexError, "invalid index");
1494
1521
    /* Allow conditional parsing of the ~/.inputrc file. */
1495
1522
    rl_readline_name = (char *)"Ruby";
1496
1523
 
 
1524
#if defined HAVE_RL_GETC_FUNCTION
 
1525
    /* libedit check rl_getc_function only when rl_initialize() is called, */
 
1526
    /* and using_history() call rl_initialize(). */
 
1527
    /* This assignment should be placed before using_history() */
 
1528
    rl_getc_function = readline_getc;
 
1529
    id_getbyte = rb_intern_const("getbyte");
 
1530
#elif defined HAVE_RL_EVENT_HOOK
 
1531
    rl_event_hook = readline_event;
 
1532
#endif
 
1533
 
1497
1534
    using_history();
1498
1535
 
1499
1536
    completion_proc = rb_intern(COMPLETION_PROC);
1604
1641
     */
1605
1642
    rb_define_const(mReadline, "USERNAME_COMPLETION_PROC", ucomp);
1606
1643
    history_get_offset_func = history_get_offset_history_base;
 
1644
    history_replace_offset_func = history_get_offset_0;
1607
1645
#if defined HAVE_RL_LIBRARY_VERSION
1608
1646
    version = rb_str_new_cstr(rl_library_version);
1609
1647
#if defined HAVE_CLEAR_HISTORY || defined HAVE_REMOVE_HISTORY
1613
1651
        if (history_get(history_get_offset_func(0)) == NULL) {
1614
1652
            history_get_offset_func = history_get_offset_0;
1615
1653
        }
1616
 
#if !defined HAVE_CLEAR_HISTORY
 
1654
#ifdef HAVE_REPLACE_HISTORY_ENTRY
 
1655
        if (replace_history_entry(0, "a", NULL) == NULL) {
 
1656
            history_replace_offset_func = history_get_offset_history_base;
 
1657
        }
 
1658
#endif
 
1659
#ifdef HAVE_CLEAR_HISTORY
1617
1660
        clear_history();
1618
1661
#else
1619
1662
        {
1633
1676
    rb_define_const(mReadline, "VERSION", version);
1634
1677
 
1635
1678
    rl_attempted_completion_function = readline_attempted_completion_function;
1636
 
#if defined HAVE_RL_GETC_FUNCTION
1637
 
    rl_getc_function = readline_getc;
1638
 
    id_getbyte = rb_intern_const("getbyte");
1639
 
#elif defined HAVE_RL_EVENT_HOOK
1640
 
    rl_event_hook = readline_event;
1641
 
#endif
1642
1679
#ifdef HAVE_RL_CATCH_SIGNALS
1643
1680
    rl_catch_signals = 0;
1644
1681
#endif