Skip to content

Commit

Permalink
Move to clang-format for C code formatting
Browse files Browse the repository at this point in the history
It's better mantained and it should make it easier to configure in
macOS.

I tried to keep current style the same as much as possible.
  • Loading branch information
deivid-rodriguez committed Dec 2, 2017
1 parent 80b2c23 commit 8e5cdc9
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 113 deletions.
17 changes: 17 additions & 0 deletions .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
9 changes: 4 additions & 5 deletions .git-hooks/pre_commit/c_cop.rb
Expand Up @@ -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
Expand Down
27 changes: 0 additions & 27 deletions .indent.pro

This file was deleted.

6 changes: 3 additions & 3 deletions .overcommit.yml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Expand Up @@ -7,14 +7,14 @@ USER root
RUN apt-get update && apt-get install -y \
autoconf \
automake \
clang-format \
bison \
bzip2 \
curl \
gawk \
g++ \
gcc \
git \
indent \
libc6-dev \
libffi-dev \
libgdbm-dev \
Expand Down
2 changes: 1 addition & 1 deletion ext/byebug/breakpoint.c
Expand Up @@ -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);
Expand Down
32 changes: 16 additions & 16 deletions 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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 \
Expand All @@ -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];
Expand All @@ -193,51 +193,51 @@ 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;

return call_at(ctx, dc, rb_intern("at_breakpoint"), 1, 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;

return call_at(ctx, dc, rb_intern("at_catchpoint"), 1, 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;

return call_at(ctx, dc, rb_intern("at_return"), 1, 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;

return call_at(ctx, dc, rb_intern("at_end"), 0, Qnil);
}

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;

Expand Down Expand Up @@ -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;
Expand Down
66 changes: 40 additions & 26 deletions ext/byebug/byebug.h
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
{
Expand All @@ -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 */
Expand All @@ -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 */
Expand Down

0 comments on commit 8e5cdc9

Please sign in to comment.