RSTRING(value)->ptr == NULL?

Tietew e$B$G$9!#e(B

RString::ptr e$B$,e(B NULL e$B$Je(B String
e$B$r%i%$%V%i%j$KEO$7$?:]$Ke(B SEGV e$B$re(B
e$B5/$3$9$3$H$,$"$j$^$9!#e(B

e$B6qBNE*$K$ONc$($Pe(B
require ‘rubygems’
require ‘idn’
IDN::Idna.toASCII(" ".chop.downcase)
e$B$,e(B SEGV e$B$j$^$9!#e(B

idna.c e$B$Oe(B
rb_check_convert_type(str, T_STRING, “String”, “to_s”);
e$B$r8F$s$G$$$^$9$,!"e(BStringValue() e$B$O$7$F$$$^$;$s!#e(B
e$B$s$Ge(B RSTRING(str)->ptr e$B$,e(B NULL e$B$N%^%^e(B idna_to_ascii_8z
e$B$r8F$s$G!"e(B
e$B$=$NCf$Ge(B SEGV e$B$7$^$9!#e(B

e$B$3$l$Oe(B StringValue() e$B$7$J$$e(B idna.c
e$B$,0-$$$s$G$7$g$&$+!#e(B

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

In message “Re: [ruby-dev:31774] RSTRING(value)->ptr == NULL ?”
on Tue, 11 Sep 2007 17:04:26 +0900, Tietew
[email protected] writes:

|RString::ptr e$B$,e(B NULL e$B$Je(B String e$B$r%i%$%V%i%j$KEO$7$?:]$Ke(B SEGV e$B$re(B
|e$B5/$3$9$3$H$,$"$j$^$9!#e(B

|e$B$3$l$Oe(B StringValue() e$B$7$J$$e(B idna.c e$B$,0-$$$s$G$7$g$&$+!#e(B

e$B$G$-$l$P$=$&$$$$$?$$$H$3$m$G$9!#OC$rJ9$+$J$$$G$b$J$$$G$9$,!#e(B

On Wed, 12 Sep 2007 14:45:59 +0900
In article [email protected]
[[ruby-dev:31778] Re: RSTRING(value)->ptr == NULL ?]
Yukihiro M. [email protected] wrote:

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

e$B$"$j$,$H$&$4$6$$$^$9!#e(B

|RString::ptr e$B$,e(B NULL e$B$Je(B String e$B$r%i%$%V%i%j$KEO$7$?:]$Ke(B SEGV e$B$re(B
|e$B5/$3$9$3$H$,$"$j$^$9!#e(B

|e$B$3$l$Oe(B StringValue() e$B$7$J$$e(B idna.c e$B$,0-$$$s$G$7$g$&$+!#e(B

e$B$G$-$l$P$=$&$$$$$?$$$H$3$m$G$9!#OC$rJ9$+$J$$$G$b$J$$$G$9$,!#e(B

rubyforgee$B$Ne(Bidne$B$K%P%0%l%]=P$=$&$H$7$F5?Ld$K;W$C$?$s$G$9!#e(B

e$B$3$&$$$&e(B String e$B$r:n$k:G>.$N%3!<%I$Oe(B " ".chop.dup
e$B$N$h$&$J$N$G!"e(B
e$B%i%$%V%i%j$K$3$&$$$&J8;zNs$r6t$o$;$FMn$A$J$$$+$I$&$+3N$+$a$F$_$ke(B
e$B$H$+!#e(B

In article [email protected],
Tietew [email protected] writes:

e$B%i%$%V%i%j$K$3$&$$$&J8;zNs$r6t$o$;$FMn$A$J$$$+$I$&$+3N$+$a$F$_$ke(B
e$B$H$+!#e(B

[ruby-core:1177] e$B$G;w$?;XE&$,$5$l$F$$$^$9!#$=$N%9%l%C%I$K$*e(B
e$B$$$F$^$D$b$H$5$s$Oe(B [ruby-core:1185] e$B$Ge(B 1.8.0
e$B$K$O6uJ8;zNs$Ge(B
e$B$be(B ptr e$B$Oe(B “” e$B$r;X$9$h$&$K$9$k$HH/[email protected]$7$F$$$^$9!#e(B

e$B$^$?!"e(B1.9 e$B$G$Oe(B RSTRING_PTR(str) e$B$Oe(B " ".chop.dup
e$B$Oe(B NULL e$B$K$Je(B
e$B$j$^$;$s!#e(B

e$B$=$N$&$Ae(B Ruby e$BK\BN$,JQ$o$C$FLdBj$,L5$/$J$k0l;~E*$JOC$KBP$7$Fe(B
e$B%i%$%V%i%[email protected]$5$;$k$N$OL5BL$JO+NO$G!"$"$^$j9,$;$JA*Br$G$Oe(B
e$BL5$$$H46$8$^$9!#e(B

e$B$J$*!“e(B[ruby-core:1185] e$B$He(B [ruby-dev:31778]
e$B$NH/[email protected]$K$O?)$$0ce(B
e$B$$$,$”$j$^$9$,!"$h$/$"$k$3$H$G$9!#;d$N?dB,$H$7$F$O!“e(BNULL e$B$Ke(B
[email protected]$l$G$”[email protected]$,9b$$$H;W$$$^$9!#e(B

[email protected]$G$9!#e(B

At Thu, 20 Sep 2007 14:12:43 +0900,
Tanaka A. wrote in [ruby-dev:31800]:

[ruby-core:1177] e$B$G;w$?;XE&$,$5$l$F$$$^$9!#$=$N%9%l%C%I$K$*e(B
e$B$$$F$^$D$b$H$5$s$Oe(B [ruby-core:1185] e$B$Ge(B 1.8.0 e$B$K$O6uJ8;zNs$Ge(B
e$B$be(B ptr e$B$Oe(B “” e$B$r;X$9$h$&$K$9$k$HH/[email protected]$7$F$$$^$9!#e(B

e$B$=$s$JOC$b$"$j$^$7$?$M$’!#e(B

e$B$^$?!"e(B1.9 e$B$G$Oe(B RSTRING_PTR(str) e$B$Oe(B " ".chop.dup e$B$Oe(B NULL e$B$K$Je(B
e$B$j$^$;$s!#e(B

RSTRING_PTR()e$B$N<BAu<+BN$,Bg$-$/JQ$o$C$F$^$9$+$i!#e(B

e$B$J$*!“e(B[ruby-core:1185] e$B$He(B [ruby-dev:31778] e$B$NH/[email protected]$K$O?)$$0ce(B
e$B$$$,$”$j$^$9$,!"$h$/$"$k$3$H$G$9!#;d$N?dB,$H$7$F$O!“e(BNULL e$B$Ke(B
[email protected]$l$G$”[email protected]$,9b$$$H;W$$$^$9!#e(B

e$B$b$&:G=i$+$ie(BNULLe$B$K$O$7$J$$$H$$$&$3$H$G$b$$$$$H;W$$$^$9$,!"$3$s$Je(B
e$B$H$3$G$I$&$G$7$g$&$+!#e(B

Index: string.c

— string.c (revision 13449)
+++ string.c (working copy)
@@ -60,11 +60,15 @@ str_frozen_check(s)
}

+static VALUE str_alloc0 _((VALUE, int));
static VALUE str_alloc _((VALUE));
+static VALUE str_alloc1 _((VALUE));
+
static VALUE
-str_alloc(klass)
+str_alloc0(klass, flags)
VALUE klass;

  • int flags;
    {
    NEWOBJ(str, struct RString);
  • OBJSETUP(str, klass, T_STRING);
  • OBJSETUP(str, klass, flags);

    str->ptr = 0;
    @@ -75,4 +79,23 @@ str_alloc(klass)
    }

+static const char null_str[] = “”;
+#define null_str (char *)null_str
+
+static VALUE
+str_alloc(klass)

  • VALUE klass;
    +{
  • VALUE str = str_alloc0(klass, T_STRING | ELTS_SHARED);
  • RSTRING(str)->ptr = null_str;
  • return str;
    +}

+static VALUE
+str_alloc1(klass)

  • VALUE klass;
    +{
  • return str_alloc0(klass, T_STRING);
    +}

static VALUE
str_new(klass, ptr, len)
@@ -87,5 +110,5 @@ str_new(klass, ptr, len)
}

  • str = str_alloc(klass);
  • str = str_alloc1(klass);
    RSTRING(str)->len = len;
    RSTRING(str)->aux.capa = len;
    @@ -146,5 +169,4 @@ str_new3(klass, str)
    RSTRING(str2)->ptr = RSTRING(str)->ptr;
    RSTRING(str2)->aux.shared = str;
  • FL_SET(str2, ELTS_SHARED);

    return str2;
    @@ -165,5 +187,5 @@ str_new4(klass, str)
    VALUE klass, str;
    {

  • VALUE str2 = str_alloc(klass);

  • VALUE str2 = str_alloc1(klass);

    RSTRING(str2)->len = RSTRING(str)->len;
    @@ -224,5 +246,5 @@ rb_str_buf_new(capa)
    long capa;
    {

  • VALUE str = str_alloc(rb_cString);
  • VALUE str = str_alloc1(rb_cString);

    if (capa < STR_BUF_MIN_SIZE) {
    @@ -258,4 +280,6 @@ rb_str_to_str(str)
    }

+static int str_independent _((VALUE));
+
static void
rb_str_shared_replace(str, str2)
@@ -263,6 +287,5 @@ rb_str_shared_replace(str, str2)
{
if (str == str2) return;

  • rb_str_modify(str);
  • if (!FL_TEST(str, ELTS_SHARED)) free(RSTRING(str)->ptr);
  • if (str_independent(str)) xfree(RSTRING(str)->ptr);
    if (NIL_P(str2)) {
    RSTRING(str)->ptr = 0;
    @@ -539,6 +570,4 @@ rb_str_associated(str)
    }

-static char *null_str = “”;

VALUE
rb_string_value(ptr)
@@ -2266,6 +2295,9 @@ rb_str_replace(str, str2)
RSTRING(str)->aux.shared = RSTRING(str2)->aux.shared;
}

  • else if (!RSTRING(str2)->len) {
  • FL_SET(str, ELTS_SHARED);
  • RSTRING(str)->ptr = null_str;
  • }
    else {
  • rb_str_modify(str);
    rb_str_resize(str, RSTRING(str2)->len);
    memcpy(RSTRING(str)->ptr, RSTRING(str2)->ptr, RSTRING(str2)->len);

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

In message “Re: [ruby-dev:31800] Re: RSTRING(value)->ptr == NULL ?”
on Thu, 20 Sep 2007 14:12:43 +0900, Tanaka A. [email protected]
writes:

|[ruby-core:1177] e$B$G;w$?;XE&$,$5$l$F$$$^$9!#$=$N%9%l%C%I$K$*e(B
|e$B$$$F$^$D$b$H$5$s$Oe(B [ruby-core:1185] e$B$Ge(B 1.8.0 e$B$K$O6uJ8;zNs$Ge(B
|e$B$be(B ptr e$B$Oe(B “” e$B$r;X$9$h$&$K$9$k$HH/[email protected]$7$F$$$^$9!#e(B

e$B$"!<!"$=$&$$$($P$=$&[email protected]$C$?$h$&$Je(B(e$BCQe(B

|e$B$J$*!“e(B[ruby-core:1185] e$B$He(B [ruby-dev:31778] e$B$NH/[email protected]$K$O?)$$0ce(B
|e$B$$$,$”$j$^$9$,!"$h$/$"$k$3$H$G$9!#;d$N?dB,$H$7$F$O!“e(BNULL e$B$Ke(B
|[email protected]$l$G$”[email protected]$,9b$$$H;W$$$^$9!#e(B

e$BCfED$5$s$Ke(B[ruby-dev:31800]e$B$N%Q%C%A$rEv$F$F$b$i$$$^$7$g$&!#e(B
e$B$*4j$$$7$^$9e(B e$B!de(B e$BCfED$5$se(B

e$BKNIt$G$9!#e(B

Nobuyoshi N. wrote:

+static const char null_str[] = “”;
+#define null_str (char *)null_str

rb_str_replacee$B$G$3$$$D$re(Brealloce$B$7$h$&$H$7$FMn$A$^$9!#e(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs