Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce RBIMPL_NONNULL_ARG macro #4898

Merged
merged 1 commit into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions enumerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -3446,11 +3446,9 @@ rb_arithmetic_sequence_extract(VALUE obj, rb_arithmetic_sequence_components_t *c
VALUE
rb_arithmetic_sequence_beg_len_step(VALUE obj, long *begp, long *lenp, long *stepp, long len, int err)
{
#if !RBIMPL_HAS_ATTRIBUTE(nonnull)
RUBY_ASSERT(begp != NULL);
RUBY_ASSERT(lenp != NULL);
RUBY_ASSERT(stepp != NULL);
#endif
RBIMPL_NONNULL_ARG(begp);
RBIMPL_NONNULL_ARG(lenp);
RBIMPL_NONNULL_ARG(stepp);

rb_arithmetic_sequence_components_t aseq;
if (!rb_arithmetic_sequence_extract(obj, &aseq)) {
Expand Down
9 changes: 1 addition & 8 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2767,21 +2767,14 @@ rb_data_object_zalloc(VALUE klass, size_t size, RUBY_DATA_FUNC dmark, RUBY_DATA_
return obj;
}

COMPILER_WARNING_PUSH
#if __has_warning("-Wnonnull-compare") || GCC_VERSION_SINCE(6, 1, 0)
COMPILER_WARNING_IGNORED(-Wnonnull-compare)
#endif

VALUE
rb_data_typed_object_wrap(VALUE klass, void *datap, const rb_data_type_t *type)
{
RUBY_ASSERT_ALWAYS(type);
RBIMPL_NONNULL_ARG(type);
if (klass) rb_data_object_check(klass);
return newobj_of(klass, T_DATA, (VALUE)type, (VALUE)1, (VALUE)datap, type->flags & RUBY_FL_WB_PROTECTED, sizeof(RVALUE));
}

COMPILER_WARNING_POP

VALUE
rb_data_typed_object_zalloc(VALUE klass, size_t size, const rb_data_type_t *type)
{
Expand Down
2 changes: 2 additions & 0 deletions include/ruby/internal/attr/nonnull.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
/** Wraps (or simulates) `__attribute__((nonnull))` */
#if RBIMPL_HAS_ATTRIBUTE(nonnull)
# define RBIMPL_ATTR_NONNULL(list) __attribute__((__nonnull__ list))
# define RBIMPL_NONNULL_ARG(arg) RBIMPL_ASSERT_NOTHING
#else
# define RBIMPL_ATTR_NONNULL(list) /* void */
# define RBIMPL_NONNULL_ARG(arg) RUBY_ASSERT(arg)
#endif

#endif /* RBIMPL_ATTR_NONNULL_H */