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

ruby-changes:38695

From: normal <ko1@a...>
Date: Fri, 5 Jun 2015 05:50:33 +0900 (JST)
Subject: [ruby-changes:38695] normal:r50776 (trunk): ext/socket/ancdata.c (bsock_sendmsg_internal): use rb_scan_args

normal	2015-06-05 05:50:08 +0900 (Fri, 05 Jun 2015)

  New Revision: 50776

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

  Log:
    ext/socket/ancdata.c (bsock_sendmsg_internal): use rb_scan_args
    
    This should make the code more maintainable and make it easier to
    add keyword argument support for "exception: false" in the future.

  Modified files:
    trunk/ext/socket/ancdata.c
Index: ext/socket/ancdata.c
===================================================================
--- ext/socket/ancdata.c	(revision 50775)
+++ ext/socket/ancdata.c	(revision 50776)
@@ -1131,12 +1131,11 @@ bsock_sendmsg_internal(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/ext/socket/ancdata.c#L1131
 {
     rb_io_t *fptr;
     VALUE data, vflags, dest_sockaddr;
-    int controls_num;
     struct msghdr mh;
     struct iovec iov;
 #if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
+    VALUE controls = Qnil;
     VALUE controls_str = 0;
-    VALUE *controls_ptr = NULL;
     int family;
 #endif
     int flags;
@@ -1151,20 +1150,20 @@ bsock_sendmsg_internal(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/ext/socket/ancdata.c#L1150
 
     if (argc == 0)
         rb_raise(rb_eArgError, "mesg argument required");
-    data = argv[0];
-    if (1 < argc) vflags = argv[1];
-    if (2 < argc) dest_sockaddr = argv[2];
-    controls_num = 3 < argc ? argc - 3 : 0;
 #if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
-    if (3 < argc) { controls_ptr = &argv[3]; }
+    rb_scan_args(argc, argv, "12*", &data, &vflags, &dest_sockaddr, &controls);
+#else
+    rb_scan_args(argc, argv, "12", &data, &vflags, &dest_sockaddr);
 #endif
 
     StringValue(data);
 
-    if (controls_num) {
+    if (!NIL_P(controls)) {
 #if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
 	int i;
+	int controls_num = RARRAY_LENINT(controls);
 	size_t last_pad = 0;
+	const VALUE *controls_ptr = RARRAY_CONST_PTR(controls);
 #if defined(__NetBSD__)
         int last_level = 0;
         int last_type = 0;
@@ -1239,6 +1238,7 @@ bsock_sendmsg_internal(int argc, VALUE * https://github.com/ruby/ruby/blob/trunk/ext/socket/ancdata.c#L1238
                 rb_str_set_len(controls_str, RSTRING_LEN(controls_str)-last_pad);
 #endif
 	}
+	RB_GC_GUARD(controls);
 #else
 	rb_raise(rb_eNotImpError, "control message for sendmsg is unimplemented");
 #endif

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

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