Resolved issues when using GCC >= 12 (#41)

Signed-off-by: Nikhil Manglore <nmanglor@amazon.com>
Signed-off-by: Nikhil Manglore <nikhilmanglore9@gmail.com>
Co-authored-by: Roshan Khatri <117414976+roshkhatri@users.noreply.github.com>
This commit is contained in:
Nikhil Manglore 2025-03-05 14:00:54 -08:00 committed by GitHub
parent 10d2793bb9
commit 4fb72a9269
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 16 deletions

View File

@ -4,7 +4,7 @@ on: [push, pull_request]
jobs:
build-ubuntu-latest:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:

View File

@ -1432,13 +1432,8 @@ STATIC JValue readLegacyDoubleAsJValue(ValkeyModuleIO *rdb) {
double d = ValkeyModule_LoadDouble(rdb);
char str[BUF_SIZE_DOUBLE_JSON];
size_t str_len = jsonutil_double_to_string(d, str, sizeof(str));
if (str) {
JValue v(str, str_len, allocator, false, /* isdouble */ true);
return v;
} else {
ValkeyModule_LogIOError(rdb, "error", "Unable to read legacy double");
return JValue();
}
}
/*

View File

@ -95,18 +95,40 @@ namespace jsn
//
// Our custom allocator
//
template <typename T> class stl_allocator : public std::allocator<T> {
public:
typedef T value_type;
stl_allocator() = default;
stl_allocator(std::allocator<T>&) {}
stl_allocator(std::allocator<T>&&) {}
template <class U> constexpr stl_allocator(const stl_allocator<U>&) noexcept {}
template <typename T> class stl_allocator {
public:
using value_type = T;
stl_allocator() = default;
stl_allocator(const stl_allocator<T>&) noexcept = default;
stl_allocator(stl_allocator<T>&&) noexcept = default;
template <class U>
constexpr stl_allocator(const stl_allocator<U>&) noexcept {}
T *allocate(std::size_t n) { return static_cast<T *>(memory_alloc(n*sizeof(T))); }
void deallocate(T *p, std::size_t n) { (void)n; memory_free(p); }
T* allocate(std::size_t n) {
return static_cast<T*>(memory_alloc(n * sizeof(T)));
}
void deallocate(T* p, std::size_t n) {
(void)n;
memory_free(p);
}
private:
static void* memory_alloc(std::size_t size) {
return std::malloc(size);
}
static void memory_free(void* p) {
std::free(p);
}
};
template <typename T, typename U>
bool operator==(const stl_allocator<T>&, const stl_allocator<U>&) { return true; }
template <typename T, typename U>
bool operator!=(const stl_allocator<T>&, const stl_allocator<U>&) { return false; }
template<class Elm> using vector = std::vector<Elm, stl_allocator<Elm>>;
template<class Key, class Compare = std::less<Key>> using set = std::set<Key, Compare, stl_allocator<Key>>;

View File

@ -2512,7 +2512,7 @@ private:
DoReserveMembersVec(count, allocator);
const typename GenericValue<Encoding,SourceAllocator>::Member* rm = rhs.GetMembersPointerVec();
for (SizeType i = 0; i < count; i++) {
KeyTable_Handle name = std::move(keyTable->clone(rm[i].name));
KeyTable_Handle name = keyTable->clone(rm[i].name);
GenericValue value(rm[i].value, allocator, copyConstStrings);
DoAddMember(name, value, allocator);
}