diff options
author | Jens-Heiner Rechtien <hr@openoffice.org> | 2006-06-19 20:53:50 +0000 |
---|---|---|
committer | Jens-Heiner Rechtien <hr@openoffice.org> | 2006-06-19 20:53:50 +0000 |
commit | d9a789422058afef5d5a6653dc26aa8459c54af5 (patch) | |
tree | e01337c71890efa9fbb587fbf2262062f64970c5 /jurt | |
parent | 2d957e32b0548cdafd35efa30aafa1e73b8d58ba (diff) |
INTEGRATION: CWS warnings01 (1.5.22); FILE MERGED
2005/11/28 09:05:52 sb 1.5.22.6: #i53898# Made code warning-free.
2005/11/09 08:26:46 sb 1.5.22.5: #i53898# Made code warning-free; fixed error introduced in 1.5.
2005/09/23 02:38:00 sb 1.5.22.4: RESYNC: (1.5-1.6); FILE MERGED
2005/09/07 15:02:56 sb 1.5.22.3: #i53898# Made code warning-free.
2005/09/06 11:48:29 sb 1.5.22.2: #i53898# Fixed use of SAL_INT_CAST to cast between pointer and integer types.
2005/09/01 08:21:33 sb 1.5.22.1: #i53898# Made code warning-free.
Diffstat (limited to 'jurt')
-rw-r--r-- | jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c | 529 |
1 files changed, 260 insertions, 269 deletions
diff --git a/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c b/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c index edad7789dcdb..7c2adcdc6382 100644 --- a/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c +++ b/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c @@ -4,9 +4,9 @@ * * $RCSfile: com_sun_star_lib_connections_pipe_PipeConnection.c,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: rt $ $Date: 2005-09-07 19:08:32 $ + * last change: $Author: hr $ $Date: 2006-06-19 21:53:50 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -33,10 +33,6 @@ * ************************************************************************/ -#if HAVE_CONFIG_H -#include <config.h> -#endif - #include "osl/security.h" #include <osl/pipe.h> @@ -48,11 +44,10 @@ static void ThrowException(JNIEnv * env, char const * type, char const * msg) { jclass c; (*env)->ExceptionClear(env); - c = (*env)->FindClass(env, "java/lang/RuntimeException"); + c = (*env)->FindClass(env, type); if (c == NULL) { (*env)->ExceptionClear(env); - (*env)->FatalError( - env, "JNI FindClass(\"java/lang/RuntimeException\") failed"); + (*env)->FatalError(env, "JNI FindClass failed"); } if ((*env)->ThrowNew(env, c, msg) != 0) { (*env)->ExceptionClear(env); @@ -73,28 +68,25 @@ static oslPipe getPipe(JNIEnv * env, jobject obj_this) { jclass tclass; jfieldID fid; - while (1) + tclass = (*env)->GetObjectClass(env, obj_this); + if (tclass == NULL) { - tclass = (*env)->GetObjectClass(env, obj_this); - if (tclass == NULL) - { - ThrowException(env, - "java/lang/RuntimeException", - "native pipe cannot find class"); - break; - } + ThrowException(env, + "java/lang/RuntimeException", + "native pipe cannot find class"); + return NULL; + } - fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J"); - if (fid == NULL) - { - ThrowException(env, - "java/lang/RuntimeException", - "native pipe cannot find field"); - break; - } - return ((oslPipe)((*env)->GetLongField(env, obj_this, fid))); + fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J"); + if (fid == NULL) + { + ThrowException(env, + "java/lang/RuntimeException", + "native pipe cannot find field"); + return NULL; } - return NULL; + return (oslPipe) SAL_INT_CAST( + sal_IntPtr, (*env)->GetLongField(env, obj_this, fid)); } /*****************************************************************************/ @@ -134,99 +126,99 @@ JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_cre oslSecurity psec = osl_getCurrentSecurity(); oslPipe npipe = NULL; rtl_uString * pname = NULL; - while (1) + if ((*env)->MonitorEnter(env, obj_this) != 0) { - if ((*env)->MonitorEnter(env, obj_this) != 0) - { - ThrowException(env, - "java/lang/RuntimeException", - "native pipe cannot synchronize on the object"); - break; - } - state = INMONITOR; + ThrowException(env, + "java/lang/RuntimeException", + "native pipe cannot synchronize on the object"); + goto error; + } + state = INMONITOR; - /* check connection state */ - npipe = getPipe(env, obj_this); - if ((*env)->ExceptionOccurred(env) != NULL) - break; - if (npipe != NULL) - { - ThrowException(env, - "com/sun/star/io/IOException", - "native pipe is already connected"); - break; - } + /* check connection state */ + npipe = getPipe(env, obj_this); + if ((*env)->ExceptionOccurred(env) != NULL) + goto error; + if (npipe != NULL) + { + ThrowException(env, + "com/sun/star/io/IOException", + "native pipe is already connected"); + goto error; + } - /* save the pipe name */ - tclass = (*env)->GetObjectClass(env, obj_this); - if (tclass == NULL) - { - ThrowException(env, - "java/lang/RuntimeException", - "native pipe cannot find class"); - break; - } + /* save the pipe name */ + tclass = (*env)->GetObjectClass(env, obj_this); + if (tclass == NULL) + { + ThrowException(env, + "java/lang/RuntimeException", + "native pipe cannot find class"); + goto error; + } - fid = (*env)->GetFieldID(env, tclass, - "_aDescription", "Ljava/lang/String;"); - if (fid == NULL) - { - ThrowException(env, - "java/lang/RuntimeException", - "native pipe cannot find field"); - break; - } + fid = (*env)->GetFieldID(env, tclass, + "_aDescription", "Ljava/lang/String;"); + if (fid == NULL) + { + ThrowException(env, + "java/lang/RuntimeException", + "native pipe cannot find field"); + goto error; + } - (*env)->SetObjectField(env, obj_this, fid, (jobject)name); + (*env)->SetObjectField(env, obj_this, fid, (jobject)name); - /* convert pipe name to rtl_uString */ - pname = jstring2ustring(env, name); - if (pname == NULL) - { - ThrowException(env, - "java/lang/RuntimeException", - "native pipe cannot convert name"); - break; - } - state = GOTNAME; - - /* try to connect */ - npipe = osl_createPipe(pname, osl_Pipe_OPEN, psec); - if (npipe == NULL) - { - ThrowException(env, - "java/lang/RuntimeException", - "cannot create native pipe"); - break; - } - state = CREATED; + /* convert pipe name to rtl_uString */ + pname = jstring2ustring(env, name); + if (pname == NULL) + { + ThrowException(env, + "java/lang/RuntimeException", + "native pipe cannot convert name"); + goto error; + } + state = GOTNAME; - /* save the pipe */ - tclass = (*env)->GetObjectClass(env, obj_this); - if (tclass == NULL) - { - ThrowException(env, - "java/lang/RuntimeException", - "native pipe cannot find class"); - break; - } + /* try to connect */ + npipe = osl_createPipe(pname, osl_Pipe_OPEN, psec); + if (npipe == NULL) + { + ThrowException(env, + "java/lang/RuntimeException", + "cannot create native pipe"); + goto error; + } + state = CREATED; - fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J"); - if (fid == NULL) - { - ThrowException(env, - "java/lang/RuntimeException", - "native pipe cannot find field"); - break; - } - (*env)->SetLongField(env, obj_this, fid, (jlong)npipe); + /* save the pipe */ + tclass = (*env)->GetObjectClass(env, obj_this); + if (tclass == NULL) + { + ThrowException(env, + "java/lang/RuntimeException", + "native pipe cannot find class"); + goto error; + } - /* done */ - rtl_uString_release(pname); - (*env)->MonitorExit(env, obj_this); - osl_freeSecurityHandle(psec); - return; + fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J"); + if (fid == NULL) + { + ThrowException(env, + "java/lang/RuntimeException", + "native pipe cannot find field"); + goto error; } + (*env)->SetLongField( + env, obj_this, fid, SAL_INT_CAST(jlong, (sal_IntPtr) npipe)); + + /* done */ + rtl_uString_release(pname); + (*env)->MonitorExit(env, obj_this); + osl_freeSecurityHandle(psec); + return; + + error: switch (state) { case CREATED: @@ -263,58 +255,57 @@ JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_clo jclass tclass; /* this class */ jfieldID fid; /* a field identifier */ - while (1) + if ((*env)->MonitorEnter(env, obj_this) != 0) { - if ((*env)->MonitorEnter(env, obj_this) != 0) - { - ThrowException(env, - "java/lang/RuntimeException", - "native pipe cannot synchronize on the object"); - break; - } - state = INMONITOR; + ThrowException(env, + "java/lang/RuntimeException", + "native pipe cannot synchronize on the object"); + goto error; + } + state = INMONITOR; - /* check connection state */ - npipe = getPipe(env, obj_this); - if ((*env)->ExceptionOccurred(env) != NULL) - break; - if (npipe == NULL) - { - ThrowException(env, - "com/sun/star/io/IOException", - "native pipe is not connected"); - break; - } + /* check connection state */ + npipe = getPipe(env, obj_this); + if ((*env)->ExceptionOccurred(env) != NULL) + goto error; + if (npipe == NULL) + { + ThrowException(env, + "com/sun/star/io/IOException", + "native pipe is not connected"); + goto error; + } - /* remove the reference to the pipe */ - tclass = (*env)->GetObjectClass(env, obj_this); - if (tclass == NULL) - { - ThrowException(env, - "java/lang/RuntimeException", - "native pipe cannot find class"); - break; - } + /* remove the reference to the pipe */ + tclass = (*env)->GetObjectClass(env, obj_this); + if (tclass == NULL) + { + ThrowException(env, + "java/lang/RuntimeException", + "native pipe cannot find class"); + goto error; + } - fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J"); - if (fid == NULL) - { - ThrowException(env, - "java/lang/RuntimeException", - "native pipe cannot find field"); - break; - } + fid = (*env)->GetFieldID(env, tclass, "_nPipeHandle", "J"); + if (fid == NULL) + { + ThrowException(env, + "java/lang/RuntimeException", + "native pipe cannot find field"); + goto error; + } - (*env)->SetLongField(env, obj_this, fid, (jlong)0); + (*env)->SetLongField(env, obj_this, fid, (jlong)0); - /* release the pipe */ - osl_closePipe(npipe); - osl_releasePipe(npipe); + /* release the pipe */ + osl_closePipe(npipe); + osl_releasePipe(npipe); - /* done */ - (*env)->MonitorExit(env, obj_this); - return; - } + /* done */ + (*env)->MonitorExit(env, obj_this); + return; + + error: switch (state) { case INMONITOR: @@ -348,87 +339,86 @@ JNIEXPORT jint JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_rea jbyteArray bytes; /* java read buffer */ jint nread; /* number of bytes has been read */ - while (1) + /* enter monitor */ + if ((*env)->MonitorEnter(env, obj_this) != 0) { - /* enter monitor */ - if ((*env)->MonitorEnter(env, obj_this) != 0) - { - ThrowException(env, - "java/lang/RuntimeException", - "native pipe cannot synchronize on the object"); - break; - } - state = INMONITOR; + ThrowException(env, + "java/lang/RuntimeException", + "native pipe cannot synchronize on the object"); + goto error; + } + state = INMONITOR; - /* check connection state */ - npipe = getPipe(env, obj_this); - if ((*env)->ExceptionOccurred(env) != NULL) - break; - if (npipe == NULL) - { - ThrowException(env, - "com/sun/star/io/IOException", - "native pipe is not connected"); - break; - } + /* check connection state */ + npipe = getPipe(env, obj_this); + if ((*env)->ExceptionOccurred(env) != NULL) + goto error; + if (npipe == NULL) + { + ThrowException(env, + "com/sun/star/io/IOException", + "native pipe is not connected"); + goto error; + } - /* aquire pipe */ - osl_acquirePipe( npipe ); - state = AQUIRED; + /* aquire pipe */ + osl_acquirePipe( npipe ); + state = AQUIRED; - /* allocate a buffer */ - if ((nbuff = malloc(len)) == NULL) - { - ThrowException(env, - "java/lang/RuntimeException", - "native pipe out of memory"); - break; - } + /* allocate a buffer */ + if ((nbuff = malloc(len)) == NULL) + { + ThrowException(env, + "java/lang/RuntimeException", + "native pipe out of memory"); + goto error; + } - state = GOTBUFFER; + state = GOTBUFFER; - /* exit monitor */ - (*env)->MonitorExit(env, obj_this); + /* exit monitor */ + (*env)->MonitorExit(env, obj_this); - /* reading */ - nread = osl_readPipe(npipe, nbuff, len); + /* reading */ + nread = osl_readPipe(npipe, nbuff, len); - /* enter monitor again */ - if ((*env)->MonitorEnter(env, obj_this) != 0) + /* enter monitor again */ + if ((*env)->MonitorEnter(env, obj_this) != 0) + { + ThrowException(env, + "java/lang/RuntimeException", + "native pipe cannot synchronize on the object"); + goto error; + } + + /* copy buffer */ + if (nread >= 0) + { + bytes = (*env)->NewByteArray(env, len); + if (bytes == NULL) { ThrowException(env, "java/lang/RuntimeException", - "native pipe cannot synchronize on the object"); - break; + "native pipe out of memory"); + goto error; } - /* copy buffer */ - if (nread >= 0) - { - bytes = (*env)->NewByteArray(env, len); - if (bytes == NULL) - { - ThrowException(env, - "java/lang/RuntimeException", - "native pipe out of memory"); - break; - } - - /* save the data */ - (*env)->SetByteArrayRegion(env, bytes, 0, len, nbuff); - (*env)->SetObjectArrayElement(env, buffer, 0, bytes); - (*env)->DeleteLocalRef(env, bytes); - } + /* save the data */ + (*env)->SetByteArrayRegion(env, bytes, 0, len, nbuff); + (*env)->SetObjectArrayElement(env, buffer, 0, bytes); + (*env)->DeleteLocalRef(env, bytes); + } - /* done */ - free(nbuff); - if ( state >= AQUIRED ) - osl_releasePipe( npipe ); + /* done */ + free(nbuff); + if ( state >= AQUIRED ) + osl_releasePipe( npipe ); - /* exit monitor */ - (*env)->MonitorExit(env, obj_this); - return nread; - } + /* exit monitor */ + (*env)->MonitorExit(env, obj_this); + return nread; + + error: switch (state) { case GOTBUFFER: @@ -463,65 +453,64 @@ JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_wri jsize nwrite; /* number of bytes to write */ jbyte * nbuff = NULL; /* native buffer */ - while (1) + if ((*env)->MonitorEnter(env, obj_this) != 0) { - if ((*env)->MonitorEnter(env, obj_this) != 0) + ThrowException(env, + "java/lang/RuntimeException", + "native pipe cannot synchronize on the object"); + goto error; + } + state = INMONITOR; + + /* check connection state */ + npipe = getPipe(env, obj_this); + if ((*env)->ExceptionOccurred(env) != NULL) + goto error; + if (npipe == NULL) + { + ThrowException(env, + "com/sun/star/io/IOException", + "native pipe is not connected"); + goto error; + } + + nwrite = (*env)->GetArrayLength(env, buffer); + if (nwrite > 0) + { + nbuff = (*env)->GetByteArrayElements(env, buffer, NULL); + if (nbuff == NULL) { ThrowException(env, "java/lang/RuntimeException", - "native pipe cannot synchronize on the object"); - break; + "native pipe out of memory"); + goto error; } - state = INMONITOR; + state = GOTBUFFER; - /* check connection state */ - npipe = getPipe(env, obj_this); - if ((*env)->ExceptionOccurred(env) != NULL) - break; - if (npipe == NULL) + (*env)->MonitorExit(env, obj_this); + /* writing */ + count = osl_writePipe(npipe, nbuff, nwrite); + if ((*env)->MonitorEnter(env, obj_this) != 0) { ThrowException(env, - "com/sun/star/io/IOException", - "native pipe is not connected"); - break; + "java/lang/RuntimeException", + "native pipe cannot synchronize on the object"); + goto error; } - - nwrite = (*env)->GetArrayLength(env, buffer); - if (nwrite > 0) + if (count != nwrite) { - nbuff = (*env)->GetByteArrayElements(env, buffer, NULL); - if (nbuff == NULL) - { - ThrowException(env, - "java/lang/RuntimeException", - "native pipe out of memory"); - break; - } - state = GOTBUFFER; - - (*env)->MonitorExit(env, obj_this); - /* writing */ - count = osl_writePipe(npipe, nbuff, nwrite); - if ((*env)->MonitorEnter(env, obj_this) != 0) - { - ThrowException(env, - "java/lang/RuntimeException", - "native pipe cannot synchronize on the object"); - break; - } - if (count != nwrite) - { - ThrowException(env, - "com/sun/star/io/IOException", - "native pipe is failed to write"); - break; - } + ThrowException(env, + "com/sun/star/io/IOException", + "native pipe is failed to write"); + goto error; } - /* done */ - (*env)->ReleaseByteArrayElements(env, buffer, nbuff, JNI_ABORT); - (*env)->MonitorExit(env, obj_this); - return; } + /* done */ + (*env)->ReleaseByteArrayElements(env, buffer, nbuff, JNI_ABORT); + (*env)->MonitorExit(env, obj_this); + return; + + error: switch (state) { case GOTBUFFER: @@ -544,5 +533,7 @@ JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_wri JNIEXPORT void JNICALL Java_com_sun_star_lib_connections_pipe_PipeConnection_flushJNI (JNIEnv * env, jobject obj_this) { + (void) env; /* not used */ + (void) obj_this; /* not used */ return; } |