Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ public void CreateMarshalFromJniMethodExpression_FuncIJavaObject ()
JavaObject __mret;
ExportTest __this_val;
JniObjectReference __mret_ref;
IntPtr __mret_handle;
IntPtr __mret_rtn;

__envp = new JniTransition(__jnienv);
Expand All @@ -468,7 +467,6 @@ public void CreateMarshalFromJniMethodExpression_FuncIJavaObject ()
{
return __mret_ref = __mret.PeerReference;
}
__mret_handle = __mret_ref.Handle;
__mret_rtn = References.NewReturnToJniRef(__mret_ref);
return __mret_rtn;
}
Expand All @@ -479,7 +477,6 @@ public void CreateMarshalFromJniMethodExpression_FuncIJavaObject ()
}
finally
{
JniObjectReference.Dispose(__mret_ref);
__envp.Dispose();
}
}");
Expand Down
22 changes: 13 additions & 9 deletions src/Java.Interop/Java.Interop/JniRuntime.JniValueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,16 @@ public override void DestroyGenericArgumentState (IJavaPeerable value, ref JniVa
}

public override Expression CreateParameterFromManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue, ParameterAttributes synchronize)
{
var r = CreateIntermediaryExpressionFromManagedExpression (context, sourceValue);
var h = Expression.Variable (typeof (IntPtr), sourceValue.Name + "_handle");
context.LocalVariables.Add (h);
context.CreationStatements.Add (Expression.Assign (h, Expression.Property (r, "Handle")));

return h;
}

Expression CreateIntermediaryExpressionFromManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue)
{
var r = Expression.Variable (typeof (JniObjectReference), sourceValue.Name + "_ref");
context.LocalVariables.Add (r);
Expand All @@ -598,24 +608,18 @@ public override Expression CreateParameterFromManagedExpression (JniValueMarshal
test: Expression.Equal (Expression.Constant (null), sourceValue),
ifTrue: Expression.Assign (r, Expression.New (typeof (JniObjectReference))),
ifFalse: Expression.Assign (r, Expression.Property (sourceValue, "PeerReference"))));
context.CleanupStatements.Add (DisposeObjectReference (r));

var h = Expression.Variable (typeof (IntPtr), sourceValue + "_handle");
context.LocalVariables.Add (h);
context.CreationStatements.Add (Expression.Assign (h, Expression.Property (r, "Handle")));
return h;
return r;
}

public override Expression CreateReturnValueFromManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue)
{
CreateParameterFromManagedExpression (context, sourceValue, 0);
var r = context.LocalVariables [sourceValue + "_ref"];
return ReturnObjectReferenceToJni (context, sourceValue.Name, r);
return ReturnObjectReferenceToJni (context, sourceValue.Name, CreateIntermediaryExpressionFromManagedExpression (context, sourceValue));
}

public override Expression CreateParameterToManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue, ParameterAttributes synchronize, Type targetType)
{
var r = Expression.Variable (targetType, sourceValue + "_val");
var r = Expression.Variable (targetType, sourceValue.Name + "_val");
context.LocalVariables.Add (r);
context.CreationStatements.Add (
Expression.Assign (r,
Expand Down
2 changes: 1 addition & 1 deletion src/Java.Interop/Java.Interop/JniValueMarshaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ Expression CreateSelf (JniValueMarshalerContext context, ParameterExpression sou
public virtual Expression CreateReturnValueFromManagedExpression (JniValueMarshalerContext context, ParameterExpression sourceValue)
{
CreateParameterFromManagedExpression (context, sourceValue, 0);
var s = context.LocalVariables [sourceValue + "_state"];
var s = context.LocalVariables [sourceValue.Name + "_state"];
return ReturnObjectReferenceToJni (context, sourceValue.Name, Expression.Property (s, "ReferenceValue"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,6 @@ protected override string GetExpectedReturnValueFromManagedExpression (string jv
JniRuntime {jvm};
IJavaPeerable {value};
JniObjectReference {value}_ref;
IntPtr {value}_handle;
IntPtr {value}_rtn;

try
Expand All @@ -604,13 +603,12 @@ protected override string GetExpectedReturnValueFromManagedExpression (string jv
{{
return {value}_ref = {value}.PeerReference;
}}
{value}_handle = {value}_ref.Handle;
{value}_rtn = References.NewReturnToJniRef({value}_ref);
return {pret.Name};
}}
finally
{{
JniObjectReference.Dispose({value}_ref);
default(void);
}}
}}";
}
Expand Down