Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/native/clr/include/host/host-environment.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -94,10 +94,10 @@ namespace xamarin::android {
static_local_string<SENSIBLE_PATH_MAX> 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 ()) {
Expand Down
14 changes: 1 addition & 13 deletions src/native/clr/include/shared/log_types.hh
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#pragma once

#include <cstdarg>
#include <cstdint>
#include <format>
#include <string>
#include <string_view>

#include "java-interop-logger.h"
#include <shared/log_level.hh>
#include <shared/log_functions.hh>

// We redeclare macros here
#if defined(log_debug)
Expand Down Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/native/clr/shared/helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <android/set_abort_message.h>

#include <shared/helpers.hh>
#include <shared/log_types.hh>
#include <shared/log_functions.hh>

using namespace xamarin::android;

Expand Down
3 changes: 1 addition & 2 deletions src/native/clr/shared/log_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

#include <android/log.h>

#include "java-interop-logger.h"
#include <shared/log_level.hh>
#include <constants.hh>
#include <shared/log_functions.hh>

using namespace xamarin::android;

Expand Down
15 changes: 11 additions & 4 deletions src/native/common/include/runtime-base/strings.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <unistd.h>

#include <shared/helpers.hh>
#include <shared/log_functions.hh>

#if defined(XA_HOST_MONOVM)
#include <runtime-base/shared-constants.hh>
Expand Down Expand Up @@ -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;
}

Expand All @@ -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<char*>(s), static_cast<int64_t>(min), static_cast<uint64_t>(max));
log_errorf (
LOG_DEFAULT,
"Value %s is out of range of this type (%lld..%llu)",
reinterpret_cast<char*>(s),
static_cast<long long>(static_cast<int64_t>(min)),
static_cast<unsigned long long>(static_cast<uint64_t>(max))
);
return false;
}

if (endp == s) {
log_error (LOG_DEFAULT, "Value {} does not represent a base {} integer", reinterpret_cast<char*>(s), base);
log_errorf (LOG_DEFAULT, "Value %s does not represent a base %d integer", reinterpret_cast<char*>(s), base);
return false;
}

if (*endp != '\0') {
log_error (LOG_DEFAULT, "Value {} has non-numeric characters at the end", reinterpret_cast<char*>(s));
log_errorf (LOG_DEFAULT, "Value %s has non-numeric characters at the end", reinterpret_cast<char*>(s));
return false;
}

Expand Down
18 changes: 18 additions & 0 deletions src/native/common/include/shared/log_functions.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <cstdarg>

#include "java-interop-logger.h"
#include <shared/log_level.hh>

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)));
}
3 changes: 1 addition & 2 deletions src/native/mono/shared/log_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

#include <android/log.h>

#include "java-interop-logger.h"
#include <shared/log_level.hh>
#include <shared/log_functions.hh>

// Must match the same ordering as LogCategories
static constexpr std::array<const char*, 12> log_names = {
Expand Down
14 changes: 1 addition & 13 deletions src/native/mono/shared/log_types.hh
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#pragma once

#include <cstdarg>
#include <cstdint>
#include <format>
#include <string>
#include <string_view>

#include "java-interop-logger.h"
#include <shared/log_level.hh>
#include <shared/log_functions.hh>

// We redeclare macros here
#if defined(log_debug)
Expand Down Expand Up @@ -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
{
Expand Down
7 changes: 5 additions & 2 deletions src/native/nativeaot/host/bridge-processing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Comment thread
jonathanpeppers marked this conversation as resolved.

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
);
}
}
Expand Down
Loading