Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
19 changes: 19 additions & 0 deletions mk/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,36 @@ macos_DEFINES=-DMONOMAC
OBJC_CFLAGS=-ObjC++ -std=c++14 -fno-exceptions -fno-objc-msgsend-selector-stubs -fobjc-abi-version=2 -fobjc-legacy-dispatch
CFLAGS=\
-Wall \
-Wextra \
-Wno-unused-parameter \
-Wno-unused-but-set-parameter \
-fms-extensions \
-Werror \
-Wconversion \
-Wdeprecated \
-Wuninitialized \
-fstack-protector-strong \
-ftrivial-auto-var-init=zero \
-Wformat \
-Wformat-security \
-Werror=format-security \
-fdiagnostics-absolute-paths \
-Wno-objc-protocol-property-synthesis \
-Wignored-qualifiers \
-Wmissing-field-initializers \
-Wcast-function-type-mismatch \
-Wsemicolon-before-method-body \
-Wsign-compare \
-Wshadow \
-Wempty-body \
-Wbuiltin-memcpy-chk-size \
-Wformat-nonliteral \
-Warray-bounds \
-Warray-bounds-pointer-arithmetic \
-Wsuspicious-memaccess \
-Wsizeof-array-div \
-Wsizeof-pointer-div \
-Wreturn-stack-address \
-g \
-I.
SWIFTFLAGS=-g -emit-library
Expand Down
2 changes: 1 addition & 1 deletion runtime/coreclr-bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@
return NULL;
}

struct stat stat_buf = { 0 };
struct stat stat_buf = { };
if (fstat (fd, &stat_buf) == -1) {
LOG (PRODUCT ": Could not stat the runtime config file '%s' in the app bundle: %s\n", path, strerror (errno));
close (fd);
Expand Down
2 changes: 1 addition & 1 deletion runtime/delegates.inc.t4
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct Delegates {
<# } #>
};

static struct Delegates delegates = { 0 };
static struct Delegates delegates = { };

static GCHandle
create_linked_away_exception (const char *func)
Expand Down
2 changes: 1 addition & 1 deletion runtime/monotouch-main.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

static char original_working_directory_path [MAXPATHLEN];

const char * const
const char *
xamarin_get_original_working_directory_path ()
{
return original_working_directory_path;
Expand Down
1 change: 0 additions & 1 deletion runtime/monovm-bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@
bool
xamarin_is_class_nsstring (MonoClass *cls)
{
MonoClass *nsstring_class = xamarin_get_nsstring_class ();
if (nsstring_class == NULL)
return false;

Expand Down
6 changes: 5 additions & 1 deletion runtime/nsstring-localization.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@

#include <pthread.h>

// Silence this warning:
// Silence these warnings:
// nsstring-localization.m:22:46: warning: format string is not a string literal (potentially insecure) [-Wformat-security]
// return [NSString localizedStringWithFormat: format];
#pragma clang diagnostic ignored "-Wformat-security"
// nsstring-localization.m:33:46: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
// 33 | return [NSString localizedStringWithFormat: format, a];
// | ^~~~~~
#pragma clang diagnostic ignored "-Wformat-nonliteral"

extern "C" {

Expand Down
47 changes: 38 additions & 9 deletions runtime/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
(void *) &xamarin_get_nsobject_data_trampoline,
};

static struct InitializationOptions options = { 0 };
static struct InitializationOptions options = { };

#if !defined (CORECLR_RUNTIME)
void
Expand Down Expand Up @@ -1310,7 +1310,16 @@ -(struct NSObjectData*) xamarinGetNSObjectData;
char *formatted = NULL;

va_start (args, msg);

// Silence this warning:
// runtime.m:1313:25: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
// 1313 | vasprintf (&formatted, msg, args);
// | ^~~~~
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
vasprintf (&formatted, msg, args);
#pragma clang diagnostic pop

va_end (args);

return formatted;
Expand All @@ -1323,7 +1332,16 @@ -(struct NSObjectData*) xamarinGetNSObjectData;
char *formatted = NULL;

va_start (args, msg);

// Silence this warning:
// runtime.m:1335:25: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
// 1335 | vasprintf (&formatted, msg, args);
// | ^~~
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
vasprintf (&formatted, msg, args);
#pragma clang diagnostic pop

if (formatted) {
PRINT ( PRODUCT ": %s", formatted);
free (formatted);
Expand Down Expand Up @@ -2176,9 +2194,11 @@ -(struct NSObjectData*) xamarinGetNSObjectData;
MarshalManagedExceptionMode mode;
GCHandle exception_gchandle = INVALID_GCHANDLE;

GCHandle handle = xamarin_gchandle_new (exception, false);
mode = xamarin_on_marshal_managed_exception (handle, &exception_gchandle);
xamarin_gchandle_free (handle);
{
GCHandle handle = xamarin_gchandle_new (exception, false);
mode = xamarin_on_marshal_managed_exception (handle, &exception_gchandle);
xamarin_gchandle_free (handle);
}

if (exception_gchandle != INVALID_GCHANDLE) {
PRINT (PRODUCT ": Got an exception while executing the MarshalManagedException event (this exception will be ignored):");
Expand All @@ -2197,7 +2217,7 @@ -(struct NSObjectData*) xamarinGetNSObjectData;
switch (mode) {
#if !defined (CORECLR_RUNTIME) // CoreCLR won't unwind through native frames, so we'll have to abort (in the default case statement)
case MarshalManagedExceptionModeDisable:
case MarshalManagedExceptionModeUnwindNativeCode:
case MarshalManagedExceptionModeUnwindNativeCode: {
//
// We want to maintain the original stack trace of the exception, but unfortunately
// calling mono_raise_exception directly with the original exception will overwrite
Expand All @@ -2210,7 +2230,7 @@ -(struct NSObjectData*) xamarinGetNSObjectData;
// to throw an exception that contains the original stack trace.
//

handle = xamarin_gchandle_new (exception, false);
GCHandle handle = xamarin_gchandle_new (exception, false);
xamarin_rethrow_managed_exception (handle, &exception_gchandle);
xamarin_gchandle_free (handle);

Expand All @@ -2231,8 +2251,9 @@ -(struct NSObjectData*) xamarinGetNSObjectData;
xamarin_handling_unhandled_exceptions = 0;

mono_raise_exception ((MonoException *) exception);
#endif
break;
}
#endif
case MarshalManagedExceptionModeThrowObjectiveCException: {
GCHandle handle = xamarin_gchandle_new (exception, false);
NSException *ns_exc = xamarin_unwrap_ns_exception (handle, &exception_gchandle);
Expand Down Expand Up @@ -2295,13 +2316,14 @@ -(struct NSObjectData*) xamarinGetNSObjectData;
case MarshalManagedExceptionModeUnwindNativeCode:
#endif
case MarshalManagedExceptionModeAbort:
default:
handle = xamarin_gchandle_new (exception, false);
default: {
GCHandle handle = xamarin_gchandle_new (exception, false);
const char *msg = [xamarin_print_all_exceptions (handle) UTF8String];
xamarin_gchandle_free (handle);
xamarin_assertion_message ("Aborting due to trying to marshal managed exception:\n%s\n", msg);
break;
}
}
}

void
Expand Down Expand Up @@ -2548,7 +2570,14 @@ -(struct NSObjectData*) xamarinGetNSObjectData;
void
xamarin_vprintf (const char *format, va_list args)
{
// Silence this warning:
// runtime.m:2564:56: error: format string is not a string literal [-Werror,-Wformat-nonliteral]
// 2564 | NSString *message = [[NSString alloc] initWithFormat: [NSString stringWithUTF8String: format] arguments: args];
// | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
NSString *message = [[NSString alloc] initWithFormat: [NSString stringWithUTF8String: format] arguments: args];
#pragma clang diagnostic pop

NSLog (@"%@", message);

Expand Down
8 changes: 4 additions & 4 deletions runtime/shared.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ -(void) dealloc;
@implementation XamarinNSThreadObject
{
}
-(id) initWithData: (void *) targ selector:(SEL) sel argument:(id) arg is_direct_binding:(bool) is_direct;
-(id) initWithData: (void *) targ selector:(SEL) sel argument:(id) arg is_direct_binding:(bool) is_direct
{
target = targ;
if (is_direct)
Expand All @@ -58,7 +58,7 @@ -(id) initWithData: (void *) targ selector:(SEL) sel argument:(id) arg is_direct
return self;
}

-(void) start: (id) arg;
-(void) start: (id) arg
{
if (is_direct_binding) {
id (*invoke) (id, SEL, id) = (id (*)(id, SEL, id)) objc_msgSend;
Expand All @@ -69,7 +69,7 @@ -(void) start: (id) arg;
}
}

-(void) dealloc;
-(void) dealloc
{
// Cast to void* so that ObjC doesn't do any funky retain/release
// on these objects when capturing them for the block, since we
Expand Down Expand Up @@ -125,7 +125,7 @@ -(void) entryPoint: (NSObject *) obj
the_func ();
[pool drain];
}
-(id) initWithFunc: (init_cocoa_func *) func;
-(id) initWithFunc: (init_cocoa_func *) func
{
self = [super init];
if (self != nil) {
Expand Down
4 changes: 2 additions & 2 deletions runtime/trampolines-arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ struct XamarinCallState {

struct ParamIterator {
struct XamarinCallState *state;
int ngrn; // Next General-purpose Register Number
int nsrn; // Next SIMD and Floating-point Register Number
unsigned int ngrn; // Next General-purpose Register Number
unsigned int nsrn; // Next SIMD and Floating-point Register Number
size_t ngrn_offset; // Offset into the current general purpose register number
uint8_t *nsaa; // Next stacked argument address.

Expand Down
8 changes: 4 additions & 4 deletions runtime/trampolines-arm64.m
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,11 @@
bool is_hfa = is_struct && struct_length >= 2 && struct_length <= 4;
if (is_hfa) {
is_hfa = struct_name [0] == 'f' || struct_name [0] == 'd';
for (int i = 1; i < struct_length; i++)
for (size_t i = 1; i < struct_length; i++)
is_hfa &= struct_name [i] == struct_name [0];
}

int ngrn_registers_left = 8 - it->ngrn;
size_t ngrn_registers_left = 8 - it->ngrn;
bool read_register = ngrn_registers_left > 0;

if (size > 16 && !is_hfa) {
Expand Down Expand Up @@ -310,7 +310,7 @@
(size == 8 && !strncmp (struct_name, "d", 1))) {
LOGZ (" marshalling as %i doubles (struct name: %s)\n", (int) size / 8, struct_name);
double* ptr = (double *) mono_object_unbox (value);
for (int i = 0; i < size / 8; i++) {
for (size_t i = 0; i < size / 8; i++) {
LOGZ (" #%i: %f\n", i, ptr [i]);
it->q [i].q = ptr [i];
}
Expand All @@ -320,7 +320,7 @@
(size == 4 && !strncmp (struct_name, "f", 1))) {
LOGZ (" marshalling as %i floats (struct name: %s)\n", (int) size / 4, struct_name);
float* ptr = (float *) mono_object_unbox (value);
for (int i = 0; i < size / 4; i++) {
for (size_t i = 0; i < size / 4; i++) {
LOGZ (" #%i: %f\n", i, ptr [i]);
it->q [i].f.f1 = ptr [i];
}
Expand Down
14 changes: 6 additions & 8 deletions runtime/trampolines-invoke.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@
}

void
xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_func iterator, marshal_return_value_func marshal_return_value, void *context)
xamarin_invoke_trampoline (enum TrampolineType trampoline_type, id self, SEL sel, iterator_func iterator, marshal_return_value_func marshal_return_value, void *context)
{
MonoObject *exception = NULL;
MonoObject **exception_ptr = xamarin_is_managed_exception_marshaling_disabled () ? NULL : &exception;
GCHandle exception_gchandle = INVALID_GCHANDLE;
bool is_static = (type & Tramp_Static) == Tramp_Static;
bool is_ctor = type == Tramp_Ctor;
bool is_static = (trampoline_type & Tramp_Static) == Tramp_Static;
bool is_ctor = trampoline_type == Tramp_Ctor;
const char *ret_type = NULL;
MonoType *sig_ret_type = NULL;

Expand Down Expand Up @@ -148,8 +148,6 @@
void *iter = NULL;
gboolean needs_writeback = FALSE; // determines if there are any ref/out parameters.
MonoType *p;
int ofs;
unsigned long i;
unsigned long mofs = 0;

unsigned long desc_arg_count = num_arg + 2; /* 1 for the return value + 1 if this is a category instance method */
Expand Down Expand Up @@ -207,11 +205,11 @@
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;

for (i = 0, ofs = 0; i < num_arg; i++) {
for (unsigned long i = 0, ofs = 0; i < num_arg; i++) {
const char *argType = [sig getArgumentTypeAtIndex: (i+2)];
const char *type = xamarin_skip_encoding_flags (argType);
unsigned long size = xamarin_objc_type_size (type);
int frameofs = ofs;
unsigned long frameofs = ofs;
p = mono_signature_get_params (msig, &iter);
ADD_TO_MONOOBJECT_RELEASE_LIST (p);
LOGZ (" argument %i's type: %s (argType: %s)\n", (int) i + 1, type, argType);
Expand Down Expand Up @@ -633,7 +631,7 @@
iterator (IteratorStart, context, NULL, 0, NULL, &exception_gchandle); // start
if (exception_gchandle != INVALID_GCHANDLE)
goto exception_handling;
for (i = 0; i < num_arg; i++) {
for (unsigned long i = 0; i < num_arg; i++) {
const char *type = [sig getArgumentTypeAtIndex: (i+2)];

type = xamarin_skip_encoding_flags (type);
Expand Down
12 changes: 6 additions & 6 deletions runtime/trampolines.m
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@
xamarin_set_gchandle_with_flags (self, INVALID_GCHANDLE, XamarinGCHandleFlags_None);

// Call the managed implementation
id (*invoke) (id, SEL, NSZone*) = (id (*)(id, SEL, NSZone*)) xamarin_trampoline;
id (*invoke) (id, SEL, NSZone*) = (id (*)(id, SEL, NSZone*)) (void *) xamarin_trampoline;
rv = invoke (self, sel, zone);

// Restore our GCHandle
Expand Down Expand Up @@ -905,7 +905,7 @@

pthread_mutex_lock (&gchandle_hash_lock);
if (gchandle_hash == NULL) {
CFDictionaryValueCallBacks value_callbacks = { 0 };
CFDictionaryValueCallBacks value_callbacks = { };
value_callbacks.release = release_gchandle_dictionary_entry;
gchandle_hash = CFDictionaryCreateMutable (kCFAllocatorDefault, 0, NULL, &value_callbacks);
}
Expand Down Expand Up @@ -1411,7 +1411,7 @@
element_class = e_class;
}

struct conversion_data data = { 0 };
struct conversion_data data = { };
data.domain = mono_domain_get ();
data.element_class = element_class;
data.element_type = mono_class_get_type (data.element_class);
Expand All @@ -1437,7 +1437,7 @@
element_class = e_class;
}

struct conversion_data data = { 0 };
struct conversion_data data = { };
data.domain = mono_domain_get ();
data.element_class = element_class;
data.element_type = mono_class_get_type (data.element_class);
Expand All @@ -1463,7 +1463,7 @@
element_class = e_class;
}

struct conversion_data data = { 0 };
struct conversion_data data = { };
data.element_class = element_class;
data.element_type = mono_class_get_type (data.element_class);
data.iface_token_ref = iface_token_ref;
Expand Down Expand Up @@ -1674,7 +1674,7 @@
return (xamarin_managed_to_id_func) xamarin_get_nsvalue_converter (managedType, method, false, exception_gchandle);
}

void *
id
xamarin_smart_enum_to_nsstring (MonoObject *value, void *context /* token ref */, GCHandle *exception_gchandle)
{
guint32 context_ref = GPOINTER_TO_UINT (context);
Expand Down
2 changes: 1 addition & 1 deletion runtime/xamarin/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void xamarin_bridge_raise_unhandled_exception_event (GCHandle exception_gchand
bool xamarin_register_monoassembly (MonoAssembly *assembly, GCHandle *exception_gchandle);
void xamarin_install_nsautoreleasepool_hooks ();
void xamarin_enable_new_refcount ();
const char * const xamarin_get_original_working_directory_path ();
const char * xamarin_get_original_working_directory_path ();
int xamarin_get_runtime_arch ();

MonoObject * xamarin_new_nsobject (id self, MonoClass *klass, GCHandle *exception_gchandle);
Expand Down
Loading
Loading