Ruby: include/ruby/internal/gc.h File Reference

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Functions
gc.h File Reference

Registering values to the GC. More...

`#include "ruby/internal/dllexport.h"`
`#include "ruby/internal/value.h"`

Go to the source code of this file.

## Functions
void | rb_gc_register_address (VALUE *valptr)
| Inform the garbage collector that `valptr` points to a live Ruby object that should not be moved. More...
void | rb_global_variable (VALUE *)
| An alias for `rb_gc_register_address()`. More...
void | rb_gc_unregister_address (VALUE *valptr)
| Inform the garbage collector that a pointer previously passed to `rb_gc_register_address()` no longer points to a live Ruby object. More...
void | rb_gc_register_mark_object (VALUE object)
| Inform the garbage collector that `object` is a live Ruby object that should not be moved. More...

## Detailed Description

Registering values to the GC.

Author
  Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Copyright
  This file is a part of the programming language Ruby. Permission is hereby granted, to either redistribute and/or modify this file, provided that the conditions mentioned in the file COPYING are met. Consult the file for details.

Warning
  Symbols prefixed with either `RBIMPL` or `rbimpl` are implementation details. Don't take them as canon. They could rapidly appear then vanish. The name (path) of this header file is also an implementation detail. Do not expect it to persist at the place it is now. Developers are free to move it anywhere anytime at will.

Note
  To ruby-core: remember that this header can be possibly recursively included from extension libraries written in C++. Do not expect for instance `__VA_ARGS__` is always available. We assume C99 for ruby itself but we don't assume languages of extension libraries. They could be written in C++98.

Definition in file gc.h.

## Function Documentation

## ◆ rb_gc_register_address()

void rb_gc_register_address | ( | VALUE * | valptr | ) |

Inform the garbage collector that `valptr` points to a live Ruby object that should not be moved.

Note that extensions should use this API on global constants instead of assuming constants defined in Ruby are always alive. Ruby code can remove global constants.

Definition at line 8040 of file gc.c.

References ALLOC, global_list, gc_list::next, rb_objspace, and gc_list::varptr.

Referenced by Init_readline(), Init_String(), rb_global_variable(), and ruby_init_loadpath().

## ◆ rb_gc_register_mark_object()

void rb_gc_register_mark_object | ( | VALUE | object | ) |

Inform the garbage collector that `object` is a live Ruby object that should not be moved.

See also: rb_gc_register_address()

Definition at line 8022 of file gc.c.

References MARK_OBJECT_ARY_BUCKET_SIZE, Qnil, RARRAY_LEN, rb_ary_last(), rb_ary_push(), rb_ary_tmp_new(), RB_VM_LOCK_ENTER, and RB_VM_LOCK_LEAVE.

Referenced by Init_class_hierarchy(), Init_Complex(), Init_date_core(), Init_Encoding(), Init_Exception(), Init_generator(), Init_IO(), Init_load(), Init_MemoryView(), Init_ossl_asn1(), Init_parser(), Init_sym(), Init_Time(), Init_VM(), Init_win32ole(), Init_win32ole_event(), InitVM_Enumerator(), rb_autoload_str(), rb_define_const(), rb_define_module_id_under(), rb_iseq_defined_string(), rb_profile_frame_absolute_path(), rb_sym_to_proc(), rb_vm_register_special_exception_str(), ruby_process_options(), and yyparse().

## ◆ rb_gc_unregister_address()

void rb_gc_unregister_address | ( | VALUE * | valptr | ) |

Inform the garbage collector that a pointer previously passed to `rb_gc_register_address()` no longer points to a live Ruby object.

Definition at line 8052 of file gc.c.

References global_list, gc_list::next, rb_objspace, t, gc_list::varptr, and xfree.

## ◆ rb_global_variable()

void rb_global_variable | ( | VALUE * | var | ) |

An alias for `rb_gc_register_address()`.

Definition at line 8075 of file gc.c.

References rb_gc_register_address().