Move alloc.cc to maxbase
Only renames the functions. Macro names are left as is to keep the diff small.
This commit is contained in:
@ -15,43 +15,10 @@
|
||||
#include <maxscale/cdefs.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <maxbase/alloc.h>
|
||||
|
||||
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.
|
||||
*
|
||||
|
49
maxutils/maxbase/include/maxbase/alloc.h
Normal file
49
maxutils/maxbase/include/maxbase/alloc.h
Normal file
@ -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 <maxbase/cdefs.h>
|
||||
|
||||
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
|
@ -1,4 +1,5 @@
|
||||
add_library(maxbase STATIC
|
||||
alloc.cc
|
||||
atomic.cc
|
||||
eventcount.cc
|
||||
format.cc
|
||||
|
@ -11,9 +11,10 @@
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include <maxscale/alloc.h>
|
||||
#include <maxbase/alloc.h>
|
||||
#include <stdlib.h>
|
||||
#include <maxscale/log.h>
|
||||
#include <string.h>
|
||||
#include <maxbase/log.h>
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
@ -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);
|
||||
|
@ -1,7 +1,6 @@
|
||||
add_library(maxscale-common SHARED
|
||||
admin.cc
|
||||
adminusers.cc
|
||||
alloc.cc
|
||||
authenticator.cc
|
||||
backend.cc
|
||||
buffer.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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user