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.
This commit is contained in:
Étienne Barrié 2025-08-14 17:26:58 +02:00 committed by Jean Boussier
parent a04555c8ab
commit 5aa5112443
2 changed files with 5 additions and 2 deletions

View file

@ -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;
};

View file

@ -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))
/**