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
678 678
    rb_define_module_function(mEtc, "sysconfdir", etc_sysconfdir, 0);
679 679
    rb_define_module_function(mEtc, "systmpdir", etc_systmpdir, 0);
680 680

  
681
    sPasswd =  rb_struct_define(NULL,
682
				"name", "passwd", "uid", "gid",
681
    sPasswd =  rb_struct_define_under(mEtc, "Passwd",
682
				      "name", "passwd", "uid", "gid",
683 683
#ifdef HAVE_ST_PW_GECOS
684
				"gecos",
684
				      "gecos",
685 685
#endif
686
				"dir", "shell",
686
				      "dir", "shell",
687 687
#ifdef HAVE_ST_PW_CHANGE
688
				"change",
688
				      "change",
689 689
#endif
690 690
#ifdef HAVE_ST_PW_QUOTA
691
				"quota",
691
				      "quota",
692 692
#endif
693 693
#ifdef HAVE_ST_PW_AGE
694
				"age",
694
				      "age",
695 695
#endif
696 696
#ifdef HAVE_ST_PW_CLASS
697
				"uclass",
697
				      "uclass",
698 698
#endif
699 699
#ifdef HAVE_ST_PW_COMMENT
700
				"comment",
700
				      "comment",
701 701
#endif
702 702
#ifdef HAVE_ST_PW_EXPIRE
703
				"expire",
703
				      "expire",
704 704
#endif
705
				NULL);
705
				      NULL);
706 706
    /* Define-const: Passwd
707 707
     *
708 708
     * Passwd is a Struct that contains the following members:
......
742 742
     * expire::
743 743
     *	    account expiration time(integer) must be compiled with +HAVE_ST_PW_EXPIRE+
744 744
     */
745
    rb_define_const(mEtc, "Passwd", sPasswd);
746
    rb_set_class_path(sPasswd, mEtc, "Passwd");
747 745
    rb_define_const(rb_cStruct, "Passwd", sPasswd); /* deprecated name */
748 746
    rb_extend_object(sPasswd, rb_mEnumerable);
749 747
    rb_define_singleton_method(sPasswd, "each", etc_each_passwd, 0);
750 748

  
751 749
#ifdef HAVE_GETGRENT
752
    sGroup = rb_struct_define(NULL, "name",
750
    sGroup = rb_struct_define_under(mEtc, "Group", "name",
753 751
#ifdef HAVE_ST_GR_PASSWD
754
			      "passwd",
752
				    "passwd",
755 753
#endif
756
			      "gid", "mem", NULL);
754
				    "gid", "mem", NULL);
757 755

  
758 756
    /* Define-const: Group
759 757
     *
......
776 774
     *	    is an Array of Strings containing the short login names of the
777 775
     *	    members of the group.
778 776
     */
779
    rb_define_const(mEtc, "Group", sGroup);
780
    rb_set_class_path(sGroup, mEtc, "Group");
781 777
    rb_define_const(rb_cStruct, "Group", sGroup); /* deprecated name */
782 778
    rb_extend_object(sGroup, rb_mEnumerable);
783 779
    rb_define_singleton_method(sGroup, "each", etc_each_group, 0);
include/ruby/intern.h
812 812
/* struct.c */
813 813
VALUE rb_struct_new(VALUE, ...);
814 814
VALUE rb_struct_define(const char*, ...);
815
VALUE rb_struct_define_under(VALUE, const char*, ...);
815 816
VALUE rb_struct_alloc(VALUE, VALUE);
816 817
VALUE rb_struct_initialize(VALUE, VALUE);
817 818
VALUE rb_struct_aref(VALUE, VALUE);
struct.c
289 289
    return setup_struct(st, ary);
290 290
}
291 291

  
292
VALUE
293
rb_struct_define_under(VALUE outer, const char *name, ...)
294
{
295
    va_list ar;
296
    VALUE ary;
297
    char *mem;
298

  
299
    ary = rb_ary_tmp_new(0);
300

  
301
    va_start(ar, name);
302
    while ((mem = va_arg(ar, char*)) != 0) {
303
	ID slot = rb_intern(mem);
304
	rb_ary_push(ary, ID2SYM(slot));
305
    }
306
    va_end(ar);
307

  
308
    return setup_struct(rb_define_class_under(outer, name, rb_cStruct), ary);
309
}
310

  
292 311
/*
293 312
 *  call-seq:
294 313
 *     Struct.new( [aString] [, aSym]+> )                         -> StructClass
295
-