7 // #include "basics.h" included later to avoid macro recursion for malloc
11 #define ALLOC_WARN_LIMIT (40*1024*1024)
15 void *Malloc_ (size_t n, size_t l, char * file)
19 if (n > ALLOC_WARN_LIMIT)
21 fprintf(stderr, "\nWarning: allocating %lu bytes, file:%s, line: %lu\n",
25 p = (void*) malloc (n);
26 if (p == NULL && n > 0)
28 fprintf (stderr,"Could not allocate %lu bytes, file: %s, line: %lu\n",n,file,l);
34 void Free_ (void *p, size_t l, char * file)
38 fprintf (stderr,"Double free, file: %s, line: %lu\n",file,l);
43 void *Realloc_ (void *p, size_t n, size_t l, char * file)
45 if (n > ALLOC_WARN_LIMIT)
47 fprintf(stderr, "\nWarning: allocating %lu bytes, file:%s, line: %lu\n",
51 p = (void*) realloc (p,n);
54 fprintf (stderr,"Could not re-allocate %lu bytes, file: %s, line: %lu\n",n,file,l);
62 // bits needed to represent a number between 0 and n
72 // returns e[p..p+len-1], assuming len <= W
74 uint bitread (uint *e, uint p, uint len)
80 { if (p) answ |= (*(e+1)) << (W-p);
82 else { if (p+len > W) answ |= (*(e+1)) << (W-p);
89 // writes e[p..p+len-1] = s, len <= W
91 void bitwrite (register uint *e, register uint p,
92 register uint len, register uint s)
96 { *e |= (*e & ((1<<p)-1)) | (s << p);
99 *e = (*e & ~((1<<p)-1)) | (s >> (W-p));
101 else { if (p+len <= W)
102 { *e = (*e & ~(((1<<len)-1)<<p)) | (s << p);
105 *e = (*e & ((1<<p)-1)) | (s << p);
107 *e = (*e & ~((1<<len)-1)) | (s >> (W-p));
110 // writes e[p..p+len-1] = 0
112 void bitzero2 (register uint *e, register uint p,
126 *e &= ~(((1<<len)-1)<<p);