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