update halloc, fix compile on gcc 5, avoid warning
This commit is contained in:
parent
1540bbfb39
commit
0bbb337e1c
5 changed files with 27 additions and 13 deletions
2
Makefile
2
Makefile
|
@ -24,7 +24,7 @@ all: ${PROG}
|
||||||
|
|
||||||
|
|
||||||
${PROG}: ${SRC}
|
${PROG}: ${SRC}
|
||||||
${CC} ${FLAGS} ${INCLUDEFLAGS} -o ${PROG} ${SRC} ${LINKFLAGS}
|
${CC} -std=c99 ${FLAGS} ${INCLUDEFLAGS} -o ${PROG} ${SRC} ${LINKFLAGS}
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-@rm -f ${PROG} *~ core *.core src/*.o src/halloc/src/*.o
|
-@rm -f ${PROG} *~ core *.core src/*.o src/halloc/src/*.o
|
||||||
|
|
|
@ -15,6 +15,15 @@
|
||||||
#ifndef _LIBP_ALIGN_H_
|
#ifndef _LIBP_ALIGN_H_
|
||||||
#define _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
|
* a type with the most strict alignment requirements
|
||||||
*/
|
*/
|
||||||
|
@ -34,3 +43,5 @@ typedef union max_align max_align_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ realloc_t halloc_allocator = NULL;
|
||||||
/*
|
/*
|
||||||
* static methods
|
* static methods
|
||||||
*/
|
*/
|
||||||
static void _set_allocator(void);
|
int halloc_set_allocator(realloc_t realloc_func);
|
||||||
static void * _realloc(void * ptr, size_t n);
|
static void * _realloc(void * ptr, size_t n);
|
||||||
|
|
||||||
static int _relate(hblock_t * b, hblock_t * p);
|
static int _relate(hblock_t * b, hblock_t * p);
|
||||||
|
@ -62,7 +62,10 @@ void * halloc(void * ptr, size_t len)
|
||||||
/* set up default allocator */
|
/* set up default allocator */
|
||||||
if (! allocator)
|
if (! allocator)
|
||||||
{
|
{
|
||||||
_set_allocator();
|
if (halloc_set_allocator(realloc) == 0)
|
||||||
|
{
|
||||||
|
halloc_set_allocator(_realloc);
|
||||||
|
}
|
||||||
assert(allocator);
|
assert(allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +175,7 @@ char * h_strdup(const char * str)
|
||||||
/*
|
/*
|
||||||
* static stuff
|
* static stuff
|
||||||
*/
|
*/
|
||||||
static void _set_allocator(void)
|
int halloc_set_allocator(realloc_t realloc_func)
|
||||||
{
|
{
|
||||||
void * p;
|
void * p;
|
||||||
assert(! allocator);
|
assert(! allocator);
|
||||||
|
@ -187,17 +190,17 @@ static void _set_allocator(void)
|
||||||
*
|
*
|
||||||
* Thanks to Stan Tobias for pointing this tricky part out.
|
* Thanks to Stan Tobias for pointing this tricky part out.
|
||||||
*/
|
*/
|
||||||
allocator = realloc;
|
if (! (p = realloc_func(NULL, 1)))
|
||||||
if (! (p = malloc(1)))
|
|
||||||
/* hmm */
|
/* hmm */
|
||||||
return;
|
return -1;
|
||||||
|
|
||||||
if ((p = realloc(p, 0)))
|
if ((p = realloc_func(p, 0)))
|
||||||
{
|
{
|
||||||
/* realloc cannot be used as free() */
|
/* realloc_func cannot be used as free() */
|
||||||
allocator = _realloc;
|
return 0;
|
||||||
free(p);
|
|
||||||
}
|
}
|
||||||
|
allocator = realloc_func;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void * _realloc(void * ptr, size_t n)
|
static void * _realloc(void * ptr, size_t n)
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
/*
|
/*
|
||||||
restore pointer to the structure by a pointer to its field
|
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
|
* redefine for the target compiler
|
||||||
|
|
|
@ -985,7 +985,7 @@ static int
|
||||||
ne_read_simple(nestegg * ctx, struct ebml_element_desc * desc, size_t length)
|
ne_read_simple(nestegg * ctx, struct ebml_element_desc * desc, size_t length)
|
||||||
{
|
{
|
||||||
struct ebml_type * storage;
|
struct ebml_type * storage;
|
||||||
int r;
|
int r = 0;
|
||||||
|
|
||||||
storage = (struct ebml_type *) (ctx->ancestor->data + desc->offset);
|
storage = (struct ebml_type *) (ctx->ancestor->data + desc->offset);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue