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

Bug fixes, documentation (source level), and general cleanup #135

Merged
merged 29 commits into from
Aug 28, 2013
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d565c8c
Another small round of cleanup
kspangsege Aug 15, 2013
6d23590
Use tightdb::Thread API in more places for improved portability
kspangsege Aug 15, 2013
b708977
Fixed bug in TableViewBase::sort().
kspangsege Aug 16, 2013
75d5518
Correction of detection of changed arrays when updating accessors aft…
kspangsege Aug 17, 2013
a1d02ba
Avoid clobbering the previous database version in GroupWriter::commit…
kspangsege Aug 19, 2013
78ada0b
More cleanup
kspangsege Aug 19, 2013
6aed1ac
In GroupWriter::reserve_free_space() after looking in the last half o…
kspangsege Aug 19, 2013
e7294cf
Merge branch 'master' into ks-cleanup
kspangsege Aug 21, 2013
6d56d96
Bad line removed from testcase 'Table1'
kspangsege Aug 21, 2013
d8b491a
Merge branch 'master' into ks-cleanup
kspangsege Aug 23, 2013
7b7a37d
Stop throwing from destructors, and from SharedGroup::rollback() and …
kspangsege Aug 23, 2013
e46d017
changelog.txt updated
kspangsege Aug 23, 2013
7b728d4
Merge branch 'master' into ks-cleanup
kspangsege Aug 23, 2013
7fc2e4e
No longer appempting to place database files in /tmp/
kspangsege Aug 24, 2013
1bb2b73
Avoid superflous use of 'const' and use UniquePtr<> instead of reinve…
kspangsege Aug 25, 2013
2cd8f48
Typos fixed
kspangsege Aug 25, 2013
298188d
Use ScopedMutexLock when possible, and keep track of exception sources
kspangsege Aug 25, 2013
9666623
Merge branch 'ks-cleanup' of github.com:kspangsege/tightdb into ks-cl…
kspangsege Aug 25, 2013
dfc3700
New conditional compilation flag TIGHTDB_ALLOC_SET_ZERO to help in hu…
kspangsege Aug 26, 2013
4ffc6b6
bugfix: remap lock file during end_read if necessary
Aug 26, 2013
bc7e2c9
Merge branch 'master' into ks-cleanup
kspangsege Aug 26, 2013
8fa0f1d
Merge branch 'master' into ks-cleanup
kspangsege Aug 26, 2013
204e6e5
Merge branch 'fs-ringbuf_fix' into ks-cleanup
kspangsege Aug 26, 2013
0cd7d26
Merge branch 'master' into ks-node-consolidation
kspangsege Aug 27, 2013
99b111b
Merge branch 'ks-cleanup' into ks-node-consolidation
kspangsege Aug 27, 2013
9ce762e
A tiny bit of cleanup
kspangsege Aug 27, 2013
71405a0
Fixing wrong assertion in Group::get_table_ptr() and adding a few mor…
kspangsege Aug 27, 2013
6e705da
Fixing Xcode project
kspangsege Aug 28, 2013
62b712f
Reintroducing use of function local static for default allocator. It …
kspangsege Aug 28, 2013
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
11 changes: 11 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,20 @@ Format:

==================


2013-08-23 (Kristian Spangsege)
+ Stop throwing from destructors (all), and from SharedGroup::rollback() and SharedGRoup::end_read().
+ General stability and eror checking improvements.
! Fixed many bugs relating to Group::commit().
! Fixed some bugs relating to SharedGroup::commit().
! Fixed bug in TableViewBase::sort().



2013-08-18 (Kenneth Geisshirt)
! Group::to_string formatting was incorrect. See https://app.asana.com/0/1441391972580/5659532773181.


2013-08-03 (Kristian Spangsege)
+ Table::find_sorted_int() replaced by Table::lower_bound_int() and Table::upper_bound_int() as these are standardized and provide more flexibility.
+ Addition of Table::lower_bound_bool() and Table::upper_bound_bool().
Expand Down
10 changes: 5 additions & 5 deletions src/tightdb/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
GENERATED_SOURCES = table_macros.hpp

INST_HEADERS = config.h meta.hpp assert.hpp exceptions.hpp terminate.hpp type_list.hpp tuple.hpp \
bind.hpp safe_int_ops.hpp unique_ptr.hpp bind_ptr.hpp string_buffer.hpp file.hpp thread.hpp \
utf8.hpp utilities.hpp alloc.hpp alloc_slab.hpp array.hpp array_string.hpp data_type.hpp \
column_type.hpp column_fwd.hpp spec.hpp date.hpp string_data.hpp binary_data.hpp mixed.hpp \
table.hpp table_ref.hpp table_basic_fwd.hpp table_accessors.hpp table_basic.hpp table_view.hpp \
table_view_basic.hpp table_macros.hpp group.hpp group_shared.hpp query.hpp \
bind.hpp safe_int_ops.hpp unique_ptr.hpp bind_ptr.hpp buffer.hpp string_buffer.hpp file.hpp \
thread.hpp utf8.hpp utilities.hpp alloc.hpp alloc_slab.hpp array.hpp array_string.hpp \
data_type.hpp column_type.hpp column_fwd.hpp spec.hpp date.hpp string_data.hpp binary_data.hpp \
mixed.hpp table.hpp table_ref.hpp table_basic_fwd.hpp table_accessors.hpp table_basic.hpp \
table_view.hpp table_view_basic.hpp table_macros.hpp group.hpp group_shared.hpp query.hpp \
query_conditions.hpp lang_bind_helper.hpp tightdb_nmmintrin.h replication.hpp

lib_LIBRARIES = libtightdb.a
Expand Down
65 changes: 50 additions & 15 deletions src/tightdb/alloc.cpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,72 @@
#include <cerrno>
#include <cstdlib>
#include <stdexcept>
#include <algorithm>

#include <tightdb/alloc_slab.hpp>

using namespace std;
using namespace tightdb;


// FIXME: Casting a pointers to std::size_t is inherently
// nonportable. For example, systems exist where pointers are 64 bits
// and std::size_t is 32. One idea would be to use a different type
// for refs such as std::uintptr_t, the problem with this one is that
// while it is described by the C++11 standard it is not required to
// be present. C++03 does not even mention it. A real working solution
// will be to introduce a new name for the type of refs. The typedef
// can then be made as complex as required to pick out an appropriate
// type on any supported platform.
//
// A better solution may be to use an instance of SlabAlloc. The main
// problem is that SlabAlloc is not thread-safe. Another problem is
// that its free-list management is currently exceedingly slow do to
// linear searches. Another problem is that it is prone to general
// memory corruption due to lack of exception safety when upding
// free-lists. But these problems must be fixed anyway.


namespace {

// For use with free-standing objects (objects that are not part of a
// TightDB group)
/// For use with free-standing objects (objects that are not part of a
/// TightDB group)
///
/// Note that it is essential that this class is stateless as it may
/// be used by multiple threads. Although it has m_replication, this
/// is not a problem, as there is no way to modify it, so it will
/// remain zero.
class DefaultAllocator: public tightdb::Allocator {
public:
MemRef alloc(size_t size) TIGHTDB_OVERRIDE
{
char* addr = static_cast<char*>(malloc(size));
if (TIGHTDB_LIKELY(addr))
return MemRef(addr, reinterpret_cast<size_t>(addr));
TIGHTDB_ASSERT(errno == ENOMEM);
throw bad_alloc();
if (TIGHTDB_UNLIKELY(!addr)) {
TIGHTDB_ASSERT(errno == ENOMEM);
throw bad_alloc();
}
#ifdef TIGHTDB_ALLOC_SET_ZERO
fill(addr, addr+size, 0);
#endif
return MemRef(addr, reinterpret_cast<size_t>(addr));
}

MemRef realloc_(ref_type, const char* addr, size_t size) TIGHTDB_OVERRIDE
MemRef realloc_(ref_type, const char* addr, size_t old_size, size_t new_size) TIGHTDB_OVERRIDE
{
char* new_addr = static_cast<char*>(realloc(const_cast<char*>(addr), size));
if (TIGHTDB_LIKELY(new_addr))
return MemRef(new_addr, reinterpret_cast<size_t>(new_addr));
TIGHTDB_ASSERT(errno == ENOMEM);
throw bad_alloc();
char* new_addr = static_cast<char*>(realloc(const_cast<char*>(addr), new_size));
if (TIGHTDB_UNLIKELY(!new_addr)) {
TIGHTDB_ASSERT(errno == ENOMEM);
throw bad_alloc();
}
#ifdef TIGHTDB_ALLOC_SET_ZERO
fill(new_addr+old_size, new_addr+new_size, 0);
#else
static_cast<void>(old_size);
#endif
return MemRef(new_addr, reinterpret_cast<size_t>(new_addr));
}

void free_(ref_type, const char* addr) TIGHTDB_OVERRIDE
void free_(ref_type, const char* addr) TIGHTDB_NOEXCEPT TIGHTDB_OVERRIDE
{
free(const_cast<char*>(addr));
}
Expand All @@ -52,12 +86,13 @@ class DefaultAllocator: public tightdb::Allocator {
#endif
};

DefaultAllocator default_alloc;

} // anonymous namespace



Allocator& Allocator::get_default() TIGHTDB_NOEXCEPT
{
static DefaultAllocator alloc;
return alloc;
return default_alloc;
}
27 changes: 8 additions & 19 deletions src/tightdb/alloc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,6 @@ struct MemRef {
ref_type m_ref;
};

// FIXME: Casting a pointer to std::size_t is inherently nonportable
// (see the default definition of Allocator::alloc()). For example,
// systems exist where pointers are 64 bits and std::size_t is 32. One
// idea would be to use a different type for refs such as
// std::uintptr_t, the problem with this one is that while it is
// described by the C++11 standard it is not required to be
// present. C++03 does not even mention it. A real working solution
// will be to introduce a new name for the type of refs. The typedef
// can then be made as complex as required to pick out an appropriate
// type on any supported platform.


/// The common interface for TightDB allocators.
///
Expand All @@ -87,16 +76,16 @@ class Allocator {
///
/// \throw std::bad_alloc If insufficient memory was available.
///
/// Note: The underscore was added because the name \c realloc
/// Note: The underscore has been added because the name `realloc`
/// would conflict with a macro on the Windows platform.
virtual MemRef realloc_(ref_type ref, const char* addr, std::size_t size) = 0;
virtual MemRef realloc_(ref_type ref, const char* addr, std::size_t old_size,
std::size_t new_size) = 0;

// FIXME: SlabAlloc::free_() should be modified such than this
// method never throws.
/// Release the specified chunk of memory.
///
/// Note: The underscore was added because the name \c free would
/// conflict with a macro on the Windows platform.
virtual void free_(ref_type, const char* addr) = 0;
/// Note: The underscore has been added because the name `free
/// would conflict with a macro on the Windows platform.
virtual void free_(ref_type, const char* addr) TIGHTDB_NOEXCEPT = 0;

/// Map the specified \a ref to the corresponding memory
/// address. Note that if is_read_only(ref) returns true, then the
Expand All @@ -118,7 +107,7 @@ class Allocator {
/// therefore, is not part of an actual database.
static Allocator& get_default() TIGHTDB_NOEXCEPT;

virtual ~Allocator() {}
virtual ~Allocator() TIGHTDB_NOEXCEPT {}

#ifdef TIGHTDB_DEBUG
virtual void Verify() const = 0;
Expand Down
Loading