|
MythTV
0.26-pre
|
00001 /* 00002 * alloc.c 00003 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> 00004 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 00005 * 00006 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. 00007 * See http://libmpeg2.sourceforge.net/ for updates. 00008 * 00009 * mpeg2dec is free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * mpeg2dec is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program; if not, write to the Free Software 00021 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00022 */ 00023 00024 #include <stdlib.h> 00025 #include <inttypes.h> 00026 00027 #include "mpeg2.h" 00028 00029 static void * (* malloc_hook) (unsigned size, mpeg2_alloc_t reason) = NULL; 00030 static int (* free_hook) (void * buf) = NULL; 00031 00032 void * mpeg2_malloc (unsigned size, mpeg2_alloc_t reason) 00033 { 00034 char * buf; 00035 00036 if (malloc_hook) { 00037 buf = (char *) malloc_hook (size, reason); 00038 if (buf) 00039 return buf; 00040 } 00041 00042 if (size) { 00043 buf = (char *) malloc (size + 63 + sizeof (void **)); 00044 if (buf) { 00045 char * align_buf; 00046 00047 align_buf = buf + 63 + sizeof (void **); 00048 align_buf -= (long)align_buf & 63; 00049 *(((void **)align_buf) - 1) = buf; 00050 return align_buf; 00051 } 00052 } 00053 return NULL; 00054 } 00055 00056 void mpeg2_free (void * buf) 00057 { 00058 if (free_hook && free_hook (buf)) 00059 return; 00060 00061 if (buf) 00062 free (*(((void **)buf) - 1)); 00063 } 00064 00065 void mpeg2_malloc_hooks (void * malloc (unsigned, mpeg2_alloc_t), 00066 int free (void *)) 00067 { 00068 malloc_hook = malloc; 00069 free_hook = free; 00070 }
1.7.6.1