From f757d023ef6c8a89895bdb03cc3452dd35fb373e Mon Sep 17 00:00:00 2001
From: Martin Stjernholm <mast@lysator.liu.se>
Date: Thu, 1 May 2008 23:44:34 +0200
Subject: [PATCH] Use a better type for counting bytes.

Rev: src/array.c:1.204
Rev: src/array.h:1.73
Rev: src/block_alloc.h:1.85
Rev: src/block_alloc_h.h:1.25
Rev: src/builtin_functions.c:1.658
Rev: src/multiset.h:1.42
Rev: src/object.c:1.287
Rev: src/program.h:1.241
Rev: src/stralloc.c:1.214
Rev: src/stralloc.h:1.101
---
 src/array.c             |  6 ++---
 src/array.h             |  4 +--
 src/block_alloc.h       |  6 ++---
 src/block_alloc_h.h     |  4 +--
 src/builtin_functions.c | 56 ++++++++++++++++++++---------------------
 src/multiset.h          |  4 +--
 src/object.c            |  6 ++---
 src/program.h           |  4 +--
 src/stralloc.c          | 12 +++++----
 src/stralloc.h          |  4 +--
 10 files changed, 54 insertions(+), 52 deletions(-)

diff --git a/src/array.c b/src/array.c
index 91eda9c9e3..a174b87526 100644
--- a/src/array.c
+++ b/src/array.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: array.c,v 1.203 2008/05/01 20:15:44 mast Exp $
+|| $Id: array.c,v 1.204 2008/05/01 21:44:32 mast Exp $
 */
 
 #include "global.h"
@@ -2816,9 +2816,9 @@ void debug_dump_array(struct array *a)
  *  memory allocated for arrays (array structs + svalues). Called from
  *  _memory_usage, which is exposed through Debug.memory_usage().
  */
-void count_memory_in_arrays(INT32 *num_, INT32 *size_)
+void count_memory_in_arrays(size_t *num_, size_t *size_)
 {
-  INT32 num=0, size=0;
+  size_t num=0, size=0;
   struct array *m;
   for(m=first_array;m;m=m->next)
   {
diff --git a/src/array.h b/src/array.h
index 6cecae9e7b..46d277ae59 100644
--- a/src/array.h
+++ b/src/array.h
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: array.h,v 1.72 2008/01/29 20:10:06 grubba Exp $
+|| $Id: array.h,v 1.73 2008/05/01 21:44:32 mast Exp $
 */
 
 #ifndef ARRAY_H
@@ -204,7 +204,7 @@ size_t gc_free_all_unreferenced_arrays(void);
 void debug_dump_type_field(TYPE_FIELD t);
 void debug_dump_array(struct array *a);
 #endif
-void count_memory_in_arrays(INT32 *num_, INT32 *size_);
+void count_memory_in_arrays(size_t *num_, size_t *size_);
 PMOD_EXPORT struct array *explode_array(struct array *a, struct array *b);
 PMOD_EXPORT struct array *implode_array(struct array *a, struct array *b);
 /* Prototypes end here */
diff --git a/src/block_alloc.h b/src/block_alloc.h
index 144ea87f19..8e1e469543 100644
--- a/src/block_alloc.h
+++ b/src/block_alloc.h
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: block_alloc.h,v 1.84 2008/01/24 18:34:19 grubba Exp $
+|| $Id: block_alloc.h,v 1.85 2008/05/01 21:44:32 mast Exp $
 */
 
 #undef PRE_INIT_BLOCK
@@ -440,9 +440,9 @@ void PIKE_CONCAT3(free_all_,DATA,_blocks)(void)				\
   DO_IF_RUN_UNLOCKED(mt_unlock(&PIKE_CONCAT(DATA,_mutex)));             \
 }                                                                       \
 									\
-void PIKE_CONCAT3(count_memory_in_,DATA,s)(INT32 *num_, INT32 *size_)	\
+void PIKE_CONCAT3(count_memory_in_,DATA,s)(size_t *num_, size_t *size_)	\
 {									\
-  INT32 num=0, size=0;							\
+  size_t num=0, size=0;							\
   struct PIKE_CONCAT(DATA,_block) *tmp;					\
   struct PIKE_CONCAT(DATA,_context) *ctx = PIKE_CONCAT(DATA,_ctxs);	\
   DO_IF_RUN_UNLOCKED(mt_lock(&PIKE_CONCAT(DATA,_mutex)));               \
diff --git a/src/block_alloc_h.h b/src/block_alloc_h.h
index cf3579116a..2a46a69a93 100644
--- a/src/block_alloc_h.h
+++ b/src/block_alloc_h.h
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: block_alloc_h.h,v 1.24 2008/01/24 18:34:19 grubba Exp $
+|| $Id: block_alloc_h.h,v 1.25 2008/05/01 21:44:32 mast Exp $
 */
 
 #undef BLOCK_ALLOC
@@ -26,7 +26,7 @@ void PIKE_CONCAT3(new_,DATA,_context)(void);				\
 void PIKE_CONCAT3(really_free_,DATA,_unlocked)(struct DATA *d);		\
 void PIKE_CONCAT(really_free_,DATA)(struct DATA *d);			\
 void PIKE_CONCAT3(free_all_,DATA,_blocks)(void);			\
-void PIKE_CONCAT3(count_memory_in_,DATA,s)(INT32 *num, INT32 *size);	\
+void PIKE_CONCAT3(count_memory_in_,DATA,s)(size_t *num, size_t *size);	\
 void PIKE_CONCAT3(init_,DATA,_blocks)(void)
 
 
diff --git a/src/builtin_functions.c b/src/builtin_functions.c
index 3ec0bded1e..2911854413 100644
--- a/src/builtin_functions.c
+++ b/src/builtin_functions.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: builtin_functions.c,v 1.657 2008/05/01 20:35:18 mast Exp $
+|| $Id: builtin_functions.c,v 1.658 2008/05/01 21:44:32 mast Exp $
 */
 
 #include "global.h"
@@ -7004,64 +7004,64 @@ struct callback *add_memory_usage_callback(callback_func call,
  */
 PMOD_EXPORT void f__memory_usage(INT32 args)
 {
-  INT32 num,size;
+  size_t num,size;
   struct svalue *ss;
   pop_n_elems(args);
   ss=Pike_sp;
 
   count_memory_in_mappings(&num, &size);
   push_text("num_mappings");
-  push_int(num);
+  push_ulongest(num);
   push_text("mapping_bytes");
-  push_int(size);
+  push_ulongest(size);
 
   count_memory_in_strings(&num, &size);
   push_text("num_strings");
-  push_int(num);
+  push_ulongest(num);
   push_text("string_bytes");
-  push_int(size);
+  push_ulongest(size);
 
   count_memory_in_arrays(&num, &size);
   push_text("num_arrays");
-  push_int(num);
+  push_ulongest(num);
   push_text("array_bytes");
-  push_int(size);
+  push_ulongest(size);
 
   count_memory_in_programs(&num,&size);
   push_text("num_programs");
-  push_int(num);
+  push_ulongest(num);
   push_text("program_bytes");
-  push_int(size);
+  push_ulongest(size);
 
   count_memory_in_multisets(&num, &size);
   push_text("num_multisets");
-  push_int(num);
+  push_ulongest(num);
   push_text("multiset_bytes");
-  push_int(size);
+  push_ulongest(size);
 
   count_memory_in_objects(&num, &size);
   push_text("num_objects");
-  push_int(num);
+  push_ulongest(num);
   push_text("object_bytes");
-  push_int(size);
+  push_ulongest(size);
 
   count_memory_in_callbacks(&num, &size);
   push_text("num_callbacks");
-  push_int(num);
+  push_ulongest(num);
   push_text("callback_bytes");
-  push_int(size);
+  push_ulongest(size);
 
   count_memory_in_callables(&num, &size);
   push_text("num_callables");
-  push_int(num);
+  push_ulongest(num);
   push_text("callable_bytes");
-  push_int(size);
+  push_ulongest(size);
 
   count_memory_in_pike_frames(&num, &size);
   push_text("num_frames");
-  push_int(num);
+  push_ulongest(num);
   push_text("frame_bytes");
-  push_int(size);
+  push_ulongest(size);
 
 #ifdef DEBUG_MALLOC
   {
@@ -7072,27 +7072,27 @@ PMOD_EXPORT void f__memory_usage(INT32 args)
 
     count_memory_in_memory_maps(&num, &size);
     push_text("num_memory_maps");
-    push_int(num);
+    push_ulongest(num);
     push_text("memory_map_bytes");
-    push_int(size);
+    push_ulongest(size);
 
     count_memory_in_memory_map_entrys(&num, &size);
     push_text("num_memory_map_entries");
-    push_int(num);
+    push_ulongest(num);
     push_text("memory_map_entrie_bytes");
-    push_int(size);
+    push_ulongest(size);
 
     count_memory_in_memlocs(&num, &size);
     push_text("num_memlocs");
-    push_int(num);
+    push_ulongest(num);
     push_text("memloc_bytes");
-    push_int(size);
+    push_ulongest(size);
 
     count_memory_in_memhdrs(&num, &size);
     push_text("num_memhdrs");
-    push_int(num);
+    push_ulongest(num);
     push_text("memhdr_bytes");
-    push_int(size);
+    push_ulongest(size);
   }
 #endif
 
diff --git a/src/multiset.h b/src/multiset.h
index 00ec7fe65d..8080489acd 100644
--- a/src/multiset.h
+++ b/src/multiset.h
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: multiset.h,v 1.41 2006/08/06 16:10:41 mast Exp $
+|| $Id: multiset.h,v 1.42 2008/05/01 21:44:33 mast Exp $
 */
 
 #ifndef MULTISET_H
@@ -446,7 +446,7 @@ void check_all_multisets (int safe);
 void debug_dump_multiset (struct multiset *l);
 #endif
 
-void count_memory_in_multisets (INT32 *num, INT32 *size);
+void count_memory_in_multisets (size_t *num, size_t *size);
 void init_multiset (void);
 void exit_multiset (void);
 void test_multiset (void);
diff --git a/src/object.c b/src/object.c
index e9517d9566..41b7256d71 100644
--- a/src/object.c
+++ b/src/object.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: object.c,v 1.286 2008/04/25 11:21:27 grubba Exp $
+|| $Id: object.c,v 1.287 2008/05/01 21:44:33 mast Exp $
 */
 
 #include "global.h"
@@ -1175,7 +1175,7 @@ PMOD_EXPORT void low_object_index_no_free(struct svalue *to,
       if (fun >= 0) {
 	DECLARE_CYCLIC();
 	fun += p->inherits[ref->inherit_offset].identifier_level;
-	if (!BEGIN_CYCLIC(o, fun)) {
+	if (!BEGIN_CYCLIC(o, (size_t) fun)) {
 	  SET_CYCLIC_RET(1);
 	  apply_low(o, fun, 0);
 	} else {
@@ -1443,7 +1443,7 @@ PMOD_EXPORT void object_low_set_index(struct object *o,
     if (fun >= 0) {
       DECLARE_CYCLIC();
       fun += p->inherits[ref->inherit_offset].identifier_level;
-      if (!BEGIN_CYCLIC(o, fun)) {
+      if (!BEGIN_CYCLIC(o, (size_t) fun)) {
 	SET_CYCLIC_RET(1);
 	push_svalue(from);
 	apply_low(o, fun, 1);
diff --git a/src/program.h b/src/program.h
index 8270a8be72..82c0d537b6 100644
--- a/src/program.h
+++ b/src/program.h
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: program.h,v 1.240 2008/04/26 19:04:26 grubba Exp $
+|| $Id: program.h,v 1.241 2008/05/01 21:44:33 mast Exp $
 */
 
 #ifndef PROGRAM_H
@@ -935,7 +935,7 @@ PMOD_EXPORT void change_compiler_compatibility(int major, int minor);
 void make_program_executable(struct program *p);
 /* Prototypes end here */
 
-void count_memory_in_programs(INT32*,INT32*);
+void count_memory_in_programs(size_t *, size_t *);
 
 #ifndef PIKE_USE_MACHINE_CODE
 #define make_program_executable(X)
diff --git a/src/stralloc.c b/src/stralloc.c
index 6b037d658f..1263879355 100644
--- a/src/stralloc.c
+++ b/src/stralloc.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: stralloc.c,v 1.213 2007/11/11 13:18:53 nilsson Exp $
+|| $Id: stralloc.c,v 1.214 2008/05/01 21:44:33 mast Exp $
 */
 
 #include "global.h"
@@ -2036,11 +2036,12 @@ void cleanup_shared_string_table(void)
 
   if (exit_with_cleanup)
   {
-    INT32 num,size;
+    size_t num,size;
     count_memory_in_strings(&num,&size);
     if(num)
     {
-      fprintf(stderr,"Strings left: %d (%d bytes) (zapped)\n",num,size);
+      fprintf(stderr,"Strings left: %"PRINTSIZET"d "
+	      "(%"PRINTSIZET"d bytes) (zapped)\n",num,size);
 #ifdef PIKE_DEBUG
       dump_stralloc_strings();
 #endif
@@ -2074,9 +2075,10 @@ void cleanup_shared_string_table(void)
 #endif /* DO_PIKE_CLEANUP */
 }
 
-void count_memory_in_strings(INT32 *num, INT32 *size)
+void count_memory_in_strings(size_t *num, size_t *size)
 {
-  unsigned INT32 e, num_=0, size_=0;
+  unsigned INT32 e;
+  size_t num_=0, size_=0;
   if(!base_table)
   {
     *num=*size=0;
diff --git a/src/stralloc.h b/src/stralloc.h
index bd23394645..8852540318 100644
--- a/src/stralloc.h
+++ b/src/stralloc.h
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: stralloc.h,v 1.100 2006/07/05 19:28:11 mast Exp $
+|| $Id: stralloc.h,v 1.101 2008/05/01 21:44:34 mast Exp $
 */
 
 #ifndef STRALLOC_H
@@ -329,7 +329,7 @@ PMOD_EXPORT struct pike_string *string_replace(struct pike_string *str,
 				   struct pike_string *to);
 void init_shared_string_table(void);
 void cleanup_shared_string_table(void);
-void count_memory_in_strings(INT32 *num, INT32 *size);
+void count_memory_in_strings(size_t *num, size_t *size);
 unsigned gc_touch_all_strings(void);
 void gc_mark_all_strings(void);
 struct pike_string *next_pike_string (struct pike_string *s);
-- 
GitLab