Skip to content

Commit 25b684e

Browse files
committed
[GR-17818] Make Array#swap private so it does not leak into keys.
PullRequest: truffleruby/1169
2 parents 32791da + 438653f commit 25b684e

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Bug fixes:
3232
* Fixed `Module#to_s` and `Module#inspect` to not return an extra `#<Class:` for singleton classes.
3333
* Arrays backed by native storage now allocate the correct amount of memory (#1828).
3434
* Fixed issue in `ConditionVariable#wait` that could lose a `ConditionVariable#signal`.
35+
* Do not leak TruffleRuby specific method Array#swap (#1816)
3536

3637
Compatibility:
3738

src/main/ruby/truffleruby/core/array.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,7 +1105,7 @@ def sample_many(count, rng)
11051105
result = Array.new(self)
11061106

11071107
count.times do |c|
1108-
result.swap c, rng.rand(size)
1108+
Truffle.privately { result.swap c, rng.rand(size) }
11091109
end
11101110

11111111
count == size ? result : result[0, count]
@@ -1670,10 +1670,11 @@ def sort!(&block)
16701670
TrufflePrimitive.steal_array_storage(self, sort(&block))
16711671
end
16721672

1673+
private
1674+
16731675
def swap(a, b)
16741676
temp = at(a)
16751677
self[a] = at(b)
16761678
self[b] = temp
16771679
end
1678-
protected :swap
16791680
end

src/main/ruby/truffleruby/core/truffle/interop.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def self.object_keys(object, internal)
4848
# FIXME (pitr-ch 11-May-2019): remove the branch
4949
keys = []
5050
else
51+
# TODO (pitr-ch 28-Nov-2019): make sure protected methods are not listed unless internal
5152
keys = []
5253
object.methods.each do |method|
5354
keys << method.to_s if Truffle::Type.object_respond_to? object, method, true

0 commit comments

Comments
 (0)