aboutsummaryrefslogtreecommitdiff
path: root/zencore
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-09-16 10:13:28 +0200
committerMartin Ridgers <[email protected]>2021-09-16 10:13:58 +0200
commit7aa3ceabe4254479bd066ae3ea941396fdc6733c (patch)
treea7d0a7fde0a5a3c42302238965c25c665fc28005 /zencore
parentMissing include (diff)
parentAdded some placeholder HttpClient functions to be fleshed out (diff)
downloadzen-7aa3ceabe4254479bd066ae3ea941396fdc6733c.tar.xz
zen-7aa3ceabe4254479bd066ae3ea941396fdc6733c.zip
Merge from main
Diffstat (limited to 'zencore')
-rw-r--r--zencore/compactbinaryvalidation.cpp2
-rw-r--r--zencore/compress.cpp6
-rw-r--r--zencore/except.cpp2
-rw-r--r--zencore/filesystem.cpp2
-rw-r--r--zencore/include/zencore/except.h4
-rw-r--r--zencore/include/zencore/intmath.h2
-rw-r--r--zencore/include/zencore/iobuffer.h20
-rw-r--r--zencore/include/zencore/logging.h57
-rw-r--r--zencore/include/zencore/session.h11
-rw-r--r--zencore/include/zencore/stream.h4
-rw-r--r--zencore/iobuffer.cpp2
-rw-r--r--zencore/logging.cpp24
-rw-r--r--zencore/session.cpp21
-rw-r--r--zencore/uid.cpp1
-rw-r--r--zencore/zencore.vcxproj5
-rw-r--r--zencore/zencore.vcxproj.filters5
16 files changed, 136 insertions, 32 deletions
diff --git a/zencore/compactbinaryvalidation.cpp b/zencore/compactbinaryvalidation.cpp
index 316da76a6..dafd1bcc8 100644
--- a/zencore/compactbinaryvalidation.cpp
+++ b/zencore/compactbinaryvalidation.cpp
@@ -418,7 +418,7 @@ ValidateCbPackageAttachment(CbFieldView& Value, MemoryView& View, CbValidateMode
{
if (const CbObjectView ObjectView = Value.AsObjectView(); !Value.HasError())
{
- return CbObject().GetHash();
+ return ObjectView.GetHash();
}
if (const IoHash ObjectAttachmentHash = Value.AsObjectAttachment(); !Value.HasError())
diff --git a/zencore/compress.cpp b/zencore/compress.cpp
index 55808375e..12a7b9ef8 100644
--- a/zencore/compress.cpp
+++ b/zencore/compress.cpp
@@ -103,7 +103,7 @@ struct BufferHeader
constexpr uint64_t MethodOffset = offsetof(BufferHeader, Method);
for (MemoryView View = HeaderView + MethodOffset; const uint64_t ViewSize = View.GetSize();)
{
- const int32_t Size = static_cast<int32_t>(zen::Min<uint64_t>(ViewSize, INT_MAX));
+ const int32_t Size = static_cast<int32_t>(zen::Min<uint64_t>(ViewSize, /* INT_MAX */ 2147483647u));
Crc32 = zen::MemCrc32(View.GetData(), Size, Crc32);
View += Size;
}
@@ -211,7 +211,7 @@ private:
CompositeBuffer
BlockEncoder::Compress(const CompositeBuffer& RawData, const uint64_t BlockSize) const
{
- ZEN_ASSERT(IsPow2(BlockSize) && BlockSize <= (1 << 31));
+ ZEN_ASSERT(IsPow2(BlockSize) && (BlockSize <= (1u << 31)));
const uint64_t RawSize = RawData.GetSize();
BLAKE3Stream RawHash;
@@ -592,7 +592,7 @@ protected:
const int Size = LZ4_decompress_safe(static_cast<const char*>(CompressedData.GetData()),
static_cast<char*>(RawData.GetData()),
static_cast<int>(CompressedData.GetSize()),
- static_cast<int>(zen::Min<uint64_t>(RawData.GetSize(), LZ4_MAX_INPUT_SIZE)));
+ static_cast<int>(zen::Min<uint64_t>(RawData.GetSize(), uint64_t(LZ4_MAX_INPUT_SIZE))));
return static_cast<uint64_t>(Size) == RawData.GetSize();
}
return false;
diff --git a/zencore/except.cpp b/zencore/except.cpp
index 123d8e231..75d0c8dd1 100644
--- a/zencore/except.cpp
+++ b/zencore/except.cpp
@@ -40,6 +40,7 @@ GetErrorAsString(uint32_t ErrorCode)
return std::error_code(ErrorCode, std::system_category()).message();
}
+#if __cpp_lib_source_location
void
ThrowLastError(std::string_view Message, const std::source_location& Location)
{
@@ -47,5 +48,6 @@ ThrowLastError(std::string_view Message, const std::source_location& Location)
throw std::system_error(std::error_code(zen::GetLastError(), std::system_category()),
"{}({}): {}"_format(Location.file_name(), Location.line(), Message));
}
+#endif
} // namespace zen
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp
index 14eef812f..2942910ed 100644
--- a/zencore/filesystem.cpp
+++ b/zencore/filesystem.cpp
@@ -619,6 +619,8 @@ PathFromHandle(void* NativeHandle)
const DWORD FinalLength = GetFinalPathNameByHandleW(NativeHandle, FullPath.data(), RequiredLengthIncludingNul, FILE_NAME_OPENED);
+ ZEN_UNUSED(FinalLength);
+
return FullPath;
#elif ZEN_PLATFORM_LINUX
char Buffer[256];
diff --git a/zencore/include/zencore/except.h b/zencore/include/zencore/except.h
index 5b4a49364..90f7d45db 100644
--- a/zencore/include/zencore/except.h
+++ b/zencore/include/zencore/except.h
@@ -54,7 +54,11 @@ ZENCORE_API void ThrowSystemException(HRESULT hRes, std::string_view Message);
#endif // ZEN_PLATFORM_WINDOWS
ZENCORE_API void ThrowLastError(std::string_view Message);
+
+#if __cpp_lib_source_location
ZENCORE_API void ThrowLastError(std::string_view Message, const std::source_location& Location);
+#endif
+
ZENCORE_API std::string GetLastErrorAsString();
ZENCORE_API std::string GetErrorAsString(uint32_t ErrorCode);
diff --git a/zencore/include/zencore/intmath.h b/zencore/include/zencore/intmath.h
index 85447c17a..814a03df4 100644
--- a/zencore/include/zencore/intmath.h
+++ b/zencore/include/zencore/intmath.h
@@ -9,7 +9,7 @@
//////////////////////////////////////////////////////////////////////////
-#if ZEN_COMPILER_MSC
+#if ZEN_COMPILER_MSC || ZEN_PLATFORM_WINDOWS
# pragma intrinsic(_BitScanReverse)
# pragma intrinsic(_BitScanReverse64)
#else
diff --git a/zencore/include/zencore/iobuffer.h b/zencore/include/zencore/iobuffer.h
index 034c3566f..c3860f2b0 100644
--- a/zencore/include/zencore/iobuffer.h
+++ b/zencore/include/zencore/iobuffer.h
@@ -13,14 +13,16 @@ struct IoBufferExtendedCore;
enum class ZenContentType : uint8_t
{
- kBinary, // Note that since this is zero, this will be the default value in IoBuffer
- kText,
- kJSON,
- kCbObject,
- kCbPackage,
- kYAML,
- kCbPackageOffer,
- kUnknownContentType
+ kBinary = 0, // Note that since this is zero, this will be the default value in IoBuffer
+ kText = 1,
+ kJSON = 2,
+ kCbObject = 3,
+ kCbPackage = 4,
+ kYAML = 5,
+ kCbPackageOffer = 6,
+ kCompressedBinary = 7,
+ kUnknownContentType = 8,
+ kCOUNT
};
struct IoBufferFileReference
@@ -321,7 +323,9 @@ public:
[[nodiscard]] void* MutableData() const { return m_Core->MutableDataPointer(); }
void MakeImmutable() { m_Core->SetIsImmutable(true); }
[[nodiscard]] const void* Data() const { return m_Core->DataPointer(); }
+ [[nodiscard]] const void* GetData() const { return m_Core->DataPointer(); }
[[nodiscard]] size_t Size() const { return m_Core->DataBytes(); }
+ [[nodiscard]] size_t GetSize() const { return m_Core->DataBytes(); }
inline void SetContentType(ZenContentType ContentType) { m_Core->SetContentType(ContentType); }
[[nodiscard]] inline ZenContentType GetContentType() const { return m_Core->GetContentType(); }
[[nodiscard]] ZENCORE_API bool GetFileReference(IoBufferFileReference& OutRef) const;
diff --git a/zencore/include/zencore/logging.h b/zencore/include/zencore/logging.h
index eefed4efa..8e6b3a244 100644
--- a/zencore/include/zencore/logging.h
+++ b/zencore/include/zencore/logging.h
@@ -13,6 +13,7 @@
namespace zen::logging {
spdlog::logger& Default();
+void SetDefault(std::shared_ptr<spdlog::logger> NewDefaultLogger);
spdlog::logger& ConsoleLog();
spdlog::logger& Get(std::string_view Name);
@@ -22,7 +23,14 @@ void ShutdownLogging();
} // namespace zen::logging
namespace zen {
-spdlog::logger& Log();
+extern spdlog::logger* TheDefaultLogger;
+
+inline spdlog::logger&
+Log()
+{
+ return *TheDefaultLogger;
+}
+
using logging::ConsoleLog;
} // namespace zen
@@ -31,9 +39,44 @@ using zen::Log;
// Helper macros for logging
-#define ZEN_TRACE(...) Log().trace(__VA_ARGS__)
-#define ZEN_DEBUG(...) Log().debug(__VA_ARGS__)
-#define ZEN_INFO(...) Log().info(__VA_ARGS__)
-#define ZEN_WARN(...) Log().warn(__VA_ARGS__)
-#define ZEN_ERROR(...) Log().error(__VA_ARGS__)
-#define ZEN_CRITICAL(...) Log().critical(__VA_ARGS__)
+#define ZEN_TRACE(fmtstr, ...) \
+ do \
+ { \
+ using namespace std::literals; \
+ Log().trace(fmtstr##sv, __VA_ARGS__); \
+ } while (false)
+
+#define ZEN_DEBUG(fmtstr, ...) \
+ do \
+ { \
+ using namespace std::literals; \
+ Log().debug(fmtstr##sv, __VA_ARGS__); \
+ } while (false)
+
+#define ZEN_INFO(fmtstr, ...) \
+ do \
+ { \
+ using namespace std::literals; \
+ Log().info(fmtstr##sv, __VA_ARGS__); \
+ } while (false)
+
+#define ZEN_WARN(fmtstr, ...) \
+ do \
+ { \
+ using namespace std::literals; \
+ Log().warn(fmtstr##sv, __VA_ARGS__); \
+ } while (false)
+
+#define ZEN_ERROR(fmtstr, ...) \
+ do \
+ { \
+ using namespace std::literals; \
+ Log().error(fmtstr##sv, __VA_ARGS__); \
+ } while (false)
+
+#define ZEN_CRITICAL(fmtstr, ...) \
+ do \
+ { \
+ using namespace std::literals; \
+ Log().critical(fmtstr##sv, __VA_ARGS__); \
+ } while (false)
diff --git a/zencore/include/zencore/session.h b/zencore/include/zencore/session.h
new file mode 100644
index 000000000..e66794704
--- /dev/null
+++ b/zencore/include/zencore/session.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include <zencore/zencore.h>
+
+namespace zen {
+
+struct Oid;
+
+ZENCORE_API Oid GetSessionId();
+
+}
diff --git a/zencore/include/zencore/stream.h b/zencore/include/zencore/stream.h
index 4e8c58382..a0e165bdc 100644
--- a/zencore/include/zencore/stream.h
+++ b/zencore/include/zencore/stream.h
@@ -36,6 +36,7 @@ class InStream : public RefCounted
public:
virtual void Read(void* DataPtr, size_t ByteCount, uint64_t Offset) = 0;
virtual uint64_t Size() const = 0;
+ uint64_t GetSize() const { return Size(); }
};
/**
@@ -50,7 +51,9 @@ public:
virtual void Write(const void* DataPtr, size_t ByteCount, uint64_t Offset) override;
virtual void Flush() override;
inline const uint8_t* Data() const { return m_Buffer.data(); }
+ inline const uint8_t* GetData() const { return m_Buffer.data(); }
inline uint64_t Size() const { return m_Buffer.size(); }
+ inline uint64_t GetSize() const { return m_Buffer.size(); }
private:
RwLock m_Lock;
@@ -76,6 +79,7 @@ public:
virtual void Read(void* DataPtr, size_t ByteCount, uint64_t ReadOffset) override;
virtual uint64_t Size() const override { return m_Buffer.size(); }
inline const uint8_t* Data() const { return m_Buffer.data(); }
+ inline const uint8_t* GetData() const { return m_Buffer.data(); }
private:
RwLock m_Lock;
diff --git a/zencore/iobuffer.cpp b/zencore/iobuffer.cpp
index 378105e69..cf167a7c6 100644
--- a/zencore/iobuffer.cpp
+++ b/zencore/iobuffer.cpp
@@ -224,7 +224,7 @@ IoBufferExtendedCore::Materialize() const
if (MappedBase == nullptr)
{
throw std::system_error(
- std::error_code(zen::GetLastError(), std::system_category()),
+ std::error_code(::GetLastError(), std::system_category()),
"MapViewOfFile failed (offset {:#x}, size {:#x}) file: '{}'"_format(MapOffset, MapSize, zen::PathFromHandle(m_FileHandle)));
}
diff --git a/zencore/logging.cpp b/zencore/logging.cpp
index 9d5a726f5..c5c0b6446 100644
--- a/zencore/logging.cpp
+++ b/zencore/logging.cpp
@@ -6,11 +6,8 @@
namespace zen {
-spdlog::logger&
-Log()
-{
- return *spdlog::default_logger();
-}
+// We shadow the underlying spdlog default logger, in order to avoid a bunch of overhead
+spdlog::logger* TheDefaultLogger;
} // namespace zen
@@ -19,20 +16,24 @@ namespace zen::logging {
spdlog::logger&
Default()
{
- return *spdlog::default_logger();
+ return *TheDefaultLogger;
+}
+
+void
+SetDefault(std::shared_ptr<spdlog::logger> NewDefaultLogger)
+{
+ spdlog::set_default_logger(NewDefaultLogger);
+ TheDefaultLogger = spdlog::default_logger_raw();
}
spdlog::logger&
Get(std::string_view Name)
{
std::shared_ptr<spdlog::logger> Logger = spdlog::get(std::string(Name));
+
if (!Logger)
{
- Logger = std::make_shared<spdlog::logger>(std::string(Name),
- begin(spdlog::default_logger()->sinks()),
- end(spdlog::default_logger()->sinks()));
-
- Logger->set_level(spdlog::default_logger()->level());
+ Logger = Default().clone(std::string(Name));
spdlog::register_logger(Logger);
}
@@ -57,6 +58,7 @@ ConsoleLog()
void
InitializeLogging()
{
+ TheDefaultLogger = spdlog::default_logger_raw();
}
void
diff --git a/zencore/session.cpp b/zencore/session.cpp
new file mode 100644
index 000000000..195a9d97c
--- /dev/null
+++ b/zencore/session.cpp
@@ -0,0 +1,21 @@
+#include "zencore/session.h"
+
+#include <zencore/uid.h>
+
+#include <mutex>
+
+namespace zen {
+
+static Oid GlobalSessionId;
+static std::once_flag SessionInitFlag;
+
+Oid GetSessionId()
+{
+ std::call_once(SessionInitFlag, [&] {
+ GlobalSessionId.Generate();
+ });
+
+ return GlobalSessionId;
+}
+
+} \ No newline at end of file
diff --git a/zencore/uid.cpp b/zencore/uid.cpp
index 644d0aa77..acf9f9790 100644
--- a/zencore/uid.cpp
+++ b/zencore/uid.cpp
@@ -100,6 +100,7 @@ TEST_CASE("Oid")
SUBCASE("Basic")
{
Oid id1 = Oid::NewOid();
+ ZEN_UNUSED(id1);
std::vector<Oid> ids;
std::set<Oid> idset;
diff --git a/zencore/zencore.vcxproj b/zencore/zencore.vcxproj
index 4f1e63670..150c42cd6 100644
--- a/zencore/zencore.vcxproj
+++ b/zencore/zencore.vcxproj
@@ -132,6 +132,7 @@
<ClInclude Include="include\zencore\prewindows.h" />
<ClInclude Include="include\zencore\refcount.h" />
<ClInclude Include="include\zencore\scopeguard.h" />
+ <ClInclude Include="include\zencore\session.h" />
<ClInclude Include="include\zencore\sha1.h" />
<ClInclude Include="include\zencore\iobuffer.h" />
<ClInclude Include="include\zencore\sharedbuffer.h" />
@@ -166,6 +167,7 @@
<ClCompile Include="md5.cpp" />
<ClCompile Include="memory.cpp" />
<ClCompile Include="refcount.cpp" />
+ <ClCompile Include="session.cpp" />
<ClCompile Include="sha1.cpp">
<Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">MaxSpeed</Optimization>
<InlineFunctionExpansion Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AnySuitable</InlineFunctionExpansion>
@@ -189,6 +191,9 @@
<ClCompile Include="xxhash.cpp" />
<ClCompile Include="zencore.cpp" />
</ItemGroup>
+ <ItemGroup>
+ <None Include="xmake.lua" />
+ </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
diff --git a/zencore/zencore.vcxproj.filters b/zencore/zencore.vcxproj.filters
index de3d915b8..ea0f8a912 100644
--- a/zencore/zencore.vcxproj.filters
+++ b/zencore/zencore.vcxproj.filters
@@ -41,6 +41,7 @@
<ClInclude Include="include\zencore\prewindows.h" />
<ClInclude Include="include\zencore\postwindows.h" />
<ClInclude Include="include\zencore\logging.h" />
+ <ClInclude Include="include\zencore\session.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="snapshot_manifest.cpp" />
@@ -72,10 +73,14 @@
<ClCompile Include="crc32.cpp" />
<ClCompile Include="logging.cpp" />
<ClCompile Include="intmath.cpp" />
+ <ClCompile Include="session.cpp" />
</ItemGroup>
<ItemGroup>
<Filter Include="CAS">
<UniqueIdentifier>{af5266fa-37a5-494c-9116-b15a3e6edd29}</UniqueIdentifier>
</Filter>
</ItemGroup>
+ <ItemGroup>
+ <None Include="xmake.lua" />
+ </ItemGroup>
</Project> \ No newline at end of file