FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Refactor Managed-Native conversion - ICustomMarshaler by vmuriart · Pull Request #407 · pythonnet/pythonnet · GitHub

Refactor Managed-Native conversion - ICustomMarshaler - #407

Merged
vmuriart merged 8 commits into
pythonnet:masterfrom
vmuriart:custom_marshal
Feb 28, 2017
Merged

Refactor Managed-Native conversion - ICustomMarshaler#407
vmuriart merged 8 commits into
pythonnet:masterfrom
vmuriart:custom_marshal

Conversation

vmuriart commented Feb 26, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

What does this implement/fix? Explain your changes.

Refactors conversions from Managed to Native type using ICustomMarshaler's to handle the various conversions scenarios and manage releasing unmanaged memory.

Does this close any currently open issues?

#408

Any other comments?

This doesn't need to implement Native to Managed conversions as it's not needed for the purposes of the pr.

Copy link
Copy Markdown
Contributor Author

@dmitriyse in case you wanted to review.

codecov Bot commented Feb 26, 2017
edited
Loading

Copy link
Copy Markdown

Codecov Report

Merging #407 into master will decrease coverage by -0.24%.
The diff coverage is 51.42%.

@@            Coverage Diff             @@
##           master     #407      +/-   ##
==========================================
- Coverage   63.62%   63.38%   -0.24%     
==========================================
  Files          61       61              
  Lines        5264     5277      +13     
  Branches      861      863       +2     
==========================================
- Hits         3349     3345       -4     
- Misses       1698     1713      +15     
- Partials      217      219       +2
Flag Coverage Δ
#Embedded_Tests 33.05% <51.42%> (-0.17%)
#Python_Tests 59.95% <51.42%> (-0.18%)
#Setup_Linux 74.5% <51.42%> (ø)
#Setup_Windows 70.5% <51.42%> (ø)
Impacted Files Coverage Δ
src/runtime/debughelper.cs 0% <0%> (ø)
src/runtime/converter.cs 77.89% <100%> (ø)
src/runtime/runtime.cs 84.37% <100%> (+3.63%)
src/runtime/CustomMarshaler.cs 49.05% <49.05%> (ø)
src/runtime/interop36.cs

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 7dba617...78939c5. Read the comment docs.

Copy link
Copy Markdown
Contributor Author

Expanded it to include #408 as well since its related.

Marshal.Copy(bStr, 0, mem, bStr.Length);
}
catch (Exception)
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

no exception throwing here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

what you mean? like re-throwing the Exception? That part was meant to de-allocate the memory in case something goes wrong, otherwise keep it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

isn't failing on Marshal.Copy need to be thrown as Exception? If not, how is this handled later?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'll throw the exception again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Added the throw in the latest commit

return mem;
}

public static ICustomMarshaler GetInstance(string cookie)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What is the purpose of string cookie?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Its part of the implementation of the interface. On the link below scroll down to Implementing the GetInstance Method. For our use case we don't need the cookie though but left it since its part of the implementation.

https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.icustommarshaler(v=vs.110).aspx#Remarks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Our old monosupport actually was an ICustomMarshaler too but it depended on mono libraries to work. It also had the same signature, except it was called s

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

oh, i see on Mono: // The Utf32Marshaler was written Jonathan Pryor and has been placed in the PUBLIC DOMAIN.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@vmuriart so is custom marshalling dependent on COM interop now?

This static method is called by the common language runtime's COM interop layer to instantiate an instance of the custom marshaler.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

No. I think that line is in reference that the COM Interop layer can call the instance. Its probably related to the whole cookie thing in which the instance returned depends on which cookie is passed.

den-run-ai Feb 28, 2017
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why is previous Mono implemented Marshalled string not a null-terminating like you added here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

because it didn't do the marshal at all, it passed it mono to do it. Mono itself then did it here

Copy link
Copy Markdown
Contributor

I'm fine with this pull request but it is a little above my knowledge.

vmuriart merged commit 01a35cb into pythonnet:master Feb 28, 2017
vmuriart deleted the custom_marshal branch February 28, 2017 03:48

Copy link
Copy Markdown
Contributor

@vmuriart somehow I completely missed the whole point of this PR. Do you know why I did not see your PR description while reviewing on github?

Add ICustomMarshaler Utf8Marshaler
Refactor PyString_FromStringAndSize
Link explains why MarshalAs(UnmanagedType.LPWStr) or CharSet.Unicode don't work

http://stackoverflow.com/a/25128147/5208670

Copy link
Copy Markdown
Contributor Author

i dont understand you question

den-run-ai commented Mar 18, 2017 via email

Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Contributor Author

Did you try the commit tab?

Copy link
Copy Markdown
Contributor

Ok, now I see. So by default the descriptions are collapsed. Thank you for the suggestion.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

2 participants


Back | FazBrowse Home | New Git URL