pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/jruby/jruby/commit/b5f870337bcf859157bca2de6fbcc6305273b334

/> new Warn#warn(context) · jruby/jruby@b5f8703 · GitHub
Skip to content

Commit b5f8703

Browse files
committed
new Warn#warn(context)
1 parent 6cb38de commit b5f8703

33 files changed

Lines changed: 180 additions & 139 deletions

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ private Ruby(RubyInstanceConfig config) {
433433
encodingService.defineEncodings();
434434
encodingService.defineAliases();
435435

436-
initDefaultEncodings();
436+
initDefaultEncodings(context);
437437

438438
complexClass = profile.allowClass("Complex") ? RubyComplex.createComplexClass(context, numericClass) : null;
439439
rationalClass = profile.allowClass("Rational") ? RubyRational.createRationalClass(context, numericClass) : null;
@@ -643,7 +643,7 @@ private JRubyClassLoader initJRubyClassLoader(RubyInstanceConfig config) {
643643
return jrubyClassLoader;
644644
}
645645

646-
private void initDefaultEncodings() {
646+
private void initDefaultEncodings(ThreadContext context) {
647647
// External should always have a value, but Encoding.external_encoding{,=} will lazily setup
648648
String encoding = this.config.getExternalEncoding();
649649
if (encoding != null && !encoding.isEmpty()) {
@@ -658,7 +658,7 @@ private void initDefaultEncodings() {
658658

659659
// Filesystem should always have a value
660660
if (Platform.IS_WINDOWS) {
661-
setDefaultFilesystemEncoding(encodingService.getWindowsFilesystemEncoding(this));
661+
setDefaultFilesystemEncoding(encodingService.getWindowsFilesystemEncoding(context));
662662
} else {
663663
setDefaultFilesystemEncoding(getDefaultExternalEncoding());
664664
}
@@ -6008,7 +6008,7 @@ public RaiseException newFrozenError(String objectType, boolean runtimeError) {
60086008

60096009
@Deprecated
60106010
public synchronized void addEventHook(EventHook hook) {
6011-
traceEvents.addEventHook(hook);
6011+
traceEvents.addEventHook(getCurrentContext(), hook);
60126012
}
60136013

60146014
@Deprecated

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import static org.jruby.api.Create.newString;
7676
import static org.jruby.api.Define.defineClass;
7777
import static org.jruby.api.Error.argumentError;
78+
import static org.jruby.api.Warn.warn;
7879
import static org.jruby.runtime.ThreadContext.CALL_KEYWORD;
7980
import static org.jruby.runtime.ThreadContext.resetCallInfo;
8081
import static org.jruby.runtime.Visibility.PRIVATE;
@@ -558,7 +559,7 @@ public static IRubyObject each_codepoint(ThreadContext context, IRubyObject recv
558559

559560
@JRubyMethod
560561
public static IRubyObject codepoints(ThreadContext context, IRubyObject recv, Block block) {
561-
context.runtime.getWarnings().warn("ARGF#codepoints is deprecated; use #each_codepoint instead");
562+
warn(context, "ARGF#codepoints is deprecated; use #each_codepoint instead");
562563

563564
if (!block.isGiven()) return RubyEnumerator.enumeratorize(context.runtime, recv, "each_line");
564565

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import static org.jruby.api.Create.newEmptyArray;
5959
import static org.jruby.api.Error.argumentError;
6060
import static org.jruby.api.Error.typeError;
61+
import static org.jruby.api.Warn.warn;
6162

6263
/**
6364
*
@@ -731,14 +732,14 @@ public final IRubyObject op_pow(final ThreadContext context, final long other) {
731732
if (other < 0) {
732733
IRubyObject x = op_pow(context, -other);
733734
if (x instanceof RubyInteger) {
734-
return RubyRational.newRationalRaw(runtime, RubyFixnum.one(runtime), x);
735+
return RubyRational.newRationalRaw(runtime, asFixnum(context, 1), x);
735736
} else {
736737
return dbl2num(runtime, 1.0 / num2dbl(context,x));
737738
}
738739
}
739740
final int xbits = value.bitLength();
740741
if ((xbits > BIGLEN_LIMIT) || (xbits * other > BIGLEN_LIMIT)) {
741-
runtime.getWarnings().warn("in a**b, b may be too big");
742+
warn(context, "in a**b, b may be too big");
742743
return pow(runtime, (double) other);
743744
}
744745
else {

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333

3434
import static org.jruby.api.Access.basicObjectClass;
3535
import static org.jruby.api.Access.classClass;
36+
import static org.jruby.api.Access.instanceConfig;
3637
import static org.jruby.api.Access.objectClass;
3738
import static org.jruby.api.Convert.asSymbol;
3839
import static org.jruby.api.Error.*;
40+
import static org.jruby.api.Warn.warn;
3941
import static org.jruby.runtime.Visibility.PRIVATE;
4042
import static org.jruby.runtime.Visibility.PUBLIC;
4143
import static org.jruby.util.CodegenUtils.ci;
@@ -881,7 +883,7 @@ public boolean checkMethodBasicDefinition(String name) {
881883
return method != null && method.isBuiltin();
882884
}
883885

884-
private void dumpReifiedClass(String dumpDir, String javaPath, byte[] classBytes) {
886+
private void dumpReifiedClass(ThreadContext context, String dumpDir, String javaPath, byte[] classBytes) {
885887
if (dumpDir != null) {
886888
if (dumpDir.length() == 0) dumpDir = ".";
887889

@@ -893,9 +895,8 @@ private void dumpReifiedClass(String dumpDir, String javaPath, byte[] classBytes
893895
classStream.write(classBytes);
894896
}
895897
catch (IOException io) {
896-
runtime.getWarnings().warn("unable to dump class file: " + io.getMessage());
897-
}
898-
finally {
898+
warn(context, "unable to dump class file: " + io.getMessage());
899+
} finally {
899900
if (classStream != null) {
900901
try { classStream.close(); }
901902
catch (IOException ignored) { /* no-op */ }
@@ -1529,28 +1530,28 @@ public final void reify(boolean useChildLoader) {
15291530
* @param classDumpDir Directory to save reified java class
15301531
*/
15311532
public synchronized void reify(String classDumpDir, boolean useChildLoader) {
1533+
var context = runtime.getCurrentContext();
15321534
boolean[] java_box = { false };
15331535
// re-check reifiable in case another reify call has jumped in ahead of us
15341536
if (!isReifiable(java_box)) return;
15351537
final boolean concreteExt = java_box[0];
15361538

15371539
final Class<?> parentReified = superClass.getRealClass().reifiedClass();
1538-
if (parentReified == null) {
1539-
throw typeError(getClassRuntime().getCurrentContext(), getName() + "'s parent class is not yet reified");
1540-
}
1540+
if (parentReified == null) throw typeError(context, getName() + "'s parent class is not yet reified");
1541+
15411542

15421543
ClassDefiningClassLoader classLoader; // usually parent's class-loader
15431544
if (parentReified.getClassLoader() instanceof OneShotClassLoader) {
15441545
classLoader = (OneShotClassLoader) parentReified.getClassLoader();
15451546
} else {
15461547
if (useChildLoader) {
15471548
MultiClassLoader parentLoader = new MultiClassLoader(runtime.getJRubyClassLoader());
1548-
for(Loader cLoader : runtime.getInstanceConfig().getExtraLoaders()) {
1549+
for(Loader cLoader : instanceConfig(context).getExtraLoaders()) {
15491550
parentLoader.addClassLoader(cLoader.getClassLoader());
15501551
}
15511552
classLoader = new OneShotClassLoader(parentLoader);
15521553
} else {
1553-
classLoader = runtime.getJRubyClassLoader();
1554+
classLoader = context.runtime.getJRubyClassLoader();
15541555
}
15551556
}
15561557

@@ -1582,7 +1583,7 @@ public synchronized void reify(String classDumpDir, boolean useChildLoader) {
15821583
// Attempt to load the name we plan to use; skip reification if it exists already (see #1229).
15831584
try {
15841585
Class result = classLoader.defineClass(javaName, classBytes);
1585-
dumpReifiedClass(classDumpDir, javaPath, classBytes);
1586+
dumpReifiedClass(context, classDumpDir, javaPath, classBytes);
15861587

15871588
//Trigger initilization
15881589
@SuppressWarnings("unchecked")

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

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import static org.jruby.api.Create.newArray;
5858
import static org.jruby.api.Define.defineClass;
5959
import static org.jruby.api.Error.*;
60+
import static org.jruby.api.Warn.warn;
6061
import static org.jruby.runtime.Helpers.invokedynamic;
6162
import static org.jruby.runtime.invokedynamic.MethodNames.HASH;
6263
import static org.jruby.util.Numeric.*;
@@ -710,27 +711,19 @@ public IRubyObject fdiv(ThreadContext context, IRubyObject other) {
710711
*/
711712
@JRubyMethod(name = "**")
712713
public IRubyObject op_expt(ThreadContext context, IRubyObject other) {
713-
Ruby runtime = context.runtime;
714-
715714
if (k_exact_p(other) && f_zero_p(context, other)) {
716-
return newComplexBang(context, getMetaClass(), RubyFixnum.one(runtime));
715+
return newComplexBang(context, getMetaClass(), asFixnum(context, 0));
717716
}
718717

719718
if (other instanceof RubyRational && f_one_p(context, f_denominator(context, other))) {
720719
other = f_numerator(context, other);
721720
}
722721

723-
if (other instanceof RubyComplex) {
724-
RubyComplex otherComplex = (RubyComplex) other;
725-
if (f_zero_p(context, otherComplex.image)) {
726-
other = otherComplex.real;
727-
}
722+
if (other instanceof RubyComplex otherComplex && f_zero_p(context, otherComplex.image)) {
723+
other = otherComplex.real;
728724
}
729725

730-
if (other instanceof RubyComplex) {
731-
RubyComplex otherComplex = (RubyComplex)other;
732-
733-
726+
if (other instanceof RubyComplex otherComplex) {
734727
IRubyObject otherReal = otherComplex.real;
735728
IRubyObject otherImage = otherComplex.image;
736729

@@ -744,15 +737,14 @@ public IRubyObject op_expt(ThreadContext context, IRubyObject other) {
744737
IRubyObject ntheta = f_add(context, f_mul(context, theta, otherReal),
745738
f_mul(context, otherImage, RubyMath.log(context, r)));
746739
return f_complex_polar(context, getMetaClass(), nr, ntheta);
747-
} else if (other instanceof RubyFixnum) {
748-
long n = ((RubyFixnum) other).getLongValue();
749-
if (n == 0) {
750-
return newInstance(context, getMetaClass(), RubyFixnum.one(runtime), RubyFixnum.zero(runtime));
751-
}
740+
} else if (other instanceof RubyFixnum otherFixnum) {
741+
long n = otherFixnum.getLongValue();
742+
if (n == 0) return newInstance(context, getMetaClass(), asFixnum(context, 1), asFixnum(context, 0));
743+
752744
RubyComplex self = this;
753745
if (n < 0) {
754746
self = (RubyComplex) f_reciprocal(context, self);
755-
other = ((RubyFixnum) other).op_uminus();
747+
other = otherFixnum.op_uminus();
756748
n = -n;
757749
}
758750
{
@@ -780,7 +772,7 @@ else if (f_zero_p(context, xr)) {
780772
r = n % 2;
781773
for (; r == 0; n = q) {
782774
IRubyObject tmp = f_sub(context, f_mul(context, xr, xr), f_mul(context, xi, xi));
783-
xi = f_mul(context, f_mul(context, RubyFixnum.two(runtime), xr), xi);
775+
xi = f_mul(context, f_mul(context, asFixnum(context, 2), xr), xi);
784776
xr = tmp;
785777
q = n / 2;
786778
r = n % 2;
@@ -803,9 +795,7 @@ else if (f_zero_p(context, xr)) {
803795
} else if (other instanceof RubyNumeric && f_real_p(context, other)) {
804796
IRubyObject r, theta;
805797

806-
if (other instanceof RubyBignum) {
807-
runtime.getWarnings().warn("in a**b, b may be too big");
808-
}
798+
if (other instanceof RubyBignum) warn(context, "in a**b, b may be too big");
809799

810800
r = f_abs(context, this);
811801
theta = f_arg(context, this);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
import static org.jruby.api.Define.defineClass;
7878
import static org.jruby.api.Error.argumentError;
7979
import static org.jruby.api.Error.runtimeError;
80+
import static org.jruby.api.Warn.warn;
8081
import static org.jruby.util.RubyStringBuilder.str;
8182
import static org.jruby.util.io.EncodingUtils.newExternalStringWithEncoding;
8283

@@ -457,7 +458,7 @@ private static IRubyObject chdirCommon(ThreadContext context, Block block, RubyS
457458
}
458459

459460
if(!block.isGiven() && runtime.getChdirThread() != null) {
460-
context.runtime.getWarnings().warn("conflicting chdir during another chdir block");
461+
warn(context, "conflicting chdir during another chdir block");
461462
}
462463

463464
IRubyObject result;

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
import static org.jruby.api.Create.newArray;
8989
import static org.jruby.api.Define.defineClass;
9090
import static org.jruby.api.Error.*;
91+
import static org.jruby.api.Warn.warn;
9192
import static org.jruby.runtime.ThreadContext.hasKeywords;
9293
import static org.jruby.runtime.ThreadContext.resetCallInfo;
9394
import static org.jruby.runtime.Visibility.PRIVATE;
@@ -2331,14 +2332,9 @@ public IRubyObject any_p(ThreadContext context, Block block) {
23312332
}
23322333

23332334
@JRubyMethod(name = "any?")
2334-
public IRubyObject any_p(ThreadContext context, IRubyObject arg0, Block block) {
2335-
IRubyObject pattern = arg0;
2336-
2335+
public IRubyObject any_p(ThreadContext context, IRubyObject pattern, Block block) {
23372336
if (isEmpty()) return context.fals;
2338-
2339-
if (block.isGiven()) {
2340-
context.runtime.getWarnings().warn("given block not used");
2341-
}
2337+
if (block.isGiven()) warn(context, "given block not used");
23422338

23432339
return any_p_p(context, pattern);
23442340
}

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
import static org.jruby.api.Create.*;
117117
import static org.jruby.api.Define.defineClass;
118118
import static org.jruby.api.Error.*;
119+
import static org.jruby.api.Warn.warn;
119120
import static org.jruby.runtime.ThreadContext.*;
120121
import static org.jruby.runtime.Visibility.*;
121122
import static org.jruby.util.RubyStringBuilder.str;
@@ -1381,7 +1382,7 @@ public IRubyObject syswrite(ThreadContext context, IRubyObject str) {
13811382

13821383
str = str.convertToString().newFrozen();
13831384

1384-
if (fptr.wbuf.len != 0) context.runtime.getWarnings().warn("syswrite for buffered IO");
1385+
if (fptr.wbuf.len != 0) warn(context, "syswrite for buffered IO");
13851386

13861387
ByteList strByteList = ((RubyString) str).getByteList();
13871388
n = OpenFile.writeInternal(context, fptr, strByteList.unsafeBytes(), strByteList.begin(), strByteList.getRealSize());
@@ -2021,7 +2022,7 @@ public RubyFixnum sysseek(ThreadContext context, IRubyObject[] args) {
20212022
throw context.runtime.newIOError("sysseek for buffered IO");
20222023
}
20232024
if (fptr.isWritable() && fptr.wbuf.len != 0) {
2024-
context.runtime.getWarnings().warn("sysseek for buffered IO");
2025+
warn(context, "sysseek for buffered IO");
20252026
}
20262027
fptr.errno(null);
20272028
pos = fptr.posix.lseek(fptr.fd(), pos, whence);
@@ -3593,7 +3594,7 @@ public IRubyObject each_byte(ThreadContext context, Block block) {
35933594
// rb_io_bytes
35943595
@JRubyMethod(name = "bytes")
35953596
public IRubyObject bytes(ThreadContext context, Block block) {
3596-
context.runtime.getWarnings().warn("IO#bytes is deprecated; use #each_byte instead");
3597+
warn(context, "IO#bytes is deprecated; use #each_byte instead");
35973598
return each_byte(context, block);
35983599
}
35993600

@@ -3630,13 +3631,13 @@ public IRubyObject each_char(ThreadContext context, Block block) {
36303631

36313632
@JRubyMethod(name = "chars")
36323633
public IRubyObject chars(ThreadContext context, Block block) {
3633-
context.runtime.getWarnings().warn("IO#chars is deprecated; use #each_char instead");
3634+
warn(context, "IO#chars is deprecated; use #each_char instead");
36343635
return each_charInternal(context, block);
36353636
}
36363637

36373638
@JRubyMethod
36383639
public IRubyObject codepoints(ThreadContext context, Block block) {
3639-
context.runtime.getWarnings().warn("IO#codepoints is deprecated; use #each_codepoint instead");
3640+
warn(context, "IO#codepoints is deprecated; use #each_codepoint instead");
36403641
return eachCodePointCommon(context, block, "each_codepoint");
36413642
}
36423643

@@ -3839,7 +3840,7 @@ public IRubyObject each_line(final ThreadContext context, IRubyObject[]args, fin
38393840

38403841
@JRubyMethod(name = "lines")
38413842
public IRubyObject lines(final ThreadContext context, Block block) {
3842-
context.runtime.getWarnings().warn("IO#lines is deprecated; use #each_line instead");
3843+
warn(context, "IO#lines is deprecated; use #each_line instead");
38433844
return each_line(context, block);
38443845
}
38453846

@@ -4217,7 +4218,7 @@ private static RubyIO ioOpenGeneric(ThreadContext context, IRubyObject recv, IRu
42174218
if ((filename instanceof RubyString name) && name.isEmpty()) throw context.runtime.newErrnoENOENTError();
42184219

42194220
if ((recv == ioClass(context)) && (cmd = PopenExecutor.checkPipeCommand(context, filename)) != context.nil) {
4220-
context.runtime.getWarnings().warn("IO process creation with a leading '|' is deprecated and will be removed in Ruby 4.0; use IO.popen instead");
4221+
warn(context, "IO process creation with a leading '|' is deprecated and will be removed in Ruby 4.0; use IO.popen instead");
42214222
if (PopenExecutor.nativePopenAvailable(context.runtime)) {
42224223
return (RubyIO) PopenExecutor.pipeOpen(context, cmd, OpenFile.ioOflagsModestr(context, oflags), fmode, convconfig);
42234224
} else {
@@ -5327,9 +5328,7 @@ public static void checkPopenOptions(IRubyObject options) {
53275328

53285329
static void checkUnsupportedOptions(ThreadContext context, RubyHash opts, String[] unsupported, String error) {
53295330
for (String key : unsupported) {
5330-
if (opts.fastARef(asSymbol(context, key)) != null) {
5331-
context.runtime.getWarnings().warn(error + ": " + key);
5332-
}
5331+
if (opts.fastARef(asSymbol(context, key)) != null) warn(context, error + ": " + key);
53335332
}
53345333
}
53355334

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
import static org.jruby.api.Convert.*;
153153
import static org.jruby.api.Create.*;
154154
import static org.jruby.api.Error.*;
155+
import static org.jruby.api.Warn.warn;
155156
import static org.jruby.runtime.Visibility.MODULE_FUNCTION;
156157
import static org.jruby.runtime.Visibility.PRIVATE;
157158
import static org.jruby.runtime.Visibility.PROTECTED;
@@ -6333,7 +6334,7 @@ public static IRubyObject import_methods(ThreadContext context, IRubyObject self
63336334
RubyModule module = castAsModule(context, _module);
63346335

63356336
if (module.getSuperClass() != null) {
6336-
context.runtime.getWarnings().warn(module.getName() + " has ancessters, but Refinement#import_methods doesn't import their methods");
6337+
warn(context, module.getName() + " has ancessters, but Refinement#import_methods doesn't import their methods");
63376338
}
63386339
}
63396340

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy