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 88
 	 -DUSE_IPV6 \
90 89
 	 -DNOISY_REPLIES -DVERY_NOISY_REPLIES\
91 90
 	 -DPINGTEL_TAG_HACK\
91
+	 -DDBG_QM_MALLOC
92
+	 #-DF_MALLOC \
92 93
  	 #-DUSE_SYNONIM\
93 94
 	 #-DNO_DEBUG \
94 95
 	 #-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 72
 static  void qm_debug_frag(struct qm_block* qm, struct qm_frag* f)
70 73
 {
71 74
 	if (f->check!=ST_CHECK_PATTERN){
72
-		LOG(L_CRIT, "BUG: qm_*: fragm. %x beginning overwritten(%x)!\n",
75
+		LOG(L_CRIT, "BUG: qm_*: fragm. %p beginning overwritten(%x)!\n",
73 76
 				f, f->check);
74 77
 		qm_status(qm);
75 78
 		abort();
76 79
 	};
77 80
 	if ((FRAG_END(f)->check1!=END_CHECK_PATTERN1)||
78 81
 		(FRAG_END(f)->check2!=END_CHECK_PATTERN2)){
79
-		LOG(L_CRIT, "BUG: qm_*: fragm. %x end overwritten(%x, %x)!\n",
82
+		LOG(L_CRIT, "BUG: qm_*: fragm. %p end overwritten(%x, %x)!\n",
80 83
 				f, FRAG_END(f)->check1, FRAG_END(f)->check2);
81 84
 		qm_status(qm);
82 85
 		abort();
... ...
@@ -84,7 +87,7 @@ static  void qm_debug_frag(struct qm_block* qm, struct qm_frag* f)
84 87
 	if ((f>qm->first_frag)&&
85 88
 			((PREV_FRAG_END(f)->check1!=END_CHECK_PATTERN1) ||
86 89
 				(PREV_FRAG_END(f)->check2!=END_CHECK_PATTERN2) ) ){
87
-		LOG(L_CRIT, "BUG: qm_*: prev. fragm. tail overwritten(%x, %x)[%x]!\n",
90
+		LOG(L_CRIT, "BUG: qm_*: prev. fragm. tail overwritten(%x, %x)[%p]!\n",
88 91
 				PREV_FRAG_END(f)->check1, PREV_FRAG_END(f)->check2, f);
89 92
 		qm_status(qm);
90 93
 		abort();
... ...
@@ -126,11 +129,11 @@ struct qm_block* qm_malloc_init(char* address, unsigned int size)
126 129
 	
127 130
 	/* make address and size multiple of 8*/
128 131
 	start=(char*)ROUNDUP((unsigned int) address);
129
-	printf("qm_malloc_init: QM_OPTIMIZE=%d, /ROUNDTO=%d\n",
132
+	DBG("qm_malloc_init: QM_OPTIMIZE=%d, /ROUNDTO=%d\n",
130 133
 			QM_MALLOC_OPTIMIZE, QM_MALLOC_OPTIMIZE/ROUNDTO);
131
-	printf("qm_malloc_init: QM_HASH_SIZE=%d, qm_block size=%d\n",
134
+	DBG("qm_malloc_init: QM_HASH_SIZE=%d, qm_block size=%d\n",
132 135
 			QM_HASH_SIZE, sizeof(struct qm_block));
133
-	printf("qm_malloc_init(%x, %d), start=%x\n", address, size, start);
136
+	DBG("qm_malloc_init(%p, %d), start=%p\n", address, size, start);
134 137
 	if (size<start-address) return 0;
135 138
 	size-=(start-address);
136 139
 	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 141
 	
139 142
 	init_overhead=ROUNDUP(sizeof(struct qm_block))+sizeof(struct qm_frag)+
140 143
 		sizeof(struct qm_frag_end);
141
-	printf("qm_malloc_init: size= %d, init_overhead=%d\n", size, init_overhead);
144
+	DBG("qm_malloc_init: size= %d, init_overhead=%d\n", size, init_overhead);
142 145
 	
143 146
 	if (size < init_overhead)
144 147
 	{
... ...
@@ -191,8 +194,6 @@ static inline void qm_detach_free(struct qm_block* qm, struct qm_frag* frag)
191 194
 	struct qm_frag *prev;
192 195
 	struct qm_frag *next;
193 196
 	
194
-	struct qm_frag_end *end;
195
-
196 197
 	prev=FRAG_END(frag)->prev_free;
197 198
 	next=frag->u.nxt_free;
198 199
 	prev->u.nxt_free=next;
... ...
@@ -211,9 +212,6 @@ static inline struct qm_frag* qm_find_free(struct qm_block* qm,
211 212
 	for (hash=GET_HASH(size); hash<QM_HASH_SIZE; hash++){
212 213
 		for (f=qm->free_hash[hash].head.u.nxt_free; 
213 214
 					f!=&(qm->free_hash[hash].head); f=f->u.nxt_free){
214
-	#ifdef DBG_QM_MALLOC
215
-			list_cntr++;
216
-	#endif
217 215
 			if (f->size>=size) return f;
218 216
 		}
219 217
 	/*try in a bigger bucket*/
... ...
@@ -240,7 +238,7 @@ void* qm_malloc(struct qm_block* qm, unsigned int size)
240 238
 	unsigned int list_cntr;
241 239
 
242 240
 	list_cntr = 0;
243
-	DBG("qm_malloc(%x, %d) called from %s: %s(%d)\n", qm, size, file, func,
241
+	DBG("qm_malloc(%p, %d) called from %s: %s(%d)\n", qm, size, file, func,
244 242
 			line);
245 243
 #endif
246 244
 	/*size must be a multiple of 8*/
... ...
@@ -296,7 +294,7 @@ void* qm_malloc(struct qm_block* qm, unsigned int size)
296 294
 		f->check=ST_CHECK_PATTERN;
297 295
 		/*  FRAG_END(f)->check1=END_CHECK_PATTERN1;
298 296
 			FRAG_END(f)->check2=END_CHECK_PATTERN2;*/
299
-		DBG("qm_malloc(%x, %d) returns address %x on %d -th hit\n", qm, size,
297
+		DBG("qm_malloc(%p, %d) returns address %p on %d -th hit\n", qm, size,
300 298
 			(char*)f+sizeof(struct qm_frag), list_cntr );
301 299
 #endif
302 300
 		return (char*)f+sizeof(struct qm_frag);
... ...
@@ -316,13 +314,12 @@ void qm_free(struct qm_block* qm, void* p)
316 314
 	struct qm_frag* f;
317 315
 	struct qm_frag* prev;
318 316
 	struct qm_frag* next;
319
-	struct qm_frag_end *end;
320 317
 	unsigned int size;
321 318
 
322 319
 #ifdef DBG_QM_MALLOC
323
-	DBG("qm_free(%x, %x), called from %s: %s(%d)\n", qm, p, file, func, line);
320
+	DBG("qm_free(%p, %p), called from %s: %s(%d)\n", qm, p, file, func, line);
324 321
 	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!) - "
322
+		LOG(L_CRIT, "BUG: qm_free: bad pointer %p (out of memory block!) - "
326 323
 				"aborting\n", p);
327 324
 		abort();
328 325
 	}
... ...
@@ -395,7 +392,7 @@ void qm_status(struct qm_block* qm)
395 392
 	int i,j;
396 393
 	int h;
397 394
 
398
-	LOG(L_INFO, "qm_status (%x):\n", qm);
395
+	LOG(L_INFO, "qm_status (%p):\n", qm);
399 396
 	if (!qm) return;
400 397
 
401 398
 	LOG(L_INFO, " heap size= %d\n", qm->size);
... ...
@@ -407,7 +404,7 @@ void qm_status(struct qm_block* qm)
407 404
 	for (f=qm->first_frag, i=0;(char*)f<(char*)qm->last_frag_end;f=FRAG_NEXT(f)
408 405
 			,i++){
409 406
 		if (! f->u.is_free){
410
-			LOG(L_INFO, "    %3d. %c  address=%x  size=%d\n", i, 
407
+			LOG(L_INFO, "    %3d. %c  address=%p  size=%d\n", i, 
411 408
 				(f->u.is_free)?'a':'N',
412 409
 				(char*)f+sizeof(struct qm_frag), f->size);
413 410
 #ifdef DBG_QM_MALLOC