Skip to content

Commit

Permalink
trim more stuff, dont delete refs for objects passed into methods ove…
Browse files Browse the repository at this point in the history
…rriden in the clr
  • Loading branch information
koush committed May 24, 2010
1 parent 9c4c411 commit 46e6360
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions java/lang/Object.cs
Expand Up @@ -56,6 +56,11 @@ void IJvmProxy.Init(JNIEnv env, JniLocalHandle obj)
env.DeleteLocalRef(obj);
}

void IJvmProxy.InitNoDelete(JNIEnv env, JniLocalHandle obj)
{
jvmHandle = env.NewGlobalRef(obj);
}

void IJvmProxy.Copy(JNIEnv env, JniGlobalHandle obj)
{
jvmHandle = obj;
Expand Down
5 changes: 5 additions & 0 deletions java/lang/Throwable.cs
Expand Up @@ -124,6 +124,11 @@ void IJvmProxy.Init(JNIEnv env, JniLocalHandle obj)
jvmHandle = env.NewGlobalRef(obj);
env.DeleteLocalRef(obj);
}

void IJvmProxy.InitNoDelete(JNIEnv env, JniLocalHandle obj)
{
jvmHandle = env.NewGlobalRef(obj);
}

void IJvmProxy.Copy(JNIEnv env, JniGlobalHandle obj)
{
Expand Down
2 changes: 2 additions & 0 deletions jni/IJvmProxy.cs
Expand Up @@ -33,6 +33,8 @@ public interface IJvmProxy : IObject

void Init(JNIEnv env, JniLocalHandle obj);

void InitNoDelete(JNIEnv env, JniLocalHandle obj);

void Copy(JNIEnv env, JniGlobalHandle obj);
}
}
2 changes: 0 additions & 2 deletions jni4net.n.androidmono.csproj
Expand Up @@ -138,7 +138,6 @@
<Compile Include="generated\java\util\Map.generated.cs" />
<Compile Include="generated\java\util\Properties.generated.cs" />
<Compile Include="generated\java\util\Set.generated.cs" />
<Compile Include="generated\java_\lang\IObject.generated.cs" />
<Compile Include="java\lang\Class.cs" />
<Compile Include="java\lang\Integer.cs" />
<Compile Include="java\lang\IObject.cs" />
Expand Down Expand Up @@ -166,7 +165,6 @@
<Compile Include="adaptors\Disposable.cs" />
<Compile Include="adaptors\Enumerator.cs" />
<Compile Include="AssemblyInf.cs" />
<Compile Include="Bridge.JVM.convertor.cs" />
<Compile Include="BridgeSetup.cs" />
<Compile Include="generated\java\io\ByteArrayInputStream.generated.cs" />
<Compile Include="generated\java\io\ByteArrayOutputStream.generated.cs" />
Expand Down
4 changes: 2 additions & 2 deletions utils/Convertor.J2C.strong.cs
Expand Up @@ -52,7 +52,7 @@ public static object StrongJ2CpUntyped(IntPtr ptr)
}
Class clazz = env.GetObjectClass(obj);
RegistryRecord record = Registry.GetJVMRecord(clazz);
return record.CreateCLRProxy(env, obj);
return record.CreateCLRProxyNoDelete(env, obj);
}

private class ConstructerHelper<T>
Expand All @@ -73,7 +73,7 @@ public static TRes StrongJ2CpTyped<TRes>(IntPtr ptr)
{
var env = JNIEnv.ThreadEnv;
var ret = ConstructerHelper<TRes>.Create(env);
(ret as IJvmProxy).Init(env, ptr);
(ret as IJvmProxy).InitNoDelete(env, ptr);
return ret;
}

Expand Down
7 changes: 7 additions & 0 deletions utils/RegistryRecord.cs
Expand Up @@ -70,6 +70,13 @@ internal IJvmProxy CreateCLRProxy(JNIEnv env, JniLocalHandle obj)
proxy.Init(env, obj);
return proxy;
}

internal IJvmProxy CreateCLRProxyNoDelete(JNIEnv env, JniLocalHandle obj)
{
IJvmProxy proxy = CLRConstructor.CreateProxy(env);
proxy.InitNoDelete(env, obj);
return proxy;
}

internal IJvmProxy CopyCLRProxy(JNIEnv env, JniGlobalHandle obj)
{
Expand Down

0 comments on commit 46e6360

Please sign in to comment.