Mercurial > libavcodec.hg
comparison mem.c @ 2425:d0bcc85d3856 libavcodec
10l (gcc 2.95 fix)
author | michael |
---|---|
date | Wed, 12 Jan 2005 11:14:12 +0000 |
parents | 18b8b2dcc037 |
children | e25782262d7d |
comparison
equal
deleted
inserted
replaced
2424:35ca0ef0c279 | 2425:d0bcc85d3856 |
---|---|
43 * CPU). av_malloc(0) must return a non NULL pointer. | 43 * CPU). av_malloc(0) must return a non NULL pointer. |
44 */ | 44 */ |
45 void *av_malloc(unsigned int size) | 45 void *av_malloc(unsigned int size) |
46 { | 46 { |
47 void *ptr; | 47 void *ptr; |
48 int diff; | |
48 | 49 |
49 /* lets disallow possible ambiguous cases */ | 50 /* lets disallow possible ambiguous cases */ |
50 if(size > INT_MAX) | 51 if(size > INT_MAX) |
51 return NULL; | 52 return NULL; |
52 | 53 |
53 #ifdef MEMALIGN_HACK | 54 #ifdef MEMALIGN_HACK |
54 int diff; | |
55 ptr = malloc(size+16+1); | 55 ptr = malloc(size+16+1); |
56 diff= ((-(int)ptr - 1)&15) + 1; | 56 diff= ((-(int)ptr - 1)&15) + 1; |
57 ptr += diff; | 57 ptr += diff; |
58 ((char*)ptr)[-1]= diff; | 58 ((char*)ptr)[-1]= diff; |
59 #elif defined (HAVE_MEMALIGN) | 59 #elif defined (HAVE_MEMALIGN) |
95 * identical to malloc(size). If size is zero, it is identical to | 95 * identical to malloc(size). If size is zero, it is identical to |
96 * free(ptr) and NULL is returned. | 96 * free(ptr) and NULL is returned. |
97 */ | 97 */ |
98 void *av_realloc(void *ptr, unsigned int size) | 98 void *av_realloc(void *ptr, unsigned int size) |
99 { | 99 { |
100 int diff; | |
100 /* lets disallow possible ambiguous cases */ | 101 /* lets disallow possible ambiguous cases */ |
101 if(size > INT_MAX) | 102 if(size > INT_MAX) |
102 return NULL; | 103 return NULL; |
103 | 104 |
104 #ifdef MEMALIGN_HACK | 105 #ifdef MEMALIGN_HACK |
105 //FIXME this isnt aligned correctly though it probably isnt needed | 106 //FIXME this isnt aligned correctly though it probably isnt needed |
106 int diff; | |
107 if(!ptr) return av_malloc(size); | 107 if(!ptr) return av_malloc(size); |
108 diff= ((char*)ptr)[-1]; | 108 diff= ((char*)ptr)[-1]; |
109 return realloc(ptr - diff, size + diff) + diff; | 109 return realloc(ptr - diff, size + diff) + diff; |
110 #else | 110 #else |
111 return realloc(ptr, size); | 111 return realloc(ptr, size); |