-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provides functions to replace standard malloc/calloc/realloc/free Signed-off-by: Francis Bouvier <[email protected]>
- Loading branch information
1 parent
6266091
commit 2507f64
Showing
7 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
* Copyright 2007 John-Mark Bell <[email protected]> | ||
*/ | ||
|
||
#include <stdlib.h> | ||
|
||
#ifndef dom_hubbub_utils_h_ | ||
#define dom_hubbub_utils_h_ | ||
|
||
|
@@ -25,4 +27,24 @@ | |
#define UNUSED(x) ((void)(x)) | ||
#endif | ||
|
||
#ifndef malloc_custom | ||
#define malloc_custom | ||
|
||
typedef void *(*custom_malloc)(size_t); | ||
typedef void *(*custom_realloc)(void*, size_t); | ||
typedef void *(*custom_calloc)(size_t, size_t); | ||
typedef void (*custom_free)(void*); | ||
|
||
void *m_alloc(size_t size); | ||
void *re_alloc(void *ptr, size_t size); | ||
void *c_alloc(size_t elementCount, size_t size); | ||
void f_ree(void *ptr); | ||
|
||
#define malloc(size) m_alloc(size) | ||
#define realloc(ptr, size) re_alloc(ptr, size) | ||
#define calloc(elementCount, size) c_alloc(elementCount, size) | ||
#define free(ptr) f_ree(ptr) | ||
|
||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
* Copyright 2007 John-Mark Bell <[email protected]> | ||
*/ | ||
|
||
#include <stdlib.h> | ||
|
||
#ifndef xml_utils_h_ | ||
#define xml_utils_h_ | ||
|
||
|
@@ -25,4 +27,23 @@ | |
#define UNUSED(x) ((void)(x)) | ||
#endif | ||
|
||
#ifndef malloc_custom | ||
#define malloc_custom | ||
typedef void *(*custom_malloc)(size_t); | ||
typedef void *(*custom_realloc)(void*, size_t); | ||
typedef void *(*custom_calloc)(size_t, size_t); | ||
typedef void (*custom_free)(void*); | ||
|
||
void *m_alloc(size_t size); | ||
void *re_alloc(void *ptr, size_t size); | ||
void *c_alloc(size_t elementCount, size_t size); | ||
void f_ree(void *ptr); | ||
|
||
#define malloc(size) m_alloc(size) | ||
#define realloc(ptr, size) re_alloc(ptr, size) | ||
#define calloc(elementCount, size) c_alloc(elementCount, size) | ||
#define free(ptr) f_ree(ptr) | ||
|
||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Sources | ||
DIR_SOURCES := namespace.c hashtable.c character_valid.c validate.c walk.c | ||
DIR_SOURCES := namespace.c hashtable.c character_valid.c validate.c walk.c utils.c | ||
|
||
include $(NSBUILD)/Makefile.subdir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <stdlib.h> | ||
#include "utils.h" | ||
|
||
custom_malloc my_malloc = malloc; | ||
custom_realloc my_realloc = realloc; | ||
custom_calloc my_calloc = calloc; | ||
custom_free my_free = free; | ||
|
||
void *m_alloc(size_t size) | ||
{ | ||
return my_malloc(size); | ||
} | ||
void *re_alloc(void *ptr, size_t size) { | ||
return my_realloc(ptr, size); | ||
} | ||
void *c_alloc(size_t elementCount, size_t size) | ||
{ | ||
return my_calloc(elementCount, size); | ||
} | ||
void f_ree(void *ptr) | ||
{ | ||
my_free(ptr); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
* Copyright 2007 John-Mark Bell <[email protected]> | ||
*/ | ||
|
||
#include <stdlib.h> | ||
|
||
#ifndef dom_utils_utils_h_ | ||
#define dom_utils_utils_h_ | ||
|
||
|
@@ -25,4 +27,24 @@ | |
#define UNUSED(x) ((void)(x)) | ||
#endif | ||
|
||
#ifndef malloc_custom | ||
#define malloc_custom | ||
|
||
typedef void *(*custom_malloc)(size_t); | ||
typedef void *(*custom_realloc)(void*, size_t); | ||
typedef void *(*custom_calloc)(size_t, size_t); | ||
typedef void (*custom_free)(void*); | ||
|
||
void *m_alloc(size_t size); | ||
void *re_alloc(void *ptr, size_t size); | ||
void *c_alloc(size_t elementCount, size_t size); | ||
void f_ree(void *ptr); | ||
|
||
#define malloc(size) m_alloc(size) | ||
#define realloc(ptr, size) re_alloc(ptr, size) | ||
#define calloc(elementCount, size) c_alloc(elementCount, size) | ||
#define free(ptr) f_ree(ptr) | ||
|
||
#endif | ||
|
||
#endif |