Browse code

- a little more verbose DBG_QM_MALLOC (frags & addresses are always displayed, etc) - fixed a gcc 2.9x warning and a gcc 3.* warning

Andrei Pelinescu-Onciul authored on 14/04/2003 18:51:58
Showing 3 changed files
... ...
@@ -3,10 +3,10 @@ $Id$
3 3
 ( - todo, x - done)
4 4
 
5 5
 release:
6
-- resolver should resolve [ipv6]
6
+x resolver should resolve [ipv6]
7 7
 - remove parse_uri debugging info
8 8
 - fix DBG("<%.*s>", len, _null_)
9
-- add -t, -w, -u -g equivalents to the config file
9
+x add -t, -w, -u -g equivalents to the config file
10 10
 x force add rport : force_rport()
11 11
 - kill all the fprintf
12 12
 see also tcp & tm
... ...
@@ -24,6 +24,12 @@
24 24
  * along with this program; if not, write to the Free Software 
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27
+/*
28
+ * History:
29
+ * --------
30
+ *  ????-??-??  created by andrei
31
+ *  2003-04-14  more debugging added in DBG_QM_MALLOC mode (andrei)
32
+ */
27 33
 
28 34
 
29 35
 #if !defined(q_malloc) && !(defined VQ_MALLOC) && !(defined F_MALLOC)
... ...
@@ -97,23 +103,29 @@ inline static int big_hash_idx(int s)
97 97
 static  void qm_debug_frag(struct qm_block* qm, struct qm_frag* f)
98 98
 {
99 99
 	if (f->check!=ST_CHECK_PATTERN){
100
-		LOG(L_CRIT, "BUG: qm_*: fragm. %p beginning overwritten(%lx)!\n",
101
-				f, f->check);
100
+		LOG(L_CRIT, "BUG: qm_*: fragm. %p (address %p) "
101
+				"beginning overwritten(%lx)!\n",
102
+				f, (char*)f+sizeof(struct qm_frag),
103
+				f->check);
102 104
 		qm_status(qm);
103 105
 		abort();
104 106
 	};
105 107
 	if ((FRAG_END(f)->check1!=END_CHECK_PATTERN1)||
106 108
 		(FRAG_END(f)->check2!=END_CHECK_PATTERN2)){
107
-		LOG(L_CRIT, "BUG: qm_*: fragm. %p end overwritten(%lx, %lx)!\n",
108
-				f, FRAG_END(f)->check1, FRAG_END(f)->check2);
109
+		LOG(L_CRIT, "BUG: qm_*: fragm. %p (address %p)"
110
+					" end overwritten(%lx, %lx)!\n",
111
+				f, (char*)f+sizeof(struct qm_frag), 
112
+				FRAG_END(f)->check1, FRAG_END(f)->check2);
109 113
 		qm_status(qm);
110 114
 		abort();
111 115
 	}
112 116
 	if ((f>qm->first_frag)&&
113 117
 			((PREV_FRAG_END(f)->check1!=END_CHECK_PATTERN1) ||
114 118
 				(PREV_FRAG_END(f)->check2!=END_CHECK_PATTERN2) ) ){
115
-		LOG(L_CRIT, "BUG: qm_*: prev. fragm. tail overwritten(%lx, %lx)[%p]!\n"
116
-				,PREV_FRAG_END(f)->check1, PREV_FRAG_END(f)->check2, f);
119
+		LOG(L_CRIT, "BUG: qm_*: prev. fragm. tail overwritten(%lx, %lx)[%p:%p]!"
120
+					"\n",
121
+				PREV_FRAG_END(f)->check1, PREV_FRAG_END(f)->check2, f,
122
+				(char*)f+sizeof(struct qm_frag));
117 123
 		qm_status(qm);
118 124
 		abort();
119 125
 	}
... ...
@@ -227,9 +239,14 @@ static inline void qm_detach_free(struct qm_block* qm, struct qm_frag* frag)
227 227
 }
228 228
 
229 229
 
230
-
230
+#ifdef DBG_QM_MALLOC
231
+static inline struct qm_frag* qm_find_free(struct qm_block* qm, 
232
+											unsigned int size,
233
+											unsigned int *count)
234
+#else
231 235
 static inline struct qm_frag* qm_find_free(struct qm_block* qm, 
232
-										unsigned int size)
236
+											unsigned int size)
237
+#endif
233 238
 {
234 239
 	int hash;
235 240
 	struct qm_frag* f;
... ...
@@ -237,6 +254,9 @@ static inline struct qm_frag* qm_find_free(struct qm_block* qm,
237 237
 	for (hash=GET_HASH(size); hash<QM_HASH_SIZE; hash++){
238 238
 		for (f=qm->free_hash[hash].head.u.nxt_free; 
239 239
 					f!=&(qm->free_hash[hash].head); f=f->u.nxt_free){
240
+#ifdef DBG_QM_MALLOC
241
+			*count+=1; /* *count++ generates a warning with gcc 2.9* -Wall */
242
+#endif
240 243
 			if (f->size>=size) return f;
241 244
 		}
242 245
 	/*try in a bigger bucket*/
... ...
@@ -271,7 +291,11 @@ void* qm_malloc(struct qm_block* qm, unsigned int size)
271 271
 	if (size>(qm->size-qm->real_used)) return 0;
272 272
 
273 273
 	/*search for a suitable free frag*/
274
+#ifdef DBG_QM_MALLOC
275
+	if ((f=qm_find_free(qm, size, &list_cntr))!=0){
276
+#else
274 277
 	if ((f=qm_find_free(qm, size))!=0){
278
+#endif
275 279
 		/* we found it!*/
276 280
 		/*detach it from the free list*/
277 281
 #ifdef DBG_QM_MALLOC
... ...
@@ -319,8 +343,9 @@ void* qm_malloc(struct qm_block* qm, unsigned int size)
319 319
 		f->check=ST_CHECK_PATTERN;
320 320
 		/*  FRAG_END(f)->check1=END_CHECK_PATTERN1;
321 321
 			FRAG_END(f)->check2=END_CHECK_PATTERN2;*/
322
-		DBG("qm_malloc(%p, %d) returns address %p on %d -th hit\n", qm, size,
323
-			(char*)f+sizeof(struct qm_frag), list_cntr );
322
+		DBG("qm_malloc(%p, %d) returns address %p frag. %p (size=%ld) on %d -th"
323
+				" hit\n",
324
+			 qm, size, (char*)f+sizeof(struct qm_frag), f, f->size, list_cntr );
324 325
 #endif
325 326
 		return (char*)f+sizeof(struct qm_frag);
326 327
 	}
... ...
@@ -363,8 +388,8 @@ void qm_free(struct qm_block* qm, void* p)
363 363
 				f->file, f->func, f->line);
364 364
 		abort();
365 365
 	}
366
-	DBG("qm_free: freeing block alloc'ed from %s: %s(%ld)\n", f->file, f->func,
367
-			f->line);
366
+	DBG("qm_free: freeing frag. %p alloc'ed from %s: %s(%ld)\n",
367
+			f, f->file, f->func, f->line);
368 368
 #endif
369 369
 	size=f->size;
370 370
 	qm->used-=size;
... ...
@@ -429,9 +454,9 @@ void qm_status(struct qm_block* qm)
429 429
 	for (f=qm->first_frag, i=0;(char*)f<(char*)qm->last_frag_end;f=FRAG_NEXT(f)
430 430
 			,i++){
431 431
 		if (! f->u.is_free){
432
-			LOG(memlog, "    %3d. %c  address=%p  size=%ld\n", i, 
432
+			LOG(memlog, "    %3d. %c  address=%p frag=%p size=%ld\n", i, 
433 433
 				(f->u.is_free)?'a':'N',
434
-				(char*)f+sizeof(struct qm_frag), f->size);
434
+				(char*)f+sizeof(struct qm_frag), f, f->size);
435 435
 #ifdef DBG_QM_MALLOC
436 436
 			LOG(memlog, "            %s from %s: %s(%ld)\n",
437 437
 				(f->u.is_free)?"freed":"alloc'd", f->file, f->func, f->line);
... ...
@@ -712,6 +712,7 @@ skip_before:
712 712
 			}
713 713
 		}
714 714
 skip_after:
715
+		; /* to make gcc 3.* happy */
715 716
 	}
716 717
 	return new_len;
717 718
 }