[前][次][番号順一覧][スレッド一覧]

ruby-changes:67750

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Fri, 10 Sep 2021 20:01:25 +0900 (JST)
Subject: [ruby-changes:67750] a2b8f61cba (master): include/ruby/internal/core/rbasic.h: add doxygen

https://git.ruby-lang.org/ruby.git/commit/?id=a2b8f61cba

From a2b8f61cba2fb4720acbed846ae0409b3a39b909 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Wed, 3 Feb 2021 11:27:49 +0900
Subject: include/ruby/internal/core/rbasic.h: add doxygen

Must not be a bad idea to improve documents. [ci skip]
---
 include/ruby/internal/core/rbasic.h | 86 ++++++++++++++++++++++++++++++++++---
 object.c                            | 20 ---------
 2 files changed, 79 insertions(+), 27 deletions(-)

diff --git a/include/ruby/internal/core/rbasic.h b/include/ruby/internal/core/rbasic.h
index 1dd1769..4617f74 100644
--- a/include/ruby/internal/core/rbasic.h
+++ b/include/ruby/internal/core/rbasic.h
@@ -31,22 +31,60 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/rbasic.h#L31
 #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 { https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/rbasic.h#L108
 };
 
 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 6dc3a8e..6149947 100644
--- a/object.c
+++ b/object.c
@@ -77,18 +77,6 @@ static VALUE rb_cFalseClass_to_s; https://github.com/ruby/ruby/blob/trunk/object.c#L77
 
 /*! \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) https://github.com/ruby/ruby/blob/trunk/object.c#L86
     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)
 {
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]