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

« back to all changes in this revision

Viewing changes to string.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:
725
725
str_new_empty(VALUE str)
726
726
{
727
727
    VALUE v = rb_str_new5(str, 0, 0);
 
728
    rb_enc_copy(v, str);
728
729
    OBJ_INFECT(v, str);
729
730
    return v;
730
731
}
1328
1329
    if (expand < 0) {
1329
1330
        rb_raise(rb_eArgError, "negative expanding string size");
1330
1331
    }
1331
 
    if (!str_independent(str) ||
1332
 
        (expand > 0 &&
1333
 
         (!STR_EMBED_P(str) ||
1334
 
          RSTRING_LEN(str) + expand > RSTRING_EMBED_LEN_MAX))) {
 
1332
    if (!str_independent(str)) {
1335
1333
        str_make_independent_expand(str, expand);
1336
1334
    }
 
1335
    else if (expand > 0) {
 
1336
        long len = RSTRING_LEN(str);
 
1337
        long capa = len + expand;
 
1338
        if (!STR_EMBED_P(str)) {
 
1339
            REALLOC_N(RSTRING(str)->as.heap.ptr, char, capa+1);
 
1340
            RSTRING(str)->as.heap.aux.capa = capa;
 
1341
        }
 
1342
        else if (capa > RSTRING_EMBED_LEN_MAX) {
 
1343
            str_make_independent_expand(str, expand);
 
1344
        }
 
1345
    }
1337
1346
    ENC_CODERANGE_CLEAR(str);
1338
1347
}
1339
1348
 
2073
2082
VALUE
2074
2083
rb_str_concat(VALUE str1, VALUE str2)
2075
2084
{
2076
 
    unsigned int lc;
 
2085
    unsigned int code;
 
2086
    rb_encoding *enc = STR_ENC_GET(str1);
2077
2087
 
2078
2088
    if (FIXNUM_P(str2) || TYPE(str2) == T_BIGNUM) {
2079
 
        if (rb_num_to_uint(str2, &lc) == 0) {
 
2089
        if (rb_num_to_uint(str2, &code) == 0) {
2080
2090
        }
2081
2091
        else if (FIXNUM_P(str2)) {
2082
2092
            rb_raise(rb_eRangeError, "%ld out of char range", FIX2LONG(str2));
2088
2098
    else {
2089
2099
        return rb_str_append(str1, str2);
2090
2100
    }
2091
 
    {
2092
 
        rb_encoding *enc = STR_ENC_GET(str1);
 
2101
 
 
2102
    if (enc == rb_usascii_encoding()) {
 
2103
        /* US-ASCII automatically extended to ASCII-8BIT */
 
2104
        char buf[1] = {(char)code};
 
2105
        if (code > 0xFF) {
 
2106
            rb_raise(rb_eRangeError, "%u out of char range", code);
 
2107
        }
 
2108
        rb_str_cat(str1, buf, 1);
 
2109
        if (code > 127) {
 
2110
            rb_enc_associate(str1, rb_ascii8bit_encoding());
 
2111
            ENC_CODERANGE_SET(str1, ENC_CODERANGE_VALID);
 
2112
        }
 
2113
    }
 
2114
    else {
2093
2115
        long pos = RSTRING_LEN(str1);
2094
2116
        int cr = ENC_CODERANGE(str1);
2095
2117
        int len;
 
2118
        char *buf;
2096
2119
 
2097
 
        if ((len = rb_enc_codelen(lc, enc)) <= 0) {
2098
 
            rb_raise(rb_eRangeError, "%u invalid char", lc);
 
2120
        switch (len = rb_enc_codelen(code, enc)) {
 
2121
          case ONIGERR_INVALID_CODE_POINT_VALUE:
 
2122
            rb_raise(rb_eRangeError, "invalid codepoint 0x%X in %s", code, rb_enc_name(enc));
 
2123
            break;
 
2124
          case ONIGERR_TOO_BIG_WIDE_CHAR_VALUE:
 
2125
          case 0:
 
2126
            rb_raise(rb_eRangeError, "%u out of char range", code);
 
2127
            break;
 
2128
        }
 
2129
        buf = ALLOCA_N(char, len + 1);
 
2130
        rb_enc_mbcput(code, buf, enc);
 
2131
        if (rb_enc_precise_mbclen(buf, buf + len + 1, enc) != len) {
 
2132
            rb_raise(rb_eRangeError, "invalid codepoint 0x%X in %s", code, rb_enc_name(enc));
2099
2133
        }
2100
2134
        rb_str_resize(str1, pos+len);
2101
 
        rb_enc_mbcput(lc, RSTRING_PTR(str1)+pos, enc);
2102
 
        if (cr == ENC_CODERANGE_7BIT && lc > 127)
 
2135
        strncpy(RSTRING_PTR(str1) + pos, buf, len);
 
2136
        if (cr == ENC_CODERANGE_7BIT && code > 127)
2103
2137
            cr = ENC_CODERANGE_VALID;
2104
2138
        ENC_CODERANGE_SET(str1, cr);
2105
 
        return str1;
2106
2139
    }
 
2140
    return str1;
2107
2141
}
2108
2142
 
2109
2143
/*
3163
3197
 *  Element Reference---If passed a single <code>Fixnum</code>, returns a
3164
3198
 *  substring of one character at that position. If passed two <code>Fixnum</code>
3165
3199
 *  objects, returns a substring starting at the offset given by the first, and
3166
 
 *  a length given by the second. If given a range, a substring containing
3167
 
 *  characters at offsets given by the range is returned. In all three cases, if
3168
 
 *  an offset is negative, it is counted from the end of <i>str</i>. Returns
3169
 
 *  <code>nil</code> if the initial offset falls outside the string, the length
3170
 
 *  is negative, or the beginning of the range is greater than the end of the
3171
 
 *  string.
 
3200
 *  with a length given by the second. If passed a range, its beginning and end
 
3201
 *  are interpreted as offsets delimiting the substring to be returned. In all
 
3202
 *  three cases, if an offset is negative, it is counted from the end of <i>str</i>.
 
3203
 *  Returns <code>nil</code> if the initial offset falls outside the string or
 
3204
 *  the length is negative.
3172
3205
 *
3173
3206
 *  If a <code>Regexp</code> is supplied, the matching portion of <i>str</i> is
3174
3207
 *  returned. If a numeric or name parameter follows the regular expression, that
3179
3212
 *
3180
3213
 *     a = "hello there"
3181
3214
 *     a[1]                   #=> "e"
3182
 
 *     a[1,3]                 #=> "ell"
3183
 
 *     a[1..3]                #=> "ell"
3184
 
 *     a[-3,2]                #=> "er"
 
3215
 *     a[2, 3]                #=> "llo"
 
3216
 *     a[2..3]                #=> "ll"
 
3217
 *     a[-3, 2]               #=> "er"
 
3218
 *     a[7..-2]               #=> "her"
3185
3219
 *     a[-4..-2]              #=> "her"
 
3220
 *     a[-2..-4]              #=> ""
3186
3221
 *     a[12..-1]              #=> nil
3187
 
 *     a[-2..-4]              #=> ""
3188
3222
 *     a[/[aeiou](.)\1/]      #=> "ell"
3189
3223
 *     a[/[aeiou](.)\1/, 0]   #=> "ell"
3190
3224
 *     a[/[aeiou](.)\1/, 1]   #=> "l"
5233
5267
 *  call-seq:
5234
5268
 *     str.tr(from_str, to_str)   => new_str
5235
5269
 *
5236
 
 *  Returns a copy of <i>str</i> with the characters in <i>from_str</i> 
5237
 
 *  replaced by the corresponding characters in <i>to_str</i>. If 
 
5270
 *  Returns a copy of <i>str</i> with the characters in <i>from_str</i>
 
5271
 *  replaced by the corresponding characters in <i>to_str</i>. If
5238
5272
 *  <i>to_str</i> is shorter than <i>from_str</i>, it is padded with its last
5239
5273
 *  character in order to maintain the correspondence.
5240
5274
 *
5241
5275
 *     "hello".tr('el', 'ip')      #=> "hippo"
5242
5276
 *     "hello".tr('aeiou', '*')    #=> "h*ll*"
5243
 
 * 
 
5277
 *
5244
5278
 *  Both strings may use the c1-c2 notation to denote ranges of characters,
5245
5279
 *  and <i>from_str</i> may start with a <code>^</code>, which denotes all
5246
5280
 *  characters except those listed.