Skip to content

Commit 6e40a2a

Browse files
committed
[GR-18163] Caching Process.pid in constant
PullRequest: truffleruby/3663
2 parents c0aa65a + 0ca8d54 commit 6e40a2a

File tree

4 files changed

+4
-3
lines changed

4 files changed

+4
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Performance:
8585

8686
* Marking of native structures wrapped in objects is now done on C call exit to reduce memory overhead (@aardvark179).
8787
* Splitting (copying) of call targets has been optimized by implementing `cloneUninitialized()` (@andrykonchin, @eregon).
88+
* `Process.pid` is now cached per process like `$$` (#2882, @horakivo)
8889

8990
Changes:
9091

lib/gems/gems/rbs-2.7.0/core/global_variables.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ $!: Exception | nil
55
$": Array[String]
66
77
# The process number of the Ruby running this script. Same as Process.pid.
8-
$$: Integer
8+
$$: Integer | nil
99
1010
# The string matched by the last successful match.
1111
$&: String | nil

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def p(*a)
8686
end
8787

8888
Truffle::Boot.delay do
89-
$$ = Process.pid if Truffle::POSIX::NATIVE
89+
$$ = Truffle::POSIX::NATIVE ? Truffle::POSIX.getpid : nil
9090

9191
ARGV.concat(Truffle::Boot.original_argv)
9292
end

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def getpgrp
343343
end
344344

345345
def pid
346-
Truffle::POSIX.getpid
346+
$$ or raise SecurityError, 'native access is not allowed'
347347
end
348348

349349
def ppid

0 commit comments

Comments
 (0)