From 8eb10a6e402a3f78d3ed5b9d107a32838aaa2120 Mon Sep 17 00:00:00 2001 From: kumpera Date: Thu, 22 Oct 2009 20:56:07 +0000 Subject: [PATCH] 2009-10-22 Rodrigo Kumpera * class-internals.h: Change signature of mono_class_inflate_generic_type_with_mempool to take a MonoError parameter. * class.h: Mark mono_class_inflate_generic_type deprecated, add new mono_class_inflate_generic_type_checked version that can does proper error handling. * class.c (inflate_generic_type): Add a MonoError parameter. Don't assert on error, use new mono error machinery. * class.c (mono_class_inflate_generic_type_with_mempool): Add new MonoError parameter. * class.c, generics-sharing.c: Changes to handle mono_class_inflate_generic_type_with_mempool new signature. git-svn-id: svn+ssh://mono-cvs.ximian.com/source/trunk/mono@144688 e3ebcda4-bce8-0310-ba0a-eca2169e7518 --- mono/metadata/ChangeLog | 14 ++++++++ mono/metadata/class-internals.h | 3 +- mono/metadata/class.c | 80 ++++++++++++++++++++++++++++++++--------- mono/metadata/class.h | 7 +++- mono/metadata/generic-sharing.c | 11 ++++-- 5 files changed, 94 insertions(+), 21 deletions(-) diff --git a/mono/metadata/ChangeLog b/mono/metadata/ChangeLog index d5a512923..a7e04642f 100644 --- a/mono/metadata/ChangeLog +++ b/mono/metadata/ChangeLog @@ -1,3 +1,17 @@ +2009-10-22 Rodrigo Kumpera + + * class-internals.h: Change signature of mono_class_inflate_generic_type_with_mempool to take + a MonoError parameter. + + * class.h: Mark mono_class_inflate_generic_type deprecated, add new mono_class_inflate_generic_type_checked + version that can does proper error handling. + + * class.c (inflate_generic_type): Add a MonoError parameter. Don't assert on error, use new mono error machinery. + + * class.c (mono_class_inflate_generic_type_with_mempool): Add new MonoError parameter. + + * class.c, generics-sharing.c: Changes to handle mono_class_inflate_generic_type_with_mempool new signature. + 2009-10-20 Zoltan Varga * debug-helpers.c (dis_one): Fix the disassembly of empty strings when diff --git a/mono/metadata/class-internals.h b/mono/metadata/class-internals.h index ac66a63dd..05956cb0b 100644 --- a/mono/metadata/class-internals.h +++ b/mono/metadata/class-internals.h @@ -6,6 +6,7 @@ #include #include #include "mono/utils/mono-compiler.h" +#include "mono/utils/mono-error.h" #define MONO_CLASS_IS_ARRAY(c) ((c)->rank) @@ -944,7 +945,7 @@ MonoMethodSignature * mono_metadata_get_inflated_signature (MonoMethodSignature *sig, MonoGenericContext *context); MonoType* -mono_class_inflate_generic_type_with_mempool (MonoImage *image, MonoType *type, MonoGenericContext *context) MONO_INTERNAL; +mono_class_inflate_generic_type_with_mempool (MonoImage *image, MonoType *type, MonoGenericContext *context, MonoError *error) MONO_INTERNAL; MonoClass* mono_class_inflate_generic_class (MonoClass *gklass, MonoGenericContext *context) MONO_INTERNAL; diff --git a/mono/metadata/class.c b/mono/metadata/class.c index 91bae5b79..ac1b85d4c 100644 --- a/mono/metadata/class.c +++ b/mono/metadata/class.c @@ -40,6 +40,7 @@ #include #include #include +#include MonoStats mono_stats; @@ -492,8 +493,10 @@ mono_class_is_open_constructed_type (MonoType *t) } static MonoType* -inflate_generic_type (MonoImage *image, MonoType *type, MonoGenericContext *context) +inflate_generic_type (MonoImage *image, MonoType *type, MonoGenericContext *context, MonoError *error) { + mono_error_init (error); + switch (type->type) { case MONO_TYPE_MVAR: { MonoType *nt; @@ -503,8 +506,9 @@ inflate_generic_type (MonoImage *image, MonoType *type, MonoGenericContext *cont return NULL; if (num >= inst->type_argc) { MonoGenericParamInfo *info = mono_generic_param_info (type->data.generic_param); - g_error ("MVAR %d (%s) cannot be expanded in this context with %d instantiations", + mono_error_set_bad_image (error, image->module_name, "MVAR %d (%s) cannot be expanded in this context with %d instantiations", num, info ? info->name : "", inst->type_argc); + return NULL; } /* @@ -525,8 +529,9 @@ inflate_generic_type (MonoImage *image, MonoType *type, MonoGenericContext *cont return NULL; if (num >= inst->type_argc) { MonoGenericParamInfo *info = mono_generic_param_info (type->data.generic_param); - g_error ("VAR %d (%s) cannot be expanded in this context with %d instantiations", + mono_error_set_bad_image (error, image->module_name, "VAR %d (%s) cannot be expanded in this context with %d instantiations", num, info ? info->name : "", inst->type_argc); + return NULL; } nt = mono_metadata_type_dup (image, inst->type_argv [num]); nt->byref = type->byref; @@ -535,8 +540,8 @@ inflate_generic_type (MonoImage *image, MonoType *type, MonoGenericContext *cont } case MONO_TYPE_SZARRAY: { MonoClass *eclass = type->data.klass; - MonoType *nt, *inflated = inflate_generic_type (NULL, &eclass->byval_arg, context); - if (!inflated) + MonoType *nt, *inflated = inflate_generic_type (NULL, &eclass->byval_arg, context, error); + if (!inflated || !mono_error_ok (error)) return NULL; nt = mono_metadata_type_dup (image, type); nt->data.klass = mono_class_from_mono_type (inflated); @@ -545,8 +550,8 @@ inflate_generic_type (MonoImage *image, MonoType *type, MonoGenericContext *cont } case MONO_TYPE_ARRAY: { MonoClass *eclass = type->data.array->eklass; - MonoType *nt, *inflated = inflate_generic_type (NULL, &eclass->byval_arg, context); - if (!inflated) + MonoType *nt, *inflated = inflate_generic_type (NULL, &eclass->byval_arg, context, error); + if (!inflated || !mono_error_ok (error)) return NULL; nt = mono_metadata_type_dup (image, type); nt->data.array = g_memdup (nt->data.array, sizeof (MonoArrayType)); @@ -644,6 +649,7 @@ mono_class_get_generic_class (MonoClass *klass) * @mempool: a mempool * @type: a type * @context: a generics context + * @error: error context * * The same as mono_class_inflate_generic_type, but allocates the MonoType * from mempool if it is non-NULL. If it is NULL, the MonoType is @@ -652,12 +658,14 @@ mono_class_get_generic_class (MonoClass *klass) * modified by the caller, and it should be freed using mono_metadata_free_type (). */ MonoType* -mono_class_inflate_generic_type_with_mempool (MonoImage *image, MonoType *type, MonoGenericContext *context) +mono_class_inflate_generic_type_with_mempool (MonoImage *image, MonoType *type, MonoGenericContext *context, MonoError *error) { MonoType *inflated = NULL; if (context) - inflated = inflate_generic_type (image, type, context); + inflated = inflate_generic_type (image, type, context, error); + if (!mono_error_ok (error)) + return NULL; if (!inflated) { MonoType *shared = mono_metadata_get_shared_type (type); @@ -682,12 +690,40 @@ mono_class_inflate_generic_type_with_mempool (MonoImage *image, MonoType *type, * generics context @context. * * Returns: the instantiated type or a copy of @type. The returned MonoType is allocated - * on the heap and is owned by the caller. + * on the heap and is owned by the caller. Returns NULL on error. + * + * @deprecated Please use mono_class_inflate_generic_type_checked instead */ MonoType* mono_class_inflate_generic_type (MonoType *type, MonoGenericContext *context) { - return mono_class_inflate_generic_type_with_mempool (NULL, type, context); + MonoError error; + MonoType *result; + result = mono_class_inflate_generic_type_checked (type, context, &error); + + if (!mono_error_ok (&error)) { + mono_error_cleanup (&error); + return NULL; + } + return result; +} + +/* + * mono_class_inflate_generic_type: + * @type: a type + * @context: a generics context + * @error: error context to use + * + * If @type is a generic type and @context is not NULL, instantiate it using the + * generics context @context. + * + * Returns: the instantiated type or a copy of @type. The returned MonoType is allocated + * on the heap and is owned by the caller. + */ +MonoType* +mono_class_inflate_generic_type_checked (MonoType *type, MonoGenericContext *context, MonoError *error) +{ + return mono_class_inflate_generic_type_with_mempool (NULL, type, context, error); } /* @@ -699,10 +735,13 @@ mono_class_inflate_generic_type (MonoType *type, MonoGenericContext *context) static MonoType* mono_class_inflate_generic_type_no_copy (MonoImage *image, MonoType *type, MonoGenericContext *context) { + MonoError error; MonoType *inflated = NULL; - if (context) - inflated = inflate_generic_type (image, type, context); + if (context) { + inflated = inflate_generic_type (image, type, context, &error); + g_assert (mono_error_ok (&error)); /*FIXME proper error handling*/ + } if (!inflated) return type; @@ -719,10 +758,12 @@ mono_class_inflate_generic_type_no_copy (MonoImage *image, MonoType *type, MonoG MonoClass* mono_class_inflate_generic_class (MonoClass *gklass, MonoGenericContext *context) { + MonoError error; MonoClass *res; MonoType *inflated; - inflated = mono_class_inflate_generic_type (&gklass->byval_arg, context); + inflated = mono_class_inflate_generic_type_checked (&gklass->byval_arg, context, &error); + g_assert (mono_error_ok (&error)); /*FIXME proper error handling*/ res = mono_class_from_mono_type (inflated); mono_metadata_free_type (inflated); @@ -892,7 +933,11 @@ mono_class_inflate_generic_method_full (MonoMethod *method, MonoClass *klass_hin result->klass = klass_hint; if (!result->klass) { - MonoType *inflated = inflate_generic_type (NULL, &method->klass->byval_arg, context); + MonoError error; + MonoType *inflated = inflate_generic_type (NULL, &method->klass->byval_arg, context, &error); + + g_assert (mono_error_ok (&error)); /*FIXME proper error handling*/ + result->klass = inflated ? mono_class_from_mono_type (inflated) : method->klass; if (inflated) mono_metadata_free_type (inflated); @@ -4983,11 +5028,14 @@ mono_class_from_mono_type (MonoType *type) static MonoType * mono_type_retrieve_from_typespec (MonoImage *image, guint32 type_spec, MonoGenericContext *context, gboolean *did_inflate) { + MonoError error; MonoType *t = mono_type_create_from_typespec (image, type_spec); if (!t) return NULL; if (context && (context->class_inst || context->method_inst)) { - MonoType *inflated = inflate_generic_type (NULL, t, context); + MonoType *inflated = inflate_generic_type (NULL, t, context, &error); + g_assert (mono_error_ok (&error)); /*FIXME proper error handling*/ + if (inflated) { t = inflated; *did_inflate = TRUE; diff --git a/mono/metadata/class.h b/mono/metadata/class.h index a1dc03355..37d06eb29 100644 --- a/mono/metadata/class.h +++ b/mono/metadata/class.h @@ -4,6 +4,8 @@ #include #include #include +#include +#include G_BEGIN_DECLS @@ -52,7 +54,10 @@ MonoClass * mono_class_from_generic_parameter (MonoGenericParam *param, MonoImage *image, gboolean is_mvar); MonoType* -mono_class_inflate_generic_type (MonoType *type, MonoGenericContext *context); +mono_class_inflate_generic_type (MonoType *type, MonoGenericContext *context) MONO_DEPRECATED; + +MonoType* +mono_class_inflate_generic_type_checked (MonoType *type, MonoGenericContext *context, MonoError *error); MonoMethod* mono_class_inflate_generic_method (MonoMethod *method, MonoGenericContext *context); diff --git a/mono/metadata/generic-sharing.c b/mono/metadata/generic-sharing.c index 690c87ed7..e4e49539e 100644 --- a/mono/metadata/generic-sharing.c +++ b/mono/metadata/generic-sharing.c @@ -486,6 +486,8 @@ mono_class_get_method_generic (MonoClass *klass, MonoMethod *method) static gpointer inflate_other_data (gpointer data, int info_type, MonoGenericContext *context, MonoClass *class, gboolean temporary) { + MonoError error; + g_assert (data); if (data == MONO_RGCTX_SLOT_USED_MARKER) @@ -497,9 +499,12 @@ inflate_other_data (gpointer data, int info_type, MonoGenericContext *context, M case MONO_RGCTX_INFO_KLASS: case MONO_RGCTX_INFO_VTABLE: case MONO_RGCTX_INFO_TYPE: - case MONO_RGCTX_INFO_REFLECTION_TYPE: - return mono_class_inflate_generic_type_with_mempool (temporary ? NULL : class->image, - data, context); + case MONO_RGCTX_INFO_REFLECTION_TYPE: { + gpointer result = mono_class_inflate_generic_type_with_mempool (temporary ? NULL : class->image, + data, context, &error); + g_assert (mono_error_ok (&error)); /*FIXME proper error handling*/ + return result; + } case MONO_RGCTX_INFO_METHOD: case MONO_RGCTX_INFO_GENERIC_METHOD_CODE: -- 2.11.4.GIT