9857
|
1 /*
|
|
2 * alloc.c
|
10303
|
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
|
9857
|
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
|
|
5 *
|
|
6 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
|
|
7 * See http://libmpeg2.sourceforge.net/ for updates.
|
|
8 *
|
|
9 * mpeg2dec is free software; you can redistribute it and/or modify
|
|
10 * it under the terms of the GNU General Public License as published by
|
|
11 * the Free Software Foundation; either version 2 of the License, or
|
|
12 * (at your option) any later version.
|
|
13 *
|
|
14 * mpeg2dec is distributed in the hope that it will be useful,
|
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 * GNU General Public License for more details.
|
|
18 *
|
|
19 * You should have received a copy of the GNU General Public License
|
|
20 * along with this program; if not, write to the Free Software
|
|
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
22 */
|
|
23
|
|
24 #include "config.h"
|
|
25
|
|
26 #include <stdlib.h>
|
|
27 #include <inttypes.h>
|
|
28
|
|
29 #include "mpeg2.h"
|
|
30 #include "mpeg2_internal.h"
|
|
31
|
|
32 #if defined(HAVE_MEMALIGN) && !defined(__cplusplus)
|
|
33 /* some systems have memalign() but no declaration for it */
|
|
34 void * memalign (size_t align, size_t size);
|
|
35 #endif
|
|
36
|
|
37 void * (* mpeg2_malloc_hook) (int size, int reason) = NULL;
|
|
38 int (* mpeg2_free_hook) (void * buf) = NULL;
|
|
39
|
|
40 void * mpeg2_malloc (int size, int reason)
|
|
41 {
|
|
42 char * buf;
|
|
43
|
|
44 if (mpeg2_malloc_hook) {
|
|
45 buf = (char *) mpeg2_malloc_hook (size, reason);
|
|
46 if (buf)
|
|
47 return buf;
|
|
48 }
|
|
49
|
|
50 #if defined(HAVE_MEMALIGN) && !defined(__cplusplus) && !defined(DEBUG)
|
|
51 return memalign (16, size);
|
|
52 #else
|
|
53 buf = (char *) malloc (size + 15 + sizeof (void **));
|
|
54 if (buf) {
|
|
55 char * align_buf;
|
|
56
|
|
57 align_buf = buf + 15 + sizeof (void **);
|
|
58 align_buf -= (long)align_buf & 15;
|
|
59 *(((void **)align_buf) - 1) = buf;
|
|
60 return align_buf;
|
|
61 }
|
|
62 return NULL;
|
|
63 #endif
|
|
64 }
|
|
65
|
|
66 void mpeg2_free (void * buf)
|
|
67 {
|
|
68 if (mpeg2_free_hook && mpeg2_free_hook (buf))
|
|
69 return;
|
|
70
|
|
71 #if defined(HAVE_MEMALIGN) && !defined(__cplusplus) && !defined(DEBUG)
|
|
72 free (buf);
|
|
73 #else
|
|
74 free (*(((void **)buf) - 1));
|
|
75 #endif
|
|
76 }
|