Changeset 1552 for trunk/bindings


Ignore:
Timestamp:
07/10/10 03:38:14 (20 months ago)
Author:
Tobias Richter
Message:

Error reporting may have failed due to memory corruption or whatever
but was masked by threading problems. If we get a fresh class reference
every time we want to throw an error that helps. refs #219

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bindings/java/native/NexusFile.c

    r1543 r1552  
    3737   the integer first before it can do useful work. 
    3838 
    39  
    4039*/ 
    4140#include <stdlib.h> 
     
    5352#endif 
    5453 
    55 //#define DEBUG  
    56 #ifdef DEBUG 
    57 static FILE *fd = NULL; 
    58 #endif 
    59  
    60 static jclass nexusException;  // Global variable 
     54#define DEBUG  
     55 
    6156static JavaVM *jvm;  // Global variable 
    6257 
    6358JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { 
    6459    JNIEnv *env; 
     60    jclass nexusException;   
    6561 
    6662    jint ret = (*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_1); 
     
    6864    assert(ret == JNI_OK); 
    6965 
    70     // Find and store the NexusException class for use in JapiError 
     66    jvm = vm; 
     67 
    7168    nexusException = (*env)->FindClass(env,"org/nexusformat/NexusException"); 
    72     assert(nexusException); 
    73  
    74     jvm = vm; 
     69    if (nexusException) { 
     70        fprintf(stderr, "cannot find NexusException - this will not work. Terminating."); 
     71        assert(nexusException); 
     72    } 
    7573 
    7674    return JNI_VERSION_1_1; 
     
    8482  --------------------------------------------------------------------------*/ 
    8583static void JapiError(void *pData, char *text) { 
    86     // better ignore the env passed in via pData, it is unsafe due to #219 
    87     JNIEnv *env; 
     84    JNIEnv *env = pData; 
     85    jclass nexusException;   
    8886 
    8987#ifdef DEBUG 
    90     fprintf(fd,"JapiError called with: %s\n", text);  
    91 #endif 
    92  
    93     (*jvm)->AttachCurrentThread (jvm, (void **) &env, NULL); 
     88    fprintf(stderr,"JapiError called with: %s\n", text);  
     89#endif 
     90 
     91    /* (*jvm)->AttachCurrentThread (jvm, (void **) &env, NULL); */ 
    9492 
    9593    if (env == NULL) { 
     
    9896    } 
    9997 
     98    // Find and store the NexusException class for use in JapiError 
     99    nexusException = (*env)->FindClass(env,"org/nexusformat/NexusException"); 
    100100    (*env)->ThrowNew(env, nexusException, text); 
    101101}  
     
    111111    int iRet; 
    112112 
    113 #ifdef DEBUG 
    114     if(fd == NULL) 
    115     { 
    116         fd = fopen("jnexusdebug.dat","w"); 
    117     } 
    118 #endif     
    119113    /* set error handler */ 
    120114    NXMSetTError(env,JapiError); 
    121115 
    122116    /* extract the filename as a C char* */ 
    123     fileName = (char *) (*env)->GetStringUTFChars(env,filename,0);     
     117    fileName = (char *) (*env)->GetStringUTFChars(env, filename, 0);     
    124118     
    125119    /* call NXopen */ 
    126120#ifdef DEBUG 
    127     fprintf(fd,"Calling NXopen on %s, with %d\n", fileName,access); 
     121    fprintf(stderr,"Calling NXopen on %s, with %d\n", fileName, access); 
    128122#endif 
    129123    iRet = NXopen(fileName,access,&handle); 
    130124 
    131125#ifdef DEBUG 
    132     fprintf(fd,"Handle %d allocated for %s\n", handle, fileName); 
     126    fprintf(stderr,"Handle allocated for %s\n", fileName); 
    133127#endif 
    134128 
     
    163157    HHRemoveHandle(handle); 
    164158 
    165  
    166159    /* call NXflush */ 
    167160    iRet = NXflush(&nxhandle); 
     
    191184    nxhandle =  (NXhandle)HHGetPointer(handle); 
    192185#ifdef DEBUG 
    193     fprintf(fd,"closing handle %d, nxhandle %d\n", handle, nxhandle); 
     186    fprintf(stderr,"closing handle %d, nxhandle %d\n", handle, nxhandle); 
    194187#endif 
    195188 
     
    251244    if(iRet != NX_OK) 
    252245    { 
    253       fprintf(fd,"Cleanup code called after raising Exception\n"); 
     246      fprintf(stderr,"Cleanup code called after raising Exception\n"); 
    254247    } 
    255248#endif 
     
    282275    if(iRet != NX_OK) 
    283276    { 
    284       fprintf(fd,"Cleanup code called after raising Exception\n"); 
     277      fprintf(stderr,"Cleanup code called after raising Exception\n"); 
    285278    } 
    286279#endif 
     
    312305    if(iRet != NX_OK) 
    313306    { 
    314       fprintf(fd,"Cleanup code called after raising Exception\n"); 
     307      fprintf(stderr,"Cleanup code called after raising Exception\n"); 
    315308    } 
    316309#endif 
     
    480473 
    481474#ifdef DEBUG 
    482     fprintf(fd,"Compressing at %d with type %d\n", nxhandle, comp_type); 
     475    fprintf(stderr,"Compressing at %d with type %d\n", nxhandle, comp_type); 
    483476#endif 
    484477    iRet = NXcompress(nxhandle,comp_type); 
     
    510503    if(iRet != NX_OK) 
    511504    { 
    512         HEprint(fd,0); 
     505        HEprint(stderr,0); 
    513506    } 
    514507#endif 
     
    626619    if(iRet != NX_OK) 
    627620    { 
    628         HEprint(fd,0); 
     621        HEprint(stderr,0); 
    629622    } 
    630623#endif 
     
    686679    iargs = (*env)->GetIntArrayElements(env,args,0); 
    687680#ifdef DEBUG 
    688     fprintf(fd,"nxgetattr converted types \n"); 
     681    fprintf(stderr,"nxgetattr converted types \n"); 
    689682#endif 
    690683 
     
    692685    iType = iargs[1]; 
    693686#ifdef DEBUG 
    694     fprintf(fd,"nxgetattr: iLen %d, iType: %d\n",iLen, iType); 
     687    fprintf(stderr,"nxgetattr: iLen %d, iType: %d\n",iLen, iType); 
    695688#endif 
    696689 
     
    699692    iargs[1] = iType; 
    700693#ifdef DEBUG 
    701     fprintf(fd,"nxgetattr cleaning up \n"); 
     694    fprintf(stderr,"nxgetattr cleaning up \n"); 
    702695#endif 
    703696 
     
    13101303   } 
    13111304} 
    1312  
    1313  
    1314  
    1315  
    1316  
    1317  
    1318  
    1319  
    1320  
Note: See TracChangeset for help on using the changeset viewer.