From e7fa2439c8f328ab146037628bce30894e36a32c Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Mon, 10 Jun 2024 10:59:08 +0200 Subject: Unify the value returned by linda:deep() and the string conversion of an unnamed Linda --- src/linda.cpp | 4 ++-- src/linda.h | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/linda.cpp b/src/linda.cpp index 81926f9..4dc2162 100644 --- a/src/linda.cpp +++ b/src/linda.cpp @@ -87,7 +87,7 @@ template std::ignore = luaG_pushstring(L_, _lindaName); } else { // obfuscate the pointer so that we can't read the value with our eyes out of a script - std::ignore = luaG_pushstring(L_, "%p", std::bit_cast(_linda) ^ kConfigRegKey.storage); + std::ignore = luaG_pushstring(L_, "%p", _linda->obfuscated()); } lua_concat(L_, 2); return 1; @@ -344,7 +344,7 @@ LUAG_FUNC(linda_count) LUAG_FUNC(linda_deep) { Linda* const _linda{ ToLinda(L_, 1) }; - lua_pushlightuserdata(L_, _linda); // just the address + lua_pushlightuserdata(L_, _linda->obfuscated()); // just the address return 1; } diff --git a/src/linda.h b/src/linda.h index 3098161..6901a86 100644 --- a/src/linda.h +++ b/src/linda.h @@ -80,6 +80,13 @@ class Linda [[nodiscard]] Keeper* acquireKeeper() const; [[nodiscard]] std::string_view getName() const; [[nodiscard]] bool inKeeperOperation() const { return keeperOperationCount.load(std::memory_order_seq_cst) != 0; } + template + [[nodiscard]] T obfuscated() const + { + // xxh64 of string "kObfuscator" generated at https://www.pelock.com/products/hash-calculator + static constexpr UniqueKey kObfuscator{ 0x7B8AA1F99A3BD782ull }; + return std::bit_cast(std::bit_cast(this) ^ kObfuscator.storage); + }; void releaseKeeper(Keeper* keeper_) const; [[nodiscard]] static int ProtectedCall(lua_State* L_, lua_CFunction f_); [[nodiscard]] KeeperOperationInProgress startKeeperOperation(lua_State* const L_) { return KeeperOperationInProgress{ *this, L_ }; }; -- cgit v1.2.3-55-g6feb