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
2 changes: 1 addition & 1 deletion runtime/delegates.t4
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},

new XDelegate ("NSException *", "IntPtr", "xamarin_unwrap_ns_exception",
"int", "int", "exc_handle"
"uint32_t", "uint", "exc_handle"
) {
WrappedManagedFunction = "UnwrapNSException",
OnlyDynamicUsage = false,
Expand Down
6 changes: 3 additions & 3 deletions runtime/runtime-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ void *xamarin_marshal_return_value (SEL sel, MonoType *mtype, const char *type,
*/
@interface XamarinGCHandle : NSObject {
@public
int handle;
uint32_t handle;
}
+(XamarinGCHandle *) createWithHandle: (int) handle;
+(XamarinGCHandle *) createWithHandle: (uint32_t) handle;
-(void) dealloc;
-(int) getHandle;
-(uint32_t) getHandle;
@end

#endif /* __RUNTIME_INTERNAL_H__ */
86 changes: 40 additions & 46 deletions runtime/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
#include "runtime-internal.h"
#include "xamarin/xamarin.h"

// TODO: temp ignore to minimize diff
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wsign-conversion"

#if defined (DEBUG)
//extern BOOL NSZombieEnabled;
#endif
Expand Down Expand Up @@ -492,43 +488,43 @@ void xamarin_framework_peer_unlock ()
return rv;
}

#define MANAGED_REF_BIT (1 << 31)
#define GCHANDLE_WEAK (1 << 30)
#define MANAGED_REF_BIT (1u << 31u)
#define GCHANDLE_WEAK (1u << 30u)
#define GCHANDLE_MASK (MANAGED_REF_BIT | GCHANDLE_WEAK)

// The XamarinExtendedObject protocol is just to avoid a
// compiler warning (no 'xamarinGetGChandle' selector found).
@protocol XamarinExtendedObject
-(int) xamarinGetGCHandle;
-(void) xamarinSetGCHandle: (int) gc_handle;
-(void) xamarinSetGCHandle: (uint32_t) gc_handle;
@end

static inline int
static inline uint32_t
get_raw_gchandle_safe (id self)
{
// COOP: we call a selector, and that must only be done in SAFE mode.
MONO_ASSERT_GC_SAFE_OR_DETACHED;
id<XamarinExtendedObject> xself = self;
return (int) [xself xamarinGetGCHandle];
return (uint32_t) [xself xamarinGetGCHandle];
}

static inline int
static inline uint32_t
get_raw_gchandle (id self)
{
// COOP: we call a selector, and that must only be done in SAFE mode.
MONO_ASSERT_GC_UNSAFE;

int rv;
uint32_t rv;
MONO_ENTER_GC_SAFE;
id<XamarinExtendedObject> xself = self;
rv = (int) [xself xamarinGetGCHandle];
rv = (uint32_t) [xself xamarinGetGCHandle];
MONO_EXIT_GC_SAFE;

return rv;
}

static inline void
set_raw_gchandle (id self, int gc_handle)
set_raw_gchandle (id self, uint32_t gc_handle)
{
// COOP: we call a selector, and that must only be done in SAFE mode.
MONO_ASSERT_GC_UNSAFE;
Expand All @@ -539,21 +535,21 @@ -(void) xamarinSetGCHandle: (int) gc_handle;
MONO_EXIT_GC_SAFE;
}

static inline int
static inline uint32_t
get_gchandle (id self)
{
// COOP: does not access managed memory: any mode
return get_raw_gchandle (self) & ~GCHANDLE_MASK;
}

int
uint32_t
xamarin_get_gchandle (id self)
{
// COOP: does not access managed memory: any mode
return get_gchandle (self);
}

int
uint32_t
xamarin_get_gchandle_with_flags (id self)
{
// COOP: does not access managed memory: any mode
Expand Down Expand Up @@ -684,7 +680,7 @@ -(void) xamarinSetGCHandle: (int) gc_handle;
char *type_name = xamarin_lookup_managed_type_name ([self class], exception_gchandle);
if (*exception_gchandle == 0) {
char *msg = xamarin_strdup_printf (m, self, object_getClassName (self), type_name, sel_getName (sel), method_full_name);
guint32 ex_handle = xamarin_create_runtime_exception (8027, msg, exception_gchandle);
guint32 ex_handle = (guint32) xamarin_create_runtime_exception (8027, msg, exception_gchandle);
xamarin_free (msg);
if (*exception_gchandle == 0)
*exception_gchandle = ex_handle;
Expand Down Expand Up @@ -1042,7 +1038,7 @@ -(void) xamarinSetGCHandle: (int) gc_handle;
options.flags = (InitializationFlags) (options.flags | InitializationFlagsIsPartialStaticRegistrar);

// Sort the type map according to Class
qsort (map->map, map->map_count, sizeof (MTClassMap), compare_mtclassmap);
qsort (map->map, (size_t) map->map_count, sizeof (MTClassMap), compare_mtclassmap);
}

/*
Expand Down Expand Up @@ -1238,7 +1234,7 @@ -(void) xamarinSetGCHandle: (int) gc_handle;
if (options.RegistrationData == NULL || options.RegistrationData->protocol_wrappers == NULL)
return INVALID_TOKEN_REF;

void* ptr = bsearch (&token_ref, options.RegistrationData->protocol_wrappers, options.RegistrationData->protocol_wrapper_count, sizeof (MTProtocolWrapperMap), xamarin_compare_ints);
void* ptr = bsearch (&token_ref, options.RegistrationData->protocol_wrappers, (size_t) options.RegistrationData->protocol_wrapper_count, sizeof (MTProtocolWrapperMap), xamarin_compare_ints);
if (ptr == NULL)
return INVALID_TOKEN_REF;

Expand Down Expand Up @@ -1585,10 +1581,10 @@ -(void) xamarinSetGCHandle: (int) gc_handle;
case _C_CHARPTR: return sizeof (char *);
case _C_BFLD: {
// Example: [NSDecimalNumberPlaceholder initWithDecimal:] = @28@0:4{?=b8b4b1b1b18[8S]}8
int bits = 0;
unsigned long bits = 0;
int bc = 1;
while (type [bc] >= '0' && type [bc] <= '9') {
bits = bits * 10 + (type [bc] - '0');
bits = bits * 10ul + (unsigned long) (type [bc] - '0');
bc++;
}
if (bits % sizeof (void *) == 0)
Expand All @@ -1602,7 +1598,7 @@ -(void) xamarinSetGCHandle: (int) gc_handle;
break;
case _C_ARY_B: {
unsigned long size = 0;
int len = atoi (type+1);
unsigned long len = (unsigned long) atol (type+1);
do {
type++;
} while (isdigit (*type));
Expand Down Expand Up @@ -1743,15 +1739,15 @@ -(void) xamarinSetGCHandle: (int) gc_handle;
*/
//#define DEBUG_REF_COUNTING
void
xamarin_create_gchandle (id self, void *managed_object, int flags, bool force_weak)
xamarin_create_gchandle (id self, void *managed_object, uint32_t flags, bool force_weak)
{
// COOP: reads managed memory: unsafe mode
MONO_ASSERT_GC_UNSAFE;

// force_weak is to avoid calling retainCount unless needed, since some classes (UIWebView in iOS 5)
// will crash if retainCount is called before init. See bug #9261.
bool weak = force_weak || ([self retainCount] == 1);
int gchandle;
uint32_t gchandle;

if (weak) {
gchandle = mono_gchandle_new_weakref ((MonoObject *) managed_object, TRUE);
Expand All @@ -1773,11 +1769,11 @@ -(void) xamarinSetGCHandle: (int) gc_handle;
// COOP: reads managed memory: unsafe mode
MONO_ASSERT_GC_SAFE_OR_DETACHED;

int new_gchandle;
int old_gchandle;
int old_gchandle_raw;
uint32_t new_gchandle;
uint32_t old_gchandle;
uint32_t old_gchandle_raw;
MonoObject *managed_object;
int flags = MANAGED_REF_BIT;
uint32_t flags = MANAGED_REF_BIT;

old_gchandle_raw = get_raw_gchandle_safe (self);
old_gchandle = old_gchandle_raw & ~GCHANDLE_MASK;
Expand Down Expand Up @@ -1865,7 +1861,7 @@ -(void) xamarinSetGCHandle: (int) gc_handle;
}

void
xamarin_set_gchandle (id self, int gchandle)
xamarin_set_gchandle (id self, uint32_t gchandle)
{
// COOP: no managed memory access: any mode
set_raw_gchandle (self, gchandle);
Expand Down Expand Up @@ -1896,7 +1892,7 @@ -(void) xamarinSetGCHandle: (int) gc_handle;

if (options.RegistrationData != NULL && options.RegistrationData->map_count > 0) {
MTClassMap *map = options.RegistrationData->map;
int idx = find_user_type_index (map, 0, options.RegistrationData->map_count - 1, cls);
int idx = find_user_type_index (map, 0, (int) options.RegistrationData->map_count - 1, cls);
if (idx >= 0)
return (map [idx].flags & MTTypeFlagsUserType) == MTTypeFlagsUserType;
// If using the partial static registrar, we need to continue
Expand Down Expand Up @@ -2035,7 +2031,7 @@ -(void) xamarinSetGCHandle: (int) gc_handle;
// COOP: we stay in unsafe mode (since we write to the managed memory) unless calling a selector (which must be done in safe mode)
MONO_ASSERT_GC_UNSAFE;

int gchandle;
uint32_t gchandle;
bool user_type = is_user_type (self);

#if defined(DEBUG_REF_COUNTING)
Expand Down Expand Up @@ -2289,13 +2285,13 @@ -(void) xamarinSetGCHandle: (int) gc_handle;
case MarshalObjectiveCExceptionModeThrowManagedException:
exc_handle = [[ns_exception userInfo] objectForKey: @"XamarinManagedExceptionHandle"];
if (exc_handle != NULL) {
int handle = [exc_handle getHandle];
uint32_t handle = [exc_handle getHandle];
MONO_ENTER_GC_UNSAFE;
MonoObject *exc = mono_gchandle_get_target (handle);
mono_runtime_set_pending_exception ((MonoException *) exc, false);
MONO_EXIT_GC_UNSAFE;
} else {
int handle = xamarin_create_ns_exception (ns_exception, &exception_gchandle);
uint32_t handle = (uint32_t) xamarin_create_ns_exception (ns_exception, &exception_gchandle);
if (exception_gchandle != 0) {
PRINT (PRODUCT ": Got an exception while creating a managed NSException wrapper (will throw this exception instead):");
PRINT ("%@", print_all_exceptions (mono_gchandle_get_target (exception_gchandle)));
Expand Down Expand Up @@ -2325,8 +2321,8 @@ -(void) xamarinSetGCHandle: (int) gc_handle;
MarshalManagedExceptionMode mode;
guint32 exception_gchandle = 0;

int handle = mono_gchandle_new (exception, false);
mode = xamarin_on_marshal_managed_exception (handle, &exception_gchandle);
uint32_t handle = mono_gchandle_new (exception, false);
mode = xamarin_on_marshal_managed_exception ((int) handle, &exception_gchandle);
mono_gchandle_free (handle);

if (exception_gchandle != 0) {
Expand Down Expand Up @@ -2373,7 +2369,7 @@ -(void) xamarinSetGCHandle: (int) gc_handle;

break;
case MarshalManagedExceptionModeThrowObjectiveCException: {
int handle = mono_gchandle_new (exception, false);
uint32_t handle = mono_gchandle_new (exception, false);
NSException *ns_exc = xamarin_unwrap_ns_exception (handle, &exception_gchandle);

if (exception_gchandle != 0) {
Expand Down Expand Up @@ -2483,7 +2479,7 @@ -(void) xamarinSetGCHandle: (int) gc_handle;

#if TARGET_OS_WATCH && defined (__arm__) // maybe make this configurable somehow?
const char *msg = [message UTF8String];
int len = strlen (msg);
size_t len = strlen (msg);
fwrite (msg, 1, len, stdout);
if (len == 0 || msg [len - 1] != '\n')
fwrite ("\n", 1, 1, stdout);
Expand Down Expand Up @@ -2513,7 +2509,7 @@ -(void) xamarinSetGCHandle: (int) gc_handle;
*/

void
xamarin_get_assembly_name_without_extension (const char *aname, char *name, int namelen)
xamarin_get_assembly_name_without_extension (const char *aname, char *name, size_t namelen)
{
size_t len = strlen (aname);
strlcpy (name, aname, namelen);
Expand All @@ -2525,7 +2521,7 @@ -(void) xamarinSetGCHandle: (int) gc_handle;
}

static bool
xamarin_locate_assembly_resource_for_root (const char *root, const char *culture, const char *resource, char *path, int pathlen)
xamarin_locate_assembly_resource_for_root (const char *root, const char *culture, const char *resource, char *path, size_t pathlen)
{
if (culture != NULL && *culture != 0) {
// culture-specific directory
Expand Down Expand Up @@ -2575,7 +2571,7 @@ -(void) xamarinSetGCHandle: (int) gc_handle;
}

bool
xamarin_locate_assembly_resource_for_name (MonoAssemblyName *assembly_name, const char *resource, char *path, int pathlen)
xamarin_locate_assembly_resource_for_name (MonoAssemblyName *assembly_name, const char *resource, char *path, size_t pathlen)
{
const char *culture = mono_assembly_name_get_culture (assembly_name);
const char *aname = mono_assembly_name_get_name (assembly_name);
Expand All @@ -2587,7 +2583,7 @@ -(void) xamarinSetGCHandle: (int) gc_handle;


bool
xamarin_locate_assembly_resource (const char *assembly_name, const char *culture, const char *resource, char *path, int pathlen)
xamarin_locate_assembly_resource (const char *assembly_name, const char *culture, const char *resource, char *path, size_t pathlen)
{
char root [1024];
char aname [256];
Expand Down Expand Up @@ -2881,7 +2877,7 @@ -(int) xamarinGetGCHandle
* XamarinGCHandle
*/
@implementation XamarinGCHandle
+(XamarinGCHandle *) createWithHandle: (int) h
+(XamarinGCHandle *) createWithHandle: (uint32_t) h
{
XamarinGCHandle *rv = [[XamarinGCHandle alloc] init];
rv->handle = h;
Expand All @@ -2895,10 +2891,8 @@ -(void) dealloc
[super dealloc];
}

-(int) getHandle
-(uint32_t) getHandle
{
return handle;
}
@end

#pragma clang diagnostic pop
@end
2 changes: 1 addition & 1 deletion runtime/trampolines.m
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@

static const char *associated_key = "x"; // the string value doesn't matter, only the pointer value.
void
xamarin_set_gchandle_trampoline (id self, SEL sel, int gc_handle)
xamarin_set_gchandle_trampoline (id self, SEL sel, uint32_t gc_handle)
{
// COOP: Called by ObjC (when the setGCHandle: selector is called on an object).
// COOP: Safe mode upon entry, and doesn't access managed memory, so no need to change.
Expand Down
20 changes: 10 additions & 10 deletions runtime/xamarin/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ struct AssemblyLocation {
};

struct AssemblyLocations {
int length;
size_t length;
struct AssemblyLocation *locations;
};

Expand Down Expand Up @@ -211,12 +211,12 @@ void xamarin_release_block_on_main_thread (void *obj);
bool xamarin_has_managed_ref (id self);
bool xamarin_has_managed_ref_safe (id self);
void xamarin_switch_gchandle (id self, bool to_weak);
int xamarin_get_gchandle (id self);
uint32_t xamarin_get_gchandle (id self);
void xamarin_free_gchandle (id self, uint32_t gchandle);
void xamarin_clear_gchandle (id self);
int xamarin_get_gchandle_with_flags (id self);
void xamarin_set_gchandle (id self, int gchandle);
void xamarin_create_gchandle (id self, void *managed_object, int flags, bool force_weak);
uint32_t xamarin_get_gchandle_with_flags (id self);
void xamarin_set_gchandle (id self, uint32_t gchandle);
void xamarin_create_gchandle (id self, void *managed_object, uint32_t flags, bool force_weak);
void xamarin_create_managed_ref (id self, void * managed_object, bool retain);
void xamarin_release_managed_ref (id self, MonoObject *managed_obj);
void xamarin_notify_dealloc (id self, uint32_t gchandle);
Expand Down Expand Up @@ -252,9 +252,9 @@ bool xamarin_is_managed_exception_marshaling_disabled ();

const char * xamarin_find_assembly_directory (const char *assembly_name);
void xamarin_set_assembly_directories (struct AssemblyLocations *directories);
void xamarin_get_assembly_name_without_extension (const char *aname, char *name, int namelen);
bool xamarin_locate_assembly_resource_for_name (MonoAssemblyName *assembly_name, const char *resource, char *path, int pathlen);
bool xamarin_locate_assembly_resource (const char *assembly_name, const char *culture, const char *resource, char *path, int pathlen);
void xamarin_get_assembly_name_without_extension (const char *aname, char *name, size_t namelen);
bool xamarin_locate_assembly_resource_for_name (MonoAssemblyName *assembly_name, const char *resource, char *path, size_t pathlen);
bool xamarin_locate_assembly_resource (const char *assembly_name, const char *culture, const char *resource, char *path, size_t pathlen);

// this functions support NSLog/NSString-style format specifiers.
void xamarin_printf (const char *format, ...);
Expand All @@ -281,7 +281,7 @@ extern xamarin_register_assemblies_callback xamarin_register_assemblies;
class XamarinObject {
public:
id native_object;
int gc_handle;
uint32_t gc_handle;

~XamarinObject ();
};
Expand All @@ -291,7 +291,7 @@ class XamarinObject {
@interface XamarinAssociatedObject : NSObject {
@public
id native_object;
int gc_handle;
uint32_t gc_handle;
}
-(void) dealloc;
@end
Expand Down
Loading