* README.EXT, README.EXT.ja (Convert VALUE into C data):

StringValueCStr() has been available since 1.8.0.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@23638 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-06-04 00:50:26 +00:00
parent 8b6403c08d
commit 593f383b24
2 changed files with 23 additions and 9 deletions

View file

@ -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:

View file

@ -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の構造体を直接アクセスする時に気をつけなければならないこ
とは,配列や文字列の構造体の中身は参照するだけで,直接変更し