Ver código fonte

Fixed memory test builds.

Thomas Buck 11 anos atrás
pai
commit
c0f771c2bd
2 arquivos alterados com 86 adições e 84 exclusões
  1. 68
    70
      src/memeory_test.cpp
  2. 18
    14
      src/memeory_test.h

+ 68
- 70
src/memeory_test.cpp Ver arquivo

@@ -1,6 +1,6 @@
1 1
 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
2 2
 /*================================================================
3
- * 
3
+ *
4 4
  * Project : MTK
5 5
  * Author  : Terry 'Mongoose' Hendrix II
6 6
  * Website : http://www.westga.edu/~stu7440/
@@ -10,10 +10,10 @@
10 10
  * Comments: Memory testing tool kit
11 11
  *
12 12
  *
13
- *           This file was generated using Mongoose's C++ 
13
+ *           This file was generated using Mongoose's C++
14 14
  *           template generator script.  <stu7440@westga.edu>
15
- * 
16
- *-- History ------------------------------------------------- 
15
+ *
16
+ *-- History -------------------------------------------------
17 17
  *
18 18
  * 2002.03.27:
19 19
  * Mongoose - Created
@@ -235,7 +235,7 @@ void tree_rotate_left(rbtree_t **root, rbtree_t *tree)
235 235
 	if (tree->parent)  // Not root
236 236
 	{
237 237
 		uncle = (tree->parent)->left;
238
-		
238
+
239 239
 		// Mix up at hosptial, switch parent's children!
240 240
 		if (tree == uncle)
241 241
 		{
@@ -286,7 +286,7 @@ void tree_rotate_right(rbtree_t **root, rbtree_t *tree)
286 286
 
287 287
 	if (left)
288 288
 	{
289
-		left->parent = tree->parent;  
289
+		left->parent = tree->parent;
290 290
 	}
291 291
 
292 292
 	parent = tree->parent;
@@ -330,7 +330,7 @@ rbtree_t *tree_insert(rbtree_t **root, void *data, DWORD key)
330 330
 
331 331
 	tree = *root;
332 332
 	prev = 0x0;
333
-		
333
+
334 334
 	do
335 335
 	{
336 336
 		prev = tree;
@@ -359,7 +359,7 @@ rbtree_t *tree_insert(rbtree_t **root, void *data, DWORD key)
359 359
 	else
360 360
 	{
361 361
 		prev->right = tree_new(data, key);
362
-		tree = prev->right;		
362
+		tree = prev->right;
363 363
 	}
364 364
 
365 365
 	tree->parent = prev;
@@ -372,64 +372,64 @@ rbtree_t *tree_insert(rbtree_t **root, void *data, DWORD key)
372 372
 		// Parent is a left child
373 373
 		if (tree->parent == tree->parent->parent->left)
374 374
 		{
375
-			// Tree's right uncle 
375
+			// Tree's right uncle
376 376
 			uncle = tree->parent->parent->right;
377
-			
377
+
378 378
 			// Parent and Uncle are RED
379 379
          if ((uncle) && (uncle->color == RB_RED))
380
-			{ 
380
+			{
381 381
            // Change Parent and Uncle to BLACK, make grandparent RED
382 382
            tree->parent->color = RB_BLACK;
383
-           uncle->color = RB_BLACK; 
383
+           uncle->color = RB_BLACK;
384 384
            tree->parent->parent->color = RB_RED;
385 385
 
386
-			  // Continue from grandparent 
386
+			  // Continue from grandparent
387 387
            tree = tree->parent->parent;
388
-         } 
388
+         }
389 389
          else  // Parent is RED and Uncle is BLACK
390 390
 			{
391
-				// Tree is a right child 
391
+				// Tree is a right child
392 392
 				if (tree == tree->parent->right)
393 393
 				{
394
-					tree_rotate_left(root, tree->parent); 
395
-					tree = tree->left; 
394
+					tree_rotate_left(root, tree->parent);
395
+					tree = tree->left;
396 396
 				}
397 397
 
398
-				tree->parent->color = RB_BLACK; 
399
-				tree->parent->parent->color = RB_RED; 
400
-				tree_rotate_right(root, tree->parent->parent); 
401
-         } 
402
-		} 
398
+				tree->parent->color = RB_BLACK;
399
+				tree->parent->parent->color = RB_RED;
400
+				tree_rotate_right(root, tree->parent->parent);
401
+         }
402
+		}
403 403
 		else // Parent is a right child
404
-		{  
405
-			// Tree's left uncle 
404
+		{
405
+			// Tree's left uncle
406 406
 			uncle = tree->parent->parent->left;
407
-			
407
+
408 408
 			// Parent and Uncle are RED
409 409
          if ((uncle) && (uncle->color == RB_RED))
410
-			{ 
410
+			{
411 411
            // Change Parent and Uncle to BLACK, make grandparent RED
412 412
            tree->parent->color = RB_BLACK;
413
-           uncle->color = RB_BLACK; 
413
+           uncle->color = RB_BLACK;
414 414
            tree->parent->parent->color = RB_RED;
415 415
 
416
-			  // Continue from grandparent 
416
+			  // Continue from grandparent
417 417
            tree = tree->parent->parent;
418
-         } 
418
+         }
419 419
          else  // Parent is RED and Uncle is BLACK
420 420
 			{
421
-				// Tree is a left child 
421
+				// Tree is a left child
422 422
 				if (tree == tree->parent->left)
423 423
 				{
424
-					tree_rotate_right(root, tree->parent); 
425
-					tree = tree->right; 
424
+					tree_rotate_right(root, tree->parent);
425
+					tree = tree->right;
426 426
 				}
427 427
 
428
-				tree->parent->color = RB_BLACK; 
429
-				tree->parent->parent->color = RB_RED; 
430
-				tree_rotate_left(root, tree->parent->parent); 
431
-         } 
432
-		} 
428
+				tree->parent->color = RB_BLACK;
429
+				tree->parent->parent->color = RB_RED;
430
+				tree_rotate_left(root, tree->parent->parent);
431
+         }
432
+		}
433 433
 	}
434 434
 
435 435
 	(*root)->color = RB_BLACK;
@@ -450,20 +450,20 @@ int tree_print(rbtree_t *tree, void (*print_func)(void *))
450 450
 		i += tree_print(tree->left, print_func);
451 451
 		printf(",\n");
452 452
 	}
453
-	
453
+
454 454
 	if (tree->data && print_func)
455 455
 	{
456 456
 		(*print_func)(tree->data);
457 457
 
458 458
 #ifdef DEBUG_MEMEORY_RBTREE
459
-		printf(" :%s%s)", 
459
+		printf(" :%s%s)",
460 460
 				 (!tree->parent) ? " (root, " : " ("),
461 461
 				 (tree->color == RB_BLACK) ? "black" : "red");
462 462
 #endif
463 463
 	}
464 464
 
465 465
 	++i;
466
-	
466
+
467 467
 	if (tree->right)
468 468
 	{
469 469
 		printf(",\n");
@@ -472,7 +472,7 @@ int tree_print(rbtree_t *tree, void (*print_func)(void *))
472 472
 
473 473
 	if (!tree->parent)
474 474
 	{
475
-		printf("\n%i nodes, %u bytes each : %i bytes\n", 
475
+		printf("\n%i nodes, %u bytes each : %i bytes\n",
476 476
 				 i, sizeof(rbtree_t), i * sizeof(rbtree_t));
477 477
 	}
478 478
 
@@ -548,7 +548,7 @@ rbtree_t *tree_get_predecessor(rbtree_t *root,rbtree_t *tree)
548 548
 		}
549 549
 
550 550
 		return predecessor;
551
-	}		
551
+	}
552 552
 }
553 553
 
554 554
 
@@ -566,7 +566,7 @@ void tree_restore_after_remove(rbtree_t **root, rbtree_t *tree)
566 566
 
567 567
 	while ((tree != (*root)) && (tree->color == RB_BLACK)) // was parent->color
568 568
 	{
569
-		if (tree == parent->left) 
569
+		if (tree == parent->left)
570 570
 		{
571 571
 			sibling = parent->right;
572 572
 
@@ -674,7 +674,7 @@ void tree_restore_after_remove(rbtree_t **root, rbtree_t *tree)
674 674
 }
675 675
 
676 676
 
677
-void tree_remove(rbtree_t **root, rbtree_t *tree) 
677
+void tree_remove(rbtree_t **root, rbtree_t *tree)
678 678
 {
679 679
 	rbtree_t *left, *right, *parent, *prev, *cur;
680 680
 
@@ -782,11 +782,11 @@ void __print_meminfo(meminfo_t *meminfo)
782 782
 {
783 783
 	if (meminfo)
784 784
 	{
785
-		printf("<addr 0x%08lx, sz %lu, \"%s\":%u>", 
786
-				 meminfo->address, 
785
+		printf("<addr 0x%08lx, sz %lu, \"%s\":%u>",
786
+				 meminfo->address,
787 787
 				 meminfo->size,
788
-				 (!meminfo->filename) ? "?" : meminfo->filename->filename, 
789
-				 meminfo->line); 
788
+				 (!meminfo->filename) ? "?" : meminfo->filename->filename,
789
+				 meminfo->line);
790 790
 	}
791 791
 }
792 792
 
@@ -852,8 +852,8 @@ void display_memory_usage()
852 852
 
853 853
 	while (cur)
854 854
 	{
855
-		printf(" %s : ( %lu bytes, %3.2f%% )\n", 
856
-				 cur->filename, cur->size, 
855
+		printf(" %s : ( %lu bytes, %3.2f%% )\n",
856
+				 cur->filename, cur->size,
857 857
 				 100.0 * ((float)cur->size / (float)MEMEORY_USED));
858 858
 
859 859
 		cur = cur->next;
@@ -883,7 +883,7 @@ void display_memory_usage()
883 883
 					break;
884 884
 				}
885 885
 			}
886
-			
886
+
887 887
 			printf("\n");
888 888
 		}
889 889
 
@@ -894,14 +894,14 @@ void display_memory_usage()
894 894
 
895 895
 	printf("Memory usage summary:\n");
896 896
 
897
-	printf(" Tracked program memory    : %lu bytes \t(%.2f MB)\n", 
897
+	printf(" Tracked program memory    : %lu bytes \t(%.2f MB)\n",
898 898
 			 MEMEORY_USED, (double)MEMEORY_USED / 1024000.0);
899
-	printf(" Untracked overhead memory : %lu bytes \t(%.2f MB)\n", 
899
+	printf(" Untracked overhead memory : %lu bytes \t(%.2f MB)\n",
900 900
 			 MEMEORYA_USED, (double)MEMEORYA_USED / 1024000.0);
901
-	printf(" Untracked m-string memory : %lu bytes\n", 
901
+	printf(" Untracked m-string memory : %lu bytes\n",
902 902
 			 MEMEORYC_USED);
903 903
 
904
-	printf("\n Total accounted memory    : %lu bytes \t(%.2f MB)\n", 
904
+	printf("\n Total accounted memory    : %lu bytes \t(%.2f MB)\n",
905 905
 			 MEMEORY_USED + MEMEORYA_USED + MEMEORYC_USED,
906 906
 			 (double)(MEMEORY_USED + MEMEORYA_USED + MEMEORYC_USED) / 1024000.0);
907 907
 
@@ -909,14 +909,14 @@ void display_memory_usage()
909 909
 
910 910
 	printf("Memory max usage summary:\n");
911 911
 
912
-	printf(" Tracked program memory    : %lu bytes \t(%.2f MB)\n", 
912
+	printf(" Tracked program memory    : %lu bytes \t(%.2f MB)\n",
913 913
 			 MAX_MEMEORY_USED, (double)MAX_MEMEORY_USED / 1024000.0);
914
-	printf(" Untracked overhead memory : %lu bytes \t(%.2f MB)\n", 
914
+	printf(" Untracked overhead memory : %lu bytes \t(%.2f MB)\n",
915 915
 			 MAX_MEMEORYA_USED, (double)MAX_MEMEORYA_USED / 1024000.0);
916
-	printf(" Untracked m-string memory : %lu bytes\n", 
916
+	printf(" Untracked m-string memory : %lu bytes\n",
917 917
 			 MAX_MEMEORYC_USED);
918 918
 
919
-	printf("\n Total accounted memory    : %lu bytes \t(%.2f MB)\n", 
919
+	printf("\n Total accounted memory    : %lu bytes \t(%.2f MB)\n",
920 920
 			 MAX_MEMEORY_USED + MAX_MEMEORYA_USED + MAX_MEMEORYC_USED,
921 921
 			 (double)(MAX_MEMEORY_USED + MAX_MEMEORYA_USED + MAX_MEMEORYC_USED) / 1024000.0);
922 922
 
@@ -933,8 +933,8 @@ void dump_memory_report()
933 933
 	printf(" Memeory status report\n");
934 934
 	printf("============================================================\n");
935 935
 	printf("Memory tracking table:\n");
936
-	i = tree_print(MEMEORY_INFO, __print_meminfo);
937
-	printf("%i records, %u bytes each : %i bytes\n", 
936
+	i = tree_print(MEMEORY_INFO, (void (*)(void *))&__print_meminfo);
937
+	printf("%i records, %u bytes each : %i bytes\n",
938 938
 			 i, sizeof(meminfo_t), i * sizeof(meminfo_t));
939 939
 	display_memory_usage();
940 940
 	printf("============================================================\n\n");
@@ -998,7 +998,7 @@ void add_track(DWORD addr, DWORD size, const char *filename, DWORD line_num)
998 998
 				memfile = memfile->next;
999 999
 			}
1000 1000
 		}
1001
-		
1001
+
1002 1002
 		if (!memfile)
1003 1003
 		{
1004 1004
 			memfile = (meminfo_filename_t *)malloc(sizeof(meminfo_filename_t));
@@ -1090,8 +1090,8 @@ void remove_track(DWORD addr)
1090 1090
 
1091 1091
 			if (meminfo->size == 0)
1092 1092
 			{
1093
-				printf("\nERROR: %s:%u Deallocated 0 bytes\n", 
1094
-						 (meminfo->filename) ? meminfo->filename->filename : "?", 
1093
+				printf("\nERROR: %s:%u Deallocated 0 bytes\n",
1094
+						 (meminfo->filename) ? meminfo->filename->filename : "?",
1095 1095
 						 meminfo->line);
1096 1096
 			}
1097 1097
 
@@ -1126,13 +1126,13 @@ void remove_track(DWORD addr)
1126 1126
 			cur = cur->next;
1127 1127
 
1128 1128
 			MEMEORYC_USED -= sizeof(meminfo_filename_t);
1129
-			
1129
+
1130 1130
 			if (del->filename)
1131 1131
 			{
1132 1132
 				MEMEORYC_USED -= del->filename_len;
1133 1133
 				free(del->filename);
1134 1134
 			}
1135
-			
1135
+
1136 1136
 			free(del);
1137 1137
 		}
1138 1138
 	}
@@ -1146,20 +1146,18 @@ void remove_track(DWORD addr)
1146 1146
 //////////////////////////////////////////////////////////////////////
1147 1147
 //////////////////////////////////////////////////////////////////////
1148 1148
 
1149
-void *operator new(unsigned int size, const char *file, int line)
1149
+void *operator new(size_t size, const char *file, int line)
1150 1150
 {
1151 1151
 	void *ptr = (void *)malloc(size);
1152
-	
1153 1152
 
1154 1153
 	add_track((DWORD)ptr, size, file, line);
1155 1154
 	return ptr;
1156 1155
 };
1157 1156
 
1158 1157
 
1159
-void *operator new [](unsigned int size, const char *file, int line)
1158
+void *operator new [](size_t size, const char *file, int line)
1160 1159
 {
1161 1160
 	void *ptr = (void *)malloc(size);
1162
-	
1163 1161
 
1164 1162
 	add_track((DWORD)ptr, size, file, line);
1165 1163
 	return ptr;

+ 18
- 14
src/memeory_test.h Ver arquivo

@@ -1,40 +1,44 @@
1 1
 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: t; c-basic-offset: 3 -*- */
2 2
 /*================================================================
3
- * 
3
+ *
4 4
  * Project : MTK
5 5
  * Author  : Terry 'Mongoose' Hendrix II
6 6
  * Website : http://www.westga.edu/~stu7440/
7 7
  * Email   : stu7440@westga.edu
8
- * Object  : 
8
+ * Object  :
9 9
  * License : No use w/o permission (C) 2002 Mongoose
10 10
  * Comments: Memory testing tool kit
11 11
  *
12 12
  *
13
- *           This file was generated using Mongoose's C++ 
13
+ *           This file was generated using Mongoose's C++
14 14
  *           template generator script.  <stu7440@westga.edu>
15
- * 
16
- *-- History ------------------------------------------------ 
15
+ *
16
+ *-- History ------------------------------------------------
17 17
  *
18 18
  * 2002.03.27:
19 19
  * Mongoose - Created
20 20
  ================================================================*/
21 21
 
22
+#include <cstddef>
22 23
 
23 24
 #ifndef __MTK_MONGOOSE_MEMEORY_TEST_H_
24 25
 #define __MTK_MONGOOSE_MEMEORY_TEST_H_
25 26
 
26 27
 #ifdef DEBUG_MEMEORY
27
-#   define DEBUG_NEW new(__FILE__, __LINE__)
28
-void *operator new(unsigned int size, const char *file, int line);
29
-void *operator new [](unsigned int size, const char *file, int line);
30 28
 
29
+#define DEBUG_NEW new(__FILE__, __LINE__)
30
+void *operator new(size_t size, const char *file, int line);
31
+void *operator new [](size_t size, const char *file, int line);
31 32
 
32 33
 #define DEBUG_DELETE delete_check(__FILE__, __LINE__, 0);delete
33 34
 void operator delete(void *p);
34 35
 void operator delete [](void *p);
36
+
35 37
 #else
36
-#   define DEBUG_NEW new
37
-#   define DEBUG_DELETE delete
38
+
39
+#define DEBUG_NEW new
40
+#define DEBUG_DELETE delete
41
+
38 42
 #endif
39 43
 
40 44
 #define new DEBUG_NEW
@@ -47,23 +51,23 @@ void operator delete [](void *p);
47 51
 
48 52
 	long memory_used();
49 53
 	/*------------------------------------------------------
50
-	 * Pre  : 
54
+	 * Pre  :
51 55
 	 * Post : Returns amount of total memory used
52 56
 	 *
53 57
 	 *-- History ------------------------------------------
54 58
 	 *
55
-	 * 2002.03.27: 
59
+	 * 2002.03.27:
56 60
 	 * Mongoose - Created
57 61
 	 ------------------------------------------------------*/
58 62
 
59 63
 	void dump_memory_report();
60 64
 	/*------------------------------------------------------
61
-	 * Pre  : 
65
+	 * Pre  :
62 66
 	 * Post : Dumps raw Tree holding memeory accounting
63 67
 	 *
64 68
 	 *-- History ------------------------------------------
65 69
 	 *
66
-	 * 2002.03.27: 
70
+	 * 2002.03.27:
67 71
 	 * Mongoose - Created
68 72
 	 ------------------------------------------------------*/
69 73
 

Carregando…
Cancelar
Salvar