mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
struct.c: rb_struct_define_under
* struct.c (rb_struct_define_under): new function to define Struct under the given namespace, not under Struct. [Feature #8264] * ext/etc/etc.c: use rb_struct_define_under. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ccd5c3ddfc
commit
042e5013a3
4 changed files with 49 additions and 20 deletions
|
@ -1,3 +1,10 @@
|
|||
Sat Aug 3 09:30:57 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* struct.c (rb_struct_define_under): new function to define Struct
|
||||
under the given namespace, not under Struct. [Feature #8264]
|
||||
|
||||
* ext/etc/etc.c: use rb_struct_define_under.
|
||||
|
||||
Sat Aug 3 06:55:29 2013 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* parse.y (value_expr_gen): now NODE_DEFN and NODE_DEFS are not void
|
||||
|
|
|
@ -672,37 +672,38 @@ Init_etc(void)
|
|||
rb_define_module_function(mEtc, "sysconfdir", etc_sysconfdir, 0);
|
||||
rb_define_module_function(mEtc, "systmpdir", etc_systmpdir, 0);
|
||||
|
||||
sPasswd = rb_struct_define(NULL,
|
||||
"name",
|
||||
sPasswd = rb_struct_define_under(mEtc, "Passwd",
|
||||
"name",
|
||||
#ifdef HAVE_STRUCT_PASSWD_PW_PASSWD
|
||||
"passwd",
|
||||
"passwd",
|
||||
#endif
|
||||
"uid",
|
||||
"gid",
|
||||
"uid",
|
||||
"gid",
|
||||
#ifdef HAVE_STRUCT_PASSWD_PW_GECOS
|
||||
"gecos",
|
||||
"gecos",
|
||||
#endif
|
||||
"dir",
|
||||
"shell",
|
||||
"dir",
|
||||
"shell",
|
||||
#ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
|
||||
"change",
|
||||
"change",
|
||||
#endif
|
||||
#ifdef HAVE_STRUCT_PASSWD_PW_QUOTA
|
||||
"quota",
|
||||
"quota",
|
||||
#endif
|
||||
#ifdef HAVE_STRUCT_PASSWD_PW_AGE
|
||||
"age",
|
||||
"age",
|
||||
#endif
|
||||
#ifdef HAVE_STRUCT_PASSWD_PW_CLASS
|
||||
"uclass",
|
||||
"uclass",
|
||||
#endif
|
||||
#ifdef HAVE_STRUCT_PASSWD_PW_COMMENT
|
||||
"comment",
|
||||
"comment",
|
||||
#endif
|
||||
#ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
|
||||
"expire",
|
||||
"expire",
|
||||
#endif
|
||||
NULL);
|
||||
NULL);
|
||||
#if 0
|
||||
/* Define-const: Passwd
|
||||
*
|
||||
* Passwd is a Struct that contains the following members:
|
||||
|
@ -743,18 +744,19 @@ Init_etc(void)
|
|||
* account expiration time(integer) must be compiled with +HAVE_STRUCT_PASSWD_PW_EXPIRE+
|
||||
*/
|
||||
rb_define_const(mEtc, "Passwd", sPasswd);
|
||||
rb_set_class_path(sPasswd, mEtc, "Passwd");
|
||||
#endif
|
||||
rb_define_const(rb_cStruct, "Passwd", sPasswd); /* deprecated name */
|
||||
rb_extend_object(sPasswd, rb_mEnumerable);
|
||||
rb_define_singleton_method(sPasswd, "each", etc_each_passwd, 0);
|
||||
|
||||
#ifdef HAVE_GETGRENT
|
||||
sGroup = rb_struct_define(NULL, "name",
|
||||
sGroup = rb_struct_define_under(mEtc, "Group", "name",
|
||||
#ifdef HAVE_STRUCT_GROUP_GR_PASSWD
|
||||
"passwd",
|
||||
"passwd",
|
||||
#endif
|
||||
"gid", "mem", NULL);
|
||||
"gid", "mem", NULL);
|
||||
|
||||
#if 0
|
||||
/* Define-const: Group
|
||||
*
|
||||
* Group is a Struct that is only available when compiled with +HAVE_GETGRENT+.
|
||||
|
@ -777,7 +779,7 @@ Init_etc(void)
|
|||
* members of the group.
|
||||
*/
|
||||
rb_define_const(mEtc, "Group", sGroup);
|
||||
rb_set_class_path(sGroup, mEtc, "Group");
|
||||
#endif
|
||||
rb_define_const(rb_cStruct, "Group", sGroup); /* deprecated name */
|
||||
rb_extend_object(sGroup, rb_mEnumerable);
|
||||
rb_define_singleton_method(sGroup, "each", etc_each_group, 0);
|
||||
|
|
|
@ -837,6 +837,7 @@ VALUE rb_str_ellipsize(VALUE, long);
|
|||
/* struct.c */
|
||||
VALUE rb_struct_new(VALUE, ...);
|
||||
VALUE rb_struct_define(const char*, ...);
|
||||
VALUE rb_struct_define_under(VALUE, const char*, ...);
|
||||
VALUE rb_struct_alloc(VALUE, VALUE);
|
||||
VALUE rb_struct_initialize(VALUE, VALUE);
|
||||
VALUE rb_struct_aref(VALUE, VALUE);
|
||||
|
|
19
struct.c
19
struct.c
|
@ -283,6 +283,25 @@ rb_struct_define(const char *name, ...)
|
|||
return setup_struct(st, ary);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_struct_define_under(VALUE outer, const char *name, ...)
|
||||
{
|
||||
va_list ar;
|
||||
VALUE ary;
|
||||
char *mem;
|
||||
|
||||
ary = rb_ary_tmp_new(0);
|
||||
|
||||
va_start(ar, name);
|
||||
while ((mem = va_arg(ar, char*)) != 0) {
|
||||
ID slot = rb_intern(mem);
|
||||
rb_ary_push(ary, ID2SYM(slot));
|
||||
}
|
||||
va_end(ar);
|
||||
|
||||
return setup_struct(rb_define_class_under(outer, name, rb_cStruct), ary);
|
||||
}
|
||||
|
||||
/*
|
||||
* call-seq:
|
||||
* Struct.new([class_name] [, member_name]+>) -> StructClass
|
||||
|
|
Loading…
Reference in a new issue