Mercurial > mplayer.hg
diff libmpeg2/alloc.c @ 12932:d0a8810e155c
Importing libmpeg2 from mpeg2dec-0.4.0b
| author | henry |
|---|---|
| date | Mon, 02 Aug 2004 11:26:43 +0000 |
| parents | 2c0b6ec77d39 |
| children | da2271c341ee |
line wrap: on
line diff
--- a/libmpeg2/alloc.c Mon Aug 02 07:58:21 2004 +0000 +++ b/libmpeg2/alloc.c Mon Aug 02 11:26:43 2004 +0000 @@ -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 +static void * (* malloc_hook) (unsigned size, mpeg2_alloc_t reason) = NULL; +static int (* free_hook) (void * buf) = NULL; -void * (* mpeg2_malloc_hook) (int size, int reason) = NULL; -int (* mpeg2_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; +}
