Skip to content

Commit 72627d8

Browse files
committed
Declare rb_data_typed_t parameters and return values as nonull
1 parent 4e0bb58 commit 72627d8

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎include/ruby/internal/core/rtypeddata.h‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ RBIMPL_ATTR_NONNULL((3))
396396
*/
397397
VALUE rb_data_typed_object_wrap(VALUE klass, void *datap, const rb_data_type_t *type);
398398

399+
RBIMPL_ATTR_NONNULL((3))
399400
/**
400401
* Identical to rb_data_typed_object_wrap(), except it allocates a new data
401402
* region internally instead of taking an existing one. The allocation is done
@@ -411,6 +412,7 @@ VALUE rb_data_typed_object_wrap(VALUE klass, void *datap, const rb_data_type_t *
411412
*/
412413
VALUE rb_data_typed_object_zalloc(VALUE klass, size_t size, const rb_data_type_t *type);
413414

415+
RBIMPL_ATTR_NONNULL(())
414416
/**
415417
* Checks for the domestic relationship between the two.
416418
*
@@ -425,6 +427,7 @@ VALUE rb_data_typed_object_zalloc(VALUE klass, size_t size, const rb_data_type_t
425427
*/
426428
int rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *parent);
427429

430+
RBIMPL_ATTR_NONNULL((2))
428431
/**
429432
* Checks if the given object is of given kind.
430433
*
@@ -435,6 +438,7 @@ int rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *
435438
*/
436439
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type);
437440

441+
RBIMPL_ATTR_NONNULL((2))
438442
/**
439443
* Identical to rb_typeddata_is_kind_of(), except it raises exceptions instead
440444
* of returning false.
@@ -586,7 +590,7 @@ RTYPEDDATA_P(VALUE obj)
586590

587591
RBIMPL_ATTR_PURE_UNLESS_DEBUG()
588592
RBIMPL_ATTR_ARTIFICIAL()
589-
/* :TODO: can this function be __attribute__((returns_nonnull)) or not? */
593+
RBIMPL_ATTR_RETURNS_NONNULL()
590594
/**
591595
* Queries for the type of given object.
592596
*
@@ -605,7 +609,9 @@ RTYPEDDATA_TYPE(VALUE obj)
605609
#endif
606610

607611
VALUE type = RTYPEDDATA(obj)->type & TYPED_DATA_PTR_MASK;
608-
return RBIMPL_CAST((const rb_data_type_t *)type);
612+
const rb_data_type_t *ptr = RBIMPL_CAST((const rb_data_type_t *)type);
613+
RBIMPL_ASSERT_OR_ASSUME(ptr);
614+
return ptr;
609615
}
610616

611617
RBIMPL_ATTR_ARTIFICIAL()
@@ -650,6 +656,7 @@ rbimpl_check_typeddata(VALUE obj, const rb_data_type_t *expected_type)
650656
#define TypedData_Get_Struct(obj,type,data_type,sval) \
651657
((sval) = RBIMPL_CAST((type *)rbimpl_check_typeddata((obj), (data_type))))
652658

659+
RBIMPL_ATTR_NONNULL((2))
653660
/**
654661
* While we don't stop you from using this function, it seems to be an
655662
* implementation detail of #TypedData_Make_Struct, which is preferred over

0 commit comments

Comments
 (0)