From 2d8b52f7443c1cb0f54ad0d8a6141f7bf89ebdad Mon Sep 17 00:00:00 2001 From: Jay Sorg Date: Sat, 25 Mar 2023 12:22:19 -0700 Subject: [PATCH] common: change g_malloc, g_free, g_memset, g_memcpy, and g_memmove to macros --- common/arch.h | 1 + common/os_calls.c | 53 ----------------------------------------------- common/os_calls.h | 12 ++++++----- 3 files changed, 8 insertions(+), 58 deletions(-) diff --git a/common/arch.h b/common/arch.h index ec0aa05a..38e79d5c 100644 --- a/common/arch.h +++ b/common/arch.h @@ -20,6 +20,7 @@ #define ARCH_H #include +#include #if defined(HAVE_STDINT_H) #include diff --git a/common/os_calls.c b/common/os_calls.c index c6bc7e7b..5f357bf1 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -192,38 +192,6 @@ g_deinit(void) g_rm_temp_dir(); } -/*****************************************************************************/ -/* allocate memory, returns a pointer to it, size bytes are allocated, - if zero is non zero, each byte will be set to zero */ -void * -g_malloc(int size, int zero) -{ - char *rv; - - rv = (char *)malloc(size); - - if (zero) - { - if (rv != 0) - { - memset(rv, 0, size); - } - } - - return rv; -} - -/*****************************************************************************/ -/* free the memory pointed to by ptr, ptr can be zero */ -void -g_free(void *ptr) -{ - if (ptr != 0) - { - free(ptr); - } -} - /*****************************************************************************/ /* output text to stdout, try to use g_write / g_writeln instead to avoid linux / windows EOL problems */ @@ -333,27 +301,6 @@ g_hexdump(const char *p, int len) } } -/*****************************************************************************/ -void -g_memset(void *ptr, int val, int size) -{ - memset(ptr, val, size); -} - -/*****************************************************************************/ -void -g_memcpy(void *d_ptr, const void *s_ptr, int size) -{ - memcpy(d_ptr, s_ptr, size); -} - -/*****************************************************************************/ -void -g_memmove(void *d_ptr, const void *s_ptr, int size) -{ - memmove(d_ptr, s_ptr, size); -} - /*****************************************************************************/ int g_getchar(void) diff --git a/common/os_calls.h b/common/os_calls.h index 5304ae66..177129ef 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -52,8 +52,6 @@ int g_rm_temp_dir(void); int g_mk_socket_path(const char *app_name); void g_init(const char *app_name); void g_deinit(void); -void *g_malloc(int size, int zero); -void g_free(void *ptr); void g_printf(const char *format, ...) printflike(1, 2); void g_sprintf(char *dest, const char *format, ...) \ printflike(2, 3); @@ -62,9 +60,6 @@ printflike(3, 4); void g_writeln(const char *format, ...) printflike(1, 2); void g_write(const char *format, ...) printflike(1, 2); void g_hexdump(const char *p, int len); -void g_memset(void *ptr, int val, int size); -void g_memcpy(void *d_ptr, const void *s_ptr, int size); -void g_memmove(void *d_ptr, const void *s_ptr, int size); int g_getchar(void); int g_tcp_set_no_delay(int sck); int g_tcp_set_keepalive(int sck); @@ -309,4 +304,11 @@ int g_tcp6_bind_address(int sck, const char *port, const char *address); #define g_new0(struct_type, n_structs) \ (struct_type *) calloc((n_structs), sizeof(struct_type)) +/* remove these when no longer used */ +#define g_malloc(_size, _zero) (_zero ? calloc(1, _size) : malloc(_size)) +#define g_free free +#define g_memset memset +#define g_memcpy memcpy +#define g_memmove memmove + #endif