Skip to content

Extend RepositoryOptions to accept path to alternate System and Global config files #160

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

Closed
wants to merge 1 commit into from
Closed

Extend RepositoryOptions to accept path to alternate System and Global config files #160

wants to merge 1 commit into from

Conversation

nulltoken
Copy link
Member

No description provided.

@nulltoken
Copy link
Member Author

@tclem, @xpaulbettsx , @haacked , @aroben, @carlosmn please review.

public static extern int git_config_add_file_ondisk(
ConfigurationSafeHandle cfg,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path,
IntPtr priority);
Copy link
Member

Choose a reason for hiding this comment

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

Why is this a pointer? The function expects an int.

Copy link
Member Author

Choose a reason for hiding this comment

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

int is either 4 bytes on x86 or 8 bytes on amd64.
IntPtr has its size aligned with the architecture and thus matches the int size.

I know, it's far from being explicit, but I haven't found a better alternative yet :)

Copy link
Member

Choose a reason for hiding this comment

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

I feel like we've been through this before... An int is 32-bits in C, be it a 32-bit or 64-bit machine. And MSDN tells me this is also the case with C#'s int type. An IntPtr will be the size of a pointer in the machine, which is not the same as an int in 64-bit processors, which means you'd be passing a variable with the wrong size. Here it's not that bad because it'd be at the top of the stack, so the other parameters would still be in the right place, but I'm not sure we'd end up reading the lower bytes of the argument (in amd64 more args get passed through registers, so this might end up working because of that).

There's also ints being used all over NativeMethods.cs where we want an int, and it seems to work just fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

ZOMG! You're right! Thank you for pointing at this mistake. The issue lies with longs, not ints.

And we might have already discussed this while you were implementing the retrieval of 64bits wide entries from the config.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I thought you might have been thinking about longs after I posted. It's all a mess, but ints are probably the most reliable datatype you can have.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks again for watching my back!
On a less positive note, this also means I have to review all the potentially wrongly chosen IntPtr in the NativeMethods type :)

Copy link
Member Author

Choose a reason for hiding this comment

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

@carlosmn Fixed! I also fixed some other "wronglies" in 0690be7

@nulltoken
Copy link
Member Author

Merged in vNext

@nulltoken nulltoken closed this May 26, 2012
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.

3 participants