Skip to content
Browse files

fixes for win32

  • Loading branch information...
1 parent ea034ae commit 58173a43d05115d1e642285ca37a12f518fcef5a @cruppstahl cruppstahl committed Nov 29, 2011
View
536 src/backend.h
@@ -1,272 +1,264 @@
-/*
- * Copyright (C) 2005-2010 Christoph Rupp (chris@crupp.de).
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * See files COPYING.* for License information.
- */
-
-/**
- * @brief a base-"class" for a generic database backend
- *
- */
-
-#ifndef HAM_BACKEND_H__
-#define HAM_BACKEND_H__
-
-#include "internal_fwd_decl.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
-* @defgroup ham_cb_status hamsterdb Backend Node/Page Enumerator Status Codes
-* @{
-*/
-
-/** continue with the traversal */
-#define CB_CONTINUE 0
-/** do not not descend another level (or descend from page to key traversal) */
-#define CB_DO_NOT_DESCEND 1
-/** stop the traversal entirely */
-#define CB_STOP 2
-
-/**
- * @}
- */
-
-
-/**
- * a callback function for enumerating the index nodes/pages using the
- * @ref ham_backend_t::_fun_enumerate callback/method.
- *
- * @param event one of the @ref ham_cb_event state codes
- *
- * @return one of the @ref ham_cb_status values or a @ref ham_status_codes
- * error code when an error occurred.
- */
-typedef ham_status_t (*ham_enumerate_cb_t)(int event, void *param1,
- void *param2, void *context);
-
-/**
-* @defgroup ham_cb_event hamsterdb Backend Node/Page Enumerator State Codes
-* @{
-*/
-
-/** descend one level; param1 is an integer value with the new level */
-#define ENUM_EVENT_DESCEND 1
-
-/** start of a new page; param1 points to the page */
-#define ENUM_EVENT_PAGE_START 2
-
-/** end of a new page; param1 points to the page */
-#define ENUM_EVENT_PAGE_STOP 3
-
-/** an item in the page; param1 points to the key; param2 is the index
- * of the key in the page */
-#define ENUM_EVENT_ITEM 4
-
-/**
-* @}
-*/
-
-/**
- * the backend structure - these functions and members are "inherited"
- * by every other backend (i.e. btree, hashdb etc).
- */
-#define BACKEND_DECLARATIONS(clss) \
- /** \
- * create and initialize a new backend \
- * \
- * @remark this function is called after the @a Database structure \
- * and the file were created \
- * \
- * the @a flags are stored in the database; only transfer \
- * the persistent flags! \
- */ \
- ham_status_t (*_fun_create)(clss *be, ham_u16_t keysize, \
- ham_u32_t flags); \
- \
- /** \
- * open and initialize a backend \
- * \
- * @remark this function is called after the ham_db_structure \
- * was allocated and the file was opened \
- */ \
- ham_status_t (*_fun_open)(clss *be, ham_u32_t flags); \
- \
- /** \
- * close the backend \
- * \
- * @remark this function is called before the file is closed \
- */ \
- ham_status_t (*_fun_close)(clss *be); \
- \
- /** \
- * flush the backend \
- * \
- * @remark this function is called during ham_flush \
- */ \
- ham_status_t (*_fun_flush)(clss *be); \
- \
- /** \
- * find a key in the index \
- */ \
- ham_status_t (*_fun_find)(clss *be, ham_key_t *key, \
- ham_record_t *record, ham_u32_t flags); \
- \
- /** \
- * insert (or update) a key in the index \
- * \
- * the backend is responsible for inserting or updating the \
- * record. (see blob.h for blob management functions) \
- */ \
- ham_status_t (*_fun_insert)(clss *be, \
- ham_key_t *key, ham_record_t *record, ham_u32_t flags); \
- \
- /** \
- * erase a key in the index \
- */ \
- ham_status_t (*_fun_erase)(clss *be, ham_key_t *key, \
- ham_u32_t flags); \
- \
- /** \
- * iterate the whole tree and enumerate every item \
- */ \
- ham_status_t (*_fun_enumerate)(clss *be, \
- ham_enumerate_cb_t cb, void *context); \
- \
- /** \
- * verify the whole tree \
- */ \
- ham_status_t (*_fun_check_integrity)(clss *be); \
- \
- /** \
- * free all allocated resources \
- * \
- * @remark this function is called after _fun_close() \
- */ \
- ham_status_t (*_fun_delete)(clss *be); \
- \
- /** \
- * estimate the number of keys per page, given the keysize \
- */ \
- ham_status_t (*_fun_calc_keycount_per_page)(clss *be, \
- ham_size_t *keycount, ham_u16_t keysize); \
- \
- /** \
- * Close (and free) all cursors related to this database table. \
- */ \
- ham_status_t (*_fun_close_cursors)(clss *be, ham_u32_t flags); \
- \
- /** \
- * uncouple all cursors from a page \
- * \
- * @remark this is called whenever the page is deleted or \
- * becoming invalid \
- */ \
- ham_status_t (*_fun_uncouple_all_cursors)(clss *be, \
- ham_page_t *page, ham_size_t start); \
- \
- /** \
- * Remove all extended keys for the given @a page from the \
- * extended key cache. \
- */ \
- ham_status_t (*_fun_free_page_extkeys)(clss *be, \
- ham_page_t *page, ham_u32_t flags); \
- \
- /** \
- * pointer to the database object \
- */ \
- Database *_db; \
- \
- /** \
- * the last used record number \
- */ \
- ham_offset_t _recno; \
- \
- /** \
- * the keysize of this backend index \
- */ \
- ham_u16_t _keysize; \
- \
- /** \
- * flag if this backend has to be written to disk \
- */ \
- unsigned _dirty: 1; \
- \
- /** \
- * flag if this backend has been fully initialized \
- */ \
- unsigned _is_active: 1; \
- \
- /** \
- * the persistent flags of this backend index \
- */ \
- ham_u32_t _flags
-
-
-#include "packstart.h"
-
-/**
- * A generic backend structure, which has the same memory layout as
- * all other backends.
- *
- * @remark We're pre-declaring struct ham_backend_t and the typedef
- * to avoid syntax errors in @ref BACKEND_DECLARATIONS .
- *
- * @remark Since this structure is not persistent, we don't really
- * need packing; however, with Microsoft Visual C++ 8, the
- * offset of ham_backend_t::_flags (the last member) is not the same
- * as the offset of ham_btree_t::_flags, unless packing is enabled.
- */
-HAM_PACK_0 struct HAM_PACK_1 ham_backend_t
-{
- BACKEND_DECLARATIONS(ham_backend_t);
-} HAM_PACK_2;
-
-#include "packstop.h"
-
-/** convenience macro to get the database of a ham_backend_t-structure */
-#define be_get_db(be) (be)->_db
-
-/** get the keysize */
-#define be_get_keysize(be) (be)->_keysize
-
-/** set the keysize */
-#define be_set_keysize(be, ks) (be)->_keysize=(ks)
-
-/** get the flags */
-#define be_get_flags(be) (be)->_flags
-
-/** set the flags */
-#define be_set_flags(be, f) (be)->_flags=(f)
-
-/** get the last used record number */
-#define be_get_recno(be) (be)->_recno
-
-/** set the last used record number */
-#define be_set_recno(be, rn) (be)->_recno=(rn)
-
-/** get the dirty-flag */
-#define be_is_dirty(be) (be)->_dirty
-
-/** set the dirty-flag */
-#define be_set_dirty(be, d) (be)->_dirty=!!(d)
-
-/** get the active-flag */
-#define be_is_active(be) (be)->_is_active
-
-/** set the active-flag */
-#define be_set_active(be, d) (be)->_is_active=!!(d)
-
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif /* HAM_BACKEND_H__ */
+/*
+ * Copyright (C) 2005-2010 Christoph Rupp (chris@crupp.de).
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * See files COPYING.* for License information.
+ */
+
+/**
+ * @brief a base-"class" for a generic database backend
+ *
+ */
+
+#ifndef HAM_BACKEND_H__
+#define HAM_BACKEND_H__
+
+#include "internal_fwd_decl.h"
+
+/**
+* @defgroup ham_cb_status hamsterdb Backend Node/Page Enumerator Status Codes
+* @{
+*/
+
+/** continue with the traversal */
+#define CB_CONTINUE 0
+/** do not not descend another level (or descend from page to key traversal) */
+#define CB_DO_NOT_DESCEND 1
+/** stop the traversal entirely */
+#define CB_STOP 2
+
+/**
+ * @}
+ */
+
+
+/**
+ * a callback function for enumerating the index nodes/pages using the
+ * @ref ham_backend_t::_fun_enumerate callback/method.
+ *
+ * @param event one of the @ref ham_cb_event state codes
+ *
+ * @return one of the @ref ham_cb_status values or a @ref ham_status_codes
+ * error code when an error occurred.
+ */
+typedef ham_status_t (*ham_enumerate_cb_t)(int event, void *param1,
+ void *param2, void *context);
+
+/**
+* @defgroup ham_cb_event hamsterdb Backend Node/Page Enumerator State Codes
+* @{
+*/
+
+/** descend one level; param1 is an integer value with the new level */
+#define ENUM_EVENT_DESCEND 1
+
+/** start of a new page; param1 points to the page */
+#define ENUM_EVENT_PAGE_START 2
+
+/** end of a new page; param1 points to the page */
+#define ENUM_EVENT_PAGE_STOP 3
+
+/** an item in the page; param1 points to the key; param2 is the index
+ * of the key in the page */
+#define ENUM_EVENT_ITEM 4
+
+/**
+* @}
+*/
+
+/**
+ * the backend structure - these functions and members are "inherited"
+ * by every other backend (i.e. btree, hashdb etc).
+ */
+#define BACKEND_DECLARATIONS(clss) \
+ /** \
+ * create and initialize a new backend \
+ * \
+ * @remark this function is called after the @a Database structure \
+ * and the file were created \
+ * \
+ * the @a flags are stored in the database; only transfer \
+ * the persistent flags! \
+ */ \
+ ham_status_t (*_fun_create)(clss *be, ham_u16_t keysize, \
+ ham_u32_t flags); \
+ \
+ /** \
+ * open and initialize a backend \
+ * \
+ * @remark this function is called after the ham_db_structure \
+ * was allocated and the file was opened \
+ */ \
+ ham_status_t (*_fun_open)(clss *be, ham_u32_t flags); \
+ \
+ /** \
+ * close the backend \
+ * \
+ * @remark this function is called before the file is closed \
+ */ \
+ ham_status_t (*_fun_close)(clss *be); \
+ \
+ /** \
+ * flush the backend \
+ * \
+ * @remark this function is called during ham_flush \
+ */ \
+ ham_status_t (*_fun_flush)(clss *be); \
+ \
+ /** \
+ * find a key in the index \
+ */ \
+ ham_status_t (*_fun_find)(clss *be, ham_key_t *key, \
+ ham_record_t *record, ham_u32_t flags); \
+ \
+ /** \
+ * insert (or update) a key in the index \
+ * \
+ * the backend is responsible for inserting or updating the \
+ * record. (see blob.h for blob management functions) \
+ */ \
+ ham_status_t (*_fun_insert)(clss *be, \
+ ham_key_t *key, ham_record_t *record, ham_u32_t flags); \
+ \
+ /** \
+ * erase a key in the index \
+ */ \
+ ham_status_t (*_fun_erase)(clss *be, ham_key_t *key, \
+ ham_u32_t flags); \
+ \
+ /** \
+ * iterate the whole tree and enumerate every item \
+ */ \
+ ham_status_t (*_fun_enumerate)(clss *be, \
+ ham_enumerate_cb_t cb, void *context); \
+ \
+ /** \
+ * verify the whole tree \
+ */ \
+ ham_status_t (*_fun_check_integrity)(clss *be); \
+ \
+ /** \
+ * free all allocated resources \
+ * \
+ * @remark this function is called after _fun_close() \
+ */ \
+ ham_status_t (*_fun_delete)(clss *be); \
+ \
+ /** \
+ * estimate the number of keys per page, given the keysize \
+ */ \
+ ham_status_t (*_fun_calc_keycount_per_page)(clss *be, \
+ ham_size_t *keycount, ham_u16_t keysize); \
+ \
+ /** \
+ * Close (and free) all cursors related to this database table. \
+ */ \
+ ham_status_t (*_fun_close_cursors)(clss *be, ham_u32_t flags); \
+ \
+ /** \
+ * uncouple all cursors from a page \
+ * \
+ * @remark this is called whenever the page is deleted or \
+ * becoming invalid \
+ */ \
+ ham_status_t (*_fun_uncouple_all_cursors)(clss *be, \
+ ham_page_t *page, ham_size_t start); \
+ \
+ /** \
+ * Remove all extended keys for the given @a page from the \
+ * extended key cache. \
+ */ \
+ ham_status_t (*_fun_free_page_extkeys)(clss *be, \
+ ham_page_t *page, ham_u32_t flags); \
+ \
+ /** \
+ * pointer to the database object \
+ */ \
+ Database *_db; \
+ \
+ /** \
+ * the last used record number \
+ */ \
+ ham_offset_t _recno; \
+ \
+ /** \
+ * the keysize of this backend index \
+ */ \
+ ham_u16_t _keysize; \
+ \
+ /** \
+ * flag if this backend has to be written to disk \
+ */ \
+ unsigned _dirty: 1; \
+ \
+ /** \
+ * flag if this backend has been fully initialized \
+ */ \
+ unsigned _is_active: 1; \
+ \
+ /** \
+ * the persistent flags of this backend index \
+ */ \
+ ham_u32_t _flags
+
+
+#include "packstart.h"
+
+/**
+ * A generic backend structure, which has the same memory layout as
+ * all other backends.
+ *
+ * @remark We're pre-declaring struct ham_backend_t and the typedef
+ * to avoid syntax errors in @ref BACKEND_DECLARATIONS .
+ *
+ * @remark Since this structure is not persistent, we don't really
+ * need packing; however, with Microsoft Visual C++ 8, the
+ * offset of ham_backend_t::_flags (the last member) is not the same
+ * as the offset of ham_btree_t::_flags, unless packing is enabled.
+ */
+HAM_PACK_0 struct HAM_PACK_1 ham_backend_t
+{
+ BACKEND_DECLARATIONS(ham_backend_t);
+} HAM_PACK_2;
+
+#include "packstop.h"
+
+/** convenience macro to get the database of a ham_backend_t-structure */
+#define be_get_db(be) (be)->_db
+
+/** get the keysize */
+#define be_get_keysize(be) (be)->_keysize
+
+/** set the keysize */
+#define be_set_keysize(be, ks) (be)->_keysize=(ks)
+
+/** get the flags */
+#define be_get_flags(be) (be)->_flags
+
+/** set the flags */
+#define be_set_flags(be, f) (be)->_flags=(f)
+
+/** get the last used record number */
+#define be_get_recno(be) (be)->_recno
+
+/** set the last used record number */
+#define be_set_recno(be, rn) (be)->_recno=(rn)
+
+/** get the dirty-flag */
+#define be_is_dirty(be) (be)->_dirty
+
+/** set the dirty-flag */
+#define be_set_dirty(be, d) (be)->_dirty=!!(d)
+
+/** get the active-flag */
+#define be_is_active(be) (be)->_is_active
+
+/** set the active-flag */
+#define be_set_active(be, d) (be)->_is_active=!!(d)
+
+
+#endif /* HAM_BACKEND_H__ */
View
10 src/blob.h
@@ -19,14 +19,8 @@
#define HAM_BLOB_H__
#include "internal_fwd_decl.h"
-
#include "endianswap.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include "packstart.h"
/**
@@ -272,8 +266,4 @@ blob_duplicate_get_table(ham_env_t *env, ham_offset_t table_id,
dupe_table_t **ptable, ham_bool_t *needs_free);
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_BLOB_H__ */
View
8 src/btree.h
@@ -27,10 +27,6 @@
#include "db.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/**
* the backend structure for a b+tree
*
@@ -404,8 +400,4 @@ btree_copy_key_int2pub(Database *db, const btree_key_t *source,
ham_key_t *dest);
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_BTREE_H__ */
View
8 src/btree_cursor.h
@@ -35,10 +35,6 @@
#include "blob.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/**
* the Cursor structure for a b+tree cursor
*/
@@ -283,8 +279,4 @@ extern void
btree_cursor_close(btree_cursor_t *cursor);
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_BTREE_CURSORS_H__ */
View
8 src/btree_key.h
@@ -20,10 +20,6 @@
#include "internal_fwd_decl.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include "packstart.h"
/**
@@ -182,8 +178,4 @@ key_erase_record(Database *db, btree_key_t *key,
ham_size_t dupe_id, ham_u32_t flags);
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_KEY_H__ */
View
8 src/btree_stats.h
@@ -19,10 +19,6 @@
#include "internal_fwd_decl.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/**
* get a reference to the statistics data of the given operation
*/
@@ -212,8 +208,4 @@ btree_stats_fill_ham_statistics_t(ham_env_t *env, Database *db,
ham_statistics_t *dst);
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_FREELIST_H__ */
View
10 src/cache.h
@@ -22,10 +22,6 @@
#include "internal_fwd_decl.h"
#include "env.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
/** CACHE_BUCKET_SIZE should be a prime number or similar, as it is used in
* a MODULO hash scheme */
@@ -282,12 +278,6 @@ class Cache
/** the buckets - a linked list of ham_page_t pointers */
std::vector<ham_page_t *> m_buckets;
-
};
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_CACHE_H__ */
View
9 src/changeset.h
@@ -20,10 +20,6 @@
#include "internal_fwd_decl.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/**
* The changeset class
@@ -75,9 +71,4 @@ class Changeset
};
-
-#ifdef __cplusplus
-} // extern "C" {
-#endif
-
#endif /* HAM_CHANGESET_H__ */
View
12 src/cursor.cc
@@ -100,10 +100,10 @@ Cursor::update_dupecache(ham_u32_t what)
dc->append(DupeCacheLine(false, op));
}
else if (txn_op_get_flags(op)&TXN_OP_INSERT_OW) {
- DupeCacheLine *e=dc->get_first_element();
ham_u32_t ref=txn_op_get_referenced_dupe(op);
if (ref) {
ham_assert(ref<=dc->get_count(), (""));
+ DupeCacheLine *e=dc->get_first_element();
(&e[ref-1])->set_txn_op(op);
}
else {
@@ -173,7 +173,7 @@ Cursor::couple_to_dupe(ham_u32_t dupe_id)
if (e->use_btree()) {
btree_cursor_t *btc=get_btree_cursor();
couple_to_btree();
- btree_cursor_set_dupe_id(btc, e->get_btree_dupe_idx());
+ btree_cursor_set_dupe_id(btc, (ham_size_t)e->get_btree_dupe_idx());
}
else {
ham_assert(e->get_txn_op()!=0, (""));
@@ -1067,14 +1067,18 @@ Cursor::is_nil(int what)
{
switch (what) {
case CURSOR_BTREE:
- return (__btree_cursor_is_nil(get_btree_cursor()));
+ return (__btree_cursor_is_nil(get_btree_cursor())
+ ? true
+ : false);
case CURSOR_TXN:
return (txn_cursor_is_nil(get_txn_cursor()));
default:
ham_assert(what==0, (""));
/* TODO btree_cursor_is_nil is different from __btree_cursor_is_nil
* - refactor and clean up! */
- return (btree_cursor_is_nil(get_btree_cursor()));
+ return (btree_cursor_is_nil(get_btree_cursor())
+ ? true
+ : false);
}
}
View
23 src/cursor.h
@@ -86,30 +86,26 @@
#include "db.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/**
* A single line in the dupecache structure - can reference a btree
* record or a txn-op
*/
class DupeCacheLine
{
public:
- DupeCacheLine(ham_bool_t use_btree=true, ham_u64_t btree_dupeidx=0)
+ DupeCacheLine(bool use_btree=HAM_TRUE, ham_u64_t btree_dupeidx=0)
: m_use_btree(use_btree), m_btree_dupeidx(btree_dupeidx), m_op(0) {
ham_assert(use_btree==true, (""));
}
- DupeCacheLine(ham_bool_t use_btree, txn_op_t *op)
+ DupeCacheLine(bool use_btree, txn_op_t *op)
: m_use_btree(use_btree), m_btree_dupeidx(0), m_op(op) {
ham_assert(use_btree==false, (""));
}
/** Returns true if this cache entry is a duplicate in the btree */
ham_bool_t use_btree(void) {
- return (m_use_btree);
+ return ((ham_bool_t)m_use_btree);
}
/** Returns the btree duplicate index */
@@ -139,15 +135,14 @@ class DupeCacheLine
}
private:
- /** Are we using btree or txn duplicates? */
- ham_bool_t m_use_btree;
+ /** using btree or txn duplicates? */
+ bool m_use_btree;
/** The btree duplicate index (of the original btree dupe table) */
ham_u64_t m_btree_dupeidx;
/** The txn op structure */
txn_op_t *m_op;
-
};
@@ -164,7 +159,7 @@ class DupeCache {
/** retrieve number of elements in the cache */
ham_size_t get_count(void) {
- return (m_elements.size());
+ return ((ham_size_t)m_elements.size());
}
/** get an element from the cache */
@@ -278,7 +273,7 @@ class Cursor
/** Returns true if a cursor is coupled to a txn-op */
bool is_coupled_to_txnop(void) {
- return (get_flags()&_CURSOR_COUPLED_TO_TXN);
+ return ((get_flags()&_CURSOR_COUPLED_TO_TXN) ? true : false);
}
/** Couples the cursor to a btree key */
@@ -620,8 +615,4 @@ class Cursor
};
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_CURSORS_H__ */
View
9 src/db.h
@@ -30,11 +30,6 @@
#include "btree.h"
#include "mem.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/**
* a macro to cast pointers to u64 and vice versa to avoid compiler
* warnings if the sizes of ptr and u64 are not equal
@@ -1112,8 +1107,4 @@ db_erase_txn(Database *db, ham_txn_t *txn, ham_key_t *key, ham_u32_t flags,
struct txn_cursor_t *cursor);
-#ifdef __cplusplus
-} // extern "C" {
-#endif
-
#endif /* HAM_DB_H__ */
View
8 src/device.h
@@ -21,10 +21,6 @@
#include "internal_fwd_decl.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/**
* the device structure
*/
@@ -215,8 +211,4 @@ ham_device_new(mem_allocator_t *alloc, ham_env_t *env, int devtype);
#define HAM_DEVTYPE_CUSTOM 2
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_DEVICE_H__ */
View
8 src/endianswap.h
@@ -18,10 +18,6 @@
#ifndef HAM_ENDIANSWAP_H__
#define HAM_ENDIANSWAP_H__
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/**
* byte swapping macros - we use little endian
@@ -71,8 +67,4 @@ extern "C" {
(((x) & 0x00000000000000ffull) << 56))
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_ENDIANSWAP_H__ */
View
2 src/env.cc
@@ -1675,7 +1675,7 @@ __purge_cache_max20(ham_env_t *env)
ham_status_t st;
ham_page_t *page;
Cache *cache=env_get_cache(env);
- unsigned i, max_pages=cache->get_cur_elements();
+ unsigned i, max_pages=(unsigned)cache->get_cur_elements();
/* don't remove pages from the cache if it's an in-memory database */
if ((env_get_rt_flags(env)&HAM_IN_MEMORY_DB))
View
9 src/env.h
@@ -28,11 +28,6 @@
#include "page.h"
#include "changeset.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#define OFFSETOF(type, member) ((size_t) &((type *)0)->member)
/**
@@ -672,8 +667,4 @@ extern ham_status_t
env_purge_cache(ham_env_t *env);
-#ifdef __cplusplus
-} // extern "C" {
-#endif
-
#endif /* HAM_ENV_H__ */
View
7 src/error.h
@@ -20,10 +20,6 @@
#include <ham/hamsterdb.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* function prototypes
*/
@@ -89,8 +85,5 @@ extern void (*ham_test_abort)(void);
dbg_verify_failed f; \
dbg_unlock(); \
}
-#ifdef __cplusplus
-} // extern "C"
-#endif
#endif /* HAM_ERROR_H__ */
View
15 src/extkeys.h
@@ -24,11 +24,6 @@
#include "mem.h"
#include "env.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#define EXTKEY_MAX_AGE 25
/**
@@ -86,7 +81,7 @@ class ExtKeyCache
void visit(const extkey_t *node) {
}
- void free(const extkey_t *node) {
+ void free_node(const extkey_t *node) {
allocator_free(env_get_allocator(m_env), node);
}
@@ -96,11 +91,11 @@ class ExtKeyCache
bool remove_if(const extkey_t *node) {
if (m_removeall) {
- free(node);
+ free_node(node);
return (true);
}
if (env_get_txn_id(m_env)-node->_age>EXTKEY_MAX_AGE) {
- free(node);
+ free_node(node);
return (true);
}
return (false);
@@ -170,8 +165,4 @@ extern ham_status_t
extkey_remove(Database *db, ham_offset_t blobid);
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_EXTKEYS_H__ */
View
8 src/freelist.h
@@ -21,10 +21,6 @@
#include "freelist_statistics.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/**
* an entry in the freelist cache
*/
@@ -490,8 +486,4 @@ freel_check_area_is_allocated(ham_env_t *env, Database *db,
ham_offset_t address, ham_size_t size);
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_FREELIST_H__ */
View
664 src/freelist_statistics.h
@@ -1,340 +1,324 @@
-/*
- * Copyright (C) 2005-2010 Christoph Rupp (chris@crupp.de).
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * See files COPYING.* for License information.
- */
-
-/**
- * @brief freelist statistics structures, functions and macros
- *
- */
-
-#ifndef HAM_FREELIST_STATISTICS_H__
-#define HAM_FREELIST_STATISTICS_H__
-
-#include "internal_fwd_decl.h"
-
-#include <ham/hamsterdb_stats.h>
-
-
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-
-#include "packstart.h"
-
-/**
-We keep track of VERY first free slot index + free slot index
-pointing at last (~ supposed largest) free range + 'utilization' of the
-range between FIRST and LAST as a ratio of number of free slots in
-there vs. total number of slots in that range (giving us a 'fill'
-ratio) + a fragmentation indication, determined by counting the number
-of freelist slot searches that FAILed vs. SUCCEEDed within the
-first..last range, when the search begun at the 'first' position
-(a FAIL here meaning the freelist scan did not deliver a free slot
-WITHIN the first..last range, i.e. it has scanned this entire range
-without finding anything suitably large).
-
-Note that the free_fill in here is AN ESTIMATE.
- */
-typedef HAM_PACK_0 struct HAM_PACK_1 freelist_slotsize_stats_t
-{
- ham_u32_t first_start;
- /* reserved: */
- ham_u32_t free_fill;
- ham_u32_t epic_fail_midrange;
- ham_u32_t epic_win_midrange;
-
- /**
- * number of scans per size range
- */
- ham_u32_t scan_count;
- ham_u32_t ok_scan_count;
-
- /**
- * summed cost ('duration') of all scans per size range.
- */
- ham_u32_t scan_cost;
- ham_u32_t ok_scan_cost;
-
-} HAM_PACK_2 freelist_slotsize_stats_t;
-
-#include "packstop.h"
-
-
-#include "packstart.h"
-
-/**
- * freelist statistics as they are persisted on disc.
- *
- * Stats are kept with each freelist entry record, but we also keep
- * some derived data in the nonpermanent space with each freelist:
- * it's not required to keep a freelist page in cache just so the
- * statistics + our operational mode combined can tell us it's a waste
- * of time to go there.
- */
-typedef HAM_PACK_0 struct HAM_PACK_1 freelist_page_statistics_t
-{
- /**
- k-way statistics store which stores requested space slot size related data.
-
- The data is stored in @ref HAM_FREELIST_SLOT_SPREAD different buckets
- which partition the statistical info across the entire space request range
- by using a logarithmic partitioning function.
-
- That way, very accurate, independent statistics can be stores for both
- small, medium and large sized space requests, so that the freelist hinter
- can deliver a high quality search hint for various requests.
- */
- freelist_slotsize_stats_t per_size[HAM_FREELIST_SLOT_SPREAD];
-
- /**
- * (bit) offset which tells us which free slot is the EVER LAST
- * created one; after all, freelistpage:maxbits is a scandalously
- * optimistic lie: all it tells us is how large the freelist page
- * _itself_ can grow, NOT how many free slots we actually have
- * _alive_ in there.
- *
- * 0: special case, meaning: not yet initialized...
- */
- ham_u32_t last_start;
-
- /**
- * total number of available bits in the page ~ all the chunks which
- * actually represent a chunk in the DB storage space.
- *
- * (Note that a freelist can be larger (_max_bits) than the actual
- * number of storage pages currently sitting in the database file.)
- *
- * The number of chunks already in use in the database therefore ~
- * persisted_bits - _allocated_bits.
- */
- ham_u32_t persisted_bits;
-
- /**
- * count the number of insert operations where this freelist page
- * played a role
- */
- ham_u32_t insert_count;
- /**
- * count the number of delete operations where this freelist page
- * played a role
- */
- ham_u32_t delete_count;
- /**
- * count the number of times the freelist size was adjusted as new storage space
- * was added to the database.
- *
- * This can occur in two situations: either when a new page is allocated and
- * a part of it is marked as 'free' as it is not used up in its entirety, or
- * when a page is released (freed) which was previously allocated without involvement
- * of the freelist manager (this can happen when new HUGE BOBs are inserted, then
- * erased again).
- */
- ham_u32_t extend_count;
- /**
- * count the number of times a freelist free space search (alloc operation) failed
- * to find any suitably large free space in this freelist page.
- */
- ham_u32_t fail_count;
- /**
- * count the number of find operations where this freelist page
- * played a role
- */
- ham_u32_t search_count;
-
- /**
- Tracks the ascent of the various statistical counters in here in order to prevent
- integer overflow.
-
- This is accomplished by tracking the summed hinting costs over time in this variable
- and when that number surpasses a predetermined 'high water mark', all statistics
- counters are 'rescaled', which scales down all counters and related data so that new
- data can be added again multiple times before the risk of integer overflow may occur
- again.
-
- The goal here is to balance usable statistical numerical data while assuring integer
- overflows @e never happen for @e any of the statistics items.
- */
- ham_u32_t rescale_monitor;
-
-} HAM_PACK_2 freelist_page_statistics_t;
-
-#include "packstop.h"
-
-
-
-/**
- * freelist algorithm specific run-time info per freelist entry (page)
- */
-struct runtime_statistics_pagedata_t
-{
- freelist_page_statistics_t _persisted_stats;
-
- ham_bool_t _dirty;
-};
-
-
-
-
-
-
-
-
-struct freelist_hints_t
-{
- /** [in/out] INCLUSIVE bound: where free slots start */
- ham_u32_t startpos;
- /** [in/out] EXCLUSIVE bound: where free slots end */
- ham_u32_t endpos;
- /** [in/out] suggested search/skip probe distance */
- ham_u32_t skip_distance;
- /** [in/out] suggested DAM mgt_mode for the remainder of this request */
- ham_u16_t mgt_mode;
- /** [input] whether or not we are looking for aligned storage */
- ham_bool_t aligned;
- /** [input] the lower bound address of the slot we're looking for. Usually zero(0). */
- ham_offset_t lower_bound_address;
- /** [input] the size of the slot we're looking for */
- ham_size_t size_bits;
- /** [input] the size of a freelist page (in chunks) */
- ham_size_t freelist_pagesize_bits;
- /**
- [input] the number of (rounded up) pages we need to fulfill the request; 1 for
- 'regular' (non-huge) requests.
-
- Cannot be 0, as that is only correct for a zero-length request.
- */
- ham_size_t page_span_width;
-
- /** [feedback] cost tracking for our statistics */
- ham_size_t cost;
-};
-
-
-struct freelist_global_hints_t
-{
- /**
- [in/out] INCLUSIVE bound: at which freelist page entry to start
- looking
- */
- ham_u32_t start_entry;
-
- /**
- [in/out] how many entries to skip
- *
- * You'd expect this to be 1 all the time, but in some modes it is
- * expected that a 'semi-random' scan will yield better results;
- * especially when we combine that approach with a limited number of
- * rounds before we switch to SEQUENTIAL+FAST mode.
- *
- * By varying the offset (start) for each operation we then are
- * assured that all freelist pages will be perused once in a while,
- * while we still cut down on freelist entry scanning quite a bit.
- */
- ham_u32_t skip_step;
-
- /** [in/out] and the accompanying start offset for the SRNG */
- ham_u32_t skip_init_offset;
-
- /**
- [in/out] upper bound on number of rounds ~ entries to scan: when
- to stop looking
- */
- ham_u32_t max_rounds;
-
- /** [in/out] suggested DAM mgt_mode for the remainder of this request */
- ham_u16_t mgt_mode;
-
- /**
- [output] whether or not we are looking for a chunk of storage
- spanning multiple pages ('huge blobs'): lists the number
- of (rounded up) pages we need to fulfill the request; 1 for
- 'regular' (non-huge) requests.
-
- Cannot be 0, as that is only correct for a zero-length request.
- */
- ham_size_t page_span_width;
-
- /** [input] whether or not we are looking for aligned storage */
- ham_bool_t aligned;
-
- /** [input] the lower bound address of the slot we're looking for. Usually zero(0). */
- ham_offset_t lower_bound_address;
-
- /** [input] the size of the slot we're looking for */
- ham_size_t size_bits;
-
- /** [input] the size of a freelist page (in chunks) */
- ham_size_t freelist_pagesize_bits;
-};
-
-
-
-
-
-
-
-
-
-
-
-
-
-extern void
-db_update_freelist_globalhints_no_hit(ham_device_t *dev, ham_env_t *env,
- freelist_entry_t *entry, freelist_hints_t *hints);
-
-
-
-extern void
-db_update_freelist_stats_edit(ham_device_t *dev, ham_env_t *env, freelist_entry_t *entry,
- freelist_payload_t *f,
- ham_u32_t position,
- ham_size_t size_bits,
- ham_bool_t free_these,
- freelist_hints_t *hints);
-
-extern void
-db_update_freelist_stats_fail(ham_device_t *dev, ham_env_t *env, freelist_entry_t *entry,
- freelist_payload_t *f,
- freelist_hints_t *hints);
-
-extern void
-db_update_freelist_stats(ham_device_t *dev, ham_env_t *env, freelist_entry_t *entry,
- freelist_payload_t *f,
- ham_u32_t position,
- freelist_hints_t *hints);
-
-extern void
-db_get_freelist_entry_hints(freelist_hints_t *dst, ham_device_t *dev, ham_env_t *env,
- freelist_entry_t *entry);
-
-extern void
-db_get_global_freelist_hints(freelist_global_hints_t *dst, ham_device_t *dev, ham_env_t *env);
-
-
-
-
-extern ham_status_t
-stats_fill_freel_statistics_t(ham_env_t *env, ham_statistics_t *dst);
-
-
-
-
-
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif /* HAM_FREELIST_H__ */
+/*
+ * Copyright (C) 2005-2010 Christoph Rupp (chris@crupp.de).
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * See files COPYING.* for License information.
+ */
+
+/**
+ * @brief freelist statistics structures, functions and macros
+ *
+ */
+
+#ifndef HAM_FREELIST_STATISTICS_H__
+#define HAM_FREELIST_STATISTICS_H__
+
+#include "internal_fwd_decl.h"
+
+#include <ham/hamsterdb_stats.h>
+
+
+#include "packstart.h"
+
+/**
+We keep track of VERY first free slot index + free slot index
+pointing at last (~ supposed largest) free range + 'utilization' of the
+range between FIRST and LAST as a ratio of number of free slots in
+there vs. total number of slots in that range (giving us a 'fill'
+ratio) + a fragmentation indication, determined by counting the number
+of freelist slot searches that FAILed vs. SUCCEEDed within the
+first..last range, when the search begun at the 'first' position
+(a FAIL here meaning the freelist scan did not deliver a free slot
+WITHIN the first..last range, i.e. it has scanned this entire range
+without finding anything suitably large).
+
+Note that the free_fill in here is AN ESTIMATE.
+ */
+typedef HAM_PACK_0 struct HAM_PACK_1 freelist_slotsize_stats_t
+{
+ ham_u32_t first_start;
+ /* reserved: */
+ ham_u32_t free_fill;
+ ham_u32_t epic_fail_midrange;
+ ham_u32_t epic_win_midrange;
+
+ /**
+ * number of scans per size range
+ */
+ ham_u32_t scan_count;
+ ham_u32_t ok_scan_count;
+
+ /**
+ * summed cost ('duration') of all scans per size range.
+ */
+ ham_u32_t scan_cost;
+ ham_u32_t ok_scan_cost;
+
+} HAM_PACK_2 freelist_slotsize_stats_t;
+
+#include "packstop.h"
+
+
+#include "packstart.h"
+
+/**
+ * freelist statistics as they are persisted on disc.
+ *
+ * Stats are kept with each freelist entry record, but we also keep
+ * some derived data in the nonpermanent space with each freelist:
+ * it's not required to keep a freelist page in cache just so the
+ * statistics + our operational mode combined can tell us it's a waste
+ * of time to go there.
+ */
+typedef HAM_PACK_0 struct HAM_PACK_1 freelist_page_statistics_t
+{
+ /**
+ k-way statistics store which stores requested space slot size related data.
+
+ The data is stored in @ref HAM_FREELIST_SLOT_SPREAD different buckets
+ which partition the statistical info across the entire space request range
+ by using a logarithmic partitioning function.
+
+ That way, very accurate, independent statistics can be stores for both
+ small, medium and large sized space requests, so that the freelist hinter
+ can deliver a high quality search hint for various requests.
+ */
+ freelist_slotsize_stats_t per_size[HAM_FREELIST_SLOT_SPREAD];
+
+ /**
+ * (bit) offset which tells us which free slot is the EVER LAST
+ * created one; after all, freelistpage:maxbits is a scandalously
+ * optimistic lie: all it tells us is how large the freelist page
+ * _itself_ can grow, NOT how many free slots we actually have
+ * _alive_ in there.
+ *
+ * 0: special case, meaning: not yet initialized...
+ */
+ ham_u32_t last_start;
+
+ /**
+ * total number of available bits in the page ~ all the chunks which
+ * actually represent a chunk in the DB storage space.
+ *
+ * (Note that a freelist can be larger (_max_bits) than the actual
+ * number of storage pages currently sitting in the database file.)
+ *
+ * The number of chunks already in use in the database therefore ~
+ * persisted_bits - _allocated_bits.
+ */
+ ham_u32_t persisted_bits;
+
+ /**
+ * count the number of insert operations where this freelist page
+ * played a role
+ */
+ ham_u32_t insert_count;
+ /**
+ * count the number of delete operations where this freelist page
+ * played a role
+ */
+ ham_u32_t delete_count;
+ /**
+ * count the number of times the freelist size was adjusted as new storage space
+ * was added to the database.
+ *
+ * This can occur in two situations: either when a new page is allocated and
+ * a part of it is marked as 'free' as it is not used up in its entirety, or
+ * when a page is released (freed) which was previously allocated without involvement
+ * of the freelist manager (this can happen when new HUGE BOBs are inserted, then
+ * erased again).
+ */
+ ham_u32_t extend_count;
+ /**
+ * count the number of times a freelist free space search (alloc operation) failed
+ * to find any suitably large free space in this freelist page.
+ */
+ ham_u32_t fail_count;
+ /**
+ * count the number of find operations where this freelist page
+ * played a role
+ */
+ ham_u32_t search_count;
+
+ /**
+ Tracks the ascent of the various statistical counters in here in order to prevent
+ integer overflow.
+
+ This is accomplished by tracking the summed hinting costs over time in this variable
+ and when that number surpasses a predetermined 'high water mark', all statistics
+ counters are 'rescaled', which scales down all counters and related data so that new
+ data can be added again multiple times before the risk of integer overflow may occur
+ again.
+
+ The goal here is to balance usable statistical numerical data while assuring integer
+ overflows @e never happen for @e any of the statistics items.
+ */
+ ham_u32_t rescale_monitor;
+
+} HAM_PACK_2 freelist_page_statistics_t;
+
+#include "packstop.h"
+
+
+
+/**
+ * freelist algorithm specific run-time info per freelist entry (page)
+ */
+struct runtime_statistics_pagedata_t
+{
+ freelist_page_statistics_t _persisted_stats;
+
+ ham_bool_t _dirty;
+};
+
+
+
+
+
+
+
+
+struct freelist_hints_t
+{
+ /** [in/out] INCLUSIVE bound: where free slots start */
+ ham_u32_t startpos;
+ /** [in/out] EXCLUSIVE bound: where free slots end */
+ ham_u32_t endpos;
+ /** [in/out] suggested search/skip probe distance */
+ ham_u32_t skip_distance;
+ /** [in/out] suggested DAM mgt_mode for the remainder of this request */
+ ham_u16_t mgt_mode;
+ /** [input] whether or not we are looking for aligned storage */
+ ham_bool_t aligned;
+ /** [input] the lower bound address of the slot we're looking for. Usually zero(0). */
+ ham_offset_t lower_bound_address;
+ /** [input] the size of the slot we're looking for */
+ ham_size_t size_bits;
+ /** [input] the size of a freelist page (in chunks) */
+ ham_size_t freelist_pagesize_bits;
+ /**
+ [input] the number of (rounded up) pages we need to fulfill the request; 1 for
+ 'regular' (non-huge) requests.
+
+ Cannot be 0, as that is only correct for a zero-length request.
+ */
+ ham_size_t page_span_width;
+
+ /** [feedback] cost tracking for our statistics */
+ ham_size_t cost;
+};
+
+
+struct freelist_global_hints_t
+{
+ /**
+ [in/out] INCLUSIVE bound: at which freelist page entry to start
+ looking
+ */
+ ham_u32_t start_entry;
+
+ /**
+ [in/out] how many entries to skip
+ *
+ * You'd expect this to be 1 all the time, but in some modes it is
+ * expected that a 'semi-random' scan will yield better results;
+ * especially when we combine that approach with a limited number of
+ * rounds before we switch to SEQUENTIAL+FAST mode.
+ *
+ * By varying the offset (start) for each operation we then are
+ * assured that all freelist pages will be perused once in a while,
+ * while we still cut down on freelist entry scanning quite a bit.
+ */
+ ham_u32_t skip_step;
+
+ /** [in/out] and the accompanying start offset for the SRNG */
+ ham_u32_t skip_init_offset;
+
+ /**
+ [in/out] upper bound on number of rounds ~ entries to scan: when
+ to stop looking
+ */
+ ham_u32_t max_rounds;
+
+ /** [in/out] suggested DAM mgt_mode for the remainder of this request */
+ ham_u16_t mgt_mode;
+
+ /**
+ [output] whether or not we are looking for a chunk of storage
+ spanning multiple pages ('huge blobs'): lists the number
+ of (rounded up) pages we need to fulfill the request; 1 for
+ 'regular' (non-huge) requests.
+
+ Cannot be 0, as that is only correct for a zero-length request.
+ */
+ ham_size_t page_span_width;
+
+ /** [input] whether or not we are looking for aligned storage */
+ ham_bool_t aligned;
+
+ /** [input] the lower bound address of the slot we're looking for. Usually zero(0). */
+ ham_offset_t lower_bound_address;
+
+ /** [input] the size of the slot we're looking for */
+ ham_size_t size_bits;
+
+ /** [input] the size of a freelist page (in chunks) */
+ ham_size_t freelist_pagesize_bits;
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+extern void
+db_update_freelist_globalhints_no_hit(ham_device_t *dev, ham_env_t *env,
+ freelist_entry_t *entry, freelist_hints_t *hints);
+
+
+
+extern void
+db_update_freelist_stats_edit(ham_device_t *dev, ham_env_t *env, freelist_entry_t *entry,
+ freelist_payload_t *f,
+ ham_u32_t position,
+ ham_size_t size_bits,
+ ham_bool_t free_these,
+ freelist_hints_t *hints);
+
+extern void
+db_update_freelist_stats_fail(ham_device_t *dev, ham_env_t *env, freelist_entry_t *entry,
+ freelist_payload_t *f,
+ freelist_hints_t *hints);
+
+extern void
+db_update_freelist_stats(ham_device_t *dev, ham_env_t *env, freelist_entry_t *entry,
+ freelist_payload_t *f,
+ ham_u32_t position,
+ freelist_hints_t *hints);
+
+extern void
+db_get_freelist_entry_hints(freelist_hints_t *dst, ham_device_t *dev, ham_env_t *env,
+ freelist_entry_t *entry);
+
+extern void
+db_get_global_freelist_hints(freelist_global_hints_t *dst, ham_device_t *dev, ham_env_t *env);
+
+
+
+
+extern ham_status_t
+stats_fill_freel_statistics_t(ham_env_t *env, ham_statistics_t *dst);
+
+
+#endif /* HAM_FREELIST_H__ */
View
7 src/freelist_v2.h
@@ -16,12 +16,5 @@
#ifndef HAM_FREELIST32_H__
#define HAM_FREELIST32_H__
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
#endif /* HAM_FREELIST_H__ */
View
210 src/internal_fwd_decl.h
@@ -1,109 +1,101 @@
-/*
- * Copyright (C) 2005-2011 Christoph Rupp (chris@crupp.de).
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * See files COPYING.* for License information.
- */
-
-/**
- * @brief provides forward declarations of internally used types
- *
- * This header file provides these forward declarations to prevent several
- * cyclic dependencies; in particular, the @ref ham_page_t is a type used
- * throughout, but a @ref ham_page_t contains several other types, which
- * again reference @ref ham_page_t pointers either directly or indirectly.
- *
- * To solve this self-referential issue once and for all, all major hamster
- * internal types are forward declared here; when the code requires the actual
- * implementation of a type it can include the related header file any time it
- * wishes.
- *
- * @remark This way of solving the cyclic dependency conundrum has the added
- * benefit of having a single, well known spot where the actual
- * 'typedef' lines reside, so there's zero risk of 'double defined types'.
- */
-
-#ifndef HAM_FWD_DECL_CMN_TYPES_H__
-#define HAM_FWD_DECL_CMN_TYPES_H__
-
-#include <ham/hamsterdb.h>
-#include <ham/hamsterdb_int.h>
-
-#include "config.h"
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-class Cursor;
-
-class Database;
-
-struct ham_page_t;
-typedef struct ham_page_t ham_page_t;
-
-struct ham_backend_t;
-typedef struct ham_backend_t ham_backend_t;
-
-class Cache;
-
-class Log;
-
-class Journal;
-
-struct extkey_t;
-typedef struct extkey_t extkey_t;
-
-class ExtKeyCache;
-
-struct freelist_entry_t;
-typedef struct freelist_entry_t freelist_entry_t;
-
-struct freelist_cache_t;
-typedef struct freelist_cache_t freelist_cache_t;
-
-struct freelist_hints_t;
-typedef struct freelist_hints_t freelist_hints_t;
-
-struct runtime_statistics_pagedata_t;
-typedef struct runtime_statistics_pagedata_t runtime_statistics_pagedata_t;
-
-struct freelist_global_hints_t;
-typedef struct freelist_global_hints_t freelist_global_hints_t;
-
-struct find_hints_t;
-typedef struct find_hints_t find_hints_t;
-
-struct insert_hints_t;
-typedef struct insert_hints_t insert_hints_t;
-
-struct erase_hints_t;
-typedef struct erase_hints_t erase_hints_t;
-
-
-#include "packstart.h"
-
-struct freelist_payload_t;
-typedef struct freelist_payload_t freelist_payload_t;
-
-#include "packstop.h"
-
-
-#include "packstart.h"
-
-struct btree_key_t;
-typedef struct btree_key_t btree_key_t;
-
-#include "packstop.h"
-
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif
+/*
+ * Copyright (C) 2005-2011 Christoph Rupp (chris@crupp.de).
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * See files COPYING.* for License information.
+ */
+
+/**
+ * @brief provides forward declarations of internally used types
+ *
+ * This header file provides these forward declarations to prevent several
+ * cyclic dependencies; in particular, the @ref ham_page_t is a type used
+ * throughout, but a @ref ham_page_t contains several other types, which
+ * again reference @ref ham_page_t pointers either directly or indirectly.
+ *
+ * To solve this self-referential issue once and for all, all major hamster
+ * internal types are forward declared here; when the code requires the actual
+ * implementation of a type it can include the related header file any time it
+ * wishes.
+ *
+ * @remark This way of solving the cyclic dependency conundrum has the added
+ * benefit of having a single, well known spot where the actual
+ * 'typedef' lines reside, so there's zero risk of 'double defined types'.
+ */
+
+#ifndef HAM_FWD_DECL_CMN_TYPES_H__
+#define HAM_FWD_DECL_CMN_TYPES_H__
+
+#include <ham/hamsterdb.h>
+#include <ham/hamsterdb_int.h>
+
+#include "config.h"
+
+
+class Cursor;
+
+class Database;
+
+struct ham_page_t;
+typedef struct ham_page_t ham_page_t;
+
+struct ham_backend_t;
+typedef struct ham_backend_t ham_backend_t;
+
+class Cache;
+
+class Log;
+
+class Journal;
+
+struct extkey_t;
+typedef struct extkey_t extkey_t;
+
+class ExtKeyCache;
+
+struct freelist_entry_t;
+typedef struct freelist_entry_t freelist_entry_t;
+
+struct freelist_cache_t;
+typedef struct freelist_cache_t freelist_cache_t;
+
+struct freelist_hints_t;
+typedef struct freelist_hints_t freelist_hints_t;
+
+struct runtime_statistics_pagedata_t;
+typedef struct runtime_statistics_pagedata_t runtime_statistics_pagedata_t;
+
+struct freelist_global_hints_t;
+typedef struct freelist_global_hints_t freelist_global_hints_t;
+
+struct find_hints_t;
+typedef struct find_hints_t find_hints_t;
+
+struct insert_hints_t;
+typedef struct insert_hints_t insert_hints_t;
+
+struct erase_hints_t;
+typedef struct erase_hints_t erase_hints_t;
+
+
+#include "packstart.h"
+
+struct freelist_payload_t;
+typedef struct freelist_payload_t freelist_payload_t;
+
+#include "packstop.h"
+
+
+#include "packstart.h"
+
+struct btree_key_t;
+typedef struct btree_key_t btree_key_t;
+
+#include "packstop.h"
+
+
+#endif
View
6 src/journal.cc
@@ -421,7 +421,7 @@ Journal::get_entry(Iterator *iter, JournalEntry *entry, void **aux)
st=os_pread(m_fd[iter->fdidx], iter->offset, *aux,
entry->followup_size);
if (st) {
- free(*aux);
+ alloc_free(*aux);
*aux=0;
return (st);
}
@@ -590,7 +590,7 @@ Journal::recover()
JournalEntry entry;
if (aux) {
- free(aux);
+ alloc_free(aux);
aux=0;
}
@@ -704,7 +704,7 @@ Journal::recover()
bail:
if (aux) {
- free(aux);
+ alloc_free(aux);
aux=0;
}
View
10 src/journal.h
@@ -26,10 +26,6 @@
#include "env.h"
#include "os.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include "journal_entries.h"
@@ -181,7 +177,7 @@ class Journal
}
/** helper function for the allocator */
- void free(void *ptr) {
+ void alloc_free(void *ptr) {
return (allocator_free(env_get_allocator(m_env), ptr));
}
@@ -216,8 +212,4 @@ class Journal
#include "packstop.h"
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_JOURNAL_H__ */
View
8 src/journal_entries.h
@@ -17,10 +17,6 @@
#ifndef HAM_JOURNAL_ENTRIES_H__
#define HAM_JOURNAL_ENTRIES_H__
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include "packstart.h"
@@ -135,8 +131,4 @@ HAM_PACK_0 struct HAM_PACK_1 JournalEntryErase
#include "packstop.h"
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_JOURNAL_ENTRIES_H__ */
View
2 src/log.cc
@@ -100,7 +100,7 @@ Log::is_empty(void)
st=os_get_filesize(m_fd, &size);
if (st)
- return (st);
+ return (st ? false : true); /* TODO throw */
if (size && size!=sizeof(Log::Header))
return (false);
View
9 src/log.h
@@ -31,11 +31,6 @@
#include "internal_fwd_decl.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
#include "packstart.h"
/**
@@ -184,8 +179,4 @@ class Log
#include "packstop.h"
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_LOG_H__ */
View
13 src/mem.h
@@ -21,12 +21,6 @@
#include <string.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
/**
* typedefs for allocator function pointers
*/
@@ -62,9 +56,6 @@ _ham_default_allocator_new(const char *fname, const int lineno);
#if defined(_MSC_VER) && defined(_CRTDBG_MAP_ALLOC)
-#include "db.h"
-#include "env.h"
-
#pragma push_macro("alloc")
#pragma push_macro("free")
#pragma push_macro("realloc")
@@ -177,8 +168,4 @@ _allocator_calloc(mem_allocator_t *a, const int lineno, ham_size_t size)
#endif /* defined(_MSC_VER) && defined(_CRTDBG_MAP_ALLOC) */
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_MEM_H__ */
View
9 src/os.h
@@ -22,11 +22,6 @@
#include <stdio.h>
#include <limits.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/**
* read data from a file with mmap
*
@@ -151,8 +146,4 @@ extern ham_status_t
os_close(ham_fd_t fd, ham_u32_t flags);
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_OS_H__ */
View
8 src/os_win32.cc
@@ -168,7 +168,7 @@ os_mmap(ham_fd_t fd, ham_fd_t *mmaph, ham_offset_t position,
return (HAM_IO_ERROR);
}
- *buffer=MapViewOfFile(*mmaph, access, i.HighPart, i.LowPart, (SIZE_T)size);
+ *buffer=(ham_u8_t *)MapViewOfFile(*mmaph, access, i.HighPart, i.LowPart, (SIZE_T)size);
if (!*buffer) {
char buf[256];
st=(ham_status_t)GetLastError();
@@ -283,7 +283,7 @@ os_writev(ham_fd_t fd, void *buffer1, ham_offset_t buffer1_len,
if (st)
return (st);
- ham_status_t st=os_write(fd, buffer1, buffer1_len);
+ st=os_write(fd, buffer1, buffer1_len);
if (st)
return (st);
if (buffer2) {
@@ -411,7 +411,7 @@ os_create(const char *filename, ham_u32_t flags, ham_u32_t mode, ham_fd_t *fd)
#ifdef UNICODE
int fnameWlen = calc_wlen4str(filename);
- WCHAR *wfilename=malloc(fnameWlen * sizeof(wfilename[0]));
+ WCHAR *wfilename=(WCHAR *)malloc(fnameWlen * sizeof(wfilename[0]));
if (!wfilename)
return (HAM_OUT_OF_MEMORY);
@@ -474,7 +474,7 @@ os_open(const char *filename, ham_u32_t flags, ham_fd_t *fd)
#ifdef UNICODE
{
int fnameWlen = calc_wlen4str(filename);
- WCHAR *wfilename=malloc(fnameWlen * sizeof(wfilename[0]));
+ WCHAR *wfilename=(WCHAR *)malloc(fnameWlen * sizeof(wfilename[0]));
if (!wfilename)
return (HAM_OUT_OF_MEMORY);
View
8 src/page.h
@@ -23,10 +23,6 @@
#include "error.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/*
* indices for page lists
*
@@ -437,8 +433,4 @@ extern ham_status_t
page_uncouple_all_cursors(ham_page_t *page, ham_size_t start);
-#ifdef __cplusplus
-} // extern "C" {
-#endif
-
#endif /* HAM_PAGE_H__ */
View
8 src/txn.h
@@ -21,10 +21,6 @@
#include "rb.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/**
* a single operation in a transaction
*/
@@ -487,8 +483,4 @@ extern void
txn_free(ham_txn_t *txn);
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_TXN_H__ */
View
10 src/txn_cursor.h
@@ -31,12 +31,6 @@
#include "txn.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
/*
* An cursor which can iterate over Transaction nodes
*/
@@ -213,8 +207,4 @@ extern ham_status_t
txn_cursor_erase(txn_cursor_t *cursor);
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_TXN_CURSOR_H__ */
View
9 src/util.h
@@ -21,10 +21,6 @@
#include <stdio.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
-
/**
* vsnprintf replacement/wrapper
*
@@ -44,9 +40,4 @@ util_vsnprintf(char *str, size_t size, const char *format, va_list ap);
#define util_snprintf snprintf
#endif
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_UTIL_H__ */
View
7 src/version.h
@@ -17,9 +17,6 @@
#ifndef HAM_VERSION_H__
#define HAM_VERSION_H__
-#ifdef __cplusplus
-extern "C" {
-#endif
/**
* the version numbers
@@ -37,8 +34,4 @@ extern "C" {
#define HAM_VERSION_STR "2.0.0 rc3"
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
#endif /* HAM_VERSION_H__ */
View
2 unittests/bfc-signal.c
@@ -106,7 +106,7 @@ bfc_signal(int code, signal_handler_f handler)
#if defined(UNDER_CE)
return 0;
#else
- return (signal_handler_f)signal(code, (__sighandler_t)handler);
+ return (0);//signal_handler_f)signal(code, (__sighandler_t)handler);
#endif