diff options
author | henry <henry@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2004-08-02 11:26:43 +0000 |
---|---|---|
committer | henry <henry@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2004-08-02 11:26:43 +0000 |
commit | 943139cc78038c3aea0837229298cb2c08e3f8a2 (patch) | |
tree | 56b2a2dac2c09fe1016e3e146ec19cb2aae0777a /libmpeg2/alloc.c | |
parent | 4779094c4be9af5ec0c5145d8a460b75e4a510c8 (diff) | |
download | mpv-943139cc78038c3aea0837229298cb2c08e3f8a2.tar.bz2 mpv-943139cc78038c3aea0837229298cb2c08e3f8a2.tar.xz |
Importing libmpeg2 from mpeg2dec-0.4.0b
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@12933 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpeg2/alloc.c')
-rw-r--r-- | libmpeg2/alloc.c | 54 |
1 files changed, 24 insertions, 30 deletions
diff --git a/libmpeg2/alloc.c b/libmpeg2/alloc.c index 2e4792e94d..0698937bce 100644 --- a/libmpeg2/alloc.c +++ b/libmpeg2/alloc.c @@ -21,56 +21,50 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "config.h" - #include <stdlib.h> #include <inttypes.h> #include "mpeg2.h" -#include "mpeg2_internal.h" - -#if defined(HAVE_MEMALIGN) && !defined(__cplusplus) -/* some systems have memalign() but no declaration for it */ -void * memalign (size_t align, size_t size); -#endif -void * (* mpeg2_malloc_hook) (int size, int reason) = NULL; -int (* mpeg2_free_hook) (void * buf) = NULL; +static void * (* malloc_hook) (unsigned size, mpeg2_alloc_t reason) = NULL; +static int (* free_hook) (void * buf) = NULL; -void * mpeg2_malloc (int size, int reason) +void * mpeg2_malloc (unsigned size, mpeg2_alloc_t reason) { char * buf; - if (mpeg2_malloc_hook) { - buf = (char *) mpeg2_malloc_hook (size, reason); + if (malloc_hook) { + buf = (char *) malloc_hook (size, reason); if (buf) return buf; } -#if defined(HAVE_MEMALIGN) && !defined(__cplusplus) && !defined(DEBUG) - return memalign (16, size); -#else - buf = (char *) malloc (size + 15 + sizeof (void **)); - if (buf) { - char * align_buf; + if (size) { + buf = (char *) malloc (size + 63 + sizeof (void **)); + if (buf) { + char * align_buf; - align_buf = buf + 15 + sizeof (void **); - align_buf -= (long)align_buf & 15; - *(((void **)align_buf) - 1) = buf; - return align_buf; + align_buf = buf + 63 + sizeof (void **); + align_buf -= (long)align_buf & 63; + *(((void **)align_buf) - 1) = buf; + return align_buf; + } } return NULL; -#endif } void mpeg2_free (void * buf) { - if (mpeg2_free_hook && mpeg2_free_hook (buf)) + if (free_hook && free_hook (buf)) return; -#if defined(HAVE_MEMALIGN) && !defined(__cplusplus) && !defined(DEBUG) - free (buf); -#else - free (*(((void **)buf) - 1)); -#endif + if (buf) + free (*(((void **)buf) - 1)); +} + +void mpeg2_malloc_hooks (void * malloc (unsigned, mpeg2_alloc_t), + int free (void *)) +{ + malloc_hook = malloc; + free_hook = free; } |