summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--INSTALL10
-rw-r--r--mrbgems/mruby-random/src/mt19937ar.c1
-rw-r--r--mrbgems/mruby-random/src/mt19937ar.h3
-rw-r--r--mrbgems/mruby-random/src/random.c62
-rw-r--r--src/class.c15
-rw-r--r--src/numeric.c2
-rw-r--r--tasks/toolchains/gcc.rake2
-rw-r--r--travis_config.rb2
8 files changed, 61 insertions, 36 deletions
diff --git a/INSTALL b/INSTALL
index d8b40243d..7a0e6cd47 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,6 +1,6 @@
* Prerequisites
-
- 1. Make sure you have bison (http://www.gnu.org/software/bison/) installed in your system.
+
+ 1. Make sure you have bison (http://www.gnu.org/software/bison/) installed in your system.
2. Make sure you have ruby installed in your system (required to build).
* Compilation and Installation
@@ -8,10 +8,10 @@
1. Run make in the top directory.
This command will create a build directory with a directory for the host environment
- and one for each crossbuild environment based on the settings in the build_config.rb
+ and one for each crossbuild environment based on the settings in the build_config.rb
file.
- Assuming a default build, each of the environment directories will have the following
+ Assuming a default build, each of the environment directories will have the following
important directories:
* bin - The binary executables for this environment
@@ -19,7 +19,7 @@
You can find the header files in the include directory at the root of the project.
- You can directory invoke 'minirake' as the following.
+ You can directly invoke 'minirake' with the following command:
$ ruby ./minirake
diff --git a/mrbgems/mruby-random/src/mt19937ar.c b/mrbgems/mruby-random/src/mt19937ar.c
index 41ed2c00d..2c22b23ad 100644
--- a/mrbgems/mruby-random/src/mt19937ar.c
+++ b/mrbgems/mruby-random/src/mt19937ar.c
@@ -4,6 +4,7 @@
** See Copyright Notice in mruby.h
*/
+#include "mruby.h"
#include "mt19937ar.h"
/* Period parameters */
diff --git a/mrbgems/mruby-random/src/mt19937ar.h b/mrbgems/mruby-random/src/mt19937ar.h
index d59bd8748..504355193 100644
--- a/mrbgems/mruby-random/src/mt19937ar.h
+++ b/mrbgems/mruby-random/src/mt19937ar.h
@@ -13,6 +13,9 @@ typedef struct {
unsigned long gen_int;
double gen_dbl;
};
+
+ mrb_int seed;
+ mrb_bool has_seed;
} mt_state;
void mrb_random_init_genrand(mt_state *, unsigned long);
diff --git a/mrbgems/mruby-random/src/random.c b/mrbgems/mruby-random/src/random.c
index 0d71ce2df..ac8f24a18 100644
--- a/mrbgems/mruby-random/src/random.c
+++ b/mrbgems/mruby-random/src/random.c
@@ -13,13 +13,8 @@
#include <time.h>
-#define GLOBAL_RAND_SEED_KEY "$mrb_g_rand_seed"
-#define GLOBAL_RAND_SEED_KEY_CSTR_LEN 16
-
-#define INSTANCE_RAND_SEED_KEY "$mrb_i_rand_seed"
-#define INSTANCE_RAND_SEED_KEY_CSTR_LEN 16
-
-#define MT_STATE_KEY "$mrb_i_mt_state"
+static char const GLOBAL_RAND_SEED_KEY[] = "$mrb_g_rand_seed";
+static char const MT_STATE_KEY[] = "$mrb_i_mt_state";
static const struct mrb_data_type mt_state_type = {
MT_STATE_KEY, mrb_free,
@@ -143,7 +138,7 @@ mrb_random_g_rand_seed(mrb_state *mrb)
{
mrb_value seed;
- seed = mrb_gv_get(mrb, mrb_intern(mrb, GLOBAL_RAND_SEED_KEY, GLOBAL_RAND_SEED_KEY_CSTR_LEN));
+ seed = mrb_gv_get(mrb, mrb_intern_lit(mrb, GLOBAL_RAND_SEED_KEY));
if (mrb_nil_p(seed)) {
mrb_random_mt_g_srand(mrb, mrb_nil_value());
}
@@ -167,8 +162,8 @@ mrb_random_g_srand(mrb_state *mrb, mrb_value self)
seed = get_opt(mrb);
seed = mrb_random_mt_g_srand(mrb, seed);
- old_seed = mrb_gv_get(mrb, mrb_intern(mrb, GLOBAL_RAND_SEED_KEY, GLOBAL_RAND_SEED_KEY_CSTR_LEN));
- mrb_gv_set(mrb, mrb_intern(mrb, GLOBAL_RAND_SEED_KEY, GLOBAL_RAND_SEED_KEY_CSTR_LEN), seed);
+ old_seed = mrb_gv_get(mrb, mrb_intern_lit(mrb, GLOBAL_RAND_SEED_KEY));
+ mrb_gv_set(mrb, mrb_intern_lit(mrb, GLOBAL_RAND_SEED_KEY), seed);
return old_seed;
}
@@ -192,7 +187,14 @@ mrb_random_init(mrb_state *mrb, mrb_value self)
seed = get_opt(mrb);
seed = mrb_random_mt_srand(mrb, t, seed);
- mrb_iv_set(mrb, self, mrb_intern(mrb, INSTANCE_RAND_SEED_KEY, INSTANCE_RAND_SEED_KEY_CSTR_LEN), seed);
+ if (mrb_nil_p(seed)) {
+ t->has_seed = FALSE;
+ }
+ else {
+ mrb_assert(mrb_fixnum_p(seed));
+ t->has_seed = TRUE;
+ t->seed = mrb_fixnum(seed);
+ }
DATA_PTR(self) = t;
@@ -200,13 +202,9 @@ mrb_random_init(mrb_state *mrb, mrb_value self)
}
static void
-mrb_random_rand_seed(mrb_state *mrb, mrb_value self)
+mrb_random_rand_seed(mrb_state *mrb, mt_state *t)
{
- mrb_value seed;
- mt_state *t = DATA_PTR(self);
-
- seed = mrb_iv_get(mrb, self, mrb_intern(mrb, INSTANCE_RAND_SEED_KEY, INSTANCE_RAND_SEED_KEY_CSTR_LEN));
- if (mrb_nil_p(seed)) {
+ if (!t->has_seed) {
mrb_random_mt_srand(mrb, t, mrb_nil_value());
}
}
@@ -218,7 +216,7 @@ mrb_random_rand(mrb_state *mrb, mrb_value self)
mt_state *t = DATA_PTR(self);
max = get_opt(mrb);
- mrb_random_rand_seed(mrb, self);
+ mrb_random_rand_seed(mrb, t);
return mrb_random_mt_rand(mrb, t, max);
}
@@ -231,8 +229,15 @@ mrb_random_srand(mrb_state *mrb, mrb_value self)
seed = get_opt(mrb);
seed = mrb_random_mt_srand(mrb, t, seed);
- old_seed = mrb_iv_get(mrb, self, mrb_intern(mrb, INSTANCE_RAND_SEED_KEY, INSTANCE_RAND_SEED_KEY_CSTR_LEN));
- mrb_iv_set(mrb, self, mrb_intern(mrb, INSTANCE_RAND_SEED_KEY, INSTANCE_RAND_SEED_KEY_CSTR_LEN), seed);
+ old_seed = t->has_seed? mrb_fixnum_value(t->seed) : mrb_nil_value();
+ if (mrb_nil_p(seed)) {
+ t->has_seed = FALSE;
+ }
+ else {
+ mrb_assert(mrb_fixnum_p(seed));
+ t->has_seed = TRUE;
+ t->seed = mrb_fixnum(seed);
+ }
return old_seed;
}
@@ -248,17 +253,16 @@ static mrb_value
mrb_ary_shuffle_bang(mrb_state *mrb, mrb_value ary)
{
mrb_int i;
- mrb_value random = mrb_nil_value();
+ mt_state *random = NULL;
if (RARRAY_LEN(ary) > 1) {
- mrb_get_args(mrb, "|o", &random);
+ mrb_get_args(mrb, "|d", &random, &mt_state_type);
- if (mrb_nil_p(random)) {
- mrb_random_g_rand_seed(mrb);
+ if (random) {
+ mrb_random_rand_seed(mrb, random);
}
else {
- mrb_data_check_type(mrb, random, &mt_state_type);
- mrb_random_rand_seed(mrb, random);
+ mrb_random_g_rand_seed(mrb);
}
mrb_ary_modify(mrb, mrb_ary_ptr(ary));
@@ -267,11 +271,11 @@ mrb_ary_shuffle_bang(mrb_state *mrb, mrb_value ary)
mrb_int j;
mrb_value tmp;
- if (mrb_nil_p(random)) {
- j = mrb_fixnum(mrb_random_mt_g_rand(mrb, mrb_fixnum_value(RARRAY_LEN(ary))));
+ if (random) {
+ j = mrb_fixnum(mrb_random_mt_rand(mrb, random, mrb_fixnum_value(RARRAY_LEN(ary))));
}
else {
- j = mrb_fixnum(mrb_random_mt_rand(mrb, DATA_PTR(random), mrb_fixnum_value(RARRAY_LEN(ary))));
+ j = mrb_fixnum(mrb_random_mt_g_rand(mrb, mrb_fixnum_value(RARRAY_LEN(ary))));
}
tmp = RARRAY_PTR(ary)[i];
diff --git a/src/class.c b/src/class.c
index 11a21f7a7..2c1145ed3 100644
--- a/src/class.c
+++ b/src/class.c
@@ -14,6 +14,7 @@
#include "mruby/string.h"
#include "mruby/variable.h"
#include "mruby/error.h"
+#include "mruby/data.h"
KHASH_DEFINE(mt, mrb_sym, struct RProc*, 1, kh_int_hash_func, kh_int_hash_equal)
@@ -406,6 +407,7 @@ to_hash(mrb_state *mrb, mrb_value val)
i: Integer [mrb_int]
b: Boolean [mrb_bool]
n: Symbol [mrb_sym]
+ d: Data [void*,mrb_data_type const] 2nd argument will be used to check data type so it won't be modified
&: Block [mrb_value]
*: rest argument [mrb_value*,int] Receive the rest of the arguments as an array.
|: optional Next argument of '|' and later are optional.
@@ -658,6 +660,19 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
}
}
break;
+ case 'd':
+ {
+ void** datap;
+ struct mrb_data_type const* type;
+
+ datap = va_arg(ap, void**);
+ type = va_arg(ap, struct mrb_data_type const*);
+ if (i < argc) {
+ *datap = mrb_data_get_ptr(mrb, *sp++, type);
+ ++i;
+ }
+ }
+ break;
case '&':
{
diff --git a/src/numeric.c b/src/numeric.c
index d09213235..e081cf80a 100644
--- a/src/numeric.c
+++ b/src/numeric.c
@@ -169,7 +169,7 @@ mrb_flo_to_str(mrb_state *mrb, mrb_value flo)
e = TRUE;
n = n / pow(10.0, exp);
if (isinf(n)) {
- if (s[0] == '-') {
+ if (s < c) { /* s[0] == '-' */
return mrb_str_new_lit(mrb, "-0.0");
}
else {
diff --git a/tasks/toolchains/gcc.rake b/tasks/toolchains/gcc.rake
index b1827bcc5..a25f840c5 100644
--- a/tasks/toolchains/gcc.rake
+++ b/tasks/toolchains/gcc.rake
@@ -1,7 +1,7 @@
MRuby::Toolchain.new(:gcc) do |conf|
[conf.cc, conf.objc, conf.asm].each do |cc|
cc.command = ENV['CC'] || 'gcc'
- cc.flags = [ENV['CFLAGS'] || %w(-g -std=gnu99 -O3 -Wall -Werror-implicit-function-declaration -Wdeclaration-after-statement -Werror=declaration-after-statement)]
+ cc.flags = [ENV['CFLAGS'] || %w(-g -std=gnu99 -O3 -Wall -Werror-implicit-function-declaration -Wdeclaration-after-statement)]
cc.include_paths = ["#{MRUBY_ROOT}/include"]
cc.defines = %w(DISABLE_GEMS)
cc.option_include_path = '-I%s'
diff --git a/travis_config.rb b/travis_config.rb
index 6f406ae37..ffa0a75d4 100644
--- a/travis_config.rb
+++ b/travis_config.rb
@@ -4,6 +4,7 @@ MRuby::Build.new('debug') do |conf|
# include all core GEMs
conf.gembox 'full-core'
+ conf.cc.flags += %w(-Werror=declaration-after-statement)
conf.cc.defines += %w(MRB_GC_FIXED_ARENA)
end
@@ -12,6 +13,7 @@ MRuby::Build.new do |conf|
# include all core GEMs
conf.gembox 'full-core'
+ conf.cc.flags += %w(-Werror=declaration-after-statement)
conf.cc.defines = %w(MRB_DEBUG MRB_GC_FIXED_ARENA)
conf.enable_bintest = true
end