Annotation of researchv10no/cmd/cfront/libC/new/_vec.c, revision 1.1.1.1

1.1       root        1: typedef void* PV;
                      2: typedef void (*PF)(PV,int,int,int,int,int,int,int,int);
                      3: typedef void (*PFI)(PV,int ...);
                      4: /*
                      5:        ERROR: cannot handle classes with more than 8 virtual bases
                      6: */
                      7: 
                      8: // functions that manage the map from arrays to their element counts
                      9: extern void    __insert_new_array(PV key, int count);
                     10:        // key is a pointer to a new array.  It must
                     11:        //      be non-zero
                     12:        //      not already be in the table
                     13:        // count is the number of elements in the array.  May be zero
                     14: extern int     __remove_old_array(PV key);
                     15:        // removes an old array from the table.  Returns the count or -1 if not found
                     16: 
                     17: #ifdef __cplusplus
                     18: extern "C"
                     19: #endif
                     20: PV __vec_new(PV op, int n, int sz, PV f)
                     21: /*
                     22:        allocate a vector of "n" elements of size "sz"
                     23:        and initialize each by a call of "f"
                     24: */
                     25: {
                     26:        if (op == 0) {
                     27:                op = PV( new char[n*sz] );
                     28:                if (op) __insert_new_array(op, n);
                     29:        }
                     30:        if (op && f) {
                     31:                register char* p = (char*) op;
                     32:                register char* lim = p + n*sz;
                     33:                register PF fp = PF(f);
                     34:                while (p < lim) {
                     35:                        (*fp) (PV(p),0,0,0,0,0,0,0,0);
                     36:                        p += sz;
                     37:                }
                     38:        }
                     39:        return PV(op);
                     40: }
                     41: 
                     42: #ifdef __cplusplus
                     43: extern "C"
                     44: #endif
                     45: void __vec_delete(PV op, int n, int sz, PV f, int del, int)
                     46: {
                     47:        if (op) {
                     48:                if (f) {
                     49:                        if (del && n == -1)
                     50:                                n = __remove_old_array(op);     // -1 if not found
                     51:                        register char* cp = (char*) op;
                     52:                        register char* p = cp;
                     53:                        register PFI fp = PFI(f);
                     54:                        p += n*sz;
                     55:                        while (p > cp) {
                     56:                                p -= sz;
                     57:                                (*fp)(PV(p), 2);  // destroy VBC, don't delete
                     58:                        }
                     59:                }
                     60:                if (del) delete op;
                     61:        }
                     62: }
                     63: 

unix.superglobalmegacorp.com

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