From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS47066 71.19.144.0/20 X-Spam-Status: No, score=-1.9 required=3.0 tests=AWL,BAYES_00, MSGID_FROM_MTA_HEADER shortcircuit=no autolearn=unavailable version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.io-splice.general Subject: [PATCH] avoid RARRAY_PTR usage for vmsplice Date: Thu, 26 Sep 2013 19:15:18 +0000 Message-ID: <20130926191518.GA880@dcvr.yhbt.net> References: <20130926191518.GA880@dcvr.yhbt.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1380222926 6505 80.91.229.3 (26 Sep 2013 19:15:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 26 Sep 2013 19:15:26 +0000 (UTC) To: ruby.io.splice@librelist.org Original-X-From: ruby.io.splice@librelist.org Thu Sep 26 21:15:28 2013 Return-path: Envelope-to: gclrig-ruby.io.splice@m.gmane.org In-Reply-To: <20130926191518.GA880@dcvr.yhbt.net> List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Precedence: list Original-Sender: ruby.io.splice@librelist.org Xref: news.gmane.org gmane.comp.lang.ruby.io-splice.general:46 Archived-At: Received: from zedshaw2.xen.prgmr.com ([71.19.156.177]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VPH27-0003KG-Lq for gclrig-ruby.io.splice@m.gmane.org; Thu, 26 Sep 2013 21:15:27 +0200 Received: from zedshaw2.xen.prgmr.com (unknown [IPv6:::1]) by zedshaw2.xen.prgmr.com (Postfix) with ESMTP id 3843F7505E for ; Thu, 26 Sep 2013 19:26:09 +0000 (UTC) In case somebody finds vmsplice useful in Ruby, we avoid incurring the performance loss from RARRAY_PTR under Ruby 2.1.0 and Rubinius. However, I still haven't found a useful use of vmsplice under Ruby (or any high-level languages). --- ext/io_splice/io_splice_ext.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/ext/io_splice/io_splice_ext.c b/ext/io_splice/io_splice_ext.c index 1c938c3..9a838df 100644 --- a/ext/io_splice/io_splice_ext.c +++ b/ext/io_splice/io_splice_ext.c @@ -108,9 +108,6 @@ rb_thread_blocking_region( #ifndef RSTRING_LEN # define RSTRING_LEN(s) (RSTRING(s)->len) #endif -#ifndef RARRAY_PTR -# define RARRAY_PTR(s) (RARRAY(s)->ptr) -#endif #ifndef RARRAY_LEN # define RARRAY_LEN(s) (RARRAY(s)->len) #endif @@ -416,20 +413,18 @@ static VALUE nogvl_vmsplice(void *ptr) /* this can't be a function since we use alloca() */ #define ARY2IOVEC(iov,iovcnt,expect,ary) \ do { \ - VALUE *cur; \ struct iovec *tmp; \ - long n; \ - cur = RARRAY_PTR(ary); \ - n = RARRAY_LEN(ary); \ - if (n > IOV_MAX) \ + unsigned long i; \ + iovcnt = (unsigned long)RARRAY_LEN(ary); \ + if (iovcnt > IOV_MAX) \ rb_raise(rb_eArgError, "array is larger than IOV_MAX"); \ - iov = tmp = alloca(sizeof(struct iovec) * n); \ + iov = tmp = alloca(sizeof(struct iovec) * iovcnt); \ expect = 0; \ - iovcnt = n; \ - for (; --n >= 0; tmp++, cur++) { \ - Check_Type(*cur, T_STRING); \ - tmp->iov_base = RSTRING_PTR(*cur); \ - tmp->iov_len = RSTRING_LEN(*cur); \ + for (i = 0; i < iovcnt; tmp++, i++) { \ + VALUE cur = rb_ary_entry(ary, (long)i); \ + Check_Type(cur, T_STRING); \ + tmp->iov_base = RSTRING_PTR(cur); \ + tmp->iov_len = RSTRING_LEN(cur); \ expect += tmp->iov_len; \ } \ } while (0) -- Eric Wong