# 2.11BSD#431 - /usr/src/new/PORT/B/src/bint/b1mem.c

##### Functions

    denote            X
    end_init          X
    endmem            X
    freemem           X
    getmem            X
    initmem           X
    initreserve       X
    mymalloc          X
    myrealloc         X
    note              X
    regetmem          X
    term_mem          X

##### Variables

    inotel            X
    notel             X
    noting            X
    p_reserve         X

##### Macros

    Negative          X
    RESERVE           X
    RES_SIZE          X
    denote            X
    initreserve       X
    mymalloc          X
    myrealloc         X
    note              X

       1: /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
       2:
       3: /*
       4:   $Header: b1mem.c,v 1.4 85/08/27 10:55:51 timo Exp $
       5: */
       6:
       7: /* B memory management */
       8:
       9: #include "b.h"
      10: #include "b1obj.h"
      11: #include "b1mem.h"
      12: #include "b3err.h" /* For still_ok */
      13:
      14: #ifdef IBMPC
      15: #define RESERVE
      16: #endif
      17:
      18: #ifdef RESERVE
      19: Forward char *mymalloc(), *myrealloc();
      20: #else
      21: #define mymalloc malloc
      22: #define myrealloc realloc
      23: #define initreserve() 0 /* Dummy routine */
      24: #endif
      25:
      26: #ifdef ebug
      27:
      28: Hidden value notel, inotel;
      29: Visible bool noting= Yes;
      30:
      31: Hidden Procedure note(p) int p; {
      32:     if (!noting) {
      33:         value ip;
      34:         noting= Yes;
      35:         insert(ip= mk_integer(p), &notel);
      36:         release(ip);
      37:         noting= No;
      38:     }
      39: }
      40:
      41: Hidden Procedure denote(p) int p; {
      42:     if (!noting) {
      43:         value ip;
      44:         noting= Yes;
      45:         if (in(ip= mk_integer(p), notel)) {
      46:             remove(ip, &notel);
      47:             if (inotel != Vnil && in(ip, inotel))
      48:                 remove(ip, &inotel);
      49:         }
      50: #ifndef IBMPC
      51:         else syserr(MESS(600, "releasing illegally"));
      52: #endif
      53:         release(ip);
      54:         noting= No;
      55:     }
      56: }
      57:
      58: Visible Procedure initmem() {
      59:     notel= mk_elt(); noting= No;
      60:     initreserve();
      61: }
      62:
      63: Visible Procedure end_init() {
      64:     noting= Yes;
      65:     inotel= copy(notel);
      66:     noting= No;
      67: }
      68:
      69: Visible Procedure term_mem() {
      70:     int l, i; value v;
      71:     testing= noting= Yes;
      72:     l= length(notel);
      73:     if (l>length(inotel)) fprintf(stdout, "Unreleased:\n");
      74:     for(i=1; i<=l; i++) {
      75:         v= thof(i, notel);
      76:         if (!in(v, inotel))
      77:             { wri((value) intval(v), No, No, No); newline(); }
      78:     }
      79: }
      80:
      81: Visible Procedure endmem() {
      82:     release(inotel); inotel= Vnil;
      83:     release(notel); notel= Vnil;
      84: }
      85:
      86: #else !ebug
      87:
      88: #define note(p)
      89: #define denote(p)
      90:
      91: Visible Procedure initmem()
      92: {
      93:     initreserve();
      94: }
      95:
      96: Visible Procedure end_init() {}
      97: Visible Procedure term_mem() {}
      98: Visible Procedure endmem() {}
      99:
     100: #endif ebug
     101:
     102: #define Negative MESS(601, "creating value of exceedingly large size")
     103:
     104: Visible ptr getmem(syze) unsigned syze; {
     105:     ptr p;
     106:     if ((int) (syze) < 0) error(Negative);
     107:     p= (ptr) mymalloc(syze);
     108:     note(p);
     109:     if (bugs || p==Nil) printf("{%u}",syze);
     110:     if (p == Nil) memexh();
     111:     return p;
     112: }
     113:
     114: Visible Procedure regetmem(v, syze) ptr *v; unsigned syze; {
     115:     if ((int) (syze) < 0) error(Negative);
     116:     if (bugs) printf("[%u]",syze);
     117:     denote(*v);
     118:     *v= myrealloc(*v, syze);
     119:     note(*v);
     120:     if (*v == Nil) memexh();
     121: }
     122:
     123: Visible Procedure freemem(p) ptr p; {
     124:     denote(p);
     125:     free(p);
     126: }
     127:
     128: #ifdef RESERVE
     129:
     130: #define RES_SIZE 3000
     131:
     132: Hidden char *p_reserve= Nil;
     133:
     134: Hidden Procedure initreserve() {
     135:     p_reserve= malloc(RES_SIZE);
     136: }
     137:
     138: Hidden char *mymalloc(syze) unsigned syze; {
     139:     char *p;
     140:     p= malloc(syze);
     141:     if (p != Nil && p_reserve != Nil) return p;
     142:     if (p_reserve != Nil) {
     143:         free(p_reserve); p_reserve= Nil;
     144:         p= malloc(syze);
     145:         if (p != Nil) error(MESS(602, "out of memory"));
     146:     }
     147:     if (p_reserve == Nil) initreserve();
     148:     return p;
     149: }
     150:
     151: Hidden char *myrealloc(p1, syze) char *p1; unsigned syze; {
     152:     char *p;
     153:     p= realloc(p1, syze);
     154:     if (p != Nil && p_reserve != Nil) return p;
     155:     if (p_reserve != Nil) {
     156:         free(p_reserve); p_reserve= Nil;
     157:         p= realloc(p1, syze);
     158:         if (p != Nil) error(MESS(602, "out of memory"));
     159:     }
     160:     if (p_reserve == Nil) initreserve();
     161:     return p;
     162: }
     163:
     164: #endif RESERVE

#### Defined functions

denote defined in line 41; never used
end_init defined in line 96; used 1 times

- in /usr/src/new/PORT/B/src/bint/b3mai.c line 220

endmem defined in line 98; used 1 times

- in /usr/src/new/PORT/B/src/bint/b3err.c line 413

freemem defined in line 123; used 8 times

- in /usr/src/new/PORT/B/src/bint/b1nuC.c line 48
- in /usr/src/new/PORT/B/src/bint/b1val.c line 336, 545
- in /usr/src/new/PORT/B/src/bint/b3scr.c line 331, 487
- in /usr/src/new/PORT/B/src/bint/b3sou.c line 748
- in /usr/src/new/PORT/B/src/bint/b3sta.c line 269, 543

getmem defined in line 104; never used
initmem defined in line 91; used 1 times

- in /usr/src/new/PORT/B/src/bint/b3mai.c line 195

initreserve defined in line 134; never used
mymalloc defined in line 138; never used
myrealloc defined in line 151; never used
note defined in line 31; never used
regetmem defined in line 114; used 5 times

- in /usr/src/new/PORT/B/src/bint/b1tex.c line 165
- in /usr/src/new/PORT/B/src/bint/b1val.c line 161, 347, 359
- in /usr/src/new/PORT/B/src/bint/b3sta.c line 169

term_mem defined in line 97; used 1 times

- in /usr/src/new/PORT/B/src/bint/b3err.c line 412

#### Defined variables

inotel defined in line 28; used 8 times

- in line 47-48(3), 65, 73-76(2), 82(2)

notel defined in line 28; used 9 times

- in line 35, 45-46(2), 59, 65, 72-75(2), 83(2)

noting defined in line 29; used 10 times

- in line 32-44(5), 54-71(5)

p_reserve defined in line 132; used 11 times

- in line 135, 141-147(5), 154-160(5)

#### Defined macros

Negative defined in line 102; used 2 times

- in line 106, 115

RESERVE defined in line 15; used 2 times

- in line 18, 128

RES_SIZE defined in line 130; used 1 times

- in line 135

denote defined in line 89; used 2 times

- in line 117, 124

initreserve defined in line 23; used 4 times

- in line 60, 93, 147, 160

mymalloc defined in line 21; used 2 times

- in line 19, 107

myrealloc defined in line 22; used 2 times

- in line 19, 118

note defined in line 88; used 2 times

- in line 108, 119

Last modified: 1985-08-27 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1004 |