A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
java: rename an internal method
[simgrid.git]
/
src
/
bindings
/
java
/
jmsg_rngstream.cpp
diff --git
a/src/bindings/java/jmsg_rngstream.cpp
b/src/bindings/java/jmsg_rngstream.cpp
index
11db6a5
..
aa1a050
100644
(file)
--- a/
src/bindings/java/jmsg_rngstream.cpp
+++ b/
src/bindings/java/jmsg_rngstream.cpp
@@
-1,14
+1,17
@@
-/*
Functions related to the RngStream Java port
*/
+/*
Java binding of the RngStream library
*/
-/* Copyright (c) 2007-2015. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2007-2017. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
+#include "xbt/sysdep.h"
+
#include "jmsg_rngstream.h"
#include "jxbt_utilities.h"
#include "jmsg_rngstream.h"
#include "jxbt_utilities.h"
+SG_BEGIN_DECL()
+
jfieldID jrngstream_bind;
RngStream jrngstream_to_native(JNIEnv *env, jobject jrngstream) {
jfieldID jrngstream_bind;
RngStream jrngstream_to_native(JNIEnv *env, jobject jrngstream) {
@@
-43,16
+46,22
@@
JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_nativeFinalize(JNIEnv *env
JNIEXPORT jboolean JNICALL
Java_org_simgrid_msg_RngStream_setPackageSeed(JNIEnv *env, jobject jrngstream, jintArray jseed) {
JNIEXPORT jboolean JNICALL
Java_org_simgrid_msg_RngStream_setPackageSeed(JNIEnv *env, jobject jrngstream, jintArray jseed) {
- jint buffer[6];
- env->GetIntArrayRegion(jseed, 0, 6, buffer);
-
- RngStream rngstream = jrngstream_to_native(env, jrngstream);
- if (!rngstream)
+ if (jseed == nullptr) {
+ jxbt_throw_null(env, xbt_strdup("seed argument is null"));
return JNI_FALSE;
return JNI_FALSE;
+ }
+
+ jint buffer[6];
+ env->GetIntArrayRegion(jseed, 0, 6, buffer);
- int result = RngStream_SetPackageSeed((unsigned long*)buffer);
+ // The C API expects unsigned long which are wider than int on LP64.
+ // We need to convert:
+ unsigned long seed[6];
+ for (int i = 0; i != 6; ++i)
+ seed[i] = buffer[i];
+ int result = RngStream_SetPackageSeed(seed);
return result == -1 ? JNI_FALSE : JNI_TRUE;
}
return result == -1 ? JNI_FALSE : JNI_TRUE;
}
@@
-102,7
+111,13
@@
JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_RngStream_setSeed(JNIEnv *env, j
if (!rngstream)
return JNI_FALSE;
if (!rngstream)
return JNI_FALSE;
- int result = RngStream_SetSeed(rngstream, (unsigned long*)buffer);
+ // The C API expects unsigned long which are wider than int on LP64.
+ // We need to convert:
+ unsigned long seed[6];
+ for (int i = 0; i != 6; ++i)
+ seed[i] = buffer[i];
+
+ int result = RngStream_SetSeed(rngstream, seed);
return result == -1 ? JNI_FALSE : JNI_TRUE;
}
return result == -1 ? JNI_FALSE : JNI_TRUE;
}
@@
-130,3
+145,5
@@
JNIEXPORT jint JNICALL Java_org_simgrid_msg_RngStream_randInt(JNIEnv *env, jobje
return (jint)RngStream_RandInt(rngstream, (int)i, (int)j);
}
return (jint)RngStream_RandInt(rngstream, (int)i, (int)j);
}
+
+SG_END_DECL()