Skip to content
Snippets Groups Projects
Commit fd32c6a1 authored by Lukas Stadler's avatar Lukas Stadler
Browse files

Merge pull request #443 in G/fastr from ~MICK.JORDAN_ORACLE.COM/fastr:bugfix/tempdir to master

* commit '9badee5c':
  terminate process if initial language initialization fails
  fix mkdtemp bug
parents d37937a3 9badee5c
Branches
No related tags found
No related merge requests found
......@@ -41,6 +41,7 @@ import com.oracle.truffle.r.engine.interop.RForeignAccessFactoryImpl;
import com.oracle.truffle.r.nodes.RASTBuilder;
import com.oracle.truffle.r.nodes.builtin.RBuiltinPackages;
import com.oracle.truffle.r.nodes.instrumentation.RSyntaxTags;
import com.oracle.truffle.r.runtime.ExitException;
import com.oracle.truffle.r.runtime.FastROptions;
import com.oracle.truffle.r.runtime.RAccuracyInfo;
import com.oracle.truffle.r.runtime.RError;
......@@ -80,7 +81,17 @@ public final class TruffleRLanguage extends TruffleLanguage<RContext> {
} catch (Throwable t) {
t.printStackTrace();
Utils.rSuicide("error during R language initialization");
/*
* Truffle currently has no distinguished exception to indicate language initialization
* failure, so nothing good can come from throwing the exception, which is what
* Utils.rSuicide does. For now we catch it and exit the process.
*/
try {
Utils.rSuicide("error during R language initialization");
} catch (ExitException ex) {
System.exit(ex.getStatus());
}
}
}
......
......@@ -58,11 +58,15 @@ Java_com_oracle_truffle_r_runtime_ffi_jni_JNI_1Base_native_1setwd(JNIEnv *env, j
JNIEXPORT jint JNICALL
Java_com_oracle_truffle_r_runtime_ffi_jni_JNI_1Base_native_1mkdtemp(JNIEnv *env, jclass c, jbyteArray jtemplate) {
char *template = (*env)->GetPrimitiveArrayCritical(env, jtemplate, NULL);
char *template = (char*) (*env)->GetByteArrayElements(env, jtemplate, NULL);
char *r = mkdtemp(template);
if (r == NULL) return 0;
(*env)->ReleasePrimitiveArrayCritical(env, jtemplate, template, 0);
return 1;
int rc = 1;
if (r == NULL) {
// printf("mkdtemp errno: %d\n", errno);
rc = 0;
}
(*env)->ReleaseByteArrayElements(env, jtemplate, (jbyte*) template, rc == 1 ? 0 : JNI_ABORT);
return rc;
}
JNIEXPORT jint JNICALL
......
......@@ -72,12 +72,19 @@ public class JNI_Base implements BaseRFFI {
@Override
public String mkdtemp(String template) {
/*
* Not only must the (C) string end in XXXXXX it must also be null-terminated. Since it is
* modified by mkdtemp we must make a copy.
*/
byte[] bytes = template.getBytes();
long result = native_mkdtemp(bytes);
byte[] ztbytes = new byte[bytes.length + 1];
System.arraycopy(bytes, 0, ztbytes, 0, bytes.length);
ztbytes[bytes.length] = 0;
long result = native_mkdtemp(ztbytes);
if (result == 0) {
return null;
} else {
return new String(bytes);
return new String(ztbytes, 0, bytes.length);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment