Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Use SString type - PathString for path allocations in binder. #1589

Merged
merged 2 commits into from
Sep 28, 2015

Conversation

Priya91
Copy link

@Priya91 Priya91 commented Sep 18, 2015

@@ -65,8 +65,11 @@ namespace BINDER_SPACE
IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BUFFER_OVERFLOW));
}

IF_FAIL_GO(StringCbCopy(szPath, sizeof(szPath), pszName));

WCHAR * szPath = szPathString.OpenUnicodeBuffer(MAX_LONGPATH);
Copy link
Member

Choose a reason for hiding this comment

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

The point of using variable size optimized buffer class is that we should be allocating only what is needed whenever possible. We know exactly on how much we need to allocate here - so we should only allocate as much.

@Priya91
Copy link
Author

Priya91 commented Sep 22, 2015

@jkotas @janvorli @JeremyKuhne : Added commit to replace allocations that are in jeremy's linux longpath change.

@@ -1006,6 +1006,9 @@ typedef InlineSString<512> StackSString;
// be needed is small and it's preferable not to take up the stack space.
typedef InlineSString<32> SmallStackSString;

// To be used specifically for path strings.
typedef InlineSString<512> PathString;
Copy link
Member

Choose a reason for hiding this comment

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

I would make this 256 (=existing MAX_PATH). Also, I would make the size much smaller in debug builds to make sure that we exercise the buffer allocation path.

#ifdef _DEBUG
// Make the size smaller in debug builds to exercise the buffer allocation path
typedef InlineSString<32> PathString; 
#else
typedef InlineSString<256> PathString; 
#endif

@jkotas
Copy link
Member

jkotas commented Sep 22, 2015

@Priya91 I went through all changes and left comments.

@Priya91 Priya91 force-pushed the pathstring branch 3 times, most recently from 9e183c3 to a2b8a58 Compare September 24, 2015 00:13
@Priya91
Copy link
Author

Priya91 commented Sep 24, 2015

@jkotas I've submitted a new commit with the PR feedback, please review for merge. Thanks!

WCHAR * pPath = new (nothrow) WCHAR[MAX_LONGPATH];
if (pPath == NULL)
{
WCHAR pPathStack[MAX_LONGPATH];
Copy link
Member

Choose a reason for hiding this comment

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

The error handling here should be:

SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;

Copy link
Member

Choose a reason for hiding this comment

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

BTW: pPathStack in your original code is guaranteed to be allocated on stack only by the closing } of the scope - pPath would be a dangling pointer.

Copy link
Member

Choose a reason for hiding this comment

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

I am not sure I understand the purpose of this construct. The pPathStack will be allocated always on the stack, so why do we allocate the pPath at all? And for compilers that would reuse the frame space of the pPathStack after it goes out of scope at the end of the block, this is even dangerous.

Copy link
Author

Choose a reason for hiding this comment

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

Yup, I just realised that. Didn't know how to handle NULL here.

@Priya91 Priya91 force-pushed the pathstring branch 2 times, most recently from f0fae35 to e5789d9 Compare September 24, 2015 23:02
@Priya91
Copy link
Author

Priya91 commented Sep 24, 2015

@jkotas @janvorli @JeremyKuhne rebased the feedback commits into a single commit. When this passes CI run, is it good to merge?

BINDER_LOG_STRING(W("combined path"), tempResultPath);
}
else
PathString tempResultPath;
Copy link
Member

Choose a reason for hiding this comment

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

We could combine it directly into the combinedPath instead of creating the tempResultPath.

@Priya91
Copy link
Author

Priya91 commented Sep 25, 2015

"d:\j\workspace\dotnet_coreclr_windows_debug_prtest\bin\obj\Windows_NT.x64.Debug\install.vcxproj" (default target) (1) ->
00:39:40        "D:\j\workspace\dotnet_coreclr_windows_debug_prtest\bin\obj\Windows_NT.x64.Debug\ALL_BUILD.vcxproj" (default target) (2) ->
00:39:40        "D:\j\workspace\dotnet_coreclr_windows_debug_prtest\bin\obj\Windows_NT.x64.Debug\src\dlls\mscoree\coreclr\coreclr.vcxproj" (default target) (20) ->
00:39:40        "D:\j\workspace\dotnet_coreclr_windows_debug_prtest\bin\obj\Windows_NT.x64.Debug\src\binder\v3binder\v3binder.vcxproj" (default target) (56) ->
00:39:40          C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(214,5): error MSB4175: The task factory "CodeTaskFactory" could not be loaded from the assembly "C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Build.Tasks.Core.dll". Could not find file 'C:\Users\dotnet-bot\AppData\Local\Temp\unr0z0yu.dll'. [D:\j\workspace\dotnet_coreclr_windows_debug_prtest\bin\obj\Windows_NT.x64.Debug\src\binder\v3binder\v3binder.vcxproj]

@dotnet-bot test this please.

WCHAR * pPath = new (nothrow) WCHAR[MAX_LONGPATH];
if (pPath == NULL)
{
return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
Copy link
Member

Choose a reason for hiding this comment

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

This should be return FALSE; - this function does not return HRESULT.

@jkotas
Copy link
Member

jkotas commented Sep 25, 2015

LGTM othewise

Respond to PR feedback. Fix test failures in mscoree.
Priya91 added a commit that referenced this pull request Sep 28, 2015
Use SString type - PathString for path allocations in binder.
@Priya91 Priya91 merged commit bdc5bce into dotnet:master Sep 28, 2015
@Priya91 Priya91 deleted the pathstring branch September 28, 2015 22:56
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Use SString type - PathString for path allocations in binder.

Commit migrated from dotnet/coreclr@bdc5bce
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants