Commit 08606c71 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

- Use posix_memalign when available.

 - Use inlines for expansion safety.
parent 88e2bbba
...@@ -109,25 +109,35 @@ ...@@ -109,25 +109,35 @@
* void *vlc_memalign( size_t align, size_t size, void **pp_orig ) * void *vlc_memalign( size_t align, size_t size, void **pp_orig )
* *pp_orig is the pointer that has to be freed afterwards. * *pp_orig is the pointer that has to be freed afterwards.
*/ */
#if 0 #if defined (HAVE_POSIX_MEMALIGN)
#ifdef HAVE_POSIX_MEMALIGN static inline
# define vlc_memalign(align,size,pp_orig) \ void *vlc_memalign (size_t align, size_t size, void **pp)
( !posix_memalign( pp_orig, align, size ) ? *(pp_orig) : NULL ) {
#endif return posix_memalign (pp, align, size) ? NULL : *pp;
#endif }
#ifdef HAVE_MEMALIGN #elif defined (HAVE_MEMALIGN)
/* Some systems have memalign() but no declaration for it */ static inline
void * memalign( size_t align, size_t size ); void *vlc_memalign (size_t align, size_t size, void **pp)
{
# define vlc_memalign(pp_orig,align,size) \ return *pp = memalign (align, size);
( *(pp_orig) = memalign( align, size ) ) }
#else /* We don't have any choice but to align manually */ #else /* We don't have any choice but to align manually */
# define vlc_memalign(pp_orig,align,size) \ static inline
(( *(pp_orig) = malloc( size + align - 1 )) \ void *vlc_memalign (size_t align, size_t size, void **pp)
? (void *)( (((unsigned long)*(pp_orig)) + (unsigned long)(align-1) ) \ {
& (~(unsigned long)(align-1)) ) \ unsigned char *ptr;
: NULL )
if (align < 1)
return NULL;
align--;
ptr = malloc (size + --align);
if (ptr == NULL)
return NULL;
*pp = ptr;
ptr += align;
return (void *)(((uintptr_t)ptr) & ~align);
}
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment