From c97fd6853fe2db1ee6f35ddff2b91651fbd46ae1 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Thu, 28 Dec 2023 13:47:57 +0100 Subject: [PATCH 1/6] use a custom empty context for global elements The extern one was never exported properly. So it's not part of the public API. --- ebml/EbmlElement.h | 5 ++--- src/EbmlContexts.cpp | 2 -- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/ebml/EbmlElement.h b/ebml/EbmlElement.h index 57d8b6ab..012711e4 100644 --- a/ebml/EbmlElement.h +++ b/ebml/EbmlElement.h @@ -50,8 +50,6 @@ class EbmlStream; class EbmlSemanticContext; class EbmlElement; -extern const EbmlSemanticContext Context_EbmlGlobal; - #define DEFINE_xxx_CONTEXT(x,global) \ const EbmlSemanticContext Context_##x = EbmlSemanticContext(countof(ContextList_##x), ContextList_##x, nullptr, global, nullptr); \ @@ -109,7 +107,8 @@ extern const EbmlSemanticContext Context_EbmlGlobal; #define DEFINE_xxx_CLASS_GLOBAL(x,id,idl,name,global) \ constexpr EbmlId Id_##x (id, idl); \ - constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, Context_EbmlGlobal); \ + const EbmlSemanticContext EmptyContext_##x = EbmlSemanticContext(0, nullptr, nullptr, global, nullptr); \ + constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, EmptyContext_##x); \ #define DEFINE_xxx_CLASS_ORPHAN(x,id,idl,name,global) \ constexpr EbmlId Id_##x (id, idl); \ diff --git a/src/EbmlContexts.cpp b/src/EbmlContexts.cpp index a40cc7e3..d435350e 100644 --- a/src/EbmlContexts.cpp +++ b/src/EbmlContexts.cpp @@ -17,8 +17,6 @@ static constexpr EbmlSemantic EbmlGlobal_ContextList[2] = EbmlSemantic(false, false, EBML_INFO(EbmlVoid)), ///< EbmlVoid }; -const EbmlSemanticContext Context_EbmlGlobal = EbmlSemanticContext(0, nullptr, nullptr, GetEbmlGlobal_Context, nullptr); - static const EbmlSemanticContext EbmlGlobal_Context = EbmlSemanticContext(countof(EbmlGlobal_ContextList), EbmlGlobal_ContextList, nullptr, GetEbmlGlobal_Context, nullptr); const EbmlSemanticContext & GetEbmlGlobal_Context() From 39ca79a47838205c4ecb9f858b227aa2988b54ec Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Thu, 28 Dec 2023 13:29:14 +0100 Subject: [PATCH 2/6] use existing macros to define the EbmlGlobal elements --- src/EbmlContexts.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/EbmlContexts.cpp b/src/EbmlContexts.cpp index d435350e..0264e274 100644 --- a/src/EbmlContexts.cpp +++ b/src/EbmlContexts.cpp @@ -11,17 +11,16 @@ namespace libebml { -static constexpr EbmlSemantic EbmlGlobal_ContextList[2] = -{ - EbmlSemantic(false, false, EBML_INFO(EbmlCrc32)), ///< EbmlCrc32 - EbmlSemantic(false, false, EBML_INFO(EbmlVoid)), ///< EbmlVoid -}; +DEFINE_START_SEMANTIC(EbmlGlobal) +DEFINE_SEMANTIC_ITEM(false, false, EbmlCrc32) +DEFINE_SEMANTIC_ITEM(false, false, EbmlVoid) +DEFINE_END_SEMANTIC(EbmlGlobal) -static const EbmlSemanticContext EbmlGlobal_Context = EbmlSemanticContext(countof(EbmlGlobal_ContextList), EbmlGlobal_ContextList, nullptr, GetEbmlGlobal_Context, nullptr); +static DEFINE_xxx_CONTEXT(EbmlGlobal, GetEbmlGlobal_Context) const EbmlSemanticContext & GetEbmlGlobal_Context() { - return EbmlGlobal_Context; + return Context_EbmlGlobal; } } // namespace libebml From efd39448095856195ab7045099a1a03284a6dfc9 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Thu, 28 Dec 2023 15:41:22 +0100 Subject: [PATCH 3/6] export the EbmlHead EbmlSemanticContext with its real name The macro was turning it into something that is not its declaration. The other extern are also using the wrong name but noone uses them. --- ebml/EbmlContexts.h | 11 +---------- src/EbmlHead.cpp | 2 +- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/ebml/EbmlContexts.h b/ebml/EbmlContexts.h index 9c2424f3..edfaee0c 100644 --- a/ebml/EbmlContexts.h +++ b/ebml/EbmlContexts.h @@ -13,16 +13,7 @@ namespace libebml { -extern const EbmlSemanticContext EBML_DLL_API EbmlHead_Context; -extern const EbmlSemanticContext EBML_DLL_API EVersion_Context; -extern const EbmlSemanticContext EBML_DLL_API EReadVersion_Context; -extern const EbmlSemanticContext EBML_DLL_API EMaxIdLength_Context; -extern const EbmlSemanticContext EBML_DLL_API EMaxSizeLength_Context; -extern const EbmlSemanticContext EBML_DLL_API EDocType_Context; -extern const EbmlSemanticContext EBML_DLL_API EDocTypeVersion_Context; -extern const EbmlSemanticContext EBML_DLL_API EDocTypeReadVersion_Context; - -#define Context_EbmlHead EbmlHead_Context +extern const EbmlSemanticContext EBML_DLL_API Context_EbmlHead; // global elements extern const EbmlSemanticContext EBML_DLL_API & GetEbmlGlobal_Context(); diff --git a/src/EbmlHead.cpp b/src/EbmlHead.cpp index 5c5d9cb7..795313a9 100644 --- a/src/EbmlHead.cpp +++ b/src/EbmlHead.cpp @@ -24,7 +24,7 @@ DEFINE_END_SEMANTIC(EbmlHead) DEFINE_EBML_MASTER_ORPHAN(EbmlHead, 0x1A45DFA3, 4, false, "EBMLHead\0ratamapaga") EbmlHead::EbmlHead() - :EbmlMaster(EbmlHead::ClassInfos, EbmlHead_Context) + :EbmlMaster(EbmlHead::ClassInfos, Context_EbmlHead) {} } // namespace libebml From 5c80413cabe415ff12e91b6d5864cc8f3a0380b0 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Thu, 28 Dec 2023 13:57:19 +0100 Subject: [PATCH 4/6] make all defined EbmlSemanticContext constexpr DEFINE_xxx_MASTER_ORPHAN is not constexpr because Context_EbmlHead needs to be exported. --- ebml/EbmlElement.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ebml/EbmlElement.h b/ebml/EbmlElement.h index 012711e4..fbb46792 100644 --- a/ebml/EbmlElement.h +++ b/ebml/EbmlElement.h @@ -51,17 +51,17 @@ class EbmlSemanticContext; class EbmlElement; #define DEFINE_xxx_CONTEXT(x,global) \ - const EbmlSemanticContext Context_##x = EbmlSemanticContext(countof(ContextList_##x), ContextList_##x, nullptr, global, nullptr); \ + constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(countof(ContextList_##x), ContextList_##x, nullptr, global, nullptr); \ #define DEFINE_xxx_MASTER(x,id,idl,parent,infinite,name,global) \ constexpr EbmlId Id_##x (id, idl); \ - const EbmlSemanticContext Context_##x = EbmlSemanticContext(countof(ContextList_##x), ContextList_##x, &Context_##parent, global, &EBML_INFO(x)); \ + constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(countof(ContextList_##x), ContextList_##x, &Context_##parent, global, &EBML_INFO(x)); \ constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, infinite, name, Context_##x); \ x::x() :EbmlMaster(x::ClassInfos, Context_##x) {} #define DEFINE_xxx_MASTER_CONS(x,id,idl,parent,infinite,name,global) \ constexpr EbmlId Id_##x (id, idl); \ - const EbmlSemanticContext Context_##x = EbmlSemanticContext(countof(ContextList_##x), ContextList_##x, &Context_##parent, global, &EBML_INFO(x)); \ + constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(countof(ContextList_##x), ContextList_##x, &Context_##parent, global, &EBML_INFO(x)); \ constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, infinite, name, Context_##x); // define a master class with no parent class @@ -72,47 +72,47 @@ class EbmlElement; #define DEFINE_xxx_CLASS(x,id,idl,parent,name,global) \ constexpr EbmlId Id_##x (id, idl); \ - const EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \ + constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \ constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, Context_##x); \ x::x() {} #define DEFINE_xxx_CLASS_CONS(x,id,idl,parent,name,global) \ constexpr EbmlId Id_##x (id, idl); \ - const EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \ + constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \ constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, Context_##x); #define DEFINE_xxx_UINTEGER_DEF(x,id,idl,parent,name,global,defval) \ constexpr EbmlId Id_##x (id, idl); \ - const EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \ + constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \ constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, Context_##x); \ x::x() :EbmlUInteger(x::ClassInfos, defval) {} #define DEFINE_xxx_SINTEGER_DEF(x,id,idl,parent,name,global,defval) \ constexpr EbmlId Id_##x (id, idl); \ - const EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \ + constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \ constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, Context_##x); \ x::x() :EbmlSInteger(x::ClassInfos, defval) {} #define DEFINE_xxx_STRING_DEF(x,id,idl,parent,name,global,defval) \ constexpr EbmlId Id_##x (id, idl); \ - const EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \ + constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \ constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, Context_##x); \ x::x() :EbmlString(x::ClassInfos, defval) {} #define DEFINE_xxx_FLOAT_DEF(x,id,idl,parent,name,global,defval) \ constexpr EbmlId Id_##x (id, idl); \ - const EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \ + constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, &Context_##parent, global, &EBML_INFO(x)); \ constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, Context_##x); \ x::x() :EbmlFloat(x::ClassInfos, defval) {} #define DEFINE_xxx_CLASS_GLOBAL(x,id,idl,name,global) \ constexpr EbmlId Id_##x (id, idl); \ - const EbmlSemanticContext EmptyContext_##x = EbmlSemanticContext(0, nullptr, nullptr, global, nullptr); \ + constexpr EbmlSemanticContext EmptyContext_##x = EbmlSemanticContext(0, nullptr, nullptr, global, nullptr); \ constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, EmptyContext_##x); \ #define DEFINE_xxx_CLASS_ORPHAN(x,id,idl,name,global) \ constexpr EbmlId Id_##x (id, idl); \ - const EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, nullptr, global, nullptr); \ + constexpr EbmlSemanticContext Context_##x = EbmlSemanticContext(0, nullptr, nullptr, global, nullptr); \ constexpr EbmlCallbacks x::ClassInfos(x::Create, Id_##x, false, name, Context_##x); \ #define DEFINE_EBML_CONTEXT(x) DEFINE_xxx_CONTEXT(x,GetEbmlGlobal_Context) From 494d29f19ed859c52655539eedcde45ada88945f Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Thu, 28 Dec 2023 15:01:59 +0100 Subject: [PATCH 5/6] define elements in the EBML header in a single file --- CMakeLists.txt | 1 - src/EbmlHead.cpp | 8 ++++++++ src/EbmlSubHead.cpp | 21 --------------------- 3 files changed, 8 insertions(+), 22 deletions(-) delete mode 100644 src/EbmlSubHead.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f64017d5..b48d6358 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,6 @@ set(libebml_SOURCES src/EbmlSInteger.cpp src/EbmlStream.cpp src/EbmlString.cpp - src/EbmlSubHead.cpp src/EbmlUInteger.cpp src/EbmlUnicodeString.cpp src/EbmlVersion.cpp diff --git a/src/EbmlHead.cpp b/src/EbmlHead.cpp index 795313a9..f1b9c82c 100644 --- a/src/EbmlHead.cpp +++ b/src/EbmlHead.cpp @@ -11,6 +11,14 @@ namespace libebml { +DEFINE_EBML_UINTEGER_DEF(EVersion, 0x4286, 2, EbmlHead, "EBMLVersion", 1) +DEFINE_EBML_UINTEGER_DEF(EReadVersion, 0x42F7, 2, EbmlHead, "EBMLReadVersion", 1) +DEFINE_EBML_UINTEGER_DEF(EMaxIdLength, 0x42F2, 2, EbmlHead, "EBMLMaxIdLength", 4) +DEFINE_EBML_UINTEGER_DEF(EMaxSizeLength, 0x42F3, 2, EbmlHead, "EBMLMaxSizeLength", 8) +DEFINE_EBML_STRING_DEF (EDocType, 0x4282, 2, EbmlHead, "EBMLDocType", "matroska") +DEFINE_EBML_UINTEGER_DEF(EDocTypeVersion, 0x4287, 2, EbmlHead, "EBMLDocTypeVersion", 1) +DEFINE_EBML_UINTEGER_DEF(EDocTypeReadVersion, 0x4285, 2, EbmlHead, "EBMLDocTypeReadVersion", 1) + DEFINE_START_SEMANTIC(EbmlHead) DEFINE_SEMANTIC_ITEM(true, true, EVersion) ///< EBMLVersion DEFINE_SEMANTIC_ITEM(true, true, EReadVersion) ///< EBMLReadVersion diff --git a/src/EbmlSubHead.cpp b/src/EbmlSubHead.cpp deleted file mode 100644 index 8279ef1f..00000000 --- a/src/EbmlSubHead.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright © 2002-2010 Steve Lhomme. -// SPDX-License-Identifier: LGPL-2.1-or-later - -/*! - \file - \author Steve Lhomme -*/ -#include "ebml/EbmlSubHead.h" -#include "ebml/EbmlContexts.h" - -namespace libebml { - -DEFINE_EBML_UINTEGER_DEF(EVersion, 0x4286, 2, EbmlHead, "EBMLVersion", 1) -DEFINE_EBML_UINTEGER_DEF(EReadVersion, 0x42F7, 2, EbmlHead, "EBMLReadVersion", 1) -DEFINE_EBML_UINTEGER_DEF(EMaxIdLength, 0x42F2, 2, EbmlHead, "EBMLMaxIdLength", 4) -DEFINE_EBML_UINTEGER_DEF(EMaxSizeLength, 0x42F3, 2, EbmlHead, "EBMLMaxSizeLength", 8) -DEFINE_EBML_STRING_DEF (EDocType, 0x4282, 2, EbmlHead, "EBMLDocType", "matroska") -DEFINE_EBML_UINTEGER_DEF(EDocTypeVersion, 0x4287, 2, EbmlHead, "EBMLDocTypeVersion", 1) -DEFINE_EBML_UINTEGER_DEF(EDocTypeReadVersion, 0x4285, 2, EbmlHead, "EBMLDocTypeReadVersion", 1) - -} // namespace libebml From 178f3433e15c9d1ac11feeb73b4b13605bdfc440 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Thu, 28 Dec 2023 15:27:08 +0100 Subject: [PATCH 6/6] make GetContext() a constexpr --- ebml/EbmlElement.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ebml/EbmlElement.h b/ebml/EbmlElement.h index fbb46792..c99dd849 100644 --- a/ebml/EbmlElement.h +++ b/ebml/EbmlElement.h @@ -215,7 +215,7 @@ class EBML_DLL_API EbmlCallbacks { } inline const EbmlId & ClassId() const { return GlobalId; } - inline const EbmlSemanticContext & GetContext() const { return Context; } + inline constexpr const EbmlSemanticContext & GetContext() const { return Context; } inline const char * GetName() const { return DebugName; } inline EbmlElement & NewElement() const { return Create(); } /// is infinite/unknown size allowed