From d27afce85268213b6e130d58d7d5adf48998bca6 Mon Sep 17 00:00:00 2001 From: Jief L Date: Wed, 29 Apr 2020 23:32:22 +0300 Subject: [PATCH 01/12] Comment out unused global var. --- rEFIt_UEFI/Platform/FixBiosDsdt.cpp | 46 ++++++++++++++--------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/rEFIt_UEFI/Platform/FixBiosDsdt.cpp b/rEFIt_UEFI/Platform/FixBiosDsdt.cpp index ebec9c337..479395d81 100755 --- a/rEFIt_UEFI/Platform/FixBiosDsdt.cpp +++ b/rEFIt_UEFI/Platform/FixBiosDsdt.cpp @@ -394,16 +394,16 @@ UINT8 hpet1[] = // Name (_CID, EisaId ("PNP0C01")) }; */ const UINT8 wakret[] = { 0xA4, 0x12, 0x04, 0x02, 0x00, 0x00 }; -const UINT8 wakslp1[] = { 0x5B, 0x80, 0x50, 0x4D, 0x33, 0x30, 0x01 }; -const UINT8 wakslp2[] = { 0x0A, 0x08, 0x5B, 0x81, 0x0D, 0x50, 0x4D, 0x33, 0x30, 0x01, - 0x00, 0x04, 0x53, 0x4C, 0x4D, 0x45, 0x01, 0x70, 0x00, 0x53, 0x4C, 0x4D, 0x45 }; +//const UINT8 wakslp1[] = { 0x5B, 0x80, 0x50, 0x4D, 0x33, 0x30, 0x01 }; +//const UINT8 wakslp2[] = { 0x0A, 0x08, 0x5B, 0x81, 0x0D, 0x50, 0x4D, 0x33, 0x30, 0x01, +// 0x00, 0x04, 0x53, 0x4C, 0x4D, 0x45, 0x01, 0x70, 0x00, 0x53, 0x4C, 0x4D, 0x45 }; const UINT8 waksecur[] = {0xA0, 0x0D, 0x91, 0x95, 0x68, 0x01, 0x94, 0x68, 0x0A, 0x05, 0x70, 0x0A, 0x03, 0x68}; -const UINT8 pwrb[] = { //? \_SB_PWRB, 0x02 - 0x86, 0x5C, 0x2E, 0x5F, 0x53, 0x42, 0x5F, 0x50, 0x57, 0x52, 0x42, 0x0A, 0x02 -}; +//const UINT8 pwrb[] = { //? \_SB_PWRB, 0x02 +// 0x86, 0x5C, 0x2E, 0x5F, 0x53, 0x42, 0x5F, 0x50, 0x57, 0x52, 0x42, 0x0A, 0x02 +//}; const UINT8 acpi3[] = { //Name(_HID, "ACPI003") @@ -423,16 +423,16 @@ const UINT8 dtgp_1[] = { // DTGP (Arg0, Arg1, Arg2, Arg3, RefOf (Local0)) 0x71, 0x60, 0xA4, 0x60 }; -const UINT8 pwrbcid[] = { - 0x08, 0x5F, 0x43, 0x49, 0x44, 0x0C, 0x41, 0xD0, 0x0C, 0x0E, 0x14, - 0x0E, 0x5F, 0x50, 0x52, 0x57, 0x00, 0xA4, 0x12, 0x06, 0x02, 0x0A, - 0x0B, 0x0A, 0x04 -}; +//const UINT8 pwrbcid[] = { +// 0x08, 0x5F, 0x43, 0x49, 0x44, 0x0C, 0x41, 0xD0, 0x0C, 0x0E, 0x14, +// 0x0E, 0x5F, 0x50, 0x52, 0x57, 0x00, 0xA4, 0x12, 0x06, 0x02, 0x0A, +// 0x0B, 0x0A, 0x04 +//}; -const UINT8 pwrbprw[] = { - 0x14, 0x0E, 0x5F, 0x50, 0x52, 0x57, 0x00, 0xA4, 0x12, 0x06, 0x02, - 0x0A, 0x0B, 0x0A, 0x04 -}; +//const UINT8 pwrbprw[] = { +// 0x14, 0x0E, 0x5F, 0x50, 0x52, 0x57, 0x00, 0xA4, 0x12, 0x06, 0x02, +// 0x0A, 0x0B, 0x0A, 0x04 +//}; const UINT8 shutdown0[] = { 0xA0, 0x05, 0x93, 0x68, 0x0A, 0x05, 0xA1, 0x01 @@ -451,14 +451,14 @@ const UINT8 pnlf[] = { 0x08, 0x5F, 0x55, 0x49, 0x44, 0x0A, 0x0A, // Name (_UID, 0x0A) 0x08, 0x5F, 0x53, 0x54, 0x41, 0x0A, 0x0B // Name (_STA, 0x0B) }; -//Scope (_SB.PCI0.LPCB) -const UINT8 pnlfLPC[] = { - 0x10, 0x3e, 0x2f, 0x03, 0x5f, 0x53, 0x42, 0x5f, 0x50, 0x43, 0x49, 0x30, 0x4c, 0x50, 0x43, 0x42, - 0x5b, 0x82, 0x2d, 0x50, 0x4e, 0x4c, 0x46, 0x08, 0x5f, 0x48, 0x49, - 0x44, 0x0c, 0x06, 0x10, 0x00, 0x02, 0x08, 0x5f, 0x43, 0x49, 0x44, 0x0d, - 0x62, 0x61, 0x63, 0x6b, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x00, 0x08, 0x5f, - 0x55, 0x49, 0x44, 0x0a, 0x0a, 0x08, 0x5f, 0x53, 0x54, 0x41, 0x0a, 0x0b -}; +////Scope (_SB.PCI0.LPCB) +//const UINT8 pnlfLPC[] = { +// 0x10, 0x3e, 0x2f, 0x03, 0x5f, 0x53, 0x42, 0x5f, 0x50, 0x43, 0x49, 0x30, 0x4c, 0x50, 0x43, 0x42, +// 0x5b, 0x82, 0x2d, 0x50, 0x4e, 0x4c, 0x46, 0x08, 0x5f, 0x48, 0x49, +// 0x44, 0x0c, 0x06, 0x10, 0x00, 0x02, 0x08, 0x5f, 0x43, 0x49, 0x44, 0x0d, +// 0x62, 0x61, 0x63, 0x6b, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x00, 0x08, 0x5f, +// 0x55, 0x49, 0x44, 0x0a, 0x0a, 0x08, 0x5f, 0x53, 0x54, 0x41, 0x0a, 0x0b +//}; const UINT8 app2[] = { //Name (_HID, EisaId("APP0002")) From db7f483cbdfc7747c91598c4dd5dd839190cc4ea Mon Sep 17 00:00:00 2001 From: Jief L Date: Wed, 29 Apr 2020 23:32:44 +0300 Subject: [PATCH 02/12] Missing L before literals. --- rEFIt_UEFI/entry_scan/loader.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/rEFIt_UEFI/entry_scan/loader.cpp b/rEFIt_UEFI/entry_scan/loader.cpp index 05050a4d6..424b591e1 100644 --- a/rEFIt_UEFI/entry_scan/loader.cpp +++ b/rEFIt_UEFI/entry_scan/loader.cpp @@ -59,9 +59,9 @@ #define DBG(...) DebugLog(DEBUG_SCAN_LOADER, __VA_ARGS__) #endif -const XStringW MACOSX_LOADER_PATH = "\\System\\Library\\CoreServices\\boot.efi"_XSW; +const XStringW MACOSX_LOADER_PATH = L"\\System\\Library\\CoreServices\\boot.efi"_XSW; -const XStringW LINUX_ISSUE_PATH = "\\etc\\issue"_XSW; +const XStringW LINUX_ISSUE_PATH = L"\\etc\\issue"_XSW; #define LINUX_BOOT_PATH L"\\boot" #define LINUX_BOOT_ALT_PATH L"\\boot" const XString LINUX_LOADER_PATH = "vmlinuz"_XS; @@ -129,7 +129,7 @@ STATIC LINUX_PATH_DATA LinuxEntryData[] = { // { L"\\EFI\\Manjaro\\grubx64.efi", L"Manjaro EFI boot menu", L"manjaro,linux", "Manjaro" }, // { L"\\EFI\\xubuntu\\grubx64.efi", L"Xubuntu EFI boot menu", L"xubuntu,linux", "Xubuntu" }, // { L"\\EFI\\zorin\\grubx64.efi", L"Zorin EFI boot menu", L"zorin,linux", "Zorin" }, - { L"\\EFI\\goofiboot\\goofibootx64.efi"_XSW, L"Solus EFI boot menu"_XSW, L"solus,linux"_XSW, "Solus"_XSW }, + { L"\\EFI\\goofiboot\\goofibootx64.efi"_XSW, L"Solus EFI boot menu"_XSW, L"solus,linux"_XSW, "Solus"_XS }, // { L"\\EFI\\centos\\grubx64.efi", L"CentOS EFI boot menu", L"centos,linux", "CentOS" }, // { L"\\EFI\\pclinuxos\\grubx64.efi", L"PCLinuxOS EFI boot menu", L"pclinux,linux", "PCLinux" }, // { L"\\EFI\\neon\\grubx64.efi", L"KDE Neon EFI boot menu", L"neon,linux", "KDE Neon" }, @@ -196,9 +196,9 @@ STATIC CONST UINTN AndroidEntryDataCount = (sizeof(AndroidEntryData) / sizeof(AN #endif #endif -CONST XStringW PaperBoot = "\\com.apple.boot.P\\boot.efi"_XSW; -CONST XStringW RockBoot = "\\com.apple.boot.R\\boot.efi"_XSW; -CONST XStringW ScissorBoot = "\\com.apple.boot.S\\boot.efi"_XSW; +CONST XStringW PaperBoot = L"\\com.apple.boot.P\\boot.efi"_XSW; +CONST XStringW RockBoot = L"\\com.apple.boot.R\\boot.efi"_XSW; +CONST XStringW ScissorBoot = L"\\com.apple.boot.S\\boot.efi"_XSW; // OS X installer paths CONST XStringW OSXInstallerPaths[] = { @@ -1163,7 +1163,7 @@ VOID ScanLoader(VOID) if (FileExists(Volume->RootDir, L"\\Install OS X Mavericks.app") || FileExists(Volume->RootDir, L"\\Install OS X Yosemite.app") || FileExists(Volume->RootDir, L"\\Install OS X El Capitan.app")) { - AddLoaderEntry("\\.IABootFiles\\boot.efi"_XSW, NullXStringArray, L"OS X Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.9 - 10.11 + AddLoaderEntry(L"\\.IABootFiles\\boot.efi"_XSW, NullXStringArray, L"OS X Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.9 - 10.11 } else { AddLoaderEntry(L"\\.IABootFiles\\boot.efi"_XSW, NullXStringArray, L"macOS Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.12 - 10.13.3 } @@ -1171,7 +1171,7 @@ VOID ScanLoader(VOID) AddLoaderEntry(MACOSX_LOADER_PATH, NullXStringArray, L"macOS Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.13.4+ } // 2nd stage - InstallESD/AppStore/startosinstall/Fusion Drive - AddLoaderEntry("\\Mac OS X Install Data\\boot.efi"_XSW, NullXStringArray, L"Mac OS X Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.7 + AddLoaderEntry(L"\\Mac OS X Install Data\\boot.efi"_XSW, NullXStringArray, L"Mac OS X Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.7 AddLoaderEntry(L"\\OS X Install Data\\boot.efi"_XSW, NullXStringArray, L"OS X Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.8 - 10.11 AddLoaderEntry(L"\\macOS Install Data\\boot.efi"_XSW, NullXStringArray, L"macOS Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.12 - 10.12.3 AddLoaderEntry(L"\\macOS Install Data\\Locked Files\\Boot Files\\boot.efi"_XSW, NullXStringArray, L"macOS Install"_XSW, Volume, NULL, OSTYPE_OSX_INSTALLER, 0); // 10.12.4+ From 0c0c2d53d496237da6e509b885b6bd35dce516f5 Mon Sep 17 00:00:00 2001 From: Jief L Date: Wed, 29 Apr 2020 23:33:45 +0300 Subject: [PATCH 03/12] Missing L before literals (bis). --- rEFIt_UEFI/entry_scan/tool.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rEFIt_UEFI/entry_scan/tool.cpp b/rEFIt_UEFI/entry_scan/tool.cpp index 996c1f2ee..191650008 100644 --- a/rEFIt_UEFI/entry_scan/tool.cpp +++ b/rEFIt_UEFI/entry_scan/tool.cpp @@ -43,10 +43,10 @@ // // Clover File location to boot from on removable media devices // -#define CLOVER_MEDIA_FILE_NAME_IA32 "\\EFI\\CLOVER\\CLOVERIA32.EFI"_XSW -#define CLOVER_MEDIA_FILE_NAME_IA64 "\\EFI\\CLOVER\\CLOVERIA64.EFI"_XSW -#define CLOVER_MEDIA_FILE_NAME_X64 "\\EFI\\CLOVER\\CLOVERX64.EFI"_XSW -#define CLOVER_MEDIA_FILE_NAME_ARM "\\EFI\\CLOVER\\CLOVERARM.EFI"_XSW +#define CLOVER_MEDIA_FILE_NAME_IA32 L"\\EFI\\CLOVER\\CLOVERIA32.EFI"_XSW +#define CLOVER_MEDIA_FILE_NAME_IA64 L"\\EFI\\CLOVER\\CLOVERIA64.EFI"_XSW +#define CLOVER_MEDIA_FILE_NAME_X64 L"\\EFI\\CLOVER\\CLOVERX64.EFI"_XSW +#define CLOVER_MEDIA_FILE_NAME_ARM L"\\EFI\\CLOVER\\CLOVERARM.EFI"_XSW #if defined (MDE_CPU_IA32) #define CLOVER_MEDIA_FILE_NAME CLOVER_MEDIA_FILE_NAME_IA32 @@ -200,7 +200,7 @@ VOID ScanTool(VOID) // DBG("Scanning for tools...\n"); if (!(ThemeX.HideUIFlags & HIDEUI_FLAG_SHELL)) { if (!AddToolEntry(L"\\EFI\\CLOVER\\tools\\Shell64U.efi"_XSW, NULL, L"UEFI Shell 64", SelfVolume, ThemeX.GetIcon(BUILTIN_ICON_TOOL_SHELL), 'S', NullXStringArray)) { - AddToolEntry("\\EFI\\CLOVER\\tools\\Shell64.efi"_XSW, NULL, L"EFI Shell 64", SelfVolume, ThemeX.GetIcon(BUILTIN_ICON_TOOL_SHELL), 'S', NullXStringArray); + AddToolEntry(L"\\EFI\\CLOVER\\tools\\Shell64.efi"_XSW, NULL, L"EFI Shell 64", SelfVolume, ThemeX.GetIcon(BUILTIN_ICON_TOOL_SHELL), 'S', NullXStringArray); } } From 82b679bcbd11e5d0e1c2c2e69e3961803f25f14f Mon Sep 17 00:00:00 2001 From: Jief L Date: Wed, 29 Apr 2020 23:34:28 +0300 Subject: [PATCH 04/12] Avoid memory copy at XString initialisation. --- .../CloverX64.xcodeproj/project.pbxproj | 4 + .../cpp_tests.xcodeproj/project.pbxproj | 115 +++ rEFIt_UEFI/Platform/Posix/stdio.cpp | 24 +- rEFIt_UEFI/cpp_foundation/XString.cpp | 100 ++- rEFIt_UEFI/cpp_foundation/XString.h | 80 ++- rEFIt_UEFI/cpp_foundation/XStringAbstract.h | 676 +++++++++++------- rEFIt_UEFI/cpp_foundation/XStringArray.h | 19 +- rEFIt_UEFI/cpp_foundation/XToolsCommon.h | 192 ++--- rEFIt_UEFI/cpp_unit_test/XString_test.cpp | 186 ++--- 9 files changed, 854 insertions(+), 542 deletions(-) diff --git a/Xcode/CloverX64/CloverX64.xcodeproj/project.pbxproj b/Xcode/CloverX64/CloverX64.xcodeproj/project.pbxproj index b62e38e26..3c6bd0eb1 100644 --- a/Xcode/CloverX64/CloverX64.xcodeproj/project.pbxproj +++ b/Xcode/CloverX64/CloverX64.xcodeproj/project.pbxproj @@ -122,6 +122,7 @@ 9A637AE82430D927000B9474 /* XTheme.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5E3262F2428F4EE002240E8 /* XTheme.cpp */; }; 9A637AE92430D928000B9474 /* XTheme.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5E3262F2428F4EE002240E8 /* XTheme.cpp */; }; 9A637AEA2430D928000B9474 /* XTheme.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A5E3262F2428F4EE002240E8 /* XTheme.cpp */; }; + 9A7AEDE7245963BF003AAD04 /* XToolsCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A7AEDE6245963BF003AAD04 /* XToolsCommon.h */; }; 9A9AEB94243F7B5600FBD7D8 /* unicode_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9AEB90243F7B5600FBD7D8 /* unicode_conversions.cpp */; }; 9A9AEB97243F7B5600FBD7D8 /* unicode_conversions.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A9AEB93243F7B5600FBD7D8 /* unicode_conversions.h */; }; 9A9AEB99243F7B7A00FBD7D8 /* printf_lite-test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A9AEB98243F7B7900FBD7D8 /* printf_lite-test.h */; }; @@ -884,6 +885,7 @@ 9A35A6172451FE1500CAFF76 /* XStringAbstract.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XStringAbstract.h; sourceTree = ""; }; 9A4185B42439F29D00BEAFB8 /* LoadOptions_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoadOptions_test.h; sourceTree = ""; }; 9A4185B52439F29D00BEAFB8 /* LoadOptions_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadOptions_test.cpp; sourceTree = ""; }; + 9A7AEDE6245963BF003AAD04 /* XToolsCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XToolsCommon.h; sourceTree = ""; }; 9A9AEB90243F7B5600FBD7D8 /* unicode_conversions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unicode_conversions.cpp; sourceTree = ""; }; 9A9AEB93243F7B5600FBD7D8 /* unicode_conversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unicode_conversions.h; sourceTree = ""; }; 9A9AEB98243F7B7900FBD7D8 /* printf_lite-test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "printf_lite-test.h"; sourceTree = ""; }; @@ -1442,6 +1444,7 @@ 9AC77FAB24176C04005CDD5C /* cpp_foundation */ = { isa = PBXGroup; children = ( + 9A7AEDE6245963BF003AAD04 /* XToolsCommon.h */, 9A9AEB90243F7B5600FBD7D8 /* unicode_conversions.cpp */, 9A9AEB93243F7B5600FBD7D8 /* unicode_conversions.h */, 9AC77FB624176C04005CDD5C /* XArray.h */, @@ -1490,6 +1493,7 @@ 9A105B7824483AE40006DE06 /* usbfix.h in Headers */, 9A28CD33241BC0DF00F3D247 /* strcmp_test.h in Headers */, 9AC7802124176C04005CDD5C /* boot.h in Headers */, + 9A7AEDE7245963BF003AAD04 /* XToolsCommon.h in Headers */, 9AC7802F24176C04005CDD5C /* ati.h in Headers */, 9A105B6D24483AE40006DE06 /* stddef.h in Headers */, 9AC780B52417EE53005CDD5C /* global_test.h in Headers */, diff --git a/Xcode/cpp_tests/cpp_tests.xcodeproj/project.pbxproj b/Xcode/cpp_tests/cpp_tests.xcodeproj/project.pbxproj index e5ad45895..a6d82154d 100644 --- a/Xcode/cpp_tests/cpp_tests.xcodeproj/project.pbxproj +++ b/Xcode/cpp_tests/cpp_tests.xcodeproj/project.pbxproj @@ -41,6 +41,27 @@ 9A28CD4B241F4CCE00F3D247 /* xcode_utf_fixed.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD4A241F4CCE00F3D247 /* xcode_utf_fixed.cpp */; }; 9A28CD4C241F4CCE00F3D247 /* xcode_utf_fixed.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD4A241F4CCE00F3D247 /* xcode_utf_fixed.cpp */; }; 9A28CD4D241F4CCE00F3D247 /* xcode_utf_fixed.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD4A241F4CCE00F3D247 /* xcode_utf_fixed.cpp */; }; + 9A2A7C6C24576CCE00422263 /* LoadOptions_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4185AF2439E4D500BEAFB8 /* LoadOptions_test.cpp */; }; + 9A2A7C6D24576CCE00422263 /* XObjArray_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08522402FE9B00E2B470 /* XObjArray_tests.cpp */; }; + 9A2A7C6E24576CCE00422263 /* abort.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD1D241BB61B00F3D247 /* abort.cpp */; }; + 9A2A7C6F24576CCE00422263 /* XString.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4FFA7C2451C8330050B38B /* XString.cpp */; }; + 9A2A7C7024576CCE00422263 /* XString_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4FFA802451C88D0050B38B /* XString_test.cpp */; }; + 9A2A7C7124576CCE00422263 /* strlen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD1E241BB61B00F3D247 /* strlen.cpp */; }; + 9A2A7C7224576CCE00422263 /* xcode_utf_fixed.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD4A241F4CCE00F3D247 /* xcode_utf_fixed.cpp */; }; + 9A2A7C7324576CCE00422263 /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9223302402FD1000483CBA /* main.cpp */; }; + 9A2A7C7424576CCE00422263 /* strlen_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD15241BACBB00F3D247 /* strlen_test.cpp */; }; + 9A2A7C7524576CCE00422263 /* strcmp_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD06241B8DD400F3D247 /* strcmp_test.cpp */; }; + 9A2A7C7624576CCE00422263 /* strncmp_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD05241B8DD400F3D247 /* strncmp_test.cpp */; }; + 9A2A7C7724576CCE00422263 /* all_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08512402FE9B00E2B470 /* all_tests.cpp */; }; + 9A2A7C7824576CCE00422263 /* unicode_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9AEB8C243F73CE00FBD7D8 /* unicode_conversions.cpp */; }; + 9A2A7C7924576CCE00422263 /* global_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08642403144C00E2B470 /* global_test.cpp */; }; + 9A2A7C7A24576CCE00422263 /* printf_lite.c in Sources */ = {isa = PBXBuildFile; fileRef = 9ACAB116242623EE00BDB3CF /* printf_lite.c */; }; + 9A2A7C7B24576CCE00422263 /* XStringArray_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B084F2402FE9B00E2B470 /* XStringArray_test.cpp */; }; + 9A2A7C7C24576CCE00422263 /* strcmp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A28CD0F241B9EF800F3D247 /* strcmp.cpp */; }; + 9A2A7C7D24576CCE00422263 /* XStringArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4185BE2439F73A00BEAFB8 /* XStringArray.cpp */; }; + 9A2A7C7E24576CCE00422263 /* XArray_tests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B08532402FE9B00E2B470 /* XArray_tests.cpp */; }; + 9A2A7C7F24576CCE00422263 /* printf_lite-test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AA045892425F94D000D6970 /* printf_lite-test.cpp */; }; + 9A2A7C8024576CCE00422263 /* Platform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B085D240300E000E2B470 /* Platform.cpp */; }; 9A4185B12439E4D600BEAFB8 /* LoadOptions_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4185AF2439E4D500BEAFB8 /* LoadOptions_test.cpp */; }; 9A4185B22439E4D600BEAFB8 /* LoadOptions_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4185AF2439E4D500BEAFB8 /* LoadOptions_test.cpp */; }; 9A4185B32439E4D600BEAFB8 /* LoadOptions_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A4185AF2439E4D500BEAFB8 /* LoadOptions_test.cpp */; }; @@ -82,6 +103,15 @@ ); runOnlyForDeploymentPostprocessing = 1; }; + 9A2A7C8224576CCE00422263 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; 9A57C22B2418B9A00029A39F /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; @@ -129,6 +159,7 @@ 9A28CD1E241BB61B00F3D247 /* strlen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = strlen.cpp; sourceTree = ""; }; 9A28CD49241F437C00F3D247 /* xcode_utf_fixed.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = xcode_utf_fixed.h; sourceTree = ""; }; 9A28CD4A241F4CCE00F3D247 /* xcode_utf_fixed.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = xcode_utf_fixed.cpp; sourceTree = ""; }; + 9A2A7C8624576CCE00422263 /* cpp_tests UTF32 c++17 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "cpp_tests UTF32 c++17"; sourceTree = BUILT_PRODUCTS_DIR; }; 9A4185AF2439E4D500BEAFB8 /* LoadOptions_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadOptions_test.cpp; sourceTree = ""; }; 9A4185B02439E4D600BEAFB8 /* LoadOptions_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoadOptions_test.h; sourceTree = ""; }; 9A4185BE2439F73A00BEAFB8 /* XStringArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XStringArray.cpp; sourceTree = ""; }; @@ -140,6 +171,7 @@ 9A57C22F2418B9A00029A39F /* cpp_tests UTF16 unsigned char */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "cpp_tests UTF16 unsigned char"; sourceTree = BUILT_PRODUCTS_DIR; }; 9A57C266241A799B0029A39F /* XString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XString.h; sourceTree = ""; }; 9A6BA73C2449977300BDA52C /* XStringAbstract.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XStringAbstract.h; sourceTree = ""; }; + 9A7AEDE82459696C003AAD04 /* XToolsCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XToolsCommon.h; sourceTree = ""; }; 9A92232D2402FD1000483CBA /* cpp_tests UTF16 signed char */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "cpp_tests UTF16 signed char"; sourceTree = BUILT_PRODUCTS_DIR; }; 9A9223302402FD1000483CBA /* main.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; 9A92234D2402FD9500483CBA /* Platform.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Platform.h; sourceTree = ""; }; @@ -178,6 +210,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 9A2A7C8124576CCE00422263 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 9A57C22A2418B9A00029A39F /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -198,6 +237,7 @@ 9A0B08432402FE9300E2B470 /* cpp_foundation */ = { isa = PBXGroup; children = ( + 9A7AEDE82459696C003AAD04 /* XToolsCommon.h */, 9A4FFA7C2451C8330050B38B /* XString.cpp */, 9A57C266241A799B0029A39F /* XString.h */, 9A6BA73C2449977300BDA52C /* XStringAbstract.h */, @@ -300,6 +340,7 @@ 9A92232D2402FD1000483CBA /* cpp_tests UTF16 signed char */, 9A0B08862403B08400E2B470 /* cpp_tests UTF32 */, 9A57C22F2418B9A00029A39F /* cpp_tests UTF16 unsigned char */, + 9A2A7C8624576CCE00422263 /* cpp_tests UTF32 c++17 */, ); name = Products; sourceTree = ""; @@ -364,6 +405,23 @@ productReference = 9A0B08862403B08400E2B470 /* cpp_tests UTF32 */; productType = "com.apple.product-type.tool"; }; + 9A2A7C6A24576CCE00422263 /* cpp_tests UTF32 c++17 */ = { + isa = PBXNativeTarget; + buildConfigurationList = 9A2A7C8324576CCE00422263 /* Build configuration list for PBXNativeTarget "cpp_tests UTF32 c++17" */; + buildPhases = ( + 9A2A7C6B24576CCE00422263 /* Sources */, + 9A2A7C8124576CCE00422263 /* Frameworks */, + 9A2A7C8224576CCE00422263 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "cpp_tests UTF32 c++17"; + productName = cpp_tests; + productReference = 9A2A7C8624576CCE00422263 /* cpp_tests UTF32 c++17 */; + productType = "com.apple.product-type.tool"; + }; 9A57C2172418B9A00029A39F /* cpp_tests UTF16 unsigned char */ = { isa = PBXNativeTarget; buildConfigurationList = 9A57C22C2418B9A00029A39F /* Build configuration list for PBXNativeTarget "cpp_tests UTF16 unsigned char" */; @@ -427,6 +485,7 @@ 9A92232C2402FD1000483CBA /* cpp_tests UTF16 signed char */, 9A0B08712403B08400E2B470 /* cpp_tests UTF32 */, 9A57C2172418B9A00029A39F /* cpp_tests UTF16 unsigned char */, + 9A2A7C6A24576CCE00422263 /* cpp_tests UTF32 c++17 */, ); }; /* End PBXProject section */ @@ -460,6 +519,34 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 9A2A7C6B24576CCE00422263 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 9A2A7C6C24576CCE00422263 /* LoadOptions_test.cpp in Sources */, + 9A2A7C6D24576CCE00422263 /* XObjArray_tests.cpp in Sources */, + 9A2A7C6E24576CCE00422263 /* abort.cpp in Sources */, + 9A2A7C6F24576CCE00422263 /* XString.cpp in Sources */, + 9A2A7C7024576CCE00422263 /* XString_test.cpp in Sources */, + 9A2A7C7124576CCE00422263 /* strlen.cpp in Sources */, + 9A2A7C7224576CCE00422263 /* xcode_utf_fixed.cpp in Sources */, + 9A2A7C7324576CCE00422263 /* main.cpp in Sources */, + 9A2A7C7424576CCE00422263 /* strlen_test.cpp in Sources */, + 9A2A7C7524576CCE00422263 /* strcmp_test.cpp in Sources */, + 9A2A7C7624576CCE00422263 /* strncmp_test.cpp in Sources */, + 9A2A7C7724576CCE00422263 /* all_tests.cpp in Sources */, + 9A2A7C7824576CCE00422263 /* unicode_conversions.cpp in Sources */, + 9A2A7C7924576CCE00422263 /* global_test.cpp in Sources */, + 9A2A7C7A24576CCE00422263 /* printf_lite.c in Sources */, + 9A2A7C7B24576CCE00422263 /* XStringArray_test.cpp in Sources */, + 9A2A7C7C24576CCE00422263 /* strcmp.cpp in Sources */, + 9A2A7C7D24576CCE00422263 /* XStringArray.cpp in Sources */, + 9A2A7C7E24576CCE00422263 /* XArray_tests.cpp in Sources */, + 9A2A7C7F24576CCE00422263 /* printf_lite-test.cpp in Sources */, + 9A2A7C8024576CCE00422263 /* Platform.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 9A57C2182418B9A00029A39F /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -536,6 +623,25 @@ }; name = Release; }; + 9A2A7C8424576CCE00422263 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CODE_SIGN_STYLE = Automatic; + GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 9A2A7C8524576CCE00422263 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; 9A57C22D2418B9A00029A39F /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -773,6 +879,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 9A2A7C8324576CCE00422263 /* Build configuration list for PBXNativeTarget "cpp_tests UTF32 c++17" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 9A2A7C8424576CCE00422263 /* Debug */, + 9A2A7C8524576CCE00422263 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 9A57C22C2418B9A00029A39F /* Build configuration list for PBXNativeTarget "cpp_tests UTF16 unsigned char" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/rEFIt_UEFI/Platform/Posix/stdio.cpp b/rEFIt_UEFI/Platform/Posix/stdio.cpp index a8f8679ca..2c5d3ddd3 100755 --- a/rEFIt_UEFI/Platform/Posix/stdio.cpp +++ b/rEFIt_UEFI/Platform/Posix/stdio.cpp @@ -44,24 +44,28 @@ int printf(const char* format, ...) const char* strerror(EFI_STATUS Status) { + size_t size = stdio_static_buf.allocatedSize(); UINTN n = 0; - do { - stdio_static_buf.CheckSize(stdio_static_buf.length()+10); - n = AsciiSPrint(stdio_static_buf.dataSized(stdio_static_buf.allocatedSize()), stdio_static_buf.allocatedSize(), "%r", Status); - } while ( n > stdio_static_buf.allocatedSize() - 2 ); - + n = AsciiSPrint(stdio_static_buf.dataSized(stdio_static_buf.allocatedSize()), stdio_static_buf.allocatedSize(), "%r", Status); + while ( n > size - 2 ) + { + size += 10; + n = AsciiSPrint(stdio_static_buf.dataSized(size), size, "%r", Status); + } return stdio_static_buf.s(); } //this function print guid in LittleEndian format while we need BigEndian as Apple do const char* strguid(EFI_GUID* guid) { + size_t size = stdio_static_buf.allocatedSize(); UINTN n = 0; - do { - stdio_static_buf.CheckSize(stdio_static_buf.length()+10); - n = AsciiSPrint(stdio_static_buf.dataSized(stdio_static_buf.allocatedSize()), stdio_static_buf.allocatedSize(), "%g", guid); - } while ( n > stdio_static_buf.allocatedSize() - 2 ); - + n = AsciiSPrint(stdio_static_buf.dataSized(size), size, "%g", guid); + while ( n > size - 2 ) + { + size += 10; + n = AsciiSPrint(stdio_static_buf.dataSized(size), size, "%g", guid); + } return stdio_static_buf.s(); } diff --git a/rEFIt_UEFI/cpp_foundation/XString.cpp b/rEFIt_UEFI/cpp_foundation/XString.cpp index 08df1e7ad..e00f930c7 100755 --- a/rEFIt_UEFI/cpp_foundation/XString.cpp +++ b/rEFIt_UEFI/cpp_foundation/XString.cpp @@ -20,50 +20,56 @@ #include "../../Include/Library/printf_lite.h" - //----------------------------------------------------------------------------- // Functions //----------------------------------------------------------------------------- - -XString operator"" _XS ( const char* s, size_t len) -{ - XString returnValue; - returnValue.takeValueFrom(s, len); - return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. -} - -XString16 operator"" _XS16 ( const char16_t* s, size_t len) -{ - XString16 returnValue; - returnValue.takeValueFrom(s, len); - return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. -} - -XString32 operator"" _XS32 ( const char32_t* s, size_t len) -{ - XString32 returnValue; - returnValue.takeValueFrom(s, len); - return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. -} - -XStringW operator"" _XSW ( const char* s, size_t len) -{ - XStringW returnValue; - returnValue.takeValueFrom(s, len); - return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. -} - -XStringW operator"" _XSW ( const wchar_t* s, size_t len) -{ - XStringW returnValue; - returnValue.takeValueFrom(s, len); - return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. -} +// +//constexpr LString8 operator"" _XS ( const char* s, size_t len) +//{ +//// LString8 returnValue; +//// returnValue.takeValueFromLiteral(s); +//// (void)len; +//// return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. +// return LString8(s); // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. +//} +// +//XString16 operator"" _XS16 ( const char16_t* s, size_t len) +//{ +// XString16 returnValue; +// returnValue.takeValueFromLiteral(s); +// (void)len; +// return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. +//} +// +//XString32 operator"" _XS32 ( const char32_t* s, size_t len) +//{ +// XString32 returnValue; +// returnValue.takeValueFromLiteral(s); +// (void)len; +// return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. +//} +// +//XStringW operator"" _XSW ( const wchar_t* s, size_t len) +//{ +// XStringW returnValue; +// returnValue.takeValueFromLiteral(s); +// (void)len; +// return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. +//} const XString NullXString; +const XString16 NullXString16; +const XString32 NullXString32; const XStringW NullXStringW; +//template +//XStringW LStringW::operator + (const O* p2) { XStringW s; s.strcat(this->s()); s.strcat(p2); return s; } +// +//template<> +//XStringW LStringW::operator + (const wchar_t* p2) { XStringW s; s.strcat(this->s()); s.strcat(p2); return s; } + + XString SPrintf(const char* format, ...) { va_list va; @@ -71,7 +77,7 @@ XString SPrintf(const char* format, ...) va_start (va, format); str.vSPrintf(format, va); - va_end(va); + va_end(va); return str; } @@ -83,7 +89,7 @@ XStringW SWPrintf(const char* format, ...) va_start (va, format); str.vSWPrintf(format, va); - va_end(va); + va_end(va); return str; } @@ -97,21 +103,3 @@ XStringW SWPrintf(const char* format, ...) // return ret; //} // -// -//XStringW CleanCtrl(const XStringW &S) -//{ -// XStringW ReturnValue; -// UINTN i; -// -// for ( i=0 ; i=0 && S.wc_str()[i] < ' ' ) ReturnValue += 'x'; /* wchar_t are signed */ -//#else -// if ( S.wc_str()[i] < ' ' ) ReturnValue += 'x'; /* wchar_t are unsigned */ -//#endif -// else ReturnValue += S.wc_str()[i]; -// } -// return ReturnValue; -//} - - diff --git a/rEFIt_UEFI/cpp_foundation/XString.h b/rEFIt_UEFI/cpp_foundation/XString.h index de144c1ec..41285760a 100755 --- a/rEFIt_UEFI/cpp_foundation/XString.h +++ b/rEFIt_UEFI/cpp_foundation/XString.h @@ -21,23 +21,33 @@ #define XString16GrowByDefault 16 #endif -//typedef XStringAbstract XString; +//------------------------------------------------------------------------------------------------------------------ +class XString; +class LString8 : public LString +{ + public: + constexpr LString8() = delete; + constexpr LString8(const char* s) : LString(s) {}; + + // no assignement, no destructor + + friend constexpr LString8 operator "" _XS ( const char* s, size_t) { return LString8(s); } +}; class XString : public XStringAbstract { public: XString() : XStringAbstract() {}; XString(const XString& S) : XStringAbstract(S) {} + XString(const LString8& S) : XStringAbstract(S) { } - template - XString(const XStringAbstract &S) : XStringAbstract(S) {} + template // enable_if is to avoid constructing with a non-corresponding LString. To avoid memory allocation. + XString(const OtherXStringClass& S) : XStringAbstract(S) {} XString& operator=(const XString &S) { this->XStringAbstract::operator=(S); return *this; } using XStringAbstract::operator =; - - - + protected: static void transmitSPrintf(const char* buf, unsigned int nbchar, void* context) { @@ -57,7 +67,16 @@ public: vSPrintf(format, va); va_end(va); } +}; + +//------------------------------------------------------------------------------------------------------------------ +class XString16; +class LString16 : public LString +{ + constexpr LString16(const char16_t* s) : LString(s) {}; + + friend constexpr LString16 operator "" _XS16 ( const char16_t* s, size_t) { return LString16(s); } }; class XString16 : public XStringAbstract @@ -66,12 +85,24 @@ class XString16 : public XStringAbstract XString16() : XStringAbstract() {}; XString16(const XString16& S) : XStringAbstract(S) {} - template - XString16(const XStringAbstract &S) : XStringAbstract(S) {} + template // enable_if is to avoid constructing with a non-corresponding LString. To avoid memory allocation. + XString16(const OtherXStringClass& S) : XStringAbstract(S) {} XString16& operator=(const XString16 &S) { this->XStringAbstract::operator=(S); return *this; } using XStringAbstract::operator =; + +// friend LString16 operator "" _XS16 ( const char16_t* s, size_t len); +}; + + +//------------------------------------------------------------------------------------------------------------------ +class XString32; +class LString32 : public LString +{ + constexpr LString32(const char32_t* s) : LString(s) {}; + + friend constexpr LString32 operator "" _XS32 ( const char32_t* s, size_t) { return LString32(s); } }; class XString32 : public XStringAbstract @@ -80,12 +111,25 @@ class XString32 : public XStringAbstract XString32() : XStringAbstract() {}; XString32(const XString32& S) : XStringAbstract(S) {} - template - XString32(const XStringAbstract &S) : XStringAbstract(S) {} + template // enable_if is to avoid constructing with a non-corresponding LString. To avoid memory allocation. + XString32(const OtherXStringClass& S) : XStringAbstract(S) {} XString32& operator=(const XString32 &S) { this->XStringAbstract::operator=(S); return *this; } using XStringAbstract::operator =; + +// friend LString32 operator "" _XS32 ( const char32_t* s, size_t len); +}; + +//------------------------------------------------------------------------------------------------------------------ +class XStringW; +class LStringW : public LString +{ + public: + constexpr LStringW() = delete; + constexpr LStringW(const wchar_t* s) : LString(s) {}; + + friend constexpr LStringW operator "" _XSW ( const wchar_t* s, size_t) { return LStringW(s); } }; class XStringW : public XStringAbstract @@ -94,8 +138,10 @@ class XStringW : public XStringAbstract XStringW() : XStringAbstract() {}; XStringW(const XStringW& S) : XStringAbstract(S) {} - template + template // enable_if is to avoid constructing with a non-corresponding LString. To avoid memory allocation. XStringW(const OtherXStringClass& S) : XStringAbstract(S) {} + + XStringW(const LStringW& S) : XStringAbstract(S) { } XStringW& operator=(const XStringW &S) { this->XStringAbstract::operator=(S); return *this; } @@ -122,14 +168,13 @@ public: vSWPrintf(format, va); va_end(va); } - }; -XString operator"" _XS ( const char* s, size_t len); -XString16 operator"" _XS16 ( const char16_t* s, size_t len); -XString32 operator"" _XS32 ( const char32_t* s, size_t len); -XStringW operator"" _XSW ( const char* s, size_t len); -XStringW operator"" _XSW ( const wchar_t* s, size_t len); + +constexpr LString8 operator"" _XS ( const char* s, size_t len); +constexpr LString16 operator"" _XS16 ( const char16_t* s, size_t len); +constexpr LString32 operator"" _XS32 ( const char32_t* s, size_t len); +constexpr LStringW operator"" _XSW ( const wchar_t* s, size_t len); extern const XString NullXString; extern const XStringW NullXStringW; @@ -144,6 +189,5 @@ XStringW SWPrintf(const char* format, ...) __attribute__((__format__ (__printf__ // //XStringAbstract SubString(const T *S, size_t pos, size_t count); -//XStringAbstract CleanCtrl(const XStringAbstract &S); #endif diff --git a/rEFIt_UEFI/cpp_foundation/XStringAbstract.h b/rEFIt_UEFI/cpp_foundation/XStringAbstract.h index 9707ff8ef..0437cc1de 100755 --- a/rEFIt_UEFI/cpp_foundation/XStringAbstract.h +++ b/rEFIt_UEFI/cpp_foundation/XStringAbstract.h @@ -1,10 +1,27 @@ -//************************************************************************************************* -//************************************************************************************************* -// -// XSTRING -// -//************************************************************************************************* -//************************************************************************************************* +/* + * Copyright (c) 2019 Jief Luce. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * +*/ #if !defined(__XSTRINGABSTRACT_H__) #define __XSTRINGABSTRACT_H__ @@ -179,15 +196,13 @@ size_t XStringAbstract__rindexOf(const O* s, size_t Pos, const P* other, bool to template -class XStringAbstractNoDtor +class __String { public: -// const SubType NullXString; - static T nullChar; - + typedef T char_t; + typedef ThisXStringClass xs_t; protected: T *m_data; - size_t m_allocatedSize; // convenience method. Did it this way to avoid #define in header. They can have an impact on other headers size_t Xmin(size_t x1, size_t x2) const { if ( x1 < x2 ) return x1; return x2; } @@ -203,101 +218,29 @@ protected: size_t offset = size_of_utf_string_len(m_data, (unsigned_type(IntegralType))pos); // If pos is too big, size_of_utf_string_len returns the end of the string return m_data + offset; } - - //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - // Init , Alloc - //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - - void Init(size_t aSize=0) - { - //DBG_XSTRING("Init aSize=%d\n", aSize); - // We don't allocate any memory at first. To not have to test all the time if m_data is null, we init it to an empty string - m_data = &nullChar; - m_allocatedSize = 0; - // if aSize == 0, nothing is done, because m_allocatedSize == aSize - CheckSize(aSize, 0); - } public: - T *CheckSize(size_t nNewSize, size_t nGrowBy = XStringGrowByDefault) // nNewSize is in number of chars, NOT bytes - { - //DBG_XSTRING("CheckSize: m_size=%d, nNewSize=%d\n", m_size, nNewSize); - - if ( m_allocatedSize < nNewSize ) - { - nNewSize += nGrowBy; - if ( m_allocatedSize == 0 ) m_data = (T*)malloc( (nNewSize+1)*sizeof(T) ); - else m_data = (T*)Xrealloc(m_data, (nNewSize+1)*sizeof(T), (m_allocatedSize+1)*sizeof(T)); - if ( !m_data ) { - panic("XStringAbstractNoDtor::CheckSize(%zu, %zu) : Xrealloc(%" PRIuPTR ", %lu, %zd) returned NULL. System halted\n", nNewSize, nGrowBy, uintptr_t(m_data), nNewSize*sizeof(T), m_allocatedSize*sizeof(T)); - } - m_allocatedSize = nNewSize; - m_data[m_allocatedSize] = 0; // we allocated one more char (nNewSize+1). This \0 is an extra precaution. It's not for the normal null terminator. All string operation must considered that only m_allocatedSize bytes were allocated. - } - return m_data; - } -// void setSize(size_t newSize) // nNewSize is in number of chars, NOT bytes -// { -// //DBG_XSTRING("setLength(%d)\n", len); -// CheckSize(newSize); -// // if ( len >= size() ) { -// // DBG_XSTRING("XStringAbstractNoDtor::setLength(size_t len) : len >= size() (%d != %d). System halted\n", len, size()); -// // panic(); -// // } -// m_data[newSize] = 0; // we may rewrite a 0 in nullChar, if no memory were allocated. That's ok. -// } - // T* memoryOffset(size_t i) { // // } - public: - constexpr XStringAbstractNoDtor() : m_data(&nullChar), m_allocatedSize(0) {} + constexpr __String(const T* s) : m_data((T*)s) {} +public: +// constexpr __String() : m_data(&nullChar) { } + constexpr __String(const __String&) = delete; + constexpr __String() = delete; -// ~XStringAbstractNoDtor() -// { -// //DBG_XSTRING("Destructor :%ls\n", data()); -//// if ( m_allocatedSize > 0 ) free((void*)m_data); -// } + // no assignement, no destructor template T* data(IntegralType pos) const { return _data(pos); } -// template::value, IntegralType>::type* = nullptr> - template - T* dataSized(IntegralType size) - { - if ( size<0 ) panic("T* dataSized() -> i < 0"); - if ( (unsigned_type(IntegralType))size > MAX_XSIZE ) panic("T* dataSized() -> i > MAX_XSIZE"); - CheckSize((size_t)size); - return _data(0); - } -// -// // Pos is counted in logical char but size is counted in physical char (char, char16_t, char32_t or wchar_t) -// template -// T* dataSized(IntegralType1 pos, IntegralType2 size) -// { -// if ( pos<0 ) panic("T* dataSized(xisize i, size_t sizeMin, size_t nGrowBy) -> i < 0"); -// if ( size<0 ) panic("T* dataSized(xisize i, size_t sizeMin, size_t nGrowBy) -> i < 0"); -// size_t offset = size_of_utf_string_len(m_data, (typename XStringAbstract__make_unsigned::type)pos); // If pos is too big, size_of_utf_string_len returns the end of the string -// CheckSize(offset + (typename XStringAbstract__make_unsigned::type)size); -// return _data(pos); -// } - - - T* forgetDataWithoutFreeing() - { - T* ret = m_data; - Init(0); - return ret; - } size_t length() const { return length_of_utf_string(m_data); } // size_t sizeZZ() const { return size_of_utf_string(m_data); } size_t sizeInNativeChars() const { return size_of_utf_string(m_data); } size_t sizeInBytes() const { return size_of_utf_string(m_data)*sizeof(T); } size_t sizeInBytesIncludingTerminator() const { return (size_of_utf_string(m_data)+1)*sizeof(T); } // usefull for unit tests - size_t allocatedSize() const { return m_allocatedSize; } const T* wc_str() const { return m_data; } @@ -306,7 +249,6 @@ public: const T* data() const { return m_data; } // todo delete /* Empty ? */ - void setEmpty() { m_data[0] = 0; } // we may rewrite a 0 in nullChar if no memory were allocated (m_data == &nullChar). That's ok. bool isEmpty() const { return m_data == nullptr || *m_data == 0; } bool notEmpty() const { return !isEmpty(); } @@ -323,7 +265,7 @@ public: char32_t char32At(IntegralType i) const { if (i < 0) { - panic("XStringAbstractNoDtor::char32At(size_t i) : i < 0. System halted\n"); + panic("__String::char32At(size_t i) : i < 0. System halted\n"); } size_t nb = 0; const T *p = m_data; @@ -332,7 +274,7 @@ public: p = get_char32_from_string(p, &char32); if (!char32) { if ( (unsigned_type(IntegralType))i == nb ) return 0; // no panic if we want to access the null terminator - panic("XStringAbstractNoDtor::char32At(size_t i) : i >= length(). System halted\n"); + panic("__String::char32At(size_t i) : i >= length(). System halted\n"); } nb += 1; } while (nb <= (unsigned_type(IntegralType))i); @@ -353,137 +295,21 @@ public: char32_t lastChar() const { if ( length() > 0 ) return char32At(length()-1); else return 0; } - - //--------------------------------------------------------------------- strcat, strcpy, operator = - - /* strcpy char */ - template - void strcpy(O otherChar) - { - if ( otherChar != 0) { - size_t newSize = utf_size_of_utf_string_len(m_data, &otherChar, 1); - CheckSize(newSize+1, 0); - utf_string_from_utf_string_len(m_data, m_allocatedSize, &otherChar, 1); - m_data[newSize] = 0; - }else{ - setEmpty(); - } - } - /* strcpy */ - template - void strcpy(const O* other) - { - if ( other && *other ) { - size_t newSize = utf_size_of_utf_string(m_data, other); - CheckSize(newSize+1, 0); - utf_string_from_utf_string(m_data, m_allocatedSize, other); - m_data[newSize] = 0; - }else{ - setEmpty(); - } - } - /* strncpy */ - template - void strncpy(const O* other, size_t other_len) - { - if ( other && *other && other_len > 0 ) { - size_t newSize = utf_size_of_utf_string_len(m_data, other, other_len); - CheckSize(newSize+1, 0); - utf_string_from_utf_string_len(m_data, m_allocatedSize, other, other_len); - m_data[newSize] = 0; - }else{ - setEmpty(); - } - } - - /* strcat char */ - template - void strcat(O otherChar) - { - if ( otherChar ) { - size_t currentSize = size_of_utf_string(m_data); - size_t newSize = currentSize + utf_size_of_utf_string_len(m_data, &otherChar, 1); - CheckSize(newSize+1, 0); - utf_string_from_utf_string_len(m_data+currentSize, m_allocatedSize, &otherChar, 1); - m_data[newSize] = 0; - }else{ - // nothing to do - } - } - /* strcat */ - template - void strcat(const O* other) - { - if ( other && *other ) { - size_t currentSize = size_of_utf_string(m_data); // size is number of T, not in bytes - size_t newSize = currentSize + utf_size_of_utf_string(m_data, other); // size is number of T, not in bytes - CheckSize(newSize+1, 0); - utf_string_from_utf_string(m_data+currentSize, m_allocatedSize-currentSize, other); - m_data[newSize] = 0; - }else{ - // nothing to do - } - } - /* strncat */ - template - void strncat(const O* other, size_t other_len) - { - if ( other && *other && other_len > 0 ) { - size_t currentSize = size_of_utf_string(m_data); - size_t newSize = currentSize + utf_size_of_utf_string_len(m_data, other, other_len); - CheckSize(newSize+1, 0); - utf_string_from_utf_string_len(m_data+currentSize, m_allocatedSize, other, other_len); - m_data[newSize] = 0; - }else{ - // nothing to do - } - } - /* takeValueFrom */ - template - ThisXStringClass& takeValueFrom(const XStringAbstractNoDtor& S) { strcpy(S.s()); return *((ThisXStringClass*)this); } - template - ThisXStringClass& takeValueFrom(const O* S) { strcpy(S); return *((ThisXStringClass*)this); } - template - ThisXStringClass& takeValueFrom(const XStringAbstractNoDtor& S, size_t len) { strncpy(S.data(0), len); return *((ThisXStringClass*)this); } - template - ThisXStringClass& takeValueFrom(const O* S, size_t len) { strncpy(S, len); return *((ThisXStringClass*)this); } - - /* copy ctor */ - XStringAbstractNoDtor(const XStringAbstractNoDtor &S) { Init(0); takeValueFrom(S); } - /* ctor */ - template - explicit XStringAbstractNoDtor(const XStringAbstractNoDtor& S) { Init(0); takeValueFrom(S); } -// template -// explicit XStringAbstractNoDtor(const O* S) { Init(0); takeValueFrom(S); } +// /* copy ctor */ +// __String(const __String &S) { Init(0); takeValueFrom(S); } +// /* ctor */ +// template +// explicit __String(const __String& S) { Init(0); takeValueFrom(S); } +//// template +//// explicit __String(const O* S) { Init(0); takeValueFrom(S); } /* Copy Assign */ // Only other XString, no litteral at the moment. - XStringAbstractNoDtor& operator =(const XStringAbstractNoDtor& S) { strcpy(S.s()); return *this; } - /* Assign */ - template - ThisXStringClass& operator =(const XStringAbstractNoDtor& S) { strcpy(S.s()); return *((ThisXStringClass*)this); } -// template -// ThisXStringClass& operator =(const O* S) { strcpy(S); return *this; } - - /* += */ - template - ThisXStringClass& operator += (const XStringAbstractNoDtor& S) { strcat(S.s()); return *((ThisXStringClass*)this); } - template - ThisXStringClass& operator += (O S) { strcat(S); return *((ThisXStringClass*)this); } - template - ThisXStringClass& operator += (const O* S) { strcat(S); return *((ThisXStringClass*)this); } - - - template - ThisXStringClass operator + (const XStringAbstractNoDtor& p2) const { ThisXStringClass s; s=*this; s+=p2; return s; } - template - ThisXStringClass operator + (O p1) const { ThisXStringClass s; s=*this; s.strcat(p1); return s; } - template - ThisXStringClass operator + (const O* p2) const { ThisXStringClass s; s=*this; s+=p2; return s; } - template - friend ThisXStringClass operator + (O p1, const ThisXStringClass& p2) { ThisXStringClass s; s.strcat(p1); s.strcat(p2.s()); return s; } - template - friend ThisXStringClass operator + (const O *p1, const ThisXStringClass& p2) { ThisXStringClass s; s.strcat(p1); s.strcat(p2.s()); return s; } - +// __String& operator =(const __String& S) { strcpy(S.s()); return *this; } +// /* Assign */ +// template +// ThisXStringClass& operator =(const __String& S) { strcpy(S.s()); return *((ThisXStringClass*)this); } +//// template +//// ThisXStringClass& operator =(const O* S) { strcpy(S); return *this; } //--------------------------------------------------------------------- indexOf, rindexOf, contains, subString @@ -496,7 +322,7 @@ public: template size_t indexOf(const O* S, size_t Pos = 0) const { return XStringAbstract__indexOf(m_data, Pos, S, false); } template - size_t indexOf(const XStringAbstractNoDtor& S, size_t Pos = 0) const { return indexOf(S.s(), Pos); } + size_t indexOf(const __String& S, size_t Pos = 0) const { return indexOf(S.s(), Pos); } /* IC */ size_t indexOfIC(char32_t char32Searched, size_t Pos = 0) const { @@ -506,7 +332,7 @@ public: template size_t indexOfIC(const O* S, size_t Pos = 0) const { return XStringAbstract__indexOf(m_data, Pos, S, true); } template - size_t indexOfIC(const XStringAbstractNoDtor& S, size_t Pos = 0) const { return indexOfIC(S.s(), Pos); } + size_t indexOfIC(const __String& S, size_t Pos = 0) const { return indexOfIC(S.s(), Pos); } /* rindexOf */ @@ -518,7 +344,7 @@ public: template size_t rindexOf(const O* S, size_t Pos = MAX_XSIZE-1) const { return XStringAbstract__rindexOf(m_data, Pos, S, false); } template - size_t rindexOf(const XStringAbstractNoDtor& S, size_t Pos = MAX_XSIZE-1) const { return rindexOf(S.s(), Pos); } + size_t rindexOf(const __String& S, size_t Pos = MAX_XSIZE-1) const { return rindexOf(S.s(), Pos); } /* IC */ size_t rindexOfIC(const char32_t char32Searched, size_t Pos = MAX_XSIZE-1) const { @@ -528,14 +354,14 @@ public: template size_t rindexOfIC(const O* S, size_t Pos = MAX_XSIZE-1) const { return XStringAbstract__rindexOf(m_data, Pos, S, true); } template - size_t rindexOfIC(const XStringAbstractNoDtor& S, size_t Pos = MAX_XSIZE-1) const { return rindexOf(S.s(), Pos); } + size_t rindexOfIC(const __String& S, size_t Pos = MAX_XSIZE-1) const { return rindexOf(S.s(), Pos); } template - bool contains(const XStringAbstractNoDtor& S) const { return indexOf(S) != MAX_XSIZE; } + bool contains(const __String& S) const { return indexOf(S) != MAX_XSIZE; } template bool contains(const O* S) const { return indexOf(S) != MAX_XSIZE; } template - size_t containsIC(const XStringAbstractNoDtor& S) const { return indexOfIC(S) != MAX_XSIZE; } + size_t containsIC(const __String& S) const { return indexOfIC(S) != MAX_XSIZE; } template size_t containsIC(const O* S) const { return indexOfIC(S) != MAX_XSIZE; } @@ -558,11 +384,11 @@ public: } template - bool startWith(const XStringAbstractNoDtor& otherS) const { return XStringAbstract__startWith(m_data, otherS.m_data, false); } + bool startWith(const __String& otherS) const { return XStringAbstract__startWith(m_data, otherS.m_data, false); } template bool startWith(const O* other) const { return XStringAbstract__startWith(m_data, other, false); } template - bool startWithIC(const XStringAbstractNoDtor& otherS) const { return XStringAbstract__startWith(m_data, otherS.m_data, true); } + bool startWithIC(const __String& otherS) const { return XStringAbstract__startWith(m_data, otherS.m_data, true); } template bool startWithIC(const O* other) const { return XStringAbstract__startWith(m_data, other, true); } @@ -636,7 +462,7 @@ public: // } // } //} -// void insert(const XStringAbstractNoDtor& Str, size_t pos); +// void insert(const __String& Str, size_t pos); //{ // if ( pos < size() ) { // CheckSize(size()+Str.size()); @@ -693,10 +519,10 @@ public: // p += 1; // } // } -// XStringAbstractNoDtor SubStringReplace(T c1, T c2); +// __String SubStringReplace(T c1, T c2); //{ // T* p; -// XStringAbstractNoDtor Result; +// __String Result; // // p = s(); // while ( *p ) { @@ -717,12 +543,12 @@ public: // int Compare(const wchar_t* S) const { return ::Compare(m_data, S); }; // template - bool equal(const XStringAbstractNoDtor& S) const { return XStringAbstract__compare(m_data, S.s(), false) == 0; } + bool equal(const __String& S) const { return XStringAbstract__compare(m_data, S.s(), false) == 0; } template bool equal(const O* S) const { return XStringAbstract__compare(m_data, S, false) == 0; } template - bool equalIC(const XStringAbstractNoDtor& S) const { return XStringAbstract__compare(m_data, S.s(), true) == 0; } + bool equalIC(const __String& S) const { return XStringAbstract__compare(m_data, S.s(), true) == 0; } template bool equalIC(const O* S) const { return XStringAbstract__compare(m_data, S, true) == 0; } @@ -731,42 +557,42 @@ public: public: // == operator template - bool operator == (const XStringAbstractNoDtor& s2) const { return (*this).strcmp(s2.s()) == 0; } + bool operator == (const __String& s2) const { return (*this).strcmp(s2.s()) == 0; } // template // bool operator == (const O* s2) const { return (*this).strcmp(s2) == 0; } // template // friend bool operator == (const O* s1, ThisXStringClass& s2) { return s2.strcmp(s1) == 0; } template - bool operator != (const XStringAbstractNoDtor& s2) const { return !(*this == s2); } + bool operator != (const __String& s2) const { return !(*this == s2); } // template // bool operator != (const O* s2) const { return !(*this == s2); } // template // friend bool operator != (const O* s1, const ThisXStringClass& s2) { return s2.strcmp(s1) != 0; } template - bool operator < (const XStringAbstractNoDtor& s2) const { return (*this).strcmp(s2.s()) < 0; } + bool operator < (const __String& s2) const { return (*this).strcmp(s2.s()) < 0; } // template // bool operator < (const O* s2) const { return (*this).strcmp(s2) < 0; } // template // friend bool operator < (const O* s1, const ThisXStringClass& s2) { return s2.strcmp(s1) > 0; } template - bool operator > (const XStringAbstractNoDtor& s2) const { return (*this).strcmp(s2.s()) > 0; } + bool operator > (const __String& s2) const { return (*this).strcmp(s2.s()) > 0; } // template // bool operator > (const O* s2) const { return (*this).strcmp(s2) > 0; } // template // friend bool operator > (const O* s1, const ThisXStringClass& s2) { return s2.strcmp(s1) < 0; } template - bool operator <= (const XStringAbstractNoDtor& s2) const { return (*this).strcmp(s2.s()) <= 0; } + bool operator <= (const __String& s2) const { return (*this).strcmp(s2.s()) <= 0; } // template // bool operator <= (const O* s2) const { return (*this).strcmp(s2) <= 0; } // template // friend bool operator <= (const O* s1, const ThisXStringClass& s2) { return s2.strcmp(s1) >= 0; } template - bool operator >= (const XStringAbstractNoDtor& s2) const { return (*this).strcmp(s2.s()) >= 0; } + bool operator >= (const __String& s2) const { return (*this).strcmp(s2.s()) >= 0; } // template // bool operator >= (const O* s2) const { return (*this).strcmp(s2) >= 0; } // template @@ -775,44 +601,368 @@ public: }; -template -T XStringAbstractNoDtor::nullChar = 0; - +//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx template -class XStringAbstract : public XStringAbstractNoDtor +class LString : public __String { - public: - XStringAbstract() : XStringAbstractNoDtor() {} - XStringAbstract(const XStringAbstract& S) : XStringAbstractNoDtor(S) {} +public: +protected: + constexpr LString(const T* s) : __String(s) {}; + constexpr LString() = delete; + constexpr LString(const LString& L) : __String(L.m_data) {}; - template - XStringAbstract(const XStringAbstract &S) : XStringAbstractNoDtor(S) {} -// - XStringAbstract& operator=(const XStringAbstract &S) { this->XStringAbstractNoDtor::operator=(S); return *this; } - using XStringAbstractNoDtor::operator =; + // no assignement, no destructor - ~XStringAbstract() - { - //DBG_XSTRING("Destructor :%ls\n", data()); - if ( XStringAbstractNoDtor::m_allocatedSize > 0 ) free((void*)XStringAbstractNoDtor::m_data); - } }; - //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +#define m_data __String::m_data + +template +class XStringAbstract : public __String +{ + static T nullChar; + + protected: + size_t m_allocatedSize; + + //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + // Init , Alloc + //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +// +// void Init(size_t aSize=0) +// { +// //DBG_XSTRING("Init aSize=%d\n", aSize); +// // We don't allocate any memory at first. To not have to test all the time if m_data is null, we init it to an empty string +// m_data = &nullChar; +// m_allocatedSize = 0; +// // if aSize == 0, nothing is done, because m_allocatedSize == aSize +// CheckSize(aSize, 0); +// } + + /* + * nNewSize doesn't include null terminator. Alloc(0) will allocate 1 char. + * NOTE : m_allocatedSize WILL include the the null terminator. Alloc(0) makes m_allocatedSize == 1 + */ + void Alloc(size_t nNewSize) + { + if ( m_allocatedSize == 0 ) m_data = (T*)malloc( (nNewSize+1)*sizeof(T) ); + else m_data = (T*)Xrealloc(m_data, (nNewSize+1)*sizeof(T), (m_allocatedSize+1)*sizeof(T)); + if ( !m_data ) { + panic("XStringAbstract::Alloc(%zu) : Xrealloc(%" PRIuPTR ", %lu, %zd) returned NULL. System halted\n", nNewSize, uintptr_t(m_data), (nNewSize+1)*sizeof(T), (m_allocatedSize+1)*sizeof(T)); + } + m_allocatedSize = nNewSize; + } +// public: + T *CheckSize(size_t nNewSize, size_t nGrowBy = XStringGrowByDefault) // nNewSize is in number of chars, NOT bytes + { + //DBG_XSTRING("CheckSize: m_size=%d, nNewSize=%d\n", m_size, nNewSize); + + if ( m_allocatedSize < nNewSize ) + { + nNewSize += nGrowBy; + if ( m_allocatedSize == 0 ) { //if ( *m_data ) { + size_t len = __String::length(); + if ( nNewSize < len ) nNewSize = len; + T* m_dataSav = m_data; + m_data = NULL; + Alloc(nNewSize); + utf_string_from_utf_string(m_data, m_allocatedSize, m_dataSav); + }else{ + Alloc(nNewSize); + } +// m_data[m_allocatedSize] = 0; // we allocated one more char (nNewSize+1). This \0 is an extra precaution. It's not for the normal null terminator. All string operation must considered that only m_allocatedSize bytes were allocated. + } + return m_data; + } +// void setSize(size_t newSize) // nNewSize is in number of chars, NOT bytes +// { +// //DBG_XSTRING("setLength(%d)\n", len); +// CheckSize(newSize); +// // if ( len >= size() ) { +// // DBG_XSTRING("__String::setLength(size_t len) : len >= size() (%d != %d). System halted\n", len, size()); +// // panic(); +// // } +// m_data[newSize] = 0; // we may rewrite a 0 in nullChar, if no memory were allocated. That's ok. +// } + + + public: + /* default ctor */ + XStringAbstract() : __String(&nullChar), m_allocatedSize(0) {} + + /* copy ctor */ + XStringAbstract(const XStringAbstract& S) : __String(&nullChar), m_allocatedSize(0) + { + if ( S.m_data && !S.m_allocatedSize ) { + m_data = S.m_data; + }else{ + takeValueFrom(S); + } + } + + ~XStringAbstract() + { + //DBG_XSTRING("Destructor :%ls\n", data()); + if ( m_allocatedSize > 0 ) free((void*)m_data); + } + + /* ctor */ + template + explicit XStringAbstract(const LString& S) : __String(S.s()), m_allocatedSize(0) {} + + template + explicit XStringAbstract(const XStringAbstract& S) : __String(&nullChar), m_allocatedSize(0) { takeValueFrom(S); } + template + explicit XStringAbstract(const LString& S) : __String(&nullChar), m_allocatedSize(0) { takeValueFrom(S); } +// TEMPORARILY DISABLED +// template +// explicit __String(const O* S) { Init(0); takeValueFrom(S); } +// + /* Copy Assign */ // Only other XString, no litteral at the moment. + XStringAbstract& operator=(const XStringAbstract &S) { takeValueFrom(S); return *this; } + /* Assign */ + template + ThisXStringClass& operator =(const __String& S) { strcpy(S.s()); return *((ThisXStringClass*)this); } +// TEMPORARILY DISABLED +// template +// ThisXStringClass& operator =(const O* S) { strcpy(S); return *this; } + +protected: + ThisXStringClass& takeValueFromLiteral (const T* s) + { + if ( m_allocatedSize > 0 ) panic("XStringAbstract::takeValueFromLiteral -> m_allocatedSize > 0"); + m_data = (T*)s; + return *((ThisXStringClass*)this); + } + +public: + + size_t allocatedSize() const { return m_allocatedSize; } + + void setEmpty() + { + if ( m_allocatedSize <= 0 ) m_data = &nullChar; + else m_data[0] = 0; + } + + + template + T* dataSized(IntegralType size) + { + if ( size<0 ) panic("T* dataSized() -> i < 0"); + if ( (unsigned_type(IntegralType))size > MAX_XSIZE ) panic("T* dataSized() -> i > MAX_XSIZE"); + CheckSize((size_t)size); + return __String::_data(0); + } +// +// // Pos is counted in logical char but size is counted in physical char (char, char16_t, char32_t or wchar_t) +// template +// T* dataSized(IntegralType1 pos, IntegralType2 size) +// { +// if ( pos<0 ) panic("T* dataSized(xisize i, size_t sizeMin, size_t nGrowBy) -> i < 0"); +// if ( size<0 ) panic("T* dataSized(xisize i, size_t sizeMin, size_t nGrowBy) -> i < 0"); +// size_t offset = size_of_utf_string_len(m_data, (typename _xtools__make_unsigned::type)pos); // If pos is too big, size_of_utf_string_len returns the end of the string +// CheckSize(offset + (typename _xtools__make_unsigned::type)size); +// return _data(pos); +// } + + + T* forgetDataWithoutFreeing() + { + T* ret = m_data; + m_data = &nullChar; + m_allocatedSize = 0; + return ret; + } + + + //--------------------------------------------------------------------- strcat, strcpy, operator = + + /* strcpy char */ + template + void strcpy(O otherChar) + { + if ( otherChar != 0) { + size_t newSize = utf_size_of_utf_string_len(m_data, &otherChar, 1); + CheckSize(newSize+1, 0); + utf_string_from_utf_string_len(m_data, m_allocatedSize, &otherChar, 1); + m_data[newSize] = 0; + }else{ + setEmpty(); + } + } + /* strcpy */ + template + void strcpy(const O* other) + { + if ( other && *other ) { + size_t newSize = utf_size_of_utf_string(m_data, other); + CheckSize(newSize+1, 0); + utf_string_from_utf_string(m_data, m_allocatedSize, other); + m_data[newSize] = 0; + }else{ + setEmpty(); + } + } + /* strncpy */ + template + void strncpy(const O* other, size_t other_len) + { + if ( other && *other && other_len > 0 ) { + size_t newSize = utf_size_of_utf_string_len(m_data, other, other_len); + CheckSize(newSize+1, 0); + utf_string_from_utf_string_len(m_data, m_allocatedSize, other, other_len); + m_data[newSize] = 0; + }else{ + setEmpty(); + } + } + + /* strcat char */ + template + void strcat(O otherChar) + { + if ( otherChar ) { + size_t currentSize = size_of_utf_string(m_data); + size_t newSize = currentSize + utf_size_of_utf_string_len(m_data, &otherChar, 1); + CheckSize(newSize+1, 0); + utf_string_from_utf_string_len(m_data+currentSize, m_allocatedSize, &otherChar, 1); + m_data[newSize] = 0; + }else{ + // nothing to do + } + } + /* strcat char* */ + template + void strcat(const O* other) + { + if ( other && *other ) { + size_t currentSize = size_of_utf_string(m_data); // size is number of T, not in bytes + size_t newSize = currentSize + utf_size_of_utf_string(m_data, other); // size is number of T, not in bytes + CheckSize(newSize+1, 0); + utf_string_from_utf_string(m_data+currentSize, m_allocatedSize-currentSize, other); + m_data[newSize] = 0; + }else{ + // nothing to do + } + } + /* strcat __String */ + template + void strcat(const __String& other) + { + size_t currentSize = size_of_utf_string(m_data); // size is number of T, not in bytes + size_t newSize = currentSize + utf_size_of_utf_string(m_data, other.s()); // size is number of T, not in bytes + CheckSize(newSize+1, 0); + utf_string_from_utf_string(m_data+currentSize, m_allocatedSize-currentSize, other.s()); + m_data[newSize] = 0; + } + /* strncat */ + template + void strncat(const O* other, size_t other_len) + { + if ( other && *other && other_len > 0 ) { + size_t currentSize = size_of_utf_string(m_data); + size_t newSize = currentSize + utf_size_of_utf_string_len(m_data, other, other_len); + CheckSize(newSize+1, 0); + utf_string_from_utf_string_len(m_data+currentSize, m_allocatedSize, other, other_len); + m_data[newSize] = 0; + }else{ + // nothing to do + } + } + /* takeValueFrom */ + template + ThisXStringClass& takeValueFrom(const __String& S) { strcpy(S.s()); return *((ThisXStringClass*)this); } + template + ThisXStringClass& takeValueFrom(const O* S) { strcpy(S); return *((ThisXStringClass*)this); } + template + ThisXStringClass& takeValueFrom(const __String& S, size_t len) { strncpy(S.data(0), len); return *((ThisXStringClass*)this); } + template + ThisXStringClass& takeValueFrom(const O* S, size_t len) { strncpy(S, len); return *((ThisXStringClass*)this); } + + + /* += */ + template + ThisXStringClass& operator += (const __String& S) { strcat(S.s()); return *((ThisXStringClass*)this); } + template + ThisXStringClass& operator += (O S) { strcat(S); return *((ThisXStringClass*)this); } + template + ThisXStringClass& operator += (const O* S) { strcat(S); return *((ThisXStringClass*)this); } + + +}; + +template +T XStringAbstract::nullChar = 0; + + +//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + +///* __String + char32_t */ +//template +//XStringClass1 operator + (const __String& p1, char32_t p2) { XStringClass1 s; s.takeValueFrom(p1); s.strcat(p2); return s; } +// +///* __String + __String */ +//template +//XStringClass1 operator + (const __String& p1, const __String& p2) { XStringClass1 s; s.takeValueFrom(p1); s.strcat(p2); return s; } +// +///* char* + __String */ +//template +//XStringClass2 operator + (const CharType1* p1, const __String& p2) { XStringClass2 s; s.takeValueFrom(p1); s.strcat(p2); return s; } +// +///* __String + char* */ +//template +//XStringClass1 operator + (const __String& p1, const CharType2* p2) { XStringClass1 s; s.takeValueFrom(p1); s.strcat(p2); return s; } + + +template _xtools__true_type is_base_of_test_func( Base* ); +template _xtools__false_type is_base_of_test_func( void* ); +template +auto test_pre_is_base_of(int) -> decltype(is_base_of_test_func(static_cast(nullptr))); + + +template< class, class = _xtools__void_t<>, class = _xtools__void_t<> > +struct __string_type { typedef void type; }; +template< typename T > +struct __string_type, _xtools__void_t> { typedef __String type; }; + +#define is___String_t(x) decltype(test_pre_is_base_of< typename __string_type::type , x>(0)) +#define is___String(x) is___String_t(x)::value + + +template< class, class = _xtools__void_t<>, class = _xtools__void_t<> > +struct __lstring_type { typedef void type; }; +template< typename T > +struct __lstring_type, _xtools__void_t> { typedef LString type; }; + +#define is___LString_t(x) decltype(test_pre_is_base_of< typename __lstring_type::type , x>(0)) +#define is___LString(x) is___LString_t(x)::value + +/* __string_class_or::type is T1 is T1 is a subclass of __String. If T1 is not a subclass of __String, returns T2 if it's a subclass of __String */ +template struct __string_class_or; +template +struct __string_class_or { /*typedef double type;*/ }; +template +struct __string_class_or { typedef typename T1::xs_t type; }; +template +struct __string_class_or { typedef typename T2::xs_t type; }; + +//------------------------------------------------------- + operator + +template +typename __string_class_or::type operator + (T1 p1, T2 p2) { typename __string_class_or::type s; s.takeValueFrom(p1); s.strcat(p2); return s; } - - - +//------------------------------------------------------- #undef DBG_XSTRING #undef asciiToLower - +#undef m_data #endif // __XSTRINGABSTRACT_H__ diff --git a/rEFIt_UEFI/cpp_foundation/XStringArray.h b/rEFIt_UEFI/cpp_foundation/XStringArray.h index fc58ebad3..37aab0713 100755 --- a/rEFIt_UEFI/cpp_foundation/XStringArray.h +++ b/rEFIt_UEFI/cpp_foundation/XStringArray.h @@ -33,7 +33,7 @@ class XStringArray_/* : public XStringArraySuper*/ bool isEmpty() const { return this->size() == 0 ; } bool notEmpty() const { return this->size() > 0 ; } -// #define enable_if XStringAbstract__enable_if_t +// #define enable_if _xtools_enable_if_t /* [] */ template const XStringClass& operator [](IntegralType i) const { return array[i]; } @@ -46,8 +46,8 @@ class XStringArray_/* : public XStringArraySuper*/ // const XStringClass& dbg(size_t i) const { return array[i]; } - - XStringClass ConcatAll(const XStringClass& Separator = ", "_XS, const XStringClass& Prefix = NullXString, const XStringClass& Suffix = NullXString) const + template + XStringClass ConcatAll(const XStringClass1& Separator, const XStringClass2& Prefix, const XStringClass3& Suffix) const { xsize i; XStringClass s; @@ -64,6 +64,17 @@ class XStringArray_/* : public XStringArraySuper*/ return s; } + XStringClass ConcatAll() const + { + return ConcatAll(", "_XS, NullXString, NullXString); + } + + template + XStringClass ConcatAll(const XStringClass1& Separator) const + { + return ConcatAll(Separator, NullXString, NullXString); + } + template bool Equal(const OtherXStringArrayClass &aStrings) const @@ -310,7 +321,7 @@ XStringArrayClass Split(const CharType1* S, const CharType2* Separator) // return Split(SS, XSeparator); }; -template +template XStringArrayClass Split(const XStringClass1& S, const XStringClass2& Separator) { return Split(S.s(), Separator.s()); diff --git a/rEFIt_UEFI/cpp_foundation/XToolsCommon.h b/rEFIt_UEFI/cpp_foundation/XToolsCommon.h index f36bea043..381db42f2 100644 --- a/rEFIt_UEFI/cpp_foundation/XToolsCommon.h +++ b/rEFIt_UEFI/cpp_foundation/XToolsCommon.h @@ -10,80 +10,61 @@ #define XToolsCommon_h -struct XStringAbstract__false_type { +struct _xtools__false_type { static constexpr bool value = false; bool v() const { return false; } }; -struct XStringAbstract__true_type { +struct _xtools__true_type { static constexpr bool value = true; bool v() const { return true; } }; /* make unsigned */ template -struct XStringAbstract__make_unsigned {}; +struct _xtools__make_unsigned {}; -template <> struct XStringAbstract__make_unsigned< char> {typedef unsigned char type;}; -template <> struct XStringAbstract__make_unsigned< signed char> {typedef unsigned char type;}; -template <> struct XStringAbstract__make_unsigned {typedef unsigned char type;}; -template <> struct XStringAbstract__make_unsigned< char16_t> {typedef char16_t type;}; -template <> struct XStringAbstract__make_unsigned< char32_t> {typedef char32_t type;}; -template <> struct XStringAbstract__make_unsigned< wchar_t> {typedef wchar_t type;}; -template <> struct XStringAbstract__make_unsigned< signed short> {typedef unsigned short type;}; -template <> struct XStringAbstract__make_unsigned {typedef unsigned short type;}; -template <> struct XStringAbstract__make_unsigned< signed int> {typedef unsigned int type;}; -template <> struct XStringAbstract__make_unsigned {typedef unsigned int type;}; -template <> struct XStringAbstract__make_unsigned< signed long> {typedef unsigned long type;}; -template <> struct XStringAbstract__make_unsigned {typedef unsigned long type;}; -template <> struct XStringAbstract__make_unsigned< signed long long> {typedef unsigned long long type;}; -template <> struct XStringAbstract__make_unsigned {typedef unsigned long long type;}; -#define unsigned_type(x) typename XStringAbstract__make_unsigned::type - -/* enable_if */ -template -struct XStringAbstract__enable_if_t -{}; - -template -struct XStringAbstract__enable_if_t { - typedef T type; -}; -//#define enable_if(x) XStringAbstract__enable_if_t(x, void)::type -#define enable_if(x) typename enable_if_type = typename XStringAbstract__enable_if_t::type - -// -//template< bool B, class T = void > -//using XStringAbstract__enable_if_t = typename XStringAbstract__enable_if::type; +template <> struct _xtools__make_unsigned< char> {typedef unsigned char type;}; +template <> struct _xtools__make_unsigned< signed char> {typedef unsigned char type;}; +template <> struct _xtools__make_unsigned {typedef unsigned char type;}; +template <> struct _xtools__make_unsigned< char16_t> {typedef char16_t type;}; +template <> struct _xtools__make_unsigned< char32_t> {typedef char32_t type;}; +template <> struct _xtools__make_unsigned< wchar_t> {typedef wchar_t type;}; +template <> struct _xtools__make_unsigned< signed short> {typedef unsigned short type;}; +template <> struct _xtools__make_unsigned {typedef unsigned short type;}; +template <> struct _xtools__make_unsigned< signed int> {typedef unsigned int type;}; +template <> struct _xtools__make_unsigned {typedef unsigned int type;}; +template <> struct _xtools__make_unsigned< signed long> {typedef unsigned long type;}; +template <> struct _xtools__make_unsigned {typedef unsigned long type;}; +template <> struct _xtools__make_unsigned< signed long long> {typedef unsigned long long type;}; +template <> struct _xtools__make_unsigned {typedef unsigned long long type;}; // is_integral -template struct XStringAbstract__is_integral_st : public XStringAbstract__false_type {}; -template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_integral_st : public XStringAbstract__true_type {}; -#define is_integral(x) XStringAbstract__is_integral_st::value +template struct _xtools__is_integral_st : public _xtools__false_type {}; +//template <> struct _xtools__is_integral_st : public _xtools__true_type {}; +template <> struct _xtools__is_integral_st : public _xtools__true_type {}; +template <> struct _xtools__is_integral_st : public _xtools__true_type {}; +template <> struct _xtools__is_integral_st : public _xtools__true_type {}; +//template <> struct _xtools__is_integral_st : public _xtools__true_type {}; +template <> struct _xtools__is_integral_st : public _xtools__true_type {}; +template <> struct _xtools__is_integral_st : public _xtools__true_type {}; +template <> struct _xtools__is_integral_st : public _xtools__true_type {}; +template <> struct _xtools__is_integral_st : public _xtools__true_type {}; +template <> struct _xtools__is_integral_st : public _xtools__true_type {}; +template <> struct _xtools__is_integral_st : public _xtools__true_type {}; +template <> struct _xtools__is_integral_st : public _xtools__true_type {}; +template <> struct _xtools__is_integral_st : public _xtools__true_type {}; // is_char -template struct XStringAbstract__is_char_st : public XStringAbstract__false_type {}; -template <> struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_char_st : public XStringAbstract__true_type {}; -#define is_char(x) XStringAbstract__is_char_st::value +template struct _xtools__is_char_st : public _xtools__false_type {}; +template <> struct _xtools__is_char_st : public _xtools__true_type {}; +template <> struct _xtools__is_char_st : public _xtools__true_type {}; +template <> struct _xtools__is_char_st : public _xtools__true_type {}; +template <> struct _xtools__is_char_st : public _xtools__true_type {}; +template <> struct _xtools__is_char_st : public _xtools__true_type {}; +template <> struct _xtools__is_char_st : public _xtools__true_type {}; // //// STRUCT TEMPLATE remove_reference @@ -100,38 +81,81 @@ template <> struct XStringAbstract__is_char_st // }; // STRUCT TEMPLATE remove_const -template - struct remove_const - { // remove const - using type = _Ty; - }; - -template - struct remove_const - { // remove const - using type = _Ty; - }; +//template +// struct remove_const +// { // remove const +// typedef _Ty type; +// }; +// +//template +// struct remove_const +// { // remove const +// typedef _Ty type; +// }; +template< class T > struct _xtools__remove_const_ptr { typedef T type; }; +template< class T > struct _xtools__remove_const_ptr { typedef T type; }; +template< class T > struct _xtools__remove_const_ptr { typedef T type; }; +template< class T > struct _xtools__remove_const_ptr { typedef T type; }; +template< class T, int n > struct _xtools__remove_const_ptr { typedef T type; }; +template< class T, int n > struct _xtools__remove_const_ptr { typedef T type; }; // is_char_ptr -template struct XStringAbstract__is_char_ptr_st : public XStringAbstract__false_type {}; -template <> struct XStringAbstract__is_char_ptr_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_char_ptr_st : public XStringAbstract__true_type {}; -template struct XStringAbstract__is_char_ptr_st : public XStringAbstract__true_type {}; -//template <> struct XStringAbstract__is_char_ptr_st : public XStringAbstract__true_type {}; -//template <> struct XStringAbstract__is_char_ptr_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_char_ptr_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_char_ptr_st : public XStringAbstract__true_type {}; -template struct XStringAbstract__is_char_ptr_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_char_ptr_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_char_ptr_st : public XStringAbstract__true_type {}; -template struct XStringAbstract__is_char_ptr_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_char_ptr_st : public XStringAbstract__true_type {}; -template <> struct XStringAbstract__is_char_ptr_st : public XStringAbstract__true_type {}; -template struct XStringAbstract__is_char_ptr_st : public XStringAbstract__true_type {}; -#define is_char_ptr(x) XStringAbstract__is_char_ptr_st::type>::value +template struct _xtools__is_char_ptr_st : public _xtools__false_type {}; +template <> struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template <> struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template <> struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template <> struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template <> struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template <> struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template <> struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template <> struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template <> struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template <> struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template <> struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template <> struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +template struct _xtools__is_char_ptr_st : public _xtools__true_type {}; +/* enable_if */ +template +struct _xtools_enable_if_t +{}; + +template +struct _xtools_enable_if_t { + typedef T type; +}; + + + +template< class... > +using _xtools__void_t = void; + +/* has type member */ +// primary template handles types that have no nested ::type member: +template< class, class = _xtools__void_t<> > +struct _xtools__has_type_member : _xtools__false_type { }; + +// specialization recognizes types that do have a nested ::type member: +template< class T > +struct _xtools__has_type_member> : _xtools__true_type { }; + + + + + +#define unsigned_type(x) typename _xtools__make_unsigned::type +#define is_integral(x) _xtools__is_integral_st::value +#define is_char(x) _xtools__is_char_st::value +#define is_char_ptr(x) _xtools__is_char_ptr_st::type>::value +#define enable_if_t(x) typename _xtools_enable_if_t::type +#define enable_if(x) typename enable_if_type = typename _xtools_enable_if_t::type #endif /* XToolsCommon_h */ diff --git a/rEFIt_UEFI/cpp_unit_test/XString_test.cpp b/rEFIt_UEFI/cpp_unit_test/XString_test.cpp index 710c87550..622730865 100755 --- a/rEFIt_UEFI/cpp_unit_test/XString_test.cpp +++ b/rEFIt_UEFI/cpp_unit_test/XString_test.cpp @@ -859,7 +859,7 @@ SimpleString teststrncat_(const InitialValue& initialValue, const ValueToCat& va xstr.takeValueFrom(initialValue.cha); xstr.strncat(valueToCat.cha, i); - size_t expectedLength = length_of_utf_string(initialValue.cha) + min(i, valueToCat.utf32_length); + size_t expectedLength = length_of_utf_string(initialValue.cha) + Xmin(i, valueToCat.utf32_length); CHECK_RESULT(xstr.length() == expectedLength, ssprintf("xstr.length() == expectedLength (%zu)", expectedLength), ssprintf("xstr.length() != expectedLength (%zu!=%zu)", xstr.length(), expectedLength) @@ -1411,34 +1411,34 @@ SimpleString teststartWith_(const InitialValue& initialValue) // typedef typename XStringClassInfo::ch_t ch_t; // ch_t c; // dummy for call utf function - XStringClass initialString; - initialString.takeValueFrom(initialValue.cha); + XStringClass initia__String; + initia__String.takeValueFrom(initialValue.cha); char32_t expectedChar = 0; if ( initialValue.utf32_length > 0) expectedChar = initialValue.utf32[initialValue.utf32_length-1]; for ( size_t count = 0 ; count < initialValue.utf32_length+3 ; count+=1 ) { - XStringClass subStr = initialString.subString(0, count); + XStringClass subStr = initia__String.subString(0, count); bool expectedResult = true; if ( subStr.length() > 0 && count >= initialValue.utf32_length ) expectedResult = false; - CHECK_RESULT(initialString.startWith(subStr) == expectedResult, - ssprintf("\"%s\".startWith(\"%s\") == %d", SimpleString(initialString.s()).c_str(), SimpleString(subStr.s()).c_str(), expectedResult), - ssprintf("\"%s\".startWith(\"%s\") != %d", SimpleString(initialString.s()).c_str(), SimpleString(subStr.s()).c_str(), expectedResult) + CHECK_RESULT(initia__String.startWith(subStr) == expectedResult, + ssprintf("\"%s\".startWith(\"%s\") == %d", SimpleString(initia__String.s()).c_str(), SimpleString(subStr.s()).c_str(), expectedResult), + ssprintf("\"%s\".startWith(\"%s\") != %d", SimpleString(initia__String.s()).c_str(), SimpleString(subStr.s()).c_str(), expectedResult) ); -//initialString.startWith(subStr); +//initia__String.startWith(subStr); - subStr = initialString.subString(0, count-1) + ((char32_t)(initialValue.utf32[count-1]+1)); + subStr = initia__String.subString(0, count-1) + ((char32_t)(initialValue.utf32[count-1]+1)); expectedResult = false; - CHECK_RESULT(initialString.startWith(subStr) == expectedResult, - ssprintf("\"%s\".startWith(\"%s\") == %d", SimpleString(initialString.s()).c_str(), SimpleString(subStr.s()).c_str(), expectedResult), - ssprintf("\"%s\".startWith(\"%s\") != %d", SimpleString(initialString.s()).c_str(), SimpleString(subStr.s()).c_str(), expectedResult) + CHECK_RESULT(initia__String.startWith(subStr) == expectedResult, + ssprintf("\"%s\".startWith(\"%s\") == %d", SimpleString(initia__String.s()).c_str(), SimpleString(subStr.s()).c_str(), expectedResult), + ssprintf("\"%s\".startWith(\"%s\") != %d", SimpleString(initia__String.s()).c_str(), SimpleString(subStr.s()).c_str(), expectedResult) ); -//subStr = initialString.subString(0, count-1); +//subStr = initia__String.subString(0, count-1); //subStr = subStr + ((char32_t)(initialValue.utf32[count-1]+1)); -//initialString.startWith(subStr); +//initia__String.startWith(subStr); } //str.takeValueFrom(initialValue.cha); @@ -1463,16 +1463,16 @@ SimpleString testbasename_(const InitialValue& initialValue, const TestString::ch_t ch_t; // ch_t c; // dummy for call utf function - XStringClass initialString; - initialString.takeValueFrom(initialValue.cha); + XStringClass initia__String; + initia__String.takeValueFrom(initialValue.cha); - XStringClass xstr = initialString.basename(); + XStringClass xstr = initia__String.basename(); CHECK_RESULT(xstr.strcmp(expectedResult.cha) == 0, - ssprintf("\"%s\".basename() == \"%s\"", SimpleString(initialString.s()).c_str(), SimpleString(expectedResult.cha).c_str()), - ssprintf("\"%s\".basename() != (\"%s\"!=\"%s\")", SimpleString(initialString.s()).c_str(), SimpleString(xstr.s()).c_str(), SimpleString(expectedResult.cha).c_str()) + ssprintf("\"%s\".basename() == \"%s\"", SimpleString(initia__String.s()).c_str(), SimpleString(expectedResult.cha).c_str()), + ssprintf("\"%s\".basename() != (\"%s\"!=\"%s\")", SimpleString(initia__String.s()).c_str(), SimpleString(xstr.s()).c_str(), SimpleString(expectedResult.cha).c_str()) ); -XStringClass xstr2 = initialString.basename(); +XStringClass xstr2 = initia__String.basename(); return SimpleString(); } @@ -1494,23 +1494,23 @@ XStringClass xstr2 = initialString.basename(); //#include //std::is_class +// +//void func_test(XStringW& xsw) +//{ +// (void)xsw; +//} -void func_test(XStringW& xsw) -{ - (void)xsw; -} - -template -class CE +class C { public: - const T* data; - constexpr CE() : data(0) { } + typedef char char_t; + const char* data; + constexpr C() : data(0) { } }; -class CE2 : public XStringAbstractNoDtor -{ -}; +//constexpr LString8 g_xs1 = "foobar"; +//constexpr LStringW g_xsw1 = L"foobar"; +//XString g_xs2 = "foobar"_XS; int XString_tests() { @@ -1518,52 +1518,27 @@ int XString_tests() // printf("XString16_tests -> Enter\n"); #endif -//constexpr CE ce; -//constexpr CE2 xsw; +//LString8 a = "dfsf"_XS; +//XStringW b = "ssdfsdf"_XS; +//XString c = a + b; -//const char c = ' '; -//const char* cc = " "; -//char buf[64]; -//char16_t* buf16 = (char16_t*)u"foo16"; -XString x1("a"_XS); -XString x2("b"_XS); -XStringW xw1("c"_XS); +//char c = 1; +//int ii = sizeof(size_t); +//unsigned long long ull = 1; +//unsigned long long ll = 3; +//xw1.dataSized(c); +//xw1.dataSized(ii); +//xw1.dataSized(ull); +//xw1.dataSized(ll); -char c = 1; -int ii = sizeof(size_t); -unsigned long long ull = 1; -unsigned long long ll = 3; -xw1.dataSized(c); -xw1.dataSized(ii); -xw1.dataSized(ull); -xw1.dataSized(ll); - -//auto x3 = xw1 = x1; -//func_test(x3); -// -//XStringAbstract__is_char_st a; -//printf("a.v()=%d\n", a.v()); - -//XStringW sw1 = buf16; - -//std::is_array b; - -//XStringAbstract__enable_if_t::type a; - -//printf("%ls", XStringW().takeValueFrom(" ").s()); -//func_test(XStringW().takeValueFrom(" ")); - -// testDefaultCtor("XString"); -// XString16 a = u"toto"_XS16; - -const char* utf8 = "ギ"; (void)utf8; -size_t utf8_size = sizeof("ギ") - 1; (void)utf8_size; // this char is 6 bytes long ! -const wchar_t* utfw = L"ギ"; (void)utfw; -size_t utfw_size = sizeof(L"ギ") - 1; (void)utfw_size; // this char is 6 bytes long ! -const char16_t* utf16 = u"ギ"; (void)utf16; -size_t utf16_size = sizeof(u"ギ") - 1; (void)utf16_size; // this char is 6 bytes long ! -const char32_t* utf32 = U"ギ"; (void)utf32; -size_t utf32_size = sizeof(U"ギ") - 1; (void)utf32_size; // this char is 6 bytes long ! +//const char* utf8 = "ギ"; (void)utf8; +//size_t utf8_size = sizeof("ギ") - 1; (void)utf8_size; // this char is 6 bytes long ! +//const wchar_t* utfw = L"ギ"; (void)utfw; +//size_t utfw_size = sizeof(L"ギ") - 1; (void)utfw_size; // this char is 6 bytes long ! +//const char16_t* utf16 = u"ギ"; (void)utf16; +//size_t utf16_size = sizeof(u"ギ") - 1; (void)utf16_size; // this char is 6 bytes long ! +//const char32_t* utf32 = U"ギ"; (void)utf32; +//size_t utf32_size = sizeof(U"ギ") - 1; (void)utf32_size; // this char is 6 bytes long ! //size_t size = sizeof("ꇉ")-1; // this char is 3 bytes long //size_t size = sizeof("伽")-1; // this char is 3 bytes long //size_t size = sizeof("楘")-1; // this char is 3 bytes long @@ -1578,46 +1553,28 @@ size_t utf32_size = sizeof(U"ギ") - 1; (void)utf32_size; // this char is 6 b #ifdef _MSC_VER //SetConsoleOutputCP(65001); #endif -// -//printf("%s", "Выход \n"); -//XString ddd = "Выход "_XS; -//printf(" xstring %s, asize=%zu, sizeinbyte=%zu sizeof=%zu lastcharat=%zu\n", ddd.c_str(), ddd.allocatedSize(), ddd.sizeInBytes(), sizeof(ddd), ddd.indexOf(ddd.lastChar())); -// -//TestString ts1 = TestString(nbchar("Выход "), "Выход ", nbchar(PREFIX_U("Выход ")), PREFIX_U("Выход ")); -//testlastChar_(ts1); - //teststrncpy_("utf8", testStringMultiCodedArray[1].utf8, testStringMultiCodedArray[1].wchar); //testindexOf(XString, utf8, utf16); //testCompare(XString, utf8, utf16); //testindexOf_(testStringMultiCoded4CaseArray[0].utf8); +//testTakeValueFrom_(testStringMultiCodedArray[0].utf16, testStringMultiCodedArray[0].utf16); -//const char* p1 = "foo/bar"; // basename returns bar -//const char* p1 = "foo/"; // basename returns foo -//const char* p1 = "foo//"; // basename returns foo -//const char* p1 = "foo///"; // basename returns foo -//const char* p1 = ""; // basename returns "." -//const char* p1 = " foo/bar "; // basename returns "bar " -//const char* p1 = " foo "; // basename returns " foo " -//const char* p1 = " "; // basename returns " " -//const char* p2 = basename((char*)p1); + TEST_ALL_CLASSES(testDefaultCtor, __TEST0); + TEST_ALL_CLASSES(testEmpty, __TEST0); + TEST_ALL_CLASSES(testTakeValueFrom, TEST_ALL_UTF); + TEST_ALL_CLASSES(testchar32At, TEST_ALL_INTEGRAL); + TEST_ALL_CLASSES(testdataSized, TEST_ALL_INTEGRAL); + TEST_ALL_CLASSES(teststrncpy, TEST_ALL_UTF); // 26944 tests + TEST_ALL_CLASSES(teststrcat, TEST_ALL_UTF_ALL_UTF); + TEST_ALL_CLASSES(teststrncat, TEST_ALL_UTF_ALL_UTF); // 2101632 tests -// TEST_ALL_CLASSES(testDefaultCtor, __TEST0); -// TEST_ALL_CLASSES(testEmpty, __TEST0); -// TEST_ALL_CLASSES(testTakeValueFrom, TEST_ALL_UTF); -// TEST_ALL_CLASSES(testchar32At, TEST_ALL_INTEGRAL); -// TEST_ALL_CLASSES(testdataSized, TEST_ALL_INTEGRAL); -// -// TEST_ALL_CLASSES(teststrncpy, TEST_ALL_UTF); // 26944 tests -// TEST_ALL_CLASSES(teststrcat, TEST_ALL_UTF_ALL_UTF); -// TEST_ALL_CLASSES(teststrncat, TEST_ALL_UTF_ALL_UTF); // 2101632 tests -// TEST_ALL_CLASSES(testSubString, __TEST0); -// TEST_ALL_CLASSES(testCompare, TEST_ALL_UTF); -// TEST_ALL_CLASSES(testindexOf, TEST_ALL_UTF); -// -// TEST_ALL_CLASSES(testlastChar, __TEST0); + TEST_ALL_CLASSES(testCompare, TEST_ALL_UTF); + TEST_ALL_CLASSES(testindexOf, TEST_ALL_UTF); + + TEST_ALL_CLASSES(testlastChar, __TEST0); TEST_ALL_CLASSES(testtrim, __TEST0); TEST_ALL_CLASSES(teststartWith, __TEST0); TEST_ALL_CLASSES(testbasename, __TEST0); @@ -1643,3 +1600,18 @@ size_t utf32_size = sizeof(U"ギ") - 1; (void)utf32_size; // this char is 6 b #endif return nbTestFailed > 0; } + + + + + +//const char* p1 = "foo/bar"; // basename returns bar +//const char* p1 = "foo/"; // basename returns foo +//const char* p1 = "foo//"; // basename returns foo +//const char* p1 = "foo///"; // basename returns foo +//const char* p1 = ""; // basename returns "." +//const char* p1 = " foo/bar "; // basename returns "bar " +//const char* p1 = " foo "; // basename returns " foo " +//const char* p1 = " "; // basename returns " " +//const char* p2 = basename((char*)p1); + From e170b16516ad520f7f72b260016f1febb90c8a5e Mon Sep 17 00:00:00 2001 From: Jief L Date: Thu, 30 Apr 2020 09:03:56 +0300 Subject: [PATCH 05/12] Rename XString to XString8. --- rEFIt_UEFI/Platform/Nvram.cpp | 2 +- rEFIt_UEFI/Platform/Posix/stdio.cpp | 2 +- rEFIt_UEFI/cpp_foundation/XString.cpp | 6 ++--- rEFIt_UEFI/cpp_foundation/XString.h | 26 +++++++++---------- rEFIt_UEFI/cpp_foundation/XStringArray.h | 2 +- rEFIt_UEFI/cpp_unit_test/LoadOptions_test.cpp | 8 +++--- rEFIt_UEFI/cpp_unit_test/XString_test.cpp | 21 +++++++++------ rEFIt_UEFI/cpp_unit_test/global_test.h | 4 +-- rEFIt_UEFI/entry_scan/loader.cpp | 6 ++--- rEFIt_UEFI/gui/shared_with_menu.cpp | 2 +- rEFIt_UEFI/libeg/VectorGraphics.cpp | 8 +++--- rEFIt_UEFI/libeg/XTheme.cpp | 12 ++++----- rEFIt_UEFI/libeg/XTheme.h | 10 +++---- rEFIt_UEFI/libeg/libeg.h | 2 +- rEFIt_UEFI/libeg/libscreen.cpp | 2 +- rEFIt_UEFI/libeg/text.cpp | 2 +- rEFIt_UEFI/refit/main.cpp | 4 +-- 17 files changed, 62 insertions(+), 57 deletions(-) diff --git a/rEFIt_UEFI/Platform/Nvram.cpp b/rEFIt_UEFI/Platform/Nvram.cpp index fce047692..052d3c017 100644 --- a/rEFIt_UEFI/Platform/Nvram.cpp +++ b/rEFIt_UEFI/Platform/Nvram.cpp @@ -1384,7 +1384,7 @@ EFI_STATUS SetStartupDiskVolume ( // Status = SetNvramVariable (L"efi-boot-device", &gEfiAppleBootGuid, Attributes, Size, EfiBootDevice); // FreePool(EfiBootDevice); - XString EfiBootDevice; + XString8 EfiBootDevice; EfiBootDevice.SPrintf( "" "IOMatch" diff --git a/rEFIt_UEFI/Platform/Posix/stdio.cpp b/rEFIt_UEFI/Platform/Posix/stdio.cpp index 2c5d3ddd3..1f6706f0d 100755 --- a/rEFIt_UEFI/Platform/Posix/stdio.cpp +++ b/rEFIt_UEFI/Platform/Posix/stdio.cpp @@ -21,7 +21,7 @@ extern "C" { #include "../../cpp_foundation/XString.h" -static XString stdio_static_buf; +static XString8 stdio_static_buf; static XStringW stdio_static_wbuf; int vprintf(const char* format, VA_LIST va) diff --git a/rEFIt_UEFI/cpp_foundation/XString.cpp b/rEFIt_UEFI/cpp_foundation/XString.cpp index e00f930c7..1e668477f 100755 --- a/rEFIt_UEFI/cpp_foundation/XString.cpp +++ b/rEFIt_UEFI/cpp_foundation/XString.cpp @@ -57,7 +57,7 @@ // return returnValue; // don't do "return returnValue.takeValueFrom(s, len)" because it break the return value optimization. //} -const XString NullXString; +const XString8 NullXString; const XString16 NullXString16; const XString32 NullXString32; const XStringW NullXStringW; @@ -70,10 +70,10 @@ const XStringW NullXStringW; //XStringW LStringW::operator + (const wchar_t* p2) { XStringW s; s.strcat(this->s()); s.strcat(p2); return s; } -XString SPrintf(const char* format, ...) +XString8 SPrintf(const char* format, ...) { va_list va; - XString str; + XString8 str; va_start (va, format); str.vSPrintf(format, va); diff --git a/rEFIt_UEFI/cpp_foundation/XString.h b/rEFIt_UEFI/cpp_foundation/XString.h index 41285760a..3964fe628 100755 --- a/rEFIt_UEFI/cpp_foundation/XString.h +++ b/rEFIt_UEFI/cpp_foundation/XString.h @@ -22,36 +22,36 @@ #endif //------------------------------------------------------------------------------------------------------------------ -class XString; -class LString8 : public LString +class XString8; +class LString8 : public LString { public: constexpr LString8() = delete; - constexpr LString8(const char* s) : LString(s) {}; + constexpr LString8(const char* s) : LString(s) {}; // no assignement, no destructor friend constexpr LString8 operator "" _XS ( const char* s, size_t) { return LString8(s); } }; -class XString : public XStringAbstract +class XString8 : public XStringAbstract { public: - XString() : XStringAbstract() {}; - XString(const XString& S) : XStringAbstract(S) {} - XString(const LString8& S) : XStringAbstract(S) { } + XString8() : XStringAbstract() {}; + XString8(const XString8& S) : XStringAbstract(S) {} + XString8(const LString8& S) : XStringAbstract(S) { } template // enable_if is to avoid constructing with a non-corresponding LString. To avoid memory allocation. - XString(const OtherXStringClass& S) : XStringAbstract(S) {} + XString8(const OtherXStringClass& S) : XStringAbstract(S) {} - XString& operator=(const XString &S) { this->XStringAbstract::operator=(S); return *this; } + XString8& operator=(const XString8 &S) { this->XStringAbstract::operator=(S); return *this; } - using XStringAbstract::operator =; + using XStringAbstract::operator =; protected: static void transmitSPrintf(const char* buf, unsigned int nbchar, void* context) { - ((XString*)(context))->strncat(buf, nbchar); + ((XString8*)(context))->strncat(buf, nbchar); } public: void vSPrintf(const char* format, va_list va) @@ -176,14 +176,14 @@ constexpr LString16 operator"" _XS16 ( const char16_t* s, size_t len); constexpr LString32 operator"" _XS32 ( const char32_t* s, size_t len); constexpr LStringW operator"" _XSW ( const wchar_t* s, size_t len); -extern const XString NullXString; +extern const XString8 NullXString; extern const XStringW NullXStringW; #ifdef _MSC_VER # define __attribute__(x) #endif -XString SPrintf(const char* format, ...) __attribute__((__format__ (__printf__, 1, 2))); +XString8 SPrintf(const char* format, ...) __attribute__((__format__ (__printf__, 1, 2))); XStringW SWPrintf(const char* format, ...) __attribute__((__format__ (__printf__, 1, 2))); diff --git a/rEFIt_UEFI/cpp_foundation/XStringArray.h b/rEFIt_UEFI/cpp_foundation/XStringArray.h index 37aab0713..b42fb6870 100755 --- a/rEFIt_UEFI/cpp_foundation/XStringArray.h +++ b/rEFIt_UEFI/cpp_foundation/XStringArray.h @@ -240,7 +240,7 @@ class XStringArray_/* : public XStringArraySuper*/ }; -class XStringArray : public XStringArray_ +class XStringArray : public XStringArray_ { }; extern const XStringArray NullXStringArray; diff --git a/rEFIt_UEFI/cpp_unit_test/LoadOptions_test.cpp b/rEFIt_UEFI/cpp_unit_test/LoadOptions_test.cpp index 57d7ce624..c736208db 100755 --- a/rEFIt_UEFI/cpp_unit_test/LoadOptions_test.cpp +++ b/rEFIt_UEFI/cpp_unit_test/LoadOptions_test.cpp @@ -183,14 +183,14 @@ int BootOptions_tests() LoadOptions = Old1_AddLoadOption(LoadOptions, L"opt2"); LoadOptions = Old1_AddLoadOption(LoadOptions, L"opt3"); - if ( XString().takeValueFrom(LoadOptions) != "opt1 opt2 opt3"_XS ) return 1; + if ( XString8().takeValueFrom(LoadOptions) != "opt1 opt2 opt3"_XS ) return 1; CHAR16* LoadOptions1 = Old1_RemoveLoadOption(LoadOptions, L"opt1"); - if ( XString().takeValueFrom(LoadOptions1) != "opt2 opt3"_XS ) return 2; + if ( XString8().takeValueFrom(LoadOptions1) != "opt2 opt3"_XS ) return 2; CHAR16* LoadOptions2 = Old1_RemoveLoadOption(LoadOptions, L"opt2"); - if ( XString().takeValueFrom(LoadOptions2) != "opt1 opt3"_XS ) return 3; + if ( XString8().takeValueFrom(LoadOptions2) != "opt1 opt3"_XS ) return 3; CHAR16* LoadOptions3 = Old1_RemoveLoadOption(LoadOptions, L"opt3"); - if ( XString().takeValueFrom(LoadOptions3) != "opt1 opt2"_XS ) return 4; + if ( XString8().takeValueFrom(LoadOptions3) != "opt1 opt2"_XS ) return 4; } // { // XString LoadOptions; diff --git a/rEFIt_UEFI/cpp_unit_test/XString_test.cpp b/rEFIt_UEFI/cpp_unit_test/XString_test.cpp index 622730865..80f402684 100755 --- a/rEFIt_UEFI/cpp_unit_test/XString_test.cpp +++ b/rEFIt_UEFI/cpp_unit_test/XString_test.cpp @@ -267,10 +267,10 @@ struct XStringClassInfo }; template<> -struct XStringClassInfo +struct XStringClassInfo { typedef char ch_t; - typedef XString xs_t; + typedef XString8 xs_t; static constexpr const char* prefix = ""; static constexpr const char* xStringClassName = "XString"; }; @@ -306,7 +306,7 @@ template<> struct XStringClassInfo { typedef char ch_t; - typedef XString xs_t; + typedef XString8 xs_t; static constexpr const char* prefix = ""; static constexpr const char* xStringClassName = "XString"; }; @@ -342,7 +342,7 @@ template<> struct XStringClassInfo> { typedef char ch_t; - typedef XString xs_t; + typedef XString8 xs_t; static constexpr const char* prefix = ""; static constexpr const char* xStringClassName = "XString"; }; @@ -470,7 +470,7 @@ bool displayOnlyIfFailed_tmp; __TEST_ALL_UTF2(test, XStringClass, classEncoding, wchar); \ #define TEST_ALL_CLASSES(test, macro) \ - macro(test, XString, utf8); \ + macro(test, XString8, utf8); \ macro(test, XString16, utf16); \ macro(test, XString32, utf32); \ macro(test, XStringW, wchar); \ @@ -1518,9 +1518,14 @@ int XString_tests() // printf("XString16_tests -> Enter\n"); #endif -//LString8 a = "dfsf"_XS; -//XStringW b = "ssdfsdf"_XS; -//XString c = a + b; +XString8 xs1 = "Test:"_XS; +XStringW xsw1 = L"world"_XSW; +XString8 xs2 = xs1 + "hel" + 'l' + L'o' + U" the " + xsw1; +XString8 xs3 = xs1; + +LString8 a = "Hello"_XS; +XStringW b = L"world"_XSW; +XString8 c = a + "foo"; // + 'o' + L'o' + b + L"bar"; //char c = 1; //int ii = sizeof(size_t); diff --git a/rEFIt_UEFI/cpp_unit_test/global_test.h b/rEFIt_UEFI/cpp_unit_test/global_test.h index 9b797eea7..6b7d441ee 100644 --- a/rEFIt_UEFI/cpp_unit_test/global_test.h +++ b/rEFIt_UEFI/cpp_unit_test/global_test.h @@ -9,10 +9,10 @@ public: } }; -class XStringTest : public XString +class XStringTest : public XString8 { public: - XStringTest(const char *S) : XString() + XStringTest(const char *S) : XString8() { strcpy(S); } diff --git a/rEFIt_UEFI/entry_scan/loader.cpp b/rEFIt_UEFI/entry_scan/loader.cpp index 424b591e1..0a9ae5560 100644 --- a/rEFIt_UEFI/entry_scan/loader.cpp +++ b/rEFIt_UEFI/entry_scan/loader.cpp @@ -64,7 +64,7 @@ const XStringW MACOSX_LOADER_PATH = L"\\System\\Library\\CoreServices\\boot.efi" const XStringW LINUX_ISSUE_PATH = L"\\etc\\issue"_XSW; #define LINUX_BOOT_PATH L"\\boot" #define LINUX_BOOT_ALT_PATH L"\\boot" -const XString LINUX_LOADER_PATH = "vmlinuz"_XS; +const XString8 LINUX_LOADER_PATH = "vmlinuz"_XS; const XStringW LINUX_FULL_LOADER_PATH = SWPrintf("%ls\\%s", LINUX_BOOT_PATH, LINUX_LOADER_PATH.c_str()); #define LINUX_LOADER_SEARCH_PATH L"vmlinuz*" const XStringArray LINUX_DEFAULT_OPTIONS = Split("ro add_efi_memmap quiet splash vt.handoff=7", " "); @@ -84,7 +84,7 @@ typedef struct LINUX_PATH_DATA CONST XStringW Path; CONST XStringW Title; CONST XStringW Icon; - CONST XString Issue; + CONST XString8 Issue; } LINUX_PATH_DATA; typedef struct LINUX_ICON_DATA @@ -339,7 +339,7 @@ STATIC CONST XStringW& LinuxIconNameFromPath(IN CONST XStringW& Path, return linux; } -STATIC CONST XString LinuxInitImagePath[] = { +STATIC CONST XString8 LinuxInitImagePath[] = { "initrd%s"_XS, "initrd.img%s"_XS, "initrd%s.img"_XS, diff --git a/rEFIt_UEFI/gui/shared_with_menu.cpp b/rEFIt_UEFI/gui/shared_with_menu.cpp index 7bda6515a..515d2e7e3 100644 --- a/rEFIt_UEFI/gui/shared_with_menu.cpp +++ b/rEFIt_UEFI/gui/shared_with_menu.cpp @@ -44,7 +44,7 @@ //#include "menu_items/menu_items.h" //#include "../entry_scan/common.h" -CONST XString ArgOptional[NUM_OPT] = { +CONST XString8 ArgOptional[NUM_OPT] = { "arch=i386"_XS, //0 "arch=x86_64"_XS, //1 "-v"_XS, //2 diff --git a/rEFIt_UEFI/libeg/VectorGraphics.cpp b/rEFIt_UEFI/libeg/VectorGraphics.cpp index 021482d81..13dcfdee9 100755 --- a/rEFIt_UEFI/libeg/VectorGraphics.cpp +++ b/rEFIt_UEFI/libeg/VectorGraphics.cpp @@ -53,7 +53,7 @@ extern UINTN FrameTime; textFaces textFace[4]; //0-help 1-message 2-menu 3-test, far future it will be infinite list with id -EFI_STATUS XTheme::ParseSVGXIcon(INTN Id, const XString& IconNameX, XImage* Image) +EFI_STATUS XTheme::ParseSVGXIcon(INTN Id, const XString8& IconNameX, XImage* Image) { EFI_STATUS Status = EFI_NOT_FOUND; NSVGimage *SVGimage; @@ -95,7 +95,7 @@ EFI_STATUS XTheme::ParseSVGXIcon(INTN Id, const XString& IconNameX, XImage* Imag shape->opacity = 0.f; } // if (strstr(shape->id, "BoundingRect") != NULL) { - if (XString().takeValueFrom(shape->id).contains("BoundingRect")) { + if (XString8().takeValueFrom(shape->id).contains("BoundingRect")) { //there is bounds after nsvgParse() IconImage->width = shape->bounds[2] - shape->bounds[0]; IconImage->height = shape->bounds[3] - shape->bounds[1]; @@ -161,7 +161,7 @@ EFI_STATUS XTheme::ParseSVGXIcon(INTN Id, const XString& IconNameX, XImage* Imag // if (strcmp(group->id, IconNameX.c_str()) == 0) { // break; // } - if (IconNameX == XString().takeValueFrom(group->id)) { + if (IconNameX == XString8().takeValueFrom(group->id)) { break; } group = group->parent; @@ -434,7 +434,7 @@ EFI_STATUS XTheme::ParseSVGXTheme(CONST CHAR8* buffer) EFI_STATUS XTheme::LoadSvgFrame(INTN i, OUT XImage* XFrame) { EFI_STATUS Status = EFI_NOT_FOUND; - XString XFrameName = SPrintf("frame_%04lld", i+1); + XString8 XFrameName = SPrintf("frame_%04lld", i+1); Status = ParseSVGXIcon(BUILTIN_ICON_ANIME, XFrameName, XFrame); if (EFI_ERROR(Status)) { DBG("frame '%s' not loaded, status=%s\n", XFrameName.c_str(), strerror(Status)); diff --git a/rEFIt_UEFI/libeg/XTheme.cpp b/rEFIt_UEFI/libeg/XTheme.cpp index aa1c6526d..07baee742 100644 --- a/rEFIt_UEFI/libeg/XTheme.cpp +++ b/rEFIt_UEFI/libeg/XTheme.cpp @@ -299,7 +299,7 @@ void XTheme::Init() static XImage NullIcon; static XImage DummyIcon; -const XImage& XTheme::GetIcon(const XString& Name) +const XImage& XTheme::GetIcon(const XString8& Name) { for (size_t i = 0; i < Icons.size(); i++) { @@ -385,15 +385,15 @@ const XImage& XTheme::GetIconAlt(INTN Id, INTN Alt) //if not found then take emb const XImage& XTheme::LoadOSIcon(const CHAR16* OSIconName) { - return LoadOSIcon(XString().takeValueFrom(OSIconName)); + return LoadOSIcon(XString8().takeValueFrom(OSIconName)); } -const XImage& XTheme::LoadOSIcon(const XString& Full) +const XImage& XTheme::LoadOSIcon(const XString8& Full) { // input value can be L"win", L"ubuntu,linux", L"moja,mac" set by GetOSIconName (OSVersion) - XString First; - XString Second; - XString Third; + XString8 First; + XString8 Second; + XString8 Third; const XImage *ReturnImage; UINTN Comma = Full.indexOf(','); UINTN Size = Full.length(); diff --git a/rEFIt_UEFI/libeg/XTheme.h b/rEFIt_UEFI/libeg/XTheme.h index 83976e9c7..d4790b5e3 100644 --- a/rEFIt_UEFI/libeg/XTheme.h +++ b/rEFIt_UEFI/libeg/XTheme.h @@ -15,7 +15,7 @@ class Icon { public: INTN Id; //for example BUILTIN_ICON_POINTER - XString Name; //for example "os_moja", "vol_internal" + XString8 Name; //for example "os_moja", "vol_internal" XImage Image; XImage ImageNight; bool Native; @@ -126,11 +126,11 @@ public: //fill the theme // const XImage& GetIcon(const char* Name); // const XImage& GetIcon(const CHAR16* Name); - const XImage& GetIcon(const XString& Name); //get by name + const XImage& GetIcon(const XString8& Name); //get by name const XImage& GetIcon(INTN Id); //get by id const XImage& GetIconAlt(INTN Id, INTN Alt); //if id not found const XImage& LoadOSIcon(const CHAR16* OSIconName); //TODO make XString provider - const XImage& LoadOSIcon(const XString& Full); + const XImage& LoadOSIcon(const XString8& Full); bool CheckNative(INTN Id); //fonts @@ -140,7 +140,7 @@ public: INTN RenderText(IN const XStringW& Text, OUT XImage* CompImage_ptr, IN INTN PosX, IN INTN PosY, IN UINTN Cursor, INTN textType, float textScale = 0.f); //overload for UTF8 text - INTN RenderText(IN const XString& Text, OUT XImage* CompImage_ptr, + INTN RenderText(IN const XString8& Text, OUT XImage* CompImage_ptr, IN INTN PosX, IN INTN PosY, IN UINTN Cursor, INTN textType, float textScale = 0.f); VOID MeasureText(IN const XStringW& Text, OUT INTN *Width, OUT INTN *Height); @@ -151,7 +151,7 @@ public: EFI_STATUS GetThemeTagSettings(void* DictPointer); void parseTheme(void* p, const char** dict); //in nano project EFI_STATUS ParseSVGXTheme(const CHAR8* buffer); // in VectorTheme - EFI_STATUS ParseSVGXIcon(INTN Id, const XString& IconNameX, XImage* Image); + EFI_STATUS ParseSVGXIcon(INTN Id, const XString8& IconNameX, XImage* Image); void* LoadTheme(const CHAR16 *TestTheme); //return TagPtr why? EFI_STATUS LoadSvgFrame(INTN i, OUT XImage* XFrame); // for animation diff --git a/rEFIt_UEFI/libeg/libeg.h b/rEFIt_UEFI/libeg/libeg.h index fba96b4e9..e597a9986 100755 --- a/rEFIt_UEFI/libeg/libeg.h +++ b/rEFIt_UEFI/libeg/libeg.h @@ -438,7 +438,7 @@ VOID egDumpGOPVideoModes(VOID); EFI_STATUS egSetMode(INT32 Next); VOID egGetScreenSize(OUT INTN *ScreenWidth, OUT INTN *ScreenHeight); -XString egScreenDescription(VOID); +XString8 egScreenDescription(VOID); BOOLEAN egHasGraphicsMode(VOID); BOOLEAN egIsGraphicsModeEnabled(VOID); VOID egSetGraphicsModeEnabled(IN BOOLEAN Enable); diff --git a/rEFIt_UEFI/libeg/libscreen.cpp b/rEFIt_UEFI/libeg/libscreen.cpp index 9e665d12d..ef119b1fa 100644 --- a/rEFIt_UEFI/libeg/libscreen.cpp +++ b/rEFIt_UEFI/libeg/libscreen.cpp @@ -439,7 +439,7 @@ VOID egGetScreenSize(OUT INTN *ScreenWidth, OUT INTN *ScreenHeight) *ScreenHeight = egScreenHeight; } -XString egScreenDescription(VOID) +XString8 egScreenDescription(VOID) { if (egHasGraphics) { if (GraphicsOutput != NULL) { diff --git a/rEFIt_UEFI/libeg/text.cpp b/rEFIt_UEFI/libeg/text.cpp index 1dcb31ca1..a1fb00066 100644 --- a/rEFIt_UEFI/libeg/text.cpp +++ b/rEFIt_UEFI/libeg/text.cpp @@ -248,7 +248,7 @@ INTN XTheme::GetEmpty(const XImage& Buffer, const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& return m; } -INTN XTheme::RenderText(IN const XString& Text, OUT XImage* CompImage_ptr, +INTN XTheme::RenderText(IN const XString8& Text, OUT XImage* CompImage_ptr, IN INTN PosX, IN INTN PosY, IN UINTN Cursor, INTN textType, float textScale) { const XStringW& UTF16Text = XStringW().takeValueFrom(Text.c_str()); diff --git a/rEFIt_UEFI/refit/main.cpp b/rEFIt_UEFI/refit/main.cpp index 74aa70e5d..851245fc1 100644 --- a/rEFIt_UEFI/refit/main.cpp +++ b/rEFIt_UEFI/refit/main.cpp @@ -751,7 +751,7 @@ static VOID StartLoader(IN LOADER_ENTRY *Entry) // Set boot argument for kernel if no caches, this should force kernel loading if ( OSFLAG_ISSET(Entry->Flags, OSFLAG_NOCACHES) && !Entry->LoadOptions.containsStartWithIC("Kernel=") ) { - XString KernelLocation; + XString8 KernelLocation; if (Entry->OSVersion && AsciiOSVersionToUint64(Entry->OSVersion) <= AsciiOSVersionToUint64("10.9")) { KernelLocation.SPrintf("\"Kernel=/mach_kernel\""); @@ -2137,7 +2137,7 @@ RefitMain (IN EFI_HANDLE ImageHandle, DBG(" string %ls, size=%lld, len=%lld sizeof=%ld iStrLen=%lld\n", aaa, StrSize(aaa), StrLen(aaa), sizeof(aaa), iStrLen(bbb, 10)); const CHAR8* ccc = "Выход "; DBG(" string %s, size=%lld, len=%lld sizeof=%ld iStrLen=%lld\n", ccc, AsciiStrSize(ccc), AsciiStrLen(ccc), sizeof(ccc), iStrLen(ccc, 10)); - XString ddd = "Выход "_XS; + XString8 ddd = "Выход "_XS; // size_t sizex = ddd.allocatedSize(); DBG(" xstring %s, asize=%ld, sizeinbyte=%ld sizeof=%ld lastcharat=%ld\n", ddd.c_str(), ddd.allocatedSize(), ddd.sizeInBytes(), sizeof(ddd), ddd.indexOf(ddd.lastChar())); From 0c88de9390ca4ae3e2fd1597a963f0a54e3d1165 Mon Sep 17 00:00:00 2001 From: Jief L Date: Thu, 30 Apr 2020 09:22:26 +0300 Subject: [PATCH 06/12] Rename _XS to _XS8 --- rEFIt_UEFI/cpp_foundation/XString.cpp | 2 +- rEFIt_UEFI/cpp_foundation/XString.h | 4 +- rEFIt_UEFI/cpp_foundation/XStringArray.h | 6 +-- rEFIt_UEFI/cpp_unit_test/LoadOptions_test.cpp | 54 +++++++++---------- .../cpp_unit_test/XStringArray_test.cpp | 24 ++++----- rEFIt_UEFI/cpp_unit_test/XString_test.cpp | 15 ++++-- rEFIt_UEFI/entry_scan/common.cpp | 6 +-- rEFIt_UEFI/entry_scan/legacy.cpp | 4 +- rEFIt_UEFI/entry_scan/loader.cpp | 54 +++++++++---------- rEFIt_UEFI/gui/REFIT_MENU_SCREEN.cpp | 4 +- rEFIt_UEFI/gui/shared_with_menu.cpp | 40 +++++++------- rEFIt_UEFI/libeg/VectorGraphics.cpp | 16 +++--- rEFIt_UEFI/libeg/XTheme.cpp | 28 +++++----- rEFIt_UEFI/libeg/libscreen.cpp | 4 +- rEFIt_UEFI/refit/main.cpp | 14 ++--- 15 files changed, 140 insertions(+), 135 deletions(-) diff --git a/rEFIt_UEFI/cpp_foundation/XString.cpp b/rEFIt_UEFI/cpp_foundation/XString.cpp index 1e668477f..3d41fcb8c 100755 --- a/rEFIt_UEFI/cpp_foundation/XString.cpp +++ b/rEFIt_UEFI/cpp_foundation/XString.cpp @@ -24,7 +24,7 @@ // Functions //----------------------------------------------------------------------------- // -//constexpr LString8 operator"" _XS ( const char* s, size_t len) +//constexpr LString8 operator"" _XS8 ( const char* s, size_t len) //{ //// LString8 returnValue; //// returnValue.takeValueFromLiteral(s); diff --git a/rEFIt_UEFI/cpp_foundation/XString.h b/rEFIt_UEFI/cpp_foundation/XString.h index 3964fe628..7cca52f81 100755 --- a/rEFIt_UEFI/cpp_foundation/XString.h +++ b/rEFIt_UEFI/cpp_foundation/XString.h @@ -31,7 +31,7 @@ class LString8 : public LString // no assignement, no destructor - friend constexpr LString8 operator "" _XS ( const char* s, size_t) { return LString8(s); } + friend constexpr LString8 operator "" _XS8 ( const char* s, size_t) { return LString8(s); } }; class XString8 : public XStringAbstract @@ -171,7 +171,7 @@ public: }; -constexpr LString8 operator"" _XS ( const char* s, size_t len); +constexpr LString8 operator"" _XS8 ( const char* s, size_t len); constexpr LString16 operator"" _XS16 ( const char16_t* s, size_t len); constexpr LString32 operator"" _XS32 ( const char32_t* s, size_t len); constexpr LStringW operator"" _XSW ( const wchar_t* s, size_t len); diff --git a/rEFIt_UEFI/cpp_foundation/XStringArray.h b/rEFIt_UEFI/cpp_foundation/XStringArray.h index b42fb6870..be36f3a46 100755 --- a/rEFIt_UEFI/cpp_foundation/XStringArray.h +++ b/rEFIt_UEFI/cpp_foundation/XStringArray.h @@ -66,7 +66,7 @@ class XStringArray_/* : public XStringArraySuper*/ XStringClass ConcatAll() const { - return ConcatAll(", "_XS, NullXString, NullXString); + return ConcatAll(", "_XS8, NullXString, NullXString); } template @@ -265,7 +265,7 @@ extern const XStringWArray NullXStringWArray; //template //XStringArrayClass Split(const XStringClass1& S) //{ -// return Split(S, ", "_XS); +// return Split(S, ", "_XS8); //}; @@ -348,7 +348,7 @@ XStringArrayClass Split(const XStringClass1& S, const XStringClass2& Separator) template XStringArrayClass Split(const XStringClass1& S) { - return Split(S, ", "_XS); + return Split(S, ", "_XS8); }; #endif diff --git a/rEFIt_UEFI/cpp_unit_test/LoadOptions_test.cpp b/rEFIt_UEFI/cpp_unit_test/LoadOptions_test.cpp index c736208db..072bd26a0 100755 --- a/rEFIt_UEFI/cpp_unit_test/LoadOptions_test.cpp +++ b/rEFIt_UEFI/cpp_unit_test/LoadOptions_test.cpp @@ -100,7 +100,7 @@ CHAR16 *Old1_RemoveLoadOption(IN CONST CHAR16 *LoadOptions, IN CONST CHAR16 *Loa // if ( LoadOptions.contains(LoadOption) ) return LoadOptions; //good // // Otherwise add option //// return SPrintf("%s %s", LoadOptions.c_str(), LoadOption.c_str()); //LoadOptions + LoadOption -// return LoadOptions + " "_XS + LoadOption; //why not? +// return LoadOptions + " "_XS8 + LoadOption; //why not? // } //} // @@ -112,7 +112,7 @@ CHAR16 *Old1_RemoveLoadOption(IN CONST CHAR16 *LoadOptions, IN CONST CHAR16 *Loa // // //DBG("LoadOptions: '%ls', remove LoadOption: '%ls'\n", LoadOptions, LoadOption); // // If there are no options then nothing to do -// if (LoadOptions.isEmpty()) return ""_XS; +// if (LoadOptions.isEmpty()) return ""_XS8; // // If there is no option to remove then duplicate original // if (LoadOption.isEmpty()) return LoadOptions; // // If not present duplicate original @@ -142,7 +142,7 @@ CHAR16 *Old1_RemoveLoadOption(IN CONST CHAR16 *LoadOptions, IN CONST CHAR16 *Loa // } // // // If it's the whole string return NULL -// if (OptionLength == Length) return ""_XS; +// if (OptionLength == Length) return ""_XS8; // // XString NewLoadOptions; // if (Offset == 0) { @@ -183,49 +183,49 @@ int BootOptions_tests() LoadOptions = Old1_AddLoadOption(LoadOptions, L"opt2"); LoadOptions = Old1_AddLoadOption(LoadOptions, L"opt3"); - if ( XString8().takeValueFrom(LoadOptions) != "opt1 opt2 opt3"_XS ) return 1; + if ( XString8().takeValueFrom(LoadOptions) != "opt1 opt2 opt3"_XS8 ) return 1; CHAR16* LoadOptions1 = Old1_RemoveLoadOption(LoadOptions, L"opt1"); - if ( XString8().takeValueFrom(LoadOptions1) != "opt2 opt3"_XS ) return 2; + if ( XString8().takeValueFrom(LoadOptions1) != "opt2 opt3"_XS8 ) return 2; CHAR16* LoadOptions2 = Old1_RemoveLoadOption(LoadOptions, L"opt2"); - if ( XString8().takeValueFrom(LoadOptions2) != "opt1 opt3"_XS ) return 3; + if ( XString8().takeValueFrom(LoadOptions2) != "opt1 opt3"_XS8 ) return 3; CHAR16* LoadOptions3 = Old1_RemoveLoadOption(LoadOptions, L"opt3"); - if ( XString8().takeValueFrom(LoadOptions3) != "opt1 opt2"_XS ) return 4; + if ( XString8().takeValueFrom(LoadOptions3) != "opt1 opt2"_XS8 ) return 4; } // { // XString LoadOptions; // -// LoadOptions = AddLoadOption(LoadOptions, "opt1"_XS); -// LoadOptions = AddLoadOption(LoadOptions, "opt2"_XS); -// LoadOptions = AddLoadOption(LoadOptions, "opt3"_XS); +// LoadOptions = AddLoadOption(LoadOptions, "opt1"_XS8); +// LoadOptions = AddLoadOption(LoadOptions, "opt2"_XS8); +// LoadOptions = AddLoadOption(LoadOptions, "opt3"_XS8); // -// if ( LoadOptions != "opt1 opt2 opt3"_XS ) return 10; +// if ( LoadOptions != "opt1 opt2 opt3"_XS8 ) return 10; // -// XString LoadOptions1 = RemoveLoadOption(LoadOptions, "opt1"_XS); -// if ( LoadOptions1 != "opt2 opt3"_XS ) return 11; -// XString LoadOptions2 = RemoveLoadOption(LoadOptions, "opt2"_XS); -// if ( LoadOptions2 != "opt1 opt3"_XS ) return 12; -// XString LoadOptions3 = RemoveLoadOption(LoadOptions, "opt3"_XS); -// if ( LoadOptions3 != "opt1 opt2"_XS ) return 13; +// XString LoadOptions1 = RemoveLoadOption(LoadOptions, "opt1"_XS8); +// if ( LoadOptions1 != "opt2 opt3"_XS8 ) return 11; +// XString LoadOptions2 = RemoveLoadOption(LoadOptions, "opt2"_XS8); +// if ( LoadOptions2 != "opt1 opt3"_XS8 ) return 12; +// XString LoadOptions3 = RemoveLoadOption(LoadOptions, "opt3"_XS8); +// if ( LoadOptions3 != "opt1 opt2"_XS8 ) return 13; // } { XStringArray LoadOptions; - LoadOptions.AddID("opt1"_XS); - LoadOptions.AddID("opt2"_XS); - LoadOptions.AddID("opt3"_XS); + LoadOptions.AddID("opt1"_XS8); + LoadOptions.AddID("opt2"_XS8); + LoadOptions.AddID("opt3"_XS8); - if ( LoadOptions.ConcatAll(" "_XS) != "opt1 opt2 opt3"_XS ) return 30; + if ( LoadOptions.ConcatAll(" "_XS8) != "opt1 opt2 opt3"_XS8 ) return 30; XStringArray LoadOptions1 = LoadOptions; - LoadOptions1.remove("opt1"_XS); - if ( LoadOptions1.ConcatAll(" "_XS) != "opt2 opt3"_XS ) return 31; + LoadOptions1.remove("opt1"_XS8); + if ( LoadOptions1.ConcatAll(" "_XS8) != "opt2 opt3"_XS8 ) return 31; XStringArray LoadOptions2 = LoadOptions; - LoadOptions2.remove("opt2"_XS); - if ( LoadOptions2.ConcatAll(" "_XS) != "opt1 opt3"_XS ) return 32; + LoadOptions2.remove("opt2"_XS8); + if ( LoadOptions2.ConcatAll(" "_XS8) != "opt1 opt3"_XS8 ) return 32; XStringArray LoadOptions3 = LoadOptions; - LoadOptions3.remove("opt3"_XS); - if ( LoadOptions3.ConcatAll(" "_XS) != "opt1 opt2"_XS ) return 33; + LoadOptions3.remove("opt3"_XS8); + if ( LoadOptions3.ConcatAll(" "_XS8) != "opt1 opt2"_XS8 ) return 33; } return 0; diff --git a/rEFIt_UEFI/cpp_unit_test/XStringArray_test.cpp b/rEFIt_UEFI/cpp_unit_test/XStringArray_test.cpp index 4f6a67f0b..eb68daee0 100644 --- a/rEFIt_UEFI/cpp_unit_test/XStringArray_test.cpp +++ b/rEFIt_UEFI/cpp_unit_test/XStringArray_test.cpp @@ -14,9 +14,9 @@ int XStringArray_tests() array1.Add(L"1"_XSW); if ( array1.isEmpty() ) return 2; - if ( array1[0] != "1"_XS ) return 21; + if ( array1[0] != "1"_XS8 ) return 21; array1.Add(L"2"_XSW); - if ( array1[1] != "2"_XS ) return 21; + if ( array1[1] != "2"_XS8 ) return 21; if ( !array1.contains(L"2"_XSW) ) return 5; @@ -33,21 +33,21 @@ int XStringArray_tests() // Split { XStringArray array = Split(" word1 word2 word3 ", " "); - if ( array[0] != "word1"_XS ) return 31; - if ( array[1] != "word2"_XS ) return 32; - if ( array[2] != "word3"_XS ) return 33; + if ( array[0] != "word1"_XS8 ) return 31; + if ( array[1] != "word2"_XS8 ) return 32; + if ( array[2] != "word3"_XS8 ) return 33; } { XStringArray array = Split("word1, word2, word3", ", "); - if ( array[0] != "word1"_XS ) return 31; - if ( array[1] != "word2"_XS ) return 32; - if ( array[2] != "word3"_XS ) return 33; + if ( array[0] != "word1"_XS8 ) return 31; + if ( array[1] != "word2"_XS8 ) return 32; + if ( array[2] != "word3"_XS8 ) return 33; } { - XStringArray array = Split(" word1 word2 word3 "_XS, " "_XS); - if ( array[0] != "word1"_XS ) return 31; - if ( array[1] != "word2"_XS ) return 32; - if ( array[2] != "word3"_XS ) return 33; + XStringArray array = Split(" word1 word2 word3 "_XS8, " "_XS8); + if ( array[0] != "word1"_XS8 ) return 31; + if ( array[1] != "word2"_XS8 ) return 32; + if ( array[2] != "word3"_XS8 ) return 33; } // Test concat and Split diff --git a/rEFIt_UEFI/cpp_unit_test/XString_test.cpp b/rEFIt_UEFI/cpp_unit_test/XString_test.cpp index 80f402684..4ef648a1a 100755 --- a/rEFIt_UEFI/cpp_unit_test/XString_test.cpp +++ b/rEFIt_UEFI/cpp_unit_test/XString_test.cpp @@ -1510,7 +1510,7 @@ class C //constexpr LString8 g_xs1 = "foobar"; //constexpr LStringW g_xsw1 = L"foobar"; -//XString g_xs2 = "foobar"_XS; +//XString g_xs2 = "foobar"_XS8; int XString_tests() { @@ -1518,12 +1518,17 @@ int XString_tests() // printf("XString16_tests -> Enter\n"); #endif -XString8 xs1 = "Test:"_XS; + +XString8 xs1 = "Test:"_XS8; +constexpr const LString8 ls1 = "foo"_XS8; +xs1 = ls1; +xs1 = ls1 + "bar"; + XStringW xsw1 = L"world"_XSW; -XString8 xs2 = xs1 + "hel" + 'l' + L'o' + U" the " + xsw1; +XString8 xs2 = xs1 + "hel" + 'l' + L'o' + L" the " + xsw1; XString8 xs3 = xs1; -LString8 a = "Hello"_XS; +LString8 a = "Hello"_XS8; XStringW b = L"world"_XSW; XString8 c = a + "foo"; // + 'o' + L'o' + b + L"bar"; @@ -1547,7 +1552,7 @@ XString8 c = a + "foo"; // + 'o' + L'o' + b + L"bar"; //size_t size = sizeof("ꇉ")-1; // this char is 3 bytes long //size_t size = sizeof("伽")-1; // this char is 3 bytes long //size_t size = sizeof("楘")-1; // this char is 3 bytes long -//XString str = "ギꇉ伽楘"_XS; +//XString str = "ギꇉ伽楘"_XS8; //char* s = str.data(42); //size_t size1 = sizeof("В")-1; diff --git a/rEFIt_UEFI/entry_scan/common.cpp b/rEFIt_UEFI/entry_scan/common.cpp index a2d397edd..c3708fbf2 100644 --- a/rEFIt_UEFI/entry_scan/common.cpp +++ b/rEFIt_UEFI/entry_scan/common.cpp @@ -134,7 +134,7 @@ const XImage& ScanVolumeDefaultIcon(REFIT_VOLUME *Volume, IN UINT8 OSType, IN EF // if ( LoadOptions.contains(LoadOption) ) return LoadOptions; //good // // Otherwise add option //// return SPrintf("%s %s", LoadOptions.c_str(), LoadOption.c_str()); //LoadOptions + LoadOption -// return LoadOptions + " "_XS + LoadOption; //why not? +// return LoadOptions + " "_XS8 + LoadOption; //why not? // } //} // @@ -146,7 +146,7 @@ const XImage& ScanVolumeDefaultIcon(REFIT_VOLUME *Volume, IN UINT8 OSType, IN EF // // //DBG("LoadOptions: '%ls', remove LoadOption: '%ls'\n", LoadOptions, LoadOption); // // If there are no options then nothing to do -// if (LoadOptions.isEmpty()) return ""_XS; +// if (LoadOptions.isEmpty()) return ""_XS8; // // If there is no option to remove then duplicate original // if (LoadOption.isEmpty()) return LoadOptions; // // If not present duplicate original @@ -176,7 +176,7 @@ const XImage& ScanVolumeDefaultIcon(REFIT_VOLUME *Volume, IN UINT8 OSType, IN EF // } // // // If it's the whole string return NULL -// if (OptionLength == Length) return ""_XS; +// if (OptionLength == Length) return ""_XS8; // // XString NewLoadOptions; // if (Offset == 0) { diff --git a/rEFIt_UEFI/entry_scan/legacy.cpp b/rEFIt_UEFI/entry_scan/legacy.cpp index 2043aa643..4385ec493 100644 --- a/rEFIt_UEFI/entry_scan/legacy.cpp +++ b/rEFIt_UEFI/entry_scan/legacy.cpp @@ -138,7 +138,7 @@ BOOLEAN AddLegacyEntry(IN const XStringW& FullTitle, IN const XStringW& LoaderTi } else { Entry->Image = ThemeX.LoadOSIcon(Volume->LegacyOS->IconName); if (Entry->Image.isEmpty()) { - Entry->Image = ThemeX.GetIcon("os_win"_XS); //we have no legacy.png + Entry->Image = ThemeX.GetIcon("os_win"_XS8); //we have no legacy.png } } @@ -161,7 +161,7 @@ BOOLEAN AddLegacyEntry(IN const XStringW& FullTitle, IN const XStringW& LoaderTi } Entry->Volume = Volume; Entry->DevicePathString = Volume->DevicePathString; -// Entry->LoadOptions = (Volume->DiskKind == DISK_KIND_OPTICAL) ? "CD"_XS : ((Volume->DiskKind == DISK_KIND_EXTERNAL) ? "USB"_XS : "HD"_XS); +// Entry->LoadOptions = (Volume->DiskKind == DISK_KIND_OPTICAL) ? "CD"_XS8 : ((Volume->DiskKind == DISK_KIND_EXTERNAL) ? "USB"_XS8 : "HD"_XS8); Entry->LoadOptions.setEmpty(); Entry->LoadOptions.Add((Volume->DiskKind == DISK_KIND_OPTICAL) ? "CD" : ((Volume->DiskKind == DISK_KIND_EXTERNAL) ? "USB" : "HD")); // create the submenu diff --git a/rEFIt_UEFI/entry_scan/loader.cpp b/rEFIt_UEFI/entry_scan/loader.cpp index 0a9ae5560..20f9aa0ad 100644 --- a/rEFIt_UEFI/entry_scan/loader.cpp +++ b/rEFIt_UEFI/entry_scan/loader.cpp @@ -64,7 +64,7 @@ const XStringW MACOSX_LOADER_PATH = L"\\System\\Library\\CoreServices\\boot.efi" const XStringW LINUX_ISSUE_PATH = L"\\etc\\issue"_XSW; #define LINUX_BOOT_PATH L"\\boot" #define LINUX_BOOT_ALT_PATH L"\\boot" -const XString8 LINUX_LOADER_PATH = "vmlinuz"_XS; +const XString8 LINUX_LOADER_PATH = "vmlinuz"_XS8; const XStringW LINUX_FULL_LOADER_PATH = SWPrintf("%ls\\%s", LINUX_BOOT_PATH, LINUX_LOADER_PATH.c_str()); #define LINUX_LOADER_SEARCH_PATH L"vmlinuz*" const XStringArray LINUX_DEFAULT_OPTIONS = Split("ro add_efi_memmap quiet splash vt.handoff=7", " "); @@ -129,7 +129,7 @@ STATIC LINUX_PATH_DATA LinuxEntryData[] = { // { L"\\EFI\\Manjaro\\grubx64.efi", L"Manjaro EFI boot menu", L"manjaro,linux", "Manjaro" }, // { L"\\EFI\\xubuntu\\grubx64.efi", L"Xubuntu EFI boot menu", L"xubuntu,linux", "Xubuntu" }, // { L"\\EFI\\zorin\\grubx64.efi", L"Zorin EFI boot menu", L"zorin,linux", "Zorin" }, - { L"\\EFI\\goofiboot\\goofibootx64.efi"_XSW, L"Solus EFI boot menu"_XSW, L"solus,linux"_XSW, "Solus"_XS }, + { L"\\EFI\\goofiboot\\goofibootx64.efi"_XSW, L"Solus EFI boot menu"_XSW, L"solus,linux"_XSW, "Solus"_XS8 }, // { L"\\EFI\\centos\\grubx64.efi", L"CentOS EFI boot menu", L"centos,linux", "CentOS" }, // { L"\\EFI\\pclinuxos\\grubx64.efi", L"PCLinuxOS EFI boot menu", L"pclinux,linux", "PCLinux" }, // { L"\\EFI\\neon\\grubx64.efi", L"KDE Neon EFI boot menu", L"neon,linux", "KDE Neon" }, @@ -340,12 +340,12 @@ STATIC CONST XStringW& LinuxIconNameFromPath(IN CONST XStringW& Path, } STATIC CONST XString8 LinuxInitImagePath[] = { - "initrd%s"_XS, - "initrd.img%s"_XS, - "initrd%s.img"_XS, - "initramfs%s"_XS, - "initramfs.img%s"_XS, - "initramfs%s.img"_XS, + "initrd%s"_XS8, + "initrd.img%s"_XS8, + "initrd%s.img"_XS8, + "initramfs%s"_XS8, + "initramfs.img%s"_XS8, + "initramfs%s.img"_XS8, }; STATIC CONST UINTN LinuxInitImagePathCount = (sizeof(LinuxInitImagePath) / sizeof(LinuxInitImagePath[0])); @@ -822,7 +822,7 @@ STATIC VOID AddDefaultMenu(IN LOADER_ENTRY *Entry) if (Guid) { SubScreen->AddMenuInfoLine_f("UUID: %s", strguid(Guid)); } - SubScreen->AddMenuInfoLine_f("Options: %s", Entry->LoadOptions.ConcatAll(" "_XS).c_str()); + SubScreen->AddMenuInfoLine_f("Options: %s", Entry->LoadOptions.ConcatAll(" "_XS8).c_str()); // loader-specific submenu entries if (Entry->LoaderType == OSTYPE_OSX || Entry->LoaderType == OSTYPE_OSX_INSTALLER || @@ -938,10 +938,10 @@ STATIC VOID AddDefaultMenu(IN LOADER_ENTRY *Entry) if (SubEntry) { if (Quiet) { SubEntry->Title.SWPrintf("%ls verbose", Entry->Title.s()); - SubEntry->LoadOptions.removeIC("quiet"_XS); + SubEntry->LoadOptions.removeIC("quiet"_XS8); } else { SubEntry->Title.SWPrintf("%ls quiet", Entry->Title.s()); - SubEntry->LoadOptions.AddID("quiet"_XS); + SubEntry->LoadOptions.AddID("quiet"_XS8); } } SubScreen->AddMenuEntry(SubEntry, true); @@ -949,10 +949,10 @@ STATIC VOID AddDefaultMenu(IN LOADER_ENTRY *Entry) if (SubEntry) { if (WithSplash) { SubEntry->Title.SWPrintf("%ls without splash", Entry->Title.s()); - SubEntry->LoadOptions.removeIC("splash"_XS); + SubEntry->LoadOptions.removeIC("splash"_XS8); } else { SubEntry->Title.SWPrintf("%ls with splash", Entry->Title.s()); - SubEntry->LoadOptions.AddID("splash"_XS); + SubEntry->LoadOptions.AddID("splash"_XS8); } } SubScreen->AddMenuEntry(SubEntry, true); @@ -961,30 +961,30 @@ STATIC VOID AddDefaultMenu(IN LOADER_ENTRY *Entry) if (WithSplash) { if (Quiet) { SubEntry->Title.SWPrintf("%ls verbose without splash", Entry->Title.s()); - SubEntry->LoadOptions.removeIC("splash"_XS); - SubEntry->LoadOptions.removeIC("quiet"_XS); + SubEntry->LoadOptions.removeIC("splash"_XS8); + SubEntry->LoadOptions.removeIC("quiet"_XS8); } else { SubEntry->Title.SWPrintf("%ls quiet without splash", Entry->Title.s()); - SubEntry->LoadOptions.removeIC("splash"_XS); - SubEntry->LoadOptions.Add("quiet"_XS); + SubEntry->LoadOptions.removeIC("splash"_XS8); + SubEntry->LoadOptions.Add("quiet"_XS8); } } else if (Quiet) { -// TempOptions.RemoveIC("quiet"_XS); +// TempOptions.RemoveIC("quiet"_XS8); SubEntry->Title.SWPrintf("%ls verbose with splash", Entry->Title.s()); - SubEntry->LoadOptions.AddID("splash"_XS); + SubEntry->LoadOptions.AddID("splash"_XS8); // FreePool(TempOptions); } else { SubEntry->Title.SWPrintf("%ls quiet with splash", Entry->Title.s()); - SubEntry->LoadOptions.AddID("quiet"_XS); - SubEntry->LoadOptions.AddID("splash"_XS); + SubEntry->LoadOptions.AddID("quiet"_XS8); + SubEntry->LoadOptions.AddID("splash"_XS8); } } SubScreen->AddMenuEntry(SubEntry, true); } else if ((Entry->LoaderType == OSTYPE_WIN) || (Entry->LoaderType == OSTYPE_WINEFI)) { // by default, skip the built-in selection and boot from hard disk only Entry->LoadOptions.setEmpty(); - Entry->LoadOptions.Add("-s"_XS); - Entry->LoadOptions.Add("-h"_XS); + Entry->LoadOptions.Add("-s"_XS8); + Entry->LoadOptions.Add("-h"_XS8); // default entry SubEntry = Entry->getPartiallyDuplicatedEntry(); @@ -1003,8 +1003,8 @@ STATIC VOID AddDefaultMenu(IN LOADER_ENTRY *Entry) if (SubEntry) { SubEntry->Title.takeValueFrom("Boot Windows from CD-ROM"); Entry->LoadOptions.setEmpty(); - Entry->LoadOptions.Add("-s"_XS); - Entry->LoadOptions.Add("-c"_XS); + Entry->LoadOptions.Add("-s"_XS8); + Entry->LoadOptions.Add("-c"_XS8); SubScreen->AddMenuEntry(SubEntry, true); } @@ -1013,7 +1013,7 @@ STATIC VOID AddDefaultMenu(IN LOADER_ENTRY *Entry) SubEntry->Title.SWPrintf("Run %ls in text mode", FileName.wc_str()); SubEntry->Flags = OSFLAG_UNSET(SubEntry->Flags, OSFLAG_USEGRAPHICS); Entry->LoadOptions.setEmpty(); - Entry->LoadOptions.Add("-v"_XS); + Entry->LoadOptions.Add("-v"_XS8); SubEntry->LoaderType = OSTYPE_OTHER; // Sothor - Why are we using OSTYPE_OTHER here? SubScreen->AddMenuEntry(SubEntry, true); } @@ -2039,7 +2039,7 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex, if (Guid) { SubScreen->AddMenuInfoLine_f("UUID: %s", strguid(Guid)); } - SubScreen->AddMenuInfoLine_f("Options: %s", Entry->LoadOptions.ConcatAll(" "_XS).c_str()); + SubScreen->AddMenuInfoLine_f("Options: %s", Entry->LoadOptions.ConcatAll(" "_XS8).c_str()); DBG("Create sub entries\n"); for (CustomSubEntry = Custom->SubEntries; CustomSubEntry; CustomSubEntry = CustomSubEntry->Next) { if (!CustomSubEntry->Settings) { diff --git a/rEFIt_UEFI/gui/REFIT_MENU_SCREEN.cpp b/rEFIt_UEFI/gui/REFIT_MENU_SCREEN.cpp index f8ff247da..801a1ddb6 100644 --- a/rEFIt_UEFI/gui/REFIT_MENU_SCREEN.cpp +++ b/rEFIt_UEFI/gui/REFIT_MENU_SCREEN.cpp @@ -2034,7 +2034,7 @@ VOID REFIT_MENU_SCREEN::DrawMainMenuEntry(REFIT_ABSTRACT_MENU_ENTRY *Entry, BOOL if (MainImage.isEmpty()) { // DBG(" why MainImage is empty? Report to devs\n"); if (!IsEmbeddedTheme()) { - MainImage = ThemeX.GetIcon("os_mac"_XS); + MainImage = ThemeX.GetIcon("os_mac"_XS8); } if (MainImage.isEmpty()) { MainImage.DummyImage(MainSize); @@ -2663,7 +2663,7 @@ UINTN REFIT_MENU_SCREEN::RunMainMenu(IN INTN DefaultSelection, OUT REFIT_ABSTRAC } if (/*MenuExit == MENU_EXIT_ENTER &&*/ MainChosenEntry->getLOADER_ENTRY()) { if (MainChosenEntry->getLOADER_ENTRY()->LoadOptions.notEmpty()) { - snprintf(gSettings.BootArgs, 255, "%s", MainChosenEntry->getLOADER_ENTRY()->LoadOptions.ConcatAll(" "_XS).c_str()); + snprintf(gSettings.BootArgs, 255, "%s", MainChosenEntry->getLOADER_ENTRY()->LoadOptions.ConcatAll(" "_XS8).c_str()); } else { ZeroMem(&gSettings.BootArgs, 255); } diff --git a/rEFIt_UEFI/gui/shared_with_menu.cpp b/rEFIt_UEFI/gui/shared_with_menu.cpp index 515d2e7e3..ec4b9f996 100644 --- a/rEFIt_UEFI/gui/shared_with_menu.cpp +++ b/rEFIt_UEFI/gui/shared_with_menu.cpp @@ -45,26 +45,26 @@ //#include "../entry_scan/common.h" CONST XString8 ArgOptional[NUM_OPT] = { - "arch=i386"_XS, //0 - "arch=x86_64"_XS, //1 - "-v"_XS, //2 - "-f"_XS, //3 - "-s"_XS, //4 - "-x"_XS, //5 - "nv_disable=1"_XS, //6 - "slide=0"_XS, //7 - "darkwake=0"_XS, //8 - "-xcpm"_XS, //9 - "-gux_no_idle"_XS, //10 - "-gux_nosleep"_XS, //11 - "-gux_nomsi"_XS, //12 - "-gux_defer_usb2"_XS, //13 - "keepsyms=1"_XS, //14 - "debug=0x100"_XS, //15 - "kextlog=0xffff"_XS, //16 - "-alcoff"_XS, //17 - "-shikioff"_XS, //18 - "nvda_drv=1"_XS //19 + "arch=i386"_XS8, //0 + "arch=x86_64"_XS8, //1 + "-v"_XS8, //2 + "-f"_XS8, //3 + "-s"_XS8, //4 + "-x"_XS8, //5 + "nv_disable=1"_XS8, //6 + "slide=0"_XS8, //7 + "darkwake=0"_XS8, //8 + "-xcpm"_XS8, //9 + "-gux_no_idle"_XS8, //10 + "-gux_nosleep"_XS8, //11 + "-gux_nomsi"_XS8, //12 + "-gux_defer_usb2"_XS8, //13 + "keepsyms=1"_XS8, //14 + "debug=0x100"_XS8, //15 + "kextlog=0xffff"_XS8, //16 + "-alcoff"_XS8, //17 + "-shikioff"_XS8, //18 + "nvda_drv=1"_XS8 //19 }; CONST CHAR16 *VBIOS_BIN = L"EFI\\CLOVER\\misc\\c0000.bin"; diff --git a/rEFIt_UEFI/libeg/VectorGraphics.cpp b/rEFIt_UEFI/libeg/VectorGraphics.cpp index 13dcfdee9..4a5bf1cc2 100755 --- a/rEFIt_UEFI/libeg/VectorGraphics.cpp +++ b/rEFIt_UEFI/libeg/VectorGraphics.cpp @@ -267,20 +267,20 @@ EFI_STATUS XTheme::ParseSVGXTheme(CONST CHAR8* buffer) } Status = EFI_NOT_FOUND; if (!ThemeX.Daylight) { - Status = ParseSVGXIcon(BUILTIN_ICON_BACKGROUND, "Background_night"_XS, &BigBack); + Status = ParseSVGXIcon(BUILTIN_ICON_BACKGROUND, "Background_night"_XS8, &BigBack); } if (EFI_ERROR(Status)) { - Status = ParseSVGXIcon(BUILTIN_ICON_BACKGROUND, "Background"_XS, &BigBack); + Status = ParseSVGXIcon(BUILTIN_ICON_BACKGROUND, "Background"_XS8, &BigBack); } DBG(" Background parsed [%lld, %lld]\n", BigBack.GetWidth(), BigBack.GetHeight()); //Background parsed [1067, 133] // --- Make Banner Banner.setEmpty(); //for the case of theme switch Status = EFI_NOT_FOUND; if (!ThemeX.Daylight) { - Status = ParseSVGXIcon(BUILTIN_ICON_BANNER, "Banner_night"_XS, &Banner); + Status = ParseSVGXIcon(BUILTIN_ICON_BANNER, "Banner_night"_XS8, &Banner); } if (EFI_ERROR(Status)) { - Status = ParseSVGXIcon(BUILTIN_ICON_BANNER, "Banner"_XS, &Banner); + Status = ParseSVGXIcon(BUILTIN_ICON_BANNER, "Banner"_XS8, &Banner); } // DBG("Banner parsed\n"); BanHeight = (int)(Banner.GetHeight() * Scale + 1.f); @@ -296,7 +296,7 @@ EFI_STATUS XTheme::ParseSVGXTheme(CONST CHAR8* buffer) // DBG("parse %s status %s\n", NewIcon->Name.c_str(), strerror(Status)); NewIcon->Native = !EFI_ERROR(Status); if (!EFI_ERROR(Status)) { - ParseSVGXIcon(i, NewIcon->Name + "_night"_XS, &NewIcon->ImageNight); + ParseSVGXIcon(i, NewIcon->Name + "_night"_XS8, &NewIcon->ImageNight); } // DBG("parse %s status %s\n", NewIcon->Name.c_str(), strerror(Status)); Icons.AddReference(NewIcon, true); @@ -315,16 +315,16 @@ EFI_STATUS XTheme::ParseSVGXTheme(CONST CHAR8* buffer) // DBG("parse %s i=%lld status %s\n", NewIcon->Name.c_str(), i, strerror(Status)); NewIcon->Native = !EFI_ERROR(Status); if (!EFI_ERROR(Status)) { - ParseSVGXIcon(i, NewIcon->Name + "_night"_XS, &NewIcon->ImageNight); + ParseSVGXIcon(i, NewIcon->Name + "_night"_XS8, &NewIcon->ImageNight); } Icons.AddReference(NewIcon, true); } //selection for bootcampstyle Icon *NewIcon = new Icon(BUILTIN_ICON_SELECTION); - Status = ParseSVGXIcon(BUILTIN_ICON_SELECTION, "selection_indicator"_XS, &NewIcon->Image); + Status = ParseSVGXIcon(BUILTIN_ICON_SELECTION, "selection_indicator"_XS8, &NewIcon->Image); if (!EFI_ERROR(Status)) { - ParseSVGXIcon(BUILTIN_ICON_SELECTION, "selection_indicator_night"_XS, &NewIcon->ImageNight); + ParseSVGXIcon(BUILTIN_ICON_SELECTION, "selection_indicator_night"_XS8, &NewIcon->ImageNight); } Icons.AddReference(NewIcon, true); diff --git a/rEFIt_UEFI/libeg/XTheme.cpp b/rEFIt_UEFI/libeg/XTheme.cpp index 07baee742..1579a89d4 100644 --- a/rEFIt_UEFI/libeg/XTheme.cpp +++ b/rEFIt_UEFI/libeg/XTheme.cpp @@ -399,12 +399,12 @@ const XImage& XTheme::LoadOSIcon(const XString8& Full) UINTN Size = Full.length(); DBG("IconName=%s comma=%lld size=%lld\n", Full.c_str(), Comma, Size); if (Comma != MAX_XSIZE) { //Comma - First = "os_"_XS + Full.subString(0, Comma); + First = "os_"_XS8 + Full.subString(0, Comma); ReturnImage = &GetIcon(First); DBG(" first=%s\n", First.c_str()); if (!ReturnImage->isEmpty()) return *ReturnImage; //else search second name - Second = "os_"_XS + Full.subString(Comma + 1, Size - Comma - 1); + Second = "os_"_XS8 + Full.subString(Comma + 1, Size - Comma - 1); //moreover names can be triple L"chrome,grub,linux" UINTN SecondComma = Second.indexOf(','); if (Comma == MAX_XSIZE) { @@ -414,14 +414,14 @@ const XImage& XTheme::LoadOSIcon(const XString8& Full) First = Second.subString(0, SecondComma); ReturnImage = &GetIcon(First); if (!ReturnImage->isEmpty()) return *ReturnImage; - Third = "os_"_XS + Second.subString(SecondComma + 1, Size - SecondComma - 1); + Third = "os_"_XS8 + Second.subString(SecondComma + 1, Size - SecondComma - 1); ReturnImage = &GetIcon(Third); if (!ReturnImage->isEmpty()) return *ReturnImage; } DBG(" Second=%s\n", Second.c_str()); if (!ReturnImage->isEmpty()) return *ReturnImage; } else { - ReturnImage = &GetIcon("os_"_XS + Full); + ReturnImage = &GetIcon("os_"_XS8 + Full); DBG(" Full=%s\n", Full.c_str()); if (!ReturnImage->isEmpty()) return *ReturnImage; } @@ -733,10 +733,10 @@ void XTheme::InitSelection() //for PNG theme } } else { //SVG theme already parsed all icons - Buttons[0] = GetIcon("radio_button"_XS); - Buttons[1] = GetIcon("radio_button_selected"_XS); - Buttons[2] = GetIcon("checkbox"_XS); - Buttons[3] = GetIcon("checkbox_checked"_XS); + Buttons[0] = GetIcon("radio_button"_XS8); + Buttons[1] = GetIcon("radio_button_selected"_XS8); + Buttons[2] = GetIcon("checkbox"_XS8); + Buttons[3] = GetIcon("checkbox_checked"_XS8); } // non-selected background images @@ -852,7 +852,7 @@ void XTheme::InitBar() if (ScrollbarBackgroundImage.isEmpty()) { if (TypeSVG) { //return OSIconsTable[i].image; - ScrollbarBackgroundImage = GetIcon("scrollbar_background"_XS); + ScrollbarBackgroundImage = GetIcon("scrollbar_background"_XS8); } if (ScrollbarBackgroundImage.isEmpty()) { ScrollbarBackgroundImage.FromPNG(ACCESS_EMB_DATA(emb_scroll_bar_fill), ACCESS_EMB_SIZE(emb_scroll_bar_fill)); @@ -860,7 +860,7 @@ void XTheme::InitBar() } if (ScrollbarImage.isEmpty()) { if (TypeSVG) { - ScrollbarImage = GetIcon("scrollbar_holder"_XS); //"_night" is already accounting + ScrollbarImage = GetIcon("scrollbar_holder"_XS8); //"_night" is already accounting } if (ScrollbarImage.isEmpty()) { ScrollbarImage.FromPNG(ACCESS_EMB_DATA(emb_scroll_scroll_fill), ACCESS_EMB_SIZE(emb_scroll_scroll_fill)); @@ -868,7 +868,7 @@ void XTheme::InitBar() } if (ScrollStartImage.isEmpty()) { if (TypeSVG) { - ScrollStartImage = GetIcon("scrollbar_start"_XS); + ScrollStartImage = GetIcon("scrollbar_start"_XS8); } if (ScrollStartImage.isEmpty()) { ScrollStartImage.FromPNG(ACCESS_EMB_DATA(emb_scroll_scroll_start), ACCESS_EMB_SIZE(emb_scroll_scroll_start)); @@ -876,7 +876,7 @@ void XTheme::InitBar() } if (ScrollEndImage.isEmpty()) { if (TypeSVG) { - ScrollEndImage = GetIcon("scrollbar_end"_XS); + ScrollEndImage = GetIcon("scrollbar_end"_XS8); } if (ScrollEndImage.isEmpty()) { ScrollEndImage.FromPNG(ACCESS_EMB_DATA(emb_scroll_scroll_end), ACCESS_EMB_SIZE(emb_scroll_scroll_end)); @@ -884,13 +884,13 @@ void XTheme::InitBar() } if (UpButtonImage.isEmpty()) { if (TypeSVG) { - UpButtonImage = GetIcon("scrollbar_up_button"_XS); + UpButtonImage = GetIcon("scrollbar_up_button"_XS8); } UpButtonImage.FromPNG(ACCESS_EMB_DATA(emb_scroll_up_button), ACCESS_EMB_SIZE(emb_scroll_up_button)); } if (DownButtonImage.isEmpty()) { if (TypeSVG) { - DownButtonImage = GetIcon("scrollbar_down_button"_XS); + DownButtonImage = GetIcon("scrollbar_down_button"_XS8); } if (DownButtonImage.isEmpty()) { DownButtonImage.FromPNG(ACCESS_EMB_DATA(emb_scroll_down_button), ACCESS_EMB_SIZE(emb_scroll_down_button)); diff --git a/rEFIt_UEFI/libeg/libscreen.cpp b/rEFIt_UEFI/libeg/libscreen.cpp index ef119b1fa..25a5fb403 100644 --- a/rEFIt_UEFI/libeg/libscreen.cpp +++ b/rEFIt_UEFI/libeg/libscreen.cpp @@ -447,10 +447,10 @@ XString8 egScreenDescription(VOID) } else if (UgaDraw != NULL) { return SPrintf("UGA Draw (EFI 1.10), %lldx%lld", egScreenWidth, egScreenHeight); } else { - return "Internal Error"_XS; + return "Internal Error"_XS8; } } else { - return "Text Console"_XS; + return "Text Console"_XS8; } } diff --git a/rEFIt_UEFI/refit/main.cpp b/rEFIt_UEFI/refit/main.cpp index 851245fc1..e4379004f 100644 --- a/rEFIt_UEFI/refit/main.cpp +++ b/rEFIt_UEFI/refit/main.cpp @@ -229,9 +229,9 @@ static EFI_STATUS StartEFILoadedImage(IN EFI_HANDLE ChildImageHandle, if (LoadOptionsPrefix != NULL) { // NOTE: That last space is also added by the EFI shell and seems to be significant // when passing options to Apple's boot.efi... - loadOptionsW = SWPrintf("%ls %s ", LoadOptionsPrefix, LoadOptions.ConcatAll(" "_XS).wc_str()); + loadOptionsW = SWPrintf("%ls %s ", LoadOptionsPrefix, LoadOptions.ConcatAll(" "_XS8).wc_str()); }else{ - loadOptionsW = SWPrintf("%s ", LoadOptions.ConcatAll(" "_XS).wc_str()); // Jief : should we add a space ? Wasn't the case before big refactoring. Yes, a space required. + loadOptionsW = SWPrintf("%s ", LoadOptions.ConcatAll(" "_XS8).wc_str()); // Jief : should we add a space ? Wasn't the case before big refactoring. Yes, a space required. } // NOTE: We also include the terminating null in the length for safety. ChildLoadedImage->LoadOptionsSize = (UINT32)loadOptionsW.sizeInBytes() + sizeof(wchar_t); @@ -776,7 +776,7 @@ static VOID StartLoader(IN LOADER_ENTRY *Entry) // If KPDebug is true boot in verbose mode to see the debug messages if ((Entry->KernelAndKextPatches != NULL) && Entry->KernelAndKextPatches->KPDebug) { - Entry->LoadOptions.AddID("-v"_XS); + Entry->LoadOptions.AddID("-v"_XS8); } DbgHeader("RestSetup macOS"); @@ -805,7 +805,7 @@ static VOID StartLoader(IN LOADER_ENTRY *Entry) !DoHibernateWake && !Entry->LoadOptions.containsStartWithIC("slide=") ) { // Add slide=0 argument for ML+ if not present - Entry->LoadOptions.AddID("slide=0"_XS); + Entry->LoadOptions.AddID("slide=0"_XS8); } @@ -819,7 +819,7 @@ static VOID StartLoader(IN LOADER_ENTRY *Entry) (AsciiOSVersionToUint64(Entry->OSVersion) < AsciiOSVersionToUint64("10.12")) && (!Entry->LoadOptions.containsIC("-xcpm"))) { // add "-xcpm" argv if not present on Haswell+ Celeron/Pentium - Entry->LoadOptions.AddID("-xcpm"_XS); + Entry->LoadOptions.AddID("-xcpm"_XS8); } // add -xcpm on Ivy Bridge if set KernelXCPM and system version is 10.8.5 - 10.11.x @@ -829,7 +829,7 @@ static VOID StartLoader(IN LOADER_ENTRY *Entry) (AsciiOSVersionToUint64(Entry->OSVersion) < AsciiOSVersionToUint64("10.12")) && (!Entry->LoadOptions.containsIC("-xcpm"))) { // add "-xcpm" argv if not present on Ivy Bridge - Entry->LoadOptions.AddID("-xcpm"_XS); + Entry->LoadOptions.AddID("-xcpm"_XS8); } if (AudioIo) { @@ -2137,7 +2137,7 @@ RefitMain (IN EFI_HANDLE ImageHandle, DBG(" string %ls, size=%lld, len=%lld sizeof=%ld iStrLen=%lld\n", aaa, StrSize(aaa), StrLen(aaa), sizeof(aaa), iStrLen(bbb, 10)); const CHAR8* ccc = "Выход "; DBG(" string %s, size=%lld, len=%lld sizeof=%ld iStrLen=%lld\n", ccc, AsciiStrSize(ccc), AsciiStrLen(ccc), sizeof(ccc), iStrLen(ccc, 10)); - XString8 ddd = "Выход "_XS; + XString8 ddd = "Выход "_XS8; // size_t sizex = ddd.allocatedSize(); DBG(" xstring %s, asize=%ld, sizeinbyte=%ld sizeof=%ld lastcharat=%ld\n", ddd.c_str(), ddd.allocatedSize(), ddd.sizeInBytes(), sizeof(ddd), ddd.indexOf(ddd.lastChar())); From 6017607113d44371366f123ff22cdc9cb69f6677 Mon Sep 17 00:00:00 2001 From: vectorsigma72 Date: Thu, 30 Apr 2020 15:55:31 +0200 Subject: [PATCH 07/12] Bug fixes for Clover.app Fixed SMBIOS->Version and SMBIOS->SerialNumber generating config.plist. Fix mount in Sierra and older by sending mount operation in a background thread and updating the UI on the main one. --- CloverApp/Clover/GengConfig.swift | 4 +- CloverApp/Clover/Installer/Installer.swift | 17 +++-- .../Clover/Installer/InstallerOutline.swift | 17 +++-- CloverApp/Clover/SettingsView.swift | 28 ++++---- .../Clover/ThemeManager/ThemeManagerVC.swift | 66 +++++++++++-------- 5 files changed, 81 insertions(+), 51 deletions(-) diff --git a/CloverApp/Clover/GengConfig.swift b/CloverApp/Clover/GengConfig.swift index b4e54c3c3..5f236663d 100644 --- a/CloverApp/Clover/GengConfig.swift +++ b/CloverApp/Clover/GengConfig.swift @@ -783,8 +783,8 @@ final class CloverConfig: NSObject { // SMBIOS TYPE1 SMBIOS["Manufacturer"] = s.value(for: "ManufactureName", type: .CHAR8String) SMBIOS["ProductName"] = s.value(for: "ProductName", type: .CHAR8String) - SMBIOS["Version"] = s.value(for: "SerialNr", type: .CHAR8String) - SMBIOS["SerialNumber"] = s.value(for: "ReleaseDate", type: .CHAR8String) + SMBIOS["Version"] = s.value(for: "VersionNr", type: .CHAR8String) + SMBIOS["SerialNumber"] = s.value(for: "SerialNr", type: .CHAR8String) SMBIOS["SmUUID"] = s.value(for: "SmUUID", type: .UUIDString) SMBIOS["Family"] = s.value(for: "FamilyName", type: .CHAR8String) // SMBIOS TYPE2 diff --git a/CloverApp/Clover/Installer/Installer.swift b/CloverApp/Clover/Installer/Installer.swift index 1795c5ec6..577e148a3 100644 --- a/CloverApp/Clover/Installer/Installer.swift +++ b/CloverApp/Clover/Installer/Installer.swift @@ -554,13 +554,13 @@ final class InstallerViewController: NSViewController { self.altBootCheck.state = .off if let disk = sender?.selectedItem?.representedObject as? String { if !isMountPoint(path: disk) { - //DispatchQueue.global(qos: .background).async { + DispatchQueue.global(priority: .background).async(execute: { () -> Void in let cmd = "diskutil mount \(disk)" let msg = String(format: "Clover wants to mount %@", disk) let script = "do shell script \"\(cmd)\" with prompt \"\(msg)\" with administrator privileges" let task = Process() - + if #available(OSX 10.12, *) { task.launchPath = "/usr/bin/osascript" task.arguments = ["-e", script] @@ -572,24 +572,31 @@ final class InstallerViewController: NSViewController { task.terminationHandler = { t in if t.terminationStatus == 0 { if isMountPoint(path: disk) { - self.targetVol = getMountPoint(from: disk) ?? "" DispatchQueue.main.async { + self.targetVol = getMountPoint(from: disk) ?? "" self.populateTargets() self.setPreferences(for: self.targetVol) } } - DispatchQueue.main.async { self.view.window?.makeKeyAndOrderFront(nil) } + DispatchQueue.main.async { + self.view.window?.makeKeyAndOrderFront(nil) + self.view.window?.level = .floating + self.view.window?.level = .normal + } } else { NSSound.beep() DispatchQueue.main.async { if #available(OSX 10.11, *) { self.driversCollection.reloadData() + self.view.window?.makeKeyAndOrderFront(nil) + self.view.window?.level = .floating + self.view.window?.level = .normal } } } } task.launch() - //} + }) } else { self.targetVol = getMountPoint(from: disk) ?? "" self.populateTargets() diff --git a/CloverApp/Clover/Installer/InstallerOutline.swift b/CloverApp/Clover/Installer/InstallerOutline.swift index 11cbe4587..270e25316 100644 --- a/CloverApp/Clover/Installer/InstallerOutline.swift +++ b/CloverApp/Clover/Installer/InstallerOutline.swift @@ -499,13 +499,13 @@ final class InstallerOutViewController: NSViewController { self.altBootCheck.state = .off if let disk = sender?.selectedItem?.representedObject as? String { if !isMountPoint(path: disk) { - //DispatchQueue.global(qos: .background).async { + DispatchQueue.global(priority: .background).async(execute: { () -> Void in let cmd = "diskutil mount \(disk)" let msg = String(format: "Clover wants to mount %@", disk) let script = "do shell script \"\(cmd)\" with prompt \"\(msg)\" with administrator privileges" let task = Process() - + if #available(OSX 10.12, *) { task.launchPath = "/usr/bin/osascript" task.arguments = ["-e", script] @@ -517,23 +517,30 @@ final class InstallerOutViewController: NSViewController { task.terminationHandler = { t in if t.terminationStatus == 0 { if isMountPoint(path: disk) { - self.targetVol = getMountPoint(from: disk) ?? "" DispatchQueue.main.async { + self.targetVol = getMountPoint(from: disk) ?? "" self.populateTargets() self.setPreferences(for: self.targetVol) } } - DispatchQueue.main.async { self.view.window?.makeKeyAndOrderFront(nil) } + DispatchQueue.main.async { + self.view.window?.makeKeyAndOrderFront(nil) + self.view.window?.level = .floating + self.view.window?.level = .normal + } } else { NSSound.beep() DispatchQueue.main.async { self.driversOutline.reloadData() self.expandAllSections() + self.view.window?.makeKeyAndOrderFront(nil) + self.view.window?.level = .floating + self.view.window?.level = .normal } } } task.launch() - //} + }) } else { self.targetVol = getMountPoint(from: disk) ?? "" self.populateTargets() diff --git a/CloverApp/Clover/SettingsView.swift b/CloverApp/Clover/SettingsView.swift index 0b23b9062..17730bd7f 100644 --- a/CloverApp/Clover/SettingsView.swift +++ b/CloverApp/Clover/SettingsView.swift @@ -630,20 +630,15 @@ final class SettingsViewController: // MARK: Controls actions @IBAction func openThemeManager(_ sender: NSButton!) { DispatchQueue.main.async { - if #available(OSX 10.11, *) { - if (AppSD.themeManagerWC == nil) { - AppSD.themeManagerWC = ThemeManagerWC.loadFromNib() - } - - AppSD.themeManagerWC?.showWindow(self) - } else { - if (AppSD.themeManagerWC == nil) { - AppSD.themeManagerWC = ThemeManagerWC.loadFromNib() - } - - AppSD.themeManagerWC?.showWindow(self) + if (AppSD.themeManagerWC == nil) { + AppSD.themeManagerWC = ThemeManagerWC.loadFromNib() } + AppSD.themeManagerWC?.showWindow(self) + + AppSD.themeManagerWC?.window?.level = .floating + AppSD.themeManagerWC?.window?.makeKeyAndOrderFront(nil) NSApp.activate(ignoringOtherApps: true) + AppSD.themeManagerWC?.window?.level = .normal } } @@ -860,14 +855,21 @@ final class SettingsViewController: } AppSD.installerWC?.showWindow(self) + AppSD.installerWC?.window?.level = .floating + AppSD.installerWC?.window?.makeKeyAndOrderFront(nil) + NSApp.activate(ignoringOtherApps: true) + AppSD.installerWC?.window?.level = .normal } else { if (AppSD.installerOutWC == nil) { AppSD.installerOutWC = InstallerOutWindowController.loadFromNib() } AppSD.installerOutWC?.showWindow(self) + AppSD.installerOutWC?.window?.level = .floating + AppSD.installerOutWC?.window?.makeKeyAndOrderFront(nil) + NSApp.activate(ignoringOtherApps: true) + AppSD.installerOutWC?.window?.level = .normal } - //NSApp.activate(ignoringOtherApps: true) } } diff --git a/CloverApp/Clover/ThemeManager/ThemeManagerVC.swift b/CloverApp/Clover/ThemeManager/ThemeManagerVC.swift index 5a124d0f3..dd5cdc191 100644 --- a/CloverApp/Clover/ThemeManager/ThemeManagerVC.swift +++ b/CloverApp/Clover/ThemeManager/ThemeManagerVC.swift @@ -759,37 +759,51 @@ NSComboBoxDataSource { @IBAction func targetPopPressed(_ sender: FWPopUpButton!) { if let disk = sender?.selectedItem?.representedObject as? String { if !isMountPoint(path: disk) { - //DispatchQueue.global(qos: .background).async { - let cmd = "diskutil mount \(disk)" - let msg = String(format: "Clover wants to mount %@", disk) - let script = "do shell script \"\(cmd)\" with prompt \"\(msg)\" with administrator privileges" - - let task = Process() - - if #available(OSX 10.12, *) { - task.launchPath = "/usr/bin/osascript" - task.arguments = ["-e", script] - } else { - task.launchPath = "/usr/sbin/diskutil" - task.arguments = ["mount", disk] - } - - task.terminationHandler = { t in - if t.terminationStatus == 0 { - if isMountPoint(path: disk) { - self.targetVolume = getMountPoint(from: disk) + self.installButton.isEnabled = false + self.view.window?.level = .floating + DispatchQueue.global(priority: .background).async(execute: { () -> Void in + let cmd = "diskutil mount \(disk)" + let msg = String(format: "Clover wants to mount %@", disk) + let script = "do shell script \"\(cmd)\" with prompt \"\(msg)\" with administrator privileges" + + let task = Process() + + if #available(OSX 10.12, *) { + task.launchPath = "/usr/bin/osascript" + task.arguments = ["-e", script] + } else { + task.launchPath = "/usr/sbin/diskutil" + task.arguments = ["mount", disk] + } + + task.terminationHandler = { t in + if t.terminationStatus == 0 { + if isMountPoint(path: disk) { + DispatchQueue.main.async { + self.targetVolume = getMountPoint(from: disk) + self.populateTargets() + self.showInstalledThemes(self.installedThemesCheckBox) + } + } DispatchQueue.main.async { - self.populateTargets() + self.installButton.isEnabled = true + self.view.window?.makeKeyAndOrderFront(nil) + self.view.window?.level = .floating + self.view.window?.level = .normal + } + } else { + DispatchQueue.main.async { + NSSound.beep() + self.installButton.isEnabled = true + self.view.window?.makeKeyAndOrderFront(nil) + self.view.window?.level = .floating + self.view.window?.level = .normal self.showInstalledThemes(self.installedThemesCheckBox) } } - DispatchQueue.main.async { self.view.window?.makeKeyAndOrderFront(nil) } - } else { - NSSound.beep() - self.showInstalledThemes(self.installedThemesCheckBox) } - } - task.launch() + task.launch() + }) //} } else { self.targetVolume = getMountPoint(from: disk) From 986c00552d807f3abc6873da3d421cba5856f239 Mon Sep 17 00:00:00 2001 From: vectorsigma72 Date: Thu, 30 Apr 2020 19:42:19 +0200 Subject: [PATCH 08/12] Update buildmtoc.sh cctools-949.0.1 --- buildmtoc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildmtoc.sh b/buildmtoc.sh index e43b5c089..4c3ec4969 100755 --- a/buildmtoc.sh +++ b/buildmtoc.sh @@ -12,7 +12,7 @@ fi # Ctools source version # here we can change source versions of tools # -export CCTOOLS_VERSION=${CCTOOLS_VERSION:-921} +export CCTOOLS_VERSION=${CCTOOLS_VERSION:-949.0.1} # Change PREFIX if you want mtoc installed on different place # From 1ec91d72cde7802a3e03dd9a459ff8a9e8c1eb60 Mon Sep 17 00:00:00 2001 From: asava Date: Thu, 30 Apr 2020 21:17:54 +0300 Subject: [PATCH 09/12] A few corrections needed for Linux booting in some cases --- rEFIt_UEFI/Platform/Settings.cpp | 5 +++-- rEFIt_UEFI/refit/main.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/rEFIt_UEFI/Platform/Settings.cpp b/rEFIt_UEFI/Platform/Settings.cpp index 9acfda56f..c38962c22 100644 --- a/rEFIt_UEFI/Platform/Settings.cpp +++ b/rEFIt_UEFI/Platform/Settings.cpp @@ -1905,12 +1905,12 @@ FillinCustomEntry ( // } else { // Entry->Options.SPrintf("%s", Prop->string); // } - Entry->LoadOptions = Split(Prop->string, " "); + Entry->LoadOptions.import(Split(Prop->string, " ")); } else { Prop = GetProperty(DictPointer, "Arguments"); if (Prop != NULL && (Prop->type == kTagTypeString)) { // Entry->Options.SPrintf("%s", Prop->string); - Entry->LoadOptions = Split(Prop->string, " "); + Entry->LoadOptions = Split(Prop->string, " "); Entry->Flags = OSFLAG_SET(Entry->Flags, OSFLAG_NODEFAULTARGS); } } @@ -2046,6 +2046,7 @@ FillinCustomEntry ( Entry->Type = OSTYPE_WINEFI; } else if (AsciiStriCmp(Prop->string, "Linux") == 0) { Entry->Type = OSTYPE_LIN; + Entry->Flags = OSFLAG_SET(Entry->Flags, OSFLAG_NODEFAULTARGS); } else if (AsciiStriCmp(Prop->string, "LinuxKernel") == 0) { Entry->Type = OSTYPE_LINEFI; } else { diff --git a/rEFIt_UEFI/refit/main.cpp b/rEFIt_UEFI/refit/main.cpp index e4379004f..0b0ed02af 100644 --- a/rEFIt_UEFI/refit/main.cpp +++ b/rEFIt_UEFI/refit/main.cpp @@ -921,7 +921,7 @@ static VOID StartLoader(IN LOADER_ENTRY *Entry) // DBG("BeginExternalScreen\n"); BeginExternalScreen(OSFLAG_ISSET(Entry->Flags, OSFLAG_USEGRAPHICS)/*, L"Booting OS"*/); - if (!OSTYPE_IS_WINDOWS(Entry->LoaderType)) { + if (!OSTYPE_IS_WINDOWS(Entry->LoaderType) && !OSTYPE_IS_LINUX(Entry->LoaderType)) { if (OSFLAG_ISSET(Entry->Flags, OSFLAG_USEGRAPHICS)) { // save orig OutputString and replace it with // null implementation From c903faa26a54ee874cfa2644af34e1cbdf166174 Mon Sep 17 00:00:00 2001 From: asava Date: Thu, 30 Apr 2020 21:50:42 +0300 Subject: [PATCH 10/12] Missing file in refit.inf --- rEFIt_UEFI/refit.inf | 1 + 1 file changed, 1 insertion(+) diff --git a/rEFIt_UEFI/refit.inf b/rEFIt_UEFI/refit.inf index ba12edf9b..b5e85c24d 100644 --- a/rEFIt_UEFI/refit.inf +++ b/rEFIt_UEFI/refit.inf @@ -248,6 +248,7 @@ cpp_foundation/XStringArray.cpp cpp_foundation/XStringArray.h cpp_foundation/XStringArray.cpp + cpp_foundation/XToolsCommon.h # cpp_foundation/XUINTN.cpp # cpp_foundation/XUINTN.h cpp_unit_test/all_tests.h From 5ad1616d7f9515594f7b278ae90aeedb5643e868 Mon Sep 17 00:00:00 2001 From: Jief L Date: Fri, 1 May 2020 00:43:44 +0300 Subject: [PATCH 11/12] XtoolsCommon tests. --- .../CloverX64.xcodeproj/project.pbxproj | 20 +++ .../cpp_tests.xcodeproj/project.pbxproj | 12 ++ rEFIt_UEFI/cpp_foundation/XToolsCommon.h | 61 +++++--- rEFIt_UEFI/cpp_unit_test/XString_test.cpp | 23 +-- .../cpp_unit_test/XToolsCommon_test.cpp | 136 ++++++++++++++++++ rEFIt_UEFI/cpp_unit_test/XToolsCommon_test.h | 1 + rEFIt_UEFI/cpp_unit_test/all_tests.cpp | 22 ++- 7 files changed, 230 insertions(+), 45 deletions(-) create mode 100755 rEFIt_UEFI/cpp_unit_test/XToolsCommon_test.cpp create mode 100755 rEFIt_UEFI/cpp_unit_test/XToolsCommon_test.h diff --git a/Xcode/CloverX64/CloverX64.xcodeproj/project.pbxproj b/Xcode/CloverX64/CloverX64.xcodeproj/project.pbxproj index 3c6bd0eb1..f1128461d 100644 --- a/Xcode/CloverX64/CloverX64.xcodeproj/project.pbxproj +++ b/Xcode/CloverX64/CloverX64.xcodeproj/project.pbxproj @@ -130,6 +130,14 @@ 9A9AEB9B243F7B8400FBD7D8 /* unicode_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9AEB90243F7B5600FBD7D8 /* unicode_conversions.cpp */; }; 9A9AEB9C243F7B8400FBD7D8 /* unicode_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9AEB90243F7B5600FBD7D8 /* unicode_conversions.cpp */; }; 9A9D3B2324221563006D8CD9 /* printf_lite-test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9D3B2124221563006D8CD9 /* printf_lite-test.cpp */; }; + 9A9EA7FE245AD97F0076EC02 /* XToolsCommon_test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A9EA7FC245AD97E0076EC02 /* XToolsCommon_test.h */; }; + 9A9EA7FF245AD97F0076EC02 /* XToolsCommon_test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A9EA7FC245AD97E0076EC02 /* XToolsCommon_test.h */; }; + 9A9EA800245AD97F0076EC02 /* XToolsCommon_test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A9EA7FC245AD97E0076EC02 /* XToolsCommon_test.h */; }; + 9A9EA801245AD97F0076EC02 /* XToolsCommon_test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A9EA7FC245AD97E0076EC02 /* XToolsCommon_test.h */; }; + 9A9EA806245AD9B30076EC02 /* XToolsCommon_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9EA7FD245AD97F0076EC02 /* XToolsCommon_test.cpp */; }; + 9A9EA807245AD9B30076EC02 /* XToolsCommon_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9EA7FD245AD97F0076EC02 /* XToolsCommon_test.cpp */; }; + 9A9EA808245AD9B40076EC02 /* XToolsCommon_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9EA7FD245AD97F0076EC02 /* XToolsCommon_test.cpp */; }; + 9A9EA80A245AD9E50076EC02 /* XToolsCommon_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9EA7FD245AD97F0076EC02 /* XToolsCommon_test.cpp */; }; 9AC77FB924176C04005CDD5C /* XStringArray_test.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ECC24176C04005CDD5C /* XStringArray_test.h */; }; 9AC77FBA24176C04005CDD5C /* XArray_tests.h in Headers */ = {isa = PBXBuildFile; fileRef = 9AC77ECD24176C04005CDD5C /* XArray_tests.h */; }; 9AC77FBB24176C04005CDD5C /* XStringArray_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AC77ECE24176C04005CDD5C /* XStringArray_test.cpp */; }; @@ -890,6 +898,8 @@ 9A9AEB93243F7B5600FBD7D8 /* unicode_conversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unicode_conversions.h; sourceTree = ""; }; 9A9AEB98243F7B7900FBD7D8 /* printf_lite-test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "printf_lite-test.h"; sourceTree = ""; }; 9A9D3B2124221563006D8CD9 /* printf_lite-test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "printf_lite-test.cpp"; sourceTree = ""; }; + 9A9EA7FC245AD97E0076EC02 /* XToolsCommon_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XToolsCommon_test.h; sourceTree = ""; }; + 9A9EA7FD245AD97F0076EC02 /* XToolsCommon_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XToolsCommon_test.cpp; sourceTree = ""; }; 9AC77EC424176BF2005CDD5C /* libCloverX64.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libCloverX64.a; sourceTree = BUILT_PRODUCTS_DIR; }; 9AC77ECC24176C04005CDD5C /* XStringArray_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XStringArray_test.h; sourceTree = ""; }; 9AC77ECD24176C04005CDD5C /* XArray_tests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XArray_tests.h; sourceTree = ""; }; @@ -1170,6 +1180,8 @@ 9AC77ECA24176C04005CDD5C /* cpp_unit_test */ = { isa = PBXGroup; children = ( + 9A9EA7FD245AD97F0076EC02 /* XToolsCommon_test.cpp */, + 9A9EA7FC245AD97E0076EC02 /* XToolsCommon_test.h */, 9A9AEB98243F7B7900FBD7D8 /* printf_lite-test.h */, 9AC77ED424176C04005CDD5C /* all_tests.cpp */, 9AC77ED724176C04005CDD5C /* all_tests.h */, @@ -1491,6 +1503,7 @@ 9AF41562242BABC700D2644C /* printlib-test-cpp_conf.h in Headers */, 9AC7808D24176C04005CDD5C /* XStringArray.h in Headers */, 9A105B7824483AE40006DE06 /* usbfix.h in Headers */, + 9A9EA7FE245AD97F0076EC02 /* XToolsCommon_test.h in Headers */, 9A28CD33241BC0DF00F3D247 /* strcmp_test.h in Headers */, 9AC7802124176C04005CDD5C /* boot.h in Headers */, 9A7AEDE7245963BF003AAD04 /* XToolsCommon.h in Headers */, @@ -1600,6 +1613,7 @@ buildActionMask = 2147483647; files = ( 9ACFE64E24309AF80071CC93 /* abort.h in Headers */, + 9A9EA801245AD97F0076EC02 /* XToolsCommon_test.h in Headers */, 9ACFE64F24309AF80071CC93 /* MSKEK.h in Headers */, 9ACFE65024309AF80071CC93 /* menu_items.h in Headers */, 9ACFE65124309AF80071CC93 /* XTheme.h in Headers */, @@ -1762,6 +1776,7 @@ 9AF415D0242CD75C00D2644C /* Hibernate.h in Headers */, 9AF415D1242CD75C00D2644C /* strlen_test.h in Headers */, 9AF415D2242CD75C00D2644C /* XArray_tests.h in Headers */, + 9A9EA7FF245AD97F0076EC02 /* XToolsCommon_test.h in Headers */, 9AF415D3242CD75C00D2644C /* Handle.h in Headers */, 9AF415D4242CD75C00D2644C /* XArray.h in Headers */, 9AF415D5242CD75C00D2644C /* MSPCADB.h in Headers */, @@ -1857,6 +1872,7 @@ 9AF416AD242CDA5800D2644C /* Hibernate.h in Headers */, 9AF416AE242CDA5800D2644C /* strlen_test.h in Headers */, 9AF416AF242CDA5800D2644C /* XArray_tests.h in Headers */, + 9A9EA800245AD97F0076EC02 /* XToolsCommon_test.h in Headers */, 9AF416B0242CDA5800D2644C /* Handle.h in Headers */, 9AF416B1242CDA5800D2644C /* XArray.h in Headers */, 9AF416B2242CDA5800D2644C /* MSPCADB.h in Headers */, @@ -2171,6 +2187,7 @@ 9AC7805E24176C04005CDD5C /* common.cpp in Sources */, 9AC7804924176C04005CDD5C /* egemb_icons.cpp in Sources */, 9AC7801124176C04005CDD5C /* Edid.cpp in Sources */, + 9A9EA80A245AD9E50076EC02 /* XToolsCommon_test.cpp in Sources */, 9AC7803A24176C04005CDD5C /* smbios.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -2284,6 +2301,7 @@ 9ACFE71F24309AF80071CC93 /* common.cpp in Sources */, 9ACFE72024309AF80071CC93 /* egemb_icons.cpp in Sources */, 9ACFE72124309AF80071CC93 /* Edid.cpp in Sources */, + 9A9EA806245AD9B30076EC02 /* XToolsCommon_test.cpp in Sources */, 9ACFE72224309AF80071CC93 /* smbios.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -2397,6 +2415,7 @@ 9AF41655242CD75C00D2644C /* common.cpp in Sources */, 9AF41656242CD75C00D2644C /* egemb_icons.cpp in Sources */, 9AF41657242CD75C00D2644C /* Edid.cpp in Sources */, + 9A9EA808245AD9B40076EC02 /* XToolsCommon_test.cpp in Sources */, 9AF41658242CD75C00D2644C /* smbios.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -2510,6 +2529,7 @@ 9AF41732242CDA5800D2644C /* common.cpp in Sources */, 9AF41733242CDA5800D2644C /* egemb_icons.cpp in Sources */, 9AF41734242CDA5800D2644C /* Edid.cpp in Sources */, + 9A9EA807245AD9B30076EC02 /* XToolsCommon_test.cpp in Sources */, 9AF41735242CDA5800D2644C /* smbios.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Xcode/cpp_tests/cpp_tests.xcodeproj/project.pbxproj b/Xcode/cpp_tests/cpp_tests.xcodeproj/project.pbxproj index a6d82154d..a6b62c9a7 100644 --- a/Xcode/cpp_tests/cpp_tests.xcodeproj/project.pbxproj +++ b/Xcode/cpp_tests/cpp_tests.xcodeproj/project.pbxproj @@ -85,6 +85,10 @@ 9A9AEB8D243F73CE00FBD7D8 /* unicode_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9AEB8C243F73CE00FBD7D8 /* unicode_conversions.cpp */; }; 9A9AEB8E243F752C00FBD7D8 /* unicode_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9AEB8C243F73CE00FBD7D8 /* unicode_conversions.cpp */; }; 9A9AEB8F243F752C00FBD7D8 /* unicode_conversions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9AEB8C243F73CE00FBD7D8 /* unicode_conversions.cpp */; }; + 9A9EA7F8245AAB310076EC02 /* XToolsCommon_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9EA7F7245AAB310076EC02 /* XToolsCommon_test.cpp */; }; + 9A9EA7F9245AAB310076EC02 /* XToolsCommon_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9EA7F7245AAB310076EC02 /* XToolsCommon_test.cpp */; }; + 9A9EA7FA245AAB310076EC02 /* XToolsCommon_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9EA7F7245AAB310076EC02 /* XToolsCommon_test.cpp */; }; + 9A9EA7FB245AAB310076EC02 /* XToolsCommon_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A9EA7F7245AAB310076EC02 /* XToolsCommon_test.cpp */; }; 9AA0458A2425F94D000D6970 /* printf_lite-test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AA045892425F94D000D6970 /* printf_lite-test.cpp */; }; 9AA0458B2425F94D000D6970 /* printf_lite-test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AA045892425F94D000D6970 /* printf_lite-test.cpp */; }; 9AA0458C2425F94D000D6970 /* printf_lite-test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9AA045892425F94D000D6970 /* printf_lite-test.cpp */; }; @@ -177,6 +181,8 @@ 9A92234D2402FD9500483CBA /* Platform.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Platform.h; sourceTree = ""; }; 9A9AEB8B243F73CE00FBD7D8 /* unicode_conversions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unicode_conversions.h; sourceTree = ""; }; 9A9AEB8C243F73CE00FBD7D8 /* unicode_conversions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = unicode_conversions.cpp; sourceTree = ""; }; + 9A9EA7F6245AAB310076EC02 /* XToolsCommon_test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XToolsCommon_test.h; sourceTree = ""; }; + 9A9EA7F7245AAB310076EC02 /* XToolsCommon_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XToolsCommon_test.cpp; sourceTree = ""; }; 9AA045732425D200000D6970 /* IO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IO.h; sourceTree = ""; }; 9AA045742425D200000D6970 /* IO.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IO.cpp; sourceTree = ""; }; 9AA045882425F94D000D6970 /* printf_lite-test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "printf_lite-test.h"; sourceTree = ""; }; @@ -255,6 +261,8 @@ 9A0B084C2402FE9B00E2B470 /* cpp_unit_test */ = { isa = PBXGroup; children = ( + 9A9EA7F7245AAB310076EC02 /* XToolsCommon_test.cpp */, + 9A9EA7F6245AAB310076EC02 /* XToolsCommon_test.h */, 9A4FFA802451C88D0050B38B /* XString_test.cpp */, 9A4FFA7F2451C88C0050B38B /* XString_test.h */, 9A4185AF2439E4D500BEAFB8 /* LoadOptions_test.cpp */, @@ -500,6 +508,7 @@ 9A28CD20241BB61B00F3D247 /* abort.cpp in Sources */, 9A4FFA842451C9740050B38B /* XString.cpp in Sources */, 9A4FFA822451C88D0050B38B /* XString_test.cpp in Sources */, + 9A9EA7F9245AAB310076EC02 /* XToolsCommon_test.cpp in Sources */, 9A28CD23241BB61B00F3D247 /* strlen.cpp in Sources */, 9A28CD4C241F4CCE00F3D247 /* xcode_utf_fixed.cpp in Sources */, 9A0B08742403B08400E2B470 /* main.cpp in Sources */, @@ -528,6 +537,7 @@ 9A2A7C6E24576CCE00422263 /* abort.cpp in Sources */, 9A2A7C6F24576CCE00422263 /* XString.cpp in Sources */, 9A2A7C7024576CCE00422263 /* XString_test.cpp in Sources */, + 9A9EA7FB245AAB310076EC02 /* XToolsCommon_test.cpp in Sources */, 9A2A7C7124576CCE00422263 /* strlen.cpp in Sources */, 9A2A7C7224576CCE00422263 /* xcode_utf_fixed.cpp in Sources */, 9A2A7C7324576CCE00422263 /* main.cpp in Sources */, @@ -556,6 +566,7 @@ 9A28CD21241BB61B00F3D247 /* abort.cpp in Sources */, 9A4FFA852451C9740050B38B /* XString.cpp in Sources */, 9A4FFA832451C88D0050B38B /* XString_test.cpp in Sources */, + 9A9EA7FA245AAB310076EC02 /* XToolsCommon_test.cpp in Sources */, 9A28CD24241BB61B00F3D247 /* strlen.cpp in Sources */, 9A28CD4D241F4CCE00F3D247 /* xcode_utf_fixed.cpp in Sources */, 9A57C21B2418B9A00029A39F /* main.cpp in Sources */, @@ -584,6 +595,7 @@ 9A4FFA7E2451C8330050B38B /* XString.cpp in Sources */, 9A4FFA812451C88D0050B38B /* XString_test.cpp in Sources */, 9A28CD22241BB61B00F3D247 /* strlen.cpp in Sources */, + 9A9EA7F8245AAB310076EC02 /* XToolsCommon_test.cpp in Sources */, 9A28CD4B241F4CCE00F3D247 /* xcode_utf_fixed.cpp in Sources */, 9A9223312402FD1000483CBA /* main.cpp in Sources */, 9A28CD16241BACBB00F3D247 /* strlen_test.cpp in Sources */, diff --git a/rEFIt_UEFI/cpp_foundation/XToolsCommon.h b/rEFIt_UEFI/cpp_foundation/XToolsCommon.h index 381db42f2..3cfb8ca6a 100644 --- a/rEFIt_UEFI/cpp_foundation/XToolsCommon.h +++ b/rEFIt_UEFI/cpp_foundation/XToolsCommon.h @@ -24,28 +24,32 @@ struct _xtools__true_type { template struct _xtools__make_unsigned {}; -template <> struct _xtools__make_unsigned< char> {typedef unsigned char type;}; -template <> struct _xtools__make_unsigned< signed char> {typedef unsigned char type;}; -template <> struct _xtools__make_unsigned {typedef unsigned char type;}; -template <> struct _xtools__make_unsigned< char16_t> {typedef char16_t type;}; -template <> struct _xtools__make_unsigned< char32_t> {typedef char32_t type;}; -template <> struct _xtools__make_unsigned< wchar_t> {typedef wchar_t type;}; -template <> struct _xtools__make_unsigned< signed short> {typedef unsigned short type;}; -template <> struct _xtools__make_unsigned {typedef unsigned short type;}; -template <> struct _xtools__make_unsigned< signed int> {typedef unsigned int type;}; -template <> struct _xtools__make_unsigned {typedef unsigned int type;}; -template <> struct _xtools__make_unsigned< signed long> {typedef unsigned long type;}; -template <> struct _xtools__make_unsigned {typedef unsigned long type;}; -template <> struct _xtools__make_unsigned< signed long long> {typedef unsigned long long type;}; +template <> struct _xtools__make_unsigned< char> {typedef unsigned char type;}; +template <> struct _xtools__make_unsigned< signed char> {typedef unsigned char type;}; +template <> struct _xtools__make_unsigned< unsigned char> {typedef unsigned char type;}; +template <> struct _xtools__make_unsigned< char16_t> {typedef char16_t type;}; +template <> struct _xtools__make_unsigned< char32_t> {typedef char32_t type;}; +#if WCHAR_MAX <= 0xFFFF +template <> struct _xtools__make_unsigned< wchar_t> {typedef char16_t type;}; +#else +template <> struct _xtools__make_unsigned< wchar_t> {typedef char32_t type;}; +#endif +template <> struct _xtools__make_unsigned< short> {typedef unsigned short type;}; +template <> struct _xtools__make_unsigned< unsigned short> {typedef unsigned short type;}; +template <> struct _xtools__make_unsigned< int> {typedef unsigned int type;}; +template <> struct _xtools__make_unsigned< unsigned int> {typedef unsigned int type;}; +template <> struct _xtools__make_unsigned< long> {typedef unsigned long type;}; +template <> struct _xtools__make_unsigned< unsigned long> {typedef unsigned long type;}; +template <> struct _xtools__make_unsigned< long long> {typedef unsigned long long type;}; template <> struct _xtools__make_unsigned {typedef unsigned long long type;}; // is_integral template struct _xtools__is_integral_st : public _xtools__false_type {}; //template <> struct _xtools__is_integral_st : public _xtools__true_type {}; -template <> struct _xtools__is_integral_st : public _xtools__true_type {}; -template <> struct _xtools__is_integral_st : public _xtools__true_type {}; -template <> struct _xtools__is_integral_st : public _xtools__true_type {}; +//template <> struct _xtools__is_integral_st : public _xtools__true_type {}; +//template <> struct _xtools__is_integral_st : public _xtools__true_type {}; +//template <> struct _xtools__is_integral_st : public _xtools__true_type {}; //template <> struct _xtools__is_integral_st : public _xtools__true_type {}; template <> struct _xtools__is_integral_st : public _xtools__true_type {}; template <> struct _xtools__is_integral_st : public _xtools__true_type {}; @@ -58,6 +62,11 @@ template <> struct _xtools__is_integral_st : public // is_char +// Looks like I don't need to remove reference. +// This : template +// void strcpy(O otherChar) +// is still enabled if parameter is a char& + template struct _xtools__is_char_st : public _xtools__false_type {}; template <> struct _xtools__is_char_st : public _xtools__true_type {}; template <> struct _xtools__is_char_st : public _xtools__true_type {}; @@ -93,6 +102,15 @@ template <> struct _xtools__is_char_st : public // typedef _Ty type; // }; + +template< class T > struct _xtools__remove_ref { typedef T type; }; +template< class T > struct _xtools__remove_ref { typedef T type; }; + +template< class T > struct _xtools__remove_const { typedef T type; }; +template< class T > struct _xtools__remove_const { typedef T type; }; +template< class T > struct _xtools__remove_const { typedef T& type; }; +template< class T > struct _xtools__remove_const { typedef T* type; }; + template< class T > struct _xtools__remove_const_ptr { typedef T type; }; template< class T > struct _xtools__remove_const_ptr { typedef T type; }; template< class T > struct _xtools__remove_const_ptr { typedef T type; }; @@ -150,11 +168,14 @@ struct _xtools__has_type_member> : _xtool +#define remove_const(x) typename _xtools__remove_const::type +#define unsigned_type(x) typename _xtools__make_unsigned::type +#define remove_ref(x) typename _xtools__remove_ref::type +#define remove_const_ptr(x) typename _xtools__remove_const_ptr::type -#define unsigned_type(x) typename _xtools__make_unsigned::type -#define is_integral(x) _xtools__is_integral_st::value -#define is_char(x) _xtools__is_char_st::value -#define is_char_ptr(x) _xtools__is_char_ptr_st::type>::value +#define is_integral(x) _xtools__is_integral_st::value +#define is_char(x) _xtools__is_char_st::value +#define is_char_ptr(x) _xtools__is_char_ptr_st::type>::value #define enable_if_t(x) typename _xtools_enable_if_t::type #define enable_if(x) typename enable_if_type = typename _xtools_enable_if_t::type diff --git a/rEFIt_UEFI/cpp_unit_test/XString_test.cpp b/rEFIt_UEFI/cpp_unit_test/XString_test.cpp index 4ef648a1a..d2bc710b1 100755 --- a/rEFIt_UEFI/cpp_unit_test/XString_test.cpp +++ b/rEFIt_UEFI/cpp_unit_test/XString_test.cpp @@ -4,9 +4,9 @@ -int nbTest = 0; -int nbTestFailed = 0; -bool displayOnlyFailed = true; +static int nbTest = 0; +static int nbTestFailed = 0; +static bool displayOnlyFailed = true; #define STRINGIFY_(s) #s @@ -1486,7 +1486,6 @@ XStringClass xstr2 = initia__String.basename(); /***************************** *****************************/ -#undef realloc // //#include //#include @@ -1515,24 +1514,12 @@ class C int XString_tests() { #ifdef JIEF_DEBUG -// printf("XString16_tests -> Enter\n"); +// printf("XString_tests -> Enter\n"); #endif -XString8 xs1 = "Test:"_XS8; -constexpr const LString8 ls1 = "foo"_XS8; -xs1 = ls1; -xs1 = ls1 + "bar"; -XStringW xsw1 = L"world"_XSW; -XString8 xs2 = xs1 + "hel" + 'l' + L'o' + L" the " + xsw1; -XString8 xs3 = xs1; - -LString8 a = "Hello"_XS8; -XStringW b = L"world"_XSW; -XString8 c = a + "foo"; // + 'o' + L'o' + b + L"bar"; - -//char c = 1; +//char c = 'a'; //int ii = sizeof(size_t); //unsigned long long ull = 1; //unsigned long long ll = 3; diff --git a/rEFIt_UEFI/cpp_unit_test/XToolsCommon_test.cpp b/rEFIt_UEFI/cpp_unit_test/XToolsCommon_test.cpp new file mode 100755 index 000000000..57d894099 --- /dev/null +++ b/rEFIt_UEFI/cpp_unit_test/XToolsCommon_test.cpp @@ -0,0 +1,136 @@ +#include +#include "../cpp_foundation/XString.h" +#include "../cpp_foundation/unicode_conversions.h" + + + +static int nbTest = 0; +static int nbTestFailed = 0; +//static bool displayOnlyFailed = true; + + +#define STRINGIFY_(s) #s +#define STRINGIFY(s) STRINGIFY_(s) + + +//#include +//#include +//#include +//#include + +class C +{ + public: + typedef char char_t; + const char* data; + constexpr C() : data(0) { } +}; + +#define ASSERT_CONST_NONCONST(test, type, expectedResult) \ + test(type, expectedResult) \ + test(const type, expectedResult) \ + +#define ASSERT_ALL_INTEGRAL(test, expectedResult) \ + ASSERT_CONST_NONCONST(test, short, expectedResult) \ + ASSERT_CONST_NONCONST(test, short, expectedResult) \ + ASSERT_CONST_NONCONST(test, int, expectedResult) \ + ASSERT_CONST_NONCONST(test, unsigned int, expectedResult) \ + ASSERT_CONST_NONCONST(test, long, expectedResult) \ + ASSERT_CONST_NONCONST(test, unsigned long, expectedResult) \ + ASSERT_CONST_NONCONST(test, long, expectedResult) \ + ASSERT_CONST_NONCONST(test, unsigned long long, expectedResult) \ + +#define ASSERT_ALL_CHAR(test, expectedResult) \ + ASSERT_CONST_NONCONST(test, char, expectedResult) \ + ASSERT_CONST_NONCONST(test, signed char, expectedResult) \ + ASSERT_CONST_NONCONST(test, unsigned char, expectedResult) \ + ASSERT_CONST_NONCONST(test, char16_t, expectedResult) \ + ASSERT_CONST_NONCONST(test, char32_t, expectedResult) \ + ASSERT_CONST_NONCONST(test, wchar_t, expectedResult) \ + +#define ASSERT_ALL_PTR(test, type, expectedResult) \ + ASSERT_CONST_NONCONST(test, type*, expectedResult) \ + ASSERT_CONST_NONCONST(test, type[], expectedResult) \ + ASSERT_CONST_NONCONST(test, type[10], expectedResult) \ + +#define ASSERT_ALL_CHAR_PTR(test, expectedResult) \ + ASSERT_ALL_PTR(test, char, expectedResult) \ + ASSERT_ALL_PTR(test, signed char, expectedResult) \ + ASSERT_ALL_PTR(test, unsigned char, expectedResult) \ + ASSERT_ALL_PTR(test, char16_t, expectedResult) \ + ASSERT_ALL_PTR(test, char32_t, expectedResult) \ + ASSERT_ALL_PTR(test, wchar_t, expectedResult) \ + +#define ASSERT_ALL_INTEGRAL_CHAR(test, expectedResult) \ + ASSERT_ALL_INTEGRAL(test, expectedResult) \ + ASSERT_ALL_CHAR(test, expectedResult) \ + +template +struct _xtools__is_unsigned_true_false : public _xtools__false_type {}; +template <> +struct _xtools__is_unsigned_true_false : public _xtools__true_type {}; +template <> +struct _xtools__is_unsigned_true_false : public _xtools__false_type {}; + +template +struct _xtools__is_unsigned : public _xtools__is_unsigned_true_false< ( _Tp(0) < _Tp(-1) ) > {}; + +#define is_unsigned(x) _xtools__is_unsigned::value + +#define ASSERT_UNSIGNED_TYPE(type, expectedResult) \ + static_assert(is_unsigned(unsigned_type(type)) == expectedResult, "unsigned_type " STRINGIFY(type) " failed"); + +#define ASSERT_SIZEOF_UNSIGNED_TYPE(type, expectedResult) \ + static_assert(sizeof(unsigned_type(type)) == sizeof(type), "sizeof(unsigned_type(" STRINGIFY(type) ")) == sizeof(" STRINGIFY(type) ") failed"); + +#define ASSERT_IS_INTEGRAL(type, expectedResult) \ + static_assert(is_integral(type) == expectedResult, "is_integral(" STRINGIFY(type) ") failed"); + +#define ASSERT_IS_CHAR(type, expectedResult) \ + static_assert(is_char(type) == expectedResult, "is_char(" STRINGIFY(type) ") failed"); + +#define ASSERT_IS_CHAR_PTR(type, expectedResult) \ + /*printf("is_char_ptr(%s)\n", STRINGIFY(type)); */ \ + static_assert(is_char_ptr(type) == expectedResult, "is_char_ptr(" STRINGIFY(type) ") failed"); + + +int XToolsCommon_tests() +{ +#ifdef JIEF_DEBUG +// printf("XToolsCommon_tests -> Enter\n"); +#endif + +ASSERT_ALL_INTEGRAL_CHAR(ASSERT_UNSIGNED_TYPE, true) +ASSERT_ALL_INTEGRAL_CHAR(ASSERT_SIZEOF_UNSIGNED_TYPE, true) // expectedResult unused by ASSERT_SIZEOF_UNSIGNED_TYPE +ASSERT_ALL_INTEGRAL(ASSERT_IS_INTEGRAL, true) +ASSERT_ALL_CHAR(ASSERT_IS_INTEGRAL, false) + +ASSERT_ALL_INTEGRAL(ASSERT_IS_CHAR, false) +ASSERT_ALL_CHAR(ASSERT_IS_CHAR, true) +ASSERT_ALL_CHAR_PTR(ASSERT_IS_CHAR_PTR, true) + + + + + +#ifdef JIEF_DEBUG + if ( nbTestFailed == 0 ) printf("All %d tests succeeded.\n", nbTest); + else printf("%d tests succeeded out of %d.\n", nbTest-nbTestFailed, nbTest); +#endif + return nbTestFailed > 0; +} + + + + + +//const char* p1 = "foo/bar"; // basename returns bar +//const char* p1 = "foo/"; // basename returns foo +//const char* p1 = "foo//"; // basename returns foo +//const char* p1 = "foo///"; // basename returns foo +//const char* p1 = ""; // basename returns "." +//const char* p1 = " foo/bar "; // basename returns "bar " +//const char* p1 = " foo "; // basename returns " foo " +//const char* p1 = " "; // basename returns " " +//const char* p2 = basename((char*)p1); + diff --git a/rEFIt_UEFI/cpp_unit_test/XToolsCommon_test.h b/rEFIt_UEFI/cpp_unit_test/XToolsCommon_test.h new file mode 100755 index 000000000..716173572 --- /dev/null +++ b/rEFIt_UEFI/cpp_unit_test/XToolsCommon_test.h @@ -0,0 +1 @@ +int XToolsCommon_tests(); diff --git a/rEFIt_UEFI/cpp_unit_test/all_tests.cpp b/rEFIt_UEFI/cpp_unit_test/all_tests.cpp index d58679e23..2751833ce 100755 --- a/rEFIt_UEFI/cpp_unit_test/all_tests.cpp +++ b/rEFIt_UEFI/cpp_unit_test/all_tests.cpp @@ -13,6 +13,7 @@ #include "strlen_test.h" #include "printf_lite-test.h" #include "LoadOptions_test.h" +#include "XToolsCommon_test.h" #if defined(JIEF_DEBUG) && defined(CLOVER_BUILD) #include "poolprint-test.h" @@ -31,11 +32,18 @@ bool all_tests() bool all_ok = true; int ret; - ret = XString_tests(); +// ret = XString_tests(); +// if ( ret != 0 ) { +// printf("XString16_tests() failed at test %d\n", ret); +// all_ok = false; +// } +#if defined(JIEF_DEBUG) + ret = XToolsCommon_tests(); if ( ret != 0 ) { - printf("XString16_tests() failed at test %d\n", ret); + printf("printlib_tests() failed at test %d\n", ret); all_ok = false; } +#endif //return ret; // ret = XUINTN_tests(); // if ( ret != 0 ) { @@ -86,11 +94,11 @@ bool all_tests() printf("XObjArray_tests() failed at test %d\n", ret); all_ok = false; } -// ret = XString_tests(); -// if ( ret != 0 ) { -// printf("XString_tests() failed at test %d\n", ret); -// all_ok = false; -// } + ret = XString_tests(); + if ( ret != 0 ) { + printf("XString_tests() failed at test %d\n", ret); + all_ok = false; + } ret = XStringArray_tests(); if ( ret != 0 ) { printf("XStringArray_tests() failed at test %d\n", ret); From 64de6d0fef712592a8baf7caf9670488b8f58b3c Mon Sep 17 00:00:00 2001 From: asava Date: Fri, 1 May 2020 03:14:11 +0300 Subject: [PATCH 12/12] Correct some problems when changing config files --- rEFIt_UEFI/Platform/Settings.cpp | 29 ++++++++++++++++++++++------- rEFIt_UEFI/refit/main.cpp | 12 ++++++++---- rEFIt_UEFI/refit/menu.cpp | 6 +++--- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/rEFIt_UEFI/Platform/Settings.cpp b/rEFIt_UEFI/Platform/Settings.cpp index c38962c22..4dbe0d57f 100644 --- a/rEFIt_UEFI/Platform/Settings.cpp +++ b/rEFIt_UEFI/Platform/Settings.cpp @@ -65,7 +65,7 @@ INTN LayoutBannerOffset = 64; INTN LayoutTextOffset = 0; INTN LayoutButtonOffset = 0; -ACPI_PATCHED_AML *ACPIPatchedAML; +ACPI_PATCHED_AML *ACPIPatchedAML = NULL; SIDELOAD_KEXT *InjectKextList = NULL; //SYSVARIABLES *SysVariables; CHAR16 *IconFormat = NULL; @@ -96,7 +96,7 @@ UINTN ThemesNum = 0; CONST CHAR16 *ThemesList[100]; //no more then 100 themes? UINTN ConfigsNum; CHAR16 *ConfigsList[20]; -UINTN DsdtsNum; +UINTN DsdtsNum = 0; CHAR16 *DsdtsList[20]; UINTN AudioNum; HDA_OUTPUTS AudioList[20]; @@ -3262,6 +3262,13 @@ GetListOfDsdts () INTN NameLen; CHAR16* AcpiPath = PoolPrint(L"%s\\ACPI\\patched", OEMPath); + if (DsdtsNum > 0) { + for (UINTN i = 0; i < DsdtsNum; i++) { + if (DsdtsList[DsdtsNum] != NULL) { + FreePool(DsdtsList[DsdtsNum]); + } + } + } DsdtsNum = 0; OldChosenDsdt = 0xFFFF; @@ -3273,13 +3280,13 @@ GetListOfDsdts () continue; } - snwprintf(FullName, 512, "%ls\\%ls", AcpiPath, DirEntry->FileName); + snwprintf(FullName, 512, "%ls\\%ls", AcpiPath, DirEntry->FileName); if (FileExists(SelfRootDir, FullName)) { if (StriCmp(DirEntry->FileName, gSettings.DsdtName) == 0) { OldChosenDsdt = DsdtsNum; } NameLen = StrLen(DirEntry->FileName); //with ".aml" - DsdtsList[DsdtsNum] = (CHAR16*)AllocateCopyPool(NameLen * sizeof(CHAR16) + 2, DirEntry->FileName); + DsdtsList[DsdtsNum] = (CHAR16*)AllocateCopyPool(NameLen * sizeof(CHAR16) + 2, DirEntry->FileName); // if changing, notice freepool above DsdtsList[DsdtsNum++][NameLen] = L'\0'; DBG("- %ls\n", DirEntry->FileName); } @@ -3297,6 +3304,14 @@ GetListOfACPI () INTN i, Count = gSettings.DisabledAMLCount; CHAR16* AcpiPath = PoolPrint(L"%s\\ACPI\\patched", OEMPath); + while (ACPIPatchedAML != NULL) { + if (ACPIPatchedAML->FileName) { + FreePool(ACPIPatchedAML->FileName); + } + ACPIPatchedAMLTmp = ACPIPatchedAML; + ACPIPatchedAML = ACPIPatchedAML->Next; + FreePool(ACPIPatchedAMLTmp); + } ACPIPatchedAML = NULL; DirIterOpen(SelfRootDir, AcpiPath, &DirIter); @@ -3310,11 +3325,11 @@ GetListOfACPI () continue; } - snwprintf(FullName, 512, "%ls\\%ls", AcpiPath, DirEntry->FileName); + snwprintf(FullName, 512, "%ls\\%ls", AcpiPath, DirEntry->FileName); if (FileExists(SelfRootDir, FullName)) { BOOLEAN ACPIDisabled = FALSE; - ACPIPatchedAMLTmp = (__typeof__(ACPIPatchedAMLTmp))AllocateZeroPool(sizeof(ACPI_PATCHED_AML)); - ACPIPatchedAMLTmp->FileName = PoolPrint(L"%s", DirEntry->FileName); + ACPIPatchedAMLTmp = (__typeof__(ACPIPatchedAMLTmp))AllocateZeroPool(sizeof(ACPI_PATCHED_AML)); // if changing, notice freepool above + ACPIPatchedAMLTmp->FileName = PoolPrint(L"%s", DirEntry->FileName); // if changing, notice freepool above for (i = 0; i < Count; i++) { if ((gSettings.DisabledAML[i] != NULL) && diff --git a/rEFIt_UEFI/refit/main.cpp b/rEFIt_UEFI/refit/main.cpp index 0b0ed02af..09833ffda 100644 --- a/rEFIt_UEFI/refit/main.cpp +++ b/rEFIt_UEFI/refit/main.cpp @@ -2364,12 +2364,17 @@ RefitMain (IN EFI_HANDLE ImageHandle, } - GetListOfDsdts(); //only after GetUserSettings - GetListOfACPI(); //ssdt and other tables - AfterTool = FALSE; gGuiIsReady = TRUE; + gBootChanged = TRUE; + gThemeChanged = TRUE; do { + if (gBootChanged && gThemeChanged) { // config changed + GetListOfDsdts(); //only after GetUserSettings + GetListOfACPI(); //ssdt and other tables + } + gBootChanged = FALSE; + MainMenu.Entries.Empty(); OptionMenu.Entries.Empty(); InitKextList(); @@ -2415,7 +2420,6 @@ RefitMain (IN EFI_HANDLE ImageHandle, if (gThemeNeedInit) { InitTheme(TRUE, &Now); gThemeNeedInit = FALSE; - gThemeChanged = TRUE; } else if (gThemeChanged) { DBG("change theme\n"); InitTheme(FALSE, NULL); diff --git a/rEFIt_UEFI/refit/menu.cpp b/rEFIt_UEFI/refit/menu.cpp index 3f16fa54f..2e719926b 100644 --- a/rEFIt_UEFI/refit/menu.cpp +++ b/rEFIt_UEFI/refit/menu.cpp @@ -1020,12 +1020,12 @@ VOID ApplyInputs(VOID) if (InputItems[i].Valid) { Status = LoadUserSettings(SelfRootDir, ConfigsList[OldChosenConfig], &dict); if (!EFI_ERROR(Status)) { + gBootChanged = TRUE; + gThemeChanged = TRUE; Status = GetUserSettings(SelfRootDir, dict); if (gConfigDict[2]) FreeTag(gConfigDict[2]); gConfigDict[2] = dict; - snwprintf(gSettings.ConfigName, 64, "%ls", ConfigsList[OldChosenConfig]); - gBootChanged = TRUE; - gThemeChanged = TRUE; + snwprintf(gSettings.ConfigName, 64, "%ls", ConfigsList[OldChosenConfig]); } FillInputs(FALSE); NeedSave = FALSE;