plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

malloc.c (772B)


      1 /*
      2  * These are here mainly so that I can link against
      3  * debugmalloc.c instead and not recompile the world.
      4  */
      5 
      6 #include <u.h>
      7 #define NOPLAN9DEFINES
      8 #include <libc.h>
      9 
     10 void*
     11 p9malloc(ulong n)
     12 {
     13 	void *v;
     14 
     15 	if(n == 0)
     16 		n++;
     17 	v = malloc(n);
     18 	print("p9malloc %lud => %p; pc %lux\n", n, v, getcallerpc(&n));
     19 	return v;
     20 }
     21 
     22 void
     23 p9free(void *v)
     24 {
     25 	if(v == nil)
     26 		return;
     27 	print("p9free %p; pc %lux\n", v, getcallerpc(&v));
     28 	free(v);
     29 }
     30 
     31 void*
     32 p9calloc(ulong a, ulong b)
     33 {
     34 	void *v;
     35 
     36 	if(a*b == 0)
     37 		a = b = 1;
     38 
     39 	v = calloc(a*b, 1);
     40 	print("p9calloc %lud %lud => %p; pc %lux\n", a, b, v, getcallerpc(&a));
     41 	return v;
     42 }
     43 
     44 void*
     45 p9realloc(void *v, ulong n)
     46 {
     47 	void *vv;
     48 
     49 	vv = realloc(v, n);
     50 	print("p9realloc %p %lud => %p; pc %lux\n", v, n, vv, getcallerpc(&v));
     51 	return vv;
     52 }