Fix GCMapAllocator not being used (#369)

* git: ignore clangd cache

* git: also ignore {build,install} dirs with dashes

* 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>>`.
pull/392/head
Sean Farley 2023-05-05 05:36:43 -07:00 committed by GitHub
parent 12c858970d
commit fb46137161
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 9 deletions

3
.gitignore vendored
View File

@ -16,8 +16,10 @@
*.pyc *.pyc
build/ build/
build_*/ build_*/
build-*/
install/ install/
install_*/ install_*/
install-*/
extra/python/src/jit.cpp extra/python/src/jit.cpp
extra/jupyter/build/ extra/jupyter/build/
@ -55,6 +57,7 @@ Thumbs.db
.idea .idea
.mypy_cache .mypy_cache
.vscode .vscode
.cache
extra/jupyter/share/jupyter/kernels/codon/kernel.json extra/jupyter/share/jupyter/kernels/codon/kernel.json
extra/python/codon/version.py extra/python/codon/version.py

View File

@ -69,15 +69,20 @@ struct Span {
seq_int_t end; seq_int_t end;
}; };
template <class Key, class Value> template <typename KV> struct GCMapAllocator : public std::allocator<KV> {
struct GCMapAllocator : public std::allocator<std::pair<const Key, Value>> { GCMapAllocator() = default;
using value_type = std::pair<const Key, Value>; GCMapAllocator(GCMapAllocator<KV> const &) = default;
value_type *allocate(std::size_t n) { template <typename KV1>
return (value_type *)seq_alloc(n * sizeof(value_type)); GCMapAllocator(const GCMapAllocator<KV1>&) noexcept {}
}
void deallocate(value_type *p, std::size_t n) { seq_gc_free(p); } KV *allocate(std::size_t n) { return (KV *)seq_alloc(n * sizeof(KV)); }
void deallocate(KV *p, std::size_t n) { seq_free(p); }
template <typename U> struct rebind {
using other = GCMapAllocator<U>;
};
}; };
static inline seq_str_t convert(const std::string &p) { static inline seq_str_t convert(const std::string &p) {
@ -106,8 +111,8 @@ struct KeyHash {
} }
}; };
static thread_local std::unordered_map<Key, Regex, KeyHash, KeyEqual, static thread_local std::unordered_map<const Key, Regex, KeyHash, KeyEqual,
GCMapAllocator<Key, Regex>> GCMapAllocator<std::pair<const Key, Regex>>>
cache; cache;
static inline Regex *get(const seq_str_t &p, seq_int_t flags) { static inline Regex *get(const seq_str_t &p, seq_int_t flags) {