"string"[/str/]=:not_string dumps core

e$B$J$+$@$G$9!#e(B

http://yowaken.dip.jp/tdiary/20070908.html#p05 e$B$N7o$N%Q%C%A$G$9!#e(B
ENCODING_*e$B%^%/%m$Oe(BT_STRINGe$B8BDj$H$$$&$3$H$G$9$h$M!#e(B

Index: encoding.c

— encoding.c (revision 13443)
+++ encoding.c (working copy)
@@ -83,4 +83,5 @@ void
rb_enc_associate_index(VALUE obj, int idx)
{

  • Check_Type(obj, T_STRING);
    if (idx < ENCODING_INLINE_MAX) {
    ENCODING_SET(obj, idx);
    @@ -118,6 +119,8 @@ int
    rb_enc_get_index(VALUE obj)
    {
  • int i = ENCODING_GET(obj);
  • int i;

  • Check_Type(obj, T_STRING);

  • i = ENCODING_GET(obj);
    if (i == ENCODING_INLINE_MAX) {
    VALUE iv;
    Index: string.c
    ===================================================================
    — string.c (revision 13443)
    +++ string.c (working copy)
    @@ -1997,4 +1997,5 @@ rb_str_subpat_set(VALUE str, VALUE re, i
    end = RMATCH(match)->END(nth);
    len = end - start;

  • StringValue(val);
    rb_enc_check(str, val);
    rb_str_splice_0(str, start, len, val);

e$B$J$+$@$G$9!#e(B

At Fri, 14 Sep 2007 23:47:26 +0900,
Nobuyoshi N. wrote in [ruby-dev:31780]:

http://yowaken.dip.jp/tdiary/20070908.html#p05 e$B$N7o$N%Q%C%A$G$9!#e(B
ENCODING_*e$B%^%/%m$Oe(BT_STRINGe$B8BDj$H$$$&$3$H$G$9$h$M!#e(B

e$B$@$1$@$H$^$:$$$G$9$M!#e(BT_REGEXPe$B$He(BT_FILEe$B$b$+$Je(B?

Index: encoding.c

— encoding.c (revision 13443)
+++ encoding.c (working copy)
@@ -80,7 +80,47 @@ rb_enc_find(const char *name)
}

+static int
+enc_capable(VALUE obj)
+{

  • if (IMMEDIATE_P(obj)) return Qfalse;
  • switch (BUILTIN_TYPE(obj)) {
  •  case T_STRING:
    
  •  case T_REGEXP:
    
  •  case T_FILE:
    
  • return Qtrue;
  •  default:
    
  • return Qfalse;
  • }
    +}

+static void
+enc_check_capable(VALUE x)
+{

  • if (!enc_capable(x)) {
  • const char *etype;
  • if (NIL_P(x)) {
  •  etype = "nil";
    
  • }
  • else if (FIXNUM_P(x)) {
  •  etype = "Fixnum";
    
  • }
  • else if (SYMBOL_P(x)) {
  •  etype = "Symbol";
    
  • }
  • else if (rb_special_const_p(x)) {
  •  etype = RSTRING_PTR(rb_obj_as_string(x));
    
  • }
  • else {
  •  etype = rb_obj_classname(x);
    
  • }
  • rb_raise(rb_eTypeError, “wrong argument type %s (not encode
    capable)”, etype);
  • }
    +}

void
rb_enc_associate_index(VALUE obj, int idx)
{

  • enc_check_capable(obj);
    if (idx < ENCODING_INLINE_MAX) {
    ENCODING_SET(obj, idx);
    @@ -118,6 +158,8 @@ int
    rb_enc_get_index(VALUE obj)
    {
  • int i = ENCODING_GET(obj);
  • int i;

  • enc_check_capable(obj);

  • i = ENCODING_GET(obj);
    if (i == ENCODING_INLINE_MAX) {
    VALUE iv;

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:31788] Re: “string”[/str/]=:not_string dumps
core”
on Sat, 15 Sep 2007 15:05:21 +0900, Nobuyoshi N.
[email protected] writes:

|At Fri, 14 Sep 2007 23:47:26 +0900,
|Nobuyoshi N. wrote in [ruby-dev:31780]:
|> http://yowaken.dip.jp/tdiary/20070908.html#p05 e$B$N7o$N%Q%C%A$G$9!#e(B
|> ENCODING_*e$B%^%/%m$Oe(BT_STRINGe$B8BDj$H$$$&$3$H$G$9$h$M!#e(B
|
|e$B$@$1$@$H$^$:$$$G$9$M!#e(BT_REGEXPe$B$He(BT_FILEe$B$b$+$Je(B?

e$BEvLL$O$=$l$G$$$$$+$J$"!#%3%_%C%H$7$F$/$@$5$$!#e(B