Skip to content

Commit

Permalink
[monodroid] C++ tweaks and legacy code cleanup (#8638)
Browse files Browse the repository at this point in the history
Remove old and unused code originally written for:

  * Classic Xamarin.Android
  * [Xamarin.Android Designer][0] on Windows
  * Xamarin.Android Designer on macOS

Remove a collection of platform and compiler compatibility macros,
typedefs and wrapper functions.

Migrate from `char` arrays to `std::string_view` for more strongly
typed code.

Move `-fstack-clash-protection` from `LOCAL_COMMON_COMPILER_ARGS` to
`LOCAL_COMMON_LINKER_ARGS`; it's a linker flag.

Use `#pragma clang diagnostic ignored "-Warray-bounds"` around
certain "MonoVM-isms" in the GC bridge to silence array bounds
checking warnings.

Refactor to use new(er) C++ types such as `std::span`, `std::array`,
and `std::string_view`.  This helps reduce memory allocations in some
scenarios, allows usage of the newer `for (e : collection)` syntax,
and increases type safety.

[0]: https://github.com/MicrosoftDocs/xamarin-docs/blob/ff833dc5af413e10802afca108212c0a7b2d6fa2/docs/android/user-interface/android-designer/designer-basics.md
  • Loading branch information
grendello authored Feb 9, 2024
1 parent 1ead0c6 commit 3212213
Show file tree
Hide file tree
Showing 43 changed files with 738 additions and 2,536 deletions.
16 changes: 15 additions & 1 deletion src/monodroid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,16 @@ endif()
# Compiler and linker flags
set(LINK_LIBS "")

#
# -Wformat-nonliteral is disabled as it's not very practical, because we use proxy functions to
# pass formats to the final Android logger functions. The Android functions have attributes that
# cause warnings similar to:
#
# warning G4FD2E6FD: format string is not a string literal [-Wformat-nonliteral]
#
# The warning is, in general, a good practice because the compiler can verify the printf format
# at compile time, but in our case it's not very useful.
#
set(LOCAL_COMMON_COMPILER_ARGS
-Wall
-Wconversion
Expand All @@ -333,6 +343,7 @@ set(LOCAL_COMMON_COMPILER_ARGS
-Wextra
-Wformat-security
-Wformat=2
-Wno-format-nonliteral
-Wimplicit-fallthrough
-Wmisleading-indentation
-Wnull-dereference
Expand All @@ -341,7 +352,6 @@ set(LOCAL_COMMON_COMPILER_ARGS
-Wsign-compare
-Wtrampolines
-Wuninitialized
-fstack-clash-protection
-fstrict-flex-arrays=3
)

Expand Down Expand Up @@ -370,6 +380,10 @@ endif()

set(LOCAL_COMMON_LINKER_ARGS "")
if(ANDROID)
list(APPEND LOCAL_COMMON_LINKER_ARGS
-fstack-clash-protection
)

if (ENABLE_CLANG_ASAN OR ENABLE_CLANG_UBSAN)
list(APPEND LOCAL_COMMON_COMPILER_ARGS
-fno-omit-frame-pointer
Expand Down
Loading

0 comments on commit 3212213

Please sign in to comment.