зеркало из https://github.com/github/ruby.git
Introduce `RBIMPL_NONNULL_ARG` macro
Runtime assertion for the argument declared as non-null. This macro does nothing if `RBIMPL_ATTR_NONNULL` is effective, otherwise asserts that the argument is non-null.
This commit is contained in:
Родитель
582602d142
Коммит
f7ffe9dbde
|
@ -3446,11 +3446,9 @@ rb_arithmetic_sequence_extract(VALUE obj, rb_arithmetic_sequence_components_t *c
|
||||||
VALUE
|
VALUE
|
||||||
rb_arithmetic_sequence_beg_len_step(VALUE obj, long *begp, long *lenp, long *stepp, long len, int err)
|
rb_arithmetic_sequence_beg_len_step(VALUE obj, long *begp, long *lenp, long *stepp, long len, int err)
|
||||||
{
|
{
|
||||||
#if !RBIMPL_HAS_ATTRIBUTE(nonnull)
|
RBIMPL_NONNULL_ARG(begp);
|
||||||
RUBY_ASSERT(begp != NULL);
|
RBIMPL_NONNULL_ARG(lenp);
|
||||||
RUBY_ASSERT(lenp != NULL);
|
RBIMPL_NONNULL_ARG(stepp);
|
||||||
RUBY_ASSERT(stepp != NULL);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rb_arithmetic_sequence_components_t aseq;
|
rb_arithmetic_sequence_components_t aseq;
|
||||||
if (!rb_arithmetic_sequence_extract(obj, &aseq)) {
|
if (!rb_arithmetic_sequence_extract(obj, &aseq)) {
|
||||||
|
|
9
gc.c
9
gc.c
|
@ -2767,21 +2767,14 @@ rb_data_object_zalloc(VALUE klass, size_t size, RUBY_DATA_FUNC dmark, RUBY_DATA_
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
COMPILER_WARNING_PUSH
|
|
||||||
#if __has_warning("-Wnonnull-compare") || GCC_VERSION_SINCE(6, 1, 0)
|
|
||||||
COMPILER_WARNING_IGNORED(-Wnonnull-compare)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_data_typed_object_wrap(VALUE klass, void *datap, const rb_data_type_t *type)
|
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);
|
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));
|
return newobj_of(klass, T_DATA, (VALUE)type, (VALUE)1, (VALUE)datap, type->flags & RUBY_FL_WB_PROTECTED, sizeof(RVALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
COMPILER_WARNING_POP
|
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_data_typed_object_zalloc(VALUE klass, size_t size, const rb_data_type_t *type)
|
rb_data_typed_object_zalloc(VALUE klass, size_t size, const rb_data_type_t *type)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,8 +25,10 @@
|
||||||
/** Wraps (or simulates) `__attribute__((nonnull))` */
|
/** Wraps (or simulates) `__attribute__((nonnull))` */
|
||||||
#if RBIMPL_HAS_ATTRIBUTE(nonnull)
|
#if RBIMPL_HAS_ATTRIBUTE(nonnull)
|
||||||
# define RBIMPL_ATTR_NONNULL(list) __attribute__((__nonnull__ list))
|
# define RBIMPL_ATTR_NONNULL(list) __attribute__((__nonnull__ list))
|
||||||
|
# define RBIMPL_NONNULL_ARG(arg) RBIMPL_ASSERT_NOTHING
|
||||||
#else
|
#else
|
||||||
# define RBIMPL_ATTR_NONNULL(list) /* void */
|
# define RBIMPL_ATTR_NONNULL(list) /* void */
|
||||||
|
# define RBIMPL_NONNULL_ARG(arg) RUBY_ASSERT(arg)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* RBIMPL_ATTR_NONNULL_H */
|
#endif /* RBIMPL_ATTR_NONNULL_H */
|
||||||
|
|
Загрузка…
Ссылка в новой задаче