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.kgio.general Subject: [PATCH] avoid downsizing casts Date: Mon, 20 Jan 2014 21:23:03 +0000 Message-ID: <20140120212303.GA18082@dcvr.yhbt.net> References: <20140120212303.GA18082@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 1390252983 15319 80.91.229.3 (20 Jan 2014 21:23:03 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 20 Jan 2014 21:23:03 +0000 (UTC) To: kgio@librelist.org Original-X-From: kgio@librelist.org Mon Jan 20 22:23:11 2014 Return-path: Envelope-to: gclrkg-kgio@m.gmane.org In-Reply-To: <20140120212303.GA18082@dcvr.yhbt.net> List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Precedence: list Original-Sender: kgio@librelist.org Xref: news.gmane.org gmane.comp.lang.ruby.kgio.general:256 Archived-At: Received: from zedshaw2.xen.prgmr.com ([71.19.156.177]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1W5MJJ-0001sN-Vq for gclrkg-kgio@m.gmane.org; Mon, 20 Jan 2014 22:23:10 +0100 Received: from zedshaw2.xen.prgmr.com (unknown [IPv6:::1]) by zedshaw2.xen.prgmr.com (Postfix) with ESMTP id DAD0073E30 for ; Mon, 20 Jan 2014 21:30:12 +0000 (UTC) It's always safe to cast a 32-bit value to a 64-bit value, but compilers can warn going the other way (because VALUE is a pointer). Tested with `ruby -v` ruby 2.2.0dev (2014-01-19 trunk 44646) [x86_64-linux] which enables -Wpointer-to-int-cast --- pushed as 809b9716a2593c0bfcaa115e7e560615c6357b55 ext/kgio/poll.c | 4 ++-- ext/kgio/tryopen.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ext/kgio/poll.c b/ext/kgio/poll.c index 15774d8..ae8d235 100644 --- a/ext/kgio/poll.c +++ b/ext/kgio/poll.c @@ -139,13 +139,13 @@ static VALUE poll_result(int nr, struct poll_args *a) static VALUE do_poll(VALUE args) { struct poll_args *a = (struct poll_args *)args; - int nr; + long nr; Check_Type(a->ios, T_HASH); retry: hash2pollfds(a); - nr = (int)rb_thread_blocking_region(nogvl_poll, a, RUBY_UBF_IO, NULL); + nr = (long)rb_thread_blocking_region(nogvl_poll, a, RUBY_UBF_IO, NULL); if (nr < 0) { if (interrupted()) { if (retryable(a)) { diff --git a/ext/kgio/tryopen.c b/ext/kgio/tryopen.c index 1d8fffd..5889294 100644 --- a/ext/kgio/tryopen.c +++ b/ext/kgio/tryopen.c @@ -81,7 +81,7 @@ static VALUE my_thread_blocking_region( */ static VALUE s_tryopen(int argc, VALUE *argv, VALUE klass) { - int fd; + long fd; VALUE pathname, flags, mode; struct open_args o; int retried = 0; @@ -106,7 +106,7 @@ static VALUE s_tryopen(int argc, VALUE *argv, VALUE klass) } retry: - fd = (int)rb_thread_blocking_region(nogvl_open, &o, RUBY_UBF_IO, 0); + fd = (long)rb_thread_blocking_region(nogvl_open, &o, RUBY_UBF_IO, 0); if (fd < 0) { if (errno == EMFILE || errno == ENFILE || errno == ENOMEM) { rb_gc(); @@ -125,7 +125,7 @@ retry: return rv; } } - rv = rb_funcall(klass, id_for_fd, 1, INT2FIX(fd)); + rv = rb_funcall(klass, id_for_fd, 1, LONG2FIX(fd)); set_file_path(rv, pathname); return rv; } -- Eric Wong