diff --git a/src/native/clr/include/host/host-environment.hh b/src/native/clr/include/host/host-environment.hh index af8976f2f83..d0c5a7ab871 100644 --- a/src/native/clr/include/host/host-environment.hh +++ b/src/native/clr/include/host/host-environment.hh @@ -48,7 +48,7 @@ namespace xamarin::android { static void set_system_property (const char *name, const char *value) noexcept { // TODO: should we **actually** try to set the system property here? Would that even work? Needs testing - log_debug (LOG_DEFAULT, " System property {} = '{}'", optional_string (name), optional_string (value)); + log_debugf (LOG_DEFAULT, " System property %s = '%s'", optional_string (name), optional_string (value)); } [[gnu::flatten, gnu::always_inline]] @@ -94,10 +94,10 @@ namespace xamarin::android { static_local_string dir (home_len + relative_path.length ()); Util::path_combine (dir, home.get_string_view (), relative_path); - log_debug (LOG_DEFAULT, "Creating XDG directory: {}"sv, optional_string (dir.get ())); + log_debugf (LOG_DEFAULT, "Creating XDG directory: %s", optional_string (dir.get ())); int rv = Util::create_directory (dir.get (), Constants::DEFAULT_DIRECTORY_MODE); if (rv < 0 && errno != EEXIST) { - log_warn (LOG_DEFAULT, "Failed to create XDG directory {}. {}"sv, optional_string (dir.get ()), strerror (errno)); + log_warnf (LOG_DEFAULT, "Failed to create XDG directory %s. %s", optional_string (dir.get ()), strerror (errno)); } if (!environment_variable_name.empty ()) { diff --git a/src/native/clr/include/shared/log_types.hh b/src/native/clr/include/shared/log_types.hh index b87347ad0a1..54e164c87f8 100644 --- a/src/native/clr/include/shared/log_types.hh +++ b/src/native/clr/include/shared/log_types.hh @@ -1,13 +1,11 @@ #pragma once -#include #include #include #include #include -#include "java-interop-logger.h" -#include +#include // We redeclare macros here #if defined(log_debug) @@ -45,16 +43,6 @@ #define log_fatal(_category_, _fmt_, ...) log_fatal_fmt ((_category_), (_fmt_) __VA_OPT__(,) __VA_ARGS__) namespace xamarin::android { - // A slightly faster alternative to other log functions as it doesn't parse the message - // for format placeholders nor it uses variable arguments - void log_write (LogCategories category, LogLevel level, const char *message) noexcept; - void log_writev (LogCategories category, LogLevel level, const char *format, va_list args) noexcept; - void log_writef (LogCategories category, LogLevel level, const char *format, ...) noexcept __attribute__ ((format (printf, 3, 4))); - void log_debugf (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3))); - void log_infof (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3))); - void log_warnf (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3))); - void log_errorf (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3))); - [[gnu::always_inline]] static inline void log_write (LogCategories category, LogLevel level, std::string_view const& message) noexcept { diff --git a/src/native/clr/shared/helpers.cc b/src/native/clr/shared/helpers.cc index 5c95342b1af..ac482e9ae74 100644 --- a/src/native/clr/shared/helpers.cc +++ b/src/native/clr/shared/helpers.cc @@ -4,7 +4,7 @@ #include #include -#include +#include using namespace xamarin::android; diff --git a/src/native/clr/shared/log_functions.cc b/src/native/clr/shared/log_functions.cc index 2f3db78abe7..ad6bca52539 100644 --- a/src/native/clr/shared/log_functions.cc +++ b/src/native/clr/shared/log_functions.cc @@ -5,9 +5,8 @@ #include -#include "java-interop-logger.h" -#include #include +#include using namespace xamarin::android; diff --git a/src/native/common/include/runtime-base/strings.hh b/src/native/common/include/runtime-base/strings.hh index 8e6bf8cbaea..589e2f45653 100644 --- a/src/native/common/include/runtime-base/strings.hh +++ b/src/native/common/include/runtime-base/strings.hh @@ -11,6 +11,7 @@ #include #include +#include #if defined(XA_HOST_MONOVM) #include @@ -205,7 +206,7 @@ namespace xamarin::android { } if (!can_access (start_index)) { - log_error (LOG_DEFAULT, "Cannot convert string to integer, index {} is out of range", start_index); + log_errorf (LOG_DEFAULT, "Cannot convert string to integer, index %zu is out of range", start_index); return false; } @@ -229,17 +230,23 @@ namespace xamarin::android { } if (out_of_range || errno == ERANGE) { - log_error (LOG_DEFAULT, "Value {} is out of range of this type ({}..{})", reinterpret_cast(s), static_cast(min), static_cast(max)); + log_errorf ( + LOG_DEFAULT, + "Value %s is out of range of this type (%lld..%llu)", + reinterpret_cast(s), + static_cast(static_cast(min)), + static_cast(static_cast(max)) + ); return false; } if (endp == s) { - log_error (LOG_DEFAULT, "Value {} does not represent a base {} integer", reinterpret_cast(s), base); + log_errorf (LOG_DEFAULT, "Value %s does not represent a base %d integer", reinterpret_cast(s), base); return false; } if (*endp != '\0') { - log_error (LOG_DEFAULT, "Value {} has non-numeric characters at the end", reinterpret_cast(s)); + log_errorf (LOG_DEFAULT, "Value %s has non-numeric characters at the end", reinterpret_cast(s)); return false; } diff --git a/src/native/common/include/shared/log_functions.hh b/src/native/common/include/shared/log_functions.hh new file mode 100644 index 00000000000..098b739a684 --- /dev/null +++ b/src/native/common/include/shared/log_functions.hh @@ -0,0 +1,18 @@ +#pragma once + +#include + +#include "java-interop-logger.h" +#include + +namespace xamarin::android { + // A slightly faster alternative to other log functions as it doesn't parse the message + // for format placeholders nor it uses variable arguments + void log_write (LogCategories category, LogLevel level, const char *message) noexcept; + void log_writev (LogCategories category, LogLevel level, const char *format, va_list args) noexcept; + void log_writef (LogCategories category, LogLevel level, const char *format, ...) noexcept __attribute__ ((format (printf, 3, 4))); + void log_debugf (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3))); + void log_infof (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3))); + void log_warnf (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3))); + void log_errorf (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3))); +} diff --git a/src/native/mono/shared/log_functions.cc b/src/native/mono/shared/log_functions.cc index 16e8eda7525..0fe808a922e 100644 --- a/src/native/mono/shared/log_functions.cc +++ b/src/native/mono/shared/log_functions.cc @@ -4,8 +4,7 @@ #include -#include "java-interop-logger.h" -#include +#include // Must match the same ordering as LogCategories static constexpr std::array log_names = { diff --git a/src/native/mono/shared/log_types.hh b/src/native/mono/shared/log_types.hh index e476b82b1cd..bbb0fb6e936 100644 --- a/src/native/mono/shared/log_types.hh +++ b/src/native/mono/shared/log_types.hh @@ -1,13 +1,11 @@ #pragma once -#include #include #include #include #include -#include "java-interop-logger.h" -#include +#include // We redeclare macros here #if defined(log_debug) @@ -45,16 +43,6 @@ #define log_fatal(_category_, _fmt_, ...) log_fatal_fmt ((_category_), (_fmt_) __VA_OPT__(,) __VA_ARGS__) namespace xamarin::android { - // A slightly faster alternative to other log functions as it doesn't parse the message - // for format placeholders nor it uses variable arguments - void log_write (LogCategories category, LogLevel level, const char *message) noexcept; - void log_writev (LogCategories category, LogLevel level, const char *format, va_list args) noexcept; - void log_writef (LogCategories category, LogLevel level, const char *format, ...) noexcept __attribute__ ((format (printf, 3, 4))); - void log_debugf (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3))); - void log_infof (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3))); - void log_warnf (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3))); - void log_errorf (LogCategories category, const char *format, ...) noexcept __attribute__ ((format (printf, 2, 3))); - [[gnu::always_inline]] static inline void log_write (LogCategories category, LogLevel level, std::string_view const& message) noexcept { diff --git a/src/native/nativeaot/host/bridge-processing.cc b/src/native/nativeaot/host/bridge-processing.cc index eb636515d6f..b3625794791 100644 --- a/src/native/nativeaot/host/bridge-processing.cc +++ b/src/native/nativeaot/host/bridge-processing.cc @@ -18,13 +18,16 @@ void BridgeProcessing::naot_initialize_on_runtime_init (JNIEnv *env) noexcept GCUserPeerable_jiAddManagedReference = env->GetMethodID (GCUserPeerable_class, "jiAddManagedReference", "(Ljava/lang/Object;)V"); GCUserPeerable_jiClearManagedReferences = env->GetMethodID (GCUserPeerable_class, "jiClearManagedReferences", "()V"); + constexpr char ABSENT[] = "absent"; + constexpr char PRESENT[] = "present"; + if (GCUserPeerable_jiAddManagedReference == nullptr || GCUserPeerable_jiClearManagedReferences == nullptr) [[unlikely]] { Helpers::abort_applicationf ( LOG_DEFAULT, std::source_location::current (), "Failed to find GCUserPeerable method(s): jiAddManagedReference (%s); jiClearManagedReferences (%s)", - GCUserPeerable_jiAddManagedReference == nullptr ? "absent" : "present", - GCUserPeerable_jiClearManagedReferences == nullptr ? "absent" : "present" + GCUserPeerable_jiAddManagedReference == nullptr ? ABSENT : PRESENT, + GCUserPeerable_jiClearManagedReferences == nullptr ? ABSENT : PRESENT ); } }