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

ruby-changes:32417

From: nobu <ko1@a...>
Date: Sat, 4 Jan 2014 19:13:45 +0900 (JST)
Subject: [ruby-changes:32417] nobu:r44496 (trunk): socket.c: use rb_syserr_fail

nobu	2014-01-04 19:13:36 +0900 (Sat, 04 Jan 2014)

  New Revision: 44496

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

  Log:
    socket.c: use rb_syserr_fail
    
    * ext/socket/socket.c (rsock_syserr_fail_host_port): add errno
      argument version anduse rb_syserr_fail_str() instead of
      rb_sys_fail_str() with restoring errno.
    * ext/socket/socket.c (rsock_syserr_fail_path): ditto, and
      rb_syserr_fail().
    * ext/socket/socket.c (rsock_sys_fail_sockaddr): ditto, use
      rsock_syserr_fail_raddrinfo().
    * ext/socket/socket.c (rsock_sys_fail_raddrinfo): ditto.
    * ext/socket/socket.c (setup_domain_and_type): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/ext/socket/rubysocket.h
    trunk/ext/socket/socket.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44495)
+++ ChangeLog	(revision 44496)
@@ -1,3 +1,19 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jan  4 19:13:34 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* ext/socket/socket.c (rsock_syserr_fail_host_port): add errno
+	  argument version anduse rb_syserr_fail_str() instead of
+	  rb_sys_fail_str() with restoring errno.
+
+	* ext/socket/socket.c (rsock_syserr_fail_path): ditto, and
+	  rb_syserr_fail().
+
+	* ext/socket/socket.c (rsock_sys_fail_sockaddr): ditto, use
+	  rsock_syserr_fail_raddrinfo().
+
+	* ext/socket/socket.c (rsock_sys_fail_raddrinfo): ditto.
+
+	* ext/socket/socket.c (setup_domain_and_type): ditto.
+
 Sat Jan  4 17:18:58 2014  Kazuki Tsujimoto  <kazuki@c...>
 
 	* vm.c (RubyVM::OPTS): get rid of a garbage character.
Index: ext/socket/rubysocket.h
===================================================================
--- ext/socket/rubysocket.h	(revision 44495)
+++ ext/socket/rubysocket.h	(revision 44496)
@@ -374,6 +374,12 @@ void rsock_init_sockopt(void); https://github.com/ruby/ruby/blob/trunk/ext/socket/rubysocket.h#L374
 void rsock_init_sockifaddr(void);
 void rsock_init_socket_init(void);
 
+NORETURN(void rsock_syserr_fail_host_port(int err, const char *, VALUE, VALUE));
+NORETURN(void rsock_syserr_fail_path(int err, const char *, VALUE));
+NORETURN(void rsock_syserr_fail_sockaddr(int err, const char *mesg, struct sockaddr *addr, socklen_t len));
+NORETURN(void rsock_syserr_fail_raddrinfo(int err, const char *mesg, VALUE rai));
+NORETURN(void rsock_syserr_fail_raddrinfo_or_sockaddr(int err, const char *mesg, VALUE addr, VALUE rai));
+
 NORETURN(void rsock_sys_fail_host_port(const char *, VALUE, VALUE));
 NORETURN(void rsock_sys_fail_path(const char *, VALUE));
 NORETURN(void rsock_sys_fail_sockaddr(const char *, struct sockaddr *addr, socklen_t len));
Index: ext/socket/socket.c
===================================================================
--- ext/socket/socket.c	(revision 44495)
+++ ext/socket/socket.c	(revision 44496)
@@ -15,23 +15,32 @@ static VALUE sock_s_unpack_sockaddr_in(V https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L15
 void
 rsock_sys_fail_host_port(const char *mesg, VALUE host, VALUE port)
 {
+    rsock_syserr_fail_host_port(errno, mesg, host, port);
+}
+
+void
+rsock_syserr_fail_host_port(int err, const char *mesg, VALUE host, VALUE port)
+{
     VALUE message;
-    int err = errno;
 
     port = rb_String(port);
 
     message = rb_sprintf("%s for \"%s\" port %s",
 	    mesg, StringValueCStr(host), StringValueCStr(port));
 
-    errno = err;
-    rb_sys_fail_str(message);
+    rb_syserr_fail_str(err, message);
 }
 
 void
 rsock_sys_fail_path(const char *mesg, VALUE path)
 {
+    rsock_syserr_fail_path(errno, mesg, path);
+}
+
+void
+rsock_syserr_fail_path(int err, const char *mesg, VALUE path)
+{
     VALUE message;
-    int err = errno;
 
     if (RB_TYPE_P(path, T_STRING)) {
         if (memchr(RSTRING_PTR(path), '\0', RSTRING_LEN(path))) {
@@ -43,54 +52,64 @@ rsock_sys_fail_path(const char *mesg, VA https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L52
             message = rb_sprintf("%s for \"%s\"", mesg,
                     StringValueCStr(path));
         }
-        errno = err;
-        rb_sys_fail_str(message);
+	rb_syserr_fail_str(err, message);
     }
     else {
-        rb_sys_fail(mesg);
+	rb_syserr_fail(err, mesg);
     }
 }
 
 void
 rsock_sys_fail_sockaddr(const char *mesg, struct sockaddr *addr, socklen_t len)
 {
+    rsock_syserr_fail_sockaddr(errno, mesg, addr, len);
+}
+
+void
+rsock_syserr_fail_sockaddr(int err, const char *mesg, struct sockaddr *addr, socklen_t len)
+{
     VALUE rai;
-    int err = errno;
 
     rai = rsock_addrinfo_new(addr, len, PF_UNSPEC, 0, 0, Qnil, Qnil);
 
-    errno = err;
-    rsock_sys_fail_raddrinfo(mesg, rai);
+    rsock_syserr_fail_raddrinfo(err, mesg, rai);
 }
 
 void
 rsock_sys_fail_raddrinfo(const char *mesg, VALUE rai)
 {
+    rsock_syserr_fail_raddrinfo(errno, mesg, rai);
+}
+
+void
+rsock_syserr_fail_raddrinfo(int err, const char *mesg, VALUE rai)
+{
     VALUE str, message;
-    int err = errno;
 
     str = rsock_addrinfo_inspect_sockaddr(rai);
     message = rb_sprintf("%s for %s", mesg, StringValueCStr(str));
 
-    errno = err;
-    rb_sys_fail_str(message);
+    rb_syserr_fail_str(err, message);
 }
 
 void
 rsock_sys_fail_raddrinfo_or_sockaddr(const char *mesg, VALUE addr, VALUE rai)
 {
-    int err = errno;
+    rsock_syserr_fail_raddrinfo_or_sockaddr(errno, mesg, addr, rai);
+}
 
+void
+rsock_syserr_fail_raddrinfo_or_sockaddr(int err, const char *mesg, VALUE addr, VALUE rai)
+{
     if (NIL_P(rai)) {
         StringValue(addr);
 
-        errno = err;
-        rsock_sys_fail_sockaddr(mesg,
+	rsock_syserr_fail_sockaddr(err, mesg,
             (struct sockaddr *)RSTRING_PTR(addr),
             (socklen_t)RSTRING_LEN(addr)); /* overflow should be checked already */
     }
     else
-        rsock_sys_fail_raddrinfo(mesg, rai);
+	rsock_syserr_fail_raddrinfo(err, mesg, rai);
 }
 
 static void

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

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