Skip to content
This repository was archived by the owner on Nov 13, 2026. It is now read-only.

Implement PalGetModuleFileName for Unix - #1004

Merged
janvorli merged 1 commit into
dotnet:masterfrom
janvorli:pal-get-module-filename
Mar 12, 2016
Merged

janvorli merged 1 commit into
dotnet:masterfrom
janvorli:pal-get-module-filename

Conversation

@janvorli

Copy link
Copy Markdown
Member

This change implements PalGetModuleFileName for Unix. Since the module name
passed to us is a utf-8 string, I have modified the signature of the function
to use TCHAR and then modified managed RhGetModuleFileName interop signature
to use byte* for Unix instead of char*. And I have also modified the caller
of this function, the TryGetFullPathToApplicationModule, to perform
conversion of that to .NET string.
I have also modified the RhConfig::GetConfigPath so that it works on Unix too now that
it can extract the module path.

@jkotas

jkotas commented Mar 11, 2016

Copy link
Copy Markdown
Member

@dotnet-bot test this please

int numUtf8Chars = RuntimeImports.RhGetModuleFileName(moduleBase, out pModuleNameUtf8);
// Number of UTF-16 chars is always less than or equal to the number of UTF-8 ones,
char* pModuleName = stackalloc char[numUtf8Chars];
int numChars = System.Text.Encoding.UTF8.GetChars(pModuleNameUtf8, numUtf8Chars, pModuleName, numUtf8Chars);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should rather be:

return System.Text.Encoding.UTF8.GetString((byte*)pModuleNameUtf8, numUtf8Chars);

@jkotas

jkotas commented Mar 11, 2016

Copy link
Copy Markdown
Member

LGTM modulo comment

This change implements PalGetModuleFileName for Unix. Since the module name
passed to us is a utf-8 string, I have modified the signature of the function
to use TCHAR and then modified managed RhGetModuleFileName interop signature
to use byte* for Unix instead of char*. And I have also modified the called
of this function, the TryGetFullPathToApplicationModule, to perform
conversion of that to regular string.
@janvorli
janvorli force-pushed the pal-get-module-filename branch from b31496f to 096c82d Compare March 11, 2016 17:45
@janvorli

Copy link
Copy Markdown
Member Author

@dotnet-bot test OSX Debug please

janvorli added a commit that referenced this pull request Mar 12, 2016
Implement PalGetModuleFileName for Unix
@janvorli
janvorli merged commit e2d9b48 into dotnet:master Mar 12, 2016
@janvorli
janvorli deleted the pal-get-module-filename branch March 12, 2016 00:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants