From bf38d85c04b24bfa7d7ad0a637840c707266c101 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 5 Jul 2010 16:52:11 +0200 Subject: [PATCH] SWZ: replace realloc with swzRealloc --- matlab/swz/c-code/mex/modify_for_mex.h | 4 ++-- matlab/swz/c-code/utilities/DWCcode/arrays/dw_array.c | 6 +++--- matlab/swz/c-code/utilities/DWCcode/ascii/dw_ascii.c | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/matlab/swz/c-code/mex/modify_for_mex.h b/matlab/swz/c-code/mex/modify_for_mex.h index 05cecd208..91d704842 100644 --- a/matlab/swz/c-code/mex/modify_for_mex.h +++ b/matlab/swz/c-code/mex/modify_for_mex.h @@ -25,12 +25,11 @@ extern int constant_seed; #define swz_fprintf_stdout mexPrintf -#undef realloc #undef free #define swzMalloc mxMalloc #define swzCalloc mxCalloc -#define realloc mxRealloc +#define swzRealloc mxRealloc #define free mxFree @@ -38,4 +37,5 @@ extern int constant_seed; #define swz_fprintf_stdout printf #define swzMalloc malloc #define swzCalloc calloc +#define swzRealloc realloc #endif diff --git a/matlab/swz/c-code/utilities/DWCcode/arrays/dw_array.c b/matlab/swz/c-code/utilities/DWCcode/arrays/dw_array.c index 74b676329..d06669c90 100644 --- a/matlab/swz/c-code/utilities/DWCcode/arrays/dw_array.c +++ b/matlab/swz/c-code/utilities/DWCcode/arrays/dw_array.c @@ -349,7 +349,7 @@ void* dw_CopyArray(void* d, void* s) Assumes Both d and s are valid pointers and both *d and *s are either null or a null terminated string. If *d is a null terminated string, then it must - have been created via a call to swzMalloc(), swzCalloc() or realloc(). + have been created via a call to swzMalloc(), swzCalloc() or swzRealloc(). Returns Returns one upon success and zero upon failure. @@ -361,14 +361,14 @@ void* dw_CopyArray(void* d, void* s) Notes It is critical that this function be called only if the destination string - was dynamically created via a call to swzMalloc(), swzCalloc() or realloc(). If + was dynamically created via a call to swzMalloc(), swzCalloc() or swzRealloc(). If this is not the case, then servere memory problems can result. */ static int dw_CopyString(void *d, void *s) { char* dest; if (*((char**)s)) - if (dest=realloc(*((char**)d),strlen(*((char**)s))+1)) + if (dest=swzRealloc(*((char**)d),strlen(*((char**)s))+1)) strcpy(*((char**)d)=dest,*((char**)s)); else return 0; diff --git a/matlab/swz/c-code/utilities/DWCcode/ascii/dw_ascii.c b/matlab/swz/c-code/utilities/DWCcode/ascii/dw_ascii.c index e0fd65151..21848479b 100644 --- a/matlab/swz/c-code/utilities/DWCcode/ascii/dw_ascii.c +++ b/matlab/swz/c-code/utilities/DWCcode/ascii/dw_ascii.c @@ -74,7 +74,7 @@ FILE *dw_AppendTextFile(char *filename) the buffer containing the file and resets *n if necessary. The if the passed buffer is null or is not large enough to contain the line, buffer is freed and a new buffer is allocated. Because of this, the passed buffer - must either null or allocated with swzMalloc(), realloc(), or swzCalloc() and the + must either null or allocated with swzMalloc(), swzRealloc(), or swzCalloc() and the calling routine is responsible for eventually freeing the memory if the return value is not null. @@ -96,7 +96,7 @@ char* dw_ReadLine(FILE *f, char *buffer, int *n) if (ptr[(i=(int)strlen(ptr))-1] == '\n') return buffer; else - if (!(nbuffer=(char*)realloc(buffer,*n+=SIZE_INCREMENT))) + if (!(nbuffer=(char*)swzRealloc(buffer,*n+=SIZE_INCREMENT))) { free(buffer); *n=0; @@ -310,7 +310,7 @@ int dw_PrintDelimitedArray(FILE *f, void* array, char delimiter) /* { */ /* //=== reallocate memory if necessary */ /* if (k+1 > *n) */ -/* if (!(ptr=(char*)realloc(buffer,*n+=INCREMENT))) */ +/* if (!(ptr=(char*)swzRealloc(buffer,*n+=INCREMENT))) */ /* { */ /* *n-=INCREMENT; */ /* return 0; */