Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Refactor Managed-Native conversion - ICustomMarshaler #407

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 8 commits into from
Feb 28, 2017

Conversation

vmuriart
Copy link
Contributor

@vmuriart vmuriart commented Feb 26, 2017

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.

@vmuriart
Copy link
Contributor Author

@dmitriyse in case you wanted to review.

@codecov
Copy link

codecov bot commented Feb 26, 2017

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.

@vmuriart
Copy link
Contributor Author

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

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

Choose a reason for hiding this comment

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

no exception throwing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll throw the exception again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the throw in the latest commit

return mem;
}

public static ICustomMarshaler GetInstance(string cookie)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of string cookie?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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
Contributor Author

Choose a reason for hiding this comment

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

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
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@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
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

@den-run-ai den-run-ai Feb 28, 2017

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

@den-run-ai
Copy link
Contributor

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

@vmuriart vmuriart merged commit 01a35cb into pythonnet:master Feb 28, 2017
@vmuriart vmuriart deleted the custom_marshal branch February 28, 2017 03:48
@den-run-ai
Copy link
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

@vmuriart
Copy link
Contributor Author

i dont understand you question

@den-run-ai
Copy link
Contributor

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

@vmuriart
Copy link
Contributor Author

Did you try the commit tab?

image

@den-run-ai
Copy link
Contributor

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

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