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

ruby-changes:48478

From: normal <ko1@a...>
Date: Wed, 1 Nov 2017 04:10:26 +0900 (JST)
Subject: [ruby-changes:48478] normal:r60592 (trunk): use mode_t where applicable (instead of int)

normal	2017-11-01 04:10:19 +0900 (Wed, 01 Nov 2017)

  New Revision: 60592

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

  Log:
    use mode_t where applicable (instead of int)
    
    mode_t is the correct type for these syscalls and it can be
    easier-to-understand.  It may also help portability to future
    platforms and improve type checking.
    
    * dir.c (dir_s_mkdir): use mode_t for mkdir(2)
    
    * file.c (chmod_internal): use mode_t for chmod(2)
      (rb_file_s_chmod): s/int/mode_t/
      (lchmod_internal): ditto, deref pointer as in chmod_internal
      (rb_file_s_lchmod): pass pointer as in rb_file_s_chmod
      (rb_file_s_rename): use mode_t for umask(2)

  Modified files:
    trunk/dir.c
    trunk/file.c
Index: dir.c
===================================================================
--- dir.c	(revision 60591)
+++ dir.c	(revision 60592)
@@ -1218,10 +1218,10 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/dir.c#L1218
 dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
 {
     VALUE path, vmode;
-    int mode;
+    mode_t mode;
 
     if (rb_scan_args(argc, argv, "11", &path, &vmode) == 2) {
-	mode = NUM2INT(vmode);
+	mode = NUM2MODET(vmode);
     }
     else {
 	mode = 0777;
Index: file.c
===================================================================
--- file.c	(revision 60591)
+++ file.c	(revision 60592)
@@ -2388,7 +2388,7 @@ rb_file_size(VALUE obj) https://github.com/ruby/ruby/blob/trunk/file.c#L2388
 static int
 chmod_internal(const char *path, void *mode)
 {
-    return chmod(path, *(int *)mode);
+    return chmod(path, *(mode_t *)mode);
 }
 
 /*
@@ -2407,10 +2407,10 @@ chmod_internal(const char *path, void *m https://github.com/ruby/ruby/blob/trunk/file.c#L2407
 static VALUE
 rb_file_s_chmod(int argc, VALUE *argv)
 {
-    int mode;
+    mode_t mode;
 
     apply2args(1);
-    mode = NUM2INT(*argv++);
+    mode = NUM2MODET(*argv++);
 
     return apply2files(chmod_internal, argc, argv, &mode);
 }
@@ -2463,7 +2463,7 @@ rb_file_chmod(VALUE obj, VALUE vmode) https://github.com/ruby/ruby/blob/trunk/file.c#L2463
 static int
 lchmod_internal(const char *path, void *mode)
 {
-    return lchmod(path, (int)(VALUE)mode);
+    return lchmod(path, *(mode_t *)mode);
 }
 
 /*
@@ -2479,12 +2479,12 @@ lchmod_internal(const char *path, void * https://github.com/ruby/ruby/blob/trunk/file.c#L2479
 static VALUE
 rb_file_s_lchmod(int argc, VALUE *argv)
 {
-    long mode;
+    mode_t mode;
 
     apply2args(1);
-    mode = NUM2INT(*argv++);
+    mode = NUM2MODET(*argv++);
 
-    return apply2files(lchmod_internal, argc, argv, (void *)(long)mode);
+    return apply2files(lchmod_internal, argc, argv, &mode);
 }
 #else
 #define rb_file_s_lchmod rb_f_notimplement
@@ -3007,19 +3007,19 @@ rb_file_s_rename(VALUE klass, VALUE from https://github.com/ruby/ruby/blob/trunk/file.c#L3007
 static VALUE
 rb_file_s_umask(int argc, VALUE *argv)
 {
-    int omask = 0;
+    mode_t omask = 0;
 
     if (argc == 0) {
 	omask = umask(0);
 	umask(omask);
     }
     else if (argc == 1) {
-	omask = umask(NUM2INT(argv[0]));
+	omask = umask(NUM2MODET(argv[0]));
     }
     else {
 	rb_check_arity(argc, 0, 1);
     }
-    return INT2FIX(omask);
+    return MODET2NUM(omask);
 }
 
 #ifdef __CYGWIN__

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

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