ruby-changes:27196
From: akr <ko1@a...>
Date: Fri, 15 Feb 2013 08:16:31 +0900 (JST)
Subject: [ruby-changes:27196] akr:r39248 (trunk): * ext/socket/sockport.h (SET_SS_LEN): removed.
akr 2013-02-15 08:14:22 +0900 (Fri, 15 Feb 2013) New Revision: 39248 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39248 Log: * ext/socket/sockport.h (SET_SS_LEN): removed. (SET_SIN_LEN): removed. (INIT_SOCKADDR): new macro. * ext/socket/ancdata.c (extract_ipv6_pktinfo): use INIT_SOCKADDR. * ext/socket/raddrinfo.c (make_inetaddr): use INIT_SOCKADDR. (addrinfo_ipv6_to_ipv4): ditto. * ext/socket/getaddrinfo.c (GET_AI): use INIT_SOCKADDR. Modified files: trunk/ChangeLog trunk/ext/socket/ancdata.c trunk/ext/socket/getaddrinfo.c trunk/ext/socket/raddrinfo.c trunk/ext/socket/sockport.h Index: ChangeLog =================================================================== --- ChangeLog (revision 39247) +++ ChangeLog (revision 39248) @@ -1,3 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Feb 15 08:12:11 2013 Tanaka Akira <akr@f...> + + * ext/socket/sockport.h (SET_SS_LEN): removed. + (SET_SIN_LEN): removed. + (INIT_SOCKADDR): new macro. + + * ext/socket/ancdata.c (extract_ipv6_pktinfo): use INIT_SOCKADDR. + + * ext/socket/raddrinfo.c (make_inetaddr): use INIT_SOCKADDR. + (addrinfo_ipv6_to_ipv4): ditto. + + * ext/socket/getaddrinfo.c (GET_AI): use INIT_SOCKADDR. + Fri Feb 15 07:49:27 2013 Eric Hodel <drbrain@s...> * lib/rdoc.rb: Update to release version of 4.0.0 Index: ext/socket/raddrinfo.c =================================================================== --- ext/socket/raddrinfo.c (revision 39247) +++ ext/socket/raddrinfo.c (revision 39248) @@ -253,9 +253,7 @@ make_inetaddr(unsigned int host, char *b https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L253 { struct sockaddr_in sin; - MEMZERO(&sin, struct sockaddr_in, 1); - sin.sin_family = AF_INET; - SET_SIN_LEN(&sin, sizeof(sin)); + INIT_SOCKADDR((struct sockaddr *)&sin, AF_INET, sizeof(sin)); sin.sin_addr.s_addr = host; make_ipaddr0((struct sockaddr*)&sin, sizeof(sin), buf, buflen); } @@ -1931,9 +1929,7 @@ addrinfo_ipv6_to_ipv4(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L1929 addr = &((struct sockaddr_in6 *)&rai->addr)->sin6_addr; if (IN6_IS_ADDR_V4MAPPED(addr) || IN6_IS_ADDR_V4COMPAT(addr)) { struct sockaddr_in sin4; - MEMZERO(&sin4, struct sockaddr_in, 1); - sin4.sin_family = AF_INET; - SET_SIN_LEN(&sin4, sizeof(sin4)); + INIT_SOCKADDR((struct sockaddr *)&sin4, AF_INET, sizeof(sin4)); memcpy(&sin4.sin_addr, (char*)addr + sizeof(*addr) - sizeof(sin4.sin_addr), sizeof(sin4.sin_addr)); return rsock_addrinfo_new((struct sockaddr *)&sin4, (socklen_t)sizeof(sin4), PF_INET, rai->socktype, rai->protocol, Index: ext/socket/sockport.h =================================================================== --- ext/socket/sockport.h (revision 39247) +++ ext/socket/sockport.h (revision 39248) @@ -18,17 +18,18 @@ https://github.com/ruby/ruby/blob/trunk/ext/socket/sockport.h#L18 #ifdef HAVE_STRUCT_SOCKADDR_SA_LEN # define SET_SA_LEN(sa, len) (void)((sa)->sa_len = (len)) -# define SET_SS_LEN(ss, len) (void)((ss)->ss_len = (len)) #else # define SET_SA_LEN(sa, len) (void)(len) -# define SET_SS_LEN(ss, len) (void)(len) #endif -#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN -# define SET_SIN_LEN(si,len) (si)->sin_len = (len) -#else -# define SET_SIN_LEN(si,len) -#endif +#define INIT_SOCKADDR(addr, family, len) \ + do { \ + struct sockaddr *init_sockaddr_ptr = (addr); \ + socklen_t init_sockaddr_len = (len); \ + memset(init_sockaddr_ptr, 0, init_sockaddr_len); \ + init_sockaddr_ptr->sa_family = (family); \ + SET_SA_LEN(init_sockaddr_ptr, init_sockaddr_len); \ + } while (0) #ifndef IN_MULTICAST # define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000) Index: ext/socket/getaddrinfo.c =================================================================== --- ext/socket/getaddrinfo.c (revision 39247) +++ ext/socket/getaddrinfo.c (revision 39248) @@ -184,9 +184,9 @@ if (pai->ai_flags & AI_CANONNAME) {\ https://github.com/ruby/ruby/blob/trunk/ext/socket/getaddrinfo.c#L184 }\ memcpy((ai), pai, sizeof(struct addrinfo));\ (ai)->ai_addr = (struct sockaddr *)((ai) + 1);\ - memset((ai)->ai_addr, 0, (afd)->a_socklen);\ - SET_SA_LEN((ai)->ai_addr, (ai)->ai_addrlen = (afd)->a_socklen);\ - (ai)->ai_addr->sa_family = (ai)->ai_family = (afd)->a_af;\ + (ai)->ai_family = (afd)->a_af;\ + (ai)->ai_addrlen = (afd)->a_socklen;\ + INIT_SOCKADDR((struct sockaddr *)(ai)->ai_addr, (afd)->a_af, (afd)->a_socklen);\ ((struct sockinet *)(ai)->ai_addr)->si_port = (port);\ p = (char *)((ai)->ai_addr);\ memcpy(p + (afd)->a_off, (addr), (afd)->a_addrlen);\ Index: ext/socket/ancdata.c =================================================================== --- ext/socket/ancdata.c (revision 39247) +++ ext/socket/ancdata.c (revision 39248) @@ -573,9 +573,7 @@ extract_ipv6_pktinfo(VALUE self, struct https://github.com/ruby/ruby/blob/trunk/ext/socket/ancdata.c#L573 memcpy(pktinfo_ptr, RSTRING_PTR(data), sizeof(*pktinfo_ptr)); - memset(sa_ptr, 0, sizeof(*sa_ptr)); - SET_SA_LEN((struct sockaddr *)sa_ptr, sizeof(struct sockaddr_in6)); - sa_ptr->sin6_family = AF_INET6; + INIT_SOCKADDR((struct sockaddr *)sa_ptr, AF_INET6, sizeof(*sa_ptr)); memcpy(&sa_ptr->sin6_addr, &pktinfo_ptr->ipi6_addr, sizeof(sa_ptr->sin6_addr)); if (IN6_IS_ADDR_LINKLOCAL(&sa_ptr->sin6_addr)) sa_ptr->sin6_scope_id = pktinfo_ptr->ipi6_ifindex; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/