summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--examples/targets/ArduinoDue.rb4
-rw-r--r--include/mruby.h8
-rw-r--r--include/mruby/value.h38
-rw-r--r--mrbgems/mruby-math/src/math.c22
-rw-r--r--mrbgems/mruby-sprintf/src/sprintf.c4
-rw-r--r--src/class.c2
-rw-r--r--src/crc.c2
-rw-r--r--src/gc.c20
-rw-r--r--src/hash.c24
-rw-r--r--src/load.c16
-rw-r--r--src/parse.y12
11 files changed, 79 insertions, 73 deletions
diff --git a/examples/targets/ArduinoDue.rb b/examples/targets/ArduinoDue.rb
index 762236f3b..a4af4a926 100644
--- a/examples/targets/ArduinoDue.rb
+++ b/examples/targets/ArduinoDue.rb
@@ -15,9 +15,9 @@ MRuby::CrossBuild.new("Arduino Due") do |conf|
conf.cc do |cc|
cc.command = "#{BIN_PATH}/arm-none-eabi-gcc"
- cc.include_paths << ["#{SAM_PATH}/system/libsam -I#{SAM_PATH}/system/CMSIS/CMSIS/Include/",
+ cc.include_paths << ["#{SAM_PATH}/system/libsam", "#{SAM_PATH}/system/CMSIS/CMSIS/Include/",
"#{SAM_PATH}/system/CMSIS/Device/ATMEL/",
- "#{SAM_PATH}/cores/arduino -I#{TARGET_PATH}"]
+ "#{SAM_PATH}/cores/arduino", "#{SAM_PATH}/libraries","#{TARGET_PATH}"]
cc.flags = %w(-g -Os -w -ffunction-sections -fdata-sections -nostdlib --param max-inline-insns-single=500
-Dprintf=iprintf -mcpu=cortex-m3 -DF_CPU=84000000L -DARDUINO=152 -D__SAM3X8E__ -mthumb -DUSB_PID=0x003e -DUSB_VID=0x2341 -DUSBCON)
cc.compile_options = "%{flags} -o %{outfile} -c %{infile}"
diff --git a/include/mruby.h b/include/mruby.h
index 33a15de0e..568ed4876 100644
--- a/include/mruby.h
+++ b/include/mruby.h
@@ -239,9 +239,11 @@ mrb_sym mrb_intern(mrb_state *mrb,const char *cstr)
return mrb_intern_cstr(mrb, cstr);
}
-void *mrb_malloc(mrb_state*, size_t);
-void *mrb_calloc(mrb_state*, size_t, size_t);
-void *mrb_realloc(mrb_state*, void*, size_t);
+void *mrb_malloc(mrb_state*, size_t); /* raise RuntimeError if no mem */
+void *mrb_calloc(mrb_state*, size_t, size_t); /* ditto */
+void *mrb_realloc(mrb_state*, void*, size_t); /* ditto */
+void *mrb_realloc_simple(mrb_state*, void*, size_t); /* return NULL if no memory available */
+void *mrb_malloc_simple(mrb_state*, size_t); /* return NULL if no memory available */
struct RBasic *mrb_obj_alloc(mrb_state*, enum mrb_vtype, struct RClass*);
void mrb_free(mrb_state*, void*);
diff --git a/include/mruby/value.h b/include/mruby/value.h
index 06241ec76..e78035b5f 100644
--- a/include/mruby/value.h
+++ b/include/mruby/value.h
@@ -51,23 +51,29 @@
typedef short mrb_sym;
#ifdef _MSC_VER
-# define _ALLOW_KEYWORD_MACROS
-# include <float.h>
-# define inline __inline
+# ifndef __cplusplus
+# define inline __inline
+# endif
# define snprintf _snprintf
-# define isnan _isnan
-# define isinf(n) (!_finite(n) && !_isnan(n))
-# define strtoll _strtoi64
-# define PRId32 "I32d"
-# define PRIi32 "I32i"
-# define PRIo32 "I32o"
-# define PRIx32 "I32x"
-# define PRIX32 "I32X"
-# define PRId64 "I64d"
-# define PRIi64 "I64i"
-# define PRIo64 "I64o"
-# define PRIx64 "I64x"
-# define PRIX64 "I64X"
+# if _MSC_VER < 1800
+# include <float.h>
+# define isnan _isnan
+# define isinf(n) (!_finite(n) && !_isnan(n))
+# define strtoll _strtoi64
+# define strtof (float)strtod
+# define PRId32 "I32d"
+# define PRIi32 "I32i"
+# define PRIo32 "I32o"
+# define PRIx32 "I32x"
+# define PRIX32 "I32X"
+# define PRId64 "I64d"
+# define PRIi64 "I64i"
+# define PRIo64 "I64o"
+# define PRIx64 "I64x"
+# define PRIX64 "I64X"
+# else
+# include <inttypes.h>
+# endif
#else
# include <inttypes.h>
#endif
diff --git a/mrbgems/mruby-math/src/math.c b/mrbgems/mruby-math/src/math.c
index bf3c007b4..bdc7767f7 100644
--- a/mrbgems/mruby-math/src/math.c
+++ b/mrbgems/mruby-math/src/math.c
@@ -12,8 +12,8 @@
#define domain_error(msg) \
mrb_raise(mrb, E_RANGE_ERROR, "Numerical argument is out of domain - " #msg)
-/* math functions not provided under Microsoft Visual C++ */
-#ifdef _MSC_VER
+/* math functions not provided by Microsoft Visual C++ 2012 or older */
+#if defined _MSC_VER && _MSC_VER < 1800
#define MATH_TOLERANCE 1E-12
@@ -87,6 +87,12 @@ erfc(double x)
return one_sqrtpi*exp(-x*x)*q2;
}
+double
+log2(double x)
+{
+ return log10(x)/log10(2.0);
+}
+
#endif
/*
@@ -358,18 +364,6 @@ math_atanh(mrb_state *mrb, mrb_value obj)
# define log10(x) ((x) < 0.0 ? nan("") : log10(x))
#endif
-#ifndef log2
-#ifndef HAVE_LOG2
-double
-log2(double x)
-{
- return log10(x)/log10(2.0);
-}
-#else
-extern double log2(double);
-#endif
-#endif
-
/*
* call-seq:
* Math.exp(x) -> float
diff --git a/mrbgems/mruby-sprintf/src/sprintf.c b/mrbgems/mruby-sprintf/src/sprintf.c
index 55698d09f..6479b19bc 100644
--- a/mrbgems/mruby-sprintf/src/sprintf.c
+++ b/mrbgems/mruby-sprintf/src/sprintf.c
@@ -15,10 +15,6 @@
#include <math.h>
#include <ctype.h>
-#ifdef _MSC_VER
-#include <float.h>
-#endif
-
#ifdef HAVE_IEEEFP_H
#include <ieeefp.h>
#endif
diff --git a/src/class.c b/src/class.c
index f94f9a933..6eb70dce6 100644
--- a/src/class.c
+++ b/src/class.c
@@ -487,7 +487,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
if (i < argc) {
ss = to_str(mrb, *sp++);
s = mrb_str_ptr(ss);
- if (strlen(s->ptr) != s->len) {
+ if (strlen(s->ptr) < s->len) {
mrb_raise(mrb, E_ARGUMENT_ERROR, "String contains NUL");
}
*ps = s->ptr;
diff --git a/src/crc.c b/src/crc.c
index 463c7abe6..3bda7bc26 100644
--- a/src/crc.c
+++ b/src/crc.c
@@ -6,7 +6,7 @@
#include <limits.h>
#include <stdint.h>
-#include <sys/types.h>
+#include <stddef.h>
// Calculate CRC (CRC-16-CCITT)
//
diff --git a/src/gc.c b/src/gc.c
index 3e33c052c..6fc400e32 100644
--- a/src/gc.c
+++ b/src/gc.c
@@ -148,18 +148,28 @@ gettimeofday_time(void)
#define GC_STEP_SIZE 1024
+
void*
-mrb_realloc(mrb_state *mrb, void *p, size_t len)
+mrb_realloc_simple(mrb_state *mrb, void *p, size_t len)
{
void *p2;
p2 = (mrb->allocf)(mrb, p, len, mrb->ud);
-
if (!p2 && len > 0 && mrb->heaps) {
mrb_garbage_collect(mrb);
p2 = (mrb->allocf)(mrb, p, len, mrb->ud);
}
+ return p2;
+}
+
+
+void*
+mrb_realloc(mrb_state *mrb, void *p, size_t len)
+{
+ void *p2;
+
+ p2 = mrb_realloc_simple(mrb, p, len);
if (!p2 && len) {
if (mrb->out_of_memory) {
/* mrb_panic(mrb); */
@@ -183,6 +193,12 @@ mrb_malloc(mrb_state *mrb, size_t len)
}
void*
+mrb_malloc_simple(mrb_state *mrb, size_t len)
+{
+ return mrb_realloc_simple(mrb, 0, len);
+}
+
+void*
mrb_calloc(mrb_state *mrb, size_t nelem, size_t len)
{
void *p;
diff --git a/src/hash.c b/src/hash.c
index 5d78a6ea7..3684b3b40 100644
--- a/src/hash.c
+++ b/src/hash.c
@@ -145,7 +145,9 @@ mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val) /* mr
k = kh_get(ht, h, key);
if (k == kh_end(h)) {
/* expand */
+ int ai = mrb_gc_arena_save(mrb);
k = kh_put(ht, h, KEY(key));
+ mrb_gc_arena_restore(mrb, ai);
}
kh_value(h, k) = val;
@@ -169,7 +171,9 @@ mrb_hash_dup(mrb_state *mrb, mrb_value hash)
for (k = kh_begin(h); k != kh_end(h); k++) {
if (kh_exist(h,k)) {
+ int ai = mrb_gc_arena_save(mrb);
ret_k = kh_put(ht, ret_h, KEY(kh_key(h,k)));
+ mrb_gc_arena_restore(mrb, ai);
kh_val(ret_h, ret_k) = kh_val(h,k);
}
}
@@ -772,16 +776,9 @@ mrb_value
mrb_hash_empty_p(mrb_state *mrb, mrb_value self)
{
khash_t(ht) *h = RHASH_TBL(self);
- mrb_bool empty_p;
- if (h) {
- empty_p = (kh_size(h) == 0);
- }
- else {
- empty_p = 1;
- }
-
- return mrb_bool_value(empty_p);
+ if (h) return mrb_bool_value(kh_size(h) == 0);
+ return mrb_true_value();
}
static mrb_value
@@ -921,17 +918,12 @@ mrb_hash_has_keyWithKey(mrb_state *mrb, mrb_value hash, mrb_value key)
{
khash_t(ht) *h = RHASH_TBL(hash);
khiter_t k;
- mrb_bool result;
if (h) {
k = kh_get(ht, h, key);
- result = (k != kh_end(h));
- }
- else {
- result = 0;
+ return mrb_bool_value(k != kh_end(h));
}
-
- return mrb_bool_value(result);
+ return mrb_false_value();
}
/* 15.2.13.4.13 */
diff --git a/src/load.c b/src/load.c
index e832de628..092ddbde8 100644
--- a/src/load.c
+++ b/src/load.c
@@ -187,7 +187,6 @@ read_rite_section_irep(mrb_state *mrb, const uint8_t *bin)
{
int result;
size_t sirep;
- size_t i;
uint32_t len;
uint16_t nirep;
uint16_t n;
@@ -200,14 +199,14 @@ read_rite_section_irep(mrb_state *mrb, const uint8_t *bin)
nirep = bin_to_uint16(header->nirep);
//Read Binary Data Section
- for (n = 0, i = sirep; n < nirep; n++, i++) {
+ for (n = 0; n < nirep; n++) {
result = read_rite_irep_record(mrb, bin, &len);
if (result != MRB_DUMP_OK)
goto error_exit;
bin += len;
}
- result = sirep + bin_to_uint16(header->sirep);
+ result = nirep;
error_exit:
if (result < MRB_DUMP_OK) {
irep_free(sirep, mrb);
@@ -368,7 +367,7 @@ mrb_read_irep(mrb_state *mrb, const uint8_t *bin)
bin += bin_to_uint32(section_header->section_size);
} while (memcmp(section_header->section_identify, RITE_BINARY_EOF, sizeof(section_header->section_identify)) != 0);
- return total_nirep;
+ return sirep;
}
static void
@@ -464,7 +463,6 @@ read_rite_section_irep_file(mrb_state *mrb, FILE *fp)
{
int32_t result;
size_t sirep;
- size_t i;
uint16_t nirep;
uint16_t n;
uint32_t len, buf_size;
@@ -488,7 +486,7 @@ read_rite_section_irep_file(mrb_state *mrb, FILE *fp)
}
//Read Binary Data Section
- for (n = 0, i = sirep; n < nirep; n++, i++) {
+ for (n = 0; n < nirep; n++) {
void *ptr;
if (fread(buf, record_header_size, 1, fp) == 0) {
@@ -516,7 +514,7 @@ read_rite_section_irep_file(mrb_state *mrb, FILE *fp)
goto error_exit;
}
- result = sirep + bin_to_uint16(header.sirep);
+ result = nirep;
error_exit:
if (buf) {
mrb_free(mrb, buf);
@@ -567,7 +565,7 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
fpos = ftell(fp);
/* You don't need use SIZE_ERROR as block_size is enough small. */
for (i = 0; i < block_fallback_count; i++,block_size >>= 1){
- buf = mrb_malloc(mrb, block_size);
+ buf = mrb_malloc_simple(mrb, block_size);
if (buf) break;
}
if (!buf) {
@@ -614,7 +612,7 @@ mrb_read_irep_file(mrb_state *mrb, FILE* fp)
fseek(fp, fpos + section_size, SEEK_SET);
} while (memcmp(section_header.section_identify, RITE_BINARY_EOF, sizeof(section_header.section_identify)) != 0);
- return total_nirep;
+ return sirep;
}
mrb_value
diff --git a/src/parse.y b/src/parse.y
index 1d5366d17..fda66e92c 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -3620,12 +3620,14 @@ parse_string(parser_state *p)
tokadd(p, '\n');
}
else {
- pushback(p, c);
-
- if(type & STR_FUNC_REGEXP)
+ if (type & STR_FUNC_REGEXP) {
tokadd(p, '\\');
-
- tokadd(p, read_escape(p));
+ if (c != -1)
+ tokadd(p, c);
+ } else {
+ pushback(p, c);
+ tokadd(p, read_escape(p));
+ }
if (hinf)
hinf->line_head = FALSE;
}