Skip to content

Commit

Permalink
Showing 8 changed files with 125 additions and 94 deletions.
161 changes: 88 additions & 73 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
@@ -4056,99 +4056,114 @@ public static IRubyObject copy_stream(ThreadContext context, IRubyObject recv, I
}
}

if (arg1 instanceof RubyString) {
io1 = (RubyIO) RubyFile.open(context, runtime.getFile(), new IRubyObject[] {arg1}, Block.NULL_BLOCK);
} else if (arg1 instanceof RubyIO) {
io1 = (RubyIO) arg1;
} else if (arg1.respondsTo("to_path")) {
RubyString path = (RubyString) TypeConverter.convertToType19(arg1, runtime.getString(), "to_path");
io1 = (RubyIO) RubyFile.open(context, runtime.getFile(), new IRubyObject[] {path}, Block.NULL_BLOCK);
} else if (arg1.respondsTo("read")) {
if (length == null) {
read = arg1.callMethod(context, "read", runtime.getNil()).convertToString();
} else {
read = arg1.callMethod(context, "read", length).convertToString();
}
} else {
throw runtime.newArgumentError("Should be String or IO");
}

if (arg2 instanceof RubyString) {
io2 = (RubyIO) RubyFile.open(context, runtime.getFile(), new IRubyObject[] {arg2, runtime.newString("w")}, Block.NULL_BLOCK);
} else if (arg2 instanceof RubyIO) {
io2 = (RubyIO) arg2;
} else if (arg2.respondsTo("to_path")) {
RubyString path = (RubyString) TypeConverter.convertToType19(arg2, runtime.getString(), "to_path");
io2 = (RubyIO) RubyFile.open(context, runtime.getFile(), new IRubyObject[] {path, runtime.newString("w")}, Block.NULL_BLOCK);
} else if (arg2.respondsTo("write")) {
if (read == null) {
boolean close1 = false;
boolean close2 = false;
try {
if (arg1 instanceof RubyString) {
io1 = (RubyIO) RubyFile.open(context, runtime.getFile(), new IRubyObject[]{arg1}, Block.NULL_BLOCK);
close1 = true;
} else if (arg1 instanceof RubyIO) {
io1 = (RubyIO) arg1;
} else if (arg1.respondsTo("to_path")) {
RubyString path = (RubyString) TypeConverter.convertToType19(arg1, runtime.getString(), "to_path");
io1 = (RubyIO) RubyFile.open(context, runtime.getFile(), new IRubyObject[]{path}, Block.NULL_BLOCK);
close1 = true;
} else if (arg1.respondsTo("read")) {
if (length == null) {
read = io1.read(context, runtime.getNil()).convertToString();
read = arg1.callMethod(context, "read", runtime.getNil()).convertToString();
} else {
read = io1.read(context, length).convertToString();
read = arg1.callMethod(context, "read", length).convertToString();
}
} else {
throw runtime.newArgumentError("Should be String or IO");
}
return arg2.callMethod(context, "write", read);
} else {
throw runtime.newArgumentError("Should be String or IO");
}

if (io1 == null) {
IRubyObject size = io2.write(context, read);
io2.flush(context);
return size;
}
if (arg2 instanceof RubyString) {
io2 = (RubyIO) RubyFile.open(context, runtime.getFile(), new IRubyObject[]{arg2, runtime.newString("w")}, Block.NULL_BLOCK);
close2 = true;
} else if (arg2 instanceof RubyIO) {
io2 = (RubyIO) arg2;
} else if (arg2.respondsTo("to_path")) {
RubyString path = (RubyString) TypeConverter.convertToType19(arg2, runtime.getString(), "to_path");
io2 = (RubyIO) RubyFile.open(context, runtime.getFile(), new IRubyObject[]{path, runtime.newString("w")}, Block.NULL_BLOCK);
close2 = true;
} else if (arg2.respondsTo("write")) {
if (read == null) {
if (length == null) {
read = io1.read(context, runtime.getNil()).convertToString();
} else {
read = io1.read(context, length).convertToString();
}
}
return arg2.callMethod(context, "write", read);
} else {
throw runtime.newArgumentError("Should be String or IO");
}

io2 = io2.GetWriteIO();
if (io1 == null) {
IRubyObject size = io2.write(context, read);
io2.flush(context);
return size;
}

if (!io1.openFile.isReadable()) throw runtime.newIOError("from IO is not readable");
if (!io2.openFile.isWritable()) throw runtime.newIOError("to IO is not writable");
io2 = io2.GetWriteIO();

// attempt to preserve position of original
OpenFile fptr = io1.getOpenFileChecked();
if (!io1.openFile.isReadable()) throw runtime.newIOError("from IO is not readable");
if (!io2.openFile.isWritable()) throw runtime.newIOError("to IO is not writable");

boolean locked = fptr.lock();
try {
long pos = fptr.tell(context);
long size = 0;
// attempt to preserve position of original
OpenFile fptr = io1.getOpenFileChecked();

boolean locked = fptr.lock();
try {
if (io1.openFile.fileChannel() == null) {
long remaining = length == null ? -1 : length.getLongValue();
long position = offset == null ? -1 : offset.getLongValue();
if (io2.openFile.fileChannel() == null) {
ReadableByteChannel from = io1.openFile.readChannel();
WritableByteChannel to = io2.openFile.writeChannel();
long pos = fptr.tell(context);
long size = 0;

size = transfer(context, from, to, remaining, position);
try {
if (io1.openFile.fileChannel() == null) {
long remaining = length == null ? -1 : length.getLongValue();
long position = offset == null ? -1 : offset.getLongValue();
if (io2.openFile.fileChannel() == null) {
ReadableByteChannel from = io1.openFile.readChannel();
WritableByteChannel to = io2.openFile.writeChannel();

size = transfer(context, from, to, remaining, position);
} else {
ReadableByteChannel from = io1.openFile.readChannel();
FileChannel to = io2.openFile.fileChannel();

size = transfer(context, from, to, remaining, position);
}
} else {
ReadableByteChannel from = io1.openFile.readChannel();
FileChannel to = io2.openFile.fileChannel();
FileChannel from = io1.openFile.fileChannel();
WritableByteChannel to = io2.openFile.writeChannel();
long remaining = length == null ? from.size() : length.getLongValue();
long position = offset == null ? from.position() : offset.getLongValue();

size = transfer(context, from, to, remaining, position);
size = transfer(from, to, remaining, position);
}
} else {
FileChannel from = io1.openFile.fileChannel();
WritableByteChannel to = io2.openFile.writeChannel();
long remaining = length == null ? from.size() : length.getLongValue();
long position = offset == null ? from.position() : offset.getLongValue();

size = transfer(from, to, remaining, position);
return context.runtime.newFixnum(size);
} catch (IOException ioe) {
ioe.printStackTrace();
throw runtime.newIOErrorFromException(ioe);
} finally {
if (offset != null) {
fptr.seek(context, pos, PosixShim.SEEK_SET);
} else {
fptr.seek(context, pos + size, PosixShim.SEEK_SET);
}
}

return context.runtime.newFixnum(size);
} catch (IOException ioe) {
ioe.printStackTrace();
throw runtime.newIOErrorFromException(ioe);
} finally {
if (offset != null) {
fptr.seek(context, pos, PosixShim.SEEK_SET);
} else {
fptr.seek(context, pos + size, PosixShim.SEEK_SET);
}
if (locked) fptr.unlock();
}
} finally {
if (locked) fptr.unlock();
if (close1 && io1 != null) {
try {io1.close();} catch (Exception e) {}
}
if (close2 && io2 != null) {
try {io2.close();} catch (Exception e) {}
}
}
}

6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/parser/ParserSupport.java
Original file line number Diff line number Diff line change
@@ -235,6 +235,12 @@ public Node appendToBlock(Node head, Node tail) {
return head;
}

// We know it has to be tLABEL or tIDENTIFIER so none of the other assignable logic is needed
public AssignableNode assignableInCurr(String name, Node value) {
currentScope.addVariableThisScope(name);
return currentScope.assign(lexer.getPosition(), name, makeNullNil(value));
}

public Node getOperatorCallNode(Node firstNode, String operator) {
checkExpression(firstNode);

10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/parser/RubyParser.java
Original file line number Diff line number Diff line change
@@ -3756,7 +3756,7 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
};
states[371] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = support.assignableLabelOrIdentifier(((String)yyVals[0+yyTop]), NilImplicitNode.NIL);
yyVal = support.assignableInCurr(((String)yyVals[0+yyTop]), NilImplicitNode.NIL);
return yyVal;
}
};
@@ -3786,13 +3786,13 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
};
states[376] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = new MultipleAsgnNode(((ListNode)yyVals[-3+yyTop]).getPosition(), ((ListNode)yyVals[-3+yyTop]), support.assignableLabelOrIdentifier(((String)yyVals[0+yyTop]), null), null);
yyVal = new MultipleAsgnNode(((ListNode)yyVals[-3+yyTop]).getPosition(), ((ListNode)yyVals[-3+yyTop]), support.assignableInCurr(((String)yyVals[0+yyTop]), null), null);
return yyVal;
}
};
states[377] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = new MultipleAsgnNode(((ListNode)yyVals[-5+yyTop]).getPosition(), ((ListNode)yyVals[-5+yyTop]), support.assignableLabelOrIdentifier(((String)yyVals[-2+yyTop]), null), ((ListNode)yyVals[0+yyTop]));
yyVal = new MultipleAsgnNode(((ListNode)yyVals[-5+yyTop]).getPosition(), ((ListNode)yyVals[-5+yyTop]), support.assignableInCurr(((String)yyVals[-2+yyTop]), null), ((ListNode)yyVals[0+yyTop]));
return yyVal;
}
};
@@ -3810,13 +3810,13 @@ public Object yyparse (RubyLexer yyLex) throws java.io.IOException {
};
states[380] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = new MultipleAsgnNode(lexer.getPosition(), null, support.assignableLabelOrIdentifier(((String)yyVals[0+yyTop]), null), null);
yyVal = new MultipleAsgnNode(lexer.getPosition(), null, support.assignableInCurr(((String)yyVals[0+yyTop]), null), null);
return yyVal;
}
};
states[381] = new ParserState() {
@Override public Object execute(ParserSupport support, RubyLexer lexer, Object yyVal, Object[] yyVals, int yyTop) {
yyVal = new MultipleAsgnNode(lexer.getPosition(), null, support.assignableLabelOrIdentifier(((String)yyVals[-2+yyTop]), null), ((ListNode)yyVals[0+yyTop]));
yyVal = new MultipleAsgnNode(lexer.getPosition(), null, support.assignableInCurr(((String)yyVals[-2+yyTop]), null), ((ListNode)yyVals[0+yyTop]));
return yyVal;
}
};
10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/parser/RubyParser.y
Original file line number Diff line number Diff line change
@@ -1552,7 +1552,7 @@ for_var : lhs
}

f_marg : f_norm_arg {
$$ = support.assignableLabelOrIdentifier($1, NilImplicitNode.NIL);
$$ = support.assignableInCurr($1, NilImplicitNode.NIL);
}
| tLPAREN f_margs rparen {
$$ = $2;
@@ -1570,10 +1570,10 @@ f_margs : f_marg_list {
$$ = new MultipleAsgnNode($1.getPosition(), $1, null, null);
}
| f_marg_list ',' tSTAR f_norm_arg {
$$ = new MultipleAsgnNode($1.getPosition(), $1, support.assignableLabelOrIdentifier($4, null), null);
$$ = new MultipleAsgnNode($1.getPosition(), $1, support.assignableInCurr($4, null), null);
}
| f_marg_list ',' tSTAR f_norm_arg ',' f_marg_list {
$$ = new MultipleAsgnNode($1.getPosition(), $1, support.assignableLabelOrIdentifier($4, null), $6);
$$ = new MultipleAsgnNode($1.getPosition(), $1, support.assignableInCurr($4, null), $6);
}
| f_marg_list ',' tSTAR {
$$ = new MultipleAsgnNode($1.getPosition(), $1, new StarNode(lexer.getPosition()), null);
@@ -1582,10 +1582,10 @@ f_margs : f_marg_list {
$$ = new MultipleAsgnNode($1.getPosition(), $1, new StarNode(lexer.getPosition()), $5);
}
| tSTAR f_norm_arg {
$$ = new MultipleAsgnNode(lexer.getPosition(), null, support.assignableLabelOrIdentifier($2, null), null);
$$ = new MultipleAsgnNode(lexer.getPosition(), null, support.assignableInCurr($2, null), null);
}
| tSTAR f_norm_arg ',' f_marg_list {
$$ = new MultipleAsgnNode(lexer.getPosition(), null, support.assignableLabelOrIdentifier($2, null), $4);
$$ = new MultipleAsgnNode(lexer.getPosition(), null, support.assignableInCurr($2, null), $4);
}
| tSTAR {
$$ = new MultipleAsgnNode(lexer.getPosition(), null, new StarNode(lexer.getPosition()), null);
10 changes: 3 additions & 7 deletions lib/pom.rb
Original file line number Diff line number Diff line change
@@ -43,13 +43,9 @@ def initialize( name, version, default_spec = true )
# just depends on jruby-core so we are sure the jruby.jar is in place
jar "org.jruby:jruby-core:#{version}", :scope => 'test'

#repository( :url => 'https://otto.takari.io/content/repositories/rubygems/maven/releases',
# :id => 'rubygems-releases' )
#repository( :url => 'http://rubygems-proxy.torquebox.org/releases',
# :id => 'tb-rubygems-releases' )
# for testing out jruby-ossl before final release :
#repository( :url => 'http://oss.sonatype.org/content/repositories/staging',
# :id => 'gem-staging' )
extension 'org.torquebox.mojo:mavengem-wagon:0.2.0'

repository :id => :mavengems, :url => 'mavengem:http://rubygems.org'

plugin( :clean,
:filesets => [ { :directory => '${basedir}/ruby/gems/shared/specifications/default',
13 changes: 13 additions & 0 deletions lib/pom.xml
Original file line number Diff line number Diff line change
@@ -175,7 +175,20 @@ DO NOT MODIFIY - GENERATED CODE
</exclusions>
</dependency>
</dependencies>
<repositories>
<repository>
<id>mavengems</id>
<url>mavengem:http://rubygems.org</url>
</repository>
</repositories>
<build>
<extensions>
<extension>
<groupId>org.torquebox.mojo</groupId>
<artifactId>mavengem-wagon</artifactId>
<version>0.2.0</version>
</extension>
</extensions>
<resources>
<resource>
<targetPath>${jruby.complete.gems}</targetPath>
1 change: 1 addition & 0 deletions spec/tags/ruby/core/module/define_method_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
fails:Module#define_method when name is :initialize passed a block sets visibility to private when method name is :initialize
fails:Module#define_method when name is :initialize given an UnboundMethod sets the visibility to private when method is named :initialize
fails:Module#define_method when name is not a special private name given an UnboundMethod sets the visibility of the method to the current visibility
8 changes: 4 additions & 4 deletions test/pom.rb
Original file line number Diff line number Diff line change
@@ -7,16 +7,16 @@
inherit 'org.jruby:jruby-parent', version
id 'org.jruby:jruby-tests'

repository( :url => 'https://otto.takari.io/content/repositories/rubygems/maven/releases',
:id => 'rubygems-releases' )
extension 'org.torquebox.mojo:mavengem-wagon:0.2.0'

repository :id => :mavengems, :url => 'mavengem:http://rubygems.org'
plugin_repository :id => :mavengems, :url => 'mavengem:http://rubygems.org'

plugin_repository( :url => 'https://oss.sonatype.org/content/repositories/snapshots/',
:id => 'sonatype' ) do
releases 'false'
snapshots 'true'
end
plugin_repository( :id => 'rubygems-releases',
:url => 'https://otto.takari.io/content/repositories/rubygems/maven/releases' )

properties( 'polyglot.dump.pom' => 'pom.xml',
'jruby.home' => '${basedir}/..',

0 comments on commit c757e7c

Please sign in to comment.