|
From: <ai...@us...> - 2009-07-19 17:30:28
|
Revision: 10162
http://plplot.svn.sourceforge.net/plplot/?rev=10162&view=rev
Author: airwin
Date: 2009-07-19 17:30:25 +0000 (Sun, 19 Jul 2009)
Log Message:
-----------
Apply simple patch submitted by anonymous user at
https://sourceforge.net/tracker/?func=detail&atid=102915&aid=2823751&group_id=2915.
This fix moves the jadat declaration to the top of the function which
apparently allows the generated source code to compile under msvc.
Modified Paths:
--------------
trunk/bindings/java/plplotjavac.i
Modified: trunk/bindings/java/plplotjavac.i
===================================================================
--- trunk/bindings/java/plplotjavac.i 2009-07-19 01:59:08 UTC (rev 10161)
+++ trunk/bindings/java/plplotjavac.i 2009-07-19 17:30:25 UTC (rev 10162)
@@ -259,9 +259,10 @@
/* Create a jdoubleArray and fill it from the C PLFLT array dat */
static jdoubleArray
-setup_java_array_1d_PLFLT( JNIEnv *jenv, PLFLT *dat, PLINT n)
+setup_java_array_1d_PLFLT( JNIEnv *jenv, PLFLT *dat, PLINT n)
{
double *x;
+ jdoubleArray jadat;
#ifdef PL_DOUBLE
x = (double *) dat;
#else
@@ -270,7 +271,7 @@
x[i] = (double) dat[i];
}
#endif
- jdoubleArray jadat = (*jenv)->NewDoubleArray(jenv, n);
+ jadat = (*jenv)->NewDoubleArray(jenv, n);
(*jenv)->SetDoubleArrayRegion(jenv, jadat, 0, n, x);
#ifndef PL_DOUBLE
free(x);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <and...@us...> - 2009-08-20 12:02:05
|
Revision: 10305
http://plplot.svn.sourceforge.net/plplot/?rev=10305&view=rev
Author: andrewross
Date: 2009-08-20 12:01:56 +0000 (Thu, 20 Aug 2009)
Log Message:
-----------
Fix up crash in plslabelfunc support. Should now work with all java implementations.
Modified Paths:
--------------
trunk/bindings/java/plplotjavac.i
Modified: trunk/bindings/java/plplotjavac.i
===================================================================
--- trunk/bindings/java/plplotjavac.i 2009-08-20 09:05:43 UTC (rev 10304)
+++ trunk/bindings/java/plplotjavac.i 2009-08-20 12:01:56 UTC (rev 10305)
@@ -52,6 +52,16 @@
typedef unsigned int PLUNICODE;
typedef PLINT PLBOOL;
+/* Set jni version and cache JVM - needed for callbacks */
+%{
+static JavaVM *cached_jvm = NULL;
+
+SWIGEXPORT JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
+ cached_jvm = jvm;
+ return JNI_VERSION_1_2;
+}
+%}
+
/* Simple (input) PLBOOL arguments */
/* Use macro style similar to INPUT_TYPEMAP defined in typemaps.i, but
* actually follow what is done in java.swg for bool C type except
@@ -1146,16 +1156,16 @@
jobject mapformClass;
jmethodID mapformID;
- JNIEnv *cbenv;
+ JNIEnv *cbenvMapform;
/* C mapform callback function which calls the java
* mapform function in a PLCallbackMapform object. */
void mapform_java(PLINT n, PLFLT *x, PLFLT *y) {
- jdoubleArray jx = setup_java_array_1d_PLFLT(cbenv,x,n);
- jdoubleArray jy = setup_java_array_1d_PLFLT(cbenv,y,n);
- (*cbenv)->CallVoidMethod(cbenv,mapformClass, mapformID,jx,jy);
- release_java_array_1d_PLFLT(cbenv,jx,x,n);
- release_java_array_1d_PLFLT(cbenv,jy,y,n);
+ jdoubleArray jx = setup_java_array_1d_PLFLT(cbenvMapform,x,n);
+ jdoubleArray jy = setup_java_array_1d_PLFLT(cbenvMapform,y,n);
+ (*cbenvMapform)->CallVoidMethod(cbenvMapform,mapformClass, mapformID,jx,jy);
+ release_java_array_1d_PLFLT(cbenvMapform,jx,x,n);
+ release_java_array_1d_PLFLT(cbenvMapform,jy,y,n);
}
%}
@@ -1168,7 +1178,7 @@
jclass cls = (*jenv)->GetObjectClass(jenv,obj);
mapformID = (*jenv)->GetMethodID(jenv,cls, "mapform","([D[D)V" );
mapformClass = obj;
- cbenv = jenv;
+ cbenvMapform = jenv;
$1 = mapform_java;
}
else {
@@ -1184,25 +1194,61 @@
%{
- jobject labelClass;
- jmethodID labelID;
- JNIEnv *cbenv;
+ jobject labelClass = 0;
+ jobject labelClassRef = 0;
/* C label plotting callback function which calls the java
- * label function in a PLCallbackLabel object. */
+ * label function in a PLCallbackLabel labelClassobelID
+bject. */
void label_java(PLINT axis, PLFLT value, char *string, PLINT len, PLPointer data) {
jstring javaString;
const char *nativeString;
jint jaxis;
jdouble jvalue;
+ JNIEnv *cbenv;
+ jmethodID labelID = 0;
jaxis = (jint) axis;
jvalue = (jdouble) value;
- javaString = (jstring)(*cbenv)->CallObjectMethod(cbenv,labelClass, labelID, jaxis, jvalue);
- nativeString = (*cbenv)->GetStringUTFChars(cbenv,javaString,0);
- strncpy(string,nativeString,len);
- (*cbenv)->ReleaseStringUTFChars(cbenv,javaString,nativeString);
- /*strncpy(string,"",len);*/
+
+ if ((string == NULL ) || (len == 0)) {
+ return;
+ }
+
+ string[0] = '\0';
+
+ if (cached_jvm == NULL) {
+ fprintf(stderr,"Error! NULL jvm\n");
+ return;
+ }
+ (*cached_jvm)->GetEnv(cached_jvm,(void **)&cbenv,JNI_VERSION_1_2);
+ if (cbenv == NULL) {
+ fprintf(stderr,"Thread not attached\n");
+ if (AttachCurrentThread(cached_jvm, &cbenv, NULL) != 0) {
+ fprintf(stderr,"Error attaching to JVM\n");
+ return;
+ }
+ }
+ if (labelClass == 0) {
+ fprintf(stderr,"Error - callback undefined\n");
+ return;
+ }
+ jclass cls = (*cbenv)->GetObjectClass(cbenv,labelClass);
+ if (cls == 0) {
+ fprintf(stderr,"Error getting callback class\n");
+ return;
+ }
+ labelID = (*cbenv)->GetMethodID(cbenv,cls, "label","(ID)Ljava/lang/String;" );
+ if (labelID != 0) {
+ javaString = (jstring)(*cbenv)->CallObjectMethod(cbenv,labelClass, labelID, jaxis, jvalue);
+ nativeString = (*cbenv)->GetStringUTFChars(cbenv,javaString,0);
+ strncpy(string,nativeString,len);
+ (*cbenv)->ReleaseStringUTFChars(cbenv,javaString,nativeString);
+ }
+ else {
+ fprintf(stderr,"Java callback not found\n");
+ string[0] = '\0';
+ }
}
%}
@@ -1211,11 +1257,18 @@
%typemap(in) label_func lf {
jobject obj = $input;
+
+ /* Delete any old references */
+ if (labelClass != 0) {
+ (*jenv)->DeleteGlobalRef(jenv,labelClass);
+ labelClass = 0;
+ }
+ /* Need a reference to this object to ensure it is
+ * valid when we reach the callback */
if (obj != NULL) {
- jclass cls = (*jenv)->GetObjectClass(jenv,obj);
- labelID = (*jenv)->GetMethodID(jenv,cls, "label","(ID)Ljava/lang/String;" );
- labelClass = obj;
- cbenv = jenv;
+ labelClass = (*jenv)->NewGlobalRef(jenv,obj);
+ }
+ if (labelClass != 0) {
$1 = label_java;
}
else {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <and...@us...> - 2009-08-20 12:44:36
|
Revision: 10308
http://plplot.svn.sourceforge.net/plplot/?rev=10308&view=rev
Author: andrewross
Date: 2009-08-20 12:44:27 +0000 (Thu, 20 Aug 2009)
Log Message:
-----------
Fix up error in last fix for java plslabelfunc support.
Modified Paths:
--------------
trunk/bindings/java/plplotjavac.i
Modified: trunk/bindings/java/plplotjavac.i
===================================================================
--- trunk/bindings/java/plplotjavac.i 2009-08-20 12:41:42 UTC (rev 10307)
+++ trunk/bindings/java/plplotjavac.i 2009-08-20 12:44:27 UTC (rev 10308)
@@ -1224,7 +1224,7 @@
(*cached_jvm)->GetEnv(cached_jvm,(void **)&cbenv,JNI_VERSION_1_2);
if (cbenv == NULL) {
fprintf(stderr,"Thread not attached\n");
- if (AttachCurrentThread(cached_jvm, &cbenv, NULL) != 0) {
+ if ((*cached_jvm)->AttachCurrentThread(cached_jvm, (void **)&cbenv, NULL) != 0) {
fprintf(stderr,"Error attaching to JVM\n");
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2011-04-13 04:19:09
|
Revision: 11698
http://plplot.svn.sourceforge.net/plplot/?rev=11698&view=rev
Author: airwin
Date: 2011-04-13 04:19:03 +0000 (Wed, 13 Apr 2011)
Log Message:
-----------
Use standard code delimiters "%{" and "%}" inside %define ... %enddef
swig directives. This change appears to make no difference to build
and test results, but there is a good possibility it will improve
uncrustify styling results.
Modified Paths:
--------------
trunk/bindings/java/plplotjavac.i
Modified: trunk/bindings/java/plplotjavac.i
===================================================================
--- trunk/bindings/java/plplotjavac.i 2011-04-13 02:45:28 UTC (rev 11697)
+++ trunk/bindings/java/plplotjavac.i 2011-04-13 04:19:03 UTC (rev 11698)
@@ -125,10 +125,10 @@
%typemap(freearg) TYPE *OUTPUT, TYPE &OUTPUT ""
%typemap(argout) TYPE *OUTPUT, TYPE &OUTPUT
-{
+%{
JNITYPE jvalue = (JNITYPE)temp$argnum;
JCALL4(Set##JAVATYPE##ArrayRegion, jenv, $input, 0, 1, &jvalue);
-}
+%}
%typemap(typecheck) TYPE *INOUT = TYPECHECKTYPE;
%typemap(typecheck) TYPE &INOUT = TYPECHECKTYPE;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2011-04-13 05:05:26
|
Revision: 11699
http://plplot.svn.sourceforge.net/plplot/?rev=11699&view=rev
Author: airwin
Date: 2011-04-13 05:05:20 +0000 (Wed, 13 Apr 2011)
Log Message:
-----------
Complete the change to use standard code delimiters "%{" and "%}" inside %define ...
%enddef swig directives. Also, correct what appears to be a
parentheses error. That unbalanced parentheses issue also appears in
/usr/share/swig1.3/java/typemaps.i for the
%typemap(directorin,descriptor=JNIDESC) TYPE &OUTPUT
typemap, but not for other related typemaps so I may be misunderstanding
something. But when I provide balanced parentheses as for the
other cases, the result continues to work (see below).
Also change to form of warning message in
/usr/share/swig1.3/java/typemaps.i for the
%typemap(directorin .....) TYPE *OUTPUT
typemap.
These changes appear to make no difference to build and test results,
but there is a good possibility they will improve uncrustify styling
results.
Modified Paths:
--------------
trunk/bindings/java/plplotjavac.i
Modified: trunk/bindings/java/plplotjavac.i
===================================================================
--- trunk/bindings/java/plplotjavac.i 2011-04-13 04:19:03 UTC (rev 11698)
+++ trunk/bindings/java/plplotjavac.i 2011-04-13 05:05:20 UTC (rev 11699)
@@ -102,7 +102,7 @@
%typemap(javadirectorout) TYPE *OUTPUT, TYPE &OUTPUT "$javacall"
%typemap(in) TYPE *OUTPUT($*1_ltype temp), TYPE &OUTPUT($*1_ltype temp)
-{
+%{
if (!$input) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "array null");
return $null;
@@ -112,14 +112,13 @@
return $null;
}
$1 = &temp;
-}
+%}
%typemap(directorin,descriptor=JNIDESC) TYPE &OUTPUT
-%{ *(($&1_ltype) $input = &$1; %}
+%{ *(($&1_ltype) $input) = &$1; %}
-%typemap(directorin,descriptor=JNIDESC) TYPE *OUTPUT
+%typemap(directorin,descriptor=JNIDESC,warning="Need to provide TYPE *OUTPUT directorin typemap, TYPE array length is unknown") TYPE *OUTPUT
%{
-#error "Need to provide OUT directorin typemap, TYPE array length is unknown"
%}
%typemap(freearg) TYPE *OUTPUT, TYPE &OUTPUT ""
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ai...@us...> - 2011-04-13 18:16:39
|
Revision: 11702
http://plplot.svn.sourceforge.net/plplot/?rev=11702&view=rev
Author: airwin
Date: 2011-04-13 18:16:33 +0000 (Wed, 13 Apr 2011)
Log Message:
-----------
It turns out (see section 10.4.1 of swig documentation) that both "{
}" and "%{ %}" can be used for typemaps depending on the scope that is
desired. So use "{ }" for three of the typemaps following what is
done in /usr/share/swig1.3/java/typemaps.i. That change causes no
problems for our styling script and also builds and tests without
issues.
Modified Paths:
--------------
trunk/bindings/java/plplotjavac.i
Modified: trunk/bindings/java/plplotjavac.i
===================================================================
--- trunk/bindings/java/plplotjavac.i 2011-04-13 05:24:00 UTC (rev 11701)
+++ trunk/bindings/java/plplotjavac.i 2011-04-13 18:16:33 UTC (rev 11702)
@@ -110,7 +110,7 @@
%typemap( javadirectorout ) TYPE * OUTPUT, TYPE & OUTPUT "$javacall"
%typemap( in ) TYPE * OUTPUT( $*1_ltype temp ), TYPE &OUTPUT( $*1_ltype temp )
-%{
+{
if ( !$input )
{
SWIG_JavaThrowException( jenv, SWIG_JavaNullPointerException, "array null" );
@@ -122,7 +122,7 @@
return $null;
}
$1 = &temp;
-%}
+}
%typemap( directorin, descriptor = JNIDESC ) TYPE & OUTPUT
%{
@@ -130,16 +130,16 @@
%}
%typemap( directorin, descriptor = JNIDESC, warning = "Need to provide TYPE *OUTPUT directorin typemap, TYPE array length is unknown" ) TYPE * OUTPUT
-%{
-%}
+{
+}
%typemap( freearg ) TYPE * OUTPUT, TYPE & OUTPUT ""
%typemap( argout ) TYPE * OUTPUT, TYPE & OUTPUT
-%{
+{
JNITYPE jvalue = (JNITYPE) temp$argnum;
JCALL4( Set ## JAVATYPE ## ArrayRegion, jenv, $input, 0, 1, &jvalue );
-%}
+}
%typemap( typecheck ) TYPE * INOUT = TYPECHECKTYPE;
%typemap( typecheck ) TYPE &INOUT = TYPECHECKTYPE;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <and...@us...> - 2012-01-05 11:58:31
|
Revision: 12121
http://plplot.svn.sourceforge.net/plplot/?rev=12121&view=rev
Author: andrewross
Date: 2012-01-05 11:58:24 +0000 (Thu, 05 Jan 2012)
Log Message:
-----------
Potential fix for java crashes with pltr2 to avoid referencing variables that are out of scope.
Modified Paths:
--------------
trunk/bindings/java/plplotjavac.i
Modified: trunk/bindings/java/plplotjavac.i
===================================================================
--- trunk/bindings/java/plplotjavac.i 2012-01-05 11:51:21 UTC (rev 12120)
+++ trunk/bindings/java/plplotjavac.i 2012-01-05 11:58:24 UTC (rev 12121)
@@ -330,6 +330,7 @@
static PLINT Xlen = 0, Ylen = 0;
static PLFLT **xg;
static PLFLT **yg;
+ static PLcGrid2 *cgrid;
%}
// The following typemaps take care of marshaling values into and out of PLplot functions. The
@@ -1536,7 +1537,6 @@
int nx = ( *jenv )->GetArrayLength( jenv, $input );
int ny = -1;
int i, j;
- PLcGrid2 cgrid;
ai = (jobject *) malloc( nx * sizeof ( jobject ) );
adat = (jPLFLT **) malloc( nx * sizeof ( jPLFLT * ) );
@@ -1580,16 +1580,18 @@
free( adat );
free( ai );
- cgrid.xg = xg;
- cgrid.yg = yg;
- cgrid.nx = nx;
- cgrid.ny = ny;
- $1 = &cgrid;
+ cgrid = (PLcGrid2 *) malloc( sizeof ( PLcGrid2 ) );
+ cgrid->xg = xg;
+ cgrid->yg = yg;
+ cgrid->nx = nx;
+ cgrid->ny = ny;
+ $1 = cgrid;
}
%typemap( freearg ) PLPointer OBJECT_DATA {
free( yg[0] );
free( yg );
+ free( cgrid );
}
%typemap( jni ) PLPointer OBJECT_DATA "jobjectArray"
%typemap( jtype ) PLPointer OBJECT_DATA jPLFLTbracket2
@@ -1679,7 +1681,6 @@
int nx = ( *jenv )->GetArrayLength( jenv, $input );
int ny = -1;
int i, j;
- PLcGrid2 cgrid;
ai = (jobject *) malloc( nx * sizeof ( jobject ) );
adat = (jPLFLT **) malloc( nx * sizeof ( jPLFLT * ) );
@@ -1723,16 +1724,18 @@
free( adat );
free( ai );
- cgrid.xg = xg;
- cgrid.yg = yg;
- cgrid.nx = nx;
- cgrid.ny = ny;
- $1 = &cgrid;
+ cgrid = (PLcGrid2 *) malloc( sizeof ( PLcGrid2 ) );
+ cgrid->xg = xg;
+ cgrid->yg = yg;
+ cgrid->nx = nx;
+ cgrid->ny = ny;
+ $1 = cgrid;
}
%typemap( freearg ) PLPointer OBJECT_DATA_img {
free( yg[0] );
free( yg );
+ free( cgrid );
}
%typemap( jni ) PLPointer OBJECT_DATA_img "jobjectArray"
%typemap( jtype ) PLPointer OBJECT_DATA_img jPLFLTbracket2
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <arj...@us...> - 2013-10-19 18:05:44
|
Revision: 12608
http://sourceforge.net/p/plplot/code/12608
Author: arjenmarkus
Date: 2013-10-19 18:05:40 +0000 (Sat, 19 Oct 2013)
Log Message:
-----------
Moved two declarations of "cls" to the top of the function, as defining them in the middle of the executable code is a C++-like extension not accepted by MSVC/C++.
Also changed a comparison against NULL to an assignment of NULL.
Modified Paths:
--------------
trunk/bindings/java/plplotjavac.i
Modified: trunk/bindings/java/plplotjavac.i
===================================================================
--- trunk/bindings/java/plplotjavac.i 2013-10-19 17:10:54 UTC (rev 12607)
+++ trunk/bindings/java/plplotjavac.i 2013-10-19 18:05:40 UTC (rev 12608)
@@ -441,7 +441,7 @@
}
else
{
- $1 == NULL;
+ $1 = NULL;
}
}
%typemap( freearg ) const PLINT * ArrayCkNull {
@@ -1368,6 +1368,7 @@
jdouble jvalue;
JNIEnv *cbenv;
jmethodID labelID = 0;
+ jclass cls;
jaxis = (jint) axis;
jvalue = (jdouble) value;
@@ -1399,7 +1400,7 @@
fprintf( stderr, "Error - callback undefined\n" );
return;
}
- jclass cls = ( *cbenv )->GetObjectClass( cbenv, labelClass );
+ cls = ( *cbenv )->GetObjectClass( cbenv, labelClass );
if ( cls == 0 )
{
fprintf( stderr, "Error getting callback class\n" );
@@ -1468,6 +1469,7 @@
jobject jdata;
JNIEnv *cbenv;
jmethodID ctID = 0;
+ jclass cls;
jx = (jdouble) x;
jy = (jdouble) y;
@@ -1495,7 +1497,7 @@
fprintf( stderr, "Error - callback undefined\n" );
return;
}
- jclass cls = ( *cbenv )->GetObjectClass( cbenv, ctClass );
+ cls = ( *cbenv )->GetObjectClass( cbenv, ctClass );
if ( cls == 0 )
{
fprintf( stderr, "Error getting callback class\n" );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|