mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Mon Jan 19 14:06:13 JST 1998
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@23 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d556e58fc0
commit
5c47ddf9e7
14 changed files with 316 additions and 160 deletions
|
@ -1,7 +1,5 @@
|
||||||
Fri Jan 16 00:43:43 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
|
Fri Jan 16 00:43:43 1998 Yukihiro Matsumoto <matz@netlab.co.jp>
|
||||||
|
|
||||||
* variable.c (rb_ivar_get): Files can have instance variables now.
|
|
||||||
|
|
||||||
* ruby.h (CLONESETUP): copies its singleton classes too.
|
* ruby.h (CLONESETUP): copies its singleton classes too.
|
||||||
|
|
||||||
* class.c (singleton_class_attached): saves binded object in the
|
* class.c (singleton_class_attached): saves binded object in the
|
||||||
|
|
22
eval.c
22
eval.c
|
@ -43,6 +43,7 @@ static VALUE f_binding _((VALUE));
|
||||||
static void f_END _((void));
|
static void f_END _((void));
|
||||||
|
|
||||||
#define SCOPE_PRIVATE FL_USER4
|
#define SCOPE_PRIVATE FL_USER4
|
||||||
|
#define SCOPE_MODFUNC FL_USER5
|
||||||
|
|
||||||
#define CACHE_SIZE 0x200
|
#define CACHE_SIZE 0x200
|
||||||
#define CACHE_MASK 0x1ff
|
#define CACHE_MASK 0x1ff
|
||||||
|
@ -717,6 +718,7 @@ ruby_init()
|
||||||
top_scope = the_scope;
|
top_scope = the_scope;
|
||||||
/* default visibility is private at toplevel */
|
/* default visibility is private at toplevel */
|
||||||
FL_SET(top_scope, SCOPE_PRIVATE);
|
FL_SET(top_scope, SCOPE_PRIVATE);
|
||||||
|
FL_UNSET(top_scope, SCOPE_MODFUNC);
|
||||||
|
|
||||||
PUSH_TAG(PROT_NONE)
|
PUSH_TAG(PROT_NONE)
|
||||||
if ((state = EXEC_TAG()) == 0) {
|
if ((state = EXEC_TAG()) == 0) {
|
||||||
|
@ -2119,6 +2121,15 @@ rb_eval(self, node)
|
||||||
noex = NOEX_PUBLIC;
|
noex = NOEX_PUBLIC;
|
||||||
}
|
}
|
||||||
rb_add_method(the_class, node->nd_mid, node->nd_defn, noex);
|
rb_add_method(the_class, node->nd_mid, node->nd_defn, noex);
|
||||||
|
if (FL_TEST(the_scope,SCOPE_MODFUNC)) {
|
||||||
|
rb_add_method(rb_singleton_class(the_class),
|
||||||
|
node->nd_mid, node->nd_defn, NOEX_PUBLIC);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FL_TEST(the_scope, SCOPE_MODFUNC)) {
|
||||||
|
rb_funcall(the_class, rb_intern("singleton_method_added"),
|
||||||
|
1, INT2FIX(node->nd_mid));
|
||||||
|
}
|
||||||
if (FL_TEST(the_class, FL_SINGLETON)) {
|
if (FL_TEST(the_class, FL_SINGLETON)) {
|
||||||
VALUE recv = rb_iv_get(the_class, "__attached__");
|
VALUE recv = rb_iv_get(the_class, "__attached__");
|
||||||
rb_funcall(recv, rb_intern("singleton_method_added"),
|
rb_funcall(recv, rb_intern("singleton_method_added"),
|
||||||
|
@ -3746,6 +3757,7 @@ f_load(obj, fname)
|
||||||
}
|
}
|
||||||
/* default visibility is private at loading toplevel */
|
/* default visibility is private at loading toplevel */
|
||||||
FL_SET(the_scope, SCOPE_PRIVATE);
|
FL_SET(the_scope, SCOPE_PRIVATE);
|
||||||
|
FL_UNSET(top_scope, SCOPE_MODFUNC);
|
||||||
|
|
||||||
state = EXEC_TAG();
|
state = EXEC_TAG();
|
||||||
last_func = the_frame->last_func;
|
last_func = the_frame->last_func;
|
||||||
|
@ -3938,6 +3950,7 @@ mod_public(argc, argv, module)
|
||||||
{
|
{
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
FL_UNSET(the_scope, SCOPE_PRIVATE);
|
FL_UNSET(the_scope, SCOPE_PRIVATE);
|
||||||
|
FL_UNSET(top_scope, SCOPE_MODFUNC);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
set_method_visibility(module, argc, argv, NOEX_PUBLIC);
|
set_method_visibility(module, argc, argv, NOEX_PUBLIC);
|
||||||
|
@ -3953,6 +3966,7 @@ mod_private(argc, argv, module)
|
||||||
{
|
{
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
FL_SET(the_scope, SCOPE_PRIVATE);
|
FL_SET(the_scope, SCOPE_PRIVATE);
|
||||||
|
FL_UNSET(top_scope, SCOPE_MODFUNC);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
set_method_visibility(module, argc, argv, NOEX_PRIVATE);
|
set_method_visibility(module, argc, argv, NOEX_PRIVATE);
|
||||||
|
@ -4006,7 +4020,12 @@ mod_modfunc(argc, argv, module)
|
||||||
ID id;
|
ID id;
|
||||||
NODE *body;
|
NODE *body;
|
||||||
|
|
||||||
rb_clear_cache();
|
if (argc == 0) {
|
||||||
|
FL_SET(the_scope, SCOPE_PRIVATE);
|
||||||
|
FL_SET(the_scope, SCOPE_MODFUNC);
|
||||||
|
return module;
|
||||||
|
}
|
||||||
|
|
||||||
set_method_visibility(module, argc, argv, NOEX_PRIVATE);
|
set_method_visibility(module, argc, argv, NOEX_PRIVATE);
|
||||||
for (i=0; i<argc; i++) {
|
for (i=0; i<argc; i++) {
|
||||||
id = rb_to_id(argv[i]);
|
id = rb_to_id(argv[i]);
|
||||||
|
@ -4015,6 +4034,7 @@ mod_modfunc(argc, argv, module)
|
||||||
NameError("undefined method `%s' for module `%s'",
|
NameError("undefined method `%s' for module `%s'",
|
||||||
rb_id2name(id), rb_class2name(module));
|
rb_id2name(id), rb_class2name(module));
|
||||||
}
|
}
|
||||||
|
rb_clear_cache_by_id(id);
|
||||||
rb_add_method(rb_singleton_class(module), id, body->nd_body, NOEX_PUBLIC);
|
rb_add_method(rb_singleton_class(module), id, body->nd_body, NOEX_PUBLIC);
|
||||||
}
|
}
|
||||||
return module;
|
return module;
|
||||||
|
|
|
@ -10,3 +10,4 @@
|
||||||
#socket
|
#socket
|
||||||
#tkutil
|
#tkutil
|
||||||
#tcltklib
|
#tcltklib
|
||||||
|
gtk
|
||||||
|
|
|
@ -196,19 +196,20 @@ static void
|
||||||
gobj_free(obj)
|
gobj_free(obj)
|
||||||
GtkObject *obj;
|
GtkObject *obj;
|
||||||
{
|
{
|
||||||
VALUE self = get_value_from_gobject(obj);
|
/* just a type mark */
|
||||||
|
|
||||||
if (GTK_OBJECT_NEED_DESTROY(obj)) {
|
|
||||||
gtk_object_destroy(obj);
|
|
||||||
}
|
|
||||||
rb_ivar_set(self, id_relatives, Qnil);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
delete_gobject(obj)
|
delete_gobject(gtkobj, obj)
|
||||||
GtkObject *obj;
|
GtkObject *gtkobj;
|
||||||
|
VALUE obj;
|
||||||
{
|
{
|
||||||
ary_delete(gtk_object_list, get_value_from_gobject(obj));
|
struct RData *data;
|
||||||
|
|
||||||
|
data = RDATA(rb_ivar_get(obj, id_gtkdata));
|
||||||
|
data->dfree = 0;
|
||||||
|
data->data = 0;
|
||||||
|
ary_delete(gtk_object_list, obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
|
@ -223,7 +224,8 @@ make_gobject(klass, gtkobj)
|
||||||
gtk_object_set_user_data(gtkobj, (gpointer)obj);
|
gtk_object_set_user_data(gtkobj, (gpointer)obj);
|
||||||
|
|
||||||
rb_ivar_set(obj, id_gtkdata, data);
|
rb_ivar_set(obj, id_gtkdata, data);
|
||||||
gtk_signal_connect(gtkobj, "destroy", (GtkSignalFunc)delete_gobject, 0);
|
gtk_signal_connect(gtkobj, "destroy",
|
||||||
|
(GtkSignalFunc)delete_gobject, (gpointer)obj);
|
||||||
ary_push(gtk_object_list, obj);
|
ary_push(gtk_object_list, obj);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,11 @@ button = []
|
||||||
end
|
end
|
||||||
0.upto(8) do |i|
|
0.upto(8) do |i|
|
||||||
button[i].signal_connect("clicked") do |w|
|
button[i].signal_connect("clicked") do |w|
|
||||||
if button[i+1].visible?
|
j = (i+1)%9
|
||||||
button[i+1].hide
|
if button[j].visible?
|
||||||
|
button[j].hide
|
||||||
else
|
else
|
||||||
button[i+1].show
|
button[j].show
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
button[i].show
|
button[i].show
|
||||||
|
|
96
ext/gtk/testd.rb
Normal file
96
ext/gtk/testd.rb
Normal file
|
@ -0,0 +1,96 @@
|
||||||
|
require 'gtk'
|
||||||
|
|
||||||
|
def create_menu(depth)
|
||||||
|
return nil if depth < 1
|
||||||
|
|
||||||
|
menu = Gtk::Menu::new()
|
||||||
|
group = nil
|
||||||
|
submenu = nil
|
||||||
|
|
||||||
|
for i in 0..4
|
||||||
|
buf = sprintf("item %2d - %d", depth, i+1)
|
||||||
|
# menuitem = Gtk::MenuItem::new(buf)
|
||||||
|
menuitem = Gtk::RadioMenuItem.new(group, buf)
|
||||||
|
group = menuitem.group
|
||||||
|
if depth % 2
|
||||||
|
menuitem.set_show_toggle TRUE
|
||||||
|
end
|
||||||
|
menu.append menuitem
|
||||||
|
menuitem.show
|
||||||
|
if depth > 0
|
||||||
|
unless submenu
|
||||||
|
submenu = create_menu(depth - 1)
|
||||||
|
end
|
||||||
|
menuitem.set_submenu submenu
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return menu
|
||||||
|
end
|
||||||
|
|
||||||
|
window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
|
||||||
|
window.signal_connect("destroy") do
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
window.signal_connect("delete_event") do
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
window.set_title("menus")
|
||||||
|
window.border_width(0)
|
||||||
|
|
||||||
|
box1 = Gtk::VBox::new(FALSE, 0)
|
||||||
|
window.add box1
|
||||||
|
box1.show
|
||||||
|
|
||||||
|
menubar = Gtk::MenuBar::new()
|
||||||
|
box1.pack_start menubar, FALSE, TRUE, 0
|
||||||
|
menubar.show
|
||||||
|
|
||||||
|
menu = create_menu(2)
|
||||||
|
menuitem = Gtk::MenuItem::new("test\nline2")
|
||||||
|
menuitem.set_submenu menu
|
||||||
|
menubar.append menuitem
|
||||||
|
menuitem.show
|
||||||
|
|
||||||
|
menuitem = Gtk::MenuItem::new("foo")
|
||||||
|
menuitem.set_submenu menu
|
||||||
|
menubar.append menuitem
|
||||||
|
menuitem.show
|
||||||
|
|
||||||
|
menuitem = Gtk::MenuItem::new("bar")
|
||||||
|
menuitem.set_submenu menu
|
||||||
|
menubar.append menuitem
|
||||||
|
menuitem.show
|
||||||
|
|
||||||
|
box2 = Gtk::VBox::new(FALSE, 10)
|
||||||
|
box2.border_width 10
|
||||||
|
box1.pack_start box2, TRUE, TRUE, 0
|
||||||
|
box2.show
|
||||||
|
|
||||||
|
optionmenu = Gtk::OptionMenu::new()
|
||||||
|
optionmenu.set_menu create_menu(1)
|
||||||
|
optionmenu.set_history 4
|
||||||
|
box2.pack_start optionmenu, TRUE, TRUE, 0
|
||||||
|
optionmenu.show
|
||||||
|
|
||||||
|
separator = Gtk::HSeparator::new()
|
||||||
|
box1.pack_start(separator, FALSE, TRUE, 0)
|
||||||
|
separator.show
|
||||||
|
|
||||||
|
box2 = Gtk::HBox::new(FALSE, 10)
|
||||||
|
box2.border_width(10)
|
||||||
|
box1.pack_start(box2, FALSE, TRUE, 0)
|
||||||
|
box2.show
|
||||||
|
|
||||||
|
button = Gtk::Button::new("close")
|
||||||
|
button.signal_connect("clicked") do
|
||||||
|
window.destroy
|
||||||
|
exit
|
||||||
|
end
|
||||||
|
box2.pack_start(button, TRUE, TRUE, 0)
|
||||||
|
button.set_flags(Gtk::CAN_DEFAULT);
|
||||||
|
button.grab_default
|
||||||
|
button.show
|
||||||
|
|
||||||
|
window.show
|
||||||
|
|
||||||
|
Gtk::main()
|
41
lib/final.rb
Normal file
41
lib/final.rb
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#
|
||||||
|
# $Id$
|
||||||
|
# Copyright (C) 1998 Yukihiro Matsumoto. All rights reserved.
|
||||||
|
|
||||||
|
# The ObjectSpace extention:
|
||||||
|
#
|
||||||
|
# ObjectSpace.define_finalizer(obj, proc=lambda())
|
||||||
|
#
|
||||||
|
# Defines the finalizer for the specified object.
|
||||||
|
#
|
||||||
|
# ObjectSpace.undefine_finalizer(obj)
|
||||||
|
#
|
||||||
|
# Removes the finalizers for the object. If multiple finalizers are
|
||||||
|
# defined for the object, all finalizers will be removed.
|
||||||
|
#
|
||||||
|
|
||||||
|
module ObjectSpace
|
||||||
|
Finalizer = {}
|
||||||
|
def define_finalizer(obj, proc=lambda())
|
||||||
|
ObjectSpace.call_finalizer(obj)
|
||||||
|
if assoc = Finalizer[obj.id]
|
||||||
|
assoc.push(proc)
|
||||||
|
else
|
||||||
|
Finalizer[obj.id] = [proc]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def undefine_finalizer(obj)
|
||||||
|
Finalizer.delete(obj.id)
|
||||||
|
end
|
||||||
|
module_function :define_finalizer, :remove_finalizer
|
||||||
|
|
||||||
|
Generic_Finalizer = proc {|id|
|
||||||
|
if Finalizer.key? id
|
||||||
|
for proc in Finalizer[id]
|
||||||
|
proc.call(id)
|
||||||
|
end
|
||||||
|
Finalizer.delete(id)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
add_finalizer Generic_Finalizer
|
||||||
|
end
|
113
lib/finalize.rb
113
lib/finalize.rb
|
@ -1,8 +1,8 @@
|
||||||
#
|
#
|
||||||
# finalizer.rb -
|
# finalizer.rb -
|
||||||
# $Release Version: 0.2$
|
# $Release Version: 0.2$
|
||||||
# $Revision: 1.1.1.2 $
|
# $Revision: 1.1.1.2.2.1 $
|
||||||
# $Date: 1998/01/16 04:14:51 $
|
# $Date: 1998/01/16 12:36:04 $
|
||||||
# by Keiju ISHITSUKA
|
# by Keiju ISHITSUKA
|
||||||
#
|
#
|
||||||
# --
|
# --
|
||||||
|
@ -13,10 +13,10 @@
|
||||||
# add_dependency(obj, dependant, method = :finalize, *opt)
|
# add_dependency(obj, dependant, method = :finalize, *opt)
|
||||||
# 依存関係 R_method(obj, dependant) の追加
|
# 依存関係 R_method(obj, dependant) の追加
|
||||||
#
|
#
|
||||||
# delete(obj_or_id, dependant, method = :finalize)
|
# delete(obj, dependant, method = :finalize)
|
||||||
# delete_dependency(obj_or_id, dependant, method = :finalize)
|
# delete_dependency(obj, dependant, method = :finalize)
|
||||||
# 依存関係 R_method(obj, dependant) の削除
|
# 依存関係 R_method(obj, dependant) の削除
|
||||||
# delete_all_dependency(obj_or_id, dependant)
|
# delete_all_dependency(obj, dependant)
|
||||||
# 依存関係 R_*(obj, dependant) の削除
|
# 依存関係 R_*(obj, dependant) の削除
|
||||||
# delete_by_dependant(dependant, method = :finalize)
|
# delete_by_dependant(dependant, method = :finalize)
|
||||||
# 依存関係 R_method(*, dependant) の削除
|
# 依存関係 R_method(*, dependant) の削除
|
||||||
|
@ -25,11 +25,11 @@
|
||||||
# delete_all
|
# delete_all
|
||||||
# 全ての依存関係の削除.
|
# 全ての依存関係の削除.
|
||||||
#
|
#
|
||||||
# finalize(obj_or_id, dependant, method = :finalize)
|
# finalize(obj, dependant, method = :finalize)
|
||||||
# finalize_dependency(obj_or_id, dependant, method = :finalize)
|
# finalize_dependency(obj, dependant, method = :finalize)
|
||||||
# 依存関連 R_method(obj, dependtant) で結ばれるdependantを
|
# 依存関連 R_method(obj, dependtant) で結ばれるdependantを
|
||||||
# finalizeする.
|
# finalizeする.
|
||||||
# finalize_all_dependency(obj_or_id, dependant)
|
# finalize_all_dependency(obj, dependant)
|
||||||
# 依存関連 R_*(obj, dependtant) で結ばれるdependantをfinalizeする.
|
# 依存関連 R_*(obj, dependtant) で結ばれるdependantをfinalizeする.
|
||||||
# finalize_by_dependant(dependant, method = :finalize)
|
# finalize_by_dependant(dependant, method = :finalize)
|
||||||
# 依存関連 R_method(*, dependtant) で結ばれるdependantをfinalizeする.
|
# 依存関連 R_method(*, dependtant) で結ばれるdependantをfinalizeする.
|
||||||
|
@ -44,47 +44,43 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
module Finalizer
|
module Finalizer
|
||||||
RCS_ID='-$Header: /home/cvsroot/ruby/lib/finalize.rb,v 1.1.1.2 1998/01/16 04:14:51 matz Exp $-'
|
RCS_ID='-$Header: /home/cvsroot/ruby/lib/finalize.rb,v 1.1.1.2.2.1 1998/01/16 12:36:04 matz Exp $-'
|
||||||
|
|
||||||
# @dependency: {id => [[dependant, method, *opt], ...], ...}
|
# Dependency: {id => [[dependant, method, opt], ...], ...}
|
||||||
|
Dependency = {}
|
||||||
|
|
||||||
# 依存関係 R_method(obj, dependant) の追加
|
# 依存関係 R_method(obj, dependant) の追加
|
||||||
def add_dependency(obj, dependant, method = :finalize, *opt)
|
def add_dependency(obj, dependant, method = :finalize, *opt)
|
||||||
ObjectSpace.call_finalizer(obj)
|
ObjectSpace.call_finalizer(obj)
|
||||||
method = method.intern unless method.kind_of?(Integer)
|
assoc = [dependant, method, opt]
|
||||||
assoc = [dependant, method].concat(opt)
|
if dep = Dependency[obj.id]
|
||||||
if dep = @dependency[obj.id]
|
|
||||||
dep.push assoc
|
dep.push assoc
|
||||||
else
|
else
|
||||||
@dependency[obj.id] = [assoc]
|
Dependency[obj.id] = [assoc]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias add add_dependency
|
alias add add_dependency
|
||||||
|
|
||||||
# 依存関係 R_method(obj, dependant) の削除
|
# 依存関係 R_method(obj, dependant) の削除
|
||||||
def delete_dependency(id, dependant, method = :finalize)
|
def delete_dependency(obj, dependant, method = :finalize)
|
||||||
id = id.id unless id.kind_of?(Integer)
|
id = obj.id
|
||||||
method = method.intern unless method.kind_of?(Integer)
|
for assoc in Dependency[id]
|
||||||
for assoc in @dependency[id]
|
assoc.delete_if do |d,m,*o|
|
||||||
assoc.delete_if do
|
|
||||||
|d, m, *o|
|
|
||||||
d == dependant && m == method
|
d == dependant && m == method
|
||||||
end
|
end
|
||||||
@dependency.delete(id) if assoc.empty?
|
Dependency.delete(id) if assoc.empty?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias delete delete_dependency
|
alias delete delete_dependency
|
||||||
|
|
||||||
# 依存関係 R_*(obj, dependant) の削除
|
# 依存関係 R_*(obj, dependant) の削除
|
||||||
def delete_all_dependency(id, dependant)
|
def delete_all_dependency(obj, dependant)
|
||||||
id = id.id unless id.kind_of?(Integer)
|
id = obj.id
|
||||||
method = method.intern unless method.kind_of?(Integer)
|
for assoc in Dependency[id]
|
||||||
for assoc in @dependency[id]
|
assoc.delete_if do |d,m,*o|
|
||||||
assoc.delete_if do
|
|
||||||
|d, m, *o|
|
|
||||||
d == dependant
|
d == dependant
|
||||||
end
|
end
|
||||||
@dependency.delete(id) if assoc.empty?
|
Dependency.delete(id) if assoc.empty?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -98,58 +94,60 @@ module Finalizer
|
||||||
|
|
||||||
# 依存関係 R_*(*, dependant) の削除
|
# 依存関係 R_*(*, dependant) の削除
|
||||||
def delete_all_by_dependant(dependant)
|
def delete_all_by_dependant(dependant)
|
||||||
for id in @dependency.keys
|
for id in Dependency.keys
|
||||||
delete_all_dependency(id, dependant)
|
delete_all_dependency(id, dependant)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# 依存関連 R_method(obj, dependtant) で結ばれるdependantをfinalizeす
|
# 依存関連 R_method(id, dependtant) で結ばれるdependantをfinalizeす
|
||||||
# る.
|
# る.
|
||||||
def finalize_dependency(id, dependant, method = :finalize)
|
def finalize_dependency(id, dependant, method = :finalize)
|
||||||
id = id.id unless id.kind_of?(Integer)
|
for assocs in Dependency[id]
|
||||||
method = method.intern unless method.kind_of?(Integer)
|
assocs.delete_if do |d, m, *o|
|
||||||
for assocs in @dependency[id]
|
if d == dependant && m == method
|
||||||
assocs.delete_if do
|
d.send(m, *o)
|
||||||
|d, m, *o|
|
true
|
||||||
d.send(m, *o) if ret = d == dependant && m == method
|
else
|
||||||
ret
|
false
|
||||||
end
|
end
|
||||||
@dependency.delete(id) if assoc.empty?
|
end
|
||||||
|
Dependency.delete(id) if assoc.empty?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
alias finalize finalize_dependency
|
alias finalize finalize_dependency
|
||||||
|
|
||||||
# 依存関連 R_*(obj, dependtant) で結ばれるdependantをfinalizeする.
|
# 依存関連 R_*(id, dependtant) で結ばれるdependantをfinalizeする.
|
||||||
def finalize_all_dependency(id, dependant)
|
def finalize_all_dependency(id, dependant)
|
||||||
id = id.id unless id.kind_of?(Integer)
|
for assoc in Dependency[id]
|
||||||
method = method.intern unless method.kind_of?(Integer)
|
assoc.delete_if do |d, m, *o|
|
||||||
for assoc in @dependency[id]
|
if d == dependant
|
||||||
assoc.delete_if do
|
d.send(m, *o)
|
||||||
|d, m, *o|
|
true
|
||||||
d.send(m, *o) if ret = d == dependant
|
else
|
||||||
|
false
|
||||||
end
|
end
|
||||||
@dependency.delete(id) if assoc.empty?
|
end
|
||||||
|
Dependency.delete(id) if assoc.empty?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# 依存関連 R_method(*, dependtant) で結ばれるdependantをfinalizeする.
|
# 依存関連 R_method(*, dependtant) で結ばれるdependantをfinalizeする.
|
||||||
def finalize_by_dependant(dependant, method = :finalize)
|
def finalize_by_dependant(dependant, method = :finalize)
|
||||||
method = method.intern unless method.kind_of?(Integer)
|
for id in Dependency.keys
|
||||||
for id in @dependency.keys
|
|
||||||
finalize(id, dependant, method)
|
finalize(id, dependant, method)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# 依存関連 R_*(*, dependtant) で結ばれるdependantをfinalizeする.
|
# 依存関連 R_*(*, dependtant) で結ばれるdependantをfinalizeする.
|
||||||
def fainalize_all_by_dependant(dependant)
|
def fainalize_all_by_dependant(dependant)
|
||||||
for id in @dependency.keys
|
for id in Dependency.keys
|
||||||
finalize_all_dependency(id, dependant)
|
finalize_all_dependency(id, dependant)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Finalizerに登録されている全てのdependantをfinalizeする
|
# Finalizerに登録されている全てのdependantをfinalizeする
|
||||||
def finalize_all
|
def finalize_all
|
||||||
for id, assocs in @dependency
|
for id, assocs in Dependency
|
||||||
for dependant, method, *opt in assocs
|
for dependant, method, *opt in assocs
|
||||||
dependant.send(method, id, *opt)
|
dependant.send(method, id, *opt)
|
||||||
end
|
end
|
||||||
|
@ -159,26 +157,24 @@ module Finalizer
|
||||||
|
|
||||||
# finalize_* を安全に呼び出すためのイテレータ
|
# finalize_* を安全に呼び出すためのイテレータ
|
||||||
def safe
|
def safe
|
||||||
old_status = Thread.critical
|
old_status, Thread.critical = Thread.critical, true
|
||||||
Thread.critical = TRUE
|
ObjectSpace.remove_finalizer(Proc)
|
||||||
ObjectSpace.remove_finalizer(@proc)
|
|
||||||
yield
|
yield
|
||||||
ObjectSpace.add_finalizer(@proc)
|
ObjectSpace.add_finalizer(Proc)
|
||||||
Thread.critical = old_status
|
Thread.critical = old_status
|
||||||
end
|
end
|
||||||
|
|
||||||
# ObjectSpace#add_finalizerへの登録関数
|
# ObjectSpace#add_finalizerへの登録関数
|
||||||
def final_of(id)
|
def final_of(id)
|
||||||
if assocs = @dependency.delete(id)
|
if assocs = Dependency.delete(id)
|
||||||
for dependant, method, *opt in assocs
|
for dependant, method, *opt in assocs
|
||||||
dependant.send(method, id, *opt)
|
dependant.send(method, id, *opt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@dependency = Hash.new
|
Proc = proc{|id| final_of(id)}
|
||||||
@proc = proc{|id| final_of(id)}
|
ObjectSpace.add_finalizer(Proc)
|
||||||
ObjectSpace.add_finalizer(@proc)
|
|
||||||
|
|
||||||
module_function :add
|
module_function :add
|
||||||
module_function :add_dependency
|
module_function :add_dependency
|
||||||
|
@ -202,4 +198,3 @@ module Finalizer
|
||||||
private_class_method :final_of
|
private_class_method :final_of
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
### ftplib.rb -*- Mode: ruby; tab-width: 8; -*-
|
### ftplib.rb -*- Mode: ruby; tab-width: 8; -*-
|
||||||
|
|
||||||
## $Revision: 1.1.1.1 $
|
## $Revision: 1.1.1.1.4.1 $
|
||||||
## $Date: 1998/01/16 04:05:49 $
|
## $Date: 1998/01/16 12:36:05 $
|
||||||
## by maeda shugo <shugo@po.aianet.ne.jp>
|
## by maeda shugo <shugo@po.aianet.ne.jp>
|
||||||
|
|
||||||
### Code:
|
### Code:
|
||||||
|
@ -17,7 +17,7 @@ class FTPProtoError < FTPError; end
|
||||||
|
|
||||||
class FTP
|
class FTP
|
||||||
|
|
||||||
RCS_ID = '$Id: ftplib.rb,v 1.1.1.1 1998/01/16 04:05:49 matz Exp $'
|
RCS_ID = '$Id: ftplib.rb,v 1.1.1.1.4.1 1998/01/16 12:36:05 matz Exp $ '
|
||||||
|
|
||||||
FTP_PORT = 21
|
FTP_PORT = 21
|
||||||
CRLF = "\r\n"
|
CRLF = "\r\n"
|
||||||
|
|
|
@ -43,7 +43,7 @@ unless defined? Thread
|
||||||
fail "Thread not available for this ruby interpreter"
|
fail "Thread not available for this ruby interpreter"
|
||||||
end
|
end
|
||||||
|
|
||||||
require "finalize"
|
require "final"
|
||||||
|
|
||||||
module Sync_m
|
module Sync_m
|
||||||
RCS_ID='-$Header$-'
|
RCS_ID='-$Header$-'
|
||||||
|
@ -321,7 +321,11 @@ module Sync_m
|
||||||
def For_primitive_object.extend_object(obj)
|
def For_primitive_object.extend_object(obj)
|
||||||
super
|
super
|
||||||
obj.sync_extended
|
obj.sync_extended
|
||||||
Finalizer.add(obj, For_primitive_object, :sync_finalize)
|
# Changed to use `final.rb'.
|
||||||
|
# Finalizer.add(obj, For_primitive_object, :sync_finalize)
|
||||||
|
ObjectSpace.define_finalizer(obj) do |id|
|
||||||
|
For_primitive_object.sync_finalize(id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
# The class for temporary files.
|
# The class for temporary files.
|
||||||
# o creates a temporary file, which name is "basename.pid.n" with mode "w+".
|
# o creates a temporary file, which name is "basename.pid.n" with mode "w+".
|
||||||
# o Tempfile objects can be used like IO object.
|
# o Tempfile objects can be used like IO object.
|
||||||
# o created temporary files are removed if it is closed or garbage collected,
|
# o created temporary files are removed on closing or script termination.
|
||||||
# or script termination.
|
|
||||||
# o file mode of the temporary files are 0600.
|
# o file mode of the temporary files are 0600.
|
||||||
|
|
||||||
require 'delegate'
|
require 'delegate'
|
||||||
|
require 'final'
|
||||||
|
|
||||||
class Tempfile < SimpleDelegater
|
class Tempfile < SimpleDelegater
|
||||||
Max_try = 10
|
Max_try = 10
|
||||||
|
@ -45,8 +45,7 @@ class Tempfile < SimpleDelegater
|
||||||
File.unlink(@tmpdir + '/' + @tmpname + '.lock')
|
File.unlink(@tmpdir + '/' + @tmpname + '.lock')
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
ObjectSpace.call_finalizer(self)
|
ObjectSpace.define_finalizer(self, @clean_files)
|
||||||
ObjectSpace.add_finalizer(@clean_files)
|
|
||||||
|
|
||||||
@tmpfile = open(@tmpname, 'w+')
|
@tmpfile = open(@tmpname, 'w+')
|
||||||
super(@tmpfile)
|
super(@tmpfile)
|
||||||
|
@ -57,8 +56,13 @@ class Tempfile < SimpleDelegater
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def Tempfile.open(*args)
|
||||||
|
Tempfile.new(*args)
|
||||||
|
end
|
||||||
|
|
||||||
def close
|
def close
|
||||||
super
|
@tmpfile.close
|
||||||
@clean_files.call
|
@clean_files.call
|
||||||
|
ObjectSpace.undefine_finalizer(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
1
ruby.h
1
ruby.h
|
@ -227,7 +227,6 @@ struct RHash {
|
||||||
|
|
||||||
struct RFile {
|
struct RFile {
|
||||||
struct RBasic basic;
|
struct RBasic basic;
|
||||||
struct st_table *iv_tbl;
|
|
||||||
struct OpenFile *fptr;
|
struct OpenFile *fptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -633,7 +633,7 @@ An end of a defun is found by moving forward from the beginning of one."
|
||||||
2 font-lock-type-face)
|
2 font-lock-type-face)
|
||||||
;; functions
|
;; functions
|
||||||
'("^\\s *def[ \t]+.*$"
|
'("^\\s *def[ \t]+.*$"
|
||||||
0 font-lock-function-name-face))
|
0 font-lock-function-name-face t))
|
||||||
"*Additional expressions to highlight in ruby mode.")
|
"*Additional expressions to highlight in ruby mode.")
|
||||||
(if (and (>= (string-to-int emacs-version) 20)
|
(if (and (>= (string-to-int emacs-version) 20)
|
||||||
(not (featurep 'xemacs)))
|
(not (featurep 'xemacs)))
|
||||||
|
|
133
variable.c
133
variable.c
|
@ -97,14 +97,14 @@ fc_i(key, value, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
find_class_path(cls)
|
find_class_path(klass)
|
||||||
VALUE cls;
|
VALUE klass;
|
||||||
{
|
{
|
||||||
struct fc_result arg;
|
struct fc_result arg;
|
||||||
|
|
||||||
arg.name = 0;
|
arg.name = 0;
|
||||||
arg.path = 0;
|
arg.path = 0;
|
||||||
arg.klass = cls;
|
arg.klass = klass;
|
||||||
arg.track = cObject;
|
arg.track = cObject;
|
||||||
arg.prev = 0;
|
arg.prev = 0;
|
||||||
if (RCLASS(cObject)->iv_tbl) {
|
if (RCLASS(cObject)->iv_tbl) {
|
||||||
|
@ -114,30 +114,30 @@ find_class_path(cls)
|
||||||
st_foreach(class_tbl, fc_i, &arg);
|
st_foreach(class_tbl, fc_i, &arg);
|
||||||
}
|
}
|
||||||
if (arg.name) {
|
if (arg.name) {
|
||||||
rb_iv_set(cls, "__classpath__", arg.path);
|
rb_iv_set(klass, "__classpath__", arg.path);
|
||||||
return arg.path;
|
return arg.path;
|
||||||
}
|
}
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
classname(cls)
|
classname(klass)
|
||||||
VALUE cls;
|
VALUE klass;
|
||||||
{
|
{
|
||||||
VALUE path;
|
VALUE path;
|
||||||
|
|
||||||
while (TYPE(cls) == T_ICLASS || FL_TEST(cls, FL_SINGLETON)) {
|
while (TYPE(klass) == T_ICLASS || FL_TEST(klass, FL_SINGLETON)) {
|
||||||
cls = (VALUE)RCLASS(cls)->super;
|
klass = (VALUE)RCLASS(klass)->super;
|
||||||
}
|
}
|
||||||
path = rb_iv_get(cls, "__classpath__");
|
path = rb_iv_get(klass, "__classpath__");
|
||||||
if (NIL_P(path)) {
|
if (NIL_P(path)) {
|
||||||
path = rb_iv_get(cls, "__classid__");
|
path = rb_iv_get(klass, "__classid__");
|
||||||
if (!NIL_P(path)) {
|
if (!NIL_P(path)) {
|
||||||
path = str_new2(rb_id2name(FIX2INT(path)));
|
path = str_new2(rb_id2name(FIX2INT(path)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (NIL_P(path)) {
|
if (NIL_P(path)) {
|
||||||
path = find_class_path(cls);
|
path = find_class_path(klass);
|
||||||
if (NIL_P(path)) {
|
if (NIL_P(path)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -158,25 +158,25 @@ mod_name(mod)
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_class_path(cls)
|
rb_class_path(klass)
|
||||||
VALUE cls;
|
VALUE klass;
|
||||||
{
|
{
|
||||||
VALUE path = classname(cls);
|
VALUE path = classname(klass);
|
||||||
|
|
||||||
if (path) return path;
|
if (path) return path;
|
||||||
else {
|
else {
|
||||||
char buf[256];
|
char buf[256];
|
||||||
char *s = "Class";
|
char *s = "Class";
|
||||||
|
|
||||||
if (TYPE(cls) == T_MODULE) s = "Module";
|
if (TYPE(klass) == T_MODULE) s = "Module";
|
||||||
sprintf(buf, "#<%s 0x%x>", s, cls);
|
sprintf(buf, "#<%s 0x%x>", s, klass);
|
||||||
return str_new2(buf);
|
return str_new2(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_set_class_path(cls, under, name)
|
rb_set_class_path(klass, under, name)
|
||||||
VALUE cls, under;
|
VALUE klass, under;
|
||||||
char *name;
|
char *name;
|
||||||
{
|
{
|
||||||
VALUE str;
|
VALUE str;
|
||||||
|
@ -189,7 +189,7 @@ rb_set_class_path(cls, under, name)
|
||||||
str_cat(str, "::", 2);
|
str_cat(str, "::", 2);
|
||||||
str_cat(str, name, strlen(name));
|
str_cat(str, name, strlen(name));
|
||||||
}
|
}
|
||||||
rb_iv_set(cls, "__classpath__", str);
|
rb_iv_set(klass, "__classpath__", str);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
|
@ -203,17 +203,17 @@ rb_path2class(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_name_class(cls, id)
|
rb_name_class(klass, id)
|
||||||
VALUE cls;
|
VALUE klass;
|
||||||
ID id;
|
ID id;
|
||||||
{
|
{
|
||||||
extern VALUE cString;
|
extern VALUE cString;
|
||||||
|
|
||||||
if (cString) {
|
if (cString) {
|
||||||
rb_iv_set(cls, "__classpath__", str_new2(rb_id2name(id)));
|
rb_iv_set(klass, "__classpath__", str_new2(rb_id2name(id)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_iv_set(cls, "__classid__", INT2FIX(id));
|
rb_iv_set(klass, "__classid__", INT2FIX(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,17 +235,17 @@ rb_autoload_id(id, filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_autoload(cls, filename)
|
rb_autoload(klass, filename)
|
||||||
char *cls, *filename;
|
char *klass, *filename;
|
||||||
{
|
{
|
||||||
rb_autoload_id(rb_intern(cls), filename);
|
rb_autoload_id(rb_intern(klass), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
f_autoload(obj, cls, file)
|
f_autoload(obj, klass, file)
|
||||||
VALUE obj, cls, file;
|
VALUE obj, klass, file;
|
||||||
{
|
{
|
||||||
ID id = rb_to_id(cls);
|
ID id = rb_to_id(klass);
|
||||||
|
|
||||||
Check_Type(file, T_STRING);
|
Check_Type(file, T_STRING);
|
||||||
rb_autoload_id(id, RSTRING(file)->ptr);
|
rb_autoload_id(id, RSTRING(file)->ptr);
|
||||||
|
@ -253,10 +253,10 @@ f_autoload(obj, cls, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
rb_class2name(cls)
|
rb_class2name(klass)
|
||||||
VALUE cls;
|
VALUE klass;
|
||||||
{
|
{
|
||||||
return RSTRING(rb_class_path(cls))->ptr;
|
return RSTRING(rb_class_path(klass))->ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct trace_var {
|
struct trace_var {
|
||||||
|
@ -702,7 +702,6 @@ rb_ivar_get(obj, id)
|
||||||
case T_OBJECT:
|
case T_OBJECT:
|
||||||
case T_CLASS:
|
case T_CLASS:
|
||||||
case T_MODULE:
|
case T_MODULE:
|
||||||
case T_FILE:
|
|
||||||
if (ROBJECT(obj)->iv_tbl && st_lookup(ROBJECT(obj)->iv_tbl, id, &val))
|
if (ROBJECT(obj)->iv_tbl && st_lookup(ROBJECT(obj)->iv_tbl, id, &val))
|
||||||
return val;
|
return val;
|
||||||
return Qnil;
|
return Qnil;
|
||||||
|
@ -729,7 +728,6 @@ rb_ivar_set(obj, id, val)
|
||||||
case T_OBJECT:
|
case T_OBJECT:
|
||||||
case T_CLASS:
|
case T_CLASS:
|
||||||
case T_MODULE:
|
case T_MODULE:
|
||||||
case T_FILE:
|
|
||||||
if (!ROBJECT(obj)->iv_tbl) ROBJECT(obj)->iv_tbl = new_idhash();
|
if (!ROBJECT(obj)->iv_tbl) ROBJECT(obj)->iv_tbl = new_idhash();
|
||||||
st_insert(ROBJECT(obj)->iv_tbl, id, val);
|
st_insert(ROBJECT(obj)->iv_tbl, id, val);
|
||||||
break;
|
break;
|
||||||
|
@ -752,7 +750,6 @@ rb_ivar_defined(obj, id)
|
||||||
case T_OBJECT:
|
case T_OBJECT:
|
||||||
case T_CLASS:
|
case T_CLASS:
|
||||||
case T_MODULE:
|
case T_MODULE:
|
||||||
case T_FILE:
|
|
||||||
if (ROBJECT(obj)->iv_tbl && st_lookup(ROBJECT(obj)->iv_tbl, id, 0))
|
if (ROBJECT(obj)->iv_tbl && st_lookup(ROBJECT(obj)->iv_tbl, id, 0))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
break;
|
break;
|
||||||
|
@ -782,7 +779,6 @@ obj_instance_variables(obj)
|
||||||
case T_OBJECT:
|
case T_OBJECT:
|
||||||
case T_CLASS:
|
case T_CLASS:
|
||||||
case T_MODULE:
|
case T_MODULE:
|
||||||
case T_FILE:
|
|
||||||
if (ROBJECT(obj)->iv_tbl) {
|
if (ROBJECT(obj)->iv_tbl) {
|
||||||
st_foreach(ROBJECT(obj)->iv_tbl, ivar_i, hash);
|
st_foreach(ROBJECT(obj)->iv_tbl, ivar_i, hash);
|
||||||
}
|
}
|
||||||
|
@ -808,7 +804,6 @@ obj_remove_instance_variable(obj, name)
|
||||||
case T_OBJECT:
|
case T_OBJECT:
|
||||||
case T_CLASS:
|
case T_CLASS:
|
||||||
case T_MODULE:
|
case T_MODULE:
|
||||||
case T_FILE:
|
|
||||||
if (ROBJECT(obj)->iv_tbl) {
|
if (ROBJECT(obj)->iv_tbl) {
|
||||||
st_delete(ROBJECT(obj)->iv_tbl, &id, &val);
|
st_delete(ROBJECT(obj)->iv_tbl, &id, &val);
|
||||||
}
|
}
|
||||||
|
@ -822,41 +817,41 @@ obj_remove_instance_variable(obj, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_const_get_at(cls, id)
|
rb_const_get_at(klass, id)
|
||||||
VALUE cls;
|
VALUE klass;
|
||||||
ID id;
|
ID id;
|
||||||
{
|
{
|
||||||
VALUE value;
|
VALUE value;
|
||||||
|
|
||||||
if (RCLASS(cls)->iv_tbl && st_lookup(RCLASS(cls)->iv_tbl, id, &value)) {
|
if (RCLASS(klass)->iv_tbl && st_lookup(RCLASS(klass)->iv_tbl, id, &value)) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
if (cls == cObject) {
|
if (klass == cObject) {
|
||||||
return rb_const_get(cls, id);
|
return rb_const_get(klass, id);
|
||||||
}
|
}
|
||||||
NameError("Uninitialized constant %s::%s",
|
NameError("Uninitialized constant %s::%s",
|
||||||
RSTRING(rb_class_path(cls))->ptr,
|
RSTRING(rb_class_path(klass))->ptr,
|
||||||
rb_id2name(id));
|
rb_id2name(id));
|
||||||
/* not reached */
|
/* not reached */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_const_get(cls, id)
|
rb_const_get(klass, id)
|
||||||
VALUE cls;
|
VALUE klass;
|
||||||
ID id;
|
ID id;
|
||||||
{
|
{
|
||||||
VALUE value;
|
VALUE value;
|
||||||
VALUE tmp;
|
VALUE tmp;
|
||||||
|
|
||||||
tmp = cls;
|
tmp = klass;
|
||||||
while (tmp) {
|
while (tmp) {
|
||||||
if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,&value)) {
|
if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,&value)) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
tmp = RCLASS(tmp)->super;
|
tmp = RCLASS(tmp)->super;
|
||||||
}
|
}
|
||||||
if (BUILTIN_TYPE(cls) == T_MODULE) {
|
if (BUILTIN_TYPE(klass) == T_MODULE) {
|
||||||
return rb_const_get(cObject, id);
|
return rb_const_get(cObject, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -872,13 +867,13 @@ rb_const_get(cls, id)
|
||||||
module = str_new2(modname);
|
module = str_new2(modname);
|
||||||
free(modname);
|
free(modname);
|
||||||
f_require(0, module);
|
f_require(0, module);
|
||||||
return rb_const_get(cls, id);
|
return rb_const_get(klass, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Uninitialized constant */
|
/* Uninitialized constant */
|
||||||
if (cls && cls != cObject)
|
if (klass && klass != cObject)
|
||||||
NameError("Uninitialized constant %s::%s",
|
NameError("Uninitialized constant %s::%s",
|
||||||
RSTRING(rb_class_path(cls))->ptr,
|
RSTRING(rb_class_path(klass))->ptr,
|
||||||
rb_id2name(id));
|
rb_id2name(id));
|
||||||
else {
|
else {
|
||||||
NameError("Uninitialized constant %s",rb_id2name(id));
|
NameError("Uninitialized constant %s",rb_id2name(id));
|
||||||
|
@ -952,15 +947,15 @@ mod_const_of(mod, ary)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
rb_const_defined_at(cls, id)
|
rb_const_defined_at(klass, id)
|
||||||
VALUE cls;
|
VALUE klass;
|
||||||
ID id;
|
ID id;
|
||||||
{
|
{
|
||||||
if (RCLASS(cls)->iv_tbl && st_lookup(RCLASS(cls)->iv_tbl, id, 0)) {
|
if (RCLASS(klass)->iv_tbl && st_lookup(RCLASS(klass)->iv_tbl, id, 0)) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
if (cls == cObject) {
|
if (klass == cObject) {
|
||||||
return rb_const_defined(cls, id);
|
return rb_const_defined(klass, id);
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -975,15 +970,15 @@ rb_autoload_defined(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
rb_const_defined(cls, id)
|
rb_const_defined(klass, id)
|
||||||
VALUE cls;
|
VALUE klass;
|
||||||
ID id;
|
ID id;
|
||||||
{
|
{
|
||||||
while (cls) {
|
while (klass) {
|
||||||
if (RCLASS(cls)->iv_tbl && st_lookup(RCLASS(cls)->iv_tbl, id, 0)) {
|
if (RCLASS(klass)->iv_tbl && st_lookup(RCLASS(klass)->iv_tbl, id, 0)) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
cls = RCLASS(cls)->super;
|
klass = RCLASS(klass)->super;
|
||||||
}
|
}
|
||||||
if (st_lookup(class_tbl, id, 0))
|
if (st_lookup(class_tbl, id, 0))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -991,24 +986,24 @@ rb_const_defined(cls, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_const_set(cls, id, val)
|
rb_const_set(klass, id, val)
|
||||||
VALUE cls;
|
VALUE klass;
|
||||||
ID id;
|
ID id;
|
||||||
VALUE val;
|
VALUE val;
|
||||||
{
|
{
|
||||||
if (!RCLASS(cls)->iv_tbl) {
|
if (!RCLASS(klass)->iv_tbl) {
|
||||||
RCLASS(cls)->iv_tbl = new_idhash();
|
RCLASS(klass)->iv_tbl = new_idhash();
|
||||||
}
|
}
|
||||||
else if (st_lookup(RCLASS(cls)->iv_tbl, id, 0)) {
|
else if (st_lookup(RCLASS(klass)->iv_tbl, id, 0)) {
|
||||||
NameError("already initialized constant %s", rb_id2name(id));
|
NameError("already initialized constant %s", rb_id2name(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
st_insert(RCLASS(cls)->iv_tbl, id, val);
|
st_insert(RCLASS(klass)->iv_tbl, id, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_define_const(cls, name, val)
|
rb_define_const(klass, name, val)
|
||||||
VALUE cls;
|
VALUE klass;
|
||||||
char *name;
|
char *name;
|
||||||
VALUE val;
|
VALUE val;
|
||||||
{
|
{
|
||||||
|
@ -1016,7 +1011,7 @@ rb_define_const(cls, name, val)
|
||||||
if (!rb_is_const_id(id)) {
|
if (!rb_is_const_id(id)) {
|
||||||
NameError("wrong constant name %s", name);
|
NameError("wrong constant name %s", name);
|
||||||
}
|
}
|
||||||
rb_const_set(cls, id, val);
|
rb_const_set(klass, id, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue