Граф коммитов

292 Коммитов

Автор SHA1 Сообщение Дата
Jeremy Evans 345db8f2aa Avoid pointless attempts to open .so file if already required
When attempting to require a file without an extension that has
already been required or provided with an .so extension, only
look for files with an .rb extension. There is no point in
trying to find files with an .so extension, since we already
know one has been loaded.

Previously, attempting to require such a file scanned the load
path twice, once for .rb and once for .so.  Now it only scans
once for .rb.  The scan once for .rb cannot be avoided, since
the .rb file would take precedence and should be loaded if it
exists.

Fixes [Bug #10902]
2021-07-28 12:29:45 +09:00
Nobuyoshi Nakada b360588cd3
Sort feature index arrays by the priority of file types [Bug #15856]
When looking for libraries to load with a feature name without
extension, `.rb` files are given priority. However, since the
feature index arrays were not in that order of priority, but in
the order in which they were loaded, a lower priority extension
library might be returned. In that case, the `.rb` file had to be
searched for again from the `$LOAD_PATH`, resulting in poor
performance.
2021-07-24 23:59:07 +09:00
Nobuyoshi Nakada 803eb1ee83
Get rid of type aliasing 2021-07-18 19:22:21 +09:00
Nobuyoshi Nakada 70833fab7f
Suppress gcc11 clobbered warning 2021-06-14 23:24:17 +09:00
Samuel Williams 25921fe1d6 Revert "Suppress gcc11 clobbered warning"
This reverts commit f0f9e77b65.
2021-06-14 22:07:59 +12:00
Nobuyoshi Nakada 635e1c5282
Pack values to preserve 2021-06-14 14:10:21 +09:00
Nobuyoshi Nakada f0f9e77b65
Suppress gcc11 clobbered warning 2021-06-14 14:09:43 +09:00
David Rodríguez 02151dad1b `$LOAD_PATH.resolve_feature_path` should not raise
I think it's more friendly and easier to work with to return `nil` when
the feature is not found in the $LOAD_PATH.
2021-02-16 18:11:13 +09:00
Nobuyoshi Nakada b72f613210
Suppress a "clobbered" warning by gcc on macOS 2020-12-11 01:17:15 +09:00
Koichi Sasada 182fb73c40 rb_ext_ractor_safe() to declare ractor-safe ext
C extensions can violate the ractor-safety, so only ractor-safe
C extensions (C methods) can run on non-main ractors.
rb_ext_ractor_safe(true) declares that the successive
defined methods are ractor-safe. Otherwiwze, defined methods
checked they are invoked in main ractor and raise an error
if invoked at non-main ractors.

[Feature #17307]
2020-12-01 15:44:18 +09:00
Stefan Stüben 8c2e5bbf58 Don't redefine #rb_intern over and over again 2020-10-21 12:45:18 +09:00
Nobuyoshi Nakada 6944b927bd
rb_class_real never returns Qnil 2020-10-09 11:49:13 +09:00
Jeremy Evans e1bbb9ea9c Document that Kernel#load will load relative to current directory [ci skip]
Update and format the Kernel#load documentation to separate the
three cases (absolute path, explicit relative path, other), and
also document that it raises LoadError on failure.

Fixes [Bug #16988]
2020-07-09 14:47:13 -07:00
卜部昌平 6575766ea0 search_required: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
卜部昌平 e551dfda9f rb_feature_p: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a
branch is definitely a bad idea.  Better refactor.
2020-06-29 11:05:41 +09:00
MSP-Greg 4cb8b49d41 [DOC] relative filename `Kernel#.require` and `Kernel#.load` [ci skip] 2020-06-01 09:20:57 +09:00
Nobuyoshi Nakada e10798b3a3
[DOC] refined `Kernel#.require` and `Kernel#.load` [ci skip] 2020-05-30 22:04:49 +09:00
Nobuyoshi Nakada 0d30f42813
[DOC] mentioned "explicit relative path" [ci skip]
`Kernel#.require` and `Kernel#.load` do not search also "explicit
relative path" files, not only absolute paths, in the load path.
2020-05-30 01:09:16 +09:00
Jeremy Evans 5a9d2da76e Remove deprecated rb_require_safe 2020-04-30 10:32:27 -07:00
Nobuyoshi Nakada 7d6903dc47
Add the loaded feature after no exception raised
Retrying after rescued `require` should try to load the same
library again.  [Bug #16607]
2020-02-04 16:10:39 +09:00
卜部昌平 5e22f873ed decouple internal.h headers
Saves comitters' daily life by avoid #include-ing everything from
internal.h to make each file do so instead.  This would significantly
speed up incremental builds.

We take the following inclusion order in this changeset:

1.  "ruby/config.h", where _GNU_SOURCE is defined (must be the very
    first thing among everything).
2.  RUBY_EXTCONF_H if any.
3.  Standard C headers, sorted alphabetically.
4.  Other system headers, maybe guarded by #ifdef
5.  Everything else, sorted alphabetically.

Exceptions are those win32-related headers, which tend not be self-
containing (headers have inclusion order dependencies).
2019-12-26 20:45:12 +09:00
Nobuyoshi Nakada 14a17063a1
Fixed stack overflow [Bug #16382]
Get rid of infinite recursion in expanding a load path to the real
path while loading a transcoder.
2019-12-03 08:51:50 +09:00
Koichi Sasada a5fe08fdd9 care about TAG_FATAL.
TAG_FATAL represents interpreter closing state and ec->errinfo
contains FIXNUM (eTerminateSignal, etc). If we need to change the
state, then errinfo is also changed because TAG_RAISE assumes that
ec->errinfo contains a Exception object.

Without this patch, TAG_FATAL is ignored and no ec->errinfo change
so that it causes critical issue.
[Bug #16177]
2019-11-19 16:56:56 +09:00
Jeremy Evans c5c05460ac Warn on access/modify of $SAFE, and remove effects of modifying $SAFE
This removes the security features added by $SAFE = 1, and warns for access
or modification of $SAFE from Ruby-level, as well as warning when calling
all public C functions related to $SAFE.

This modifies some internal functions that took a safe level argument
to no longer take the argument.

rb_require_safe now warns, rb_require_string has been added as a
version that takes a VALUE and does not warn.

One public C function that still takes a safe level argument and that
this doesn't warn for is rb_eval_cmd.  We may want to consider
adding an alternative method that does not take a safe level argument,
and warn for rb_eval_cmd.
2019-11-18 01:00:25 +02:00
卜部昌平 c9ffe751d1 delete unused functions
Looking at the list of symbols inside of libruby-static.a, I found
hundreds of functions that are defined, but used from nowhere.

There can be reasons for each of them (e.g. some functions are
specific to some platform, some are useful when debugging, etc).
However it seems the functions deleted here exist for no reason.

This changeset reduces the size of ruby binary from 26,671,456
bytes to 26,592,864 bytes on my machine.
2019-11-14 20:35:48 +09:00
卜部昌平 7bcfd9189a drop-in type check for rb_define_global_function
We can check the function pointer passed to rb_define_global_function
like we do so in rb_define_method.  It turns out that almost anybody
is misunderstanding the API.
2019-08-29 18:34:09 +09:00
卜部昌平 1663d347c9 delete `$` sign from C identifiers
They lack portability. See also
https://travis-ci.org/shyouhei/ruby/jobs/577164015
2019-08-27 15:52:26 +09:00
卜部昌平 bd8dc2561d struct MEMO now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  There is only one usage of
MEMO::u3::func in load.c (where void Init_Foobar(vodi) is registered)
so why not just be explicit.
2019-08-27 15:52:26 +09:00
卜部昌平 ae2dc3f217 rb_define_hooked_variable now free from ANYARGS
After 5e86b005c0, I now think ANYARGS is
dangerous and should be extinct.  This commit uses rb_gvar_getter_t /
rb_gvar_setter_t for rb_define_hooked_variable /
rb_define_virtual_variable which revealed lots of function prototype
inconsistencies.  Some of them were literally decades old, going back
to dda5dc00cf.
2019-08-27 15:52:26 +09:00
Nobuyoshi Nakada 74ca6b88dd
Omit a tag unless loading with a wrapper module 2019-08-18 00:34:12 +09:00
Nobuyoshi Nakada ad3f7a3667
Should require without wrapper module 2019-08-09 00:12:54 +09:00
Nobuyoshi Nakada 995c2e9536
Reduce unnecessary EXEC_TAG in require 2019-08-08 22:28:00 +09:00
Nobuyoshi Nakada 76bd0714cf
solve "duplicate :raise event" in require too [Bug #15877] 2019-08-08 21:27:39 +09:00
Nobuyoshi Nakada 3d87b774c4
Use `ec` instead of `th->ec` where the `th` came from the `ec` 2019-08-08 21:27:39 +09:00
git 29bdfeb0c6 * expand tabs. 2019-08-08 17:59:38 +09:00
Koichi Sasada b004d3e830 solve "duplicate :raise event" [Bug #15877]
Without this patch, "raise" event invoked twice when raise an
exception in "load"ed script.
This patch by  danielwaterworth (Daniel Waterworth).
[Bug #15877]
2019-08-08 17:56:04 +09:00
Nobuyoshi Nakada 8cfa3d861c
Do not expect RSTRING_PTR valid after rb_fstring 2019-08-05 10:51:52 +09:00
git 7817a6fa09 * expand tabs. 2019-08-04 22:27:17 +09:00
Nobuyoshi Nakada 76e2370f13
Fix dangling path name from fstring
* load.c (rb_require_internal): make sure in advance that the path
  to be loaded shares a fstring, to get rid of dangling path name.
  Fixed up 5931857281.  [Bug #16041]
2019-08-04 22:21:53 +09:00
Yusuke Endoh 61577fa53b Add a /* fall through */ comment 2019-07-14 17:32:53 +09:00
Benoit Daloze 4a935bc6f6 Document $LOAD_PATH.resolve_feature_path in globals.rdoc
* RDoc does not seem to support documenting singleton object methods,
  and making $LOAD_PATH a class as a workaround is too weird.
2019-07-13 15:23:49 +02:00
Nobuyoshi Nakada d77b84ca82
$LOAD_PATH.resolve_feature_path
Moved from RubyVM.  [Feature #15903]
2019-07-11 14:05:34 +09:00
Nobuyoshi Nakada 5b7cc63d11
Turned `recur` into `int` [Feature #15777] 2019-06-21 17:28:37 +09:00
Jean Boussier fb85a42860
Add an optional `inherit` argument to Module#autoload?
[Feature #15777]

Closes: https://github.com/ruby/ruby/pull/2173
2019-06-21 17:28:37 +09:00
nobu 56557ec28a [DOC] fix markups [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-03-22 11:04:59 +00:00
svn d7c7382f7a * expand tabs.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-31 01:14:52 +00:00
nobu 58508e8b55 load.c: resolve_feature_path
* load.c (rb_resolve_feature_path): search the path for already
  loaded feature.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66661 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-31 01:14:51 +00:00
mame c6915042ab vm.c: Move the rdoc of RubyVM.resolve_feature_path [Bug #15482]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66653 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-30 13:21:30 +00:00
ko1 496267023c fix missed script_compiled events. [Bug #15471]
* ruby.c (process_options): script_compiled events are missed on
  command line -e or specified file. this commit fix it.
  [Bug #15471]

  This patch should be backport to Ruby 2.6 branch.

* vm_core.h (rb_exec_event_hook_script_compiled): introduce utility
  function to invoke a script_compiled event.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-27 17:39:17 +00:00
ko1 5ac990e83e `script_compiled` TracePoint event [Feature #15287]
* vm_trace.c: add `script_compiled` event. This event invoked
  after script compiling and before evaluating compiled script.
  Also the following methods are added:

  `TracePoint#compiled_instruction_sequence` method to get compiled
  `RubyVM::InstructionSequence` instance.

  `TracePoint#compiled_eval_script` method to get compiled script (String)
  by *eval methods (return nil if compiling by file).

* vm_trace.c (tracepoint_attr_raised_exception):


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66249 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06 13:42:32 +00:00
mame 0cd28199e5 load.c (RubyVM.resolve_feature_path): New method. [Feature #15230]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06 06:40:54 +00:00
nobu fa8b08b424 Prefer `rb_fstring_lit` over `rb_fstring_cstr`
The former states explicitly that the argument must be a literal,
and can optimize away `strlen` on all compilers.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-10-13 09:59:22 +00:00
normal 4f53579896 load.c: use ruby_sized_xfree for calloc-ed RArray VALUE
IMHO, this increases readability, too, since it's not
immediately clear that the object is on the malloc heap
and not a regular Ruby object.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63483 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-05-21 21:40:54 +00:00
tenderlove bf04b4e188 load.c: reduce memory usage of loaded_features_index
Use integer hashsum instead of string as a key in loaded_features_index.
Do not use ruby strings for substring operation, just plain pointer
and length.

[ruby-core:53688]

Co-authored-by: Sokolov Yura aka funny_falcon <funny.falcon@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62404 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-02-14 18:38:33 +00:00
normal 903b6628de load.c: use rb_warning directly
This removes the last dependency on rb_mWarning outside of
error.c and allows future commits to mark it static.

Yes, I expect this to slow down the emitting of a warning
message in a cold code path slightly :P

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-20 22:07:36 +00:00
nobu e9cb552ec9 internal.h: remove dependecy on ruby/encoding.h
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-09 06:24:11 +00:00
mame 92b81dc597 make rb_iseq_new* accept rb_ast_body_t instead of NODE*
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-05 08:59:22 +00:00
mame 503b858cef node.h: define rb_ast_body_t and restructure rb_ast_t
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-05 08:59:20 +00:00
ko1 0e34638f79 remove `PUSH_TAG`/`EXEC_AG`/`POP_TAG`/`JUMO_TAG`.
* eval_intern.h: remove non-`EC_` prefix *_TAG() macros.
  Use `EC_` prefix macros explicitly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61040 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-06 03:16:08 +00:00
nobu 7a693278c2 load.c: cwd encoding
* load.c (rb_get_expanded_load_path): save cwd cache in OS path
  encoding, to get rid of unnecessary conversion and infinite
  loading when it needs encoding conversion.
  [ruby-dev:50221] [Bug #13863]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-12 04:45:51 +00:00
ko1 8b7f06d2d6 th->ec: rb_load_internal0
* load.c (rb_load_internal0): accepts `ec`.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60689 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-07 05:45:46 +00:00
ko1 85fcaf025d * node.h (ast_t): renamed to `rb_ast_t`.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-29 15:51:23 +00:00
mame e35fe8d11b Revert "Revert "Manage AST NODEs out of GC""
This re-introduces r60485.
This reverts commit 5a176b75b1.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60488 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27 16:44:57 +00:00
mame 5a176b75b1 Revert "Manage AST NODEs out of GC"
This reverts commit 620ba74778.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60486 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27 16:02:34 +00:00
mame 620ba74778 Manage AST NODEs out of GC
NODEs in AST are no longer objects managed by GC.  This change will
remove the restriction imposed by the GC.  For example, a NODE can use
more than five words (this is my primary purpose; we want to store the
position data for each NODE, for coverage library), or even a NODE can
have variable length (some kinds of NODEs have unused fields).
To do this, however, we need more work, since Ripper still uses T_NODE
objects managed by the GC.

The life time of NODEs is more obvious than other kinds of objects; they
are created at parsing, and they become disused immediately after
compilation.  This change releases all NODEs by a few `xfree`s after
compilation, so performance will be improved a bit.  In extreme example,
`eval("x=1;" * 10000000)` runs much faster (40 sec. -> 7.8 sec. on my
machine).

The most important part of this change is `ast_t` struct, which has
three contents: (1) NODE buffer (malloc'ed memory), (2) a reference to
the root NODE, and (3) an array that contains objects that must be
marked during parsing (such as literal objects).  Some functions that
had received `NODE*` arguments, must now receive `ast_t*`.

* node.c, node.h: defines `ast_t` struct and related operations.
* gc.c, internal.h: defines `imemo_ast`.
* parse.y: makes `parser_params` struct have a reference to `ast_t`.
  Instead of `rb_node_newnode`, use `rb_ast_newnode` to create a NODE.
* iseq.c, load.c, ruby.c, template/prelude.c.tmpl: modifies some
  functions to handle `ast_t*` instead of `NODE*`.
* test/ruby/test_gc.rb: ad-hoc fix for a failed test.  The test assumes
  GC eden is increased at startup by NODE object creation.  However,
  this change now create no NODE object, so GC eden is not necessarily
  increased.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60485 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-27 15:59:02 +00:00
ko1 4552f74715 introduce EC_*_TAG() instead of TH_*_TAG()
* eval_intern.h:
  introduce EC_*_TAG() macros instead of TH_*_TAG() macros.
  * TH_PUSH_TAG() -> EC_PUSH_TAG()
  * TH_POP_TAG() -> EC_POP_TAG()
  * TH_TMPPOP_TAG() -> EC_TMPPOP_TAG()
  * TH_REPUSH_TAG() -> EC_REPUSH_TAG()
  * TH_EXEC_TAG() -> EC_EXEC_TAG()
  * TH_JUMP_TAG() -> EC_JUMP_TAG()

  rb_threadptr_tag_state() , rb_ec_tag_jump() also accept `ec` instead of `th`.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60450 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26 11:02:13 +00:00
ko1 837fd5e494 Use rb_execution_context_t instead of rb_thread_t
to represent execution context [Feature #14038]

* vm_core.h (rb_thread_t): rb_thread_t::ec is now a pointer.
  There are many code using `th` to represent execution context
  (such as cfp, VM stack and so on). To access `ec`, they need to
  use `th->ec->...` (adding one indirection) so that we need to
  replace them by passing `ec` instead of `th`.

* vm_core.h (GET_EC()): introduced to access current ec. Also
  remove `ruby_current_thread` global variable.

* cont.c (rb_context_t): introduce rb_context_t::thread_ptr instead of
  rb_context_t::thread_value.

* cont.c (ec_set_vm_stack): added to update vm_stack explicitly.

* cont.c (ec_switch): added to switch ec explicitly.

* cont.c (rb_fiber_close): added to terminate fibers explicitly.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60440 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-26 08:32:49 +00:00
nobu d352d0a0a7 vm.c: fetch retval iff necessary
* vm.c (rb_vm_make_jump_tag_but_local_jump): get rid of fetching
  retval when it is not used.  it is necessary for local jump
  state only.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-25 21:51:56 +00:00
nobu 6f968cab15 load.c: fix rb_load_protect condition
* load.c (rb_load_protect): fix the condition to load the found
  file.  fixup of r59155.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60007 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-24 05:22:23 +00:00
nobu b6d3927e16 load.c: real path to load
* load.c (rb_construct_expanded_load_path): expand load paths to
  real paths to get rid of duplicate loading from symbolic-linked
  directories.  [Feature #10222]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59984 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-09-21 07:29:20 +00:00
ko1 8dd9c12c58 move fields to ec.
* vm_core.h (rb_thread.h): move errinfo and trace_arg to
  rb_execution_context_t.

* cont.c (fiber_switch, rb_cont_call): do not restore "trace_arg" here.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-28 14:27:49 +00:00
ko1 2108e55c0b use "enum ruby_tag_type" and TAG_NONE.
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
2017-06-23 07:25:52 +00:00
nobu 942dbb0238 load.c: get rid of side effects
* 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
2017-06-07 14:36:18 +00:00
nobu 86ae6129cb load.c: encode to OS path outside PUSH_TAG
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59013 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-06-04 07:29:52 +00:00
nobu b9f5cab23a load.c: convert by rb_get_path_check
* 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
2017-06-01 13:05:54 +00:00
normal b7ad549654 load.c: remove a redundant rb_str_freeze call
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
2017-04-29 10:50:59 +00:00
eregon acde55201b Send the backtrace of the circular require warning as a single String to Warning.warn
* 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
2017-04-27 12:07:43 +00:00
normal 42c2df9937 load.c: make fstrings from C strings sooner
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
2017-04-27 03:16:39 +00:00
nobu 5ad56e7c0b load.c: backtrace of circular require
* load.c (load_lock): print backtrace of circular require via
  `Warning.warn` [ruby-core:80850] [Bug #13505]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58471 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-04-25 08:17:24 +00:00
ko1 7519688ed8 introduce imemo_type_p(v, imemo_type)
* 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
2017-04-07 06:41:32 +00:00
normal d1a506eca7 deduplicate strings sooner at load and compile
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
2017-03-01 01:16:26 +00:00
nobu d8761cf251 Adjust indent [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57032 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-09 02:59:55 +00:00
shugo 1ac9b2ed5c Add a comment.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-12-05 23:37:25 +00:00
shugo 11f9b8c05c Don't insert an entry to loading_tbl if another thread succeed to load.
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
2016-12-05 11:10:05 +00:00
nobu d3cde81666 load.c: setup syntax error backtrace
* 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
2016-10-06 08:29:46 +00:00
nobu 24b37eb0a6 load.c: fix load/require context
* 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
2016-10-06 06:53:22 +00:00
ko1 9f60791a04 * vm_core.h: revisit the structure of frame, block and env.
[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
2016-07-28 11:02:30 +00:00
nobu 84f94652b0 use TH_JUMP_TAG
* 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
2016-05-05 03:22:20 +00:00
nobu e6c88132a5 load.c: fix r54521
* load.c (rb_f_load): do not convert the encoding twice.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-04-09 03:58:01 +00:00
nobu 56417d1f24 load.c: raise name before conversion
* 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
2016-04-09 01:03:15 +00:00
nobu d7935475fc remove rb_thread_t::parse_in_eval
* 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
2016-03-28 21:39:24 +00:00
nobu bc343b851d SyntaxError message at iseq compile
* 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
2016-03-19 05:46:20 +00:00
ko1 3dbb390180 * introduce new ISeq binary format serializer/de-serializer
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
2015-12-08 13:58:50 +00:00
normal a2e025a7d0 introduce rb_autoload_str to replace rb_autoload
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
2015-12-06 12:28:09 +00:00
nobu 9d64a54209 internal.h: RUBY_DTRACE_HOOK
* internal.h (RUBY_DTRACE_HOOK): extract from
  RUBY_DTRACE_CREATE_HOOK for other type hooks.

* gc.c (RUBY_DTRACE_GC_HOOK): ditto.

* parse.y (RUBY_DTRACE_PARSE_HOOK): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52399 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-10-31 01:02:29 +00:00
normal efef2c6308 load.c (features_index_add): avoid repeat calculation
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
2015-08-13 00:02:01 +00:00
normal 243ab2a23e load.c: match comment with variable (`e' => `ext') [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-08-12 23:43:41 +00:00
nobu 9a0f5286d7 load.c: use rb_load_internal0
* 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
2015-07-31 12:34:54 +00:00
nobu 2735af4daf load.c: stop separating exits at loading
* 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
2015-07-30 02:52:57 +00:00
nobu bcba951320 load.c: avoid segfault when 'throw' occurs in the middle of rb_load_file_str
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
2015-07-30 01:42:35 +00:00