diff options
Diffstat (limited to 'ext/etc')
-rw-r--r-- | ext/etc/.document | 2 | ||||
-rw-r--r-- | ext/etc/depend | 1 | ||||
-rw-r--r-- | ext/etc/etc.c | 113 | ||||
-rw-r--r-- | ext/etc/extconf.rb | 12 | ||||
-rw-r--r-- | ext/etc/mkconstants.rb | 32 |
5 files changed, 110 insertions, 50 deletions
diff --git a/ext/etc/.document b/ext/etc/.document new file mode 100644 index 0000000000..9bbea23b92 --- /dev/null +++ b/ext/etc/.document @@ -0,0 +1,2 @@ +etc.c +constdefs.h diff --git a/ext/etc/depend b/ext/etc/depend index 00787b6aaf..675699b129 100644 --- a/ext/etc/depend +++ b/ext/etc/depend @@ -162,6 +162,7 @@ etc.o: $(hdrdir)/ruby/internal/special_consts.h etc.o: $(hdrdir)/ruby/internal/static_assert.h etc.o: $(hdrdir)/ruby/internal/stdalign.h etc.o: $(hdrdir)/ruby/internal/stdbool.h +etc.o: $(hdrdir)/ruby/internal/stdckdint.h etc.o: $(hdrdir)/ruby/internal/symbol.h etc.o: $(hdrdir)/ruby/internal/value.h etc.o: $(hdrdir)/ruby/internal/value_type.h diff --git a/ext/etc/etc.c b/ext/etc/etc.c index 0b3e5ffd5e..fcbd1af1b5 100644 --- a/ext/etc/etc.c +++ b/ext/etc/etc.c @@ -54,9 +54,9 @@ static VALUE sGroup; # include <stdlib.h> # endif #endif -char *getlogin(); +RUBY_EXTERN char *getlogin(void); -#define RUBY_ETC_VERSION "1.4.2" +#define RUBY_ETC_VERSION "1.4.3" #ifdef HAVE_RB_DEPRECATE_CONSTANT void rb_deprecate_constant(VALUE mod, const char *name); @@ -68,7 +68,8 @@ void rb_deprecate_constant(VALUE mod, const char *name); #ifndef HAVE_RB_IO_DESCRIPTOR static int -io_descriptor_fallback(VALUE io) { +io_descriptor_fallback(VALUE io) +{ rb_io_t *fptr; GetOpenFile(io, fptr); return fptr->fd; @@ -202,7 +203,7 @@ setup_passwd(struct passwd *pwd) #endif /* call-seq: - * getpwuid(uid) -> Passwd + * getpwuid(uid) -> Etc::Passwd * * Returns the <tt>/etc/passwd</tt> information for the user with the given * integer +uid+. @@ -214,7 +215,7 @@ setup_passwd(struct passwd *pwd) * * See the unix manpage for <code>getpwuid(3)</code> for more detail. * - * === Example: + * *Example:* * * Etc.getpwuid(0) * #=> #<struct Etc::Passwd name="root", passwd="x", uid=0, gid=0, gecos="root",dir="/root", shell="/bin/bash"> @@ -242,7 +243,7 @@ etc_getpwuid(int argc, VALUE *argv, VALUE obj) } /* call-seq: - * getpwnam(name) -> Passwd + * getpwnam(name) -> Etc::Passwd * * Returns the <tt>/etc/passwd</tt> information for the user with specified * login +name+. @@ -251,7 +252,7 @@ etc_getpwuid(int argc, VALUE *argv, VALUE obj) * * See the unix manpage for <code>getpwnam(3)</code> for more detail. * - * === Example: + * *Example:* * * Etc.getpwnam('root') * #=> #<struct Etc::Passwd name="root", passwd="x", uid=0, gid=0, gecos="root",dir="/root", shell="/bin/bash"> @@ -306,8 +307,8 @@ each_passwd(void) #endif /* call-seq: - * Etc.passwd { |struct| block } -> Passwd - * Etc.passwd -> Passwd + * passwd { |struct| block } + * passwd -> Etc::Passwd * * Provides a convenient Ruby iterator which executes a block for each entry * in the <tt>/etc/passwd</tt> file. @@ -316,7 +317,7 @@ each_passwd(void) * * See ::getpwent above for details. * - * Example: + * *Example:* * * require 'etc' * @@ -342,7 +343,7 @@ etc_passwd(VALUE obj) } /* call-seq: - * Etc::Passwd.each { |struct| block } -> Passwd + * Etc::Passwd.each { |struct| block } -> Etc::Passwd * Etc::Passwd.each -> Enumerator * * Iterates for each entry in the <tt>/etc/passwd</tt> file if a block is @@ -354,7 +355,7 @@ etc_passwd(VALUE obj) * * See Etc.getpwent above for details. * - * Example: + * *Example:* * * require 'etc' * @@ -376,7 +377,10 @@ etc_each_passwd(VALUE obj) return obj; } -/* Resets the process of reading the <tt>/etc/passwd</tt> file, so that the +/* call-seq: + * setpwent + * + * Resets the process of reading the <tt>/etc/passwd</tt> file, so that the * next call to ::getpwent will return the first entry again. */ static VALUE @@ -388,7 +392,10 @@ etc_setpwent(VALUE obj) return Qnil; } -/* Ends the process of scanning through the <tt>/etc/passwd</tt> file begun +/* call-seq: + * endpwent + * + * Ends the process of scanning through the <tt>/etc/passwd</tt> file begun * with ::getpwent, and closes the file. */ static VALUE @@ -400,7 +407,10 @@ etc_endpwent(VALUE obj) return Qnil; } -/* Returns an entry from the <tt>/etc/passwd</tt> file. +/* call-seq: + * getpwent -> Etc::Passwd + * + * Returns an entry from the <tt>/etc/passwd</tt> file. * * The first time it is called it opens the file and returns the first entry; * each successive call returns the next entry, or +nil+ if the end of the file @@ -448,7 +458,7 @@ setup_group(struct group *grp) #endif /* call-seq: - * getgrgid(group_id) -> Group + * getgrgid(group_id) -> Etc::Group * * Returns information about the group with specified integer +group_id+, * as found in <tt>/etc/group</tt>. @@ -457,7 +467,7 @@ setup_group(struct group *grp) * * See the unix manpage for <code>getgrgid(3)</code> for more detail. * - * === Example: + * *Example:* * * Etc.getgrgid(100) * #=> #<struct Etc::Group name="users", passwd="x", gid=100, mem=["meta", "root"]> @@ -486,7 +496,7 @@ etc_getgrgid(int argc, VALUE *argv, VALUE obj) } /* call-seq: - * getgrnam(name) -> Group + * getgrnam(name) -> Etc::Group * * Returns information about the group with specified +name+, as found in * <tt>/etc/group</tt>. @@ -495,7 +505,7 @@ etc_getgrgid(int argc, VALUE *argv, VALUE obj) * * See the unix manpage for <code>getgrnam(3)</code> for more detail. * - * === Example: + * *Example:* * * Etc.getgrnam('users') * #=> #<struct Etc::Group name="users", passwd="x", gid=100, mem=["meta", "root"]> @@ -528,7 +538,6 @@ group_ensure(VALUE _) return Qnil; } - static VALUE group_iterate(VALUE _) { @@ -551,14 +560,18 @@ each_group(void) } #endif -/* Provides a convenient Ruby iterator which executes a block for each entry +/* call-seq: + * group { |struct| block } + * group -> Etc::Group + * + * Provides a convenient Ruby iterator which executes a block for each entry * in the <tt>/etc/group</tt> file. * * The code block is passed an Group struct. * * See ::getgrent above for details. * - * Example: + * *Example:* * * require 'etc' * @@ -585,7 +598,7 @@ etc_group(VALUE obj) #ifdef HAVE_GETGRENT /* call-seq: - * Etc::Group.each { |group| block } -> obj + * Etc::Group.each { |group| block } -> Etc::Group * Etc::Group.each -> Enumerator * * Iterates for each entry in the <tt>/etc/group</tt> file if a block is @@ -595,7 +608,7 @@ etc_group(VALUE obj) * * The code block is passed a Group struct. * - * Example: + * *Example:* * * require 'etc' * @@ -616,7 +629,10 @@ etc_each_group(VALUE obj) } #endif -/* Resets the process of reading the <tt>/etc/group</tt> file, so that the +/* call-seq: + * setgrent + * + * Resets the process of reading the <tt>/etc/group</tt> file, so that the * next call to ::getgrent will return the first entry again. */ static VALUE @@ -628,7 +644,10 @@ etc_setgrent(VALUE obj) return Qnil; } -/* Ends the process of scanning through the <tt>/etc/group</tt> file begun +/* call-seq: + * endgrent + * + * Ends the process of scanning through the <tt>/etc/group</tt> file begun * by ::getgrent, and closes the file. */ static VALUE @@ -640,7 +659,10 @@ etc_endgrent(VALUE obj) return Qnil; } -/* Returns an entry from the <tt>/etc/group</tt> file. +/* call-seq: + * getgrent -> Etc::Group + * + * Returns an entry from the <tt>/etc/group</tt> file. * * The first time it is called it opens the file and returns the first entry; * each successive call returns the next entry, or +nil+ if the end of the file @@ -671,7 +693,9 @@ UINT rb_w32_system_tmpdir(WCHAR *path, UINT len); VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc); #endif -/* +/* call-seq: + * sysconfdir -> String + * * Returns system configuration directory. * * This is typically <code>"/etc"</code>, but is modified by the prefix used @@ -691,7 +715,9 @@ etc_sysconfdir(VALUE obj) #endif } -/* +/* call-seq: + * systmpdir -> String + * * Returns system temporary directory; typically "/tmp". */ static VALUE @@ -735,13 +761,15 @@ etc_systmpdir(VALUE _) } #ifdef HAVE_UNAME -/* +/* call-seq: + * uname -> hash + * * Returns the system information obtained by uname system call. * * The return value is a hash which has 5 keys at least: * :sysname, :nodename, :release, :version, :machine * - * Example: + * *Example:* * * require 'etc' * require 'pp' @@ -851,7 +879,9 @@ etc_uname(VALUE obj) #endif #ifdef HAVE_SYSCONF -/* +/* call-seq: + * sysconf(name) -> Integer + * * Returns system configuration variable using sysconf(). * * _name_ should be a constant under <code>Etc</code> which begins with <code>SC_</code>. @@ -885,7 +915,9 @@ etc_sysconf(VALUE obj, VALUE arg) #endif #ifdef HAVE_CONFSTR -/* +/* call-seq: + * confstr(name) -> String + * * Returns system configuration variable using confstr(). * * _name_ should be a constant under <code>Etc</code> which begins with <code>CS_</code>. @@ -932,7 +964,9 @@ etc_confstr(VALUE obj, VALUE arg) #endif #ifdef HAVE_FPATHCONF -/* +/* call-seq: + * pathconf(name) -> Integer + * * Returns pathname configuration variable using fpathconf(). * * _name_ should be a constant under <code>Etc</code> which begins with <code>PC_</code>. @@ -1024,7 +1058,9 @@ etc_nprocessors_affin(void) } #endif -/* +/* call-seq: + * nprocessors -> Integer + * * Returns the number of online processors. * * The result is intended as the number of processes to @@ -1034,7 +1070,7 @@ etc_nprocessors_affin(void) * - sched_getaffinity(): Linux * - sysconf(_SC_NPROCESSORS_ONLN): GNU/Linux, NetBSD, FreeBSD, OpenBSD, DragonFly BSD, OpenIndiana, Mac OS X, AIX * - * Example: + * *Example:* * * require 'etc' * p Etc.nprocessors #=> 4 @@ -1043,7 +1079,7 @@ etc_nprocessors_affin(void) * process is bound to specific cpus. This is intended for getting better * parallel processing. * - * Example: (Linux) + * *Example:* (Linux) * * linux$ taskset 0x3 ./ruby -retc -e "p Etc.nprocessors" #=> 2 * @@ -1093,7 +1129,7 @@ etc_nprocessors(VALUE obj) * The Etc module provides a more reliable way to access information about * the logged in user than environment variables such as +$USER+. * - * == Example: + * *Example:* * * require 'etc' * @@ -1117,6 +1153,7 @@ Init_etc(void) RB_EXT_RACTOR_SAFE(true); #endif mEtc = rb_define_module("Etc"); + /* The version */ rb_define_const(mEtc, "VERSION", rb_str_new_cstr(RUBY_ETC_VERSION)); init_constants(mEtc); diff --git a/ext/etc/extconf.rb b/ext/etc/extconf.rb index 7c30b38bfd..2e28d58037 100644 --- a/ext/etc/extconf.rb +++ b/ext/etc/extconf.rb @@ -43,8 +43,16 @@ have_struct_member('struct group', 'gr_passwd', 'grp.h') # for https://github.com/ruby/etc srcdir = File.expand_path("..", __FILE__) -if !File.exist?("#{srcdir}/depend") - %x[#{RbConfig.ruby} #{srcdir}/mkconstants.rb -o #{srcdir}/constdefs.h] +constdefs = "#{srcdir}/constdefs.h" +if !File.exist?(constdefs) + ruby = RbConfig.ruby + if File.file?(ruby) + ruby = [ruby] + else + require "shellwords" + ruby = Shellwords.split(ruby) + end + system(*ruby, "#{srcdir}/mkconstants.rb", "-o", constdefs) end # TODO: remove when dropping 2.7 support, as exported since 3.0 diff --git a/ext/etc/mkconstants.rb b/ext/etc/mkconstants.rb index a752d64519..a766560a8a 100644 --- a/ext/etc/mkconstants.rb +++ b/ext/etc/mkconstants.rb @@ -35,6 +35,12 @@ opt.def_option('-H FILE', 'specify output header file') {|filename| opt.parse! +CONST_PREFIXES = { + 'SC' => 'for Etc.sysconf; See <tt>man sysconf</tt>', + 'CS' => 'for Etc.confstr; See <tt>man constr</tt>', + 'PC' => 'for IO#pathconf; See <tt>man fpathconf</tt>', +} + h = {} COMMENTS = {} @@ -49,6 +55,13 @@ DATA.each_line {|s| next end h[name] = default_value + if additional = CONST_PREFIXES[name[/\A_([A-Z]+)_/, 1]] + if comment&.match(/\w\z/) + comment << " " << additional + else + (comment ||= String.new) << " " << additional.sub(/\A\w/) {$&.upcase} + end + end COMMENTS[name] = comment if comment } DEFS = h.to_a @@ -66,15 +79,11 @@ def each_name(pat) } end -erb_new = lambda do |src, safe, trim| - if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+ - ERB.new(src, trim_mode: trim) - else - ERB.new(src, safe, trim) - end +erb_new = lambda do |src, trim| + ERB.new(src, trim_mode: trim) end -erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_const_decls") +erb_new.call(<<'EOS', '%').def_method(Object, "gen_const_decls") % each_const {|name, default_value| #if !defined(<%=name%>) # if defined(HAVE_CONST_<%=name.upcase%>) @@ -88,7 +97,7 @@ erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_const_decls") % } EOS -erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_const_defs") +erb_new.call(<<'EOS', '%').def_method(Object, "gen_const_defs") % each_const {|name, default_value| #if defined(<%=name%>) % if comment = COMMENTS[name] @@ -99,13 +108,13 @@ erb_new.call(<<'EOS', nil, '%').def_method(Object, "gen_const_defs") % } EOS -header_result = erb_new.call(<<'EOS', nil, '%').result(binding) +header_result = erb_new.call(<<'EOS', '%').result(binding) /* autogenerated file */ <%= gen_const_decls %> EOS -result = erb_new.call(<<'EOS', nil, '%').result(binding) +result = erb_new.call(<<'EOS', '%').result(binding) /* autogenerated file */ #ifdef HAVE_LONG_LONG @@ -123,6 +132,9 @@ result = erb_new.call(<<'EOS', nil, '%').result(binding) static void init_constants(VALUE mod) { +#if 0 + mod = rb_define_module("Etc"); +#endif <%= gen_const_defs %> } EOS |