Skip to content

Commit

Permalink
Backport from trunk/62369
Browse files Browse the repository at this point in the history
svn path=/branches/mono-1-1-16/mcs/; revision=62405
  • Loading branch information
migueldeicaza committed Jul 10, 2006
1 parent fda57d1 commit ec3870d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 6 deletions.
8 changes: 8 additions & 0 deletions mcs/class/corlib/System.Reflection.Emit/ChangeLog
@@ -1,3 +1,11 @@
2006-07-08 Zoltan Varga <vargaz@gmail.com>

* DynamicMethod.cs: Create all other DynamicMethod's referenced by
this method as well. Check for an empty method body.

* ILGenerator.cs (Emit): Handle DynamicMethod's which might not have a
declaring type.

2006-05-15 Zoltan Varga <vargaz@gmail.com>

* AssemblyBuilder.cs (MonoResource): Add a 'stream' field.
Expand Down
25 changes: 23 additions & 2 deletions mcs/class/corlib/System.Reflection.Emit/DynamicMethod.cs
Expand Up @@ -63,6 +63,7 @@ public sealed class DynamicMethod : MethodInfo {
private Delegate deleg;
private MonoMethod method;
private ParameterBuilder[] pinfo;
internal bool creating;

public DynamicMethod (string name, Type returnType, Type[] parameterTypes, Module m) : this (name, returnType, parameterTypes, m, false) {
}
Expand Down Expand Up @@ -110,8 +111,28 @@ public sealed class DynamicMethod : MethodInfo {

private void CreateDynMethod () {
if (mhandle.Value == IntPtr.Zero) {
if (ilgen != null)
ilgen.label_fixup ();
if (ilgen == null)
throw new InvalidOperationException ("Method '" + name + "' does not have a method body.");

ilgen.label_fixup ();

// Have to create all DynamicMethods referenced by this one
try {
// Used to avoid cycles
creating = true;
if (refs != null) {
for (int i = 0; i < refs.Length; ++i) {
if (refs [i] is DynamicMethod) {
DynamicMethod m = (DynamicMethod)refs [i];
if (!m.creating)
m.CreateDynMethod ();
}
}
}
} finally {
creating = false;
}

create_dynamic_method (this);
}
}
Expand Down
16 changes: 12 additions & 4 deletions mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs
Expand Up @@ -705,8 +705,12 @@ public virtual void Emit (OpCode opcode, MethodInfo method)
int token = token_gen.GetToken (method);
make_room (6);
ll_emit (opcode);
if (method.DeclaringType.Module == module)
add_token_fixup (method);
Type declaringType = method.DeclaringType;
// Might be a DynamicMethod with no declaring type
if (declaringType != null) {
if (declaringType.Module == module)
add_token_fixup (method);
}
emit_int (token);
if (method.ReturnType != void_type)
cur_stack ++;
Expand All @@ -719,8 +723,12 @@ private void Emit (OpCode opcode, MethodInfo method, int token)
{
make_room (6);
ll_emit (opcode);
if (method.DeclaringType.Module == module)
add_token_fixup (method);
// Might be a DynamicMethod with no declaring type
Type declaringType = method.DeclaringType;
if (declaringType != null) {
if (declaringType.Module == module)
add_token_fixup (method);
}
emit_int (token);
if (method.ReturnType != void_type)
cur_stack ++;
Expand Down

0 comments on commit ec3870d

Please sign in to comment.