Skip to content

Commit c352808

Browse files
committed
Introduce typed-data embeddable predicate macros
The combination of `&` and `&&` is confusing.
1 parent 9d37155 commit c352808

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

gc.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,9 @@ rb_data_object_zalloc(VALUE klass, size_t size, RUBY_DATA_FUNC dmark, RUBY_DATA_
10961096
return obj;
10971097
}
10981098

1099+
#define RB_DATA_TYPE_EMBEDDABLE_P(type) ((type)->flags & RUBY_TYPED_EMBEDDABLE)
1100+
#define RTYPEDDATA_EMBEDDABLE_P(obj) RB_DATA_TYPE_EMBEDDABLE_P(RTYPEDDATA_TYPE(obj))
1101+
10991102
static VALUE
11001103
typed_data_alloc(VALUE klass, VALUE typed_flag, void *datap, const rb_data_type_t *type, size_t size)
11011104
{
@@ -1117,7 +1120,7 @@ typed_data_alloc(VALUE klass, VALUE typed_flag, void *datap, const rb_data_type_
11171120
VALUE
11181121
rb_data_typed_object_wrap(VALUE klass, void *datap, const rb_data_type_t *type)
11191122
{
1120-
if (UNLIKELY(type->flags & RUBY_TYPED_EMBEDDABLE)) {
1123+
if (UNLIKELY(RB_DATA_TYPE_EMBEDDABLE_P(type))) {
11211124
rb_raise(rb_eTypeError, "Cannot wrap an embeddable TypedData");
11221125
}
11231126

@@ -1127,7 +1130,7 @@ rb_data_typed_object_wrap(VALUE klass, void *datap, const rb_data_type_t *type)
11271130
VALUE
11281131
rb_data_typed_object_zalloc(VALUE klass, size_t size, const rb_data_type_t *type)
11291132
{
1130-
if (type->flags & RUBY_TYPED_EMBEDDABLE) {
1133+
if (RB_DATA_TYPE_EMBEDDABLE_P(type)) {
11311134
if (!(type->flags & RUBY_TYPED_FREE_IMMEDIATELY)) {
11321135
rb_raise(rb_eTypeError, "Embeddable TypedData must be freed immediately");
11331136
}
@@ -1153,7 +1156,7 @@ rb_objspace_data_type_memsize(VALUE obj)
11531156
const rb_data_type_t *type = RTYPEDDATA_TYPE(obj);
11541157
const void *ptr = RTYPEDDATA_GET_DATA(obj);
11551158

1156-
if (RTYPEDDATA_TYPE(obj)->flags & RUBY_TYPED_EMBEDDABLE && !RTYPEDDATA_EMBEDDED_P(obj)) {
1159+
if (RTYPEDDATA_EMBEDDABLE_P(obj) && !RTYPEDDATA_EMBEDDED_P(obj)) {
11571160
#ifdef HAVE_MALLOC_USABLE_SIZE
11581161
size += malloc_usable_size((void *)ptr);
11591162
#endif
@@ -1285,7 +1288,7 @@ rb_data_free(void *objspace, VALUE obj)
12851288
}
12861289
else if (free_immediately) {
12871290
(*dfree)(data);
1288-
if (RTYPEDDATA_TYPE(obj)->flags & RUBY_TYPED_EMBEDDABLE && !RTYPEDDATA_EMBEDDED_P(obj)) {
1291+
if (RTYPEDDATA_EMBEDDABLE_P(obj) && !RTYPEDDATA_EMBEDDED_P(obj)) {
12891292
xfree(data);
12901293
}
12911294

0 commit comments

Comments
 (0)