Skip to content

Commit 5989bf5

Browse files
committed
[GR-15575] Initialize $0 to a String as RubyGems expects it to.
PullRequest: truffleruby/829
2 parents f08dd1a + 754db2b commit 5989bf5

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Bug fixes:
66
* Temporary variables are no longer visible in the debugger.
77
* Setting breakpoints on some lines has been fixed.
88
* The OpenSSL C extension is now always recompiled, fixing various bugs when using the extension (e.g., when using Bundler in TravisCI) (#1676, #1627, #1632).
9+
* Initialize `$0` when not run from the 'ruby' launcher, which is needed to `require` gems (#1653).
910

1011
Compatibility:
1112

src/main/java/org/truffleruby/core/CoreLibrary.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,10 @@ private void afterLoadCoreLibrary() {
849849
assert Layouts.CLASS.isClass(eagainWaitWritable);
850850

851851
findGlobalVariableStorage();
852+
853+
// Initialize $0 so it is set to a String as RubyGems expect, also when not run from the RubyLauncher
854+
DynamicObject dollarZeroValue = StringOperations.createString(context, StringOperations.encodeRope("-", USASCIIEncoding.INSTANCE, CodeRange.CR_7BIT));
855+
getContext().getCoreLibrary().getGlobalVariables().getStorage("$0").setValueInternal(dollarZeroValue);
852856
}
853857

854858
@TruffleBoundary

0 commit comments

Comments
 (0)