Switched to using SafeHandle for native code interrupt #297

Closed
itsff wants to merge 1 commits from fix/issue_295 into master
itsff commented 2016-12-22 22:08:51 -08:00 (Migrated from github.com)

This PR fixes issue #295

  • Created a new internal YGNodeHandle class extending SafeHandle.
  • YogaNode now stores a reference to YGNodeHandle.
  • Removed finalizer from YogaNode.
  • Pulling in System.Runtime.Handles 4.3.0.
This PR fixes issue #295 - Created a new internal YGNodeHandle class extending SafeHandle. - YogaNode now stores a reference to YGNodeHandle. - Removed finalizer from YogaNode. - Pulling in System.Runtime.Handles 4.3.0.
facebook-github-bot commented 2016-12-22 23:24:57 -08:00 (Migrated from github.com)

@splhack has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@splhack has imported this pull request. If you are a Facebook employee, you can view this diff [on Phabricator](https://phabricator.intern.facebook.com/D4365462).
woehrl01 (Migrated from github.com) requested changes 2016-12-23 01:08:48 -08:00
@@ -23,0 +37,4 @@
protected override bool ReleaseHandle()
{
Native.YGNodeFree(this.handle);
GC.KeepAlive(this);
woehrl01 (Migrated from github.com) commented 2016-12-22 22:13:50 -08:00

Out of curiosity, why do we need the GC.KeepAlive here?

Out of curiosity, why do we need the GC.KeepAlive here?
@@ -99,3 +121,3 @@
[DllImport(DllName)]
public static extern void YGNodeSetHasNewLayout(IntPtr node, [MarshalAs(UnmanagedType.I1)] bool hasNewLayout);
public static extern void YGNodeSetHasNewLayout(YGNodeHandle node, [MarshalAs(UnmanagedType.I1)] bool hasNewLayout);
woehrl01 (Migrated from github.com) commented 2016-12-22 22:12:54 -08:00

I think this must return only intptr as we don't own the underlying node here.

I think this must return only intptr as we don't own the underlying node here.
splhack (Migrated from github.com) reviewed 2016-12-23 07:55:40 -08:00
@@ -99,3 +121,3 @@
[DllImport(DllName)]
public static extern void YGNodeSetHasNewLayout(IntPtr node, [MarshalAs(UnmanagedType.I1)] bool hasNewLayout);
public static extern void YGNodeSetHasNewLayout(YGNodeHandle node, [MarshalAs(UnmanagedType.I1)] bool hasNewLayout);
splhack (Migrated from github.com) commented 2016-12-23 07:55:40 -08:00

I'll remove this declaration in merge commit since managed code doesn't use it

I'll remove this declaration in merge commit since managed code doesn't use it
itsff (Migrated from github.com) reviewed 2016-12-23 10:06:04 -08:00
@@ -99,3 +121,3 @@
[DllImport(DllName)]
public static extern void YGNodeSetHasNewLayout(IntPtr node, [MarshalAs(UnmanagedType.I1)] bool hasNewLayout);
public static extern void YGNodeSetHasNewLayout(YGNodeHandle node, [MarshalAs(UnmanagedType.I1)] bool hasNewLayout);
itsff (Migrated from github.com) commented 2016-12-23 10:06:04 -08:00

You guys beat me to it. Thank you for noticing this one (@woehrl01) and removing it (@splhack). It could have caused some confusion and lifetime problems. We should similarly remove YGNodeSetContext and YGNodeSetContext since this functionality is achieved by the YogaNode::Data property.

You guys beat me to it. Thank you for noticing this one (@woehrl01) and removing it (@splhack). It could have caused some confusion and lifetime problems. We should similarly remove `YGNodeSetContext` and `YGNodeSetContext` since this functionality is achieved by the `YogaNode::Data` property.
itsff (Migrated from github.com) reviewed 2016-12-23 10:06:59 -08:00
@@ -23,0 +37,4 @@
protected override bool ReleaseHandle()
{
Native.YGNodeFree(this.handle);
GC.KeepAlive(this);
itsff (Migrated from github.com) commented 2016-12-23 10:06:59 -08:00

Likely not necessary, but I wasn't sure of the implementation of the parent class. Shouldn't hurt.

Likely not necessary, but I wasn't sure of the implementation of the parent class. Shouldn't hurt.

Pull request closed

Sign in to join this conversation.
No description provided.