summaryrefslogtreecommitdiff
path: root/ext/socket/mkconstants.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-01 07:49:31 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-01 07:49:31 +0000
commit0c838b4947a36ea0f706dfbd131b92de9a7b18a3 (patch)
tree968a89c07b8213fc3e0e30202efed808e8992633 /ext/socket/mkconstants.rb
parent30f3c8c70bbfab845ea8db868e961f9482bf637f (diff)
* ext/socket/mkconstants.rb: generate family_to_int().
* ext/socket/socket.c (setup_domain_and_type): use family_to_int. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21240 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket/mkconstants.rb')
-rw-r--r--ext/socket/mkconstants.rb35
1 files changed, 30 insertions, 5 deletions
diff --git a/ext/socket/mkconstants.rb b/ext/socket/mkconstants.rb
index 257b315..64743d7 100644
--- a/ext/socket/mkconstants.rb
+++ b/ext/socket/mkconstants.rb
@@ -34,10 +34,15 @@ result = ''
# workaround for NetBSD, OpenBSD and etc.
result << "#define pseudo_AF_FTIP pseudo_AF_RTIP\n"
-def each_data
- DATA.each_line {|s|
- name, default_value = s.scan(/\S+/)
- next unless name && name[0] != ?#
+DEFS = []
+DATA.each_line {|s|
+ name, default_value = s.scan(/\S+/)
+ next unless name && name[0] != ?#
+ DEFS << [name, default_value]
+}
+
+def each_const
+ DEFS.each {|name, default_value|
if name =~ /\AINADDR_/
define = "sock_define_uconst"
else
@@ -52,11 +57,18 @@ def each_data
}
end
+def each_name(pat)
+ DEFS.each {|name, default_value|
+ next if pat !~ name
+ yield name
+ }
+end
+
result << ERB.new(<<'EOS', nil, '%').result(binding)
static void
init_constants(VALUE mConst)
{
-% each_data {|guard, define, name, default_value|
+% each_const {|guard, define, name, default_value|
% if guard
#if <%=guard%>
% end
@@ -73,6 +85,19 @@ init_constants(VALUE mConst)
% }
}
+
+static int
+family_to_int(char *str, int len)
+{
+% each_name(/\A[AP]F_/) {|name|
+#ifdef <%=name%>
+% size = name.bytesize
+ if (len == <%=size%> && memcmp(str, <%=c_str name%>, <%=size%>) == 0) return <%=name%>;
+#endif
+% }
+ return -1;
+}
+
EOS
if opt_o