diff --git a/README.EXT b/README.EXT index bd2aa57c66..7e39504754 100644 --- a/README.EXT +++ b/README.EXT @@ -105,6 +105,13 @@ representation of var. These macros will skip the replacement if var is a String. Notice that the macros take only the lvalue as their argument, to change the value of var in place. +You can also use the macro named StringValueCStr(). This is just +like StringValuePtr(), but always add nul character at the end of +the result. If the result contains nul character, this macro causes +the ArgumentError exception. +StringValuePtr() doesn't gurantee to exist nul at the end of the +result, and the result may contain nul. + In version 1.6 or earlier, STR2CSTR() was used to do the same thing but now it is deprecated in version 1.7, because STR2CSTR() has a risk of a dangling pointer problem in the to_str() impliclit conversion. @@ -115,10 +122,10 @@ can be cast to retrieve the pointer to the struct. The casting macro will be of the form RXXXX for each data type; for instance, RARRAY(obj). See "ruby.h". -For example, `RSTRING(str)->len' is the way to get the size of the -Ruby String object. The allocated region can be accessed by -`RSTRING(str)->ptr'. For arrays, use `RARRAY(ary)->len' and -`RARRAY(ary)->ptr' respectively. +There are some accessing macros for structure members, for example +`RSTRING_LEN(s)' to get the size of the Ruby String object. The +allocated region can be accessed by `RSTRING_PTR(str)'. For arrays, +use `RARRAY_LEN(ary)' and `RARRAY_PTR(ary)' respectively. Notice: Do not change the value of the structure directly, unless you are responsible for the result. This ends up being the cause of interesting @@ -209,7 +216,7 @@ interpreter. Some (not all) of the useful functions are listed below: 2. Extending Ruby with C -2.1 Addding new features to Ruby +2.1 Adding new features to Ruby You can add new features (classes, methods, etc.) to the Ruby interpreter. Ruby provides APIs for defining the following things: diff --git a/README.EXT.ja b/README.EXT.ja index 6b5c1596c2..ea12c45e18 100644 --- a/README.EXT.ja +++ b/README.EXT.ja @@ -117,6 +117,13 @@ obsolete てから var の文字列表現に対する char* を返すマクロです。var の 内容を直接置き換える処理が入るので、var は lvalue である必要が あります。 +また,StringValuePtr() に類似した StringValueCStr() というマ +クロもあります.StringValueCStr(var) は var を String に置き +換えてから var の文字列表現に対する char* を返します.返され +る文字列の末尾には nul 文字が付加されます.なお,途中に nul +文字が含まれる場合は ArgumentError が発生します. +一方,StringValuePtr() では,末尾に nul 文字がある保証はなく, +途中に nul 文字が含まれている可能性もあります. それ以外のデータタイプは対応するCの構造体があります.対応す る構造体のあるVALUEはそのままキャスト(型変換)すれば構造体の @@ -129,10 +136,10 @@ obsolete ruby.hでは構造体へキャストするマクロも「RXXXXX()」(全部大文 字にしたもの)という名前で提供されています(例: RSTRING()). -例えば,文字列strの長さを得るためには「RSTRING(str)->len」と -し,文字列strをchar*として得るためには「RSTRING(str)->ptr」 -とします.配列の場合には,それぞれ「RARRAY(ary)->len」, -「RARRAY(ary)->ptr」となります. +例えば,文字列strの長さを得るためには「RSTRING_LEN(str)」とし, +文字列strをchar*として得るためには「RSTRING_PTR(str)」としま +す.配列の場合には,それぞれ「RARRAY_LEN(ary)」, +「RARRAY_PTR(ary)」となります. Rubyの構造体を直接アクセスする時に気をつけなければならないこ とは,配列や文字列の構造体の中身は参照するだけで,直接変更し