gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r365 - in GNUnet/src: include util


From: durner
Subject: [GNUnet-SVN] r365 - in GNUnet/src: include util
Date: Fri, 4 Mar 2005 11:31:24 -0800 (PST)

Author: durner
Date: 2005-03-04 11:31:22 -0800 (Fri, 04 Mar 2005)
New Revision: 365

Modified:
   GNUnet/src/include/gnunet_util.h
   GNUnet/src/util/xmalloc.c
Log:
REALLOC

Modified: GNUnet/src/include/gnunet_util.h
===================================================================
--- GNUnet/src/include/gnunet_util.h    2005-03-04 17:33:48 UTC (rev 364)
+++ GNUnet/src/include/gnunet_util.h    2005-03-04 19:31:22 UTC (rev 365)
@@ -1026,6 +1026,23 @@
 #define MALLOC(size) xmalloc_(size, __FILE__,__LINE__)
 
 /**
+ * Reallocate memory. Checks the return value, aborts if no more
+ * memory is available.
+ */
+void * xrealloc_(void * ptr,
+      const size_t n,
+      const char * filename,
+      const int linenumber);
+
+/**
+ * Wrapper around realloc. Rellocates size bytes of memory.
+ * @param ptr the pointer to reallocate
+ * @param size the number of bytes to reallocate
+ * @return pointer to size bytes of memory
+ */
+#define REALLOC(ptr, size) xrealloc_(ptr, size, __FILE__,__LINE__)
+
+/**
  * Free memory. Merely a wrapper for the case that we
  * want to keep track of allocations.  Don't use xfree_
  * directly. Use the FREE macro.

Modified: GNUnet/src/util/xmalloc.c
===================================================================
--- GNUnet/src/util/xmalloc.c   2005-03-04 17:33:48 UTC (rev 364)
+++ GNUnet/src/util/xmalloc.c   2005-03-04 19:31:22 UTC (rev 365)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2003 Christian Grothoff (and other contributing authors)
+     (C) 2001, 2002, 2003, 2005 Christian Grothoff (and other contributing 
authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -97,6 +97,50 @@
 }
 
 /**
+ * Reallocate memory. Checks the return value, aborts if no more
+ * memory is available.
+ *
+ * @ptr the pointer to reallocate
+ * @param size how many bytes of memory to allocate, do NOT use
+ *  this function (or MALLOC) to allocate more than several MB
+ *  of memory
+ * @param filename where in the code was the call to REALLOC
+ * @param linenumber where in the code was the call to REALLOC
+ * @return pointer to size bytes of memory
+ */
+void * xrealloc_(void * ptr,
+      const size_t n,
+      const char * filename,
+      const int linenumber) {
+#if DEBUG_MALLOC 
+  MUTEX_LOCK(&lock);
+  printf("%p free %s:%d\n", 
+   ptr, 
+   filename,
+   linenumber);
+  MUTEX_UNLOCK(&lock);
+#endif        
+  
+  ptr = realloc(ptr, n);
+
+  if (!ptr) 
+    DIE_STRERROR_FL(filename, linenumber, "realloc");
+
+#if DEBUG_MALLOC 
+  MUTEX_LOCK(&lock);
+  printf("%p malloc %s:%d (%d bytes)\n", 
+   ptr, 
+   filename,
+   linenumber,
+   n);
+  fflush(stdout);
+  MUTEX_UNLOCK(&lock);
+#endif
+    
+  return ptr;
+}
+
+/**
  * Free memory. Merely a wrapper for the case that we
  * want to keep track of allocations.
  *





reply via email to

[Prev in Thread] Current Thread [Next in Thread]