From 760f2ff34c65ead476ebef7932cb0cd6ac06aa3b Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Fri, 30 Nov 2018 15:21:07 +0200 Subject: [PATCH] Move alloc.cc to maxbase Only renames the functions. Macro names are left as is to keep the diff small. --- include/maxscale/alloc.h | 35 +------------ maxutils/maxbase/include/maxbase/alloc.h | 49 +++++++++++++++++++ maxutils/maxbase/src/CMakeLists.txt | 1 + .../core => maxutils/maxbase/src}/alloc.cc | 49 +++++++------------ query_classifier/qc_sqlite/qc_sqlite.cc | 6 +-- server/core/CMakeLists.txt | 1 - server/modules/routing/binlogrouter/blr.cc | 2 +- .../modules/routing/binlogrouter/blr_slave.cc | 4 +- 8 files changed, 75 insertions(+), 72 deletions(-) create mode 100644 maxutils/maxbase/include/maxbase/alloc.h rename {server/core => maxutils/maxbase/src}/alloc.cc (86%) diff --git a/include/maxscale/alloc.h b/include/maxscale/alloc.h index 774400362..b9cb2af6e 100644 --- a/include/maxscale/alloc.h +++ b/include/maxscale/alloc.h @@ -15,43 +15,10 @@ #include #include #include +#include MXS_BEGIN_DECLS -/* - * NOTE: Do not use these functions directly, use the macros below. - */ - -// "caller" arg temporarily disabled so that existing code -// using the previous version of mxs_alloc etc. will continue -// to compile. -void* mxs_malloc(size_t size /*, const char *caller*/); -void* mxs_calloc(size_t nmemb, size_t size /*, const char *caller*/); -void* mxs_realloc(void* ptr, size_t size /*, const char *caller*/); -void mxs_free(void* ptr /*, const char *caller*/); - -char* mxs_strdup(const char* s /*, const char *caller*/); -char* mxs_strndup(const char* s, size_t n /*, const char *caller*/); - -char* mxs_strdup_a(const char* s /*, const char *caller*/); -char* mxs_strndup_a(const char* s, size_t n /*, const char *caller*/); - - -/* - * NOTE: USE these macros instead of the functions above. - */ -#define MXS_MALLOC(size) mxs_malloc(size /*, __func__*/) -#define MXS_CALLOC(nmemb, size) mxs_calloc(nmemb, size /*, __func__*/) -#define MXS_REALLOC(ptr, size) mxs_realloc(ptr, size /*, __func__*/) -#define MXS_FREE(ptr) mxs_free(ptr /*, __func__*/) - -#define MXS_STRDUP(s) mxs_strdup(s /*, __func__*/) -#define MXS_STRNDUP(s, n) mxs_strndup(s, n /*, __func__*/) - -#define MXS_STRDUP_A(s) mxs_strdup_a(s /*, __func__*/) -#define MXS_STRNDUP_A(s, n) mxs_strndup_a(s, n /*, __func__*/) - - /** * @brief Abort the process if the pointer is NULL. * diff --git a/maxutils/maxbase/include/maxbase/alloc.h b/maxutils/maxbase/include/maxbase/alloc.h new file mode 100644 index 000000000..4844e4b32 --- /dev/null +++ b/maxutils/maxbase/include/maxbase/alloc.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2018 MariaDB Corporation Ab + * + * Use of this software is governed by the Business Source License included + * in the LICENSE.TXT file and at www.mariadb.com/bsl11. + * + * Change Date: 2022-01-01 + * + * On the date above, in accordance with the Business Source License, use + * of this software will be governed by version 2 or later of the General + * Public License. + */ +#pragma once + +#include + +MXB_BEGIN_DECLS + +/* NOTE: Do not use these functions directly, use the macros below. */ +// "caller" arg temporarily disabled so that existing code +// using the previous version of mxs_alloc etc. will continue +// to compile. +void* mxb_malloc(size_t size /*, const char *caller*/); +void* mxb_calloc(size_t nmemb, size_t size /*, const char *caller*/); +void* mxb_realloc(void* ptr, size_t size /*, const char *caller*/); +void mxb_free(void* ptr /*, const char *caller*/); + +char* mxb_strdup(const char* s /*, const char *caller*/); +char* mxb_strndup(const char* s, size_t n /*, const char *caller*/); + +char* mxb_strdup_a(const char* s /*, const char *caller*/); +char* mxb_strndup_a(const char* s, size_t n /*, const char *caller*/); + + +/* + * NOTE: USE these macros instead of the functions above. + */ +#define MXS_MALLOC(size) mxb_malloc(size /*, __func__*/) +#define MXS_CALLOC(nmemb, size) mxb_calloc(nmemb, size /*, __func__*/) +#define MXS_REALLOC(ptr, size) mxb_realloc(ptr, size /*, __func__*/) +#define MXS_FREE(ptr) mxb_free(ptr /*, __func__*/) + +#define MXS_STRDUP(s) mxb_strdup(s /*, __func__*/) +#define MXS_STRNDUP(s, n) mxb_strndup(s, n /*, __func__*/) + +#define MXS_STRDUP_A(s) mxb_strdup_a(s /*, __func__*/) +#define MXS_STRNDUP_A(s, n) mxb_strndup_a(s, n /*, __func__*/) + +MXB_END_DECLS diff --git a/maxutils/maxbase/src/CMakeLists.txt b/maxutils/maxbase/src/CMakeLists.txt index f6186ebd5..bb135123c 100644 --- a/maxutils/maxbase/src/CMakeLists.txt +++ b/maxutils/maxbase/src/CMakeLists.txt @@ -1,4 +1,5 @@ add_library(maxbase STATIC + alloc.cc atomic.cc eventcount.cc format.cc diff --git a/server/core/alloc.cc b/maxutils/maxbase/src/alloc.cc similarity index 86% rename from server/core/alloc.cc rename to maxutils/maxbase/src/alloc.cc index 677a9cb0b..bb850bba3 100644 --- a/server/core/alloc.cc +++ b/maxutils/maxbase/src/alloc.cc @@ -11,9 +11,10 @@ * Public License. */ -#include +#include #include -#include +#include +#include /** * @brief Allocates memory; behaves exactly like `malloc`. @@ -27,16 +28,14 @@ * @param caller The name of the function calling this function. * @return A pointer to the allocated memory. */ -void* mxs_malloc(size_t size /*, const char *caller*/) +void* mxb_malloc(size_t size /*, const char *caller*/) { void* ptr = malloc(size); - if (!ptr) { // MXS_OOM_MESSAGE(caller); - MXS_OOM(); + MXB_OOM(); } - return ptr; } @@ -53,16 +52,14 @@ void* mxs_malloc(size_t size /*, const char *caller*/) * @param caller The name of the function calling this function. * @return A pointer to the allocated memory. */ -void* mxs_calloc(size_t nmemb, size_t size /*, const char *caller*/) +void* mxb_calloc(size_t nmemb, size_t size /*, const char *caller*/) { void* ptr = calloc(nmemb, size); - if (!ptr) { // MXS_OOM_MESSAGE(caller); - MXS_OOM(); + MXB_OOM(); } - return ptr; } @@ -81,16 +78,14 @@ void* mxs_calloc(size_t nmemb, size_t size /*, const char *caller*/) * @param caller The name of the function calling this function. * @return A pointer to the allocated memory. */ -void* mxs_realloc(void* ptr, size_t size /*, const char *caller*/) +void* mxb_realloc(void* ptr, size_t size /*, const char *caller*/) { ptr = realloc(ptr, size); - if (!ptr) { // MXS_OOM_MESSAGE(caller); - MXS_OOM(); + MXB_OOM(); } - return ptr; } @@ -105,16 +100,14 @@ void* mxs_realloc(void* ptr, size_t size /*, const char *caller*/) * @param caller The name of the function calling this function. * @return A copy of the string. */ -char* mxs_strdup(const char* s1 /*, const char *caller*/) +char* mxb_strdup(const char* s1 /*, const char *caller*/) { char* s2 = strdup(s1); - if (!s2) { // MXS_OOM_MESSAGE(caller); - MXS_OOM(); + MXB_OOM(); } - return s2; } @@ -130,16 +123,14 @@ char* mxs_strdup(const char* s1 /*, const char *caller*/) * @param caller The name of the function calling this function. * @return A copy of the string. */ -char* mxs_strndup(const char* s1, size_t n /*, const char *caller*/) +char* mxb_strndup(const char* s1, size_t n /*, const char *caller*/) { char* s2 = strndup(s1, n); - if (!s2) { // MXS_OOM_MESSAGE(caller); - MXS_OOM(); + MXB_OOM(); } - return s2; } @@ -155,7 +146,7 @@ char* mxs_strndup(const char* s1, size_t n /*, const char *caller*/) * @param ptr Pointer to the memory to be freed. * @param caller The name of the function calling this function. */ -void mxs_free(void* ptr /*, const char *caller*/) +void mxb_free(void* ptr /*, const char *caller*/) { free(ptr); } @@ -176,15 +167,13 @@ void mxs_free(void* ptr /*, const char *caller*/) * @param caller The name of the function calling this function. * @return A copy of the string. */ -char* mxs_strdup_a(const char* s1 /*, const char *caller*/) +char* mxb_strdup_a(const char* s1 /*, const char *caller*/) { - char* s2 = mxs_strdup(s1 /*, caller*/); - + char* s2 = mxb_strdup(s1 /*, caller*/); if (!s2) { abort(); } - return s2; } @@ -205,14 +194,12 @@ char* mxs_strdup_a(const char* s1 /*, const char *caller*/) * @param caller The name of the function calling this function. * @return A copy of the string. */ -char* mxs_strndup_a(const char* s1, size_t n /*, const char *caller*/) +char* mxb_strndup_a(const char* s1, size_t n /*, const char *caller*/) { - char* s2 = mxs_strndup(s1, n /*, caller*/); - + char* s2 = mxb_strndup(s1, n /*, caller*/); if (!s2) { abort(); } - return s2; } diff --git a/query_classifier/qc_sqlite/qc_sqlite.cc b/query_classifier/qc_sqlite/qc_sqlite.cc index 57d26af4d..da812b0c6 100644 --- a/query_classifier/qc_sqlite/qc_sqlite.cc +++ b/query_classifier/qc_sqlite/qc_sqlite.cc @@ -3083,10 +3083,10 @@ private: { mxb_assert(m_refs == 0); - std::for_each(m_table_names.begin(), m_table_names.end(), mxs_free); - std::for_each(m_table_fullnames.begin(), m_table_fullnames.end(), mxs_free); + std::for_each(m_table_names.begin(), m_table_names.end(), mxb_free); + std::for_each(m_table_fullnames.begin(), m_table_fullnames.end(), mxb_free); free(m_zCreated_table_name); - std::for_each(m_database_names.begin(), m_database_names.end(), mxs_free); + std::for_each(m_database_names.begin(), m_database_names.end(), mxb_free); free(m_zPrepare_name); gwbuf_free(m_pPreparable_stmt); std::for_each(m_field_infos.begin(), m_field_infos.end(), finish_field_info); diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index 588b824e4..fab931f5b 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -1,7 +1,6 @@ add_library(maxscale-common SHARED admin.cc adminusers.cc - alloc.cc authenticator.cc backend.cc buffer.cc diff --git a/server/modules/routing/binlogrouter/blr.cc b/server/modules/routing/binlogrouter/blr.cc index 1b51118ea..dfa419ac5 100644 --- a/server/modules/routing/binlogrouter/blr.cc +++ b/server/modules/routing/binlogrouter/blr.cc @@ -2404,7 +2404,7 @@ static void errorReply(MXS_ROUTER* instance, { free(router->m_errmsg); } - router->m_errmsg = mxs_strdup("#28000 Authentication with master server failed"); + router->m_errmsg = mxb_strdup("#28000 Authentication with master server failed"); /* set mysql_errno */ router->m_errno = 1045; diff --git a/server/modules/routing/binlogrouter/blr_slave.cc b/server/modules/routing/binlogrouter/blr_slave.cc index ce7b04c01..6fbb2c2fe 100644 --- a/server/modules/routing/binlogrouter/blr_slave.cc +++ b/server/modules/routing/binlogrouter/blr_slave.cc @@ -7763,12 +7763,12 @@ static bool blr_handle_set_stmt(ROUTER_INSTANCE* router, v_len = strlen(word); if (v_len > 6) { - new_val = mxs_strndup_a(word, v_len - 6); + new_val = mxb_strndup_a(word, v_len - 6); slave->heartbeat = atoi(new_val) / 1000; } else { - new_val = mxs_strndup_a(word, v_len); + new_val = mxb_strndup_a(word, v_len); slave->heartbeat = atoi(new_val) / 1000000; }