Bug 677653 - part 1 - indirect libogg memory allocations through variables; r=glandium,rillian
authorNathan Froyd <froydnj@mozilla.com>
Wed, 05 Mar 2014 10:58:29 -0500
changeset 172785 54c0440b476fd741f2b075ffe2633f145a8780a0
parent 172784 0cafe4b56db34a5297e4ecef6b72c887dbd7cef4
child 172786 f84cf36472d3265c221fb75c756364552856a568
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersglandium, rillian
bugs677653
milestone30.0a1
Bug 677653 - part 1 - indirect libogg memory allocations through variables; r=glandium,rillian
layout/media/symbols.def.in
media/libogg/README_MOZILLA
media/libogg/include/ogg/ogg.h
media/libogg/include/ogg/os_types.h
media/libogg/memory-reporting.patch
media/libogg/moz.build
media/libogg/src/ogg_alloc.c
media/libogg/update.sh
--- a/layout/media/symbols.def.in
+++ b/layout/media/symbols.def.in
@@ -62,16 +62,17 @@ vpx_codec_enc_config_default
 vpx_img_alloc
 vpx_codec_encode
 #endif
 #endif
 #ifdef MOZ_VORBIS
 ogg_page_bos
 ogg_page_granulepos
 ogg_page_serialno
+ogg_set_mem_functions
 ogg_stream_check
 ogg_stream_clear
 ogg_stream_eos
 ogg_stream_flush
 ogg_stream_init
 ogg_stream_packetin
 ogg_stream_packetout
 ogg_stream_pagein
--- a/media/libogg/README_MOZILLA
+++ b/media/libogg/README_MOZILLA
@@ -1,10 +1,8 @@
 The source from this directory was copied from the libogg subversion
-repository using the update.sh script. The only changes made were
-those applied by update.sh and the addition/update of moz.build and
-Makefile.in files for the Mozilla build system.
+repository using the update.sh script.
 
 The svn revision number used was r17287.
 
 The int-types.patch address a bug that config_types.h generated from
 Linux platform can't be used on OpenSolaris directly see Mozilla bug
 449754
--- a/media/libogg/include/ogg/ogg.h
+++ b/media/libogg/include/ogg/ogg.h
@@ -197,14 +197,18 @@ extern int      ogg_page_bos(const ogg_p
 extern int      ogg_page_eos(const ogg_page *og);
 extern ogg_int64_t  ogg_page_granulepos(const ogg_page *og);
 extern int      ogg_page_serialno(const ogg_page *og);
 extern long     ogg_page_pageno(const ogg_page *og);
 extern int      ogg_page_packets(const ogg_page *og);
 
 extern void     ogg_packet_clear(ogg_packet *op);
 
+extern void     ogg_set_mem_functions(ogg_malloc_function_type *malloc_func,
+                                      ogg_calloc_function_type *calloc_func,
+                                      ogg_realloc_function_type *realloc_func,
+                                      ogg_free_function_type *free_func);
 
 #ifdef __cplusplus
 }
 #endif
 
 #endif  /* _OGG_H */
--- a/media/libogg/include/ogg/os_types.h
+++ b/media/libogg/include/ogg/os_types.h
@@ -12,22 +12,43 @@
 
  function: #ifdef jail to whip a few platforms into the UNIX ideal.
  last mod: $Id: os_types.h 17712 2010-12-03 17:10:02Z xiphmont $
 
  ********************************************************************/
 #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
-#define _ogg_free    free
+#include <stddef.h>
+
+/* We indirect mallocs through settable-at-runtime functions to accommodate
+   memory reporting in the browser. */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void* (ogg_malloc_function_type)(size_t);
+typedef void* (ogg_calloc_function_type)(size_t, size_t);
+typedef void* (ogg_realloc_function_type)(void*, size_t);
+typedef void (ogg_free_function_type)(void*);
+
+extern ogg_malloc_function_type *ogg_malloc_func;
+extern ogg_calloc_function_type *ogg_calloc_func;
+extern ogg_realloc_function_type *ogg_realloc_func;
+extern ogg_free_function_type *ogg_free_func;
+
+#ifdef __cplusplus
+}
+#endif
+
+#define _ogg_malloc ogg_malloc_func
+#define _ogg_calloc ogg_calloc_func
+#define _ogg_realloc ogg_realloc_func
+#define _ogg_free ogg_free_func
 
 #if defined(_WIN32) 
 
 #  if defined(__CYGWIN__)
 #    include <stdint.h>
      typedef int16_t ogg_int16_t;
      typedef uint16_t ogg_uint16_t;
      typedef int32_t ogg_int32_t;
new file mode 100644
--- /dev/null
+++ b/media/libogg/memory-reporting.patch
@@ -0,0 +1,102 @@
+commit 16362f7dc755d9a2cfb8df06db74a16fcc97e495
+Author: Nathan Froyd <froydnj@mozilla.com>
+Date:   Wed Mar 5 10:58:29 2014 -0500
+
+    Bug 677653 - part 1 - indirect libogg memory allocations through variables
+
+diff --git a/media/libogg/include/ogg/ogg.h b/media/libogg/include/ogg/ogg.h
+index cea4ebe..cebe38e 100644
+--- include/ogg/ogg.h
++++ include/ogg/ogg.h
+@@ -202,6 +202,10 @@ extern int      ogg_page_packets(const ogg_page *og);
+ 
+ extern void     ogg_packet_clear(ogg_packet *op);
+ 
++extern void     ogg_set_mem_functions(ogg_malloc_function_type *malloc_func,
++                                      ogg_calloc_function_type *calloc_func,
++                                      ogg_realloc_function_type *realloc_func,
++                                      ogg_free_function_type *free_func);
+ 
+ #ifdef __cplusplus
+ }
+diff --git a/media/libogg/include/ogg/os_types.h b/media/libogg/include/ogg/os_types.h
+index 2c75a20..83ed732 100644
+--- include/ogg/os_types.h
++++ include/ogg/os_types.h
+@@ -17,12 +17,33 @@
+ #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
+-#define _ogg_free    free
++#include <stddef.h>
++
++/* We indirect mallocs through settable-at-runtime functions to accommodate
++   memory reporting in the browser. */
++
++#ifdef __cplusplus
++extern "C" {
++#endif
++
++typedef void* (ogg_malloc_function_type)(size_t);
++typedef void* (ogg_calloc_function_type)(size_t, size_t);
++typedef void* (ogg_realloc_function_type)(void*, size_t);
++typedef void (ogg_free_function_type)(void*);
++
++extern ogg_malloc_function_type *ogg_malloc_func;
++extern ogg_calloc_function_type *ogg_calloc_func;
++extern ogg_realloc_function_type *ogg_realloc_func;
++extern ogg_free_function_type *ogg_free_func;
++
++#ifdef __cplusplus
++}
++#endif
++
++#define _ogg_malloc ogg_malloc_func
++#define _ogg_calloc ogg_calloc_func
++#define _ogg_realloc ogg_realloc_func
++#define _ogg_free ogg_free_func
+ 
+ #if defined(_WIN32) 
+ 
+diff --git a/media/libogg/src/ogg_alloc.c b/media/libogg/src/ogg_alloc.c
+new file mode 100644
+index 0000000..4238d7b
+--- /dev/null
++++ src/ogg_alloc.c
+@@ -0,0 +1,31 @@
++/********************************************************************
++ *                                                                  *
++ * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
++ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
++ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
++ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
++ *                                                                  *
++ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
++ * by the Xiph.Org Foundation http://www.xiph.org/                  *
++ *                                                                  *
++ *********************************************************************/
++
++#include <stdlib.h>
++#include "ogg/os_types.h"
++
++ogg_malloc_function_type *ogg_malloc_func = malloc;
++ogg_calloc_function_type *ogg_calloc_func = calloc;
++ogg_realloc_function_type *ogg_realloc_func = realloc;
++ogg_free_function_type *ogg_free_func = free;
++
++void
++ogg_set_mem_functions(ogg_malloc_function_type *malloc_func,
++                      ogg_calloc_function_type *calloc_func,
++                      ogg_realloc_function_type *realloc_func,
++                      ogg_free_function_type *free_func)
++{
++  ogg_malloc_func = malloc_func;
++  ogg_calloc_func = calloc_func;
++  ogg_realloc_func = realloc_func;
++  ogg_free_func = free_func;
++}
--- a/media/libogg/moz.build
+++ b/media/libogg/moz.build
@@ -6,16 +6,17 @@
 
 EXPORTS.ogg += [
     'include/ogg/config_types.h',
     'include/ogg/ogg.h',
     'include/ogg/os_types.h',
 ]
 
 UNIFIED_SOURCES += [
+    'src/ogg_alloc.c',
     'src/ogg_bitwise.c',
     'src/ogg_framing.c',
 ]
 
 MSVC_ENABLE_PGO = True
 
 if CONFIG['GKMEDIAS_SHARED_LIBRARY']:
     NO_VISIBILITY_FLAGS = True
new file mode 100644
--- /dev/null
+++ b/media/libogg/src/ogg_alloc.c
@@ -0,0 +1,31 @@
+/********************************************************************
+ *                                                                  *
+ * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
+ *                                                                  *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
+ * by the Xiph.Org Foundation http://www.xiph.org/                  *
+ *                                                                  *
+ *********************************************************************/
+
+#include <stdlib.h>
+#include "ogg/os_types.h"
+
+ogg_malloc_function_type *ogg_malloc_func = malloc;
+ogg_calloc_function_type *ogg_calloc_func = calloc;
+ogg_realloc_function_type *ogg_realloc_func = realloc;
+ogg_free_function_type *ogg_free_func = free;
+
+void
+ogg_set_mem_functions(ogg_malloc_function_type *malloc_func,
+                      ogg_calloc_function_type *calloc_func,
+                      ogg_realloc_function_type *realloc_func,
+                      ogg_free_function_type *free_func)
+{
+  ogg_malloc_func = malloc_func;
+  ogg_calloc_func = calloc_func;
+  ogg_realloc_func = realloc_func;
+  ogg_free_func = free_func;
+}
--- a/media/libogg/update.sh
+++ b/media/libogg/update.sh
@@ -7,8 +7,12 @@ cp $1/include/ogg/ogg.h ./include/ogg/og
 cp $1/include/ogg/os_types.h ./include/ogg/os_types.h
 cp $1/CHANGES ./CHANGES
 cp $1/COPYING ./COPYING
 cp $1/README ./README
 cp $1/src/bitwise.c ./src/ogg_bitwise.c
 cp $1/src/framing.c ./src/ogg_framing.c
 cp $1/AUTHORS ./AUTHORS
 patch -p0 < solaris-types.patch
+# memory-reporting.patch adds ogg_alloc.c, make sure it doesn't exist to avoid
+# unpleasantries.
+rm -f ./src/ogg_alloc.c
+patch -p0 < memory-reporting.patch
\ No newline at end of file