* ext/socket/mkconstants.rb: generate a header file for generated

functions.

* ext/socket/rubysocket.h: include constdefs.h.  don't declare
  generated functions.

* ext/socket/constants.c: include constdefs.c instead of constants.h.

* ext/socket/depend: dependency updated.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21627 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2009-01-17 10:19:03 +00:00
Родитель 29aff19f1a
Коммит 28028fc2b9
5 изменённых файлов: 74 добавлений и 28 удалений

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

@ -1,3 +1,15 @@
Sat Jan 17 19:16:16 2009 Tanaka Akira <akr@fsij.org>
* ext/socket/mkconstants.rb: generate a header file for generated
functions.
* ext/socket/rubysocket.h: include constdefs.h. don't declare
generated functions.
* ext/socket/constants.c: include constdefs.c instead of constants.h.
* ext/socket/depend: dependency updated.
Sat Jan 17 17:58:22 2009 Yuki Sonoda (Yugui) <yugui@yugui.jp>
* lib/irb/xmp.rb: multilingualizes XMP::StringInputMethod.

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

@ -14,7 +14,7 @@ static void sock_define_const(const char *name, int value, VALUE mConst);
static void sock_define_uconst(const char *name, unsigned int value, VALUE mConst);
#define sock_define_const(name, value) sock_define_const(name, value, mConst)
#define sock_define_uconst(name, value) sock_define_uconst(name, value, mConst)
#include "constants.h"
#include "constdefs.c"
#undef sock_define_const
#undef sock_define_uconst

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

@ -1,9 +1,9 @@
SOCK_HEADERS = rubysocket.h $(hdrdir)/ruby/ruby.h $(arch_hdrdir)/ruby/config.h \
$(hdrdir)/ruby/defines.h $(hdrdir)/ruby/io.h \
sockport.h constants.h
sockport.h constdefs.h
init.o: init.c $(SOCK_HEADERS)
constants.o: constants.c $(SOCK_HEADERS)
constants.o: constants.c constdefs.c $(SOCK_HEADERS)
basicsocket.o: basicsocket.c $(SOCK_HEADERS)
socket.o: socket.c $(SOCK_HEADERS)
ipsocket.o: ipsocket.c $(SOCK_HEADERS)
@ -18,6 +18,6 @@ raddrinfo.o: raddrinfo.c $(SOCK_HEADERS)
getnameinfo.o: getnameinfo.c $(arch_hdrdir)/ruby/config.h addrinfo.h sockport.h
getaddrinfo.o: getaddrinfo.c $(arch_hdrdir)/ruby/config.h addrinfo.h sockport.h
constants.h: $(srcdir)/mkconstants.rb
@echo "generating constants.h"
@$(RUBY) $(srcdir)/mkconstants.rb -o $@
constdefs.h constdefs.c : $(srcdir)/mkconstants.rb
@echo "generating constant definitions"
@$(RUBY) $(srcdir)/mkconstants.rb -H constdefs.h -o constdefs.c

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

@ -13,6 +13,11 @@ opt.def_option('-o FILE', 'specify output file') {|filename|
opt_o = filename
}
opt_H = nil
opt.def_option('-H FILE', 'specify output header file') {|filename|
opt_H = filename
}
C_ESC = {
"\\" => "\\\\",
'"' => '\"',
@ -132,6 +137,16 @@ def each_names_with_len(pat, prefix_optional=nil)
}
end
ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int_decl(funcname, pat, prefix_optional, guard=nil)")
%if guard
#ifdef <%=guard%>
int <%=funcname%>(char *str, int len, int *valp);
#endif
%else
int <%=funcname%>(char *str, int len, int *valp);
%end
EOS
ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int_func_in_guard(funcname, pat, prefix_optional, guard=nil)")
int
<%=funcname%>(char *str, int len, int *valp)
@ -163,6 +178,13 @@ ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_name_to_int_func(funcname, pa
%end
EOS
NAME_TO_INT_DEFS = []
def def_name_to_int(funcname, pat, prefix_optional, guard=nil)
decl = gen_name_to_int_decl(funcname, pat, prefix_optional, guard)
func = gen_name_to_int_func(funcname, pat, prefix_optional, guard)
NAME_TO_INT_DEFS << [decl, func]
end
def reverse_each_name_with_prefix_optional(pat, prefix_pat)
reverse_each_name(pat) {|n|
yield n, n
@ -175,7 +197,6 @@ def reverse_each_name_with_prefix_optional(pat, prefix_pat)
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_with_prefix_optional(pat, prefix_pat) {|n,s|
@ -196,6 +217,10 @@ ID
}
EOS
ERB.new(<<'EOS', nil, '%').def_method(Object, "gen_int_to_name_decl(func_name, hash_var)")
ID <%=func_name%>(int val);
EOS
INTERN_DEFS = []
def def_intern(func_name, pat, prefix_optional=nil)
prefix_pat = nil
@ -207,12 +232,23 @@ def def_intern(func_name, pat, prefix_optional=nil)
end
end
hash_var = "#{func_name}_hash"
decl = "static st_table *#{hash_var};"
vardef = "static st_table *#{hash_var};"
gen_hash = gen_int_to_name_hash(hash_var, pat, prefix_pat)
decl = gen_int_to_name_decl(func_name, hash_var)
func = gen_int_to_name_func(func_name, hash_var)
INTERN_DEFS << [decl, gen_hash, func]
INTERN_DEFS << [vardef, gen_hash, decl, func]
end
def_name_to_int("family_to_int", /\A(AF_|PF_)/, "AF_")
def_name_to_int("socktype_to_int", /\ASOCK_/, "SOCK_")
def_name_to_int("level_to_int", /\A(SOL_SOCKET\z|IPPROTO_)/, /\A(SOL_|IPPROTO_)/)
def_name_to_int("so_optname_to_int", /\ASO_/, "SO_")
def_name_to_int("ip_optname_to_int", /\AIP_/, "IP_")
def_name_to_int("ipv6_optname_to_int", /\AIPV6_/, "IPV6_", "IPPROTO_IPV6")
def_name_to_int("tcp_optname_to_int", /\ATCP_/, "TCP_")
def_name_to_int("udp_optname_to_int", /\AUDP_/, "UDP_")
def_name_to_int("shutdown_how_to_int", /\ASHUT_/, "SHUT_")
def_intern('intern_family', /\AAF_/)
def_intern('intern_protocol_family', /\APF_/)
def_intern('intern_socktype', /\ASOCK_/)
@ -220,29 +256,33 @@ def_intern('intern_ipproto', /\AIPPROTO_/)
result << ERB.new(<<'EOS', nil, '%').result(binding)
<%= INTERN_DEFS.map {|decl, gen_hash, func| decl }.join("\n") %>
<%= INTERN_DEFS.map {|vardef, gen_hash, decl, func| vardef }.join("\n") %>
static void
init_constants(VALUE mConst)
{
<%= gen_const_defs %>
<%= INTERN_DEFS.map {|decl, gen_hash, func| gen_hash }.join("\n") %>
<%= INTERN_DEFS.map {|vardef, gen_hash, decl, func| gen_hash }.join("\n") %>
}
<%= gen_name_to_int_func("family_to_int", /\A(AF_|PF_)/, "AF_") %>
<%= gen_name_to_int_func("socktype_to_int", /\ASOCK_/, "SOCK_") %>
<%= gen_name_to_int_func("level_to_int", /\A(SOL_SOCKET\z|IPPROTO_)/, /\A(SOL_|IPPROTO_)/) %>
<%= gen_name_to_int_func("so_optname_to_int", /\ASO_/, "SO_") %>
<%= gen_name_to_int_func("ip_optname_to_int", /\AIP_/, "IP_") %>
<%= gen_name_to_int_func("ipv6_optname_to_int", /\AIPV6_/, "IPV6_", "IPPROTO_IPV6") %>
<%= gen_name_to_int_func("tcp_optname_to_int", /\ATCP_/, "TCP_") %>
<%= gen_name_to_int_func("udp_optname_to_int", /\AUDP_/, "UDP_") %>
<%= gen_name_to_int_func("shutdown_how_to_int", /\ASHUT_/, "SHUT_") %>
<%= NAME_TO_INT_DEFS.map {|decl, func| func }.join("\n") %>
<%= INTERN_DEFS.map {|decl, gen_hash, func| func }.join("\n") %>
<%= INTERN_DEFS.map {|vardef, gen_hash, decl, func| func }.join("\n") %>
EOS
header_result = ERB.new(<<'EOS', nil, '%').result(binding)
<%= NAME_TO_INT_DEFS.map {|decl, func| decl }.join("\n") %>
<%= INTERN_DEFS.map {|vardef, gen_hash, decl, func| decl }.join("\n") %>
EOS
if opt_H
File.open(opt_H, 'w') {|f|
f << header_result
}
end
if opt_o
File.open(opt_o, 'w') {|f|
f << result

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

@ -142,6 +142,7 @@ int Rconnect();
#endif
#endif
#include "constdefs.h"
#define BLOCKING_REGION(func, arg) (long)rb_thread_blocking_region((func), (arg), RUBY_UBF_IO, 0)
@ -152,19 +153,12 @@ char *sockaddr_string_value_ptr(volatile VALUE *);
NORETURN(void raise_socket_error(const char *, int));
int family_to_int(char *str, int len, int *valp);
int family_arg(VALUE domain);
int socktype_arg(VALUE type);
int level_arg(VALUE level);
int optname_arg(int level, VALUE optname);
int shutdown_how_arg(VALUE how);
ID intern_protocol_family(int val);
ID intern_socktype(int val);
ID intern_ipproto(int val);
ID intern_family(int val);
int rb_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);
int rb_getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags);
struct addrinfo *sock_addrinfo(VALUE host, VALUE port, int socktype, int flags);