aboutsummaryrefslogtreecommitdiffstats
path: root/thread.c
Commit message (Collapse)AuthorAgeFilesLines
* thread.c: avoid needless read after select|ppollEric Wong2019-12-161-4/+9
| | | | | We do not need to issue pipe|eventfd read(2) syscall unless select, ppoll|poll declares the FD needs reading.
* Make Thread#to_s consistent with Method and Proc to_sJean byroot Boussier2019-12-111-1/+1
|
* move an interrupt point.Koichi Sasada2019-12-051-1/+1
| | | | | `args_ptr` can be corrupted by interrupt handlers. Pointed by nagachika <https://ruby-trunk-changes.hatenablog.com/entry/ruby_trunk_changes_20191204>.
* Check interrupts before starting threadJeremy Evans2019-12-031-0/+1
| | | | | | Fixes a hang when Thread.new calls Thread.new in a loop. Fixes [Bug #13688]
* Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans2019-11-181-1/+0
| | | | | | This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby.
* Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans2019-11-181-1/+2
| | | | | | | | | | | | | | | | | 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.
* Use ident hash for top-level recursion checkJohn Hawthorn2019-11-041-18/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | We track recursion in order to not infinite loop in ==, inspect, and similar methods by keeping a thread-local 1 or 2 level hash. This allows us to track when we have seen the same object (ex. using inspect) or same pair of objects (ex. using ==) in this stack before and to treat that differently. Previously both levels of this Hash used the object's memory_id as a key (using object_id would be slow and wasteful). Unfortunately, prettyprint (pp.rb) uses this thread local variable to "pretend" to be inspect and inherit its same recursion behaviour. This commit changes the top-level hash to be an identity hash and to use objects as keys instead of their object_ids. I'd like to have also converted the 2nd level hash to an ident hash, but it would have prevented an optimization which avoids allocating a 2nd level hash for only a single element, which we want to keep because it's by far the most common case. So the new format of this hash is: { object => true } (not paired) { lhs_object => rhs_object_memory_id } (paired, single object) { lhs_object => { rhs_object_memory_id => true, ... } } (paired, many objects) We must also update pp.rb to match this (using identity hashes).
* Prefer st_is_member over st_lookup with 0Ben Woosley2019-10-091-1/+1
| | | | The st_is_member DEFINE has simpler semantics, for more readable code.
* avoid overflow in integer multiplication卜部昌平2019-10-091-1/+3
| | | | | | | This changeset basically replaces `ruby_xmalloc(x * y)` into `ruby_xmalloc2(x, y)`. Some convenient functions are also provided for instance `rb_xmalloc_mul_add(x, y, z)` which allocates x * y + z byes.
* Add rb_adjust_argv_kw_splat to internal.hJeremy Evans2019-09-261-2/+0
| | | | | We are calling this in a few other files, it is better to have it in a header than adding prototypes to the other files.
* Check the argument sizeNobuyoshi Nakada2019-09-271-0/+1
| | | | | Ensure that argument array size does not overflow as `int`, before cast in thread_do_start after new thread created.
* Fix shorten-64-to-32 compile warnings/errorsJeremy Evans2019-09-261-1/+1
|
* Fix keyword argument separation issues in Thread.newJeremy Evans2019-09-261-3/+10
|
* Adjusted directives order of a function [ci skip]Nobuyoshi Nakada2019-09-231-1/+3
|
* Lazy init thread local storageLourens Naudé2019-09-231-6/+24
|
* Only set RB_PASS_CALLED_KEYWORDS in C functions called directly from RubyJeremy Evans2019-09-141-1/+1
| | | | | | | | | | | It is not safe to set this in C functions that can be called from other C functions, as in the non argument-delegation case, you can end up calling a Ruby method with a flag indicating keywords are set without passing keywords. Introduce some new *_kw functions that take a kw_splat flag and use these functions to set RB_PASS_CALLED_KEYWORDS in places where we know we are delegating methods (e.g. Class#new, Method#call)
* Add VM_NO_KEYWORDSJeremy Evans2019-09-051-1/+1
| | | | | I think this is easier to read than using literal 0 with comments in every case where it is used.
* Propagate kw_splat informationYusuke Endoh2019-09-051-1/+1
| | | | | | | The kw_splat flag is whether the original call passes keyword or not. Some types of methods (e.g., bmethod and sym_proc) drops the information. This change tries to propagate the flag to the final callee, as far as I can.
* drop-in type check for rb_define_singleton_method卜部昌平2019-08-291-30/+42
| | | | | | We can check the function pointer passed to rb_define_singleton_method like how we do so in rb_define_method. Doing so revealed many arity mismatches.
* rb_uninterruptible now free from ANYARGS卜部昌平2019-08-271-1/+1
| | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This function has only one call site so adding appropriate prototype is trivial.
* rb_thread_create now free from ANYARGS卜部昌平2019-08-271-2/+2
| | | | | | After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from rb_thread_create, which seems very safe to do.
* unsigned int should have enough bits for rb_thread_shield_waitingNobuyoshi Nakada2019-08-191-5/+11
|
* gc.h is required on mswin build.Koichi Sasada2019-08-091-0/+1
| | | | thread.c requires gc.h on mswin build. Sorry.
* add rp() and bp() in internal.h.Koichi Sasada2019-08-091-1/+0
| | | | | | | | debug utility macro rp() (rp_m()) and bp() are introduced. * rp(obj) shows obj information w/o any side-effect to STDERR. * rp_m(m, obj) is similar to rp(obj), but show m before. * bp() is alias of ruby_debug_breakpoint(), which is registered as a breakpoint in run.gdb (used by `make gdb` or make gdb-ruby`).
* Remove `rb_vm_push_frame` as it is no longer used.Samuel Williams2019-07-191-11/+0
|
* check return value of blocking_region_begin().Koichi Sasada2019-07-151-1/+2
| | | | | blocking_region_begin() can return FALSE if it fails to acquire GVL, so check it.
* thread.c (rb_thread_shield_waiting_{inc,dec}): prefer long to intYusuke Endoh2019-07-151-4/+4
| | | | | | `(unsigned int)(THREAD_SHIELD_WAITING_MASK>>THREAD_SHIELD_WAITING_SHIFT)` is 0xffffffff, and w > 0xffffffff is always true. Coverity Scan pointed out this issue.
* [DOC] Re-apply r11000, 41256fd43275c8bf66460510da7ab958a802e2a2Nobuyoshi Nakada2019-06-281-8/+6
| | | | | | | * eval.c (rb_thread_kill): fix Thread#kill docs, which returns the thread object in all cases. From: why the lucky stiff <why@ruby-lang.org>
* Transition root fiber into state FIBER_TERMINATED.Samuel Williams2019-06-201-2/+3
| | | | | | | During fork, it's possible that threads with root fibers are terminated, but fiber state is not updated. `fiber_verify` will subsequently fail. We forcefully enter the FIBER_TERMINATED state when terminating the root fiber.
* Ensure that vm_stack is cleared in `thread_cleanup_func_before_exec`.Samuel Williams2019-06-201-4/+12
| | | | | | | | If `vm_stack` is left dangling in a forked process, the gc attempts to scan it, but it is invalid and will cause a segfault. Therefore, we clear it before forking. In order to simplify this, `rb_ec_clear_vm_stack` was introduced.
* Revert failed attempt at fixing invalid usage of vm_stack.Samuel Williams2019-06-201-13/+4
|
* Don't clear cfp, it causes problems.Samuel Williams2019-06-201-5/+2
|
* Skip `rb_ec_clear_vm_stack` for now.Samuel Williams2019-06-201-2/+5
|
* * remove trailing spaces.git2019-06-201-1/+1
|
* Ensure `vm_stack` is cleared after fork.Samuel Williams2019-06-201-0/+4
|
* Fix typo in VM_ASSERT.Samuel Williams2019-06-201-2/+2
|
* Extra assertions around thread.Samuel Williams2019-06-201-4/+9
|
* Don't change vm_stack/cfp without acquiring gvl first.Samuel Williams2019-06-201-1/+4
|
* Remove IA64 support.Samuel Williams2019-06-191-19/+3
|
* * remove trailing spaces, expand tabs.git2019-06-191-10/+10
|
* Use shared implementation of `rb_ec_initialize_vm_stack`.Samuel Williams2019-06-191-10/+1
|
* Update `stack_start` and `stack_maxsize` according to stack direction.Samuel Williams2019-06-191-2/+3
|
* Make sure `alloca` fast path is used (inline assembler).Samuel Williams2019-06-191-2/+6
|
* Track how stack was allocated for `cont_free`.Samuel Williams2019-06-191-1/+1
|
* Ensure execution context is cleared after thread is finished.Samuel Williams2019-06-191-1/+1
|
* Better handling of root fiber.Samuel Williams2019-06-191-13/+14
|
* Fix handling of vm_stack_size and avoid trying to deallocate it.Samuel Williams2019-06-191-11/+14
|
* Move vm stack init into thread.Samuel Williams2019-06-191-2/+26
|
* * expand tabs.git2019-05-271-2/+2
|
* Add FrozenError#receiverJeremy Evans2019-05-261-2/+2
| | | | | | | | | | | | | | | | | Similar to NameError#receiver, this returns the object on which the modification was attempted. This is useful as it can pinpoint exactly what is frozen. In many cases when a FrozenError is raised, you cannot determine from the context which object is frozen that you attempted to modify. Users of the current rb_error_frozen C function will have to switch to using rb_error_frozen_object or the new rb_frozen_error_raise in order to set the receiver of the FrozenError. To allow the receiver to be set from Ruby, support an optional second argument to FrozenError#initialize. Implements [Feature #15751]