From 375fec7c53c5b32f85c05f759c080678d29a9a94 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Tue, 17 Dec 2024 15:06:43 -0500 Subject: [PATCH] [DOC] Add note to rb_id2name about GC compaction --- include/ruby/internal/symbol.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/ruby/internal/symbol.h b/include/ruby/internal/symbol.h index 9b863d090e..594652151a 100644 --- a/include/ruby/internal/symbol.h +++ b/include/ruby/internal/symbol.h @@ -125,6 +125,10 @@ ID rb_intern_str(VALUE str); * @retval otherwise A name that the id represents. * @note The return value is managed by the interpreter. Don't pass it * to free(). + * @note This C string is backed by an underlying Ruby string. The Ruby + * string may move during GC compaction which would make this + * C string point to invalid memory. Do not use the return value + * of this function after a potential GC entry point. */ const char *rb_id2name(ID id);