[request]C API$B$N3HD%(B

藤と申します。

RubyのC APIã«è¿½åŠ ã—ã¦ã„ãŸã ããŸã„ã‚‚ã®ãŒã‚ã‚‹ã®ã§ã™ãŒï¼Œæ¤œè¨Žã—ã¦ã„ãŸã ã‘ã¾ã›ã‚“ã‹ã€‚
あるいは以下2ã¤ã¨ã‚‚ä»£æ›¿æ‰‹æ®µãŒã‚ã‚Šï¼Œç§ãŒçŸ¥ã‚‰ãªã„ã ã‘ã‹ã‚‚ã—ã‚Œã¾ã›ã‚“ãŒï¼Œãã®å ´åˆã¯ãŠè¨±ã—ãã ã•ã„ã€‚

  1. version.hをインストールしてほしい

version.hは1.8まではインストールされているようですが,1.9になってからインストールされないようです。ruby/version.hとしてインストールしていただけませんか。

  1. 文字列操作の C APIの拡張
    拡張ライブラリを書いていると何かと文字列操作をすることが多いのですが,フォーマット系APIがrb_sprintf()くらいしかなく不便を感じることがあります。
    そこで,以下のAPIã‚’åŠ ãˆã¦ã„ãŸã ã‘ã¾ã›ã‚“ã‹ï¼ˆå®Ÿè£…ã¯æ·»ä»˜ã—ãŸsprintf.c.diff)。

/* include/ruby/encoding.h /
PRINTF_ARGS(VALUE rb_str_enc_newf(rb_encoding
, const char*, …), 2,
3);
VALUE rb_str_enc_vnewf(rb_encoding*, const char*, va_list);

/* include/ruby/intern.h /
PRINTF_ARGS(VALUE rb_str_newf(const char
, …), 1, 2);
PRINTF_ARGS(VALUE rb_str_catf(VALUE, const char*, …), 2, 3);
VALUE rb_str_vnewf(const char*, va_list);
VALUE rb_str_vcatf(VALUE, const char*, va_list);

rb_str_catf()/rb_str_vcatf()は,rb_str_cat()+rb_sprintf()のようなもので,フォーマットにしたがって整形した文字列を別の文字列に連結します。
newf()類はrb_sprintf()類の単なる別名なので,「新しくオブジェクトを作成する」という強い印象を与える以外の効果は特にありません。

なお,フォーマット系APIを充実させるメリットとしては

  • sprintf() / snprintf()を使わずにすむ
  • バッファを自前で管理せずに済むため,書きやすく読みやすい
    また,デメリットは
  • ヒープ上にメモリを確保するのでsprintf()/snprintf()より遅い
  • 新しいAPIを導入することによりC APが複雑になる
  • 新しいコードを導入することによりバグが混入する可能性がある
    ということが考えられます。

要望は以上です。ご検討よろしくお願いします。

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

Goro Fuji wrote:

PRINTF_ARGS(VALUE rb_str_newf(const char*, …), 1, 2);
PRINTF_ARGS(VALUE rb_str_catf(VALUE, const char*, …), 2, 3);
VALUE rb_str_vnewf(const char*, va_list);
VALUE rb_str_vcatf(VALUE, const char*, va_list);

rb_str_catf()/rb_str_vcatf()e$B$O!$e(Brb_str_cat()+rb_sprintf()e$B$N$h$&$J$b$N$G!$e(B
e$B%U%)!<%^%C%H$K$7$?$,[email protected]$7$?J8;zNs$rJL$NJ8;zNs$KO"7k$7$^$9!#e(B
newf()e$BN$Oe(Brb_sprintf()e$BN$NC1$J$kJLL>$J$N$G!$!V?7$7$/%*%V%8%’%/%H$r:[email protected]$9$k!We(B
e$B$H$$$&6/$$0u>]$rM?$($k0J30$N8z2L$OFC$K$"$j$^$;$s!#e(B

[email protected]$r$$$/$D$+!#e(B

== e$BL>A0e(B
e$B%(%s%3!<%I$r0U<1$7$?J8;zNs=hM}$Ne(B C API e$BL>$O!"e(Brb_enc_str_*
e$B$+$H;W$$$^$9!#e(B

== newf
e$B$$$A$$$Ae(B new e$B$O$$$i$J$$$+$J$!$H;W$$$^$9!#e(B
Ruby e$B$Ne(B C API
e$B$,FbIt=hM}MQ$K%*%V%8%’%/%H$r:n$k$3$H$O$h$/$"$k$N$G!#e(B
e$B$D$^$k$H$3$m!"e(Bsprintf e$B%7%j!<%:$G==J,$G$7$g$&!#e(B

== rb_str_newf
rb_encoding e$B$Ke(B NULL e$B$rEO$9$N$O$$$+$,$J$b$N$+$H!#e(B
e$B$^$!!"$=$&$;[email protected]$J$$>l9g$b$"$k$N$+$b$7$l$^$;$s$,!"e(B
e$B$o$6$o$6JXMx$K$9$kI,MW$O$J$$$G$7$g$&!#e(B

== catfe$B7Oe(B
e$B$3$l$C$F!“e(Brb_str_concat(str, rb_sprintf(”%s", “hoge”))
e$B$H$+$8$c%@%a$J$s$G$9$+$M!#e(B

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

At Sun, 20 Jul 2008 14:26:19 +0900,
Goro Fuji wrote in [ruby-dev:35597]:

  1. version.he$B$r%$%s%9%H!<%k$7$F$[$7$$e(B

version.he$B$Oe(B1.8e$B$^$G$O%$%s%9%H!<%k$5$l$F$$$k$h$&$G$9$,!$e(B1.9e$B$K$J$Ce(B
e$B$F$+$i%$%s%9%H!<%k$5$l$J$$$h$&$G$9!#e(Bruby/version.he$B$H$7$F%$%s%9e(B
e$B%H!<%[email protected]$1$^$;$s$+!#e(B

e$B2?$N$?$a$G$7$g$&$+!#$"$ke(BAPIe$B$NM-L5$rD4$Y$k$J$I$J$i!"e(Bmkmf.rbe$B$Ne(B
have_funce$B%a%=%C%I$J$I$r;H$C$F$/[email protected]$5$$!#e([email protected]$1$G$OD4$Y$k$3$He(B
e$B$,Fq$7$$$b$N$K$D$$$F$O!"6qBNE*$KMWK>[email protected]$1$l$P%^%/%m$re(B
e$BDj5A$9$k$3$H$GBP=h$7$^$9!#e(B

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

At Sun, 20 Jul 2008 14:26:19 +0900,
Goro Fuji wrote in [ruby-dev:35597]:

  1. e$BJ8;zNsA:n$Ne(B C APIe$B$N3HD%e(B e$B3HD%%i%$%V%i%j$r=q$$$F$$$k$H2?$+$HJ8;zNsA:n$r$9$k$3$H$,B?$$$Ne(B
    e$B$G$9$,!$%U%)!<%^%C%H7Oe(BAPIe$B$,e(Brb_sprintf()e$B$/$i$$$7$+$J$/ITJX$r46e(B
    e$B$8$k$3$H$,$"$j$^$9!#e(B
    e$B$=$3$G!$0J2<$Ne(BAPIe$B$r2C$([email protected]$1$^$;$s$+!J<BAu$OE:IU$7$?e(Bsprintf.c.diffe$B!K!#e(B

newfe$B7O$O4{B8$Ne(Brb_sprintf, rb_vsprintf, rb_enc_sprintf,
rb_enc_vsprintfe$B$H$^$C$?$/F1$8$G$9$h$M!#!VITJX!W$r2r>C$9$k$3$H$Ke(B
e$B$O$J$i$J$$$N$G$O$H;W$$$^$9$,!#e(B

rb_str_catf()/rb_str_vcatf()e$B$O!$e(Brb_str_cat()+rb_sprintf()e$B$N$he(B
e$B$&$J$b$N$G!$%U%)!<%^%C%H$K$7$?$,[email protected]$7$?J8;zNs$rJL$NJ8;zNse(B
e$B$KO"7k$7$^$9!#e(B

e$B0U?^$O$^$!M}2r$G$-$k$N$G$9$,!"ItJ,E*$KO"7k$7$J$,$ie(Bsprintfe$B$9$k$3e(B
e$B$H$C$F$I$N$/$i$$B?$$$s$G$7$g$&!#e(B

newf()e$BN$Oe(Brb_sprintf()e$BN$NC1$J$kJLL>$J$N$G!$!V?7$7$/%*%V%8%’%/e(B
e$B%H$r:[email protected]$9$k!W$H$$$&6/$$0u>]$rM?$($k0J30$N8z2L$OFC$K$"$j$^$;$s!#e(B

[email protected]$1$Ge(Bprintfe$B$rA[5/$7$m!"$H$$$&$N$O$$$5$5$+6l$7$$$N$G$O!#e(B

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

e$BFC$K;[email protected]$G$bH?BP$G$b$J$$$N$G$9$,!"0l$D5?Ld$J$N$O!“[email protected]$N8!>Z$H$$$&$N$,e(B
e$B$I$&$$$C$?$3$H$r;X$7$F$$$k$N$+$h$/$o$+$i$J$$$G$9!#$h$/J,$+$i$J$$$N$G!”$=e(B
e$B$l$,Fq$7$$$N$+$I$&$+$,;d$K$O8!>Z$G$-$J$$$G$9!#$*$=$i$/!“LdBj0U<1$NItJ,$re(B
e$B$_$s$J$H6&M-$7$F$b$i$($k$H!”;[email protected]$H$+H?BP$H$+$$$m$s$J0U8+$,$G$F$-$d$9$$$Ne(B
e$B$G$O$J$$$G$7$g$&$+!#e(B

Goro Fuji e$B$5$s$O=q$-$^$7$?e(B:

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

  1. e$BF05!e(B

e$B$^$:[email protected]@$,IT==J,[email protected]$C$?$3$H$r$*OM$S$7$^$9!#e(B

e$B$b$H$b$H6/$/M_$7$$$H;W$C$?$N$Oe(Brb_str_catf()e$B$G!$$3$l$O%i%$%V%i%jB&$G4J0W$+$D8zN($h$/<BAu$9$k$N$,Fq$7$$$?$a!$:#2s$NMWK>$r=P$9$K;j$j$^$7$?!#e(B
e$B$b$A$m$s!$;HMQ$9$k$N$,;[email protected][email protected]$H$7$?$iFH$j$h$,$j$JMWK>$G$9!#$=$3$Ge(BRubye$B$N%=!<%9%3!<%I$Ge(B/\bsn?printf/e$B$,;H$o$l$F$$$k>u67$bD4$Y$^$7$?!J0J2<$N5-=R$Oe(B2008e$BG/e(B7e$B7ne(B16e$BF|HG$K4p$E$-$^$9!K!#e(B

1.1 rb_str_catf()e$B$N<{MWe(B

e$B$?$H$($P!$0J2<$N$h$&$J%3!<%I$,e(Biseq.ce$B$K$"$j$^$9!#e(B

#line 747 iseq.c (ruby_iseq_disasm_insn())
snprintf(buff, sizeof(buff), "%04d %-16s ", pos, insn_name_buff);
rb_str_cat2(str, buff);

e$B$3$l$Oe(Brb_str_catf()e$B$,$"$l$P0J2<$N$h$&$K5-=R$G$-$^$9!J<B:]$K$O$5$i$Ke([email protected]@$b:o=|$G$-$^$9!K!#e(B

rb_str_catf(str, "%04d %-16s ", pos, insn_name_buff);

e$B$3$N=q$-49$($N7k2L!$e(Bsizeof(buff)[email protected]$N8!>Z$,ITMW$K$J$j!$J]<i$7$d$9$/$J$k$H;W$o$l$^$9!#e(B

e$BF1MM$N%3!<%I$,e(Biseq.ce$B$Ne(Bruby_iseq_disasm()e$B$Ne(B843e$B9TL\IU6a$He(B885e$B9TL\IU6a!$e(Bprocess.ce$B$Ne(Bps_message()e$B!$e(Bfile.ce$B$Ne(Brb_stat_inspec()e$B$J$I$K$_$i$l$^$9!#3HD%%i%$%V%i%j$K$D$$$F$O>$7$/D4$Y$F$$$^$;$s$,!$e(Bbigdecimale$B$J$I$Ge(Bsprintf()e$B$rB?MQ$7$F$$$k$h$&$G$9!#e(B

e$B$3$N$3$H$+$i!$e(Bcatf()e$B$K$D$$$F$O$=$l$J$j$N<{MW$,$"$k$N$G$O$J$$$+$H9M$($^$7$?!#e(B

1.2 rb_str_newf()e$B$N<{MWe(B

e$B$^$?!$$3$ND4::$N7k2L!$e(Bcatf()e$B$NMQES0J30$G$be(Bs(n)printf()e$B$,B?MQ$5$l$F$$$k$3$H$K5$IU$-$^$7$?!#$?$H$($P!$e(Berror.ce$B$Ne(Brb_name_error()e$B$K$*$$$F0J2<$N5-=R$,$"$j$^$9!#e(B

#line 624 error.c
char buf[BUFSIZ];

va_start(args, fmt);
vsnprintf(buf, BUFSIZ, fmt, args);
va_end(args);

argv[0] = rb_str_new2(buf);

e$B$3$l$Oe(Brb_sprintf()e$B$G5-=R$G$-!$$^$?$=$NJ}$,e(BBUFSIZe$B$H$$$&[email protected]$N8!>Z$,Fq$7$$Dj?t$r;H$o$:$K$9$_$^$9!#$3$N$h$&$Je(Brb_sprintf()e$B$G=q$-49$($?J}$,$$$$$H;W$o$l$k%3!<%I$bB??t$"$j!$$=$N:]$K;HMQ$5$l$k%P%C%U%!%5%$%:$be([email protected]$1$G$J$/e(B0x100e$B$de(B1024e$B!$e(B32e$B$J$IB?:L$G$9!#$^$?!$e(Bsnprintf()e$B$G$O$J$/e(Bsprintf()e$B$r;H$C$F$$$k2U=j$bB??t$"$j$^$9!#e(B

e$B$=$l$G$O$J$<e(Brb_sprintf()e$B$G$O$J$/!$e(Bs(n)printf()e$B$He(Brb_str_new2()e$B$r;H$C$F$$$k$N$+$H$$$&$3$H$K$J$j$^[email protected]$7!$;d$O:#2s$N7o$G>$7$/D4$Y$k$^$GCQ$:$+$7$J$,$ie(Brb_sprintf()e$B$NB8:$rCN$j$^$;[email protected]$O40A4$K?dB,$K4p$E$-$^$9!K!#$=$NM}M3$r9M$($F$$^$7$?!#e(B

(1) README.EXT(.ja)e$B$K:$C$F$$$J$$$?$ae(B
(2) e$B4X?t$N<BBN$,e(Bstring.ce$B$G$O$J$/e(Bsprintf.ce$B$K$"$k$?$ae(B
(3)
e$B:G=E$J!Ve(BStringe$B$r:[email protected]$9$k!W$H$$$&L\E*$+$i!$e(Brb_str_newe$B%U%!%_%j$r8F$S=P$9$3$HA0Ds$G;W9M$rAH$_N)$F$k$?$ae(B
(4)
e$B!Ve(BCe$B%b!<%I!W$G;W9M$7$F$$$k$H$-$O!$e(Brb_sprintf()e$B$KBP$7$Fe(BCe$B$Ne(Bsprintf()e$B$N%$%a!<%8$,43>D$7!$e(Brb_sprintf()e$B$,8uJd$K5s$,$k$N$r<YKb$7$F$$$k$?$ae(B

e$B:#2s!$e(Bcatf()e$B$K2C$($Fe(Bnewf()e$B$NMWK>$r=P$7$?$N$O!$e(B(3)e$B$He(B(4)e$B$r2r>C$9$k$?$a$G$9!#e(Brb_sprintf()e$B$N5-=R$re(BREADME.EXTe$B$K2C$($k$3$H$Ge(B(1)e$B$r2r>C$G$-$k$+$i$=$l$G==J,$G$O$J$$$+$H;W$o$l$k$+$b$7$l$^$;$s$,!$e(B(1)[email protected]$1$G$Oe(BRubye$BK\BN$N%=!<%9%3!<%IFb$Ke(Brb_sprintf()e$B$K4JC1$K=q$-49$($i$l$k%3!<%I$,<B:]$KB??tB8:_$9$kM}M3$H$7$F$OIT==J,[email protected]$H9M$($^$7$?!#$=$3$G:#2se(Bnewf()e$B$NMWK>$r=P$9$K;j$j$^$7$?!#$J$*!$7+$jJV$7$^$9$,$3$l$O?dB,$G$7$+$J$/!$$3$l$,@5$7$$$H$$$&6/$$3N?.$O$"$j$^$;$s!#$^$?!$e(Bnewf()e$B$H$$$&L>A0$J$i$Pe(B(3)e$B$He(B(4)e$B$N2r7h$K$J$k$H$$$&3N?.$,$"$k$o$1$G$b$"$j$^$;$s!#e(B

e$B$^$?!$:#[email protected]$O!$e(Bs(n)printf()e$B$O%P%C%U%!%5%$%:[email protected]$r8!>Z$9$k$3$H$,Fq$7$/!$;HMQ$rHr$1$?J}$,NI$$$H$$$&$3$H$rA0Ds$H$7$F$$$^$9$,!$;[email protected]$r6/$/46$8$9$.$F$$$k$+$b$7$l$^$;$s!#e(B

  1. e$BJVEze(B

e$BD9$/$J$C$F$7$^$$?=$7Lu$"$j$^$;$s$,!$$40U8+$KJVEzCW$7$^$9!#e(B

[email protected]@%$5$se(B

e$B%(%s%3!<%I$r0U<1$7$?J8;zNs=hM}$Ne(B C API e$BL>$O!"e(Brb_enc_str_* e$B$+$H;W$$$^$9!#e(B

e$B$$C$7$c$k$H$$j!$e(Brb_enc_str_*e$B$,@5$7$$$H;W$$$^$9!#G’<1ITB-$r$*OM$S$7$^$9!#e(B

rb_encoding e$B$Ke(B NULL e$B$rEO$9$N$O$$$+$,$J$b$N$+$H!#e(B

e$B$3$l$K$D$$$F$Oe(Bnewf()e$B$Oe(Brb_sprintf()e$B$NJLL>$G$"$j!$e(Brb_sprintf()e$B$N5-=R$r$=$N$^$^[email protected]$1$J$N$G$=$N$h$&$K$J$j$^$7$?!#e(B

e$B$=$NB>$N$40U8+$K$D$$$F$Oe(B<1.
e$BF05!e(B>e$B$GJVEz$K$J$C$?$H;W$$$^$9!#e(B

[email protected]$5$se(B

  • version.h

e$BJ,$+$j$^$7$?!#e(B1.8e$B$G$ODs6!$5$l$F$$$?$N$GFC$K5?Ld$r;}$?$:MWK>$7$F$7$^$$$^$7$?$,!$e(BRUBY_VERSION_*e$B$rD>@\D4$Y$k$N$OHs>)Ne$H$$$&M}2r$G$h$m$7$$$G$7$g$&$+!#e(B

  • e$B%U%)!<%^%C%H7Oe(B

newfe$B7O$O4{B8$Ne(Brb_sprintf, rb_vsprintf, rb_enc_sprintf,
rb_enc_vsprintfe$B$H$^$C$?$/F1$8$G$9$h$M!#!VITJX!W$r2r>C$9$k$3$H$Ke(B
e$B$O$J$i$J$$$N$G$O$H;W$$$^$9$,!#e(B

e$B$O$$!$$^$C$?$/F1$8$G$9!#$3$l$K$D$$$F$OITJX$r2r>C$9$k$?$a$G$O$J$/!$e(B<1.2
rb_str_newf()e$B$N<{MWe(B>e$B$K<($7$?$h$&$K!$e(Brb_sprintf()e$B$,;H$o$l$J$$%1!<%9$,B??t$"$k$H$$$&8=<B$r$U$^$($F!$e(Brb_str_newe$B%U%!%_%j$N0l$D$H$7$FDs6!$5$l$?$[$&$,;H$o$l$d$9$$$N$G$O$J$$$+$H$$$&?dB,$K4p$E$-$^$9!#$G$9$,!$$3$l$OC1$K?dB,$G$7$+$J$/!$$3$N9M$($,@5$7$$$N$+$I$&$+$r8!>Z$9$k$3$H$b$G$-$^$;$s!#$h$C$F6/$$MWK>$G$O$"$j$^$;$s!#e(B

e$B0U?^$O$^$!M}2r$G$-$k$N$G$9$,!"ItJ,E*$KO"7k$7$J$,$ie(Bsprintfe$B$9$k$3e(B
e$B$H$C$F$I$N$/$i$$B?$$$s$G$7$g$&!#e(B

<1.1
rb_str_catf()e$B$N<{MWe(B>e$B$K<($7$?$h$&$K!$$$$/$D$+$O$"$k$h$&$G$9!#[email protected]!$$=$l$,!VB?$$!W$H$$$($k$+$I$&$+$OJ,$+$j$^$;$s!#e(B

[email protected]$1$Ge(Bprintfe$B$rA[5/$7$m!"$H$$$&$N$O$$$5$5$+6l$7$$$N$G$O!#e(B

print()e$B$He(Bprintf()e$B$N0c$$$,e([email protected]$1$J$N$G$=$l$G==J,$+$H;W$C$F$7$^$$$^$7$?!#L>[email protected]$o$j$O$"$j$^$;$s!#e(BRubye$B$N47=,$K=>$&$J$i$P!$e(Brb_str_new6()e$B$H$$$&$3$H$K$J$k$G$7$g$&$+!#e(B

e$BD9$/$J$j$^$7$?$,!$0J>e$G$9!#$h$m$7$/$*4j$$$7$^$9!#e(B


Goro Fuji (e$BF#e(B e$B8cO:e(B)

e$BKNIt$5$se(B

snprintf()e$B$N%P%C%U%!%5%$%:$r7hDj$9$k$N$,!$;d$K$H$C$F$O$o$j$HLLE]$J:n6H$G$"$j!$$^$?e(BRubye$B%=!<%9%3!<%ICf$GMQ$$$i$l$kCM$,MM!9$G$"$k$3$H$+$i!$$3$N!VLLE]$/$5$5!W$O$o$j$HIaJW$J$N$G$O$J$$$+$H;W$$$^$7$?!#<BAu$7$F$$$k$H$-$K!VLLE]$/$5$$!W$H;W$&$3$H$O!$Bh;0<T!J$d!$?t%u7n8e$N<+J,!K$K$H$C$F$O!VM}2r$7$K$/$$!W$H$$$&$3$H$K$J$j$,$A$J$h$&$J5$$,$7$^$9!#[email protected]$N8!>Z$,Fq$7$$!W$H$$$&[email protected]$O$=$&$$$&0UL#$G;HMQ$7$^$7$?!#e(B

[email protected]$5$se(B

e$B$"$j$,$H$&$4$6$$$^$9!#e(B
e$B%Q%C%A$N%P%0$K$D$$$F$O$9$_$^$;$s!#e(B

sprintf()e$B$K$^[email protected]$r9MN8$7$J$+$C$?$3$H$K$D$$$F$OD4::ITB-$G$7$?!#$?$7$+$K!$!V2u$l$F$$$J$$$b$N$rD>$9$J!W$H$$$&$3$H$G!$4{B8$N%3!<%I$r=q$-49$($kI,MW$O$J$$$N$G$7$g$&!#e(B

e$B$H$3$m$GL>A0$G$9$,!$e(Brb_append_(v)sprintf()e$B$OJ,$+$j$K$/$$$h$&$K;W$$$^$9!#Bh0l0z?t$,e(BStringe$B$J$N$Ge(Brb_str_*e$B$G;O$^$kJ}$,<+A3$G3P$($d$9$$!J$N$G!$;H$$$d$9$$!&;H$o$l$d$9$$!K$N$G$O$J$$$+$H;W$$$^$9$,$$$+$,$G$7$g$&$+!#$7$+$7$=$&$J$k$He(Brb_str_append_(v)sprintf()e$B$H$J$j$5$9$,$KD9$9$.$k$h$&$K$b;W$$$^$9$,!#e(B

2008/07/21 16:31 Nobuyoshi N. [email protected]:

e$B$$$k$H$_$J$7$F$$$k$N$G$^$:$$$G$9!#e(B

(1) README.EXT(.ja)e$B$K:$C$F$$$J$$$?$ae(B
print()e$B$He(Bprintf()e$B$N0c$$$,e([email protected]$1$J$N$G$=$l$G==J,$+$H;W$C$F$7$^$$e(B
e$B$^$7$?!#L>[email protected]$o$j$O$"$j$^$;$s!#e(BRubye$B$N47=,$K=>e(B
e$B$&$J$i$P!$e(Brb_str_new6()e$B$H$$$&$3$H$K$J$k$G$7$g$&$+!#e(B

e$B$b$&e(Bnew+e$B?t;z$O$d$a$^$7$g$&$h!#$9$G$K$"$k$b$N$O$H$b$+$/!":#$5$iA}e(B
e$B$d$9$3$H$O$J$$$G$7$g$&!#e(B

new+e$B?t;z$H$$$&L>A0$K$D$$$F$O>iCL$,2a$.$^$7$?!#?=$7Lu$"$j$^$;$s!#e(B
e$B$^$?$3$l$K$D$$$F$O!$9M$($F$_$l$P!$%^%/%m$G==J,BP=h$G$-$k$N$G!$$b$7:NMQ$9$k$H$7$F$b?7$7$/%7%s%%k$rDj5A$9$k$K$O5Z$S$^$;$s$M!#e(B

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

At Mon, 21 Jul 2008 12:23:42 +0900,
Goro Fuji wrote in [ruby-dev:35611]:

1.1 rb_str_catf()e$B$N<{MWe(B

e$B$3$N$3$H$+$i!$e(Bcatf()e$B$K$D$$$F$O$=$l$J$j$N<{MW$,$"$k$N$G$O$J$$$+$H9M$($^$7$?!#e(B

e$B$?$7$+$K<{MW$O$=$3$=$3$"$k$h$&$G$9$M!#$"$H$OL>A0$+$J!#$A$J$$K!"e(B
[ruby-dev:35597]e$B$N%Q%C%A$G$O<B:]$Ne(Bcapae$B$r9MN8$;$:$Ke(B120bytee$B6u$$$Fe(B
e$B$$$k$H$
$J$7$F$$$k$N$G$^$:$$$G$9!#e(B

1.2 rb_str_newf()e$B$N<{MWe(B

e$B$=$l$G$O$J$<e(Brb_sprintf()e$B$G$O$J$/!$e(Bs(n)printf()e$B$He(Brb_str_new2()
e$B$r;H$C$F$$$k$N$+$H$$$&$3$H$K$J$j$^$9e(B

e$B$=$NB?$/$O!"e(Brb_sprintf()e$B$,DI2C$5$l$k0JA0$+$i$N%3!<%I$G$O$J$$$G$7$ge(B
e$B$&$+!#C1$K!"8!>Z:Q$_$N%3!<%I$r$o$6$o$6A4It=q$-D>$9$3$H$O$7$F$$$Je(B
[email protected][email protected]$H;W$$$^$9!#e(B

(1) README.EXT(.ja)e$B$K:$C$F$$$J$$$?$ae(B

e$B4JC1$J$,$iDI2C$7$F$*$-$^$7$?!#@bL@$N2~A1$O4?7^$G$9!#e(B

e$B$^$?!$:#[email protected]$O!$e(Bs(n)printf()e$B$O%P%C%U%!%5%$%:[email protected]$r8!>Ze(B
e$B$9$k$3$H$,Fq$7$/!$;HMQ$rHr$1$?J}$,NI$$$H$$$&$3$H$rA0Ds$H$7$F$$e(B
e$B$^$9$,!$;[email protected]$r6/$/46$8$9$.$F$$$k$+$b$7$l$^$;$s!#e(B

e$B$3$l$O0JA0<h$j>e$2$i$l$?LdBj$G$7$F!"4{B8$N%3!<%I$N8!>Z$He(B
rb_sprintf()e$B$NDI2C$H$$$&$3$H$K$J$C$?$H;W$$$^$9!#e(B

print()e$B$He(Bprintf()e$B$N0c$$$,e([email protected]$1$J$N$G$=$l$G==J,$+$H;W$C$F$7$^$$e(B
e$B$^$7$?!#L>[email protected]$o$j$O$"$j$^$;$s!#e(BRubye$B$N47=,$K=>e(B
e$B$&$J$i$P!$e(Brb_str_new6()e$B$H$$$&$3$H$K$J$k$G$7$g$&$+!#e(B

e$B$b$&e(Bnew+e$B?t;z$O$d$a$^$7$g$&$h!#$9$G$K$"$k$b$N$O$H$b$+$/!":#$5$iA}e(B
e$B$d$9$3$H$O$J$$$G$7$g$&!#e(B

Index: string.c

— string.c (revision 18141)
+++ string.c (working copy)
@@ -341,4 +341,18 @@ str_frozen_check(VALUE s)
}

+size_t
+rb_str_capacity(VALUE str)
+{

  • if (STR_EMBED_P(str)) {
  • return RSTRING_EMBED_LEN_MAX;
  • }
  • else if (STR_NOCAPA_P(str)) {
  • return RSTRING(str)->as.heap.len;
  • }
  • else {
  • return RSTRING(str)->as.heap.aux.capa;
  • }
    +}

static inline VALUE
str_alloc(VALUE klass)
Index: sprintf.c

— sprintf.c (revision 18142)
+++ sprintf.c (working copy)
@@ -1116,2 +1116,39 @@ rb_sprintf(const char *format, …)
return result;
}
+
+extern size_t rb_str_capacity(VALUE);
+
+VALUE
+rb_append_vsprintf(VALUE str, const char *fmt, va_list ap)
+{

  • rb_printf_buffer f;
  • VALUE klass;
  • StringValue(str);
  • rb_str_modify(str);
  • f._flags = __SWR | __SSTR;
  • f._bf._size = 0;
  • f._w = rb_str_capacity(str);
  • f._bf._base = (unsigned char *)str;
  • f._p = (unsigned char *)RSTRING_END(str);
  • klass = RBASIC(str)->klass;
  • RBASIC(str)->klass = 0;
  • f.vwrite = ruby__sfvwrite;
  • BSD_vfprintf(&f, fmt, ap);
  • RBASIC(str)->klass = klass;
  • rb_str_resize(str, (char *)f._p - RSTRING_PTR(str));
  • return str;
    +}

+VALUE
+rb_append_sprintf(VALUE str, const char *format, …)
+{

  • va_list ap;
  • va_start(ap, format);
  • str = rb_append_vsprintf(str, format, ap);
  • va_end(ap);
  • return str;
    +}

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

Goro Fuji e$B$5$s$O=q$-$^$7$?e(B:

e$BKNIt$5$se(B

snprintf()e$B$N%P%C%U%!%5%$%:$r7hDj$9$k$N$,!$;d$K$H$C$F$O$o$j$HLLE]$J:n6H$G$"$j!$$^$?e(BRubye$B%=!<%9%3!<%ICf$GMQ$$$i$l$kCM$,MM!9$G$"$k$3$H$+$i!$$3$N!VLLE]$/$5$5!W$O$o$j$HIaJW$J$N$G$O$J$$$+$H;W$$$^$7$?!#<BAu$7$F$$$k$H$-$K!VLLE]$/$5$$!W$H;W$&$3$H$O!$Bh;0<T!J$d!$?t%u7n8e$N<+J,!K$K$H$C$F$O!VM}2r$7$K$/$$!W$H$$$&$3$H$K$J$j$,$A$J$h$&$J5$$,$7$^$9!#[email protected]$N8!>Z$,Fq$7$$!W$H$$$&[email protected]$O$=$&$$$&0UL#$G;HMQ$7$^$7$?!#e(B

e$BJ,$+$j$^$7$?!#2a5n$O$H$b$+$/!":#$J$i!VG:[email protected]$ie(Brb_sprintfe$B;H$C$H$1!W$/$i$$e(B
e$B$NF($2$+$?$G$$$`$M$$$$$s$8$c$J$$$+$H;W$&$N$G!“FC$Ke(Bnewfe$B7O$,:NMQ$5$l$?$He(B
e$B$7$F$I$N$/$i$$;H$o$l$k$+$OFf$+$b$7$l$^$;$s!#$^$”$=$A$i$ODs0F$NK\6Z$G$O$Je(B
e$B$+$C$?$h$&$G$9$,!#e(B

e$B$H$3$m$GL>A0$G$9$,!$e(Brb_append_(v)sprintf()e$B$OJ,$+$j$K$/$$$h$&$K;W$$$^$9!#Bh0l0z?t$,e(BStringe$B$J$N$Ge(Brb_str_*e$B$G;O$^$kJ}$,<+A3$G3P$($d$9$$!J$N$G!$;H$$$d$9$$!&;H$o$l$d$9$$!K$N$G$O$J$$$+$H;W$$$^$9$,$$$+$,$G$7$g$&$+!#$7$+$7$=$&$J$k$He(Brb_str_append_(v)sprintf()e$B$H$J$j$5$9$,$KD9$9$.$k$h$&$K$b;W$$$^$9$,!#e(B

e$B$s!<!"$?$H$($PF1MM$J=hM}$r;}$DB>$N%W%m%8%’%/%H$O$I$&[email protected]$m$&$He(B
e$B;W$C$Fe(BNetBSDe$B$Ne(Bsyslog(3)e$B$rFI$s$G$_$^$7$?$,!“e(Bsnprintf
e$B$GE%=-$/<BAu$7$F$”$je(B
e$B$^$7$?!#;DG0!#e(B

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

At Mon, 21 Jul 2008 22:09:09 +0900,

e$B$?$a$7$Ke(Brb_append_sprintf()[email protected]@$re(BREADME.EXT.jae$B$K2C$($F$_$^$7e(B
e$B$?$,!$5!G=$H$7$F$Oe(Brb_str_cate$B$NN`$J$N$G!$e(Brb_str_cat_e$B$G;O$^$k$[e(B
e$B$&$,[email protected]$O$"$k$h$&$K;W$($^$9!#e(B

rb_append_ e$B$O2>L>$J$N$G!"$b$C$H$$$$L>A0$O$J$$$G$9$+$M$’!#e(B
e$B$A$g$C$HD9$$46$8$G$9$,!"e(Brb_str_cat_sprintfe$B$N$[$&$,$$$$$+$J!#e(B

rb_sprintfe$B$K$D$$$F$O!$$re(Brb_str_newe$B7O$N<!$N0LCV$K0\F0$5$;$?$[e(B

e$B$+!$e([email protected]$7$F$"$j$^$9!#e(B

[email protected]$He([email protected]@$O%3%_%C%H$7$^$7$?!#e(B

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

2008/07/21 18:45 Urabe S. [email protected]:

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

e$B$H$3$m$GL>A0$G$9$,!$e(Brb_append_(v)sprintf()e$B$OJ,$+$j$K$/$$$h$&$K;W$$$^$9!#Bh0l0z?t$,e(BStringe$B$J$N$Ge(Brb_str_*e$B$G;O$^$kJ}$,<+A3$G3P$($d$9$$!J$N$G!$;H$$$d$9$$!&;H$o$l$d$9$$!K$N$G$O$J$$$+$H;W$$$^$9$,$$$+$,$G$7$g$&$+!#$7$+$7$=$&$J$k$He(Brb_str_append_(v)sprintf()e$B$H$J$j$5$9$,$KD9$9$.$k$h$&$K$b;W$$$^$9$,!#e(B

e$B$s!<!"$?$H$($PF1MM$J=hM}$r;}$DB>$N%W%m%8%’%/%H$O$I$&[email protected]$m$&$He(B
e$B;W$C$Fe(BNetBSDe$B$Ne(Bsyslog(3)e$B$rFI$s$G$_$^$7$?$,!“e(Bsnprintf e$B$GE%=-$/<BAu$7$F$”$je(B
e$B$^$7$?!#;DG0!#e(B

Perle$B$K$bF1Ey$N4X?t$,$"$j$^$9$,!$$3$NN`$N4X?t$Oe(BnewSVpvf()e$B!Je(BPerle$B$G$Oe(BVALUEe$B$KAjEv$9$k$b$N$,e(Bsv:
scalar
valuee$B$G!$e(BCe$B$NJ8;zNs$re(Bpv: pointer
valuee$B$H8F$s$G$$$^$9!K!$e(Bsv_setpvf(),
sv_catpvf()e$B$H$J$C$F$$$^$9!#e(B

e$B$?$a$7$Ke(Brb_append_sprintf()[email protected]@$re(BREADME.EXT.jae$B$K2C$($F$_$^$7$?$,!$5!G=$H$7$F$Oe(Brb_str_cate$B$NN`$J$N$G!$e(Brb_str_cat_e$B$G;O$^$k$[$&$,[email protected]$O$"$k$h$&$K;W$($^$9!#e(B

rb_sprintfe$B$K$D$$$F$O!$$re(Brb_str_newe$B7O$N<!$N0LCV$K0\F0$5$;$?$[$+!$e([email protected]$7$F$"$j$^$9!#e(B

*** README.EXT.ja.orig Mon Jul 21 16:48:50 2008
— README.EXT.ja Mon Jul 21 21:59:03 2008


*** 212,225 ****

  Ce$B$NJ8;[email protected]%^!<%/$,IU2C$5$l$?e(BRubye$B$NJ8;[email protected]@.$9$k!%e(B

rb_str_cat(VALUE str, const char *ptr, long len)

  Rubye$B$NJ8;zNse(Bstre$B$Ke(Blene$B%P%$%H$NJ8;zNse(Bptre$B$rDI2C$9$k!%e(B

! rb_sprintf(const char *format, …)
! rb_vsprintf(const char *format, …)

!
printf(3)e$B$N%U%)!<%^%C%H$K$7$?$,$C$F!$e(BRubye$B$NJ8;[email protected]@.$9$k!%e(B

e$BG[Ns$KBP$9$k4X?te(B

— 212,237 ----

  Ce$B$NJ8;[email protected]%^!<%/$,IU2C$5$l$?e(BRubye$B$NJ8;[email protected]@.$9$k!%e(B
  • rb_sprintf(const char *format, …)
  • rb_vsprintf(const char *format, va_list ap)

printf(3)e$B$N%U%)!<%^%C%H$K$7$?$,$C$F!$e(BRubye$B$NJ8;[email protected]@.$9$k!%e(B
+
rb_str_cat(VALUE str, const char *ptr, long len)

  Rubye$B$NJ8;zNse(Bstre$B$Ke(Blene$B%P%$%H$NJ8;zNse(Bptre$B$rDI2C$9$k!%e(B

! rb_str_cat2(VALUE str, const char* ptr)

!
Rubye$B$NJ8;zNse(Bstre$B$Ke(BCe$B$NJ8;zNse(Bptre$B$rDI2C$9$k!#$3$N4X?t$N5!G=$Oe(B
! rb_str_cat(str, ptr, strlen(ptr))e$B$HF1Ey$G$"$k!#e(B
!
! rb_append_sprintf(VALUE str, const char* format, …)
! rb_append_vsprintf(VALUE str, const char* format, va_list ap)
!
!
Ce$B$NJ8;zNse(Bformate$B$HB3$/0z?t$re(Bprintf(3)e$B$N%U%)!<%^%C%H$K$7$?$,$C$Fe(B
!
[email protected]$7!$e(BRubye$B$NJ8;zNse(Bstre$B$KDI2C$9$k!#$3$N4X?t$N5!G=$Oe(B
! rb_str_cat2(str, rb_sprintf(format, …))e$B$HF1Ey$G$"$k!#e(B

e$BG[Ns$KBP$9$k4X?te(B

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

At Tue, 22 Jul 2008 03:53:32 +0900,
Yukihiro M. wrote in [ruby-dev:35624]:

sprintfe$B$7$?7k2L$re(Bconcate$B$9$k$H$$$&0UL#[email protected]$JL>[email protected]$H$O;W$$e(B
e$B$^$9$,!"e(B

  • e$B$=$b$=$be(Bprinte$B$7$F$J$$$H$+e(B
  • concate$B$Oe(Bcate$B$HN,[email protected]$5$rDI5a$9$k0UL#$J$7!)e(B

e$B<B$O?)FyL$N>.7?F0J*[email protected]$H$+!#e(B

e$B$H$+$r9M$($k$J$i!">iD9J82=$H$O7hJL$7$F!"$b$&e(Brb_str_catfe$B$G$$!<e(B
e$B$8$c$s$H$$$&5$$b$7$^$9$M!#e(B

rb_str_newfe$B$O$I$&$7$^$9$+e(B?

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

In message “Re: [ruby-dev:35623] Re: [request]C APIe$B$N3HD%e(B”
on Tue, 22 Jul 2008 02:51:09 +0900, Nobuyoshi N.
[email protected] writes:

|At Mon, 21 Jul 2008 22:09:09 +0900,
|> e$B$?$a$7$Ke(Brb_append_sprintf()[email protected]@$re(BREADME.EXT.jae$B$K2C$($F$$^$7e(B
|> e$B$?$,!$5!G=$H$7$F$Oe(Brb_str_cate$B$NN`$J$N$G!$e(Brb_str_cat_e$B$G;O$^$k$[e(B
|> e$B$&$,[email protected]$O$"$k$h$&$K;W$($^$9!#e(B
|
|rb_append
e$B$O2>L>$J$N$G!"$b$C$H$$$$L>A0$O$J$$$G$9$+$M$’!#e(B
|e$B$A$g$C$HD9$$46$8$G$9$,!"e(Brb_str_cat_sprintfe$B$N$[$&$,$$$$$+$J!#e(B

sprintfe$B$7$?7k2L$re(Bconcate$B$9$k$H$$$&0UL#[email protected]$JL>[email protected]$H$O;W$$e(B
e$B$^$9$,!"e(B

  • e$B$=$b$=$be(Bprinte$B$7$F$J$$$H$+e(B
  • concate$B$Oe(Bcate$B$HN,[email protected]$5$rDI5a$9$k0UL#$J$7!)e(B

e$B$H$+$r9M$($k$J$i!">iD9J82=$H$O7hJL$7$F!"$b$&e(Brb_str_catfe$B$G$$!<e(B
e$B$8$c$s$H$$$&5$$b$7$^$9$M!#e(B

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

In message “Re: [ruby-dev:35625] Re: [request]C APIe$B$N3HD%e(B”
on Tue, 22 Jul 2008 04:54:44 +0900, Nobuyoshi N.
[email protected] writes:

|rb_str_newfe$B$O$I$&$7$^$9$+e(B?

sprintfe$B$,$"[email protected]$H;W$$$^$9!#e(B

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

e$BM_$7$$5!G=$H$7$F$O$3$l$GK~B-$G$9!#$"$j$,$H$&$4$6$$$^$7$?!#e(B

e$B$H$3$m$G:G=i$K=q$$$?%Q%C%A$Ne(Brb_str_catf()e$B$G$Oe(BStringValue()e$B$r8F$S=P$7$F$$$^$7$?$,!$B>$Ne(Brb_str_cate$B7O$r8+D>$7$F$_$k$H$=$N$h$&$J%3!<%I$OL5$/!$7?$K$D$$$F$O<[email protected]$$H$J$C$F$$$^$9!#$J$N$G!$e(Brb_str_catf()e$B$K$D$$$F$bF1$807$$$G$$$$$N$G$O$J$$$+$H;W$$$^$9!#e(B

e$B$h$m$7$/$*4j$$$7$^$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