From e6c6b961ebee9a4f8c2b0b3eff6b19ad7990b3c3 Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Tue, 1 Aug 2023 16:02:52 +0300 Subject: [PATCH] Run tool/lint.sh for C files in spec/ruby/optional/capi and fix formatting --- optional/capi/ext/class_spec.c | 8 +++---- optional/capi/ext/debug_spec.c | 2 +- optional/capi/ext/encoding_spec.c | 8 +++---- optional/capi/ext/exception_spec.c | 2 +- optional/capi/ext/gc_spec.c | 2 +- optional/capi/ext/integer_spec.c | 5 ++-- optional/capi/ext/io_spec.c | 8 +++---- optional/capi/ext/kernel_spec.c | 8 +++---- optional/capi/ext/object_spec.c | 36 ++++++++++++++--------------- optional/capi/ext/range_spec.c | 2 +- optional/capi/ext/string_spec.c | 17 +++++++------- optional/capi/ext/struct_spec.c | 13 ++++------- optional/capi/ext/tracepoint_spec.c | 2 +- 13 files changed, 53 insertions(+), 60 deletions(-) diff --git a/optional/capi/ext/class_spec.c b/optional/capi/ext/class_spec.c index 589025f677..f376534924 100644 --- a/optional/capi/ext/class_spec.c +++ b/optional/capi/ext/class_spec.c @@ -72,7 +72,7 @@ static VALUE class_spec_rb_class_new_instance_kw(VALUE self, VALUE args, VALUE k #endif static VALUE class_spec_rb_class_real(VALUE self, VALUE object) { - if(rb_type_p(object, T_FIXNUM)) { + if (rb_type_p(object, T_FIXNUM)) { return INT2FIX(rb_class_real(FIX2INT(object))); } else { return rb_class_real(CLASS_OF(object)); @@ -116,19 +116,19 @@ VALUE class_spec_define_attr(VALUE self, VALUE klass, VALUE sym, VALUE read, VAL } static VALUE class_spec_rb_define_class(VALUE self, VALUE name, VALUE super) { - if(NIL_P(super)) super = 0; + if (NIL_P(super)) super = 0; return rb_define_class(RSTRING_PTR(name), super); } static VALUE class_spec_rb_define_class_under(VALUE self, VALUE outer, VALUE name, VALUE super) { - if(NIL_P(super)) super = 0; + if (NIL_P(super)) super = 0; return rb_define_class_under(outer, RSTRING_PTR(name), super); } static VALUE class_spec_rb_define_class_id_under(VALUE self, VALUE outer, VALUE name, VALUE super) { - if(NIL_P(super)) super = 0; + if (NIL_P(super)) super = 0; return rb_define_class_id_under(outer, SYM2ID(name), super); } diff --git a/optional/capi/ext/debug_spec.c b/optional/capi/ext/debug_spec.c index 344dfc33fa..9131eda78b 100644 --- a/optional/capi/ext/debug_spec.c +++ b/optional/capi/ext/debug_spec.c @@ -45,7 +45,7 @@ static VALUE rb_debug_inspector_frame_iseq_get_callback(const rb_debug_inspector return rb_debug_inspector_frame_iseq_get(dc, NUM2LONG((VALUE) ptr)); } -static VALUE debug_spec_callback_data(VALUE self){ +static VALUE debug_spec_callback_data(VALUE self) { return callback_data; } diff --git a/optional/capi/ext/encoding_spec.c b/optional/capi/ext/encoding_spec.c index a0136530f2..a454ae8395 100644 --- a/optional/capi/ext/encoding_spec.c +++ b/optional/capi/ext/encoding_spec.c @@ -12,7 +12,7 @@ static VALUE encoding_spec_MBCLEN_CHARFOUND_P(VALUE self, VALUE obj) { } static VALUE encoding_spec_ENC_CODERANGE_ASCIIONLY(VALUE self, VALUE obj) { - if(ENC_CODERANGE_ASCIIONLY(obj)) { + if (ENC_CODERANGE_ASCIIONLY(obj)) { return Qtrue; } else { return Qfalse; @@ -61,13 +61,13 @@ static VALUE encoding_spec_rb_filesystem_encindex(VALUE self) { static VALUE encoding_spec_rb_default_internal_encoding(VALUE self) { rb_encoding* enc = rb_default_internal_encoding(); - if(enc == 0) return Qnil; + if (enc == 0) return Qnil; return rb_str_new2(enc->name); } static VALUE encoding_spec_rb_default_external_encoding(VALUE self) { rb_encoding* enc = rb_default_external_encoding(); - if(enc == 0) return Qnil; + if (enc == 0) return Qnil; return rb_str_new2(enc->name); } @@ -86,7 +86,7 @@ static VALUE encoding_spec_rb_enc_associate_index(VALUE self, VALUE obj, VALUE i static VALUE encoding_spec_rb_enc_compatible(VALUE self, VALUE a, VALUE b) { rb_encoding* enc = rb_enc_compatible(a, b); - if(!enc) return INT2FIX(0); + if (!enc) return INT2FIX(0); return rb_enc_from_encoding(enc); } diff --git a/optional/capi/ext/exception_spec.c b/optional/capi/ext/exception_spec.c index 0ff6bd55c7..0e8347ab0d 100644 --- a/optional/capi/ext/exception_spec.c +++ b/optional/capi/ext/exception_spec.c @@ -27,7 +27,7 @@ VALUE exception_spec_rb_exc_new3(VALUE self, VALUE str) { } VALUE exception_spec_rb_exc_raise(VALUE self, VALUE exc) { - if (self != Qundef) rb_exc_raise(exc); + if (self != Qundef) rb_exc_raise(exc); return Qnil; } diff --git a/optional/capi/ext/gc_spec.c b/optional/capi/ext/gc_spec.c index b323c2456d..7dd0b87655 100644 --- a/optional/capi/ext/gc_spec.c +++ b/optional/capi/ext/gc_spec.c @@ -51,7 +51,7 @@ static VALUE gc_spec_rb_gc(VALUE self) { return Qnil; } -static VALUE gc_spec_rb_gc_latest_gc_info(VALUE self, VALUE hash_or_key){ +static VALUE gc_spec_rb_gc_latest_gc_info(VALUE self, VALUE hash_or_key) { return rb_gc_latest_gc_info(hash_or_key); } diff --git a/optional/capi/ext/integer_spec.c b/optional/capi/ext/integer_spec.c index 16cd95f111..792fc0652a 100644 --- a/optional/capi/ext/integer_spec.c +++ b/optional/capi/ext/integer_spec.c @@ -6,8 +6,7 @@ extern "C" { #endif static VALUE integer_spec_rb_integer_pack(VALUE self, VALUE value, - VALUE words, VALUE numwords, VALUE wordsize, VALUE nails, VALUE flags) -{ + VALUE words, VALUE numwords, VALUE wordsize, VALUE nails, VALUE flags) { int result = rb_integer_pack(value, (void*)RSTRING_PTR(words), FIX2INT(numwords), FIX2INT(wordsize), FIX2INT(nails), FIX2INT(flags)); return INT2FIX(result); @@ -15,7 +14,7 @@ static VALUE integer_spec_rb_integer_pack(VALUE self, VALUE value, RUBY_EXTERN VALUE rb_int_positive_pow(long x, unsigned long y); /* internal.h, used in ripper */ -static VALUE integer_spec_rb_int_positive_pow(VALUE self, VALUE a, VALUE b){ +static VALUE integer_spec_rb_int_positive_pow(VALUE self, VALUE a, VALUE b) { return rb_int_positive_pow(FIX2INT(a), FIX2INT(b)); } diff --git a/optional/capi/ext/io_spec.c b/optional/capi/ext/io_spec.c index 1c554a1a31..ab3aef4c92 100644 --- a/optional/capi/ext/io_spec.c +++ b/optional/capi/ext/io_spec.c @@ -134,7 +134,7 @@ VALUE io_spec_rb_io_wait_readable(VALUE self, VALUE io, VALUE read_p) { rb_sys_fail("set_non_blocking failed"); #ifndef SET_NON_BLOCKING_FAILS_ALWAYS - if(RTEST(read_p)) { + if (RTEST(read_p)) { if (read(fd, buf, RB_IO_WAIT_READABLE_BUF) != -1) { return Qnil; } @@ -145,7 +145,7 @@ VALUE io_spec_rb_io_wait_readable(VALUE self, VALUE io, VALUE read_p) { ret = rb_io_wait_readable(fd); - if(RTEST(read_p)) { + if (RTEST(read_p)) { ssize_t r = read(fd, buf, RB_IO_WAIT_READABLE_BUF); if (r != RB_IO_WAIT_READABLE_BUF) { perror("read"); @@ -185,7 +185,7 @@ VALUE io_spec_rb_io_maybe_wait_readable(VALUE self, VALUE error, VALUE io, VALUE rb_sys_fail("set_non_blocking failed"); #ifndef SET_NON_BLOCKING_FAILS_ALWAYS - if(RTEST(read_p)) { + if (RTEST(read_p)) { if (read(fd, buf, RB_IO_WAIT_READABLE_BUF) != -1) { return Qnil; } @@ -197,7 +197,7 @@ VALUE io_spec_rb_io_maybe_wait_readable(VALUE self, VALUE error, VALUE io, VALUE // main part ret = rb_io_maybe_wait_readable(NUM2INT(error), io, timeout); - if(RTEST(read_p)) { + if (RTEST(read_p)) { ssize_t r = read(fd, buf, RB_IO_WAIT_READABLE_BUF); if (r != RB_IO_WAIT_READABLE_BUF) { perror("read"); diff --git a/optional/capi/ext/kernel_spec.c b/optional/capi/ext/kernel_spec.c index c83c49e923..a921eb13e0 100644 --- a/optional/capi/ext/kernel_spec.c +++ b/optional/capi/ext/kernel_spec.c @@ -220,7 +220,7 @@ static VALUE kernel_spec_rb_eval_string_protect(VALUE self, VALUE str, VALUE ary VALUE kernel_spec_rb_sys_fail(VALUE self, VALUE msg) { errno = 1; - if(msg == Qnil) { + if (msg == Qnil) { rb_sys_fail(0); } else if (self != Qundef) { rb_sys_fail(StringValuePtr(msg)); @@ -229,7 +229,7 @@ VALUE kernel_spec_rb_sys_fail(VALUE self, VALUE msg) { } VALUE kernel_spec_rb_syserr_fail(VALUE self, VALUE err, VALUE msg) { - if(msg == Qnil) { + if (msg == Qnil) { rb_syserr_fail(NUM2INT(err), NULL); } else if (self != Qundef) { rb_syserr_fail(NUM2INT(err), StringValuePtr(msg)); @@ -292,9 +292,9 @@ static VALUE kernel_spec_rb_yield_values2(VALUE self, VALUE ary) { } static VALUE do_rec(VALUE obj, VALUE arg, int is_rec) { - if(is_rec) { + if (is_rec) { return obj; - } else if(arg == Qtrue) { + } else if (arg == Qtrue) { return rb_exec_recursive(do_rec, obj, Qnil); } else { return Qnil; diff --git a/optional/capi/ext/object_spec.c b/optional/capi/ext/object_spec.c index 30ac44cf1f..fbcf6d9962 100644 --- a/optional/capi/ext/object_spec.c +++ b/optional/capi/ext/object_spec.c @@ -218,126 +218,126 @@ static VALUE so_check_type(VALUE self, VALUE obj, VALUE other) { } static VALUE so_is_type_nil(VALUE self, VALUE obj) { - if(TYPE(obj) == T_NIL) { + if (TYPE(obj) == T_NIL) { return Qtrue; } return Qfalse; } static VALUE so_is_type_object(VALUE self, VALUE obj) { - if(TYPE(obj) == T_OBJECT) { + if (TYPE(obj) == T_OBJECT) { return Qtrue; } return Qfalse; } static VALUE so_is_type_array(VALUE self, VALUE obj) { - if(TYPE(obj) == T_ARRAY) { + if (TYPE(obj) == T_ARRAY) { return Qtrue; } return Qfalse; } static VALUE so_is_type_module(VALUE self, VALUE obj) { - if(TYPE(obj) == T_MODULE) { + if (TYPE(obj) == T_MODULE) { return Qtrue; } return Qfalse; } static VALUE so_is_type_class(VALUE self, VALUE obj) { - if(TYPE(obj) == T_CLASS) { + if (TYPE(obj) == T_CLASS) { return Qtrue; } return Qfalse; } static VALUE so_is_type_data(VALUE self, VALUE obj) { - if(TYPE(obj) == T_DATA) { + if (TYPE(obj) == T_DATA) { return Qtrue; } return Qfalse; } static VALUE so_is_rb_type_p_nil(VALUE self, VALUE obj) { - if(rb_type_p(obj, T_NIL)) { + if (rb_type_p(obj, T_NIL)) { return Qtrue; } return Qfalse; } static VALUE so_is_rb_type_p_object(VALUE self, VALUE obj) { - if(rb_type_p(obj, T_OBJECT)) { + if (rb_type_p(obj, T_OBJECT)) { return Qtrue; } return Qfalse; } static VALUE so_is_rb_type_p_array(VALUE self, VALUE obj) { - if(rb_type_p(obj, T_ARRAY)) { + if (rb_type_p(obj, T_ARRAY)) { return Qtrue; } return Qfalse; } static VALUE so_is_rb_type_p_module(VALUE self, VALUE obj) { - if(rb_type_p(obj, T_MODULE)) { + if (rb_type_p(obj, T_MODULE)) { return Qtrue; } return Qfalse; } static VALUE so_is_rb_type_p_class(VALUE self, VALUE obj) { - if(rb_type_p(obj, T_CLASS)) { + if (rb_type_p(obj, T_CLASS)) { return Qtrue; } return Qfalse; } static VALUE so_is_rb_type_p_data(VALUE self, VALUE obj) { - if(rb_type_p(obj, T_DATA)) { + if (rb_type_p(obj, T_DATA)) { return Qtrue; } return Qfalse; } static VALUE so_is_rb_type_p_file(VALUE self, VALUE obj) { - if(rb_type_p(obj, T_FILE)) { + if (rb_type_p(obj, T_FILE)) { return Qtrue; } return Qfalse; } static VALUE so_is_builtin_type_object(VALUE self, VALUE obj) { - if(BUILTIN_TYPE(obj) == T_OBJECT) { + if (BUILTIN_TYPE(obj) == T_OBJECT) { return Qtrue; } return Qfalse; } static VALUE so_is_builtin_type_array(VALUE self, VALUE obj) { - if(BUILTIN_TYPE(obj) == T_ARRAY) { + if (BUILTIN_TYPE(obj) == T_ARRAY) { return Qtrue; } return Qfalse; } static VALUE so_is_builtin_type_module(VALUE self, VALUE obj) { - if(BUILTIN_TYPE(obj) == T_MODULE) { + if (BUILTIN_TYPE(obj) == T_MODULE) { return Qtrue; } return Qfalse; } static VALUE so_is_builtin_type_class(VALUE self, VALUE obj) { - if(BUILTIN_TYPE(obj) == T_CLASS) { + if (BUILTIN_TYPE(obj) == T_CLASS) { return Qtrue; } return Qfalse; } static VALUE so_is_builtin_type_data(VALUE self, VALUE obj) { - if(BUILTIN_TYPE(obj) == T_DATA) { + if (BUILTIN_TYPE(obj) == T_DATA) { return Qtrue; } return Qfalse; diff --git a/optional/capi/ext/range_spec.c b/optional/capi/ext/range_spec.c index 7a475ec695..b0cf1a8662 100644 --- a/optional/capi/ext/range_spec.c +++ b/optional/capi/ext/range_spec.c @@ -7,7 +7,7 @@ extern "C" { VALUE range_spec_rb_range_new(int argc, VALUE* argv, VALUE self) { int exclude_end = 0; - if(argc == 3) { + if (argc == 3) { exclude_end = RTEST(argv[2]); } return rb_range_new(argv[0], argv[1], exclude_end); diff --git a/optional/capi/ext/string_spec.c b/optional/capi/ext/string_spec.c index 9cbb50484d..24a9b4e4ca 100644 --- a/optional/capi/ext/string_spec.c +++ b/optional/capi/ext/string_spec.c @@ -62,7 +62,7 @@ VALUE string_spec_rb_str_buf_new(VALUE self, VALUE len, VALUE str) { buf = rb_str_buf_new(NUM2LONG(len)); - if(RTEST(str)) { + if (RTEST(str)) { snprintf(RSTRING_PTR(buf), NUM2LONG(len), "%s", RSTRING_PTR(str)); } @@ -129,7 +129,7 @@ VALUE string_spec_rb_str_conv_enc(VALUE self, VALUE str, VALUE from, VALUE to) { from_enc = rb_to_encoding(from); - if(NIL_P(to)) { + if (NIL_P(to)) { to_enc = 0; } else { to_enc = rb_to_encoding(to); @@ -139,14 +139,13 @@ VALUE string_spec_rb_str_conv_enc(VALUE self, VALUE str, VALUE from, VALUE to) { } VALUE string_spec_rb_str_conv_enc_opts(VALUE self, VALUE str, VALUE from, VALUE to, - VALUE ecflags, VALUE ecopts) -{ + VALUE ecflags, VALUE ecopts) { rb_encoding* from_enc; rb_encoding* to_enc; from_enc = rb_to_encoding(from); - if(NIL_P(to)) { + if (NIL_P(to)) { to_enc = 0; } else { to_enc = rb_to_encoding(to); @@ -200,7 +199,7 @@ VALUE string_spec_rb_str_new_offset(VALUE self, VALUE str, VALUE offset, VALUE l } VALUE string_spec_rb_str_new2(VALUE self, VALUE str) { - if(NIL_P(str)) { + if (NIL_P(str)) { return rb_str_new2(""); } else { return rb_str_new2(RSTRING_PTR(str)); @@ -216,7 +215,7 @@ VALUE string_spec_rb_str_export_to_enc(VALUE self, VALUE str, VALUE enc) { } VALUE string_spec_rb_str_new_cstr(VALUE self, VALUE str) { - if(NIL_P(str)) { + if (NIL_P(str)) { return rb_str_new_cstr(""); } else { return rb_str_new_cstr(RSTRING_PTR(str)); @@ -390,7 +389,7 @@ VALUE string_spec_RSTRING_PTR_set(VALUE self, VALUE str, VALUE i, VALUE chr) { VALUE string_spec_RSTRING_PTR_after_funcall(VALUE self, VALUE str, VALUE cb) { /* Silence gcc 4.3.2 warning about computed value not used */ - if(RSTRING_PTR(str)) { /* force it out */ + if (RSTRING_PTR(str)) { /* force it out */ rb_funcall(cb, rb_intern("call"), 1, str); } @@ -573,7 +572,7 @@ static VALUE string_spec_rb_utf8_str_new_cstr(VALUE self) { } PRINTF_ARGS(static VALUE call_rb_str_vcatf(VALUE mesg, const char *fmt, ...), 2, 3); -static VALUE call_rb_str_vcatf(VALUE mesg, const char *fmt, ...){ +static VALUE call_rb_str_vcatf(VALUE mesg, const char *fmt, ...) { va_list ap; va_start(ap, fmt); VALUE result = rb_str_vcatf(mesg, fmt, ap); diff --git a/optional/capi/ext/struct_spec.c b/optional/capi/ext/struct_spec.c index 0393d6937d..9c45bd5672 100644 --- a/optional/capi/ext/struct_spec.c +++ b/optional/capi/ext/struct_spec.c @@ -15,13 +15,11 @@ static VALUE struct_spec_rb_struct_getmember(VALUE self, VALUE st, VALUE key) { return rb_struct_getmember(st, SYM2ID(key)); } -static VALUE struct_spec_rb_struct_s_members(VALUE self, VALUE klass) -{ +static VALUE struct_spec_rb_struct_s_members(VALUE self, VALUE klass) { return rb_ary_dup(rb_struct_s_members(klass)); } -static VALUE struct_spec_rb_struct_members(VALUE self, VALUE st) -{ +static VALUE struct_spec_rb_struct_members(VALUE self, VALUE st) { return rb_ary_dup(rb_struct_members(st)); } @@ -56,14 +54,11 @@ static VALUE struct_spec_struct_define_under(VALUE self, VALUE outer, } static VALUE struct_spec_rb_struct_new(VALUE self, VALUE klass, - VALUE a, VALUE b, VALUE c) -{ - + VALUE a, VALUE b, VALUE c) { return rb_struct_new(klass, a, b, c); } -static VALUE struct_spec_rb_struct_size(VALUE self, VALUE st) -{ +static VALUE struct_spec_rb_struct_size(VALUE self, VALUE st) { return rb_struct_size(st); } diff --git a/optional/capi/ext/tracepoint_spec.c b/optional/capi/ext/tracepoint_spec.c index 78c459d6cb..6666c8f85c 100644 --- a/optional/capi/ext/tracepoint_spec.c +++ b/optional/capi/ext/tracepoint_spec.c @@ -17,7 +17,7 @@ static VALUE tracepoint_spec_rb_tracepoint_new(VALUE self, VALUE data) { return rb_tracepoint_new(Qnil, RUBY_EVENT_LINE, callback, (void*) data); } -static VALUE tracepoint_spec_callback_called(VALUE self){ +static VALUE tracepoint_spec_callback_called(VALUE self) { return callback_called; }