ruby-changes:49832
From: shyouhei <ko1@a...>
Date: Fri, 19 Jan 2018 18:12:13 +0900 (JST)
Subject: [ruby-changes:49832] shyouhei:r61950 (trunk): there is no guarantee that mode_t is as wide as int
shyouhei 2018-01-19 18:12:06 +0900 (Fri, 19 Jan 2018) New Revision: 61950 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61950 Log: there is no guarantee that mode_t is as wide as int POSIX only defines mode_t to be "an integer typea", and in fact MacOS defines it to be uint16_t. We didn't have NUM2USHORT before so it did not make sense but now that we have it. Why not check apptopriately. Modified files: trunk/configure.ac trunk/file.c trunk/include/ruby/ruby.h trunk/process.c Index: configure.ac =================================================================== --- configure.ac (revision 61949) +++ configure.ac (revision 61950) @@ -1611,6 +1611,8 @@ AC_DEFUN([RUBY_REPLACE_TYPE], [dnl https://github.com/ruby/ruby/blob/trunk/configure.ac#L1611 t=LL], [*" long "*], [ t=LONG], + [*" short "*], [ + t=SHORT], [ t=INT]) rb_cv_[$1]_convertible=${u}${t}]) @@ -1620,6 +1622,7 @@ AC_DEFUN([RUBY_REPLACE_TYPE], [dnl https://github.com/ruby/ruby/blob/trunk/configure.ac#L1622 AS_CASE(["${rb_cv_[$1]_convertible}"], [*LL], [n="long long"], [*LONG], [n="long"], + [*SHORT], [n="short"], [n="int"]) AS_CASE(["${rb_cv_[$1]_convertible}"], [U*], [n="unsigned $n"]) @@ -1637,7 +1640,7 @@ RUBY_REPLACE_TYPE(uid_t, int, UIDT) https://github.com/ruby/ruby/blob/trunk/configure.ac#L1640 RUBY_REPLACE_TYPE(gid_t, int, GIDT) RUBY_REPLACE_TYPE(time_t, [], TIMET, [@%:@include <time.h>]) RUBY_REPLACE_TYPE(dev_t, [int long "long long"], DEVT) -RUBY_REPLACE_TYPE(mode_t, ["unsigned int" long], MODET, [@%:@include <sys/stat.h>]) +RUBY_REPLACE_TYPE(mode_t, ["unsigned short" "unsigned int" long], MODET, [@%:@include <sys/stat.h>]) RUBY_REPLACE_TYPE(rlim_t, [int long "long long"], RLIM, [ @%:@ifdef HAVE_SYS_TYPES_H @%:@include <sys/types.h> Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 61949) +++ include/ruby/ruby.h (revision 61950) @@ -113,6 +113,9 @@ typedef char ruby_check_sizeof_voidp[SIZ https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L113 #ifndef PRI_LONG_PREFIX #define PRI_LONG_PREFIX "l" #endif +#ifndef PRI_SHORT_PREFIX +#define PRI_SHORT_PREFIX "h" +#endif #if SIZEOF_LONG == 8 #define PRI_64_PREFIX PRI_LONG_PREFIX @@ -1571,6 +1574,7 @@ rb_num2char_inline(VALUE x) https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1574 #define LONG2NUM(x) RB_LONG2NUM(x) #define ULONG2NUM(x) RB_ULONG2NUM(x) +#define USHORT2NUM(x) RB_INT2FIX(x) #define NUM2CHR(x) RB_NUM2CHR(x) #define CHR2FIX(x) RB_CHR2FIX(x) Index: process.c =================================================================== --- process.c (revision 61949) +++ process.c (revision 61950) @@ -2348,7 +2348,7 @@ rb_execarg_parent_start1(VALUE execarg_o https://github.com/ruby/ruby/blob/trunk/process.c#L2348 VALUE param = RARRAY_AREF(elt, 1); VALUE vpath = RARRAY_AREF(param, 0); int flags = NUM2INT(RARRAY_AREF(param, 1)); - int perm = NUM2INT(RARRAY_AREF(param, 2)); + mode_t perm = NUM2MODET(RARRAY_AREF(param, 2)); VALUE fd2v = RARRAY_AREF(param, 3); int fd2; if (NIL_P(fd2v)) { Index: file.c =================================================================== --- file.c (revision 61949) +++ file.c (revision 61950) @@ -2384,12 +2384,12 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/file.c#L2384 rb_file_chmod(VALUE obj, VALUE vmode) { rb_io_t *fptr; - int mode; + mode_t mode; #if !defined HAVE_FCHMOD || !HAVE_FCHMOD VALUE path; #endif - mode = NUM2INT(vmode); + mode = NUM2MODET(vmode); GetOpenFile(obj, fptr); #ifdef HAVE_FCHMOD -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/