From d12acf1939733a7a04b953537aab511f29f10452 Mon Sep 17 00:00:00 2001 From: Robin Linden Date: Thu, 22 Feb 2024 01:44:02 +0100 Subject: [PATCH 1/2] cleanup: Drop compat bits for not-quite-C++14 compilers --- BUILD.bazel | 3 -- lib/src/jvmMain/cpp/CMakeLists.txt | 43 ----------------------- lib/src/jvmMain/cpp/ToxAv/lifecycle.cpp | 4 ++- lib/src/jvmMain/cpp/ToxCore/lifecycle.cpp | 4 ++- lib/src/jvmMain/cpp/cpp14compat.h | 34 ------------------ lib/src/jvmMain/cpp/tox4j/Tox4j.h | 2 -- lib/src/jvmMain/cpp/util/wrap_void.h | 3 +- 7 files changed, 7 insertions(+), 86 deletions(-) delete mode 100644 lib/src/jvmMain/cpp/cpp14compat.h diff --git a/BUILD.bazel b/BUILD.bazel index c467fdf00..d200de9d8 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -53,9 +53,6 @@ cc_binary( ":lib/src/jvmMain/cpp/jni.h", ":lib/src/jvmMain/cpp/jni_md.h", ], - copts = [ - "-DHAVE_TO_STRING", - ], includes = [ "lib/src/jvmMain/cpp", "lib/src/jvmMain/proto", diff --git a/lib/src/jvmMain/cpp/CMakeLists.txt b/lib/src/jvmMain/cpp/CMakeLists.txt index 91c37d371..b59409bb3 100644 --- a/lib/src/jvmMain/cpp/CMakeLists.txt +++ b/lib/src/jvmMain/cpp/CMakeLists.txt @@ -17,48 +17,6 @@ find_package(JNI) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") -# -# C++ standard library features -# - -include(CheckCXXSourceCompiles) - -# ::gets -check_cxx_source_compiles( - " -#include -using ::gets; -int main() {} -" - HAVE_GETS) -if(HAVE_GETS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_GETS=1") -endif() - -# std::make_unique -check_cxx_source_compiles( - " -#include -using std::make_unique; -int main() {} -" - HAVE_MAKE_UNIQUE) -if(HAVE_MAKE_UNIQUE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_MAKE_UNIQUE=1") -endif() - -# std::to_string -check_cxx_source_compiles( - " -#include -using std::to_string; -int main() {} -" - HAVE_TO_STRING) -if(HAVE_TO_STRING) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_TO_STRING=1") -endif() - # # Build # @@ -101,7 +59,6 @@ add_library( ToxCrypto/ToxCrypto.cpp ToxCrypto/ToxCrypto.h Tox4j.cpp - cpp14compat.h tox4j/ToxInstances.h tox4j/Tox4j.h tox/av.cpp diff --git a/lib/src/jvmMain/cpp/ToxAv/lifecycle.cpp b/lib/src/jvmMain/cpp/ToxAv/lifecycle.cpp index b2a7900b1..5935b9f92 100644 --- a/lib/src/jvmMain/cpp/ToxAv/lifecycle.cpp +++ b/lib/src/jvmMain/cpp/ToxAv/lifecycle.cpp @@ -1,3 +1,5 @@ +#include + #include "ToxAv.h" #include "../ToxCore/ToxCore.h" @@ -122,7 +124,7 @@ TOX_METHOD (jint, New, tox4j_assert (toxav != nullptr); // Create the master events object and set up our callbacks. - auto events = tox::callbacks (make_unique ()) + auto events = tox::callbacks (std::make_unique ()) #define CALLBACK(NAME) .set () #include "tox/generated/av.h" #undef CALLBACK diff --git a/lib/src/jvmMain/cpp/ToxCore/lifecycle.cpp b/lib/src/jvmMain/cpp/ToxCore/lifecycle.cpp index 9f70b3559..d6e8727ec 100644 --- a/lib/src/jvmMain/cpp/ToxCore/lifecycle.cpp +++ b/lib/src/jvmMain/cpp/ToxCore/lifecycle.cpp @@ -1,3 +1,5 @@ +#include + #include "ToxCore.h" using namespace core; @@ -269,7 +271,7 @@ TOX_METHOD (jint, New, tox4j_assert (tox != nullptr); // Create the master events object and set up our callbacks. - auto events = tox::callbacks (make_unique ()) + auto events = tox::callbacks (std::make_unique ()) #define CALLBACK(NAME) .set () #include "tox/generated/core.h" #undef CALLBACK diff --git a/lib/src/jvmMain/cpp/cpp14compat.h b/lib/src/jvmMain/cpp/cpp14compat.h deleted file mode 100644 index a5a6148d5..000000000 --- a/lib/src/jvmMain/cpp/cpp14compat.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#if !defined(HAVE_GETS) -extern "C" char *gets (char *); -#endif - -#include - -#if defined(HAVE_MAKE_UNIQUE) -using ::std::make_unique; -#else - -template -std::unique_ptr -make_unique (Args &&...args) -{ - return std::unique_ptr (new T (std::forward (args)...)); -} -#endif - -#if !defined(HAVE_TO_STRING) -#include - -namespace std { - template - string - to_string (T const &v) - { - ostringstream out; - out << v; - return out.str (); - } -} -#endif diff --git a/lib/src/jvmMain/cpp/tox4j/Tox4j.h b/lib/src/jvmMain/cpp/tox4j/Tox4j.h index 9a88b0437..81cf18f20 100644 --- a/lib/src/jvmMain/cpp/tox4j/Tox4j.h +++ b/lib/src/jvmMain/cpp/tox4j/Tox4j.h @@ -1,7 +1,5 @@ #pragma once -#include "cpp14compat.h" - #include "ToxInstances.h" #include "util/jni/ArrayFromJava.h" #include "util/jni/ArrayToJava.h" diff --git a/lib/src/jvmMain/cpp/util/wrap_void.h b/lib/src/jvmMain/cpp/util/wrap_void.h index d9454fa93..7ee3831ed 100644 --- a/lib/src/jvmMain/cpp/util/wrap_void.h +++ b/lib/src/jvmMain/cpp/util/wrap_void.h @@ -1,9 +1,8 @@ #pragma once +#include #include -#include "cpp14compat.h" - /** * Helper template to capture the return value of a function call so that * functions returning void can be treated the same way as non-void ones. From 84ffab8af081b3fac83e7d0e63b0ce79298d1ea4 Mon Sep 17 00:00:00 2001 From: Robin Linden Date: Thu, 22 Feb 2024 01:52:07 +0100 Subject: [PATCH 2/2] cleanup: Replace GNU attributes w/ standardized ones --- lib/src/jvmMain/cpp/CMakeLists.txt | 1 - lib/src/jvmMain/cpp/tox4j/Tox4j.h | 7 ------- lib/src/jvmMain/cpp/util/exceptions.cpp | 2 +- lib/src/jvmMain/cpp/util/exceptions.h | 4 +--- lib/src/jvmMain/cpp/util/pp_attributes.h | 14 -------------- 5 files changed, 2 insertions(+), 26 deletions(-) delete mode 100644 lib/src/jvmMain/cpp/util/pp_attributes.h diff --git a/lib/src/jvmMain/cpp/CMakeLists.txt b/lib/src/jvmMain/cpp/CMakeLists.txt index b59409bb3..85e364ba3 100644 --- a/lib/src/jvmMain/cpp/CMakeLists.txt +++ b/lib/src/jvmMain/cpp/CMakeLists.txt @@ -78,7 +78,6 @@ add_library( util/exceptions.cpp util/exceptions.h util/instance_manager.h - util/pp_attributes.h util/pp_cat.h util/to_bytes.cpp util/to_bytes.h diff --git a/lib/src/jvmMain/cpp/tox4j/Tox4j.h b/lib/src/jvmMain/cpp/tox4j/Tox4j.h index 81cf18f20..87ed7d86b 100644 --- a/lib/src/jvmMain/cpp/tox4j/Tox4j.h +++ b/lib/src/jvmMain/cpp/tox4j/Tox4j.h @@ -9,13 +9,6 @@ #include "util/to_bytes.h" -#if defined(__GNUC__) -#define NORETURN __attribute__((__noreturn__)) -#else -#define NORETURN -#endif - - #define JAVA_METHOD_NAME(NAME) \ PP_CAT(Java_im_tox_tox4j_impl_jni_, PP_CAT(CLASS, PP_CAT(Jni_, NAME))) diff --git a/lib/src/jvmMain/cpp/util/exceptions.cpp b/lib/src/jvmMain/cpp/util/exceptions.cpp index 0756908ea..e0a7776d8 100644 --- a/lib/src/jvmMain/cpp/util/exceptions.cpp +++ b/lib/src/jvmMain/cpp/util/exceptions.cpp @@ -4,7 +4,7 @@ #include -PP_NORETURN void +[[noreturn]] void tox4j_fatal_error (JNIEnv *env, char const *message) { env->FatalError (message); diff --git a/lib/src/jvmMain/cpp/util/exceptions.h b/lib/src/jvmMain/cpp/util/exceptions.h index 762000992..e96d552b2 100644 --- a/lib/src/jvmMain/cpp/util/exceptions.h +++ b/lib/src/jvmMain/cpp/util/exceptions.h @@ -4,8 +4,6 @@ #include -#include "util/pp_attributes.h" - void throw_tox_killed_exception (JNIEnv *env, jint instance_number, char const *message); void throw_illegal_state_exception (JNIEnv *env, jint instance_number, char const *message); @@ -13,7 +11,7 @@ void throw_illegal_state_exception (JNIEnv *env, jint instance_number, std::stri void throw_tox_exception (JNIEnv *env, char const *module, char const *prefix, char const *method, char const *code); -PP_NORETURN void tox4j_fatal_error (JNIEnv *env, char const *message); +[[noreturn]] void tox4j_fatal_error (JNIEnv *env, char const *message); #define tox4j_fatal(message) tox4j_fatal_error (env, message) diff --git a/lib/src/jvmMain/cpp/util/pp_attributes.h b/lib/src/jvmMain/cpp/util/pp_attributes.h deleted file mode 100644 index 3e90d1bc4..000000000 --- a/lib/src/jvmMain/cpp/util/pp_attributes.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef PP_ATTRIBUTES_H -#define PP_ATTRIBUTES_H - - -#if defined(__GNUC__) -# define PP_UNUSED __attribute__ ((__unused__)) -# define PP_NORETURN __attribute__ ((__noreturn__)) -#else -# define PP_NORETURN -# define PP_UNUSED -#endif - - -#endif /* PP_ATTRIBUTES_H */