Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

2002-05-11 Dietmar Maurer <dietmar@ximian.com>

	* object.c (mono_runtime_class_init): make sure that we call all
	static class constructors.

svn path=/trunk/mono/; revision=4522
  • Loading branch information...
commit 2ab39a5f8f4e4d9bafa7df763b2c853b0f4438a3 1 parent 4ee685d
Dietmar Maurer authored
View
4 mono/metadata/ChangeLog
@@ -1,3 +1,7 @@
+2002-05-11 Dietmar Maurer <dietmar@ximian.com>
+
+ * object.c (mono_runtime_class_init): make sure that we call all
+ static class constructors.
Fri May 10 18:14:51 CEST 2002 Paolo Molaro <lupus@ximian.com>
View
2  mono/metadata/class.h
@@ -39,7 +39,7 @@ struct _MonoClass {
guint dummy : 1; /* temorary hack */
guint inited : 1;
-
+ guint runtime_inited : 1;
/* We use init_pending to detect cyclic calls to mono_class_init */
guint init_pending : 1;
View
12 mono/metadata/object.c
@@ -58,6 +58,14 @@ mono_runtime_class_init (MonoClass *klass)
{
int i;
+ if (klass->runtime_inited)
+ return;
+
+ if (klass->parent && !klass->parent->runtime_inited)
+ mono_runtime_class_init (klass->parent);
+
+ klass->runtime_inited = 1;
+
for (i = 0; i < klass->method.count; ++i) {
MonoMethod *method = klass->methods [i];
if ((method->flags & METHOD_ATTRIBUTE_SPECIAL_NAME) &&
@@ -66,6 +74,7 @@ mono_runtime_class_init (MonoClass *klass)
return;
}
}
+
/* No class constructor found */
}
@@ -250,7 +259,8 @@ mono_class_vtable (MonoDomain *domain, MonoClass *class)
mono_g_hash_table_insert (domain->class_vtable_hash, class, vt);
mono_domain_unlock (domain);
- mono_runtime_class_init (class);
+ if (!class->runtime_inited)
+ mono_runtime_class_init (class);
return vt;
}
View
3  mono/tests/Makefile.am
@@ -96,7 +96,8 @@ TESTSRC= \
nonvirt.cs \
largeexp.cs \
largeexp2.cs \
- marshalbyref1.cs
+ marshalbyref1.cs \
+ static-ctor.cs
TESTSI=$(TESTSRC:.cs=.exe)
View
33 mono/tests/static-ctor.cs
@@ -0,0 +1,33 @@
+using System;
+
+class X {
+ static X ()
+ {
+ test.global = 1;
+ }
+}
+
+class Y : X {
+}
+
+class Z : Y {
+ public Z ()
+ {
+ }
+}
+
+class test {
+ static public int global;
+
+ static int Main ()
+ {
+ Z z = new Z ();
+
+ if (global != 1){
+ Console.WriteLine ("Error");
+ return 1;
+ }
+ Console.WriteLine ("Ok");
+ return 0;
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.