8000 Decref the members of Runtime(split from #958) by amos402 · Pull Request #1019 · pythonnet/pythonnet · GitHub
[go: up one dir, main page]

Skip to content

Decref the members of Runtime(split from #958) #1019

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 22, 2020

Conversation

amos402
Copy link
Member
@amos402 amos402 commented Dec 18, 2019

What does this implement/fix? Explain your changes.

  • Add mechanism for calling XDecref and set member to null automately.
  • Unified the GetBuiltins method

Does this close any currently open issues?

...

Any other comments?

...

Checklist

Check all those that are applicable and complete.

  • Make sure to include one or more tests for your change
  • If an enhancement PR, please create docs and at best an example
  • Add yourself to AUTHORS
  • Updated the CHANGELOG

* Unified GetBuiltins method
@codecov-io
Copy link
codecov-io commented Dec 18, 2019

Codecov Report

Merging #1019 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1019   +/-   ##
=======================================
  Coverage   86.71%   86.71%           
=======================================
  Files           1        1           
  Lines         301      301           
=======================================
  Hits          261      261           
  Misses         40       40
Flag Coverage Δ
#setup_linux 65.44% <ø> (ø) ⬆️
#setup_windows 71.42% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab0cb02...1b257a5. Read the comment docs.

Copy link
Member
@lostmsu lostmsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to ignore the NITs if you wish.

@@ -393,6 +415,19 @@ internal static int AtExit()
return 0;
}

private static void SetPyMember(ref IntPtr obj, IntPtr value, Action onRelease)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: obj can be out IntPtr

/// </summary>
public void Add(IntPtr ob, Action onRelease)
{
_actions.Add(new KeyValuePair<IntPtr, Action>(ob, onRelease));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: use Tuple<T1, T2>, e.g. just _actions.Add((ob, onRelease))

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using Tuple? As my experience, with two elements cases, KeyValue would always faster than tuple(unless the struct is too big).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply for readability. This code is not a hot path, so a little performance difference hardly matters.
Also, once we retarget to newer framework, C# will use ValueTuple anyway.

Comment on lines +2014 to +2018
foreach (var item in _actions)
{
Runtime.XDecref(item.Key);
item.Value?.Invoke();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: use foreach(var (ob, onRelease) in _actions) (requires modification from previous comment).

@lostmsu lostmsu requested a review from filmor December 21, 2019 06:41
@filmor filmor merged commit 3b938a5 into pythonnet:master Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0