Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CMakeFiles/
CMakeDoxyfile.in
install_manifest.txt
Testing/
build/
build*/

# msvc / Windows
*.vcxproj*
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ list(APPEND CMAKE_PREFIX_PATH "${LIBLCF_PREFIX_PATH_APPEND}")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)

# lcf library files
set(LCF_SOURCES
src/dbarray.cpp
Expand Down
14 changes: 8 additions & 6 deletions src/dbarray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

namespace lcf {

const DBArrayAlloc::size_type DBArrayAlloc::_empty_buf[2] = { 0, 0 };

static ptrdiff_t HeaderSize(size_t align) {
return std::max(sizeof(DBArrayAlloc::size_type), align);
}
Expand Down Expand Up @@ -48,8 +46,9 @@ void* DBArrayAlloc::alloc(size_type size, size_type field_size, size_type align)

void DBArrayAlloc::free(void* p, size_type align) noexcept {
assert(p != nullptr);
if (p != empty_buf()) {
auto* raw = Adjust(p, -HeaderSize(align));
if (*get_size_ptr(p)!=0) {
void* raw = new void*;
raw = Adjust(p, -HeaderSize(align));
#ifdef LCF_DEBUG_DBARRAY
std::cout << "DBArray: Free"
<< " align=" << align
Expand All @@ -58,7 +57,9 @@ void DBArrayAlloc::free(void* p, size_type align) noexcept {
<< " field_size=" << *get_size_ptr(p)
<< std::endl;
#endif
::operator delete(raw);
delete(raw);


}
}

Expand All @@ -71,7 +72,7 @@ char* DBString::construct_z(const char* s, size_t len) {
}

char* DBString::construct_sv(const char* s, size_t len) {
auto* p = alloc(len);
char* p = alloc(len);
if (len) {
std::memcpy(p, s, len);
p[len] = '\0';
Expand All @@ -80,6 +81,7 @@ char* DBString::construct_sv(const char* s, size_t len) {
}

DBString& DBString::operator=(const DBString& o) {

if (this != &o) {
destroy();
_storage = construct_z(o.data(), o.size());
Expand Down
6 changes: 3 additions & 3 deletions src/lcf/dbarrayalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ struct DBArrayAlloc {
static void free(void* p, size_type align) noexcept;

static void* empty_buf() {
return const_cast<size_type*>(&_empty_buf[1]);
}

return (void*)(&_empty_buf + 1);
}
static constexpr size_type* get_size_ptr(void* p) {
return static_cast<size_type*>(p) - 1;
}
Expand All @@ -39,7 +39,7 @@ struct DBArrayAlloc {
}

private:
static const size_type _empty_buf[2];
static const uint16_t _empty_buf = 0;
};

} // namespace lcf
Expand Down