SWZ: replace realloc with swzRealloc
parent
571f430085
commit
bf38d85c04
|
@ -25,12 +25,11 @@ extern int constant_seed;
|
||||||
|
|
||||||
#define swz_fprintf_stdout mexPrintf
|
#define swz_fprintf_stdout mexPrintf
|
||||||
|
|
||||||
#undef realloc
|
|
||||||
#undef free
|
#undef free
|
||||||
|
|
||||||
#define swzMalloc mxMalloc
|
#define swzMalloc mxMalloc
|
||||||
#define swzCalloc mxCalloc
|
#define swzCalloc mxCalloc
|
||||||
#define realloc mxRealloc
|
#define swzRealloc mxRealloc
|
||||||
#define free mxFree
|
#define free mxFree
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,4 +37,5 @@ extern int constant_seed;
|
||||||
#define swz_fprintf_stdout printf
|
#define swz_fprintf_stdout printf
|
||||||
#define swzMalloc malloc
|
#define swzMalloc malloc
|
||||||
#define swzCalloc calloc
|
#define swzCalloc calloc
|
||||||
|
#define swzRealloc realloc
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -349,7 +349,7 @@ void* dw_CopyArray(void* d, void* s)
|
||||||
Assumes
|
Assumes
|
||||||
Both d and s are valid pointers and both *d and *s are either null or a
|
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
|
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
|
||||||
Returns one upon success and zero upon failure.
|
Returns one upon success and zero upon failure.
|
||||||
|
@ -361,14 +361,14 @@ void* dw_CopyArray(void* d, void* s)
|
||||||
|
|
||||||
Notes
|
Notes
|
||||||
It is critical that this function be called only if the destination string
|
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.
|
this is not the case, then servere memory problems can result.
|
||||||
*/
|
*/
|
||||||
static int dw_CopyString(void *d, void *s)
|
static int dw_CopyString(void *d, void *s)
|
||||||
{
|
{
|
||||||
char* dest;
|
char* dest;
|
||||||
if (*((char**)s))
|
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));
|
strcpy(*((char**)d)=dest,*((char**)s));
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -74,7 +74,7 @@ FILE *dw_AppendTextFile(char *filename)
|
||||||
the buffer containing the file and resets *n if necessary. The if the
|
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
|
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
|
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
|
calling routine is responsible for eventually freeing the memory if the
|
||||||
return value is not null.
|
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')
|
if (ptr[(i=(int)strlen(ptr))-1] == '\n')
|
||||||
return buffer;
|
return buffer;
|
||||||
else
|
else
|
||||||
if (!(nbuffer=(char*)realloc(buffer,*n+=SIZE_INCREMENT)))
|
if (!(nbuffer=(char*)swzRealloc(buffer,*n+=SIZE_INCREMENT)))
|
||||||
{
|
{
|
||||||
free(buffer);
|
free(buffer);
|
||||||
*n=0;
|
*n=0;
|
||||||
|
@ -310,7 +310,7 @@ int dw_PrintDelimitedArray(FILE *f, void* array, char delimiter)
|
||||||
/* { */
|
/* { */
|
||||||
/* //=== reallocate memory if necessary */
|
/* //=== reallocate memory if necessary */
|
||||||
/* if (k+1 > *n) */
|
/* if (k+1 > *n) */
|
||||||
/* if (!(ptr=(char*)realloc(buffer,*n+=INCREMENT))) */
|
/* if (!(ptr=(char*)swzRealloc(buffer,*n+=INCREMENT))) */
|
||||||
/* { */
|
/* { */
|
||||||
/* *n-=INCREMENT; */
|
/* *n-=INCREMENT; */
|
||||||
/* return 0; */
|
/* return 0; */
|
||||||
|
|
Loading…
Reference in New Issue