Author: zoltan
Date: 2007-12-10 16:24:08 -0500 (Mon, 10 Dec 2007)
New Revision: 91065

Modified:
   trunk/mono/mono/metadata/class-internals.h
   trunk/mono/mono/metadata/class.c
   trunk/mono/mono/metadata/icall.c
   trunk/mono/mono/metadata/object-internals.h
   trunk/mono/mono/metadata/reflection.c
Log:
2007-12-10  Zoltan Varga  <[EMAIL PROTECTED]>

        * reflection.c (mono_reflection_get_token): Call 
mono_image_create_token () for
        FieldBuilders.

        * icall.c 
(ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor): 
Fix a warning.

        * class.c (mono_lookup_dynamic_token_class): Add a 'valid token' 
argument to
        prevent asserts when this is called with a token which might not be 
valid.

        * icall.c (ves_icall_System_Reflection_Module_ResolveTypeToken): Call
        lookup_dynamic_token_class with valid_token == FALSE.

        * icall.c (ves_icall_System_Reflection_Module_ResolveMethodToken): 
Ditto.       

        * icall.c (ves_icall_System_Reflection_Module_ResolveStringToken): 
Ditto.

        * icall.c (ves_icall_System_Reflection_Module_ResolveFieldToken): Ditto.


Modified: trunk/mono/mono/metadata/class-internals.h
===================================================================
--- trunk/mono/mono/metadata/class-internals.h  2007-12-10 21:18:37 UTC (rev 
91064)
+++ trunk/mono/mono/metadata/class-internals.h  2007-12-10 21:24:08 UTC (rev 
91065)
@@ -587,7 +587,7 @@
 typedef gpointer (*MonoRemotingTrampoline)       (MonoMethod *method, 
MonoRemotingTarget target);
 typedef gpointer (*MonoDelegateTrampoline)       (MonoClass *klass);
 
-typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token, 
MonoClass **handle_class, MonoGenericContext *context);
+typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token, 
gboolean valid_token, MonoClass **handle_class, MonoGenericContext *context);
 
 typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, 
MonoCachedClassInfo *res);
 
@@ -664,7 +664,7 @@
 mono_lookup_dynamic_token (MonoImage *image, guint32 token, MonoGenericContext 
*context) MONO_INTERNAL;
 
 gpointer
-mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, MonoClass 
**handle_class, MonoGenericContext *context) MONO_INTERNAL;
+mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, gboolean 
check_token, MonoClass **handle_class, MonoGenericContext *context) 
MONO_INTERNAL;
 
 void
 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func) MONO_INTERNAL;

Modified: trunk/mono/mono/metadata/class.c
===================================================================
--- trunk/mono/mono/metadata/class.c    2007-12-10 21:18:37 UTC (rev 91064)
+++ trunk/mono/mono/metadata/class.c    2007-12-10 21:24:08 UTC (rev 91065)
@@ -5209,7 +5209,7 @@
 {
        if (image->dynamic) {
                MonoClass *tmp_handle_class;
-               gpointer obj = mono_lookup_dynamic_token_class (image, token, 
&tmp_handle_class, context);
+               gpointer obj = mono_lookup_dynamic_token_class (image, token, 
TRUE, &tmp_handle_class, context);
 
                g_assert (tmp_handle_class);
                if (handle_class)
@@ -5299,13 +5299,13 @@
 {
        MonoClass *handle_class;
 
-       return lookup_dynamic (image, token, &handle_class, context);
+       return lookup_dynamic (image, token, TRUE, &handle_class, context);
 }
 
 gpointer
-mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, MonoClass 
**handle_class, MonoGenericContext *context)
+mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, gboolean 
valid_token, MonoClass **handle_class, MonoGenericContext *context)
 {
-       return lookup_dynamic (image, token, handle_class, context);
+       return lookup_dynamic (image, token, valid_token, handle_class, 
context);
 }
 
 static MonoGetCachedClassInfo get_cached_class_info = NULL;

Modified: trunk/mono/mono/metadata/icall.c
===================================================================
--- trunk/mono/mono/metadata/icall.c    2007-12-10 21:18:37 UTC (rev 91064)
+++ trunk/mono/mono/metadata/icall.c    2007-12-10 21:24:08 UTC (rev 91065)
@@ -817,7 +817,6 @@
 ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_RunClassConstructor 
(MonoType *handle)
 {
        MonoClass *klass;
-       MonoMethod *method;
 
        MONO_ARCH_SAVE_REGS;
 
@@ -5149,7 +5148,7 @@
        if (image->dynamic) {
                if (type_args || method_args)
                        mono_raise_exception 
(mono_get_exception_not_implemented (NULL));
-               return mono_lookup_dynamic_token (image, token, NULL);
+               return mono_lookup_dynamic_token_class (image, token, FALSE, 
NULL, NULL);
        }
 
        if ((index <= 0) || (index > image->tables [table].rows)) {
@@ -5187,7 +5186,7 @@
                if (type_args || method_args)
                        mono_raise_exception 
(mono_get_exception_not_implemented (NULL));
                /* FIXME: validate memberref token type */
-               return mono_lookup_dynamic_token (image, token, NULL);
+               return mono_lookup_dynamic_token_class (image, token, FALSE, 
NULL, NULL);
        }
 
        if ((index <= 0) || (index > image->tables [table].rows)) {
@@ -5219,7 +5218,7 @@
        }
 
        if (image->dynamic)
-               return mono_lookup_dynamic_token (image, token, NULL);
+               return mono_lookup_dynamic_token_class (image, token, FALSE, 
NULL, NULL);
 
        if ((index <= 0) || (index >= image->heap_us.size)) {
                *error = ResolveTokenError_OutOfRange;
@@ -5252,7 +5251,7 @@
                if (type_args || method_args)
                        mono_raise_exception 
(mono_get_exception_not_implemented (NULL));
                /* FIXME: validate memberref token type */
-               return mono_lookup_dynamic_token (image, token, NULL);
+               return mono_lookup_dynamic_token_class (image, token, FALSE, 
NULL, NULL);
        }
 
        if ((index <= 0) || (index > image->tables [table].rows)) {

Modified: trunk/mono/mono/metadata/object-internals.h
===================================================================
--- trunk/mono/mono/metadata/object-internals.h 2007-12-10 21:18:37 UTC (rev 
91064)
+++ trunk/mono/mono/metadata/object-internals.h 2007-12-10 21:24:08 UTC (rev 
91065)
@@ -1102,7 +1102,7 @@
 MonoReflectionMarshal* mono_reflection_marshal_from_marshal_spec (MonoDomain 
*domain, MonoClass *klass, MonoMarshalSpec *spec) MONO_INTERNAL;
 
 gpointer
-mono_reflection_lookup_dynamic_token (MonoImage *image, guint32 token, 
MonoClass **handle_class, MonoGenericContext *context) MONO_INTERNAL;
+mono_reflection_lookup_dynamic_token (MonoImage *image, guint32 token, 
gboolean valid_token, MonoClass **handle_class, MonoGenericContext *context) 
MONO_INTERNAL;
 
 gboolean
 mono_reflection_call_is_assignable_to (MonoClass *klass, MonoClass *oklass) 
MONO_INTERNAL;

Modified: trunk/mono/mono/metadata/reflection.c
===================================================================
--- trunk/mono/mono/metadata/reflection.c       2007-12-10 21:18:37 UTC (rev 
91064)
+++ trunk/mono/mono/metadata/reflection.c       2007-12-10 21:24:08 UTC (rev 
91065)
@@ -6678,7 +6678,9 @@
                token = mb->table_idx | MONO_TOKEN_METHOD_DEF;
        } else if (strcmp (klass->name, "FieldBuilder") == 0) {
                MonoReflectionFieldBuilder *fb = (MonoReflectionFieldBuilder 
*)obj;
-               token = fb->table_idx | MONO_TOKEN_FIELD_DEF;
+
+               /* Call mono_image_create_token so the object gets added to the 
tokens hash table */
+               token = mono_image_create_token 
(((MonoReflectionTypeBuilder*)fb->typeb)->module->dynamic_image, obj, FALSE);
        } else if (strcmp (klass->name, "TypeBuilder") == 0) {
                MonoReflectionTypeBuilder *tb = (MonoReflectionTypeBuilder 
*)obj;
                token = tb->table_idx | MONO_TOKEN_TYPE_DEF;
@@ -9698,18 +9700,27 @@
  * mono_reflection_lookup_dynamic_token:
  *
  * Finish the Builder object pointed to by TOKEN and return the corresponding
- * runtime structure. HANDLE_CLASS is set to the class required by 
- * mono_ldtoken.
+ * runtime structure. If HANDLE_CLASS is not NULL, it is set to the class 
required by 
+ * mono_ldtoken. If valid_token is TRUE, assert if it is not found in the 
token->object
+ * mapping table.
  */
 gpointer
-mono_reflection_lookup_dynamic_token (MonoImage *image, guint32 token, 
MonoClass **handle_class, MonoGenericContext *context)
+mono_reflection_lookup_dynamic_token (MonoImage *image, guint32 token, 
gboolean valid_token, MonoClass **handle_class, MonoGenericContext *context)
 {
        MonoDynamicImage *assembly = (MonoDynamicImage*)image;
        MonoObject *obj;
+       MonoClass *klass;
 
        obj = mono_g_hash_table_lookup (assembly->tokens, GUINT_TO_POINTER 
(token));
-       g_assert (obj);
+       if (!obj) {
+               if (valid_token)
+                       g_assert_not_reached ();
+               else
+                       return NULL;
+       }
 
+       if (!handle_class)
+               handle_class = &klass;
        return resolve_object (image, obj, handle_class, context);
 }
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to