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

dsdperror.c

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

Generated on Sat Oct 15 11:05:40 2005 for DSDP by  doxygen 1.4.2