mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* struct.c (rb_struct_define_without_accessor): new function.
* range.c (range_alloc): removed. (Init_Range): use rb_struct_define_without_accessor. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d73f08d56d
commit
0dbdad7599
4 changed files with 45 additions and 24 deletions
|
@ -1,3 +1,10 @@
|
|||
Fri Nov 23 13:34:08 2007 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* struct.c (rb_struct_define_without_accessor): new function.
|
||||
|
||||
* range.c (range_alloc): removed.
|
||||
(Init_Range): use rb_struct_define_without_accessor.
|
||||
|
||||
Fri Nov 23 11:01:54 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* re.c (match_begin): should return offset by character.
|
||||
|
|
|
@ -542,6 +542,7 @@ VALUE rb_struct_getmember(VALUE, ID);
|
|||
VALUE rb_struct_iv_get(VALUE, const char*);
|
||||
VALUE rb_struct_s_members(VALUE);
|
||||
VALUE rb_struct_members(VALUE);
|
||||
VALUE rb_struct_define_without_accessor(char *, VALUE, ...);
|
||||
/* thread.c */
|
||||
typedef void rb_unblock_function_t(void *);
|
||||
typedef VALUE rb_blocking_function_t(void *);
|
||||
|
|
26
range.c
26
range.c
|
@ -22,22 +22,6 @@ static ID id_cmp, id_succ, id_beg, id_end, id_excl;
|
|||
#define EXCL(r) RTEST(RANGE_EXCL(r))
|
||||
#define SET_EXCL(r,v) (RSTRUCT(r)->as.ary[2] = (v) ? Qtrue : Qfalse)
|
||||
|
||||
static VALUE
|
||||
range_alloc(VALUE klass)
|
||||
{
|
||||
long n;
|
||||
NEWOBJ(r, struct RStruct);
|
||||
OBJSETUP(r, klass, T_STRUCT);
|
||||
|
||||
n = 3;
|
||||
|
||||
RBASIC(r)->flags &= ~RSTRUCT_EMBED_LEN_MASK;
|
||||
RBASIC(r)->flags |= n << RSTRUCT_EMBED_LEN_SHIFT;
|
||||
rb_mem_clear(r->as.ary, n);
|
||||
|
||||
return (VALUE)r;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
range_failed(void)
|
||||
{
|
||||
|
@ -895,15 +879,9 @@ Init_Range(void)
|
|||
id_end = rb_intern("end");
|
||||
id_excl = rb_intern("excl");
|
||||
|
||||
rb_cRange = rb_define_class("Range", rb_cObject);
|
||||
rb_cRange = rb_struct_define_without_accessor("Range", rb_cObject,
|
||||
"begin", "end", "excl", NULL);
|
||||
|
||||
/* compatibility for rb_struct_members, etc. */
|
||||
members = rb_ary_new3(3, ID2SYM(id_beg), ID2SYM(id_end), ID2SYM(id_excl));
|
||||
OBJ_FREEZE(members);
|
||||
rb_iv_set(rb_cRange, "__size__", INT2FIX(3));
|
||||
rb_iv_set(rb_cRange, "__members__", members);
|
||||
|
||||
rb_define_alloc_func(rb_cRange, range_alloc);
|
||||
rb_include_module(rb_cRange, rb_mEnumerable);
|
||||
rb_marshal_define_compat(rb_cRange, rb_cObject, range_dumper, range_loader);
|
||||
rb_define_method(rb_cRange, "initialize", range_initialize, -1);
|
||||
|
|
35
struct.c
35
struct.c
|
@ -217,6 +217,41 @@ make_struct(VALUE name, VALUE members, VALUE klass)
|
|||
return nstr;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_struct_define_without_accessor(char *class_name, VALUE super, ...)
|
||||
{
|
||||
VALUE klass;
|
||||
va_list ar;
|
||||
VALUE members;
|
||||
long i;
|
||||
char *name;
|
||||
|
||||
members = rb_ary_new2(0);
|
||||
va_start(ar, super);
|
||||
i = 0;
|
||||
while ((name = va_arg(ar, char*)) != NULL) {
|
||||
rb_ary_push(members, ID2SYM(rb_intern(name)));
|
||||
}
|
||||
va_end(ar);
|
||||
OBJ_FREEZE(members);
|
||||
|
||||
if (class_name) {
|
||||
klass = rb_define_class(class_name, super);
|
||||
}
|
||||
else {
|
||||
klass = rb_class_new(super);
|
||||
rb_make_metaclass(klass, RBASIC(super)->klass);
|
||||
rb_class_inherited(super, klass);
|
||||
}
|
||||
|
||||
rb_iv_set(klass, "__size__", LONG2NUM(RARRAY_LEN(members)));
|
||||
rb_iv_set(klass, "__members__", members);
|
||||
|
||||
rb_define_alloc_func(klass, struct_alloc);
|
||||
|
||||
return klass;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_struct_define(const char *name, ...)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue