ruby-changes:54892
From: nobu <ko1@a...>
Date: Wed, 20 Feb 2019 15:54:29 +0900 (JST)
Subject: [ruby-changes:54892] nobu:r67097 (trunk): Try statx syscall
nobu 2019-02-20 15:54:23 +0900 (Wed, 20 Feb 2019) New Revision: 67097 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67097 Log: Try statx syscall * file.c (rb_file_s_birthtime): export for pathname to check if birthtime is supported. Modified files: trunk/configure.ac trunk/ext/pathname/extconf.rb trunk/ext/pathname/pathname.c trunk/file.c trunk/test/pathname/test_pathname.rb Index: file.c =================================================================== --- file.c (revision 67096) +++ file.c (revision 67097) @@ -1113,6 +1113,24 @@ stat_without_gvl(const char *path, struc https://github.com/ruby/ruby/blob/trunk/file.c#L1113 } #ifdef HAVE_STATX + +# if HAVE_STATX == 0 +# ifdef HAVE_SYSCALL_H +# include <syscall.h> +# elif defined HAVE_SYS_SYSCALL_H +# include <sys/syscall.h> +# endif +# if defined __linux__ +# include <linux/stat.h> +static inline int +statx(int dirfd, const char *pathname, int flags, + unsigned int mask, struct statx *statxbuf) +{ + return syscall(__NR_statx, dirfd, pathname, flags, mask, statxbuf); +} +# endif +# endif + typedef struct no_gvl_statx_data { struct statx *stx; int fd; @@ -2360,9 +2378,10 @@ rb_file_ctime(VALUE obj) https://github.com/ruby/ruby/blob/trunk/file.c#L2378 * */ -#if defined(HAVE_STAT_BIRTHTIME) -static VALUE +#if defined(HAVE_STAT_BIRTHTIME) || defined(HAVE_STATX) +RUBY_FUNC_EXPORTED VALUE rb_file_s_birthtime(VALUE klass, VALUE fname) +# if defined(HAVE_STAT_BIRTHTIME) { struct stat st; @@ -2373,9 +2392,7 @@ rb_file_s_birthtime(VALUE klass, VALUE f https://github.com/ruby/ruby/blob/trunk/file.c#L2392 } return stat_birthtime(&st); } -#elif defined(HAVE_STATX) -static VALUE -rb_file_s_birthtime(VALUE klass, VALUE fname) +# elif defined(HAVE_STATX) { struct statx stx; @@ -2390,6 +2407,9 @@ rb_file_s_birthtime(VALUE klass, VALUE f https://github.com/ruby/ruby/blob/trunk/file.c#L2407 } return statx_birthtime(&stx); } +# else +# error Not implemented +# endif #else # define rb_file_s_birthtime rb_f_notimplement #endif Index: test/pathname/test_pathname.rb =================================================================== --- test/pathname/test_pathname.rb (revision 67096) +++ test/pathname/test_pathname.rb (revision 67097) @@ -789,10 +789,15 @@ class TestPathname < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/pathname/test_pathname.rb#L789 end def test_birthtime - assert_kind_of(Time, Pathname(__FILE__).birthtime) - rescue NotImplementedError - assert_raise(NotImplementedError) do - File.birthtime(__FILE__) + # Check under a (probably) local filesystem. + # Remote filesystems often may not support birthtime. + with_tmpchdir('rubytest-pathname') do |dir| + open("a", "w") {} + assert_kind_of(Time, Pathname("a").birthtime) + rescue NotImplementedError + assert_raise(NotImplementedError) do + File.birthtime("a") + end end end Index: configure.ac =================================================================== --- configure.ac (revision 67096) +++ configure.ac (revision 67097) @@ -1897,7 +1897,18 @@ AC_CHECK_FUNCS(sigaltstack) https://github.com/ruby/ruby/blob/trunk/configure.ac#L1897 AC_CHECK_FUNCS(sigprocmask) AC_CHECK_FUNCS(sinh) AC_CHECK_FUNCS(spawnv) -AC_CHECK_FUNCS(statx) +AC_CHECK_FUNCS(statx, [], + [AS_CASE(["$target_os"], [linux*], + [AC_CHECK_DECLS([__NR_statx], [ac_cv_func_statx=syscall], [], + [ + @%:@ ifdef HAVE_SYSCALL_H + @%:@ include <syscall.h> + @%:@ elif defined HAVE_SYS_SYSCALL_H + @%:@ include <sys/syscall.h> + @%:@ endif + ]) + ]) +]) AC_CHECK_FUNCS(symlink) AC_CHECK_FUNCS(syscall) AC_CHECK_FUNCS(sysconf) @@ -1913,6 +1924,8 @@ AC_CHECK_FUNCS(utimes) https://github.com/ruby/ruby/blob/trunk/configure.ac#L1924 AC_CHECK_FUNCS(wait4) AC_CHECK_FUNCS(waitpid) +AS_IF([test "$ac_cv_func_statx" = syscall], [AC_DEFINE(HAVE_STATX, 0)]) + AS_CASE(["$ac_cv_func_memset_s:$ac_cv_func_qsort_s"], [*yes*], [RUBY_DEFINE_IF([!defined __STDC_WANT_LIB_EXT1__], [__STDC_WANT_LIB_EXT1__], 1)]) Index: ext/pathname/pathname.c =================================================================== --- ext/pathname/pathname.c (revision 67096) +++ ext/pathname/pathname.c (revision 67097) @@ -512,7 +512,7 @@ path_atime(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L512 return rb_funcall(rb_cFile, id_atime, 1, get_strpath(self)); } -#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC) || defined(_WIN32) +#if defined(HAVE_RB_FILE_S_BIRTHTIME) /* * call-seq: * pathname.birthtime -> time @@ -528,6 +528,7 @@ path_birthtime(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L528 return rb_funcall(rb_cFile, id_birthtime, 1, get_strpath(self)); } #else +/* check at compilation time for `respond_to?` */ # define path_birthtime rb_f_notimplement #endif Index: ext/pathname/extconf.rb =================================================================== --- ext/pathname/extconf.rb (revision 67096) +++ ext/pathname/extconf.rb (revision 67097) @@ -1,4 +1,4 @@ https://github.com/ruby/ruby/blob/trunk/ext/pathname/extconf.rb#L1 # frozen_string_literal: false require 'mkmf' -have_struct_member("struct stat", "st_birthtimespec", "sys/stat.h") +have_func("rb_file_s_birthtime") create_makefile('pathname') -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/