Skip to content

Commit 233500f

Browse files
committed
[C++] fix a handful of compiler warnings
Context: dotnet/java-interop#703 This commit fixes a handful of warnings reported by GCC and clang when building for different platforms. monodroid-glue.cc:1609:8: warning: declaration shadows a static data member of 'xamarin::android::internal::MonodroidRuntime' [-Wshadow] void *api_dso_handle = nullptr; ^ monodroid-glue.cc:102:25: note: previous declaration is here void *MonodroidRuntime::api_dso_handle = nullptr; Fix by renaming the local variable. No functionality changes result from this fix. MinGW builds report: xa-internal-api.cc: In member function ‘virtual mono_bool xamarin::android::internal::MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_up_state(const char*, mono_bool*)’: xa-internal-api.cc:24:86: warning: unused parameter ‘ifname’ [-Wunused-parameter] 24 | MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_up_state (const char *ifname, mono_bool *is_up) | ~~~~~~~~~~~~^~~~~~ xa-internal-api.cc:24:105: warning: unused parameter ‘is_up’ [-Wunused-parameter] 24 | MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_up_state (const char *ifname, mono_bool *is_up) | ~~~~~~~~~~~^~~~~ xa-internal-api.cc: In member function ‘virtual mono_bool xamarin::android::internal::MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_supports_multicast(const char*, mono_bool*)’: xa-internal-api.cc:34:96: warning: unused parameter ‘ifname’ [-Wunused-parameter] 34 | MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_supports_multicast (const char *ifname, mono_bool *supports_multicast) | ~~~~~~~~~~~~^~~~~~ xa-internal-api.cc:34:115: warning: unused parameter ‘supports_multicast’ [-Wunused-parameter] 34 | MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_supports_multicast (const char *ifname, mono_bool *supports_multicast) | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ xa-internal-api.cc: In member function ‘virtual int xamarin::android::internal::MonoAndroidInternalCalls_Impl::monodroid_get_dns_servers(void**)’: xa-internal-api.cc:44:66: warning: unused parameter ‘dns_servers_array’ [-Wunused-parameter] 44 | MonoAndroidInternalCalls_Impl::monodroid_get_dns_servers (void **dns_servers_array) | ~~~~~~~^~~~~~~~~~~~~~~~~ xa-internal-api.cc: In member function ‘virtual int xamarin::android::internal::MonoAndroidInternalCalls_Impl::monodroid_getifaddrs(_monodroid_ifaddrs**)’: xa-internal-api.cc:54:82: warning: unused parameter ‘ifap’ [-Wunused-parameter] 54 | MonoAndroidInternalCalls_Impl::monodroid_getifaddrs (struct _monodroid_ifaddrs **ifap) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~ xa-internal-api.cc: In member function ‘virtual void xamarin::android::internal::MonoAndroidInternalCalls_Impl::monodroid_freeifaddrs(_monodroid_ifaddrs*)’: xa-internal-api.cc:64:82: warning: unused parameter ‘ifa’ [-Wunused-parameter] 64 | MonoAndroidInternalCalls_Impl::monodroid_freeifaddrs (struct _monodroid_ifaddrs *ifa) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ The fix is to ignore the unused parameters only during Windows builds by using the C++17 attribute `[[maybe_unused]]` Another Windows-only warning: embedded-assemblies.cc: In static member function ‘static ssize_t xamarin::android::internal::EmbeddedAssemblies::do_read(int, void*, size_t)’: embedded-assemblies.cc:663:26: warning: conversion from ‘size_t’ {aka ‘long long unsigned int’} to ‘unsigned int’ may change value [-Wconversion] 663 | ret = ::read (fd, buf, count); | It is caused by `read(2)` declared in MinGW headers with the third parameter using `unsigned int` type instead of the standard `size_t`. Fixed by casting properly on Windows builds.
1 parent 9c62618 commit 233500f

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

external/Java.Interop

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<PackageReference Include="System.Reflection.Metadata" Version="1.8.0" />
5454
<PackageReference Include="System.Runtime" Version="4.3.1" />
5555
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
56-
<PackageReference Include="XliffTasks" Version="1.0.0-beta.19252.1" PrivateAssets="all" />
56+
<PackageReference Include="XliffTasks" Version="1.0.0-beta.20206.1" PrivateAssets="all" />
5757
<PackageReference Include="K4os.Compression.LZ4" Version="1.1.11" />
5858
</ItemGroup>
5959

src/monodroid/jni/embedded-assemblies.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,15 @@ ssize_t EmbeddedAssemblies::do_read (int fd, void *buf, size_t count)
660660
{
661661
ssize_t ret;
662662
do {
663-
ret = ::read (fd, buf, count);
663+
ret = ::read (
664+
fd,
665+
buf,
666+
#if defined (WINDOWS)
667+
static_cast<unsigned int>(count)
668+
#else
669+
count
670+
#endif
671+
);
664672
} while (ret < 0 && errno == EINTR);
665673

666674
return ret;

src/monodroid/jni/monodroid-glue.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,28 +1606,28 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl
16061606
utils.set_world_accessable (counters_path);
16071607
}
16081608

1609-
void *api_dso_handle = nullptr;
1609+
void *dso_handle = nullptr;
16101610
#if defined (WINDOWS) || defined (APPLE_OS_X)
16111611
const char *my_location = get_my_location ();
16121612
if (my_location != nullptr) {
16131613
simple_pointer_guard<char, false> dso_path (utils.path_combine (my_location, API_DSO_NAME));
16141614
log_info (LOG_DEFAULT, "Attempting to load %s", dso_path.get ());
1615-
api_dso_handle = java_interop_lib_load (dso_path.get (), JAVA_INTEROP_LIB_LOAD_GLOBALLY, nullptr);
1615+
dso_handle = java_interop_lib_load (dso_path.get (), JAVA_INTEROP_LIB_LOAD_GLOBALLY, nullptr);
16161616
#if defined (APPLE_OS_X)
16171617
delete[] my_location;
16181618
#else // !defined(APPLE_OS_X)
16191619
free (static_cast<void*>(const_cast<char*>(my_location))); // JI allocates with `calloc`
16201620
#endif // defined(APPLE_OS_X)
16211621
}
16221622

1623-
if (api_dso_handle == nullptr) {
1623+
if (dso_handle == nullptr) {
16241624
log_info (LOG_DEFAULT, "Attempting to load %s with \"bare\" dlopen", API_DSO_NAME);
1625-
api_dso_handle = java_interop_lib_load (API_DSO_NAME, JAVA_INTEROP_LIB_LOAD_GLOBALLY, nullptr);
1625+
dso_handle = java_interop_lib_load (API_DSO_NAME, JAVA_INTEROP_LIB_LOAD_GLOBALLY, nullptr);
16261626
}
16271627
#endif // defined(WINDOWS) || defined(APPLE_OS_X)
1628-
if (api_dso_handle == nullptr)
1629-
api_dso_handle = androidSystem.load_dso_from_any_directories (API_DSO_NAME, JAVA_INTEROP_LIB_LOAD_GLOBALLY);
1630-
init_internal_api_dso (api_dso_handle);
1628+
if (dso_handle == nullptr)
1629+
dso_handle = androidSystem.load_dso_from_any_directories (API_DSO_NAME, JAVA_INTEROP_LIB_LOAD_GLOBALLY);
1630+
init_internal_api_dso (dso_handle);
16311631

16321632
mono_dl_fallback_register (monodroid_dlopen, monodroid_dlsym, nullptr, nullptr);
16331633

src/monodroid/jni/xa-internal-api.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
#include "globals.hh"
1111
#include "xa-internal-api-impl.hh"
1212

13+
#if defined (WINDOWS)
14+
#define WINDOWS_UNUSED_ARG UNUSED_ARG
15+
#else
16+
#define WINDOWS_UNUSED_ARG
17+
#endif
18+
1319
using namespace xamarin::android;
1420
using namespace xamarin::android::internal;
1521

@@ -21,7 +27,7 @@ int _monodroid_getifaddrs (struct _monodroid_ifaddrs **ifap);
2127
void _monodroid_freeifaddrs (struct _monodroid_ifaddrs *ifa);
2228

2329
mono_bool
24-
MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_up_state (const char *ifname, mono_bool *is_up)
30+
MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_up_state (WINDOWS_UNUSED_ARG const char *ifname, WINDOWS_UNUSED_ARG mono_bool *is_up)
2531
{
2632
#ifdef WINDOWS
2733
return FALSE;
@@ -31,7 +37,7 @@ MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_up_state (const c
3137
}
3238

3339
mono_bool
34-
MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_supports_multicast (const char *ifname, mono_bool *supports_multicast)
40+
MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_supports_multicast (WINDOWS_UNUSED_ARG const char *ifname, WINDOWS_UNUSED_ARG mono_bool *supports_multicast)
3541
{
3642
#ifdef WINDOWS
3743
return FALSE;
@@ -41,7 +47,7 @@ MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_supports_multicas
4147
}
4248

4349
int
44-
MonoAndroidInternalCalls_Impl::monodroid_get_dns_servers (void **dns_servers_array)
50+
MonoAndroidInternalCalls_Impl::monodroid_get_dns_servers (WINDOWS_UNUSED_ARG void **dns_servers_array)
4551
{
4652
#ifdef WINDOWS
4753
return FALSE;
@@ -51,7 +57,7 @@ MonoAndroidInternalCalls_Impl::monodroid_get_dns_servers (void **dns_servers_arr
5157
}
5258

5359
int
54-
MonoAndroidInternalCalls_Impl::monodroid_getifaddrs (struct _monodroid_ifaddrs **ifap)
60+
MonoAndroidInternalCalls_Impl::monodroid_getifaddrs (WINDOWS_UNUSED_ARG struct _monodroid_ifaddrs **ifap)
5561
{
5662
#ifdef WINDOWS
5763
return -1;
@@ -61,7 +67,7 @@ MonoAndroidInternalCalls_Impl::monodroid_getifaddrs (struct _monodroid_ifaddrs *
6167
}
6268

6369
void
64-
MonoAndroidInternalCalls_Impl::monodroid_freeifaddrs (struct _monodroid_ifaddrs *ifa)
70+
MonoAndroidInternalCalls_Impl::monodroid_freeifaddrs (WINDOWS_UNUSED_ARG struct _monodroid_ifaddrs *ifa)
6571
{
6672
#ifndef WINDOWS
6773
::_monodroid_freeifaddrs (ifa);

0 commit comments

Comments
 (0)