summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author卜部昌平 <shyouhei@ruby-lang.org>2021-02-03 11:27:49 +0900
committer卜部昌平 <shyouhei@ruby-lang.org>2021-09-10 20:00:06 +0900
commita2b8f61cba2fb4720acbed846ae0409b3a39b909 (patch)
tree1c9f4b330bf004a5f86907118cf21f1b553d1f89
parent9c4aa94a199fbbf0dacb1b5e3530b1d8ccc65105 (diff)
include/ruby/internal/core/rbasic.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4815
-rw-r--r--include/ruby/internal/core/rbasic.h86
-rw-r--r--object.c20
2 files changed, 79 insertions, 27 deletions
diff --git a/include/ruby/internal/core/rbasic.h b/include/ruby/internal/core/rbasic.h
index 1dd1769f43..4617f743a7 100644
--- a/include/ruby/internal/core/rbasic.h
+++ b/include/ruby/internal/core/rbasic.h
@@ -31,22 +31,60 @@
#include "ruby/internal/value.h"
#include "ruby/assert.h"
-#define RBASIC(obj) RBIMPL_CAST((struct RBasic *)(obj))
-#define RBASIC_CLASS RBASIC_CLASS
-#define RVALUE_EMBED_LEN_MAX RVALUE_EMBED_LEN_MAX
-
+/**
+ * Convenient casting macro.
+ *
+ * @param obj Arbitrary Ruby object.
+ * @return The passed object casted to ::RBasic.
+ */
+#define RBASIC(obj) RBIMPL_CAST((struct RBasic *)(obj))
/** @cond INTERNAL_MACRO */
+#define RBASIC_CLASS RBASIC_CLASS
+#define RBIMPL_RVALUE_EMBED_LEN_MAX 3
+#define RVALUE_EMBED_LEN_MAX RVALUE_EMBED_LEN_MAX
#define RBIMPL_EMBED_LEN_MAX_OF(T) \
RBIMPL_CAST((int)(sizeof(VALUE[RBIMPL_RVALUE_EMBED_LEN_MAX]) / (sizeof(T))))
/** @endcond */
-#define RBIMPL_RVALUE_EMBED_LEN_MAX 3
-enum ruby_rvalue_flags { RVALUE_EMBED_LEN_MAX = RBIMPL_RVALUE_EMBED_LEN_MAX };
+/**
+ * This is an enum because GDB wants it (rather than a macro). People need not
+ * bother.
+ */
+enum ruby_rvalue_flags {
+ /** Max possible number of objects that can be embedded. */
+ RVALUE_EMBED_LEN_MAX = RBIMPL_RVALUE_EMBED_LEN_MAX
+};
+/**
+ * Ruby's object's, base components. Every single ruby objects have them in
+ * common.
+ */
struct
RUBY_ALIGNAS(SIZEOF_VALUE)
RBasic {
- VALUE flags; /**< @see enum ::ruby_fl_type. */
+
+ /**
+ * Per-object flags. Each ruby objects have their own characteristics
+ * apart from their classes. For instance whether an object is frozen or
+ * not is not controlled by its class. This is where such properties are
+ * stored.
+ *
+ * @see enum ::ruby_fl_type
+ *
+ * @note This is ::VALUE rather than an enum for alignment purpose. Back
+ * in the 1990s there were no such thing like `_Alignas` in C.
+ */
+ VALUE flags;
+
+ /**
+ * Class of an object. Every object has its class. Also, everything is an
+ * object in Ruby. This means classes are also objects. Classes have
+ * their own classes, classes of classes have their classes, too ... and
+ * it recursively continues forever.
+ *
+ * Also note the `const` qualifier. In ruby an object cannot "change" its
+ * class.
+ */
const VALUE klass;
#ifdef __cplusplus
@@ -70,12 +108,46 @@ RBasic {
};
RBIMPL_SYMBOL_EXPORT_BEGIN()
+/**
+ * Make the object invisible from Ruby code.
+ *
+ * It is useful to let Ruby's GC manage your internal data structure -- The
+ * object keeps being managed by GC, but `ObjectSpace.each_object` never yields
+ * the object.
+ *
+ * Note that the object also lose a way to call a method on it.
+ *
+ * @param[out] obj A Ruby object.
+ * @return The passed object.
+ * @post The object is destructively modified to be invisible.
+ * @see rb_obj_reveal
+ */
VALUE rb_obj_hide(VALUE obj);
+
+/**
+ * Make a hidden object visible again.
+ *
+ * It is the caller's responsibility to pass the right `klass` which `obj`
+ * originally used to belong to.
+ *
+ * @param[out] obj A Ruby object.
+ * @param[in] klass Class of `obj`.
+ * @return Passed `obj`.
+ * @pre `obj` was previously hidden.
+ * @post `obj`'s class is `klass`.
+ * @see rb_obj_hide
+ */
VALUE rb_obj_reveal(VALUE obj, VALUE klass); /* do not use this API to change klass information */
RBIMPL_SYMBOL_EXPORT_END()
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
RBIMPL_ATTR_ARTIFICIAL()
+/**
+ * Queries the class of an object.
+ *
+ * @param[in] obj An object.
+ * @return Its class.
+ */
static inline VALUE
RBASIC_CLASS(VALUE obj)
{
diff --git a/object.c b/object.c
index 6dc3a8ea00..6149947c4a 100644
--- a/object.c
+++ b/object.c
@@ -77,18 +77,6 @@ static VALUE rb_cFalseClass_to_s;
/*! \endcond */
-/*!
- * Make the object invisible from Ruby code.
- *
- * It is useful to let Ruby's GC manage your internal data structure --
- * The object keeps being managed by GC, but \c ObjectSpace.each_object
- * never yields the object.
- *
- * Note that the object also lose a way to call a method on it.
- *
- * \param[in] obj a Ruby object
- * \sa rb_obj_reveal
- */
VALUE
rb_obj_hide(VALUE obj)
{
@@ -98,14 +86,6 @@ rb_obj_hide(VALUE obj)
return obj;
}
-/*!
- * Make a hidden object visible again.
- *
- * It is the caller's responsibility to pass the right \a klass
- * which \a obj originally used to belong to.
- *
- * \sa rb_obj_hide
- */
VALUE
rb_obj_reveal(VALUE obj, VALUE klass)
{