dumping ground for random patches and texts
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] dir.c (check_dirname): avoid volatile, use return value
Date: Tue, 23 Jun 2015 00:39:16 +0000	[thread overview]
Message-ID: <1435019956-6268-1-git-send-email-e@80x24.org> (raw)

volatile is unnecessary since we use rb_sys_fail_path nowadays
and that prevents the path argument from being GC-ed.
Using a return value instead of modifying the argument directly
simplifies the generated code.
---
 dir.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/dir.c b/dir.c
index 311a5e0..e271503 100644
--- a/dir.c
+++ b/dir.c
@@ -1004,10 +1004,10 @@ dir_s_getwd(VALUE dir)
     return rb_dir_getwd();
 }
 
-static void
-check_dirname(volatile VALUE *dir)
+static VALUE
+check_dirname(VALUE dir)
 {
-    VALUE d = *dir;
+    VALUE d = dir;
     char *path, *pend;
     long len;
     rb_encoding *enc;
@@ -1020,7 +1020,7 @@ check_dirname(volatile VALUE *dir)
     if (pend - path < len) {
 	d = rb_str_subseq(d, 0, pend - path);
     }
-    *dir = rb_str_encode_ospath(d);
+    return rb_str_encode_ospath(d);
 }
 
 #if defined(HAVE_CHROOT)
@@ -1036,7 +1036,7 @@ check_dirname(volatile VALUE *dir)
 static VALUE
 dir_s_chroot(VALUE dir, VALUE path)
 {
-    check_dirname(&path);
+    path = check_dirname(path);
     if (chroot(RSTRING_PTR(path)) == -1)
 	rb_sys_fail_path(path);
 
@@ -1074,7 +1074,7 @@ dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
 	mode = 0777;
     }
 
-    check_dirname(&path);
+    path = check_dirname(path);
     if (mkdir(RSTRING_PTR(path), mode) == -1)
 	rb_sys_fail_path(path);
 
@@ -1093,7 +1093,7 @@ dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
 static VALUE
 dir_s_rmdir(VALUE obj, VALUE dir)
 {
-    check_dirname(&dir);
+    dir = check_dirname(dir);
     if (rmdir(RSTRING_PTR(dir)) < 0)
 	rb_sys_fail_path(dir);
 
-- 
EW


                 reply	other threads:[~2015-06-23  0:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1435019956-6268-1-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=spew@80x24.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.
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).