Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GCMapAllocator not being used #369

Merged
merged 3 commits into from
May 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
re2: fix GCMapAllocator definition
Previously, the GCMapAllocator specified the wrong template arguments
and, thus, would not actually be used. This can be verified by the fact
that `GCMapAllocator::deallocate` used an undefined symbol:
`seq_gc_free`.

C++20 makes this an error like so:

```
error: static assertion failed due to requirement 'is_same<GCMapAllocator<std::pair<seq_str_t, long long>, re2::RE2>, GCMapAllocator<std::pair<const std::pair<seq_str_t, long long>, re2::RE2>, re2::RE2>>::value': [allocator.requirements] states that rebinding an allocator to the same type should result in the original allocator
    static_assert(is_same<allocator_type, __rebind_alloc<__alloc_traits, value_type> >::value,
    ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 errors generated.
```

This patch fixes the undefined symbol of `seq_gc_free` with `seq_free`
along with fixing `<Key, Value>` -> `<std::pair<Key, Value>>`.
  • Loading branch information
seanfarley committed May 2, 2023
commit 4d5410a7aa745600df4438c1f3a2a9e48d2bacbf
23 changes: 14 additions & 9 deletions codon/runtime/re.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,20 @@ struct Span {
seq_int_t end;
};

template <class Key, class Value>
struct GCMapAllocator : public std::allocator<std::pair<const Key, Value>> {
using value_type = std::pair<const Key, Value>;
template <typename KV> struct GCMapAllocator : public std::allocator<KV> {
GCMapAllocator() = default;
GCMapAllocator(GCMapAllocator<KV> const &) = default;

value_type *allocate(std::size_t n) {
return (value_type *)seq_alloc(n * sizeof(value_type));
}
template <typename KV1>
GCMapAllocator(const GCMapAllocator<KV1>&) noexcept {}

KV *allocate(std::size_t n) { return (KV *)seq_alloc(n * sizeof(KV)); }

void deallocate(KV *p, std::size_t n) { seq_free(p); }

void deallocate(value_type *p, std::size_t n) { seq_gc_free(p); }
template <typename U> struct rebind {
using other = GCMapAllocator<U>;
};
};

static inline seq_str_t convert(const std::string &p) {
Expand Down Expand Up @@ -106,8 +111,8 @@ struct KeyHash {
}
};

static thread_local std::unordered_map<Key, Regex, KeyHash, KeyEqual,
GCMapAllocator<Key, Regex>>
static thread_local std::unordered_map<const Key, Regex, KeyHash, KeyEqual,
GCMapAllocator<std::pair<const Key, Regex>>>
cache;

static inline Regex *get(const seq_str_t &p, seq_int_t flags) {
Expand Down