IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 10892


Ignore:
Timestamp:
Jan 3, 2007, 11:53:56 AM (19 years ago)
Author:
jhoblitt
Message:

remove inclusion of psAssert.h and use of ps_* assertions (they potentially allocate memory)
remove inclusion of psLogMsg.h (unused)
rework PS_MEM_ABORT to call psErrorStackPrint()
add PS_MEM_ERROR
replace all usage of psError() with PS_MEM_ERROR

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/jch-memory/psLib/src/sys/psMemory.c

    r10888 r10892  
    88*  @author Robert Lupton, Princeton University
    99*
    10 *  @version $Revision: 1.88.2.4 $ $Name: not supported by cvs2svn $
    11 *  @date $Date: 2007-01-03 04:46:32 $
     10*  @version $Revision: 1.88.2.5 $ $Name: not supported by cvs2svn $
     11*  @date $Date: 2007-01-03 21:53:56 $
    1212*
    1313*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2424#include "psMemory.h"
    2525#include "psError.h"
    26 #include "psAssert.h"
    27 #include "psLogMsg.h"
     26
    2827#include "psBitSet.h"
    2928#include "psFits.h"
     
    5150// this and would deadlock while trying to allocate memory.
    5251#define PS_MEM_ABORT(name, ...) \
    53 fprintf(stderr, "Memory Management Error. This error can not be logged.\n") ;\
     52P_PS_MEM_ABORT(__FILE__, __LINE__, __func__, name, __VA_ARGS__)
     53
     54#define P_PS_MEM_ABORT(filename, lineno, func, name, ...) \
     55fprintf(stderr, "%s (%s:%d) ", func, filename, lineno); \
    5456fprintf(stderr, __VA_ARGS__);\
     57psErrorStackPrint(stderr, "\nAborting.  Error stack:"); \
    5558fprintf(stderr, "\n");\
    5659abort();
     60
     61#define PS_MEM_ERROR(code, new, ...) \
     62P_PS_MEM_ERROR(__FILE__, __LINE__, __func__, code, new, __VA_ARGS__)
     63
     64#define P_PS_MEM_ERROR(filename, lineno, func, code, new, ...) \
     65fprintf(stderr, "%s (%s:%d) ", func, filename, lineno); \
     66fprintf(stderr, __VA_ARGS__);\
     67fprintf(stderr, "\n");
    5768
    5869static psS32 checkMemBlock(const psMemBlock* m, const char *funcName);
     
    109120{
    110121    if (ptr->refCounter < 1) {
    111         psError(PS_ERR_MEMORY_CORRUPTION, false,
    112                 _("Block %lu, allocated at %s:%d, freed multiple times at %s:%d."),
    113                 (unsigned long)ptr->id, ptr->file, ptr->lineno, file, lineno);
     122        PS_MEM_ERROR(PS_ERR_MEMORY_CORRUPTION, false,
     123                     _("Block %lu, allocated at %s:%d, freed multiple times at %s:%d."),
     124                     (unsigned long)ptr->id, ptr->file, ptr->lineno, file, lineno);
    114125    }
    115126
     
    131142
    132143    if (m == NULL) {
    133         psError(PS_ERR_MEMORY_CORRUPTION, true,
    134                 _("NULL memory block found."));
     144        PS_MEM_ERROR(PS_ERR_MEMORY_CORRUPTION, true,
     145                     _("NULL memory block found."));
    135146        return 1;
    136147    }
     
    138149    if (m->refCounter == 0) {
    139150        // using an unreferenced block of memory, are you?
    140         psError(PS_ERR_MEMORY_CORRUPTION, true,
    141                 _("Memory block %lu was freed but still being used."),
    142                 (unsigned long)m->id);
     151        PS_MEM_ERROR(PS_ERR_MEMORY_CORRUPTION, true,
     152                     _("Memory block %lu was freed but still being used."),
     153                     (unsigned long)m->id);
    143154        return 1;
    144155    }
    145156
    146157    if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC) {
    147         psError(PS_ERR_MEMORY_CORRUPTION, true,
    148                 _("Memory block %lu is corrupted; buffer underflow detected."),
    149                 (unsigned long)m->id);
     158        PS_MEM_ERROR(PS_ERR_MEMORY_CORRUPTION, true,
     159                     _("Memory block %lu is corrupted; buffer underflow detected."),
     160                     (unsigned long)m->id);
    150161        return 1;
    151162    }
    152163    if (*(psPtr *)((int8_t *) (m + 1) + m->userMemorySize) != P_PS_MEMMAGIC) {
    153         psError(PS_ERR_MEMORY_CORRUPTION, true,
    154                 _("Memory block %lu is corrupted; buffer overflow detected."),
    155                 (unsigned long)m->id);
     164        PS_MEM_ERROR(PS_ERR_MEMORY_CORRUPTION, true,
     165                     _("Memory block %lu is corrupted; buffer overflow detected."),
     166                     (unsigned long)m->id);
    156167        return 1;
    157168    }
     
    709720                    psPtr ptr)
    710721{
    711     PS_ASSERT_PTR(ptr, false);
     722    //    PS_ASSERT_PTR(ptr, false);
    712723
    713724    switch(type) {
     
    716727            return true;
    717728        else {
    718             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    719                     "Incorrect pointer.  Datatypes do not match.\n");
     729            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     730                         "Incorrect pointer.  Datatypes do not match.\n");
    720731            break;
    721732        }
     
    724735            return true;
    725736        else {
    726             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    727                     "Incorrect pointer.  Datatypes do not match.\n");
     737            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     738                         "Incorrect pointer.  Datatypes do not match.\n");
    728739            break;
    729740        }
     
    732743            return true;
    733744        else {
    734             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    735                     "Incorrect pointer.  Datatypes do not match.\n");
     745            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     746                         "Incorrect pointer.  Datatypes do not match.\n");
    736747            break;
    737748        }
     
    740751            return true;
    741752        else {
    742             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    743                     "Incorrect pointer.  Datatypes do not match.\n");
     753            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     754                         "Incorrect pointer.  Datatypes do not match.\n");
    744755            break;
    745756        }
     
    748759            return true;
    749760        else {
    750             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    751                     "Incorrect pointer.  Datatypes do not match.\n");
     761            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     762                         "Incorrect pointer.  Datatypes do not match.\n");
    752763            break;
    753764        }
     
    756767            return true;
    757768        else {
    758             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    759                     "Incorrect pointer.  Datatypes do not match.\n");
     769            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     770                         "Incorrect pointer.  Datatypes do not match.\n");
    760771            break;
    761772        }
     
    764775            return true;
    765776        else {
    766             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    767                     "Incorrect pointer.  Datatypes do not match.\n");
     777            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     778                         "Incorrect pointer.  Datatypes do not match.\n");
    768779            break;
    769780        }
     
    772783            return true;
    773784        else {
    774             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    775                     "Incorrect pointer.  Datatypes do not match.\n");
     785            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     786                         "Incorrect pointer.  Datatypes do not match.\n");
    776787            break;
    777788        }
     
    780791            return true;
    781792        else {
    782             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    783                     "Incorrect pointer.  Datatypes do not match.\n");
     793            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     794                         "Incorrect pointer.  Datatypes do not match.\n");
    784795            break;
    785796        }
     
    788799            return true;
    789800        else {
    790             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    791                     "Incorrect pointer.  Datatypes do not match.\n");
     801            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     802                         "Incorrect pointer.  Datatypes do not match.\n");
    792803            break;
    793804        }
     
    796807            return true;
    797808        else {
    798             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    799                     "Incorrect pointer.  Datatypes do not match.\n");
     809            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     810                         "Incorrect pointer.  Datatypes do not match.\n");
    800811            break;
    801812        }
     
    804815            return true;
    805816        else {
    806             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    807                     "Incorrect pointer.  Datatypes do not match.\n");
     817            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     818                         "Incorrect pointer.  Datatypes do not match.\n");
    808819            break;
    809820        }
     
    812823            return true;
    813824        else {
    814             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    815                     "Incorrect pointer.  Datatypes do not match.\n");
     825            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     826                         "Incorrect pointer.  Datatypes do not match.\n");
    816827            break;
    817828        }
     
    820831            return true;
    821832        else {
    822             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    823                     "Incorrect pointer.  Datatypes do not match.\n");
     833            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     834                         "Incorrect pointer.  Datatypes do not match.\n");
    824835            break;
    825836        }
     
    828839            return true;
    829840        else {
    830             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    831                     "Incorrect pointer.  Datatypes do not match.\n");
     841            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     842                         "Incorrect pointer.  Datatypes do not match.\n");
    832843            break;
    833844        }
     
    836847            return true;
    837848        else {
    838             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    839                     "Incorrect pointer.  Datatypes do not match.\n");
     849            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     850                         "Incorrect pointer.  Datatypes do not match.\n");
    840851            break;
    841852        }
     
    844855            return true;
    845856        else {
    846             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    847                     "Incorrect pointer.  Datatypes do not match.\n");
     857            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     858                         "Incorrect pointer.  Datatypes do not match.\n");
    848859            break;
    849860        }
     
    852863            return true;
    853864        else {
    854             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    855                     "Incorrect pointer.  Datatypes do not match.\n");
     865            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     866                         "Incorrect pointer.  Datatypes do not match.\n");
    856867            break;
    857868        }
     
    860871            return true;
    861872        else {
    862             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    863                     "Incorrect pointer.  Datatypes do not match.\n");
     873            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     874                         "Incorrect pointer.  Datatypes do not match.\n");
    864875            break;
    865876        }
     
    868879            return true;
    869880        else {
    870             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    871                     "Incorrect pointer.  Datatypes do not match.\n");
     881            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     882                         "Incorrect pointer.  Datatypes do not match.\n");
    872883            break;
    873884        }
     
    876887            return true;
    877888        else {
    878             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    879                     "Incorrect pointer.  Datatypes do not match.\n");
     889            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     890                         "Incorrect pointer.  Datatypes do not match.\n");
    880891            break;
    881892        }
     
    884895            return true;
    885896        else {
    886             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    887                     "Incorrect pointer.  Datatypes do not match.\n");
     897            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     898                         "Incorrect pointer.  Datatypes do not match.\n");
    888899            break;
    889900        }
     
    892903            return true;
    893904        else {
    894             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    895                     "Incorrect pointer.  Datatypes do not match.\n");
     905            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     906                         "Incorrect pointer.  Datatypes do not match.\n");
    896907            break;
    897908        }
     
    900911            return true;
    901912        else {
    902             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    903                     "Incorrect pointer.  Datatypes do not match.\n");
     913            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     914                         "Incorrect pointer.  Datatypes do not match.\n");
    904915            break;
    905916        }
     
    908919            return true;
    909920        else {
    910             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    911                     "Incorrect pointer.  Datatypes do not match.\n");
     921            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     922                         "Incorrect pointer.  Datatypes do not match.\n");
    912923            break;
    913924        }
     
    916927            return true;
    917928        else {
    918             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    919                     "Incorrect pointer.  Datatypes do not match.\n");
     929            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     930                         "Incorrect pointer.  Datatypes do not match.\n");
    920931            break;
    921932        }
     
    924935            return true;
    925936        else {
    926             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    927                     "Incorrect pointer.  Datatypes do not match.\n");
     937            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     938                         "Incorrect pointer.  Datatypes do not match.\n");
    928939            break;
    929940        }
     
    932943            return true;
    933944        else {
    934             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    935                     "Incorrect pointer.  Datatypes do not match.\n");
     945            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     946                         "Incorrect pointer.  Datatypes do not match.\n");
    936947            break;
    937948        }
     
    940951            return true;
    941952        else {
    942             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    943                     "Incorrect pointer.  Datatypes do not match.\n");
     953            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     954                         "Incorrect pointer.  Datatypes do not match.\n");
    944955            break;
    945956        }
     
    948959            return true;
    949960        else {
    950             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    951                     "Incorrect pointer.  Datatypes do not match.\n");
     961            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     962                         "Incorrect pointer.  Datatypes do not match.\n");
    952963            break;
    953964        }
     
    956967            return true;
    957968        else {
    958             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    959                     "Incorrect pointer.  Datatypes do not match.\n");
     969            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     970                         "Incorrect pointer.  Datatypes do not match.\n");
    960971            break;
    961972        }
     
    964975            return true;
    965976        else {
    966             psError(PS_ERR_BAD_PARAMETER_VALUE, false,
    967                     "Incorrect pointer.  Datatypes do not match.\n");
     977            PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_VALUE, false,
     978                         "Incorrect pointer.  Datatypes do not match.\n");
    968979            break;
    969980        }
    970981    default:
    971         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    972                 "Invalid datatype specified.\n");
     982        PS_MEM_ERROR(PS_ERR_BAD_PARAMETER_TYPE, true,
     983                     "Invalid datatype specified.\n");
    973984    }
    974985    return false;
Note: See TracChangeset for help on using the changeset viewer.