Return value of EXEC_TAG() is saved by "int state".
Instead of "int", use "enum ruby_tag_type". First EXEC_TAG()
value should be 0, so that define TAG_NONE (= 0) and use it.
Some code used "status" instead of "state". To make them clear,
rename them to state.
We can change variable name from "state" to "tag_state", but this
ticket doesn't contain it.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* load.c (rb_f_load, rb_require_internal): DTrace hooks should not
have side effects, i.e., conversion to String.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59035 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* load.c (rb_require_internal): convert to path name with the
given safe level, without setting global safe level.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58987 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
rb_file_expand_path_fast already performs the buffer shrinking
rb_str_freeze does (via expand_path macro in file.c); the
result of rb_fstring is always frozen, and that rb_fstring
call is the last use of `expanded_path` in its scope.
load.c (rb_construct_expanded_load_path): remove rb_str_freeze
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58506 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* load.c: send as a single string.
* error.c: expose the string formatted by rb_warning as rb_warning_string().
* test/ruby/test_exception.rb: update tests.
[ruby-core:80850] [Bug #13505]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
The underlying string objects will become fstrings anyways,
so create the fstring directly from the C string to reduce
intermediate garbage.
* load.c (rb_provide, rb_provide): create fstring
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58491 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* internal.h: introduce imemo_type_p() which checks the given value is
T_IMEMO and imemo_type() == given imemo_type.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
We can use rb_fstring_cstr in some places to prevent an
intermediate object from being created before deduplication
via rb_fstring.
* compile.c (iseq_compile_each): use rb_fstring_cstr
(rb_insns_name_array): ditto
* load.c (rb_load_internal0): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57745 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
If rb_thread_shield_wait() returns Qfalse, the file has been successfully
loaded by another thread, so there is no need to insert a new entry into
loading_tbl. [ruby-core:78464] [Bug #12999]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56985 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* load.c (rb_require_safe): SyntaxError created by the parser just
has the mesage and needs to set up the backtrace.
[ruby-core:77491] [Bug #12811]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* load.c (rb_load_internal0): load/require is not the main
script.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56362 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
[Bug #12628]
This patch introduce many changes.
* Introduce concept of "Block Handler (BH)" to represent
passed blocks.
* move rb_control_frame_t::flag to ep[0] (as a special local
variable). This flags represents not only frame type, but also
env flags such as escaped.
* rename `rb_block_t` to `struct rb_block`.
* Make Proc, Binding and RubyVM::Env objects wb-protected.
Check [Bug #12628] for more details.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* vm_eval.c (rb_eval_cmd, rb_catch_obj): use TH_JUMP_TAG with the
same rb_thread_t used for TH_PUSH_TAG, instead of JUMP_TAG with
the current thread global variable.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* load.c (rb_f_load): raise with the original path name before
encoding conversion.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54521 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* parse.y (struct parser_params): move parse_in_eval flag from
rb_thread_t.
* parse.y (rb_parser_set_context): set parsing context, not only
mild error flag.
* iseq.c (rb_iseq_compile_with_option): the parser now refers no
thread local states to be restored.
* vm_eval.c (eval_string_with_cref): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* iseq.c (rb_iseq_compile_with_option): make the parser in mild
error.
* load.c (rb_load_internal0): ditto.
* parse.y (yycompile0): return the error message within the error
to be raised. [Feature #11951]
* parse.y (parser_compile_error): accumulate error messages in the
error_buffer.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
and a pre-compilation/runtime loader sample.
[Feature #11788]
* iseq.c: add new methods:
* RubyVM::InstructionSequence#to_binary_format(extra_data = nil)
* RubyVM::InstructionSequence.from_binary_format(binary)
* RubyVM::InstructionSequence.from_binary_format_extra_data(binary)
* compile.c: implement body of this new feature.
* load.c (rb_load_internal0), iseq.c (rb_iseq_load_iseq):
call RubyVM::InstructionSequence.load_iseq(fname) with
loading script name if this method is defined.
We can return any ISeq object as a result value.
Otherwise loading will be continue as usual.
This interface is not matured and is not extensible.
So that we don't guarantee the future compatibility of this method.
Basically, you should'nt use this method.
* iseq.h: move ISEQ_MAJOR/MINOR_VERSION (and some definitions)
from iseq.c.
* encoding.c (rb_data_is_encoding), internal.h: added.
* vm_core.h: add several supports for lazy load.
* add USE_LAZY_LOAD macro to specify enable or disable of
this feature.
* add several fields to rb_iseq_t.
* introduce new macro rb_iseq_check().
* insns.def: some check for lazy loading feature.
* vm_insnhelper.c: ditto.
* proc.c: ditto.
* vm.c: ditto.
* test/lib/iseq_loader_checker.rb: enabled iff suitable
environment variables are provided.
* test/runner.rb: enable lib/iseq_loader_checker.rb.
* sample/iseq_loader.rb: add sample compiler and loader.
$ ruby sample/iseq_loader.rb [dir]
will compile all ruby scripts in [dir].
With default setting, this compile creates *.rb.yarb files
in same directory of target .rb scripts.
$ ruby -r sample/iseq_loader.rb [app]
will run with enable to load compiled binary data.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
rb_autoload_str may be safer by preventing premature GC. It
can also be more efficient by passing a pre-frozen string that
can be deduped using rb_fstring. Common autoload callers (e.g.
rubygems, rdoc) already use string literals as the file
argument.
There seems to be no reason to expose rb_autoload_str to the
public C API since autoload is not performance-critical.
Applications may declare autoloads in Ruby code or via
rb_funcall; so merely deprecate rb_autoload without exposing
rb_autoload_str to new users.
Running: valgrind -v ruby -rrdoc -rubygems -e exit
shows a minor memory reduction (32-bit userspace)
before:
in use at exit: 1,600,621 bytes in 28,819 blocks
total heap usage: 55,786 allocs, 26,967 frees, 6,693,790 bytes allocated
after:
in use at exit: 1,599,778 bytes in 28,789 blocks
total heap usage: 55,739 allocs, 26,950 frees, 6,692,973 bytes allocated
* include/ruby/intern.h (rb_autoload): deprecate
* internal.h (rb_autoload_str): declare
* load.c (rb_mod_autoload): use rb_autoload_str
* variable.c (rb_autoload): become compatibility wrapper
(rb_autoload_str): hoisted out from old rb_autoload
[ruby-core:71369] [Feature #11664]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52909 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Reduce cognitive overhead, eye strain and keep lines less than 80
columns to benefit users of giant fonts (honestly I prefer 64 column
wrap :P).
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51559 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* load.c (rb_require_internal): use rb_load_internal0 not to raise
a exception to be caught.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51451 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* load.c (rb_load_internal0): stop separating exits at loading
from exits from execution. TAG_FATAL is the only case that
`errinfo` is a Fixnum, and should continue to exit by JUMP_TAG
but not raising as an ordinary exception.
[ruby-core:70169] [Bug #11404]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
How can a 'throw' happen while the current thread is reading a Ruby source file
from disk and parsing it? It can happen if another thread calls Thread#raise,
and passes an Exception object which responds to #exception, and the custom #exception
method calls Kernel#throw.
In practice, this is most likely to happen if you combine the use of autoload and
Timeout.timeout.
An extra check is required to avoid a segfault in this case.
* load.c (rb_load_internal0): extra check before returning TAG_RAISE when a
non-local transfer of control happens while loading and parsing a Ruby source file.
[ruby-core:70169] [Bug #11404]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* load.c (rb_construct_expanded_load_path): use enum for the
purpose.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51388 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
All contents of previous rb_iseq_t is in rb_iseq_t::body.
Remove rb_iseq_t::self because rb_iseq_t is an object.
RubyVM::InstructionSequence is wrapper object points T_IMEMO/iseq.
So RubyVM::ISeq.of(something) method returns different wrapper
objects but they point the same T_IMEMO/iseq object.
This patch is big, but most of difference is replacement of
iseq->xxx to iseq->body->xxx.
(previous) rb_iseq_t::compile_data is also located to
rb_iseq_t::compile_data.
It was moved from rb_iseq_body::compile_data.
Now rb_iseq_t has empty two pointers.
I will split rb_iseq_body data into static data and dynamic data.
* compile.c: rename some functions/macros.
Now, we don't need to separate iseq and iseqval (only VALUE).
* eval.c (ruby_exec_internal): `n' is rb_iseq_t (T_IMEMO/iseq).
* ext/objspace/objspace.c (count_imemo_objects): count T_IMEMO/iseq.
* gc.c: check T_IMEMO/iseq.
* internal.h: add imemo_type::imemo_iseq.
* iseq.c: define RubyVM::InstructionSequnce as T_OBJECT.
Methods are implemented by functions named iseqw_....
* load.c (rb_load_internal0): rb_iseq_new_top() returns
rb_iseq_t (T_IMEMO/iesq).
* method.h (rb_add_method_iseq): accept rb_iseq_t (T_IMEMO/iseq).
* vm_core.h (GetISeqPtr): removed because it is not T_DATA now.
* vm_core.h (struct rb_iseq_body): remove padding for
[Bug #10037][ruby-core:63721].
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51327 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This isn't used outside of load.c, so there appears to be no
reason to expose it to other modules.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51309 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* load.c (rb_require_internal): use TAG_RETURN not a magic number.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51294 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* load.c (rb_load_internal0): do not raise any exceptions but
return the result tag state.
* load.c (rb_load_protect): reduce nested EXEC_TAGs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Loaded features is an obvious candidate for fstring since
feature paths of Ruby sources are included in iseq locations,
and iseq locations are in the fstring table anyways.
Deduplicating expanded load path can reuse old objects, since since
repeated expansions may recycle before old expanded paths are GC-ed
away.
* load.c (rb_construct_expanded_load_path): fstring expanded path
(get_loaded_features_index): fstring feature path
(rb_provide_feature): ditto
[ruby-core:69871] [Feature #11331]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51261 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* load.c (rb_feature_provided): use RB_GC_GUARD for fullpath after
last use of feature.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51013 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* eval_intern.h: move decl. of rb_scope_visibility_set() to method.h.
* load.c: catch up this fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
do NULL checks when looking up the `loading_table` hash.
https://github.com/ruby/ruby/pull/918
* load.c: remove various NULL checks
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50746 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
`flag' contains several categories of attributes and it makes us
confusion (at least, I had confused).
* rb_method_visibility_t (flags::visi)
* NOEX_UNDEF -> METHOD_VISI_UNDEF = 0
* NOEX_PUBLIC -> METHOD_VISI_PUBLIC = 1
* NOEX_PRIVATE -> METHOD_VISI_PRIVATE = 2
* NOEX_PROTECTED -> METHOD_VISI_PROTECTED = 3
* NOEX_SAFE(flag)) -> safe (flags::safe, 2 bits)
* NOEX_BASIC -> basic (flags::basic, 1 bit)
* NOEX_MODFUNC -> rb_scope_visibility_t in CREF
* NOEX_SUPER -> MISSING_SUPER (enum missing_reason)
* NOEX_VCALL -> MISSING_VCALL (enum missing_reason)
* NOEX_RESPONDS -> BOUND_RESPONDS (macro)
Now, NOEX_NOREDEF is not supported (I'm not sure it is needed).
Background:
I did not know what "NOEX" stands for.
I asked Matz (who made this name) and his answer was "Nothing".
"At first, it meant NO EXport (private), but the original
meaning was gone."
This is why I remove the mysterious word "NOEX" from MRI.
* vm_core.h: introduce `enum missing_reason' to represent
method_missing (NoMethodError) reason.
* eval_intern.h: introduce rb_scope_visibility_t to represent
scope visibility.
It has 3 method visibilities (public/private/protected)
and `module_function`.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
filenames which are trailing substrings of file extensions. For
example, 'b', which a trailing substring of ".rb" should not return
false. [Bug #11155][ruby-core:69206]
* test/ruby/test_autoload.rb: test for fix
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
memo->v1 and memo->v2 is WB protected values.
So use MEMO_V1/V2_SET() macros to set these values.
memo->u3 is ambiguous (sometimes a VALUE, sometimes an integer
value), so use gc_mark_maybe() in gc.c to mark it.
Rename NEW_MEMO() to MEMO_NEW().
Move MEMO_FOR and NEW_MEMO_FOF macros from node.h.
Export a rb_imemo_new() function for ext/ripper.
* node.h: remove NODE_MEMO.
* enum.c: catch up these change.
* enumerator.c: ditto.
* load.c: ditto.
* ext/objspace/objspace.c (count_nodes): ditto.
* gc.c (gc_mark_children): mark imemo_memo type.
* parse.y (new_args_gen): use T_IMEMO.
(I'm not sure it is working correctly...)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* eval.c (setup_exception): use the given thread instead of
implicit current thread.
* load.c (rb_load_internal0): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* encoding.c (load_encoding): use rb_require_internal instead of
calling rb_require_safe with protection.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48700 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* load.c (rb_require_internal): tweak the return value, 1 and 0
correspond to true and false in Kernel#require, respectively.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48697 b2dd03c8-39d4-4d8f-98ff-823fe69b080e