From 318486c7e9a3216982c612c49057fbc2ee611224 Mon Sep 17 00:00:00 2001 From: Monty Date: Sat, 4 Nov 2000 06:43:56 +0000 Subject: trade out malloc, calloc, realloc for redefinable hooks _ogg_malloc, _ogg_calloc, _ogg_realloc. svn path=/branches/branch_beta3/ogg/; revision=972 --- include/ogg/os_types.h | 8 +++++++- src/bitwise.c | 6 +++--- src/framing.c | 26 +++++++++++++------------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/include/ogg/os_types.h b/include/ogg/os_types.h index 9b65a27..ae2ec45 100644 --- a/include/ogg/os_types.h +++ b/include/ogg/os_types.h @@ -12,12 +12,18 @@ ******************************************************************** function: #ifdef jail to whip a few platforms into the UNIX ideal. - last mod: $Id: os_types.h,v 1.1.2.1 2000/11/04 06:17:22 xiphmont Exp $ + last mod: $Id: os_types.h,v 1.1.2.2 2000/11/04 06:43:28 xiphmont Exp $ ********************************************************************/ #ifndef _OS_TYPES_H #define _OS_TYPES_H +/* make it easy on the folks that want to compile the libs with a + different malloc than stdlib */ +#define _ogg_malloc malloc +#define _ogg_calloc calloc +#define _ogg_realloc realloc + #ifdef _WIN32 # ifndef __GNUC__ diff --git a/src/bitwise.c b/src/bitwise.c index fd92cd1..2f08809 100644 --- a/src/bitwise.c +++ b/src/bitwise.c @@ -12,7 +12,7 @@ ******************************************************************** function: packing variable sized words into an octet stream - last mod: $Id: bitwise.c,v 1.2.2.1 2000/11/04 06:17:23 xiphmont Exp $ + last mod: $Id: bitwise.c,v 1.2.2.2 2000/11/04 06:43:28 xiphmont Exp $ ********************************************************************/ @@ -36,7 +36,7 @@ static unsigned long mask[]= void oggpack_writeinit(oggpack_buffer *b){ memset(b,0,sizeof(oggpack_buffer)); - b->ptr=b->buffer=malloc(BUFFER_INCREMENT); + b->ptr=b->buffer=_ogg_malloc(BUFFER_INCREMENT); b->buffer[0]='\0'; b->storage=BUFFER_INCREMENT; } @@ -61,7 +61,7 @@ void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){ /* Takes only up to 32 bits. */ void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){ if(b->endbyte+4>=b->storage){ - b->buffer=realloc(b->buffer,b->storage+BUFFER_INCREMENT); + b->buffer=_ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT); b->storage+=BUFFER_INCREMENT; b->ptr=b->buffer+b->endbyte; } diff --git a/src/framing.c b/src/framing.c index 9803174..59d36f2 100644 --- a/src/framing.c +++ b/src/framing.c @@ -13,7 +13,7 @@ function: code raw [Vorbis] packets into framed OggSquish stream and decode Ogg streams back into raw packets - last mod: $Id: framing.c,v 1.6.2.3 2000/11/04 06:17:23 xiphmont Exp $ + last mod: $Id: framing.c,v 1.6.2.4 2000/11/04 06:43:28 xiphmont Exp $ note: The CRC code is directly derived from public domain code by Ross Williams (ross@guest.adelaide.edu.au). See docs/framing.html @@ -137,11 +137,11 @@ int ogg_stream_init(ogg_stream_state *os,int serialno){ if(os){ memset(os,0,sizeof(ogg_stream_state)); os->body_storage=16*1024; - os->body_data=malloc(os->body_storage*sizeof(char)); + os->body_data=_ogg_malloc(os->body_storage*sizeof(char)); os->lacing_storage=1024; - os->lacing_vals=malloc(os->lacing_storage*sizeof(int)); - os->granule_vals=malloc(os->lacing_storage*sizeof(ogg_int64_t)); + os->lacing_vals=_ogg_malloc(os->lacing_storage*sizeof(int)); + os->granule_vals=_ogg_malloc(os->lacing_storage*sizeof(ogg_int64_t)); /* initialize the crc_lookup table if not done */ _ogg_crc_init(); @@ -179,15 +179,15 @@ int ogg_stream_destroy(ogg_stream_state *os){ static void _os_body_expand(ogg_stream_state *os,int needed){ if(os->body_storage<=os->body_fill+needed){ os->body_storage+=(needed+1024); - os->body_data=realloc(os->body_data,os->body_storage); + os->body_data=_ogg_realloc(os->body_data,os->body_storage); } } static void _os_lacing_expand(ogg_stream_state *os,int needed){ if(os->lacing_storage<=os->lacing_fill+needed){ os->lacing_storage+=(needed+32); - os->lacing_vals=realloc(os->lacing_vals,os->lacing_storage*sizeof(int)); - os->granule_vals=realloc(os->granule_vals,os->lacing_storage*sizeof(ogg_int64_t)); + os->lacing_vals=_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(int)); + os->granule_vals=_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(ogg_int64_t)); } } @@ -462,9 +462,9 @@ char *ogg_sync_buffer(ogg_sync_state *oy, long size){ long newsize=size+oy->fill+4096; /* an extra page to be nice */ if(oy->data) - oy->data=realloc(oy->data,newsize); + oy->data=_ogg_realloc(oy->data,newsize); else - oy->data=malloc(newsize); + oy->data=_ogg_malloc(newsize); oy->storage=newsize; } @@ -913,11 +913,11 @@ void print_header(ogg_page *og){ } void copy_page(ogg_page *og){ - unsigned char *temp=malloc(og->header_len); + unsigned char *temp=_ogg_malloc(og->header_len); memcpy(temp,og->header,og->header_len); og->header=temp; - temp=malloc(og->body_len); + temp=_ogg_malloc(og->body_len); memcpy(temp,og->body,og->body_len); og->body=temp; } @@ -1114,7 +1114,7 @@ const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05, 1,0}; void test_pack(const int *pl, const int **headers){ - unsigned char *data=malloc(1024*1024); /* for scripted test cases only */ + unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */ long inptr=0; long outptr=0; long deptr=0; @@ -1371,7 +1371,7 @@ int main(void){ { /* build a bunch of pages for testing */ - unsigned char *data=malloc(1024*1024); + unsigned char *data=_ogg_malloc(1024*1024); int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1}; int inptr=0,i,j; ogg_page og[5]; -- cgit v1.2.1