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

ruby-changes:67708

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Fri, 10 Sep 2021 20:00:46 +0900 (JST)
Subject: [ruby-changes:67708] 28b7b0e13e (master): include/ruby/internal/xmalloc.h: add doxygen

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

From 28b7b0e13e261006dee4b4d9152aaabdb1286718 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, 13 Jan 2021 14:38:03 +0900
Subject: include/ruby/internal/xmalloc.h: add doxygen

Must not be a bad idea to improve documents. [ci skip]
---
 include/ruby/internal/xmalloc.h | 105 ++++++++++++++++++++++++++--------------
 template/Doxyfile.tmpl          |   1 +
 2 files changed, 69 insertions(+), 37 deletions(-)

diff --git a/include/ruby/internal/xmalloc.h b/include/ruby/internal/xmalloc.h
index 173f271..57552e4 100644
--- a/include/ruby/internal/xmalloc.h
+++ b/include/ruby/internal/xmalloc.h
@@ -37,16 +37,25 @@ https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/xmalloc.h#L37
 #include "ruby/internal/attr/returns_nonnull.h"
 #include "ruby/internal/dllexport.h"
 
+/**
+ * @private
+ * @warning  Do not touch this macro.
+ * @warning  It is an implementation detail.
+ * @warning  It was a failure at the first place to let you know about it.
+ * @warning  The  value of  this  macro  must match  for  ruby  itself and  all
+ *           extension  libraries, otherwise  serious  memory corruption  shall
+ *           occur.
+ */
 #ifndef USE_GC_MALLOC_OBJ_INFO_DETAILS
 # define USE_GC_MALLOC_OBJ_INFO_DETAILS 0
 #endif
 
-#define xmalloc ruby_xmalloc
-#define xmalloc2 ruby_xmalloc2
-#define xcalloc ruby_xcalloc
-#define xrealloc ruby_xrealloc
-#define xrealloc2 ruby_xrealloc2
-#define xfree ruby_xfree
+#define xmalloc   ruby_xmalloc   /**< @old{ruby_xmalloc} */
+#define xmalloc2  ruby_xmalloc2  /**< @old{ruby_xmalloc2} */
+#define xcalloc   ruby_xcalloc   /**< @old{ruby_xcalloc} */
+#define xrealloc  ruby_xrealloc  /**< @old{ruby_xrealloc} */
+#define xrealloc2 ruby_xrealloc2 /**< @old{ruby_xrealloc2} */
+#define xfree     ruby_xfree     /**< @old{ruby_xfree} */
 
 RBIMPL_SYMBOL_EXPORT_BEGIN()
 
@@ -114,9 +123,9 @@ RBIMPL_ATTR_RESTRICT() https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/xmalloc.h#L123
 RBIMPL_ATTR_RETURNS_NONNULL()
 RBIMPL_ATTR_ALLOC_SIZE((1,2))
 /**
- * Identical  to ruby_xmalloc2(),  except it  zero-fills the  region before  it
- * returns.  This could also be seen  as a routine identical to ruby_xmalloc(),
- * except it calls calloc() instead of malloc() internally.
+ * Identical  to  ruby_xmalloc2(),  except  it returns  a  zero-filled  storage
+ * instance.  It  can also be  seen as  a routine identical  to ruby_xmalloc(),
+ * except it calls calloc() instead of malloc().
  *
  * @param[in]  nelems          Number of elements.
  * @param[in]  elemsiz         Size of an element.
@@ -125,6 +134,7 @@ RBIMPL_ATTR_ALLOC_SIZE((1,2)) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/xmalloc.h#L134
  * @return     A valid pointer  to an allocated storage instance;  which has at
  *             least  `nelems`  *  `elemsiz`   bytes  width,  with  appropriate
  *             alignment detected by the underlying calloc() routine.
+ * @post       The returned storage instance is filled with zeros.
  * @note       It doesn't return NULL.
  * @note       Unlike some calloc() implementations, it allocates something and
  *             returns a  meaningful value even  when `nelems` or  `elemsiz` or
@@ -145,22 +155,28 @@ RBIMPL_ATTR_ALLOC_SIZE((2)) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/xmalloc.h#L155
  * Resize the storage instance.
  *
  * @param[in]  ptr             A valid  pointer to a storage  instance that was
- *                             previously returned  from either ruby_xmalloc(),
- *                             ruby_xmalloc2(),                 ruby_xcalloc(),
- *                             ruby_xrealloc(), or ruby_xrealloc2().
+ *                             previously returned from either:
+ *                               - ruby_xmalloc(),
+ *                               - ruby_xmalloc2(),
+ *                               - ruby_xcalloc(),
+ *                               - ruby_xrealloc(), or
+ *                               - ruby_xrealloc2().
  * @param[in]  newsiz          Requested new amount of memory.
  * @exception  rb_eNoMemError  No space left for `newsiz` bytes allocation.
- * @retval     ptr             In case the function  returns the passed pointer
- *                             as-is,  the storage  instance  that the  pointer
- *                             holds  is either  grown or  shrunken to  have at
- *                             least `newsiz` bytes.
- * @retval     otherwise       A  valid pointer  to a  newly allocated  storage
- *                             instance  which  has  at  least  `newsiz`  bytes
- *                             width, and holds previous contents of `ptr`.  In
- *                             this  case `ptr`  is  invalidated as  if it  was
- *                             passed to ruby_xfree().
+ * @return     A  valid  pointer  to   a  (possibly  newly  allocated)  storage
+ *             instance;  which  has  at   least  `newsiz`  bytes  width,  with
+ *             appropriate  alignment  detected  by  the  underlying  realloc()
+ *             routine.
+ * @pre        The passed pointer must point  to a valid live storage instance.
+ *             It is a failure to pass an already freed pointer.
+ * @post       In  case the  function  returns the  passed  pointer as-is,  the
+ *             storage  instance that  the  pointer holds  is  either grown  or
+ *             shrunken  to have  at least  `newsiz` bytes.  Otherwise a  valid
+ *             pointer to a  newly allocated storage instance  is returned.  In
+ *             this  case  `ptr`  is  invalidated   as  if  it  was  passed  to
+ *             ruby_xfree().
  * @note       It doesn't return NULL.
- * @warning    Unlike some realloc() implementations, passing zero to `elemsiz`
+ * @warning    Unlike some realloc() implementations,  passing zero to `newsiz`
  *             is not the  same as calling ruby_xfree(),  because this function
  *             never returns NULL.  Something meaningful still returns then.
  * @warning    It is  a failure not to  check the return value.   Do not assume
@@ -193,22 +209,28 @@ RBIMPL_ATTR_ALLOC_SIZE((2,3)) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/xmalloc.h#L209
  * etc. provides, but also interacts with our GC.
  *
  * @param[in]  ptr             A valid  pointer to a storage  instance that was
- *                             previously returned  from either ruby_xmalloc(),
- *                             ruby_xmalloc2(),                 ruby_xcalloc(),
- *                             ruby_xrealloc(), or ruby_xrealloc2().
+ *                             previously returned from either:
+ *                               - ruby_xmalloc(),
+ *                               - ruby_xmalloc2(),
+ *                               - ruby_xcalloc(),
+ *                               - ruby_xrealloc(), or
+ *                               - ruby_xrealloc2().
  * @param[in]  newelems        Requested new number of elements.
  * @param[in]  newsiz          Requested new size of each element.
  * @exception  rb_eNoMemError  No space left for  allocation.
  * @exception  rb_eArgError    `newelems` * `newsiz` would overflow.
- * @retval     ptr             In case the function  returns the passed pointer
- *                             as-is,  the storage  instance  that the  pointer
- *                             holds  is either  grown or  shrunken to  have at
- *                             least `newelems` * `newsiz` bytes.
- * @retval     otherwise       A  valid pointer  to a  newly allocated  storage
- *                             instance  which   has  at  least   `newelems`  *
- *                             `newsiz`   bytes  width,   and  holds   previous
- *                             contents  of  `ptr`.   In  this  case  `ptr`  is
- *                             invalidated as if it was passed to ruby_xfree().
+ * @return     A  valid  pointer  to   a  (possibly  newly  allocated)  storage
+ *             instance; which has at least  `newelems` * `newsiz` bytes width,
+ *             with appropriate alignment detected  by the underlying realloc()
+ *             routine.
+ * @pre        The passed pointer must point  to a valid live storage instance.
+ *             It is a failure to pass an already freed pointer.
+ * @post       In  case the  function  returns the  passed  pointer as-is,  the
+ *             storage  instance that  the  pointer holds  is  either grown  or
+ *             shrunken  to   have  at  least  `newelems`   *  `newsiz`  bytes.
+ *             Otherwise a valid pointer to  a newly allocated storage instance
+ *             is returned.   In this case  `ptr` is  invalidated as if  it was
+ *             passed to ruby_xfree().
  * @note       It doesn't return NULL.
  * @warning    Unlike some  realloc() implementations,  passing zero  to either
  *             `newelems`   or  `elemsiz`   are   not  the   same  as   calling
@@ -232,9 +254,18 @@ RBIMPL_ATTR_NOEXCEPT(realloc(ptr, newelems * newsiz)) https://github.com/ruby/ruby/blob/trunk/include/ruby/internal/xmalloc.h#L254
 /**
  * Deallocates a storage instance.
  *
- * @param[out]  ptr  Either NULL,  or a valid pointer  previously returned from
- *                   one  of  ruby_xmalloc(), ruby_xmalloc2(),  ruby_xcalloc(),
- *                   ruby_xrealloc(), or ruby_xrealloc2().
+ * @param[out]  ptr  Either
+ *                     - NULL, or
+ *                     - a valid pointer previously returned from one of:
+ *                       - ruby_xmalloc(),
+ *                       - ruby_xmalloc2(),
+ *                       - ruby_xcalloc(),
+ *                       - ruby_xrealloc(), or
+ *                       - ruby_xrealloc2().
+ * @pre         The passed pointer must point to a valid live storage instance.
+ *              It is a failure to pass an already freed pointer.
+ * @post        The  (... truncated)

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

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