Author: mprobst
Date: 2007-07-19 11:42:53 -0400 (Thu, 19 Jul 2007)
New Revision: 82294
Added:
trunk/mono/mono/tests/bug-81691-a.cs
trunk/mono/mono/tests/bug-81691-b.cs
trunk/mono/mono/tests/bug-81691.cs
Modified:
trunk/mono/mono/metadata/ChangeLog
trunk/mono/mono/metadata/class-internals.h
trunk/mono/mono/metadata/class.c
trunk/mono/mono/metadata/icall.c
trunk/mono/mono/metadata/loader.c
trunk/mono/mono/mini/ChangeLog
trunk/mono/mono/mini/mini.c
trunk/mono/mono/tests/ChangeLog
trunk/mono/mono/tests/Makefile.am
Log:
2007-07-19 Mark Probst <[EMAIL PROTECTED]>
* class.c, loader.c, class-internals.h: Removed the
MonoLoaderErrorKind enum and replaced it with the MONO_EXCEPTION_
defines.
* icall.c: Better error checking in some internal reflection
methods.
2007-07-19 Mark Probst <[EMAIL PROTECTED]>
* mini.c: Removed the MonoLoaderErrorKind enum and replaced it
with the MONO_EXCEPTION_ defines.
2007-07-19 Mark Probst <[EMAIL PROTECTED]>
* Makefile.am (test-bug-81691), bug-81691.cs, bug-81691-a.cs,
bug-81691-b.cs: Test for bug #81691.
Modified: trunk/mono/mono/metadata/ChangeLog
===================================================================
--- trunk/mono/mono/metadata/ChangeLog 2007-07-19 15:35:28 UTC (rev 82293)
+++ trunk/mono/mono/metadata/ChangeLog 2007-07-19 15:42:53 UTC (rev 82294)
@@ -1,3 +1,12 @@
+2007-07-19 Mark Probst <[EMAIL PROTECTED]>
+
+ * class.c, loader.c, class-internals.h: Removed the
+ MonoLoaderErrorKind enum and replaced it with the MONO_EXCEPTION_
+ defines.
+
+ * icall.c: Better error checking in some internal reflection
+ methods.
+
2007-07-18 William Holmes <[EMAIL PROTECTED]>
* filewatcher.c : removed unused variable 'filename' in
Modified: trunk/mono/mono/metadata/class-internals.h
===================================================================
--- trunk/mono/mono/metadata/class-internals.h 2007-07-19 15:35:28 UTC (rev
82293)
+++ trunk/mono/mono/metadata/class-internals.h 2007-07-19 15:42:53 UTC (rev
82294)
@@ -171,7 +171,8 @@
MONO_EXCEPTION_UNVERIFIABLE_IL = 4,
MONO_EXCEPTION_MISSING_METHOD = 5,
MONO_EXCEPTION_MISSING_FIELD = 6,
- MONO_EXCEPTION_TYPE_LOAD = 7
+ MONO_EXCEPTION_TYPE_LOAD = 7,
+ MONO_EXCEPTION_FILE_NOT_FOUND = 8
/* add other exception type */
};
@@ -488,18 +489,8 @@
MonoMethodSignature *sig;
} MonoJitICallInfo;
-/*
- * Information about a type load error encountered by the loader.
- */
-typedef enum {
- MONO_LOADER_ERROR_TYPE,
- MONO_LOADER_ERROR_METHOD,
- MONO_LOADER_ERROR_FIELD,
- MONO_LOADER_ERROR_ASSEMBLY
-} MonoLoaderErrorKind;
-
typedef struct {
- MonoLoaderErrorKind kind;
+ guint8 exception_type;
char *class_name; /* If kind == TYPE */
char *assembly_name; /* If kind == TYPE or ASSEMBLY */
MonoClass *klass; /* If kind != TYPE */
Modified: trunk/mono/mono/metadata/class.c
===================================================================
--- trunk/mono/mono/metadata/class.c 2007-07-19 15:35:28 UTC (rev 82293)
+++ trunk/mono/mono/metadata/class.c 2007-07-19 15:42:53 UTC (rev 82294)
@@ -2389,6 +2389,66 @@
return method;
}
+static char*
+concat_two_strings_with_zero (MonoMemPool *pool, const char *s1, const char
*s2)
+{
+ int len = strlen (s1) + strlen (s2) + 2;
+ char *s = mono_mempool_alloc (pool, len);
+ int result;
+
+ result = g_snprintf (s, len, "%s%c%s", s1, '\0', s2);
+ g_assert (result == len);
+
+ return s;
+}
+
+static void
+set_failure_from_loader_error (MonoClass *class, MonoLoaderError *error)
+{
+ class->exception_type = error->exception_type;
+
+ switch (error->exception_type) {
+ case MONO_EXCEPTION_TYPE_LOAD:
+ class->exception_data = concat_two_strings_with_zero
(class->image->mempool, error->class_name, error->assembly_name);
+ break;
+
+ case MONO_EXCEPTION_MISSING_METHOD:
+ class->exception_data = concat_two_strings_with_zero
(class->image->mempool, error->class_name, error->member_name);
+ break;
+
+ case MONO_EXCEPTION_MISSING_FIELD: {
+ const char *name_space = error->klass->name_space ?
error->klass->name_space : NULL;
+ const char *class_name;
+
+ if (name_space)
+ class_name = g_strdup_printf ("%s.%s", name_space,
error->klass->name);
+ else
+ class_name = error->klass->name;
+
+ class->exception_data = concat_two_strings_with_zero
(class->image->mempool, class_name, error->member_name);
+
+ if (name_space)
+ g_free ((void*)class_name);
+ break;
+ }
+
+ case MONO_EXCEPTION_FILE_NOT_FOUND: {
+ const char *msg;
+
+ if (error->ref_only)
+ msg = "Cannot resolve dependency to assembly '%s'
because it has not been preloaded. When using the ReflectionOnly APIs,
dependent assemblies must be pre-loaded or loaded on demand through the
ReflectionOnlyAssemblyResolve event.";
+ else
+ msg = "Could not load file or assembly '%s' or one of
its dependencies.";
+
+ class->exception_data = concat_two_strings_with_zero
(class->image->mempool, msg, error->assembly_name);
+ break;
+ }
+
+ default :
+ g_assert_not_reached ();
+ }
+}
+
/**
* mono_class_init:
* @class: the class to initialize
@@ -2422,7 +2482,7 @@
if (class->inited) {
mono_loader_unlock ();
/* Somebody might have gotten in before us */
- return TRUE;
+ return class->exception_type == MONO_EXCEPTION_NONE;
}
if (class->init_pending) {
@@ -2676,6 +2736,13 @@
class->inited = 1;
class->init_pending = 0;
+ if (mono_loader_get_last_error ()) {
+ if (class->exception_type == MONO_EXCEPTION_NONE)
+ set_failure_from_loader_error (class,
mono_loader_get_last_error ());
+
+ mono_loader_clear_error ();
+ }
+
mono_loader_unlock ();
if (mono_debugger_class_init_func)
@@ -5479,6 +5546,30 @@
g_free (astr);
return ex;
}
+ case MONO_EXCEPTION_MISSING_METHOD: {
+ char *class_name = klass->exception_data;
+ char *assembly_name = class_name + strlen (class_name) + 1;
+
+ return mono_get_exception_missing_method (class_name,
assembly_name);
+ }
+ case MONO_EXCEPTION_MISSING_FIELD: {
+ char *class_name = klass->exception_data;
+ char *member_name = class_name + strlen (class_name) + 1;
+
+ return mono_get_exception_missing_field (class_name,
member_name);
+ }
+ case MONO_EXCEPTION_FILE_NOT_FOUND: {
+ char *msg_format = klass->exception_data;
+ char *assembly_name = msg_format + strlen (msg_format) + 1;
+ char *msg = g_strdup_printf (msg_format, assembly_name);
+ MonoException *ex;
+
+ ex = mono_get_exception_file_not_found2 (msg, mono_string_new
(mono_domain_get (), assembly_name));
+
+ g_free (msg);
+
+ return ex;
+ }
default: {
MonoLoaderError *error;
MonoException *ex;
Modified: trunk/mono/mono/metadata/icall.c
===================================================================
--- trunk/mono/mono/metadata/icall.c 2007-07-19 15:35:28 UTC (rev 82293)
+++ trunk/mono/mono/metadata/icall.c 2007-07-19 15:42:53 UTC (rev 82294)
@@ -3070,9 +3070,15 @@
compare_func = (bflags & BFLAGS_IgnoreCase) ? g_strcasecmp : strcmp;
handle_parent:
+ if (klass->exception_type != MONO_EXCEPTION_NONE)
+ mono_raise_exception (mono_class_get_exception_for_failure
(klass));
+
iter = NULL;
while ((field = mono_class_get_fields (klass, &iter))) {
match = 0;
+
+ if (field->type == NULL)
+ continue;
if (mono_field_is_deleted (field))
continue;
if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) ==
FIELD_ATTRIBUTE_PUBLIC) {
@@ -3136,6 +3142,9 @@
len = 2;
res = mono_array_new (domain, mono_defaults.field_info_class, len);
handle_parent:
+ if (klass->exception_type != MONO_EXCEPTION_NONE)
+ mono_raise_exception (mono_class_get_exception_for_failure
(klass));
+
iter = NULL;
while ((field = mono_class_get_fields (klass, &iter))) {
match = 0;
@@ -3231,6 +3240,9 @@
res = mono_array_new (domain, mono_defaults.method_info_class, len);
handle_parent:
mono_class_setup_vtable (klass);
+ if (klass->exception_type != MONO_EXCEPTION_NONE)
+ mono_raise_exception (mono_class_get_exception_for_failure
(klass));
+
iter = NULL;
while ((method = mono_class_get_methods (klass, &iter))) {
match = 0;
@@ -3320,6 +3332,9 @@
klass = startklass = mono_class_from_mono_type (type->type);
refklass = mono_class_from_mono_type (reftype->type);
+ if (klass->exception_type != MONO_EXCEPTION_NONE)
+ mono_raise_exception (mono_class_get_exception_for_failure
(klass));
+
if (!System_Reflection_ConstructorInfo)
System_Reflection_ConstructorInfo = mono_class_from_name (
mono_defaults.corlib, "System.Reflection",
"ConstructorInfo");
@@ -3423,6 +3438,14 @@
res = mono_array_new (domain, System_Reflection_PropertyInfo, len);
handle_parent:
mono_class_setup_vtable (klass);
+ if (klass->exception_type != MONO_EXCEPTION_NONE) {
+ if (method_slots != method_slots_default)
+ g_free (method_slots);
+ if (name != NULL)
+ g_free (propname);
+ mono_raise_exception (mono_class_get_exception_for_failure
(klass));
+ }
+
iter = NULL;
while ((prop = mono_class_get_properties (klass, &iter))) {
match = 0;
@@ -3519,6 +3542,9 @@
domain = mono_object_domain (type);
handle_parent:
+ if (klass->exception_type != MONO_EXCEPTION_NONE)
+ mono_raise_exception (mono_class_get_exception_for_failure
(klass));
+
iter = NULL;
while ((event = mono_class_get_events (klass, &iter))) {
if (strcmp (event->name, event_name))
@@ -3580,6 +3606,9 @@
len = 2;
res = mono_array_new (domain, System_Reflection_EventInfo, len);
handle_parent:
+ if (klass->exception_type != MONO_EXCEPTION_NONE)
+ mono_raise_exception (mono_class_get_exception_for_failure
(klass));
+
iter = NULL;
while ((event = mono_class_get_events (klass, &iter))) {
match = 0;
@@ -3660,6 +3689,9 @@
str = mono_string_to_utf8 (name);
handle_parent:
+ if (klass->exception_type != MONO_EXCEPTION_NONE)
+ mono_raise_exception (mono_class_get_exception_for_failure
(klass));
+
/*
* If a nested type is generic, return its generic type definition.
* Note that this means that the return value is essentially a
@@ -3712,6 +3744,8 @@
if (type->type->byref)
return mono_array_new (domain, mono_defaults.monotype_class, 0);
klass = mono_class_from_mono_type (type->type);
+ if (klass->exception_type != MONO_EXCEPTION_NONE)
+ mono_raise_exception (mono_class_get_exception_for_failure
(klass));
/*
* If a nested type is generic, return its generic type definition.
Modified: trunk/mono/mono/metadata/loader.c
===================================================================
--- trunk/mono/mono/metadata/loader.c 2007-07-19 15:35:28 UTC (rev 82293)
+++ trunk/mono/mono/metadata/loader.c 2007-07-19 15:42:53 UTC (rev 82294)
@@ -100,7 +100,7 @@
return;
error = g_new0 (MonoLoaderError, 1);
- error->kind = MONO_LOADER_ERROR_ASSEMBLY;
+ error->exception_type = MONO_EXCEPTION_FILE_NOT_FOUND;
error->assembly_name = g_strdup (assembly_name);
error->ref_only = ref_only;
@@ -131,7 +131,7 @@
return;
error = g_new0 (MonoLoaderError, 1);
- error->kind = MONO_LOADER_ERROR_TYPE;
+ error->exception_type = MONO_EXCEPTION_TYPE_LOAD;
error->class_name = g_strdup (class_name);
error->assembly_name = g_strdup (assembly_name);
@@ -161,7 +161,7 @@
return;
error = g_new0 (MonoLoaderError, 1);
- error->kind = MONO_LOADER_ERROR_METHOD;
+ error->exception_type = MONO_EXCEPTION_MISSING_METHOD;
error->class_name = g_strdup (class_name);
error->member_name = member_name;
@@ -184,7 +184,7 @@
return;
error = g_new0 (MonoLoaderError, 1);
- error->kind = MONO_LOADER_ERROR_FIELD;
+ error->exception_type = MONO_EXCEPTION_MISSING_FIELD;
error->klass = klass;
error->member_name = member_name;
@@ -235,8 +235,8 @@
{
MonoException *ex = NULL;
- switch (error->kind) {
- case MONO_LOADER_ERROR_TYPE: {
+ switch (error->exception_type) {
+ case MONO_EXCEPTION_TYPE_LOAD: {
char *cname = g_strdup (error->class_name);
char *aname = g_strdup (error->assembly_name);
MonoString *class_name;
@@ -250,7 +250,7 @@
g_free (aname);
break;
}
- case MONO_LOADER_ERROR_METHOD: {
+ case MONO_EXCEPTION_MISSING_METHOD: {
char *cname = g_strdup (error->class_name);
char *aname = g_strdup (error->member_name);
@@ -261,7 +261,7 @@
break;
}
- case MONO_LOADER_ERROR_FIELD: {
+ case MONO_EXCEPTION_MISSING_FIELD: {
char *cnspace = g_strdup (*error->klass->name_space ?
error->klass->name_space : "");
char *cname = g_strdup (error->klass->name);
char *cmembername = g_strdup (error->member_name);
@@ -278,7 +278,7 @@
break;
}
- case MONO_LOADER_ERROR_ASSEMBLY: {
+ case MONO_EXCEPTION_FILE_NOT_FOUND: {
char *msg;
char *filename;
Modified: trunk/mono/mono/mini/ChangeLog
===================================================================
--- trunk/mono/mono/mini/ChangeLog 2007-07-19 15:35:28 UTC (rev 82293)
+++ trunk/mono/mono/mini/ChangeLog 2007-07-19 15:42:53 UTC (rev 82294)
@@ -1,3 +1,8 @@
+2007-07-19 Mark Probst <[EMAIL PROTECTED]>
+
+ * mini.c: Removed the MonoLoaderErrorKind enum and replaced it
+ with the MONO_EXCEPTION_ defines.
+
2007-07-17 Zoltan Varga <[EMAIL PROTECTED]>
* mini-amd64.c (mono_arch_find_imt_method): Handle mov reg,IMM64 case.
Fixes
Modified: trunk/mono/mono/mini/mini.c
===================================================================
--- trunk/mono/mono/mini/mini.c 2007-07-19 15:35:28 UTC (rev 82293)
+++ trunk/mono/mono/mini/mini.c 2007-07-19 15:42:53 UTC (rev 82294)
@@ -10724,7 +10724,8 @@
case MONO_EXCEPTION_NONE: break;
case MONO_EXCEPTION_TYPE_LOAD:
case MONO_EXCEPTION_MISSING_FIELD:
- case MONO_EXCEPTION_MISSING_METHOD: {
+ case MONO_EXCEPTION_MISSING_METHOD:
+ case MONO_EXCEPTION_FILE_NOT_FOUND: {
/* Throw a type load exception if needed */
MonoLoaderError *error = mono_loader_get_last_error ();
MonoException *ex;
@@ -10741,6 +10742,8 @@
ex = mono_exception_from_name_msg
(mono_defaults.corlib, "System", "MissingMethodException",
cfg->exception_message);
else if (cfg->exception_type ==
MONO_EXCEPTION_TYPE_LOAD)
ex = mono_exception_from_name_msg
(mono_defaults.corlib, "System", "TypeLoadException", cfg->exception_message);
+ else if (cfg->exception_type ==
MONO_EXCEPTION_FILE_NOT_FOUND)
+ ex = mono_exception_from_name_msg
(mono_defaults.corlib, "System", "FileNotFoundException",
cfg->exception_message);
else
g_assert_not_reached ();
}
Modified: trunk/mono/mono/tests/ChangeLog
===================================================================
--- trunk/mono/mono/tests/ChangeLog 2007-07-19 15:35:28 UTC (rev 82293)
+++ trunk/mono/mono/tests/ChangeLog 2007-07-19 15:42:53 UTC (rev 82294)
@@ -1,3 +1,8 @@
+2007-07-19 Mark Probst <[EMAIL PROTECTED]>
+
+ * Makefile.am (test-bug-81691), bug-81691.cs, bug-81691-a.cs,
+ bug-81691-b.cs: Test for bug #81691.
+
2007-07-11 Raja R Harinath <[EMAIL PROTECTED]>
* Makefile.am (bug-81673.exe): Look for bug-81673.cs in $(srcdir).
Modified: trunk/mono/mono/tests/Makefile.am
===================================================================
--- trunk/mono/mono/tests/Makefile.am 2007-07-19 15:35:28 UTC (rev 82293)
+++ trunk/mono/mono/tests/Makefile.am 2007-07-19 15:42:53 UTC (rev 82294)
@@ -319,13 +319,13 @@
# mkbundle works on ppc, but the pkg-config POC doesn't when run with make test
if POWERPC
-test: testjit test-type-load test-inline-call-stack test-bug-80307
test-bug-81673
+test: testjit test-type-load test-inline-call-stack test-bug-80307
test-bug-81673 test-bug-81691
else
# Can't use mkbundle on win32 since there is no static build there
if PLATFORM_WIN32
-test: testjit test-type-load test-inline-call-stack test-bug-80307
test-bug-81673
+test: testjit test-type-load test-inline-call-stack test-bug-80307
test-bug-81673 test-bug-81691
else
-test: testjit testbundle test-type-load test-inline-call-stack
test-iomap-regression test-bug-80307 test-bug-81673
+test: testjit testbundle test-type-load test-inline-call-stack
test-iomap-regression test-bug-80307 test-bug-81673 test-bug-81691
endif
endif
@@ -515,8 +515,18 @@
$(MCS) -define:WITH_STOP -target:library -out:bug-81673-interface.dll
$(srcdir)/bug-81673-interface.cs
test-bug-81673 : bug-81673.exe bug-81673-interface.dll
- $(RUNTIME) --optimize=-inline bug-81673.exe
+ $(RUNTIME) bug-81673.exe
+EXTRA_DIST += bug-81691.cs bug-81691-a.cs bug-81691-b.cs
+bug-81691.exe bug-81691-b.dll: $(srcdir)/bug-81691.cs $(srcdir)/bug-81691-a.cs
$(srcdir)/bug-81691-b.cs
+ $(GMCS) -target:library -out:bug-81691-a.dll $(srcdir)/bug-81691-a.cs
+ $(GMCS) -target:library -out:bug-81691-b.dll -r:bug-81691-a.dll
$(srcdir)/bug-81691-b.cs
+ $(GMCS) -r:bug-81691-b.dll $(srcdir)/bug-81691.cs
+ rm bug-81691-a.dll
+
+test-bug-81691 : bug-81691.exe bug-81691-b.dll
+ $(RUNTIME) bug-81691.exe
+
# Useful if mono is compiled with --enable-shared=no
patch-libtool:
cp "../../libtool" .
Added: trunk/mono/mono/tests/bug-81691-a.cs
===================================================================
--- trunk/mono/mono/tests/bug-81691-a.cs 2007-07-19 15:35:28 UTC (rev
82293)
+++ trunk/mono/mono/tests/bug-81691-a.cs 2007-07-19 15:42:53 UTC (rev
82294)
@@ -0,0 +1,6 @@
+namespace NS.A
+{
+ public class TestA
+ {
+ }
+}
Added: trunk/mono/mono/tests/bug-81691-b.cs
===================================================================
--- trunk/mono/mono/tests/bug-81691-b.cs 2007-07-19 15:35:28 UTC (rev
82293)
+++ trunk/mono/mono/tests/bug-81691-b.cs 2007-07-19 15:42:53 UTC (rev
82294)
@@ -0,0 +1,13 @@
+namespace NS.B
+{
+ public class TestB
+ {
+ private static readonly NS.A.TestA testb = new NS.A.TestA ();
+
+ public TestB ()
+ {
+ if (testb == null) {
+ }
+ }
+ }
+}
Added: trunk/mono/mono/tests/bug-81691.cs
===================================================================
--- trunk/mono/mono/tests/bug-81691.cs 2007-07-19 15:35:28 UTC (rev 82293)
+++ trunk/mono/mono/tests/bug-81691.cs 2007-07-19 15:42:53 UTC (rev 82294)
@@ -0,0 +1,28 @@
+using System;
+using System.IO;
+using System.Reflection;
+
+class Program
+{
+ static int Main ()
+ {
+ string assemblyFile = Path.Combine
(AppDomain.CurrentDomain.BaseDirectory, "bug-81691-b.dll");
+ Assembly assembly = Assembly.LoadFile (assemblyFile);
+ int i;
+ int numExceptions = 0;
+
+ for (i = 0; i < 100000; ++i) {
+ try {
+ Type type = assembly.GetType ("NS.B.TestB");
+ FieldInfo field =type.GetField ("testb",
BindingFlags.NonPublic | BindingFlags.Static);
+ if (field.FieldType == null)
+ return 1;
+ } catch (TypeLoadException ex) {
+ ++numExceptions;
+ }
+ }
+ if (numExceptions == 100000)
+ return 0;
+ return 1;
+ }
+}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches