Skip to content

Commit 4a01563

Browse files
committed
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.
1 parent c30d900 commit 4a01563

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

include/ruby/internal/core/rdata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ struct RData {
143143
RUBY_DATA_FUNC dfree;
144144

145145
/** Pointer to the actual C level struct that you want to wrap.
146-
* This is in between dmark and dfree to allow DATA_PTR to continue
147-
* to work for both RData and non-embedded RTypedData.
146+
* This is after dmark and dfree to allow DATA_PTR to continue to work for
147+
* both RData and non-embedded RTypedData.
148148
*/
149149
void *data;
150150
};

include/ruby/internal/core/rtypeddata.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "ruby/internal/dllexport.h"
3838
#include "ruby/internal/error.h"
3939
#include "ruby/internal/fl_type.h"
40+
#include "ruby/internal/static_assert.h"
4041
#include "ruby/internal/stdbool.h"
4142
#include "ruby/internal/value_type.h"
4243

@@ -374,6 +375,8 @@ struct RTypedData {
374375
void *data;
375376
};
376377

378+
RBIMPL_STATIC_ASSERT(data_in_rtypeddata, offsetof(struct RData, data) == offsetof(struct RTypedData, data));
379+
377380
RBIMPL_SYMBOL_EXPORT_BEGIN()
378381
RBIMPL_ATTR_NONNULL((3))
379382
/**

0 commit comments

Comments
 (0)