diff options
| -rw-r--r-- | INSTALL | 10 | ||||
| -rw-r--r-- | doc/mrbgems/README.md | 5 | ||||
| -rw-r--r-- | examples/targets/IntelGalileo.rb | 90 | ||||
| -rw-r--r-- | include/mruby/error.h | 17 | ||||
| -rw-r--r-- | include/mruby/version.h | 23 | ||||
| -rw-r--r-- | mrbgems/mruby-bin-mirb/tools/mirb/mirb.c | 2 | ||||
| -rw-r--r-- | mrbgems/mruby-hash-ext/src/hash-ext.c | 4 | ||||
| -rw-r--r-- | mrbgems/mruby-hash-ext/test/hash.rb | 5 | ||||
| -rw-r--r-- | mrbgems/mruby-random/src/mt19937ar.c | 1 | ||||
| -rw-r--r-- | mrbgems/mruby-random/src/mt19937ar.h | 3 | ||||
| -rw-r--r-- | mrbgems/mruby-random/src/random.c | 62 | ||||
| -rw-r--r-- | src/class.c | 17 | ||||
| -rw-r--r-- | src/error.c | 2 | ||||
| -rw-r--r-- | src/error.h | 20 | ||||
| -rw-r--r-- | src/kernel.c | 3 | ||||
| -rw-r--r-- | src/numeric.c | 30 | ||||
| -rw-r--r-- | src/symbol.c | 2 | ||||
| -rw-r--r-- | src/variable.c | 8 | ||||
| -rw-r--r-- | src/vm.c | 2 | ||||
| -rw-r--r-- | tasks/mruby_build.rake | 10 | ||||
| -rw-r--r-- | tasks/mruby_build_commands.rake | 2 | ||||
| -rw-r--r-- | tasks/toolchains/gcc.rake | 2 | ||||
| -rw-r--r-- | test/t/string.rb | 3 | ||||
| -rw-r--r-- | travis_config.rb | 2 |
24 files changed, 247 insertions, 78 deletions
@@ -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/doc/mrbgems/README.md b/doc/mrbgems/README.md index 65b794dc0..481ce08de 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -203,6 +203,7 @@ mruby can be extended with pure Ruby. It is possible to override existing classes or add new ones in this way. Put all Ruby files into the *mrblib* folder. + ### Pre-Conditions none @@ -229,6 +230,10 @@ mruby can be extended with C and Ruby at the same time. It is possible to override existing classes or add new ones in this way. Put all Ruby files into the *mrblib* folder and all C files into the *src* folder. +mruby codes under *mrblib* directory would be executed after gem init C +function is called. Make sure *mruby script* depends on *C code* and +*C code* doesn't depend on *mruby script*. + ### Pre-Conditions See C and Ruby example. diff --git a/examples/targets/IntelGalileo.rb b/examples/targets/IntelGalileo.rb new file mode 100644 index 000000000..0ee073344 --- /dev/null +++ b/examples/targets/IntelGalileo.rb @@ -0,0 +1,90 @@ +# Cross Compiling configuration for Intel Galileo on Arduino environment +# http://arduino.cc/en/ArduinoCertified/IntelGalileo +# +# Requires Arduino IDE for Intel Galileo + +MRuby::CrossBuild.new("Galileo") do |conf| + toolchain :gcc + + # Mac OS X + # Assume you renamed Arduino.app to Arduino_Galileo.app + GALILEO_ARDUINO_PATH = '/Applications/Arduino_Galileo.app/Contents/Resources/Java' + # GNU Linux + #ARDUINO_GALILEO_PATH = '/opt/arduino' + + GALILEO_BIN_PATH = "#{GALILEO_ARDUINO_PATH}/hardware/tools/x86/i386-pokysdk-darwin/usr/bin/i586-poky-linux-uclibc" + GALILEO_SYSROOT = "#{GALILEO_ARDUINO_PATH}/hardware/tools/x86/i586-poky-linux-uclibc" + GALILEO_X86_PATH = "#{GALILEO_ARDUINO_PATH}/hardware/arduino/x86" + + + conf.cc do |cc| + cc.command = "#{GALILEO_BIN_PATH}/i586-poky-linux-uclibc-gcc" + cc.include_paths << ["#{GALILEO_X86_PATH}/cores/arduino", "#{GALILEO_X86_PATH}/variants/galileo_fab_d"] + cc.flags = %w(-m32 -march=i586 -c -g -Os -w + -ffunction-sections -fdata-sections -MMD -DARDUINO=153) + cc.flags << "--sysroot=#{GALILEO_SYSROOT}" + cc.compile_options = "%{flags} -o %{outfile} -c %{infile}" + end + + conf.cxx do |cxx| + cxx.command = "#{GALILEO_BIN_PATH}/i586-poky-linux-uclibc-g++" + cxx.include_paths = conf.cc.include_paths.dup + cxx.include_paths << "#{GALILEO_ARDUINO_PATH}/hardware/tools/x86/i586-poky-linux-uclibc/usr/include/c++" + cxx.include_paths << "#{GALILEO_ARDUINO_PATH}/hardware/tools/x86/i586-poky-linux-uclibc/usr/include/c++/i586-poky-linux-uclibc" + cxx.flags = conf.cc.flags.dup + cxx.defines = conf.cc.defines.dup + cxx.compile_options = conf.cc.compile_options.dup + end + + conf.archiver do |archiver| + archiver.command = "#{GALILEO_BIN_PATH}/i586-poky-linux-uclibc-ar" + archiver.archive_options = 'rcs %{outfile} %{objs}' + end + + conf.linker do |linker| + linker.command = "#{GALILEO_BIN_PATH}/i586-poky-linux-uclibc-g++" + linker.flags = %w(-m32 -march=i586) + linker.flags << "--sysroot=#{GALILEO_SYSROOT}" + linker.flags << %w(-Os -Wl,--gc-sections) + linker.libraries = %w(m pthread) + end + + #no executables + conf.bins = [] + + #do not build executable test + conf.build_mrbtest_lib_only + + #official mrbgems + conf.gem :core => "mruby-sprintf" + conf.gem :core => "mruby-print" + conf.gem :core => "mruby-math" + conf.gem :core => "mruby-time" + conf.gem :core => "mruby-struct" + conf.gem :core => "mruby-enum-ext" + conf.gem :core => "mruby-string-ext" + conf.gem :core => "mruby-numeric-ext" + conf.gem :core => "mruby-array-ext" + conf.gem :core => "mruby-hash-ext" + conf.gem :core => "mruby-range-ext" + conf.gem :core => "mruby-proc-ext" + conf.gem :core => "mruby-symbol-ext" + conf.gem :core => "mruby-random" + conf.gem :core => "mruby-object-ext" + conf.gem :core => "mruby-objectspace" + conf.gem :core => "mruby-fiber" + conf.gem :core => "mruby-toplevel-ext" + + #lightweigh regular expression + conf.gem :github => "masamitsu-murase/mruby-hs-regexp", :branch => "master" + + #Arduino API + #conf.gem :github =>"kyab/mruby-arduino", :branch => "master" do |g| + # g.cxx.include_paths << "#{GALILEO_X86_PATH}/libraries/Wire" + # g.cxx.include_paths << "#{GALILEO_X86_PATH}/libraries/Servo" + + #enable unsupported Servo class + # g.cxx.defines << "MRUBY_ARDUINO_GALILEO_ENABLE_SERVO" + #end + +end
\ No newline at end of file diff --git a/include/mruby/error.h b/include/mruby/error.h new file mode 100644 index 000000000..b04dc1082 --- /dev/null +++ b/include/mruby/error.h @@ -0,0 +1,17 @@ +/* +** error.h - Exception class +** +** See Copyright Notice in mruby.h +*/ + +#ifndef MRUBY_ERROR_H +#define MRUBY_ERROR_H + +void mrb_sys_fail(mrb_state *mrb, const char *mesg); +mrb_value mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str); +mrb_value mrb_make_exception(mrb_state *mrb, int argc, mrb_value *argv); +mrb_value mrb_format(mrb_state *mrb, const char *format, ...); +void mrb_exc_print(mrb_state *mrb, struct RObject *exc); +void mrb_longjmp(mrb_state *mrb); + +#endif /* MRUBY_ERROR_H */ diff --git a/include/mruby/version.h b/include/mruby/version.h index 3547f6a3b..d451dfb31 100644 --- a/include/mruby/version.h +++ b/include/mruby/version.h @@ -18,16 +18,17 @@ #define MRUBY_AUTHOR "mruby developers" -#define STRINGIZE0(expr) #expr -#define STRINGIZE(expr) STRINGIZE0(expr) - -#define MRUBY_DESCRIPTION \ - "mruby "MRUBY_VERSION \ - " ("MRUBY_RELEASE_DATE") " -#define MRUBY_COPYRIGHT \ - "mruby - Copyright (c) " \ - STRINGIZE(MRUBY_BIRTH_YEAR)"-" \ - STRINGIZE(MRUBY_RELEASE_YEAR)" " \ - MRUBY_AUTHOR +#define MRB_STRINGIZE0(expr) #expr +#define MRB_STRINGIZE(expr) MRB_STRINGIZE0(expr) + +#define MRUBY_DESCRIPTION \ + "mruby " MRUBY_VERSION \ + " (" MRUBY_RELEASE_DATE ") " \ + +#define MRUBY_COPYRIGHT \ + "mruby - Copyright (c) " \ + MRB_STRINGIZE(MRUBY_BIRTH_YEAR)"-" \ + MRB_STRINGIZE(MRUBY_RELEASE_YEAR)" " \ + MRUBY_AUTHOR \ #endif /* MRUBY_VERSION_H */ diff --git a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c index a9d6850a5..b204c8e2d 100644 --- a/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +++ b/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c @@ -218,6 +218,7 @@ print_hint(void) printf("mirb - Embeddable Interactive Ruby Shell\n\n"); } +#ifndef ENABLE_READLINE /* Print the command line prompt of the REPL */ static void print_cmdline(int code_block_open) @@ -229,6 +230,7 @@ print_cmdline(int code_block_open) printf("> "); } } +#endif void mrb_codedump_all(mrb_state*, struct RProc*); diff --git a/mrbgems/mruby-hash-ext/src/hash-ext.c b/mrbgems/mruby-hash-ext/src/hash-ext.c index 298559686..937a7fddd 100644 --- a/mrbgems/mruby-hash-ext/src/hash-ext.c +++ b/mrbgems/mruby-hash-ext/src/hash-ext.c @@ -23,12 +23,14 @@ static mrb_value hash_values_at(mrb_state *mrb, mrb_value hash) { mrb_value *argv, result; - int argc, i; + int argc, i, ai; mrb_get_args(mrb, "*", &argv, &argc); result = mrb_ary_new_capa(mrb, argc); + ai = mrb_gc_arena_save(mrb); for (i = 0; i < argc; i++) { mrb_ary_push(mrb, result, mrb_hash_get(mrb, hash, argv[i])); + mrb_gc_arena_restore(mrb, ai); } return result; } diff --git a/mrbgems/mruby-hash-ext/test/hash.rb b/mrbgems/mruby-hash-ext/test/hash.rb index 40f6ac8bf..cdf00173a 100644 --- a/mrbgems/mruby-hash-ext/test/hash.rb +++ b/mrbgems/mruby-hash-ext/test/hash.rb @@ -21,4 +21,9 @@ end assert('Hash#values_at') do h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" } assert_equal ["bovine", "feline"], h.values_at("cow", "cat") + + keys = [] + (0...1000).each { |v| keys.push "#{v}" } + h = Hash.new { |hash,k| hash[k] = k } + assert_equal keys, h.values_at(*keys) end 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 58eaaab0e..2c1145ed3 100644 --- a/src/class.c +++ b/src/class.c @@ -13,7 +13,8 @@ #include "mruby/proc.h" #include "mruby/string.h" #include "mruby/variable.h" -#include "error.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/error.c b/src/error.c index 1ee891619..8d0ec67e0 100644 --- a/src/error.c +++ b/src/error.c @@ -14,7 +14,7 @@ #include "mruby/string.h" #include "mruby/variable.h" #include "mruby/debug.h" -#include "error.h" +#include "mruby/error.h" mrb_value mrb_exc_new(mrb_state *mrb, struct RClass *c, const char *ptr, long len) diff --git a/src/error.h b/src/error.h index b04dc1082..0e0dacf63 100644 --- a/src/error.h +++ b/src/error.h @@ -1,17 +1,3 @@ -/* -** error.h - Exception class -** -** See Copyright Notice in mruby.h -*/ - -#ifndef MRUBY_ERROR_H -#define MRUBY_ERROR_H - -void mrb_sys_fail(mrb_state *mrb, const char *mesg); -mrb_value mrb_exc_new_str(mrb_state *mrb, struct RClass* c, mrb_value str); -mrb_value mrb_make_exception(mrb_state *mrb, int argc, mrb_value *argv); -mrb_value mrb_format(mrb_state *mrb, const char *format, ...); -void mrb_exc_print(mrb_state *mrb, struct RObject *exc); -void mrb_longjmp(mrb_state *mrb); - -#endif /* MRUBY_ERROR_H */ +/* this header file is to be removed soon. + added for compatibility purpose (1.0.0) */ +#include "mruby/error.h" diff --git a/src/kernel.c b/src/kernel.c index f13a13ea2..25863c897 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -10,7 +10,7 @@ #include "mruby/proc.h" #include "mruby/string.h" #include "mruby/variable.h" -#include "error.h" +#include "mruby/error.h" typedef enum { NOEX_PUBLIC = 0x00, @@ -309,6 +309,7 @@ init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj) case MRB_TT_CLASS: case MRB_TT_MODULE: copy_class(mrb, dest, obj); + /* fall through */ case MRB_TT_OBJECT: case MRB_TT_SCLASS: case MRB_TT_HASH: diff --git a/src/numeric.c b/src/numeric.c index 2140a8411..5f23b2461 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -19,9 +19,11 @@ #define ceil(f) ceilf(f) #define fmod(x,y) fmodf(x,y) #define FLO_MAX_DIGITS 7 +#define FLO_MAX_SIGN_LENGTH 3 #define FLO_EPSILON FLT_EPSILON #else #define FLO_MAX_DIGITS 14 +#define FLO_MAX_SIGN_LENGTH 10 #define FLO_EPSILON DBL_EPSILON #endif @@ -130,6 +132,7 @@ mrb_flo_to_str(mrb_state *mrb, mrb_float flo) mrb_bool e = FALSE; char s[48]; char *c = &s[0]; + int length = 0; if (signbit(n)) { n = -n; @@ -147,11 +150,36 @@ mrb_flo_to_str(mrb_state *mrb, mrb_float flo) else { exp = 0; } + + /* preserve significands */ + if (exp < 0) { + int i, beg = -1, end = 0; + double f = n; + double fd = 0; + for (i = 0; i < FLO_MAX_DIGITS; ++i) { + f = (f - fd) * 10.0; + fd = floor(f + FLO_EPSILON); + if (fd != 0) { + if (beg < 0) beg = i; + end = i + 1; + } + } + if (beg >= 0) length = end - beg; + if (length > FLO_MAX_SIGN_LENGTH) length = FLO_MAX_SIGN_LENGTH; + } - if ((exp < 0 ? -exp : exp) >= FLO_MAX_DIGITS) { + if (abs(exp) + length >= FLO_MAX_DIGITS) { /* exponent representation */ e = TRUE; n = n / pow(10.0, exp); + if (isinf(n)) { + if (s < c) { /* s[0] == '-' */ + return mrb_str_new_lit(mrb, "-0.0"); + } + else { + return mrb_str_new_lit(mrb, "0.0"); + } + } } else { /* un-exponent (normal) representation */ diff --git a/src/symbol.c b/src/symbol.c index b311551c0..7971f71ca 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -97,7 +97,7 @@ mrb_value mrb_check_intern(mrb_state *mrb, const char *name, size_t len) { khash_t(n2s) *h = mrb->name2sym; - symbol_name sname; + symbol_name sname = { 0 }; khiter_t k; if (len > UINT16_MAX) { diff --git a/src/variable.c b/src/variable.c index 3dc562a5e..957383ad2 100644 --- a/src/variable.c +++ b/src/variable.c @@ -369,10 +369,12 @@ iv_foreach(mrb_state *mrb, iv_tbl *t, iv_foreach_func *func, void *p) static size_t iv_size(mrb_state *mrb, iv_tbl *t) { - khash_t(iv) *h = &t->h; + khash_t(iv) *h; - if (!h) return 0; - return kh_size(h); + if (t && (h = &t->h)) { + return kh_size(h); + } + return 0; } static iv_tbl* @@ -17,7 +17,7 @@ #include "mruby/range.h" #include "mruby/string.h" #include "mruby/variable.h" -#include "error.h" +#include "mruby/error.h" #include "opcode.h" #include "value_array.h" diff --git a/tasks/mruby_build.rake b/tasks/mruby_build.rake index c92400cf9..b7efa96b9 100644 --- a/tasks/mruby_build.rake +++ b/tasks/mruby_build.rake @@ -52,7 +52,7 @@ module MRuby Exts = Struct.new(:object, :executable, :library) - def initialize(name='host', &block) + def initialize(name='host', build_dir=nil, &block) @name = name.to_s unless MRuby.targets[@name] @@ -62,9 +62,11 @@ module MRuby @exts = Exts.new('.o', '', '.a') end + build_dir = build_dir || ENV['MRUBY_BUILD_DIR'] || "#{MRUBY_ROOT}/build" + @file_separator = '/' - @build_dir = "#{MRUBY_ROOT}/build/#{@name}" - @gem_clone_dir = "#{MRUBY_ROOT}/build/mrbgems" + @build_dir = "#{build_dir}/#{@name}" + @gem_clone_dir = "#{build_dir}/mrbgems" @cc = Command::Compiler.new(self, %w(.c)) @cxx = Command::Compiler.new(self, %w(.cc .cxx .cpp)) @objc = Command::Compiler.new(self, %w(.m)) @@ -204,7 +206,7 @@ module MRuby class CrossBuild < Build attr_block %w(test_runner) - def initialize(name, &block) + def initialize(name, build_dir=nil, &block) @test_runner = Command::CrossTestRunner.new(self) super end diff --git a/tasks/mruby_build_commands.rake b/tasks/mruby_build_commands.rake index d7b87514e..b0965ea09 100644 --- a/tasks/mruby_build_commands.rake +++ b/tasks/mruby_build_commands.rake @@ -110,7 +110,7 @@ module MRuby File.read(file).gsub("\\\n ", "").scan(/^\S+:\s+(.+)$/).flatten.map {|s| s.split(' ') }.flatten else [] - end + end + [ MRUBY_CONFIG ] end end diff --git a/tasks/toolchains/gcc.rake b/tasks/toolchains/gcc.rake index dec502732..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)] + 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/test/t/string.rb b/test/t/string.rb index c42fa006f..3219f98c3 100644 --- a/test/t/string.rb +++ b/test/t/string.rb @@ -125,6 +125,7 @@ assert('String#capitalize!', '15.2.10.5.8') do a.capitalize! assert_equal 'Abc', a + assert_equal nil, 'Abc'.capitalize! end assert('String#chomp', '15.2.10.5.9') do @@ -204,6 +205,7 @@ assert('String#downcase!', '15.2.10.5.14') do a.downcase! assert_equal 'abc', a + assert_equal nil, 'abc'.downcase! end assert('String#each_line', '15.2.10.5.15') do @@ -442,6 +444,7 @@ assert('String#upcase!', '15.2.10.5.43') do a.upcase! assert_equal 'ABC', a + assert_equal nil, 'ABC'.upcase! end # Not ISO specified 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 |
