Permalink
Browse files

Use RBOOL and CBOOL where appropriate

In a lot of places we used ? : or multiple return style to return Ruby
boolean values. We have a helper for that, RBOOL so we might as well use
it. Also switch to using CBOOL where it's appropriate for Ruby to C(++)
boolean checks.
  • Loading branch information...
1 parent bdcd473 commit 8ffde2ea6930fca59de6aa03b2fa15720ac0ac7e @dbussink dbussink committed Mar 26, 2013
View
@@ -101,7 +101,7 @@ namespace rubinius {
}
if(Module* mod = try_as<Module>(unit->value())) {
- return obj->kind_of_p(state, mod) ? cTrue : cFalse;
+ return RBOOL(obj->kind_of_p(state, mod));
} else {
return cFalse;
}
@@ -368,7 +368,7 @@ namespace rubinius {
}
}
- return removed ? cTrue : cFalse;
+ return RBOOL(removed);
}
Object* CompiledCode::is_breakpoint(STATE, Fixnum* ip) {
@@ -380,8 +380,7 @@ namespace rubinius {
bool found = false;
breakpoints_->fetch(state, ip, &found);
- if(found) return cTrue;
- return cFalse;
+ return RBOOL(found);
}
CompiledCode* CompiledCode::of_sender(STATE, CallFrame* calling_environment) {
View
@@ -80,7 +80,7 @@ namespace rubinius {
}
Object* Dir::closed_p(STATE) {
- return os_ ? cFalse : cTrue;
+ return RBOOL(!os_);
}
Object* Dir::read(STATE) {
View
@@ -443,8 +443,7 @@ namespace rubinius {
}
Object* Encoding::ascii_compatible_p(STATE) {
- bool v = encoding_->min_enc_len == 1 && dummy_ == cFalse;
- return v ? cTrue : cFalse;
+ return RBOOL(encoding_->min_enc_len == 1 && dummy_ == cFalse);
}
void Encoding::make_managed(STATE, const char* name, OnigEncodingType* enc) {
@@ -296,7 +296,7 @@ namespace rubinius {
ret = Fixnum::from((unsigned int)(READ(unsigned char)));
break;
case RBX_FFI_TYPE_BOOL:
- ret = (READ(unsigned char)) ? cTrue : cFalse;
+ ret = RBOOL(READ(unsigned char));
break;
case RBX_FFI_TYPE_SHORT:
ret = Fixnum::from((int)(READ(short)));
View
@@ -245,15 +245,15 @@ namespace rubinius {
}
Object* Fixnum::equal(STATE, Fixnum* other) {
- return to_native() == other->to_native() ? cTrue : cFalse;
+ return RBOOL(to_native() == other->to_native());
}
Object* Fixnum::equal(STATE, Bignum* other) {
return other->equal(state, this);
}
Object* Fixnum::equal(STATE, Float* other) {
- return (double)to_native() == other->val ? cTrue : cFalse;
+ return RBOOL((double)to_native() == other->val);
}
Object* Fixnum::compare(STATE, Fixnum* other) {
@@ -296,39 +296,39 @@ namespace rubinius {
}
Object* Fixnum::gt(STATE, Float* other) {
- return (double) to_native() > other->val ? cTrue : cFalse;
+ return RBOOL((double) to_native() > other->val);
}
Object* Fixnum::ge(STATE, Fixnum* other) {
- return to_native() >= other->to_native() ? cTrue : cFalse;
+ return RBOOL(to_native() >= other->to_native());
}
Object* Fixnum::ge(STATE, Bignum* other) {
return other->le(state, this);
}
Object* Fixnum::ge(STATE, Float* other) {
- return (double) to_native() >= other->val ? cTrue : cFalse;
+ return RBOOL((double) to_native() >= other->val);
}
Object* Fixnum::lt(STATE, Bignum* other) {
return other->gt(state, this);
}
Object* Fixnum::lt(STATE, Float* other) {
- return (double) to_native() < other->val ? cTrue : cFalse;
+ return RBOOL((double) to_native() < other->val);
}
Object* Fixnum::le(STATE, Fixnum* other) {
- return to_native() <= other->to_native() ? cTrue : cFalse;
+ return RBOOL(to_native() <= other->to_native());
}
Object* Fixnum::le(STATE, Bignum* other) {
return other->ge(state, this);
}
Object* Fixnum::le(STATE, Float* other) {
- return (double) to_native() <= other->val ? cTrue : cFalse;
+ return RBOOL((double) to_native() <= other->val);
}
Integer* Fixnum::left_shift(STATE, Fixnum* bits) {
View
@@ -36,7 +36,7 @@ namespace rubinius {
// Rubinius.primitive :fixnum_s_eqq
static Object* is_fixnum(STATE, Object* obj) {
- return obj->fixnum_p() ? cTrue : cFalse;
+ return RBOOL(obj->fixnum_p());
}
// Rubinius.primitive! :fixnum_add
@@ -139,7 +139,7 @@ namespace rubinius {
// Rubinius.primitive! :fixnum_gt
Object* gt(STATE, Fixnum* other) {
- return to_native() > other->to_native() ? cTrue : cFalse;
+ return RBOOL(to_native() > other->to_native());
}
// Rubinius.primitive! :fixnum_gt
@@ -159,7 +159,7 @@ namespace rubinius {
// Rubinius.primitive! :fixnum_lt
Object* lt(STATE, Fixnum* other) {
- return to_native() < other->to_native() ? cTrue : cFalse;
+ return RBOOL(to_native() < other->to_native());
}
// Rubinius.primitive! :fixnum_lt
View
@@ -76,7 +76,7 @@ namespace rubinius {
while(isspace(*str) || *str == '_') {
if(*str == '_') {
// Leading underscores are not allowed in strict mode.
- if(strict == cTrue) {
+ if(CBOOL(strict)) {
return nil<Float>();
}
@@ -97,7 +97,7 @@ namespace rubinius {
while(*str) {
// Remove underscores between digits.
if(*str == '_') {
- if(strict == cTrue) {
+ if(CBOOL(strict)) {
// Underscores are only allowed to be used as separators in strict mode.
char next = *++str;
@@ -112,7 +112,7 @@ namespace rubinius {
}
// Ensure there is a digit to the right side of the decimal in strict mode.
- if(*str == '.' && !isdigit(str[1]) && strict == cTrue) {
+ if(*str == '.' && !isdigit(str[1]) && CBOOL(strict)) {
return nil<Float>();
}
@@ -125,7 +125,7 @@ namespace rubinius {
// Check for the hex prefix.
if(p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) {
- if(strict == cTrue) {
+ if(CBOOL(strict)) {
// Only allow hex in Ruby > 1.8.
if(LANGUAGE_18_ENABLED(state)) {
return nil<Float>();
@@ -166,7 +166,7 @@ namespace rubinius {
// Disallow if the string is indeed a special value.
if(special) {
- if(strict == cTrue) {
+ if(CBOOL(strict)) {
return nil<Float>();
} else {
return Float::create(state, 0.0);
@@ -179,7 +179,7 @@ namespace rubinius {
char *rest;
double value = ruby_strtod(p, &rest);
- if(strict == cTrue) {
+ if(CBOOL(strict)) {
// Disallow empty strings in strict mode.
if(p == rest) {
return nil<Float>();
@@ -282,25 +282,16 @@ namespace rubinius {
}
Object* Float::equal(STATE, Float* other) {
- if(this->val == other->val) {
- return cTrue;
- }
- return cFalse;
+ return RBOOL(this->val == other->val);
}
Object* Float::equal(STATE, Integer* other) {
Float* o = Float::coerce(state, other);
- if(this->val == o->val) {
- return cTrue;
- }
- return cFalse;
+ return RBOOL(this->val == o->val);
}
Object* Float::eql(STATE, Float* other) {
- if(this->val == other->val) {
- return cTrue;
- }
- return cFalse;
+ return RBOOL(this->val == other->val);
}
Object* Float::eql(STATE, Integer* other) {
@@ -322,7 +313,7 @@ namespace rubinius {
Object* Float::compare(STATE, Integer* other) {
if(isinf(this->val)) {
if(this->val > 0) {
- return Fixnum::from(1);
+ return Fixnum::from(1);
} else {
return Fixnum::from(-1);
}
@@ -340,35 +331,35 @@ namespace rubinius {
}
Object* Float::gt(STATE, Float* other) {
- return this->val > other->val ? cTrue : cFalse;
+ return RBOOL(this->val > other->val);
}
Object* Float::gt(STATE, Integer* other) {
- return this->val > Float::coerce(state, other)->val ? cTrue : cFalse;
+ return RBOOL(this->val > Float::coerce(state, other)->val);
}
Object* Float::ge(STATE, Float* other) {
- return this->val >= other->val ? cTrue : cFalse;
+ return RBOOL(this->val >= other->val);
}
Object* Float::ge(STATE, Integer* other) {
- return this->val >= Float::coerce(state, other)->val ? cTrue : cFalse;
+ return RBOOL(this->val >= Float::coerce(state, other)->val);
}
Object* Float::lt(STATE, Float* other) {
- return this->val < other->val ? cTrue : cFalse;
+ return RBOOL(this->val < other->val);
}
Object* Float::lt(STATE, Integer* other) {
- return this->val < Float::coerce(state, other)->val ? cTrue : cFalse;
+ return RBOOL(this->val < Float::coerce(state, other)->val);
}
Object* Float::le(STATE, Float* other) {
- return this->val <= other->val ? cTrue : cFalse;
+ return RBOOL(this->val <= other->val);
}
Object* Float::le(STATE, Integer* other) {
- return this->val <= Float::coerce(state, other)->val ? cTrue : cFalse;
+ return RBOOL(this->val <= Float::coerce(state, other)->val);
}
Object* Float::fisinf(STATE) {
@@ -380,7 +371,7 @@ namespace rubinius {
}
Object* Float::fisnan(STATE) {
- return isnan(this->val) == 1 ? cTrue : cFalse;
+ return RBOOL(isnan(this->val));
}
Integer* Float::fround(STATE) {
@@ -458,7 +449,7 @@ namespace rubinius {
char str[sizeof(double)];
int sz;
- if (want_double == cTrue) {
+ if(CBOOL(want_double)) {
double* p = (double *)str;
*p = this->val;
sz = 8;
View
@@ -140,7 +140,7 @@ namespace rubinius {
// Leading whitespace is OK in strict mode, but underscores are not.
while(isspace(*str) || *str == '_') {
if(*str == '_') {
- if(strict == cTrue) {
+ if(CBOOL(strict)) {
return nil<Integer>();
} else if(!LANGUAGE_18_ENABLED(state)) {
return value;
@@ -243,7 +243,7 @@ namespace rubinius {
// If there is more stuff after the spaces, get out of dodge.
if(chr) {
- if(strict == cTrue) {
+ if(CBOOL(strict)) {
return nil<Integer>();
} else {
goto return_value;
@@ -258,7 +258,7 @@ namespace rubinius {
if(chr == '_') {
if(underscore) {
// Double underscore is forbidden in strict mode.
- if(strict == cTrue) {
+ if(CBOOL(strict)) {
return nil<Integer>();
} else {
// Stop parse number after two underscores in a row
@@ -280,7 +280,7 @@ namespace rubinius {
chr -= ('a' - 10);
} else {
//Invalid character, stopping right here.
- if(strict == cTrue) {
+ if(CBOOL(strict)) {
return nil<Integer>();
} else {
break;
@@ -290,7 +290,7 @@ namespace rubinius {
// Bail if the current chr is greater or equal to the base,
// mean it's invalid.
if(chr >= base) {
- if(strict == cTrue) {
+ if(CBOOL(strict)) {
return nil<Integer>();
} else {
break;
@@ -313,7 +313,7 @@ namespace rubinius {
}
// If we last saw an underscore and we're strict, bail.
- if(underscore && strict == cTrue) {
+ if(underscore && CBOOL(strict)) {
return nil<Integer>();
}
View
@@ -938,7 +938,7 @@ namespace rubinius {
native_int fd = to_fd();
if(op == state->symbol("tty?")) {
- return isatty(fd) ? cTrue : cFalse;
+ return RBOOL(isatty(fd));
#ifndef RBX_WINDOWS
} else if(op == state->symbol("ttyname")) {
return String::create(state, ttyname(fd));
@@ -1131,11 +1131,7 @@ namespace rubinius {
}
Object* IO::fnmatch(STATE, String* pattern, String* path, Fixnum* flags) {
- if(mri_fnmatch(pattern->c_str(state), path->c_str(state), flags->to_native())) {
- return cTrue;
- }
-
- return cFalse;
+ return RBOOL(mri_fnmatch(pattern->c_str(state), path->c_str(state), flags->to_native()));
}
View
@@ -349,7 +349,7 @@ namespace rubinius {
mod = as<Module>(sc->attached_instance());
}
- if (this->cvar_defined(state, name) == cTrue) {
+ if(CBOOL(this->cvar_defined(state, name))) {
ss << "cannot remove ";
ss << name->debug_str(state);
ss << " for ";
Oops, something went wrong.

0 comments on commit 8ffde2e

Please sign in to comment.