From 10219a531b65ebff434f6faa04a3d7a5f56f8cc7 Mon Sep 17 00:00:00 2001 From: strawberry Date: Wed, 10 Apr 2024 20:30:40 -0400 Subject: [PATCH] dual malloc feature check Signed-off-by: strawberry --- src/config/check.rs | 7 +++++++ src/main.rs | 20 ++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/config/check.rs b/src/config/check.rs index 6e4c1587..f221cbd5 100644 --- a/src/config/check.rs +++ b/src/config/check.rs @@ -9,6 +9,13 @@ pub fn check(config: &Config) -> Result<(), Error> { config.warn_deprecated(); config.warn_unknown_key(); + if cfg!(feature = "hardened_malloc") && cfg!(feature = "jemalloc") { + warn!( + "hardened_malloc and jemalloc were built together, this causes neither to be used. Conduwuit will still \ + function, but consider rebuilding and pick one as this is now no-op." + ); + } + if config.unix_socket_path.is_some() && !cfg!(unix) { return Err(Error::bad_config( "UNIX socket support is only available on *nix platforms. Please remove \"unix_socket_path\" from your \ diff --git a/src/main.rs b/src/main.rs index 724c8d92..30932d23 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,7 @@ use ruma::api::client::{ error::{Error as RumaError, ErrorBody, ErrorKind}, uiaa::UiaaResponse, }; -#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] +#[cfg(all(not(target_env = "msvc"), feature = "jemalloc", not(feature = "hardened_malloc")))] use tikv_jemallocator::Jemalloc; use tokio::{ signal, @@ -42,14 +42,26 @@ use tracing_subscriber::{prelude::*, reload, EnvFilter, Registry}; mod routes; -#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))] +#[cfg(all(not(target_env = "msvc"), feature = "jemalloc", not(feature = "hardened_malloc")))] #[global_allocator] static GLOBAL: Jemalloc = Jemalloc; -#[cfg(all(not(target_env = "msvc"), not(target_os = "macos"), feature = "hardened_malloc", target_os = "linux"))] +#[cfg(all( + not(target_env = "msvc"), + not(target_os = "macos"), + not(feature = "jemalloc"), + feature = "hardened_malloc", + target_os = "linux" +))] use hardened_malloc_rs::HardenedMalloc; -#[cfg(all(not(target_env = "msvc"), not(target_os = "macos"), feature = "hardened_malloc", target_os = "linux"))] +#[cfg(all( + not(target_env = "msvc"), + not(target_os = "macos"), + feature = "hardened_malloc", + target_os = "linux", + not(feature = "jemalloc") +))] #[global_allocator] static GLOBAL: HardenedMalloc = HardenedMalloc;