From 46a7e96339d166fee60f80f03a8cf9281b42aa32 Mon Sep 17 00:00:00 2001 From: Julius Goryavsky Date: Thu, 2 Mar 2023 14:21:59 +0100 Subject: move alloca() definition from all *.h files to one new header file --- include/CMakeLists.txt | 2 + include/my_alloca.h | 45 ++++++++++++++++++++++ include/my_global.h | 8 +--- include/my_sys.h | 14 +------ include/mysql/service_encryption.h | 11 ++---- .../cracklib_password_check.c | 2 +- .../handlersocket/hstcpsvr_worker.cpp | 5 +-- plugin/handler_socket/libhsclient/allocator.hpp | 1 + 8 files changed, 56 insertions(+), 32 deletions(-) create mode 100644 include/my_alloca.h diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 9a3f820e62f..fe02098621e 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -37,6 +37,7 @@ SET(HEADERS ma_dyncol.h my_list.h my_alloc.h + my_alloca.h typelib.h my_dbug.h m_string.h @@ -105,6 +106,7 @@ ENDMACRO() INSTALL_COMPAT_HEADER(my_global.h "") INSTALL_COMPAT_HEADER(my_config.h "") +INSTALL_COMPAT_HEADER(my_alloca.h "") INSTALL_COMPAT_HEADER(my_sys.h "") INSTALL_COMPAT_HEADER(mysql_version.h " #include diff --git a/include/my_alloca.h b/include/my_alloca.h new file mode 100644 index 00000000000..761c2adb890 --- /dev/null +++ b/include/my_alloca.h @@ -0,0 +1,45 @@ +/* Copyright (c) 2023, MariaDB Corporation. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#ifndef MY_ALLOCA_INCLUDED +#define MY_ALLOCA_INCLUDED + +#ifdef _WIN32 +#include /*for alloca*/ +/* + MSVC may define "alloca" when compiling in /Ze mode + (with extensions from Microsoft), but otherwise only + the _alloca function is defined: +*/ +#ifndef alloca +#define alloca _alloca +#endif +#else +#ifdef HAVE_ALLOCA_H +#include +#endif +#endif + +#if defined(HAVE_ALLOCA) +/* + If the GCC/LLVM compiler from the MinGW is used, + alloca may not be defined when using the MSVC CRT: +*/ +#if defined(__GNUC__) && !defined(HAVE_ALLOCA_H) && !defined(alloca) +#define alloca __builtin_alloca +#endif /* GNUC */ +#endif + +#endif /* MY_ALLOCA_INCLUDED */ diff --git a/include/my_global.h b/include/my_global.h index 1e1821e2f25..8cf06ddcb1e 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -358,13 +358,6 @@ C_MODE_END #ifdef HAVE_UNISTD_H #include #endif -#if defined(__cplusplus) && defined(NO_CPLUSPLUS_ALLOCA) -#undef HAVE_ALLOCA -#undef HAVE_ALLOCA_H -#endif -#ifdef HAVE_ALLOCA_H -#include -#endif #include /* Recommended by debian */ /* We need the following to go around a problem with openssl on solaris */ @@ -521,6 +514,7 @@ typedef unsigned short ushort; #endif #include +#include /* Wen using the embedded library, users might run into link problems, diff --git a/include/my_sys.h b/include/my_sys.h index 91610f15a50..87df04c6087 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -36,9 +36,7 @@ typedef struct my_aio_result { #include /* for CHARSET_INFO */ #include #include -#ifdef _WIN32 -#include /*for alloca*/ -#endif +#include #include #include @@ -196,16 +194,6 @@ my_bool my_test_if_atomic_write(File handle, int pagesize); extern my_bool my_may_have_atomic_write; #if defined(HAVE_ALLOCA) && !defined(HAVE_valgrind) -#if defined(_AIX) && !defined(__GNUC__) && !defined(_AIX43) -#pragma alloca -#endif /* _AIX */ -#if defined(__MWERKS__) -#undef alloca -#define alloca _alloca -#endif /* __MWERKS__ */ -#if defined(__GNUC__) && !defined(HAVE_ALLOCA_H) && ! defined(alloca) -#define alloca __builtin_alloca -#endif /* GNUC */ #define my_alloca(SZ) alloca((size_t) (SZ)) #define my_afree(PTR) ((void)0) #define MAX_ALLOCA_SZ 4096 diff --git a/include/mysql/service_encryption.h b/include/mysql/service_encryption.h index 69d205a27e8..280b9c69e35 100644 --- a/include/mysql/service_encryption.h +++ b/include/mysql/service_encryption.h @@ -24,22 +24,19 @@ *provider* (encryption plugin). */ -#ifdef __cplusplus -extern "C" { -#endif - #ifndef MYSQL_ABI_CHECK +#include #ifdef _WIN32 -#include #ifndef __cplusplus #define inline __inline #endif #else #include -#ifdef HAVE_ALLOCA_H -#include #endif #endif + +#ifdef __cplusplus +extern "C" { #endif /* returned from encryption_key_get_latest_version() */ diff --git a/plugin/cracklib_password_check/cracklib_password_check.c b/plugin/cracklib_password_check/cracklib_password_check.c index 470e6e5280f..5a7c7f3f234 100644 --- a/plugin/cracklib_password_check/cracklib_password_check.c +++ b/plugin/cracklib_password_check/cracklib_password_check.c @@ -13,7 +13,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ -#include +#include #include #include #include diff --git a/plugin/handler_socket/handlersocket/hstcpsvr_worker.cpp b/plugin/handler_socket/handlersocket/hstcpsvr_worker.cpp index 9863602af7a..f6bbe9004c2 100644 --- a/plugin/handler_socket/handlersocket/hstcpsvr_worker.cpp +++ b/plugin/handler_socket/handlersocket/hstcpsvr_worker.cpp @@ -6,7 +6,7 @@ * See COPYRIGHT.txt for details. */ -#include +#include #include #include #include @@ -17,9 +17,6 @@ #if __linux__ #include #endif -#ifdef HAVE_ALLOCA_H -#include -#endif #include "hstcpsvr_worker.hpp" #include "string_buffer.hpp" diff --git a/plugin/handler_socket/libhsclient/allocator.hpp b/plugin/handler_socket/libhsclient/allocator.hpp index dd3a28ba7bd..9df6a1ab752 100644 --- a/plugin/handler_socket/libhsclient/allocator.hpp +++ b/plugin/handler_socket/libhsclient/allocator.hpp @@ -11,6 +11,7 @@ #include #include +#include #if 0 extern "C" { -- cgit v1.2.1