* ext/socket/mkconstants.rb: rename family_to_str to intern_family.

it returns ID now.

* ext/socket/socket.c (ipaddr): use intern_family.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21272 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2009-01-02 08:46:26 +00:00
Родитель b5aebd12c0
Коммит e4b7c0e8a3
3 изменённых файлов: 21 добавлений и 13 удалений

Просмотреть файл

@ -1,3 +1,10 @@
Fri Jan 2 17:45:19 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/mkconstants.rb: rename family_to_str to intern_family.
it returns ID now.
* ext/socket/socket.c (ipaddr): use intern_family.
Fri Jan 2 17:20:31 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/mkconstants.rb: use ID in the values of

Просмотреть файл

@ -144,18 +144,18 @@ ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_int_to_name_hash(hash_var, pa
EOS
ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_int_to_name_func(func_name, hash_var)")
static VALUE
static ID
<%=func_name%>(int val)
{
st_data_t name;
if (st_lookup(<%=hash_var%>, (st_data_t)val, &name))
return rb_id2str((ID)name);
return Qnil;
return (ID)name;
return 0;
}
EOS
STRINGIZER_DEFS = []
def def_stringizer(func_name, pat, prefix_optional=nil)
INTERN_DEFS = []
def def_intern(func_name, pat, prefix_optional=nil)
prefix_pat = nil
if prefix_optional
if Regexp === prefix_optional
@ -168,14 +168,14 @@ def def_stringizer(func_name, pat, prefix_optional=nil)
decl = "static st_table *#{hash_var};"
gen_hash = gen_int_to_name_hash(hash_var, pat, prefix_pat)
func = gen_int_to_name_func(func_name, hash_var)
STRINGIZER_DEFS << [decl, gen_hash, func]
INTERN_DEFS << [decl, gen_hash, func]
end
def_stringizer('family_to_str', /\AAF_/)
def_intern('intern_family', /\AAF_/)
result << ERB.new(<<'EOS', nil, '%').result(binding)
<%= STRINGIZER_DEFS.map {|decl, gen_hash, func| decl }.join("\n") %>
<%= INTERN_DEFS.map {|decl, gen_hash, func| decl }.join("\n") %>
static void
init_constants(VALUE mConst)
@ -195,7 +195,7 @@ init_constants(VALUE mConst)
#endif
% end
% }
<%= STRINGIZER_DEFS.map {|decl, gen_hash, func| gen_hash }.join("\n") %>
<%= INTERN_DEFS.map {|decl, gen_hash, func| gen_hash }.join("\n") %>
}
static int
@ -246,7 +246,7 @@ udp_optname_to_int(char *str, int len, int *valp)
<%= gen_name_to_int("str", "len", "valp", /\AUDP_/, "UDP_") %>
}
<%= STRINGIZER_DEFS.map {|decl, gen_hash, func| func }.join("\n") %>
<%= INTERN_DEFS.map {|decl, gen_hash, func| func }.join("\n") %>
EOS

Просмотреть файл

@ -1061,10 +1061,11 @@ ipaddr(struct sockaddr *sockaddr, int norevlookup)
VALUE ary;
int error;
char hbuf[1024], pbuf[1024];
ID id;
family = family_to_str(sockaddr->sa_family);
if (!NIL_P(family)) {
family = rb_str_dup(family);
id = intern_family(sockaddr->sa_family);
if (id) {
family = rb_str_dup(rb_id2str(id));
}
else {
sprintf(pbuf, "unknown:%d", sockaddr->sa_family);