[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-developers] Patch: xrealloc instead of ralloc
From: |
january |
Subject: |
[GNUnet-developers] Patch: xrealloc instead of ralloc |
Date: |
Tue, 18 Feb 2003 09:12:37 -0800 |
Index: ./src/include/util/xmalloc.h
===================================================================
RCS file: /var/cvs/GNUnet/GNUnet/src/include/util/xmalloc.h,v
retrieving revision 1.14
diff -c -r1.14 xmalloc.h
*** ./src/include/util/xmalloc.h 20 Jan 2003 06:59:57 -0000 1.14
--- ./src/include/util/xmalloc.h 16 Feb 2003 19:29:11 -0000
***************
*** 55,60 ****
--- 55,72 ----
const char * filename,
const int linenumber);
+ /**
+ * Changes the size of the memory block pointed to by ptr to
+ * size bytes. The contents will be unchanged to the minimum of the old
+ * and new sizes; newly allocated memory will be uninitialized.
+ * Checks the return value, aborts if no more
+ * memory is available.
+ **/
+ void * xrealloc(void* ptr,
+ int size,
+ const char * site);
+
+
#define STRDUP(a) xstrdup(a,__FILE__,__LINE__)
#endif
Index: ./src/util/xmalloc.c
===================================================================
RCS file: /var/cvs/GNUnet/GNUnet/src/util/xmalloc.c,v
retrieving revision 1.33
diff -c -r1.33 xmalloc.c
*** ./src/util/xmalloc.c 4 Feb 2003 18:21:11 -0000 1.33
--- ./src/util/xmalloc.c 16 Feb 2003 19:29:12 -0000
***************
*** 113,116 ****
--- 113,148 ----
return res;
}
+ /**
+ * Changes the size of the memory block pointed to by ptr to
+ * size bytes. The contents will be unchanged to the minimum of the old
+ * and new sizes; newly allocated memory will be uninitialized.
+ * Checks the return value, aborts if no more
+ * memory is available.
+ **/
+ void * xrealloc(void* ptr,
+ int size,
+ const char * site) {
+ void * result;
+
+ result = realloc(ptr, size);
+ #if DEBUG_MALLOC > 2
+ printf("xrealloc: rallocating %d bytes (%x)->(%x) at site %s\n",
+ size,
+ (int) ptr,
+ (int) result,
+ site);
+ fflush(stdout);
+ #endif
+ #if DEBUG_MALLOC == 2
+ printf("%x realloc(%x) %s\n", (int)result, ptr, site);
+ fflush(stdout);
+ #endif
+ if (result == NULL && size > 0) {
+ errexit("ERROR: out of memory (%d at %s)!\n",
+ size, site);
+ }
+ return result;
+ }
+
/* end of xmalloc.c */
Index: ./src/util/parseconfig.c
===================================================================
RCS file: /var/cvs/GNUnet/GNUnet/src/util/parseconfig.c,v
retrieving revision 1.7
diff -c -r1.7 parseconfig.c
*** ./src/util/parseconfig.c 5 Feb 2003 17:54:45 -0000 1.7
--- ./src/util/parseconfig.c 16 Feb 2003 19:29:12 -0000
***************
*** 26,32 ****
*
* Todo:
* - add shutdown/done functionality
- * - realloc => xrealloc or xfree + xmalloc
**/
#include <stdio.h>
--- 26,31 ----
***************
*** 97,104 ****
/* 404 not found => create a new one */
if ((c->sec_count % ALLOC_SIZE) == (ALLOC_SIZE-2)) {
! c->sec_names =
realloc(c->sec_names,(c->sec_count+2+ALLOC_SIZE)*sizeof(char*));
! c->sec_entries =
realloc(c->sec_entries,(c->sec_count+2+ALLOC_SIZE)*sizeof(struct CFG_ENTRIES*));
}
e = cfg_init_entries();
c->sec_names[c->sec_count] = strdup(name);
--- 96,103 ----
/* 404 not found => create a new one */
if ((c->sec_count % ALLOC_SIZE) == (ALLOC_SIZE-2)) {
! c->sec_names =
xrealloc(c->sec_names,(c->sec_count+2+ALLOC_SIZE)*sizeof(char*),
"c->sec_names");
! c->sec_entries =
xrealloc(c->sec_entries,(c->sec_count+2+ALLOC_SIZE)*sizeof(struct
CFG_ENTRIES*), "c->sec_entries");
}
e = cfg_init_entries();
c->sec_names[c->sec_count] = strdup(name);
***************
*** 120,128 ****
if (i == e->ent_count) {
/* 404 not found => create a new one */
if ((e->ent_count % ALLOC_SIZE) == (ALLOC_SIZE-2)) {
! e->ent_names =
realloc(e->ent_names,(e->ent_count+2+ALLOC_SIZE)*sizeof(char*));
! e->ent_values =
realloc(e->ent_values,(e->ent_count+2+ALLOC_SIZE)*sizeof(char*));
! e->ent_seen =
realloc(e->ent_seen,(e->ent_count+2+ALLOC_SIZE)*sizeof(int*));
}
e->ent_count++;
e->ent_names[e->ent_count] = NULL;
--- 119,127 ----
if (i == e->ent_count) {
/* 404 not found => create a new one */
if ((e->ent_count % ALLOC_SIZE) == (ALLOC_SIZE-2)) {
! e->ent_names =
xrealloc(e->ent_names,(e->ent_count+2+ALLOC_SIZE)*sizeof(char*),
"e->ent_names");
! e->ent_values =
xrealloc(e->ent_values,(e->ent_count+2+ALLOC_SIZE)*sizeof(char*),
"e->ent_values");
! e->ent_seen =
xrealloc(e->ent_seen,(e->ent_count+2+ALLOC_SIZE)*sizeof(int*), "e->ent_seen");
}
e->ent_count++;
e->ent_names[e->ent_count] = NULL;
Concerned about your privacy? Follow this link to get
FREE encrypted email: https://www.hushmail.com/?l=2
Big $$$ to be made with the HushMail Affiliate Program:
https://www.hushmail.com/about.php?subloc=affiliate&l=427
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-developers] Patch: xrealloc instead of ralloc,
january <=