diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-02 08:22:36 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-01-02 08:22:36 +0000 |
commit | b5aebd12c003342a68ca756b2a43c17b1ff254c1 (patch) | |
tree | 53412ededf9490e28c0659dc08d0180a494684e3 /ext/socket | |
parent | 9ce8d4e3b964774294c88d9414fdf4a92c352709 (diff) | |
download | ruby-b5aebd12c003342a68ca756b2a43c17b1ff254c1.tar.gz |
* ext/socket/mkconstants.rb: use ID in the values of
family_to_str_hash. family_to_str returns a VALUE.
* ext/socket/socket.c (ipaddr): follow family_to_str change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21271 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r-- | ext/socket/mkconstants.rb | 31 | ||||
-rw-r--r-- | ext/socket/socket.c | 8 |
2 files changed, 22 insertions, 17 deletions
diff --git a/ext/socket/mkconstants.rb b/ext/socket/mkconstants.rb index a90171277e..83efde1cd4 100644 --- a/ext/socket/mkconstants.rb +++ b/ext/socket/mkconstants.rb @@ -121,31 +121,36 @@ ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int(str_var, len_var, } EOS +def reverse_each_name_with_prefix_optional(pat, prefix_pat) + reverse_each_name(pat) {|n| + yield n, n + } + if prefix_pat + reverse_each_name(pat) {|n| + next if prefix_pat !~ n + yield n, $' + } + end +end + + ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_int_to_name_hash(hash_var, pat, prefix_pat)") <%=hash_var%> = st_init_numtable(); -% reverse_each_name(pat) {|n| +% reverse_each_name_with_prefix_optional(pat, prefix_pat) {|n,s| #ifdef <%=n%> - st_insert(<%=hash_var%>, (st_data_t)<%=n%>, (st_data_t)<%=c_str n%>); + st_insert(<%=hash_var%>, (st_data_t)<%=n%>, (st_data_t)rb_intern2(<%=c_str s%>, <%=s.bytesize%>)); #endif % } -% if prefix_pat -% reverse_each_name(pat) {|n| -% next if prefix_pat !~ n -#ifdef <%=n%> - st_insert(<%=hash_var%>, (st_data_t)<%=n%>, (st_data_t)<%=c_str $'%>); -#endif -% } -% end EOS ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_int_to_name_func(func_name, hash_var)") -static char * +static VALUE <%=func_name%>(int val) { st_data_t name; if (st_lookup(<%=hash_var%>, (st_data_t)val, &name)) - return (char*)name; - return NULL; + return rb_id2str((ID)name); + return Qnil; } EOS diff --git a/ext/socket/socket.c b/ext/socket/socket.c index b50747a5e1..76cb4ae045 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -1061,11 +1061,11 @@ ipaddr(struct sockaddr *sockaddr, int norevlookup) VALUE ary; int error; char hbuf[1024], pbuf[1024]; - char *name; - name = family_to_str(sockaddr->sa_family); - if (name) - family = rb_str_new2(name); + family = family_to_str(sockaddr->sa_family); + if (!NIL_P(family)) { + family = rb_str_dup(family); + } else { sprintf(pbuf, "unknown:%d", sockaddr->sa_family); family = rb_str_new2(pbuf); |