From: Eric Wong <normalperson@yhbt.net>
To: kgio@librelist.org
Subject: [PATCH] avoid downsizing casts
Date: Mon, 20 Jan 2014 21:23:03 +0000 [thread overview]
Message-ID: <20140120212303.GA18082@dcvr.yhbt.net> (raw)
In-Reply-To: <20140120212303.GA18082@dcvr.yhbt.net>
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
parent reply other threads:[~2014-01-20 21:23 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20140120212303.GA18082@dcvr.yhbt.net>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/kgio/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140120212303.GA18082@dcvr.yhbt.net \
--to=normalperson@yhbt.net \
--cc=kgio@librelist.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/kgio.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).