Commit graph

1505 commits

Author SHA1 Message Date
nagachika
b72deb7ca1 merge revision(s) 58918788ab: [Backport #20342]
[Bug #20342] Consider wrapped load in `main` methods
2024-07-15 17:56:01 +09:00
nagachika
5fc9825ccf merge revision(s) 02a7e12b80: [Backport #19593]
Ensure throw data is not set as cause

	[Bug #19593]

	rb_ec_setup_exception did not check if errinfo is a throw_data. This can
	cause crashes in code since it is assumed that id_cause is an object.

	We saw a crash in show_cause due to id_cause of errinfo being a
	throw_data. It crashes on rb_obj_is_kind_of since it cannot be called on
	T_IMEMO objects.

	Unfortunately, we couldn't find a reproduction script, however we
	debugged the core dump and rb_ec_setup_exception is the only place where
	id_cause is assigned from errinfo without checking if it is a
	throw_data.

	```
	0x0000556c5708e6dd in sigsegv (sig=11, info=0x7f301befa3f0, ctx=0x7f301befa2c0) at signal.c:964
	0x00007f301d046420 in <signal handler called> () at /lib/x86_64-linux-gnu/libpthread.so.0
	class_search_class_ancestor (c=139844586301760, cl=<optimized out>) at object.c:810
	rb_obj_is_kind_of (obj=obj@entry=139839221734880, c=139844586301760) at object.c:861
	0x0000556c56f2f00f in show_cause
	    (errinfo=errinfo@entry=139838840645160, str=str@entry=139839221730520, opt=139839221730480, highlight=0, reverse=reverse@entry=0, backtrace_limit=backtrace_limit@entry=-1, shown_causes=0x7ffe9d1a2d68) at ./include/ruby/internal/special_consts.h:175
	```

	Co-Authored-By: Jean Boussier <byroot@ruby-lang.org>
	---
	 eval.c | 4 ++++
	 1 file changed, 4 insertions(+)
2023-07-17 16:09:00 +09:00
Nobuyoshi Nakada
2e7e153a2a [Bug #19242] Prohibit circular causes to be loaded 2022-12-20 14:12:38 +09:00
Nobuyoshi Nakada
45bad8c7b8 The mode flags may be clobbered by tag jumps 2022-11-25 15:50:06 +09:00
Nobuyoshi Nakada
5b959e238e [Bug #19016] re-order error handling at cleanup
Build and store the error message with `#detailed_message` before
terminating all Ractors, then show the message later.
2022-11-22 00:33:19 +09:00
Nobuyoshi Nakada
701dfe4eb7
[Bug #19016] Handle syntax error in main script like other errors
So that `SyntaxError#detailed_message` will be used also in the case
exiting by such syntax error.
2022-11-20 20:00:40 +09:00
Nobuyoshi Nakada
12b7b85227
Use enum ruby_tag_type over int 2022-11-20 20:00:40 +09:00
S-H-GAMELINKS
1f4f6c9832 Using UNDEF_P macro 2022-11-16 18:58:33 +09:00
Takashi Kokubun
d9d9005a3a
MJIT: Stop using the VM barrier for jit_cont
This solves multiple problems.

First, RB_VM_LOCK_ENTER/LEAVE is a barrier. We could at least use the
_NO_BARRIER variant.

Second, this doesn't need to interfere with GC or other GVL users when
multiple Ractors are used. This needs to be used in very few places, so
the benefit of fine-grained locking would outweigh its small maintenance
cost.

Third, it fixes a crash for YJIT. Because YJIT is never disabled until a
process exits unlike MJIT that finishes earlier, we could call jit_cont_free
when EC no longer exists, which crashes RB_VM_LOCK_ENTER.
2022-10-19 17:20:48 -07:00
Takashi Kokubun
e7c71c6c92
Make mjit_cont sharable with YJIT (#6556)
* Make mjit_cont sharable with YJIT

* Update dependencies

* Update YJIT binding
2022-10-17 09:27:59 -07:00
Chris Salzberg
82ac4a2399 Support using at toplevel in wrapped script
Allow refinements to be used at the toplevel within a script that is
loaded under a module.

Fixes [Bug #18960]
2022-09-24 09:41:15 +09:00
Takashi Kokubun
5b21e94beb Expand tabs [ci skip]
[Misc #18891]
2022-07-21 09:42:04 -07:00
Jemma Issroff
80ad0e751f Remove unnecessary module flag, add module assertions to other module flags 2022-05-23 11:04:34 -07:00
Peter Zhu
5f10bd634f Add ISEQ_BODY macro
Use ISEQ_BODY macro to get the rb_iseq_constant_body of the ISeq. Using
this macro will make it easier for us to change the allocation strategy
of rb_iseq_constant_body when using Variable Width Allocation.
2022-03-24 10:03:51 -04:00
Nobuyoshi Nakada
4fdb10e65e
A positional Hash is not keyword arguments [Bug #18632] 2022-03-18 00:35:02 +09:00
Jeremy Evans
791343b5bb Remove Refinement#{extend_object,append_features,prepend_features}
Also make include, prepend, and extend raise a TypeError if one
of the modules is a refinement.

Implements [Feature #18270]
2022-01-05 10:59:03 -08:00
Shugo Maeda
54198c7b97
Add Module#refinements and Refinement#refined_class [Feature #12737] 2022-01-05 17:47:29 +09:00
Shugo Maeda
21ee5341f8
Add Module.used_refinements 2022-01-05 16:58:23 +09:00
Nobuyoshi Nakada
69f03c864e
Remove Refinement#include and Refinement#prepend 2021-12-26 23:28:54 +09:00
zverok
34deea3b42 Add docs for Refinement class 2021-12-24 10:31:04 +09:00
Shugo Maeda
c2192cb985
Clarify the error message when trying to import C methods [Bug #18385] 2021-12-06 09:40:54 +09:00
Shugo Maeda
6606597109
Deprecate include/prepend in refinements and add Refinement#import_methods instead
Refinement#import_methods imports methods from modules.
Unlike Module#include, it copies methods and adds them into the refinement,
so the refinement is activated in the imported methods.

[Bug #17429] [ruby-core:101639]
2021-10-21 16:31:54 +09:00
Nobuyoshi Nakada
65285bf673 Consider modified modules initialized [Bug #18185] 2021-09-24 08:29:00 +09:00
卜部昌平
3fa875f88b include/ruby/internal/intern/eval.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]
2021-09-10 20:00:06 +09:00
卜部昌平
26b7efc51c include/ruby/internal/intern/proc.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]
2021-09-10 20:00:06 +09:00
卜部昌平
1b6245ccdc include/ruby/internal/error.h: add doxygen
Must not be a bad idea to improve documents.
2021-09-10 20:00:06 +09:00
卜部昌平
f83b14af24 include/ruby/internal/interpreter.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]

In fact many functions declared in the header file are already
documented more or less.  They were just copy & pasted, with applying
some style updates.
2021-09-10 20:00:06 +09:00
卜部昌平
03fd22a170 include/ruby/internal/iterator.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]
2021-09-10 20:00:06 +09:00
卜部昌平
9ba9dbf168 include/ruby/internal/module.h: add doxygen
Must not be a bad idea to improve documents. [ci skip]

In fact many functions declared in the header file are already
documented more or less.  They were just copy & pasted, with applying
some style updates.
2021-09-10 20:00:06 +09:00
Nobuyoshi Nakada
28d03ee776 Remove root_jmpbuf in rb_thread_struct
It has not been used since 1b82c877df.
2021-08-10 19:08:38 +09:00
Nobuyoshi Nakada
6736323194 Suppress a clobbered warning 2021-08-09 11:21:56 +09:00
Nobuyoshi Nakada
a14671a6b6 Suppress warnings in C++2a
* bitwise operation between different enumeration types
  ('ruby_value_type' and 'ruby_fl_type') is deprecated
  [-Wdeprecated-enum-enum-conversion]

* volatile-qualified parameter type 'volatile int' is deprecated
  [-Wdeprecated-volatile]
2021-08-09 11:21:56 +09:00
Samuel Williams
42130a64f0
Replace copy coroutine with pthread implementation. 2021-07-01 11:23:03 +12:00
S.H
be343946c7
Refactor rb_obj_call_init and rb_obj_call_init_kw (#4351) 2021-04-04 11:34:51 +09:00
S.H
89fa5b1348
Add rb_exc_exception function
`rb_exc_raise` and `rb_fatal` func have similar code(in `eval.c`).
I think that better cut out and replace these code like `rb_exc_exception`
function.
2021-03-27 16:39:01 +09:00
Alan Wu
b9908ea666 Make a few functions static 2021-03-18 15:03:14 -04:00
Samuel Williams
5f69a7f604
Expose scheduler as public interface & bug fixes. (#3945)
* Rename `rb_scheduler` to `rb_fiber_scheduler`.

* Use public interface if available.

* Use `rb_check_funcall` where possible.

* Don't use `unblock` unless the fiber was non-blocking.
2021-02-09 19:39:56 +13:00
Nobuyoshi Nakada
97cf290063 Copy va_list of exception classes
The list is reused when an exception raised again after retrying
in the rescue procedure.
2021-02-09 12:59:06 +09:00
Nobuyoshi Nakada
a6f5f3cccd Also eclass loop can raise in rb_obj_is_kind_of 2021-02-09 12:59:06 +09:00
Nobuyoshi Nakada
0d89aedb73
Assign TAG_NONE to ruby_tag_type instead of 0 2021-02-09 00:44:37 +09:00
Marcus Stollsteimer
3108ad7bf3 [DOC] Fix grammar: "is same as" -> "is the same as" 2021-01-05 15:13:53 +01:00
Takashi Kokubun
01f38693aa
Remove obsoleted internal/mjit.h inclusion
🙇
2020-11-22 20:28:34 -08:00
Koichi Sasada
5e3259ea74 fix public interface
To make some kind of Ractor related extensions, some functions
should be exposed.

* include/ruby/thread_native.h
  * rb_native_mutex_*
  * rb_native_cond_*
* include/ruby/ractor.h
  * RB_OBJ_SHAREABLE_P(obj)
  * rb_ractor_shareable_p(obj)
  * rb_ractor_std*()
  * rb_cRactor

and rm ractor_pub.h
and rename srcdir/ractor.h to srcdir/ractor_core.h
    (to avoid conflict with include/ruby/ractor.h)
2020-11-18 03:52:41 +09:00
Samuel Williams
a08ee8330d Rename to Fiber#set_scheduler. 2020-11-07 23:39:50 +13:00
Koichi Sasada
99310e3eb5 Some global variables can be accessed from ractors
Some global variables should be used from non-main Ractors.
[Bug #17268]

```ruby
     # ractor-local (derived from created ractor): debug
     '$DEBUG' => $DEBUG,
     '$-d' => $-d,

     # ractor-local (derived from created ractor): verbose
     '$VERBOSE' => $VERBOSE,
     '$-w' => $-w,
     '$-W' => $-W,
     '$-v' => $-v,

     # process-local (readonly): other commandline parameters
     '$-p' => $-p,
     '$-l' => $-l,
     '$-a' => $-a,

     # process-local (readonly): getpid
     '$$'  => $$,

     # thread local: process result
     '$?'  => $?,

     # scope local: match
     '$~'  => $~.inspect,
     '$&'  => $&,
     '$`'  => $`,
     '$\''  => $',
     '$+'  => $+,
     '$1'  => $1,

     # scope local: last line
     '$_' => $_,

     # scope local: last backtrace
     '$@' => $@,
     '$!' => $!,

     # ractor local: stdin, out, err
     '$stdin'  => $stdin.inspect,
     '$stdout' => $stdout.inspect,
     '$stderr' => $stderr.inspect,
```
2020-10-20 15:38:54 +09:00
Samuel Williams
a88fe61a3e Rework rb_ec_scheduler_finalize to ensure exceptions are printed. 2020-10-01 16:56:05 +13:00
Samuel Williams
388281c5c9 Fix order of operations during rb_ec_finalize. 2020-09-30 16:34:38 +13:00
Samuel Williams
501fff14c7 When setting current thread scheduler to nil, invoke #close. 2020-09-21 09:51:33 +12:00
Koichi Sasada
79df14c04b Introduce Ractor mechanism for parallel execution
This commit introduces Ractor mechanism to run Ruby program in
parallel. See doc/ractor.md for more details about Ractor.
See ticket [Feature #17100] to see the implementation details
and discussions.

[Feature #17100]

This commit does not complete the implementation. You can find
many bugs on using Ractor. Also the specification will be changed
so that this feature is experimental. You will see a warning when
you make the first Ractor with `Ractor.new`.

I hope this feature can help programmers from thread-safety issues.
2020-09-03 21:11:06 +09:00
Alan Wu
264e4cd04f Remove write barrier exemption for T_ICLASS
Before this commit, iclasses were "shady", or not protected by write
barriers. Because of that, the GC needs to spend more time marking these
objects than otherwise.

Applications that make heavy use of modules should see reduction in GC
time as they have a significant number of live iclasses on the heap.

 - Put logic for iclass method table ownership into a function
 - Remove calls to WB_UNPROTECT and insert write barriers for iclasses

This commit relies on the following invariant: for any non oirigin
iclass `I`, `RCLASS_M_TBL(I) == RCLASS_M_TBL(RBasic(I)->klass)`. This
invariant did not hold prior to 98286e9 for classes and modules that
have prepended modules.

[Feature #16984]
2020-08-17 17:17:47 -04:00