From 5aa5112443274feb21f8c52789e216e213f4cf69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Thu, 14 Aug 2025 17:26:58 +0200 Subject: [PATCH] Fix documentation about struct RData's data field Also adds a static assertion to ensure the documented behavior stays true, namely that the data field is at the same position in the RData and RTypedData structs. --- include/ruby/internal/core/rdata.h | 4 ++-- include/ruby/internal/core/rtypeddata.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/ruby/internal/core/rdata.h b/include/ruby/internal/core/rdata.h index bebb2a8822..f9ff3acc5f 100644 --- a/include/ruby/internal/core/rdata.h +++ b/include/ruby/internal/core/rdata.h @@ -143,8 +143,8 @@ struct RData { RUBY_DATA_FUNC dfree; /** Pointer to the actual C level struct that you want to wrap. - * This is in between dmark and dfree to allow DATA_PTR to continue - * to work for both RData and non-embedded RTypedData. + * This is after dmark and dfree to allow DATA_PTR to continue to work for + * both RData and non-embedded RTypedData. */ void *data; }; diff --git a/include/ruby/internal/core/rtypeddata.h b/include/ruby/internal/core/rtypeddata.h index 539a2f86d2..9441b2f5c2 100644 --- a/include/ruby/internal/core/rtypeddata.h +++ b/include/ruby/internal/core/rtypeddata.h @@ -37,6 +37,7 @@ #include "ruby/internal/dllexport.h" #include "ruby/internal/error.h" #include "ruby/internal/fl_type.h" +#include "ruby/internal/static_assert.h" #include "ruby/internal/stdbool.h" #include "ruby/internal/value_type.h" @@ -374,6 +375,8 @@ struct RTypedData { void *data; }; +RBIMPL_STATIC_ASSERT(data_in_rtypeddata, offsetof(struct RData, data) == offsetof(struct RTypedData, data)); + RBIMPL_SYMBOL_EXPORT_BEGIN() RBIMPL_ATTR_NONNULL((3)) /**