Changeset 212fc04 in git for omalloc/omDebug.c


Ignore:
Timestamp:
Nov 22, 1999, 7:13:00 PM (24 years ago)
Author:
Olaf Bachmann <obachman@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
6ea5825fc0e0bfabf56883aee9dac9b5bbe415fe
Parents:
e6908a0f43ea328a1aa0c3942e8d309db7de26d5
Message:
* as we go along


git-svn-id: file:///usr/local/Singular/svn/trunk@3878 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • omalloc/omDebug.c

    re6908a0 r212fc04  
    44 *  Author:  obachman@mathematik.uni-kl.de (Olaf Bachmann)
    55 *  Created: 11/99
    6  *  Version: $Id: omDebug.c,v 1.1.1.1 1999-11-18 17:45:53 obachman Exp $
     6 *  Version: $Id: omDebug.c,v 1.2 1999-11-22 18:12:58 obachman Exp $
    77 *******************************************************************/
    88#include "omConfig.h"
     
    1212#include "omDebug.h"
    1313
    14 static int omdCheckBinAddrSize(void* addr, omBin bin, size_t size,
    15                                int level, const char* fn, const int l);
    16 static int omdPrintBinError(const char* msg, void* addr, size_t size,omBin bin,
    17                             const char* fn, const int l);
    18 static const char* omdTestBinAddrSize(void* addr, omBin bin, size_t size,
    19                                       int level);
     14static int omdCheckBinAddrSize(void* addr, size_t size, int level);
     15static int omdPrintBinError(const char* msg, void* addr, size_t size,
     16                            omBin bin);
     17static const char* omdTestBinAddrSize(void* addr, size_t size, int level,
     18                                      omBin *bin);
    2019static const char* omdTestBin(omBin bin, int level);
    2120static const char* omdTestBinPage(omBinPage page, int level);
    22 static int   omdIsKnownBin(omBin bin);
     21static int   omdIsKnownTopBin(omBin bin);
    2322
    2423/*******************************************************************
     
    2726 * 
    2827 *******************************************************************/
    29 int omdCheckBinAddr(void* addr, omBin bin, int level,
    30                     const char* fn, const int l)
    31 {
    32   if (! omdCheckBinAddrSize(addr, bin, bin->sizeW*SIZEOF_LONG, level, fn, l))
     28int omdCheckBinAddr(void* addr, int level)
     29{
     30  return omdCheckBinAddrSize(addr, 0, level);
     31}
     32
     33int omdCheckBlockAddr(void* addr, size_t size, int level)
     34{
     35  if (size == 0)
     36  {
     37    omError("0 size");
    3338    return 0;
    34   return omdCheckBins(level - 2, fn, l);
    35 }
    36 
    37 int omdCheckBlockAddr(void* addr, size_t size, int level,
    38                       const char* fn, const int l)
    39 {
    40   omBin bin = omSize2Bin(size);
    41   if (bin != om_LargeBin &&
    42       ! omdCheckBinAddrSize(addr, bin, size, level, fn, l))
    43     return 0;
    44   return omdCheckBins(level - 2, fn, l);
    45 }
    46 
    47 int omdCheckChunkAddr(void* addr, int level, const char* fn, const int l)
     39  }
     40  if (size <= OM_MAX_BLOCK_SIZE)
     41    return omdCheckBinAddrSize(addr, size, level);
     42  else
     43    return 1;
     44}
     45
     46int omdCheckChunkAddr(void* addr, int level)
    4847{
    4948  omBinPage page;
    5049  addr = addr - SIZEOF_OM_ALIGNMENT;
    5150  page = *((omBinPage*) addr);
    52   if (page != om_LargePage &&
    53       ! omdCheckBinAddr(addr, omBinOfPage(page), level, fn, l))
    54     return 0;
    55   return omdCheckBins(level - 2, fn, l);
     51  if (page != om_LargePage)
     52    return omdCheckBinAddrSize(addr, -1, level);
     53  else
     54    return 1;
    5655}
    5756   
     
    6160 * 
    6261 *******************************************************************/
    63 static int omdIsKnownBin(omBin bin)
     62static int omdIsKnownTopBin(omBin bin)
    6463{
    6564  int i = 0;
     
    8180}
    8281
    83 int omdCheckBin(omBin bin, int level, const char* fn, const int l)
     82int omdCheckBin(omBin bin, int level)
    8483{
    8584  const char* msg = omdTestBin(bin, level);
    8685  if (msg != NULL)
    8786  {
    88     if (fn != NULL) omdPrintBinError(msg, NULL, 0, bin, fn, l);
     87    omdPrintBinError(msg, NULL, 0, bin);
    8988    return 0;
    9089  }
     
    9291}
    9392
    94 int omdCheckBins(int level, const char* fn, const int l)
     93int omdCheckBins(int level)
    9594{
    9695  if (level <= 0)
     
    106105    for (i=0; i<= OM_MAX_BIN_INDEX; i++)
    107106    {
    108       if (! omdCheckBin(&om_StaticBin[i], level, fn, l)) return 0;
     107      if (! omdCheckBin(&om_StaticBin[i], level)) return 0;
    109108    }
    110109    s_bin = om_SpecBin;
    111110    while (s_bin != NULL)
    112111    {
    113       if (! omdCheckBin(s_bin->bin, level, fn, l)) return 0;
     112      if (! omdCheckBin(s_bin->bin, level)) return 0;
    114113      s_bin = s_bin->next;
    115114    }
     
    124123 *******************************************************************/
    125124
    126 void* omdCheckAllocBin(omBin bin, const int zero, int level,
    127                        const char* fn, const int l)
     125void* omdCheckAllocBin(omBin bin, const int zero, int level)
    128126{
    129127  void* res;
    130128 
    131   omdCheckBins(level-2, fn, l);
     129  omdCheckBins(level-2);
    132130
    133131  if (zero)
     
    136134    __omTypeAllocBin(void*, res, bin);
    137135
    138   omdCheckBinAddr(res, bin, level-1,fn, l);
    139   omdCheckBins(level-2, fn, l);
     136  omdCheckBinAddr(res, level-1);
     137  omdCheckBins(level-2);
    140138
    141139  return res;
    142140}
    143141 
    144 void  omdCheckFreeBin(void* addr, omBin bin,
    145                       int level, const char* fn, const int l)
    146 {
    147   omdCheckBins(level-2, fn, l);
    148 
    149   if (omdCheckBinAddr(addr, bin, level, fn, l))
     142void  omdCheckFreeBin(void* addr, int level)
     143{
     144  omdCheckBins(level-2);
     145
     146  if (omdCheckBinAddr(addr, level))
    150147    __omFreeBin(addr);
    151148
    152   omdCheckBin(bin, level - 1, fn, l);
    153   omdCheckBins(level - 2, fn, l);
    154 }
    155 
    156 void* omdCheckAllocBlock(size_t size, const int zero,
    157                         int level, const char* fn, const int l)
     149  omdCheckBins(level - 2);
     150}
     151
     152void* omdCheckAllocBlock(size_t size, const int zero, int level)
    158153{
    159154  void* res;
     
    161156  if (level > 0 && size <= 0)
    162157  {
    163     if (fn != NULL) omdPrintBinError("requested AllocBlock size <= 0",
    164                                      NULL, size, NULL, fn, l);
     158    omdPrintBinError("requested AllocBlock size <= 0",
     159                     NULL, size, NULL);
    165160    size = 1;
    166161  }
    167162
    168   omdCheckBins(level-2, fn, l);
     163  omdCheckBins(level-2);
    169164
    170165  if (zero)
     
    173168    __omTypeAllocBlock(void*, res, size);
    174169 
    175   omdCheckBlockAddr(res, size, level - 1, fn, l);
    176   omdCheckBins(level - 2, fn, l);
     170  omdCheckBlockAddr(res, size, level - 1);
     171  omdCheckBins(level - 2);
    177172
    178173  return res;
    179174}
    180175
    181 void omdCheckFreeBlock(void* addr, size_t size,
    182                        int level, const char* fn, const int l)
    183 {
    184   omdCheckBins(level - 2, fn, l);
    185   if (! omdCheckBlockAddr(addr, size, level, fn, l)) return;
     176void omdCheckFreeBlock(void* addr, size_t size, int level)
     177{
     178  omdCheckBins(level - 2);
     179  if (! omdCheckBlockAddr(addr, size, level)) return;
    186180 
    187181  __omFreeBlock(addr, size);
    188182 
    189   omdCheckBins(level - 2, fn, l);
    190 }
    191 
    192 
    193 void* omdCheckAllocChunk(size_t size, const int zero,
    194                         int level, const char* fn, const int l)
     183  omdCheckBins(level - 2);
     184}
     185
     186
     187void* omdCheckAllocChunk(size_t size, const int zero, int level)
    195188{
    196189  void* res;
     
    198191  if (level > 0 && size <= 0)
    199192  {
    200     if (fn != NULL) omdPrintBinError("requested AllocBlock size <= 0",
    201                                      NULL, size, NULL, fn, l);
     193    omdPrintBinError("requested AllocBlock size <= 0",
     194                     NULL, size, NULL);
    202195    size = 1;
    203196  }
    204   omdCheckBins(level - 2, fn, l);
     197  omdCheckBins(level - 2);
    205198
    206199  if (zero)
     
    209202    __omTypeAllocChunk(void*, res, size);
    210203 
    211   omdCheckChunkAddr(res, level - 1, fn, l);
    212   omdCheckBins(level - 2, fn, l);
     204  omdCheckChunkAddr(res, level - 1);
     205  omdCheckBins(level - 2);
    213206
    214207  return res;
    215208}
    216209
    217 void omdCheckFreeChunk(void* addr, int level, const char* fn, const int l)
    218 {
    219   if (! omdCheckChunkAddr(addr, level, fn, l)) return;
     210void omdCheckFreeChunk(void* addr, int level)
     211{
     212  if (! omdCheckChunkAddr(addr, level)) return;
    220213 
    221214  __omFreeChunk(addr);
    222215 
    223   omdCheckBins(level - 2, fn, l);
     216  omdCheckBins(level - 2);
    224217}
    225218
     
    230223 * 
    231224 *******************************************************************/
    232 static int omdPrintBinError(const char* msg, void* addr, size_t size,omBin bin,
    233                             const char* fn, const int l)
     225static int omdPrintBinError(const char* msg, void* addr, size_t size,omBin bin)
    234226{
    235227  fprintf(stderr,
    236           "***BinError:
    237 %s: occured for addr:%p (%d) bin:%p (%ld:%ld) in %s:%d\n",
    238           msg, addr, size, (void*) bin,
     228          "for addr:%p (%d) bin:%p (%ld:%ld)\n",
     229          addr, size, (void*) bin,
    239230          (bin != NULL ? bin->max_blocks : 0),
    240           (bin != NULL ? bin->sizeW : 0), fn, l);
     231          (bin != NULL ? bin->sizeW : 0));
     232  fflush(stderr);
    241233  return 0;
    242234}
    243235
    244 static int omdCheckBinAddrSize(void* addr, omBin bin, size_t size,
    245                                int level, const char* fn, const int l)
    246 {
    247   const char* msg = omdTestBinAddrSize(addr, bin, size, level);
     236static int omdCheckBinAddrSize(void* addr, size_t size, int level)
     237{
     238  omBin bin = NULL;
     239  const char* msg = omdTestBinAddrSize(addr, size, level, &bin);
    248240  if (msg != NULL)
    249     return omdPrintBinError(msg, addr, size, bin, fn, l);
     241    return omdPrintBinError(msg, addr, size, bin);
    250242  else
    251243    return 1;
     
    255247/* Check that addr is activ (used) adr of bin */
    256248static const char*
    257 omdTestBinAddrSize(void* addr, omBin bin, size_t size, int level)
    258 {
     249omdTestBinAddrSize(void* addr, size_t size, int level, omBin* r_bin)
     250{
     251  omBin bin;
    259252  omBinPage page;
    260253  omBin h_bin;
    261254  const char* msg;
    262255 
    263 
    264256  if (level <= 0) return NULL;
    265257 
    266258  if (addr == NULL) return omError("NULL addr");
     259
     260  if (size > OM_MAX_BLOCK_SIZE) return NULL;
     261
     262  bin = omGetTopBinOfAddr(addr);
     263 
    267264  if (bin == NULL) return omError("NULL Bin");
    268265
    269   if (! omdIsKnownBin(bin))
     266  if (! omdIsKnownTopBin(bin))
    270267    return omError("Addr not from Bin (Bin unknown)");
     268  *r_bin = bin;
    271269 
    272270  if ((msg = omdTestBin(bin, level - 1)) != NULL) return msg;
    273271
    274272  // check for right bin
    275   if (omIsStaticBin(bin))
    276     h_bin = omSize2Bin(size);
    277   else
    278     h_bin = omGetSpecBin(size);
    279   if (bin != h_bin) return omError("size is wrong");
    280   if (! omIsStaticBin(bin)) omUnGetSpecBin(&h_bin);
     273  if (size > 0)
     274  {
     275    if (omIsStaticBin(bin))
     276      h_bin = omSize2Bin(size);
     277    else
     278      h_bin = omGetSpecBin(size);
     279    if (bin != h_bin) return omError("size is wrong");
     280    if (! omIsStaticBin(bin)) omUnGetSpecBin(&h_bin);
     281  }
    281282
    282283  // check page
     
    285286 
    286287  // look that page is in queue of pages of this Bin
    287   h_bin = omBinOfPage(page);
     288  h_bin = omGetBinOfPage(page);
     289  *r_bin = h_bin;
    288290  if ( ! omIsOnGList(h_bin->last_page, prev, page))
    289291    return omError("page of addr not from this Bin");
     
    347349  {
    348350    void* current = page->current;
     351    int i = 1;
    349352    if (current != NULL &&
    350353        omListLength(current) != bin->max_blocks - page->used_blocks - 1)
     
    362365           != 0)
    363366        return omError("current has unaligned adress");
    364       current = *((void**) (current + SIZEOF_VOIDP));
     367      current = *((void**) current);
     368      i++;
    365369    }
    366370  }
     
    379383  if (bin == NULL) return omError("NULL Bin");
    380384
    381   if (! omdIsKnownBin(bin)) return omError("Bin unknown");
     385  if (! omdIsKnownTopBin(bin)) return omError("TopBin unknown");
    382386 
    383387  if (level > 2 &&
     
    440444        return omError("Sticky of page wrong");
    441445
    442       if (omBinOfPage(page) != bin)
     446      if (omGetBinOfPage(page) != bin)
    443447        return omError("Bin of Page wrong");
    444448       
     
    457461        {
    458462          if (page->current == NULL ||
    459               page->used_blocks == 0 ||
     463              page->used_blocks < 0 ||
    460464              page->used_blocks == bin->max_blocks - 1)
    461465            return omError("used_blocks and current of upage out of sync");
Note: See TracChangeset for help on using the changeset viewer.