[Aug.2014 to Dec.2014] mruby news

written by Daniel Bovensiepen on 2015-01-02 12:41 UTC

What happened with mruby between August 2014 and December 2014?


The biggest highlights since the last update were definitely the release of mruby 1.1.0 and the implementation of the mruby debugger (mrbd). The debugger came surprisingly with a really amazing test coverage and also a proper documentation file.


25 commits were dedicated to refactor the current mruby source. Most famously probably the refactoring of mrb_sym2name_len which went thru two phases. The original refactor approach replaced the linear search by a hash search. This improved the speed but had the disadvantage that the memory consumption increased. Matz pointed out that this function was originally implemented with this slower algorithm to keep the memory consumption low. Based on some profiling performed by dycoon it turned out that the time spend inside of mrb_sym2name_len seemed really long:

Profiling of mruby code

Based on these results, matz refactored the code with a linear symbol table which lead to a search performance now of O(1).

Improve Testing

The biggest improvement on the testing side was definitely the tests provided together with the mruby debugger. It is amazing to see that a new piece of code comes immediately with a proper test coverage. I hope this will set a standard of how to add amazing new functions and programs to the mruby core. A big thanks goes here to the mruby forum which seem to be the main contributor of the mruby debugger test cases as also to Mitsubishi Electric Micro-Computer Application Software Co.,Ltd which was mentioned in the commit and has also provided support for implementing the debugger and the test cases.

Improve stdlib

The standard library slowly reaches a state that not to many important features are missing for daily usage. Nevertheless 14 commits were dedicated to improve the following:


71 commits were dedicated to bug fixing. In general this is the major task these days as more and more people starting to use mruby more and more corner cases are identified where mruby doesn’t perform proper. In general it is a good thing that these bugs are found but as I said before in other blog entries, we still have the issue that regression tests are most of the time not provided, so it is likely that we will see some of these fixed bugs in the future again.


Here a list with all commits during these months.



Add mruby debugger (mrdb)


Avoid block_given? in mrbgem:enum.rb to reduce method calls

avoid block_given? in enum.rb to reduce method calls

Refactor for_body func

Refactor yylex func

Refactor mrbc_context_new func

Refactor mrb_f_array func

refactoring C part of #2611

refactor Hash generator loop

condition refactoring in load.c

refactor MACRO to avoid local variable name conflict; ref #2585

Refactor mrb_obj_is_kind_of_m() in kernel.c

Refactor obj_is_instance_of() in kernel.c

refactor valid instance variable name check

refactor mruby method(fix indent. remove temporary value, duplicate procedure)

refactor class.c methods (fix indent, remove unneed temp value. )

Refactor flo_mod func in numeric.c

refactor mrb_hash_shift, num_pow, flo_eq, flo_finite_p method

Refactor incremental_sweep_phase() in gc.c

Refactor obj_free() in gc.c

code reduce by using mrb_get_args(“n”)

O(1) mrb_sym2name_len(); close #2591

remove unnecessary CHAR_BIT != 8 check

mruby-strip doesn’t need mrbgems

remove unnecessary mrb_float casting; ref #2531

implement attr_reader and attr_writer in C; use cfunc closure to speed-up

Improve Testing

add multiple assignment decomposition test

avoid iseq allocation from static irep binary. it reduces 424KB allocation for mrbtest

Add test for Numeric#pow.

remove test for succ on Unicode (non-ASCII) char; #2520

added Math.cos and Math.tan test case

Improve stdlib

String#[] accepts float.

Add String#prepend

Add String#insert

add Float::{INFINITY,NAN} if available

Add Kernel.Integer

Add Kernel.Float

Add Kernel.Hash

Add Kernel.String

Add Kernel.Array

Add String#succ, String#succ!, String#next, String#next!

Handle Array#[float, int] Close #2626

String#[]: float handling merged to #2677

String#[] should reject nil index

implement Hash.[]


khash.h: keep key/value table accessible from original hashtable during resize; fix #2682

mruby-eval: fix typo

now retrieves number of arguments of blocks from OP_ENTER op code; close #2671

block_given? should return correct value when called in blocks; close #2678

block_given? should return false on top-level; ref #2678

Fix splat and multiple assignments

mrdb: fix that break command cannot handle Windows paths

avoid out-of-bounds access of irep->lv; ref #2671, fix #2675

eval() should preserve stack in env properly; fix #2671

Fix crash if #inspect does not return a string value

Fix crash if #inspect does not return a string value

mirb dies if #inspect returns a non-string value; fix #2666

fix usage message

block_given did not work with nested block invocation for some cases; fix #2665

fix ISBLANK() for Visual Studio < 2013 (ref #2658)

preserve ICLASS in ci->target_class; fix #2657; ensuring #1467 #1470 #1493 still works

adhoc fix for pass build

Fix: Numeric#step infinite loop.

fix(String) String#[] accepts float; close #2650 #2651

wrong register number adjustment in multiple assignment; fix #2654

Fix String#slice! raise TypeError or return invalid value.

fix heap-use-after-free

[ci skip] run spell checker on doc/debugger/ and fixed typos mentioned from @bovi and @rmosolgo; ref #2640

Fix an error when calling a method implemented in C by super() with arguments. This fix makes the following code workable:

Fix mailing-list description

fix mrb_notimplement typo

Fix mrb_iv_check function decleration

Fix indent

Fix misaligned access when reading irep; close #2630

Fix mrb_convert_to_integer.

instance_methods etc should not include undef’ed method names; based on a patch from @cremno; fix #2613

context proc may be cfunc; fix #2609

fix typo (i->idx)

fixed. cygwin-gcc(ver4.8.3) warning in conv_digit()

fixed. closures scope in eval(string)

Fix `mrb_get_args` arguments types found by mruby-clang-plugin.

`Module#const_defined?` to take second optional argument as CRuby; fix #2593

Fix MSVC C++ ABI build. Close #2588.

fixed wandering filename problem

Fix default gem loading in `generate_gem_table`.

fix strict aliasing rule violation

instance variable name validation based on ; fix #2584

Fix error handlings for fputs().

Fix error handlings for fprintf().

Fix Numeric#pow behavior.

Fix allocation-error-handlings for scope_new().

Fix error handlings for mrb_open_core().

Fix error handling for mrb_open_allocf().

Fix error handling for mrb_pool_realloc().

Fix error handling for mrb_generate_code().

Fix error hanldlings in read_irep_record().

Fix error handlings in mirb.

revert mrb_equal method

Fix indents in numeric.c

need to add space for receiver to proc env; fix #2525

fix build when neither src nor mrblib directory exists.

Fix String#succ. “-a-”.succ should be “-b-”

Fix String#succ. “-”.succ should be “.”

timer on windows bug fixed.

Fix a bug that class variable can’t be referenced from class method

Fix typo in gc.c

Fix a typo in etc.c

fix linkage of range_beg_len and mrb_range_beg_len

fix conversion warnings

fix typo with MRB_INT16; fix #2495

revert 6c1dfc9; ref #2525 #2565

revert accidental constify.

revert 6c1dfc9; ref #2525 #2565


Fix mismatches for MRB_API declarations.

Implement C API mrb_notimplement

add some MRB_API to function prototypes

remove unnecessary MRB_API from mrb_num_div(); close #2578

Add API `mrb_data_init` to initialize `MRB_TT_DATA` tagged instance.

add MRB_API modifiers to mruby API functions

mrb_str_new(mrb, “”, len) creates an unmodifiable string object; ref #2674

mrb_p() should print mrb_obj_as_string() if #inspect does not return a string value

mrb_parser_dump() did not work with block arguments

Add write_barrier docs

write barrier doc update


Use suitable type.

try to convert not only nil but every objects to fixnums; ref #2677

mruby-eval: proc from env may be NULL; close #2676

should not pop register when value from multiple assignment required

closing to Local Scope

wrong register adjustment

add “fall through” comment

OP_APOST local variable display was wrong

free memory used by breakpoints

free return value of dirname()

remove unnecessary _WIN32 preprocessor check

add missing null-termination

align indent of local variable names in codedump()

should support recursive mlhs decomposition, e.g. (a,b),c = [1,2],3

use mrb_str_xxx_lit for mrdb.

remove const type qualifier

don’t convert function pointer to object pointer

remove cast

free memory used by breakpoints

free return value of dirname()

separate mrb_notimplement() and mrb_notimplement_m(); ref #2636

[ci skip] rephrasing about mailing list description; ref #2639

change BIN_PATH for new gc in Arduino IDE >= 1.5.7

Modify Arduino build config for IDE >= 1.5.7

%zu format is not supported by MSVC

update teeny of MRUBY_VERSION; ref #2629

avoid using rewind(3) to load mrb files

read whole mrb file at once to calculate correct padding offset; ref #2630

specify alignment specifier for GCC and MSC; ref #2630

Under cygwin host, ncurses.a is only available instead of termcap.a.

avoid wrong ArgumentError from mrb_get_args() when surrounding method takes more than one argument; ref #2627

add cast to return from aget_index(); ref #2627

use mrb_get_args to parse Integer() option; ref #2625

Replace int with mrb_bool in parse_string func

Replace int with mrb_bool in local_var_p func

need addtional type check to avoid SEGV; ref #2609

remove header prototype of mrb_exc_print; close #2607

add similar range check for tm->usec as well

always check range before casting time_t to mrb_int

time_t may overflow mrb_int when word boxing is used

word_boxing.h used int to represent symbols; use mrb_sym instead

remove accidental check-in of mruby-thread gem

cast MRB_ENV_STACK_LEN to (mrb_int); ref #2600

Change mrblib’s source path to absolute path

Pacify MSVC warnings for numeric.c, proc.c, and symbol.c

use __init_array_start to determine readonly data section;

load.c to use mrb_ro_data_p()

mrbconf.h option MRB_USE_ETEXT_EDATA to reduce memory.

mrb_sym2name_len() should initialize lenp even when proper symbol does not exist

remove unnecessary trailing comma to remove pre C99 declaration error with -Wdeclaration-after-statement

target_class should not be TT_ICLASS in instance_eval(string); ref #1152

Remove duplicated mrb_print_backtrace() declaration

Wrap to 80 columns

Wrap INSTALL to 80 columns

Wrap to 80 columns

change class argument of mrb_const_defined_at from `struct RClass*` to `mrb_value` to make it consistent with mrb_const_defined; ref #2593

const_defined? to check superclasses; ref #2593

to_hash/to_a check in Hash[] should only be done when only one argument is given; ref #2594

copy documentation comment from CRuby

remove line number from raise message

update outdated links to the original program.

change mrb_sym type from uint16_t to uint32_t

constify pointer from RARRAY_PTR to detect potential write barrier bugs.

add benchmark/bm_app_lc_fizzbuzz.rb

Add inline to str_with_class().

remove execution bit from benchmark/fib39.rb

support native byteorder in mrb files; ref 3492be

get rid of shadowing variables (mrbgems)

wrong iseq conversion flag

rename a local variable current_node -> nodetype; ref #2583

get rid of shadowing variables

save and restore arena index to prevent arena overflow.

Use mrb_str_cat_lit() instead of mrb_str_cat_cstr() for string-literals.

move mrb_proc_new_cfunc_with_env() to the core

attr_reader and attr_writer should return nil

remove ci->nreg initialization from cipush()

delete obsolete macros (mrb_basic + mrb_object)

use RITE_LV_NULL_MARK for better readability

add sym_validate_len() to validate symbol length

more OP_MOVE swap detection in peephole optimization

allow no_optimize esp. for debugger

Remove unused macro.

adjust node lineno of muiti line statements

print lineno of dumping node

adjust node lineno of muiti line statements

print lineno of dumping node

Rename functions for avoinding symbol confiliction.

Unify duplicated functions (noregexp() and regexp_check()).

add write barrier to env on pop call info poped. #2525

add symbol table overflow check

Add a missing space after “,”.

Use mrb_malloc() instead of mrb_realloc().

Remove discareded NULL checks.

remove unused MSVC strtoll fallback


printf: cast variables to the expected type

Remove spaces in end-of-line.

Use sizeof() instead of strlen().

Update math.c

use mrb_str_cat_lit() instead of mrb_str_cat_cstr().

changed to call check_cv_name_str in check_cv_name_sym and adjust indent

Unify include guard styles and header comments.

Remove a discarded comparison.

should use non NULL scope for raise_error(); ref #2547

Remove empty lines.

Use specified macro(NULL) instead of magic-number.

Improve replacement math functions for Visual C++.

use mrb_false_value instead of mrb_bool_value

removed unused variable in range_beg_len

Remove some roundoff from mrb_flo_to_str

add write barrier when iv is copied

changed some string method’s mrb-aspec

mrb_str_bytesize is a carbon copy of mrb_str_size. remove it.

“-a-a-”.succ should be “-a-b-”

changed mrb_str_size and mrb_str_bytesize comments.

fixed evaluation context of eval(string) and instance_eval(string)

move StopIteration to core; close #2518

removed non-need space


don’t always generate gem functions

change linkage of mrb_str_size to internal

MSVC: add simple (v)snprintf implementation

turn string obsolete functions into macros

rename obsolete mrb_special_const_p to mrb_immediate_p

Time#to_i and Time#usec should care about mrb_int overflow on MRB_INT16; ref #2495

Use Boolean macro in variable.c

available also via rss