Skip to content

Commit

Permalink
Split IO.pipe into specific arities
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Jan 19, 2024
1 parent 46e69f2 commit d56f620
Showing 1 changed file with 50 additions and 47 deletions.
97 changes: 50 additions & 47 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -4438,66 +4438,38 @@ public static IRubyObject popen(ThreadContext context, IRubyObject recv, IRubyOb
}
}

@Deprecated
public static IRubyObject pipe19(ThreadContext context, IRubyObject recv) {
return pipe19(context, recv, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
public static IRubyObject pipe(ThreadContext context, IRubyObject recv) {
return pipe(context, recv, Block.NULL_BLOCK);
}

@Deprecated
public static IRubyObject pipe19(ThreadContext context, IRubyObject recv, IRubyObject modes) {
return pipe19(context, recv, new IRubyObject[] {modes}, Block.NULL_BLOCK);
@JRubyMethod(name = "pipe", meta = true)
public static IRubyObject pipe(ThreadContext context, IRubyObject klass, Block block) {
return pipe(context, klass, context.nil, context.nil, context.nil, block);
}

@Deprecated
public static IRubyObject pipe19(ThreadContext context, IRubyObject klass, IRubyObject[] argv, Block block) {
return pipe(context, klass, argv, block);
@JRubyMethod(name = "pipe", meta = true)
public static IRubyObject pipe(ThreadContext context, IRubyObject klass, IRubyObject arg0, Block block) {
IRubyObject opt = TypeConverter.checkHashType(context.runtime, arg0);

return pipe(context, klass, opt.isNil() ? arg0 : context.nil, context.nil, opt, block);
}

@JRubyMethod(name = "pipe", meta = true)
public static IRubyObject pipe(ThreadContext context, IRubyObject klass, IRubyObject arg0, IRubyObject arg1, Block block) {
IRubyObject opt = TypeConverter.checkHashType(context.runtime, arg1);

public static IRubyObject pipe(ThreadContext context, IRubyObject recv) {
return pipe(context, recv, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
return pipe(context, klass, arg0, !opt.isNil() ? context.nil : arg1, opt, block);
}

@JRubyMethod(name = "pipe", optional = 3, checkArity = false, meta = true)
public static IRubyObject pipe(ThreadContext context, IRubyObject klass, IRubyObject[] argv, Block block) {
int argc = Arity.checkArgumentCount(context, argv, 0, 3);

@JRubyMethod(name = "pipe", meta = true)
public static IRubyObject pipe(ThreadContext context, IRubyObject klass, IRubyObject v1, IRubyObject v2, IRubyObject opt, Block block) {
Ruby runtime = context.runtime;
int state;

RubyIO r, w;
// IRubyObject args[] = new IRubyObject[3]
IRubyObject v1, v2;
IRubyObject opt;
v1 = v2 = opt = context.nil;
OpenFile fptr, fptr2;
int[] fmode_p = {0};
IRubyObject ret;

switch (argc) {
case 3:
opt = argv[2].convertToHash();
argc--;
v2 = argv[1];
v1 = argv[0];
break;
case 2:
opt = TypeConverter.checkHashType(runtime, argv[1]);
if (!opt.isNil()) {
argc--;
} else {
v2 = argv[1];
}
v1 = argv[0];
break;
case 1:
opt = TypeConverter.checkHashType(runtime, argv[0]);
if (!opt.isNil()) {
argc--;
} else {
v1 = argv[0];
}
}

PosixShim posix = new PosixShim(runtime);
Channel[] fds = posix.pipe();
if (fds == null)
Expand All @@ -4512,7 +4484,7 @@ public static IRubyObject pipe(ThreadContext context, IRubyObject klass, IRubyOb
// close(pipes[1]);
// rb_jump_tag(state);
// }
r = new RubyIO(runtime, (RubyClass)klass);
r = new RubyIO(runtime, (RubyClass) klass);
r.initializeCommon(context, new ChannelFD(fds[0], runtime.getPosix(), runtime.getFilenoUtil()), runtime.newFixnum(OpenFlags.O_RDONLY), context.nil);
fptr = r.getOpenFileChecked();

Expand All @@ -4526,7 +4498,7 @@ public static IRubyObject pipe(ThreadContext context, IRubyObject klass, IRubyOb
// if (!NIL_P(r)) rb_io_close(r);
// rb_jump_tag(state);
// }
w = new RubyIO(runtime, (RubyClass)klass);
w = new RubyIO(runtime, (RubyClass) klass);
w.initializeCommon(context, new ChannelFD(fds[1], runtime.getPosix(), runtime.getFilenoUtil()), runtime.newFixnum(OpenFlags.O_WRONLY), context.nil);
fptr2 = w.getOpenFileChecked();
fptr2.setSync(true);
Expand Down Expand Up @@ -5646,6 +5618,37 @@ public IRubyObject sysread(ThreadContext context, IRubyObject[] args) {
return sysreadCommon(context, runtime, _length, _str);
}

@Deprecated
public static IRubyObject pipe19(ThreadContext context, IRubyObject recv) {
return pipe19(context, recv, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
}

@Deprecated
public static IRubyObject pipe19(ThreadContext context, IRubyObject recv, IRubyObject modes) {
return pipe19(context, recv, new IRubyObject[] {modes}, Block.NULL_BLOCK);
}

@Deprecated
public static IRubyObject pipe19(ThreadContext context, IRubyObject klass, IRubyObject[] argv, Block block) {
return pipe(context, klass, argv, block);
}

@Deprecated
public static IRubyObject pipe(ThreadContext context, IRubyObject klass, IRubyObject[] argv, Block block) {
switch (argv.length) {
case 0:
return pipe(context, klass, block);
case 1:
return pipe(context, klass, argv[0], block);
case 2:
return pipe(context, klass, argv[0], argv[1], block);
case 3:
return pipe(context, klass, argv[0], argv[1], argv[2], block);
default:
throw context.runtime.newArgumentError(argv.length, 0, 3);
}
}

protected OpenFile openFile;

/**
Expand Down

0 comments on commit d56f620

Please sign in to comment.