mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #5713 from dearblue/assert-object-size
Introduced `mrb_static_assert_object_size()`
This commit is contained in:
@@ -40,4 +40,8 @@ struct RFiber {
|
||||
struct mrb_context *cxt;
|
||||
};
|
||||
|
||||
#define mrb_static_assert_object_size(st) \
|
||||
mrb_static_assert(sizeof(st) <= sizeof(void*) * 6, \
|
||||
#st " size must be within 6 words")
|
||||
|
||||
#endif /* MRUBY_OBJECT_H */
|
||||
|
||||
@@ -84,4 +84,6 @@ struct RBigint {
|
||||
|
||||
#define RBIGINT(v) ((struct RBigint*)mrb_ptr(v))
|
||||
|
||||
mrb_static_assert_object_size(struct RBigint);
|
||||
|
||||
#endif /* MRUBY_BIGINT_H */
|
||||
|
||||
@@ -45,6 +45,8 @@ struct RComplex {
|
||||
#define complex_ptr(mrb, v) (&((struct RComplex*)mrb_obj_ptr(v))->r)
|
||||
#endif
|
||||
|
||||
mrb_static_assert_object_size(struct RComplex);
|
||||
|
||||
static struct RBasic*
|
||||
complex_alloc(mrb_state *mrb, struct RClass *c, struct mrb_complex **p)
|
||||
{
|
||||
@@ -352,10 +354,6 @@ void mrb_mruby_complex_gem_init(mrb_state *mrb)
|
||||
{
|
||||
struct RClass *comp;
|
||||
|
||||
#ifdef COMPLEX_INLINE
|
||||
mrb_assert(sizeof(struct mrb_complex) < sizeof(void*)*3);
|
||||
#endif
|
||||
|
||||
comp = mrb_define_class_id(mrb, MRB_SYM(Complex), mrb_class_get_id(mrb, MRB_SYM(Numeric)));
|
||||
MRB_SET_INSTANCE_TT(comp, MRB_TT_COMPLEX);
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ struct RRational {
|
||||
#define rational_ptr(mrb, v) (&((struct RRational*)mrb_obj_ptr(v))->r)
|
||||
#endif
|
||||
|
||||
mrb_static_assert_object_size(struct RRational);
|
||||
|
||||
static struct RBasic*
|
||||
rational_alloc(mrb_state *mrb, struct RClass *c, struct mrb_rational **p)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user