Skip to content

Commit

Permalink
Add space between control statements and brackets.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 8, 2020
1 parent aadfd52 commit 77f859a
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 82 deletions.
2 changes: 1 addition & 1 deletion ext/nio4r/.clang-format
Expand Up @@ -11,6 +11,6 @@ BraceWrapping:
AfterControlStatement: Never
IndentCaseLabels: true
PointerAlignment: Right
SpaceBeforeParens: Never
SpaceBeforeParens: ControlStatements
IndentWidth: 4
...
46 changes: 23 additions & 23 deletions ext/nio4r/bytebuffer.c
Expand Up @@ -85,7 +85,7 @@ static void NIO_ByteBuffer_gc_mark(struct NIO_ByteBuffer *buffer)

static void NIO_ByteBuffer_free(struct NIO_ByteBuffer *buffer)
{
if(buffer->buffer)
if (buffer->buffer)
xfree(buffer->buffer);
xfree(buffer);
}
Expand Down Expand Up @@ -133,17 +133,17 @@ static VALUE NIO_ByteBuffer_set_position(VALUE self, VALUE new_position)

pos = NUM2INT(new_position);

if(pos < 0) {
if (pos < 0) {
rb_raise(rb_eArgError, "negative position given");
}

if(pos > buffer->limit) {
if (pos > buffer->limit) {
rb_raise(rb_eArgError, "specified position exceeds limit");
}

buffer->position = pos;

if(buffer->mark > buffer->position) {
if (buffer->mark > buffer->position) {
buffer->mark = MARK_UNSET;
}

Expand All @@ -166,21 +166,21 @@ static VALUE NIO_ByteBuffer_set_limit(VALUE self, VALUE new_limit)

lim = NUM2INT(new_limit);

if(lim < 0) {
if (lim < 0) {
rb_raise(rb_eArgError, "negative limit given");
}

if(lim > buffer->capacity) {
if (lim > buffer->capacity) {
rb_raise(rb_eArgError, "specified limit exceeds capacity");
}

buffer->limit = lim;

if(buffer->position > lim) {
if (buffer->position > lim) {
buffer->position = lim;
}

if(buffer->mark > lim) {
if (buffer->mark > lim) {
buffer->mark = MARK_UNSET;
}

Expand Down Expand Up @@ -220,17 +220,17 @@ static VALUE NIO_ByteBuffer_get(int argc, VALUE *argv, VALUE self)

rb_scan_args(argc, argv, "01", &length);

if(length == Qnil) {
if (length == Qnil) {
len = buffer->limit - buffer->position;
} else {
len = NUM2INT(length);
}

if(len < 0) {
if (len < 0) {
rb_raise(rb_eArgError, "negative length given");
}

if(len > buffer->limit - buffer->position) {
if (len > buffer->limit - buffer->position) {
rb_raise(cNIO_ByteBuffer_UnderflowError, "not enough data in buffer");
}

Expand All @@ -248,11 +248,11 @@ static VALUE NIO_ByteBuffer_fetch(VALUE self, VALUE index)

i = NUM2INT(index);

if(i < 0) {
if (i < 0) {
rb_raise(rb_eArgError, "negative index given");
}

if(i >= buffer->limit) {
if (i >= buffer->limit) {
rb_raise(rb_eArgError, "specified index exceeds limit");
}

Expand All @@ -268,7 +268,7 @@ static VALUE NIO_ByteBuffer_put(VALUE self, VALUE string)
StringValue(string);
length = RSTRING_LEN(string);

if(length > buffer->limit - buffer->position) {
if (length > buffer->limit - buffer->position) {
rb_raise(cNIO_ByteBuffer_OverflowError, "buffer is full");
}

Expand All @@ -289,14 +289,14 @@ static VALUE NIO_ByteBuffer_read_from(VALUE self, VALUE io)
rb_io_set_nonblock(fptr);

nbytes = buffer->limit - buffer->position;
if(nbytes == 0) {
if (nbytes == 0) {
rb_raise(cNIO_ByteBuffer_OverflowError, "buffer is full");
}

bytes_read = read(FPTR_TO_FD(fptr), buffer->buffer + buffer->position, nbytes);

if(bytes_read < 0) {
if(errno == EAGAIN) {
if (bytes_read < 0) {
if (errno == EAGAIN) {
return INT2NUM(0);
} else {
rb_sys_fail("write");
Expand All @@ -319,14 +319,14 @@ static VALUE NIO_ByteBuffer_write_to(VALUE self, VALUE io)
rb_io_set_nonblock(fptr);

nbytes = buffer->limit - buffer->position;
if(nbytes == 0) {
if (nbytes == 0) {
rb_raise(cNIO_ByteBuffer_UnderflowError, "no data remaining in buffer");
}

bytes_written = write(FPTR_TO_FD(fptr), buffer->buffer + buffer->position, nbytes);

if(bytes_written < 0) {
if(errno == EAGAIN) {
if (bytes_written < 0) {
if (errno == EAGAIN) {
return INT2NUM(0);
} else {
rb_sys_fail("write");
Expand Down Expand Up @@ -375,7 +375,7 @@ static VALUE NIO_ByteBuffer_reset(VALUE self)
struct NIO_ByteBuffer *buffer;
Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);

if(buffer->mark < 0) {
if (buffer->mark < 0) {
rb_raise(cNIO_ByteBuffer_MarkUnsetError, "mark has not been set");
} else {
buffer->position = buffer->mark;
Expand All @@ -402,8 +402,8 @@ static VALUE NIO_ByteBuffer_each(VALUE self)
struct NIO_ByteBuffer *buffer;
Data_Get_Struct(self, struct NIO_ByteBuffer, buffer);

if(rb_block_given_p()) {
for(i = 0; i < buffer->limit; i++) {
if (rb_block_given_p()) {
for (i = 0; i < buffer->limit; i++) {
rb_yield(INT2NUM(buffer->buffer[i]));
}
} else {
Expand Down
44 changes: 22 additions & 22 deletions ext/nio4r/monitor.c
Expand Up @@ -85,11 +85,11 @@ static VALUE NIO_Monitor_initialize(VALUE self, VALUE io, VALUE interests, VALUE

Data_Get_Struct(self, struct NIO_Monitor, monitor);

if(interests_id == rb_intern("r")) {
if (interests_id == rb_intern("r")) {
monitor->interests = EV_READ;
} else if(interests_id == rb_intern("w")) {
} else if (interests_id == rb_intern("w")) {
monitor->interests = EV_WRITE;
} else if(interests_id == rb_intern("rw")) {
} else if (interests_id == rb_intern("rw")) {
monitor->interests = EV_READ | EV_WRITE;
} else {
rb_raise(rb_eArgError, "invalid event type %s (must be :r, :w, or :rw)", RSTRING_PTR(rb_funcall(interests, rb_intern("inspect"), 0)));
Expand All @@ -111,7 +111,7 @@ static VALUE NIO_Monitor_initialize(VALUE self, VALUE io, VALUE interests, VALUE
object where it originally came from */
monitor->selector = selector;

if(monitor->interests) {
if (monitor->interests) {
ev_io_start(selector->ev_loop, &monitor->ev_io);
}

Expand All @@ -127,17 +127,17 @@ static VALUE NIO_Monitor_close(int argc, VALUE *argv, VALUE self)
rb_scan_args(argc, argv, "01", &deregister);
selector = rb_ivar_get(self, rb_intern("selector"));

if(selector != Qnil) {
if (selector != Qnil) {
/* if ev_loop is 0, it means that the loop has been stopped already (see NIO_Selector_shutdown) */
if(monitor->interests && monitor->selector->ev_loop) {
if (monitor->interests && monitor->selector->ev_loop) {
ev_io_stop(monitor->selector->ev_loop, &monitor->ev_io);
}

monitor->selector = 0;
rb_ivar_set(self, rb_intern("selector"), Qnil);

/* Default value is true */
if(deregister == Qtrue || deregister == Qnil) {
if (deregister == Qtrue || deregister == Qnil) {
rb_funcall(selector, rb_intern("deregister"), 1, rb_ivar_get(self, rb_intern("io")));
}
}
Expand Down Expand Up @@ -165,7 +165,7 @@ static VALUE NIO_Monitor_interests(VALUE self)

static VALUE NIO_Monitor_set_interests(VALUE self, VALUE interests)
{
if(NIL_P(interests)) {
if (NIL_P(interests)) {
NIO_Monitor_update_interests(self, 0);
} else {
NIO_Monitor_update_interests(self, NIO_Monitor_symbol2interest(interests));
Expand Down Expand Up @@ -216,11 +216,11 @@ static VALUE NIO_Monitor_readiness(VALUE self)
struct NIO_Monitor *monitor;
Data_Get_Struct(self, struct NIO_Monitor, monitor);

if((monitor->revents & (EV_READ | EV_WRITE)) == (EV_READ | EV_WRITE)) {
if ((monitor->revents & (EV_READ | EV_WRITE)) == (EV_READ | EV_WRITE)) {
return ID2SYM(rb_intern("rw"));
} else if(monitor->revents & EV_READ) {
} else if (monitor->revents & EV_READ) {
return ID2SYM(rb_intern("r"));
} else if(monitor->revents & EV_WRITE) {
} else if (monitor->revents & EV_WRITE) {
return ID2SYM(rb_intern("w"));
} else {
return Qnil;
Expand All @@ -232,7 +232,7 @@ static VALUE NIO_Monitor_is_readable(VALUE self)
struct NIO_Monitor *monitor;
Data_Get_Struct(self, struct NIO_Monitor, monitor);

if(monitor->revents & EV_READ) {
if (monitor->revents & EV_READ) {
return Qtrue;
} else {
return Qfalse;
Expand All @@ -244,7 +244,7 @@ static VALUE NIO_Monitor_is_writable(VALUE self)
struct NIO_Monitor *monitor;
Data_Get_Struct(self, struct NIO_Monitor, monitor);

if(monitor->revents & EV_WRITE) {
if (monitor->revents & EV_WRITE) {
return Qtrue;
} else {
return Qfalse;
Expand All @@ -258,11 +258,11 @@ static int NIO_Monitor_symbol2interest(VALUE interests)
ID interests_id;
interests_id = SYM2ID(interests);

if(interests_id == rb_intern("r")) {
if (interests_id == rb_intern("r")) {
return EV_READ;
} else if(interests_id == rb_intern("w")) {
} else if (interests_id == rb_intern("w")) {
return EV_WRITE;
} else if(interests_id == rb_intern("rw")) {
} else if (interests_id == rb_intern("rw")) {
return EV_READ | EV_WRITE;
} else {
rb_raise(rb_eArgError, "invalid interest type %s (must be :r, :w, or :rw)", RSTRING_PTR(rb_funcall(interests, rb_intern("inspect"), 0)));
Expand All @@ -275,12 +275,12 @@ static void NIO_Monitor_update_interests(VALUE self, int interests)
struct NIO_Monitor *monitor;
Data_Get_Struct(self, struct NIO_Monitor, monitor);

if(NIO_Monitor_is_closed(self) == Qtrue) {
if (NIO_Monitor_is_closed(self) == Qtrue) {
rb_raise(rb_eEOFError, "monitor is closed");
}

if(interests) {
switch(interests) {
if (interests) {
switch (interests) {
case EV_READ:
interests_id = rb_intern("r");
break;
Expand All @@ -299,9 +299,9 @@ static void NIO_Monitor_update_interests(VALUE self, int interests)
rb_ivar_set(self, rb_intern("interests"), Qnil);
}

if(monitor->interests != interests) {
if (monitor->interests != interests) {
// If the monitor currently has interests, we should stop it.
if(monitor->interests) {
if (monitor->interests) {
ev_io_stop(monitor->selector->ev_loop, &monitor->ev_io);
}

Expand All @@ -310,7 +310,7 @@ static void NIO_Monitor_update_interests(VALUE self, int interests)
ev_io_set(&monitor->ev_io, monitor->ev_io.fd, monitor->interests);

// If we are interested in events, schedule the monitor back into the event loop:
if(monitor->interests) {
if (monitor->interests) {
ev_io_start(monitor->selector->ev_loop, &monitor->ev_io);
}
}
Expand Down

0 comments on commit 77f859a

Please sign in to comment.