summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-04-15 11:48:11 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-04-15 11:48:11 +0900
commit5944a31614279e814fff6a47d034f5c034226855 (patch)
treedc9881da4da41069ae0dc8432fc49c515f243013
parent9a1c737deefc3f91473691fcb806a5b4aaf7716a (diff)
[DOC] Update sample callback of `rb_objspace_each_objects`
* refine liveness check * fix missing closing brace
-rw-r--r--gc.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/gc.c b/gc.c
index 79f53f6b31..f6c214ea9d 100644
--- a/gc.c
+++ b/gc.c
@@ -3944,14 +3944,16 @@ objspace_each_objects_try(VALUE arg)
*
* This is a sample callback code to iterate liveness objects:
*
- * int
- * sample_callback(void *vstart, void *vend, int stride, void *data) {
- * VALUE v = (VALUE)vstart;
- * for (; v != (VALUE)vend; v += stride) {
- * if (RBASIC(v)->flags) { // liveness check
- * // do something with live object 'v'
- * }
- * return 0; // continue to iteration
+ * static int
+ * sample_callback(void *vstart, void *vend, int stride, void *data)
+ * {
+ * VALUE v = (VALUE)vstart;
+ * for (; v != (VALUE)vend; v += stride) {
+ * if (!rb_objspace_internal_object_p(v)) { // liveness check
+ * // do something with live object 'v'
+ * }
+ * }
+ * return 0; // continue to iteration
* }
*
* Note: 'vstart' is not a top of heap_page. This point the first