From d0987afc748dca7c2cab11011a5ee4b86bb59ba0 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 3 Aug 2014 01:55:10 +0000 Subject: make symbol conversion functions public * include/ruby/encoding.h (rb_check_symbol_cstr): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 4 ++++ README.EXT | 10 ++++++++++ README.EXT.ja | 10 ++++++++++ include/ruby/encoding.h | 1 + include/ruby/ruby.h | 2 ++ internal.h | 6 ------ 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index dd4136469d..a6aec13206 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sun Aug 3 10:55:07 2014 Nobuyoshi Nakada + + * include/ruby/encoding.h (rb_check_symbol_cstr): ditto. + Sun Aug 3 10:43:08 2014 Nobuyoshi Nakada * vm_insnhelper.c (vm_call_method): unusable super class should cause diff --git a/README.EXT b/README.EXT index 756f46f98b..bfea6001c2 100644 --- a/README.EXT +++ b/README.EXT @@ -482,6 +482,16 @@ After this function returned a non-zero value, *name is always a Symbol or a String, otherwise it is a String if the result is 0. The third function takes NUL-terminated C string, not Ruby VALUE. +You can retrieve Symbol from Ruby object (Symbol or String) given as +an argument by using + + rb_to_symbol(VALUE name) + rb_check_symbol(volatile VALUE *namep) + rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc) + +These functions are similar to above functions except that these +return a Symbol instead of an ID. + You can convert C ID to Ruby Symbol by using VALUE ID2SYM(ID id) diff --git a/README.EXT.ja b/README.EXT.ja index 0d60a7d500..0ab61abcbe 100644 --- a/README.EXT.ja +++ b/README.EXT.ja @@ -524,6 +524,16 @@ IDとは変数名,メソッド名を表す整数です.Rubyの中では 返した場合は常に文字列です.第三の関数はRubyの文字列ではなく NUL終端されたCの文字列を使います. +Rubyから引数として与えられたシンボル(または文字列)をシンボル +に変換するには以下の関数を使います. + + rb_to_symbol(VALUE name) + rb_check_symbol(volatile VALUE *namep) + rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc) + +これらの関数は,IDの代わりにシンボルを返すことを除けば上記の +関数と同じです. + === CからRubyのメソッドを呼び出す Cから文字列を経由せずにRubyのメソッドを呼び出すためには以下 diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h index 94a7f0f96b..4a5324d62e 100644 --- a/include/ruby/encoding.h +++ b/include/ruby/encoding.h @@ -232,6 +232,7 @@ char *rb_enc_path_end(const char *,const char *,rb_encoding*); const char *ruby_enc_find_basename(const char *name, long *baselen, long *alllen, rb_encoding *enc); const char *ruby_enc_find_extname(const char *name, long *len, rb_encoding *enc); ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc); +VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc); RUBY_EXTERN VALUE rb_cEncoding; diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index 472e1e417a..1f2fbafeb7 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1356,6 +1356,8 @@ ID rb_check_id(volatile VALUE *); ID rb_to_id(VALUE); VALUE rb_id2str(ID); VALUE rb_sym2str(VALUE); +VALUE rb_to_symbol(VALUE name); +VALUE rb_check_symbol(volatile VALUE *namep); #define CONST_ID_CACHE(result, str) \ { \ diff --git a/internal.h b/internal.h index 1cea556a2d..cc7daa82fa 100644 --- a/internal.h +++ b/internal.h @@ -806,12 +806,6 @@ void rb_gc_free_dsymbol(VALUE); VALUE rb_str_dynamic_intern(VALUE); ID rb_id_attrget(ID id); -VALUE rb_to_symbol(VALUE name); -VALUE rb_check_symbol(volatile VALUE *namep); -#ifdef RUBY_ENCODING_H -VALUE rb_check_symbol_cstr(const char *ptr, long len, rb_encoding *enc); -#endif - /* proc.c */ VALUE rb_proc_location(VALUE self); st_index_t rb_hash_proc(st_index_t hash, VALUE proc); -- cgit v1.2.1