Skip to content

Commit

Permalink
Dedup checkExecEnv logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Apr 16, 2015
1 parent 4c52c92 commit edce1da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
24 changes: 1 addition & 23 deletions core/src/main/java/org/jruby/RubyIO.java
Expand Up @@ -4476,29 +4476,7 @@ private static void checkValidOptions(IRubyObject options, Set<String> valid) {

// MRI: check_exec_env, w/ check_exec_env_i body in-line
public static RubyArray checkExecEnv(ThreadContext context, RubyHash hash) {
Ruby runtime = context.runtime;
RubyArray env = runtime.newArray();
for (Map.Entry<IRubyObject, IRubyObject> entry : (Set<Map.Entry<IRubyObject, IRubyObject>>)hash.directEntrySet()) {
IRubyObject key = entry.getKey();
IRubyObject val = entry.getValue();
ByteList k;

k = StringSupport.checkEmbeddedNulls(runtime, key).getByteList();
if (k.indexOf('=') != -1)
throw runtime.newArgumentError("environment name contains a equal : " + k);

if (!val.isNil())
StringSupport.checkEmbeddedNulls(runtime, val);

if (Platform.IS_WINDOWS) {
key = ((RubyString)key).export(context);
}
if (!val.isNil()) val = ((RubyString)val).export(context);

env.push(runtime.newArray(key, val));
}

return env;
return PopenExecutor.checkExecEnv(context, hash);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/util/io/PopenExecutor.java
Expand Up @@ -23,7 +23,6 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ByteList;
import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.ShellLauncher;
import org.jruby.util.StringSupport;
import org.jruby.util.TypeConverter;
Expand Down Expand Up @@ -314,10 +313,11 @@ public static IRubyObject popen(ThreadContext context, IRubyObject[] argv, RubyC
}

static void execargSetenv(ThreadContext context, Ruby runtime, ExecArg eargp, IRubyObject env) {
eargp.env_modification = !env.isNil() ? checkExecEnv(context, runtime, (RubyHash)env) : null;
eargp.env_modification = !env.isNil() ? checkExecEnv(context, (RubyHash)env) : null;
}

static RubyArray checkExecEnv(ThreadContext context, Ruby runtime, RubyHash hash) {
public static RubyArray checkExecEnv(ThreadContext context, RubyHash hash) {
Ruby runtime = context.runtime;
RubyArray env;

env = runtime.newArray();
Expand Down Expand Up @@ -1769,7 +1769,7 @@ private static void execFillarg(ThreadContext context, RubyString prog, IRubyObj
}

if (!env.isNil()) {
eargp.env_modification = RubyIO.checkExecEnv(context, (RubyHash)env);
eargp.env_modification = checkExecEnv(context, (RubyHash) env);
}

prog = prog.export(context);
Expand Down

0 comments on commit edce1da

Please sign in to comment.