Project

General

Profile

Feature #8264 ยป 0001-struct.c-rb_struct_define_under.patch

nobu (Nobuyoshi Nakada), 04/13/2013 11:39 AM

View differences:

ext/etc/etc.c
rb_define_module_function(mEtc, "sysconfdir", etc_sysconfdir, 0);
rb_define_module_function(mEtc, "systmpdir", etc_systmpdir, 0);
sPasswd = rb_struct_define(NULL,
"name", "passwd", "uid", "gid",
sPasswd = rb_struct_define_under(mEtc, "Passwd",
"name", "passwd", "uid", "gid",
#ifdef HAVE_ST_PW_GECOS
"gecos",
"gecos",
#endif
"dir", "shell",
"dir", "shell",
#ifdef HAVE_ST_PW_CHANGE
"change",
"change",
#endif
#ifdef HAVE_ST_PW_QUOTA
"quota",
"quota",
#endif
#ifdef HAVE_ST_PW_AGE
"age",
"age",
#endif
#ifdef HAVE_ST_PW_CLASS
"uclass",
"uclass",
#endif
#ifdef HAVE_ST_PW_COMMENT
"comment",
"comment",
#endif
#ifdef HAVE_ST_PW_EXPIRE
"expire",
"expire",
#endif
NULL);
NULL);
/* Define-const: Passwd
*
* Passwd is a Struct that contains the following members:
......
* expire::
* account expiration time(integer) must be compiled with +HAVE_ST_PW_EXPIRE+
*/
rb_define_const(mEtc, "Passwd", sPasswd);
rb_set_class_path(sPasswd, mEtc, "Passwd");
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_ST_GR_PASSWD
"passwd",
"passwd",
#endif
"gid", "mem", NULL);
"gid", "mem", NULL);
/* Define-const: Group
*
......
* is an Array of Strings containing the short login names of the
* members of the group.
*/
rb_define_const(mEtc, "Group", sGroup);
rb_set_class_path(sGroup, mEtc, "Group");
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);
include/ruby/intern.h
/* 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);
struct.c
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( [aString] [, aSym]+> ) -> StructClass
    (1-1/1)