Update of /cvsroot/crystal/CS/include/ivaria
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23966/include/ivaria
Modified Files:
javapre.i
Log Message:
Eric Sunshine fixed bugs in the csWrapPtr "out" typemap in javapre.i where
it was incorrectly returning a corrupt Java object when the wrapped
pointer was 0. It should have been returning 'null' in this
case. Subsequent Java operations on the returned bogus object would then
crash within the JNI glue code. This problem manifested, for instance,
when any of the query macros, such as CS_QUERY_REGISTRY(), failed to find
the requested object.
Index: javapre.i
===================================================================
RCS file: /cvsroot/crystal/CS/include/ivaria/javapre.i,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- javapre.i 21 Oct 2004 13:13:50 -0000 1.12
+++ javapre.i 28 Oct 2004 14:28:12 -0000 1.13
@@ -201,13 +201,18 @@
ptr = iBase__DynamicCast((iBase *)$1.Ref, $1.Type).VoidPtr;
}
//ref->IncRef();
- jlong cptr = 0;
- *(void **)&cptr = ptr;
- char cls_name[1024];
- strcat(strcpy(cls_name, "com/crystalspace/"), $1.Type);
- jclass cls = jenv->FindClass(cls_name);
- jmethodID mid = jenv->GetMethodID(cls, "<init>", "(JZ)V");
- $result = jenv->NewObject(cls, mid, cptr, false);
+ if (ptr == 0)
+ $result = 0;
+ else
+ {
+ jlong cptr = 0;
+ *(void **)&cptr = ptr;
+ char cls_name[1024];
+ strcat(strcpy(cls_name, "com/crystalspace/"), $1.Type);
+ jclass cls = jenv->FindClass(cls_name);
+ jmethodID mid = jenv->GetMethodID(cls, "<init>", "(JZ)V");
+ $result = jenv->NewObject(cls, mid, cptr, false);
+ }
}
//%typemap(out) csWrapPtr %{ $result = $1; %}
%typemap(jni) csWrapPtr "jobject";
@@ -215,7 +220,7 @@
%typemap(jstype) csWrapPtr "Object";
%typemap(javain) csWrapPtr "$javainput";
//%typemap(javaout) csWrapPtr { return $jnicall; }
- %typemap(javaout) csWrapPtr { Object _obj = $jnicall; iBase ibase = (iBase) _obj; ibase.IncRef(); return _obj; }
+ %typemap(javaout) csWrapPtr { Object _obj = $jnicall; iBase ibase = (iBase) _obj; if (ibase != null) ibase.IncRef(); return _obj; }
%enddef
#undef INTERFACE_EQUALS
|