2000-05-01 05:42:38 -04:00
|
|
|
/**********************************************************************
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
object.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
$Date$
|
|
|
|
created at: Thu Jul 15 12:01:24 JST 1993
|
|
|
|
|
2003-01-16 02:34:03 -05:00
|
|
|
Copyright (C) 1993-2003 Yukihiro Matsumoto
|
2000-05-01 05:42:38 -04:00
|
|
|
Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
2000-05-09 00:53:16 -04:00
|
|
|
Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-05-01 05:42:38 -04:00
|
|
|
**********************************************************************/
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
#include "ruby.h"
|
|
|
|
#include "st.h"
|
2002-05-14 02:22:31 -04:00
|
|
|
#include "util.h"
|
1998-01-16 07:13:05 -05:00
|
|
|
#include <stdio.h>
|
2000-12-25 01:29:27 -05:00
|
|
|
#include <errno.h>
|
2001-05-16 05:05:54 -04:00
|
|
|
#include <ctype.h>
|
2002-06-28 10:42:46 -04:00
|
|
|
#include <math.h>
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE rb_mKernel;
|
|
|
|
VALUE rb_cObject;
|
|
|
|
VALUE rb_cModule;
|
|
|
|
VALUE rb_cClass;
|
|
|
|
VALUE rb_cData;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE rb_cNilClass;
|
|
|
|
VALUE rb_cTrueClass;
|
|
|
|
VALUE rb_cFalseClass;
|
2000-03-07 03:37:59 -05:00
|
|
|
VALUE rb_cSymbol;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-05-19 01:41:08 -04:00
|
|
|
static ID id_eq, id_eql, id_inspect, id_init_copy;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_equal(obj1, obj2)
|
|
|
|
VALUE obj1, obj2;
|
|
|
|
{
|
|
|
|
VALUE result;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (obj1 == obj2) return Qtrue;
|
2003-05-19 01:41:08 -04:00
|
|
|
result = rb_funcall(obj1, id_eq, 1, obj2);
|
2000-07-17 05:38:10 -04:00
|
|
|
if (RTEST(result)) return Qtrue;
|
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rb_eql(obj1, obj2)
|
|
|
|
VALUE obj1, obj2;
|
|
|
|
{
|
2003-05-19 01:41:08 -04:00
|
|
|
return RTEST(rb_funcall(obj1, id_eql, 1, obj2));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
|
|
|
rb_obj_equal(obj1, obj2)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE obj1, obj2;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
if (obj1 == obj2) return Qtrue;
|
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE
|
|
|
|
rb_obj_id(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
2000-07-17 05:38:10 -04:00
|
|
|
if (SPECIAL_CONST_P(obj)) {
|
2002-08-21 11:47:54 -04:00
|
|
|
return LONG2NUM((long)obj);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2000-07-17 05:38:10 -04:00
|
|
|
return (VALUE)((long)obj|FIXNUM_FLAG);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2002-11-03 06:04:35 -05:00
|
|
|
VALUE
|
|
|
|
rb_obj_id_obsolete(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
rb_warning("Object#id will be deprecated; use Object#object_id");
|
|
|
|
return rb_obj_id(obj);
|
|
|
|
}
|
|
|
|
|
2001-07-14 11:17:19 -04:00
|
|
|
VALUE
|
|
|
|
rb_class_real(cl)
|
|
|
|
VALUE cl;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
while (FL_TEST(cl, FL_SINGLETON) || TYPE(cl) == T_ICLASS) {
|
1998-01-16 07:19:22 -05:00
|
|
|
cl = RCLASS(cl)->super;
|
|
|
|
}
|
|
|
|
return cl;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2002-10-02 02:02:17 -04:00
|
|
|
VALUE
|
|
|
|
rb_obj_type(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
2002-10-04 13:54:29 -04:00
|
|
|
rb_warn("Object#type is deprecated; use Object#class");
|
2002-10-02 02:02:17 -04:00
|
|
|
return rb_class_real(CLASS_OF(obj));
|
|
|
|
}
|
|
|
|
|
2001-07-14 11:17:19 -04:00
|
|
|
VALUE
|
2001-08-20 00:29:58 -04:00
|
|
|
rb_obj_class(obj)
|
2001-07-14 11:17:19 -04:00
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
return rb_class_real(CLASS_OF(obj));
|
|
|
|
}
|
|
|
|
|
2002-09-03 01:20:14 -04:00
|
|
|
static void
|
2003-05-19 01:41:08 -04:00
|
|
|
init_copy(dest, obj)
|
2002-09-03 01:20:14 -04:00
|
|
|
VALUE dest, obj;
|
|
|
|
{
|
2002-09-04 02:37:39 -04:00
|
|
|
if (OBJ_FROZEN(dest)) {
|
2003-01-30 23:00:17 -05:00
|
|
|
rb_raise(rb_eTypeError, "[bug] frozen object (%s) allocated", rb_obj_classname(dest));
|
2002-09-04 02:37:39 -04:00
|
|
|
}
|
|
|
|
RBASIC(dest)->flags &= ~(T_MASK|FL_EXIVAR);
|
2002-09-03 01:20:14 -04:00
|
|
|
RBASIC(dest)->flags |= RBASIC(obj)->flags & (T_MASK|FL_EXIVAR|FL_TAINT);
|
|
|
|
if (FL_TEST(obj, FL_EXIVAR)) {
|
|
|
|
rb_copy_generic_ivar(dest, obj);
|
|
|
|
}
|
2002-12-04 02:39:32 -05:00
|
|
|
rb_gc_copy_finalizer(dest, obj);
|
2002-09-03 01:20:14 -04:00
|
|
|
switch (TYPE(obj)) {
|
|
|
|
case T_OBJECT:
|
|
|
|
case T_CLASS:
|
|
|
|
case T_MODULE:
|
|
|
|
if (ROBJECT(dest)->iv_tbl) {
|
|
|
|
st_free_table(ROBJECT(dest)->iv_tbl);
|
|
|
|
ROBJECT(dest)->iv_tbl = 0;
|
|
|
|
}
|
|
|
|
if (ROBJECT(obj)->iv_tbl) {
|
|
|
|
ROBJECT(dest)->iv_tbl = st_copy(ROBJECT(obj)->iv_tbl);
|
|
|
|
}
|
|
|
|
}
|
2003-05-20 04:40:50 -04:00
|
|
|
rb_funcall(dest, id_init_copy, 1, obj);
|
2002-09-03 01:20:14 -04:00
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE
|
|
|
|
rb_obj_clone(obj)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
VALUE clone;
|
|
|
|
|
2001-10-10 04:21:13 -04:00
|
|
|
if (rb_special_const_p(obj)) {
|
2003-01-30 23:00:17 -05:00
|
|
|
rb_raise(rb_eTypeError, "can't clone %s", rb_obj_classname(obj));
|
2001-10-10 04:21:13 -04:00
|
|
|
}
|
2002-09-03 01:20:14 -04:00
|
|
|
clone = rb_obj_alloc(rb_obj_class(obj));
|
2002-09-04 02:37:39 -04:00
|
|
|
RBASIC(clone)->klass = rb_singleton_class_clone(obj);
|
2003-05-22 12:37:22 -04:00
|
|
|
RBASIC(clone)->flags = (RBASIC(obj)->flags | FL_TEST(clone, FL_TAINT)) & ~FL_FREEZE;
|
2003-05-20 04:40:50 -04:00
|
|
|
init_copy(clone, obj);
|
2003-05-22 12:37:22 -04:00
|
|
|
RBASIC(clone)->flags |= RBASIC(obj)->flags & FL_FREEZE;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
2000-07-17 05:38:10 -04:00
|
|
|
VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_obj_dup(obj)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE obj;
|
|
|
|
{
|
2000-07-17 05:38:10 -04:00
|
|
|
VALUE dup;
|
2000-06-22 04:29:58 -04:00
|
|
|
|
2002-02-01 01:03:03 -05:00
|
|
|
if (rb_special_const_p(obj)) {
|
2003-01-30 23:00:17 -05:00
|
|
|
rb_raise(rb_eTypeError, "can't dup %s", rb_obj_classname(obj));
|
2002-02-01 01:03:03 -05:00
|
|
|
}
|
2002-09-03 01:20:14 -04:00
|
|
|
dup = rb_obj_alloc(rb_obj_class(obj));
|
2003-05-19 01:41:08 -04:00
|
|
|
init_copy(dup, obj);
|
2002-08-27 04:31:08 -04:00
|
|
|
|
|
|
|
return dup;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
2003-05-19 01:41:08 -04:00
|
|
|
rb_obj_init_copy(obj, orig)
|
2002-08-27 04:31:08 -04:00
|
|
|
VALUE obj, orig;
|
|
|
|
{
|
2002-09-03 01:20:14 -04:00
|
|
|
if (obj == orig) return obj;
|
|
|
|
rb_check_frozen(obj);
|
|
|
|
if (TYPE(obj) != TYPE(orig) || rb_obj_class(obj) != rb_obj_class(orig)) {
|
2003-05-19 01:41:08 -04:00
|
|
|
rb_raise(rb_eTypeError, "initialize_copy should take same class object");
|
2000-07-17 05:38:10 -04:00
|
|
|
}
|
2002-08-27 04:31:08 -04:00
|
|
|
return obj;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2000-01-18 01:09:05 -05:00
|
|
|
static VALUE
|
|
|
|
rb_any_to_a(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
2002-06-28 10:42:46 -04:00
|
|
|
rb_warn("default `to_a' will be obsolete");
|
2000-01-18 01:09:05 -05:00
|
|
|
return rb_ary_new3(1, obj);
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_any_to_s(obj)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE obj;
|
|
|
|
{
|
2003-01-30 23:00:17 -05:00
|
|
|
char *cname = rb_obj_classname(obj);
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE str;
|
|
|
|
|
2001-05-11 01:24:59 -04:00
|
|
|
str = rb_str_new(0, strlen(cname)+6+16+1); /* 6:tags 16:addr 1:nul */
|
2000-10-10 03:03:36 -04:00
|
|
|
sprintf(RSTRING(str)->ptr, "#<%s:0x%lx>", cname, obj);
|
2000-10-13 05:01:58 -04:00
|
|
|
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
|
1999-01-19 23:59:39 -05:00
|
|
|
if (OBJ_TAINTED(obj)) OBJ_TAINT(str);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
return str;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_inspect(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
2003-05-19 01:41:08 -04:00
|
|
|
return rb_obj_as_string(rb_funcall(obj, id_inspect, 0, 0));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
inspect_i(id, value, str)
|
|
|
|
ID id;
|
|
|
|
VALUE value;
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE str;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
VALUE str2;
|
|
|
|
char *ivname;
|
|
|
|
|
|
|
|
/* need not to show internal data */
|
|
|
|
if (CLASS_OF(value) == 0) return ST_CONTINUE;
|
1999-01-19 23:59:39 -05:00
|
|
|
if (!rb_is_instance_id(id)) return ST_CONTINUE;
|
2000-05-24 00:34:26 -04:00
|
|
|
if (RSTRING(str)->ptr[0] == '-') { /* first element */
|
1998-01-16 07:19:22 -05:00
|
|
|
RSTRING(str)->ptr[0] = '#';
|
2001-01-15 02:01:00 -05:00
|
|
|
rb_str_cat2(str, " ");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
else {
|
2000-04-10 01:48:43 -04:00
|
|
|
rb_str_cat2(str, ", ");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
ivname = rb_id2name(id);
|
2000-04-10 01:48:43 -04:00
|
|
|
rb_str_cat2(str, ivname);
|
|
|
|
rb_str_cat2(str, "=");
|
1999-01-19 23:59:39 -05:00
|
|
|
str2 = rb_inspect(value);
|
2000-04-10 01:48:43 -04:00
|
|
|
rb_str_append(str, str2);
|
2000-02-23 00:23:12 -05:00
|
|
|
OBJ_INFECT(str, str2);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
return ST_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
inspect_obj(obj, str)
|
|
|
|
VALUE obj, str;
|
|
|
|
{
|
|
|
|
st_foreach(ROBJECT(obj)->iv_tbl, inspect_i, str);
|
2000-04-10 01:48:43 -04:00
|
|
|
rb_str_cat2(str, ">");
|
2001-01-15 02:01:00 -05:00
|
|
|
RSTRING(str)->ptr[0] = '#';
|
2000-02-23 00:23:12 -05:00
|
|
|
OBJ_INFECT(str, obj);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_obj_inspect(obj)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
if (TYPE(obj) == T_OBJECT
|
1998-01-16 07:19:22 -05:00
|
|
|
&& ROBJECT(obj)->iv_tbl
|
|
|
|
&& ROBJECT(obj)->iv_tbl->num_entries > 0) {
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE str;
|
2000-10-10 03:03:36 -04:00
|
|
|
char *c;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-01-30 23:00:17 -05:00
|
|
|
c = rb_obj_classname(obj);
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_inspecting_p(obj)) {
|
2001-05-11 01:24:59 -04:00
|
|
|
str = rb_str_new(0, strlen(c)+10+16+1); /* 10:tags 16:addr 1:nul */
|
2000-10-10 03:03:36 -04:00
|
|
|
sprintf(RSTRING(str)->ptr, "#<%s:0x%lx ...>", c, obj);
|
2000-10-13 05:01:58 -04:00
|
|
|
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
|
2000-10-10 03:03:36 -04:00
|
|
|
return str;
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
2001-05-11 01:24:59 -04:00
|
|
|
str = rb_str_new(0, strlen(c)+6+16+1); /* 6:tags 16:addr 1:nul */
|
2001-01-15 02:01:00 -05:00
|
|
|
sprintf(RSTRING(str)->ptr, "-<%s:0x%lx", c, obj);
|
2000-10-13 05:01:58 -04:00
|
|
|
RSTRING(str)->len = strlen(RSTRING(str)->ptr);
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_protect_inspect(inspect_obj, obj, str);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
return rb_funcall(obj, rb_intern("to_s"), 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_obj_is_instance_of(obj, c)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE obj, c;
|
|
|
|
{
|
|
|
|
switch (TYPE(c)) {
|
|
|
|
case T_MODULE:
|
|
|
|
case T_CLASS:
|
2000-07-14 20:33:12 -04:00
|
|
|
case T_ICLASS:
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_raise(rb_eTypeError, "class or module required");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2001-08-20 00:29:58 -04:00
|
|
|
if (rb_obj_class(obj) == c) return Qtrue;
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_obj_is_kind_of(obj, c)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE obj, c;
|
|
|
|
{
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE cl = CLASS_OF(obj);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
switch (TYPE(c)) {
|
|
|
|
case T_MODULE:
|
|
|
|
case T_CLASS:
|
2000-07-14 20:33:12 -04:00
|
|
|
case T_ICLASS:
|
1998-01-16 07:13:05 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_raise(rb_eTypeError, "class or module required");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
while (cl) {
|
|
|
|
if (cl == c || RCLASS(cl)->m_tbl == RCLASS(c)->m_tbl)
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qtrue;
|
1998-01-16 07:19:22 -05:00
|
|
|
cl = RCLASS(cl)->super;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2000-02-29 03:05:32 -05:00
|
|
|
rb_obj_dummy()
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE
|
|
|
|
rb_obj_tainted(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
if (OBJ_TAINTED(obj))
|
|
|
|
return Qtrue;
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_obj_taint(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-12-14 01:50:43 -05:00
|
|
|
rb_secure(4);
|
2001-01-18 03:43:14 -05:00
|
|
|
if (!OBJ_TAINTED(obj)) {
|
2001-01-15 02:01:00 -05:00
|
|
|
if (OBJ_FROZEN(obj)) {
|
|
|
|
rb_error_frozen("object");
|
|
|
|
}
|
|
|
|
OBJ_TAINT(obj);
|
2001-01-09 11:55:50 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_obj_untaint(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
rb_secure(3);
|
2001-01-18 03:43:14 -05:00
|
|
|
if (OBJ_TAINTED(obj)) {
|
2001-01-15 02:01:00 -05:00
|
|
|
if (OBJ_FROZEN(obj)) {
|
|
|
|
rb_error_frozen("object");
|
|
|
|
}
|
|
|
|
FL_UNSET(obj, FL_TAINT);
|
2001-01-09 11:55:50 -05:00
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2003-03-24 22:11:27 -05:00
|
|
|
void
|
|
|
|
rb_obj_infect(obj1, obj2)
|
|
|
|
VALUE obj1, obj2;
|
|
|
|
{
|
|
|
|
OBJ_INFECT(obj1, obj2);
|
|
|
|
}
|
|
|
|
|
2000-01-31 22:12:21 -05:00
|
|
|
VALUE
|
|
|
|
rb_obj_freeze(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
2001-01-18 03:43:14 -05:00
|
|
|
if (!OBJ_FROZEN(obj)) {
|
2001-01-15 02:01:00 -05:00
|
|
|
if (rb_safe_level() >= 4 && !OBJ_TAINTED(obj)) {
|
|
|
|
rb_raise(rb_eSecurityError, "Insecure: can't freeze object");
|
|
|
|
}
|
|
|
|
OBJ_FREEZE(obj);
|
|
|
|
}
|
2000-01-31 22:12:21 -05:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_obj_frozen_p(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
if (OBJ_FROZEN(obj)) return Qtrue;
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
|
|
|
nil_to_i(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
return INT2FIX(0);
|
|
|
|
}
|
|
|
|
|
2002-06-28 10:42:46 -04:00
|
|
|
static VALUE
|
|
|
|
nil_to_f(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
|
|
|
return rb_float_new(0.0);
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
1998-01-16 07:19:22 -05:00
|
|
|
nil_to_s(obj)
|
|
|
|
VALUE obj;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_str_new2("");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1998-01-16 07:19:22 -05:00
|
|
|
nil_to_a(obj)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_ary_new2(0);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
nil_inspect(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_str_new2("nil");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
#ifdef NIL_PLUS
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
|
|
|
nil_plus(x, y)
|
|
|
|
VALUE x, y;
|
|
|
|
{
|
|
|
|
switch (TYPE(y)) {
|
1999-01-19 23:59:39 -05:00
|
|
|
case T_NIL:
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_FIXNUM:
|
|
|
|
case T_FLOAT:
|
|
|
|
case T_BIGNUM:
|
|
|
|
case T_STRING:
|
|
|
|
case T_ARRAY:
|
|
|
|
return y;
|
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_raise(rb_eTypeError, "tried to add %s(%s) to nil",
|
2001-05-02 00:22:21 -04:00
|
|
|
RSTRING(rb_inspect(y))->ptr,
|
2003-01-30 23:00:17 -05:00
|
|
|
rb_obj_classname(y));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
/* not reached */
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
#endif
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
static VALUE
|
|
|
|
main_to_s(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_str_new2("main");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
true_to_s(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_str_new2("true");
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
true_and(obj, obj2)
|
|
|
|
VALUE obj, obj2;
|
|
|
|
{
|
|
|
|
return RTEST(obj2)?Qtrue:Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
true_or(obj, obj2)
|
|
|
|
VALUE obj, obj2;
|
|
|
|
{
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
true_xor(obj, obj2)
|
|
|
|
VALUE obj, obj2;
|
|
|
|
{
|
|
|
|
return RTEST(obj2)?Qfalse:Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
false_to_s(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_str_new2("false");
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
false_and(obj, obj2)
|
|
|
|
VALUE obj, obj2;
|
|
|
|
{
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
false_or(obj, obj2)
|
|
|
|
VALUE obj, obj2;
|
|
|
|
{
|
|
|
|
return RTEST(obj2)?Qtrue:Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
false_xor(obj, obj2)
|
|
|
|
VALUE obj, obj2;
|
|
|
|
{
|
|
|
|
return RTEST(obj2)?Qtrue:Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_true(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qtrue;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_false(obj)
|
|
|
|
VALUE obj;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qfalse;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2000-03-07 03:37:59 -05:00
|
|
|
static VALUE
|
|
|
|
sym_to_i(sym)
|
|
|
|
VALUE sym;
|
|
|
|
{
|
|
|
|
ID id = SYM2ID(sym);
|
|
|
|
|
2002-08-21 11:47:54 -04:00
|
|
|
return LONG2FIX(id);
|
2000-03-07 03:37:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2000-04-10 01:48:43 -04:00
|
|
|
sym_inspect(sym)
|
2000-03-07 03:37:59 -05:00
|
|
|
VALUE sym;
|
|
|
|
{
|
2000-10-10 03:03:36 -04:00
|
|
|
VALUE str;
|
|
|
|
char *name;
|
2002-10-23 06:17:30 -04:00
|
|
|
ID id = SYM2ID(sym);
|
2000-03-08 01:25:19 -05:00
|
|
|
|
2002-10-23 06:17:30 -04:00
|
|
|
name = rb_id2name(id);
|
2001-03-20 22:41:45 -05:00
|
|
|
str = rb_str_new(0, strlen(name)+1);
|
2001-03-13 00:45:13 -05:00
|
|
|
RSTRING(str)->ptr[0] = ':';
|
|
|
|
strcpy(RSTRING(str)->ptr+1, name);
|
2002-10-23 06:17:30 -04:00
|
|
|
if (rb_is_junk_id(id)) {
|
|
|
|
str = rb_str_dump(str);
|
|
|
|
strncpy(RSTRING(str)->ptr, ":\"", 2);
|
|
|
|
}
|
2000-10-10 03:03:36 -04:00
|
|
|
return str;
|
2000-03-07 03:37:59 -05:00
|
|
|
}
|
|
|
|
|
2000-03-09 04:04:36 -05:00
|
|
|
static VALUE
|
2000-04-10 01:48:43 -04:00
|
|
|
sym_to_s(sym)
|
2000-03-09 04:04:36 -05:00
|
|
|
VALUE sym;
|
|
|
|
{
|
|
|
|
return rb_str_new2(rb_id2name(SYM2ID(sym)));
|
|
|
|
}
|
|
|
|
|
2001-03-26 03:57:16 -05:00
|
|
|
static VALUE
|
2002-11-03 06:04:35 -05:00
|
|
|
sym_to_sym(sym)
|
2001-03-26 03:57:16 -05:00
|
|
|
VALUE sym;
|
|
|
|
{
|
|
|
|
return sym;
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_mod_to_s(klass)
|
|
|
|
VALUE klass;
|
2001-05-11 01:24:59 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-05-11 01:24:59 -04:00
|
|
|
if (FL_TEST(klass, FL_SINGLETON)) {
|
|
|
|
VALUE s = rb_str_new2("#<");
|
2002-02-25 04:16:25 -05:00
|
|
|
VALUE v = rb_iv_get(klass, "__attached__");
|
2001-05-11 01:24:59 -04:00
|
|
|
|
|
|
|
rb_str_cat2(s, "Class:");
|
2002-02-25 04:16:25 -05:00
|
|
|
switch (TYPE(v)) {
|
|
|
|
case T_CLASS: case T_MODULE:
|
|
|
|
rb_str_append(s, rb_inspect(v));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rb_str_append(s, rb_any_to_s(v));
|
|
|
|
break;
|
|
|
|
}
|
2001-05-11 01:24:59 -04:00
|
|
|
rb_str_cat2(s, ">");
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_str_dup(rb_class_path(klass));
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_mod_eqq(mod, arg)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE mod, arg;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_obj_is_kind_of(arg, mod);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_mod_le(mod, arg)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE mod, arg;
|
|
|
|
{
|
2003-05-15 03:57:07 -04:00
|
|
|
VALUE start = mod;
|
|
|
|
|
2002-01-23 02:30:43 -05:00
|
|
|
if (mod == arg) return Qtrue;
|
1998-01-16 07:19:22 -05:00
|
|
|
switch (TYPE(arg)) {
|
|
|
|
case T_MODULE:
|
|
|
|
case T_CLASS:
|
|
|
|
break;
|
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_raise(rb_eTypeError, "compared with non class/module");
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
while (mod) {
|
|
|
|
if (RCLASS(mod)->m_tbl == RCLASS(arg)->m_tbl)
|
1999-01-19 23:59:39 -05:00
|
|
|
return Qtrue;
|
1998-01-16 07:19:22 -05:00
|
|
|
mod = RCLASS(mod)->super;
|
|
|
|
}
|
2003-05-15 03:57:07 -04:00
|
|
|
/* not mod < arg; check if mod > arg */
|
|
|
|
while (arg) {
|
|
|
|
if (RCLASS(arg)->m_tbl == RCLASS(start)->m_tbl)
|
|
|
|
return Qfalse;
|
|
|
|
arg = RCLASS(arg)->super;
|
|
|
|
}
|
|
|
|
return Qnil;
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_mod_lt(mod, arg)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE mod, arg;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
if (mod == arg) return Qfalse;
|
|
|
|
return rb_mod_le(mod, arg);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_mod_ge(mod, arg)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE mod, arg;
|
|
|
|
{
|
|
|
|
switch (TYPE(arg)) {
|
|
|
|
case T_MODULE:
|
|
|
|
case T_CLASS:
|
|
|
|
break;
|
|
|
|
default:
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_raise(rb_eTypeError, "compared with non class/module");
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
return rb_mod_le(arg, mod);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_mod_gt(mod, arg)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE mod, arg;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
if (mod == arg) return Qfalse;
|
|
|
|
return rb_mod_ge(mod, arg);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_mod_cmp(mod, arg)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE mod, arg;
|
|
|
|
{
|
2002-01-23 02:30:43 -05:00
|
|
|
VALUE start = mod;
|
2003-05-15 03:57:07 -04:00
|
|
|
VALUE cmp;
|
1998-01-16 07:19:22 -05:00
|
|
|
|
2002-01-23 02:30:43 -05:00
|
|
|
if (mod == arg) return INT2FIX(0);
|
1998-01-16 07:19:22 -05:00
|
|
|
switch (TYPE(arg)) {
|
|
|
|
case T_MODULE:
|
|
|
|
case T_CLASS:
|
|
|
|
break;
|
|
|
|
default:
|
2002-12-19 04:20:20 -05:00
|
|
|
return Qnil;
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
2003-05-15 03:57:07 -04:00
|
|
|
cmp = rb_mod_le(mod, arg);
|
2003-05-19 02:27:06 -04:00
|
|
|
if (NIL_P(cmp)) return Qnil;
|
2003-05-15 03:57:07 -04:00
|
|
|
if (cmp) {
|
|
|
|
return INT2FIX(-1);
|
2002-01-23 02:30:43 -05:00
|
|
|
}
|
2003-05-15 03:57:07 -04:00
|
|
|
return INT2FIX(1);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
2000-05-25 01:55:12 -04:00
|
|
|
static VALUE
|
2002-01-23 02:30:43 -05:00
|
|
|
rb_mod_initialize(module)
|
2001-10-10 04:21:13 -04:00
|
|
|
VALUE module;
|
2000-05-25 01:55:12 -04:00
|
|
|
{
|
2001-10-15 23:27:23 -04:00
|
|
|
if (rb_block_given_p()) {
|
|
|
|
rb_mod_module_eval(0, 0, module);
|
|
|
|
}
|
2000-05-25 01:55:12 -04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2002-01-23 02:30:43 -05:00
|
|
|
static VALUE
|
|
|
|
rb_class_initialize(argc, argv, klass)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
VALUE klass;
|
|
|
|
{
|
|
|
|
return rb_mod_initialize(klass);
|
|
|
|
}
|
|
|
|
|
* array.c (ary_alloc), dir.c (dir_s_alloc), eval.c (thgroup_s_alloc),
file.c (rb_stat_s_alloc), hash.c (hash_alloc), io.c (io_alloc),
object.c (rb_module_s_alloc, rb_class_allocate_instance),
re.c (match_alloc, rb_reg_s_alloc), string.c (str_alloc),
time.c (time_s_alloc), ext/digest/digest.c (rb_digest_base_alloc),
ext/tcltklib/tcltklib.c (ip_alloc),
ext/win32ole/win32ole.c (fole_s_allocate, fev_s_allocate)
: add prototype to get rid of VC++ warnings.
* ext/sdbm/init.c (fsdbm_alloc): allocator takes only one argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-21 13:02:01 -05:00
|
|
|
static VALUE rb_module_s_alloc _((VALUE));
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
2001-10-03 03:19:19 -04:00
|
|
|
rb_module_s_alloc(klass)
|
2000-02-29 03:05:32 -05:00
|
|
|
VALUE klass;
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
|
|
|
VALUE mod = rb_module_new();
|
|
|
|
|
|
|
|
RBASIC(mod)->klass = klass;
|
|
|
|
return mod;
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_class_s_new(argc, argv)
|
1998-01-16 07:13:05 -05:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
{
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE super, klass;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
if (rb_scan_args(argc, argv, "01", &super) == 0) {
|
|
|
|
super = rb_cObject;
|
|
|
|
}
|
|
|
|
klass = rb_class_new(super);
|
2002-01-10 15:18:39 -05:00
|
|
|
rb_make_metaclass(klass, RBASIC(super)->klass);
|
2000-05-24 00:34:26 -04:00
|
|
|
rb_obj_call_init(klass, argc, argv);
|
2002-01-10 15:18:39 -05:00
|
|
|
rb_class_inherited(super, klass);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
return klass;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2001-10-03 03:19:19 -04:00
|
|
|
VALUE
|
|
|
|
rb_obj_alloc(klass)
|
|
|
|
VALUE klass;
|
|
|
|
{
|
2003-05-16 19:28:31 -04:00
|
|
|
VALUE obj;
|
2001-10-03 03:19:19 -04:00
|
|
|
|
2003-05-16 19:28:31 -04:00
|
|
|
if (FL_TEST(klass, FL_SINGLETON)) {
|
|
|
|
rb_raise(rb_eTypeError, "can't create instance of virtual class");
|
|
|
|
}
|
|
|
|
obj = rb_funcall(klass, ID_ALLOCATOR, 0, 0);
|
2001-10-03 03:19:19 -04:00
|
|
|
if (rb_obj_class(obj) != rb_class_real(klass)) {
|
|
|
|
rb_raise(rb_eTypeError, "wrong instance allocation");
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
* array.c (ary_alloc), dir.c (dir_s_alloc), eval.c (thgroup_s_alloc),
file.c (rb_stat_s_alloc), hash.c (hash_alloc), io.c (io_alloc),
object.c (rb_module_s_alloc, rb_class_allocate_instance),
re.c (match_alloc, rb_reg_s_alloc), string.c (str_alloc),
time.c (time_s_alloc), ext/digest/digest.c (rb_digest_base_alloc),
ext/tcltklib/tcltklib.c (ip_alloc),
ext/win32ole/win32ole.c (fole_s_allocate, fev_s_allocate)
: add prototype to get rid of VC++ warnings.
* ext/sdbm/init.c (fsdbm_alloc): allocator takes only one argument.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3197 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2002-12-21 13:02:01 -05:00
|
|
|
static VALUE rb_class_allocate_instance _((VALUE));
|
2001-10-03 03:19:19 -04:00
|
|
|
static VALUE
|
|
|
|
rb_class_allocate_instance(klass)
|
|
|
|
VALUE klass;
|
|
|
|
{
|
2003-05-16 19:28:31 -04:00
|
|
|
NEWOBJ(obj, struct RObject);
|
|
|
|
OBJSETUP(obj, klass, T_OBJECT);
|
|
|
|
return (VALUE)obj;
|
2001-10-03 03:19:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_class_new_instance(argc, argv, klass)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
|
|
|
VALUE klass;
|
|
|
|
{
|
|
|
|
VALUE obj;
|
|
|
|
|
|
|
|
obj = rb_obj_alloc(klass);
|
|
|
|
rb_obj_call_init(obj, argc, argv);
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_class_superclass(klass)
|
|
|
|
VALUE klass;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE super = RCLASS(klass)->super;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
while (TYPE(super) == T_ICLASS) {
|
1998-01-16 07:19:22 -05:00
|
|
|
super = RCLASS(super)->super;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
if (!super) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
return super;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ID
|
|
|
|
rb_to_id(name)
|
|
|
|
VALUE name;
|
|
|
|
{
|
2003-03-24 04:38:37 -05:00
|
|
|
VALUE tmp;
|
1999-01-19 23:59:39 -05:00
|
|
|
ID id;
|
|
|
|
|
2000-03-07 03:37:59 -05:00
|
|
|
switch (TYPE(name)) {
|
|
|
|
case T_STRING:
|
1998-01-16 07:13:05 -05:00
|
|
|
return rb_intern(RSTRING(name)->ptr);
|
2000-03-07 03:37:59 -05:00
|
|
|
case T_FIXNUM:
|
2003-03-24 04:38:37 -05:00
|
|
|
rb_warn("do not use Fixnums as Symbols");
|
2002-08-21 11:47:54 -04:00
|
|
|
id = FIX2LONG(name);
|
2000-03-07 03:37:59 -05:00
|
|
|
if (!rb_id2name(id)) {
|
2002-10-29 16:35:28 -05:00
|
|
|
rb_raise(rb_eArgError, "%ld is not a symbol", id);
|
2000-03-07 03:37:59 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case T_SYMBOL:
|
|
|
|
id = SYM2ID(name);
|
|
|
|
break;
|
2000-07-06 03:21:26 -04:00
|
|
|
default:
|
2003-03-24 04:38:37 -05:00
|
|
|
tmp = rb_check_string_type(name);
|
|
|
|
if (!NIL_P(tmp)) {
|
|
|
|
return rb_intern(RSTRING(tmp)->ptr);
|
|
|
|
}
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_raise(rb_eTypeError, "%s is not a symbol", RSTRING(rb_inspect(name))->ptr);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
return id;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_mod_attr(argc, argv, klass)
|
1998-01-16 07:13:05 -05:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE klass;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
|
|
|
VALUE name, pub;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &name, &pub);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_attr(klass, rb_to_id(name), 1, RTEST(pub), Qtrue);
|
1998-01-16 07:19:22 -05:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_mod_attr_reader(argc, argv, klass)
|
1998-01-16 07:19:22 -05:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE klass;
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<argc; i++) {
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_attr(klass, rb_to_id(argv[i]), 1, 0, Qtrue);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_mod_attr_writer(argc, argv, klass)
|
1998-01-16 07:19:22 -05:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE klass;
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<argc; i++) {
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_attr(klass, rb_to_id(argv[i]), 0, 1, Qtrue);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_mod_attr_accessor(argc, argv, klass)
|
1998-01-16 07:19:22 -05:00
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE klass;
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<argc; i++) {
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_attr(klass, rb_to_id(argv[i]), 1, 1, Qtrue);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-12-14 01:50:43 -05:00
|
|
|
rb_mod_const_get(mod, name)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE mod, name;
|
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
ID id = rb_to_id(name);
|
|
|
|
|
|
|
|
if (!rb_is_const_id(id)) {
|
2001-07-02 04:46:28 -04:00
|
|
|
rb_name_error(id, "wrong constant name %s", rb_id2name(id));
|
2001-05-02 00:22:21 -04:00
|
|
|
}
|
|
|
|
return rb_const_get(mod, id);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-12-14 01:50:43 -05:00
|
|
|
rb_mod_const_set(mod, name, value)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE mod, name, value;
|
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
ID id = rb_to_id(name);
|
|
|
|
|
|
|
|
if (!rb_is_const_id(id)) {
|
2001-07-02 04:46:28 -04:00
|
|
|
rb_name_error(id, "wrong constant name %s", rb_id2name(id));
|
2001-05-02 00:22:21 -04:00
|
|
|
}
|
|
|
|
rb_const_set(mod, id, value);
|
1998-01-16 07:19:22 -05:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
1999-12-14 01:50:43 -05:00
|
|
|
rb_mod_const_defined(mod, name)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE mod, name;
|
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
ID id = rb_to_id(name);
|
|
|
|
|
|
|
|
if (!rb_is_const_id(id)) {
|
2001-07-02 04:46:28 -04:00
|
|
|
rb_name_error(id, "wrong constant name %s", rb_id2name(id));
|
2001-05-02 00:22:21 -04:00
|
|
|
}
|
|
|
|
return rb_const_defined_at(mod, id);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2003-05-04 12:03:24 -04:00
|
|
|
rb_obj_methods(argc, argv, obj)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj;
|
|
|
|
{
|
2003-05-06 02:51:31 -04:00
|
|
|
retry:
|
2003-05-04 12:03:24 -04:00
|
|
|
if (argc == 0) {
|
|
|
|
VALUE args[1];
|
1998-01-16 07:19:22 -05:00
|
|
|
|
2003-05-04 12:03:24 -04:00
|
|
|
args[0] = Qtrue;
|
|
|
|
return rb_class_instance_methods(1, args, CLASS_OF(obj));
|
|
|
|
}
|
2003-05-06 02:51:31 -04:00
|
|
|
else {
|
|
|
|
VALUE recur;
|
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "1", &recur);
|
|
|
|
if (RTEST(recur)) {
|
|
|
|
argc = 0;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
return rb_obj_singleton_methods(argc, argv, obj);
|
|
|
|
}
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2003-05-04 12:03:24 -04:00
|
|
|
rb_obj_protected_methods(argc, argv, obj)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE obj;
|
|
|
|
{
|
2003-05-04 12:03:24 -04:00
|
|
|
if (argc == 0) { /* hack to stop warning */
|
|
|
|
VALUE args[1];
|
1998-01-16 07:19:22 -05:00
|
|
|
|
2003-05-04 12:03:24 -04:00
|
|
|
args[0] = Qtrue;
|
|
|
|
return rb_class_protected_instance_methods(1, args, CLASS_OF(obj));
|
|
|
|
}
|
|
|
|
return rb_class_protected_instance_methods(argc, argv, CLASS_OF(obj));
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
2003-05-04 12:03:24 -04:00
|
|
|
rb_obj_private_methods(argc, argv, obj)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE obj;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2003-05-04 12:03:24 -04:00
|
|
|
if (argc == 0) { /* hack to stop warning */
|
|
|
|
VALUE args[1];
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-05-04 12:03:24 -04:00
|
|
|
args[0] = Qtrue;
|
|
|
|
return rb_class_private_instance_methods(1, args, CLASS_OF(obj));
|
|
|
|
}
|
|
|
|
return rb_class_private_instance_methods(argc, argv, CLASS_OF(obj));
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
2002-10-30 03:04:32 -05:00
|
|
|
static VALUE
|
2003-05-04 12:03:24 -04:00
|
|
|
rb_obj_public_methods(argc, argv, obj)
|
|
|
|
int argc;
|
|
|
|
VALUE *argv;
|
2002-10-30 03:04:32 -05:00
|
|
|
VALUE obj;
|
|
|
|
{
|
2003-05-04 12:03:24 -04:00
|
|
|
if (argc == 0) { /* hack to stop warning */
|
|
|
|
VALUE args[1];
|
2002-10-30 03:04:32 -05:00
|
|
|
|
2003-05-04 12:03:24 -04:00
|
|
|
args[0] = Qtrue;
|
|
|
|
return rb_class_public_instance_methods(1, args, CLASS_OF(obj));
|
|
|
|
}
|
|
|
|
return rb_class_public_instance_methods(argc, argv, CLASS_OF(obj));
|
2002-10-30 03:04:32 -05:00
|
|
|
}
|
|
|
|
|
2003-02-10 04:40:13 -05:00
|
|
|
static VALUE
|
|
|
|
rb_obj_ivar_get(obj, iv)
|
|
|
|
VALUE obj, iv;
|
|
|
|
{
|
|
|
|
ID id = rb_to_id(iv);
|
|
|
|
|
|
|
|
if (!rb_is_instance_id(id)) {
|
2003-04-09 14:33:52 -04:00
|
|
|
rb_name_error(id, "`%s' is not allowed as an instance variable name", rb_id2name(id));
|
2003-02-10 04:40:13 -05:00
|
|
|
}
|
|
|
|
return rb_ivar_get(obj, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_obj_ivar_set(obj, iv, val)
|
|
|
|
VALUE obj, iv, val;
|
|
|
|
{
|
|
|
|
ID id = rb_to_id(iv);
|
|
|
|
|
|
|
|
if (!rb_is_instance_id(id)) {
|
2003-04-09 14:33:52 -04:00
|
|
|
rb_name_error(id, "`%s' is not allowed as an instance variable name", rb_id2name(id));
|
2003-02-10 04:40:13 -05:00
|
|
|
}
|
|
|
|
return rb_ivar_set(obj, id, val);
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
2002-01-04 09:15:33 -05:00
|
|
|
convert_type(val, tname, method, raise)
|
|
|
|
VALUE val;
|
|
|
|
const char *tname, *method;
|
|
|
|
int raise;
|
1999-01-19 23:59:39 -05:00
|
|
|
{
|
2002-01-04 09:15:33 -05:00
|
|
|
ID m;
|
|
|
|
|
|
|
|
m = rb_intern(method);
|
|
|
|
if (!rb_respond_to(val, m)) {
|
|
|
|
if (raise) {
|
2002-04-24 00:54:16 -04:00
|
|
|
rb_raise(rb_eTypeError, "cannot convert %s into %s",
|
2002-01-04 09:15:33 -05:00
|
|
|
NIL_P(val) ? "nil" :
|
|
|
|
val == Qtrue ? "true" :
|
|
|
|
val == Qfalse ? "false" :
|
2003-01-30 23:00:17 -05:00
|
|
|
rb_obj_classname(val),
|
2002-01-04 09:15:33 -05:00
|
|
|
tname);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rb_funcall(val, m, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_convert_type(val, type, tname, method)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE val;
|
1999-01-19 23:59:39 -05:00
|
|
|
int type;
|
1999-08-13 01:45:20 -04:00
|
|
|
const char *tname, *method;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2002-01-04 09:15:33 -05:00
|
|
|
VALUE v;
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
if (TYPE(val) == type) return val;
|
2002-01-04 09:15:33 -05:00
|
|
|
v = convert_type(val, tname, method, Qtrue);
|
|
|
|
if (TYPE(v) != type) {
|
2000-08-31 01:29:54 -04:00
|
|
|
rb_raise(rb_eTypeError, "%s#%s should return %s",
|
2003-01-30 23:00:17 -05:00
|
|
|
rb_obj_classname(val), method, tname);
|
2000-08-31 01:29:54 -04:00
|
|
|
}
|
2002-01-04 09:15:33 -05:00
|
|
|
return v;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
2001-11-29 10:57:25 -05:00
|
|
|
VALUE
|
|
|
|
rb_check_convert_type(val, type, tname, method)
|
|
|
|
VALUE val;
|
|
|
|
int type;
|
|
|
|
const char *tname, *method;
|
|
|
|
{
|
2002-01-04 09:15:33 -05:00
|
|
|
VALUE v;
|
2001-11-29 10:57:25 -05:00
|
|
|
|
2002-04-24 00:54:16 -04:00
|
|
|
/* always convert T_DATA */
|
|
|
|
if (TYPE(val) == type && type != T_DATA) return val;
|
2002-01-04 09:15:33 -05:00
|
|
|
v = convert_type(val, tname, method, Qfalse);
|
|
|
|
if (NIL_P(v)) return Qnil;
|
|
|
|
if (TYPE(v) != type) {
|
2001-11-29 10:57:25 -05:00
|
|
|
rb_raise(rb_eTypeError, "%s#%s should return %s",
|
2003-01-30 23:00:17 -05:00
|
|
|
rb_obj_classname(val), method, tname);
|
2001-11-29 10:57:25 -05:00
|
|
|
}
|
2002-01-04 09:15:33 -05:00
|
|
|
return v;
|
2001-11-29 10:57:25 -05:00
|
|
|
}
|
|
|
|
|
2002-06-28 10:42:46 -04:00
|
|
|
|
2000-11-13 00:39:35 -05:00
|
|
|
static VALUE
|
|
|
|
rb_to_integer(val, method)
|
1999-08-13 01:45:20 -04:00
|
|
|
VALUE val;
|
2000-11-13 00:39:35 -05:00
|
|
|
char *method;
|
1999-08-13 01:45:20 -04:00
|
|
|
{
|
2002-01-04 09:15:33 -05:00
|
|
|
VALUE v = convert_type(val, "Integer", method, Qtrue);
|
|
|
|
if (!rb_obj_is_kind_of(v, rb_cInteger)) {
|
2000-11-14 02:10:31 -05:00
|
|
|
rb_raise(rb_eTypeError, "%s#%s should return Integer",
|
2003-01-30 23:00:17 -05:00
|
|
|
rb_obj_classname(val), method);
|
2000-11-13 00:39:35 -05:00
|
|
|
}
|
2002-01-04 09:15:33 -05:00
|
|
|
return v;
|
2000-11-13 00:39:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_to_int(val)
|
|
|
|
VALUE val;
|
|
|
|
{
|
|
|
|
return rb_to_integer(val, "to_int");
|
|
|
|
}
|
|
|
|
|
|
|
|
VALUE
|
|
|
|
rb_Integer(val)
|
|
|
|
VALUE val;
|
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
switch (TYPE(val)) {
|
|
|
|
case T_FLOAT:
|
|
|
|
if (RFLOAT(val)->value <= (double)FIXNUM_MAX
|
|
|
|
&& RFLOAT(val)->value >= (double)FIXNUM_MIN) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rb_dbl2big(RFLOAT(val)->value);
|
|
|
|
|
2002-07-02 05:58:13 -04:00
|
|
|
case T_FIXNUM:
|
1999-08-13 01:45:20 -04:00
|
|
|
case T_BIGNUM:
|
|
|
|
return val;
|
|
|
|
|
|
|
|
case T_STRING:
|
2002-02-01 05:23:22 -05:00
|
|
|
return rb_str_to_inum(val, 0, Qtrue);
|
1999-08-13 01:45:20 -04:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2002-06-28 10:42:46 -04:00
|
|
|
if (rb_respond_to(val, rb_intern("to_int"))) {
|
|
|
|
return rb_to_integer(val, "to_int");
|
|
|
|
}
|
2002-07-02 05:58:13 -04:00
|
|
|
return rb_to_integer(val, "to_i");
|
1999-08-13 01:45:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
rb_f_integer(obj, arg)
|
|
|
|
VALUE obj, arg;
|
|
|
|
{
|
|
|
|
return rb_Integer(arg);
|
|
|
|
}
|
|
|
|
|
2002-02-01 05:23:22 -05:00
|
|
|
double
|
|
|
|
rb_cstr_to_dbl(p, badcheck)
|
|
|
|
const char *p;
|
|
|
|
int badcheck;
|
|
|
|
{
|
|
|
|
const char *q;
|
|
|
|
char *end;
|
|
|
|
double d;
|
|
|
|
|
2002-10-17 03:27:00 -04:00
|
|
|
if (!p) return 0.0;
|
2002-02-01 05:23:22 -05:00
|
|
|
q = p;
|
|
|
|
if (badcheck) {
|
|
|
|
while (ISSPACE(*p)) p++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (ISSPACE(*p) || *p == '_') p++;
|
|
|
|
}
|
|
|
|
d = strtod(p, &end);
|
|
|
|
if (p == end) {
|
|
|
|
if (badcheck) {
|
2002-05-14 02:22:31 -04:00
|
|
|
bad:
|
2002-02-01 05:23:22 -05:00
|
|
|
rb_invalid_str(q, "Float()");
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
if (*end) {
|
2002-08-27 04:31:08 -04:00
|
|
|
char *buf = ALLOCA_N(char, strlen(p)+1);
|
2002-02-01 05:23:22 -05:00
|
|
|
char *n = buf;
|
|
|
|
|
|
|
|
while (p < end) *n++ = *p++;
|
|
|
|
while (*p) {
|
|
|
|
if (*p == '_') {
|
|
|
|
/* remove underscores between digits */
|
|
|
|
if (badcheck) {
|
|
|
|
if (n == buf || !ISDIGIT(n[-1])) goto bad;
|
|
|
|
++p;
|
|
|
|
if (!ISDIGIT(*p)) goto bad;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
while (*++p == '_');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*n++ = *p++;
|
|
|
|
}
|
|
|
|
*n = '\0';
|
|
|
|
p = buf;
|
|
|
|
d = strtod(p, &end);
|
|
|
|
if (badcheck) {
|
|
|
|
if (p == end) goto bad;
|
|
|
|
while (*end && ISSPACE(*end)) end++;
|
|
|
|
if (*end) goto bad;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (errno == ERANGE) {
|
|
|
|
errno = 0;
|
|
|
|
rb_raise(rb_eArgError, "Float %s out of range", q);
|
|
|
|
}
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
rb_str_to_dbl(str, badcheck)
|
|
|
|
VALUE str;
|
|
|
|
int badcheck;
|
|
|
|
{
|
|
|
|
char *s;
|
2002-08-21 11:47:54 -04:00
|
|
|
long len;
|
2002-02-01 05:23:22 -05:00
|
|
|
|
|
|
|
StringValue(str);
|
|
|
|
s = RSTRING(str)->ptr;
|
|
|
|
len = RSTRING(str)->len;
|
2002-10-17 03:27:00 -04:00
|
|
|
if (s) {
|
|
|
|
if (s[len]) { /* no sentinel somehow */
|
|
|
|
char *p = ALLOCA_N(char, len+1);
|
2002-02-01 05:23:22 -05:00
|
|
|
|
2002-10-17 03:27:00 -04:00
|
|
|
MEMCPY(p, s, char, len);
|
|
|
|
p[len] = '\0';
|
|
|
|
s = p;
|
|
|
|
}
|
|
|
|
if (badcheck && len != strlen(s)) {
|
|
|
|
rb_raise(rb_eArgError, "string for Float contains null byte");
|
|
|
|
}
|
2002-02-01 05:23:22 -05:00
|
|
|
}
|
|
|
|
return rb_cstr_to_dbl(s, badcheck);
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE
|
|
|
|
rb_Float(val)
|
|
|
|
VALUE val;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
switch (TYPE(val)) {
|
1998-01-16 07:19:22 -05:00
|
|
|
case T_FIXNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new((double)FIX2LONG(val));
|
1998-01-16 07:19:22 -05:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
case T_FLOAT:
|
1999-01-19 23:59:39 -05:00
|
|
|
return val;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
case T_BIGNUM:
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_float_new(rb_big2dbl(val));
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-12-25 01:29:27 -05:00
|
|
|
case T_STRING:
|
2002-02-01 05:23:22 -05:00
|
|
|
return rb_float_new(rb_str_to_dbl(val, Qtrue));
|
2000-12-25 01:29:27 -05:00
|
|
|
|
1999-08-13 01:45:20 -04:00
|
|
|
case T_NIL:
|
2002-06-28 10:42:46 -04:00
|
|
|
rb_raise(rb_eTypeError, "cannot convert nil into Float");
|
|
|
|
break;
|
1999-08-13 01:45:20 -04:00
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
default:
|
2002-06-28 10:42:46 -04:00
|
|
|
{
|
|
|
|
VALUE f = rb_convert_type(val, T_FLOAT, "Float", "to_f");
|
|
|
|
if (isnan(RFLOAT(f)->value)) {
|
|
|
|
rb_raise(rb_eArgError, "invalid value for Float()");
|
|
|
|
}
|
|
|
|
return f;
|
|
|
|
}
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
|
|
|
rb_f_float(obj, arg)
|
|
|
|
VALUE obj, arg;
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_Float(arg);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
double
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_num2dbl(val)
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE val;
|
|
|
|
{
|
1999-08-13 01:45:20 -04:00
|
|
|
switch (TYPE(val)) {
|
|
|
|
case T_FLOAT:
|
|
|
|
return RFLOAT(val)->value;
|
|
|
|
|
|
|
|
case T_STRING:
|
2001-10-02 00:31:23 -04:00
|
|
|
rb_raise(rb_eTypeError, "no implicit conversion to float from string");
|
1999-08-13 01:45:20 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_NIL:
|
2001-10-02 00:31:23 -04:00
|
|
|
rb_raise(rb_eTypeError, "no implicit conversion to float from nil");
|
1999-08-13 01:45:20 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RFLOAT(rb_Float(val))->value;
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
char*
|
|
|
|
rb_str2cstr(str, len)
|
|
|
|
VALUE str;
|
2002-08-21 11:47:54 -04:00
|
|
|
long *len;
|
1998-01-16 07:13:05 -05:00
|
|
|
{
|
2001-05-02 00:22:21 -04:00
|
|
|
StringValue(str);
|
1999-01-19 23:59:39 -05:00
|
|
|
if (len) *len = RSTRING(str)->len;
|
2002-04-11 06:03:01 -04:00
|
|
|
else if (RTEST(ruby_verbose) && RSTRING(str)->len != strlen(RSTRING(str)->ptr)) {
|
2001-03-28 03:43:25 -05:00
|
|
|
rb_warn("string contains \\0 character");
|
|
|
|
}
|
1999-01-19 23:59:39 -05:00
|
|
|
return RSTRING(str)->ptr;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE
|
|
|
|
rb_String(val)
|
|
|
|
VALUE val;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_convert_type(val, T_STRING, "String", "to_s");
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
1998-01-16 07:13:05 -05:00
|
|
|
static VALUE
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_f_string(obj, arg)
|
1998-01-16 07:13:05 -05:00
|
|
|
VALUE obj, arg;
|
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_String(arg);
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
|
|
|
|
2003-05-26 04:22:33 -04:00
|
|
|
#if 0
|
1998-01-16 07:19:22 -05:00
|
|
|
VALUE
|
|
|
|
rb_Array(val)
|
|
|
|
VALUE val;
|
|
|
|
{
|
2003-05-26 04:22:33 -04:00
|
|
|
VALUE tmp = rb_check_array_type(val);
|
|
|
|
ID to_a;
|
2000-09-12 01:37:38 -04:00
|
|
|
|
2003-05-26 04:22:33 -04:00
|
|
|
if (NIL_P(tmp)) {
|
|
|
|
to_a = rb_intern("to_a");
|
|
|
|
if (rb_respond_to(val, to_a)) {
|
|
|
|
val = rb_funcall(val, to_a, 0);
|
|
|
|
if (TYPE(val) != T_ARRAY) {
|
|
|
|
rb_raise(rb_eTypeError, "`to_a' did not return Array");
|
|
|
|
}
|
|
|
|
return val;
|
2003-03-28 21:56:18 -05:00
|
|
|
}
|
|
|
|
else {
|
2003-05-26 04:22:33 -04:00
|
|
|
return rb_ary_new3(1, val);
|
2003-03-28 21:56:18 -05:00
|
|
|
}
|
2000-09-12 01:37:38 -04:00
|
|
|
}
|
2003-05-26 04:22:33 -04:00
|
|
|
return tmp;
|
1998-01-16 07:19:22 -05:00
|
|
|
}
|
2003-05-26 04:22:33 -04:00
|
|
|
#endif
|
1998-01-16 07:19:22 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
static VALUE
|
|
|
|
rb_f_array(obj, arg)
|
|
|
|
VALUE obj, arg;
|
1998-01-16 07:19:22 -05:00
|
|
|
{
|
1999-01-19 23:59:39 -05:00
|
|
|
return rb_Array(arg);
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
boot_defclass(name, super)
|
|
|
|
char *name;
|
|
|
|
VALUE super;
|
|
|
|
{
|
|
|
|
extern st_table *rb_class_tbl;
|
2001-07-18 01:56:05 -04:00
|
|
|
VALUE obj = rb_class_boot(super);
|
1998-01-16 07:13:05 -05:00
|
|
|
ID id = rb_intern(name);
|
|
|
|
|
|
|
|
rb_name_class(obj, id);
|
|
|
|
st_add_direct(rb_class_tbl, id, obj);
|
1999-01-19 23:59:39 -05:00
|
|
|
return obj;
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
VALUE ruby_top_self;
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
Init_Object()
|
|
|
|
{
|
|
|
|
VALUE metaclass;
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_cObject = boot_defclass("Object", 0);
|
|
|
|
rb_cModule = boot_defclass("Module", rb_cObject);
|
|
|
|
rb_cClass = boot_defclass("Class", rb_cModule);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2002-01-10 15:18:39 -05:00
|
|
|
metaclass = rb_make_metaclass(rb_cObject, rb_cClass);
|
|
|
|
metaclass = rb_make_metaclass(rb_cModule, metaclass);
|
|
|
|
metaclass = rb_make_metaclass(rb_cClass, metaclass);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_mKernel = rb_define_module("Kernel");
|
|
|
|
rb_include_module(rb_cObject, rb_mKernel);
|
2002-12-20 03:33:17 -05:00
|
|
|
rb_define_alloc_func(rb_cObject, rb_class_allocate_instance);
|
2000-02-29 03:05:32 -05:00
|
|
|
rb_define_private_method(rb_cObject, "initialize", rb_obj_dummy, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_private_method(rb_cClass, "inherited", rb_obj_dummy, 1);
|
2001-05-11 01:24:59 -04:00
|
|
|
rb_define_private_method(rb_cModule, "included", rb_obj_dummy, 1);
|
|
|
|
rb_define_private_method(rb_cModule, "method_added", rb_obj_dummy, 1);
|
|
|
|
rb_define_private_method(rb_cModule, "method_removed", rb_obj_dummy, 1);
|
|
|
|
rb_define_private_method(rb_cModule, "method_undefined", rb_obj_dummy, 1);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ruby's Class Hierarchy Chart
|
|
|
|
*
|
|
|
|
* +------------------+
|
|
|
|
* | |
|
|
|
|
* Object---->(Object) |
|
|
|
|
* ^ ^ ^ ^ |
|
|
|
|
* | | | | |
|
|
|
|
* | | +-----+ +---------+ |
|
|
|
|
* | | | | |
|
|
|
|
* | +-----------+ | |
|
|
|
|
* | | | | |
|
|
|
|
* +------+ | Module--->(Module) |
|
|
|
|
* | | ^ ^ |
|
|
|
|
* OtherClass-->(OtherClass) | | |
|
|
|
|
* | | |
|
|
|
|
* Class---->(Class) |
|
|
|
|
* ^ |
|
|
|
|
* | |
|
|
|
|
* +----------------+
|
|
|
|
*
|
|
|
|
* + All metaclasses are instances of the class `Class'.
|
|
|
|
*/
|
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_mKernel, "nil?", rb_false, 0);
|
|
|
|
rb_define_method(rb_mKernel, "==", rb_obj_equal, 1);
|
2001-05-11 01:24:59 -04:00
|
|
|
rb_define_method(rb_mKernel, "equal?", rb_obj_equal, 1);
|
2003-02-03 03:45:26 -05:00
|
|
|
rb_define_method(rb_mKernel, "===", rb_equal, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_mKernel, "=~", rb_false, 1);
|
|
|
|
|
|
|
|
rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1);
|
|
|
|
|
2000-07-17 05:38:10 -04:00
|
|
|
rb_define_method(rb_mKernel, "hash", rb_obj_id, 0);
|
2002-11-03 06:04:35 -05:00
|
|
|
rb_define_method(rb_mKernel, "id", rb_obj_id_obsolete, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_mKernel, "__id__", rb_obj_id, 0);
|
2002-11-03 06:04:35 -05:00
|
|
|
rb_define_method(rb_mKernel, "object_id", rb_obj_id, 0);
|
2002-10-02 02:02:17 -04:00
|
|
|
rb_define_method(rb_mKernel, "type", rb_obj_type, 0);
|
2001-08-20 00:29:58 -04:00
|
|
|
rb_define_method(rb_mKernel, "class", rb_obj_class, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
rb_define_method(rb_mKernel, "clone", rb_obj_clone, 0);
|
|
|
|
rb_define_method(rb_mKernel, "dup", rb_obj_dup, 0);
|
2003-05-19 01:41:08 -04:00
|
|
|
rb_define_method(rb_mKernel, "initialize_copy", rb_obj_init_copy, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
rb_define_method(rb_mKernel, "taint", rb_obj_taint, 0);
|
|
|
|
rb_define_method(rb_mKernel, "tainted?", rb_obj_tainted, 0);
|
|
|
|
rb_define_method(rb_mKernel, "untaint", rb_obj_untaint, 0);
|
2000-01-31 22:12:21 -05:00
|
|
|
rb_define_method(rb_mKernel, "freeze", rb_obj_freeze, 0);
|
|
|
|
rb_define_method(rb_mKernel, "frozen?", rb_obj_frozen_p, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2002-06-28 10:42:46 -04:00
|
|
|
rb_define_method(rb_mKernel, "to_a", rb_any_to_a, 0); /* to be removed */
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_mKernel, "to_s", rb_any_to_s, 0);
|
|
|
|
rb_define_method(rb_mKernel, "inspect", rb_obj_inspect, 0);
|
2003-05-04 12:03:24 -04:00
|
|
|
rb_define_method(rb_mKernel, "methods", rb_obj_methods, -1);
|
2001-05-30 05:12:34 -04:00
|
|
|
rb_define_method(rb_mKernel, "singleton_methods", rb_obj_singleton_methods, -1);
|
2003-05-04 12:03:24 -04:00
|
|
|
rb_define_method(rb_mKernel, "protected_methods", rb_obj_protected_methods, -1);
|
|
|
|
rb_define_method(rb_mKernel, "private_methods", rb_obj_private_methods, -1);
|
|
|
|
rb_define_method(rb_mKernel, "public_methods", rb_obj_public_methods, -1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_mKernel, "instance_variables", rb_obj_instance_variables, 0);
|
2003-02-10 04:40:13 -05:00
|
|
|
rb_define_method(rb_mKernel, "instance_variable_get", rb_obj_ivar_get, 1);
|
|
|
|
rb_define_method(rb_mKernel, "instance_variable_set", rb_obj_ivar_set, 2);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_private_method(rb_mKernel, "remove_instance_variable",
|
2000-05-24 00:34:26 -04:00
|
|
|
rb_obj_remove_instance_variable, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
rb_define_method(rb_mKernel, "instance_of?", rb_obj_is_instance_of, 1);
|
|
|
|
rb_define_method(rb_mKernel, "kind_of?", rb_obj_is_kind_of, 1);
|
|
|
|
rb_define_method(rb_mKernel, "is_a?", rb_obj_is_kind_of, 1);
|
|
|
|
|
2003-05-02 02:41:33 -04:00
|
|
|
rb_define_private_method(rb_mKernel, "singleton_method_added", rb_obj_dummy, 1);
|
|
|
|
rb_define_private_method(rb_mKernel, "singleton_method_removed", rb_obj_dummy, 1);
|
|
|
|
rb_define_private_method(rb_mKernel, "singleton_method_undefined", rb_obj_dummy, 1);
|
1999-08-13 01:45:20 -04:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_global_function("sprintf", rb_f_sprintf, -1);
|
|
|
|
rb_define_global_function("format", rb_f_sprintf, -1);
|
|
|
|
|
|
|
|
rb_define_global_function("Integer", rb_f_integer, 1);
|
|
|
|
rb_define_global_function("Float", rb_f_float, 1);
|
|
|
|
|
|
|
|
rb_define_global_function("String", rb_f_string, 1);
|
|
|
|
rb_define_global_function("Array", rb_f_array, 1);
|
|
|
|
|
|
|
|
rb_cNilClass = rb_define_class("NilClass", rb_cObject);
|
|
|
|
rb_define_method(rb_cNilClass, "to_i", nil_to_i, 0);
|
2002-07-02 05:58:13 -04:00
|
|
|
rb_define_method(rb_cNilClass, "to_f", nil_to_f, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cNilClass, "to_s", nil_to_s, 0);
|
|
|
|
rb_define_method(rb_cNilClass, "to_a", nil_to_a, 0);
|
|
|
|
rb_define_method(rb_cNilClass, "inspect", nil_inspect, 0);
|
1999-08-13 01:45:20 -04:00
|
|
|
rb_define_method(rb_cNilClass, "&", false_and, 1);
|
|
|
|
rb_define_method(rb_cNilClass, "|", false_or, 1);
|
|
|
|
rb_define_method(rb_cNilClass, "^", false_xor, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
rb_define_method(rb_cNilClass, "nil?", rb_true, 0);
|
2002-12-20 03:33:17 -05:00
|
|
|
rb_undef_alloc_func(rb_cNilClass);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_undef_method(CLASS_OF(rb_cNilClass), "new");
|
1998-01-16 07:19:22 -05:00
|
|
|
rb_define_global_const("NIL", Qnil);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2000-03-07 03:37:59 -05:00
|
|
|
rb_cSymbol = rb_define_class("Symbol", rb_cObject);
|
2001-05-02 00:22:21 -04:00
|
|
|
rb_define_singleton_method(rb_cSymbol, "all_symbols", rb_sym_all_symbols, 0);
|
2002-12-20 03:33:17 -05:00
|
|
|
rb_undef_alloc_func(rb_cSymbol);
|
2001-10-03 03:19:19 -04:00
|
|
|
rb_undef_method(CLASS_OF(rb_cSymbol), "new");
|
2001-05-02 00:22:21 -04:00
|
|
|
|
2000-03-07 03:37:59 -05:00
|
|
|
rb_define_method(rb_cSymbol, "to_i", sym_to_i, 0);
|
2000-11-14 02:10:31 -05:00
|
|
|
rb_define_method(rb_cSymbol, "to_int", sym_to_i, 0);
|
2000-04-10 01:48:43 -04:00
|
|
|
rb_define_method(rb_cSymbol, "inspect", sym_inspect, 0);
|
2000-03-07 03:37:59 -05:00
|
|
|
rb_define_method(rb_cSymbol, "to_s", sym_to_s, 0);
|
2000-04-10 01:48:43 -04:00
|
|
|
rb_define_method(rb_cSymbol, "id2name", sym_to_s, 0);
|
2002-11-03 06:04:35 -05:00
|
|
|
rb_define_method(rb_cSymbol, "to_sym", sym_to_sym, 0);
|
2000-03-07 03:37:59 -05:00
|
|
|
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cModule, "===", rb_mod_eqq, 1);
|
2002-05-21 01:39:19 -04:00
|
|
|
rb_define_method(rb_cModule, "==", rb_obj_equal, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cModule, "<=>", rb_mod_cmp, 1);
|
|
|
|
rb_define_method(rb_cModule, "<", rb_mod_lt, 1);
|
|
|
|
rb_define_method(rb_cModule, "<=", rb_mod_le, 1);
|
|
|
|
rb_define_method(rb_cModule, ">", rb_mod_gt, 1);
|
|
|
|
rb_define_method(rb_cModule, ">=", rb_mod_ge, 1);
|
|
|
|
rb_define_method(rb_cModule, "clone", rb_mod_clone, 0);
|
2000-09-26 03:07:13 -04:00
|
|
|
rb_define_method(rb_cModule, "dup", rb_mod_dup, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cModule, "to_s", rb_mod_to_s, 0);
|
|
|
|
rb_define_method(rb_cModule, "included_modules", rb_mod_included_modules, 0);
|
2001-07-24 05:07:33 -04:00
|
|
|
rb_define_method(rb_cModule, "include?", rb_mod_include_p, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cModule, "name", rb_mod_name, 0);
|
|
|
|
rb_define_method(rb_cModule, "ancestors", rb_mod_ancestors, 0);
|
|
|
|
|
|
|
|
rb_define_private_method(rb_cModule, "attr", rb_mod_attr, -1);
|
|
|
|
rb_define_private_method(rb_cModule, "attr_reader", rb_mod_attr_reader, -1);
|
|
|
|
rb_define_private_method(rb_cModule, "attr_writer", rb_mod_attr_writer, -1);
|
|
|
|
rb_define_private_method(rb_cModule, "attr_accessor", rb_mod_attr_accessor, -1);
|
|
|
|
|
2002-12-20 03:33:17 -05:00
|
|
|
rb_define_alloc_func(rb_cModule, rb_module_s_alloc);
|
2002-01-23 02:30:43 -05:00
|
|
|
rb_define_method(rb_cModule, "initialize", rb_mod_initialize, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cModule, "instance_methods", rb_class_instance_methods, -1);
|
2002-10-30 03:04:32 -05:00
|
|
|
rb_define_method(rb_cModule, "public_instance_methods", rb_class_public_instance_methods, -1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cModule, "protected_instance_methods", rb_class_protected_instance_methods, -1);
|
|
|
|
rb_define_method(rb_cModule, "private_instance_methods", rb_class_private_instance_methods, -1);
|
|
|
|
|
1999-12-14 01:50:43 -05:00
|
|
|
rb_define_method(rb_cModule, "constants", rb_mod_constants, 0);
|
|
|
|
rb_define_method(rb_cModule, "const_get", rb_mod_const_get, 1);
|
|
|
|
rb_define_method(rb_cModule, "const_set", rb_mod_const_set, 2);
|
|
|
|
rb_define_method(rb_cModule, "const_defined?", rb_mod_const_defined, 1);
|
|
|
|
rb_define_private_method(rb_cModule, "remove_const", rb_mod_remove_const, 1);
|
2000-09-15 02:00:30 -04:00
|
|
|
rb_define_method(rb_cModule, "class_variables", rb_mod_class_variables, 0);
|
2000-12-08 02:10:38 -05:00
|
|
|
rb_define_private_method(rb_cModule, "remove_class_variable", rb_mod_remove_cvar, 1);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
2002-12-20 04:00:10 -05:00
|
|
|
rb_define_method(rb_cClass, "allocate", rb_obj_alloc, 0);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cClass, "new", rb_class_new_instance, -1);
|
2002-01-23 02:30:43 -05:00
|
|
|
rb_define_method(rb_cClass, "initialize", rb_class_initialize, -1);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0);
|
2002-12-20 03:33:17 -05:00
|
|
|
rb_undef_alloc_func(rb_cClass);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_define_singleton_method(rb_cClass, "new", rb_class_s_new, -1);
|
|
|
|
rb_undef_method(rb_cClass, "extend_object");
|
|
|
|
rb_undef_method(rb_cClass, "append_features");
|
|
|
|
|
|
|
|
rb_cData = rb_define_class("Data", rb_cObject);
|
2002-12-20 03:33:17 -05:00
|
|
|
rb_undef_alloc_func(rb_cData);
|
1999-01-19 23:59:39 -05:00
|
|
|
|
|
|
|
ruby_top_self = rb_obj_alloc(rb_cObject);
|
|
|
|
rb_global_variable(&ruby_top_self);
|
|
|
|
rb_define_singleton_method(ruby_top_self, "to_s", main_to_s, 0);
|
|
|
|
|
|
|
|
rb_cTrueClass = rb_define_class("TrueClass", rb_cObject);
|
|
|
|
rb_define_method(rb_cTrueClass, "to_s", true_to_s, 0);
|
|
|
|
rb_define_method(rb_cTrueClass, "&", true_and, 1);
|
|
|
|
rb_define_method(rb_cTrueClass, "|", true_or, 1);
|
|
|
|
rb_define_method(rb_cTrueClass, "^", true_xor, 1);
|
2002-12-20 03:33:17 -05:00
|
|
|
rb_undef_alloc_func(rb_cTrueClass);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_undef_method(CLASS_OF(rb_cTrueClass), "new");
|
|
|
|
rb_define_global_const("TRUE", Qtrue);
|
|
|
|
|
|
|
|
rb_cFalseClass = rb_define_class("FalseClass", rb_cObject);
|
|
|
|
rb_define_method(rb_cFalseClass, "to_s", false_to_s, 0);
|
|
|
|
rb_define_method(rb_cFalseClass, "&", false_and, 1);
|
|
|
|
rb_define_method(rb_cFalseClass, "|", false_or, 1);
|
|
|
|
rb_define_method(rb_cFalseClass, "^", false_xor, 1);
|
2002-12-20 03:33:17 -05:00
|
|
|
rb_undef_alloc_func(rb_cFalseClass);
|
1999-01-19 23:59:39 -05:00
|
|
|
rb_undef_method(CLASS_OF(rb_cFalseClass), "new");
|
|
|
|
rb_define_global_const("FALSE", Qfalse);
|
1998-01-16 07:13:05 -05:00
|
|
|
|
2003-05-19 01:41:08 -04:00
|
|
|
id_eq = rb_intern("==");
|
|
|
|
id_eql = rb_intern("eql?");
|
|
|
|
id_inspect = rb_intern("inspect");
|
|
|
|
id_init_copy = rb_intern("initialize_copy");
|
1998-01-16 07:13:05 -05:00
|
|
|
}
|