diff --git a/.clang-format b/.clang-format new file mode 100644 index 000000000..7b6c459a3 --- /dev/null +++ b/.clang-format @@ -0,0 +1,17 @@ +AlwaysBreakAfterDefinitionReturnType: All +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Custom +BraceWrapping: + AfterControlStatement: true + AfterEnum: true + AfterFunction: true + AfterStruct: true + AfterUnion: true + BeforeElse: true +ColumnLimit: 0 +ContinuationIndentWidth: 2 +IndentCaseLabels: true +MaxEmptyLinesToKeep: 2 +PointerAlignment: Right +SpaceAfterCStyleCast: false +SpacesBeforeTrailingComments: 1 diff --git a/.git-hooks/pre_commit/c_cop.rb b/.git-hooks/pre_commit/c_cop.rb index 787bb0204..d71dcb236 100644 --- a/.git-hooks/pre_commit/c_cop.rb +++ b/.git-hooks/pre_commit/c_cop.rb @@ -17,19 +17,18 @@ def run offenses = 0 applicable_files.each do |file| - res = execute([required_executable, file, '-o', "#{file}_"]) + res = execute(command, args: [file]) - unchanged = FileUtils.compare_file(file, "#{file}_") if res.success? + unchanged = res.success? && File.read(file) == res.stdout offenses += 1 unless unchanged - - FileUtils.rm_f("#{file}_") end return :pass if offenses.zero? file_list = applicable_files.join(' ') - [:fail, "#{offenses} errors found. Run `indent #{file_list}`"] + fixing_command = "#{command.join(' ')} -i #{file_list}" + [:fail, "#{offenses} errors found. Run `#{fixing_command}`"] end end end diff --git a/.indent.pro b/.indent.pro deleted file mode 100644 index eae1493eb..000000000 --- a/.indent.pro +++ /dev/null @@ -1,27 +0,0 @@ ---blank-lines-after-declarations ---blank-lines-after-procedures ---brace-indent 0 ---braces-after-if-line ---break-before-boolean-operator ---case-brace-indentation 0 ---case-indentation 2 ---comment-indentation 1 ---continuation-indentation 0 ---continue-at-parentheses ---declaration-comment-column 1 ---ignore-newlines ---indent-level 2 ---leave-optional-blank-lines ---dont-left-justify-declarations ---line-comments-indentation 0 ---line-length 80 ---no-blank-lines-after-commas ---no-parameter-indentation ---no-space-after-casts ---no-space-after-function-call-names ---no-space-after-parentheses ---no-tabs ---remove-preprocessor-space ---space-after-for ---space-after-if ---space-after-while diff --git a/.overcommit.yml b/.overcommit.yml index 97c236fe4..dbf341d90 100644 --- a/.overcommit.yml +++ b/.overcommit.yml @@ -23,11 +23,11 @@ CommitMsg: # PreCommit: CCop: - description: Analyzing C files with indent + description: Formatting C files with clang-format enabled: true - required_executable: indent - install_command: sudo apt-get install indent + required_executable: clang-format include: ext/byebug/*.[ch] + flags: ['-style=file'] BundleCheck: enabled: true diff --git a/.travis.yml b/.travis.yml index d97794ef9..08cdb9d7c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ cache: language: ruby before_install: - - sudo apt-get install indent shellcheck + - sudo apt-get install shellcheck - if [ "$LIBEDIT" == "true" ]; then sudo apt-get install libedit-dev; fi diff --git a/Dockerfile b/Dockerfile index 8642399d3..c2a5dbc2f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ USER root RUN apt-get update && apt-get install -y \ autoconf \ automake \ + clang-format \ bison \ bzip2 \ curl \ @@ -14,7 +15,6 @@ RUN apt-get update && apt-get install -y \ g++ \ gcc \ git \ - indent \ libc6-dev \ libffi-dev \ libgdbm-dev \ diff --git a/ext/byebug/breakpoint.c b/ext/byebug/breakpoint.c index de07625d6..08e036fa9 100644 --- a/ext/byebug/breakpoint.c +++ b/ext/byebug/breakpoint.c @@ -239,7 +239,7 @@ brkpt_source(VALUE self) } static void -mark_breakpoint(breakpoint_t * breakpoint) +mark_breakpoint(breakpoint_t *breakpoint) { rb_gc_mark(breakpoint->source); rb_gc_mark(breakpoint->expr); diff --git a/ext/byebug/byebug.c b/ext/byebug/byebug.c index 21a097910..d24a81e35 100644 --- a/ext/byebug/byebug.c +++ b/ext/byebug/byebug.c @@ -1,6 +1,6 @@ #include "byebug.h" -static VALUE mByebug; /* Ruby Byebug Module object */ +static VALUE mByebug; /* Ruby Byebug Module object */ static VALUE tracing = Qfalse; static VALUE post_mortem = Qfalse; @@ -75,7 +75,7 @@ check_started() } static void -trace_print(rb_trace_arg_t * trace_arg, debug_context_t * dc, +trace_print(rb_trace_arg_t *trace_arg, debug_context_t *dc, const char *file_filter, const char *debug_msg) { char *fullpath = NULL; @@ -127,7 +127,7 @@ trace_print(rb_trace_arg_t * trace_arg, debug_context_t * dc, } static void -cleanup(debug_context_t * dc) +cleanup(debug_context_t *dc) { dc->stop_reason = CTX_STOP_NONE; @@ -156,11 +156,11 @@ cleanup(debug_context_t * dc) if (CTX_FL_TEST(dc, CTX_FL_IGNORE)) \ return; \ \ - acquire_lock(dc); \ - \ + acquire_lock(dc); + -#define CALL_EVENT_SETUP \ - dc->calced_stack_size++; \ +#define CALL_EVENT_SETUP \ + dc->calced_stack_size++; \ dc->steps_out = dc->steps_out < 0 ? -1 : dc->steps_out + 1; #define RETURN_EVENT_SETUP \ @@ -176,7 +176,7 @@ cleanup(debug_context_t * dc) /* Functions that return control to byebug after the different events */ static VALUE -call_at(VALUE ctx, debug_context_t * dc, ID mid, int argc, VALUE arg) +call_at(VALUE ctx, debug_context_t *dc, ID mid, int argc, VALUE arg) { struct call_with_inspection_data cwi; VALUE argv[1]; @@ -193,19 +193,19 @@ call_at(VALUE ctx, debug_context_t * dc, ID mid, int argc, VALUE arg) } static VALUE -call_at_line(VALUE ctx, debug_context_t * dc) +call_at_line(VALUE ctx, debug_context_t *dc) { return call_at(ctx, dc, rb_intern("at_line"), 0, Qnil); } static VALUE -call_at_tracing(VALUE ctx, debug_context_t * dc) +call_at_tracing(VALUE ctx, debug_context_t *dc) { return call_at(ctx, dc, rb_intern("at_tracing"), 0, Qnil); } static VALUE -call_at_breakpoint(VALUE ctx, debug_context_t * dc, VALUE breakpoint) +call_at_breakpoint(VALUE ctx, debug_context_t *dc, VALUE breakpoint) { dc->stop_reason = CTX_STOP_BREAKPOINT; @@ -213,7 +213,7 @@ call_at_breakpoint(VALUE ctx, debug_context_t * dc, VALUE breakpoint) } static VALUE -call_at_catchpoint(VALUE ctx, debug_context_t * dc, VALUE exp) +call_at_catchpoint(VALUE ctx, debug_context_t *dc, VALUE exp) { dc->stop_reason = CTX_STOP_CATCHPOINT; @@ -221,7 +221,7 @@ call_at_catchpoint(VALUE ctx, debug_context_t * dc, VALUE exp) } static VALUE -call_at_return(VALUE ctx, debug_context_t * dc, VALUE return_value) +call_at_return(VALUE ctx, debug_context_t *dc, VALUE return_value) { dc->stop_reason = CTX_STOP_BREAKPOINT; @@ -229,7 +229,7 @@ call_at_return(VALUE ctx, debug_context_t * dc, VALUE return_value) } static VALUE -call_at_end(VALUE ctx, debug_context_t * dc) +call_at_end(VALUE ctx, debug_context_t *dc) { dc->stop_reason = CTX_STOP_BREAKPOINT; @@ -237,7 +237,7 @@ call_at_end(VALUE ctx, debug_context_t * dc) } static void -call_at_line_check(VALUE ctx, debug_context_t * dc, VALUE breakpoint) +call_at_line_check(VALUE ctx, debug_context_t *dc, VALUE breakpoint) { dc->stop_reason = CTX_STOP_STEP; @@ -721,7 +721,7 @@ Start(VALUE self) * +stop+ parameter forces byebug to stop at the first line of code in +file+ */ static VALUE -Debug_load(int argc, VALUE * argv, VALUE self) +Debug_load(int argc, VALUE *argv, VALUE self) { VALUE file, stop, context; debug_context_t *dc; diff --git a/ext/byebug/byebug.h b/ext/byebug/byebug.h index de60c7e00..d596b1371 100644 --- a/ext/byebug/byebug.h +++ b/ext/byebug/byebug.h @@ -8,22 +8,29 @@ #define UNUSED(x) (void)(x) /* flags */ -#define CTX_FL_DEAD (1<<1) /* this context belonged to a dead thread */ -#define CTX_FL_IGNORE (1<<2) /* this context belongs to ignored thread */ -#define CTX_FL_SUSPEND (1<<3) /* thread currently suspended */ -#define CTX_FL_TRACING (1<<4) /* call at_tracing method */ -#define CTX_FL_WAS_RUNNING (1<<5) /* thread was previously running */ -#define CTX_FL_STOP_ON_RET (1<<6) /* can stop on method 'end' */ -#define CTX_FL_IGNORE_STEPS (1<<7) /* doesn't countdown steps to break */ +#define CTX_FL_DEAD (1 << 1) /* this context belonged to a dead thread */ +#define CTX_FL_IGNORE (1 << 2) /* this context belongs to ignored thread */ +#define CTX_FL_SUSPEND (1 << 3) /* thread currently suspended */ +#define CTX_FL_TRACING (1 << 4) /* call at_tracing method */ +#define CTX_FL_WAS_RUNNING (1 << 5) /* thread was previously running */ +#define CTX_FL_STOP_ON_RET (1 << 6) /* can stop on method 'end' */ +#define CTX_FL_IGNORE_STEPS (1 << 7) /* doesn't countdown steps to break */ /* macro functions */ -#define CTX_FL_TEST(c,f) ((c)->flags & (f)) -#define CTX_FL_SET(c,f) do { (c)->flags |= (f); } while (0) -#define CTX_FL_UNSET(c,f) do { (c)->flags &= ~(f); } while (0) +#define CTX_FL_TEST(c, f) ((c)->flags & (f)) +#define CTX_FL_SET(c, f) \ + do \ + { \ + (c)->flags |= (f); \ + } while (0) +#define CTX_FL_UNSET(c, f) \ + do \ + { \ + (c)->flags &= ~(f); \ + } while (0) /* types */ -typedef enum -{ +typedef enum { CTX_STOP_NONE, CTX_STOP_STEP, CTX_STOP_BREAKPOINT, @@ -39,16 +46,15 @@ typedef struct VALUE thread; int thnum; - int dest_frame; /* next stop's frame if stopped by next */ - int lines; /* # of lines in dest_frame before stopping */ - int steps; /* # of steps before stopping */ - int steps_out; /* # of returns before stopping */ + int dest_frame; /* next stop's frame if stopped by next */ + int lines; /* # of lines in dest_frame before stopping */ + int steps; /* # of steps before stopping */ + int steps_out; /* # of returns before stopping */ - VALUE backtrace; /* [[loc, self, klass, binding], ...] */ + VALUE backtrace; /* [[loc, self, klass, binding], ...] */ } debug_context_t; -typedef enum -{ +typedef enum { LOCATION, SELF, CLASS, @@ -70,10 +76,18 @@ typedef struct } threads_table_t; enum bp_type -{ BP_POS_TYPE, BP_METHOD_TYPE }; +{ + BP_POS_TYPE, + BP_METHOD_TYPE +}; enum hit_condition -{ HIT_COND_NONE, HIT_COND_GE, HIT_COND_EQ, HIT_COND_MOD }; +{ + HIT_COND_NONE, + HIT_COND_GE, + HIT_COND_EQ, + HIT_COND_MOD +}; typedef struct { @@ -100,9 +114,9 @@ extern void remove_from_locked(VALUE thread); /* functions from threads.c */ extern void Init_threads_table(VALUE mByebug); extern VALUE create_threads_table(void); -extern void thread_context_lookup(VALUE thread, VALUE * context); +extern void thread_context_lookup(VALUE thread, VALUE *context); extern int is_living_thread(VALUE thread); -extern void acquire_lock(debug_context_t * dc); +extern void acquire_lock(debug_context_t *dc); extern void release_lock(void); /* global variables */ @@ -112,10 +126,10 @@ extern VALUE next_thread; /* functions from context.c */ extern void Init_context(VALUE mByebug); extern VALUE context_create(VALUE thread); -extern VALUE context_dup(debug_context_t * context); -extern void reset_stepping_stop_points(debug_context_t * context); +extern VALUE context_dup(debug_context_t *context); +extern void reset_stepping_stop_points(debug_context_t *context); extern VALUE call_with_debug_inspector(struct call_with_inspection_data *data); -extern VALUE context_backtrace_set(const rb_debug_inspector_t * inspector, +extern VALUE context_backtrace_set(const rb_debug_inspector_t *inspector, void *data); /* functions from breakpoint.c */ diff --git a/ext/byebug/context.c b/ext/byebug/context.c index 7bd2099cb..a9fe0ec7b 100644 --- a/ext/byebug/context.c +++ b/ext/byebug/context.c @@ -7,7 +7,7 @@ static int thnum_max = 0; /* "Step", "Next" and "Finish" do their work by saving information about where * to stop next. reset_stepping_stop_points removes/resets this information. */ extern void -reset_stepping_stop_points(debug_context_t * context) +reset_stepping_stop_points(debug_context_t *context) { context->dest_frame = -1; context->lines = -1; @@ -34,19 +34,19 @@ Context_dead(VALUE self) static void context_mark(void *data) { - debug_context_t *context = (debug_context_t *) data; + debug_context_t *context = (debug_context_t *)data; rb_gc_mark(context->backtrace); } static VALUE -dc_backtrace(const debug_context_t * context) +dc_backtrace(const debug_context_t *context) { return context->backtrace; } static int -dc_stack_size(debug_context_t * context) +dc_stack_size(debug_context_t *context) { if (NIL_P(dc_backtrace(context))) @@ -76,7 +76,7 @@ context_create(VALUE thread) } extern VALUE -context_dup(debug_context_t * context) +context_dup(debug_context_t *context) { debug_context_t *new_context = ALLOC(debug_context_t); @@ -90,7 +90,7 @@ context_dup(debug_context_t * context) static VALUE -dc_frame_get(const debug_context_t * context, int frame_index, frame_part type) +dc_frame_get(const debug_context_t *context, int frame_index, frame_part type) { VALUE frame; @@ -105,31 +105,31 @@ dc_frame_get(const debug_context_t * context, int frame_index, frame_part type) } static VALUE -dc_frame_location(const debug_context_t * context, int frame_index) +dc_frame_location(const debug_context_t *context, int frame_index) { return dc_frame_get(context, frame_index, LOCATION); } static VALUE -dc_frame_self(const debug_context_t * context, int frame_index) +dc_frame_self(const debug_context_t *context, int frame_index) { return dc_frame_get(context, frame_index, SELF); } static VALUE -dc_frame_class(const debug_context_t * context, int frame_index) +dc_frame_class(const debug_context_t *context, int frame_index) { return dc_frame_get(context, frame_index, CLASS); } static VALUE -dc_frame_binding(const debug_context_t * context, int frame_index) +dc_frame_binding(const debug_context_t *context, int frame_index) { return dc_frame_get(context, frame_index, BINDING); } static VALUE -load_backtrace(const rb_debug_inspector_t * inspector) +load_backtrace(const rb_debug_inspector_t *inspector) { VALUE backtrace = rb_ary_new(); VALUE locs = rb_debug_inspector_backtrace_locations(inspector); @@ -151,9 +151,9 @@ load_backtrace(const rb_debug_inspector_t * inspector) } extern VALUE -context_backtrace_set(const rb_debug_inspector_t * inspector, void *data) +context_backtrace_set(const rb_debug_inspector_t *inspector, void *data) { - debug_context_t *dc = (debug_context_t *) data; + debug_context_t *dc = (debug_context_t *)data; dc->backtrace = load_backtrace(inspector); @@ -161,7 +161,7 @@ context_backtrace_set(const rb_debug_inspector_t * inspector, void *data) } static VALUE -open_debug_inspector_i(const rb_debug_inspector_t * inspector, void *data) +open_debug_inspector_i(const rb_debug_inspector_t *inspector, void *data) { struct call_with_inspection_data *cwi = (struct call_with_inspection_data *)data; @@ -187,8 +187,8 @@ close_debug_inspector(struct call_with_inspection_data *cwi) extern VALUE call_with_debug_inspector(struct call_with_inspection_data *data) { - return rb_ensure(open_debug_inspector, (VALUE) data, close_debug_inspector, - (VALUE) data); + return rb_ensure(open_debug_inspector, (VALUE)data, close_debug_inspector, + (VALUE)data); } #define FRAME_SETUP \ @@ -208,7 +208,7 @@ call_with_debug_inspector(struct call_with_inspection_data *data) * Returns frame's binding. */ static VALUE -Context_frame_binding(int argc, VALUE * argv, VALUE self) +Context_frame_binding(int argc, VALUE *argv, VALUE self) { FRAME_SETUP; @@ -222,7 +222,7 @@ Context_frame_binding(int argc, VALUE * argv, VALUE self) * Returns frame's defined class. */ static VALUE -Context_frame_class(int argc, VALUE * argv, VALUE self) +Context_frame_class(int argc, VALUE *argv, VALUE self) { FRAME_SETUP; @@ -236,7 +236,7 @@ Context_frame_class(int argc, VALUE * argv, VALUE self) * Returns the name of the file in the frame. */ static VALUE -Context_frame_file(int argc, VALUE * argv, VALUE self) +Context_frame_file(int argc, VALUE *argv, VALUE self) { VALUE loc, absolute_path; @@ -259,7 +259,7 @@ Context_frame_file(int argc, VALUE * argv, VALUE self) * Returns the line number in the file in the frame. */ static VALUE -Context_frame_line(int argc, VALUE * argv, VALUE self) +Context_frame_line(int argc, VALUE *argv, VALUE self) { VALUE loc; @@ -277,7 +277,7 @@ Context_frame_line(int argc, VALUE * argv, VALUE self) * Returns the sym of the method in the frame. */ static VALUE -Context_frame_method(int argc, VALUE * argv, VALUE self) +Context_frame_method(int argc, VALUE *argv, VALUE self) { VALUE loc; @@ -295,7 +295,7 @@ Context_frame_method(int argc, VALUE * argv, VALUE self) * Returns self object of the frame. */ static VALUE -Context_frame_self(int argc, VALUE * argv, VALUE self) +Context_frame_self(int argc, VALUE *argv, VALUE self) { FRAME_SETUP; @@ -395,7 +395,7 @@ Context_stop_reason(VALUE self) * +frame+ (by default the newest one). */ static VALUE -Context_step_into(int argc, VALUE * argv, VALUE self) +Context_step_into(int argc, VALUE *argv, VALUE self) { VALUE steps, v_frame; int n_args, from_frame; @@ -435,7 +435,7 @@ Context_step_into(int argc, VALUE * argv, VALUE self) * event for that frame is triggered. */ static VALUE -Context_step_out(int argc, VALUE * argv, VALUE self) +Context_step_out(int argc, VALUE *argv, VALUE self) { int n_args, n_frames; VALUE v_frames, force; @@ -468,7 +468,7 @@ Context_step_out(int argc, VALUE * argv, VALUE self) * higher (if frame +frame+ finishes). */ static VALUE -Context_step_over(int argc, VALUE * argv, VALUE self) +Context_step_over(int argc, VALUE *argv, VALUE self) { int n_args, frame; VALUE lines, v_frame; diff --git a/ext/byebug/threads.c b/ext/byebug/threads.c index 5ea719c85..1a656e1c5 100644 --- a/ext/byebug/threads.c +++ b/ext/byebug/threads.c @@ -14,12 +14,12 @@ t_tbl_mark_keyvalue(st_data_t key, st_data_t value, st_data_t tbl) { UNUSED(tbl); - rb_gc_mark((VALUE) key); + rb_gc_mark((VALUE)key); if (!value) return ST_CONTINUE; - rb_gc_mark((VALUE) value); + rb_gc_mark((VALUE)value); return ST_CONTINUE; } @@ -27,16 +27,16 @@ t_tbl_mark_keyvalue(st_data_t key, st_data_t value, st_data_t tbl) static void t_tbl_mark(void *data) { - threads_table_t *t_tbl = (threads_table_t *) data; + threads_table_t *t_tbl = (threads_table_t *)data; st_table *tbl = t_tbl->tbl; - st_foreach(tbl, t_tbl_mark_keyvalue, (st_data_t) tbl); + st_foreach(tbl, t_tbl_mark_keyvalue, (st_data_t)tbl); } static void t_tbl_free(void *data) { - threads_table_t *t_tbl = (threads_table_t *) data; + threads_table_t *t_tbl = (threads_table_t *)data; st_free_table(t_tbl->tbl); xfree(t_tbl); @@ -70,7 +70,7 @@ check_thread_i(st_data_t key, st_data_t value, st_data_t data) if (!value) return ST_DELETE; - if (!is_living_thread((VALUE) key)) + if (!is_living_thread((VALUE)key)) return ST_DELETE; return ST_CONTINUE; @@ -110,7 +110,7 @@ cleanup_dead_threads(void) * Looks up a context in the threads table. If not present, it creates it. */ void -thread_context_lookup(VALUE thread, VALUE * context) +thread_context_lookup(VALUE thread, VALUE *context) { threads_table_t *t_tbl; @@ -129,7 +129,7 @@ thread_context_lookup(VALUE thread, VALUE * context) * Thanks to this, all threads are "frozen" while the user is typing commands. */ void -acquire_lock(debug_context_t * dc) +acquire_lock(debug_context_t *dc) { while ((!NIL_P(locker) && locker != rb_thread_current()) || CTX_FL_TEST(dc, CTX_FL_SUSPEND))