In Files
- gc.c
Parent
Methods
Included Modules
Files
- grammar.en.rdoc
- test.ja.rdoc
- contributing.rdoc
- contributors.rdoc
- dtrace_probes.rdoc
- extension.ja.rdoc
- extension.rdoc
- globals.rdoc
- keywords.rdoc
- maintainers.rdoc
- marshal.rdoc
- regexp.rdoc
- security.rdoc
- standard_library.rdoc
- syntax.rdoc
- assignment.rdoc
- calling_methods.rdoc
- control_expressions.rdoc
- exceptions.rdoc
- literals.rdoc
- methods.rdoc
- miscellaneous.rdoc
- modules_and_classes.rdoc
- precedence.rdoc
- refinements.rdoc
- README.ja.rdoc
- README.rdoc
Class/Module Index
- ArgumentError
- Array
- BasicObject
- Bignum
- Binding
- Class
- ClosedQueueError
- Comparable
- Complex
- Complex::compatible
- ConditionVariable
- Continuation
- Data
- Dir
- ENV
- EOFError
- Encoding
- Encoding::CompatibilityError
- Encoding::Converter
- Encoding::ConverterNotFoundError
- Encoding::InvalidByteSequenceError
- Encoding::UndefinedConversionError
- EncodingError
- Enumerable
- Enumerator
- Enumerator::Generator
- Enumerator::Lazy
- Enumerator::Yielder
- Errno
- Exception
- FalseClass
- Fiber
- FiberError
- File
- File::Constants
- File::Stat
- FileTest
- Fixnum
- Float
- FloatDomainError
- GC
- GC::Profiler
- Hash
- IO
- IO::EAGAINWaitReadable
- IO::EAGAINWaitWritable
- IO::EINPROGRESSWaitReadable
- IO::EINPROGRESSWaitWritable
- IO::EWOULDBLOCKWaitReadable
- IO::EWOULDBLOCKWaitWritable
- IO::WaitReadable
- IO::WaitWritable
- IOError
- IndexError
- Integer
- Interrupt
- Kernel
- KeyError
- LoadError
- LocalJumpError
- Marshal
- MatchData
- Math
- Math::DomainError
- Method
- Module
- NameError
- NilClass
- NoMemoryError
- NoMethodError
- NotImplementedError
- Numeric
- Object
- ObjectSpace
- ObjectSpace::WeakMap
- Proc
- Process
- Process::GID
- Process::Status
- Process::Sys
- Process::UID
- Process::Waiter
- Queue
- Random
- Random::Formatter
- Range
- RangeError
- Rational
- Rational::compatible
- Regexp
- RegexpError
- RubyVM
- RubyVM::Env
- RubyVM::InstructionSequence
- RuntimeError
- ScriptError
- SecurityError
- Signal
- SignalException
- SizedQueue
- StandardError
- StopIteration
- String
- Struct
- Symbol
- SyntaxError
- SystemCallError
- SystemExit
- SystemStackError
- Thread
- Thread::Backtrace::Location
- Thread::Mutex
- ThreadError
- ThreadGroup
- Time
- TracePoint
- TrueClass
- TypeError
- UnboundMethod
- UncaughtThrowError
- ZeroDivisionError
- fatal
- unknown
ObjectSpace::WeakMap
An ObjectSpace::WeakMap object holds references to any objects, but those objects can get garbage collected.
This class is mostly used internally by WeakRef, please use
lib/weakref.rb
for the public interface.
Public Instance Methods
Retrieves a weakly referenced object with the given key
static VALUE wmap_aref(VALUE self, VALUE wmap) { st_data_t data; VALUE obj; struct weakmap *w; rb_objspace_t *objspace = &rb_objspace; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); if (!st_lookup(w->wmap2obj, (st_data_t)wmap, &data)) return Qnil; obj = (VALUE)data; if (!is_id_value(objspace, obj)) return Qnil; if (!is_live_object(objspace, obj)) return Qnil; return obj; }
Creates a weak reference from the given key to the given value
static VALUE wmap_aset(VALUE self, VALUE wmap, VALUE orig) { struct weakmap *w; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); should_be_finalizable(orig); should_be_finalizable(wmap); define_final0(orig, w->final); define_final0(wmap, w->final); st_update(w->obj2wmap, (st_data_t)orig, wmap_aset_update, wmap); st_insert(w->wmap2obj, (st_data_t)wmap, (st_data_t)orig); return nonspecial_obj_id(orig); }
Iterates over keys and objects in a weakly referenced object
static VALUE wmap_each(VALUE self) { struct weakmap *w; rb_objspace_t *objspace = &rb_objspace; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); st_foreach(w->wmap2obj, wmap_each_i, (st_data_t)objspace); return self; }
Iterates over keys and objects in a weakly referenced object
static VALUE wmap_each_key(VALUE self) { struct weakmap *w; rb_objspace_t *objspace = &rb_objspace; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); st_foreach(w->wmap2obj, wmap_each_key_i, (st_data_t)objspace); return self; }
Iterates over keys and objects in a weakly referenced object
static VALUE wmap_each(VALUE self) { struct weakmap *w; rb_objspace_t *objspace = &rb_objspace; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); st_foreach(w->wmap2obj, wmap_each_i, (st_data_t)objspace); return self; }
Iterates over keys and objects in a weakly referenced object
static VALUE wmap_each_value(VALUE self) { struct weakmap *w; rb_objspace_t *objspace = &rb_objspace; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); st_foreach(w->wmap2obj, wmap_each_value_i, (st_data_t)objspace); return self; }
Returns true
if key
is registered
static VALUE wmap_has_key(VALUE self, VALUE key) { return NIL_P(wmap_aref(self, key)) ? Qfalse : Qtrue; }
static VALUE wmap_inspect(VALUE self) { VALUE str; VALUE c = rb_class_name(CLASS_OF(self)); struct weakmap *w; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); str = rb_sprintf("-<%"PRIsVALUE":%p", c, (void *)self); if (w->wmap2obj) { st_foreach(w->wmap2obj, wmap_inspect_i, str); } RSTRING_PTR(str)[0] = '#'; rb_str_cat2(str, ">"); return str; }
Returns true
if key
is registered
static VALUE wmap_has_key(VALUE self, VALUE key) { return NIL_P(wmap_aref(self, key)) ? Qfalse : Qtrue; }
Iterates over keys and objects in a weakly referenced object
static VALUE wmap_keys(VALUE self) { struct weakmap *w; struct wmap_iter_arg args; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); args.objspace = &rb_objspace; args.value = rb_ary_new(); st_foreach(w->wmap2obj, wmap_keys_i, (st_data_t)&args); return args.value; }
static VALUE wmap_size(VALUE self) { struct weakmap *w; st_index_t n; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); n = w->wmap2obj->num_entries; #if SIZEOF_ST_INDEX_T <= SIZEOF_LONG return ULONG2NUM(n); #else return ULL2NUM(n); #endif }
Returns true
if key
is registered
static VALUE wmap_has_key(VALUE self, VALUE key) { return NIL_P(wmap_aref(self, key)) ? Qfalse : Qtrue; }
static VALUE wmap_size(VALUE self) { struct weakmap *w; st_index_t n; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); n = w->wmap2obj->num_entries; #if SIZEOF_ST_INDEX_T <= SIZEOF_LONG return ULONG2NUM(n); #else return ULL2NUM(n); #endif }
Iterates over values and objects in a weakly referenced object
static VALUE wmap_values(VALUE self) { struct weakmap *w; struct wmap_iter_arg args; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); args.objspace = &rb_objspace; args.value = rb_ary_new(); st_foreach(w->wmap2obj, wmap_values_i, (st_data_t)&args); return args.value; }
Private Instance Methods
static VALUE wmap_finalize(VALUE self, VALUE objid) { st_data_t orig, wmap, data; VALUE obj, *rids, i, size; struct weakmap *w; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); /* Get reference from object id. */ obj = obj_id_to_ref(objid); /* obj is original referenced object and/or weak reference. */ orig = (st_data_t)obj; if (st_delete(w->obj2wmap, &orig, &data)) { rids = (VALUE *)data; size = *rids++; for (i = 0; i < size; ++i) { wmap = (st_data_t)rids[i]; st_delete(w->wmap2obj, &wmap, NULL); } ruby_sized_xfree((VALUE *)data, (size + 1) * sizeof(VALUE)); } wmap = (st_data_t)obj; if (st_delete(w->wmap2obj, &wmap, &orig)) { wmap = (st_data_t)obj; st_update(w->obj2wmap, orig, wmap_final_func, wmap); } return self; }