memory-reporting.patch (3631B)
1 commit 16362f7dc755d9a2cfb8df06db74a16fcc97e495 2 Author: Nathan Froyd <froydnj@mozilla.com> 3 Date: Wed Mar 5 10:58:29 2014 -0500 4 5 Bug 677653 - part 1 - indirect libogg memory allocations through variables 6 7 diff --git a/include/ogg/ogg.h b/include/ogg/ogg.h 8 index cea4ebe..cebe38e 100644 9 --- a/include/ogg/ogg.h 10 +++ b/include/ogg/ogg.h 11 @@ -202,6 +202,10 @@ extern int ogg_page_packets(const ogg_page *og); 12 13 extern void ogg_packet_clear(ogg_packet *op); 14 15 +extern void ogg_set_mem_functions(ogg_malloc_function_type *malloc_func, 16 + ogg_calloc_function_type *calloc_func, 17 + ogg_realloc_function_type *realloc_func, 18 + ogg_free_function_type *free_func); 19 20 #ifdef __cplusplus 21 } 22 diff --git a/include/ogg/os_types.h b/include/ogg/os_types.h 23 index 2c75a20..83ed732 100644 24 --- a/include/ogg/os_types.h 25 +++ b/include/ogg/os_types.h 26 @@ -17,12 +17,33 @@ 27 #ifndef _OS_TYPES_H 28 #define _OS_TYPES_H 29 30 -/* make it easy on the folks that want to compile the libs with a 31 - different malloc than stdlib */ 32 -#define _ogg_malloc malloc 33 -#define _ogg_calloc calloc 34 -#define _ogg_realloc realloc 35 -#define _ogg_free free 36 +#include <stddef.h> 37 + 38 +/* We indirect mallocs through settable-at-runtime functions to accommodate 39 + memory reporting in the browser. */ 40 + 41 +#ifdef __cplusplus 42 +extern "C" { 43 +#endif 44 + 45 +typedef void* (ogg_malloc_function_type)(size_t); 46 +typedef void* (ogg_calloc_function_type)(size_t, size_t); 47 +typedef void* (ogg_realloc_function_type)(void*, size_t); 48 +typedef void (ogg_free_function_type)(void*); 49 + 50 +extern ogg_malloc_function_type *ogg_malloc_func; 51 +extern ogg_calloc_function_type *ogg_calloc_func; 52 +extern ogg_realloc_function_type *ogg_realloc_func; 53 +extern ogg_free_function_type *ogg_free_func; 54 + 55 +#ifdef __cplusplus 56 +} 57 +#endif 58 + 59 +#define _ogg_malloc ogg_malloc_func 60 +#define _ogg_calloc ogg_calloc_func 61 +#define _ogg_realloc ogg_realloc_func 62 +#define _ogg_free ogg_free_func 63 64 #if defined(_WIN32) 65 66 diff --git a/src/ogg_alloc.c b/src/ogg_alloc.c 67 new file mode 100644 68 index 0000000..4238d7b 69 --- /dev/null 70 +++ b/src/ogg_alloc.c 71 @@ -0,0 +1,31 @@ 72 +/******************************************************************** 73 + * * 74 + * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 75 + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 76 + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 77 + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 78 + * * 79 + * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 * 80 + * by the Xiph.Org Foundation http://www.xiph.org/ * 81 + * * 82 + *********************************************************************/ 83 + 84 +#include <stdlib.h> 85 +#include "ogg/os_types.h" 86 + 87 +ogg_malloc_function_type *ogg_malloc_func = malloc; 88 +ogg_calloc_function_type *ogg_calloc_func = calloc; 89 +ogg_realloc_function_type *ogg_realloc_func = realloc; 90 +ogg_free_function_type *ogg_free_func = free; 91 + 92 +void 93 +ogg_set_mem_functions(ogg_malloc_function_type *malloc_func, 94 + ogg_calloc_function_type *calloc_func, 95 + ogg_realloc_function_type *realloc_func, 96 + ogg_free_function_type *free_func) 97 +{ 98 + ogg_malloc_func = malloc_func; 99 + ogg_calloc_func = calloc_func; 100 + ogg_realloc_func = realloc_func; 101 + ogg_free_func = free_func; 102 +}