Skip to content

Commit

Permalink
[cxx] Better types at the mono_gc_alloc layer per #6695 (diff). (#10042)
Browse files Browse the repository at this point in the history
This allows for fewer casts from void* to non-void* elsewehere.
  • Loading branch information
jaykrell authored Aug 14, 2018
1 parent 675c94e commit 566b81f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 32 deletions.
16 changes: 8 additions & 8 deletions mono/metadata/boehm-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,12 +699,12 @@ mono_gc_make_root_descr_all_refs (int numbits)
return NULL;
}

void*
MonoObject*
mono_gc_alloc_fixed (size_t size, void *descr, MonoGCRootSource source, void *key, const char *msg)
{
void *start = GC_MALLOC_UNCOLLECTABLE (size);
MONO_PROFILER_RAISE (gc_root_register, ((const mono_byte *) start, size, source, key, msg));
return start;
return (MonoObject*)start;
}

void
Expand All @@ -714,7 +714,7 @@ mono_gc_free_fixed (void* addr)
GC_FREE (addr);
}

void *
MonoObject*
mono_gc_alloc_obj (MonoVTable *vtable, size_t size)
{
MonoObject *obj;
Expand Down Expand Up @@ -746,7 +746,7 @@ mono_gc_alloc_obj (MonoVTable *vtable, size_t size)
return obj;
}

void *
MonoArray*
mono_gc_alloc_vector (MonoVTable *vtable, size_t size, uintptr_t max_length)
{
MonoArray *obj;
Expand Down Expand Up @@ -780,7 +780,7 @@ mono_gc_alloc_vector (MonoVTable *vtable, size_t size, uintptr_t max_length)
return obj;
}

void *
MonoArray*
mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uintptr_t bounds_size)
{
MonoArray *obj;
Expand Down Expand Up @@ -817,7 +817,7 @@ mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uint
return obj;
}

void *
MonoString*
mono_gc_alloc_string (MonoVTable *vtable, size_t size, gint32 len)
{
MonoString *obj = (MonoString *)GC_MALLOC_ATOMIC (size);
Expand All @@ -835,13 +835,13 @@ mono_gc_alloc_string (MonoVTable *vtable, size_t size, gint32 len)
return obj;
}

void*
MonoObject*
mono_gc_alloc_mature (MonoVTable *vtable, size_t size)
{
return mono_gc_alloc_obj (vtable, size);
}

void*
MonoObject*
mono_gc_alloc_pinned_obj (MonoVTable *vtable, size_t size)
{
return mono_gc_alloc_obj (vtable, size);
Expand Down
21 changes: 14 additions & 7 deletions mono/metadata/gc-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ gboolean mono_gc_user_markers_supported (void);
* size bytes will be available from the returned address (ie, descr
* must not be stored in the returned memory)
*/
void* mono_gc_alloc_fixed (size_t size, MonoGCDescriptor descr, MonoGCRootSource source, void *key, const char *msg);
MonoObject* mono_gc_alloc_fixed (size_t size, MonoGCDescriptor descr, MonoGCRootSource source, void *key, const char *msg);
void mono_gc_free_fixed (void* addr);

/* make sure the gchandle was allocated for an object in domain */
Expand All @@ -169,32 +169,39 @@ void mono_gchandle_free_domain (MonoDomain *domain);

typedef void (*FinalizerThreadCallback) (gpointer user_data);

void* mono_gc_alloc_pinned_obj (MonoVTable *vtable, size_t size);
MonoObject*
mono_gc_alloc_pinned_obj (MonoVTable *vtable, size_t size);

MonoObjectHandle
mono_gc_alloc_handle_pinned_obj (MonoVTable *vtable, gsize size);

void* mono_gc_alloc_obj (MonoVTable *vtable, size_t size);
MonoObject*
mono_gc_alloc_obj (MonoVTable *vtable, size_t size);

MonoObjectHandle
mono_gc_alloc_handle_obj (MonoVTable *vtable, gsize size);

void* mono_gc_alloc_vector (MonoVTable *vtable, size_t size, uintptr_t max_length);
MonoArray*
mono_gc_alloc_vector (MonoVTable *vtable, size_t size, uintptr_t max_length);

MonoArrayHandle
mono_gc_alloc_handle_vector (MonoVTable *vtable, gsize size, gsize max_length);

void* mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uintptr_t bounds_size);
MonoArray*
mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uintptr_t bounds_size);

MonoArrayHandle
mono_gc_alloc_handle_array (MonoVTable *vtable, gsize size, gsize max_length, gsize bounds_size);

void* mono_gc_alloc_string (MonoVTable *vtable, size_t size, gint32 len);
MonoString*
mono_gc_alloc_string (MonoVTable *vtable, size_t size, gint32 len);

MonoStringHandle
mono_gc_alloc_handle_string (MonoVTable *vtable, gsize size, gint32 len);

void* mono_gc_alloc_mature (MonoVTable *vtable, size_t size);
MonoObject*
mono_gc_alloc_mature (MonoVTable *vtable, size_t size);

MonoGCDescriptor mono_gc_make_descr_for_string (gsize *bitmap, int numbits);

MonoObjectHandle
Expand Down
16 changes: 8 additions & 8 deletions mono/metadata/null-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ mono_gc_make_root_descr_all_refs (int numbits)
return NULL;
}

void*
MonoObject*
mono_gc_alloc_fixed (size_t size, void *descr, MonoGCRootSource source, void *key, const char *msg)
{
return g_malloc0 (size);
return (MonoObject*)g_malloc0 (size);
}

void
Expand All @@ -176,7 +176,7 @@ mono_gc_free_fixed (void* addr)
g_free (addr);
}

void *
MonoObject*
mono_gc_alloc_obj (MonoVTable *vtable, size_t size)
{
MonoObject *obj = g_calloc (1, size);
Expand All @@ -186,7 +186,7 @@ mono_gc_alloc_obj (MonoVTable *vtable, size_t size)
return obj;
}

void *
MonoArray*
mono_gc_alloc_vector (MonoVTable *vtable, size_t size, uintptr_t max_length)
{
MonoArray *obj = g_calloc (1, size);
Expand All @@ -197,7 +197,7 @@ mono_gc_alloc_vector (MonoVTable *vtable, size_t size, uintptr_t max_length)
return obj;
}

void *
MonoArray*
mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uintptr_t bounds_size)
{
MonoArray *obj = g_calloc (1, size);
Expand All @@ -211,7 +211,7 @@ mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uint
return obj;
}

void *
MonoString*
mono_gc_alloc_string (MonoVTable *vtable, size_t size, gint32 len)
{
MonoString *obj = g_calloc (1, size);
Expand All @@ -223,13 +223,13 @@ mono_gc_alloc_string (MonoVTable *vtable, size_t size, gint32 len)
return obj;
}

void*
MonoObject*
mono_gc_alloc_mature (MonoVTable *vtable, size_t size)
{
return mono_gc_alloc_obj (vtable, size);
}

void*
MonoObject*
mono_gc_alloc_pinned_obj (MonoVTable *vtable, size_t size)
{
return mono_gc_alloc_obj (vtable, size);
Expand Down
2 changes: 1 addition & 1 deletion mono/metadata/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -5629,7 +5629,7 @@ mono_object_new_pinned (MonoDomain *domain, MonoClass *klass, MonoError *error)
vtable = mono_class_vtable_checked (domain, klass, error);
return_val_if_nok (error, NULL);

MonoObject *o = (MonoObject *)mono_gc_alloc_pinned_obj (vtable, mono_class_instance_size (klass));
MonoObject *o = mono_gc_alloc_pinned_obj (vtable, mono_class_instance_size (klass));

return object_new_common_tail (o, klass, error);
}
Expand Down
16 changes: 8 additions & 8 deletions mono/metadata/sgen-mono.c
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ mono_gc_clear_domain (MonoDomain * domain)
* Allocation
*/

void*
MonoObject*
mono_gc_alloc_obj (MonoVTable *vtable, size_t size)
{
MonoObject *obj = sgen_alloc_obj (vtable, size);
Expand All @@ -914,7 +914,7 @@ mono_gc_alloc_obj (MonoVTable *vtable, size_t size)
return obj;
}

void*
MonoObject*
mono_gc_alloc_pinned_obj (MonoVTable *vtable, size_t size)
{
MonoObject *obj = sgen_alloc_obj_pinned (vtable, size);
Expand All @@ -925,7 +925,7 @@ mono_gc_alloc_pinned_obj (MonoVTable *vtable, size_t size)
return obj;
}

void*
MonoObject*
mono_gc_alloc_mature (MonoVTable *vtable, size_t size)
{
MonoObject *obj = sgen_alloc_obj_mature (vtable, size);
Expand All @@ -939,7 +939,7 @@ mono_gc_alloc_mature (MonoVTable *vtable, size_t size)
/**
* mono_gc_alloc_fixed:
*/
void*
MonoObject*
mono_gc_alloc_fixed (size_t size, MonoGCDescriptor descr, MonoGCRootSource source, void *key, const char *msg)
{
/* FIXME: do a single allocation */
Expand All @@ -950,7 +950,7 @@ mono_gc_alloc_fixed (size_t size, MonoGCDescriptor descr, MonoGCRootSource sourc
g_free (res);
res = NULL;
}
return res;
return (MonoObject*)res;
}

/**
Expand Down Expand Up @@ -1287,7 +1287,7 @@ sgen_client_cardtable_scan_object (GCObject *obj, guint8 *cards, ScanCopyContext
* Array and string allocation
*/

void*
MonoArray*
mono_gc_alloc_vector (MonoVTable *vtable, size_t size, uintptr_t max_length)
{
MonoArray *arr;
Expand Down Expand Up @@ -1328,7 +1328,7 @@ mono_gc_alloc_vector (MonoVTable *vtable, size_t size, uintptr_t max_length)
return arr;
}

void*
MonoArray*
mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uintptr_t bounds_size)
{
MonoArray *arr;
Expand Down Expand Up @@ -1376,7 +1376,7 @@ mono_gc_alloc_array (MonoVTable *vtable, size_t size, uintptr_t max_length, uint
return arr;
}

void*
MonoString*
mono_gc_alloc_string (MonoVTable *vtable, size_t size, gint32 len)
{
MonoString *str;
Expand Down

0 comments on commit 566b81f

Please sign in to comment.