-
Notifications
You must be signed in to change notification settings - Fork 751
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
Conversation
@dmitriyse in case you wanted to review. |
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Expanded it to include #408 as well since its related. |
Marshal.Copy(bStr, 0, mem, bStr.Length); | ||
} | ||
catch (Exception) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no exception throwing here?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Useful resources https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.icustommarshaler(v=vs.110).aspx https://limbioliong.wordpress.com/2013/11/03/understanding-custom-marshaling-part-1/ https://github.com/mono/mono/blob/master/mcs/class/Mono.Posix/Mono.Unix/UnixMarshal.cs http://stackoverflow.com/a/33514037/5208670
Refactor PyString_FromStringAndSize Link explains why `MarshalAs(UnmanagedType.LPWStr)` or `CharSet.Unicode` don't work http://stackoverflow.com/a/25128147/5208670
Its redundant with PyUnicode_AsUnicode now that the signature is fixed between UCS2/UCS4. Apply char conversion that work on both UCS2/UCS4
This won't change during runtime.
84209c6
to
78939c5
Compare
I'm fine with this pull request but it is a little above my knowledge. |
@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?
|
i dont understand you question |
I missed the headers of commits in this PR, e.g.:
vmuriart@e487076
I'm not sure if there is any better way to expose these headers during PR?
…On Sat, Mar 18, 2017, 11:58 AM Victor Uriarte ***@***.***> wrote:
i dont understand you question
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#407 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHgZ5W9FxuZc5GcKb49fmp_C1kYQdXZFks5rnA1MgaJpZM4MMNTo>
.
|
Ok, now I see. So by default the descriptions are collapsed. Thank you for the suggestion. |
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
.