diff --git a/far/PluginA.cpp b/far/PluginA.cpp index 53ea449788..8b2810f647 100644 --- a/far/PluginA.cpp +++ b/far/PluginA.cpp @@ -235,12 +235,12 @@ class oem_plugin_factory: public native_plugin_factory } private: - virtual bool FindExport(const char* ExportName) const override + virtual bool FindExport(const basic_string_view& ExportName) const override { // module with ANY known export can be OEM plugin return std::find_if(ALL_RANGE(m_ExportsNames), [&](const export_name& i) { - return !std::strcmp(ExportName, i.AName); + return i.AName == ExportName; }) != m_ExportsNames.end(); } @@ -1519,10 +1519,7 @@ static void WINAPI qsort(void *base, size_t nelem, size_t width, comparer cmp) n { return NativeFSF.qsort(base, nelem, width, comparer_wrapper, reinterpret_cast(cmp)); } - catch (...) - { - StoreGlobalException(); - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } static void WINAPI qsortex(void *base, size_t nelem, size_t width, comparer_ex cmp, void *userparam) noexcept @@ -1532,10 +1529,7 @@ static void WINAPI qsortex(void *base, size_t nelem, size_t width, comparer_ex c comparer_helper helper = { cmp, userparam }; return NativeFSF.qsort(base, nelem, width, comparer_ex_wrapper, &helper); } - catch (...) - { - StoreGlobalException(); - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } static void* WINAPI bsearch(const void *key, const void *base, size_t nelem, size_t width, comparer cmp) noexcept @@ -1544,11 +1538,8 @@ static void* WINAPI bsearch(const void *key, const void *base, size_t nelem, siz { return NativeFSF.bsearch(key, base, nelem, width, comparer_wrapper, reinterpret_cast(cmp)); } - catch (...) - { - StoreGlobalException(); - return nullptr; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return nullptr; } static int WINAPI LocalIslower(unsigned Ch) noexcept @@ -1597,10 +1588,7 @@ static void WINAPI LocalUpperBuf(char *Buf, int Length) noexcept { std::for_each(Buf, Buf + Length, [](char& i){ i = LowerToUpper[i]; }); } - catch (...) - { - StoreGlobalException(); - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } static unsigned WINAPI LocalLower(unsigned UpperChar) noexcept @@ -1615,10 +1603,7 @@ static void WINAPI LocalLowerBuf(char *Buf, int Length) noexcept { std::for_each(Buf, Buf + Length, [](char& i){ i = UpperToLower[i]; }); } - catch (...) - { - StoreGlobalException(); - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } static void WINAPI LocalStrupr(char *s1) noexcept @@ -1628,10 +1613,7 @@ static void WINAPI LocalStrupr(char *s1) noexcept const auto Iterator = null_iterator(s1); std::for_each(Iterator, Iterator.end(), [](char& i){ i = LowerToUpper[i]; }); } - catch (...) - { - StoreGlobalException(); - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } static void WINAPI LocalStrlwr(char *s1) noexcept @@ -1641,10 +1623,7 @@ static void WINAPI LocalStrlwr(char *s1) noexcept const auto Iterator = null_iterator(s1); std::for_each(Iterator, Iterator.end(), [](char& i){ i = UpperToLower[i]; }); } - catch (...) - { - StoreGlobalException(); - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } static int WINAPI LStricmp(const char *s1, const char *s2) noexcept @@ -1653,11 +1632,8 @@ static int WINAPI LStricmp(const char *s1, const char *s2) noexcept { return LocalStricmp(s1, s2); } - catch (...) - { - StoreGlobalException(); - return -1; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return -1; } static int WINAPI LStrnicmp(const char *s1, const char *s2, int n) noexcept @@ -1666,11 +1642,8 @@ static int WINAPI LStrnicmp(const char *s1, const char *s2, int n) noexcept { return LocalStrnicmp(s1, s2, n); } - catch (...) - { - StoreGlobalException(); - return -1; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return -1; } static char* WINAPI RemoveTrailingSpacesA(char *Str) noexcept @@ -1693,11 +1666,8 @@ static char* WINAPI RemoveTrailingSpacesA(char *Str) noexcept return Str; } - catch (...) - { - StoreGlobalException(); - return Str; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Str; } static char *WINAPI FarItoaA(int value, char *string, int radix) noexcept @@ -1741,11 +1711,8 @@ static char* WINAPI PointToNameA(char *Path) noexcept return NamePtr; } - catch (...) - { - StoreGlobalException(); - return Path; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Path; } static void WINAPI UnquoteA(char *Str) noexcept @@ -1781,11 +1748,8 @@ static char* WINAPI RemoveLeadingSpacesA(char *Str) noexcept return Str; } - catch (...) - { - StoreGlobalException(); - return Str; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Str; } static char* WINAPI RemoveExternalSpacesA(char *Str) noexcept @@ -1814,12 +1778,8 @@ static char* WINAPI TruncStrA(char *Str, int MaxLength) noexcept } return Str; } - catch (...) - { - StoreGlobalException(); - return Str; - } - + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Str; } static char* WINAPI TruncPathStrA(char *Str, int MaxLength) noexcept @@ -1853,11 +1813,8 @@ static char* WINAPI TruncPathStrA(char *Str, int MaxLength) noexcept } return Str; } - catch (...) - { - StoreGlobalException(); - return Str; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Str; } static char* WINAPI QuoteSpaceOnlyA(char *Str) noexcept @@ -1868,11 +1825,8 @@ static char* WINAPI QuoteSpaceOnlyA(char *Str) noexcept InsertQuoteA(Str); return Str; } - catch (...) - { - StoreGlobalException(); - return Str; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Str; } static BOOL WINAPI AddEndSlashA(char *Path) noexcept @@ -1920,12 +1874,8 @@ static BOOL WINAPI AddEndSlashA(char *Path) noexcept } return TRUE; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } - + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static void WINAPI GetPathRootA(const char *Path, char *Root) noexcept @@ -1937,10 +1887,7 @@ static void WINAPI GetPathRootA(const char *Path, char *Root) noexcept if (Size) encoding::oem::get_bytes(Buffer, Size - 1, Root, std::size(Buffer)); } - catch (...) - { - StoreGlobalException(); - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } static int WINAPI CopyToClipboardA(const char *Data) noexcept @@ -1949,11 +1896,8 @@ static int WINAPI CopyToClipboardA(const char *Data) noexcept { return NativeFSF.CopyToClipboard(FCT_STREAM, Data? encoding::oem::get_chars(Data).data() : nullptr); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static char* WINAPI PasteFromClipboardA() noexcept @@ -1968,11 +1912,8 @@ static char* WINAPI PasteFromClipboardA() noexcept } return nullptr; } - catch (...) - { - StoreGlobalException(); - return nullptr; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return nullptr; } static void WINAPI DeleteBufferA(void* Buffer) noexcept @@ -2018,11 +1959,8 @@ static int WINAPI ProcessNameA(const char *Param1, char *Param2, DWORD Flags) no return ret; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static int WINAPI KeyNameToKeyA(const char *Name) noexcept @@ -2031,11 +1969,8 @@ static int WINAPI KeyNameToKeyA(const char *Name) noexcept { return KeyToOldKey(KeyNameToKey(encoding::oem::get_chars(Name))); } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } static BOOL WINAPI FarKeyToNameA(int Key, char *KeyText, int Size) noexcept @@ -2050,11 +1985,8 @@ static BOOL WINAPI FarKeyToNameA(int Key, char *KeyText, int Size) noexcept } return FALSE; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static int WINAPI InputRecordToKeyA(const INPUT_RECORD *r) noexcept @@ -2063,11 +1995,8 @@ static int WINAPI InputRecordToKeyA(const INPUT_RECORD *r) noexcept { return KeyToOldKey(InputRecordToKey(r)); } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } static char* WINAPI FarMkTempA(char *Dest, const char *Prefix) noexcept @@ -2080,11 +2009,8 @@ static char* WINAPI FarMkTempA(char *Dest, const char *Prefix) noexcept encoding::oem::get_bytes(D, Size - 1, Dest, std::size(D)); return Dest; } - catch (...) - { - StoreGlobalException(); - return Dest; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Dest; } static int WINAPI FarMkLinkA(const char *Src, const char *Dest, DWORD OldFlags) noexcept @@ -2111,11 +2037,8 @@ static int WINAPI FarMkLinkA(const char *Src, const char *Dest, DWORD OldFlags) return NativeFSF.MkLink(encoding::oem::get_chars(Src).data(), encoding::oem::get_chars(Dest).data(), Type, Flags); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static int WINAPI GetNumberOfLinksA(const char *Name) noexcept @@ -2124,11 +2047,8 @@ static int WINAPI GetNumberOfLinksA(const char *Name) noexcept { return static_cast(NativeFSF.GetNumberOfLinks(encoding::oem::get_chars(Name).data())); } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } static int WINAPI ConvertNameToRealA(const char *Src, char *Dest, int DestSize) noexcept @@ -2143,11 +2063,8 @@ static int WINAPI ConvertNameToRealA(const char *Src, char *Dest, int DestSize) encoding::oem::get_bytes(strDest, Dest, DestSize); return std::min(static_cast(strDest.size()), DestSize); } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } static int WINAPI FarGetReparsePointInfoA(const char *Src, char *Dest, int DestSize) noexcept @@ -2172,11 +2089,8 @@ static int WINAPI FarGetReparsePointInfoA(const char *Src, char *Dest, int DestS } return static_cast(Result); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static int WINAPI FarRecursiveSearchA_Callback(const PluginPanelItem *FData, const wchar_t *FullName, void *param) noexcept @@ -2197,11 +2111,8 @@ static int WINAPI FarRecursiveSearchA_Callback(const PluginPanelItem *FData, con encoding::oem::get_bytes(FullName, FullNameA); return pCallbackParam->Func(&FindData, FullNameA, pCallbackParam->Param); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static void WINAPI FarRecursiveSearchA(const char *InitDir, const char *Mask, oldfar::FRSUSERFUNC Func, DWORD Flags, void *Param) noexcept @@ -2224,10 +2135,7 @@ static void WINAPI FarRecursiveSearchA(const char *InitDir, const char *Mask, ol NativeFSF.FarRecursiveSearch(encoding::oem::get_chars(InitDir).data(), encoding::oem::get_chars(Mask).data(), FarRecursiveSearchA_Callback, NewFlags, static_cast(&CallbackParam)); } - catch (...) - { - StoreGlobalException(); - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } static DWORD WINAPI ExpandEnvironmentStrA(const char *src, char *dest, size_t size) noexcept @@ -2239,11 +2147,8 @@ static DWORD WINAPI ExpandEnvironmentStrA(const char *src, char *dest, size_t si encoding::oem::get_bytes(strD, dest, len + 1); return static_cast(len); } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } static int WINAPI FarViewerA(const char *FileName, const char *Title, int X1, int Y1, int X2, int Y2, DWORD Flags) noexcept @@ -2252,11 +2157,8 @@ static int WINAPI FarViewerA(const char *FileName, const char *Title, int X1, in { return NativeInfo.Viewer(encoding::oem::get_chars(FileName).data(), encoding::oem::get_chars(Title).data(), X1, Y1, X2, Y2, Flags, CP_DEFAULT); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static int WINAPI FarEditorA(const char *FileName, const char *Title, int X1, int Y1, int X2, int Y2, DWORD Flags, int StartLine, int StartChar) noexcept @@ -2265,11 +2167,8 @@ static int WINAPI FarEditorA(const char *FileName, const char *Title, int X1, in { return NativeInfo.Editor(encoding::oem::get_chars(FileName).data(), encoding::oem::get_chars(Title).data(), X1, Y1, X2, Y2, Flags, StartLine, StartChar, CP_DEFAULT); } - catch (...) - { - StoreGlobalException(); - return EEC_OPEN_ERROR; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return EEC_OPEN_ERROR; } static int WINAPI FarCmpNameA(const char *pattern, const char *str, int skippath) noexcept @@ -2285,10 +2184,7 @@ static void WINAPI FarTextA(int X, int Y, int ConColor, const char *Str) noexcep const auto Color = colors::ConsoleColorToFarColor(ConColor); return NativeInfo.Text(X, Y, &Color, Str? encoding::oem::get_chars(Str).data() : nullptr); } - catch (...) - { - StoreGlobalException(); - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } static BOOL WINAPI FarShowHelpA(const char *ModuleName, const char *HelpTopic, DWORD Flags) noexcept @@ -2297,11 +2193,8 @@ static BOOL WINAPI FarShowHelpA(const char *ModuleName, const char *HelpTopic, D { return NativeInfo.ShowHelp(encoding::oem::get_chars(ModuleName).data(), (HelpTopic ? encoding::oem::get_chars(HelpTopic).data() : nullptr), Flags); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static int WINAPI FarInputBoxA(const char *Title, const char *Prompt, const char *HistoryName, const char *SrcText, char *DestText, int DestLength, const char *HelpTopic, DWORD Flags) noexcept @@ -2337,11 +2230,8 @@ static int WINAPI FarInputBoxA(const char *Title, const char *Prompt, const char return ret; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static int WINAPI FarMessageFnA(intptr_t PluginNumber, DWORD Flags, const char *HelpTopic, const char * const *Items, int ItemsNumber, int ButtonsNumber) noexcept @@ -2402,11 +2292,8 @@ static int WINAPI FarMessageFnA(intptr_t PluginNumber, DWORD Flags, const char * AnsiItems.empty() ? reinterpret_cast(AllInOneAnsiItem.get()) : reinterpret_cast(AnsiItems.data()), ItemsNumber, ButtonsNumber); } - catch (...) - { - StoreGlobalException(); - return -1; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return -1; } static const char * WINAPI FarGetMsgFnA(intptr_t PluginHandle, int MsgId) noexcept @@ -2423,12 +2310,8 @@ static const char * WINAPI FarGetMsgFnA(intptr_t PluginHandle, int MsgId) noexce return ""; } - catch (...) - { - StoreGlobalException(); - return ""; - } - + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return ""; } static int WINAPI FarMenuFnA(intptr_t PluginNumber, int X, int Y, int MaxHeight, DWORD Flags, const char *Title, const char *Bottom, const char *HelpTopic, const int *BreakKeys, int *BreakCode, const oldfar::FarMenuItem *Item, int ItemsNumber) noexcept @@ -2552,11 +2435,8 @@ static int WINAPI FarMenuFnA(intptr_t PluginNumber, int X, int Y, int MaxHeight, return ret; } - catch (...) - { - StoreGlobalException(); - return -1; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return -1; } static intptr_t WINAPI FarDefDlgProcA(HANDLE hDlg, int Msg, int Param1, void* Param2) noexcept @@ -2574,11 +2454,8 @@ static intptr_t WINAPI FarDefDlgProcA(HANDLE hDlg, int Msg, int Param1, void* Pa } return Result; } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } static intptr_t WINAPI CurrentDlgProc(HANDLE hDlg, intptr_t Msg, intptr_t Param1, void* Param2) noexcept @@ -2588,11 +2465,8 @@ static intptr_t WINAPI CurrentDlgProc(HANDLE hDlg, intptr_t Msg, intptr_t Param1 const auto Data = FindDialogData(hDlg); return (Data->DlgProc ? Data->DlgProc : FarDefDlgProcA)(hDlg, Msg, Param1, Param2); } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } static intptr_t WINAPI DlgProcA(HANDLE hDlg, intptr_t NewMsg, intptr_t Param1, void* Param2) noexcept @@ -2753,11 +2627,8 @@ static intptr_t WINAPI DlgProcA(HANDLE hDlg, intptr_t NewMsg, intptr_t Param1, v } return CurrentDlgProc(hDlg, Msg, Param1, Param2); } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } static intptr_t WINAPI FarSendDlgMessageA(HANDLE hDlg, int OldMsg, int Param1, void* Param2) noexcept @@ -3291,11 +3162,8 @@ static intptr_t WINAPI FarSendDlgMessageA(HANDLE hDlg, int OldMsg, int Param1, v } return NativeInfo.SendDlgMessage(hDlg, Msg, Param1, Param2); } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } static int WINAPI FarDialogExA(intptr_t PluginNumber, int X1, int Y1, int X2, int Y2, const char *HelpTopic, oldfar::FarDialogItem *Item, int ItemsNumber, DWORD, DWORD Flags, oldfar::FARWINDOWPROC DlgProc, void* Param) noexcept @@ -3399,11 +3267,8 @@ static int WINAPI FarDialogExA(intptr_t PluginNumber, int X1, int Y1, int X2, in return ret; } - catch (...) - { - StoreGlobalException(); - return -1; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return -1; } static int WINAPI FarDialogFnA(intptr_t PluginNumber, int X1, int Y1, int X2, int Y2, const char *HelpTopic, oldfar::FarDialogItem *Item, int ItemsNumber) noexcept @@ -3710,11 +3575,8 @@ static int WINAPI FarPanelControlA(HANDLE hPlugin, int Command, void *Param) noe } return FALSE; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static HANDLE WINAPI FarSaveScreenA(int X1, int Y1, int X2, int Y2) noexcept @@ -3723,11 +3585,8 @@ static HANDLE WINAPI FarSaveScreenA(int X1, int Y1, int X2, int Y2) noexcept { return NativeInfo.SaveScreen(X1, Y1, X2, Y2); } - catch (...) - { - StoreGlobalException(); - return nullptr; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return nullptr; } static void WINAPI FarRestoreScreenA(HANDLE Screen) noexcept @@ -3736,10 +3595,7 @@ static void WINAPI FarRestoreScreenA(HANDLE Screen) noexcept { return NativeInfo.RestoreScreen(Screen); } - catch (...) - { - StoreGlobalException(); - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } static int GetDirListGeneric(oldfar::PluginPanelItem*& PanelItems, int& ItemsSize, const std::function& Getter) @@ -3786,11 +3642,8 @@ static int WINAPI FarGetDirListA(const char *Dir, oldfar::PluginPanelItem **pPan return NativeInfo.GetDirList(strDir.data(), &Items, &Size); }); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static int WINAPI FarGetPluginDirListA(intptr_t PluginNumber, HANDLE hPlugin, const char *Dir, oldfar::PluginPanelItem **pPanelItem, int *pItemsNumber) noexcept @@ -3803,11 +3656,8 @@ static int WINAPI FarGetPluginDirListA(intptr_t PluginNumber, HANDLE hPlugin, co return NativeInfo.GetPluginDirList(GetPluginGuid(PluginNumber), hPlugin, encoding::oem::get_chars(Dir).data(), &Items, &Size); }); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static void WINAPI FarFreeDirListA(const oldfar::PluginPanelItem *PanelItem) noexcept @@ -3819,10 +3669,7 @@ static void WINAPI FarFreeDirListA(const oldfar::PluginPanelItem *PanelItem) noe size_t count = PanelItem->Reserved[0]; FreePanelItemA(PanelItem, count); } - catch (...) - { - StoreGlobalException(); - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } static intptr_t WINAPI FarAdvControlA(intptr_t ModuleNumber, oldfar::ADVANCED_CONTROL_COMMANDS Command, void *Param) noexcept @@ -4161,11 +4008,8 @@ static intptr_t WINAPI FarAdvControlA(intptr_t ModuleNumber, oldfar::ADVANCED_CO } return FALSE; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static int WINAPI FarEditorControlA(oldfar::EDITOR_CONTROL_COMMANDS OldCommand, void* Param) noexcept @@ -4614,11 +4458,8 @@ static int WINAPI FarEditorControlA(oldfar::EDITOR_CONTROL_COMMANDS OldCommand, } return static_cast(NativeInfo.EditorControl(-1, Command, 0, Param)); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static int WINAPI FarViewerControlA(int Command, void* Param) noexcept @@ -4747,11 +4588,8 @@ static int WINAPI FarViewerControlA(int Command, void* Param) noexcept } return TRUE; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static int WINAPI FarCharTableA(int Command, char *Buffer, int BufferSize) noexcept @@ -4813,11 +4651,8 @@ static int WINAPI FarCharTableA(int Command, char *Buffer, int BufferSize) noexc } return -1; } - catch (...) - { - StoreGlobalException(); - return -1; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return -1; } char* WINAPI XlatA( @@ -4847,11 +4682,8 @@ char* WINAPI XlatA( encoding::oem::get_bytes(Buffer.data(), strLine.size(), Line, strLine.size()); return Line; } - catch (...) - { - StoreGlobalException(); - return Line; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Line; } static int WINAPI GetFileOwnerA(const char *Computer, const char *Name, char *Owner) noexcept @@ -4866,11 +4698,8 @@ static int WINAPI GetFileOwnerA(const char *Computer, const char *Name, char *Ow } return Ret; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } } diff --git a/far/blob_builder.hpp b/far/blob_builder.hpp index 2a5337444a..6c8b13a009 100644 --- a/far/blob_builder.hpp +++ b/far/blob_builder.hpp @@ -55,23 +55,23 @@ class blob_builder return *this; } - blob_view get() const + bytes_view get() const { if (m_Data.empty() || (m_Signature && m_Data.size() == 1)) { - return {}; + return { nullptr, 0 }; } if (m_CodePage == CP_UNICODE) { - return make_blob_view(m_Data.data(), m_Data.size() * sizeof(wchar_t)); + return bytes_view(m_Data.data(), m_Data.size() * sizeof(wchar_t)); } if (m_Buffer.empty()) { m_Buffer = encoding::get_bytes(m_CodePage, m_Data); } - return make_blob_view(m_Buffer.data(), m_Buffer.size()); + return bytes_view(m_Buffer.data(), m_Buffer.size()); } private: diff --git a/far/cddrv.cpp b/far/cddrv.cpp index 0529c9bd8b..fe43cd9f27 100644 --- a/far/cddrv.cpp +++ b/far/cddrv.cpp @@ -405,7 +405,7 @@ UINT FAR_GetDriveType(const string& RootDir, DWORD Detect) else { constexpr auto UncDevicePrefix = L"\\\\.\\"_sv; - VolumePath.insert(0, UncDevicePrefix.data(), UncDevicePrefix.size()); + VolumePath.insert(0, UncDevicePrefix.raw_data(), UncDevicePrefix.size()); } if(const auto Device = os::fs::file(VolumePath, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, nullptr, OPEN_EXISTING)) diff --git a/far/changelog b/far/changelog index a3a8036a5a..965ededc12 100644 --- a/far/changelog +++ b/far/changelog @@ -1,3 +1,9 @@ +drkns 09.09.2017 22:00:37 +0100 - build 5026 + +1. Записываем стек и для тех исключений, которые были пойманы и переброшены через exception_ptr. + +2. Рефакторинг. + drkns 09.09.2017 17:32:31 +0100 - build 5025 1. 0003485: Exception при попытке просмотра некорректного? hlf diff --git a/far/clipboard.cpp b/far/clipboard.cpp index 305d452662..84b6750340 100644 --- a/far/clipboard.cpp +++ b/far/clipboard.cpp @@ -282,7 +282,7 @@ bool clipboard::SetText(const string_view& Str) if (!Clear()) return false; - auto hData = os::memory::global::copy(Str.data(), Str.size()); + auto hData = os::memory::global::copy(Str.raw_data(), Str.size()); if (!hData) return false; @@ -402,7 +402,7 @@ bool clipboard::GetHDROPAsText(string& data) const { for (const auto& i: enum_substrings(StartA)) { - append(data, encoding::ansi::get_chars(i.data(), i.size()), L"\r\n"_sv); + append(data, encoding::ansi::get_chars(i), L"\r\n"_sv); } } diff --git a/far/common.hpp b/far/common.hpp index b18fae1a31..1e09fff6a9 100644 --- a/far/common.hpp +++ b/far/common.hpp @@ -58,7 +58,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "common/enum_substrings.hpp" #include "common/string_utils.hpp" #include "common/zip_view.hpp" -#include "common/blob_view.hpp" +#include "common/bytes_view.hpp" #include "common/singleton.hpp" // TODO: clean up & split diff --git a/far/common/blob_view.hpp b/far/common/bytes_view.hpp similarity index 62% rename from far/common/blob_view.hpp rename to far/common/bytes_view.hpp index 2fdae0916c..471279b954 100644 --- a/far/common/blob_view.hpp +++ b/far/common/bytes_view.hpp @@ -1,9 +1,9 @@ -#ifndef BLOB_VIEW_HPP_3707377A_7C4B_4B2E_89EC_6411A1988FB3 -#define BLOB_VIEW_HPP_3707377A_7C4B_4B2E_89EC_6411A1988FB3 +#ifndef BYTES_VIEW_HPP_3707377A_7C4B_4B2E_89EC_6411A1988FB3 +#define BYTES_VIEW_HPP_3707377A_7C4B_4B2E_89EC_6411A1988FB3 #pragma once /* -blob_view.hpp +bytes_view.hpp */ /* Copyright © 2016 Far Group @@ -32,21 +32,46 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -using blob_view = range; +class bytes_view: public range +{ +public: + bytes_view(const void* Data, size_t Size): + range(reinterpret_cast(Data), reinterpret_cast(Data) + Size) + { + } + + template + explicit bytes_view(T& Object): + bytes_view(&Object, sizeof(Object)) + { + static_assert(std::is_trivially_copyable::value); + } +}; -class writable_blob_view: public range +class bytes: public range { public: - NONCOPYABLE(writable_blob_view); - writable_blob_view() = default; - writable_blob_view(void* Data, size_t Size): range(reinterpret_cast(Data), reinterpret_cast(Data) + Size) {} - ~writable_blob_view() + NONCOPYABLE(bytes); + MOVABLE(bytes); + + bytes() = default; + + bytes(void* Data, size_t Size): range(reinterpret_cast(Data), reinterpret_cast(Data) + Size) {} + + template + explicit bytes(T& Object): + bytes(&Object, sizeof(Object)) { - if (m_Allocated) + static_assert(std::is_trivially_copyable::value); + } + + ~bytes() + { + if (*m_Allocated) delete[] static_cast(data()); } - writable_blob_view& operator=(const blob_view& rhs) + auto& operator=(const bytes_view& rhs) { if (data()) { @@ -56,25 +81,14 @@ class writable_blob_view: public range else { static_cast&>(*this) = make_range(new char[rhs.size()], rhs.size()); - m_Allocated = true; + *m_Allocated = true; } memcpy(data(), rhs.data(), size()); return *this; } + private: - bool m_Allocated{}; + movable m_Allocated{ false }; }; -inline auto make_blob_view(const void* Object, size_t Size) -{ - return make_range(reinterpret_cast(Object), Size); -} - -template -auto make_blob_view(const T& Object) -{ - static_assert(std::is_pod::value); - return make_blob_view(&Object, sizeof Object); -} - -#endif // BLOB_VIEW_HPP_3707377A_7C4B_4B2E_89EC_6411A1988FB3 +#endif // BYTES_VIEW_HPP_3707377A_7C4B_4B2E_89EC_6411A1988FB3 diff --git a/far/common/string_utils.hpp b/far/common/string_utils.hpp index 7ec0f4056e..edcaa7fdd5 100644 --- a/far/common/string_utils.hpp +++ b/far/common/string_utils.hpp @@ -51,7 +51,7 @@ class null_terminated_t { public: explicit null_terminated_t(const basic_string_view& Str): - m_Terminated(Str.data()[Str.size()] == 0) + m_Terminated(!Str.raw_data()[Str.size()]) { if (m_Terminated) placement::construct(m_View, Str); @@ -69,7 +69,7 @@ class null_terminated_t auto data() const { - return m_Terminated? m_View.data() : m_Str.data(); + return m_Terminated? m_View.raw_data() : m_Str.data(); } auto size() const @@ -95,7 +95,7 @@ namespace detail inline void append_one(string& Str, wchar_t Arg, size_t) { Str += Arg; } inline void append_one(string& Str, const wchar_t* Arg, size_t Size) { Str.append(Arg, Size); } inline void append_one(string& Str, const string& Arg, size_t) { Str += Arg; } - inline void append_one(string& Str, const string_view& Arg, size_t) { Str.append(Arg.data(), Arg.size()); } + inline void append_one(string& Str, const string_view& Arg, size_t) { Str.append(Arg.raw_data(), Arg.size()); } inline void append_impl(string&, const size_t*) {} @@ -284,12 +284,12 @@ inline bool equal(const string_view& Str1, const string_view& Str2) inline bool starts_with(const string_view& Str, const string_view& Prefix) { - return Str.size() >= Prefix.size() && equal({ Str.data(), Prefix.size() }, Prefix); + return Str.size() >= Prefix.size() && equal({ Str.raw_data(), Prefix.size() }, Prefix); } inline bool ends_with(const string_view& Str, const string_view& Suffix) { - return Str.size() >= Suffix.size() && equal({ Str.data() + Str.size() - Suffix.size(), Suffix.size() }, Suffix); + return Str.size() >= Suffix.size() && equal({ Str.raw_data() + Str.size() - Suffix.size(), Suffix.size() }, Suffix); } inline bool contains(const string_view& Str, const string_view& Token) diff --git a/far/common/string_view.hpp b/far/common/string_view.hpp index 35f17c62f0..f96acdbd35 100644 --- a/far/common/string_view.hpp +++ b/far/common/string_view.hpp @@ -56,8 +56,34 @@ class basic_string_view: public range { } + constexpr basic_string_view substr(size_t Pos = 0, size_t Count = std::basic_string::npos) const + { + return { this->raw_data() + Pos, std::min(Count, this->size() - Pos) }; + } + + /* + ISO/IEC N4659 24.4.2.4 771 + "Note: Unlike basic_string::data() and string literals, data() may return a pointer to a buffer that + is not null-terminated. Therefore it is typically a mistake to pass data() to a function that takes just a + const charT* and expects a null-terminated string." + + - Another splendid design decision from the committee. + If it's "typically a mistake", why didn't you give some other, "less-similar-to-basic_string::data()" name? + + For now, our implementation intentionally does not provide data() member function - + we heavily rely on the platform API which requires C strings in about 99% of the cases and it's too easy to make a mistake + and "rescue the Princess, her dog, her entire wardrobe & everything she has ever eaten...". + Hopefully we will thin out C strings numbers enough by the time we switch to a C++17-conformant compiler. + */ + constexpr auto data() const = delete; + constexpr auto raw_data() const + { + return range::data(); + } + private: - static size_t length(const T* Str) { auto Ptr = Str; while (*Ptr) ++Ptr; return Ptr - Str; } + static auto length(const char* Str) { return strlen(Str); } + static auto length(const wchar_t* Str) { return wcslen(Str); } }; constexpr auto operator "" _sv(const char* Data, size_t Size) noexcept { return basic_string_view(Data, Size); } @@ -68,7 +94,7 @@ auto operator+(const std::basic_string& Lhs, const basic_string_view& Rhs) { std::basic_string Result; Result.reserve(Lhs.size() + Rhs.size()); - return Result.append(Lhs).append(Rhs.data(), Rhs.size()); + return Result.append(Lhs).append(Rhs.raw_data(), Rhs.size()); } template @@ -76,7 +102,7 @@ auto operator+(const basic_string_view& Lhs, const std::basic_string& Rhs) { std::basic_string Result; Result.reserve(Lhs.size() + Rhs.size()); - return Result.append(Lhs.data(), Lhs.size()).append(Rhs); + return Result.append(Lhs.raw_data(), Lhs.size()).append(Rhs); } template @@ -84,7 +110,7 @@ auto operator+(const basic_string_view& Lhs, const basic_string_view& Rhs) { std::basic_string Result; Result.reserve(Lhs.size() + Rhs.size()); - return Result.append(Lhs.data(), Lhs.size()).append(Rhs.data(), Rhs.size()); + return Result.append(Lhs.raw_data(), Lhs.size()).append(Rhs.raw_data(), Rhs.size()); } template @@ -108,7 +134,7 @@ bool operator==(const std::basic_string& Lhs, const basic_string_view& Rhs template std::basic_string make_string(const basic_string_view& View) { - return { View.data(), View.size() }; + return { View.raw_data(), View.size() }; } template diff --git a/far/config.cpp b/far/config.cpp index 499b2edcda..3a724a7223 100644 --- a/far/config.cpp +++ b/far/config.cpp @@ -219,19 +219,15 @@ void Options::TreeSettings() { DialogBuilder Builder(lng::MConfigTreeTitle, L"TreeSettings"); - DialogItemEx *TemplateEdit; - Builder.AddCheckbox(lng::MConfigTreeAutoChange, Tree.AutoChangeFolder); - TemplateEdit = Builder.AddIntEditField(Tree.MinTreeCount, 3); + auto TemplateEdit = Builder.AddIntEditField(Tree.MinTreeCount, 3); Builder.AddTextBefore(TemplateEdit, lng::MConfigTreeLabelMinFolder); #if defined(TREEFILE_PROJECT) - DialogItemEx *Checkbox; - Builder.AddSeparator(lng::MConfigTreeLabel1); - Checkbox = Builder.AddCheckbox(lng::MConfigTreeLabelLocalDisk, Tree.LocalDisk); + auto Checkbox = Builder.AddCheckbox(lng::MConfigTreeLabelLocalDisk, Tree.LocalDisk); TemplateEdit = Builder.AddEditField(Tree.strLocalDisk, 44); TemplateEdit->Indent(4); Builder.LinkFlags(Checkbox, TemplateEdit, DIF_DISABLE); diff --git a/far/configdb.cpp b/far/configdb.cpp index ac2149d5be..ad5941a185 100644 --- a/far/configdb.cpp +++ b/far/configdb.cpp @@ -52,7 +52,6 @@ class representation_source { public: explicit representation_source(const string& File): - m_File(File), m_Root(nullptr) { const auto RootName = "farconfig"; @@ -76,7 +75,6 @@ class representation_source private: tinyxml::XMLDocument m_Document; - string m_File; tinyxml::XMLHandle m_Root; }; @@ -178,27 +176,22 @@ class iGeneralConfigDb: public GeneralConfig, public SQLiteDb ; } - virtual bool SetValue(const string& Key, const string& Name, const string& Value) override + virtual bool SetValue(const string_view& Key, const string_view& Name, const string_view& Value) override { return SetValueT(Key, Name, Value); } - virtual bool SetValue(const string& Key, const string& Name, const wchar_t* Value) override + virtual bool SetValue(const string_view& Key, const string_view& Name, unsigned long long Value) override { return SetValueT(Key, Name, Value); } - virtual bool SetValue(const string& Key, const string& Name, unsigned long long Value) override + virtual bool SetValue(const string_view& Key, const string_view& Name, const bytes_view& Value) override { return SetValueT(Key, Name, Value); } - virtual bool SetValue(const string& Key, const string& Name, const blob_view& Value) override - { - return SetValueT(Key, Name, Value); - } - - virtual bool GetValue(const string& Key, const string& Name, bool& Value, bool Default) const override + virtual bool GetValue(const string_view& Key, const string_view& Name, bool& Value, bool Default) const override { long long Data = Default; const auto Result = GetValue(Key, Name, Data, Data); @@ -206,32 +199,32 @@ class iGeneralConfigDb: public GeneralConfig, public SQLiteDb return Result; } - virtual bool GetValue(const string& Key, const string& Name, long long& Value, long long Default) const override + virtual bool GetValue(const string_view& Key, const string_view& Name, long long& Value, long long Default) const override { return GetValueT(Key, Name, Value, Default, &SQLiteStmt::GetColInt64); } - virtual bool GetValue(const string& Key, const string& Name, string& Value, const wchar_t* Default) const override + virtual bool GetValue(const string_view& Key, const string_view& Name, string& Value, const wchar_t* Default) const override { return GetValueT(Key, Name, Value, Default, &SQLiteStmt::GetColText); } - virtual bool GetValue(const string& Key, const string& Name, string& Value, const string& Default) const override + virtual bool GetValue(const string_view& Key, const string_view& Name, string& Value, const string& Default) const override { return GetValueT(Key, Name, Value, Default, &SQLiteStmt::GetColText); } - virtual bool DeleteValue(const string& Key, const string& Name) override + virtual bool DeleteValue(const string_view& Key, const string_view& Name) override { return ExecuteStatement(stmtDelValue, Key, Name); } - virtual bool EnumValues(const string& Key, DWORD Index, string &Name, string &Value) const override + virtual bool EnumValues(const string_view& Key, DWORD Index, string &Name, string &Value) const override { return EnumValuesT(Key, Index, Name, Value, &SQLiteStmt::GetColText); } - virtual bool EnumValues(const string& Key, DWORD Index, string &Name, long long& Value) const override + virtual bool EnumValues(const string_view& Key, DWORD Index, string &Name, long long& Value) const override { return EnumValuesT(Key, Index, Name, Value, &SQLiteStmt::GetColInt64); } @@ -303,7 +296,7 @@ class iGeneralConfigDb: public GeneralConfig, public SQLiteDb if (!strcmp(type,"hex")) { const auto Blob = HexStringToBlob(value); - SetValue(Key, Name, make_blob_view(Blob.data(), Blob.size())); + SetValue(Key, Name, bytes_view(Blob.data(), Blob.size())); continue; } } @@ -312,7 +305,7 @@ class iGeneralConfigDb: public GeneralConfig, public SQLiteDb virtual const char* GetKeyName() const = 0; template - bool GetValueT(const string& Key, const string& Name, T& Value, const DT& Default, getter_t Getter) const + bool GetValueT(const string_view& Key, const string_view& Name, T& Value, const DT& Default, getter_t Getter) const { const auto Stmt = AutoStatement(stmtGetValue); if (!Stmt->Bind(Key, Name).Step() || Stmt->GetColType(0) != TypeId) @@ -326,7 +319,7 @@ class iGeneralConfigDb: public GeneralConfig, public SQLiteDb } template - bool SetValueT(const string& Key, const string& Name, const T Value) + bool SetValueT(const string_view& Key, const string_view& Name, const T Value) { bool b = ExecuteStatement(stmtUpdateValue, Key, Name, Value); if (!b || !Changes()) @@ -335,7 +328,7 @@ class iGeneralConfigDb: public GeneralConfig, public SQLiteDb } template - bool EnumValuesT(const string& Key, DWORD Index, string& Name, T& Value, getter_t Getter) const + bool EnumValuesT(const string_view& Key, DWORD Index, string& Name, T& Value, getter_t Getter) const { auto Stmt = AutoStatement(stmtEnumValues); if (Index == 0) @@ -442,10 +435,10 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb return b; } - virtual key CreateKey(const key& Root, const string& Name, const string* Description) override + virtual key CreateKey(const key& Root, const string_view& Name, const string* Description) override { - if (ExecuteStatement(stmtCreateKey, Root.get(), Name, Description? Description->data() : nullptr)) - return make_key(LastInsertRowID()); + if (ExecuteStatement(stmtCreateKey, Root.get(), Name, Description)) + return key(LastInsertRowID()); const auto Key = FindByName(Root, Name); if (Key.get() && Description) @@ -453,51 +446,46 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb return Key; } - virtual key FindByName(const key& Root, const string& Name) const override + virtual key FindByName(const key& Root, const string_view& Name) const override { const auto Stmt = AutoStatement(stmtFindKey); if (!Stmt->Bind(Root.get(), Name).Step()) - return make_key(0); + return root_key(); - return make_key(Stmt->GetColInt64(0)); + return key(Stmt->GetColInt64(0)); } - virtual bool SetKeyDescription(const key& Root, const string& Description) override + virtual bool SetKeyDescription(const key& Root, const string_view& Description) override { return ExecuteStatement(stmtSetKeyDescription, Description, Root.get()); } - virtual bool SetValue(const key& Root, const string& Name, const string& Value) override + virtual bool SetValue(const key& Root, const string_view& Name, const string_view& Value) override { return SetValueT(Root, Name, Value); } - virtual bool SetValue(const key& Root, const string& Name, const wchar_t* Value) override + virtual bool SetValue(const key& Root, const string_view& Name, unsigned long long Value) override { return SetValueT(Root, Name, Value); } - virtual bool SetValue(const key& Root, const string& Name, unsigned long long Value) override + virtual bool SetValue(const key& Root, const string_view& Name, const bytes_view& Value) override { return SetValueT(Root, Name, Value); } - virtual bool SetValue(const key& Root, const string& Name, const blob_view& Value) override - { - return SetValueT(Root, Name, Value); - } - - virtual bool GetValue(const key& Root, const string& Name, unsigned long long& Value) const override + virtual bool GetValue(const key& Root, const string_view& Name, unsigned long long& Value) const override { return GetValueT(Root, Name, Value, &SQLiteStmt::GetColInt64); } - virtual bool GetValue(const key& Root, const string& Name, string &Value) const override + virtual bool GetValue(const key& Root, const string_view& Name, string& Value) const override { return GetValueT(Root, Name, Value, &SQLiteStmt::GetColText); } - virtual bool GetValue(const key& Root, const string& Name, writable_blob_view& Value) const override + virtual bool GetValue(const key& Root, const string_view& Name, bytes& Value) const override { return GetValueT(Root, Name, Value, &SQLiteStmt::GetColBlob); } @@ -508,7 +496,7 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb return ExecuteStatement(stmtDeleteTree, Key.get()); } - virtual bool DeleteValue(const key& Root, const string& Name) override + virtual bool DeleteValue(const key& Root, const string_view& Name) override { return ExecuteStatement(stmtDelValue, Root.get(), Name); } @@ -612,7 +600,7 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb if (const auto description = stmtEnumSubKeys.GetColTextUTF8(2)) e.SetAttribute("description", description); - Export(Representation, make_key(stmtEnumSubKeys.GetColInt64(0)), e); + Export(Representation, key(stmtEnumSubKeys.GetColInt64(0)), e); } } @@ -641,7 +629,7 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb if (!name || !type) continue; - string Name = encoding::utf8::get_chars(name); + const auto Name = encoding::utf8::get_chars(name); if (value && !strcmp(type, "qword")) { @@ -655,13 +643,13 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb else if (value && !strcmp(type, "hex")) { const auto Blob = HexStringToBlob(value); - SetValue(Key, Name, make_blob_view(Blob.data(), Blob.size())); + SetValue(Key, Name, bytes_view(Blob.data(), Blob.size())); } else { // custom types, value is optional const auto Blob = DeserializeBlob(name, type, value, *e); - SetValue(Key, Name, make_blob_view(Blob.data(), Blob.size())); + SetValue(Key, Name, bytes_view(Blob.data(), Blob.size())); } } @@ -672,7 +660,7 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb } template - bool GetValueT(const key& Root, const string& Name, T& Value, getter_t Getter) const + bool GetValueT(const key& Root, const string_view& Name, T& Value, getter_t Getter) const { const auto Stmt = AutoStatement(stmtGetValue); if (!Stmt->Bind(Root.get(), Name).Step()) @@ -683,7 +671,7 @@ class HierarchicalConfigDb: public HierarchicalConfig, public SQLiteDb } template - bool SetValueT(const key& Root, const string& Name, const T& Value) + bool SetValueT(const key& Root, const string_view& Name, const T& Value) { return ExecuteStatement(stmtSetValue, Root.get(), Name, Value); } @@ -798,16 +786,16 @@ class ColorsConfigDb: public ColorsConfig, public SQLiteDb ; } - virtual bool SetValue(const string& Name, const FarColor& Value) override + virtual bool SetValue(const string_view& Name, const FarColor& Value) override { - const auto Blob = make_blob_view(Value); + const auto Blob = bytes_view(Value); bool b = ExecuteStatement(stmtUpdateValue, Name, Blob); if (!b || !Changes()) b = ExecuteStatement(stmtInsertValue, Name, Blob); return b; } - virtual bool GetValue(const string& Name, FarColor& Value) const override + virtual bool GetValue(const string_view& Name, FarColor& Value) const override { const auto Stmt = AutoStatement(stmtGetValue); if (!Stmt->Bind(Name).Step()) @@ -984,7 +972,7 @@ class AssociationsConfigDb: public AssociationsConfig, public SQLiteDb return true; } - virtual bool SetCommand(unsigned long long id, int Type, const string& Command, bool Enabled) override + virtual bool SetCommand(unsigned long long id, int Type, const string_view& Command, bool Enabled) override { return ExecuteStatement(stmtSetCommand, id, Type, Enabled, Command); } @@ -1005,12 +993,12 @@ class AssociationsConfigDb: public AssociationsConfig, public SQLiteDb return ExecuteStatement(stmtSetWeight, weight1, id2) && ExecuteStatement(stmtSetWeight, weight2, id1); } - virtual unsigned long long AddType(unsigned long long after_id, const string& Mask, const string& Description) override + virtual unsigned long long AddType(unsigned long long after_id, const string_view& Mask, const string_view& Description) override { return ExecuteStatement(stmtReorder, after_id) && ExecuteStatement(stmtAddType, after_id, Mask, Description)? LastInsertRowID() : 0; } - virtual bool UpdateType(unsigned long long id, const string& Mask, const string& Description) override + virtual bool UpdateType(unsigned long long id, const string_view& Mask, const string_view& Description) override { return ExecuteStatement(stmtUpdateType, Mask, Description, id); } @@ -1202,12 +1190,12 @@ class PluginsCacheConfigDb: public PluginsCacheConfig, public SQLiteDb virtual void Import(const representation_source&) override {} virtual void Export(representation_destination&) const override {} - virtual unsigned long long CreateCache(const string& CacheName) override + virtual unsigned long long CreateCache(const string_view& CacheName) override { return ExecuteStatement(stmtCreateCache, CacheName)? LastInsertRowID() : 0; } - virtual unsigned long long GetCacheID(const string& CacheName) const override + virtual unsigned long long GetCacheID(const string_view& CacheName) const override { const auto Stmt = AutoStatement(stmtFindCacheName); return Stmt->Bind(CacheName).Step()? @@ -1215,7 +1203,7 @@ class PluginsCacheConfigDb: public PluginsCacheConfig, public SQLiteDb 0; } - virtual bool DeleteCache(const string& CacheName) override + virtual bool DeleteCache(const string_view& CacheName) override { //All related entries are automatically deleted because of foreign key constraints return ExecuteStatement(stmtDelCache, CacheName); @@ -1232,9 +1220,9 @@ class PluginsCacheConfigDb: public PluginsCacheConfig, public SQLiteDb return GetTextFromID(stmtGetSignature, id); } - virtual bool GetExportState(unsigned long long id, const wchar_t* ExportName) const override + virtual bool GetExportState(unsigned long long id, const string_view& ExportName) const override { - if (!*ExportName) + if (ExportName.empty()) return false; const auto Stmt = AutoStatement(stmtGetExportState); @@ -1302,27 +1290,27 @@ class PluginsCacheConfigDb: public PluginsCacheConfig, public SQLiteDb return ExecuteStatement(stmtSetPreloadState, id, Preload); } - virtual bool SetSignature(unsigned long long id, const string& Signature) override + virtual bool SetSignature(unsigned long long id, const string_view& Signature) override { return ExecuteStatement(stmtSetSignature, id, Signature); } - virtual bool SetDiskMenuItem(unsigned long long id, size_t index, const string& Text, const GUID& Guid) override + virtual bool SetDiskMenuItem(unsigned long long id, size_t index, const string_view& Text, const GUID& Guid) override { return SetMenuItem(id, DRIVE_MENU, index, Text, Guid); } - virtual bool SetPluginsMenuItem(unsigned long long id, size_t index, const string& Text, const GUID& Guid) override + virtual bool SetPluginsMenuItem(unsigned long long id, size_t index, const string_view& Text, const GUID& Guid) override { return SetMenuItem(id, PLUGINS_MENU, index, Text, Guid); } - virtual bool SetPluginsConfigMenuItem(unsigned long long id, size_t index, const string& Text, const GUID& Guid) override + virtual bool SetPluginsConfigMenuItem(unsigned long long id, size_t index, const string_view& Text, const GUID& Guid) override { return SetMenuItem(id, CONFIG_MENU, index, Text, Guid); } - virtual bool SetCommandPrefix(unsigned long long id, const string& Prefix) override + virtual bool SetCommandPrefix(unsigned long long id, const string_view& Prefix) override { return ExecuteStatement(stmtSetPrefix, id, Prefix); } @@ -1332,37 +1320,37 @@ class PluginsCacheConfigDb: public PluginsCacheConfig, public SQLiteDb return ExecuteStatement(stmtSetFlags, id, Flags); } - virtual bool SetExportState(unsigned long long id, const wchar_t* ExportName, bool Exists) override + virtual bool SetExportState(unsigned long long id, const string_view& ExportName, bool Exists) override { - return *ExportName && ExecuteStatement(stmtSetExportState, id, ExportName, Exists); + return !ExportName.empty() && ExecuteStatement(stmtSetExportState, id, ExportName, Exists); } virtual bool SetMinFarVersion(unsigned long long id, const VersionInfo *Version) override { - return ExecuteStatement(stmtSetMinFarVersion, id, make_blob_view(*Version)); + return ExecuteStatement(stmtSetMinFarVersion, id, bytes_view(*Version)); } virtual bool SetVersion(unsigned long long id, const VersionInfo *Version) override { - return ExecuteStatement(stmtSetVersion, id, make_blob_view(*Version)); + return ExecuteStatement(stmtSetVersion, id, bytes_view(*Version)); } - virtual bool SetGuid(unsigned long long id, const string& Guid) override + virtual bool SetGuid(unsigned long long id, const string_view& Guid) override { return ExecuteStatement(stmtSetGuid, id, Guid); } - virtual bool SetTitle(unsigned long long id, const string& Title) override + virtual bool SetTitle(unsigned long long id, const string_view& Title) override { return ExecuteStatement(stmtSetTitle, id, Title); } - virtual bool SetAuthor(unsigned long long id, const string& Author) override + virtual bool SetAuthor(unsigned long long id, const string_view& Author) override { return ExecuteStatement(stmtSetAuthor, id, Author); } - virtual bool SetDescription(unsigned long long id, const string& Description) override + virtual bool SetDescription(unsigned long long id, const string_view& Description) override { return ExecuteStatement(stmtSetDescription, id, Description); } @@ -1404,7 +1392,7 @@ class PluginsCacheConfigDb: public PluginsCacheConfig, public SQLiteDb return StrToGuid(Stmt->GetColText(1), Guid); } - bool SetMenuItem(unsigned long long id, MenuItemTypeEnum type, size_t index, const string& Text, const GUID& Guid) const + bool SetMenuItem(unsigned long long id, MenuItemTypeEnum type, size_t index, const string_view& Text, const GUID& Guid) const { return ExecuteStatement(stmtSetMenuItem, id, type, index, GuidToStr(Guid), Text); } @@ -1499,7 +1487,7 @@ class PluginsHotkeysConfigDb: public PluginsHotkeysConfig, public SQLiteDb return Stmt->Bind(as_underlying_type(HotKeyType)).Step() && Stmt->GetColInt(0); } - virtual string GetHotkey(const string& PluginKey, const GUID& MenuGuid, hotkey_type HotKeyType) override + virtual string GetHotkey(const string_view& PluginKey, const GUID& MenuGuid, hotkey_type HotKeyType) override { const auto Stmt = AutoStatement(stmtGetHotkey); if (!Stmt->Bind(PluginKey, GuidToStr(MenuGuid), as_underlying_type(HotKeyType)).Step()) @@ -1508,12 +1496,12 @@ class PluginsHotkeysConfigDb: public PluginsHotkeysConfig, public SQLiteDb return Stmt->GetColText(0); } - virtual bool SetHotkey(const string& PluginKey, const GUID& MenuGuid, hotkey_type HotKeyType, const string& HotKey) override + virtual bool SetHotkey(const string_view& PluginKey, const GUID& MenuGuid, hotkey_type HotKeyType, const string_view& HotKey) override { return ExecuteStatement(stmtSetHotkey, PluginKey, GuidToStr(MenuGuid), as_underlying_type(HotKeyType), HotKey); } - virtual bool DelHotkey(const string& PluginKey, const GUID& MenuGuid, hotkey_type HotKeyType) override + virtual bool DelHotkey(const string_view& PluginKey, const GUID& MenuGuid, hotkey_type HotKeyType) override { return ExecuteStatement(stmtDelHotkey, PluginKey, GuidToStr(MenuGuid), as_underlying_type(HotKeyType)); } @@ -1717,7 +1705,7 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb return ExecuteStatement(stmtDel, id); } - unsigned long long GetPrevImpl(unsigned int TypeHistory, const string& HistoryName, unsigned long long id, string& Name, const std::function& Fallback) const + unsigned long long GetPrevImpl(unsigned int TypeHistory, const string_view& HistoryName, unsigned long long id, string& Name, const std::function& Fallback) const { WaitAllAsync(); Name.clear(); @@ -1816,7 +1804,7 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb return DeleteInternal(id); } - virtual bool Enum(DWORD index, unsigned int TypeHistory, const string& HistoryName, unsigned long long *id, string &Name, history_record_type* Type, bool *Lock, unsigned long long *Time, string &strGuid, string &strFile, string &strData, bool Reverse = false) override + virtual bool Enum(DWORD index, unsigned int TypeHistory, const string_view& HistoryName, unsigned long long *id, string &Name, history_record_type* Type, bool *Lock, unsigned long long *Time, string &strGuid, string &strFile, string &strData, bool Reverse = false) override { WaitAllAsync(); auto Stmt = AutoStatement(Reverse? stmtEnumDesc : stmtEnum); @@ -1839,13 +1827,13 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb return true; } - virtual bool DeleteAndAddAsync(unsigned long long DeleteId, unsigned int TypeHistory, const string& HistoryName, const string& Name, int Type, bool Lock, string &strGuid, string &strFile, string &strData) override + virtual bool DeleteAndAddAsync(unsigned long long DeleteId, unsigned int TypeHistory, const string_view& HistoryName, const string_view& Name, int Type, bool Lock, string &strGuid, string &strFile, string &strData) override { auto item = std::make_unique(); item->DeleteId=DeleteId; item->TypeHistory=TypeHistory; - item->HistoryName=HistoryName; - item->strName=Name; + item->HistoryName = make_string(HistoryName); + item->strName = make_string(Name); item->Type=Type; item->Lock=Lock; item->strGuid=strGuid; @@ -1860,7 +1848,7 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb return true; } - virtual bool DeleteOldUnlocked(unsigned int TypeHistory, const string& HistoryName, int DaysToKeep, int MinimumEntries) override + virtual bool DeleteOldUnlocked(unsigned int TypeHistory, const string_view& HistoryName, int DaysToKeep, int MinimumEntries) override { WaitAllAsync(); const auto older = GetCurrentUTCTimeInUI64() - DaysToUI64(DaysToKeep); @@ -1882,7 +1870,7 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb return true; } - virtual bool GetNewest(unsigned int TypeHistory, const string& HistoryName, string& Name) override + virtual bool GetNewest(unsigned int TypeHistory, const string_view& HistoryName, string& Name) override { WaitAllAsync(); const auto Stmt = AutoStatement(stmtGetNewestName); @@ -1919,7 +1907,7 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb return true; } - virtual DWORD Count(unsigned int TypeHistory, const string& HistoryName) override + virtual DWORD Count(unsigned int TypeHistory, const string_view& HistoryName) override { WaitAllAsync(); const auto Stmt = AutoStatement(stmtCount); @@ -1939,13 +1927,13 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb return Stmt->Bind(id).Step() && Stmt->GetColInt(0) != 0; } - virtual bool DeleteAllUnlocked(unsigned int TypeHistory, const string& HistoryName) override + virtual bool DeleteAllUnlocked(unsigned int TypeHistory, const string_view& HistoryName) override { WaitAllAsync(); return ExecuteStatement(stmtDelUnlocked, TypeHistory, HistoryName); } - virtual unsigned long long GetNext(unsigned int TypeHistory, const string& HistoryName, unsigned long long id, string& Name) override + virtual unsigned long long GetNext(unsigned int TypeHistory, const string_view& HistoryName, unsigned long long id, string& Name) override { WaitAllAsync(); Name.clear(); @@ -1961,23 +1949,23 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb return Stmt->GetColInt64(0); } - virtual unsigned long long GetPrev(unsigned int TypeHistory, const string& HistoryName, unsigned long long id, string& Name) override + virtual unsigned long long GetPrev(unsigned int TypeHistory, const string_view& HistoryName, unsigned long long id, string& Name) override { return GetPrevImpl(TypeHistory, HistoryName, id, Name, [&]() { return Get(id, Name)? id : 0; }); } - virtual unsigned long long CyclicGetPrev(unsigned int TypeHistory, const string& HistoryName, unsigned long long id, string& Name) override + virtual unsigned long long CyclicGetPrev(unsigned int TypeHistory, const string_view& HistoryName, unsigned long long id, string& Name) override { return GetPrevImpl(TypeHistory, HistoryName, id, Name, [&]() { return 0; }); } - virtual unsigned long long SetEditorPos(const string& Name, int Line, int LinePos, int ScreenLine, int LeftPos, uintptr_t CodePage) override + virtual unsigned long long SetEditorPos(const string_view& Name, int Line, int LinePos, int ScreenLine, int LeftPos, uintptr_t CodePage) override { WaitCommitAsync(); return ExecuteStatement(stmtSetEditorPos, Name, GetCurrentUTCTimeInUI64(), Line, LinePos, ScreenLine, LeftPos, CodePage)? LastInsertRowID() : 0; } - virtual unsigned long long GetEditorPos(const string& Name, int *Line, int *LinePos, int *ScreenLine, int *LeftPos, uintptr_t *CodePage) override + virtual unsigned long long GetEditorPos(const string_view& Name, int *Line, int *LinePos, int *ScreenLine, int *LeftPos, uintptr_t *CodePage) override { WaitCommitAsync(); const auto Stmt = AutoStatement(stmtGetEditorPos); @@ -2012,13 +2000,13 @@ class HistoryConfigCustom: public HistoryConfig, public SQLiteDb return true; } - virtual unsigned long long SetViewerPos(const string& Name, long long FilePos, long long LeftPos, int Hex_Wrap, uintptr_t CodePage) override + virtual unsigned long long SetViewerPos(const string_view& Name, long long FilePos, long long LeftPos, int Hex_Wrap, uintptr_t CodePage) override { WaitCommitAsync(); return ExecuteStatement(stmtSetViewerPos, Name, GetCurrentUTCTimeInUI64(), FilePos, LeftPos, Hex_Wrap, CodePage)? LastInsertRowID() : 0; } - virtual unsigned long long GetViewerPos(const string& Name, long long *FilePos, long long *LeftPos, int *Hex, uintptr_t *CodePage) override + virtual unsigned long long GetViewerPos(const string_view& Name, long long *FilePos, long long *LeftPos, int *Hex, uintptr_t *CodePage) override { WaitCommitAsync(); const auto Stmt = AutoStatement(stmtGetViewerPos); @@ -2222,9 +2210,9 @@ enum dbcheck: int CHECK_PANELMODES = bit(3), }; -HierarchicalConfigUniquePtr config_provider::CreatePluginsConfig(const string& guid, bool Local) +HierarchicalConfigUniquePtr config_provider::CreatePluginsConfig(const string_view& guid, bool Local) { - return CreateHierarchicalConfig(CHECK_NONE, L"PluginsData\\" + guid + L".db", encoding::utf8::get_bytes(guid).data(), Local, true); + return CreateHierarchicalConfig(CHECK_NONE, concat(L"PluginsData\\"_sv, guid, L".db"_sv), encoding::utf8::get_bytes(guid).data(), Local, true); } HierarchicalConfigUniquePtr config_provider::CreateFiltersConfig() diff --git a/far/configdb.hpp b/far/configdb.hpp index 24fd0e3214..6b98c7d088 100644 --- a/far/configdb.hpp +++ b/far/configdb.hpp @@ -59,25 +59,18 @@ class GeneralConfig: public representable, virtual public transactional public: virtual ~GeneralConfig() override = default; - virtual bool SetValue(const string& Key, const string& Name, const string& Value) = 0; - virtual bool SetValue(const string& Key, const string& Name, const wchar_t* Value) = 0; - virtual bool SetValue(const string& Key, const string& Name, unsigned long long Value) = 0; - virtual bool SetValue(const string& Key, const string& Name, const blob_view& Value) = 0; - template::value && !std::is_integral::value)> - bool SetValue(const string& Key, const string& Name, const T& Value) - { - static_assert(std::is_pod::value); - return SetValue(Key, Name, &Value, sizeof(Value)); - } + virtual bool SetValue(const string_view& Key, const string_view& Name, const string_view& Value) = 0; + virtual bool SetValue(const string_view& Key, const string_view& Name, unsigned long long Value) = 0; + virtual bool SetValue(const string_view& Key, const string_view& Name, const bytes_view& Value) = 0; - virtual bool GetValue(const string& Key, const string& Name, bool& Value, bool Default) const = 0; - virtual bool GetValue(const string& Key, const string& Name, long long& Value, long long Default) const = 0; - virtual bool GetValue(const string& Key, const string& Name, string& Value, const string& Default) const = 0; - virtual bool GetValue(const string& Key, const string& Name, string& Value, const wchar_t *Default) const = 0; + virtual bool GetValue(const string_view& Key, const string_view& Name, bool& Value, bool Default) const = 0; + virtual bool GetValue(const string_view& Key, const string_view& Name, long long& Value, long long Default) const = 0; + virtual bool GetValue(const string_view& Key, const string_view& Name, string& Value, const string& Default) const = 0; + virtual bool GetValue(const string_view& Key, const string_view& Name, string& Value, const wchar_t* Default) const = 0; - virtual bool DeleteValue(const string& Key, const string& Name) = 0; - virtual bool EnumValues(const string& Key, DWORD Index, string &strName, string &strValue) const = 0; - virtual bool EnumValues(const string& Key, DWORD Index, string &strName, long long& Value) const = 0; + virtual bool DeleteValue(const string_view& Key, const string_view& Name) = 0; + virtual bool EnumValues(const string_view& Key, DWORD Index, string& strName, string& strValue) const = 0; + virtual bool EnumValues(const string_view& Key, DWORD Index, string& strName, long long& Value) const = 0; template auto ValuesEnumerator(const string&&) const = delete; @@ -101,48 +94,35 @@ class HierarchicalConfig: public representable, virtual public transactional, pu class key: public conditional { public: + explicit key(unsigned long long Key): m_Key(Key) {} + unsigned long long get() const { return m_Key; } bool operator!() const noexcept { return m_Key == 0; } private: - friend class HierarchicalConfig; - - explicit key(unsigned long long Key): m_Key(Key) {} unsigned long long m_Key; }; - static key root_key() { return make_key(0); } + static key root_key() { return key(0); } virtual void AsyncFinish() = 0; - virtual key CreateKey(const key& Root, const string& Name, const string* Description = nullptr) = 0; - virtual key FindByName(const key& Root, const string& Name) const = 0; - virtual bool SetKeyDescription(const key& Root, const string& Description) = 0; - - virtual bool SetValue(const key& Root, const string& Name, const string& Value) = 0; - virtual bool SetValue(const key& Root, const string& Name, const wchar_t* Value) = 0; - virtual bool SetValue(const key& Root, const string& Name, unsigned long long Value) = 0; - virtual bool SetValue(const key& Root, const string& Name, const blob_view& Value) = 0; - template::value && !std::is_integral::value)> - bool SetValue(const key& Root, const string& Name, const T& Value) - { - return SetValue(Root, Name, make_blob_view(Value)); - } + virtual key CreateKey(const key& Root, const string_view& Name, const string* Description = nullptr) = 0; + virtual key FindByName(const key& Root, const string_view& Name) const = 0; + virtual bool SetKeyDescription(const key& Root, const string_view& Description) = 0; - virtual bool GetValue(const key& Root, const string& Name, unsigned long long& Value) const = 0; - virtual bool GetValue(const key& Root, const string& Name, string &strValue) const = 0; - virtual bool GetValue(const key& Root, const string& Name, writable_blob_view& Value) const = 0; - template::value && !std::is_integral::value)> - bool GetValue(const key& Root, const string& Name, T& Value) const - { - static_assert(std::is_pod::value); - writable_blob_view Blob(&Value, sizeof(Value)); - return GetValue(Root, Name, Blob); - } + virtual bool SetValue(const key& Root, const string_view& Name, const string_view& Value) = 0; + virtual bool SetValue(const key& Root, const string_view& Name, unsigned long long Value) = 0; + virtual bool SetValue(const key& Root, const string_view& Name, const bytes_view& Value) = 0; + + virtual bool GetValue(const key& Root, const string_view& Name, unsigned long long& Value) const = 0; + virtual bool GetValue(const key& Root, const string_view& Name, string& strValue) const = 0; + virtual bool GetValue(const key& Root, const string_view& Name, bytes& Value) const = 0; + bool GetValue(const key& Root, const string_view& Name, bytes&& Value) const { return GetValue(Root, Name, Value); } virtual bool DeleteKeyTree(const key& Key) = 0; - virtual bool DeleteValue(const key& Root, const string& Name) = 0; - virtual bool EnumKeys(const key& Root, DWORD Index, string &strName) const = 0; - virtual bool EnumValues(const key& Root, DWORD Index, string &strName, int& Type) const = 0; + virtual bool DeleteValue(const key& Root, const string_view& Name) = 0; + virtual bool EnumKeys(const key& Root, DWORD Index, string& strName) const = 0; + virtual bool EnumValues(const key& Root, DWORD Index, string& strName, int& Type) const = 0; virtual bool Flush() = 0; void KeysEnumerator(const key&&) const = delete; @@ -168,8 +148,6 @@ class HierarchicalConfig: public representable, virtual public transactional, pu protected: HierarchicalConfig() = default; virtual ~HierarchicalConfig() override = default; - - static key make_key(unsigned long long Key) { return key(Key); } }; namespace detail @@ -186,8 +164,8 @@ class ColorsConfig: public representable, virtual public transactional { public: virtual ~ColorsConfig() override = default; - virtual bool SetValue(const string& Name, const FarColor& Value) = 0; - virtual bool GetValue(const string& Name, FarColor& Value) const = 0; + virtual bool SetValue(const string_view& Name, const FarColor& Value) = 0; + virtual bool GetValue(const string_view& Name, FarColor& Value) const = 0; protected: ColorsConfig() = default; @@ -202,10 +180,10 @@ class AssociationsConfig: public representable, virtual public transactional { virtual bool GetMask(unsigned long long id, string &strMask) = 0; virtual bool GetDescription(unsigned long long id, string &strDescription) = 0; virtual bool GetCommand(unsigned long long id, int Type, string &strCommand, bool *Enabled=nullptr) = 0; - virtual bool SetCommand(unsigned long long id, int Type, const string& Command, bool Enabled) = 0; + virtual bool SetCommand(unsigned long long id, int Type, const string_view& Command, bool Enabled) = 0; virtual bool SwapPositions(unsigned long long id1, unsigned long long id2) = 0; - virtual unsigned long long AddType(unsigned long long after_id, const string& Mask, const string& Description) = 0; - virtual bool UpdateType(unsigned long long id, const string& Mask, const string& Description) = 0; + virtual unsigned long long AddType(unsigned long long after_id, const string_view& Mask, const string_view& Description) = 0; + virtual bool UpdateType(unsigned long long id, const string_view& Mask, const string_view& Description) = 0; virtual bool DelType(unsigned long long id) = 0; auto MasksEnumerator() @@ -234,12 +212,12 @@ class PluginsCacheConfig: public representable, virtual public transactional { public: virtual ~PluginsCacheConfig() override = default; - virtual unsigned long long CreateCache(const string& CacheName) = 0; - virtual unsigned long long GetCacheID(const string& CacheName) const = 0; - virtual bool DeleteCache(const string& CacheName) = 0; + virtual unsigned long long CreateCache(const string_view& CacheName) = 0; + virtual unsigned long long GetCacheID(const string_view& CacheName) const = 0; + virtual bool DeleteCache(const string_view& CacheName) = 0; virtual bool IsPreload(unsigned long long id) const = 0; virtual string GetSignature(unsigned long long id) const = 0; - virtual bool GetExportState(unsigned long long id, const wchar_t* ExportName) const = 0; + virtual bool GetExportState(unsigned long long id, const string_view& ExportName) const = 0; virtual string GetGuid(unsigned long long id) const = 0; virtual string GetTitle(unsigned long long id) const = 0; virtual string GetAuthor(unsigned long long id) const = 0; @@ -252,19 +230,19 @@ class PluginsCacheConfig: public representable, virtual public transactional virtual string GetCommandPrefix(unsigned long long id) const = 0; virtual unsigned long long GetFlags(unsigned long long id) const = 0; virtual bool SetPreload(unsigned long long id, bool Preload) = 0; - virtual bool SetSignature(unsigned long long id, const string& Signature) = 0; - virtual bool SetDiskMenuItem(unsigned long long id, size_t index, const string& Text, const GUID& Guid) = 0; - virtual bool SetPluginsMenuItem(unsigned long long id, size_t index, const string& Text, const GUID& Guid) = 0; - virtual bool SetPluginsConfigMenuItem(unsigned long long id, size_t index, const string& Text, const GUID& Guid) = 0; - virtual bool SetCommandPrefix(unsigned long long id, const string& Prefix) = 0; + virtual bool SetSignature(unsigned long long id, const string_view& Signature) = 0; + virtual bool SetDiskMenuItem(unsigned long long id, size_t index, const string_view& Text, const GUID& Guid) = 0; + virtual bool SetPluginsMenuItem(unsigned long long id, size_t index, const string_view& Text, const GUID& Guid) = 0; + virtual bool SetPluginsConfigMenuItem(unsigned long long id, size_t index, const string_view& Text, const GUID& Guid) = 0; + virtual bool SetCommandPrefix(unsigned long long id, const string_view& Prefix) = 0; virtual bool SetFlags(unsigned long long id, unsigned long long Flags) = 0; - virtual bool SetExportState(unsigned long long id, const wchar_t* ExportName, bool Exists) = 0; + virtual bool SetExportState(unsigned long long id, const string_view& ExportName, bool Exists) = 0; virtual bool SetMinFarVersion(unsigned long long id, const VersionInfo *Version) = 0; virtual bool SetVersion(unsigned long long id, const VersionInfo *Version) = 0; - virtual bool SetGuid(unsigned long long id, const string& Guid) = 0; - virtual bool SetTitle(unsigned long long id, const string& Title) = 0; - virtual bool SetAuthor(unsigned long long id, const string& Author) = 0; - virtual bool SetDescription(unsigned long long id, const string& Description) = 0; + virtual bool SetGuid(unsigned long long id, const string_view& Guid) = 0; + virtual bool SetTitle(unsigned long long id, const string_view& Title) = 0; + virtual bool SetAuthor(unsigned long long id, const string_view& Author) = 0; + virtual bool SetDescription(unsigned long long id, const string_view& Description) = 0; virtual bool EnumPlugins(DWORD index, string &CacheName) const = 0; virtual bool DiscardCache() = 0; virtual bool IsCacheEmpty() const = 0; @@ -285,9 +263,9 @@ class PluginsHotkeysConfig: public representable, virtual public transactional public: virtual ~PluginsHotkeysConfig() override = default; virtual bool HotkeysPresent(hotkey_type HotKeyType) = 0; - virtual string GetHotkey(const string& PluginKey, const GUID& MenuGuid, hotkey_type HotKeyType) = 0; - virtual bool SetHotkey(const string& PluginKey, const GUID& MenuGuid, hotkey_type HotKeyType, const string& HotKey) = 0; - virtual bool DelHotkey(const string& PluginKey, const GUID& MenuGuid, hotkey_type HotKeyType) = 0; + virtual string GetHotkey(const string_view& PluginKey, const GUID& MenuGuid, hotkey_type HotKeyType) = 0; + virtual bool SetHotkey(const string_view& PluginKey, const GUID& MenuGuid, hotkey_type HotKeyType, const string_view& HotKey) = 0; + virtual bool DelHotkey(const string_view& PluginKey, const GUID& MenuGuid, hotkey_type HotKeyType) = 0; protected: PluginsHotkeysConfig() = default; @@ -301,29 +279,29 @@ class HistoryConfig: public representable, virtual public transactional virtual ~HistoryConfig() override = default; //command,view,edit,folder,dialog history - virtual bool Enum(DWORD index, unsigned int TypeHistory, const string& HistoryName, unsigned long long *id, string &strName, history_record_type* Type, bool *Lock, unsigned long long *Time, string &strGuid, string &strFile, string &strData, bool Reverse=false) = 0; + virtual bool Enum(DWORD index, unsigned int TypeHistory, const string_view& HistoryName, unsigned long long *id, string &strName, history_record_type* Type, bool *Lock, unsigned long long *Time, string &strGuid, string &strFile, string &strData, bool Reverse=false) = 0; virtual bool Delete(unsigned long long id) = 0; - virtual bool DeleteAndAddAsync(unsigned long long DeleteId, unsigned int TypeHistory, const string& HistoryName, const string& strName, int Type, bool Lock, string &strGuid, string &strFile, string &strData) = 0; - virtual bool DeleteOldUnlocked(unsigned int TypeHistory, const string& HistoryName, int DaysToKeep, int MinimumEntries) = 0; + virtual bool DeleteAndAddAsync(unsigned long long DeleteId, unsigned int TypeHistory, const string_view& HistoryName, const string_view& strName, int Type, bool Lock, string &strGuid, string &strFile, string &strData) = 0; + virtual bool DeleteOldUnlocked(unsigned int TypeHistory, const string_view& HistoryName, int DaysToKeep, int MinimumEntries) = 0; virtual bool EnumLargeHistories(DWORD index, unsigned int TypeHistory, int MinimumEntries, string& strHistoryName) = 0; - virtual bool GetNewest(unsigned int TypeHistory, const string& HistoryName, string &strName) = 0; + virtual bool GetNewest(unsigned int TypeHistory, const string_view& HistoryName, string &strName) = 0; virtual bool Get(unsigned long long id, string &strName) = 0; virtual bool Get(unsigned long long id, string &strName, history_record_type& Type, string &strGuid, string &strFile, string &strData) = 0; - virtual DWORD Count(unsigned int TypeHistory, const string& HistoryName) = 0; + virtual DWORD Count(unsigned int TypeHistory, const string_view& HistoryName) = 0; virtual bool FlipLock(unsigned long long id) = 0; virtual bool IsLocked(unsigned long long id) = 0; - virtual bool DeleteAllUnlocked(unsigned int TypeHistory, const string& HistoryName) = 0; - virtual unsigned long long GetNext(unsigned int TypeHistory, const string& HistoryName, unsigned long long id, string &strName) = 0; - virtual unsigned long long GetPrev(unsigned int TypeHistory, const string& HistoryName, unsigned long long id, string &strName) = 0; - virtual unsigned long long CyclicGetPrev(unsigned int TypeHistory, const string& HistoryName, unsigned long long id, string &strName) = 0; + virtual bool DeleteAllUnlocked(unsigned int TypeHistory, const string_view& HistoryName) = 0; + virtual unsigned long long GetNext(unsigned int TypeHistory, const string_view& HistoryName, unsigned long long id, string &strName) = 0; + virtual unsigned long long GetPrev(unsigned int TypeHistory, const string_view& HistoryName, unsigned long long id, string &strName) = 0; + virtual unsigned long long CyclicGetPrev(unsigned int TypeHistory, const string_view& HistoryName, unsigned long long id, string &strName) = 0; //view,edit file positions and bookmarks history - virtual unsigned long long SetEditorPos(const string& Name, int Line, int LinePos, int ScreenLine, int LeftPos, uintptr_t CodePage) = 0; - virtual unsigned long long GetEditorPos(const string& Name, int *Line, int *LinePos, int *ScreenLine, int *LeftPos, uintptr_t *CodePage) = 0; + virtual unsigned long long SetEditorPos(const string_view& Name, int Line, int LinePos, int ScreenLine, int LeftPos, uintptr_t CodePage) = 0; + virtual unsigned long long GetEditorPos(const string_view& Name, int *Line, int *LinePos, int *ScreenLine, int *LeftPos, uintptr_t *CodePage) = 0; virtual bool SetEditorBookmark(unsigned long long id, size_t i, int Line, int LinePos, int ScreenLine, int LeftPos) = 0; virtual bool GetEditorBookmark(unsigned long long id, size_t i, int *Line, int *LinePos, int *ScreenLine, int *LeftPos) = 0; - virtual unsigned long long SetViewerPos(const string& Name, long long FilePos, long long LeftPos, int Hex_Wrap, uintptr_t CodePage) = 0; - virtual unsigned long long GetViewerPos(const string& Name, long long *FilePos, long long *LeftPos, int *Hex, uintptr_t *CodePage) = 0; + virtual unsigned long long SetViewerPos(const string_view& Name, long long FilePos, long long LeftPos, int Hex_Wrap, uintptr_t CodePage) = 0; + virtual unsigned long long GetViewerPos(const string_view& Name, long long *FilePos, long long *LeftPos, int *Hex, uintptr_t *CodePage) = 0; virtual bool SetViewerBookmark(unsigned long long id, size_t i, long long FilePos, long long LeftPos) = 0; virtual bool GetViewerBookmark(unsigned long long id, size_t i, long long *FilePos, long long *LeftPos) = 0; virtual void DeleteOldPositions(int DaysToKeep, int MinimumEntries) = 0; @@ -388,7 +366,7 @@ class config_provider: noncopyable const auto& HistoryCfg() const { return m_HistoryCfg; } const auto& HistoryCfgMem() const { return m_HistoryCfgMem; } - HierarchicalConfigUniquePtr CreatePluginsConfig(const string& guid, bool Local=false); + HierarchicalConfigUniquePtr CreatePluginsConfig(const string_view& guid, bool Local=false); HierarchicalConfigUniquePtr CreateFiltersConfig(); HierarchicalConfigUniquePtr CreateHighlightConfig(); HierarchicalConfigUniquePtr CreateShortcutsConfig(); diff --git a/far/console.cpp b/far/console.cpp index 4ca89c6000..2da1957ac9 100644 --- a/far/console.cpp +++ b/far/console.cpp @@ -398,8 +398,8 @@ virtual bool Write(const string_view& Str) const override DWORD Mode; return GetMode(OutputHandle, Mode)? - WriteConsole(OutputHandle, Str.data(), static_cast(Str.size()), &NumberOfCharsWritten, nullptr) != FALSE : - WriteFile(OutputHandle, Str.data(), static_cast(Str.size() * sizeof(wchar_t)), &NumberOfCharsWritten, nullptr) != FALSE; + WriteConsole(OutputHandle, Str.raw_data(), static_cast(Str.size()), &NumberOfCharsWritten, nullptr) != FALSE : + WriteFile(OutputHandle, Str.raw_data(), static_cast(Str.size() * sizeof(wchar_t)), &NumberOfCharsWritten, nullptr) != FALSE; } virtual bool Commit() const override @@ -494,7 +494,7 @@ virtual std::unordered_map> GetAllAli std::vector AliasesBuffer; for (const auto& ExeToken: enum_substrings(ExeBuffer.data())) { - const auto ExeNamePtr = const_cast(ExeToken.data()); + const auto ExeNamePtr = const_cast(ExeToken.raw_data()); const auto AliasesLength = GetConsoleAliasesLength(ExeNamePtr); AliasesBuffer.resize(AliasesLength / sizeof(wchar_t) + 1); // +1 for double \0 if (!GetConsoleAliases(AliasesBuffer.data(), AliasesLength, ExeNamePtr)) diff --git a/far/copy.cpp b/far/copy.cpp index 2b5194dab9..511a87a07e 100644 --- a/far/copy.cpp +++ b/far/copy.cpp @@ -3684,11 +3684,9 @@ int ShellCopy::ShellSystemCopy(const string& SrcName,const string& DestName,cons { return CallbackData->Owner->CopyProgressRoutine(TotalFileSize.QuadPart, TotalBytesTransferred.QuadPart, StreamSize.QuadPart, StreamBytesTransferred.QuadPart, StreamNumber, CallbackReason, SourceFile, DestinationFile); } - catch(...) - { - CallbackData->ExceptionPtr = std::current_exception(); - return PROGRESS_CANCEL; - } + CATCH_AND_SAVE_EXCEPTION_TO(CallbackData->ExceptionPtr) + + return PROGRESS_CANCEL; } }; diff --git a/far/elevation.cpp b/far/elevation.cpp index adc8949f4f..ad791c6178 100644 --- a/far/elevation.cpp +++ b/far/elevation.cpp @@ -150,7 +150,7 @@ void elevation::WriteArg(const T& Data) const throw MAKE_FAR_EXCEPTION(L"Pipe write error"); } -void elevation::WriteArg(const blob_view& Data) const +void elevation::WriteArg(const bytes_view& Data) const { if (!pipe::Write(m_Pipe, Data.data(), Data.size())) throw MAKE_FAR_EXCEPTION(L"Pipe write error"); @@ -194,7 +194,7 @@ auto elevation::execute(lng Why, const string& Object, T Fallback, const F1& Pri { return ElevatedHandler(); } - catch(const far_exception&) + catch (const far_exception&) { // Something went really bad, it's better to stop any further attempts TerminateChildProcess(); @@ -677,8 +677,8 @@ int elevation::fMoveToRecycleBin(SHFILEOPSTRUCT& FileOpStruct) [&] { Write(C_FUNCTION_MOVETORECYCLEBIN, FileOpStruct, - make_blob_view(FileOpStruct.pFrom, (wcslen(FileOpStruct.pFrom) + 1 + 1) * sizeof(wchar_t)), // achtung! +1 - make_blob_view(FileOpStruct.pTo, FileOpStruct.pTo ? (wcslen(FileOpStruct.pTo) + 1 + 1) * sizeof(wchar_t) : 0)); // achtung! +1 + bytes_view(FileOpStruct.pFrom, (wcslen(FileOpStruct.pFrom) + 1 + 1) * sizeof(wchar_t)), // achtung! +1 + bytes_view(FileOpStruct.pTo, FileOpStruct.pTo ? (wcslen(FileOpStruct.pTo) + 1 + 1) * sizeof(wchar_t) : 0)); // achtung! +1 Read(FileOpStruct.fAnyOperationsAborted); // achtung! no "last error" here @@ -1098,11 +1098,9 @@ class elevated:noncopyable Context->Process(Result); } } - catch(...) - { - Param->ExceptionPtr = std::current_exception(); - return PROGRESS_CANCEL; - } + CATCH_AND_SAVE_EXCEPTION_TO(Param->ExceptionPtr) + + return PROGRESS_CANCEL; } bool Process(int Command) const @@ -1136,7 +1134,7 @@ class elevated:noncopyable std::invoke(Handlers[Command], this); return m_Active; } - catch(...) + catch (...) { // TODO: log return false; diff --git a/far/elevation.hpp b/far/elevation.hpp index 61e0bb9b91..34aee937f9 100644 --- a/far/elevation.hpp +++ b/far/elevation.hpp @@ -100,7 +100,7 @@ class elevation: noncopyable, public singleton template void WriteArg(const T& Data) const; - void WriteArg(const blob_view& Data) const; + void WriteArg(const bytes_view& Data) const; void RetrieveLastError() const; diff --git a/far/encoding.cpp b/far/encoding.cpp index 61580c0e44..1a50a7654c 100644 --- a/far/encoding.cpp +++ b/far/encoding.cpp @@ -96,11 +96,9 @@ class system_codepages_enumerator return TRUE; } - catch(...) - { - context->m_ExceptionPtr = std::current_exception(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(context->m_ExceptionPtr); + + return FALSE; } }; diff --git a/far/encoding.hpp b/far/encoding.hpp index 95c15abd4c..13fed19d6a 100644 --- a/far/encoding.hpp +++ b/far/encoding.hpp @@ -44,7 +44,7 @@ namespace encoding inline auto get_bytes(uintptr_t Codepage, const string_view& Data, char* Buffer, size_t BufferSize, bool* UsedDefaultChar = nullptr) { - return get_bytes(Codepage, Data.data(), Data.size(), Buffer, BufferSize, UsedDefaultChar); + return get_bytes(Codepage, Data.raw_data(), Data.size(), Buffer, BufferSize, UsedDefaultChar); } //------------------------------------------------------------------------- @@ -57,7 +57,7 @@ namespace encoding template auto get_bytes(uintptr_t Codepage, const string_view& Data, T& Buffer, bool* UsedDefaultChar = nullptr) { - return get_bytes(Codepage, Data.data(), Data.size(), std::data(Buffer), std::size(Buffer), UsedDefaultChar); + return get_bytes(Codepage, Data.raw_data(), Data.size(), std::data(Buffer), std::size(Buffer), UsedDefaultChar); } //------------------------------------------------------------------------- @@ -65,7 +65,7 @@ namespace encoding inline auto get_bytes(uintptr_t Codepage, const string_view& Data, bool* UsedDefaultChar = nullptr) { - return get_bytes(Codepage, Data.data(), Data.size(), UsedDefaultChar); + return get_bytes(Codepage, Data.raw_data(), Data.size(), UsedDefaultChar); } //------------------------------------------------------------------------- @@ -76,7 +76,7 @@ namespace encoding inline auto get_bytes_count(uintptr_t Codepage, const string_view& Data) { - return get_bytes_count(Codepage, Data.data(), Data.size()); + return get_bytes_count(Codepage, Data.raw_data(), Data.size()); } //------------------------------------------------------------------------- @@ -84,14 +84,14 @@ namespace encoding inline auto get_chars(uintptr_t Codepage, const basic_string_view& Data, wchar_t* Buffer, size_t BufferSize) { - return get_chars(Codepage, Data.data(), Data.size(), Buffer, BufferSize); + return get_chars(Codepage, Data.raw_data(), Data.size(), Buffer, BufferSize); } //------------------------------------------------------------------------- template auto get_chars(uintptr_t Codepage, const basic_string_view& Data, Y& Buffer) { - return get_chars(Codepage, Data.data(), Data.size(), std::data(Buffer), std::size(Buffer)); + return get_chars(Codepage, Data.raw_data(), Data.size(), std::data(Buffer), std::size(Buffer)); } template @@ -105,7 +105,7 @@ namespace encoding inline auto get_chars(uintptr_t Codepage, const basic_string_view& Data) { - return get_chars(Codepage, Data.data(), Data.size()); + return get_chars(Codepage, Data.raw_data(), Data.size()); } //------------------------------------------------------------------------- @@ -116,7 +116,7 @@ namespace encoding inline auto get_chars_count(uintptr_t Codepage, const basic_string_view& Data) { - return get_chars_count(Codepage, Data.data(), Data.size()); + return get_chars_count(Codepage, Data.raw_data(), Data.size()); } #undef NOT_PTR diff --git a/far/exception.cpp b/far/exception.cpp index be4c044c28..361d5a887a 100644 --- a/far/exception.cpp +++ b/far/exception.cpp @@ -34,6 +34,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "exception.hpp" #include "imports.hpp" #include "encoding.hpp" +#include "tracer.hpp" error_codes::error_codes(): Win32Error(GetLastError()), @@ -53,6 +54,18 @@ far_exception::far_exception(const string& Message, const char* Function, const { } +far_exception::far_exception(const string& Message, std::vector&& Stack, const char* Function, const char* File, int Line): + exception_impl(Message, Function, File, Line), + std::runtime_error(encoding::utf8::get_bytes(get_full_message())), + m_Stack(std::move(Stack)) +{ +} + +const std::vector& far_exception::get_stack() const +{ + return m_Stack; +} + exception_context::exception_context(DWORD Code, const EXCEPTION_POINTERS* Pointers, bool ResumeThread): m_Code(Code), @@ -85,15 +98,21 @@ exception_context::~exception_context() } -std::exception_ptr& GlobalExceptionPtr() +std::exception_ptr CurrentException() { - static std::exception_ptr ExceptionPtr; - return ExceptionPtr; + return std::current_exception(); } -void StoreGlobalException() +std::exception_ptr CurrentException(const std::exception& e) { - GlobalExceptionPtr() = std::current_exception(); + try + { + std::throw_with_nested(MAKE_FAR_EXCEPTION(L"->", tracer::get(&e))); + } + catch (...) + { + return CurrentException(); + } } void RethrowIfNeeded(std::exception_ptr& Ptr) diff --git a/far/exception.hpp b/far/exception.hpp index 4706326f8d..13e9171284 100644 --- a/far/exception.hpp +++ b/far/exception.hpp @@ -69,6 +69,11 @@ class far_exception: public detail::exception_impl, public std::runtime_error { public: far_exception(const string& Message, const char* Function, const char* File, int Line); + far_exception(const string& Message, std::vector&& Stack, const char* Function, const char* File, int Line); + const std::vector& get_stack() const; + +private: + std::vector m_Stack; }; #define MAKE_EXCEPTION(ExceptionType, ...) ExceptionType(__VA_ARGS__, __FUNCTION__, __FILE__, __LINE__) @@ -113,8 +118,18 @@ class seh_exception: public std::exception }; -std::exception_ptr& GlobalExceptionPtr(); -void StoreGlobalException(); +std::exception_ptr CurrentException(); +std::exception_ptr CurrentException(const std::exception& e); void RethrowIfNeeded(std::exception_ptr& Ptr); +#define CATCH_AND_SAVE_EXCEPTION_TO(ExceptionPtr) \ + catch (const std::exception& e) \ + { \ + ExceptionPtr = CurrentException(e); \ + } \ + catch (...) \ + { \ + ExceptionPtr = CurrentException(); \ + } + #endif // EXCEPTION_HPP_2CD5B7D1_D39C_4CAF_858A_62496C9221DF diff --git a/far/far.vcxproj b/far/far.vcxproj index 63da7bbaba..6c817c1337 100644 --- a/far/far.vcxproj +++ b/far/far.vcxproj @@ -326,7 +326,7 @@ cl /nologo /c /Fo"$(IntDir)%(Filename)_c++.testobj" /TP api_test.c - + diff --git a/far/far.vcxproj.filters b/far/far.vcxproj.filters index 722cb81c40..b7faa5f4e4 100644 --- a/far/far.vcxproj.filters +++ b/far/far.vcxproj.filters @@ -961,9 +961,6 @@ Header Files - - Header Files\common - Header Files\common @@ -1000,6 +997,9 @@ Header Files\common + + Header Files\common + diff --git a/far/farexcpt.cpp b/far/farexcpt.cpp index 8236142d8f..74ac976655 100644 --- a/far/farexcpt.cpp +++ b/far/farexcpt.cpp @@ -80,10 +80,19 @@ enum exception_dialog ed_last_button = ed_button_ignore }; -static void ShowStackTrace(std::vector&& Symbols) +static void ShowStackTrace(std::vector&& Symbols, const std::vector* NestedStack) { if (Global && Global->WindowManager && !Global->WindowManager->ManagerIsDown()) { + if (NestedStack && !NestedStack->empty()) + { + Symbols.reserve(Symbols.size() + 3 + NestedStack->size()); + Symbols.emplace_back(40, L'-'); + Symbols.emplace_back(L"Nested stack:"); + Symbols.emplace_back(40, L'-'); + Symbols.insert(Symbols.end(), ALL_CONST_RANGE(*NestedStack)); + } + Message(MSG_WARNING | MSG_LEFTALIGN, msg(lng::MExcTrappedException), std::move(Symbols), @@ -113,6 +122,8 @@ static bool write_minidump(const exception_context& Context) return Imports().MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), DumpFile.handle().native_handle(), MiniDumpWithFullMemory, &Mei, nullptr, nullptr) != FALSE; } +using dialog_data_type = std::pair*>; + intptr_t ExcDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,void* Param2) { switch (Msg) @@ -156,16 +167,16 @@ intptr_t ExcDlgProc(Dialog* Dlg,intptr_t Msg,intptr_t Param1,void* Param2) case DN_CLOSE: { - const auto& Context = *reinterpret_cast(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); + const auto& DialogData = *reinterpret_cast(Dlg->SendMessage(DM_GETDLGDATA, 0, nullptr)); switch (Param1) { case ed_button_stack: - ShowStackTrace(tracer::get(Context)); + ShowStackTrace(tracer::get(*DialogData.first), DialogData.second); return FALSE; case ed_button_minidump: - write_minidump(Context); + write_minidump(*DialogData.first); return FALSE; } } @@ -184,12 +195,13 @@ enum reply reply_ignore, }; -static reply ExcDialog(const string& ModuleName, LPCWSTR Exception, const exception_context& Context, const wchar_t* Function, const Plugin* PluginModule) +static reply ExcDialog(const string& ModuleName, LPCWSTR Exception, const exception_context& Context, const string_view& Function, const Plugin* PluginModule, const std::vector* NestedStack) { // TODO: Far Dialog is not the best choice for exception reporting // replace with something trivial const auto strAddr = tracer::get_one(Context.GetPointers()->ExceptionRecord->ExceptionAddress); + const null_terminated FunctionName(Function); FarDialogItem EditDlgData[]= { @@ -199,7 +211,7 @@ static reply ExcDialog(const string& ModuleName, LPCWSTR Exception, const except {DI_TEXT, 5,3, 17,3,0,nullptr,nullptr,0,msg(lng::MExcAddress).data()}, {DI_EDIT, 18,3, 75,3,0,nullptr,nullptr,DIF_READONLY|DIF_SELECTONENTRY,strAddr.data()}, {DI_TEXT, 5,4, 17,4,0,nullptr,nullptr,0,msg(lng::MExcFunction).data()}, - {DI_EDIT, 18,4, 75,4,0,nullptr,nullptr,DIF_READONLY|DIF_SELECTONENTRY,Function}, + {DI_EDIT, 18,4, 75,4,0,nullptr,nullptr,DIF_READONLY|DIF_SELECTONENTRY, FunctionName.data() }, {DI_TEXT, 5,5, 17,5,0,nullptr,nullptr,0,msg(lng::MExcModule).data()}, {DI_EDIT, 18,5, 75,5,0,nullptr,nullptr,DIF_READONLY|DIF_SELECTONENTRY,ModuleName.data()}, {DI_TEXT, -1,6, 0,6,0,nullptr,nullptr,DIF_SEPARATOR,L""}, @@ -209,7 +221,8 @@ static reply ExcDialog(const string& ModuleName, LPCWSTR Exception, const except {DI_BUTTON, 0,7, 0,7,0,nullptr,nullptr,DIF_CENTERGROUP,msg(lng::MIgnore).data()}, }; auto EditDlg = MakeDialogItemsEx(EditDlgData); - const auto Dlg = Dialog::create(EditDlg, ExcDlgProc, const_cast(&Context)); + auto DlgData = dialog_data_type(&Context, NestedStack); + const auto Dlg = Dialog::create(EditDlg, ExcDlgProc, &DlgData); Dlg->SetDialogMode(DMODE_WARNINGSTYLE|DMODE_NOPLUGINS); Dlg->SetPosition(-1, -1, 80, 10); Dlg->Process(); @@ -225,7 +238,7 @@ static reply ExcDialog(const string& ModuleName, LPCWSTR Exception, const except } } -static reply ExcConsole(const string& ModuleName, LPCWSTR Exception, const exception_context& Context, const wchar_t* Function, const Plugin* Module) +static reply ExcConsole(const string& ModuleName, LPCWSTR Exception, const exception_context& Context, const string_view& Function, const Plugin* Module, const std::vector* NestedStack) { const auto strAddr = tracer::get_one(Context.GetPointers()->ExceptionRecord->ExceptionAddress); @@ -245,15 +258,15 @@ static reply ExcConsole(const string& ModuleName, LPCWSTR Exception, const excep Msg[3] = L"Module: "; } - string Dump = - Msg[0] + L' ' + Exception + L'\n' + - Msg[1] + L' ' + strAddr + L'\n' + - Msg[2] + L' ' + Function + L'\n' + - Msg[3] + L' ' + ModuleName + L'\n'; + const auto Dump = concat( + Msg[0], L' ', Exception, L'\n', + Msg[1], L' ', strAddr, L'\n', + Msg[2], L' ', Function, L'\n', + Msg[3], L' ', ModuleName, L'\n'); std::wcerr << Dump << std::endl; - ShowStackTrace(tracer::get(Context)); + ShowStackTrace(tracer::get(Context), NestedStack); for (;;) { @@ -295,7 +308,7 @@ static string ExtractObjectName(const EXCEPTION_RECORD* xr) return encoding::ansi::get_chars(DataPtr); } -static bool ProcessGenericException(const exception_context& Context, const wchar_t* Function, const Plugin* PluginModule, const char* Message) +static bool ProcessGenericException(const exception_context& Context, const string_view& Function, const Plugin* PluginModule, const char* Message, const std::vector* NestedStack = nullptr) { if (Global) Global->ProcessException = true; @@ -478,12 +491,12 @@ static bool ProcessGenericException(const exception_context& Context, const wcha if (Global && Global->WindowManager && !Global->WindowManager->ManagerIsDown()) { - MsgCode = ExcDialog(strFileName, Exception, Context, Function, PluginModule); + MsgCode = ExcDialog(strFileName, Exception, Context, Function, PluginModule, NestedStack); ShowMessages = true; } else { - MsgCode = ExcConsole(strFileName, Exception, Context, Function, PluginModule); + MsgCode = ExcConsole(strFileName, Exception, Context, Function, PluginModule, NestedStack); } if (ShowMessages && !PluginModule) @@ -507,7 +520,27 @@ void RestoreGPFaultUI() SetErrorMode(Global? Global->ErrorMode & ~SEM_NOGPFAULTERRORBOX : 0); } -bool ProcessStdException(const std::exception& e, const wchar_t* Function, Plugin* Module) +static std::string extract_nested_messages(const std::exception& Exception) +{ + std::string Result = Exception.what(); + + try + { + std::rethrow_if_nested(Exception); + } + catch (const std::exception& e) + { + Result.append(" -> "s).append(extract_nested_messages(e)); + } + catch (...) + { + Result.append(" -> "s).append("Unknown exception"); + } + + return Result; +} + +bool ProcessStdException(const std::exception& e, const string_view& Function, Plugin* Module) { if (const auto SehException = dynamic_cast(&e)) { @@ -525,10 +558,16 @@ bool ProcessStdException(const std::exception& e, const wchar_t* Function, Plugi ContextPtr = Context.get(); } + if (const auto FarException = dynamic_cast(&e)) + { + const auto Message = extract_nested_messages(e); + return ProcessGenericException(*ContextPtr, Function, Module, Message.data(), &FarException->get_stack()); + } + return ProcessGenericException(*ContextPtr, Function, Module, e.what()); } -bool ProcessUnknownException(const wchar_t* Function, Plugin* Module) +bool ProcessUnknownException(const string_view& Function, Plugin* Module) { exception_context Context; return ProcessGenericException(Context, Function, Module, nullptr); @@ -537,7 +576,7 @@ bool ProcessUnknownException(const wchar_t* Function, Plugin* Module) static LONG WINAPI FarUnhandledExceptionFilter(EXCEPTION_POINTERS *ExceptionInfo) { exception_context Context(ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo); - if (ProcessGenericException(Context, L"FarUnhandledExceptionFilter", nullptr, nullptr)) + if (ProcessGenericException(Context, L"FarUnhandledExceptionFilter"_sv, nullptr, nullptr)) { std::terminate(); } @@ -766,7 +805,7 @@ void ResetStackOverflowIfNeeded() } } -int SehFilter(int Code, EXCEPTION_POINTERS* Info, const wchar_t* Function, Plugin* Module) +int SehFilter(int Code, EXCEPTION_POINTERS* Info, const string_view& Function, Plugin* Module) { exception_context Context(Code, Info); if (Code == EXCEPTION_STACK_OVERFLOW) diff --git a/far/farexcpt.hpp b/far/farexcpt.hpp index 9a1bd4bffb..7fe027f2a0 100644 --- a/far/farexcpt.hpp +++ b/far/farexcpt.hpp @@ -37,8 +37,8 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. class Plugin; -bool ProcessStdException(const std::exception& e, const wchar_t* Function, Plugin* Module = nullptr); -bool ProcessUnknownException(const wchar_t* Function, Plugin* Module = nullptr); +bool ProcessStdException(const std::exception& e, const string_view& Function, Plugin* Module = nullptr); +bool ProcessUnknownException(const string_view& Function, Plugin* Module = nullptr); class unhandled_exception_filter { @@ -85,9 +85,9 @@ auto seh_invoke(function&& Callable, filter&& Filter, handler&& Handler) } template -auto seh_invoke_with_ui(function&& Callable, handler&& Handler, const wchar_t* Function, Plugin* Module = nullptr) +auto seh_invoke_with_ui(function&& Callable, handler&& Handler, const string_view& Function, Plugin* Module = nullptr) { - int SehFilter(int, EXCEPTION_POINTERS*, const wchar_t*, Plugin*); + int SehFilter(int, EXCEPTION_POINTERS*, const string_view&, Plugin*); return seh_invoke(FWD(Callable), [&](auto Code, auto Info) { return SehFilter(Code, Info, Function, Module); }, FWD(Handler)); } diff --git a/far/farwinapi.cpp b/far/farwinapi.cpp index 5139a19371..9610b9cd21 100644 --- a/far/farwinapi.cpp +++ b/far/farwinapi.cpp @@ -1628,7 +1628,7 @@ static bool internalNtQueryGetFinalPathNameByHandle(HANDLE hFile, string& FinalF { if (!starts_with(NtPath, OldRoot)) return false; - FinalFilePath = NtPath.replace(0, OldRoot.size(), NewRoot.data(), NewRoot.size()); + FinalFilePath = NtPath.replace(0, OldRoot.size(), NewRoot.raw_data(), NewRoot.size()); return true; }; diff --git a/far/fileedit.cpp b/far/fileedit.cpp index a21572a0a7..cfdbab5630 100644 --- a/far/fileedit.cpp +++ b/far/fileedit.cpp @@ -2106,7 +2106,7 @@ int FileEditor::SaveFile(const string& Name,int Ask, bool bSaveAs, int TextForma EditFile.SetEnd(); } - catch(const far_exception& e) + catch (const far_exception& e) { RetCode = SAVEFILE_ERROR; Global->CatchError(e.get_error_codes()); diff --git a/far/filefilter.cpp b/far/filefilter.cpp index 67760c4be5..8298af6cd4 100644 --- a/far/filefilter.cpp +++ b/far/filefilter.cpp @@ -738,7 +738,7 @@ void FileFilter::InitFilter() } DWORD Flags[FFFT_COUNT] = {}; - cfg->GetValue(root,L"FoldersFilterFFlags", Flags); + cfg->GetValue(root, L"FoldersFilterFFlags", bytes(Flags)); for (DWORD i=FFFT_FIRST; i < FFFT_COUNT; i++) FoldersFilter->SetFlags((enumFileFilterFlagsType)i, Flags[i]); @@ -764,8 +764,8 @@ void FileFilter::InitFilter() NewItem.SetMask(UseMask != 0, strMask); FILETIME DateAfter = {}, DateBefore = {}; - cfg->GetValue(key,L"DateAfter", DateAfter); - cfg->GetValue(key,L"DateBefore", DateBefore); + cfg->GetValue(key,L"DateAfter", bytes(DateAfter)); + cfg->GetValue(key,L"DateBefore", bytes(DateBefore)); unsigned long long UseDate = 0; cfg->GetValue(key, L"UseDate", UseDate); @@ -800,7 +800,7 @@ void FileFilter::InitFilter() NewItem.SetAttr(UseAttr != 0, (DWORD)AttrSet, (DWORD)AttrClear); DWORD Flags[FFFT_COUNT] = {}; - cfg->GetValue(key,L"FFlags", Flags); + cfg->GetValue(key,L"FFlags", bytes(Flags)); for (DWORD i=FFFT_FIRST; i < FFFT_COUNT; i++) NewItem.SetFlags((enumFileFilterFlagsType)i, Flags[i]); @@ -821,7 +821,7 @@ void FileFilter::InitFilter() //Авто фильтры они только для файлов, папки не должны к ним подходить NewItem.SetAttr(true, 0, FILE_ATTRIBUTE_DIRECTORY); DWORD Flags[FFFT_COUNT] = {}; - cfg->GetValue(key,L"FFlags", Flags); + cfg->GetValue(key,L"FFlags", bytes(Flags)); for (DWORD i=FFFT_FIRST; i < FFFT_COUNT; i++) NewItem.SetFlags((enumFileFilterFlagsType)i, Flags[i]); @@ -871,8 +871,8 @@ void FileFilter::Save(bool always) bool bRelative; cfg->SetValue(Key, L"UseDate",CurFilterData.GetDate(&DateType, &DateAfter, &DateBefore, &bRelative)? 1 : 0); cfg->SetValue(Key, L"DateType", DateType); - cfg->SetValue(Key, L"DateAfter", DateAfter); - cfg->SetValue(Key, L"DateBefore", DateBefore); + cfg->SetValue(Key, L"DateAfter", bytes_view(DateAfter)); + cfg->SetValue(Key, L"DateBefore", bytes_view(DateBefore)); cfg->SetValue(Key, L"RelativeDate", bRelative?1:0); cfg->SetValue(Key, L"UseSize", CurFilterData.IsSizeUsed()); cfg->SetValue(Key, L"SizeAboveS", CurFilterData.GetSizeAbove()); @@ -890,7 +890,7 @@ void FileFilter::Save(bool always) for (DWORD j=FFFT_FIRST; j < FFFT_COUNT; j++) Flags[j] = CurFilterData.GetFlags((enumFileFilterFlagsType)j); - cfg->SetValue(Key, L"FFlags", Flags); + cfg->SetValue(Key, L"FFlags", bytes_view(Flags)); } for (size_t i=0; iSetValue(Key, L"FFlags", Flags); + cfg->SetValue(Key, L"FFlags", bytes_view(Flags)); } { @@ -915,7 +915,7 @@ void FileFilter::Save(bool always) for (DWORD i=FFFT_FIRST; i < FFFT_COUNT; i++) Flags[i] = FoldersFilter->GetFlags((enumFileFilterFlagsType)i); - cfg->SetValue(root,L"FoldersFilterFFlags", Flags); + cfg->SetValue(root,L"FoldersFilterFFlags", bytes_view(Flags)); } } diff --git a/far/filelist.cpp b/far/filelist.cpp index f7f0838d02..e15d3af427 100644 --- a/far/filelist.cpp +++ b/far/filelist.cpp @@ -730,8 +730,8 @@ class list_less const auto Name1Ptr = PointToName(a.strName); const auto Name2Ptr = PointToName(b.strName); - const string_view Name1(Name1Ptr, Ext1.data() - Name1Ptr); - const string_view Name2(Name2Ptr, Ext2.data() - Name2Ptr); + const string_view Name1(Name1Ptr, Ext1.raw_data() - Name1Ptr); + const string_view Name2(Name2Ptr, Ext2.raw_data() - Name2Ptr); const auto Comparer = get_comparer(ListNumericSort, ListCaseSensitiveSort); diff --git a/far/filesystemwatcher.cpp b/far/filesystemwatcher.cpp index f03fe0005d..8da89f2d1e 100644 --- a/far/filesystemwatcher.cpp +++ b/far/filesystemwatcher.cpp @@ -56,7 +56,7 @@ FileSystemWatcher::~FileSystemWatcher() { Release(); } - catch(...) + catch (...) { // TODO: log } @@ -161,12 +161,10 @@ void FileSystemWatcher::Register() waiter.add(m_Notification.native_handle()); waiter.add(m_Cancelled); waiter.wait(os::multi_waiter::mode::any); + return; } - catch (...) - { - m_ExceptionPtr = std::current_exception(); - m_IsRegularException = true; - } + CATCH_AND_SAVE_EXCEPTION_TO(m_ExceptionPtr) + m_IsRegularException = true; }); } diff --git a/far/findfile.cpp b/far/findfile.cpp index 0824ab57af..13dff2da03 100644 --- a/far/findfile.cpp +++ b/far/findfile.cpp @@ -2540,11 +2540,8 @@ void background_searcher::Search() m_PluginMode? DoPreparePluginList(false) : DoPrepareFileList(); ReleaseInFileSearch(); } - catch (...) - { - m_ExceptionPtr = std::current_exception(); - m_IsRegularException = true; - } + CATCH_AND_SAVE_EXCEPTION_TO(m_ExceptionPtr) + m_IsRegularException = true; }); } diff --git a/far/hilight.cpp b/far/hilight.cpp index ec462b9c30..b056dc9d64 100644 --- a/far/hilight.cpp +++ b/far/hilight.cpp @@ -174,8 +174,8 @@ static void SetHighlighting(bool DeleteOld, HierarchicalConfig *cfg) cfg->SetValue(Key, HLS.IgnoreMask, i.IgnoreMask); cfg->SetValue(Key, HLS.IncludeAttributes, i.IncludeAttr); - cfg->SetValue(Key, HLS.NormalColor, i.NormalColor); - cfg->SetValue(Key, HLS.CursorColor, i.CursorColor); + cfg->SetValue(Key, HLS.NormalColor, bytes_view(i.NormalColor)); + cfg->SetValue(Key, HLS.CursorColor, bytes_view(i.CursorColor)); static const wchar_t* const Names[] = { @@ -190,7 +190,7 @@ static void SetHighlighting(bool DeleteOld, HierarchicalConfig *cfg) for (const auto& j: Names) { static const FarColor DefaultColor = {FCF_FG_4BIT | FCF_BG_4BIT, 0xff000000, 0x00000000}; - cfg->SetValue(Key, j, DefaultColor); + cfg->SetValue(Key, j, bytes_view(DefaultColor)); } } } @@ -222,9 +222,9 @@ static void LoadFilter(const HierarchicalConfig* cfg, const HierarchicalConfig:: } FILETIME DateAfter = {}; - cfg->GetValue(key,HLS.DateAfter, DateAfter); + cfg->GetValue(key,HLS.DateAfter, bytes(DateAfter)); FILETIME DateBefore = {}; - cfg->GetValue(key,HLS.DateBefore, DateBefore); + cfg->GetValue(key,HLS.DateBefore, bytes(DateBefore)); unsigned long long UseDate = 0; cfg->GetValue(key, HLS.UseDate, UseDate); unsigned long long DateType = 0; @@ -273,14 +273,14 @@ static void LoadFilter(const HierarchicalConfig* cfg, const HierarchicalConfig:: HData.SetSortGroup(SortGroup); highlight::element Colors = {}; - cfg->GetValue(key,HLS.NormalColor, Colors.Color[highlight::color::normal].FileColor); - cfg->GetValue(key,HLS.SelectedColor, Colors.Color[highlight::color::selected].FileColor); - cfg->GetValue(key,HLS.CursorColor, Colors.Color[highlight::color::normal_current].FileColor); - cfg->GetValue(key,HLS.SelectedCursorColor, Colors.Color[highlight::color::selected_current].FileColor); - cfg->GetValue(key,HLS.MarkCharNormalColor, Colors.Color[highlight::color::normal].MarkColor); - cfg->GetValue(key,HLS.MarkCharSelectedColor, Colors.Color[highlight::color::selected].MarkColor); - cfg->GetValue(key,HLS.MarkCharCursorColor, Colors.Color[highlight::color::normal_current].MarkColor); - cfg->GetValue(key,HLS.MarkCharSelectedCursorColor, Colors.Color[highlight::color::selected_current].MarkColor); + cfg->GetValue(key,HLS.NormalColor, bytes(Colors.Color[highlight::color::normal].FileColor)); + cfg->GetValue(key,HLS.SelectedColor, bytes(Colors.Color[highlight::color::selected].FileColor)); + cfg->GetValue(key,HLS.CursorColor, bytes(Colors.Color[highlight::color::normal_current].FileColor)); + cfg->GetValue(key,HLS.SelectedCursorColor, bytes(Colors.Color[highlight::color::selected_current].FileColor)); + cfg->GetValue(key,HLS.MarkCharNormalColor, bytes(Colors.Color[highlight::color::normal].MarkColor)); + cfg->GetValue(key,HLS.MarkCharSelectedColor, bytes(Colors.Color[highlight::color::selected].MarkColor)); + cfg->GetValue(key,HLS.MarkCharCursorColor, bytes(Colors.Color[highlight::color::normal_current].MarkColor)); + cfg->GetValue(key,HLS.MarkCharSelectedCursorColor, bytes(Colors.Color[highlight::color::selected_current].MarkColor)); unsigned long long MarkChar; if (cfg->GetValue(key, HLS.MarkChar, MarkChar)) @@ -855,8 +855,8 @@ static void SaveFilter(HierarchicalConfig *cfg, const HierarchicalConfig::key& k bool bRelative; cfg->SetValue(key,HLS.UseDate,CurHiData->GetDate(&DateType, &DateAfter, &DateBefore, &bRelative)?1:0); cfg->SetValue(key,HLS.DateType,DateType); - cfg->SetValue(key,HLS.DateAfter, DateAfter); - cfg->SetValue(key,HLS.DateBefore, DateBefore); + cfg->SetValue(key,HLS.DateAfter, bytes_view(DateAfter)); + cfg->SetValue(key,HLS.DateBefore, bytes_view(DateBefore)); cfg->SetValue(key,HLS.DateRelative,bRelative?1:0); cfg->SetValue(key, HLS.UseSize, CurHiData->IsSizeUsed()); cfg->SetValue(key, HLS.SizeAbove, CurHiData->GetSizeAbove()); @@ -870,14 +870,14 @@ static void SaveFilter(HierarchicalConfig *cfg, const HierarchicalConfig::key& k cfg->SetValue(key,(bSortGroup?HLS.AttrSet:HLS.IncludeAttributes),AttrSet); cfg->SetValue(key,(bSortGroup?HLS.AttrClear:HLS.ExcludeAttributes),AttrClear); const auto Colors = CurHiData->GetColors(); - cfg->SetValue(key,HLS.NormalColor, Colors.Color[highlight::color::normal].FileColor); - cfg->SetValue(key,HLS.SelectedColor, Colors.Color[highlight::color::selected].FileColor); - cfg->SetValue(key,HLS.CursorColor, Colors.Color[highlight::color::normal_current].FileColor); - cfg->SetValue(key,HLS.SelectedCursorColor, Colors.Color[highlight::color::selected_current].FileColor); - cfg->SetValue(key,HLS.MarkCharNormalColor, Colors.Color[highlight::color::normal].MarkColor); - cfg->SetValue(key,HLS.MarkCharSelectedColor, Colors.Color[highlight::color::selected].MarkColor); - cfg->SetValue(key,HLS.MarkCharCursorColor, Colors.Color[highlight::color::normal_current].MarkColor); - cfg->SetValue(key,HLS.MarkCharSelectedCursorColor, Colors.Color[highlight::color::selected_current].MarkColor); + cfg->SetValue(key,HLS.NormalColor, bytes_view(Colors.Color[highlight::color::normal].FileColor)); + cfg->SetValue(key,HLS.SelectedColor, bytes_view(Colors.Color[highlight::color::selected].FileColor)); + cfg->SetValue(key,HLS.CursorColor, bytes_view(Colors.Color[highlight::color::normal_current].FileColor)); + cfg->SetValue(key,HLS.SelectedCursorColor, bytes_view(Colors.Color[highlight::color::selected_current].FileColor)); + cfg->SetValue(key,HLS.MarkCharNormalColor, bytes_view(Colors.Color[highlight::color::normal].MarkColor)); + cfg->SetValue(key,HLS.MarkCharSelectedColor, bytes_view(Colors.Color[highlight::color::selected].MarkColor)); + cfg->SetValue(key,HLS.MarkCharCursorColor, bytes_view(Colors.Color[highlight::color::normal_current].MarkColor)); + cfg->SetValue(key,HLS.MarkCharSelectedCursorColor, bytes_view(Colors.Color[highlight::color::selected_current].MarkColor)); cfg->SetValue(key,HLS.MarkChar, MAKELONG(Colors.Mark.Char, MAKEWORD(Colors.Mark.Transparent? 0xff : 0, 0))); cfg->SetValue(key,HLS.ContinueProcessing, CurHiData->GetContinueProcessing()?1:0); } diff --git a/far/hotplug.cpp b/far/hotplug.cpp index 2cda295fa7..0162e46b4b 100644 --- a/far/hotplug.cpp +++ b/far/hotplug.cpp @@ -237,7 +237,7 @@ static DWORD GetRelationDrivesMask(DEVINST hDevInst) for (const auto& i: enum_substrings(DeviceIdListPtr)) { DEVINST hRelationDevInst; - if (CM_Locate_DevNode(&hRelationDevInst, const_cast(i.data()), 0) == CR_SUCCESS) + if (CM_Locate_DevNode(&hRelationDevInst, const_cast(i.raw_data()), 0) == CR_SUCCESS) dwMask |= GetDriveMaskFromMountPoints(hRelationDevInst); } diff --git a/far/interf.hpp b/far/interf.hpp index b59cc9f451..3807991135 100644 --- a/far/interf.hpp +++ b/far/interf.hpp @@ -148,20 +148,20 @@ inline void Text(int X, int Y, const FarColor& Color, const wchar_t* Str) { retu inline void Text(int X, int Y, const FarColor& Color, const string& Str) { return Text(X, Y, Color, Str.data(), Str.size()); } void Text(const wchar_t* Str, size_t Size); -inline void Text(const string_view& Str) { return Text(Str.data(), Str.size()); } +inline void Text(const string_view& Str) { return Text(Str.raw_data(), Str.size()); } inline void Text(wchar_t c) { return Text(&c, 1); } void Text(lng MsgId); void VText(const wchar_t* Str, size_t Size); -inline void VText(const string_view& Str) { return VText(Str.data(), Str.size()); } +inline void VText(const string_view& Str) { return VText(Str.raw_data(), Str.size()); } void HiText(const string& Str,const FarColor& HiColor,int isVertText=0); void PutText(int X1,int Y1,int X2,int Y2,const FAR_CHAR_INFO* Src); void GetText(int X1, int Y1, int X2, int Y2, matrix& Dest); void BoxText(const wchar_t* Str, size_t Size, bool IsVert = false); -inline void BoxText(const string_view& Str, bool IsVert = false) { return BoxText(Str.data(), Str.size(), IsVert); } +inline void BoxText(const string_view& Str, bool IsVert = false) { return BoxText(Str.raw_data(), Str.size(), IsVert); } inline void BoxText(wchar_t Chr) { return BoxText(&Chr, 1, false); } void SetScreen(int X1,int Y1,int X2,int Y2,wchar_t Ch,const FarColor& Color); diff --git a/far/keyboard.cpp b/far/keyboard.cpp index 44bb50bd5b..4596312628 100644 --- a/far/keyboard.cpp +++ b/far/keyboard.cpp @@ -1274,10 +1274,13 @@ int KeyNameToKey(const string& Name) // пройдемся по всем модификаторам for (const auto& i: ModifKeyName) { - if (!(Key & i.Key) && contains(strTmpName, i.UpperName.data())) + if (!(Key & i.Key)) { - Key |= i.Key; - Pos += i.UpperName.size() * ReplaceStrings(strTmpName, i.UpperName.data(), L"", true); + if (const auto Count = ReplaceStrings(strTmpName, i.UpperName, L"", true)) + { + Key |= i.Key; + Pos += i.UpperName.size() * Count; + } } } diff --git a/far/main.cpp b/far/main.cpp index 25cfe6dff4..0c22b6a4d3 100644 --- a/far/main.cpp +++ b/far/main.cpp @@ -794,7 +794,7 @@ static int mainImpl(const range& Args) } catch (const std::exception& e) { - if (ProcessStdException(e, L"mainImpl")) + if (ProcessStdException(e, L"mainImpl"_sv)) { std::terminate(); } @@ -824,7 +824,7 @@ static int wmain_seh(int Argc, wchar_t *Argv[]) } catch (const std::exception& e) { - if (ProcessStdException(e, L"wmain")) + if (ProcessStdException(e, L"wmain"_sv)) { std::terminate(); } diff --git a/far/new_handler.cpp b/far/new_handler.cpp index 42991412d7..e873ea598f 100644 --- a/far/new_handler.cpp +++ b/far/new_handler.cpp @@ -83,7 +83,7 @@ new_handler::new_handler(): { SetConsoleCursorPosition(m_Screen.native_handle(), { static_cast((m_BufferSize.X - Str.size()) / 2), static_cast(Y) }); DWORD Written; - return WriteConsole(m_Screen.native_handle(), Str.data(), static_cast(Str.size()), &Written, nullptr) && Written == Str.size(); + return WriteConsole(m_Screen.native_handle(), Str.raw_data(), static_cast(Str.size()), &Written, nullptr) && Written == Str.size(); }; auto InitialY = (m_BufferSize.Y - std::size(Strings)) / 2; diff --git a/far/plclass.cpp b/far/plclass.cpp index 4fbcd611b0..d287b65abc 100644 --- a/far/plclass.cpp +++ b/far/plclass.cpp @@ -48,6 +48,12 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "language.hpp" #include "configdb.hpp" +std::exception_ptr& GlobalExceptionPtr() +{ + static std::exception_ptr ExceptionPtr; + return ExceptionPtr; +} + #define DECLARE_PLUGIN_FUNCTION(name, signature) DECLARE_GEN_PLUGIN_FUNCTION(name, true, signature) DECLARE_PLUGIN_FUNCTION(iClosePanel, void (WINAPI*)(const ClosePanelInfo *Info)) @@ -187,13 +193,13 @@ bool native_plugin_factory::Destroy(plugin_factory::plugin_module_ptr& instance) plugin_factory::function_address native_plugin_factory::GetFunction(const plugin_factory::plugin_module_ptr& Instance, const plugin_factory::export_name& Name) { - return Name.AName? static_cast(Instance.get())->m_Module.GetProcAddress(Name.AName) : nullptr; + return !Name.AName.empty()? static_cast(Instance.get())->m_Module.GetProcAddress(null_terminated_t(Name.AName).data()) : nullptr; } -bool native_plugin_factory::FindExport(const char* ExportName) const +bool native_plugin_factory::FindExport(const basic_string_view& ExportName) const { // only module with GetGlobalInfoW can be native plugin - return !std::strcmp(ExportName, m_ExportsNames[iGetGlobalInfo].AName); + return ExportName == m_ExportsNames[iGetGlobalInfo].AName; } bool native_plugin_factory::IsPlugin2(const void* Module) const @@ -1228,7 +1234,7 @@ class custom_plugin_factory: public plugin_factory m_Success = CheckVersion(&FAR_VERSION, &Info.MinFarVersion) != FALSE; // TODO: store info, show message if version is bad } - custom_plugin_factory::ProcessError(L"Initialize"); + custom_plugin_factory::ProcessError(L"Initialize"_sv); } ~custom_plugin_factory() @@ -1238,7 +1244,7 @@ class custom_plugin_factory: public plugin_factory ExitInfo Info = { sizeof(Info) }; m_Imports.pFree(&Info); - custom_plugin_factory::ProcessError(L"Free"); + custom_plugin_factory::ProcessError(L"Free"_sv); } bool Success() const { return m_Success; } @@ -1246,7 +1252,7 @@ class custom_plugin_factory: public plugin_factory virtual bool IsPlugin(const string& Filename) const override { const auto Result = m_Imports.pIsPlugin(Filename.data()) != FALSE; - ProcessError(L"IsPlugin"); + ProcessError(L"IsPlugin"_sv); return Result; } @@ -1258,7 +1264,7 @@ class custom_plugin_factory: public plugin_factory Global->CatchError(); Module.reset(); } - ProcessError(L"Create"); + ProcessError(L"Create"_sv); return Module; } @@ -1266,20 +1272,20 @@ class custom_plugin_factory: public plugin_factory { const auto Result = m_Imports.pDestroyInstance(static_cast(Module.get())->get_opaque()) != FALSE; Module.reset(); - ProcessError(L"Destroy"); + ProcessError(L"Destroy"_sv); return Result; } virtual function_address GetFunction(const plugin_module_ptr& Instance, const export_name& Name) override { - if (!*Name.UName) + if (Name.UName.empty()) return nullptr; - const auto Result = m_Imports.pGetFunctionAddress(static_cast(Instance.get())->get_opaque(), Name.UName); - ProcessError(L"GetFunction"); + const auto Result = m_Imports.pGetFunctionAddress(static_cast(Instance.get())->get_opaque(), null_terminated(Name.UName).data()); + ProcessError(L"GetFunction"_sv); return Result; } - virtual void ProcessError(const wchar_t* Function) const override + virtual void ProcessError(const string_view& Function) const override { if (!m_Imports.pGetError) return; @@ -1289,7 +1295,7 @@ class custom_plugin_factory: public plugin_factory return; std::vector MessageLines; - string Summary = Info.Summary, Description = Info.Description; + const string Summary = concat(Info.Summary, L" ("_sv, Function, L')'), Description = Info.Description; const auto Enumerator = enum_tokens(Description, L"\n"); std::transform(ALL_CONST_RANGE(Enumerator), std::back_inserter(MessageLines), [](const string_view& View) { return make_string(View); }); Message(MSG_WARNING | MSG_LEFTALIGN, diff --git a/far/plclass.hpp b/far/plclass.hpp index 6badbbd656..2ad3a2caa1 100644 --- a/far/plclass.hpp +++ b/far/plclass.hpp @@ -44,6 +44,38 @@ class Plugin; class language; class PluginsCacheConfig; +std::exception_ptr& GlobalExceptionPtr(); + +namespace detail +{ + template + auto invoke_and_store_exception(callable&& Callable, fallback&& Fallback) + { + try + { + return Callable(); + } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Fallback(); + } +} + +template +auto invoke_and_store_exception(callable&& Callable) +{ + return detail::invoke_and_store_exception(FWD(Callable), [] {}); +} + +template +auto invoke_and_store_exception(fallback Result, callable&& Callable) +{ + using result_type = std::common_type_t, fallback>; + return detail::invoke_and_store_exception( + FWD(Callable), + [&]() -> result_type { return Result; } + ); +} + enum EXPORTS_ENUM { iGetGlobalInfo, @@ -115,8 +147,8 @@ class plugin_factory struct export_name { - const wchar_t* UName; - const char* AName; + string_view UName; + basic_string_view AName; }; virtual ~plugin_factory() = default; @@ -128,7 +160,7 @@ class plugin_factory virtual bool Destroy(plugin_module_ptr& module) = 0; virtual function_address GetFunction(const plugin_module_ptr& Instance, const export_name& Name) = 0; - virtual void ProcessError(const wchar_t* Function) const {} + virtual void ProcessError(const string_view& Function) const {} auto GetOwner() const { return m_owner; } const auto& ExportsNames() const { return m_ExportsNames; } @@ -164,7 +196,7 @@ class native_plugin_factory : public plugin_factory private: // the rest shouldn't be here, just an optimization for OEM plugins bool IsPlugin2(const void* Module) const; - virtual bool FindExport(const char* ExportName) const; + virtual bool FindExport(const basic_string_view& ExportName) const; }; template @@ -383,6 +415,6 @@ class Plugin: noncopyable plugin_factory_ptr CreateCustomPluginFactory(PluginManager* Owner, const string& Filename); #define DECLARE_GEN_PLUGIN_FUNCTION(name, is_native, signature) template<> struct prototype { using type = signature; }; -#define WA(string) {L##string, string} +#define WA(string) { L##string##_sv, string##_sv } #endif // PLCLASS_HPP_E324EC16_24F2_4402_BA87_74212799246D diff --git a/far/plist.cpp b/far/plist.cpp index 4023e4e69a..2f84266e84 100644 --- a/far/plist.cpp +++ b/far/plist.cpp @@ -93,11 +93,9 @@ static BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM Param) return TRUE; } - catch(...) - { - pi->ExceptionPtr = std::current_exception(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(pi->ExceptionPtr) + + return FALSE; } void ShowProcessList() diff --git a/far/plugapi.cpp b/far/plugapi.cpp index ef2df7a640..4226524cd2 100644 --- a/far/plugapi.cpp +++ b/far/plugapi.cpp @@ -215,11 +215,8 @@ wchar_t* WINAPI apiQuoteSpace(wchar_t *Str) noexcept { return QuoteSpace(Str); } - catch (...) - { - StoreGlobalException(); - return nullptr; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return nullptr; } wchar_t* WINAPI apiInsertQuote(wchar_t *Str) noexcept @@ -228,11 +225,8 @@ wchar_t* WINAPI apiInsertQuote(wchar_t *Str) noexcept { return InsertQuote(Str); } - catch (...) - { - StoreGlobalException(); - return nullptr; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return nullptr; } void WINAPI apiUnquote(wchar_t *Str) noexcept @@ -245,11 +239,7 @@ void WINAPI apiUnquote(wchar_t *Str) noexcept const auto Iterator = null_iterator(Str); *std::remove(Iterator, Iterator.end(), L'"') = 0; } - catch (...) - { - StoreGlobalException(); - return; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } wchar_t* WINAPI apiRemoveLeadingSpaces(wchar_t *Str) noexcept @@ -258,11 +248,8 @@ wchar_t* WINAPI apiRemoveLeadingSpaces(wchar_t *Str) noexcept { return RemoveLeadingSpaces(Str); } - catch (...) - { - StoreGlobalException(); - return nullptr; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return nullptr; } wchar_t * WINAPI apiRemoveTrailingSpaces(wchar_t *Str) noexcept @@ -271,11 +258,8 @@ wchar_t * WINAPI apiRemoveTrailingSpaces(wchar_t *Str) noexcept { return RemoveTrailingSpaces(Str); } - catch (...) - { - StoreGlobalException(); - return nullptr; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return nullptr; } wchar_t* WINAPI apiRemoveExternalSpaces(wchar_t *Str) noexcept @@ -284,11 +268,8 @@ wchar_t* WINAPI apiRemoveExternalSpaces(wchar_t *Str) noexcept { return RemoveExternalSpaces(Str); } - catch (...) - { - StoreGlobalException(); - return nullptr; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return nullptr; } wchar_t* WINAPI apiQuoteSpaceOnly(wchar_t *Str) noexcept @@ -297,11 +278,8 @@ wchar_t* WINAPI apiQuoteSpaceOnly(wchar_t *Str) noexcept { return QuoteSpaceOnly(Str); } - catch (...) - { - StoreGlobalException(); - return nullptr; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return nullptr; } intptr_t WINAPI apiInputBox( @@ -327,11 +305,8 @@ intptr_t WINAPI apiInputBox( xwcsncpy(DestText, strDest.data(), DestSize); return nResult; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } /* Функция вывода помощи */ @@ -408,11 +383,8 @@ BOOL WINAPI apiShowHelp(const wchar_t *ModuleName, const wchar_t *HelpTopic, FAR return !Help::create(strTopic, strMask.data(), OFlags)->GetError(); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } /* $ 05.07.2000 IS @@ -792,11 +764,8 @@ intptr_t WINAPI apiAdvControl(const GUID* PluginId, ADVANCED_CONTROL_COMMANDS Co return FALSE; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } intptr_t WINAPI apiMenuFn( @@ -945,11 +914,8 @@ intptr_t WINAPI apiMenuFn( // CheckScreenLock(); return ExitCode; } - catch (...) - { - StoreGlobalException(); - return -1; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return -1; } // Функция FarDefDlgProc обработки диалога по умолчанию @@ -959,11 +925,8 @@ intptr_t WINAPI apiDefDlgProc(HANDLE hDlg,intptr_t Msg,intptr_t Param1,void* Par { return static_cast(hDlg)->DefProc(Msg, Param1, Param2); } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } // Посылка сообщения диалогу @@ -987,11 +950,8 @@ intptr_t WINAPI apiSendDlgMessage(HANDLE hDlg,intptr_t Msg,intptr_t Param1,void* const auto dialog = static_cast(hDlg); return Dialog::IsValid(dialog)? dialog->SendMessage(Msg, Param1, Param2) : ErrorResult(); } - catch (...) - { - StoreGlobalException(); - return ErrorResult(); - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return ErrorResult(); } HANDLE WINAPI apiDialogInit(const GUID* PluginId, const GUID* Id, intptr_t X1, intptr_t Y1, intptr_t X2, intptr_t Y2, @@ -1078,11 +1038,8 @@ HANDLE WINAPI apiDialogInit(const GUID* PluginId, const GUID* Id, intptr_t X1, i } return hDlg; } - catch (...) - { - StoreGlobalException(); - return INVALID_HANDLE_VALUE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return INVALID_HANDLE_VALUE; } intptr_t WINAPI apiDialogRun(HANDLE hDlg) noexcept @@ -1101,11 +1058,8 @@ intptr_t WINAPI apiDialogRun(HANDLE hDlg) noexcept Global->WindowManager->RefreshWindow(); //?? - //AY - это нужно чтоб обновлять панели после выхода из диалога return ExitCode; } - catch (...) - { - StoreGlobalException(); - return -1; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return -1; } void WINAPI apiDialogFree(HANDLE hDlg) noexcept @@ -1119,11 +1073,7 @@ void WINAPI apiDialogFree(HANDLE hDlg) noexcept std::any_of(RANGE(*Plugins, i) { return i->RemoveDialog(Dlg); }); } } - catch (...) - { - StoreGlobalException(); - return; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } const wchar_t* WINAPI apiGetMsgFn(const GUID* PluginId,intptr_t MsgId) noexcept @@ -1140,11 +1090,8 @@ const wchar_t* WINAPI apiGetMsgFn(const GUID* PluginId,intptr_t MsgId) noexcept } return L""; } - catch (...) - { - StoreGlobalException(); - return L""; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return L""; } intptr_t WINAPI apiMessageFn(const GUID* PluginId,const GUID* Id,unsigned long long Flags,const wchar_t *HelpTopic, @@ -1248,11 +1195,8 @@ intptr_t WINAPI apiMessageFn(const GUID* PluginId,const GUID* Id,unsigned long l return MsgCode; } - catch (...) - { - StoreGlobalException(); - return -1; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return -1; } intptr_t WINAPI apiPanelControl(HANDLE hPlugin,FILE_CONTROL_COMMANDS Command,intptr_t Param1,void* Param2) noexcept @@ -1459,11 +1403,8 @@ intptr_t WINAPI apiPanelControl(HANDLE hPlugin,FILE_CONTROL_COMMANDS Command,int return FALSE; } } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } @@ -1482,11 +1423,8 @@ HANDLE WINAPI apiSaveScreen(intptr_t X1,intptr_t Y1,intptr_t X2,intptr_t Y2) noe return new SaveScreen(X1, Y1, X2, Y2); } - catch (...) - { - StoreGlobalException(); - return nullptr; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return nullptr; } void WINAPI apiRestoreScreen(HANDLE hScreen) noexcept @@ -1505,11 +1443,7 @@ void WINAPI apiRestoreScreen(HANDLE hScreen) noexcept Global->ScrBuf->Flush(); } } - catch (...) - { - StoreGlobalException(); - return; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } namespace magic @@ -1595,11 +1529,8 @@ intptr_t WINAPI apiGetDirList(const wchar_t *Dir,PluginPanelItem **pPanelItem,si } return TRUE; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } intptr_t WINAPI apiGetPluginDirList(const GUID* PluginId, HANDLE hPlugin, const wchar_t *Dir, PluginPanelItem **pPanelItem, size_t *pItemsNumber) noexcept @@ -1614,11 +1545,8 @@ intptr_t WINAPI apiGetPluginDirList(const GUID* PluginId, HANDLE hPlugin, const std::tie(*pPanelItem, *pItemsNumber) = magic::CastVectorToRawData(std::move(Items)); return Result; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } void WINAPI apiFreeDirList(PluginPanelItem *PanelItems, size_t ItemsNumber) noexcept @@ -1628,11 +1556,7 @@ void WINAPI apiFreeDirList(PluginPanelItem *PanelItems, size_t ItemsNumber) noex auto Items = magic::CastRawDataToVector(PanelItems, ItemsNumber); FreePluginPanelItems(*Items); } - catch (...) - { - StoreGlobalException(); - return; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } void WINAPI apiFreePluginDirList(HANDLE hPlugin, PluginPanelItem *PanelItems, size_t ItemsNumber) noexcept @@ -1642,11 +1566,7 @@ void WINAPI apiFreePluginDirList(HANDLE hPlugin, PluginPanelItem *PanelItems, si auto Items = magic::CastRawDataToVector(PanelItems, ItemsNumber); FreePluginDirList(hPlugin, *Items); } - catch (...) - { - StoreGlobalException(); - return; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } intptr_t WINAPI apiViewer(const wchar_t *FileName,const wchar_t *Title, @@ -1722,11 +1642,8 @@ intptr_t WINAPI apiViewer(const wchar_t *FileName,const wchar_t *Title, return TRUE; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } intptr_t WINAPI apiEditor(const wchar_t* FileName, const wchar_t* Title, intptr_t X1, intptr_t Y1, intptr_t X2, intptr_t Y2, unsigned long long Flags, intptr_t StartLine, intptr_t StartChar, uintptr_t CodePage) noexcept @@ -1884,11 +1801,8 @@ intptr_t WINAPI apiEditor(const wchar_t* FileName, const wchar_t* Title, intptr_ return ExitCode; } - catch (...) - { - StoreGlobalException(); - return EEC_OPEN_ERROR; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return EEC_OPEN_ERROR; } void WINAPI apiText(intptr_t X,intptr_t Y,const FarColor* Color,const wchar_t *Str) noexcept @@ -1910,11 +1824,7 @@ void WINAPI apiText(intptr_t X,intptr_t Y,const FarColor* Color,const wchar_t *S Text(X, Y, *Color, Str); } } - catch (...) - { - StoreGlobalException(); - return; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } template @@ -1952,11 +1862,8 @@ intptr_t WINAPI apiEditorControl(intptr_t EditorID, EDITOR_CONTROL_COMMANDS Comm { return apiTControl(EditorID, Command, Param1, Param2, &Manager::GetCurrentEditor, &FileEditor::EditorControl); } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } intptr_t WINAPI apiViewerControl(intptr_t ViewerID, VIEWER_CONTROL_COMMANDS Command, intptr_t Param1, void* Param2) noexcept @@ -1965,11 +1872,8 @@ intptr_t WINAPI apiViewerControl(intptr_t ViewerID, VIEWER_CONTROL_COMMANDS Comm { return apiTControl(ViewerID, Command, Param1, Param2, &Manager::GetCurrentViewer, &Viewer::ViewerControl); } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } void WINAPI apiUpperBuf(wchar_t *Buf, intptr_t Length) noexcept @@ -1978,11 +1882,7 @@ void WINAPI apiUpperBuf(wchar_t *Buf, intptr_t Length) noexcept { return inplace::upper(Buf, Length); } - catch (...) - { - StoreGlobalException(); - return; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } void WINAPI apiLowerBuf(wchar_t *Buf, intptr_t Length) noexcept @@ -1991,11 +1891,7 @@ void WINAPI apiLowerBuf(wchar_t *Buf, intptr_t Length) noexcept { return inplace::lower(Buf, Length); } - catch (...) - { - StoreGlobalException(); - return; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } void WINAPI apiStrUpper(wchar_t *s1) noexcept @@ -2004,11 +1900,7 @@ void WINAPI apiStrUpper(wchar_t *s1) noexcept { return inplace::upper(s1); } - catch (...) - { - StoreGlobalException(); - return; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } void WINAPI apiStrLower(wchar_t *s1) noexcept @@ -2017,11 +1909,7 @@ void WINAPI apiStrLower(wchar_t *s1) noexcept { return inplace::lower(s1); } - catch (...) - { - StoreGlobalException(); - return; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } wchar_t WINAPI apiUpper(wchar_t Ch) noexcept @@ -2030,11 +1918,8 @@ wchar_t WINAPI apiUpper(wchar_t Ch) noexcept { return upper(Ch); } - catch (...) - { - StoreGlobalException(); - return Ch; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Ch; } wchar_t WINAPI apiLower(wchar_t Ch) noexcept @@ -2043,11 +1928,8 @@ wchar_t WINAPI apiLower(wchar_t Ch) noexcept { return lower(Ch); } - catch (...) - { - StoreGlobalException(); - return Ch; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Ch; } int WINAPI apiStrCmpNI(const wchar_t *s1, const wchar_t *s2, intptr_t n) noexcept @@ -2056,11 +1938,8 @@ int WINAPI apiStrCmpNI(const wchar_t *s1, const wchar_t *s2, intptr_t n) noexcep { return StrCmpNI(s1, s2, n); } - catch (...) - { - StoreGlobalException(); - return -1; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return -1; } int WINAPI apiStrCmpI(const wchar_t *s1, const wchar_t *s2) noexcept @@ -2069,11 +1948,8 @@ int WINAPI apiStrCmpI(const wchar_t *s1, const wchar_t *s2) noexcept { return StrCmpI(s1, s2); } - catch (...) - { - StoreGlobalException(); - return -1; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return -1; } int WINAPI apiIsLower(wchar_t Ch) noexcept @@ -2082,11 +1958,8 @@ int WINAPI apiIsLower(wchar_t Ch) noexcept { return is_lower(Ch); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } int WINAPI apiIsUpper(wchar_t Ch) noexcept @@ -2095,11 +1968,8 @@ int WINAPI apiIsUpper(wchar_t Ch) noexcept { return is_upper(Ch); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } int WINAPI apiIsAlpha(wchar_t Ch) noexcept @@ -2108,12 +1978,8 @@ int WINAPI apiIsAlpha(wchar_t Ch) noexcept { return is_alpha(Ch); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } - + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } int WINAPI apiIsAlphaNum(wchar_t Ch) noexcept @@ -2122,11 +1988,8 @@ int WINAPI apiIsAlphaNum(wchar_t Ch) noexcept { return is_alphanumeric(Ch); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } wchar_t* WINAPI apiTruncStr(wchar_t *Str,intptr_t MaxLength) noexcept @@ -2135,11 +1998,8 @@ wchar_t* WINAPI apiTruncStr(wchar_t *Str,intptr_t MaxLength) noexcept { return TruncStr(Str, MaxLength); } - catch (...) - { - StoreGlobalException(); - return Str; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Str; } wchar_t* WINAPI apiTruncStrFromCenter(wchar_t *Str, intptr_t MaxLength) noexcept @@ -2148,11 +2008,8 @@ wchar_t* WINAPI apiTruncStrFromCenter(wchar_t *Str, intptr_t MaxLength) noexcept { return TruncStrFromCenter(Str, MaxLength); } - catch (...) - { - StoreGlobalException(); - return Str; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Str; } wchar_t* WINAPI apiTruncStrFromEnd(wchar_t *Str, intptr_t MaxLength) noexcept @@ -2161,11 +2018,8 @@ wchar_t* WINAPI apiTruncStrFromEnd(wchar_t *Str, intptr_t MaxLength) noexcept { return TruncStrFromEnd(Str, MaxLength); } - catch (...) - { - StoreGlobalException(); - return Str; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Str; } wchar_t* WINAPI apiTruncPathStr(wchar_t *Str, intptr_t MaxLength) noexcept @@ -2174,11 +2028,8 @@ wchar_t* WINAPI apiTruncPathStr(wchar_t *Str, intptr_t MaxLength) noexcept { return TruncPathStr(Str, MaxLength); } - catch (...) - { - StoreGlobalException(); - return Str; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Str; } const wchar_t* WINAPI apiPointToName(const wchar_t* Path) noexcept @@ -2187,11 +2038,8 @@ const wchar_t* WINAPI apiPointToName(const wchar_t* Path) noexcept { return PointToName(Path); } - catch (...) - { - StoreGlobalException(); - return Path; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Path; } size_t WINAPI apiGetFileOwner(const wchar_t *Computer, const wchar_t *Name, wchar_t *Owner, size_t Size) noexcept @@ -2207,11 +2055,9 @@ size_t WINAPI apiGetFileOwner(const wchar_t *Computer, const wchar_t *Name, wcha return strOwner.size() + 1; } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; + } size_t WINAPI apiConvertPath(CONVERTPATHMODES Mode, const wchar_t *Src, wchar_t *Dest, size_t DestSize) noexcept @@ -2241,11 +2087,8 @@ size_t WINAPI apiConvertPath(CONVERTPATHMODES Mode, const wchar_t *Src, wchar_t return strDest.size() + 1; } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } size_t WINAPI apiGetReparsePointInfo(const wchar_t *Src, wchar_t *Dest, size_t DestSize) noexcept @@ -2263,11 +2106,8 @@ size_t WINAPI apiGetReparsePointInfo(const wchar_t *Src, wchar_t *Dest, size_t D return strDest.size()+1; } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } size_t WINAPI apiGetNumberOfLinks(const wchar_t* Name) noexcept @@ -2276,11 +2116,8 @@ size_t WINAPI apiGetNumberOfLinks(const wchar_t* Name) noexcept { return GetNumberOfLinks(Name); } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } size_t WINAPI apiGetPathRoot(const wchar_t *Path, wchar_t *Root, size_t DestSize) noexcept @@ -2294,11 +2131,8 @@ size_t WINAPI apiGetPathRoot(const wchar_t *Path, wchar_t *Root, size_t DestSize return strRoot.size()+1; } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } BOOL WINAPI apiCopyToClipboard(enum FARCLIPBOARD_TYPE Type, const wchar_t *Data) noexcept @@ -2317,11 +2151,8 @@ BOOL WINAPI apiCopyToClipboard(enum FARCLIPBOARD_TYPE Type, const wchar_t *Data) return FALSE; } } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } static size_t apiPasteFromClipboardEx(bool Type, wchar_t *Data, size_t Size) @@ -2366,11 +2197,8 @@ size_t WINAPI apiPasteFromClipboard(enum FARCLIPBOARD_TYPE Type, wchar_t *Data, } return size; } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } unsigned long long WINAPI apiFarClock() noexcept @@ -2379,11 +2207,8 @@ unsigned long long WINAPI apiFarClock() noexcept { return Global->FarUpTime(); } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } intptr_t WINAPI apiMacroControl(const GUID* PluginId, FAR_MACRO_CONTROL_COMMANDS Command, intptr_t Param1, void* Param2) noexcept @@ -2496,11 +2321,8 @@ intptr_t WINAPI apiMacroControl(const GUID* PluginId, FAR_MACRO_CONTROL_COMMANDS } return 0; } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } intptr_t WINAPI apiPluginsControl(HANDLE Handle, FAR_PLUGINS_CONTROL_COMMANDS Command, intptr_t Param1, void* Param2) noexcept @@ -2574,11 +2396,8 @@ intptr_t WINAPI apiPluginsControl(HANDLE Handle, FAR_PLUGINS_CONTROL_COMMANDS Co } return 0; } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } intptr_t WINAPI apiFileFilterControl(HANDLE hHandle, FAR_FILE_FILTER_CONTROL_COMMANDS Command, intptr_t Param1, void* Param2) noexcept @@ -2643,11 +2462,8 @@ intptr_t WINAPI apiFileFilterControl(HANDLE hHandle, FAR_FILE_FILTER_CONTROL_COM } return FALSE; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } intptr_t WINAPI apiRegExpControl(HANDLE hHandle, FAR_REGEXP_CONTROL_COMMANDS Command, intptr_t Param1, void* Param2) noexcept @@ -2702,12 +2518,8 @@ intptr_t WINAPI apiRegExpControl(HANDLE hHandle, FAR_REGEXP_CONTROL_COMMANDS Com return FALSE; } } - catch (...) - { - StoreGlobalException(); - return FALSE; - } - + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } intptr_t WINAPI apiSettingsControl(HANDLE hHandle, FAR_SETTINGS_CONTROL_COMMANDS Command, intptr_t Param1, void* Param2) noexcept @@ -2774,11 +2586,8 @@ intptr_t WINAPI apiSettingsControl(HANDLE hHandle, FAR_SETTINGS_CONTROL_COMMANDS } return FALSE; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } size_t WINAPI apiGetCurrentDirectory(size_t Size, wchar_t* Buffer) noexcept @@ -2794,11 +2603,8 @@ size_t WINAPI apiGetCurrentDirectory(size_t Size, wchar_t* Buffer) noexcept return strCurDir.size() + 1; } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } size_t WINAPI apiFormatFileSize(unsigned long long Size, intptr_t Width, FARFORMATFILESIZEFLAGS Flags, wchar_t *Dest, size_t DestSize) noexcept @@ -2826,11 +2632,8 @@ size_t WINAPI apiFormatFileSize(unsigned long long Size, intptr_t Width, FARFORM return strDestStr.size()+1; } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } void WINAPI apiRecursiveSearch(const wchar_t *InitDir, const wchar_t *Mask, FRSUSERFUNC Func, unsigned long long Flags, void *Param) noexcept @@ -2858,12 +2661,7 @@ void WINAPI apiRecursiveSearch(const wchar_t *InitDir, const wchar_t *Mask, FRSU } } } - catch (...) - { - StoreGlobalException(); - return; - } - + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) } size_t WINAPI apiMkTemp(wchar_t *Dest, size_t DestSize, const wchar_t *Prefix) noexcept @@ -2877,11 +2675,8 @@ size_t WINAPI apiMkTemp(wchar_t *Dest, size_t DestSize, const wchar_t *Prefix) n } return strDest.size() + 1; } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } size_t WINAPI apiProcessName(const wchar_t *param1, wchar_t *param2, size_t size, PROCESSNAME_FLAGS flags) noexcept @@ -2940,11 +2735,8 @@ size_t WINAPI apiProcessName(const wchar_t *param1, wchar_t *param2, size_t size return FALSE; } } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } BOOL WINAPI apiColorDialog(const GUID* PluginId, COLORDIALOGFLAGS Flags, FarColor *Color) noexcept @@ -2955,11 +2747,8 @@ BOOL WINAPI apiColorDialog(const GUID* PluginId, COLORDIALOGFLAGS Flags, FarColo Console().GetColorDialog(*Color, true, false): FALSE; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } size_t WINAPI apiInputRecordToKeyName(const INPUT_RECORD* Key, wchar_t *KeyText, size_t Size) noexcept @@ -2982,11 +2771,8 @@ size_t WINAPI apiInputRecordToKeyName(const INPUT_RECORD* Key, wchar_t *KeyText, *KeyText = 0; return len + 1; } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } BOOL WINAPI apiKeyNameToInputRecord(const wchar_t *Name, INPUT_RECORD* RecKey) noexcept @@ -2996,11 +2782,8 @@ BOOL WINAPI apiKeyNameToInputRecord(const wchar_t *Name, INPUT_RECORD* RecKey) n int Key = KeyNameToKey(Name); return Key > 0 ? KeyToInputRecord(Key, RecKey) : FALSE; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } BOOL WINAPI apiMkLink(const wchar_t *Target, const wchar_t *LinkName, LINK_TYPE Type, MKLINK_FLAGS Flags) noexcept @@ -3057,11 +2840,8 @@ BOOL WINAPI apiMkLink(const wchar_t *Target, const wchar_t *LinkName, LINK_TYPE return Result; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } BOOL WINAPI apiAddEndSlash(wchar_t *Path) noexcept @@ -3070,11 +2850,8 @@ BOOL WINAPI apiAddEndSlash(wchar_t *Path) noexcept { return AddEndSlash(Path) ? TRUE : FALSE; } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } wchar_t* WINAPI apiXlat(wchar_t *Line, intptr_t StartPos, intptr_t EndPos, XLAT_FLAGS Flags) noexcept @@ -3083,11 +2860,8 @@ wchar_t* WINAPI apiXlat(wchar_t *Line, intptr_t StartPos, intptr_t EndPos, XLAT_ { return Xlat(Line, StartPos, EndPos, Flags); } - catch (...) - { - StoreGlobalException(); - return Line; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return Line; } HANDLE WINAPI apiCreateFile(const wchar_t *Object, DWORD DesiredAccess, DWORD ShareMode, LPSECURITY_ATTRIBUTES SecurityAttributes, DWORD CreationDistribution, DWORD FlagsAndAttributes, HANDLE TemplateFile) noexcept @@ -3096,11 +2870,8 @@ HANDLE WINAPI apiCreateFile(const wchar_t *Object, DWORD DesiredAccess, DWORD Sh { return os::CreateFile(Object, DesiredAccess, ShareMode, SecurityAttributes, CreationDistribution, FlagsAndAttributes, TemplateFile).release(); } - catch (...) - { - StoreGlobalException(); - return INVALID_HANDLE_VALUE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return INVALID_HANDLE_VALUE; } DWORD WINAPI apiGetFileAttributes(const wchar_t *FileName) noexcept @@ -3109,11 +2880,8 @@ DWORD WINAPI apiGetFileAttributes(const wchar_t *FileName) noexcept { return os::GetFileAttributes(FileName); } - catch (...) - { - StoreGlobalException(); - return INVALID_FILE_ATTRIBUTES; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return INVALID_FILE_ATTRIBUTES; } BOOL WINAPI apiSetFileAttributes(const wchar_t *FileName, DWORD dwFileAttributes) noexcept @@ -3122,11 +2890,8 @@ BOOL WINAPI apiSetFileAttributes(const wchar_t *FileName, DWORD dwFileAttributes { return os::SetFileAttributes(FileName, dwFileAttributes); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } BOOL WINAPI apiMoveFileEx(const wchar_t *ExistingFileName, const wchar_t *NewFileName, DWORD dwFlags) noexcept @@ -3135,11 +2900,8 @@ BOOL WINAPI apiMoveFileEx(const wchar_t *ExistingFileName, const wchar_t *NewFil { return os::MoveFileEx(ExistingFileName, NewFileName, dwFlags); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } BOOL WINAPI apiDeleteFile(const wchar_t *FileName) noexcept @@ -3148,11 +2910,8 @@ BOOL WINAPI apiDeleteFile(const wchar_t *FileName) noexcept { return os::DeleteFile(FileName); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } BOOL WINAPI apiRemoveDirectory(const wchar_t *DirName) noexcept @@ -3161,11 +2920,8 @@ BOOL WINAPI apiRemoveDirectory(const wchar_t *DirName) noexcept { return os::RemoveDirectory(DirName); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } BOOL WINAPI apiCreateDirectory(const wchar_t *PathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes) noexcept @@ -3174,11 +2930,8 @@ BOOL WINAPI apiCreateDirectory(const wchar_t *PathName, LPSECURITY_ATTRIBUTES lp { return os::CreateDirectory(PathName, lpSecurityAttributes); } - catch (...) - { - StoreGlobalException(); - return FALSE; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return FALSE; } intptr_t WINAPI apiCallFar(intptr_t CheckCode, FarMacroCall* Data) noexcept @@ -3187,11 +2940,8 @@ intptr_t WINAPI apiCallFar(intptr_t CheckCode, FarMacroCall* Data) noexcept { return Global->CtrlObject ? Global->CtrlObject->Macro.CallFar(CheckCode, Data) : 0; } - catch (...) - { - StoreGlobalException(); - return 0; - } + CATCH_AND_SAVE_EXCEPTION_TO(GlobalExceptionPtr()) + return 0; } } diff --git a/far/plugsettings.cpp b/far/plugsettings.cpp index 79d23fdc0e..63ef95639a 100644 --- a/far/plugsettings.cpp +++ b/far/plugsettings.cpp @@ -137,7 +137,7 @@ bool PluginSettings::Set(const FarSettingsItem& Item) return PluginsCfg->SetValue(m_Keys[Item.Root], Item.Name, Item.String); case FST_DATA: - return PluginsCfg->SetValue(m_Keys[Item.Root], Item.Name, make_blob_view(Item.Data.Data, Item.Data.Size)); + return PluginsCfg->SetValue(m_Keys[Item.Root], Item.Name, bytes_view(Item.Data.Data, Item.Data.Size)); default: return false; @@ -178,7 +178,7 @@ bool PluginSettings::Get(FarSettingsItem& Item) case FST_DATA: { - writable_blob_view data; + bytes data; if (PluginsCfg->GetValue(m_Keys[Item.Root], Item.Name, data)) { Item.Data.Data = Add(data.data(), data.size()); diff --git a/far/sqlitedb.cpp b/far/sqlitedb.cpp index 56097f258e..f273ea738a 100644 --- a/far/sqlitedb.cpp +++ b/far/sqlitedb.cpp @@ -100,37 +100,31 @@ bool SQLiteDb::SQLiteStmt::FinalStep() const return sqlite::sqlite3_step(m_Stmt.get()) == SQLITE_DONE; } -SQLiteDb::SQLiteStmt& SQLiteDb::SQLiteStmt::BindImpl(int Value) -{ - sqlite::sqlite3_bind_int(m_Stmt.get(), m_Param++, Value); - return *this; -} - -SQLiteDb::SQLiteStmt& SQLiteDb::SQLiteStmt::BindImpl(long long Value) +SQLiteDb::SQLiteStmt& SQLiteDb::SQLiteStmt::BindImpl(std::nullptr_t) { - sqlite::sqlite3_bind_int64(m_Stmt.get(), m_Param++, Value); + sqlite::sqlite3_bind_null(m_Stmt.get(), m_Param++); return *this; } -SQLiteDb::SQLiteStmt& SQLiteDb::SQLiteStmt::BindImpl(const wchar_t* Value, bool bStatic) +SQLiteDb::SQLiteStmt& SQLiteDb::SQLiteStmt::BindImpl(int Value) { - sqlite::sqlite3_bind_text16(m_Stmt.get(), m_Param++, Value, -1, bStatic? sqlite::static_destructor : sqlite::transient_destructor); + sqlite::sqlite3_bind_int(m_Stmt.get(), m_Param++, Value); return *this; } -SQLiteDb::SQLiteStmt& SQLiteDb::SQLiteStmt::BindImpl(const string& Value, bool bStatic) +SQLiteDb::SQLiteStmt& SQLiteDb::SQLiteStmt::BindImpl(long long Value) { - sqlite::sqlite3_bind_text16(m_Stmt.get(), m_Param++, Value.data(), static_cast(Value.size() * sizeof(wchar_t)), bStatic? sqlite::static_destructor : sqlite::transient_destructor); + sqlite::sqlite3_bind_int64(m_Stmt.get(), m_Param++, Value); return *this; } -SQLiteDb::SQLiteStmt& SQLiteDb::SQLiteStmt::BindImpl(string&& Value) +SQLiteDb::SQLiteStmt& SQLiteDb::SQLiteStmt::BindImpl(const string_view& Value, bool bStatic) { - sqlite::sqlite3_bind_text16(m_Stmt.get(), m_Param++, Value.data(), static_cast(Value.size() * sizeof(wchar_t)), sqlite::transient_destructor); + sqlite::sqlite3_bind_text16(m_Stmt.get(), m_Param++, Value.raw_data(), static_cast(Value.size() * sizeof(wchar_t)), bStatic? sqlite::static_destructor : sqlite::transient_destructor); return *this; } -SQLiteDb::SQLiteStmt& SQLiteDb::SQLiteStmt::BindImpl(const blob_view& Value, bool bStatic) +SQLiteDb::SQLiteStmt& SQLiteDb::SQLiteStmt::BindImpl(const bytes_view& Value, bool bStatic) { sqlite::sqlite3_bind_blob(m_Stmt.get(), m_Param++, Value.data(), static_cast(Value.size()), bStatic? sqlite::static_destructor : sqlite::transient_destructor); return *this; @@ -156,9 +150,9 @@ unsigned long long SQLiteDb::SQLiteStmt::GetColInt64(int Col) const return sqlite::sqlite3_column_int64(m_Stmt.get(), Col); } -blob_view SQLiteDb::SQLiteStmt::GetColBlob(int Col) const +bytes_view SQLiteDb::SQLiteStmt::GetColBlob(int Col) const { - return make_blob_view(sqlite::sqlite3_column_blob(m_Stmt.get(), Col), sqlite::sqlite3_column_bytes(m_Stmt.get(), Col)); + return bytes_view(sqlite::sqlite3_column_blob(m_Stmt.get(), Col), sqlite::sqlite3_column_bytes(m_Stmt.get(), Col)); } SQLiteDb::column_type SQLiteDb::SQLiteStmt::GetColType(int Col) const diff --git a/far/sqlitedb.hpp b/far/sqlitedb.hpp index 01de58dba4..ff707406cb 100644 --- a/far/sqlitedb.hpp +++ b/far/sqlitedb.hpp @@ -92,18 +92,23 @@ class SQLiteDb: noncopyable, virtual transactional const char *GetColTextUTF8(int Col) const; int GetColInt(int Col) const; unsigned long long GetColInt64(int Col) const; - blob_view GetColBlob(int Col) const; + bytes_view GetColBlob(int Col) const; column_type GetColType(int Col) const; private: auto& Bind() { return *this; } + template + SQLiteStmt& BindImpl(const type* Value) + { + return Value? BindImpl(*Value) : BindImpl(nullptr); + } + + SQLiteStmt& BindImpl(std::nullptr_t); SQLiteStmt& BindImpl(int Value); SQLiteStmt& BindImpl(long long Value); - SQLiteStmt& BindImpl(const wchar_t* Value, bool bStatic = true); - SQLiteStmt& BindImpl(const string& Value, bool bStatic = true); - SQLiteStmt& BindImpl(string&& Value); - SQLiteStmt& BindImpl(const blob_view& Value, bool bStatic = true); + SQLiteStmt& BindImpl(const string_view& Value, bool bStatic = true); + SQLiteStmt& BindImpl(const bytes_view& Value, bool bStatic = true); SQLiteStmt& BindImpl(unsigned int Value) { return BindImpl(static_cast(Value)); } SQLiteStmt& BindImpl(unsigned long long Value) { return BindImpl(static_cast(Value)); } template diff --git a/far/string_utils.cpp b/far/string_utils.cpp index 555b85bb15..866e176353 100644 --- a/far/string_utils.cpp +++ b/far/string_utils.cpp @@ -156,12 +156,12 @@ bool equal_icase(const string_view& Str1, const string_view& Str2) bool starts_with_icase(const string_view& Str, const string_view& Prefix) { - return Str.size() >= Prefix.size() && equal_icase({ Str.data(), Prefix.size() }, Prefix); + return Str.size() >= Prefix.size() && equal_icase(Str.substr(0, Prefix.size()), Prefix); } bool ends_with_icase(const string_view& Str, const string_view& Suffix) { - return Str.size() >= Suffix.size() && equal_icase({ Str.data() + Str.size() - Suffix.size(), Suffix.size() }, Suffix); + return Str.size() >= Suffix.size() && equal_icase(Str.substr(Str.size() - Suffix.size()), Suffix); } bool contains_icase(const string_view& Str, const string_view& Token) @@ -187,12 +187,12 @@ int StrCmpNI(const wchar_t *s1, const wchar_t *s2, size_t n) int StrCmp(const string_view& Str1, const string_view& Str2) { - return CompareString(0, SORT_STRINGSORT, Str1.data(), static_cast(Str1.size()), Str2.data(), static_cast(Str2.size())) - 2; + return CompareString(0, SORT_STRINGSORT, Str1.raw_data(), static_cast(Str1.size()), Str2.raw_data(), static_cast(Str2.size())) - 2; } int StrCmpI(const string_view& Str1, const string_view& Str2) { - return CompareString(0, SORT_STRINGSORT | NORM_IGNORECASE, Str1.data(), static_cast(Str1.size()), Str2.data(), static_cast(Str2.size())) - 2; + return CompareString(0, SORT_STRINGSORT | NORM_IGNORECASE, Str1.raw_data(), static_cast(Str1.size()), Str2.raw_data(), static_cast(Str2.size())) - 2; } static int per_char_compare(const string_view& Str1, const string_view& Str2, const std::function& Comparer) diff --git a/far/strmix.cpp b/far/strmix.cpp index 5621a36f20..ee5c0057a7 100644 --- a/far/strmix.cpp +++ b/far/strmix.cpp @@ -580,7 +580,7 @@ size_t ReplaceStrings(string &strStr, const string_view& FindStr, const string_v if (!AreEqual(make_string_view(strStr, I, FindStr.size()), FindStr)) continue; - strStr.replace(I, FindStr.size(), ReplStr.data(), ReplStr.size()); + strStr.replace(I, FindStr.size(), ReplStr.raw_data(), ReplStr.size()); L += ReplStr.size(); L -= FindStr.size(); @@ -890,35 +890,20 @@ unsigned long long ConvertFileSizeString(const string& FileSizeStr) if (!CheckFileSizeStringFormat(FileSizeStr)) return 0; - auto n = std::stoull(FileSizeStr); - wchar_t c = ::upper(FileSizeStr.back()); + const auto n = std::stoull(FileSizeStr); - // http://en.wikipedia.org/wiki/SI_prefix - switch (c) + // https://en.wikipedia.org/wiki/Binary_prefix + // https://en.wikipedia.org/wiki/SI_prefix + switch (upper(FileSizeStr.back())) { - case L'K': // kilo 10x3 - n <<= 10; - break; - case L'M': // mega 10x6 - n <<= 20; - break; - case L'G': // giga 10x9 - n <<= 30; - break; - case L'T': // tera 10x12 - n <<= 40; - break; - case L'P': // peta 10x15 - n <<= 50; - break; - case L'E': // exa 10x18 - n <<= 60; - break; - // Z - zetta 10x21 - // Y - yotta 10x24 + case L'K': return n << 10; // Ki kibi 1024^1 - ~kilo ~10^3 + case L'M': return n << 20; // Mi mebi 1024^2 - ~mega ~10^6 + case L'G': return n << 30; // Gi gibi 1024^3 - ~giga ~10^9 + case L'T': return n << 40; // Ti tebi 1024^4 - ~tera ~10^12 + case L'P': return n << 50; // Pi pebi 1024^5 - ~peta ~10^15 + case L'E': return n << 60; // Ei exbi 1024^6 - ~exa ~10^18 + default: return n; } - - return n; } string ReplaceBrackets(const wchar_t *SearchStr, const string& ReplaceStr, const RegExpMatch* Match, size_t Count, const MatchHash* HMatch) diff --git a/far/tracer.cpp b/far/tracer.cpp index 42ebbb9790..964f7f42b8 100644 --- a/far/tracer.cpp +++ b/far/tracer.cpp @@ -173,31 +173,41 @@ const exception_context* tracer::get_exception_context(const void* CppObject) return GetInstance()->get_context(CppObject); } +class with_symbols +{ +public: + NONCOPYABLE(with_symbols); + + with_symbols() + { + tracer::GetInstance()->SymInitialise(); + } + + ~with_symbols() + { + tracer::GetInstance()->SymCleanup(); + } +}; + std::vector tracer::get(const void* CppObject) { const auto Context = GetInstance()->get_context(CppObject); if (!Context) return {}; - GetInstance()->SymInitialise(); - SCOPE_EXIT{ GetInstance()->SymCleanup(); }; - + SCOPED_ACTION(with_symbols); return GetSymbols(GetBackTrace(*Context)); } std::vector tracer::get(const exception_context& Context) { - GetInstance()->SymInitialise(); - SCOPE_EXIT{ GetInstance()->SymCleanup(); }; - + SCOPED_ACTION(with_symbols); return GetSymbols(GetBackTrace(Context)); } string tracer::get_one(const void* Address) { - GetInstance()->SymInitialise(); - SCOPE_EXIT{ GetInstance()->SymCleanup(); }; - + SCOPED_ACTION(with_symbols); return GetSymbols({Address}).front(); } diff --git a/far/tracer.hpp b/far/tracer.hpp index 08d5471830..17dd9f68f8 100644 --- a/far/tracer.hpp +++ b/far/tracer.hpp @@ -51,6 +51,8 @@ class tracer: noncopyable static const exception_context* get_exception_context(const void* CppObject); private: + friend class with_symbols; + const exception_context* get_context(const void* CppObject) const; bool SymInitialise(); diff --git a/far/vbuild.m4 b/far/vbuild.m4 index bada8a40ff..9d2e4a8c8b 100644 --- a/far/vbuild.m4 +++ b/far/vbuild.m4 @@ -1 +1 @@ -m4_define(BUILD,5025)m4_dnl +m4_define(BUILD,5026)m4_dnl diff --git a/far/wm_listener.cpp b/far/wm_listener.cpp index c1ac18c3d4..2393a9df75 100644 --- a/far/wm_listener.cpp +++ b/far/wm_listener.cpp @@ -110,10 +110,8 @@ static LRESULT CALLBACK WndProc(HWND Hwnd, UINT Msg, WPARAM wParam, LPARAM lPara } } - catch(...) - { - *WndProcExceptionPtr = std::current_exception(); - } + CATCH_AND_SAVE_EXCEPTION_TO(*WndProcExceptionPtr) + return DefWindowProc(Hwnd, Msg, wParam, lParam); }