Browse code

- DBG_QM_MALLOC compile & warnings fixes

Andrei Pelinescu-Onciul authored on 08/07/2002 14:11:49
Showing 2 changed files
... ...
@@ -81,7 +81,6 @@ ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/ )
81 81
 DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
82 82
 	 -DOS='"$(OS)"' -DCOMPILER='"$(CC_VER)"'\
83 83
 	 -DPKG_MALLOC \
84
-	 -DF_MALLOC \
85 84
 	 -DSHM_MEM  -DSHM_MMAP \
86 85
 	 -DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 \
87 86
 	 -DWAIT -DNEW_HNAME \
... ...
@@ -89,6 +88,8 @@ DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
89 89
 	 -DUSE_IPV6 \
90 90
 	 -DNOISY_REPLIES -DVERY_NOISY_REPLIES\
91 91
 	 -DPINGTEL_TAG_HACK\
92
+	 -DDBG_QM_MALLOC
93
+	 #-DF_MALLOC \
92 94
  	 #-DUSE_SYNONIM\
93 95
 	 #-DNO_DEBUG \
94 96
 	 #-DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=0 \
... ...
@@ -5,6 +5,9 @@
5 5
 #if !defined(q_malloc) && !(defined VQ_MALLOC) && !(defined F_MALLOC)
6 6
 #define q_malloc
7 7
 
8
+#include <stdlib.h>
9
+#include <string.h>
10
+
8 11
 #include "q_malloc.h"
9 12
 #include "../dprint.h"
10 13
 
... ...
@@ -69,14 +72,14 @@ inline static int big_hash_idx(int s)
69 69
 static  void qm_debug_frag(struct qm_block* qm, struct qm_frag* f)
70 70
 {
71 71
 	if (f->check!=ST_CHECK_PATTERN){
72
-		LOG(L_CRIT, "BUG: qm_*: fragm. %x beginning overwritten(%x)!\n",
72
+		LOG(L_CRIT, "BUG: qm_*: fragm. %p beginning overwritten(%x)!\n",
73 73
 				f, f->check);
74 74
 		qm_status(qm);
75 75
 		abort();
76 76
 	};
77 77
 	if ((FRAG_END(f)->check1!=END_CHECK_PATTERN1)||
78 78
 		(FRAG_END(f)->check2!=END_CHECK_PATTERN2)){
79
-		LOG(L_CRIT, "BUG: qm_*: fragm. %x end overwritten(%x, %x)!\n",
79
+		LOG(L_CRIT, "BUG: qm_*: fragm. %p end overwritten(%x, %x)!\n",
80 80
 				f, FRAG_END(f)->check1, FRAG_END(f)->check2);
81 81
 		qm_status(qm);
82 82
 		abort();
... ...
@@ -84,7 +87,7 @@ static  void qm_debug_frag(struct qm_block* qm, struct qm_frag* f)
84 84
 	if ((f>qm->first_frag)&&
85 85
 			((PREV_FRAG_END(f)->check1!=END_CHECK_PATTERN1) ||
86 86
 				(PREV_FRAG_END(f)->check2!=END_CHECK_PATTERN2) ) ){
87
-		LOG(L_CRIT, "BUG: qm_*: prev. fragm. tail overwritten(%x, %x)[%x]!\n",
87
+		LOG(L_CRIT, "BUG: qm_*: prev. fragm. tail overwritten(%x, %x)[%p]!\n",
88 88
 				PREV_FRAG_END(f)->check1, PREV_FRAG_END(f)->check2, f);
89 89
 		qm_status(qm);
90 90
 		abort();
... ...
@@ -126,11 +129,11 @@ struct qm_block* qm_malloc_init(char* address, unsigned int size)
126 126
 	
127 127
 	/* make address and size multiple of 8*/
128 128
 	start=(char*)ROUNDUP((unsigned int) address);
129
-	printf("qm_malloc_init: QM_OPTIMIZE=%d, /ROUNDTO=%d\n",
129
+	DBG("qm_malloc_init: QM_OPTIMIZE=%d, /ROUNDTO=%d\n",
130 130
 			QM_MALLOC_OPTIMIZE, QM_MALLOC_OPTIMIZE/ROUNDTO);
131
-	printf("qm_malloc_init: QM_HASH_SIZE=%d, qm_block size=%d\n",
131
+	DBG("qm_malloc_init: QM_HASH_SIZE=%d, qm_block size=%d\n",
132 132
 			QM_HASH_SIZE, sizeof(struct qm_block));
133
-	printf("qm_malloc_init(%x, %d), start=%x\n", address, size, start);
133
+	DBG("qm_malloc_init(%p, %d), start=%p\n", address, size, start);
134 134
 	if (size<start-address) return 0;
135 135
 	size-=(start-address);
136 136
 	if (size <(MIN_FRAG_SIZE+FRAG_OVERHEAD)) return 0;
... ...
@@ -138,7 +141,7 @@ struct qm_block* qm_malloc_init(char* address, unsigned int size)
138 138
 	
139 139
 	init_overhead=ROUNDUP(sizeof(struct qm_block))+sizeof(struct qm_frag)+
140 140
 		sizeof(struct qm_frag_end);
141
-	printf("qm_malloc_init: size= %d, init_overhead=%d\n", size, init_overhead);
141
+	DBG("qm_malloc_init: size= %d, init_overhead=%d\n", size, init_overhead);
142 142
 	
143 143
 	if (size < init_overhead)
144 144
 	{
... ...
@@ -191,8 +194,6 @@ static inline void qm_detach_free(struct qm_block* qm, struct qm_frag* frag)
191 191
 	struct qm_frag *prev;
192 192
 	struct qm_frag *next;
193 193
 	
194
-	struct qm_frag_end *end;
195
-
196 194
 	prev=FRAG_END(frag)->prev_free;
197 195
 	next=frag->u.nxt_free;
198 196
 	prev->u.nxt_free=next;
... ...
@@ -211,9 +212,6 @@ static inline struct qm_frag* qm_find_free(struct qm_block* qm,
211 211
 	for (hash=GET_HASH(size); hash<QM_HASH_SIZE; hash++){
212 212
 		for (f=qm->free_hash[hash].head.u.nxt_free; 
213 213
 					f!=&(qm->free_hash[hash].head); f=f->u.nxt_free){
214
-	#ifdef DBG_QM_MALLOC
215
-			list_cntr++;
216
-	#endif
217 214
 			if (f->size>=size) return f;
218 215
 		}
219 216
 	/*try in a bigger bucket*/
... ...
@@ -240,7 +238,7 @@ void* qm_malloc(struct qm_block* qm, unsigned int size)
240 240
 	unsigned int list_cntr;
241 241
 
242 242
 	list_cntr = 0;
243
-	DBG("qm_malloc(%x, %d) called from %s: %s(%d)\n", qm, size, file, func,
243
+	DBG("qm_malloc(%p, %d) called from %s: %s(%d)\n", qm, size, file, func,
244 244
 			line);
245 245
 #endif
246 246
 	/*size must be a multiple of 8*/
... ...
@@ -296,7 +294,7 @@ void* qm_malloc(struct qm_block* qm, unsigned int size)
296 296
 		f->check=ST_CHECK_PATTERN;
297 297
 		/*  FRAG_END(f)->check1=END_CHECK_PATTERN1;
298 298
 			FRAG_END(f)->check2=END_CHECK_PATTERN2;*/
299
-		DBG("qm_malloc(%x, %d) returns address %x on %d -th hit\n", qm, size,
299
+		DBG("qm_malloc(%p, %d) returns address %p on %d -th hit\n", qm, size,
300 300
 			(char*)f+sizeof(struct qm_frag), list_cntr );
301 301
 #endif
302 302
 		return (char*)f+sizeof(struct qm_frag);
... ...
@@ -316,13 +314,12 @@ void qm_free(struct qm_block* qm, void* p)
316 316
 	struct qm_frag* f;
317 317
 	struct qm_frag* prev;
318 318
 	struct qm_frag* next;
319
-	struct qm_frag_end *end;
320 319
 	unsigned int size;
321 320
 
322 321
 #ifdef DBG_QM_MALLOC
323
-	DBG("qm_free(%x, %x), called from %s: %s(%d)\n", qm, p, file, func, line);
322
+	DBG("qm_free(%p, %p), called from %s: %s(%d)\n", qm, p, file, func, line);
324 323
 	if (p>(void*)qm->last_frag_end || p<(void*)qm->first_frag){
325
-		LOG(L_CRIT, "BUG: qm_free: bad pointer %x (out of memory block!) - "
324
+		LOG(L_CRIT, "BUG: qm_free: bad pointer %p (out of memory block!) - "
326 325
 				"aborting\n", p);
327 326
 		abort();
328 327
 	}
... ...
@@ -395,7 +392,7 @@ void qm_status(struct qm_block* qm)
395 395
 	int i,j;
396 396
 	int h;
397 397
 
398
-	LOG(L_INFO, "qm_status (%x):\n", qm);
398
+	LOG(L_INFO, "qm_status (%p):\n", qm);
399 399
 	if (!qm) return;
400 400
 
401 401
 	LOG(L_INFO, " heap size= %d\n", qm->size);
... ...
@@ -407,7 +404,7 @@ void qm_status(struct qm_block* qm)
407 407
 	for (f=qm->first_frag, i=0;(char*)f<(char*)qm->last_frag_end;f=FRAG_NEXT(f)
408 408
 			,i++){
409 409
 		if (! f->u.is_free){
410
-			LOG(L_INFO, "    %3d. %c  address=%x  size=%d\n", i, 
410
+			LOG(L_INFO, "    %3d. %c  address=%p  size=%d\n", i, 
411 411
 				(f->u.is_free)?'a':'N',
412 412
 				(char*)f+sizeof(struct qm_frag), f->size);
413 413
 #ifdef DBG_QM_MALLOC