From 8dbd938bf3a9de05926b4cefe20cde1dd6332641 Mon Sep 17 00:00:00 2001 From: Sergey Isakov Date: Thu, 27 Feb 2020 08:20:15 +0300 Subject: [PATCH 01/10] replace std::vector with XArray Signed-off-by: Sergey Isakov --- rEFIt_UEFI/libeg/lodepng.cpp | 47 +++++++++++++------------ rEFIt_UEFI/libeg/lodepng.h | 67 +++++++++++++++++++----------------- 2 files changed, 60 insertions(+), 54 deletions(-) diff --git a/rEFIt_UEFI/libeg/lodepng.cpp b/rEFIt_UEFI/libeg/lodepng.cpp index 9b6d1711f..461e66cdf 100644 --- a/rEFIt_UEFI/libeg/lodepng.cpp +++ b/rEFIt_UEFI/libeg/lodepng.cpp @@ -248,6 +248,9 @@ About uivector, ucvector and string: -They're not used in the interface, only internally in this file as static functions. -As with many other structs in this file, the init and cleanup functions serve as ctor and dtor. */ +/* + Replaced std::vector by XArray + */ #ifdef LODEPNG_COMPILE_ZLIB /*dynamic vector of unsigned ints*/ @@ -6086,7 +6089,7 @@ namespace lodepng { #ifdef LODEPNG_COMPILE_DISK -unsigned load_file(std::vector& buffer, const std::string& filename) +unsigned load_file(XArray& buffer, const std::string& filename) { long size = lodepng_filesize(filename.c_str()); if(size < 0) return 78; @@ -6095,7 +6098,7 @@ unsigned load_file(std::vector& buffer, const std::string& filena } /*write given buffer to the file, overwriting the file, it doesn't append to it.*/ -unsigned save_file(const std::vector& buffer, const std::string& filename) +unsigned save_file(const XArray& buffer, const std::string& filename) { return lodepng_save_file(buffer.empty() ? 0 : &buffer[0], buffer.size(), filename.c_str()); } @@ -6103,7 +6106,7 @@ unsigned save_file(const std::vector& buffer, const std::string& #ifdef LODEPNG_COMPILE_ZLIB #ifdef LODEPNG_COMPILE_DECODER -unsigned decompress(std::vector& out, const unsigned char* in, size_t insize, +unsigned decompress(XArray& out, const unsigned char* in, size_t insize, const LodePNGDecompressSettings& settings) { unsigned char* buffer = 0; @@ -6117,7 +6120,7 @@ unsigned decompress(std::vector& out, const unsigned char* in, si return error; } -unsigned decompress(std::vector& out, const std::vector& in, +unsigned decompress(XArray& out, const XArray& in, const LodePNGDecompressSettings& settings) { return decompress(out, in.empty() ? 0 : &in[0], in.size(), settings); @@ -6125,7 +6128,7 @@ unsigned decompress(std::vector& out, const std::vector& out, const unsigned char* in, size_t insize, +unsigned compress(XArray& out, const unsigned char* in, size_t insize, const LodePNGCompressSettings& settings) { unsigned char* buffer = 0; @@ -6139,7 +6142,7 @@ unsigned compress(std::vector& out, const unsigned char* in, size return error; } -unsigned compress(std::vector& out, const std::vector& in, +unsigned compress(XArray& out, const XArray& in, const LodePNGCompressSettings& settings) { return compress(out, in.empty() ? 0 : &in[0], in.size(), settings); @@ -6174,7 +6177,7 @@ State& State::operator=(const State& other) #ifdef LODEPNG_COMPILE_DECODER -unsigned decode(std::vector& out, unsigned& w, unsigned& h, const unsigned char* in, +unsigned decode(XArray& out, unsigned& w, unsigned& h, const unsigned char* in, size_t insize, LodePNGColorType colortype, unsigned bitdepth) { unsigned char* buffer; @@ -6191,13 +6194,13 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h, const return error; } -unsigned decode(std::vector& out, unsigned& w, unsigned& h, - const std::vector& in, LodePNGColorType colortype, unsigned bitdepth) +unsigned decode(XArray& out, unsigned& w, unsigned& h, + const XArray& in, LodePNGColorType colortype, unsigned bitdepth) { return decode(out, w, h, in.empty() ? 0 : &in[0], (unsigned)in.size(), colortype, bitdepth); } -unsigned decode(std::vector& out, unsigned& w, unsigned& h, +unsigned decode(XArray& out, unsigned& w, unsigned& h, State& state, const unsigned char* in, size_t insize) { @@ -6212,18 +6215,18 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h, return error; } -unsigned decode(std::vector& out, unsigned& w, unsigned& h, +unsigned decode(XArray& out, unsigned& w, unsigned& h, State& state, - const std::vector& in) + const XArray& in) { return decode(out, w, h, state, in.empty() ? 0 : &in[0], in.size()); } #ifdef LODEPNG_COMPILE_DISK -unsigned decode(std::vector& out, unsigned& w, unsigned& h, const std::string& filename, +unsigned decode(XArray& out, unsigned& w, unsigned& h, const std::string& filename, LodePNGColorType colortype, unsigned bitdepth) { - std::vector buffer; + XArray buffer; unsigned error = load_file(buffer, filename); if(error) return error; return decode(out, w, h, buffer, colortype, bitdepth); @@ -6232,7 +6235,7 @@ unsigned decode(std::vector& out, unsigned& w, unsigned& h, const #endif /* LODEPNG_COMPILE_DISK */ #ifdef LODEPNG_COMPILE_ENCODER -unsigned encode(std::vector& out, const unsigned char* in, unsigned w, unsigned h, +unsigned encode(XArray& out, const unsigned char* in, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { unsigned char* buffer; @@ -6246,15 +6249,15 @@ unsigned encode(std::vector& out, const unsigned char* in, unsign return error; } -unsigned encode(std::vector& out, - const std::vector& in, unsigned w, unsigned h, +unsigned encode(XArray& out, + const XArray& in, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { if(lodepng_get_raw_size_lct(w, h, colortype, bitdepth) > in.size()) return 84; return encode(out, in.empty() ? 0 : &in[0], w, h, colortype, bitdepth); } -unsigned encode(std::vector& out, +unsigned encode(XArray& out, const unsigned char* in, unsigned w, unsigned h, State& state) { @@ -6269,8 +6272,8 @@ unsigned encode(std::vector& out, return error; } -unsigned encode(std::vector& out, - const std::vector& in, unsigned w, unsigned h, +unsigned encode(XArray& out, + const XArray& in, unsigned w, unsigned h, State& state) { if(lodepng_get_raw_size(w, h, &state.info_raw) > in.size()) return 84; @@ -6282,14 +6285,14 @@ unsigned encode(const std::string& filename, const unsigned char* in, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { - std::vector buffer; + XArray buffer; unsigned error = encode(buffer, in, w, h, colortype, bitdepth); if(!error) error = save_file(buffer, filename); return error; } unsigned encode(const std::string& filename, - const std::vector& in, unsigned w, unsigned h, + const XArray& in, unsigned w, unsigned h, LodePNGColorType colortype, unsigned bitdepth) { if(lodepng_get_raw_size_lct(w, h, colortype, bitdepth) > in.size()) return 84; diff --git a/rEFIt_UEFI/libeg/lodepng.h b/rEFIt_UEFI/libeg/lodepng.h index a7095b4cb..e55a61c7c 100644 --- a/rEFIt_UEFI/libeg/lodepng.h +++ b/rEFIt_UEFI/libeg/lodepng.h @@ -29,6 +29,9 @@ freely, subject to the following restrictions: //MODSNI v #include +#include "../cpp_foundation/XToolsCommon.h" +#include "../cpp_foundation/XArray.h" + //#define LODEPNG_NO_COMPILE_DECODER #define LODEPNG_NO_COMPILE_DISK @@ -224,33 +227,33 @@ unsigned lodepng_encode24_file(const char* filename, namespace lodepng { #ifdef LODEPNG_COMPILE_DECODER -/*Same as lodepng_decode_memory, but decodes to an std::vector. The colortype +/*Same as lodepng_decode_memory, but decodes to an XArray. The colortype is the format to output the pixels to. Default is RGBA 8-bit per channel.*/ -unsigned decode(std::vector& out, unsigned& w, unsigned& h, +unsigned decode(XArray& out, unsigned& w, unsigned& h, const unsigned char* in, size_t insize, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); -unsigned decode(std::vector& out, unsigned& w, unsigned& h, - const std::vector& in, +unsigned decode(XArray& out, unsigned& w, unsigned& h, + const XArray& in, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); #ifdef LODEPNG_COMPILE_DISK /* Converts PNG file from disk to raw pixel data in memory. Same as the other decode functions, but instead takes a filename as input. */ -unsigned decode(std::vector& out, unsigned& w, unsigned& h, +unsigned decode(XArray& out, unsigned& w, unsigned& h, const std::string& filename, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); #endif /* LODEPNG_COMPILE_DISK */ #endif /* LODEPNG_COMPILE_DECODER */ #ifdef LODEPNG_COMPILE_ENCODER -/*Same as lodepng_encode_memory, but encodes to an std::vector. colortype +/*Same as lodepng_encode_memory, but encodes to an XArray. colortype is that of the raw input data. The output PNG color type will be auto chosen.*/ -unsigned encode(std::vector& out, +unsigned encode(XArray& out, const unsigned char* in, unsigned w, unsigned h, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); -unsigned encode(std::vector& out, - const std::vector& in, unsigned w, unsigned h, +unsigned encode(XArray& out, + const XArray& in, unsigned w, unsigned h, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); #ifdef LODEPNG_COMPILE_DISK /* @@ -262,7 +265,7 @@ unsigned encode(const std::string& filename, const unsigned char* in, unsigned w, unsigned h, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); unsigned encode(const std::string& filename, - const std::vector& in, unsigned w, unsigned h, + const XArray& in, unsigned w, unsigned h, LodePNGColorType colortype = LCT_RGBA, unsigned bitdepth = 8); #endif /* LODEPNG_COMPILE_DISK */ #endif /* LODEPNG_COMPILE_ENCODER */ @@ -838,7 +841,7 @@ unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const #endif /*LODEPNG_COMPILE_DISK*/ #ifdef LODEPNG_COMPILE_CPP -/* The LodePNG C++ wrapper uses std::vectors instead of manually allocated memory buffers. */ +/* The LodePNG C++ wrapper uses XArrays instead of manually allocated memory buffers. */ namespace lodepng { #ifdef LODEPNG_COMPILE_PNG @@ -853,57 +856,57 @@ class State : public LodePNGState #ifdef LODEPNG_COMPILE_DECODER /* Same as other lodepng::decode, but using a State for more settings and information. */ -unsigned decode(std::vector& out, unsigned& w, unsigned& h, +unsigned decode(XArray& out, unsigned& w, unsigned& h, State& state, const unsigned char* in, size_t insize); -unsigned decode(std::vector& out, unsigned& w, unsigned& h, +unsigned decode(XArray& out, unsigned& w, unsigned& h, State& state, - const std::vector& in); + const XArray& in); #endif /*LODEPNG_COMPILE_DECODER*/ #ifdef LODEPNG_COMPILE_ENCODER /* Same as other lodepng::encode, but using a State for more settings and information. */ -unsigned encode(std::vector& out, +unsigned encode(XArray& out, const unsigned char* in, unsigned w, unsigned h, State& state); -unsigned encode(std::vector& out, - const std::vector& in, unsigned w, unsigned h, +unsigned encode(XArray& out, + const XArray& in, unsigned w, unsigned h, State& state); #endif /*LODEPNG_COMPILE_ENCODER*/ #ifdef LODEPNG_COMPILE_DISK /* -Load a file from disk into an std::vector. +Load a file from disk into an XArray. return value: error code (0 means ok) */ -unsigned load_file(std::vector& buffer, const std::string& filename); +unsigned load_file(XArray& buffer, const std::string& filename); /* -Save the binary data in an std::vector to a file on disk. The file is overwritten +Save the binary data in an XArray to a file on disk. The file is overwritten without warning. */ -unsigned save_file(const std::vector& buffer, const std::string& filename); +unsigned save_file(const XArray& buffer, const std::string& filename); #endif /* LODEPNG_COMPILE_DISK */ #endif /* LODEPNG_COMPILE_PNG */ #ifdef LODEPNG_COMPILE_ZLIB #ifdef LODEPNG_COMPILE_DECODER /* Zlib-decompress an unsigned char buffer */ -unsigned decompress(std::vector& out, const unsigned char* in, size_t insize, +unsigned decompress(XArray& out, const unsigned char* in, size_t insize, const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings); -/* Zlib-decompress an std::vector */ -unsigned decompress(std::vector& out, const std::vector& in, +/* Zlib-decompress an XArray */ +unsigned decompress(XArray& out, const XArray& in, const LodePNGDecompressSettings& settings = lodepng_default_decompress_settings); #endif /* LODEPNG_COMPILE_DECODER */ #ifdef LODEPNG_COMPILE_ENCODER /* Zlib-compress an unsigned char buffer */ -unsigned compress(std::vector& out, const unsigned char* in, size_t insize, +unsigned compress(XArray& out, const unsigned char* in, size_t insize, const LodePNGCompressSettings& settings = lodepng_default_compress_settings); -/* Zlib-compress an std::vector */ -unsigned compress(std::vector& out, const std::vector& in, +/* Zlib-compress an XArray */ +unsigned compress(XArray& out, const XArray& in, const LodePNGCompressSettings& settings = lodepng_default_compress_settings); #endif /* LODEPNG_COMPILE_ENCODER */ #endif /* LODEPNG_COMPILE_ZLIB */ @@ -1058,7 +1061,7 @@ The C version uses buffers allocated with alloc that you need to free() yourself. You need to use init and cleanup functions for each struct whenever using a struct from the C version to avoid exploits and memory leaks. -The C++ version has extra functions with std::vectors in the interface and the +The C++ version has extra functions with XArrays in the interface and the lodepng::State class which is a LodePNGState with constructor and destructor. These files work without modification for both C and C++ compilers because all @@ -1492,7 +1495,7 @@ encoder and decoder, this makes a large difference. Make sure that LodePNG is compiled with the same compiler of the same version and with the same settings as the rest of the program, or the interfaces with -std::vectors and std::strings in C++ can be incompatible. +XArrays and std::strings in C++ can be incompatible. CHAR_BITS must be 8 or higher, because LodePNG uses unsigned chars for octets. @@ -1555,7 +1558,7 @@ int main(int argc, char *argv[]) const char* filename = argc > 1 ? argv[1] : "test.png"; //load and decode - std::vector image; + XArray image; unsigned width, height; unsigned error = lodepng::decode(image, width, height, filename); @@ -1672,7 +1675,7 @@ symbol. *) 21 jul 2007: deflate code placed in new namespace separate from zlib code *) 08 jun 2007: fixed bug with 2- and 4-bit color, and small interlaced images *) 04 jun 2007: improved support for Visual Studio 2005: crash with accessing - invalid std::vector element [0] fixed, and level 3 and 4 warnings removed + invalid XArray element [0] fixed, and level 3 and 4 warnings removed *) 02 jun 2007: made the encoder add a tag with version by default *) 27 may 2007: zlib and png code separated (but still in the same file), simple encoder/decoder functions added for more simple usage cases @@ -1726,7 +1729,7 @@ symbol. in LodePNG namespace. Changed the order of the parameters. Rewrote the documentation in the header. Renamed files to lodepng.cpp and lodepng.h *) 22 apr 2006: Optimized and improved some code -*) 07 sep 2005: (!) Changed to std::vector interface +*) 07 sep 2005: (!) Changed to XArray interface *) 12 aug 2005: Initial release (C++, decoder only) From d1043e2673385835a56321595c890976637d4a8f Mon Sep 17 00:00:00 2001 From: Sergey Isakov Date: Thu, 27 Feb 2020 12:17:50 +0300 Subject: [PATCH 02/10] modify XArray and lodepng to compile as cpp Signed-off-by: Sergey Isakov --- rEFIt_UEFI/cpp_foundation/XArray.h | 23 +++++++++++++++++++++-- rEFIt_UEFI/libeg/XImage.cpp | 10 +++++----- rEFIt_UEFI/libeg/lodepng.cpp | 18 ++++++++++++------ 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/rEFIt_UEFI/cpp_foundation/XArray.h b/rEFIt_UEFI/cpp_foundation/XArray.h index 92442121b..152f88fea 100755 --- a/rEFIt_UEFI/cpp_foundation/XArray.h +++ b/rEFIt_UEFI/cpp_foundation/XArray.h @@ -52,13 +52,26 @@ class XArray xsize Length() const { return m_len; } void SetLength(xsize l); + //low case functions like in std::vector + xsize size() const { return m_len; } + const TYPE& begin() const { return ElementAt(0); } + TYPE& begin() { return ElementAt(0); } + + const TYPE& end() const { return ElementAt(m_len - 1); } + TYPE& end() { return ElementAt(m_len - 1); } + + xsize insert(const TYPE newElement, xsize pos, xsize count = 1) { return Insert(newElement, pos, count); } + const bool empty() const; + +//-------------------------------------------------- + const TYPE& ElementAt(xsize nIndex) const; TYPE& ElementAt(xsize nIndex); const TYPE& operator[](xsize nIndex) const { return ElementAt(nIndex); } TYPE& operator[](xsize nIndex) { return ElementAt(nIndex); } - const TYPE& operator[]( int nIndex) const { return ElementAt(nIndex); } - TYPE& operator[]( int nIndex) { return ElementAt(nIndex); } + const TYPE& operator[]( int nIndex) const { return ElementAt(nIndex); } + TYPE& operator[]( int nIndex) { return ElementAt(nIndex); } operator const void *() const { return m_data; }; operator void *() { return m_data; }; @@ -333,4 +346,10 @@ void XArray::Empty() m_len = 0; } +template +const bool XArray::empty() const +{ + //printf("XArray Empty\n"); + return m_len == 0; +} #endif diff --git a/rEFIt_UEFI/libeg/XImage.cpp b/rEFIt_UEFI/libeg/XImage.cpp index 72a06fdfb..53939c8ca 100644 --- a/rEFIt_UEFI/libeg/XImage.cpp +++ b/rEFIt_UEFI/libeg/XImage.cpp @@ -260,7 +260,7 @@ void XImage::GetArea(UINTN x, UINTN y, UINTN W, UINTN H) UINT32 ScreenHeight = 0; UINT32 Depth = 0; UINT32 RefreshRate = 60; - EFI_STATUS Status = UgaDraw->GetMode(UgaDraw, &LineWidth, &ScreenHeight, &Depth, &RefreshRate); + Status = UgaDraw->GetMode(UgaDraw, &LineWidth, &ScreenHeight, &Depth, &RefreshRate); if (EFI_ERROR(Status)) { return; // graphics not available } @@ -277,10 +277,10 @@ void XImage::GetArea(UINTN x, UINTN y, UINTN W, UINTN H) void XImage::Draw(int x, int y, float scale) { //prepare images - INTN UGAWidth = 0; - INTN UGAHeight = 0; - egGetScreenSize(&UGAWidth, &UGAHeight); - XImage Background(UGAWidth, UGAHeight); + INTN ScreenWidth = 0; + INTN ScreenHeight = 0; + egGetScreenSize(&ScreenWidth, &ScreenHeight); + XImage Background(ScreenWidth, ScreenHeight); Background.GetArea(x, y, Width, Height); XImage Top(*this, scale); Background.Compose(x, y, Top, true); diff --git a/rEFIt_UEFI/libeg/lodepng.cpp b/rEFIt_UEFI/libeg/lodepng.cpp index 461e66cdf..b5fce5b22 100644 --- a/rEFIt_UEFI/libeg/lodepng.cpp +++ b/rEFIt_UEFI/libeg/lodepng.cpp @@ -6114,7 +6114,8 @@ unsigned decompress(XArray& out, const unsigned char* in, size_t unsigned error = zlib_decompress(&buffer, &buffersize, in, insize, &settings); if(buffer) { - out.insert(out.end(), &buffer[0], &buffer[buffersize]); +// out.insert(out.end(), &buffer[0], &buffer[buffersize]); + out.AddArray(buffer, buffersize); lodepng_free(buffer); } return error; @@ -6136,7 +6137,8 @@ unsigned compress(XArray& out, const unsigned char* in, size_t in unsigned error = zlib_compress(&buffer, &buffersize, in, insize, &settings); if(buffer) { - out.insert(out.end(), &buffer[0], &buffer[buffersize]); +// out.insert(out.end(), &buffer[0], &buffer[buffersize]); + out.AddArray(buffer, buffersize); lodepng_free(buffer); } return error; @@ -6188,7 +6190,8 @@ unsigned decode(XArray& out, unsigned& w, unsigned& h, const unsi state.info_raw.colortype = colortype; state.info_raw.bitdepth = bitdepth; size_t buffersize = lodepng_get_raw_size(w, h, &state.info_raw); - out.insert(out.end(), &buffer[0], &buffer[buffersize]); +// out.insert(out.end(), &buffer[0], &buffer[buffersize]); + out.AddArray(buffer, buffersize); lodepng_free(buffer); } return error; @@ -6209,7 +6212,8 @@ unsigned decode(XArray& out, unsigned& w, unsigned& h, if(buffer && !error) { size_t buffersize = lodepng_get_raw_size(w, h, &state.info_raw); - out.insert(out.end(), &buffer[0], &buffer[buffersize]); +// out.insert(out.end(), &buffer[0], &buffer[buffersize]); + out.AddArray(buffer, buffersize); } lodepng_free(buffer); return error; @@ -6243,7 +6247,8 @@ unsigned encode(XArray& out, const unsigned char* in, unsigned w, unsigned error = lodepng_encode_memory(&buffer, &buffersize, in, w, h, colortype, bitdepth); if(buffer) { - out.insert(out.end(), &buffer[0], &buffer[buffersize]); +// out.insert(out.end(), &buffer[0], &buffer[buffersize]); + out.AddArray(buffer, buffersize); lodepng_free(buffer); } return error; @@ -6266,7 +6271,8 @@ unsigned encode(XArray& out, unsigned error = lodepng_encode(&buffer, &buffersize, in, w, h, &state); if(buffer) { - out.insert(out.end(), &buffer[0], &buffer[buffersize]); + // out.insert(out.end(), &buffer[0], &buffer[buffersize]); + out.AddArray(buffer, buffersize); lodepng_free(buffer); } return error; From 4be169f058d717a60593aab5f2ed4252d262720f Mon Sep 17 00:00:00 2001 From: Sergey Isakov Date: Thu, 27 Feb 2020 12:49:02 +0300 Subject: [PATCH 03/10] full lodecpp features Signed-off-by: Sergey Isakov --- rEFIt_UEFI/libeg/lodepng.cpp | 2 +- rEFIt_UEFI/libeg/lodepng.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rEFIt_UEFI/libeg/lodepng.cpp b/rEFIt_UEFI/libeg/lodepng.cpp index b5fce5b22..75e4e60bd 100644 --- a/rEFIt_UEFI/libeg/lodepng.cpp +++ b/rEFIt_UEFI/libeg/lodepng.cpp @@ -5858,7 +5858,7 @@ unsigned lodepng_encode(unsigned char** out, size_t* outsize, unsigned alread_added_id_text = 0; for(i = 0; i != info.text_num; ++i) { - if(!strcmp(info.text_keys[i], "LodePNG")) + if(!AsciiStrCmp(info.text_keys[i], "LodePNG")) { alread_added_id_text = 1; break; diff --git a/rEFIt_UEFI/libeg/lodepng.h b/rEFIt_UEFI/libeg/lodepng.h index e55a61c7c..1df62968c 100644 --- a/rEFIt_UEFI/libeg/lodepng.h +++ b/rEFIt_UEFI/libeg/lodepng.h @@ -37,8 +37,8 @@ freely, subject to the following restrictions: #define LODEPNG_NO_COMPILE_DISK //#define LODEPNG_NO_COMPILE_ALLOCATORS //#define LODEPNG_NO_COMPILE_ERROR_TEXT -#define LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS -#define LODEPNG_NO_COMPILE_CPP +//#define LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS +//#define LODEPNG_NO_COMPILE_CPP // Microsoft compiler has built-in size_t //#if !defined(_MSC_VER) From 5fc9b805af5a9c03c36c17ae1c614bbc4bdb5b3a Mon Sep 17 00:00:00 2001 From: jief Date: Thu, 27 Feb 2020 14:48:47 +0300 Subject: [PATCH 04/10] empty cannot be define for a const object, because empty modifed itself. --- rEFIt_UEFI/cpp_foundation/XArray.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/rEFIt_UEFI/cpp_foundation/XArray.h b/rEFIt_UEFI/cpp_foundation/XArray.h index 152f88fea..bda46d1eb 100755 --- a/rEFIt_UEFI/cpp_foundation/XArray.h +++ b/rEFIt_UEFI/cpp_foundation/XArray.h @@ -346,10 +346,4 @@ void XArray::Empty() m_len = 0; } -template -const bool XArray::empty() const -{ - //printf("XArray Empty\n"); - return m_len == 0; -} #endif From 08fbee9846fb8b4c2633ee5b4febc6855e842f38 Mon Sep 17 00:00:00 2001 From: jief Date: Thu, 27 Feb 2020 14:50:29 +0300 Subject: [PATCH 05/10] Avoid using explicit type. --- rEFIt_UEFI/Platform/Settings.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rEFIt_UEFI/Platform/Settings.cpp b/rEFIt_UEFI/Platform/Settings.cpp index 3f0a67614..d26c69fd1 100644 --- a/rEFIt_UEFI/Platform/Settings.cpp +++ b/rEFIt_UEFI/Platform/Settings.cpp @@ -5074,7 +5074,8 @@ GetUserSettings( for (j = 0; j < PropCount; j++) { Prop3 = NULL; DevProps = *Child; - *Child = (__typeof_am__(*Child))AllocateZeroPool(sizeof(DEV_PROPERTY)); +// *Child = (__typeof_am__(*Child))AllocateZeroPool(sizeof(**Child)); + *Child = new (__typeof_am__(**Child)); (*Child)->Next = DevProps; if (EFI_ERROR(GetElement(Prop2, j, &Prop3))) { // Prop3 -> From cf70d0a26733a5c1a6b4962653e06fa17fd01678 Mon Sep 17 00:00:00 2001 From: Sergey Isakov Date: Thu, 27 Feb 2020 15:06:01 +0300 Subject: [PATCH 06/10] cant use enum in packed structure Signed-off-by: Sergey Isakov --- MdePkg/Include/IndustryStandard/SmBios.h | 2 +- rEFIt_UEFI/Platform/smbios.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/MdePkg/Include/IndustryStandard/SmBios.h b/MdePkg/Include/IndustryStandard/SmBios.h index b472232c3..f3b6f1870 100644 --- a/MdePkg/Include/IndustryStandard/SmBios.h +++ b/MdePkg/Include/IndustryStandard/SmBios.h @@ -1765,7 +1765,7 @@ typedef struct { UINT16 TotalWidth; UINT16 DataWidth; UINT16 Size; - MEMORY_FORM_FACTOR FormFactor; ///< The enumeration value from MEMORY_FORM_FACTOR. + UINT8 FormFactor; ///< The enumeration value from MEMORY_FORM_FACTOR. UINT8 DeviceSet; SMBIOS_TABLE_STRING DeviceLocator; SMBIOS_TABLE_STRING BankLocator; diff --git a/rEFIt_UEFI/Platform/smbios.cpp b/rEFIt_UEFI/Platform/smbios.cpp index a6fcc6958..232314f5d 100644 --- a/rEFIt_UEFI/Platform/smbios.cpp +++ b/rEFIt_UEFI/Platform/smbios.cpp @@ -1326,14 +1326,14 @@ VOID PatchTableType17() // Inject tables for (Index = 0; Index < gRAM.UserInUse; Index++) { UINTN UserIndex = channelMap[Index]; - UINT8 bank = (UINT8)Index / gRAM.UserChannels; + UINT8 bank = (UINT8)(Index / gRAM.UserChannels); ZeroMem((VOID*)newSmbiosTable.Type17, MAX_TABLE_SIZE); newSmbiosTable.Type17->Hdr.Type = EFI_SMBIOS_TYPE_MEMORY_DEVICE; newSmbiosTable.Type17->Hdr.Length = sizeof(SMBIOS_TABLE_TYPE17); newSmbiosTable.Type17->TotalWidth = 0xFFFF; newSmbiosTable.Type17->DataWidth = 0xFFFF; newSmbiosTable.Type17->Hdr.Handle = (UINT16)(0x1100 + UserIndex); - newSmbiosTable.Type17->FormFactor = gMobile ? MemoryFormFactorSodimm : MemoryFormFactorDimm; + newSmbiosTable.Type17->FormFactor = (UINT8)(gMobile ? MemoryFormFactorSodimm : MemoryFormFactorDimm); newSmbiosTable.Type17->TypeDetail.Synchronous = TRUE; newSmbiosTable.Type17->DeviceSet = bank + 1; newSmbiosTable.Type17->MemoryArrayHandle = mHandle16; @@ -1347,7 +1347,7 @@ VOID PatchTableType17() UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type17->DeviceLocator, (CHAR8*)&deviceLocator[0]); if ((gRAM.User[UserIndex].InUse) && (gRAM.User[UserIndex].ModuleSize > 0)) { if (iStrLen(gRAM.User[UserIndex].Vendor, 64) > 0) { - CHAR8* vendor = (CHAR8*)AllocatePool(AsciiStrLen(gRAM.User[UserIndex].Vendor)+1); // this will never be freed. WIll be solved when using a string object. + CHAR8* vendor = (CHAR8*)AllocatePool(AsciiStrLen(gRAM.User[UserIndex].Vendor)+1); // this will never be freed. Will be solved when using a string object. AsciiStrCpy(vendor, gRAM.User[UserIndex].Vendor); UpdateSmbiosString(newSmbiosTable, &newSmbiosTable.Type17->Manufacturer, vendor); gRAM.User[UserIndex].Vendor = vendor; @@ -1617,7 +1617,7 @@ VOID PatchTableType17() } Once = TRUE; newSmbiosTable.Type17->Hdr.Handle = (UINT16)(0x1100 + Index); - newSmbiosTable.Type17->FormFactor = gMobile ? MemoryFormFactorSodimm : MemoryFormFactorDimm; + newSmbiosTable.Type17->FormFactor = (UINT8)(gMobile ? MemoryFormFactorSodimm : MemoryFormFactorDimm); newSmbiosTable.Type17->TypeDetail.Synchronous = TRUE; newSmbiosTable.Type17->DeviceSet = bank + 1; newSmbiosTable.Type17->MemoryArrayHandle = mHandle16; From 6c6fe9084226c160cef04ecc3b94c5e828ef1d6c Mon Sep 17 00:00:00 2001 From: Sergey Isakov Date: Thu, 27 Feb 2020 15:32:14 +0300 Subject: [PATCH 07/10] use isEmpty and setEmpty Signed-off-by: Sergey Isakov --- rEFIt_UEFI/cpp_foundation/XArray.h | 5 +++-- rEFIt_UEFI/libeg/lodepng.cpp | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/rEFIt_UEFI/cpp_foundation/XArray.h b/rEFIt_UEFI/cpp_foundation/XArray.h index bda46d1eb..354664d08 100755 --- a/rEFIt_UEFI/cpp_foundation/XArray.h +++ b/rEFIt_UEFI/cpp_foundation/XArray.h @@ -104,7 +104,8 @@ class XArray void RemoveAtIndex(xsize nIndex); void RemoveAtIndex(int nIndex); - void Empty(); + void setEmpty(); + const bool isEmpty() const { return size() == 0; } xsize IdxOf(TYPE& e) const; bool ExistIn(TYPE& e) const { return IdxOf(e) != MAX_XSIZE; } @@ -340,7 +341,7 @@ void XArray::Remove(const TYPE *Element) /* Empty() */ template -void XArray::Empty() +void XArray::setEmpty() { //printf("XArray Empty\n"); m_len = 0; diff --git a/rEFIt_UEFI/libeg/lodepng.cpp b/rEFIt_UEFI/libeg/lodepng.cpp index 75e4e60bd..6d012933a 100644 --- a/rEFIt_UEFI/libeg/lodepng.cpp +++ b/rEFIt_UEFI/libeg/lodepng.cpp @@ -6100,7 +6100,7 @@ unsigned load_file(XArray& buffer, const std::string& filename) /*write given buffer to the file, overwriting the file, it doesn't append to it.*/ unsigned save_file(const XArray& buffer, const std::string& filename) { - return lodepng_save_file(buffer.empty() ? 0 : &buffer[0], buffer.size(), filename.c_str()); + return lodepng_save_file(buffer.isEmpty() ? 0 : &buffer[0], buffer.size(), filename.c_str()); } #endif /* LODEPNG_COMPILE_DISK */ @@ -6124,7 +6124,7 @@ unsigned decompress(XArray& out, const unsigned char* in, size_t unsigned decompress(XArray& out, const XArray& in, const LodePNGDecompressSettings& settings) { - return decompress(out, in.empty() ? 0 : &in[0], in.size(), settings); + return decompress(out, in.isEmpty() ? 0 : &in[0], in.size(), settings); } #endif /* LODEPNG_COMPILE_DECODER */ @@ -6147,7 +6147,7 @@ unsigned compress(XArray& out, const unsigned char* in, size_t in unsigned compress(XArray& out, const XArray& in, const LodePNGCompressSettings& settings) { - return compress(out, in.empty() ? 0 : &in[0], in.size(), settings); + return compress(out, in.isEmpty() ? 0 : &in[0], in.size(), settings); } #endif /* LODEPNG_COMPILE_ENCODER */ #endif /* LODEPNG_COMPILE_ZLIB */ @@ -6200,7 +6200,7 @@ unsigned decode(XArray& out, unsigned& w, unsigned& h, const unsi unsigned decode(XArray& out, unsigned& w, unsigned& h, const XArray& in, LodePNGColorType colortype, unsigned bitdepth) { - return decode(out, w, h, in.empty() ? 0 : &in[0], (unsigned)in.size(), colortype, bitdepth); + return decode(out, w, h, in.isEmpty() ? 0 : &in[0], (unsigned)in.size(), colortype, bitdepth); } unsigned decode(XArray& out, unsigned& w, unsigned& h, @@ -6223,7 +6223,7 @@ unsigned decode(XArray& out, unsigned& w, unsigned& h, State& state, const XArray& in) { - return decode(out, w, h, state, in.empty() ? 0 : &in[0], in.size()); + return decode(out, w, h, state, in.isEmpty() ? 0 : &in[0], in.size()); } #ifdef LODEPNG_COMPILE_DISK @@ -6259,7 +6259,7 @@ unsigned encode(XArray& out, LodePNGColorType colortype, unsigned bitdepth) { if(lodepng_get_raw_size_lct(w, h, colortype, bitdepth) > in.size()) return 84; - return encode(out, in.empty() ? 0 : &in[0], w, h, colortype, bitdepth); + return encode(out, in.isEmpty() ? 0 : &in[0], w, h, colortype, bitdepth); } unsigned encode(XArray& out, @@ -6283,7 +6283,7 @@ unsigned encode(XArray& out, State& state) { if(lodepng_get_raw_size(w, h, &state.info_raw) > in.size()) return 84; - return encode(out, in.empty() ? 0 : &in[0], w, h, state); + return encode(out, in.isEmpty() ? 0 : &in[0], w, h, state); } #ifdef LODEPNG_COMPILE_DISK @@ -6302,7 +6302,7 @@ unsigned encode(const std::string& filename, LodePNGColorType colortype, unsigned bitdepth) { if(lodepng_get_raw_size_lct(w, h, colortype, bitdepth) > in.size()) return 84; - return encode(filename, in.empty() ? 0 : &in[0], w, h, colortype, bitdepth); + return encode(filename, in.isEmpty() ? 0 : &in[0], w, h, colortype, bitdepth); } #endif /* LODEPNG_COMPILE_DISK */ #endif /* LODEPNG_COMPILE_ENCODER */ From 5c73df9febe63d99cd7b595a4681f86f662b2f4f Mon Sep 17 00:00:00 2001 From: Sergey Isakov Date: Thu, 27 Feb 2020 16:11:03 +0300 Subject: [PATCH 08/10] use setEmpty in XArray Signed-off-by: Sergey Isakov --- rEFIt_UEFI/cpp_foundation/XArray.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rEFIt_UEFI/cpp_foundation/XArray.h b/rEFIt_UEFI/cpp_foundation/XArray.h index 354664d08..117e644fe 100755 --- a/rEFIt_UEFI/cpp_foundation/XArray.h +++ b/rEFIt_UEFI/cpp_foundation/XArray.h @@ -61,8 +61,7 @@ class XArray TYPE& end() { return ElementAt(m_len - 1); } xsize insert(const TYPE newElement, xsize pos, xsize count = 1) { return Insert(newElement, pos, count); } - const bool empty() const; - + //-------------------------------------------------- const TYPE& ElementAt(xsize nIndex) const; @@ -152,7 +151,7 @@ const XArray &XArray::operator =(const XArray &anArray) { xsize ui; - Empty(); + setEmpty(); for ( ui=0 ; ui Date: Thu, 27 Feb 2020 17:02:43 +0300 Subject: [PATCH 09/10] implement smooth image scaling Signed-off-by: Sergey Isakov --- rEFIt_UEFI/libeg/XImage.cpp | 44 +++++++++++++++++++++++++++++++------ rEFIt_UEFI/refit.inf | 4 ++-- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/rEFIt_UEFI/libeg/XImage.cpp b/rEFIt_UEFI/libeg/XImage.cpp index 53939c8ca..209a2d19f 100644 --- a/rEFIt_UEFI/libeg/XImage.cpp +++ b/rEFIt_UEFI/libeg/XImage.cpp @@ -13,19 +13,49 @@ XImage::XImage(UINTN W, UINTN H) Height = H; PixelData.CheckSize(GetWidth()*GetHeight()); } -#if 0 -UINT8 Smooth(UINT8* P, int a01, int a10, int a11, int a21, int a12, int dx, int dy, float scale) +#if 1 +UINT8 Smooth(const UINT8* p, int a01, int a10, int a21, int a12, int dx, int dy, float scale) { - return (UINT8)((*(p + a01) * (scale - dx) * 3 + *(p + a10) * (scale - dy) * 3 + *(p + a21) * dx * 3 + - *(p + a12) * dy * 3 + *(p + a11) * 2 *scale) / (scale * 8)); + return (UINT8)((*(p + a01) * (scale - dx) * 3.f + *(p + a10) * (scale - dy) * 3.f + *(p + a21) * dx * 3.f + + *(p + a12) * dy * 3.f + *(p) * 2.f *scale) / (scale * 8.f)); } #endif XImage::XImage(const XImage& Image, float scale) { - Width = (UINTN)(Image.GetWidth() * scale); - Height = (UINTN)(Image.GetHeight() * scale); + int SrcWidth = Image.GetWidth(); + int SrcHeight = Image.GetHeight(); + Width = (UINTN)(SrcWidth * scale); + Height = (UINTN)(SrcHeight * scale); PixelData.CheckSize(GetWidth()*GetHeight()); + if (scale < 1.e-4) return; + + int Pixel = sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL); + int Row = SrcWidth * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL); + + const XArray& Source = Image.GetData(); + + for (size_t y = 0; y < Height; y++) + { + int ly = (int)(y / scale); + int dy = (int)(y - ly * scale); + for (size_t x = 0; x < Width; x++) + { + int lx = (int)(x / scale); + int dx = (int)(x - lx * scale); + int a01 = (x == 0) ? 0 : -Pixel; + int a10 = (y == 0) ? 0 : -Row; + int a21 = (x == Width - 1) ? 0 : Pixel; + int a12 = (y == Height - 1) ? 0 : Row; + EFI_GRAPHICS_OUTPUT_BLT_PIXEL& dst = *GetPixelPtr(x, y); + dst.Blue = Smooth(&Source[lx + ly * SrcWidth].Blue, a01, a10, a21, a12, dx, dy, scale); + dst.Green = Smooth(&Source[lx + ly * SrcWidth].Green, a01, a10, a21, a12, dx, dy, scale); + dst.Red = Smooth(&Source[lx + ly * SrcWidth].Red, a01, a10, a21, a12, dx, dy, scale); + } + + } +} + #if 0 UINTN Offset = OFFSET_OF(EFI_GRAPHICS_OUTPUT_BLT_PIXEL, Blue); @@ -86,7 +116,7 @@ do { \ } } #endif -} + XImage::~XImage() { diff --git a/rEFIt_UEFI/refit.inf b/rEFIt_UEFI/refit.inf index ff5beb9d3..00f31c56e 100644 --- a/rEFIt_UEFI/refit.inf +++ b/rEFIt_UEFI/refit.inf @@ -81,8 +81,8 @@ libeg/VectorGraphics.cpp libeg/libeg.h libeg/libegint.h - libeg/XImage.cpp - libeg/XImage.h +# libeg/XImage.cpp +# libeg/XImage.h Platform/AcpiPatcher.cpp Platform/ati_reg.h Platform/AmlGenerator.cpp From c77802d200617a23d5c207f9e3c432de2a767b76 Mon Sep 17 00:00:00 2001 From: jief Date: Thu, 27 Feb 2020 17:34:29 +0300 Subject: [PATCH 10/10] Refactor of "Volumes" global var as an XObjArray. --- rEFIt_UEFI/Platform/BdsConnect.cpp | 2 +- rEFIt_UEFI/Platform/Hibernate.cpp | 4 +- rEFIt_UEFI/Platform/LegacyBoot.cpp | 6 +- rEFIt_UEFI/Platform/Nvram.cpp | 12 +-- rEFIt_UEFI/Platform/Platform.h | 4 + rEFIt_UEFI/Platform/Settings.cpp | 2 +- rEFIt_UEFI/cpp_foundation/XArray.h | 6 +- rEFIt_UEFI/cpp_foundation/XObjArray.h | 19 ++--- rEFIt_UEFI/cpp_foundation/XStringWArray.cpp | 18 ++--- rEFIt_UEFI/cpp_foundation/XStringWArray.h | 4 +- rEFIt_UEFI/cpp_foundation/XToolsCommon.h | 17 +++- .../cpp_unit_test/XStringWArray_test.cpp | 8 +- rEFIt_UEFI/entry_scan/common.cpp | 16 ++-- rEFIt_UEFI/entry_scan/legacy.cpp | 20 ++--- rEFIt_UEFI/entry_scan/loader.cpp | 12 +-- rEFIt_UEFI/entry_scan/tool.cpp | 8 +- rEFIt_UEFI/refit/lib.cpp | 81 +++++++++---------- rEFIt_UEFI/refit/lib.h | 5 +- rEFIt_UEFI/refit/main.cpp | 8 +- rEFIt_UEFI/refit/menu.cpp | 4 +- 20 files changed, 138 insertions(+), 118 deletions(-) diff --git a/rEFIt_UEFI/Platform/BdsConnect.cpp b/rEFIt_UEFI/Platform/BdsConnect.cpp index 734ab0562..2fc50f2b0 100644 --- a/rEFIt_UEFI/Platform/BdsConnect.cpp +++ b/rEFIt_UEFI/Platform/BdsConnect.cpp @@ -311,7 +311,7 @@ EFI_STATUS ScanDeviceHandles(EFI_HANDLE ControllerHandle, Status = gBS->LocateHandleBuffer (AllHandles, NULL, NULL, HandleCount, HandleBuffer); if (EFI_ERROR (Status)) goto Error; - *HandleType = (__typeof_am__(*HandleType))AllocatePool (*HandleCount * sizeof (UINT32)); + *HandleType = (__typeof_am__(*HandleType))AllocatePool (*HandleCount * sizeof (**HandleType)); if (*HandleType == NULL) goto Error; for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) { diff --git a/rEFIt_UEFI/Platform/Hibernate.cpp b/rEFIt_UEFI/Platform/Hibernate.cpp index a7412463f..0788440a7 100644 --- a/rEFIt_UEFI/Platform/Hibernate.cpp +++ b/rEFIt_UEFI/Platform/Hibernate.cpp @@ -698,8 +698,8 @@ REFIT_VOLUME *FoundParentVolume(REFIT_VOLUME *Volume) return NULL; //don't search! } - for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) { - Volume1 = Volumes[VolumeIndex]; + for (VolumeIndex = 0; VolumeIndex < Volumes.size(); VolumeIndex++) { + Volume1 = &Volumes[VolumeIndex]; if (Volume1 != Volume && Volume1->WholeDiskBlockIO == Volume->WholeDiskBlockIO) { if (PartNumForVolume(Volume1) == SearchPartNum - 1) { diff --git a/rEFIt_UEFI/Platform/LegacyBoot.cpp b/rEFIt_UEFI/Platform/LegacyBoot.cpp index 19b0b6860..af48c150b 100644 --- a/rEFIt_UEFI/Platform/LegacyBoot.cpp +++ b/rEFIt_UEFI/Platform/LegacyBoot.cpp @@ -919,10 +919,10 @@ EFI_STATUS bootPBR(REFIT_VOLUME* volume, BOOLEAN SataReset) // DBG("Looking for parent disk of %s\n", FileDevicePathToStr(volume->DevicePath)); BiosDriveNum = 0; - for (i = 0; i < VolumesCount; i++) { - if (Volumes[i] != volume && Volumes[i]->BlockIO == volume->WholeDiskBlockIO) + for (i = 0; i < Volumes.size(); i++) { + if (&Volumes[i] != volume && Volumes[i].BlockIO == volume->WholeDiskBlockIO) { - BiosDriveNum = GetBiosDriveNumForVolume(Volumes[i]); + BiosDriveNum = GetBiosDriveNumForVolume(&Volumes[i]); break; } } diff --git a/rEFIt_UEFI/Platform/Nvram.cpp b/rEFIt_UEFI/Platform/Nvram.cpp index 7650f17f0..9ee2dcb91 100644 --- a/rEFIt_UEFI/Platform/Nvram.cpp +++ b/rEFIt_UEFI/Platform/Nvram.cpp @@ -334,8 +334,8 @@ ResetNativeNvram () if (gFirmwareClover || gDriversFlags.EmuVariableLoaded) { //DBG("Searching volumes for nvram.plist\n"); - for (VolumeIndex = 0; VolumeIndex < VolumesCount; ++VolumeIndex) { - Volume = Volumes[VolumeIndex]; + for (VolumeIndex = 0; VolumeIndex < Volumes.size(); ++VolumeIndex) { + Volume = &Volumes[VolumeIndex]; if (!Volume->RootDir) { continue; @@ -889,8 +889,8 @@ LoadLatestNvramPlist () LastModifTimeMs = 0; // search all volumes - for (UINTN Index = 0; Index < VolumesCount; ++Index) { - Volume = Volumes[Index]; + for (UINTN Index = 0; Index < Volumes.size(); ++Index) { + Volume = &Volumes[Index]; if (!Volume->RootDir) { continue; @@ -1224,8 +1224,8 @@ FindStartupDiskVolume ( // DiskVolume = NULL; DBG (" - searching for that disk\n"); - for (Index = 0; Index < (INTN)VolumesCount; ++Index) { - Volume = Volumes[Index]; + for (UINTN Index = 0; Index < Volumes.size(); ++Index) { + Volume = &Volumes[Index]; if (BootVolumeDevicePathEqual (gEfiBootVolume, Volume->DevicePath)) { // that's the one DiskVolume = Volume; diff --git a/rEFIt_UEFI/Platform/Platform.h b/rEFIt_UEFI/Platform/Platform.h index 983c161ea..3f425e2e1 100755 --- a/rEFIt_UEFI/Platform/Platform.h +++ b/rEFIt_UEFI/Platform/Platform.h @@ -82,6 +82,10 @@ extern "C" { } #endif +#include "../cpp_foundation/XStringW.h" +#include "../cpp_foundation/XArray.h" +#include "../cpp_foundation/XObjArray.h" + #include "../refit/lib.h" #include "string.h" #include "boot.h" diff --git a/rEFIt_UEFI/Platform/Settings.cpp b/rEFIt_UEFI/Platform/Settings.cpp index d26c69fd1..e59448e14 100644 --- a/rEFIt_UEFI/Platform/Settings.cpp +++ b/rEFIt_UEFI/Platform/Settings.cpp @@ -431,7 +431,7 @@ ParseLoadOptions ( AsciiConf = (__typeof__(AsciiConf))AllocateCopyPool (TailSize + 1, Start); if (AsciiConf != NULL) { *(AsciiConf + TailSize) = '\0'; - *Conf = (__typeof_am__(*Conf))AllocateZeroPool ((TailSize + 1) * sizeof (CHAR16)); + *Conf = (__typeof_am__(*Conf))AllocateZeroPool ((TailSize + 1) * sizeof(**Conf)); AsciiStrToUnicodeStrS (AsciiConf, *Conf, TailSize); FreePool (AsciiConf); } diff --git a/rEFIt_UEFI/cpp_foundation/XArray.h b/rEFIt_UEFI/cpp_foundation/XArray.h index 117e644fe..12d4eb551 100755 --- a/rEFIt_UEFI/cpp_foundation/XArray.h +++ b/rEFIt_UEFI/cpp_foundation/XArray.h @@ -11,7 +11,7 @@ #if !defined(__XARRAY_H__) #define __XARRAY_H__ -#include // Only use angled for Platform, else, xcode project won't compile // for DebugLog +//#include // Only use angled for Platform, else, xcode project won't compile // for DebugLog //VOID EFIAPI DebugLog(IN INTN DebugMode, IN CONST CHAR8 *FormatString, ...); // To avoid include Platform just for this //extern "C" { // #include @@ -104,9 +104,9 @@ class XArray void RemoveAtIndex(int nIndex); void setEmpty(); - const bool isEmpty() const { return size() == 0; } + bool isEmpty() const { return size() == 0; } - xsize IdxOf(TYPE& e) const; + xsize IdxOf(TYPE& e) const; bool ExistIn(TYPE& e) const { return IdxOf(e) != MAX_XSIZE; } }; diff --git a/rEFIt_UEFI/cpp_foundation/XObjArray.h b/rEFIt_UEFI/cpp_foundation/XObjArray.h index 6409542cf..d9b9ec86c 100755 --- a/rEFIt_UEFI/cpp_foundation/XObjArray.h +++ b/rEFIt_UEFI/cpp_foundation/XObjArray.h @@ -11,7 +11,7 @@ #if !defined(__XOBJARRAY_H__) #define __XOBJARRAY_H__ -#include // Only use angled for Platform, else, xcode project won't compile // for DebugLog +//#include // Only use angled for Platform, else, xcode project won't compile // for DebugLog //VOID EFIAPI DebugLog(IN INTN DebugMode, IN CONST CHAR8 *FormatString, ...); // To avoid include Platform just for this //extern "C" { // #include @@ -56,11 +56,12 @@ class XObjArrayNC xsize _getLen() const { return _Len; } public: - xsize Size() const { return _Size; } - xsize Length() const { return _Len; } + xsize AllocatedSize() const { return _Size; } + xsize size() const { return _Len; } + xsize length() const { return _Len; } - bool NotNull() const { return Length() > 0; } - bool IsNull() const { return Length() == 0; } + bool NotNull() const { return size() > 0; } + bool IsNull() const { return size() == 0; } const TYPE &ElementAt(xsize nIndex) const; TYPE &ElementAt(xsize nIndex); @@ -156,8 +157,8 @@ XObjArray::XObjArray(const XObjArray &anObjArray) xsize ui; XObjArrayNC::Init(); - this->CheckSize(anObjArray.Length(), (xsize)0); - for ( ui=0 ; uiCheckSize(anObjArray.size(), (xsize)0); + for ( ui=0 ; ui &XObjArray::operator =(const XObjArray &anObjA XObjArrayNC::Empty(); CheckSize(anObjArray.Length(), 0); - for ( ui=0 ; ui const TYPE &XObjArrayNC::ElementAt(xsize index) const { if ( index >= _Len ) { - DebugLog(2, "XObjArray::ElementAt(xsize) -> operator [] - index (%d) greater than length (%d)\n", index, _Len); + DebugLog(2, "XObjArray::ElementAt(xsize) const -> operator [] - index (%d) greater than length (%d)\n", index, _Len); CpuDeadLoop(); } return *((TYPE *)(_Data[index].Object)); diff --git a/rEFIt_UEFI/cpp_foundation/XStringWArray.cpp b/rEFIt_UEFI/cpp_foundation/XStringWArray.cpp index ff51103ce..31e195f5f 100755 --- a/rEFIt_UEFI/cpp_foundation/XStringWArray.cpp +++ b/rEFIt_UEFI/cpp_foundation/XStringWArray.cpp @@ -42,10 +42,10 @@ XStringW XStringWArray::ConcatAll(XStringW Separator, XStringW Prefix, XStringW xsize i; XStringW s; - if ( Length() > 0 ) { + if ( size() > 0 ) { s = Prefix; s += ElementAt(0); - for ( i=1 ; i 0 ; } + bool IsNull() const { return size() == 0 ; } + bool NotNull() const { return size() > 0 ; } XStringW ConcatAll(XStringW Separator = L", ", XStringW Prefix = L"", XStringW Suffix = L"") const; diff --git a/rEFIt_UEFI/cpp_foundation/XToolsCommon.h b/rEFIt_UEFI/cpp_foundation/XToolsCommon.h index 247380bb5..ccb2a3246 100755 --- a/rEFIt_UEFI/cpp_foundation/XToolsCommon.h +++ b/rEFIt_UEFI/cpp_foundation/XToolsCommon.h @@ -1,7 +1,6 @@ #ifndef __XTOOLSCOMMON_H__ #define __XTOOLSCOMMON_H__ -#include #define xsize UINTN #define MAX_XSIZE MAX_UINTN @@ -14,8 +13,24 @@ extern xsize XBufferGrowByDefault; */ #define __XTOOLS_INT_CHECK__ +extern "C" { +#include // for CpuDeadLoop +#include +#include // for CopyMen +} #define Xalloc(AllocationSize) AllocatePool(AllocationSize) #define Xrealloc(OldSize, NewSize, OldBuffer) ReallocatePool(OldSize, NewSize, OldBuffer) #define Xfree(Buffer) FreePool(Buffer) #define Xmemmove(dest,source,count) CopyMem(dest, (void*)(source), count) // that has to handle overlapping memory (prefer memmove to memcpy). + + + +// Declare here instead of include to avoid circular dependancy. +VOID +EFIAPI +DebugLog ( + IN INTN DebugMode, + IN CONST CHAR8 *FormatString, ...); + + #endif diff --git a/rEFIt_UEFI/cpp_unit_test/XStringWArray_test.cpp b/rEFIt_UEFI/cpp_unit_test/XStringWArray_test.cpp index 006f4147b..c83b724aa 100644 --- a/rEFIt_UEFI/cpp_unit_test/XStringWArray_test.cpp +++ b/rEFIt_UEFI/cpp_unit_test/XStringWArray_test.cpp @@ -54,13 +54,13 @@ int XStringWArray_tests() if ( !array1.Same(array2) ) return 41; // Arrays are the same array1.AddNoNull(L"3"); - if ( array1.Length() != 3 ) return 50; + if ( array1.size() != 3 ) return 50; array1.AddNoNull(L""); - if ( array1.Length() != 3 ) return 51; + if ( array1.size() != 3 ) return 51; array1.AddEvenNull(XStringW()); - if ( array1.Length() != 4 ) return 52; + if ( array1.size() != 4 ) return 52; array1.AddID(L"2"); - if ( array1.Length() != 4 ) return 53; + if ( array1.size() != 4 ) return 53; return 0; diff --git a/rEFIt_UEFI/entry_scan/common.cpp b/rEFIt_UEFI/entry_scan/common.cpp index b7071be4a..4cc8cfa78 100644 --- a/rEFIt_UEFI/entry_scan/common.cpp +++ b/rEFIt_UEFI/entry_scan/common.cpp @@ -441,15 +441,15 @@ BOOLEAN AskUserForFilePathFromVolumes(IN CHAR16 *Title OPTIONAL, OUT EFI_DEVICE_ return FALSE; } // Allocate entries - Entries = (REFIT_MENU_ENTRY **)AllocateZeroPool(sizeof(REFIT_MENU_ENTRY *) + ((sizeof(REFIT_MENU_ENTRY *) + sizeof(REFIT_MENU_ENTRY)) * VolumesCount)); + Entries = (REFIT_MENU_ENTRY **)AllocateZeroPool(sizeof(REFIT_MENU_ENTRY *) + ((sizeof(REFIT_MENU_ENTRY *) + sizeof(REFIT_MENU_ENTRY)) * Volumes.size())); if (Entries == NULL) { return FALSE; } - EntryPtr = (REFIT_MENU_ENTRY *)(Entries + (VolumesCount + 1)); + EntryPtr = (REFIT_MENU_ENTRY *)(Entries + (Volumes.size() + 1)); // Create volume entries - for (Index = 0; Index < VolumesCount; ++Index) { + for (Index = 0; Index < Volumes.size(); ++Index) { REFIT_MENU_ENTRY *Entry; - REFIT_VOLUME *Volume = Volumes[Index]; + REFIT_VOLUME *Volume = &Volumes[Index]; if ((Volume == NULL) || (Volume->RootDir == NULL) || ((Volume->DevicePathString == NULL) && (Volume->VolName == NULL))) { continue; @@ -474,9 +474,9 @@ BOOLEAN AskUserForFilePathFromVolumes(IN CHAR16 *Title OPTIONAL, OUT EFI_DEVICE_ ((MenuExit == MENU_EXIT_ENTER) || (MenuExit == MENU_EXIT_DETAILS))) { if (ChosenEntry->Tag >= TAG_OFFSET) { Index = (ChosenEntry->Tag - TAG_OFFSET); - if (Index < VolumesCount) { + if (Index < Volumes.size()) { // Run directory chooser menu - if (!AskUserForFilePathFromDir(Title, Volumes[Index], NULL, Volumes[Index]->RootDir, Result)) { + if (!AskUserForFilePathFromDir(Title, &Volumes[Index], NULL, Volumes[Index].RootDir, Result)) { continue; } Responded = TRUE; @@ -502,8 +502,8 @@ BOOLEAN AskUserForFilePath(IN CHAR16 *Title OPTIONAL, IN EFI_DEVICE_PATH_PROTOCO if (DevicePathStr != NULL) { UINTN Index = 0; // Check the volumes for a match - for (Index = 0; Index < VolumesCount; ++Index) { - REFIT_VOLUME *Volume = Volumes[Index]; + for (Index = 0; Index < Volumes.size(); ++Index) { + REFIT_VOLUME *Volume = &Volumes[Index]; UINTN Length; if ((Volume == NULL) || (Volume->RootDir == NULL) || (Volume->DevicePathString == NULL)) { diff --git a/rEFIt_UEFI/entry_scan/legacy.cpp b/rEFIt_UEFI/entry_scan/legacy.cpp index 1d7745b40..178aa4088 100644 --- a/rEFIt_UEFI/entry_scan/legacy.cpp +++ b/rEFIt_UEFI/entry_scan/legacy.cpp @@ -185,8 +185,8 @@ VOID ScanLegacy(VOID) DBG("Scanning legacy ...\n"); - for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) { - Volume = Volumes[VolumeIndex]; + for (VolumeIndex = 0; VolumeIndex < Volumes.size(); VolumeIndex++) { + Volume = &Volumes[VolumeIndex]; if ((Volume->BootType != BOOTING_BY_PBR) && (Volume->BootType != BOOTING_BY_MBR) && (Volume->BootType != BOOTING_BY_CD)) { @@ -232,10 +232,10 @@ VOID ScanLegacy(VOID) if (HideIfOthersFound) { // check for other bootable entries on the same disk //if PBR exists then Hide MBR - for (VolumeIndex2 = 0; VolumeIndex2 < VolumesCount; VolumeIndex2++) { + for (VolumeIndex2 = 0; VolumeIndex2 < Volumes.size(); VolumeIndex2++) { if (VolumeIndex2 != VolumeIndex && - Volumes[VolumeIndex2]->HasBootCode && - Volumes[VolumeIndex2]->WholeDiskBlockIO == Volume->BlockIO){ + Volumes[VolumeIndex2].HasBootCode && + Volumes[VolumeIndex2].WholeDiskBlockIO == Volume->BlockIO){ ShowVolume = FALSE; // DBG("PBR volume at index %d\n", VolumeIndex2); break; @@ -280,8 +280,8 @@ VOID AddCustomLegacy(VOID) if (Custom->Volume) { DBG("Custom legacy %d matching \"%s\" ...\n", i, Custom->Volume); } - for (VolumeIndex = 0; VolumeIndex < VolumesCount; ++VolumeIndex) { - Volume = Volumes[VolumeIndex]; + for (VolumeIndex = 0; VolumeIndex < Volumes.size(); ++VolumeIndex) { + Volume = &Volumes[VolumeIndex]; DBG(" Checking volume \"%s\" (%s) ... ", Volume->VolName, Volume->DevicePathString); @@ -327,10 +327,10 @@ VOID AddCustomLegacy(VOID) if (HideIfOthersFound) { // check for other bootable entries on the same disk //if PBR exists then Hide MBR - for (VolumeIndex2 = 0; VolumeIndex2 < VolumesCount; VolumeIndex2++) { + for (VolumeIndex2 = 0; VolumeIndex2 < Volumes.size(); VolumeIndex2++) { if (VolumeIndex2 != VolumeIndex && - Volumes[VolumeIndex2]->HasBootCode && - Volumes[VolumeIndex2]->WholeDiskBlockIO == Volume->BlockIO) { + Volumes[VolumeIndex2].HasBootCode && + Volumes[VolumeIndex2].WholeDiskBlockIO == Volume->BlockIO) { ShowVolume = FALSE; break; } diff --git a/rEFIt_UEFI/entry_scan/loader.cpp b/rEFIt_UEFI/entry_scan/loader.cpp index d6056ff47..4e48967cc 100644 --- a/rEFIt_UEFI/entry_scan/loader.cpp +++ b/rEFIt_UEFI/entry_scan/loader.cpp @@ -342,8 +342,8 @@ STATIC BOOLEAN isFirstRootUUID(REFIT_VOLUME *Volume) UINTN VolumeIndex; REFIT_VOLUME *scanedVolume; - for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) { - scanedVolume = Volumes[VolumeIndex]; + for (VolumeIndex = 0; VolumeIndex < Volumes.size(); VolumeIndex++) { + scanedVolume = &Volumes[VolumeIndex]; if (scanedVolume == Volume) return TRUE; @@ -1075,8 +1075,8 @@ VOID ScanLoader(VOID) //DBG("Scanning loaders...\n"); DbgHeader("ScanLoader"); - for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) { - Volume = Volumes[VolumeIndex]; + for (VolumeIndex = 0; VolumeIndex < Volumes.size(); VolumeIndex++) { + Volume = &Volumes[VolumeIndex]; if (Volume->RootDir == NULL) { // || Volume->VolName == NULL) //DBG(", no file system\n", VolumeIndex); continue; @@ -1541,14 +1541,14 @@ STATIC VOID AddCustomEntry(IN UINTN CustomIndex, DBG("all volumes\n"); } - for (VolumeIndex = 0; VolumeIndex < VolumesCount; ++VolumeIndex) { + for (VolumeIndex = 0; VolumeIndex < Volumes.size(); ++VolumeIndex) { CUSTOM_LOADER_ENTRY *CustomSubEntry; LOADER_ENTRY *Entry = NULL; EG_IMAGE *Image, *DriveImage; EFI_GUID *Guid = NULL; UINT64 VolumeSize; - Volume = Volumes[VolumeIndex]; + Volume = &Volumes[VolumeIndex]; if ((Volume == NULL) || (Volume->RootDir == NULL)) { continue; } diff --git a/rEFIt_UEFI/entry_scan/tool.cpp b/rEFIt_UEFI/entry_scan/tool.cpp index 9ff238c86..2a7e9bade 100644 --- a/rEFIt_UEFI/entry_scan/tool.cpp +++ b/rEFIt_UEFI/entry_scan/tool.cpp @@ -205,8 +205,8 @@ VOID ScanTool(VOID) } // if (!gFirmwareClover) { //Slice: I wish to extend functionality on emulated nvram - for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) { - Volume = Volumes[VolumeIndex]; + for (VolumeIndex = 0; VolumeIndex < Volumes.size(); VolumeIndex++) { + Volume = &Volumes[VolumeIndex]; if (!Volume->RootDir || !Volume->DeviceHandle) { continue; } @@ -258,8 +258,8 @@ VOID AddCustomTool(VOID) if (Custom->Volume) { DBG("Custom tool %d matching \"%s\" ...\n", i, Custom->Volume); } - for (VolumeIndex = 0; VolumeIndex < VolumesCount; ++VolumeIndex) { - Volume = Volumes[VolumeIndex]; + for (VolumeIndex = 0; VolumeIndex < Volumes.size(); ++VolumeIndex) { + Volume = &Volumes[VolumeIndex]; DBG(" Checking volume \"%s\" (%s) ... ", Volume->VolName, Volume->DevicePathString); diff --git a/rEFIt_UEFI/refit/lib.cpp b/rEFIt_UEFI/refit/lib.cpp index 9f8dd3a7d..98ceeac23 100644 --- a/rEFIt_UEFI/refit/lib.cpp +++ b/rEFIt_UEFI/refit/lib.cpp @@ -71,8 +71,9 @@ EFI_FILE *OemThemeDir = NULL; REFIT_VOLUME *SelfVolume = NULL; -REFIT_VOLUME **Volumes = NULL; -UINTN VolumesCount = 0; +//REFIT_VOLUME **Volumes = NULL; +//UINTN VolumesCount = 0; +XObjArray Volumes; // // Unicode collation protocol interface // @@ -334,19 +335,19 @@ BOOLEAN IsEmbeddedTheme() // // list functions // - -VOID CreateList(OUT VOID ***ListPtr, OUT UINTN *ElementCount, IN UINTN InitialElementCount) -{ - UINTN AllocateCount; - - *ElementCount = InitialElementCount; - if (*ElementCount > 0) { - AllocateCount = (*ElementCount + 7) & ~7; // next multiple of 8 - *ListPtr = (__typeof_am__(*ListPtr))AllocatePool(sizeof(VOID *) * AllocateCount); - } else { - *ListPtr = NULL; - } -} +// +//VOID CreateList(OUT VOID ***ListPtr, OUT UINTN *ElementCount, IN UINTN InitialElementCount) +//{ +// UINTN AllocateCount; +// +// *ElementCount = InitialElementCount; +// if (*ElementCount > 0) { +// AllocateCount = (*ElementCount + 7) & ~7; // next multiple of 8 +// *ListPtr = (__typeof_am__(*ListPtr))AllocatePool(sizeof(VOID *) * AllocateCount); +// } else { +// *ListPtr = NULL; +// } +//} VOID AddListElement(IN OUT VOID ***ListPtr, IN OUT UINTN *ElementCount, IN VOID *NewElement) { @@ -1077,7 +1078,7 @@ static VOID ScanExtendedPartition(REFIT_VOLUME *WholeDiskVolume, MBR_PARTITION_I } else { // found a logical partition - Volume = (__typeof__(Volume))AllocateZeroPool(sizeof(REFIT_VOLUME)); + Volume = (__typeof__(Volume))AllocateZeroPool(sizeof(*Volume)); Volume->DiskKind = WholeDiskVolume->DiskKind; Volume->IsMbrPartition = TRUE; Volume->MbrPartitionIndex = LogicalPartitionIndex++; @@ -1092,7 +1093,8 @@ static VOID ScanExtendedPartition(REFIT_VOLUME *WholeDiskVolume, MBR_PARTITION_I if (!Bootable) Volume->HasBootCode = FALSE; - AddListElement((VOID ***) &Volumes, &VolumesCount, Volume); + Volumes.AddReference(Volume, true); +// AddListElement((VOID ***) &Volumes, &VolumesCount, Volume); } } } @@ -1105,7 +1107,7 @@ VOID ScanVolumes(VOID) UINTN HandleCount = 0; UINTN HandleIndex; EFI_HANDLE *Handles = NULL; - REFIT_VOLUME *Volume, *WholeDiskVolume; + REFIT_VOLUME *WholeDiskVolume; UINTN VolumeIndex, VolumeIndex2; MBR_PARTITION_INFO *MbrTable; UINTN PartitionIndex; @@ -1127,7 +1129,7 @@ VOID ScanVolumes(VOID) // first pass: collect information about all handles for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) { - Volume = (__typeof__(Volume))AllocateZeroPool(sizeof(REFIT_VOLUME)); + REFIT_VOLUME* Volume = (__typeof__(Volume))AllocateZeroPool(sizeof(*Volume)); Volume->LegacyOS = (__typeof__(Volume->LegacyOS))AllocateZeroPool(sizeof(LEGACY_OS)); Volume->DeviceHandle = Handles[HandleIndex]; if (Volume->DeviceHandle == SelfDeviceHandle) { @@ -1140,8 +1142,8 @@ VOID ScanVolumes(VOID) Status = ScanVolume(Volume); if (!EFI_ERROR(Status)) { - - AddListElement((VOID ***) &Volumes, &VolumesCount, Volume); + Volumes.AddReference(Volume, true); +// AddListElement((VOID ***) &Volumes, &VolumesCount, Volume); if (!gSettings.ShowHiddenEntries) { for (HVi = 0; HVi < gSettings.HVCount; HVi++) { if (StriStr(Volume->DevicePathString, gSettings.HVHideStrings[HVi]) || @@ -1186,8 +1188,8 @@ VOID ScanVolumes(VOID) } // second pass: relate partitions and whole disk devices - for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) { - Volume = Volumes[VolumeIndex]; + for (VolumeIndex = 0; VolumeIndex < Volumes.size(); VolumeIndex++) { + REFIT_VOLUME* Volume = &Volumes[VolumeIndex]; // check MBR partition table for extended partitions if (Volume->BlockIO != NULL && Volume->WholeDiskBlockIO != NULL && @@ -1206,10 +1208,10 @@ VOID ScanVolumes(VOID) WholeDiskVolume = NULL; if (Volume->BlockIO != NULL && Volume->WholeDiskBlockIO != NULL && Volume->BlockIO != Volume->WholeDiskBlockIO) { - for (VolumeIndex2 = 0; VolumeIndex2 < VolumesCount; VolumeIndex2++) { - if (Volumes[VolumeIndex2]->BlockIO == Volume->WholeDiskBlockIO && - Volumes[VolumeIndex2]->BlockIOOffset == 0) - WholeDiskVolume = Volumes[VolumeIndex2]; + for (VolumeIndex2 = 0; VolumeIndex2 < Volumes.size(); VolumeIndex2++) { + if (Volumes[VolumeIndex2].BlockIO == Volume->WholeDiskBlockIO && + Volumes[VolumeIndex2].BlockIOOffset == 0) + WholeDiskVolume = &Volumes[VolumeIndex2]; } } if (WholeDiskVolume != NULL && WholeDiskVolume->MbrPartitionTable != NULL) { @@ -1263,8 +1265,8 @@ static VOID UninitVolumes(VOID) REFIT_VOLUME *Volume; UINTN VolumeIndex; - for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) { - Volume = Volumes[VolumeIndex]; + for (VolumeIndex = 0; VolumeIndex < Volumes.size(); VolumeIndex++) { + Volume = &Volumes[VolumeIndex]; if (Volume->RootDir != NULL) { Volume->RootDir->Close(Volume->RootDir); @@ -1277,13 +1279,7 @@ static VOID UninitVolumes(VOID) Volume->WholeDiskDeviceHandle = NULL; FreePool(Volume); } - - if (Volumes != NULL) { - FreePool(Volumes); - Volumes = NULL; - } - VolumesCount = 0; - + Volumes.Empty(); } VOID ReinitVolumes(VOID) @@ -1295,8 +1291,8 @@ VOID ReinitVolumes(VOID) EFI_DEVICE_PATH *RemainingDevicePath; EFI_HANDLE DeviceHandle, WholeDiskHandle; - for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) { - Volume = Volumes[VolumeIndex]; + for (VolumeIndex = 0; VolumeIndex < Volumes.size(); VolumeIndex++) { + Volume = &Volumes[VolumeIndex]; if (!Volume) { continue; } @@ -1337,7 +1333,10 @@ VOID ReinitVolumes(VOID) // CheckError(Status, L"from LocateDevicePath"); } } - VolumesCount = VolumesFound; +// Jief : I'm not sure to understand the next line. Why would we change the count when we didn't change the array. +// This code is not currently not used. +// Beware if you want to reuse this. +// VolumesCount = VolumesFound; } REFIT_VOLUME *FindVolumeByName(IN CHAR16 *VolName) @@ -1349,8 +1348,8 @@ REFIT_VOLUME *FindVolumeByName(IN CHAR16 *VolName) return NULL; } - for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) { - Volume = Volumes[VolumeIndex]; + for (VolumeIndex = 0; VolumeIndex < Volumes.size(); VolumeIndex++) { + Volume = &Volumes[VolumeIndex]; if (!Volume) { continue; } diff --git a/rEFIt_UEFI/refit/lib.h b/rEFIt_UEFI/refit/lib.h index 9583f03c7..48347bf5a 100644 --- a/rEFIt_UEFI/refit/lib.h +++ b/rEFIt_UEFI/refit/lib.h @@ -68,6 +68,7 @@ // Experimental <-- #include "libeg.h" +#include "../cpp_foundation/XObjArray.h" #define REFIT_DEBUG (2) #define Print if ((!GlobalConfig.Quiet) || (GlobalConfig.TextOnly)) Print @@ -693,8 +694,8 @@ extern BOOLEAN MainAnime; extern GUI_ANIME *GuiAnime; extern REFIT_VOLUME *SelfVolume; -extern REFIT_VOLUME **Volumes; -extern UINTN VolumesCount; +extern XObjArray Volumes; +//extern UINTN VolumesCount; extern EG_IMAGE *Banner; extern EG_IMAGE *BigBack; diff --git a/rEFIt_UEFI/refit/main.cpp b/rEFIt_UEFI/refit/main.cpp index 12bb79676..b9c59c77c 100644 --- a/rEFIt_UEFI/refit/main.cpp +++ b/rEFIt_UEFI/refit/main.cpp @@ -630,7 +630,7 @@ static VOID StartLoader(IN LOADER_ENTRY *Entry) font = nextFont; } nsvg__deleteParser(mainParser); - destruct_globals_objects(NULL); + //destruct_globals_objects(NULL); //we can't destruct our globals here. We need, for example, Volumes. //DumpKernelAndKextPatches(Entry->KernelAndKextPatches); @@ -1847,9 +1847,9 @@ UINT8 *APFSContainer_Support(VOID) { EFI_GUID *TmpUUID = NULL; //Fill APFSUUIDBank - APFSUUIDBank = (__typeof__(APFSUUIDBank))AllocateZeroPool(0x10*VolumesCount); - for (VolumeIndex = 0; VolumeIndex < VolumesCount; VolumeIndex++) { - Volume = Volumes[VolumeIndex]; + APFSUUIDBank = (__typeof__(APFSUUIDBank))AllocateZeroPool(0x10*Volumes.size()); + for (VolumeIndex = 0; VolumeIndex < Volumes.size(); VolumeIndex++) { + Volume = &Volumes[VolumeIndex]; //Check that current volume - apfs partition if ((TmpUUID = APFSPartitionUUIDExtract(Volume->DevicePath)) != NULL){ CopyMem(APFSUUIDBank+APFSUUIDBankCounter*0x10,(UINT8 *)TmpUUID,0x10); diff --git a/rEFIt_UEFI/refit/menu.cpp b/rEFIt_UEFI/refit/menu.cpp index 2b303df55..82343f63b 100644 --- a/rEFIt_UEFI/refit/menu.cpp +++ b/rEFIt_UEFI/refit/menu.cpp @@ -4353,7 +4353,7 @@ UINTN RunMenu(IN REFIT_MENU_SCREEN *Screen, OUT REFIT_MENU_ENTRY **ChosenEntry) VOID NewEntry(REFIT_MENU_ENTRY **Entry, REFIT_MENU_SCREEN **SubScreen, ACTION AtClick, UINTN ID, CONST CHAR8 *Title) { //create entry - *Entry = (__typeof_am__(*Entry))AllocateZeroPool(sizeof(LOADER_ENTRY)); + *Entry = (__typeof_am__(*Entry))AllocateZeroPool(sizeof(LOADER_ENTRY)); // carefull, **Entry is not a LOADER_ENTRY. Don't use sizeof. if (Title) { (*Entry)->Title = PoolPrint(L"%a", Title); } else { @@ -4364,7 +4364,7 @@ VOID NewEntry(REFIT_MENU_ENTRY **Entry, REFIT_MENU_SCREEN **SubScreen, ACTION At (*Entry)->Tag = TAG_OPTIONS; (*Entry)->AtClick = AtClick; // create the submenu - *SubScreen = (__typeof_am__(*SubScreen))AllocateZeroPool(sizeof(REFIT_MENU_SCREEN)); + *SubScreen = (__typeof_am__(*SubScreen))AllocateZeroPool(sizeof(**SubScreen)); (*SubScreen)->Title = (*Entry)->Title; (*SubScreen)->TitleImage = (*Entry)->Image; (*SubScreen)->ID = ID;