Commit graph

16692 commits

Author SHA1 Message Date
Jeremy Evans
cd77e71bba [ruby/net-http] Remove ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE
This list is out of date.  At least OpenBSD since 2013 does not
allow one user to read the environment variables of a process
run by another user.

While we could try to keep the list updated, I think it's a bad
idea to not use the user/password from the environment, even if
another user on the system could read it.  If http_proxy exists
in the environment, and other users can read it, it doesn't
make it more secure for Ruby to ignore it.  You could argue that
it encourages poor security practices, but net/http should provide
mechanism, not policy.

Fixes [Bug #18908]

1e4585153d
2022-09-28 17:26:03 +09:00
Hiroshi SHIBATA
b58710e006
dbm and gdbm have been extracted gems. 2022-09-28 17:06:12 +09:00
Mike Dalessio
8f7f12ad64 [rubygems/rubygems] fix: Gem::Platform.match handles String argument properly
Previously 9eead86 introduced non-commutativity of platforms, and
later commit 1b9f7f50 changed the behavior of `Gem::Platform.match` to
ensure the callee of `#=~` was the gem platform.

However, when the platform argument is a String, then the callee and
argument of `#=~` are flipped (see docs for `String#=~`), which works
against the fix from 1b9f7f50.

Closes #5938

3b1fb562e8
2022-09-28 05:55:28 +09:00
Lars Kanis
9d56d9975d [ruby/timeout] Explicit add the timeout thread to default ThreadGroup
Otherwise the timeout thread would be added to the ThreadGroup of the thread that makes the first call to Timeout.timeout .

Fixes bug 19020: https://bugs.ruby-lang.org/issues/19020

Add a test case to make sure the common thread doesn't leak to another ThreadGroup

c4f1385c9a
2022-09-28 01:59:35 +09:00
Aaron Patterson
06abfa5be6
Revert this until we can figure out WB issues or remove shapes from GC
Revert "* expand tabs. [ci skip]"

This reverts commit 830b5b5c35.

Revert "This commit implements the Object Shapes technique in CRuby."

This reverts commit 9ddfd2ca00.
2022-09-26 16:10:11 -07:00
Jeremy Evans
b39690df3a Rename method name in keyword test from y to yo
Kernel#y is defined by psych/yaml, which causes occasional
nondeterministic problems with this test when doing parallel testing.
2022-09-27 04:00:40 +09:00
Jemma Issroff
9ddfd2ca00 This commit implements the Object Shapes technique in CRuby.
Object Shapes is used for accessing instance variables and representing the
"frozenness" of objects.  Object instances have a "shape" and the shape
represents some attributes of the object (currently which instance variables are
set and the "frozenness").  Shapes form a tree data structure, and when a new
instance variable is set on an object, that object "transitions" to a new shape
in the shape tree.  Each shape has an ID that is used for caching. The shape
structure is independent of class, so objects of different types can have the
same shape.

For example:

```ruby
class Foo
  def initialize
    # Starts with shape id 0
    @a = 1 # transitions to shape id 1
    @b = 1 # transitions to shape id 2
  end
end

class Bar
  def initialize
    # Starts with shape id 0
    @a = 1 # transitions to shape id 1
    @b = 1 # transitions to shape id 2
  end
end

foo = Foo.new # `foo` has shape id 2
bar = Bar.new # `bar` has shape id 2
```

Both `foo` and `bar` instances have the same shape because they both set
instance variables of the same name in the same order.

This technique can help to improve inline cache hits as well as generate more
efficient machine code in JIT compilers.

This commit also adds some methods for debugging shapes on objects.  See
`RubyVM::Shape` for more details.

For more context on Object Shapes, see [Feature: #18776]

Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
Co-Authored-By: Eileen M. Uchitelle <eileencodes@gmail.com>
Co-Authored-By: John Hawthorn <john@hawthorn.email>
2022-09-26 09:21:30 -07:00
Samuel Williams
025b8701c0
Add several new methods for getting and setting buffer contents. (#6434) 2022-09-26 18:06:12 +13:00
John Hawthorn
b361bdc200 [Bug #19021] Fix safe call w/ conditional assign
As of fbaac837cf, when we were performing
a safe call (`o&.x=`) with a conditional assign (`||= 1`) and discarding
the result the stack would end up in a bad state due to a missing pop.

This commit fixes that by adjusting the target label of the branchnil to
be before a pop in that case (as was previously done in the
non-conditional assignment case).
2022-09-25 20:44:54 -07:00
Yuichiro Kaneko
d89f8a0467 [ruby/rdoc] Fix ruby script in "test_parse_method_bracket" (https://github.com/ruby/rdoc/pull/927)
Because it's syntax error.

993f2532ff
2022-09-26 09:38:40 +09:00
Yusuke Endoh
a78c733cc3 Revert "Revert "error.c: Let Exception#inspect inspect its message""
This reverts commit b9f030954a.

[Bug #18170]
2022-09-23 16:40:59 +09:00
Otávio Schwanck dos Santos
4bdd8f2ddf [ruby/reline] use assert_nothing_raised
f08be5da09
2022-09-22 22:28:39 +09:00
Otávio Schwanck dos Santos
696e8914b7 [ruby/reline] PR changes
e8e8d81f47
2022-09-22 22:28:38 +09:00
Samuel Williams
9434a7333c Enable coverage for eval. 2022-09-22 22:19:12 +12:00
tompng
78cb638002 [ruby/irb] Update expected colorize result that were uncolored before
52446eb77f
2022-09-22 00:37:39 +09:00
tompng
9f68687879 [ruby/irb] Scan every single characters in IRB::Color.scan
d14e56a65d
2022-09-22 00:37:38 +09:00
Stan Lo
c21f820b49 [ruby/irb] Fix completion tests
eb1691f636
2022-09-21 22:59:45 +09:00
st0012
6325fc8854 [ruby/irb] Handle non-String $LOAD_PATH values more carefully
In addition to String values, $LOAD_PATH can also take objects that
respond_to the `to_path` method, like Pathname objects. So `irb` should
be able to handle those objects too.

And if $LOAD_PATH contains objects that can't be converted into String,
`irb` should simply ignore it.

b2f562176b
2022-09-21 22:24:27 +09:00
Hiroshi SHIBATA
c287deecb6 backup IRBRC environmental variable. It's used by test methods when it's defined. 2022-09-21 14:25:42 +09:00
Hiroshi SHIBATA
d6e84d97fe Fix the missing locale error 2022-09-21 14:25:42 +09:00
Nobuyoshi Nakada
55e540f7ab
Ignore EPERM which means already being process-leader 2022-09-20 11:12:11 +09:00
Nobuyoshi Nakada
1c9381283e Add another test for Process.daemon
Check for that the daemon process is detached, that means it is not a
child and not waitable.
2022-09-19 15:34:16 +09:00
Takashi Kokubun
1825d3673f
Skip test_wait on MinGW CI
This test has been unstable, and it seems like we're not interested in
fixing that for MinGW.
4965373284
2022-09-17 22:08:36 +09:00
Jeremy Evans
b07db96744 [ruby/irb] Support --noscript option to not use first non-option argument as script
Also add --script option to turn the option back on.

Previously there wasn't a way to get an interactive IRB session
and access arguments provided on the command line.

Additionally, handle `-` as script as stdin. In Unix-like tools, `-`
means to take standard input instead of a file.  This doesn't
result in exactly the same output for:

```
echo 'p ARGV' > args.rb; irb args.rb a b c
```

and

```
echo 'p ARGV' | irb - a b c
```

Due to how irb handles whether stdin is a tty.

However, this change allows use of `-` as a argument, instead of
giving an unrecognized switch error. This required some small
changes to context.rb (to handle `-` as standard input) and
input-method.rb (to have FileInputMethod accept IO arguments in
addition to strings).

Implements [Feature #15371]

4192683ba2
2022-09-17 02:25:26 +09:00
Takashi Kokubun
6ad6994457
Omit a DRb test on MinGW
This test seems to leak a thread and let TestIOWait fail:
4949517274

DRb almost never seemed to stably work on MinGW. I don't think we intend
to fix it either. We should just omit DRb tests when they fail on MinGW.
2022-09-16 17:05:59 +09:00
Kevin Newton
68a5b0f086 [rubygems/rubygems] Mask the file mode when extracting files
When extracting files from the tarball, a mode is retrieved from
the header. Occasionally you'll encounter a gem that was packaged
on a system whose permission bits result in a value that is larger
than the value that File.chmod will allow (anything >= 2^16). In
that case the extraction fails with a RangeError, which is pretty
esoteric.

If you extract the tarball with the tar and gunzip utilities, the
file permissions end up being just the bottom 16 bits masked off
from the original value. I've mirrored that behavior here. Per the
tar spec:

> Modes which are not supported by the operating system restoring
> files from the archive will be ignored.

I think that basically means what I've done here.

---

This commit also changes the behavior very slightly with regard to
when the chmod is called. Previously it was called while the file
descriptor was still open, but after the write call.

When write flushes, the file permissions are changed to the mode
value from the File.open call, undoing the changes made by
FileUtils.chmod. CRuby appears to flush the buffer after the
chmod call, whereas TruffleRuby flushes before the chmod call.
So the file permissions can change depending on implementation.
Both implementations end up getting the correct file permissions
for the bottom 9 bits (user, group, world), but differ with
regard to the sticky bit in the next 3.

To get consistent behavior, this commit changes it to close the
file descriptor before attempting to chmod anything, which makes
it consistent because the write flushes in both cases.

22ce076e99
2022-09-15 14:49:20 +09:00
Nobuyoshi Nakada
752ae81ed1 [ruby/irb] Refine assertion for failures
fd047512b3
2022-09-15 08:25:53 +09:00
Nobuyoshi Nakada
ae2e8d364f [ruby/irb] Dir.mktmpdir creates a directory including the process ID
a15f68ffdb
2022-09-15 08:25:52 +09:00
Jeremy Evans
9299db49f5 [ruby/irb] Fix history file saving with concurrent irb sessions when history file doesn't exist
If history file didn't exist when irb was started, @loaded_history_mtime
would be nil.  However, if the history file didn't exist before, but it
exists when saving history, that means the history file was modified,
and we should handle it the same way as we handle the other case where
the history file was modified.

Fixes #388

8d277aafcb
2022-09-14 10:15:45 +09:00
Benoit Daloze
6525b6f760 Remove get_actual_encoding() and the dynamic endian detection for dummy UTF-16/UTF-32
* And simplify callers of get_actual_encoding().
* See [Feature #18949].
* See https://github.com/ruby/ruby/pull/6322#issuecomment-1242758474
2022-09-12 14:02:34 +02:00
Jeremy Bopp
684353fc03
[Win32] Negative length IO#sysread
Raise `ArgumentError` in `IO#sysread` on Windows when given a negative
length.

Fixes [Bug #18880]
2022-09-11 23:08:14 +09:00
Takashi Kokubun
106744107b
[ruby/fiddle] Fix PACK_MAP for unsigned types (https://github.com/ruby/fiddle/pull/110)
4a71246645
2022-09-11 15:30:49 +09:00
Benoit Daloze
14bcf69c9c Deprecate Encoding#replicate
* See [Feature #18949].
2022-09-10 19:02:15 +02:00
Benoit Daloze
92b907d12d Enable deprecation warnings for test-all
* So deprecated methods/constants/functions are dealt with early,
  instead of many tests breaking suddenly when removing a deprecated
  method/constant/function.
* Follows https://bugs.ruby-lang.org/issues/17591
2022-09-10 13:14:18 +02:00
David Rodríguez
b350053ae4 [rubygems/rubygems] Fix resolution on non-musl platforms
Gems without specific platform were being preferred over matching
platform specific gems.

37b95b9159
2022-09-09 19:38:52 +09:00
Kazuki Tsujimoto
db0e0dad11
Fix unexpected "duplicated key name" error in paren-less one line pattern matching
[Bug #18990]
2022-09-09 14:00:27 +09:00
David Rodríguez
24fd2f73d0 Resync Bundler & RubyGems 2022-09-08 11:25:03 +09:00
Nobuyoshi Nakada
e6b47f2fb0
Now Psych uses the proleptic Gregorian calendar 2022-09-07 10:37:01 +09:00
Nobuyoshi Nakada
cbdde8e0c5 [ruby/psych] Dump Date/DateTime as proleptic Gregorian date as well as Time
Fix ruby/psych#572

92304269bc
2022-09-07 09:44:14 +09:00
Hiroshi SHIBATA
bfa6d0f6d7
fixup 8cd6f2a087
we should handle ensure block when omit this test
2022-09-07 09:41:28 +09:00
Antonio Paulino
4c1f6750f2 [rubygems/rubygems] Fix: Gem info bug with version flag
e4cee1f975
2022-09-07 06:18:58 +09:00
Hiroshi SHIBATA
8cd6f2a087
omit random failure tests with FreeBSD
20220906T043002Z.fail.html.gz
  20220905T103002Z.fail.html.gz
2022-09-06 16:27:12 +09:00
Takashi Kokubun
f4dbfa0f04
Skip test_redefinition_mismatch on trunk-mjit for now
Investigating:
http://ci.rvm.jp/logfiles/brlog.trunk-mjit.20220906-025646
which is not immediately reproducible on my laptop.
2022-09-06 15:40:13 +09:00
Takashi Kokubun
915cbdb226
Stop testing MJIT on s390x
It didn't work either.
20220905T080003Z.fail.html.gz
2022-09-05 02:02:17 -07:00
Hiroshi SHIBATA
3eca1e438d Merge 16c3535413 2022-09-05 14:37:12 +09:00
Nobuyoshi Nakada
b5cf356447 Consider Complex from Complex cases
The assertions that "an argument of a Complex constructor must not be
a Complex" may not hold for some Numeric objects.
2022-09-02 14:33:23 +09:00
Nobuyoshi Nakada
9212d96307 [Bug #18937] Coerce non-real non-Numeric into Complex at comparisons 2022-09-02 14:33:23 +09:00
John Hawthorn
679ef34586 New constant caching insn: opt_getconstant_path
Previously YARV bytecode implemented constant caching by having a pair
of instructions, opt_getinlinecache and opt_setinlinecache, wrapping a
series of getconstant calls (with putobject providing supporting
arguments).

This commit replaces that pattern with a new instruction,
opt_getconstant_path, handling both getting/setting the inline cache and
fetching the constant on a cache miss.

This is implemented by storing the full constant path as a
null-terminated array of IDs inside of the IC structure. idNULL is used
to signal an absolute constant reference.

    $ ./miniruby --dump=insns -e '::Foo::Bar::Baz'
    == disasm: #<ISeq:<main>@-e:1 (1,0)-(1,13)> (catch: FALSE)
    0000 opt_getconstant_path                   <ic:0 ::Foo::Bar::Baz>      (   1)[Li]
    0002 leave

The motivation for this is that we had increasingly found the need to
disassemble the instructions between the opt_getinlinecache and
opt_setinlinecache in order to determine the constant we are fetching,
or otherwise store metadata.

This disassembly was done:
* In opt_setinlinecache, to register the IC against the constant names
  it is using for granular invalidation.
* In rb_iseq_free, to unregister the IC from the invalidation table.
* In YJIT to find the position of a opt_getinlinecache instruction to
  invalidate it when the cache is populated
* In YJIT to register the constant names being used for invalidation.

With this change we no longe need disassemly for these (in fact
rb_iseq_each is now unused), as the list of constant names being
referenced is held in the IC. This should also make it possible to make
more optimizations in the future.

This may also reduce the size of iseqs, as previously each segment
required 32 bytes (on 64-bit platforms) for each constant segment. This
implementation only stores one ID per-segment.

There should be no significant performance change between this and the
previous implementation. Previously opt_getinlinecache was a "leaf"
instruction, but it included a jump (almost always to a separate cache
line). Now opt_getconstant_path is a non-leaf (it may
raise/autoload/call const_missing) but it does not jump. These seem to
even out.
2022-09-01 15:20:49 -07:00
Imir Kiyamov
f67ab7f30c [ruby/did_you_mean] Fixed correction duplicates in VariableNameChecker
c3fc412f6f
2022-09-01 19:47:39 +09:00
Nobuyoshi Nakada
59e8569cf9 [ruby/reline] Support dumb terminal
The "dumb" terminal is considered only on MSys tty now.  However, the
`TERM` feature has been used on many Unix-like systems for decades,
not MSys specific.

53fd51ab62
2022-09-01 16:36:16 +09:00