[前][次][番号順一覧][スレッド一覧]

ruby-changes:28104

From: nobu <ko1@a...>
Date: Sat, 6 Apr 2013 16:59:06 +0900 (JST)
Subject: [ruby-changes:28104] nobu:r40156 (trunk): socket/extconf.rb: RSTRING_SOCKLEN

nobu	2013-04-06 16:58:51 +0900 (Sat, 06 Apr 2013)

  New Revision: 40156

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40156

  Log:
    socket/extconf.rb: RSTRING_SOCKLEN
    
    * ext/socket/extconf.rb (RSTRING_SOCKLEN): macro to cast RSTRING_LEN
      to socklen_t.

  Modified files:
    trunk/ext/socket/ancdata.c
    trunk/ext/socket/basicsocket.c
    trunk/ext/socket/extconf.rb
    trunk/ext/socket/raddrinfo.c
    trunk/ext/socket/rubysocket.h
    trunk/ext/socket/socket.c

Index: ext/socket/rubysocket.h
===================================================================
--- ext/socket/rubysocket.h	(revision 40155)
+++ ext/socket/rubysocket.h	(revision 40156)
@@ -91,6 +91,9 @@ https://github.com/ruby/ruby/blob/trunk/ext/socket/rubysocket.h#L91
 #ifndef HAVE_TYPE_SOCKLEN_T
 typedef int socklen_t;
 #endif
+#ifndef RSTRING_SOCKLEN
+#  define RSTRING_SOCKLEN (socklen_t)RSTRING_LENINT
+#endif
 
 #ifndef EWOULDBLOCK
 #  define EWOULDBLOCK EAGAIN
Index: ext/socket/raddrinfo.c
===================================================================
--- ext/socket/raddrinfo.c	(revision 40155)
+++ ext/socket/raddrinfo.c	(revision 40156)
@@ -923,7 +923,7 @@ addrinfo_initialize(int argc, VALUE *arg https://github.com/ruby/ruby/blob/trunk/ext/socket/raddrinfo.c#L923
     else {
         StringValue(sockaddr_arg);
         sockaddr_ptr = (struct sockaddr *)RSTRING_PTR(sockaddr_arg);
-        sockaddr_len = RSTRING_LENINT(sockaddr_arg);
+        sockaddr_len = RSTRING_SOCKLEN(sockaddr_arg);
         init_addrinfo(rai, sockaddr_ptr, sockaddr_len,
                       i_pfamily, i_socktype, i_protocol,
                       canonname, inspectname);
Index: ext/socket/extconf.rb
===================================================================
--- ext/socket/extconf.rb	(revision 40155)
+++ ext/socket/extconf.rb	(revision 40156)
@@ -41,7 +41,11 @@ have_type("struct sockaddr_storage", hea https://github.com/ruby/ruby/blob/trunk/ext/socket/extconf.rb#L41
 
 have_type("struct addrinfo", headers)
 
-have_type("socklen_t", headers)
+if have_type("socklen_t", headers)
+  if try_static_assert("sizeof(socklen_t) >= sizeof(long)", headers)
+    $defs << "-DRSTRING_SOCKLEN=(socklen_t)RSTRING_LEN"
+  end
+end
 
 have_type("struct in_pktinfo", headers) {|src|
   src.sub(%r'^/\*top\*/', '\&'"\n#if defined(IPPROTO_IP) && defined(IP_PKTINFO)") <<
Index: ext/socket/socket.c
===================================================================
--- ext/socket/socket.c	(revision 40155)
+++ ext/socket/socket.c	(revision 40156)
@@ -381,7 +381,7 @@ sock_connect(VALUE sock, VALUE addr) https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L381
     addr = rb_str_new4(addr);
     GetOpenFile(sock, fptr);
     fd = fptr->fd;
-    n = rsock_connect(fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LENINT(addr), 0);
+    n = rsock_connect(fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_SOCKLEN(addr), 0);
     if (n < 0) {
 	rsock_sys_fail_addrinfo_or_sockaddr("connect(2)", addr, rai);
     }
@@ -442,7 +442,7 @@ sock_connect_nonblock(VALUE sock, VALUE https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L442
     addr = rb_str_new4(addr);
     GetOpenFile(sock, fptr);
     rb_io_set_nonblock(fptr);
-    n = connect(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LENINT(addr));
+    n = connect(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_SOCKLEN(addr));
     if (n < 0) {
         if (errno == EINPROGRESS)
             rb_mod_sys_fail(rb_mWaitWritable, "connect(2) would block");
@@ -546,7 +546,7 @@ sock_bind(VALUE sock, VALUE addr) https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L546
 
     SockAddrStringValueWithAddrinfo(addr, rai);
     GetOpenFile(sock, fptr);
-    if (bind(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_LENINT(addr)) < 0)
+    if (bind(fptr->fd, (struct sockaddr*)RSTRING_PTR(addr), RSTRING_SOCKLEN(addr)) < 0)
 	rsock_sys_fail_addrinfo_or_sockaddr("bind(2)", addr, rai);
 
     return INT2FIX(0);
@@ -1096,7 +1096,7 @@ sock_s_gethostbyaddr(int argc, VALUE *ar https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L1096
 	t = AF_INET6;
     }
 #endif
-    h = gethostbyaddr(RSTRING_PTR(addr), RSTRING_LENINT(addr), t);
+    h = gethostbyaddr(RSTRING_PTR(addr), RSTRING_SOCKLEN(addr), t);
     if (h == NULL) {
 #ifdef HAVE_HSTRERROR
 	extern int h_errno;
@@ -1319,7 +1319,7 @@ sock_s_getnameinfo(int argc, VALUE *argv https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L1319
 	    rb_raise(rb_eTypeError, "sockaddr size differs - should not happen");
 	}
 	sap = &ss.addr;
-        salen = RSTRING_LENINT(sa);
+        salen = RSTRING_SOCKLEN(sa);
 	goto call_nameinfo;
     }
     tmp = rb_check_array_type(sa);
@@ -1483,7 +1483,7 @@ sock_s_unpack_sockaddr_in(VALUE self, VA https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L1483
         rb_raise(rb_eArgError, "not an AF_INET sockaddr");
 #endif
     }
-    host = rsock_make_ipaddr((struct sockaddr*)sockaddr, RSTRING_LENINT(addr));
+    host = rsock_make_ipaddr((struct sockaddr*)sockaddr, RSTRING_SOCKLEN(addr));
     OBJ_INFECT(host, addr);
     return rb_assoc_new(INT2NUM(ntohs(sockaddr->sin_port)), host);
 }
@@ -1550,7 +1550,7 @@ sock_s_unpack_sockaddr_un(VALUE self, VA https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L1550
 	rb_raise(rb_eTypeError, "too long sockaddr_un - %ld longer than %d",
 		 RSTRING_LEN(addr), (int)sizeof(struct sockaddr_un));
     }
-    path = rsock_unixpath_str(sockaddr, RSTRING_LENINT(addr));
+    path = rsock_unixpath_str(sockaddr, RSTRING_SOCKLEN(addr));
     OBJ_INFECT(path, addr);
     return path;
 }
Index: ext/socket/basicsocket.c
===================================================================
--- ext/socket/basicsocket.c	(revision 40155)
+++ ext/socket/basicsocket.c	(revision 40156)
@@ -243,7 +243,7 @@ bsock_setsockopt(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ext/socket/basicsocket.c#L243
       default:
 	StringValue(val);
 	v = RSTRING_PTR(val);
-	vlen = RSTRING_LENINT(val);
+	vlen = RSTRING_SOCKLEN(val);
 	break;
     }
 
@@ -555,7 +555,7 @@ rsock_bsock_send(int argc, VALUE *argv, https://github.com/ruby/ruby/blob/trunk/ext/socket/basicsocket.c#L555
 	SockAddrStringValue(to);
 	to = rb_str_new4(to);
 	arg.to = (struct sockaddr *)RSTRING_PTR(to);
-	arg.tolen = (socklen_t)RSTRING_LENINT(to);
+	arg.tolen = RSTRING_SOCKLEN(to);
 	func = rsock_sendto_blocking;
     }
     else {
Index: ext/socket/ancdata.c
===================================================================
--- ext/socket/ancdata.c	(revision 40155)
+++ ext/socket/ancdata.c	(revision 40156)
@@ -1255,7 +1255,7 @@ bsock_sendmsg_internal(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/ext/socket/ancdata.c#L1255
     memset(&mh, 0, sizeof(mh));
     if (!NIL_P(dest_sockaddr)) {
         mh.msg_name = RSTRING_PTR(dest_sockaddr);
-        mh.msg_namelen = RSTRING_LENINT(dest_sockaddr);
+        mh.msg_namelen = RSTRING_SOCKLEN(dest_sockaddr);
     }
     mh.msg_iovlen = 1;
     mh.msg_iov = &iov;
@@ -1264,7 +1264,7 @@ bsock_sendmsg_internal(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/ext/socket/ancdata.c#L1264
 #if defined(HAVE_ST_MSG_CONTROL)
     if (controls_str) {
         mh.msg_control = RSTRING_PTR(controls_str);
-        mh.msg_controllen = RSTRING_LENINT(controls_str);
+        mh.msg_controllen = RSTRING_SOCKLEN(controls_str);
     }
     else {
         mh.msg_control = NULL;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]