From ea96aa6b896efba2cfe401c5da52922dcfe260ae Mon Sep 17 00:00:00 2001 From: janwas Date: Sat, 1 Dec 2007 18:23:28 +0000 Subject: [PATCH] bucket: remove size optimization that causes warnings path_util: add path_IsDirectory and path_split wdbg_sym.cpp: bugfix for non-IA32 codepath This was SVN commit r5498. --- source/lib/allocators/bucket.h | 4 ++-- source/lib/path_util.cpp | 35 +++++++++++++++++++++++++++++- source/lib/path_util.h | 16 +++++++++++++- source/lib/sysdep/win/wdbg_sym.cpp | 16 +++++++++----- 4 files changed, 62 insertions(+), 9 deletions(-) diff --git a/source/lib/allocators/bucket.h b/source/lib/allocators/bucket.h index 117286d4b9..d243a87d80 100644 --- a/source/lib/allocators/bucket.h +++ b/source/lib/allocators/bucket.h @@ -41,12 +41,12 @@ struct Bucket void* freelist; - size_t el_size : 16; + size_t el_size; /** * records # buckets allocated; verifies the list of buckets is correct. **/ - uint num_buckets : 16; + uint num_buckets; }; diff --git a/source/lib/path_util.cpp b/source/lib/path_util.cpp index 02508eb0d1..530543111f 100644 --- a/source/lib/path_util.cpp +++ b/source/lib/path_util.cpp @@ -38,6 +38,19 @@ bool path_is_dir_sep(char c) } +bool path_IsDirectory(const char* path) +{ + if(path[0] == '\0') // root dir + return true; + + const char lastChar = path[strlen(path)-1]; + if(path_is_dir_sep(lastChar)) + return true; + + return false; +} + + // is s2 a subpath of s1, or vice versa? // (equal counts as subpath) bool path_is_subpath(const char* s1, const char* s2) @@ -228,6 +241,27 @@ LibError path_replace(char* dst, const char* src, const char* remove, const char // split paths into specific parts +void path_split(const char* pathname, const char** ppath, const char** pname) +{ + const char* name = path_name_only(pathname); + if(pname) + { + if(name[0] == '\0') + *pname = 0; + else + *pname = path_Pool()->UniqueCopy(name); + } + + if(ppath) + { + char pathnameCopy[PATH_MAX]; + path_copy(pathnameCopy, pathname); + + pathnameCopy[name-pathname] = '\0'; // strip filename + *ppath = path_Pool()->UniqueCopy(pathnameCopy); + } +} + // return pointer to the name component within path (i.e. skips over all // characters up to the last dir separator, if any). const char* path_name_only(const char* path) @@ -309,7 +343,6 @@ const char* path_extension(const char* fn) } -// call with for each component in . LibError path_foreach_component(const char* path_org, PathComponentCb cb, uintptr_t cbData) { CHECK_PATH(path_org); diff --git a/source/lib/path_util.h b/source/lib/path_util.h index 4cbfd9c659..a0aac75707 100644 --- a/source/lib/path_util.h +++ b/source/lib/path_util.h @@ -64,6 +64,13 @@ extern LibError path_component_validate(const char* name); **/ extern bool path_is_dir_sep(char c); +/** + * is the given path(name) a directory? + * + * @return bool + **/ +extern bool path_IsDirectory(const char* path); + /** * is s2 a subpath of s1, or vice versa? (equal counts as subpath) * @@ -107,7 +114,7 @@ enum PathAppendFlags extern LibError path_append(char* dst, const char* path1, const char* path2, uint flags = 0); // same as path_append, but returns a unique pointer to the result -extern const char* path_append2(const char* path1, const char* path2, uint flags); +extern const char* path_append2(const char* path1, const char* path2, uint flags = 0); /** * at the start of a path, replace the given substring with another. @@ -122,6 +129,12 @@ extern const char* path_append2(const char* path1, const char* path2, uint flags **/ extern LibError path_replace(char* dst, const char* src, const char* remove, const char* replace); +/** + * combination of path_name_only and path_dir_only2 + * (more efficient than calling them separately) + **/ +extern void path_split(const char* pathname, const char** path, const char** name); + /** * get the name component of a path. @@ -192,6 +205,7 @@ typedef LibError (*PathComponentCb)(const char* component, bool is_dir, uintptr_ /** * call with for each component in . + * * @return LibError **/ extern LibError path_foreach_component(const char* path, PathComponentCb cb, uintptr_t cbData); diff --git a/source/lib/sysdep/win/wdbg_sym.cpp b/source/lib/sysdep/win/wdbg_sym.cpp index 459d246e7b..ddc1b04b6e 100644 --- a/source/lib/sysdep/win/wdbg_sym.cpp +++ b/source/lib/sysdep/win/wdbg_sym.cpp @@ -218,7 +218,7 @@ LibError debug_resolve_symbol(void* ptr_of_interest, char* sym_name, char* file, // stack walk //---------------------------------------------------------------------------- -static VOID (*pRtlCaptureContext)(PCONTEXT*); +static VOID (*pRtlCaptureContext)(PCONTEXT); /* Subroutine linkage example code: @@ -362,9 +362,16 @@ static LibError walk_stack(StackFrameCallback cb, void* user_arg = 0, uint skip { __try { - RaiseException(0xF001, 0, 0, 0); + // note: RaiseException apparently runs our filter in its + // context; this (kernel) stack frame is invalidated when + // it returns. we either have to do the stack walk from + // within the filter expression (could be done via recursion, + // but a bit hard to understand), or trigger an SEH exception + // by different means. we prefer the latter, although it may + // run afoul of sufficiently clever static analysis. + *(char*)0 = 0; // intentional access violation } - __except(context = (GetExceptionInformation())->ContextRecord, EXCEPTION_CONTINUE_EXECUTION) + __except(context = *GetExceptionInformation()->ContextRecord, EXCEPTION_CONTINUE_EXECUTION) { } } @@ -413,8 +420,7 @@ static LibError walk_stack(StackFrameCallback cb, void* user_arg = 0, uint skip // so we have to reset it and check for 0. *sigh* SetLastError(0); const HANDLE hThread = GetCurrentThread(); - BOOL ok = StackWalk64(machine, hProcess, hThread, &sf, (PVOID)pcontext, - 0, SymFunctionTableAccess64, SymGetModuleBase64, 0); + BOOL ok = StackWalk64(machine, hProcess, hThread, &sf, pcontext, 0, SymFunctionTableAccess64, SymGetModuleBase64, 0); // note: don't use LibError_from_win32 because it raises a warning, // and this "fails" commonly (when no stack frames are left). err = ok? INFO::OK : ERR::FAIL;