[Bug #674] Failure: test_aset(TestSDBM)

Bug #674: Failure: test_aset(TestSDBM)
http://redmine.ruby-lang.org/issues/show/674

e$B5/I<<Te(B: Kazuhiro NISHIYAMA
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal
e$B%+%F%4%je(B: core

  1. Failure:
    test_aset(TestSDBM) […/trunk/test/sdbm/test_sdbm.rb:174]:
    <“”> expected but was
    <“barbarfoo”>.
    e$B$K$D$$$FD4$Y$F$_$^$7$?!#e(B

ext/sdbm/init.ce$B$Ne(Bfsdbm_fetche$B$Ne(B
return rb_external_str_new(value.dptr, value.dsize);
e$B$Ge(Bvalue = {dptr = “barbarfoo”, dsize = 0}e$B$H$J$C$F$$$F!"e(B
lene$B$Ke(B0e$B$r;XDj$7$F$$$k$N$Ke(Bstring.ce$B$Ne(Brb_external_str_new_with_ence$B$,e(B
if (len == 0 && ptr) len = strlen(ptr);
e$B$Ge(Blene$B$rL5;k$7$Fe(Bstrlene$B$7$F$7$^$C$F$$$k$N$,860x$N$h$&$G$9!#e(B

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

At Wed, 22 Oct 2008 03:16:57 +0900,
Kazuhiro NISHIYAMA wrote in [ruby-dev:36854]:

ext/sdbm/init.ce$B$Ne(Bfsdbm_fetche$B$Ne(B
return rb_external_str_new(value.dptr, value.dsize);
e$B$Ge(Bvalue = {dptr = “barbarfoo”, dsize = 0}e$B$H$J$C$F$$$F!"e(B
lene$B$Ke(B0e$B$r;XDj$7$F$$$k$N$Ke(Bstring.ce$B$Ne(Brb_external_str_new_with_ence$B$,e(B
if (len == 0 && ptr) len = strlen(ptr);
e$B$Ge(Blene$B$rL5;k$7$Fe(Bstrlene$B$7$F$7$^$C$F$$$k$N$,860x$N$h$&$G$9!#e(B

e$B$^$@e(Blen==0e$B$r;XDj$7$Fe(Brb_external_str_new_with_enc()e$B$r8F$V%3!<%I$Oe(B
e$B$J$$$h$&$G$9$7!“e(Brb_{external,locale}_str_new()e$B$r$=$l$>$lFs$D$KJ,e(B
e$B$1$?$[$&$,$$$$$s$8$c$J$$$G$7$g$&$+!#$”$k$$$O!"@5$7$$CM$H$7$F$"$je(B
e$B$&$ke(B0e$B$8$c$J$/$Fe(B-1e$B$"$?$j$K$9$k$H$+!#e(B

Index: include/ruby/intern.h

— include/ruby/intern.h (revision 19872)
+++ include/ruby/intern.h (working copy)
@@ -549,5 +549,7 @@ VALUE rb_tainted_str_new(const char*, lo
VALUE rb_tainted_str_new2(const char*);
VALUE rb_external_str_new(const char*, long);
+VALUE rb_external_str_new_cstr(const char*);
VALUE rb_locale_str_new(const char*, long);
+VALUE rb_locale_str_new_cstr(const char*);
VALUE rb_str_buf_new(long);
VALUE rb_str_buf_new_cstr(const char*);
@@ -620,4 +622,16 @@ size_t rb_str_capacity(VALUE);
rb_usascii_str_new_cstr(str);
})
+#define rb_external_str_new_cstr(str) extension (
+{ \

  • (__builtin_constant_p(str)) ? \
  • rb_external_str_new(str, strlen(str)) : \
  • rb_external_str_new_cstr(str);
    +})
    +#define rb_locale_str_new_cstr(str) extension (
    +{ \
  • (__builtin_constant_p(str)) ? \
  • rb_locale_str_new(str, strlen(str)) : \
  • rb_locale_str_new_cstr(str);
    +})
    #define rb_str_buf_new_cstr(str) extension (
    {
    Index: string.c
    ===================================================================
    — string.c (revision 19872)
    +++ string.c (working copy)
    @@ -29,4 +29,6 @@
    #undef rb_tainted_str_new_cstr
    #undef rb_usascii_str_new_cstr
    +#undef rb_external_str_new_cstr
    +#undef rb_locale_str_new_cstr
    #undef rb_str_new2
    #undef rb_str_new3
    @@ -529,5 +531,4 @@ rb_external_str_new_with_enc(const char
    VALUE str;
  • if (len == 0 && !ptr) len = strlen(ptr);
    str = rb_tainted_str_new(ptr, len);
    rb_enc_associate(str, eenc);
    @@ -542,4 +543,11 @@ rb_external_str_new(const char *ptr, lon

VALUE
+rb_external_str_new_cstr(const char *ptr)
+{

  • long len = ptr ? strlen(ptr) : 0;
  • return rb_external_str_new_with_enc(ptr, len,
    rb_default_external_encoding());
    +}

+VALUE
rb_locale_str_new(const char *ptr, long len)
{
@@ -548,4 +556,11 @@ rb_locale_str_new(const char *ptr, long

VALUE
+rb_locale_str_new_cstr(const char *ptr)
+{

  • long len = ptr ? strlen(ptr) : 0;
  • return rb_external_str_new_with_enc(ptr, len,
    rb_locale_encoding());
    +}

+VALUE
rb_str_export(VALUE str)
{

e$B%A%1%C%He(B #674 e$B$,99?7$5$l$^$7$?!#e(B (by Yukihiro M.)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

Applied in changeset r19885.

http://redmine.ruby-lang.org/issues/show/674