2000-05-01 13:42:38 +04:00
|
|
|
/**********************************************************************
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
class.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
$Date$
|
|
|
|
created at: Tue Aug 10 15:05:44 JST 1993
|
|
|
|
|
* encoding.c: provide basic features for M17N.
* parse.y: encoding aware parsing.
* parse.y (pragma_encoding): encoding specification pragma.
* parse.y (rb_intern3): encoding specified symbols.
* string.c (rb_str_length): length based on characters.
for older behavior, bytesize method added.
* string.c (rb_str_index_m): index based on characters. rindex as
well.
* string.c (succ_char): encoding aware succeeding string.
* string.c (rb_str_reverse): reverse based on characters.
* string.c (rb_str_inspect): encoding aware string description.
* string.c (rb_str_upcase_bang): encoding aware case conversion.
downcase, capitalize, swapcase as well.
* string.c (rb_str_tr_bang): tr based on characters. delete,
squeeze, tr_s, count as well.
* string.c (rb_str_split_m): split based on characters.
* string.c (rb_str_each_line): encoding aware each_line.
* string.c (rb_str_each_char): added. iteration based on
characters.
* string.c (rb_str_strip_bang): encoding aware whitespace
stripping. lstrip, rstrip as well.
* string.c (rb_str_justify): encoding aware justifying (ljust,
rjust, center).
* string.c (str_encoding): get encoding attribute from a string.
* re.c (rb_reg_initialize): encoding aware regular expression
* sprintf.c (rb_str_format): formatting (i.e. length count) based
on characters.
* io.c (rb_io_getc): getc to return one-character string.
for older behavior, getbyte method added.
* ext/stringio/stringio.c (strio_getc): ditto.
* io.c (rb_io_ungetc): allow pushing arbitrary string at the
current reading point.
* ext/stringio/stringio.c (strio_ungetc): ditto.
* ext/strscan/strscan.c: encoding support.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-08-25 07:29:39 +04:00
|
|
|
Copyright (C) 1993-2007 Yukihiro Matsumoto
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-05-01 13:42:38 +04:00
|
|
|
**********************************************************************/
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-06-10 07:06:15 +04:00
|
|
|
#include "ruby/ruby.h"
|
|
|
|
#include "ruby/signal.h"
|
|
|
|
#include "ruby/node.h"
|
|
|
|
#include "ruby/st.h"
|
1999-01-20 07:59:39 +03:00
|
|
|
#include <ctype.h>
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
extern st_table *rb_class_tbl;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-09-28 10:21:46 +04:00
|
|
|
static VALUE
|
|
|
|
class_alloc(VALUE flags, VALUE klass)
|
|
|
|
{
|
|
|
|
rb_classext_t *ext = ALLOC(rb_classext_t);
|
|
|
|
NEWOBJ(obj, struct RClass);
|
|
|
|
OBJSETUP(obj, klass, flags);
|
|
|
|
obj->ptr = ext;
|
|
|
|
RCLASS_IV_TBL(obj) = 0;
|
|
|
|
RCLASS_M_TBL(obj) = 0;
|
|
|
|
RCLASS_SUPER(obj) = 0;
|
|
|
|
RCLASS_IV_INDEX_TBL(obj) = 0;
|
|
|
|
return (VALUE)obj;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_class_boot(VALUE super)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2007-09-28 10:21:46 +04:00
|
|
|
VALUE klass = class_alloc(T_CLASS, rb_cClass);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-09-28 10:21:46 +04:00
|
|
|
RCLASS_SUPER(klass) = super;
|
|
|
|
RCLASS_M_TBL(klass) = st_init_numtable();
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-08-14 12:13:31 +04:00
|
|
|
OBJ_INFECT(klass, super);
|
1998-01-16 15:19:22 +03:00
|
|
|
return (VALUE)klass;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2004-11-16 07:55:14 +03:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_check_inheritable(VALUE super)
|
2004-11-16 07:55:14 +03:00
|
|
|
{
|
|
|
|
if (TYPE(super) != T_CLASS) {
|
|
|
|
rb_raise(rb_eTypeError, "superclass must be a Class (%s given)",
|
|
|
|
rb_obj_classname(super));
|
|
|
|
}
|
|
|
|
if (RBASIC(super)->flags & FL_SINGLETON) {
|
|
|
|
rb_raise(rb_eTypeError, "can't make subclass of singleton class");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-07-18 09:56:05 +04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_class_new(VALUE super)
|
2001-07-18 09:56:05 +04:00
|
|
|
{
|
|
|
|
Check_Type(super, T_CLASS);
|
2004-11-16 07:55:14 +03:00
|
|
|
rb_check_inheritable(super);
|
2001-07-18 09:56:05 +04:00
|
|
|
if (super == rb_cClass) {
|
|
|
|
rb_raise(rb_eTypeError, "can't make subclass of Class");
|
|
|
|
}
|
|
|
|
return rb_class_boot(super);
|
|
|
|
}
|
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
struct clone_method_data {
|
|
|
|
st_table *tbl;
|
|
|
|
VALUE klass;
|
|
|
|
};
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
static int
|
2006-12-31 18:02:22 +03:00
|
|
|
clone_method(ID mid, NODE *body, struct clone_method_data *data)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2006-12-31 18:02:22 +03:00
|
|
|
if (body == 0) {
|
|
|
|
st_insert(data->tbl, mid, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
st_insert(data->tbl, mid,
|
|
|
|
(st_data_t)
|
|
|
|
NEW_FBODY(
|
|
|
|
NEW_METHOD(body->nd_body->nd_body,
|
|
|
|
data->klass, /* TODO */
|
|
|
|
body->nd_body->nd_noex),
|
|
|
|
0));
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2004-01-18 17:16:47 +03:00
|
|
|
/* :nodoc: */
|
2001-05-02 08:22:21 +04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_init_copy(VALUE clone, VALUE orig)
|
2001-05-02 08:22:21 +04:00
|
|
|
{
|
2003-08-07 01:50:06 +04:00
|
|
|
rb_obj_init_copy(clone, orig);
|
2003-12-22 15:15:34 +03:00
|
|
|
if (!FL_TEST(CLASS_OF(clone), FL_SINGLETON)) {
|
|
|
|
RBASIC(clone)->klass = rb_singleton_class_clone(orig);
|
|
|
|
}
|
2007-09-28 10:21:46 +04:00
|
|
|
RCLASS_SUPER(clone) = RCLASS_SUPER(orig);
|
|
|
|
if (RCLASS_IV_TBL(orig)) {
|
2001-10-22 10:48:18 +04:00
|
|
|
ID id;
|
|
|
|
|
2007-09-28 10:21:46 +04:00
|
|
|
RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(orig));
|
2001-10-22 10:48:18 +04:00
|
|
|
id = rb_intern("__classpath__");
|
2007-09-28 10:21:46 +04:00
|
|
|
st_delete(RCLASS_IV_TBL(clone), (st_data_t*)&id, 0);
|
2001-10-22 10:48:18 +04:00
|
|
|
id = rb_intern("__classid__");
|
2007-09-28 10:21:46 +04:00
|
|
|
st_delete(RCLASS_IV_TBL(clone), (st_data_t*)&id, 0);
|
2001-05-02 08:22:21 +04:00
|
|
|
}
|
2007-09-28 10:21:46 +04:00
|
|
|
if (RCLASS_M_TBL(orig)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
struct clone_method_data data;
|
2007-09-28 10:21:46 +04:00
|
|
|
data.tbl = RCLASS_M_TBL(clone) = st_init_numtable();
|
2006-12-31 18:02:22 +03:00
|
|
|
data.klass = clone;
|
2007-09-28 10:21:46 +04:00
|
|
|
st_foreach(RCLASS_M_TBL(orig), clone_method,
|
2006-12-31 18:02:22 +03:00
|
|
|
(st_data_t)&data);
|
2001-05-02 08:22:21 +04:00
|
|
|
}
|
|
|
|
|
2003-08-07 01:50:06 +04:00
|
|
|
return clone;
|
2001-05-02 08:22:21 +04:00
|
|
|
}
|
|
|
|
|
2004-01-18 17:16:47 +03:00
|
|
|
/* :nodoc: */
|
2001-05-02 08:22:21 +04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_class_init_copy(VALUE clone, VALUE orig)
|
2001-05-02 08:22:21 +04:00
|
|
|
{
|
2007-09-28 10:21:46 +04:00
|
|
|
if (RCLASS_SUPER(clone) != 0) {
|
2003-08-07 01:50:06 +04:00
|
|
|
rb_raise(rb_eTypeError, "already initialized class");
|
|
|
|
}
|
2005-05-16 17:28:59 +04:00
|
|
|
if (FL_TEST(orig, FL_SINGLETON)) {
|
|
|
|
rb_raise(rb_eTypeError, "can't copy singleton class");
|
|
|
|
}
|
2003-08-07 01:50:06 +04:00
|
|
|
return rb_mod_init_copy(clone, orig);
|
2001-05-02 08:22:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_singleton_class_clone(VALUE obj)
|
2001-05-02 08:22:21 +04:00
|
|
|
{
|
2002-09-03 09:20:14 +04:00
|
|
|
VALUE klass = RBASIC(obj)->klass;
|
2001-05-02 08:22:21 +04:00
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
if (!FL_TEST(klass, FL_SINGLETON))
|
|
|
|
return klass;
|
1998-01-16 15:13:05 +03:00
|
|
|
else {
|
2006-12-31 18:02:22 +03:00
|
|
|
struct clone_method_data data;
|
1998-01-16 15:13:05 +03:00
|
|
|
/* copy singleton(unnamed) class */
|
2007-09-28 10:21:46 +04:00
|
|
|
VALUE clone = class_alloc(RBASIC(klass)->flags, 0);
|
2002-09-03 09:20:14 +04:00
|
|
|
|
|
|
|
if (BUILTIN_TYPE(obj) == T_CLASS) {
|
|
|
|
RBASIC(clone)->klass = (VALUE)clone;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
RBASIC(clone)->klass = rb_singleton_class_clone(klass);
|
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-09-28 10:21:46 +04:00
|
|
|
RCLASS_SUPER(clone) = RCLASS_SUPER(klass);
|
|
|
|
if (RCLASS_IV_TBL(klass)) {
|
|
|
|
RCLASS_IV_TBL(clone) = st_copy(RCLASS_IV_TBL(klass));
|
2001-03-28 12:43:25 +04:00
|
|
|
}
|
2007-09-28 10:21:46 +04:00
|
|
|
RCLASS_M_TBL(clone) = st_init_numtable();
|
|
|
|
data.tbl = RCLASS_M_TBL(clone);
|
2006-12-31 18:02:22 +03:00
|
|
|
data.klass = (VALUE)clone;
|
2007-09-28 10:21:46 +04:00
|
|
|
st_foreach(RCLASS_M_TBL(klass), clone_method,
|
2006-12-31 18:02:22 +03:00
|
|
|
(st_data_t)&data);
|
2002-09-03 09:20:14 +04:00
|
|
|
rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
|
1998-01-16 15:13:05 +03:00
|
|
|
FL_SET(clone, FL_SINGLETON);
|
|
|
|
return (VALUE)clone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_singleton_class_attached(VALUE klass, VALUE obj)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2001-05-02 08:22:21 +04:00
|
|
|
if (FL_TEST(klass, FL_SINGLETON)) {
|
2007-09-28 10:21:46 +04:00
|
|
|
if (!RCLASS_IV_TBL(klass)) {
|
|
|
|
RCLASS_IV_TBL(klass) = st_init_numtable();
|
2001-05-02 08:22:21 +04:00
|
|
|
}
|
2007-09-28 10:21:46 +04:00
|
|
|
st_insert(RCLASS_IV_TBL(klass), rb_intern("__attached__"), obj);
|
2001-05-02 08:22:21 +04:00
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2002-01-10 23:18:39 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_make_metaclass(VALUE obj, VALUE super)
|
2002-01-10 23:18:39 +03:00
|
|
|
{
|
2002-09-25 11:03:05 +04:00
|
|
|
if (BUILTIN_TYPE(obj) == T_CLASS && FL_TEST(obj, FL_SINGLETON)) {
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
return RBASIC(obj)->klass = rb_cClass;
|
2002-09-25 11:03:05 +04:00
|
|
|
}
|
|
|
|
else {
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
VALUE metasuper;
|
|
|
|
VALUE klass = rb_class_boot(super);
|
2002-09-28 06:41:05 +04:00
|
|
|
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
FL_SET(klass, FL_SINGLETON);
|
|
|
|
RBASIC(obj)->klass = klass;
|
|
|
|
rb_singleton_class_attached(klass, obj);
|
|
|
|
|
|
|
|
metasuper = RBASIC(rb_class_real(super))->klass;
|
2002-09-28 06:41:05 +04:00
|
|
|
/* metaclass of a superclass may be NULL at boot time */
|
|
|
|
if (metasuper) {
|
2002-10-01 12:14:03 +04:00
|
|
|
RBASIC(klass)->klass = metasuper;
|
2002-09-28 06:41:05 +04:00
|
|
|
}
|
* array.c: replace rb_protect_inspect() and rb_inspecting_p() by
rb_exec_recursive() in eval.c.
* eval.c (rb_exec_recursive): new function.
* array.c (rb_ary_join): use rb_exec_recursive().
* array.c (rb_ary_inspect, rb_ary_hash): ditto.
* file.c (rb_file_join): ditto.
* hash.c (rb_hash_inspect, rb_hash_to_s, rb_hash_hash): ditto.
* io.c (rb_io_puts): ditto.
* object.c (rb_obj_inspect): ditto
* struct.c (rb_struct_inspect): ditto.
* lib/set.rb (SortedSet::setup): a hack to shut up warning.
[ruby-talk:132866]
* lib/time.rb (Time::strptime): add new function. inspired by
[ruby-talk:132815].
* lib/parsedate.rb (ParseDate::strptime): ditto.
* regparse.c: move st_*_strend() functions from st.c. fixed some
potential memory leaks.
* exception error messages updated. [ruby-core:04497]
* ext/socket/socket.c (Init_socket): add bunch of Socket
constants. Patch from Sam Roberts <sroberts@uniserve.com>.
[ruby-core:04409]
* array.c (rb_ary_s_create): no need for negative argc check.
[ruby-core:04463]
* array.c (rb_ary_unshift_m): ditto.
* lib/xmlrpc/parser.rb (XMLRPC::FaultException): make it subclass
of StandardError class, not Exception class. [ruby-core:04429]
* parse.y (fcall_gen): lvar(arg) will be evaluated as
lvar.call(arg) when lvar is a defined local variable. [new]
* object.c (rb_class_initialize): call inherited method before
calling initializing block.
* eval.c (rb_thread_start_1): initialize newly pushed frame.
* lib/open3.rb (Open3::popen3): $? should not be EXIT_FAILURE.
fixed: [ruby-core:04444]
* eval.c (is_defined): NODE_IASGN is an assignment.
* ext/readline/readline.c (Readline.readline): use rl_outstream
and rl_instream. [ruby-dev:25699]
* ext/etc/etc.c (Init_etc): sGroup needs HAVE_ST_GR_PASSWD check
[ruby-dev:25675]
* misc/ruby-mode.el: [ruby-core:04415]
* lib/rdoc/generators/html_generator.rb: [ruby-core:04412]
* lib/rdoc/generators/ri_generator.rb: ditto.
* struct.c (make_struct): fixed: [ruby-core:04402]
* ext/curses/curses.c (window_color_set): [ruby-core:04393]
* ext/socket/socket.c (Init_socket): SO_REUSEPORT added.
[ruby-talk:130092]
* object.c: [ruby-doc:818]
* parse.y (open_args): fix too verbose warnings for the space
before argument parentheses. [ruby-dev:25492]
* parse.y (parser_yylex): ditto.
* parse.y (parser_yylex): the first expression in the parentheses
should not be a command. [ruby-dev:25492]
* lib/irb/context.rb (IRB::Context::initialize): [ruby-core:04330]
* object.c (Init_Object): remove Object#type. [ruby-core:04335]
* st.c (st_foreach): report success/failure by return value.
[ruby-Bugs-1396]
* parse.y: forgot to initialize parser struct. [ruby-dev:25492]
* parse.y (parser_yylex): no tLABEL on EXPR_BEG.
[ruby-talk:127711]
* document updates - [ruby-core:04296], [ruby-core:04301],
[ruby-core:04302], [ruby-core:04307]
* dir.c (rb_push_glob): should work for NUL delimited patterns.
* dir.c (rb_glob2): should aware of offset in the pattern.
* string.c (rb_str_new4): should propagate taintedness.
* env.h: rename member names in struct FRAME; last_func -> callee,
orig_func -> this_func, last_class -> this_class.
* struct.c (rb_struct_set): use original method name, not callee
name, to retrieve member slot. [ruby-core:04268]
* time.c (time_strftime): protect from format modification from GC
finalizers.
* object.c (Init_Object): remove rb_obj_id_obsolete()
* eval.c (rb_mod_define_method): incomplete subclass check.
[ruby-dev:25464]
* gc.c (rb_data_object_alloc): klass may be NULL.
[ruby-list:40498]
* bignum.c (rb_big_rand): should return positive random number.
[ruby-dev:25401]
* bignum.c (rb_big_rand): do not use rb_big_modulo to generate
random bignums. [ruby-dev:25396]
* variable.c (rb_autoload): [ruby-dev:25373]
* eval.c (svalue_to_avalue): [ruby-dev:25366]
* string.c (rb_str_justify): [ruby-dev:25367]
* io.c (rb_f_select): [ruby-dev:25312]
* ext/socket/socket.c (sock_s_getservbyport): [ruby-talk:124072]
* struct.c (make_struct): [ruby-dev:25249]
* dir.c (dir_open_dir): new function. [ruby-dev:25242]
* io.c (rb_f_open): add type check for return value from to_open.
* lib/pstore.rb (PStore#transaction): Use the empty content when a
file is not found. [ruby-dev:24561]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-03-04 09:47:45 +03:00
|
|
|
return klass;
|
2002-09-03 09:20:14 +04:00
|
|
|
}
|
2002-01-10 23:18:39 +03:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_define_class_id(ID id, VALUE super)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE klass;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (!super) super = rb_cObject;
|
|
|
|
klass = rb_class_new(super);
|
2002-01-10 23:18:39 +03:00
|
|
|
rb_make_metaclass(klass, RBASIC(super)->klass);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
return klass;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2002-01-10 23:18:39 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_class_inherited(VALUE super, VALUE klass)
|
2002-01-10 23:18:39 +03:00
|
|
|
{
|
2002-01-16 05:20:25 +03:00
|
|
|
if (!super) super = rb_cObject;
|
2002-01-10 23:18:39 +03:00
|
|
|
return rb_funcall(super, rb_intern("inherited"), 1, klass);
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_define_class(const char *name, VALUE super)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE klass;
|
1998-01-16 15:13:05 +03:00
|
|
|
ID id;
|
|
|
|
|
|
|
|
id = rb_intern(name);
|
2001-05-02 08:22:21 +04:00
|
|
|
if (rb_const_defined(rb_cObject, id)) {
|
|
|
|
klass = rb_const_get(rb_cObject, id);
|
2001-12-18 11:47:06 +03:00
|
|
|
if (TYPE(klass) != T_CLASS) {
|
|
|
|
rb_raise(rb_eTypeError, "%s is not a class", name);
|
|
|
|
}
|
2007-09-28 10:21:46 +04:00
|
|
|
if (rb_class_real(RCLASS_SUPER(klass)) != super) {
|
2001-12-18 11:47:06 +03:00
|
|
|
rb_name_error(id, "%s is already defined", name);
|
|
|
|
}
|
|
|
|
return klass;
|
2001-05-02 08:22:21 +04:00
|
|
|
}
|
2002-02-17 17:44:14 +03:00
|
|
|
if (!super) {
|
|
|
|
rb_warn("no super class for `%s', Object assumed", name);
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
klass = rb_define_class_id(id, super);
|
|
|
|
st_add_direct(rb_class_tbl, id, klass);
|
2004-01-19 12:19:31 +03:00
|
|
|
rb_name_class(klass, id);
|
2003-07-01 05:36:25 +04:00
|
|
|
rb_const_set(rb_cObject, id, klass);
|
2003-01-07 10:36:40 +03:00
|
|
|
rb_class_inherited(super, klass);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
return klass;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_define_class_under(VALUE outer, const char *name, VALUE super)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE klass;
|
1998-01-16 15:13:05 +03:00
|
|
|
ID id;
|
|
|
|
|
|
|
|
id = rb_intern(name);
|
2001-05-02 08:22:21 +04:00
|
|
|
if (rb_const_defined_at(outer, id)) {
|
2003-06-20 11:11:44 +04:00
|
|
|
klass = rb_const_get_at(outer, id);
|
2001-12-18 11:47:06 +03:00
|
|
|
if (TYPE(klass) != T_CLASS) {
|
|
|
|
rb_raise(rb_eTypeError, "%s is not a class", name);
|
|
|
|
}
|
2007-09-28 10:21:46 +04:00
|
|
|
if (rb_class_real(RCLASS_SUPER(klass)) != super) {
|
2001-12-18 11:47:06 +03:00
|
|
|
rb_name_error(id, "%s is already defined", name);
|
|
|
|
}
|
|
|
|
return klass;
|
2001-05-02 08:22:21 +04:00
|
|
|
}
|
2002-02-17 17:44:14 +03:00
|
|
|
if (!super) {
|
|
|
|
rb_warn("no super class for `%s::%s', Object assumed",
|
|
|
|
rb_class2name(outer), name);
|
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
klass = rb_define_class_id(id, super);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_set_class_path(klass, outer, name);
|
2002-01-10 23:18:39 +03:00
|
|
|
rb_const_set(outer, id, klass);
|
2003-01-07 10:36:40 +03:00
|
|
|
rb_class_inherited(super, klass);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
return klass;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_module_new(void)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2007-09-28 10:21:46 +04:00
|
|
|
VALUE mdl = class_alloc(T_MODULE, rb_cModule);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2007-09-28 10:21:46 +04:00
|
|
|
RCLASS_M_TBL(mdl) = st_init_numtable();
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
return (VALUE)mdl;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_define_module_id(ID id)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE mdl;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
mdl = rb_module_new();
|
1998-01-16 15:13:05 +03:00
|
|
|
rb_name_class(mdl, id);
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
return mdl;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_define_module(const char *name)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE module;
|
|
|
|
ID id;
|
|
|
|
|
|
|
|
id = rb_intern(name);
|
2001-05-02 08:22:21 +04:00
|
|
|
if (rb_const_defined(rb_cObject, id)) {
|
|
|
|
module = rb_const_get(rb_cObject, id);
|
|
|
|
if (TYPE(module) == T_MODULE)
|
|
|
|
return module;
|
2003-01-31 07:00:17 +03:00
|
|
|
rb_raise(rb_eTypeError, "%s is not a module", rb_obj_classname(module));
|
2001-05-02 08:22:21 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
module = rb_define_module_id(id);
|
|
|
|
st_add_direct(rb_class_tbl, id, module);
|
2003-07-01 05:36:25 +04:00
|
|
|
rb_const_set(rb_cObject, id, module);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_define_module_under(VALUE outer, const char *name)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
VALUE module;
|
|
|
|
ID id;
|
|
|
|
|
|
|
|
id = rb_intern(name);
|
2002-01-07 08:27:01 +03:00
|
|
|
if (rb_const_defined_at(outer, id)) {
|
2003-06-20 11:11:44 +04:00
|
|
|
module = rb_const_get_at(outer, id);
|
2001-05-02 08:22:21 +04:00
|
|
|
if (TYPE(module) == T_MODULE)
|
|
|
|
return module;
|
|
|
|
rb_raise(rb_eTypeError, "%s::%s is not a module",
|
2003-01-31 07:00:17 +03:00
|
|
|
rb_class2name(outer), rb_obj_classname(module));
|
2001-05-02 08:22:21 +04:00
|
|
|
}
|
1998-01-16 15:13:05 +03:00
|
|
|
module = rb_define_module_id(id);
|
1999-12-14 09:50:43 +03:00
|
|
|
rb_const_set(outer, id, module);
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_set_class_path(module, outer, name);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
return module;
|
|
|
|
}
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
include_class_new(VALUE module, VALUE super)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2007-09-28 10:21:46 +04:00
|
|
|
VALUE klass = class_alloc(T_ICLASS, rb_cClass);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-07-11 12:22:18 +04:00
|
|
|
if (BUILTIN_TYPE(module) == T_ICLASS) {
|
|
|
|
module = RBASIC(module)->klass;
|
|
|
|
}
|
2007-09-28 10:21:46 +04:00
|
|
|
if (!RCLASS_IV_TBL(module)) {
|
|
|
|
RCLASS_IV_TBL(module) = st_init_numtable();
|
1999-08-13 09:45:20 +04:00
|
|
|
}
|
2007-09-28 10:21:46 +04:00
|
|
|
RCLASS_IV_TBL(klass) = RCLASS_IV_TBL(module);
|
|
|
|
RCLASS_M_TBL(klass) = RCLASS_M_TBL(module);
|
|
|
|
RCLASS_SUPER(klass) = super;
|
1998-01-16 15:13:05 +03:00
|
|
|
if (TYPE(module) == T_ICLASS) {
|
1999-01-20 07:59:39 +03:00
|
|
|
RBASIC(klass)->klass = RBASIC(module)->klass;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-01-20 07:59:39 +03:00
|
|
|
RBASIC(klass)->klass = module;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2001-08-14 12:13:31 +04:00
|
|
|
OBJ_INFECT(klass, module);
|
|
|
|
OBJ_INFECT(klass, super);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
return (VALUE)klass;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_include_module(VALUE klass, VALUE module)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2006-11-07 11:56:18 +03:00
|
|
|
VALUE p, c;
|
2001-03-28 12:43:25 +04:00
|
|
|
int changed = 0;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2001-05-02 08:22:21 +04:00
|
|
|
rb_frozen_class_p(klass);
|
|
|
|
if (!OBJ_TAINTED(klass)) {
|
|
|
|
rb_secure(4);
|
|
|
|
}
|
|
|
|
|
2002-12-19 12:20:20 +03:00
|
|
|
if (TYPE(module) != T_MODULE) {
|
1998-01-16 15:13:05 +03:00
|
|
|
Check_Type(module, T_MODULE);
|
|
|
|
}
|
|
|
|
|
2001-08-14 12:13:31 +04:00
|
|
|
OBJ_INFECT(klass, module);
|
2001-09-08 18:17:53 +04:00
|
|
|
c = klass;
|
1998-01-16 15:13:05 +03:00
|
|
|
while (module) {
|
2006-12-31 18:02:22 +03:00
|
|
|
int superclass_seen = Qfalse;
|
2006-11-07 11:56:18 +03:00
|
|
|
|
2007-09-28 10:21:46 +04:00
|
|
|
if (RCLASS_M_TBL(klass) == RCLASS_M_TBL(module))
|
2002-01-25 11:22:11 +03:00
|
|
|
rb_raise(rb_eArgError, "cyclic include detected");
|
2006-12-31 18:02:22 +03:00
|
|
|
/* ignore if the module included already in superclasses */
|
2007-09-28 10:21:46 +04:00
|
|
|
for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
switch (BUILTIN_TYPE(p)) {
|
|
|
|
case T_ICLASS:
|
2007-09-28 10:21:46 +04:00
|
|
|
if (RCLASS_M_TBL(p) == RCLASS_M_TBL(module)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
if (!superclass_seen) {
|
|
|
|
c = p; /* move insertion point */
|
|
|
|
}
|
|
|
|
goto skip;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case T_CLASS:
|
|
|
|
superclass_seen = Qtrue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-09-28 10:21:46 +04:00
|
|
|
c = RCLASS_SUPER(c) = include_class_new(module, RCLASS_SUPER(c));
|
2001-03-28 12:43:25 +04:00
|
|
|
changed = 1;
|
2006-11-07 11:56:18 +03:00
|
|
|
skip:
|
2007-09-28 10:21:46 +04:00
|
|
|
module = RCLASS_SUPER(module);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
2001-03-28 12:43:25 +04:00
|
|
|
if (changed) rb_clear_cache();
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mod.included_modules -> array
|
|
|
|
*
|
|
|
|
* Returns the list of modules included in <i>mod</i>.
|
|
|
|
*
|
|
|
|
* module Mixin
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* module Outer
|
|
|
|
* include Mixin
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* Mixin.included_modules #=> []
|
|
|
|
* Outer.included_modules #=> [Mixin]
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_included_modules(VALUE mod)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE ary = rb_ary_new();
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE p;
|
|
|
|
|
2007-09-28 10:21:46 +04:00
|
|
|
for (p = RCLASS_SUPER(mod); p; p = RCLASS_SUPER(p)) {
|
1998-01-16 15:19:22 +03:00
|
|
|
if (BUILTIN_TYPE(p) == T_ICLASS) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_ary_push(ary, RBASIC(p)->klass);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mod.include?(module) => true or false
|
|
|
|
*
|
|
|
|
* Returns <code>true</code> if <i>module</i> is included in
|
|
|
|
* <i>mod</i> or one of <i>mod</i>'s ancestors.
|
|
|
|
*
|
|
|
|
* module A
|
|
|
|
* end
|
|
|
|
* class B
|
|
|
|
* include A
|
|
|
|
* end
|
|
|
|
* class C < B
|
|
|
|
* end
|
|
|
|
* B.include?(A) #=> true
|
|
|
|
* C.include?(A) #=> true
|
|
|
|
* A.include?(A) #=> false
|
|
|
|
*/
|
|
|
|
|
2001-07-24 13:07:33 +04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_include_p(VALUE mod, VALUE mod2)
|
2001-07-24 13:07:33 +04:00
|
|
|
{
|
|
|
|
VALUE p;
|
|
|
|
|
|
|
|
Check_Type(mod2, T_MODULE);
|
2007-09-28 10:21:46 +04:00
|
|
|
for (p = RCLASS_SUPER(mod); p; p = RCLASS_SUPER(p)) {
|
2001-07-24 13:07:33 +04:00
|
|
|
if (BUILTIN_TYPE(p) == T_ICLASS) {
|
|
|
|
if (RBASIC(p)->klass == mod2) return Qtrue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
|
|
|
* mod.ancestors -> array
|
|
|
|
*
|
|
|
|
* Returns a list of modules included in <i>mod</i> (including
|
|
|
|
* <i>mod</i> itself).
|
|
|
|
*
|
|
|
|
* module Mod
|
|
|
|
* include Math
|
|
|
|
* include Comparable
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* Mod.ancestors #=> [Mod, Comparable, Math]
|
|
|
|
* Math.ancestors #=> [Math]
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_mod_ancestors(VALUE mod)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2003-08-07 01:50:06 +04:00
|
|
|
VALUE p, ary = rb_ary_new();
|
1998-01-16 15:19:22 +03:00
|
|
|
|
2007-09-28 10:21:46 +04:00
|
|
|
for (p = mod; p; p = RCLASS_SUPER(p)) {
|
1999-01-20 07:59:39 +03:00
|
|
|
if (FL_TEST(p, FL_SINGLETON))
|
|
|
|
continue;
|
1998-01-16 15:19:22 +03:00
|
|
|
if (BUILTIN_TYPE(p) == T_ICLASS) {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_ary_push(ary, RBASIC(p)->klass);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_ary_push(ary, p);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
2003-05-02 12:24:43 +04:00
|
|
|
#define VISI(x) ((x)&NOEX_MASK)
|
|
|
|
#define VISI_CHECK(x,f) (VISI(x) == (f))
|
2002-10-30 11:04:32 +03:00
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
ins_methods_push(ID name, long type, VALUE ary, long visi)
|
2003-05-02 12:24:43 +04:00
|
|
|
{
|
|
|
|
if (type == -1) return ST_CONTINUE;
|
2006-12-31 18:02:22 +03:00
|
|
|
|
2003-05-02 12:24:43 +04:00
|
|
|
switch (visi) {
|
|
|
|
case NOEX_PRIVATE:
|
|
|
|
case NOEX_PROTECTED:
|
|
|
|
case NOEX_PUBLIC:
|
|
|
|
visi = (type == visi);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
visi = (type != NOEX_PRIVATE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (visi) {
|
2006-09-02 19:05:27 +04:00
|
|
|
rb_ary_push(ary, ID2SYM(name));
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
ins_methods_i(ID name, long type, VALUE ary)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
2003-05-02 12:24:43 +04:00
|
|
|
return ins_methods_push(name, type, ary, -1); /* everything but private */
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2003-05-02 12:24:43 +04:00
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
ins_methods_prot_i(ID name, long type, VALUE ary)
|
2003-05-02 12:24:43 +04:00
|
|
|
{
|
|
|
|
return ins_methods_push(name, type, ary, NOEX_PROTECTED);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
ins_methods_priv_i(ID name, long type, VALUE ary)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2003-05-02 12:24:43 +04:00
|
|
|
return ins_methods_push(name, type, ary, NOEX_PRIVATE);
|
|
|
|
}
|
2002-10-30 11:04:32 +03:00
|
|
|
|
2003-05-02 12:24:43 +04:00
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
ins_methods_pub_i(ID name, long type, VALUE ary)
|
2003-05-02 12:24:43 +04:00
|
|
|
{
|
|
|
|
return ins_methods_push(name, type, ary, NOEX_PUBLIC);
|
2002-10-30 11:04:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
method_entry(ID key, NODE *body, st_table *list)
|
2002-10-30 11:04:32 +03:00
|
|
|
{
|
2003-05-02 12:24:43 +04:00
|
|
|
long type;
|
1998-01-16 15:19:22 +03:00
|
|
|
|
2006-12-31 18:02:22 +03:00
|
|
|
if (key == ID_ALLOCATOR) {
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2003-05-02 12:24:43 +04:00
|
|
|
if (!st_lookup(list, key, 0)) {
|
2006-12-31 18:02:22 +03:00
|
|
|
if (body ==0 || !body->nd_body->nd_body) {
|
|
|
|
type = -1; /* none */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
type = VISI(body->nd_body->nd_noex);
|
|
|
|
}
|
2003-05-02 12:24:43 +04:00
|
|
|
st_add_direct(list, key, type);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2003-06-25 11:12:10 +04:00
|
|
|
static VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
class_instance_method_list(int argc, VALUE *argv, VALUE mod, int (*func) (ID, long, VALUE))
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2003-06-26 16:34:51 +04:00
|
|
|
VALUE ary;
|
|
|
|
int recur;
|
|
|
|
st_table *list;
|
1998-01-16 15:19:22 +03:00
|
|
|
|
2003-05-02 20:11:48 +04:00
|
|
|
if (argc == 0) {
|
|
|
|
recur = Qtrue;
|
|
|
|
}
|
2003-06-26 16:34:51 +04:00
|
|
|
else {
|
|
|
|
VALUE r;
|
|
|
|
rb_scan_args(argc, argv, "01", &r);
|
|
|
|
recur = RTEST(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
list = st_init_numtable();
|
2007-09-28 10:21:46 +04:00
|
|
|
for (; mod; mod = RCLASS_SUPER(mod)) {
|
|
|
|
st_foreach(RCLASS_M_TBL(mod), method_entry, (st_data_t)list);
|
2003-08-04 12:31:24 +04:00
|
|
|
if (BUILTIN_TYPE(mod) == T_ICLASS) continue;
|
|
|
|
if (FL_TEST(mod, FL_SINGLETON)) continue;
|
2003-06-26 16:34:51 +04:00
|
|
|
if (!recur) break;
|
|
|
|
}
|
|
|
|
ary = rb_ary_new();
|
|
|
|
st_foreach(list, func, ary);
|
|
|
|
st_free_table(list);
|
|
|
|
|
|
|
|
return ary;
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2004-07-15 15:46:00 +04:00
|
|
|
* mod.instance_methods(include_super=true) => array
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* Returns an array containing the names of public instance methods in
|
|
|
|
* the receiver. For a module, these are the public methods; for a
|
|
|
|
* class, they are the instance (not singleton) methods. With no
|
|
|
|
* argument, or with an argument that is <code>false</code>, the
|
|
|
|
* instance methods in <i>mod</i> are returned, otherwise the methods
|
|
|
|
* in <i>mod</i> and <i>mod</i>'s superclasses are returned.
|
|
|
|
*
|
|
|
|
* module A
|
|
|
|
* def method1() end
|
|
|
|
* end
|
|
|
|
* class B
|
|
|
|
* def method2() end
|
|
|
|
* end
|
|
|
|
* class C < B
|
|
|
|
* def method3() end
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* A.instance_methods #=> ["method1"]
|
2004-06-16 18:21:34 +04:00
|
|
|
* B.instance_methods(false) #=> ["method2"]
|
|
|
|
* C.instance_methods(false) #=> ["method3"]
|
2003-12-28 09:33:07 +03:00
|
|
|
* C.instance_methods(true).length #=> 43
|
|
|
|
*/
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_class_instance_methods(int argc, VALUE *argv, VALUE mod)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
2003-06-25 11:12:10 +04:00
|
|
|
return class_instance_method_list(argc, argv, mod, ins_methods_i);
|
|
|
|
}
|
1999-01-20 07:59:39 +03:00
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2004-07-15 15:46:00 +04:00
|
|
|
* mod.protected_instance_methods(include_super=true) => array
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* Returns a list of the protected instance methods defined in
|
|
|
|
* <i>mod</i>. If the optional parameter is not <code>false</code>, the
|
|
|
|
* methods of any ancestors are included.
|
|
|
|
*/
|
|
|
|
|
2003-06-25 11:12:10 +04:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_class_protected_instance_methods(int argc, VALUE *argv, VALUE mod)
|
2003-06-25 11:12:10 +04:00
|
|
|
{
|
|
|
|
return class_instance_method_list(argc, argv, mod, ins_methods_prot_i);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2004-07-15 15:46:00 +04:00
|
|
|
* mod.private_instance_methods(include_super=true) => array
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* Returns a list of the private instance methods defined in
|
|
|
|
* <i>mod</i>. If the optional parameter is not <code>false</code>, the
|
|
|
|
* methods of any ancestors are included.
|
|
|
|
*
|
|
|
|
* module Mod
|
|
|
|
* def method1() end
|
|
|
|
* private :method1
|
|
|
|
* def method2() end
|
|
|
|
* end
|
|
|
|
* Mod.instance_methods #=> ["method2"]
|
|
|
|
* Mod.private_instance_methods #=> ["method1"]
|
|
|
|
*/
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_class_private_instance_methods(int argc, VALUE *argv, VALUE mod)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2003-06-25 11:12:10 +04:00
|
|
|
return class_instance_method_list(argc, argv, mod, ins_methods_priv_i);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2004-07-15 15:46:00 +04:00
|
|
|
* mod.public_instance_methods(include_super=true) => array
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* Returns a list of the public instance methods defined in <i>mod</i>.
|
|
|
|
* If the optional parameter is not <code>false</code>, the methods of
|
|
|
|
* any ancestors are included.
|
|
|
|
*/
|
|
|
|
|
2002-10-30 11:04:32 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_class_public_instance_methods(int argc, VALUE *argv, VALUE mod)
|
2002-10-30 11:04:32 +03:00
|
|
|
{
|
2003-06-25 11:12:10 +04:00
|
|
|
return class_instance_method_list(argc, argv, mod, ins_methods_pub_i);
|
2002-10-30 11:04:32 +03:00
|
|
|
}
|
|
|
|
|
2003-12-28 09:33:07 +03:00
|
|
|
/*
|
|
|
|
* call-seq:
|
2004-07-15 15:46:00 +04:00
|
|
|
* obj.singleton_methods(all=true) => array
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* Returns an array of the names of singleton methods for <i>obj</i>.
|
|
|
|
* If the optional <i>all</i> parameter is true, the list will include
|
|
|
|
* methods in modules included in <i>obj</i>.
|
|
|
|
*
|
|
|
|
* module Other
|
|
|
|
* def three() end
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* class Single
|
|
|
|
* def Single.four() end
|
|
|
|
* end
|
|
|
|
*
|
|
|
|
* a = Single.new
|
|
|
|
*
|
|
|
|
* def a.one()
|
2004-05-12 06:51:54 +04:00
|
|
|
* end
|
2003-12-28 09:33:07 +03:00
|
|
|
*
|
|
|
|
* class << a
|
|
|
|
* include Other
|
|
|
|
* def two()
|
2004-05-12 06:51:54 +04:00
|
|
|
* end
|
2003-12-28 09:33:07 +03:00
|
|
|
* end
|
|
|
|
*
|
|
|
|
* Single.singleton_methods #=> ["four"]
|
2004-06-16 18:21:34 +04:00
|
|
|
* a.singleton_methods(false) #=> ["two", "one"]
|
|
|
|
* a.singleton_methods #=> ["two", "one", "three"]
|
2003-12-28 09:33:07 +03:00
|
|
|
*/
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
|
1998-01-16 15:19:22 +03:00
|
|
|
{
|
2003-05-06 10:51:31 +04:00
|
|
|
VALUE recur, ary, klass;
|
2003-05-02 12:24:43 +04:00
|
|
|
st_table *list;
|
1998-01-16 15:19:22 +03:00
|
|
|
|
2003-05-06 10:51:31 +04:00
|
|
|
rb_scan_args(argc, argv, "01", &recur);
|
2003-05-02 20:11:48 +04:00
|
|
|
if (argc == 0) {
|
2003-05-04 20:03:24 +04:00
|
|
|
recur = Qtrue;
|
2003-05-02 20:11:48 +04:00
|
|
|
}
|
1998-01-16 15:19:22 +03:00
|
|
|
klass = CLASS_OF(obj);
|
2003-05-02 12:24:43 +04:00
|
|
|
list = st_init_numtable();
|
2003-08-02 00:16:53 +04:00
|
|
|
if (klass && FL_TEST(klass, FL_SINGLETON)) {
|
2007-09-28 10:21:46 +04:00
|
|
|
st_foreach(RCLASS_M_TBL(klass), method_entry, (st_data_t)list);
|
|
|
|
klass = RCLASS_SUPER(klass);
|
1998-01-16 15:19:22 +03:00
|
|
|
}
|
2003-05-06 10:51:31 +04:00
|
|
|
if (RTEST(recur)) {
|
2003-08-02 00:16:53 +04:00
|
|
|
while (klass && (FL_TEST(klass, FL_SINGLETON) || TYPE(klass) == T_ICLASS)) {
|
2007-09-28 10:21:46 +04:00
|
|
|
st_foreach(RCLASS_M_TBL(klass), method_entry, (st_data_t)list);
|
|
|
|
klass = RCLASS_SUPER(klass);
|
2001-05-30 13:12:34 +04:00
|
|
|
}
|
|
|
|
}
|
2003-05-02 12:24:43 +04:00
|
|
|
ary = rb_ary_new();
|
|
|
|
st_foreach(list, ins_methods_i, ary);
|
|
|
|
st_free_table(list);
|
1998-01-16 15:19:22 +03:00
|
|
|
|
|
|
|
return ary;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-10-20 06:56:22 +04:00
|
|
|
rb_define_method_id(VALUE klass, ID name, VALUE (*func)(ANYARGS), int argc)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2003-07-16 11:11:30 +04:00
|
|
|
rb_add_method(klass, name, NEW_CFUNC(func,argc), NOEX_PUBLIC);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-10-20 06:56:22 +04:00
|
|
|
rb_define_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2004-06-16 18:21:34 +04:00
|
|
|
rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PUBLIC);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-10-20 06:56:22 +04:00
|
|
|
rb_define_protected_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2003-07-16 11:11:30 +04:00
|
|
|
rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PROTECTED);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-10-20 06:56:22 +04:00
|
|
|
rb_define_private_method(VALUE klass, const char *name, VALUE (*func)(ANYARGS), int argc)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2003-07-16 11:11:30 +04:00
|
|
|
rb_add_method(klass, rb_intern(name), NEW_CFUNC(func, argc), NOEX_PRIVATE);
|
1999-01-20 07:59:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_undef_method(VALUE klass, const char *name)
|
1999-01-20 07:59:39 +03:00
|
|
|
{
|
|
|
|
rb_add_method(klass, rb_intern(name), 0, NOEX_UNDEF);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
2002-04-25 17:57:01 +04:00
|
|
|
#define SPECIAL_SINGLETON(x,c) do {\
|
|
|
|
if (obj == (x)) {\
|
|
|
|
return c;\
|
|
|
|
}\
|
|
|
|
} while (0)
|
2002-03-08 10:03:09 +03:00
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_singleton_class(VALUE obj)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-12-14 09:50:43 +03:00
|
|
|
VALUE klass;
|
2000-03-07 11:37:59 +03:00
|
|
|
|
2000-05-01 13:42:38 +04:00
|
|
|
if (FIXNUM_P(obj) || SYMBOL_P(obj)) {
|
1999-08-13 09:45:20 +04:00
|
|
|
rb_raise(rb_eTypeError, "can't define singleton");
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-05-01 13:42:38 +04:00
|
|
|
if (rb_special_const_p(obj)) {
|
|
|
|
SPECIAL_SINGLETON(Qnil, rb_cNilClass);
|
|
|
|
SPECIAL_SINGLETON(Qfalse, rb_cFalseClass);
|
|
|
|
SPECIAL_SINGLETON(Qtrue, rb_cTrueClass);
|
2002-05-28 22:11:07 +04:00
|
|
|
rb_bug("unknown immediate %ld", obj);
|
2000-05-01 13:42:38 +04:00
|
|
|
}
|
|
|
|
|
2000-07-27 13:49:34 +04:00
|
|
|
DEFER_INTS;
|
2002-03-08 10:03:09 +03:00
|
|
|
if (FL_TEST(RBASIC(obj)->klass, FL_SINGLETON) &&
|
2002-09-25 11:03:05 +04:00
|
|
|
rb_iv_get(RBASIC(obj)->klass, "__attached__") == obj) {
|
1999-12-14 09:50:43 +03:00
|
|
|
klass = RBASIC(obj)->klass;
|
|
|
|
}
|
|
|
|
else {
|
2002-01-10 23:18:39 +03:00
|
|
|
klass = rb_make_metaclass(obj, RBASIC(obj)->klass);
|
1999-12-14 09:50:43 +03:00
|
|
|
}
|
|
|
|
if (OBJ_TAINTED(obj)) {
|
|
|
|
OBJ_TAINT(klass);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
1999-12-14 09:50:43 +03:00
|
|
|
else {
|
|
|
|
FL_UNSET(klass, FL_TAINT);
|
|
|
|
}
|
2000-06-22 12:29:58 +04:00
|
|
|
if (OBJ_FROZEN(obj)) OBJ_FREEZE(klass);
|
2000-07-27 13:49:34 +04:00
|
|
|
ALLOW_INTS;
|
1999-12-14 09:50:43 +03:00
|
|
|
|
|
|
|
return klass;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-10-20 06:56:22 +04:00
|
|
|
rb_define_singleton_method(VALUE obj, const char *name, VALUE (*func)(ANYARGS), int argc)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
rb_define_method(rb_singleton_class(obj), name, func, argc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-10-20 06:56:22 +04:00
|
|
|
rb_define_module_function(VALUE module, const char *name, VALUE (*func)(ANYARGS), int argc)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
|
|
|
rb_define_private_method(module, name, func, argc);
|
|
|
|
rb_define_singleton_method(module, name, func, argc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-10-20 06:56:22 +04:00
|
|
|
rb_define_global_function(const char *name, VALUE (*func)(ANYARGS), int argc)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_define_module_function(rb_mKernel, name, func, argc);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_define_alias(VALUE klass, const char *name1, const char *name2)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1998-01-16 15:19:22 +03:00
|
|
|
rb_alias(klass, rb_intern(name1), rb_intern(name2));
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
rb_define_attr(VALUE klass, const char *name, int read, int write)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_attr(klass, rb_intern(name), read, write, Qfalse);
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
#include <stdarg.h>
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
int
|
2002-04-18 12:46:18 +04:00
|
|
|
rb_scan_args(int argc, const VALUE *argv, const char *fmt, ...)
|
1998-01-16 15:13:05 +03:00
|
|
|
{
|
2000-02-18 09:59:36 +03:00
|
|
|
int n, i = 0;
|
1999-08-13 09:45:20 +04:00
|
|
|
const char *p = fmt;
|
1998-01-16 15:13:05 +03:00
|
|
|
VALUE *var;
|
|
|
|
va_list vargs;
|
|
|
|
|
* array.c: moved to ANSI function style from K&R function style.
(used protoize on windows, so still K&R remains on #ifdef part of
other platforms. And `foo _((boo))' stuff is still there)
[ruby-dev:26975]
* bignum.c, class.c, compar.c, dir.c, dln.c, dmyext.c, enum.c,
enumerator.c, error.c, eval.c, file.c, gc.c, hash.c, inits.c,
io.c, main.c, marshal.c, math.c, numeric.c, object.c, pack.c,
prec.c, process.c, random.c, range.c, re.c, regcomp.c, regenc.c,
regerror.c, regexec.c, regparse.c, regparse.h, ruby.c, signal.c,
sprintf.c, st.c, string.c, struct.c, time.c, util.h, variable.c,
version.c: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2005-09-12 14:44:21 +04:00
|
|
|
va_start(vargs, fmt);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-02-25 06:51:23 +03:00
|
|
|
if (*p == '*') goto rest_arg;
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (ISDIGIT(*p)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
n = *p - '0';
|
|
|
|
if (n > argc)
|
2001-11-19 08:03:03 +03:00
|
|
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, n);
|
1998-01-16 15:13:05 +03:00
|
|
|
for (i=0; i<n; i++) {
|
|
|
|
var = va_arg(vargs, VALUE*);
|
1999-08-13 09:45:20 +04:00
|
|
|
if (var) *var = argv[i];
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
if (ISDIGIT(*p)) {
|
1998-01-16 15:13:05 +03:00
|
|
|
n = i + *p - '0';
|
|
|
|
for (; i<n; i++) {
|
|
|
|
var = va_arg(vargs, VALUE*);
|
|
|
|
if (argc > i) {
|
1999-08-13 09:45:20 +04:00
|
|
|
if (var) *var = argv[i];
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-08-13 09:45:20 +04:00
|
|
|
if (var) *var = Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*p == '*') {
|
2000-02-25 06:51:23 +03:00
|
|
|
rest_arg:
|
1998-01-16 15:13:05 +03:00
|
|
|
var = va_arg(vargs, VALUE*);
|
|
|
|
if (argc > i) {
|
1999-08-13 09:45:20 +04:00
|
|
|
if (var) *var = rb_ary_new4(argc-i, argv+i);
|
2000-02-18 09:59:36 +03:00
|
|
|
i = argc;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-08-13 09:45:20 +04:00
|
|
|
if (var) *var = rb_ary_new();
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-02-18 09:59:36 +03:00
|
|
|
p++;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-02-18 09:59:36 +03:00
|
|
|
|
|
|
|
if (*p == '&') {
|
|
|
|
var = va_arg(vargs, VALUE*);
|
2000-05-24 08:34:26 +04:00
|
|
|
if (rb_block_given_p()) {
|
2003-06-16 11:14:50 +04:00
|
|
|
*var = rb_block_proc();
|
2000-02-18 09:59:36 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*var = Qnil;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-02-18 09:59:36 +03:00
|
|
|
p++;
|
1998-01-16 15:13:05 +03:00
|
|
|
}
|
2000-02-18 09:59:36 +03:00
|
|
|
va_end(vargs);
|
|
|
|
|
|
|
|
if (*p != '\0') {
|
1998-01-16 15:13:05 +03:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2000-02-18 09:59:36 +03:00
|
|
|
if (argc > i) {
|
2004-03-29 11:54:38 +04:00
|
|
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for %d)", argc, i);
|
2000-02-18 09:59:36 +03:00
|
|
|
}
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
return argc;
|
|
|
|
|
|
|
|
error:
|
1999-01-20 07:59:39 +03:00
|
|
|
rb_fatal("bad scan arg format: %s", fmt);
|
1998-01-16 15:13:05 +03:00
|
|
|
return 0;
|
|
|
|
}
|