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

Commit bdc5bce

Browse files
committed
Merge pull request #1589 from Priya91/pathstring
Use SString type - PathString for path allocations in binder.
2 parents 99458af + 965e5d6 commit bdc5bce

File tree

9 files changed

+93
-123
lines changed

9 files changed

+93
-123
lines changed

src/binder/assemblybinder.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ namespace BINDER_SPACE
164164
}
165165
else
166166
{
167-
PathString fullAssemblyPath;
167+
SString fullAssemblyPath;
168168
WCHAR *pwzFullAssemblyPath = fullAssemblyPath.OpenUnicodeBuffer(MAX_LONGPATH);
169169
DWORD dwCCFullAssemblyPath = MAX_LONGPATH + 1; // SString allocates extra byte for null.
170170

@@ -184,9 +184,6 @@ namespace BINDER_SPACE
184184
{
185185
assemblyPath.Set(fullAssemblyPath);
186186
}
187-
188-
// Now turn this path into our canonical representation
189-
CanonicalizePath(assemblyPath);
190187
}
191188

192189
return hr;

src/binder/cdebuglog.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace BINDER_SPACE
5656
{
5757
HRESULT hr=S_OK;
5858
LPTSTR pszFileName;
59-
TCHAR szPath[MAX_LONGPATH];
59+
PathString szPathString;
6060
DWORD dw = 0;
6161

6262
// _ASSERTE (pszPath ) ;
@@ -65,8 +65,12 @@ namespace BINDER_SPACE
6565
IF_FAIL_GO(HRESULT_FROM_WIN32(ERROR_BUFFER_OVERFLOW));
6666
}
6767

68-
IF_FAIL_GO(StringCbCopy(szPath, sizeof(szPath), pszName));
69-
68+
size_t pszNameLen = wcslen(pszName);
69+
WCHAR * szPath = szPathString.OpenUnicodeBuffer(static_cast<COUNT_T>(pszNameLen));
70+
size_t cbSzPath = (sizeof(WCHAR)) * (pszNameLen + 1); // SString allocates extra byte for null
71+
IF_FAIL_GO(StringCbCopy(szPath, cbSzPath, pszName));
72+
szPathString.CloseBuffer(static_cast<COUNT_T>(pszNameLen));
73+
7074
pszFileName = PathFindFileName(szPath);
7175

7276
if (pszFileName <= szPath)
@@ -330,7 +334,6 @@ namespace BINDER_SPACE
330334
CombinePath(g_BinderVariables->logPath, sCategory, logFilePath);
331335
CombinePath(logFilePath, m_applicationName, logFilePath);
332336
CombinePath(logFilePath, m_logFileName, logFilePath);
333-
CanonicalizePath(logFilePath);
334337

335338
BINDER_LOG_STRING(L"logFilePath", logFilePath);
336339

src/binder/debuglog.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ namespace BINDER_SPACE
9090
kCount2.u.HighPart);
9191

9292
PlatformPath(logFilePath);
93-
CanonicalizePath(logFilePath);
9493
}
9594

9695
fFileExists = (FileOrDirectoryExists(logFilePath) == S_OK);

src/binder/inc/bindertypes.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ class PEAssembly;
3232

3333
namespace BINDER_SPACE
3434
{
35-
typedef InlineSString<MAX_LONGPATH + 1> PathString;
36-
3735
class AssemblyVersion;
3836
class AssemblyName;
3937
class Assembly;

src/binder/utils.cpp

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -260,37 +260,6 @@ namespace BINDER_SPACE
260260
BINDER_LOG_LEAVE(W("Utils::PlatformPath"));
261261
}
262262

263-
void CanonicalizePath(SString &path, BOOL fAppendPathSeparator)
264-
{
265-
BINDER_LOG_ENTER(W("Utils::CanonicalizePath"));
266-
BINDER_LOG_STRING(W("input path"), path);
267-
268-
if (!path.IsEmpty())
269-
{
270-
WCHAR wszCanonicalPath[MAX_LONGPATH];
271-
PlatformPath(path);
272-
273-
// This is also defined in rotor pal
274-
if (PathCanonicalizeW(wszCanonicalPath, path))
275-
{
276-
path.Set(wszCanonicalPath);
277-
}
278-
279-
if (fAppendPathSeparator)
280-
{
281-
SString platformPathSeparator(SString::Literal, GetPlatformPathSeparator());
282-
283-
if (!path.EndsWith(platformPathSeparator))
284-
{
285-
path.Append(platformPathSeparator);
286-
}
287-
}
288-
}
289-
290-
BINDER_LOG_STRING(W("canonicalized path"), path);
291-
BINDER_LOG_LEAVE(W("Utils::CanonicalizePath"));
292-
}
293-
294263
void CombinePath(SString &pathA,
295264
SString &pathB,
296265
SString &combinedPath)
@@ -300,17 +269,16 @@ namespace BINDER_SPACE
300269
BINDER_LOG_STRING(W("path A"), pathA);
301270
BINDER_LOG_STRING(W("path B"), pathB);
302271

303-
WCHAR tempResultPath[MAX_LONGPATH];
304-
if (PathCombineW(tempResultPath, pathA, pathB))
305-
{
306-
combinedPath.Set(tempResultPath);
307-
BINDER_LOG_STRING(W("combined path"), tempResultPath);
308-
}
309-
else
272+
SString platformPathSeparator(SString::Literal, GetPlatformPathSeparator());
273+
combinedPath.Set(pathA);
274+
275+
if (!combinedPath.EndsWith(platformPathSeparator))
310276
{
311-
combinedPath.Clear();
277+
combinedPath.Append(platformPathSeparator);
312278
}
313279

280+
combinedPath.Append(pathB);
281+
314282
BINDER_LOG_LEAVE(W("Utils::CombinePath"));
315283
}
316284

src/classlibnative/bcltype/system.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "classnames.h"
2525
#include "system.h"
2626
#include "string.h"
27+
#include "sstring.h"
2728
#include "eeconfig.h"
2829
#include "assemblynative.hpp"
2930
#include "generics.h"
@@ -288,34 +289,29 @@ FCIMPL0(StringObject*, SystemNative::_GetModuleFileName)
288289
{
289290
FCALL_CONTRACT;
290291

291-
WCHAR wszFile[MAX_LONGPATH];
292-
STRINGREF refRetVal = NULL;
293-
LPCWSTR pFileName = NULL;
294-
DWORD lgth = 0;
292+
STRINGREF refRetVal = NULL;
295293

294+
HELPER_METHOD_FRAME_BEGIN_RET_1(refRetVal);
296295
if (g_pCachedModuleFileName)
297296
{
298-
pFileName = g_pCachedModuleFileName;
299-
lgth = (DWORD)wcslen(pFileName);
297+
refRetVal = StringObject::NewString(g_pCachedModuleFileName);
300298
}
301299
else
302300
{
303-
HELPER_METHOD_FRAME_BEGIN_RET_1(refRetVal);
304-
lgth = WszGetModuleFileName(NULL, wszFile, MAX_LONGPATH);
301+
SString wszFilePathString;
302+
303+
WCHAR * wszFile = wszFilePathString.OpenUnicodeBuffer(MAX_LONGPATH);
304+
DWORD lgth = WszGetModuleFileName(NULL, wszFile, MAX_LONGPATH);
305305
if (!lgth)
306306
{
307307
COMPlusThrowWin32();
308308
}
309-
HELPER_METHOD_FRAME_END();
310-
pFileName = wszFile;
311-
}
309+
wszFilePathString.CloseBuffer(lgth);
312310

313-
if(lgth)
314-
{
315-
HELPER_METHOD_FRAME_BEGIN_RET_1(refRetVal);
316-
refRetVal = StringObject::NewString(pFileName, lgth);
317-
HELPER_METHOD_FRAME_END();
311+
refRetVal = StringObject::NewString(wszFilePathString.GetUnicode());
318312
}
313+
HELPER_METHOD_FRAME_END();
314+
319315
return (StringObject*)OBJECTREFToObject(refRetVal);
320316
}
321317
FCIMPLEND
@@ -347,14 +343,16 @@ FCIMPL0(StringObject*, SystemNative::GetRuntimeDirectory)
347343
{
348344
FCALL_CONTRACT;
349345

350-
wchar_t wszFile[MAX_LONGPATH+1];
351346
STRINGREF refRetVal = NULL;
352347
DWORD dwFile = MAX_LONGPATH+1;
353348

354349
HELPER_METHOD_FRAME_BEGIN_RET_1(refRetVal);
350+
SString wszFilePathString;
355351

352+
WCHAR * wszFile = wszFilePathString.OpenUnicodeBuffer(dwFile);
356353
HRESULT hr = GetInternalSystemDirectory(wszFile, &dwFile);
357-
354+
wszFilePathString.CloseBuffer(dwFile);
355+
358356
if(FAILED(hr))
359357
COMPlusThrowHR(hr);
360358

src/debug/ee/debugger.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15136,7 +15136,8 @@ HRESULT Debugger::InitAppDomainIPC(void)
1513615136
} hEnsureCleanup(this);
1513715137

1513815138
DWORD dwStrLen = 0;
15139-
WCHAR szExeName[MAX_LONGPATH];
15139+
SString szExeNamePathString;
15140+
WCHAR * szExeName = szExeNamePathString.OpenUnicodeBuffer(MAX_LONGPATH);
1514015141
int i;
1514115142

1514215143
// all fields in the object can be zero initialized.
@@ -15188,6 +15189,7 @@ HRESULT Debugger::InitAppDomainIPC(void)
1518815189
szExeName,
1518915190
MAX_LONGPATH);
1519015191

15192+
szExeNamePathString.CloseBuffer(dwStrLen);
1519115193
// If we couldn't get the name, then use a nice default.
1519215194
if (dwStrLen == 0)
1519315195
{

0 commit comments

Comments
 (0)