Skip to content

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

Merged
merged 1 commit into from
Jun 25, 2014
Merged

git_strarray marshaling improvements #773

merged 1 commit into from
Jun 25, 2014

Conversation

phkelley
Copy link
Member

I noticed that GitStrArrayOut's Dispose method was implemented incorrectly -- fixing that led me down this path towards trying to unify our GitStrArray types and clean things up. We still end up with two different types, GitStrArrayManaged and GitStrArrayNative, 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 the UnSafeNativeMethods class entirely!

I'm eager to get the Mono results...


for (int i = 0; i < count; i++)
{
toReturn[i] = EncodingMarshaler.FromNative(Encoding.UTF8, Marshal.ReadIntPtr(Strings, i * IntPtr.Size));
Copy link
Member

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?

Copy link
Member Author

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.

@phkelley
Copy link
Member Author

What's up with Travis?

@ethomson
Copy link
Member

Dead: http://status.travis-ci.com/

On Tue, Jun 24, 2014 at 6:46 PM, Philip Kelley [email protected]
wrote:

What's up with Travis?


Reply to this email directly or view it on GitHub
#773 (comment).

@nulltoken
Copy link
Member

👍 for me.

@Therzok How do you like this?

finally
{
array.Dispose();
}
Copy link
Member

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.

@Therzok
Copy link
Member

Therzok commented Jun 25, 2014

Other than using using wherever appropriate, this looks awesome!

pointers[i] = marshaler(item);
}

GitStrArrayManaged toReturn = new GitStrArrayManaged();
Copy link
Member

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() ?

@Therzok
Copy link
Member

Therzok commented Jun 25, 2014

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. 👍)

@nulltoken
Copy link
Member

switching the try\catch to the using statement doesn't make the compiler happy 😿

error CS1655: Cannot pass fields of 'array' as a ref or out argument because it
is a 'using variable'
error CS1656: Cannot assign to 'array' because it is a 'using variable'

@nulltoken
Copy link
Member

Fixed the vars

@Therzok
Copy link
Member

Therzok commented Jun 25, 2014

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.

@phkelley
Copy link
Member Author

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 GitDiffOptions.

I didn't know we had standardized on 'var' syntax everywhere. I'll keep that in mind for future changes.

The Array = new GitStrArray(); lines are basically just a safety mechanism to protect against double-dispose being a double-free. They just set the Strings and Count members to zero so that on any re-run of the Dispose method, nothing happens. I agree that the caller should only ever call Dispose() once. Let me know what you think on that.

@nulltoken
Copy link
Member

I didn't know we had standardized on 'var' syntax everywhere. I'll keep that in mind for future changes.

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();

@nulltoken nulltoken merged commit 18c57ac into vNext Jun 25, 2014
@nulltoken nulltoken deleted the strarray branch June 25, 2014 14:05
@nulltoken
Copy link
Member

@phkelley 💟

@nulltoken nulltoken added this to the v0.19.0 milestone Aug 24, 2014
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.

4 participants