Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More C++ warnings cleanup + C++17 changes #3574

Merged
merged 1 commit into from
Sep 4, 2019
Merged
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
25 changes: 15 additions & 10 deletions src/monodroid/jni/android-system.cc
Original file line number Diff line number Diff line change
@@ -44,7 +44,6 @@ using namespace xamarin::android::internal;

#if defined (DEBUG) || !defined (ANDROID)
BundledProperty *AndroidSystem::bundled_properties = nullptr;
constexpr char AndroidSystem::OVERRIDE_ENVIRONMENT_FILE_NAME[];
#endif // DEBUG || !ANDROID

#if defined (WINDOWS)
@@ -126,8 +125,8 @@ AndroidSystem::add_system_property (const char *name, const char *value)
return;
}

size_t name_len = strlen (name) + 1;
size_t alloc_size = ADD_WITH_OVERFLOW_CHECK (size_t, sizeof (BundledProperty), name_len);
size_t name_len = strlen (name);
size_t alloc_size = ADD_WITH_OVERFLOW_CHECK (size_t, sizeof (BundledProperty), name_len + 1);
p = reinterpret_cast<BundledProperty*> (malloc (alloc_size));
if (p == nullptr)
return;
@@ -266,7 +265,10 @@ AndroidSystem::monodroid_read_file_into_memory (const char *path, char **value)
if (fstat (fileno (fp), &fileStat) == 0) {
r = ADD_WITH_OVERFLOW_CHECK (size_t, static_cast<size_t>(fileStat.st_size), 1);
if (value && (*value = new char[r])) {
fread (*value, 1, static_cast<size_t>(fileStat.st_size), fp);
size_t nread = fread (*value, 1, static_cast<size_t>(fileStat.st_size), fp);
if (nread == 0 || nread != r) {
log_warn(LOG_DEFAULT, "While reading file %s: expected to read %u bytes, actually read %u bytes", path, r, nread);
}
}
}
fclose (fp);
@@ -583,6 +585,11 @@ AndroidSystem::setup_environment (const char *name, const char *value)
void
AndroidSystem::setup_environment_from_override_file (const char *path)
{
#if WINDOWS
using read_count_type = unsigned int;
#else
using read_count_type = size_t;
#endif
monodroid_stat_t sbuf;
if (utils.monodroid_stat (path, &sbuf) < 0) {
log_warn (LOG_DEFAULT, "Failed to stat the environment override file %s: %s", path, strerror (errno));
@@ -595,13 +602,13 @@ AndroidSystem::setup_environment_from_override_file (const char *path)
return;
}

size_t file_size = static_cast<size_t>(sbuf.st_size);
char *buf = new char [file_size];
auto file_size = static_cast<size_t>(sbuf.st_size);
auto *buf = new char [file_size];
size_t nread = 0;
ssize_t r;
do {
size_t i = nread;
r = read (fd, buf + i, file_size - i);
auto read_count = static_cast<read_count_type>(file_size - nread);
r = read (fd, buf + nread, read_count);
if (r > 0)
nread += static_cast<size_t>(r);
} while (r < 0 && errno == EINTR);
@@ -771,8 +778,6 @@ AndroidSystem::readdir (monodroid_dir_t *dir)
struct _wdirent*
AndroidSystem::readdir_windows (_WDIR *dirp)
{
int error_code = 0;

std::lock_guard<std::mutex> lock (readdir_mutex);
errno = 0;
struct _wdirent *entry = _wreaddir (dirp);
2 changes: 0 additions & 2 deletions src/monodroid/jni/basic-android-system.cc
Original file line number Diff line number Diff line change
@@ -11,8 +11,6 @@ const char **BasicAndroidSystem::app_lib_directories;
size_t BasicAndroidSystem::app_lib_directories_size = 0;
#if WINDOWS
static const char *SYSTEM_LIB_PATH;
#else
constexpr char BasicAndroidSystem::SYSTEM_LIB_PATH[];
#endif

// Values correspond to the CPU_KIND_* macros
17 changes: 0 additions & 17 deletions src/monodroid/jni/debug-app-helper.cc
Original file line number Diff line number Diff line change
@@ -29,7 +29,6 @@ void log_fatal (LogCategories category, const char *format, ...);

static void copy_file_to_internal_location (char *to_dir, char *from_dir, char *file);
static void copy_native_libraries_to_internal_location ();
static bool try_load_libmonosgen (const char *dir, char*& libmonoso);
static char* get_libmonosgen_path ();

bool maybe_load_library (const char *path);
@@ -96,22 +95,6 @@ Java_mono_android_DebugRuntime_init (JNIEnv *env, jclass klass, jobjectArray run
}
}

bool
maybe_load_library (const char *path)
{
struct stat sbuf;

if (stat (path, &sbuf) != 0)
return false;

if (dlopen (path, RTLD_LAZY | RTLD_GLOBAL | RTLD_NODELETE) != nullptr) {
log_info (LOG_DEFAULT, "Mono runtime loaded from %s", path);
return true;
}

return false;
}

#ifdef ANDROID
static void
copy_file_to_internal_location (char *to_dir, char *from_dir, char *file)
4 changes: 2 additions & 2 deletions src/monodroid/jni/debug.hh
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
#include <pthread.h>

#ifdef __cplusplus
namespace xamarin { namespace android
namespace xamarin::android
{
class Debug
{
@@ -52,7 +52,7 @@ namespace xamarin { namespace android

#endif
};
} }
}
#else // __cplusplus
const char *__get_debug_mono_log_property (void);

5 changes: 0 additions & 5 deletions src/monodroid/jni/embedded-assemblies.cc
Original file line number Diff line number Diff line change
@@ -52,11 +52,6 @@ const char *EmbeddedAssemblies::suffixes[] = {
".exe",
};

constexpr char EmbeddedAssemblies::assemblies_prefix[];
#if defined (DEBUG) || !defined (ANDROID)
constexpr char EmbeddedAssemblies::override_typemap_entry_name[];
#endif

void EmbeddedAssemblies::set_assemblies_prefix (const char *prefix)
{
if (assemblies_prefix_override != nullptr)
4 changes: 2 additions & 2 deletions src/monodroid/jni/embedded-assemblies.hh
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@

struct TypeMapHeader;

namespace xamarin { namespace android { namespace internal {
namespace xamarin::android::internal {
#if defined (DEBUG) || !defined (ANDROID)
struct TypeMappingInfo;
#endif
@@ -95,7 +95,7 @@ namespace xamarin { namespace android { namespace internal {
#endif // DEBUG || !ANDROID
const char *assemblies_prefix_override = nullptr;
};
}}}
}

MONO_API int monodroid_embedded_assemblies_set_assemblies_prefix (const char *prefix);
#endif /* INC_MONODROID_EMBEDDED_ASSEMBLIES_H */
4 changes: 2 additions & 2 deletions src/monodroid/jni/jni-wrappers.hh
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@

#ifdef __cplusplus

namespace xamarin { namespace android
namespace xamarin::android
{
class jstring_array_wrapper;

@@ -173,7 +173,7 @@ namespace xamarin { namespace android
jstring_wrapper static_wrappers[5];
jstring_wrapper invalid_wrapper;
};
}}
}

#endif // __cplusplus
#endif // __JNI_WRAPPERS_H
1 change: 1 addition & 0 deletions src/monodroid/jni/logger.cc
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
#include "util.hh"
#include "globals.hh"

#undef DO_LOG
#define DO_LOG(_level_,_category_,_format_,_args_) \
va_start ((_args_), (_format_)); \
__android_log_vprint ((_level_), CATEGORY_NAME((_category_)), (_format_), (_args_)); \
4 changes: 2 additions & 2 deletions src/monodroid/jni/monodroid-glue-internal.hh
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
#include "android-system.hh"
#include "osbridge.hh"

namespace xamarin { namespace android { namespace internal
namespace xamarin::android::internal
{
extern char *primary_override_dir;
extern char *external_override_dir;
@@ -16,5 +16,5 @@ namespace xamarin { namespace android { namespace internal
class MonodroidRuntime
{
};
} } }
}
#endif
51 changes: 27 additions & 24 deletions src/monodroid/jni/monodroid-glue.cc
Original file line number Diff line number Diff line change
@@ -997,28 +997,30 @@ create_domain (JNIEnv *env, jclass runtimeClass, jstring_array_wrapper &runtimeA
free (domain_name);
}

if (is_running_on_desktop && is_root_domain) {
// Check that our corlib is coherent with the version of Mono we loaded otherwise
// tell the IDE that the project likely need to be recompiled.
char* corlib_error_message = const_cast<char*>(mono_check_corlib_version ());
if (corlib_error_message == nullptr) {
if (!androidSystem.monodroid_get_system_property ("xamarin.studio.fakefaultycorliberrormessage", &corlib_error_message)) {
if constexpr (is_running_on_desktop) {
if (is_root_domain) {
// Check that our corlib is coherent with the version of Mono we loaded otherwise
// tell the IDE that the project likely need to be recompiled.
char* corlib_error_message = const_cast<char*>(mono_check_corlib_version ());
if (corlib_error_message == nullptr) {
if (!androidSystem.monodroid_get_system_property ("xamarin.studio.fakefaultycorliberrormessage", &corlib_error_message)) {
free (corlib_error_message);
corlib_error_message = nullptr;
}
}
if (corlib_error_message != nullptr) {
jclass ex_klass = env->FindClass ("mono/android/MonoRuntimeException");
jonpryor marked this conversation as resolved.
Show resolved Hide resolved
env->ThrowNew (ex_klass, corlib_error_message);
free (corlib_error_message);
corlib_error_message = nullptr;
return nullptr;
}
}
if (corlib_error_message != nullptr) {
jclass ex_klass = env->FindClass ("mono/android/MonoRuntimeException");
env->ThrowNew (ex_klass, corlib_error_message);
free (corlib_error_message);
return nullptr;
}

// Load a basic environment for the RootDomain if run on desktop so that we can unload
// and reload most assemblies including Mono.Android itself
MonoAssemblyName *aname = mono_assembly_name_new ("System");
mono_assembly_load_full (aname, nullptr, nullptr, 0);
mono_assembly_name_free (aname);
// Load a basic environment for the RootDomain if run on desktop so that we can unload
// and reload most assemblies including Mono.Android itself
MonoAssemblyName *aname = mono_assembly_name_new ("System");
mono_assembly_load_full (aname, nullptr, nullptr, 0);
mono_assembly_name_free (aname);
}
}

return domain;
@@ -1865,8 +1867,11 @@ create_and_initialize_domain (JNIEnv* env, jclass runtimeClass, jstring_array_wr
MonoDomain* domain = create_domain (env, runtimeClass, runtimeApks, loader, is_root_domain);

// When running on desktop, the root domain is only a dummy so don't initialize it
if (is_running_on_desktop && is_root_domain)
return domain;
if constexpr (is_running_on_desktop) {
if (is_root_domain) {
return domain;
}
}

if (androidSystem.is_assembly_preload_enabled ())
load_assemblies (domain, env, assemblies);
@@ -2050,7 +2055,7 @@ Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass klass, jstring lang,
delete[] runtime_args;

// Install our dummy exception handler on Desktop
if (is_running_on_desktop) {
if constexpr (is_running_on_desktop) {
mono_add_internal_call ("System.Diagnostics.Debugger::Mono_UnhandledException_internal(System.Exception)",
reinterpret_cast<const void*> (monodroid_Mono_UnhandledException_internal));
}
@@ -2226,8 +2231,6 @@ extern "C" int monodroid_dylib_mono_init (void *mono_imports, const char *libmon
{
if (mono_imports == nullptr)
return FALSE;

void *libmono_handle = libmono_path ? androidSystem.load_dso_from_any_directories(libmono_path, RTLD_LAZY | RTLD_GLOBAL) : dlopen (libmono_path, RTLD_LAZY | RTLD_GLOBAL);;
return TRUE;
}

4 changes: 2 additions & 2 deletions src/monodroid/jni/osbridge.hh
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
#include <jni.h>
#include <mono/metadata/sgen-bridge.h>

namespace xamarin { namespace android { namespace internal
namespace xamarin::android::internal
{
class OSBridge
{
@@ -171,5 +171,5 @@ namespace xamarin { namespace android { namespace internal
jmethodID ArrayList_add;
jmethodID GCUserPeer_ctor;
};
}}}
}
#endif // !__OS_BRIDGE_H
6 changes: 3 additions & 3 deletions src/monodroid/jni/util.cc
Original file line number Diff line number Diff line change
@@ -213,7 +213,7 @@ Util::monodroid_get_namespaced_system_property (const char *name, char **value)
if (value)
*value = nullptr;

if (strlen (package_property_suffix) > 0) {
if (package_property_suffix[0] != '\0') {
log_info (LOG_DEFAULT, "Trying to get property %s.%s", name, package_property_suffix);
char *propname;
#if WINDOWS
@@ -229,11 +229,11 @@ Util::monodroid_get_namespaced_system_property (const char *name, char **value)
#endif
}

if (result <= 0 || !local_value)
if (result <= 0 || local_value == nullptr)
result = androidSystem.monodroid_get_system_property (name, &local_value);

if (result > 0) {
if (strlen (local_value) == 0) {
if (local_value != nullptr && local_value[0] == '\0') {
delete[] local_value;
return 0;
}
4 changes: 2 additions & 2 deletions src/monodroid/jni/util.hh
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ extern "C" {
#ifdef __cplusplus
}

namespace xamarin { namespace android
namespace xamarin::android
{
struct timing_point
{
@@ -139,6 +139,6 @@ namespace xamarin { namespace android
private:
char package_property_suffix[9];
};
} }
}
#endif // __cplusplus
#endif /* __MONODROID_UTIL_H__ */