mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
9ce8d4e3b9
commit
b5aebd12c0
3 changed files with 29 additions and 17 deletions
|
@ -1,3 +1,10 @@
|
|||
Fri Jan 2 17:20:31 2009 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* 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.
|
||||
|
||||
Fri Jan 2 17:01:51 2009 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/socket/mkconstants.rb: refactored to gather stringizer
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue