Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix illegal delegate usage#1328

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

BadSingleton
Copy link
Contributor

@BadSingletonBadSingleton commentedDec 17, 2020
edited
Loading

What does this implement/fix? Explain your changes.

Cache the delegates to native code we've created so that when we need to
call that delegate, we don't ask for a delegate from a native pointer
(that is a delegate to managed code.)

Does this close any currently open issues?

This fixes issue#1323 .

Any other comments?

This is needed in order for#1287 to pass the domain reload tests on Mono.

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 toAUTHORS
  • Updated theCHANGELOG

Cache the delegates to native code we've created so that when we need tocall that delegate, we don't ask for a delegate from a native pointer(that is a delegate to managed code.)
@BadSingleton
Copy link
ContributorAuthor

Test failures are the same as the ones in the current master:https://github.com/pythonnet/pythonnet/runs/1571830014

if (!Interop.allocatedThunks.TryGetValue(fp, out d))
{
// Use Marshal.GetDelegateForFunctionPointer<> directly after upgrade the framework
d = Marshal.GetDelegateForFunctionPointer(fp, typeof(T));
Copy link
Member

Choose a reason for hiding this comment

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

Can you also apply the comment here? The generic function was introduced in .NET 4.5.1.

BadSingleton reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

Actually, maybe just remove the comment. You are not writing this intoallocatedThunks right now, btw.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yes, I don't cache these because they truly point to unmanaged code. We should only cache the function pointers to managed code.

// We don't cache this delegate because this is a pure delegate ot unmanaged.
d = Marshal.GetDelegateForFunctionPointer<T>(fp);
}
return (T)d;
Copy link
Contributor

Choose a reason for hiding this comment

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

You'd save a couple instructions with:

Delegate d; // no initif (trygetvalue(out d)) {  return (T)d;} else {  return Marshal.GetDelegate...(); // no cast}

Comment on lines +45 to +46
Delegate d = null;
if (!Interop.allocatedThunks.TryGetValue(fp, out d))
Copy link
Member

@lostmsulostmsuDec 18, 2020
edited
Loading

Choose a reason for hiding this comment

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

NIT: you don't need to assign an initial value tod. You could also doTryGetValue(fp, out var d).

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@benoithudsonbenoithudsonbenoithudson left review comments

@lostmsulostmsulostmsu approved these changes

@filmorfilmorAwaiting requested review from filmor

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@BadSingleton@filmor@lostmsu@benoithudson

[8]ページ先頭

©2009-2025 Movatter.jp