Browse Source

simplify alloc

Julius Pfrommer 10 years ago
parent
commit
c5d284033a
3 changed files with 13 additions and 40 deletions
  1. 0 1
      CMakeLists.txt
  2. 0 28
      src/ua_util.c
  3. 13 11
      src/ua_util.h

+ 0 - 1
CMakeLists.txt

@@ -21,7 +21,6 @@ file(GLOB_RECURSE exported_headers "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h")
 file(GLOB_RECURSE headers "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h")
 file(GLOB generated_headers "${PROJECT_BINARY_DIR}/src_generated/*.h")
 set(lib_sources src/ua_types.c
-                src/ua_util.c
                 src/ua_types_encoding_binary.c
                 ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.c
                 ${PROJECT_BINARY_DIR}/src_generated/ua_namespace_0.c

+ 0 - 28
src/ua_util.c

@@ -1,28 +0,0 @@
-#include "ua_util.h"
-
-#define __USE_POSIX
-#include <stdlib.h> // malloc, free
-#include <string.h> // memcpy
-
-/* the extern inline in a *.c-file is required for other compilation units to
-   see the inline function. */
-
-void UA_free(void *ptr) {
-    free(ptr); // checks if ptr != UA_NULL in the background
-}
-
-void * UA_malloc(UA_UInt32 size) {
-    return malloc(size);
-}
-
-void * UA_realloc(void *ptr, UA_UInt32 size) {
-    return realloc(ptr, size);
-}
-
-void UA_memcpy(void *dst, void const *src, UA_UInt32 size) {
-    memcpy(dst, src, size);
-}
-
-void * UA_memset(void *ptr, UA_Int32 value, UA_UInt32 size) {
-    return memset(ptr, value, size);
-}

+ 13 - 11
src/ua_util.h

@@ -1,17 +1,19 @@
 #ifndef UA_UTIL_H_
 #define UA_UTIL_H_
 
-#include <assert.h> // assert
-
-#include <stddef.h> /* Needed for queue.h */
-#include "queue.h"
-
 #ifndef _WIN32
 #include <alloca.h>
 #else
 #include <malloc.h>
 #endif
 
+#define __USE_POSIX
+#include <stdlib.h> // malloc, free
+#include <string.h> // memcpy
+#include <assert.h> // assert
+#include <stddef.h> /* Needed for queue.h */
+#include "queue.h"
+
 #include "ua_types.h"
 
 #define UA_NULL ((void *)0)
@@ -22,12 +24,12 @@
 
 #define UA_assert(ignore) assert(ignore)
 
-// these are inlined for release builds
-void UA_free(void *ptr);
-void * UA_malloc(UA_UInt32 size);
-void * UA_realloc(void *ptr, UA_UInt32 size);
-void UA_memcpy(void *dst, void const *src, UA_UInt32 size);
-void * UA_memset(void *ptr, UA_Int32 value, UA_UInt32 size);
+/* Replace the macros with functions for custom allocators.. */
+#define UA_free(ptr) free(ptr)
+#define UA_malloc(size) malloc(size)
+#define UA_realloc(ptr, size) realloc(ptr, size)
+#define UA_memcpy(dst, src, size) memcpy(dst, src, size)
+#define UA_memset(ptr, value, size) memset(ptr, value, size)
 
 #ifdef _WIN32
 #define UA_alloca(SIZE) _alloca(SIZE)