update halloc, fix compile on gcc 5, avoid warning

This commit is contained in:
j 2015-08-28 16:32:15 +02:00
parent 1540bbfb39
commit 0bbb337e1c
5 changed files with 27 additions and 13 deletions

View File

@ -24,7 +24,7 @@ all: ${PROG}
${PROG}: ${SRC}
${CC} ${FLAGS} ${INCLUDEFLAGS} -o ${PROG} ${SRC} ${LINKFLAGS}
${CC} -std=c99 ${FLAGS} ${INCLUDEFLAGS} -o ${PROG} ${SRC} ${LINKFLAGS}
clean:
-@rm -f ${PROG} *~ core *.core src/*.o src/halloc/src/*.o

View File

@ -15,6 +15,15 @@
#ifndef _LIBP_ALIGN_H_
#define _LIBP_ALIGN_H_
#ifdef _MSC_VER
/*
* MSVC defines max_align_t as a double.
*/
typedef double max_align_t;
#else
/*
* a type with the most strict alignment requirements
*/
@ -34,3 +43,5 @@ typedef union max_align max_align_t;
#endif
#endif

View File

@ -46,7 +46,7 @@ realloc_t halloc_allocator = NULL;
/*
* static methods
*/
static void _set_allocator(void);
int halloc_set_allocator(realloc_t realloc_func);
static void * _realloc(void * ptr, size_t n);
static int _relate(hblock_t * b, hblock_t * p);
@ -62,7 +62,10 @@ void * halloc(void * ptr, size_t len)
/* set up default allocator */
if (! allocator)
{
_set_allocator();
if (halloc_set_allocator(realloc) == 0)
{
halloc_set_allocator(_realloc);
}
assert(allocator);
}
@ -172,7 +175,7 @@ char * h_strdup(const char * str)
/*
* static stuff
*/
static void _set_allocator(void)
int halloc_set_allocator(realloc_t realloc_func)
{
void * p;
assert(! allocator);
@ -187,17 +190,17 @@ static void _set_allocator(void)
*
* Thanks to Stan Tobias for pointing this tricky part out.
*/
allocator = realloc;
if (! (p = malloc(1)))
if (! (p = realloc_func(NULL, 1)))
/* hmm */
return;
return -1;
if ((p = realloc(p, 0)))
if ((p = realloc_func(p, 0)))
{
/* realloc cannot be used as free() */
allocator = _realloc;
free(p);
/* realloc_func cannot be used as free() */
return 0;
}
allocator = realloc_func;
return 1;
}
static void * _realloc(void * ptr, size_t n)

View File

@ -20,7 +20,7 @@
/*
restore pointer to the structure by a pointer to its field
*/
#define structof(p,t,f) ((t*)(- offsetof(t,f) + (char*)(p)))
#define structof(p,t,f) ((t*)(- (ptrdiff_t) offsetof(t,f) + (char*)(p)))
/*
* redefine for the target compiler

View File

@ -985,7 +985,7 @@ static int
ne_read_simple(nestegg * ctx, struct ebml_element_desc * desc, size_t length)
{
struct ebml_type * storage;
int r;
int r = 0;
storage = (struct ebml_type *) (ctx->ancestor->data + desc->offset);