Annotation of researchv10no/cmd/cfront/cfront2.00/alloc.c, revision 1.1.1.1

1.1       root        1: /*ident        "@(#)ctrans:src/alloc.c 1.1.1.8" */
                      2: /**************************************************************************
                      3: 
                      4:         C++ source for cfront, the C++ compiler front-end
                      5:         written in the computer science research center of Bell Labs
                      6: 
                      7:         Copyright (c) 1984 AT&T, Inc. All Rights Reserved
                      8:         THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T, INC.
                      9: 
                     10: alloc.c:
                     11: 
                     12: *****************************************************************************/
                     13: #include "cfront.h"
                     14: #include "size.h"
                     15: 
                     16: //int Nchunk;
                     17: 
                     18: //void print_free()
                     19: //{
                     20: //     fprintf(stderr,"free store: %d bytes alloc()=%d free()=%d\n",Nfree_store,Nal//loc, Nfree);
                     21: //     fprintf(stderr,"%d chunks: %d (%d)\n",Nchunk,CHUNK,Nchunk*CHUNK);
                     22: //}
                     23: 
                     24: 
                     25: void* chunk(int i)     // get memory that is not to be freed
                     26: {
                     27:        register char* cp = malloc(i*CHUNK-8);
                     28:        if (cp == 0) {                  // no space
                     29:                free((char*)gtbl);      // get space for error message
                     30: //             if (Nspy) print_free();
                     31:                error('i',"free store exhausted");
                     32:        }
                     33: //     Nchunk += i;
                     34: //     Nfree_store += i*CHUNK;
                     35:        return cp;
                     36: }
                     37: 
                     38: /*
                     39: #ifdef __cplusplus
                     40: #include <new.h>
                     41: #define NEW_SIZE size_t
                     42: #else
                     43: #define NEW_SIZE long
                     44: #endif
                     45: */
                     46: 
                     47: // now __HAVE_SIZE_T defined in 2.0 malloc.h c++ header file
                     48: #ifdef __HAVE_SIZE_T
                     49: #include <new.h>
                     50: #define NEW_SIZE size_t
                     51: #else
                     52: #define NEW_SIZE long
                     53: #endif
                     54: 
                     55: void* operator new(NEW_SIZE sz)        // get memory that might be freed
                     56: {
                     57:        char* p = calloc((unsigned)sz,1);
                     58: 
                     59: //fprintf(stderr,"alloc(%d)->%d\n",sz,p);
                     60:        if (p == 0) {                   // no space
                     61:                free((char*)gtbl);      // get space for error message
                     62: //             if (Nspy) print_free();
                     63:                error('i',"free store exhausted");
                     64:        }
                     65: //     Nalloc++;
                     66: //     Nfree_store += sz+sizeof(int*);
                     67:        return p;
                     68: }
                     69: //int NFn, NFtn, NFbt, NFpv, NFf, NFe, NFs, NFc;
                     70: 
                     71: void operator delete (void* p)
                     72: {
                     73:        if (p == 0) return;
                     74: 
                     75: //fprintf(stderr,"free(%d) %d\n",p,((int*)p)[-1]-(int)p-1+sizeof(int*));
                     76: 
                     77: //if (Nspy) {
                     78: //     Pname pp = (Pname) p;
                     79: //     TOK t = pp->base;
                     80: //     Nfree++;
                     81: //     Nfree_store -= ((int*)p)[-1]-(int)p-1+sizeof(int*);
                     82: //     switch (t) {    // can be fooled by character strings
                     83: //     case INT: case CHAR: case TYPE: case VOID: case SHORT: case LONG:
                     84: //     case FLOAT: case DOUBLE: case LDOUBLE: case COBJ: case EOBJ: case FIELD:
                     85: //                     NFbt++; break;
                     86: //
                     87: //     case PTR: case VEC:
                     88: //                     NFpv++; break;
                     89: //
                     90: //     case FCT:       NFf++; break;
                     91: //
                     92: //     case ICON: case CCON: case STRING: case FCON: case THIS:
                     93: //                     NFc++; break;
                     94: //     }
                     95: //}
                     96:        free((char*)p);
                     97: }

unix.superglobalmegacorp.com

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