-
Notifications
You must be signed in to change notification settings - Fork 899
git_strarray marshaling improvements #773
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
|
||
for (int i = 0; i < count; i++) | ||
{ | ||
toReturn[i] = EncodingMarshaler.FromNative(Encoding.UTF8, Marshal.ReadIntPtr(Strings, i * IntPtr.Size)); |
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.
Couldn't we somehow leverage LaxUtf8Marshaler.FromNative()
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.
I can do that. I think at the time I was writing it I felt like it was weird to mix the policy of the marshaler itself (its "Lax-ness") with what I was doing here, which doesn't have anything to do with the marshaler's policy other than its choice of an encoding.
What's up with Travis? |
Dead: http://status.travis-ci.com/ On Tue, Jun 24, 2014 at 6:46 PM, Philip Kelley [email protected]
|
👍 for me. @Therzok How do you like this? |
finally | ||
{ | ||
array.Dispose(); | ||
} |
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.
An using
could be used here.
Other than using |
pointers[i] = marshaler(item); | ||
} | ||
|
||
GitStrArrayManaged toReturn = new GitStrArrayManaged(); |
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.
use var toReturn = new GitStrArrayManaged()
?
I think I missed a few var/using usages towards the end, just because I didn't want to spam them all. I'm really happy to merge this once those nitpicks are done. (Clean code is even better than better code. 👍) |
switching the try\catch to the
|
Fixed the |
Oh, I see the try/finally thing now. We're just allocating the memory there then we're passing the structure. Oh well, try/finally it is then. |
Thanks guys for the fixups. Yes, we can't make use of "using" syntax here which is unfortunate. It's the price of using structs, but I think we really have to have the structs because of the way that GitStrArray and friends end up embedded inside of other types like I didn't know we had standardized on 'var' syntax everywhere. I'll keep that in mind for future changes. The |
Actually, it's not var everywhere. If the type is known on the right hand side, we use var. Otherwise, we don't. var l = new List<int>();
var c = (int)count;
MyStronglyType mst = Build(); |
I noticed that
GitStrArrayOut
'sDispose
method was implemented incorrectly -- fixing that led me down this path towards trying to unify ourGitStrArray
types and clean things up. We still end up with two different types,GitStrArrayManaged
andGitStrArrayNative
, which correspond to the old In and Out types, respectively. But this PR switches to structs, gives a bit more code re-use, fixes some bugs, and manages to eliminate theUnSafeNativeMethods
class entirely!I'm eager to get the Mono results...