Skip to content

Commit

Permalink
Showing 3,699 changed files with 6,329 additions and 6,295 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
77 changes: 42 additions & 35 deletions core/src/main/java/org/jruby/RubyMarshal.java
Original file line number Diff line number Diff line change
@@ -41,10 +41,7 @@
import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyModule;

import org.jruby.runtime.Block;
import org.jruby.runtime.Constants;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.*;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.runtime.marshal.MarshalStream;
import org.jruby.runtime.marshal.UnmarshalStream;
@@ -73,17 +70,19 @@ public static RubyModule createMarshalModule(Ruby runtime) {
}

@JRubyMethod(required = 1, optional = 2, module = true, visibility = Visibility.PRIVATE)
public static IRubyObject dump(IRubyObject recv, IRubyObject[] args, Block unusedBlock) {
Ruby runtime = recv.getRuntime();
public static IRubyObject dump(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block unusedBlock) {
final Ruby runtime = context.runtime;

IRubyObject objectToDump = args[0];
IRubyObject io = null;
int depthLimit = -1;

if (args.length >= 2) {
if (args[1].respondsTo("write")) {
io = args[1];
} else if (args[1] instanceof RubyFixnum) {
depthLimit = (int) ((RubyFixnum) args[1]).getLongValue();
IRubyObject arg1 = args[1];
if (sites(context).respond_to_write.respondsTo(context, arg1, arg1)) {
io = arg1;
} else if (arg1 instanceof RubyFixnum) {
depthLimit = (int) ((RubyFixnum) arg1).getLongValue();
} else {
throw runtime.newTypeError("Instance of IO needed");
}
@@ -94,48 +93,42 @@ public static IRubyObject dump(IRubyObject recv, IRubyObject[] args, Block unuse

try {
if (io != null) {
dumpToStream(runtime, objectToDump, outputStream(runtime.getCurrentContext(), io), depthLimit);
dumpToStream(runtime, objectToDump, outputStream(context, io), depthLimit);
return io;
}

ByteArrayOutputStream stringOutput = new ByteArrayOutputStream();
boolean taint = dumpToStream(runtime, objectToDump, stringOutput, depthLimit);
RubyString result = RubyString.newString(runtime, new ByteList(stringOutput.toByteArray()));
RubyString result = RubyString.newString(runtime, new ByteList(stringOutput.toByteArray(), false));

if (taint) result.setTaint(true);

return result;
} catch (IOException ioe) {
throw runtime.newIOErrorFromException(ioe);
}

}

private static OutputStream outputStream(ThreadContext context, IRubyObject out) {
setBinmodeIfPossible(context, out);
return new IOOutputStream(out);
}

private static void setBinmodeIfPossible(ThreadContext context, IRubyObject io) {
if (io.respondsTo("binmode")) io.callMethod(context, "binmode");
@Deprecated
public static IRubyObject dump(IRubyObject recv, IRubyObject[] args, Block unusedBlock) {
return dump(recv.getRuntime().getCurrentContext(), recv, args, unusedBlock);
}

@JRubyMethod(name = {"load", "restore"}, required = 1, optional = 1, module = true, visibility = Visibility.PRIVATE)
public static IRubyObject load(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block unusedBlock) {
Ruby runtime = context.runtime;
IRubyObject in = args[0];
IRubyObject proc = args.length == 2 ? args[1] : context.nil;


final IRubyObject str = in.checkStringType();
try {
InputStream rawInput;
boolean tainted;
IRubyObject v = in.checkStringType();

if (!v.isNil()) {
InputStream rawInput; boolean tainted;
if (str != context.nil) {
tainted = in.isTaint();
ByteList bytes = ((RubyString) v).getByteList();
ByteList bytes = ((RubyString) str).getByteList();
rawInput = new ByteArrayInputStream(bytes.getUnsafeBytes(), bytes.begin(), bytes.length());
} else if (in.respondsTo("getc") && in.respondsTo("read")) {
} else if (sites(context).respond_to_getc.respondsTo(context, in, in) &&
sites(context).respond_to_read.respondsTo(context, in, in)) {
tainted = true;
rawInput = inputStream(context, in);
} else {
@@ -144,7 +137,7 @@ public static IRubyObject load(ThreadContext context, IRubyObject recv, IRubyObj

return new UnmarshalStream(runtime, rawInput, proc, tainted).unmarshalObject();
} catch (EOFException e) {
if (in.respondsTo("to_str")) throw runtime.newArgumentError("marshal data too short");
if (str != context.nil) throw runtime.newArgumentError("marshal data too short");

throw runtime.newEOFError();
} catch (IOException ioe) {
@@ -154,22 +147,36 @@ public static IRubyObject load(ThreadContext context, IRubyObject recv, IRubyObj

private static InputStream inputStream(ThreadContext context, IRubyObject in) {
setBinmodeIfPossible(context, in);
return new IOInputStream(in);
return new IOInputStream(in, false); // respond_to?(:read) already checked
}

private static boolean dumpToStream(Ruby runtime, IRubyObject object, OutputStream rawOutput,
int depthLimit) throws IOException {
private static OutputStream outputStream(ThreadContext context, IRubyObject out) {
setBinmodeIfPossible(context, out);
return new IOOutputStream(out, true, false); // respond_to?(:write) already checked
}

private static boolean dumpToStream(Ruby runtime, IRubyObject object, OutputStream rawOutput, int depthLimit)
throws IOException {
MarshalStream output = new MarshalStream(runtime, rawOutput, depthLimit);
output.dumpObject(object);
return output.isTainted();
}

private static void setBinmodeIfPossible(ThreadContext context, IRubyObject io) {
if (sites(context).respond_to_binmode.respondsTo(context, io, io)) {
sites(context).binmode.call(context, io, io);
}
}

/**
* Convenience method for objects that are undumpable. Always throws.
*
* @throws TypeError
* Convenience method for objects that are undumpable. Always throws (a TypeError).
*/
public static IRubyObject undumpable(ThreadContext context, RubyObject self) {
throw context.runtime.newTypeError("can't dump " + self.type());
}

private static JavaSites.MarshalSites sites(ThreadContext context) {
return context.sites.Marshal;
}

}
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/RubyRational.java
Original file line number Diff line number Diff line change
@@ -555,6 +555,11 @@ public final RubyNumeric op_minus(ThreadContext context, RubyRational other) {
@Deprecated
public IRubyObject op_sub(ThreadContext context, IRubyObject other) { return op_minus(context, other); }

@Override
public IRubyObject op_uminus(ThreadContext context) {
return RubyRational.newRationalNoReduce(context, num.negate(), den);
}

/** f_muldiv
*
*/
Original file line number Diff line number Diff line change
@@ -146,15 +146,6 @@ public void inject() {
*/
@Override
public void remove() {
final ThreadContext context = getCurrentContext();
try {
DynamicScope currentScope = context.getCurrentScope();
ManyVarsDynamicScope scope = (ManyVarsDynamicScope) context.getCurrentScope();
scope = new ManyVarsDynamicScope(context.runtime.getStaticScopeFactory().newEvalScope(currentScope.getStaticScope()), currentScope);
}
catch (ArrayIndexOutOfBoundsException e) {
//no context is left.
//no operation is needed.
}
// FIXME: Code originally here did not appear to actually do anything, so it was removed.
}
}
Original file line number Diff line number Diff line change
@@ -89,14 +89,13 @@ public String[] toStringNonOperandArgs() {
}

public IRubyObject callHelper(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block.Type blockType) {
StaticScope scope = currDynScope.getStaticScope();
Operand[] operands = getOperands();

if (helperMethod == Methods.IS_DEFINED_BACKREF) {
return IRRuntimeHelpers.isDefinedBackref(
context,
(IRubyObject) getOperands()[0].retrieve(context, self, currScope, currDynScope, temp));
(IRubyObject) operands[0].retrieve(context, self, currScope, currDynScope, temp));
}
Operand[] operands = getOperands();

switch (helperMethod) {
case IS_DEFINED_NTH_REF:
@@ -117,9 +116,9 @@ public IRubyObject callHelper(ThreadContext context, StaticScope currScope, Dyna
case HANDLE_PROPAGATED_BREAK:
return IRRuntimeHelpers.handlePropagatedBreak(context, currDynScope, arg1, blockType);
case HANDLE_NONLOCAL_RETURN:
return IRRuntimeHelpers.handleNonlocalReturn(scope, currDynScope, arg1, blockType);
return IRRuntimeHelpers.handleNonlocalReturn(currScope, currDynScope, arg1, blockType);
case HANDLE_BREAK_AND_RETURNS_IN_LAMBDA:
return IRRuntimeHelpers.handleBreakAndReturnsInLambdas(context, scope, currDynScope, arg1, blockType);
return IRRuntimeHelpers.handleBreakAndReturnsInLambdas(context, currScope, currDynScope, arg1, blockType);
case IS_DEFINED_CALL:
return IRRuntimeHelpers.isDefinedCall(
context,
Loading

0 comments on commit bc809f7

Please sign in to comment.