Skip to content

Commit fb41bdc

Browse files
committed
merge changes I already made with ones I did again a day later
2 parents bbbe8c8 + 4e8f7e3 commit fb41bdc

File tree

8 files changed

+33
-32
lines changed

8 files changed

+33
-32
lines changed

core/src/main/java/org/jruby/MetaClass.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ private static void logSingleton(Ruby runtime, RubyClass superClass, RubyBasicOb
9090
}
9191

9292
@Override
93-
public final IRubyObject allocate() {
94-
throw typeError(getRuntime().getCurrentContext(), "can't create instance of virtual class");
93+
public final IRubyObject allocate(ThreadContext context) {
94+
throw typeError(context, "can't create instance of virtual class");
9595
}
9696

9797
@Override

core/src/main/java/org/jruby/Ruby.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4133,7 +4133,7 @@ public RaiseException newNameError(String message, IRubyObject recv, IRubyObject
41334133
*/
41344134
public RaiseException newNameError(String message, IRubyObject recv, IRubyObject name, boolean privateCall) {
41354135
IRubyObject msg = new RubyNameError.RubyNameErrorMessage(this, message, recv, name);
4136-
RubyException err = RubyNameError.newNameError(getNameError(), msg, name, privateCall);
4136+
RubyException err = RubyNameError.newNameError(getCurrentContext(), getNameError(), msg, name, privateCall);
41374137

41384138
return err.toThrowable();
41394139
}

core/src/main/java/org/jruby/RubyClass.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ public IRubyObject allocate(ThreadContext context) {
297297
}
298298
IRubyObject obj = allocator.allocate(context.runtime, this);
299299
if (getMetaClass(obj).getRealClass() != getRealClass()) throw typeError(context, "wrong instance allocation");
300-
301300
return obj;
302301
}
303302

core/src/main/java/org/jruby/RubyIO.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public RubyIO(Ruby runtime, ShellLauncher.POpenProcess process, IOOptions ioOpti
214214
// MRI: prep_stdio
215215
public static RubyIO prepStdio(Ruby runtime, InputStream f, Channel c, int fmode, RubyClass klass, String path) {
216216
OpenFile fptr;
217-
RubyIO io = prepIO(runtime, c, fmode | OpenFile.PREP | EncodingUtils.DEFAULT_TEXTMODE, klass, path);
217+
RubyIO io = prepIO(runtime.getCurrentContext(), c, fmode | OpenFile.PREP | EncodingUtils.DEFAULT_TEXTMODE, klass, path);
218218

219219
fptr = io.getOpenFileChecked();
220220

@@ -236,7 +236,7 @@ public static RubyIO prepStdio(Ruby runtime, InputStream f, Channel c, int fmode
236236
// MRI: prep_stdio
237237
public static RubyIO prepStdio(Ruby runtime, OutputStream f, Channel c, int fmode, RubyClass klass, String path) {
238238
OpenFile fptr;
239-
RubyIO io = prepIO(runtime, c, fmode | OpenFile.PREP | EncodingUtils.DEFAULT_TEXTMODE, klass, path);
239+
RubyIO io = prepIO(runtime.getCurrentContext(), c, fmode | OpenFile.PREP | EncodingUtils.DEFAULT_TEXTMODE, klass, path);
240240

241241
fptr = io.getOpenFileChecked();
242242

@@ -280,9 +280,9 @@ private static void prepStdioEcflags(OpenFile fptr, int fmode) {
280280
}
281281

282282
// MRI: prep_io
283-
private static RubyIO prepIO(Ruby runtime, Channel fd, int fmode, RubyClass klass, String path) {
283+
private static RubyIO prepIO(ThreadContext context, Channel fd, int fmode, RubyClass klass, String path) {
284284
OpenFile fp;
285-
RubyIO io = (RubyIO)klass.allocate(runtime.getCurrentContext());
285+
RubyIO io = (RubyIO)klass.allocate(context);
286286

287287
fp = io.MakeOpenFile();
288288
fp.setChannel(fd);
@@ -4222,10 +4222,9 @@ static RubyIO ioOpen(ThreadContext context, IRubyObject recv, RubyString filenam
42224222

42234223
// MRI: rb_io_open_generic
42244224
private static RubyIO ioOpenGeneric(ThreadContext context, IRubyObject recv, IRubyObject filename, int oflags, int fmode, IOEncodable convconfig, int perm) {
4225-
IRubyObject cmd;
4226-
42274225
if ((filename instanceof RubyString name) && name.isEmpty()) throw context.runtime.newErrnoENOENTError();
42284226

4227+
IRubyObject cmd;
42294228
if ((recv == ioClass(context)) && (cmd = PopenExecutor.checkPipeCommand(context, filename)) != context.nil) {
42304229
warningDeprecated(context, "IO process creation with a leading '|' is deprecated and will be removed in Ruby 4.0; use IO.popen instead");
42314230
if (PopenExecutor.nativePopenAvailable(context.runtime)) {

core/src/main/java/org/jruby/RubyNameError.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,20 @@ public IRubyObject to_str(ThreadContext context) {
150150
if (klass.isSingleton()) {
151151
separator = newString(context, "");
152152
if (object == runtime.getTopSelf()) {
153-
classTmp = newString(context, "main");
153+
className = newString(context, "main");
154154
} else {
155-
classTmp = object.anyToString();
155+
className = (RubyString) object.anyToString();
156156
}
157157
} else {
158158
separator = newString(context, "an instance of ");
159159
classTmp = klass.getRealClass();
160+
className = getNameOrInspect(context, classTmp);
160161
}
162+
} else {
163+
className = getNameOrInspect(context, classTmp);
161164
}
162165

163-
className = getNameOrInspect(context, classTmp);
166+
164167
}
165168

166169
RubyArray arr = RubyArray.newArray(runtime, this.name, description, separator, className);
@@ -239,21 +242,20 @@ protected RaiseException constructThrowable(String message) {
239242

240243
@JRubyMethod(name = "exception", meta = true)
241244
public static IRubyObject exception(ThreadContext context, IRubyObject recv) {
242-
return newNameError(recv, NULL_ARRAY);
245+
return newNameError(context, recv, NULL_ARRAY);
243246
}
244247

245248
@JRubyMethod(name = "exception", meta = true)
246249
public static RubyException exception(ThreadContext context, IRubyObject recv, IRubyObject message) {
247-
return newNameError(recv, new IRubyObject[] { message });
250+
return newNameError(context, recv, new IRubyObject[] { message });
248251
}
249252

250253
@JRubyMethod(name = "exception", meta = true)
251254
public static RubyException exception(ThreadContext context, IRubyObject recv, IRubyObject message, IRubyObject name) {
252-
return newNameError(recv, message, name, false);
255+
return newNameError(context, recv, message, name, false);
253256
}
254257

255-
private static RubyException newNameError(IRubyObject recv, IRubyObject[] args) {
256-
var context = recv.getRuntime().getCurrentContext();
258+
private static RubyException newNameError(ThreadContext context, IRubyObject recv, IRubyObject[] args) {
257259
final RubyClass klass = (RubyClass) recv;
258260
RubyException newError = (RubyException) klass.allocate(context);
259261

@@ -262,8 +264,7 @@ private static RubyException newNameError(IRubyObject recv, IRubyObject[] args)
262264
return newError;
263265
}
264266

265-
static RubyException newNameError(IRubyObject recv, IRubyObject message, IRubyObject name, boolean privateCall) {
266-
var context = recv.getRuntime().getCurrentContext();
267+
static RubyException newNameError(ThreadContext context, IRubyObject recv, IRubyObject message, IRubyObject name, boolean privateCall) {
267268
final RubyClass klass = (RubyClass) recv;
268269
RubyNameError newError = (RubyNameError) klass.allocate(context);
269270

core/src/main/java/org/jruby/RubyProcess.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ public void marshalTo(Object obj, RubyClass type,
185185

186186
@Override
187187
public Object unmarshalFrom(Ruby runtime, RubyClass type, UnmarshalStream input) throws IOException {
188-
RubyStatus status = (RubyStatus) input.entry(type.allocate(runtime.getCurrentContext()));
188+
var context = runtime.getCurrentContext();
189+
RubyStatus status = (RubyStatus) input.entry(type.allocate(context));
189190

190191
input.ivar(null, status, null);
191192

core/src/main/java/org/jruby/javasupport/Java.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,18 +1656,19 @@ private static RaiseException mapGeneratedProxyException(final Ruby runtime, fin
16561656
}
16571657

16581658
public static IRubyObject allocateProxy(Object javaObject, RubyClass clazz) {
1659-
final Ruby runtime = clazz.getRuntime();
1659+
var context = clazz.getRuntime().getCurrentContext();
16601660
// Arrays are never stored in OPC
1661-
if ( clazz.getSuperClass() == runtime.getJavaSupport().getArrayProxyClass() ) {
1662-
return new ArrayJavaProxy(runtime, clazz, javaObject, JavaUtil.getJavaConverter(javaObject.getClass().getComponentType()));
1661+
if ( clazz.getSuperClass() == context.runtime.getJavaSupport().getArrayProxyClass() ) {
1662+
return new ArrayJavaProxy(context.runtime, clazz, javaObject, JavaUtil.getJavaConverter(javaObject.getClass().getComponentType()));
16631663
}
16641664

1665-
final IRubyObject proxy = clazz.allocate(runtime.getCurrentContext());
1666-
if ( proxy instanceof JavaProxy ) {
1667-
((JavaProxy) proxy).setObject(javaObject);
1665+
final IRubyObject proxy = clazz.allocate(context);
1666+
1667+
if ( proxy instanceof JavaProxy jproxy) {
1668+
jproxy.setObject(javaObject);
16681669
} else {
16691670
// TODO (JavaObject transition) is this really necessary?
1670-
proxy.dataWrapStruct(new JavaProxy(runtime, clazz, javaObject));
1671+
proxy.dataWrapStruct(new JavaProxy(context.runtime, clazz, javaObject));
16711672
}
16721673
return proxy;
16731674
}

core/src/main/java/org/jruby/runtime/marshal/UnmarshalStream.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,12 @@ private IRubyObject objectForClass(ThreadContext context, boolean partial) throw
312312
private IRubyObject objectForData(ThreadContext context, MarshalState state, boolean partial,
313313
List<RubyModule> extendedModules) throws IOException {
314314
IRubyObject name = unique();
315-
RubyClass klass = getClassFromPath(runtime, name.asJavaString());
315+
RubyClass klass = getClassFromPath(context.runtime, name.asJavaString());
316316
IRubyObject obj = entry(klass.allocate(context));
317317
// FIXME: Missing T_DATA error check?
318318

319319
if (!obj.respondsTo("_load_data")) {
320-
throw typeError(context, str(runtime, name, " needs to have instance method _load_data"));
320+
throw typeError(context, str(context.runtime, name, " needs to have instance method _load_data"));
321321
}
322322

323323
IRubyObject arg = object0(context, state, partial, extendedModules);
@@ -327,7 +327,7 @@ private IRubyObject objectForData(ThreadContext context, MarshalState state, boo
327327

328328
private IRubyObject objectForObject(ThreadContext context, boolean partial) throws IOException {
329329
RubySymbol className = symbol();
330-
RubyClass type = getClassFromPath(runtime, className.idString());
330+
RubyClass type = getClassFromPath(context.runtime, className.idString());
331331

332332
IRubyObject obj = (IRubyObject) type.unmarshal(this);
333333
return leave(context, obj, partial);
@@ -719,7 +719,7 @@ private IRubyObject userUnmarshal(MarshalState state) throws IOException {
719719
// FIXME: This is missing a much more complicated set of logic in tracking old compatibility allocators. See MRI for more details
720720
private IRubyObject objectForUsrMarshal(ThreadContext context, MarshalState state, boolean partial,
721721
List<RubyModule> extendedModules) throws IOException {
722-
RubyClass classInstance = getClassFromPath(runtime, unique().asJavaString());
722+
RubyClass classInstance = getClassFromPath(context.runtime, unique().asJavaString());
723723
IRubyObject obj = classInstance.allocate(context);
724724

725725
if (extendedModules != null) appendExtendedModules(context, obj, extendedModules);

0 commit comments

Comments
 (0)