void *av_malloc(unsigned int size)
{
void *ptr;
+#ifdef MEMALIGN_HACK
+ int diff;
+#endif
+
+ /* lets disallow possible ambiguous cases */
+ if(size > INT_MAX)
+ return NULL;
-#if defined (HAVE_MEMALIGN)
+#ifdef MEMALIGN_HACK
+ ptr = malloc(size+16+1);
+ diff= ((-(int)ptr - 1)&15) + 1;
+ ptr += diff;
+ ((char*)ptr)[-1]= diff;
+#elif defined (HAVE_MEMALIGN)
ptr = memalign(16,size);
/* Why 64?
Indeed, we should align it:
*/
void *av_realloc(void *ptr, unsigned int size)
{
+#ifdef MEMALIGN_HACK
+ int diff;
+#endif
+
+ /* lets disallow possible ambiguous cases */
+ if(size > INT_MAX)
+ return NULL;
+
+#ifdef MEMALIGN_HACK
+ //FIXME this isnt aligned correctly though it probably isnt needed
+ if(!ptr) return av_malloc(size);
+ diff= ((char*)ptr)[-1];
+ return realloc(ptr - diff, size + diff) + diff;
+#else
return realloc(ptr, size);
+#endif
}
/* NOTE: ptr = NULL is explicetly allowed */
{
/* XXX: this test should not be needed on most libcs */
if (ptr)
+#ifdef MEMALIGN_HACK
+ free(ptr - ((char*)ptr)[-1]);
+#else
free(ptr);
+#endif
}