Commit Graph

137 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 49ae2a69f2 Add mrb_get_arg1() that retrieves single (and only) argument.
`mrb_get_arg1()` raises `ArgumentError` if the method does not receive one
argument.

And replaces all `mrb_get_args(mrb, "o", &arg)` by the new function.
2020-06-20 12:49:46 +09:00
Yukihiro "Matz" Matsumoto 9174b18f34 Rename mrb_num_args_error to mrb_argnum_error; ref #4863 2020-01-01 22:37:14 +09:00
KOBAYASHI Shuji 81de1f159c Add mrb_num_args_error() for "wrong number of arguments" error
To unify the style of messages.
2019-12-12 11:45:58 +09:00
KOBAYASHI Shuji e23840a3fc Remove unneeded Array creation in Struct#_inspect 2019-10-29 20:55:28 +09:00
Yukihiro "Matz" Matsumoto a365f9a67d Rename symbol-to-string functions; close #4684
* mrb_sym2name -> mrb_sym_name
* mrb_sym2name_len -> mrb_sym_name_len
* mrb_sym2str -> mrb_sym_str
2019-09-25 23:52:00 +09:00
KOBAYASHI Shuji 334afb167c Use new specifiers/modifiers of mrb_vfromat()
The binary sizes (gems are only `mruby-bin-mruby`) are reduced slightly in
my environment than before the introduction of new specifiers/modifiers
(5116789a) with this change.

  ------------+-------------------+-------------------+--------
   BINARY     | BEFORE (5116789a) |   AFTER (This PR) |  RATIO
  ------------+-------------------+-------------------+--------
   mruby      |      593416 bytes |      593208 bytes | -0.04%
   libmruby.a |      769048 bytes |      767264 bytes | -0.23%
  ------------+-------------------+-------------------+--------

BTW, I accidentally changed `tasks/toolchains/visualcpp.rake` at #4613,
so I put it back.
2019-08-05 13:18:50 +09:00
Yukihiro "Matz" Matsumoto d605b72c1d Merge branch 'master' into i110/inspect-recursion 2019-07-17 10:35:41 +09:00
Yukihiro "Matz" Matsumoto ace0c76a69 Renamed stacked to onstack; ref #4523 2019-06-25 18:07:48 +09:00
dearblue a76da32567 Use stack memory for small name of Struct members 2019-06-22 17:49:07 +09:00
Yukihiro "Matz" Matsumoto e514264b53 Merge pull request #4507 from shuujii/fix-index-in-error-message-of-Struct-aref
Fix index in error message of `Struct#[]`
2019-06-17 12:21:48 +09:00
Yukihiro "Matz" Matsumoto c1901539a8 Merge pull request #4502 from shuujii/adjust-allocation-size-in-mrb_id_attrset-mruby-struct
Adjust allocation size in `mrb_id_attrset()` (`mruby-struct`)
2019-06-17 12:18:48 +09:00
KOBAYASHI Shuji 9e378b451f Fix index in error message of Struct#[]
Before this patch:

  $ bin/mruby -e 'Struct.new(:a,:b).new[-3]'
  #=> offset -1 too small for struct(size:2) (IndexError)

After this patch (same as Ruby):

  $ bin/mruby -e 'Struct.new(:a,:b).new[-3]'
  #=> offset -3 too small for struct(size:2) (IndexError)
2019-06-15 19:41:04 +09:00
KOBAYASHI Shuji 6084048b28 Remove a meaningless branch condition in mruby-struct
The following branch condition is always true:

  // mrbgems/mruby-struct/src/struct.c:187 in make_struct_define_accessors()
  if (is_local_id(mrb, name) || is_const_id(mrb, name)) {
2019-06-14 10:26:19 +09:00
KOBAYASHI Shuji 9bd692bc67 Fix class name validation in Struct.new
Before this patch:

  $ bin/mruby -e 'p Struct.new("A-")'
  #=> Struct::"A-"

After this patch:

  $ bin/mruby -e 'p Struct.new("A-")'
  #=> NameError: identifier A- needs to be constant
2019-06-13 21:24:48 +09:00
KOBAYASHI Shuji ee955b58f7 Adjust allocation size in mrb_id_attrset() (mruby-struct) 2019-06-12 18:52:58 +09:00
KOBAYASHI Shuji 5969ed1afb Commented out "Struct.new removes existing constant" test
Because this test is always skipped.
2019-04-28 18:42:23 +09:00
KOBAYASHI Shuji e3beef065c Extract frozen checking to function 2019-04-09 18:23:11 +09:00
KOBAYASHI Shuji fbad7a1595 Use FrozenError instead of RuntimeError in frozen object modification test 2019-03-19 20:48:32 +09:00
Wataru Ashihara e91f3ec770 Move Object#dig to Struct#dig
This method seems to be mistakenly put into `Object` instead of `Struct`
since it's in `struct.rb` and daf83946b says:

  add #dig to Array,Hash and Struct
2019-02-24 16:59:02 +09:00
Yukihiro "Matz" Matsumoto 6397ec727f Raise NameError for symbol struct access. 2019-02-07 15:52:33 +09:00
Yukihiro "Matz" Matsumoto 9516731329 Use type checking mrb_to_str instead of converting mrb_str_to_str. 2018-11-19 12:08:28 +09:00
Yukihiro "Matz" Matsumoto 14206a75a3 Remove potential path to avoid uninitialized variable access. 2018-08-13 23:15:52 +09:00
Yukihiro "Matz" Matsumoto afbbc0a2cb Small refactoring.
The macro `RCLASS_SUPER`, `RCLASS_IV_TBL` and `RCLASS_M_TBL` are
removed from `include/mruby/class.h`.
2018-08-06 10:15:55 +09:00
Ichito Nagata 2af92d0ebc Let inspect recursion do the right thing 2018-06-04 11:25:10 +09:00
Yukihiro "Matz" Matsumoto bbb0882343 Modifying frozen objects will raise FrozenError.
`FrozenError` is a subclass of `RuntimeError` which used to be
raised.  [Ruby2.5]
2017-12-12 18:41:18 +09:00
Yukihiro "Matz" Matsumoto 8f2c62407c Add MRB_METHOD_TABLE_INLINE option.
Now the method tables (in classes/modules and caches) keeps C function
pointers without wrapping in `struct RProc` objects. For the sake of
portability, `mrb_method_t` is represented by the struct and union, but
if the most significant bit of the pointer is not used by the platform,
`mrb_method_t` should be packed in `uintptr_t` to reduce memory usage.

`MRB_METHOD_TABLE_INLINE` is turned on by default for linux.
2017-11-20 18:33:41 +09:00
Yukihiro "Matz" Matsumoto 12e38597c8 Always check division-by-zero to avoid undefined behavior; fix #3816
Also removed the code to normalize NaN value for `MRB_NAN_BOXING`.
Tha code was added to fix #1712 but no longer required after 249f05e7d.
2017-11-03 09:35:55 +09:00
Yukihiro "Matz" Matsumoto 77edafb04c Need to check number of argument of Struct#new; fix #3823 2017-10-29 00:25:45 +09:00
Yukihiro "Matz" Matsumoto fb85855fa1 Add more checks before accessing struct pointer; ref #3831 2017-10-17 07:43:35 +09:00
Yukihiro "Matz" Matsumoto be2c1592ed Check struct-array pointer before accessing; fix #3831 2017-10-16 22:53:36 +09:00
dearblue 44e2c97152 fix alias for Struct accessors 2017-10-15 23:43:55 +09:00
Yukihiro "Matz" Matsumoto f26d00d9e8 Embed small size array elements in the heap.
It reduces the memory consumption and sometimes improve the
performance as well.  For example, the consumed memory size
of `bench/bm_ao_render.rb` is reduced from 1.2GB to 1GB, and
its total execution time become 18.795 sec from 22.229 sec.
2017-07-27 16:13:06 +09:00
Yukihiro "Matz" Matsumoto a18904a4c2 Use "$!" specifier of mrb_get_args. 2017-07-12 14:49:55 +09:00
Yukihiro "Matz" Matsumoto 3554a41a54 Remove unnecessary initialization of a local variable. 2017-06-27 22:48:06 +09:00
take_cheeze da5b7fa769 Support freeze in Struct. 2017-04-21 17:23:54 +09:00
Yukihiro "Matz" Matsumoto 17377af984 Struct may not be initialized in #to_h; fix #3607 2017-04-13 10:51:16 +09:00
Yukihiro "Matz" Matsumoto bd7bf260e8 Should specify instance type of Structs; fix #3591 2017-04-05 17:52:26 +09:00
Yukihiro "Matz" Matsumoto 74712c73ac Need to insert write barriers in struct updates; fix #3547 2017-04-05 11:53:20 +09:00
Yukihiro "Matz" Matsumoto 5771c9778e add a test for #3296 2016-11-30 03:51:23 +09:00
Yukihiro "Matz" Matsumoto 37743111d9 should not refer Struct class by name; fix #3296 2016-11-30 03:49:56 +09:00
Yukihiro "Matz" Matsumoto 743c1e7be1 stop warnings in the test; ref #3280 2016-11-25 09:44:22 +09:00
Yukihiro "Matz" Matsumoto 79e3980a7f resolve conflict; ref #3281 2016-11-25 09:31:51 +09:00
Clayton Smith b60d6c42aa Don't allow array parameter in Struct.new 2016-11-24 10:05:05 -05:00
Clayton Smith 82731d9ee0 Remove constant when a struct is redefined. 2016-11-24 10:04:09 -05:00
Tomasz Dąbrowski 8e0dc6fa8d Correct argument specifications for few methods:
- Struct#values_at
 - Module#define_method
 - String#chop
 - String#chop!
2016-11-16 15:46:28 +01:00
Yukihiro "Matz" Matsumoto a66a1e92e7 Merge pull request #3179 from ksss/struct
Should not define to `Struct` class
2016-07-25 14:19:10 +09:00
Yukihiro "Matz" Matsumoto 417092360d Fixed crash error when #initialize is redefined for Struct; fix #3177
refactored redundant functions; removed optimized accessors for safety
this fix also close #3178
2016-07-25 10:32:10 +09:00
ksss bf21063a72 Add regression test 2016-07-22 15:26:17 +09:00
ksss 1a8074accf Should not define to Struct class 2016-07-22 15:26:11 +09:00
Yukihiro "Matz" Matsumoto 817b884343 add #dig tests 2016-03-23 12:34:32 +09:00