Annotation of 43BSD/contrib/B/src/bsmall/b1mem.c, revision 1.1

1.1     ! root        1: /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */
        !             2: /* $Header: b1mem.c,v 1.2 84/07/19 14:09:35 guido Exp $ */
        !             3: 
        !             4: /* B memory management */
        !             5: 
        !             6: #include "b.h"
        !             7: #include "b1obj.h"
        !             8: #include "b1mem.h"
        !             9: 
        !            10: #define Plausible(syze) {if ((int) (syze) < 0) \
        !            11:        error("creating value of exceedingly large size");}
        !            12: 
        !            13: #define Note(p) /* note(p) */
        !            14: #define deNote(p) /* denote(p) */
        !            15: 
        !            16: Visible ptr getmem(syze) unsigned syze; {
        !            17:        ptr p;
        !            18:        Plausible(syze);
        !            19:        p= (ptr) malloc(syze);
        !            20:        Note(p);
        !            21:        if (bugs || p==Nil) printf("{%u}",syze);
        !            22:        if (p == Nil) memexh();
        !            23:        return p;
        !            24: }
        !            25: 
        !            26: Visible Procedure regetmem(v, syze) value *v; unsigned syze; {
        !            27:        Plausible(syze);
        !            28:        uniql(v);
        !            29:        if (bugs) printf("[%u]",syze);
        !            30:        criton();
        !            31:        deNote((ptr)*v);
        !            32:        *v= (value) realloc((ptr) *v, syze);
        !            33:        Note((ptr)*v);
        !            34:        critoff();
        !            35:        if ((ptr) *v == Nil) memexh();
        !            36: }
        !            37: 
        !            38: Visible Procedure freemem(p) ptr p; {
        !            39:        deNote(p);
        !            40:        free(p);
        !            41: }
        !            42: 
        !            43: value notel; bool noting=Yes;
        !            44: 
        !            45: Hidden Procedure note(p) int p; {
        !            46:        if (!noting) {
        !            47:                value ip;
        !            48:                noting= Yes;
        !            49:                insert(ip= mk_integer(p), &notel);
        !            50:                release(ip);
        !            51:                noting= No;
        !            52:        }
        !            53: }
        !            54: 
        !            55: Hidden Procedure denote(p) int p; {
        !            56:        if (!noting) {
        !            57:                value ip;
        !            58:                noting= Yes;
        !            59:                if (!in(ip= mk_integer(p), notel))
        !            60:                        syserr("releasing illegally");
        !            61:                remove(ip, &notel);
        !            62:                release(ip);
        !            63:                noting= No;
        !            64:        }
        !            65: }
        !            66: 
        !            67: /*
        !            68:  * Hack to delay (but not ignore) interrupts during realloc calls.
        !            69:  */
        !            70: 
        !            71: #include <signal.h>
        !            72: 
        !            73: Hidden int (*inthandler)();
        !            74: Hidden bool intrupted;
        !            75: 
        !            76: Hidden Procedure sighold(sig) int sig; {
        !            77:        signal(sig, sighold);
        !            78:        intrupted= Yes;
        !            79: }
        !            80: 
        !            81: Hidden Procedure criton() {
        !            82:        intrupted= No;
        !            83:        inthandler= signal(SIGINT, sighold);
        !            84: }
        !            85: 
        !            86: Hidden Procedure critoff() {
        !            87:        signal(SIGINT, inthandler);
        !            88:        if (intrupted && inthandler != SIG_IGN && inthandler != SIG_DFL)
        !            89:                (*inthandler)(SIGINT);
        !            90:        intrupted= No;
        !            91: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.