summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mrbgems/mruby-array-ext/mrblib/array.rb1
-rw-r--r--mrbgems/mruby-math/src/math.c39
-rw-r--r--src/gc.c6
-rw-r--r--tasks/toolchains/visualcpp.rake3
4 files changed, 42 insertions, 7 deletions
diff --git a/mrbgems/mruby-array-ext/mrblib/array.rb b/mrbgems/mruby-array-ext/mrblib/array.rb
index df3ab97e4..fd80fa0bb 100644
--- a/mrbgems/mruby-array-ext/mrblib/array.rb
+++ b/mrbgems/mruby-array-ext/mrblib/array.rb
@@ -617,7 +617,6 @@ class Array
return to_enum :delete_if unless block_given?
idx = 0
- len = self.size
while idx < self.size do
if block.call(self[idx])
self.delete_at(idx)
diff --git a/mrbgems/mruby-math/src/math.c b/mrbgems/mruby-math/src/math.c
index a699a12f0..871cba301 100644
--- a/mrbgems/mruby-math/src/math.c
+++ b/mrbgems/mruby-math/src/math.c
@@ -9,8 +9,14 @@
#include <math.h>
-#define domain_error(msg) \
- mrb_raise(mrb, E_RANGE_ERROR, "Numerical argument is out of domain - " #msg)
+static void
+domain_error(mrb_state *mrb, const char *func)
+{
+ struct RClass *math = mrb_module_get(mrb, "Math");
+ struct RClass *domainerror = mrb_class_get_under(mrb, math, "DomainError");
+ mrb_value str = mrb_str_new_cstr(mrb, func);
+ mrb_raisef(mrb, domainerror, "Numerical argument is out of domain - %S", str);
+}
/* math functions not provided by Microsoft Visual C++ 2012 or older */
#if defined _MSC_VER && _MSC_VER < 1800
@@ -172,6 +178,9 @@ math_asin(mrb_state *mrb, mrb_value obj)
mrb_float x;
mrb_get_args(mrb, "f", &x);
+ if (x < -1.0 || x > 1.0) {
+ domain_error(mrb, "asin");
+ }
x = asin(x);
return mrb_float_value(mrb, x);
@@ -189,6 +198,9 @@ math_acos(mrb_state *mrb, mrb_value obj)
mrb_float x;
mrb_get_args(mrb, "f", &x);
+ if (x < -1.0 || x > 1.0) {
+ domain_error(mrb, "acos");
+ }
x = acos(x);
return mrb_float_value(mrb, x);
@@ -334,6 +346,9 @@ math_acosh(mrb_state *mrb, mrb_value obj)
mrb_float x;
mrb_get_args(mrb, "f", &x);
+ if (x < 1.0) {
+ domain_error(mrb, "acosh");
+ }
x = acosh(x);
return mrb_float_value(mrb, x);
@@ -351,6 +366,9 @@ math_atanh(mrb_state *mrb, mrb_value obj)
mrb_float x;
mrb_get_args(mrb, "f", &x);
+ if (x < -1.0 || x > 1.0) {
+ domain_error(mrb, "atanh");
+ }
x = atanh(x);
return mrb_float_value(mrb, x);
@@ -404,8 +422,14 @@ math_log(mrb_state *mrb, mrb_value obj)
int argc;
argc = mrb_get_args(mrb, "f|f", &x, &base);
+ if (x < 0.0) {
+ domain_error(mrb, "log");
+ }
x = log(x);
if (argc == 2) {
+ if (base < 0.0) {
+ domain_error(mrb, "log");
+ }
x /= log(base);
}
return mrb_float_value(mrb, x);
@@ -429,6 +453,9 @@ math_log2(mrb_state *mrb, mrb_value obj)
mrb_float x;
mrb_get_args(mrb, "f", &x);
+ if (x < 0.0) {
+ domain_error(mrb, "log2");
+ }
x = log2(x);
return mrb_float_value(mrb, x);
@@ -451,6 +478,9 @@ math_log10(mrb_state *mrb, mrb_value obj)
mrb_float x;
mrb_get_args(mrb, "f", &x);
+ if (x < 0.0) {
+ domain_error(mrb, "log10");
+ }
x = log10(x);
return mrb_float_value(mrb, x);
@@ -469,6 +499,9 @@ math_sqrt(mrb_state *mrb, mrb_value obj)
mrb_float x;
mrb_get_args(mrb, "f", &x);
+ if (x < 0.0) {
+ domain_error(mrb, "sqrt");
+ }
x = sqrt(x);
return mrb_float_value(mrb, x);
@@ -624,6 +657,8 @@ mrb_mruby_math_gem_init(mrb_state* mrb)
struct RClass *mrb_math;
mrb_math = mrb_define_module(mrb, "Math");
+ mrb_define_class_under(mrb, mrb_math, "DomainError", mrb->eStandardError_class);
+
#ifdef M_PI
mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(mrb, M_PI));
#else
diff --git a/src/gc.c b/src/gc.c
index 2660ffcc7..4478b71f3 100644
--- a/src/gc.c
+++ b/src/gc.c
@@ -121,9 +121,9 @@ static double gc_total_time = 0;
static double
gettimeofday_time(void)
{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return tv.tv_sec + tv.tv_usec * 1e-6;
+ struct timeval tv;
+ gettimeofday(&tv, NULL);
+ return tv.tv_sec + tv.tv_usec * 1e-6;
}
#define GC_INVOKE_TIME_REPORT(with) do {\
diff --git a/tasks/toolchains/visualcpp.rake b/tasks/toolchains/visualcpp.rake
index 1498ec3c9..a5726dce7 100644
--- a/tasks/toolchains/visualcpp.rake
+++ b/tasks/toolchains/visualcpp.rake
@@ -1,7 +1,8 @@
MRuby::Toolchain.new(:visualcpp) do |conf|
[conf.cc].each do |cc|
cc.command = ENV['CC'] || 'cl.exe'
- cc.flags = [ENV['CFLAGS'] || %w(/c /nologo /W3 /Zi /MD /O2 /D_CRT_SECURE_NO_WARNINGS)]
+ # C4013: implicit function declaration
+ cc.flags = [ENV['CFLAGS'] || %w(/c /nologo /W3 /we4013 /Zi /MD /O2 /D_CRT_SECURE_NO_WARNINGS)]
cc.include_paths = ["#{MRUBY_ROOT}/include"]
cc.defines = %w(DISABLE_GEMS MRB_STACK_EXTEND_DOUBLING)
cc.option_include_path = '/I%s'