michael@0: commit 16362f7dc755d9a2cfb8df06db74a16fcc97e495 michael@0: Author: Nathan Froyd michael@0: Date: Wed Mar 5 10:58:29 2014 -0500 michael@0: michael@0: Bug 677653 - part 1 - indirect libogg memory allocations through variables michael@0: michael@0: diff --git a/media/libogg/include/ogg/ogg.h b/media/libogg/include/ogg/ogg.h michael@0: index cea4ebe..cebe38e 100644 michael@0: --- include/ogg/ogg.h michael@0: +++ include/ogg/ogg.h michael@0: @@ -202,6 +202,10 @@ extern int ogg_page_packets(const ogg_page *og); michael@0: michael@0: extern void ogg_packet_clear(ogg_packet *op); michael@0: michael@0: +extern void ogg_set_mem_functions(ogg_malloc_function_type *malloc_func, michael@0: + ogg_calloc_function_type *calloc_func, michael@0: + ogg_realloc_function_type *realloc_func, michael@0: + ogg_free_function_type *free_func); michael@0: michael@0: #ifdef __cplusplus michael@0: } michael@0: diff --git a/media/libogg/include/ogg/os_types.h b/media/libogg/include/ogg/os_types.h michael@0: index 2c75a20..83ed732 100644 michael@0: --- include/ogg/os_types.h michael@0: +++ include/ogg/os_types.h michael@0: @@ -17,12 +17,33 @@ michael@0: #ifndef _OS_TYPES_H michael@0: #define _OS_TYPES_H michael@0: michael@0: -/* make it easy on the folks that want to compile the libs with a michael@0: - different malloc than stdlib */ michael@0: -#define _ogg_malloc malloc michael@0: -#define _ogg_calloc calloc michael@0: -#define _ogg_realloc realloc michael@0: -#define _ogg_free free michael@0: +#include michael@0: + michael@0: +/* We indirect mallocs through settable-at-runtime functions to accommodate michael@0: + memory reporting in the browser. */ michael@0: + michael@0: +#ifdef __cplusplus michael@0: +extern "C" { michael@0: +#endif michael@0: + michael@0: +typedef void* (ogg_malloc_function_type)(size_t); michael@0: +typedef void* (ogg_calloc_function_type)(size_t, size_t); michael@0: +typedef void* (ogg_realloc_function_type)(void*, size_t); michael@0: +typedef void (ogg_free_function_type)(void*); michael@0: + michael@0: +extern ogg_malloc_function_type *ogg_malloc_func; michael@0: +extern ogg_calloc_function_type *ogg_calloc_func; michael@0: +extern ogg_realloc_function_type *ogg_realloc_func; michael@0: +extern ogg_free_function_type *ogg_free_func; michael@0: + michael@0: +#ifdef __cplusplus michael@0: +} michael@0: +#endif michael@0: + michael@0: +#define _ogg_malloc ogg_malloc_func michael@0: +#define _ogg_calloc ogg_calloc_func michael@0: +#define _ogg_realloc ogg_realloc_func michael@0: +#define _ogg_free ogg_free_func michael@0: michael@0: #if defined(_WIN32) michael@0: michael@0: diff --git a/media/libogg/src/ogg_alloc.c b/media/libogg/src/ogg_alloc.c michael@0: new file mode 100644 michael@0: index 0000000..4238d7b michael@0: --- /dev/null michael@0: +++ src/ogg_alloc.c michael@0: @@ -0,0 +1,31 @@ michael@0: +/******************************************************************** michael@0: + * * michael@0: + * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * michael@0: + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * michael@0: + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * michael@0: + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * michael@0: + * * michael@0: + * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 * michael@0: + * by the Xiph.Org Foundation http://www.xiph.org/ * michael@0: + * * michael@0: + *********************************************************************/ michael@0: + michael@0: +#include michael@0: +#include "ogg/os_types.h" michael@0: + michael@0: +ogg_malloc_function_type *ogg_malloc_func = malloc; michael@0: +ogg_calloc_function_type *ogg_calloc_func = calloc; michael@0: +ogg_realloc_function_type *ogg_realloc_func = realloc; michael@0: +ogg_free_function_type *ogg_free_func = free; michael@0: + michael@0: +void michael@0: +ogg_set_mem_functions(ogg_malloc_function_type *malloc_func, michael@0: + ogg_calloc_function_type *calloc_func, michael@0: + ogg_realloc_function_type *realloc_func, michael@0: + ogg_free_function_type *free_func) michael@0: +{ michael@0: + ogg_malloc_func = malloc_func; michael@0: + ogg_calloc_func = calloc_func; michael@0: + ogg_realloc_func = realloc_func; michael@0: + ogg_free_func = free_func; michael@0: +}