Skip to content

Commit

Permalink
hotfix: Resolve possible name conflic issue on memcpy
Browse files Browse the repository at this point in the history
  • Loading branch information
cwahn committed Feb 19, 2024
1 parent eceea8a commit 7656752
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 10 additions & 3 deletions include/efp/cpp_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@
#include <cstring>

namespace efp {
void* (*memcpy)(void* dest, const void* src, size_t size) = std::memcpy;
// Use a function alias for clarity and avoid direct assignment to avoid potential confusion.
inline void* _memcpy(void* dest, const void* src, size_t size) {
return std::memcpy(dest, src, size);
}
} // namespace efp

#else

namespace efp {
void* memcpy(void* dest, const void* src, size_t size) {
// Custom memcpy implementation for freestanding environments.
// Added extern "C" to ensure C linkage for compatibility with C libraries or code.
extern "C" void* _memcpy(void* dest, const void* src, size_t size) {
auto* d = static_cast<char*>(dest);
const auto* s = static_cast<const char*>(src);
for (size_t i = 0; i < size; ++i) {
static_cast<char*>(dest)[i] = static_cast<const char*>(src)[i];
d[i] = s[i];
}
return dest;
}
Expand Down
6 changes: 3 additions & 3 deletions include/efp/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ class Vector<Char, Allocator, Traits, EnableIf<detail::IsCharType<Char>::value>>
Base::_size = Traits::length(c_str);
Base::_capacity = Base::_size + 1;
Base::_data = Base::_allocator.allocate(Base::_capacity);
efp::memcpy(Base::_data, c_str, Base::_size * sizeof(Char));
_memcpy(Base::_data, c_str, Base::_size * sizeof(Char));
}

Vector(const Char* s, size_t count, const Allocator& alloc = Allocator()) {
Base::_size = count;
Base::_capacity = Base::_size + 1;
Base::_data = Base::_allocator.allocate(Base::_capacity);
efp::memcpy(Base::_data, s, Base::_size * sizeof(Char));
_memcpy(Base::_data, s, Base::_size * sizeof(Char));
}

Vector(size_t size, Char c) {
Expand Down Expand Up @@ -220,7 +220,7 @@ class Vector<Char, Allocator, Traits, EnableIf<detail::IsCharType<Char>::value>>
count = Base::_size - pos;
}

efp::memcpy(dest, Base::_data + pos, count * sizeof(Char));
_memcpy(dest, Base::_data + pos, count * sizeof(Char));
return count;
}

Expand Down

0 comments on commit 7656752

Please sign in to comment.