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

ruby-changes:67748

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:67748] 005ff5da52 (master): include/ruby/internal/core/rdata.h: add doxygen

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

From 005ff5da52f8b9c8e7633fad9d39e6a47c39ae40 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: Tue, 2 Feb 2021 12:58:32 +0900
Subject: include/ruby/internal/core/rdata.h: add doxygen

Must not be a bad idea to improve documents. [ci skip]
---
 include/ruby/internal/core/rdata.h | 229 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 226 insertions(+), 3 deletions(-)

diff --git a/include/ruby/internal/core/rdata.h b/include/ruby/internal/core/rdata.h
index 232ee89..f6656b6 100644
--- a/include/ruby/internal/core/rdata.h
+++ b/include/ruby/internal/core/rdata.h
@@ -36,6 +36,7 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/rdata.h#L36
 #include "ruby/internal/value_type.h"
 #include "ruby/defines.h"
 
+/** @cond INTERNAL_MACRO */
 #ifdef RUBY_UNTYPED_DATA_WARNING
 # /* Take that. */
 #elif defined(RUBY_EXPORT)
@@ -44,39 +45,160 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/rdata.h#L45
 # define RUBY_UNTYPED_DATA_WARNING 0
 #endif
 
-/** @cond INTERNAL_MACRO */
 #define RBIMPL_DATA_FUNC(f) RBIMPL_CAST((void (*)(void *))(f))
 #define RBIMPL_ATTRSET_UNTYPED_DATA_FUNC() \
     RBIMPL_ATTR_WARNING(("untyped Data is unsafe; use TypedData instead")) \
     RBIMPL_ATTR_DEPRECATED(("by TypedData"))
+
+#define RBIMPL_MACRO_SELECT(x, y) x ## y
+#define RUBY_MACRO_SELECT(x, y)   RBIMPL_MACRO_SELECT(x, y)
 /** @endcond */
 
+/**
+ * Convenient casting macro.
+ *
+ * @param   obj  An object, which is in fact an ::RData.
+ * @return  The passed object casted to ::RData.
+ */
 #define RDATA(obj)                RBIMPL_CAST((struct RData *)(obj))
+
+/**
+ * Convenient getter macro.
+ *
+ * @param   obj  An object, which is in fact an ::RData.
+ * @return  The passed object's ::RData::data field.
+ */
 #define DATA_PTR(obj)             RDATA(obj)->data
-#define RBIMPL_MACRO_SELECT(x, y) x ## y
-#define RUBY_MACRO_SELECT(x, y)   RBIMPL_MACRO_SELECT(x, y)
+
+/**
+ * This is a value you can set  to ::RData::dfree.  Setting this means the data
+ * was allocated using ::ruby_xmalloc() (or variants), and shall be freed using
+ * ::ruby_xfree().
+ *
+ * @warning  Do not  use this  if you  want to use  system malloc,  because the
+ *           system  and  Ruby  might  or  might  not  share  the  same  malloc
+ *           implementation.
+ */
 #define RUBY_DEFAULT_FREE         RBIMPL_DATA_FUNC(-1)
+
+/**
+ * This is a value you can set  to ::RData::dfree.  Setting this means the data
+ * is managed by  someone else, like, statically allocated.  Of  course you are
+ * on your own then.
+ */
 #define RUBY_NEVER_FREE           RBIMPL_DATA_FUNC(0)
+
+/**
+ * @private
+ *
+ * @deprecated  This macro once was a thing in the old days, but makes no sense
+ *              any  longer today.   Exists  here  for backwards  compatibility
+ *              only.  You can safely forget about it.
+ */
 #define RUBY_UNTYPED_DATA_FUNC(f) f RBIMPL_ATTRSET_UNTYPED_DATA_FUNC()
 
 /*
 #define RUBY_DATA_FUNC(func) ((void (*)(void*))(func))
 */
+
+/**
+ * This is  the type of callbacks  registered to ::RData.  The  argument is the
+ * `data` field.
+ */
 typedef void (*RUBY_DATA_FUNC)(void*);
 
+/**
+ * @deprecated
+ *
+ * Old  "untyped"  user  data.   It  has  roughly  the  same  usage  as  struct
+ * ::RTypedData, but lacked several features such as support for compaction GC.
+ * Use of this struct is not recommended  any longer.  If it is dead necessary,
+ * please inform the core devs about your usage.
+ *
+ * @internal
+ *
+ * @shyouhei tried to add RBIMPL_ATTR_DEPRECATED for this type but that yielded
+ * too many warnings  in the core.  Maybe  we want to retry  later...  Just add
+ * deprecated document for now.
+ */
 struct RData {
+
+    /** Basic part, including flags and class. */
     struct RBasic basic;
+
+    /**
+     * This function is called when the object is experiencing GC marks.  If it
+     * contains references to  other Ruby objects, you need to  mark them also.
+     * Otherwise GC will smash your data.
+     *
+     * @see      rb_gc_mark()
+     * @warning  This  is  called  during  GC  runs.   Object  allocations  are
+     *           impossible at that moment (that is why GC runs).
+     */
     RUBY_DATA_FUNC dmark;
+
+    /**
+     * This function is called when the object  is no longer used.  You need to
+     * do whatever necessary to avoid memory leaks.
+     *
+     * @warning  This  is  called  during  GC  runs.   Object  allocations  are
+     *           impossible at that moment (that is why GC runs).
+     */
     RUBY_DATA_FUNC dfree;
+
+    /** Pointer to the actual C level struct that you want to wrap. */
     void *data;
 };
 
 RBIMPL_SYMBOL_EXPORT_BEGIN()
+
+/**
+ * This is the primitive way to wrap an existing C struct into ::RData.
+ *
+ * @param[in]  klass          Ruby level class of the returning object.
+ * @param[in]  datap          Pointer to the target C struct.
+ * @param[in]  dmark          Mark function.
+ * @param[in]  dfree          Free function.
+ * @exception  rb_eTypeError  `klass` is not a class.
+ * @exception  rb_eNoMemError  Out of memory.
+ * @return     An allocated object that wraps `datap`.
+ */
 VALUE rb_data_object_wrap(VALUE klass, void *datap, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree);
+
+/**
+ * Identical to  rb_data_object_wrap(), except it  allocates a new  data region
+ * internally instead of taking an existing  one.  The allocation is done using
+ * ruby_calloc().   Hence  it  makes  no  sense to  pass  anything  other  than
+ * ::RUBY_DEFAULT_FREE to the last argument.
+ *
+ * @param[in]  klass          Ruby level class of the returning object.
+ * @param[in]  size           Requested size of memory to allocate.
+ * @param[in]  dmark          Mark function.
+ * @param[in]  dfree          Free function.
+ * @exception  rb_eTypeError  `klass` is not a class.
+ * @exception  rb_eNoMemError  Out of memory.
+ * @return     An allocated object that wraps a new `size` byte region.
+ */
 VALUE rb_data_object_zalloc(VALUE klass, size_t size, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree);
+
+/**
+ * @private
+ * Documented in include/ruby/internal/globals.h
+ */
 RUBY_EXTERN VALUE rb_cObject;
 RBIMPL_SYMBOL_EXPORT_END()
 
+/**
+ * Converts sval, a pointer to your struct, into a Ruby object.
+ *
+ * @param      klass          A ruby level class.
+ * @param      mark           Mark function.
+ * @param      free           Free function.
+ * @param      sval           A pointer to your struct.
+ * @exception  rb_eTypeError  `klass` is not a class.
+ * @exception  rb_eNoMemError  Out of memory.
+ * @return     A created Ruby object.
+ */
 #define Data_Wrap_Struct(klass, mark, free, sval) \
     rb_data_object_wrap(                          \
         (klass),                                  \
@@ -84,6 +206,20 @@ RBIMPL_SYMBOL_EXPORT_END() https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/rdata.h#L206
         RBIMPL_DATA_FUNC(mark),                    \
         RBIMPL_DATA_FUNC(free))
 
+/**
+ * @private
+ *
+ * This is an implementation detail  of #Data_Make_Struct.  People don't use it
+ * directly.
+ *
+ * @param  result     Variable name of created Ruby object.
+ * @param  klass      Ruby level class of the object.
+ * @param  type       Type name of the C struct.
+ * @param  size       Size of the C struct.
+ * @param  mark       Mark function.
+ * @param  free       Free function.
+ * @param  sval       Variable name of created C struct.
+ */
 #define Data_Make_Struct0(result, klass, type, size, mark, free, sval)  \
     VALUE result = rb_data_object_zalloc(          \
         (klass),                                   \
@@ -93,6 +229,21 @@ RBIMPL_SYMBOL_EXPORT_END() https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/rdata.h#L229
     (sval) = RBIMPL_CAST((type *)DATA_PTR(result)); \
     RBIMPL_CAST(/*suppress unused variable warnings*/(void)(sval))
 
+/**
+ * Identical  to  #Data_Wrap_Struct, except  it  allocates  a new  data  region
+ * internally instead of taking an existing  one.  The allocation is done using
+ * ruby_calloc().   Hence  it  makes  no  sense to  pass  anything  other  than
+ * ::RUBY_DEFAULT_FREE to the `free` argument.
+ *
+ * @param      klass          Ruby level class of the returning object.
+ * @param      type           Type name of the C struct.
+ * @param      mark           Mark function.
+ * @param      free           Free function.
+ * @param      sval           Variable name of created C struct.
+ * @exception  rb_eTypeError  `klass` is not a class.
+ * @exception  rb_eNoMemError  Out of memory.
+ * @return     A created Ruby object.
+ */
 #ifdef HAVE_STMT_AND_DECL_IN_EXPR
 #define Data_Make_Struct(klass, type, mark, free, sval) \
     RB_GNUC_EXTENSION({      \
@@ -116,16 +267,47 @@ RBIMPL_SYMBOL_EXPORT_END() https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/core/rdata.h#L267
         sizeof(type))
 #endif
 
+/**
+ * Obtains a C struct from inside of a wrapper Ruby object.
+ *
+ * @param      obj            An instance of ::RData.
+ * @param      type           Type name of the C struct.
+ * @param      sval           Variable name of obtained C struct.
+ * @return     Unwrapped C struct that `obj` holds.
+ */
 #define Data_Get_Struct(obj, type, sval) \
     ((sval) = RBIMPL_CAST((type*)rb_data_object_get(obj)))
 
 RBIMPL_ATTRSET_UNTYPED_DATA_FUNC()
+/**
+ * @private
+ *
+ * This is an implementation detail of rb_data_object_wrap().  People don't use
+ * it directly.
+ *
+ * @param[in]  klass          Ruby level class of the returning object.
+ * @param[in]  ptr            Pointer to the target C struct.
+ * @param[in]  mark           Mark function.
+ * @param[in]  free           Free function.
+ * @exception  rb_eTypeError  `klass` is not a class.
+ * @exception  rb_eNoMemError  Out of memory.
+ * @return     An allocated object that wraps `datap`.
+ */
 static inline VALUE
 rb_data_objec (... truncated)

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

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