annotate libmpeg2/alloc.c @ 24058:345b18b889c9

allow setting of ar from the commandline of configure
author mhoffman
date Thu, 16 Aug 2007 12:41:01 +0000
parents d0a8810e155c
children da2271c341ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
1 /*
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
2 * alloc.c
10303
2c0b6ec77d39 sync with libmpeg2 cvs
alex
parents: 9857
diff changeset
3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
5 *
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
6 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
7 * See http://libmpeg2.sourceforge.net/ for updates.
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
8 *
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
9 * mpeg2dec is free software; you can redistribute it and/or modify
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
12 * (at your option) any later version.
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
13 *
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
14 * mpeg2dec is distributed in the hope that it will be useful,
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
17 * GNU General Public License for more details.
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
18 *
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
22 */
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
23
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
24 #include <stdlib.h>
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
25 #include <inttypes.h>
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
26
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
27 #include "mpeg2.h"
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
28
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
29 static void * (* malloc_hook) (unsigned size, mpeg2_alloc_t reason) = NULL;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
30 static int (* free_hook) (void * buf) = NULL;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
31
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
32 void * mpeg2_malloc (unsigned size, mpeg2_alloc_t reason)
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
33 {
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
34 char * buf;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
35
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
36 if (malloc_hook) {
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
37 buf = (char *) malloc_hook (size, reason);
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
38 if (buf)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
39 return buf;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
40 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
41
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
42 if (size) {
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
43 buf = (char *) malloc (size + 63 + sizeof (void **));
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
44 if (buf) {
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
45 char * align_buf;
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
46
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
47 align_buf = buf + 63 + sizeof (void **);
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
48 align_buf -= (long)align_buf & 63;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
49 *(((void **)align_buf) - 1) = buf;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
50 return align_buf;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
51 }
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
52 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
53 return NULL;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
54 }
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
55
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
56 void mpeg2_free (void * buf)
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
57 {
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
58 if (free_hook && free_hook (buf))
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
59 return;
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
60
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
61 if (buf)
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
62 free (*(((void **)buf) - 1));
9857
89b48bc6c441 Importing libmpeg2 from mpeg2dec-0.3.1
arpi
parents:
diff changeset
63 }
12932
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
64
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
65 void mpeg2_malloc_hooks (void * malloc (unsigned, mpeg2_alloc_t),
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
66 int free (void *))
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
67 {
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
68 malloc_hook = malloc;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
69 free_hook = free;
d0a8810e155c Importing libmpeg2 from mpeg2dec-0.4.0b
henry
parents: 10303
diff changeset
70 }