Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Globals | Related Pages

dsdperror.c

Go to the documentation of this file.
00001 #include "dsdpsys.h"
00006 #include <stdarg.h>
00007 #include <sys/types.h>
00008 
00009 
00010 #define DSDP_NULL 0
00011 #define DSDP_MAX_PATH_LEN 200
00012 
00013 static FILE      *DSDPLogInfoFile      = DSDP_NULL;
00014 static FILE *dsdp_history=0;
00015 
00016 typedef void* DSDPObject;
00017 
00018 int DSDPFError(void *vobj, const char functionname[], int linen, const char filename[], const char message[], ...)
00019 {
00020   va_list     Argp;
00021   int         urank;
00022   size_t      len;
00023   char        string[8*1024];
00024 
00025   DSDPFunctionBegin;
00026   DSDPLogInfoFile = stdout; 
00027   /*
00028  if (DSDPLogPrintInfo == DSDP_FALSE) DSDPFunctionReturn(0);
00029   if ((DSDPLogPrintInfoNull == DSDP_FALSE) && !vobj) DSDPFunctionReturn(0);
00030   */
00031   urank = 0;
00032 
00033   va_start(Argp, message);
00034   sprintf(string, "[%d] DSDP: %s(): Line %d in file %s ", urank,functionname,linen,filename);
00035   len = strlen(string);
00036 
00037 #if defined(DSDP_HAVE_VPRINTF_CHAR)
00038   vsprintf(string+len, message, (char *) Argp);
00039 #else
00040   vsprintf(string+len, message, Argp);
00041 #endif
00042   fprintf(DSDPLogInfoFile, "%s", string);
00043   fflush(DSDPLogInfoFile);
00044   if (dsdp_history) {
00045 #if defined(DSDP_HAVE_VPRINTF_CHAR)
00046     vfprintf(dsdp_history, message, (char *) Argp);
00047 #else
00048     vfprintf(dsdp_history, message, Argp);
00049 #endif
00050   }
00051   va_end(Argp);
00052   DSDPFunctionReturn(0);
00053 }
00054 
00055 
00056 void DSDPError(const char * functionname, int linen, const char filename[]){
00057   DSDPErrorPrintf("DSDP Error in function: %s , line %d of file %s \n",functionname, linen,filename);
00058   return;
00059 }
00060 typedef struct{
00061   void *mem;
00062   char fname[20];
00063   size_t size;
00064   int freed;
00065 } DSDPMemory;
00066 
00067 #define DSDPMEMMAX 1
00068 static DSDPMemory DSDPMemoryTable[DSDPMEMMAX];
00069 
00070 static long int mmmem=0;
00071 #undef __FUNCT__  
00072 #define __FUNCT__ "DSDPMMalloc"
00073 int DSDPMMalloc(const char* fname, size_t size, void** mmem){
00074   void*tt=0;
00075   DSDPFunctionBegin;
00076   if (size>0){
00077 #ifdef DSDPMATLAB
00078     tt=(void*)mxMalloc(size);
00079 #else
00080     tt=(void*)malloc(size);
00081 #endif    
00082     if (tt==NULL){ 
00083       *mmem=0;
00084       DSDPSETERR3(100,"Memory Error in routine '%s'. Cannot allocate %d bytes, %d MB\n",fname,size,(int)(size/1000000)); 
00085     }
00086     memset(tt,0,size);
00087     *mmem=tt;
00088 
00089     if (mmmem<DSDPMEMMAX){
00090       DSDPMemoryTable[mmmem].size=size;
00091       DSDPMemoryTable[mmmem].freed=0;
00092       strncpy(DSDPMemoryTable[mmmem].fname,fname,19);
00093       DSDPMemoryTable[mmmem].mem=tt;
00094     }
00095     mmmem++;
00096 
00097   } else {
00098     *mmem=0;
00099   }
00100   DSDPFunctionReturn(0);
00101 }
00102 
00103 #undef __FUNCT__  
00104 #define __FUNCT__ "DSDPFFree"
00105 int DSDPFFree(void** mmem){
00106   int j,gotit=0;
00107   DSDPFunctionBegin;
00108   if (mmem && *mmem){
00109     for (j=0;j<DSDPMEMMAX;j++){
00110       if (*mmem==DSDPMemoryTable[j].mem){
00111         DSDPMemoryTable[j].freed=1;
00112         gotit=1;
00113      }
00114     }  
00115     mmmem--;
00116 #ifdef DSDPMATLAB
00117     mxFree(*mmem);
00118 #else
00119     free(*mmem);
00120 #endif    
00121     *mmem=0;
00122     if (0==1 && gotit==0){
00123       printf(" DSDP MEMORY Error: Already Freed? \n");
00124     }
00125   }
00126   DSDPFunctionReturn(0);
00127 }
00128 
00129 void DSDPMemoryLog(){
00130   int j;
00131   DSDPFunctionBegin;
00132   for (j=0;j<DSDPMEMMAX;j++){
00133     if (DSDPMemoryTable[j].size>0 && DSDPMemoryTable[j].freed==0){
00134       printf("%d, MEMORY Not FREED: %s, %d \n",j,DSDPMemoryTable[j].fname,(int)DSDPMemoryTable[j].size);
00135     }
00136   }
00137   
00138   DSDPLogInfo(0,2,"  MEMORY MALLOC NOT FREED: %ld\n",mmmem);
00139 
00140   return;
00141 }

Generated on Fri Oct 21 14:28:36 2005 for DSDP by  doxygen 1.4.2