summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/char/char.c5
-rw-r--r--src/char/int_guild.c8
-rw-r--r--src/char/int_homun.c4
-rw-r--r--src/char/int_party.c4
-rw-r--r--src/char/int_pet.c4
-rw-r--r--src/char/int_status.c5
-rw-r--r--src/char/int_storage.c8
-rw-r--r--src/char/inter.c8
-rw-r--r--src/char_sql/char.c9
-rw-r--r--src/char_sql/int_guild.c4
-rw-r--r--src/char_sql/int_party.c4
-rw-r--r--src/char_sql/inter.c4
-rw-r--r--src/common/db.c457
-rw-r--r--src/common/db.h231
-rw-r--r--src/login/login.c4
-rw-r--r--src/login_sql/login.c4
-rw-r--r--src/map/atcommand.c4
-rw-r--r--src/map/chrif.c12
-rw-r--r--src/map/guild.c20
-rw-r--r--src/map/itemdb.c4
-rw-r--r--src/map/map.c20
-rw-r--r--src/map/npc.c12
-rw-r--r--src/map/party.c4
-rw-r--r--src/map/script.c20
-rw-r--r--src/map/script.h4
-rw-r--r--src/map/storage.c8
-rw-r--r--src/plugins/console.c2
-rw-r--r--src/txt-converter/login-converter.c20
28 files changed, 387 insertions, 506 deletions
diff --git a/src/char/char.c b/src/char/char.c
index fb991ec71..0e7d5782d 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -169,7 +169,8 @@ struct online_char_data {
short server;
};
-struct dbt *online_char_db; //Holds all online characters.
+// Holds all online characters.
+static DBMap* online_char_db; // int account_id -> struct online_char_data*
time_t update_online; // to update online files when we receiving information from a server (not less than 8 seconds)
@@ -4227,7 +4228,7 @@ int do_init(int argc, char **argv)
char_log("The char-server starting...\n");
ShowInfo("Initializing char server.\n");
- online_char_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ online_char_db = idb_alloc(DB_OPT_RELEASE_DATA);
mmo_char_init();
char_read_fame_list(); //Read fame lists.
#ifdef ENABLE_SC_SAVING
diff --git a/src/char/int_guild.c b/src/char/int_guild.c
index 563ad360e..685ef1d00 100644
--- a/src/char/int_guild.c
+++ b/src/char/int_guild.c
@@ -22,8 +22,8 @@ char guild_txt[1024] = "save/guild.txt";
char castle_txt[1024] = "save/castle.txt";
#ifndef TXT_SQL_CONVERT
-static struct dbt *guild_db;
-static struct dbt *castle_db;
+static DBMap* guild_db; // int guild_id -> struct guild*
+static DBMap* castle_db; // int castle_id -> struct guild_castle*
static int guild_newid = 10000;
@@ -376,8 +376,8 @@ int inter_guild_init() {
inter_guild_readdb();
- guild_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
- castle_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ guild_db = idb_alloc(DB_OPT_RELEASE_DATA);
+ castle_db = idb_alloc(DB_OPT_RELEASE_DATA);
if ((fp = fopen(guild_txt,"r")) == NULL)
return 1;
diff --git a/src/char/int_homun.c b/src/char/int_homun.c
index 62b5a78a1..545f0d08c 100644
--- a/src/char/int_homun.c
+++ b/src/char/int_homun.c
@@ -17,7 +17,7 @@
char homun_txt[1024]="save/homun.txt";
-static struct dbt *homun_db;
+static DBMap* homun_db; // int hom_id -> struct s_homunculus*
static int homun_newid = 100;
int inter_homun_tostr(char *str,struct s_homunculus *p)
@@ -118,7 +118,7 @@ int inter_homun_init()
FILE *fp;
int c=0;
- homun_db= db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ homun_db= idb_alloc(DB_OPT_RELEASE_DATA);
if( (fp=fopen(homun_txt,"r"))==NULL )
return 1;
diff --git a/src/char/int_party.c b/src/char/int_party.c
index 4e6366807..7e71adb64 100644
--- a/src/char/int_party.c
+++ b/src/char/int_party.c
@@ -25,7 +25,7 @@ struct party_data {
unsigned char size; //Total size of party.
};
-static struct dbt *party_db;
+static DBMap* party_db; // int party_id -> struct party_data*
static int party_newid = 100;
int mapif_party_broken(int party_id, int flag);
@@ -178,7 +178,7 @@ int inter_party_init() {
int c = 0;
int i, j;
- party_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ party_db = idb_alloc(DB_OPT_RELEASE_DATA);
if ((fp = fopen(party_txt, "r")) == NULL)
return 1;
diff --git a/src/char/int_pet.c b/src/char/int_pet.c
index 8d0f53472..2f06e2df5 100644
--- a/src/char/int_pet.c
+++ b/src/char/int_pet.c
@@ -18,7 +18,7 @@
char pet_txt[1024]="save/pet.txt";
#ifndef TXT_SQL_CONVERT
-static struct dbt *pet_db;
+static DBMap* pet_db; // int pet_id -> struct s_pet*
static int pet_newid = 100;
int inter_pet_tostr(char *str,struct s_pet *p)
@@ -88,7 +88,7 @@ int inter_pet_init()
FILE *fp;
int c=0;
- pet_db= db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ pet_db= idb_alloc(DB_OPT_RELEASE_DATA);
if( (fp=fopen(pet_txt,"r"))==NULL )
return 1;
diff --git a/src/char/int_status.c b/src/char/int_status.c
index cc25b1485..29886d45c 100644
--- a/src/char/int_status.c
+++ b/src/char/int_status.c
@@ -10,7 +10,8 @@
#include <stdio.h>
-static struct dbt * scdata_db = NULL; //Contains all the status change data in-memory. [Skotlex]
+// Contains all the status change data in-memory. [Skotlex]
+static DBMap* scdata_db = NULL; // int char_id -> struct scdata*
char scdata_txt[1024]="save/scdata.txt"; //By [Skotlex]
#ifdef ENABLE_SC_SAVING
@@ -156,7 +157,7 @@ void inter_status_save()
*------------------------------------------*/
void status_init()
{
- scdata_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
+ scdata_db = idb_alloc(DB_OPT_BASE);
status_load_scdata(scdata_txt);
}
diff --git a/src/char/int_storage.c b/src/char/int_storage.c
index daee13134..cba4a28a9 100644
--- a/src/char/int_storage.c
+++ b/src/char/int_storage.c
@@ -24,8 +24,8 @@ char storage_txt[1024]="save/storage.txt";
char guild_storage_txt[1024]="save/g_storage.txt";
#ifndef TXT_SQL_CONVERT
-static struct dbt *storage_db;
-static struct dbt *guild_storage_db;
+static DBMap* storage_db; // int account_id -> struct storage*
+static DBMap* guild_storage_db; // int guild_id -> struct guild_storage*
// 倉庫データを文字列に変換
int storage_tostr(char *str,struct storage *p)
@@ -198,7 +198,7 @@ int inter_storage_init()
struct guild_storage *gs;
FILE *fp;
- storage_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ storage_db = idb_alloc(DB_OPT_RELEASE_DATA);
fp=fopen(storage_txt,"r");
if(fp==NULL){
@@ -227,7 +227,7 @@ int inter_storage_init()
fclose(fp);
c = 0;
- guild_storage_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ guild_storage_db = idb_alloc(DB_OPT_RELEASE_DATA);
fp=fopen(guild_storage_txt,"r");
if(fp==NULL){
diff --git a/src/char/inter.c b/src/char/inter.c
index 9856c13b2..85b4793f7 100644
--- a/src/char/inter.c
+++ b/src/char/inter.c
@@ -30,7 +30,7 @@ char accreg_txt[1024] = "save/accreg.txt";
char inter_log_filename[1024] = "log/inter.log";
char main_chat_nick[16] = "Main";
-static struct dbt *accreg_db = NULL;
+static DBMap* accreg_db = NULL; // int account_id -> struct accreg*
unsigned int party_share_level = 10;
@@ -66,7 +66,7 @@ struct WisData {
unsigned long tick;
unsigned char src[24], dst[24], msg[1024];
};
-static struct dbt * wis_db = NULL;
+static DBMap* wis_db = NULL; // int wis_id -> struct WisData*
static int wis_dellist[WISDELLIST_MAX], wis_delnum;
@@ -109,7 +109,7 @@ int inter_accreg_init(void) {
int c = 0;
struct accreg *reg;
- accreg_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ accreg_db = idb_alloc(DB_OPT_RELEASE_DATA);
if( (fp = fopen(accreg_txt, "r")) == NULL)
return 1;
@@ -259,7 +259,7 @@ int inter_init_txt(const char *file) {
inter_config_read(file);
#ifndef TXT_SQL_CONVERT
- wis_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ wis_db = idb_alloc(DB_OPT_RELEASE_DATA);
inter_party_init();
inter_guild_init();
diff --git a/src/char_sql/char.c b/src/char_sql/char.c
index 5c6040cf2..89f31e2c1 100644
--- a/src/char_sql/char.c
+++ b/src/char_sql/char.c
@@ -64,7 +64,7 @@ char friend_db[256] = "friends";
char hotkey_db[256] = "hotkey";
#ifndef TXT_SQL_CONVERT
-static struct dbt *char_db_;
+static DBMap* char_db_; // int char_id -> struct mmo_charstatus*
char db_path[1024] = "db";
@@ -192,7 +192,8 @@ struct online_char_data {
short server; // -2: unknown server, -1: not connected, 0+: id of server
};
-struct dbt* online_char_db; //Holds all online characters.
+// Holds all online characters.
+DBMap* online_char_db; // int account_id -> struct online_char_data*
static void* create_online_char_data(DBKey key, va_list args)
{
@@ -1066,7 +1067,7 @@ int mmo_char_fromsql(int char_id, struct mmo_charstatus* p, bool load_everything
int mmo_char_sql_init(void)
{
ShowInfo("Begin Initializing.......\n");
- char_db_= db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA, sizeof(int));
+ char_db_= idb_alloc(DB_OPT_RELEASE_DATA);
if(char_per_account == 0){
ShowStatus("Chars per Account: 'Unlimited'.......\n");
@@ -3771,7 +3772,7 @@ int do_init(int argc, char **argv)
ShowInfo("Finished reading the inter-server configuration.\n");
ShowInfo("Initializing char server.\n");
- online_char_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ online_char_db = idb_alloc(DB_OPT_RELEASE_DATA);
mmo_char_sql_init();
char_read_fame_list(); //Read fame lists.
if(char_gm_read)
diff --git a/src/char_sql/int_guild.c b/src/char_sql/int_guild.c
index d315a1833..8502c1be6 100644
--- a/src/char_sql/int_guild.c
+++ b/src/char_sql/int_guild.c
@@ -32,7 +32,7 @@ static const char dataToHex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9
#ifndef TXT_SQL_CONVERT
//Guild cache
-static struct dbt *guild_db_;
+static DBMap* guild_db_; // int guild_id -> struct guild*
struct guild_castle castles[MAX_GUILDCASTLE];
@@ -797,7 +797,7 @@ int inter_guild_CharOffline(int char_id, int guild_id) {
int inter_guild_sql_init(void)
{
//Initialize the guild cache
- guild_db_= db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ guild_db_= idb_alloc(DB_OPT_RELEASE_DATA);
//Read exp file
inter_guild_ReadEXP();
diff --git a/src/char_sql/int_party.c b/src/char_sql/int_party.c
index f5afb1777..cff17c5b5 100644
--- a/src/char_sql/int_party.c
+++ b/src/char_sql/int_party.c
@@ -27,7 +27,7 @@ struct party_data {
};
static struct party_data *party_pt;
-static struct dbt *party_db_;
+static DBMap* party_db_; // int party_id -> struct party_data*
int mapif_party_broken(int party_id,int flag);
int party_check_empty(struct party_data *p);
@@ -269,7 +269,7 @@ struct party_data *inter_party_fromsql(int party_id)
int inter_party_sql_init(void)
{
//memory alloc
- party_db_ = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ party_db_ = idb_alloc(DB_OPT_RELEASE_DATA);
party_pt = (struct party_data*)aCalloc(sizeof(struct party_data), 1);
if (!party_pt) {
ShowFatalError("inter_party_sql_init: Out of Memory!\n");
diff --git a/src/char_sql/inter.c b/src/char_sql/inter.c
index bb15ad50b..e595324b6 100644
--- a/src/char_sql/inter.c
+++ b/src/char_sql/inter.c
@@ -79,7 +79,7 @@ struct WisData {
unsigned long tick;
unsigned char src[24], dst[24], msg[512];
};
-static struct dbt * wis_db = NULL;
+static DBMap* wis_db = NULL; // int wis_id -> struct WisData*
static int wis_dellist[WISDELLIST_MAX], wis_delnum;
int inter_sql_test (void);
@@ -390,7 +390,7 @@ int inter_init_sql(const char *file)
}
#ifndef TXT_SQL_CONVERT
- wis_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ wis_db = idb_alloc(DB_OPT_RELEASE_DATA);
inter_guild_sql_init();
inter_storage_sql_init();
inter_party_sql_init();
diff --git a/src/common/db.c b/src/common/db.c
index 476c5a0c9..27aa6776a 100644
--- a/src/common/db.c
+++ b/src/common/db.c
@@ -82,7 +82,7 @@
* DBNColor - Enumeration of colors of the nodes. *
* DBNode - Structure of a node in RED-BLACK trees. *
* struct db_free - Structure that holds a deleted node to be freed. *
- * DB_impl - Struture of the database. *
+ * DBMap_impl - Struture of the database. *
* stats - Statistics about the database system. *
\*****************************************************************************/
@@ -101,7 +101,7 @@
/**
* Size of the hashtable in the database.
* @private
- * @see DB_impl#ht
+ * @see DBMap_impl#ht
*/
#define HASH_SIZE (256+27)
@@ -115,7 +115,7 @@
* @param deleted If the node is deleted
* @param color Color of the node
* @private
- * @see DB_impl#ht
+ * @see DBMap_impl#ht
*/
typedef struct dbn {
// Tree structure
@@ -135,7 +135,7 @@ typedef struct dbn {
* @param node Deleted node
* @param root Address to the root of the tree
* @private
- * @see DB_impl#free_list
+ * @see DBMap_impl#free_list
*/
struct db_free {
DBNode node;
@@ -144,7 +144,7 @@ struct db_free {
/**
* Complete database structure.
- * @param dbi Interface of the database
+ * @param vtable Interface of the database
* @param alloc_file File where the database was allocated
* @param alloc_line Line in the file where the database was allocated
* @param free_list Array of deleted nodes to be freed
@@ -162,11 +162,11 @@ struct db_free {
* @param maxlen Maximum length of strings in DB_STRING and DB_ISTRING databases
* @param global_lock Global lock of the database
* @private
- * @see #db_alloc(const char *,int,DBOptions,DBType,...)
+ * @see #db_alloc(const char*,int,DBType,DBOptions,unsigned short)
*/
-typedef struct db {
+typedef struct DBMap_impl {
// Database interface
- struct dbt vtable;
+ struct DBMap vtable;
// File and line of allocation
const char *alloc_file;
int alloc_line;
@@ -187,9 +187,9 @@ typedef struct db {
uint32 item_count;
unsigned short maxlen;
unsigned global_lock : 1;
-} *DB_impl;
+} DBMap_impl;
-#ifdef DB_ENABLE_STATS
+#if defined(DB_ENABLE_STATS)
/**
* Structure with what is counted when the database estatistics are enabled.
* @private
@@ -268,8 +268,10 @@ static struct db_stats {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};
-#define COUNT(func) if (stats. ## func != UINT32_MAX) ++stats. ## func
-#endif /* DB_ENABLE_STATS */
+#define DB_COUNTSTAT(token) if (stats. ## token != UINT32_MAX) ++stats. ## token
+#else /* !defined(DB_ENABLE_STATS) */
+#define DB_COUNTSTAT(token)
+#endif /* !defined(DB_ENABLE_STATS) */
/*****************************************************************************\
* (2) Section of private functions used by the database system. *
@@ -300,9 +302,7 @@ static void db_rotate_left(DBNode node, DBNode *root)
{
DBNode y = node->right;
-#ifdef DB_ENABLE_STATS
- COUNT(db_rotate_left);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_rotate_left);
// put the left of y at the right of node
node->right = y->left;
if (y->left)
@@ -333,9 +333,7 @@ static void db_rotate_right(DBNode node, DBNode *root)
{
DBNode y = node->left;
-#ifdef DB_ENABLE_STATS
- COUNT(db_rotate_right);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_rotate_right);
// put the right of y at the left of node
node->left = y->right;
if (y->right != 0)
@@ -362,15 +360,13 @@ static void db_rotate_right(DBNode node, DBNode *root)
* @private
* @see #db_rotate_left(DBNode,DBNode *)
* @see #db_rotate_right(DBNode,DBNode *)
- * @see #db_put(DB,DBKey,void *)
+ * @see #db_obj_put(DBMap*,DBKey,void *)
*/
static void db_rebalance(DBNode node, DBNode *root)
{
DBNode y;
-#ifdef DB_ENABLE_STATS
- COUNT(db_rebalance);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_rebalance);
// Restore the RED-BLACK properties
node->color = RED;
while (node != *root && node->parent->color == RED) {
@@ -426,7 +422,7 @@ static void db_rebalance(DBNode node, DBNode *root)
* @private
* @see #db_rotate_left(DBNode,DBNode *)
* @see #db_rotate_right(DBNode,DBNode *)
- * @see #db_free_unlock(DB_impl)
+ * @see #db_free_unlock(DBMap_impl*)
*/
static void db_rebalance_erase(DBNode node, DBNode *root)
{
@@ -435,9 +431,7 @@ static void db_rebalance_erase(DBNode node, DBNode *root)
DBNode x_parent = NULL;
DBNode w;
-#ifdef DB_ENABLE_STATS
- COUNT(db_rebalance_erase);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_rebalance_erase);
// Select where to change the tree
if (y->left == NULL) { // no left
x = y->right;
@@ -567,15 +561,13 @@ static void db_rebalance_erase(DBNode node, DBNode *root)
* @param key Key being tested
* @return not 0 if considered NULL, 0 otherwise
* @private
- * @see #db_get(DB,DBKey)
- * @see #db_put(DB,DBKey,void *)
- * @see #db_remove(DB,DBKey)
+ * @see #db_obj_get(DBMap*,DBKey)
+ * @see #db_obj_put(DBMap*,DBKey,void *)
+ * @see #db_obj_remove(DBMap*,DBKey)
*/
static int db_is_key_null(DBType type, DBKey key)
{
-#ifdef DB_ENABLE_STATS
- COUNT(db_is_key_null);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_is_key_null);
switch (type) {
case DB_STRING:
case DB_ISTRING:
@@ -592,18 +584,16 @@ static int db_is_key_null(DBType type, DBKey key)
* @param key Key to be duplicated
* @param Duplicated key
* @private
- * @see #db_free_add(DB_impl,DBNode,DBNode *)
- * @see #db_free_remove(DB_impl,DBNode)
- * @see #db_put(DB,DBKey,void *)
- * @see #db_dup_key_free(DB_impl,DBKey)
+ * @see #db_free_add(DBMap_impl*,DBNode,DBNode *)
+ * @see #db_free_remove(DBMap_impl*,DBNode)
+ * @see #db_obj_put(DBMap*,DBKey,void *)
+ * @see #db_dup_key_free(DBMap_impl*,DBKey)
*/
-static DBKey db_dup_key(DB_impl db, DBKey key)
+static DBKey db_dup_key(DBMap_impl* db, DBKey key)
{
char *str;
-#ifdef DB_ENABLE_STATS
- COUNT(db_dup_key);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_dup_key);
switch (db->type) {
case DB_STRING:
case DB_ISTRING:
@@ -627,13 +617,11 @@ static DBKey db_dup_key(DB_impl db, DBKey key)
* @param db Database the key is being used in
* @param key Key to be freed
* @private
- * @see #db_dup_key(DB_impl,DBKey)
+ * @see #db_dup_key(DBMap_impl*,DBKey)
*/
-static void db_dup_key_free(DB_impl db, DBKey key)
+static void db_dup_key_free(DBMap_impl* db, DBKey key)
{
-#ifdef DB_ENABLE_STATS
- COUNT(db_dup_key_free);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_dup_key_free);
switch (db->type) {
case DB_STRING:
case DB_ISTRING:
@@ -654,19 +642,17 @@ static void db_dup_key_free(DB_impl db, DBKey key)
* @param node Target node
* @private
* @see #struct db_free
- * @see DB_impl#free_list
- * @see DB_impl#free_count
- * @see DB_impl#free_max
- * @see #db_remove(DB,DBKey)
- * @see #db_free_remove(DB_impl,DBNode)
+ * @see DBMap_impl#free_list
+ * @see DBMap_impl#free_count
+ * @see DBMap_impl#free_max
+ * @see #db_obj_remove(DBMap*,DBKey)
+ * @see #db_free_remove(DBMap_impl*,DBNode)
*/
-static void db_free_add(DB_impl db, DBNode node, DBNode *root)
+static void db_free_add(DBMap_impl* db, DBNode node, DBNode *root)
{
DBKey old_key;
-#ifdef DB_ENABLE_STATS
- COUNT(db_free_add);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_free_add);
if (db->free_lock == (unsigned int)~0) {
ShowFatalError("db_free_add: free_lock overflow\n"
"Database allocated at %s:%d\n",
@@ -706,18 +692,16 @@ static void db_free_add(DB_impl db, DBNode node, DBNode *root)
* @param node Node being removed from free_list
* @private
* @see #struct db_free
- * @see DB_impl#free_list
- * @see DB_impl#free_count
- * @see #db_put(DB,DBKey,void *)
- * @see #db_free_add(DB_impl,DBNode *,DBNode)
+ * @see DBMap_impl#free_list
+ * @see DBMap_impl#free_count
+ * @see #db_obj_put(DBMap*,DBKey,void*)
+ * @see #db_free_add(DBMap_impl*,DBNode*,DBNode)
*/
-static void db_free_remove(DB_impl db, DBNode node)
+static void db_free_remove(DBMap_impl* db, DBNode node)
{
unsigned int i;
-#ifdef DB_ENABLE_STATS
- COUNT(db_free_remove);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_free_remove);
for (i = 0; i < db->free_count; i++) {
if (db->free_list[i].node == node) {
if (i < db->free_count -1) // copy the last item to where the removed one was
@@ -739,14 +723,12 @@ static void db_free_remove(DB_impl db, DBNode node)
* Increment the free_lock of the database.
* @param db Target database
* @private
- * @see DB_impl#free_lock
- * @see #db_unlock(DB_impl)
+ * @see DBMap_impl#free_lock
+ * @see #db_unlock(DBMap_impl*)
*/
-static void db_free_lock(DB_impl db)
+static void db_free_lock(DBMap_impl* db)
{
-#ifdef DB_ENABLE_STATS
- COUNT(db_free_lock);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_free_lock);
if (db->free_lock == (unsigned int)~0) {
ShowFatalError("db_free_lock: free_lock overflow\n"
"Database allocated at %s:%d\n",
@@ -763,17 +745,15 @@ static void db_free_lock(DB_impl db)
* NOTE: Frees the duplicated keys of the nodes
* @param db Target database
* @private
- * @see DB_impl#free_lock
+ * @see DBMap_impl#free_lock
* @see #db_free_dbn(DBNode)
- * @see #db_lock(DB_impl)
+ * @see #db_lock(DBMap_impl*)
*/
-static void db_free_unlock(DB_impl db)
+static void db_free_unlock(DBMap_impl* db)
{
unsigned int i;
-#ifdef DB_ENABLE_STATS
- COUNT(db_free_unlock);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_free_unlock);
if (db->free_lock == 0) {
ShowWarning("db_free_unlock: free_lock was already 0\n"
"Database allocated at %s:%d\n",
@@ -787,9 +767,7 @@ static void db_free_unlock(DB_impl db)
for (i = 0; i < db->free_count ; i++) {
db_rebalance_erase(db->free_list[i].node, db->free_list[i].root);
db_dup_key_free(db, db->free_list[i].node->key);
-#ifdef DB_ENABLE_STATS
- if (stats.db_node_free != (unsigned int)~0) stats.db_node_free++;
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_node_free);
ers_free(db->nodes, db->free_list[i].node);
}
db->free_count = 0;
@@ -829,9 +807,7 @@ static void db_free_unlock(DB_impl db)
static int db_int_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
{
(void)maxlen;//not used
-#ifdef DB_ENABLE_STATS
- COUNT(db_int_cmp);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_int_cmp);
if (key1.i < key2.i) return -1;
if (key1.i > key2.i) return 1;
return 0;
@@ -853,9 +829,7 @@ static int db_int_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
static int db_uint_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
{
(void)maxlen;//not used
-#ifdef DB_ENABLE_STATS
- COUNT(db_uint_cmp);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_uint_cmp);
if (key1.ui < key2.ui) return -1;
if (key1.ui > key2.ui) return 1;
return 0;
@@ -875,9 +849,7 @@ static int db_uint_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
*/
static int db_string_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
{
-#ifdef DB_ENABLE_STATS
- COUNT(db_string_cmp);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_string_cmp);
if (maxlen == 0)
maxlen = UINT16_MAX;
return strncmp((const char *)key1.str, (const char *)key2.str, maxlen);
@@ -897,9 +869,7 @@ static int db_string_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
*/
static int db_istring_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
{
-#ifdef DB_ENABLE_STATS
- COUNT(db_istring_cmp);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_istring_cmp);
if (maxlen == 0)
maxlen = UINT16_MAX;
return strncasecmp((const char *)key1.str, (const char *)key2.str, maxlen);
@@ -919,9 +889,7 @@ static int db_istring_cmp(DBKey key1, DBKey key2, unsigned short maxlen)
static unsigned int db_int_hash(DBKey key, unsigned short maxlen)
{
(void)maxlen;//not used
-#ifdef DB_ENABLE_STATS
- COUNT(db_int_hash);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_int_hash);
return (unsigned int)key.i;
}
@@ -939,9 +907,7 @@ static unsigned int db_int_hash(DBKey key, unsigned short maxlen)
static unsigned int db_uint_hash(DBKey key, unsigned short maxlen)
{
(void)maxlen;//not used
-#ifdef DB_ENABLE_STATS
- COUNT(db_uint_hash);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_uint_hash);
return key.ui;
}
@@ -961,9 +927,7 @@ static unsigned int db_string_hash(DBKey key, unsigned short maxlen)
unsigned int hash = 0;
unsigned short i;
-#ifdef DB_ENABLE_STATS
- COUNT(db_string_hash);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_string_hash);
if (maxlen == 0)
maxlen = UINT16_MAX;
@@ -992,9 +956,7 @@ static unsigned int db_istring_hash(DBKey key, unsigned short maxlen)
unsigned int hash = 0;
unsigned short i;
-#ifdef DB_ENABLE_STATS
- COUNT(db_istring_hash);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_istring_hash);
if (maxlen == 0)
maxlen = UINT16_MAX;
@@ -1020,9 +982,7 @@ static unsigned int db_istring_hash(DBKey key, unsigned short maxlen)
static void db_release_nothing(DBKey key, void *data, DBRelease which)
{
(void)key;(void)data;(void)which;//not used
-#ifdef DB_ENABLE_STATS
- COUNT(db_release_nothing);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_release_nothing);
}
/**
@@ -1037,9 +997,7 @@ static void db_release_nothing(DBKey key, void *data, DBRelease which)
static void db_release_key(DBKey key, void *data, DBRelease which)
{
(void)data;//not used
-#ifdef DB_ENABLE_STATS
- COUNT(db_release_key);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_release_key);
if (which&DB_RELEASE_KEY) aFree((char*)key.str); // needs to be a pointer
}
@@ -1049,17 +1007,15 @@ static void db_release_key(DBKey key, void *data, DBRelease which)
* @param data Data of the database entry
* @param which What is being requested to be released
* @protected
- * @see common\db.h#DBKey
- * @see common\db.h#DBRelease
- * @see common\db.h#DBReleaser
+ * @see #DBKey
+ * @see #DBRelease
+ * @see #DBReleaser
* @see #db_default_release(DBType,DBOptions)
*/
static void db_release_data(DBKey key, void *data, DBRelease which)
{
(void)key;//not used
-#ifdef DB_ENABLE_STATS
- COUNT(db_release_data);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_release_data);
if (which&DB_RELEASE_DATA) aFree(data);
}
@@ -1069,16 +1025,14 @@ static void db_release_data(DBKey key, void *data, DBRelease which)
* @param data Data of the database entry
* @param which What is being requested to be released
* @protected
- * @see common\db.h#DBKey
- * @see common\db.h#DBRelease
- * @see common\db.h#DBReleaser
+ * @see #DBKey
+ * @see #DBRelease
+ * @see #DBReleaser
* @see #db_default_release(DBType,DBOptions)
*/
static void db_release_both(DBKey key, void *data, DBRelease which)
{
-#ifdef DB_ENABLE_STATS
- COUNT(db_release_both);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_release_both);
if (which&DB_RELEASE_KEY) aFree((char*)key.str); // needs to be a pointer
if (which&DB_RELEASE_DATA) aFree(data);
}
@@ -1112,18 +1066,16 @@ static void db_release_both(DBKey key, void *data, DBRelease which)
* @param key Key that identifies the entry
* @return Data of the entry or NULL if not found
* @protected
- * @see DB_impl::vtable#get
+ * @see DBMap#get
*/
-static void *db_obj_get(DB self, DBKey key)
+static void* db_obj_get(DBMap* self, DBKey key)
{
- DB_impl db = (DB_impl)self;
+ DBMap_impl* db = (DBMap_impl*)self;
DBNode node;
int c;
void *data = NULL;
-#ifdef DB_ENABLE_STATS
- COUNT(db_get);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_get);
if (db == NULL) return NULL; // nullpo candidate
if (!(db->options&DB_OPT_ALLOW_NULL_KEY) && db_is_key_null(db->type, key)) {
ShowError("db_get: Attempted to retrieve non-allowed NULL key for db allocated at %s:%d\n",db->alloc_file, db->alloc_line);
@@ -1165,19 +1117,17 @@ static void *db_obj_get(DB self, DBKey key)
* @param ... Extra arguments for match
* @return The number of entries that matched
* @protected
- * @see DB_impl::vtable#vgetall
+ * @see DBMap#vgetall
*/
-static unsigned int db_obj_vgetall(DB self, void **buf, unsigned int max, DBMatcher match, va_list args)
+static unsigned int db_obj_vgetall(DBMap* self, void **buf, unsigned int max, DBMatcher match, va_list args)
{
- DB_impl db = (DB_impl)self;
+ DBMap_impl* db = (DBMap_impl*)self;
unsigned int i;
DBNode node;
DBNode parent;
unsigned int ret = 0;
-#ifdef DB_ENABLE_STATS
- COUNT(db_vgetall);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_vgetall);
if (db == NULL) return 0; // nullpo candidate
if (match == NULL) return 0; // nullpo candidate
@@ -1215,7 +1165,7 @@ static unsigned int db_obj_vgetall(DB self, void **buf, unsigned int max, DBMatc
}
/**
- * Just calls {@link DB#vgetall(DB,void **,unsigned int,DBMatch,va_list)}.
+ * Just calls {@link DBMap#vgetall}.
* Get the data of the entries matched by <code>match</code>.
* It puts a maximum of <code>max</code> entries into <code>buf</code>.
* If <code>buf</code> is NULL, it only counts the matches.
@@ -1229,17 +1179,15 @@ static unsigned int db_obj_vgetall(DB self, void **buf, unsigned int max, DBMatc
* @param ... Extra arguments for match
* @return The number of entries that matched
* @protected
- * @see DB_impl::vtable#vgetall
- * @see DB_impl::vtable#getall
+ * @see DBMap#vgetall
+ * @see DBMap#getall
*/
-static unsigned int db_obj_getall(DB self, void **buf, unsigned int max, DBMatcher match, ...)
+static unsigned int db_obj_getall(DBMap* self, void **buf, unsigned int max, DBMatcher match, ...)
{
va_list args;
unsigned int ret;
-#ifdef DB_ENABLE_STATS
- COUNT(db_getall);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_getall);
if (self == NULL) return 0; // nullpo candidate
va_start(args, match);
@@ -1258,20 +1206,18 @@ static unsigned int db_obj_getall(DB self, void **buf, unsigned int max, DBMatch
* @param args Extra arguments for create
* @return Data of the entry
* @protected
- * @see DB_impl::vtable#vensure
+ * @see DBMap#vensure
*/
-static void *db_obj_vensure(DB self, DBKey key, DBCreateData create, va_list args)
+static void *db_obj_vensure(DBMap* self, DBKey key, DBCreateData create, va_list args)
{
- DB_impl db = (DB_impl)self;
+ DBMap_impl* db = (DBMap_impl*)self;
DBNode node;
DBNode parent = NULL;
unsigned int hash;
int c = 0;
void *data = NULL;
-#ifdef DB_ENABLE_STATS
- COUNT(db_vensure);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_vensure);
if (db == NULL) return NULL; // nullpo candidate
if (create == NULL) {
ShowError("db_ensure: Create function is NULL for db allocated at %s:%d\n",db->alloc_file, db->alloc_line);
@@ -1307,9 +1253,7 @@ static void *db_obj_vensure(DB self, DBKey key, DBCreateData create, va_list arg
db->alloc_file, db->alloc_line);
return NULL;
}
-#ifdef DB_ENABLE_STATS
- COUNT(db_node_alloc);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_node_alloc);
node = ers_alloc(db->nodes, struct dbn);
node->left = NULL;
node->right = NULL;
@@ -1348,7 +1292,7 @@ static void *db_obj_vensure(DB self, DBKey key, DBCreateData create, va_list arg
}
/**
- * Just calls {@link DB#vensure(DB,DBKey,DBCreateData,va_list)}.
+ * Just calls {@link DBMap#vensure}.
* Get the data of the entry identified by the key.
* If the entry does not exist, an entry is added with the data returned by
* <code>create</code>.
@@ -1358,17 +1302,15 @@ static void *db_obj_vensure(DB self, DBKey key, DBCreateData create, va_list arg
* @param ... Extra arguments for create
* @return Data of the entry
* @protected
- * @see DB_impl::vtable#vensure
- * @see DB_impl::vtable#ensure
+ * @see DBMap#vensure
+ * @see DBMap#ensure
*/
-static void *db_obj_ensure(DB self, DBKey key, DBCreateData create, ...)
+static void *db_obj_ensure(DBMap* self, DBKey key, DBCreateData create, ...)
{
va_list args;
void *ret;
-#ifdef DB_ENABLE_STATS
- COUNT(db_ensure);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_ensure);
if (self == NULL) return 0; // nullpo candidate
va_start(args, create);
@@ -1387,20 +1329,18 @@ static void *db_obj_ensure(DB self, DBKey key, DBCreateData create, ...)
* @return The previous data if the entry exists or NULL
* @protected
* @see #db_malloc_dbn(void)
- * @see DB_impl::vtable#put
+ * @see DBMap#put
*/
-static void *db_obj_put(DB self, DBKey key, void *data)
+static void *db_obj_put(DBMap* self, DBKey key, void *data)
{
- DB_impl db = (DB_impl)self;
+ DBMap_impl* db = (DBMap_impl*)self;
DBNode node;
DBNode parent = NULL;
int c = 0;
unsigned int hash;
void *old_data = NULL;
-#ifdef DB_ENABLE_STATS
- COUNT(db_put);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_put);
if (db == NULL) return NULL; // nullpo candidate
if (db->global_lock) {
ShowError("db_put: Database is being destroyed, aborting entry insertion.\n"
@@ -1446,9 +1386,7 @@ static void *db_obj_put(DB self, DBKey key, void *data)
}
// allocate a new node if necessary
if (node == NULL) {
-#ifdef DB_ENABLE_STATS
- COUNT(db_node_alloc);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_node_alloc);
node = ers_alloc(db->nodes, struct dbn);
node->left = NULL;
node->right = NULL;
@@ -1488,25 +1426,23 @@ static void *db_obj_put(DB self, DBKey key, void *data)
/**
* Remove an entry from the database.
* Returns the data of the entry.
- * NOTE: The key (of the database) is released in {@link #db_free_add(DB_impl,DBNode,DBNode *)}.
+ * NOTE: The key (of the database) is released in {@link #db_free_add(DBMap_impl*,DBNode,DBNode *)}.
* @param self Interface of the database
* @param key Key that identifies the entry
* @return The data of the entry or NULL if not found
* @protected
- * @see #db_free_add(DB_impl,DBNode,DBNode *)
- * @see DB_impl::vtable#remove
+ * @see #db_free_add(DBMap_impl*,DBNode,DBNode *)
+ * @see DBMap#remove
*/
-static void *db_obj_remove(DB self, DBKey key)
+static void *db_obj_remove(DBMap* self, DBKey key)
{
- DB_impl db = (DB_impl)self;
+ DBMap_impl* db = (DBMap_impl*)self;
void *data = NULL;
DBNode node;
unsigned int hash;
int c = 0;
-#ifdef DB_ENABLE_STATS
- COUNT(db_remove);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_remove);
if (db == NULL) return NULL; // nullpo candidate
if (db->global_lock) {
ShowError("db_remove: Database is being destroyed. Aborting entry deletion.\n"
@@ -1550,19 +1486,17 @@ static void *db_obj_remove(DB self, DBKey key)
* @param args Extra arguments for func
* @return Sum of the values returned by func
* @protected
- * @see DB_impl::vtable#vforeach
+ * @see DBMap#vforeach
*/
-static int db_obj_vforeach(DB self, DBApply func, va_list args)
+static int db_obj_vforeach(DBMap* self, DBApply func, va_list args)
{
- DB_impl db = (DB_impl)self;
+ DBMap_impl* db = (DBMap_impl*)self;
unsigned int i;
int sum = 0;
DBNode node;
DBNode parent;
-#ifdef DB_ENABLE_STATS
- COUNT(db_vforeach);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_vforeach);
if (db == NULL) return 0; // nullpo candidate
if (func == NULL) {
ShowError("db_foreach: Passed function is NULL for db allocated at %s:%d\n",db->alloc_file, db->alloc_line);
@@ -1608,17 +1542,15 @@ static int db_obj_vforeach(DB self, DBApply func, va_list args)
* @param ... Extra arguments for func
* @return Sum of the values returned by func
* @protected
- * @see DB_impl::vtable#vforeach
- * @see DB_impl::vtable#foreach
+ * @see DBMap#vforeach
+ * @see DBMap#foreach
*/
-static int db_obj_foreach(DB self, DBApply func, ...)
+static int db_obj_foreach(DBMap* self, DBApply func, ...)
{
va_list args;
int ret;
-#ifdef DB_ENABLE_STATS
- COUNT(db_foreach);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_foreach);
if (self == NULL) return 0; // nullpo candidate
va_start(args, func);
@@ -1637,19 +1569,17 @@ static int db_obj_foreach(DB self, DBApply func, ...)
* @param args Extra arguments for func
* @return Sum of values returned by func
* @protected
- * @see DB_impl::vtable#vclear
+ * @see DBMap#vclear
*/
-static int db_obj_vclear(DB self, DBApply func, va_list args)
+static int db_obj_vclear(DBMap* self, DBApply func, va_list args)
{
- DB_impl db = (DB_impl)self;
+ DBMap_impl* db = (DBMap_impl*)self;
int sum = 0;
unsigned int i;
DBNode node;
DBNode parent;
-#ifdef DB_ENABLE_STATS
- COUNT(db_vclear);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_vclear);
if (db == NULL) return 0; // nullpo candidate
db_free_lock(db);
@@ -1676,9 +1606,7 @@ static int db_obj_vclear(DB self, DBApply func, va_list args)
db->release(node->key, node->data, DB_RELEASE_BOTH);
node->deleted = 1;
}
-#ifdef DB_ENABLE_STATS
- COUNT(db_node_free);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_node_free);
ers_free(db->nodes, node);
if (parent) {
if (parent->left == node)
@@ -1697,7 +1625,7 @@ static int db_obj_vclear(DB self, DBApply func, va_list args)
}
/**
- * Just calls {@link common\db.h\DB#vclear(DB,DBApply,va_list)}.
+ * Just calls {@link DBMap#vclear}.
* Removes all entries from the database.
* Before deleting an entry, func is applyed to it.
* Releases the key and the data.
@@ -1709,17 +1637,15 @@ static int db_obj_vclear(DB self, DBApply func, va_list args)
* @param ... Extra arguments for func
* @return Sum of values returned by func
* @protected
- * @see DB_impl::vtable#vclear
- * @see DB_impl::vtable#clear
+ * @see DBMap#vclear
+ * @see DBMap#clear
*/
-static int db_obj_clear(DB self, DBApply func, ...)
+static int db_obj_clear(DBMap* self, DBApply func, ...)
{
va_list args;
int ret;
-#ifdef DB_ENABLE_STATS
- COUNT(db_clear);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_clear);
if (self == NULL) return 0; // nullpo candidate
va_start(args, func);
@@ -1739,16 +1665,14 @@ static int db_obj_clear(DB self, DBApply func, ...)
* @param args Extra arguments for func
* @return Sum of values returned by func
* @protected
- * @see DB_impl::vtable#vdestroy
+ * @see DBMap#vdestroy
*/
-static int db_obj_vdestroy(DB self, DBApply func, va_list args)
+static int db_obj_vdestroy(DBMap* self, DBApply func, va_list args)
{
- DB_impl db = (DB_impl)self;
+ DBMap_impl* db = (DBMap_impl*)self;
int sum;
-#ifdef DB_ENABLE_STATS
- COUNT(db_vdestroy);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_vdestroy);
if (db == NULL) return 0; // nullpo candidate
if (db->global_lock) {
ShowError("db_vdestroy: Database is already locked for destruction. Aborting second database destruction.\n"
@@ -1763,10 +1687,10 @@ static int db_obj_vdestroy(DB self, DBApply func, va_list args)
#ifdef DB_ENABLE_STATS
switch (db->type) {
- case DB_INT: COUNT(db_int_destroy); break;
- case DB_UINT: COUNT(db_uint_destroy); break;
- case DB_STRING: COUNT(db_string_destroy); break;
- case DB_ISTRING: COUNT(db_istring_destroy); break;
+ case DB_INT: DB_COUNTSTAT(db_int_destroy); break;
+ case DB_UINT: DB_COUNTSTAT(db_uint_destroy); break;
+ case DB_STRING: DB_COUNTSTAT(db_string_destroy); break;
+ case DB_ISTRING: DB_COUNTSTAT(db_istring_destroy); break;
}
#endif /* DB_ENABLE_STATS */
db_free_lock(db);
@@ -1782,29 +1706,27 @@ static int db_obj_vdestroy(DB self, DBApply func, va_list args)
}
/**
- * Just calls {@link DB#db_vdestroy(DB,DBApply,va_list)}.
+ * Just calls {@link DBMap#db_vdestroy}.
* Finalize the database, feeing all the memory it uses.
* Before deleting an entry, func is applyed to it.
* Releases the key and the data.
* Returns the sum of values returned by func, if it exists.
* NOTE: This locks the database globally. Any attempt to insert or remove
* a database entry will give an error and be aborted.
- * @param self Interface of the database
+ * @param self Database
* @param func Function to be applyed to every entry before deleting
* @param ... Extra arguments for func
* @return Sum of values returned by func
* @protected
- * @see DB_impl::vtable#vdestroy
- * @see DB_impl::vtable#destroy
+ * @see DBMap#vdestroy
+ * @see DBMap#destroy
*/
-static int db_obj_destroy(DB self, DBApply func, ...)
+static int db_obj_destroy(DBMap* self, DBApply func, ...)
{
va_list args;
int ret;
-#ifdef DB_ENABLE_STATS
- COUNT(db_destroy);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_destroy);
if (self == NULL) return 0; // nullpo candidate
va_start(args, func);
@@ -1818,17 +1740,15 @@ static int db_obj_destroy(DB self, DBApply func, ...)
* @param self Interface of the database
* @return Size of the database
* @protected
- * @see DB_impl#item_count
- * @see DB_impl::vtable#size
+ * @see DBMap_impl#item_count
+ * @see DBMap#size
*/
-static unsigned int db_obj_size(DB self)
+static unsigned int db_obj_size(DBMap* self)
{
- DB_impl db = (DB_impl)self;
+ DBMap_impl* db = (DBMap_impl*)self;
unsigned int item_count;
-#ifdef DB_ENABLE_STATS
- COUNT(db_size);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_size);
if (db == NULL) return 0; // nullpo candidate
db_free_lock(db);
@@ -1843,17 +1763,15 @@ static unsigned int db_obj_size(DB self)
* @param self Interface of the database
* @return Type of the database
* @protected
- * @see DB_impl#type
- * @see DB_impl::vtable#type
+ * @see DBMap_impl#type
+ * @see DBMap#type
*/
-static DBType db_obj_type(DB self)
+static DBType db_obj_type(DBMap* self)
{
- DB_impl db = (DB_impl)self;
+ DBMap_impl* db = (DBMap_impl*)self;
DBType type;
-#ifdef DB_ENABLE_STATS
- COUNT(db_type);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_type);
if (db == NULL) return -1; // nullpo candidate - TODO what should this return?
db_free_lock(db);
@@ -1868,17 +1786,15 @@ static DBType db_obj_type(DB self)
* @param self Interface of the database
* @return Options of the database
* @protected
- * @see DB_impl#options
- * @see DB_impl::vtable#options
+ * @see DBMap_impl#options
+ * @see DBMap#options
*/
-static DBOptions db_obj_options(DB self)
+static DBOptions db_obj_options(DBMap* self)
{
- DB_impl db = (DB_impl)self;
+ DBMap_impl* db = (DBMap_impl*)self;
DBOptions options;
-#ifdef DB_ENABLE_STATS
- COUNT(db_options);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_options);
if (db == NULL) return DB_OPT_BASE; // nullpo candidate - TODO what should this return?
db_free_lock(db);
@@ -1916,9 +1832,7 @@ static DBOptions db_obj_options(DB self)
*/
DBOptions db_fix_options(DBType type, DBOptions options)
{
-#ifdef DB_ENABLE_STATS
- COUNT(db_fix_options);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_fix_options);
switch (type) {
case DB_INT:
case DB_UINT: // Numeric database, do nothing with the keys
@@ -1944,9 +1858,7 @@ DBOptions db_fix_options(DBType type, DBOptions options)
*/
DBComparator db_default_cmp(DBType type)
{
-#ifdef DB_ENABLE_STATS
- COUNT(db_default_cmp);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_default_cmp);
switch (type) {
case DB_INT: return db_int_cmp;
case DB_UINT: return db_uint_cmp;
@@ -1970,9 +1882,7 @@ DBComparator db_default_cmp(DBType type)
*/
DBHasher db_default_hash(DBType type)
{
-#ifdef DB_ENABLE_STATS
- COUNT(db_default_hash);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_default_hash);
switch (type) {
case DB_INT: return db_int_hash;
case DB_UINT: return db_uint_hash;
@@ -2001,9 +1911,7 @@ DBHasher db_default_hash(DBType type)
*/
DBReleaser db_default_release(DBType type, DBOptions options)
{
-#ifdef DB_ENABLE_STATS
- COUNT(db_default_release);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_default_release);
options = db_fix_options(type, options);
if (options&DB_OPT_RELEASE_DATA) { // Release data, what about the key?
if (options&(DB_OPT_DUP_KEY|DB_OPT_RELEASE_KEY))
@@ -2028,9 +1936,7 @@ DBReleaser db_default_release(DBType type, DBOptions options)
*/
DBReleaser db_custom_release(DBRelease which)
{
-#ifdef DB_ENABLE_STATS
- COUNT(db_custom_release);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_custom_release);
switch (which) {
case DB_RELEASE_NOTHING: return db_release_nothing;
case DB_RELEASE_KEY: return db_release_key;
@@ -2054,32 +1960,24 @@ DBReleaser db_custom_release(DBRelease which)
* databases
* @return The interface of the database
* @public
- * @see #DB_impl
+ * @see #DBMap_impl
* @see #db_fix_options(DBType,DBOptions)
*/
-DB db_alloc(const char *file, int line, DBType type, DBOptions options, unsigned short maxlen)
+DBMap* db_alloc(const char *file, int line, DBType type, DBOptions options, unsigned short maxlen)
{
- DB_impl db;
+ DBMap_impl* db;
unsigned int i;
#ifdef DB_ENABLE_STATS
- if (stats.db_alloc != (unsigned int)~0) stats.db_alloc++;
+ DB_COUNTSTAT(db_alloc);
switch (type) {
- case DB_INT:
- COUNT(db_int_alloc);
- break;
- case DB_UINT:
- COUNT(db_uint_alloc);
- break;
- case DB_STRING:
- COUNT(db_string_alloc);
- break;
- case DB_ISTRING:
- COUNT(db_istring_alloc);
- break;
+ case DB_INT: DB_COUNTSTAT(db_int_alloc); break;
+ case DB_UINT: DB_COUNTSTAT(db_uint_alloc); break;
+ case DB_STRING: DB_COUNTSTAT(db_string_alloc); break;
+ case DB_ISTRING: DB_COUNTSTAT(db_istring_alloc); break;
}
#endif /* DB_ENABLE_STATS */
- CREATE(db, struct db, 1);
+ CREATE(db, struct DBMap_impl, 1);
options = db_fix_options(type, options);
/* Interface of the database */
@@ -2137,9 +2035,7 @@ DBKey db_i2key(int key)
{
DBKey ret;
-#ifdef DB_ENABLE_STATS
- COUNT(db_i2key);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_i2key);
ret.i = key;
return ret;
}
@@ -2156,9 +2052,7 @@ DBKey db_ui2key(unsigned int key)
{
DBKey ret;
-#ifdef DB_ENABLE_STATS
- COUNT(db_ui2key);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_ui2key);
ret.ui = key;
return ret;
}
@@ -2175,9 +2069,7 @@ DBKey db_str2key(const char *key)
{
DBKey ret;
-#ifdef DB_ENABLE_STATS
- COUNT(db_str2key);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_str2key);
ret.str = key;
return ret;
}
@@ -2190,9 +2082,7 @@ DBKey db_str2key(const char *key)
*/
void db_init(void)
{
-#ifdef DB_ENABLE_STATS
- COUNT(db_init);
-#endif /* DB_ENABLE_STATS */
+ DB_COUNTSTAT(db_init);
}
/**
@@ -2203,8 +2093,7 @@ void db_init(void)
void db_final(void)
{
#ifdef DB_ENABLE_STATS
- if (stats.db_final != (unsigned int)~0)
- stats.db_final++;
+ DB_COUNTSTAT(db_final);
ShowInfo(CL_WHITE"Database nodes"CL_RESET":\n"
"allocated %u, freed %u\n",
stats.db_node_alloc, stats.db_node_free);
diff --git a/src/common/db.h b/src/common/db.h
index ec6539bc6..45034c141 100644
--- a/src/common/db.h
+++ b/src/common/db.h
@@ -23,8 +23,8 @@
* HISTORY: *
* 2.1 (Athena build #???#) - Portability fix *
* - Fixed the portability of casting to union and added the functions *
- * {@link DB#ensure(DB,DBKey,DBCreateData,...)} and *
- * {@link DB#clear(DB,DBApply,...)}. *
+ * {@link DBMap#ensure(DBMap,DBKey,DBCreateData,...)} and *
+ * {@link DBMap#clear(DBMap,DBApply,...)}. *
* 2.0 (Athena build 4859) - Transition version *
* - Almost everything recoded with a strategy similar to objects, *
* database structure is maintained. *
@@ -40,6 +40,7 @@
#ifndef _DB_H_
#define _DB_H_
+#include "../common/cbasetypes.h"
#include <stdarg.h>
/*****************************************************************************\
@@ -51,19 +52,19 @@
* DBOptions - Bitfield enumeration of database options. *
* DBKey - Union of used key types. *
* DBApply - Format of functions applyed to the databases. *
- * DBMatcher - Format of matchers used in DB::getall. *
+ * DBMatcher - Format of matchers used in DBMap::getall. *
* DBComparator - Format of the comparators used by the databases. *
* DBHasher - Format of the hashers used by the databases. *
* DBReleaser - Format of the releasers used by the databases. *
- * DB - Database interface. *
+ * DBMap - Database interface. *
\*****************************************************************************/
/**
* Define this to enable the functions that cast to unions.
* Required when the compiler doesn't support casting to unions.
* NOTE: It is recommened that the conditional tests to determine if this
- * should be defined be located in a makefile or a header file specific for
- * of compatibility and portability issues.
+ * should be defined be located in the configure script or a header file
+ * specific for compatibility and portability issues.
* @public
* @see #db_i2key(int)
* @see #db_ui2key(unsigned int)
@@ -120,7 +121,7 @@ typedef enum DBType {
* @param DB_OPT_RELEASE_KEY Releases the key.
* @param DB_OPT_RELEASE_DATA Releases the data whenever an entry is removed
* from the database.
- * WARNING: for funtions that return the data (like DB::remove),
+ * WARNING: for funtions that return the data (like DBMap::remove),
* a dangling pointer will be returned.
* @param DB_OPT_RELEASE_BOTH Releases both key and data.
* @param DB_OPT_ALLOW_NULL_KEY Allow NULL keys in the database.
@@ -130,7 +131,7 @@ typedef enum DBType {
* @see #db_default_release(DBType,DBOptions)
* @see #db_alloc(const char *,int,DBType,DBOptions,unsigned short)
*/
-typedef enum db_opt {
+typedef enum DBOptions {
DB_OPT_BASE = 0,
DB_OPT_DUP_KEY = 1,
DB_OPT_RELEASE_KEY = 2,
@@ -147,11 +148,11 @@ typedef enum db_opt {
* @param str Type of key for DB_STRING and DB_ISTRING databases
* @public
* @see #DBType
- * @see DB#get
- * @see DB#put
- * @see DB#remove
+ * @see DBMap#get
+ * @see DBMap#put
+ * @see DBMap#remove
*/
-typedef union dbkey {
+typedef union DBKey {
int i;
unsigned int ui;
const char *str;
@@ -164,27 +165,27 @@ typedef union dbkey {
* @param args Extra arguments of the funtion
* @return Data identified by the key to be put in the database
* @public
- * @see DB#vensure
- * @see DB#ensure
+ * @see DBMap#vensure
+ * @see DBMap#ensure
*/
-typedef void *(*DBCreateData)(DBKey key, va_list args);
+typedef void* (*DBCreateData)(DBKey key, va_list args);
/**
* Format of functions to be applyed to an unspecified quantity of entries of
* a database.
- * Any function that applyes this function to the database will return the sum
+ * Any function that applies this function to the database will return the sum
* of values returned by this function.
* @param key Key of the database entry
* @param data Data of the database entry
* @param args Extra arguments of the funtion
* @return Value to be added up by the funtion that is applying this
* @public
- * @see DB#vforeach
- * @see DB#foreach
- * @see DB#vdestroy
- * @see DB#destroy
+ * @see DBMap#vforeach
+ * @see DBMap#foreach
+ * @see DBMap#vdestroy
+ * @see DBMap#destroy
*/
-typedef int (*DBApply)(DBKey key, void *data, va_list args);
+typedef int (*DBApply)(DBKey key, void* data, va_list args);
/**
* Format of functions that match database entries.
@@ -195,9 +196,9 @@ typedef int (*DBApply)(DBKey key, void *data, va_list args);
* @param args Extra arguments of the function
* @return 0 if a match, another number otherwise
* @public
- * @see DB#getall
+ * @see DBMap#getall
*/
-typedef int (*DBMatcher)(DBKey key, void *data, va_list args);
+typedef int (*DBMatcher)(DBKey key, void* data, va_list args);
/**
* Format of the comparators used internally by the database system.
@@ -241,58 +242,49 @@ typedef unsigned int (*DBHasher)(DBKey key, unsigned short maxlen);
* @see #db_default_releaser(DBType,DBOptions)
* @see #db_custom_release(DBRelease)
*/
-typedef void (*DBReleaser)(DBKey key, void *data, DBRelease which);
+typedef void (*DBReleaser)(DBKey key, void* data, DBRelease which);
+
+
+
+typedef struct DBMap DBMap;
+
+
/**
* Public interface of a database. Only contains funtions.
* All the functions take the interface as the first argument.
* @public
- * @see DB#get(DB,DBKey)
- * @see DB#getall(DB,void **,unsigned int,DBMatch,...)
- * @see DB#vgetall(DB,void **,unsigned int,DBMatch,va_list)
- * @see DB#put(DB,DBKey,void *)
- * @see DB#remove(DB,DBKey)
- * @see DB#foreach(DB,DBApply,...)
- * @see DB#vforeach(DB,DBApply,va_list)
- * @see DB#destroy(DB,DBApply,...)
- * @see DB#destroy(DB,DBApply,va_list)
- * @see DB#size(DB)
- * @see DB#type(DB)
- * @see DB#options(DB)
- * @see #db_alloc(const char *,int,DBType,DBOptions,unsigned short)
+ * @see #db_alloc(const char*,int,DBType,DBOptions,unsigned short)
*/
-typedef struct dbt *DB;
-struct dbt {
+struct DBMap {
/**
* Get the data of the entry identifid by the key.
- * @param dbi Interface of the database
+ * @param self Database
* @param key Key that identifies the entry
* @return Data of the entry or NULL if not found
* @protected
- * @see #db_get(DB,DBKey)
*/
- void *(*get)(DB self, DBKey key);
+ void* (*get)(DBMap* self, DBKey key);
/**
- * Just calls {@link DB#vgetall(DB,void **,unsigned int,DBMatch,va_list)}.
+ * Just calls {@link DBMap#vgetall}.
* Get the data of the entries matched by <code>match</code>.
* It puts a maximum of <code>max</code> entries into <code>buf</code>.
* If <code>buf</code> is NULL, it only counts the matches.
* Returns the number of entries that matched.
* NOTE: if the value returned is greater than <code>max</code>, only the
* first <code>max</code> entries found are put into the buffer.
- * @param dbi Interface of the database
+ * @param self Database
* @param buf Buffer to put the data of the matched entries
* @param max Maximum number of data entries to be put into buf
* @param match Function that matches the database entries
* @param ... Extra arguments for match
* @return The number of entries that matched
* @protected
- * @see DB#vgetall
- * @see #db_getall(DB,void **,unsigned int,DBMatch,...)
+ * @see DBMap#vgetall(DBMap*,void **,unsigned int,DBMatcher,va_list)
*/
- unsigned int (*getall)(DB self, void **buf, unsigned int max, DBMatcher match, ...);
+ unsigned int (*getall)(DBMap* self, void** buf, unsigned int max, DBMatcher match, ...);
/**
* Get the data of the entries matched by <code>match</code>.
@@ -301,149 +293,139 @@ struct dbt {
* Returns the number of entries that matched.
* NOTE: if the value returned is greater than <code>max</code>, only the
* first <code>max</code> entries found are put into the buffer.
- * @param dbi Interface of the database
+ * @param self Database
* @param buf Buffer to put the data of the matched entries
* @param max Maximum number of data entries to be put into buf
* @param match Function that matches the database entries
* @param ... Extra arguments for match
* @return The number of entries that matched
* @protected
- * @see DB#getall
- * @see #db_vgetall(DB,void **,unsigned int,DBMatch,va_list)
+ * @see DBMap#getall(DBMap*,void **,unsigned int,DBMatcher,...)
*/
- unsigned int (*vgetall)(DB self, void **buf, unsigned int max, DBMatcher match, va_list args);
+ unsigned int (*vgetall)(DBMap* self, void** buf, unsigned int max, DBMatcher match, va_list args);
/**
- * Just calls {@link common\db.h\DB#vensure(DB,DBKey,DBCreateData,va_list)}.
+ * Just calls {@link DBMap#vensure}.
* Get the data of the entry identified by the key.
* If the entry does not exist, an entry is added with the data returned by
* <code>create</code>.
- * @param dbi Interface of the database
+ * @param self Database
* @param key Key that identifies the entry
* @param create Function used to create the data if the entry doesn't exist
* @param ... Extra arguments for create
* @return Data of the entry
* @protected
- * @see DB#vensure(DB,DBKey,DBCreateData,va_list)
- * @see #db_ensure(DB,DBKey,DBCreateData,...)
+ * @see DBMap#vensure(DBMap*,DBKey,DBCreateData,va_list)
*/
- void *(*ensure)(DB self, DBKey key, DBCreateData create, ...);
+ void* (*ensure)(DBMap* self, DBKey key, DBCreateData create, ...);
/**
* Get the data of the entry identified by the key.
* If the entry does not exist, an entry is added with the data returned by
* <code>create</code>.
- * @param dbi Interface of the database
+ * @param self Database
* @param key Key that identifies the entry
* @param create Function used to create the data if the entry doesn't exist
* @param args Extra arguments for create
* @return Data of the entry
* @protected
- * @see DB#ensure(DB,DBKey,DBCreateData,...)
- * @see #db_vensure(DB,DBKey,DBCreateData,va_list)
+ * @see DBMap#ensure(DBMap*,DBKey,DBCreateData,...)
*/
- void *(*vensure)(DB self, DBKey key, DBCreateData create, va_list args);
+ void* (*vensure)(DBMap* self, DBKey key, DBCreateData create, va_list args);
/**
* Put the data identified by the key in the database.
* Returns the previous data if the entry exists or NULL.
* NOTE: Uses the new key, the old one is released.
- * @param dbi Interface of the database
+ * @param self Database
* @param key Key that identifies the data
* @param data Data to be put in the database
* @return The previous data if the entry exists or NULL
* @protected
- * @see #db_put(DB,DBKey,void *)
*/
- void *(*put)(DB self, DBKey key, void *data);
+ void* (*put)(DBMap* self, DBKey key, void* data);
/**
* Remove an entry from the database.
* Returns the data of the entry.
* NOTE: The key (of the database) is released.
- * @param dbi Interface of the database
+ * @param self Database
* @param key Key that identifies the entry
* @return The data of the entry or NULL if not found
* @protected
- * @see #db_remove(DB,DBKey)
*/
- void *(*remove)(DB self, DBKey key);
+ void* (*remove)(DBMap* self, DBKey key);
/**
- * Just calls {@link DB#vforeach(DB,DBApply,va_list)}.
+ * Just calls {@link DBMap#vforeach}.
* Apply <code>func</code> to every entry in the database.
* Returns the sum of values returned by func.
- * @param dbi Interface of the database
+ * @param self Database
* @param func Function to be applyed
* @param ... Extra arguments for func
* @return Sum of the values returned by func
* @protected
- * @see DB#vforeach
- * @see #db_foreach(DB,DBApply,...)
+ * @see DBMap#vforeach(DBMap*,DBApply,va_list)
*/
- int (*foreach)(DB self, DBApply func, ...);
+ int (*foreach)(DBMap* self, DBApply func, ...);
/**
* Apply <code>func</code> to every entry in the database.
* Returns the sum of values returned by func.
- * @param dbi Interface of the database
+ * @param self Database
* @param func Function to be applyed
* @param args Extra arguments for func
* @return Sum of the values returned by func
* @protected
- * @see DB#foreach
- * @see #db_vforeach(DB,DBApply,va_list)
+ * @see DBMap#foreach(DBMap*,DBApply,...)
*/
- int (*vforeach)(DB self, DBApply func, va_list args);
+ int (*vforeach)(DBMap* self, DBApply func, va_list args);
/**
- * Just calls {@link DB#vclear(DB,DBApply,va_list)}.
+ * Just calls {@link DBMap#vclear}.
* Removes all entries from the database.
* Before deleting an entry, func is applyed to it.
* Releases the key and the data.
* Returns the sum of values returned by func, if it exists.
- * @param dbi Interface of the database
+ * @param self Database
* @param func Function to be applyed to every entry before deleting
* @param ... Extra arguments for func
* @return Sum of values returned by func
* @protected
- * @see DB#vclear
- * @see #db_clear(DB,DBApply,...)
+ * @see DBMap#vclear(DBMap*,DBApply,va_list)
*/
- int (*clear)(DB self, DBApply func, ...);
+ int (*clear)(DBMap* self, DBApply func, ...);
/**
* Removes all entries from the database.
* Before deleting an entry, func is applyed to it.
* Releases the key and the data.
* Returns the sum of values returned by func, if it exists.
- * @param dbi Interface of the database
+ * @param self Database
* @param func Function to be applyed to every entry before deleting
* @param args Extra arguments for func
* @return Sum of values returned by func
* @protected
- * @see DB#clear
- * @see #vclear(DB,DBApply,va_list)
+ * @see DBMap#clear(DBMap*,DBApply,...)
*/
- int (*vclear)(DB self, DBApply func, va_list args);
+ int (*vclear)(DBMap* self, DBApply func, va_list args);
/**
- * Just calls {@link DB#vdestroy(DB,DBApply,va_list)}.
+ * Just calls {@link DBMap#vdestroy}.
* Finalize the database, feeing all the memory it uses.
* Before deleting an entry, func is applyed to it.
* Releases the key and the data.
* Returns the sum of values returned by func, if it exists.
* NOTE: This locks the database globally. Any attempt to insert or remove
* a database entry will give an error and be aborted (except for clearing).
- * @param dbi Interface of the database
+ * @param self Database
* @param func Function to be applyed to every entry before deleting
* @param ... Extra arguments for func
* @return Sum of values returned by func
* @protected
- * @see DB#vdestroy
- * @see #db_destroy(DB,DBApply,...)
+ * @see DBMap#vdestroy(DBMap*,DBApply,va_list)
*/
- int (*destroy)(DB self, DBApply func, ...);
+ int (*destroy)(DBMap* self, DBApply func, ...);
/**
* Finalize the database, feeing all the memory it uses.
@@ -451,42 +433,38 @@ struct dbt {
* Returns the sum of values returned by func, if it exists.
* NOTE: This locks the database globally. Any attempt to insert or remove
* a database entry will give an error and be aborted (except for clearing).
- * @param dbi Interface of the database
+ * @param self Database
* @param func Function to be applyed to every entry before deleting
* @param args Extra arguments for func
* @return Sum of values returned by func
* @protected
- * @see DB#destroy
- * @see #db_vdestroy(DB,DBApply,va_list)
+ * @see DBMap#destroy(DBMap*,DBApply,...)
*/
- int (*vdestroy)(DB self, DBApply func, va_list args);
+ int (*vdestroy)(DBMap* self, DBApply func, va_list args);
/**
* Return the size of the database (number of items in the database).
- * @param dbi Interface of the database
+ * @param self Database
* @return Size of the database
* @protected
- * @see #db_size(DB)
*/
- unsigned int (*size)(DB self);
+ unsigned int (*size)(DBMap* self);
/**
* Return the type of the database.
- * @param dbi Interface of the database
+ * @param self Database
* @return Type of the database
* @protected
- * @see #db_type(DB)
*/
- DBType (*type)(DB self);
+ DBType (*type)(DBMap* self);
/**
* Return the options of the database.
- * @param dbi Interface of the database
+ * @param self Database
* @return Options of the database
* @protected
- * @see #db_options(DB)
*/
- DBOptions (*options)(DB self);
+ DBOptions (*options)(DBMap* self);
};
@@ -501,27 +479,34 @@ struct dbt {
# define str2key(k) ((DBKey)(const char *)(k))
#endif /* not DB_MANUAL_CAST_TO_UNION */
-#define db_get(db,k) (db)->get((db),(k))
-#define idb_get(db,k) (db)->get((db),i2key(k))
-#define uidb_get(db,k) (db)->get((db),ui2key(k))
-#define strdb_get(db,k) (db)->get((db),str2key(k))
+#define db_get(db,k) ( (db)->get((db),(k)) )
+#define idb_get(db,k) ( (db)->get((db),i2key(k)) )
+#define uidb_get(db,k) ( (db)->get((db),ui2key(k)) )
+#define strdb_get(db,k) ( (db)->get((db),str2key(k)) )
-#define db_put(db,k,d) (db)->put((db),(k),(d))
-#define idb_put(db,k,d) (db)->put((db),i2key(k),(d))
-#define uidb_put(db,k,d) (db)->put((db),ui2key(k),(d))
-#define strdb_put(db,k,d) (db)->put((db),str2key(k),(d))
+#define db_put(db,k,d) ( (db)->put((db),(k),(d)) )
+#define idb_put(db,k,d) ( (db)->put((db),i2key(k),(d)) )
+#define uidb_put(db,k,d) ( (db)->put((db),ui2key(k),(d)) )
+#define strdb_put(db,k,d) ( (db)->put((db),str2key(k),(d)) )
-#define db_remove(db,k) (db)->remove((db),(k))
-#define idb_remove(db,k) (db)->remove((db),i2key(k))
-#define uidb_remove(db,k) (db)->remove((db),ui2key(k))
-#define strdb_remove(db,k) (db)->remove((db),str2key(k))
+#define db_remove(db,k) ( (db)->remove((db),(k)) )
+#define idb_remove(db,k) ( (db)->remove((db),i2key(k)) )
+#define uidb_remove(db,k) ( (db)->remove((db),ui2key(k)) )
+#define strdb_remove(db,k) ( (db)->remove((db),str2key(k)) )
//These are discarding the possible vargs you could send to the function, so those
//that require vargs must not use these defines.
-#define db_ensure(db,k,f) (db)->ensure((db),(k),f)
-#define idb_ensure(db,k,f) (db)->ensure((db),i2key(k),f)
-#define uidb_ensure(db,k,f) (db)->ensure((db),ui2key(k),f)
-#define strdb_ensure(db,k,f) (db)->ensure((db),str2key(k),f)
+#define db_ensure(db,k,f) ( (db)->ensure((db),(k),(f)) )
+#define idb_ensure(db,k,f) ( (db)->ensure((db),i2key(k),(f)) )
+#define uidb_ensure(db,k,f) ( (db)->ensure((db),ui2key(k),(f)) )
+#define strdb_ensure(db,k,f) ( (db)->ensure((db),str2key(k),(f)) )
+
+// Database creation and destruction macros
+#define idb_alloc(opt) db_alloc(__FILE__,__LINE__,DB_INT,(opt),sizeof(int))
+#define uidb_alloc(opt) db_alloc(__FILE__,__LINE__,DB_UINT,(opt),sizeof(unsigned int))
+#define strdb_alloc(opt,maxlen) db_alloc(__FILE__,__LINE__,DB_STRING,(opt),(maxlen))
+#define stridb_alloc(opt,maxlen) db_alloc(__FILE__,__LINE__,DB_ISTRING,(opt),(maxlen))
+#define db_destroy(db) ( (db)->destroy((db),NULL) )
/*****************************************************************************\
* (2) Section with public functions. *
@@ -550,7 +535,6 @@ struct dbt {
* @see #DBType
* @see #DBOptions
* @see #db_default_release(DBType,DBOptions)
- * @see common\db.c#db_fix_options(DBType,DBOptions)
*/
DBOptions db_fix_options(DBType type, DBOptions options);
@@ -561,7 +545,6 @@ DBOptions db_fix_options(DBType type, DBOptions options);
* @public
* @see #DBType
* @see #DBComparator
- * @see common\db.c#db_default_cmp(DBType)
*/
DBComparator db_default_cmp(DBType type);
@@ -572,7 +555,6 @@ DBComparator db_default_cmp(DBType type);
* @public
* @see #DBType
* @see #DBHasher
- * @see common\db.c#db_default_hash(DBType)
*/
DBHasher db_default_hash(DBType type);
@@ -590,7 +572,6 @@ DBHasher db_default_hash(DBType type);
* @see #DBReleaser
* @see #db_fix_options(DBType,DBOptions)
* @see #db_custom_release(DBRelease)
- * @see common\db.c#db_default_release(DBType,DBOptions)
*/
DBReleaser db_default_release(DBType type, DBOptions options);
@@ -602,7 +583,6 @@ DBReleaser db_default_release(DBType type, DBOptions options);
* @see #DBRelease
* @see #DBReleaser
* @see #db_default_release(DBType,DBOptions)
- * @see common\db.c#db_custom_release(DBRelease)
*/
DBReleaser db_custom_release(DBRelease which);
@@ -621,14 +601,13 @@ DBReleaser db_custom_release(DBRelease which);
* @return The interface of the database
* @public
* @see #DBType
- * @see #DB
+ * @see #DBMap
* @see #db_default_cmp(DBType)
* @see #db_default_hash(DBType)
* @see #db_default_release(DBType,DBOptions)
* @see #db_fix_options(DBType,DBOptions)
- * @see common\db.c#db_alloc(const char *,int,DBType,DBOptions,unsigned short)
*/
-DB db_alloc(const char *file, int line, DBType type, DBOptions options, unsigned short maxlen);
+DBMap* db_alloc(const char *file, int line, DBType type, DBOptions options, unsigned short maxlen);
#ifdef DB_MANUAL_CAST_TO_UNION
/**
diff --git a/src/login/login.c b/src/login/login.c
index f992054aa..2b1650e2c 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -159,7 +159,7 @@ char gm_pass[64] = "";
int level_new_gm = 60;
-static struct dbt *online_db;
+static DBMap* online_db; // int account_id -> struct online_login_data*
int charif_sendallwos(int sfd, unsigned char *buf, unsigned int len);
@@ -3938,7 +3938,7 @@ int do_init(int argc, char** argv)
server_fd[i] = -1;
// Online user database init
- online_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ online_db = idb_alloc(DB_OPT_RELEASE_DATA);
add_timer_func_list(waiting_disconnect_timer, "waiting_disconnect_timer");
// Auth init
diff --git a/src/login_sql/login.c b/src/login_sql/login.c
index a0e4b6964..7139c0b2c 100644
--- a/src/login_sql/login.c
+++ b/src/login_sql/login.c
@@ -116,7 +116,7 @@ struct online_login_data {
//-----------------------------------------------------
-struct dbt* online_db;
+static DBMap* online_db; // int account_id -> struct online_login_data*
static void* create_online_user(DBKey key, va_list args)
{
@@ -1928,7 +1928,7 @@ int do_init(int argc, char** argv)
server_fd[i] = -1;
// Online user database init
- online_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ online_db = idb_alloc(DB_OPT_RELEASE_DATA);
add_timer_func_list(waiting_disconnect_timer, "waiting_disconnect_timer");
// Auth init
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 43294ca87..7a590c2d2 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -6430,7 +6430,7 @@ int atcommand_pettalk(const int fd, struct map_session_data* sd, const char* com
* @users - displays the number of players present on each map (percentage)
*------------------------------------------*/
-static struct dbt *users_db = NULL;
+static DBMap* users_db = NULL; // unsigned int mapindex -> int users
static int users_all;
static int atcommand_users_sub1(struct map_session_data* sd,va_list va)
@@ -8554,7 +8554,7 @@ int atcommand_config_read(const char* cfgName)
void do_init_atcommand()
{
- users_db = db_alloc(__FILE__,__LINE__,DB_UINT,DB_OPT_BASE,sizeof(int));
+ users_db = uidb_alloc(DB_OPT_BASE);
duel_count = 0;
memset(&duel_list[0], 0, sizeof(duel_list));
add_timer_func_list(atshowmobs_timer, "atshowmobs_timer");
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 0ea1e06a9..6369a6745 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -25,7 +25,7 @@
#include <sys/types.h>
#include <time.h>
-struct dbt *auth_db;
+DBMap* auth_db; // int id -> struct auth_node*
static const int packet_len_table[0x3d] = { // U - used, F - free
60, 3,-1,27,10,-1, 6,-1, // 2af8-2aff: U->2af8, U->2af9, U->2afa, U->2afb, U->2afc, U->2afd, U->2afe, U->2aff
@@ -430,7 +430,7 @@ void chrif_authreq(struct map_session_data *sd)
auth_data->account_id = sd->bl.id;
auth_data->login_id1 = sd->login_id1;
auth_data->node_created = gettick();
- uidb_put(auth_db, sd->bl.id, auth_data);
+ idb_put(auth_db, sd->bl.id, auth_data);
}
return;
}
@@ -451,7 +451,7 @@ void chrif_authok(int fd)
return;
}
- if ((auth_data =uidb_get(auth_db, RFIFOL(fd, 4))) != NULL)
+ if ((auth_data =idb_get(auth_db, RFIFOL(fd, 4))) != NULL)
{ //Is the character already awaiting authorization?
if (auth_data->sd)
{
@@ -472,7 +472,7 @@ void chrif_authok(int fd)
//Delete the data of this node...
if (auth_data->char_dat)
aFree (auth_data->char_dat);
- uidb_remove(auth_db, RFIFOL(fd, 4));
+ idb_remove(auth_db, RFIFOL(fd, 4));
return;
}
// Awaiting for client to connect.
@@ -485,7 +485,7 @@ void chrif_authok(int fd)
auth_data->login_id2=RFIFOL(fd, 16);
memcpy(auth_data->char_dat,RFIFOP(fd, 20),sizeof(struct mmo_charstatus));
auth_data->node_created=gettick();
- uidb_put(auth_db, RFIFOL(fd, 4), auth_data);
+ idb_put(auth_db, RFIFOL(fd, 4), auth_data);
}
int auth_db_cleanup_sub(DBKey key,void *data,va_list ap)
@@ -1445,7 +1445,7 @@ int do_init_chrif(void)
#endif
add_timer_interval(gettick() + 1000, auth_db_cleanup, 0, 0, 30 * 1000);
- auth_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ auth_db = idb_alloc(DB_OPT_RELEASE_DATA);
return 0;
}
diff --git a/src/map/guild.c b/src/map/guild.c
index c2738dc91..40449baf0 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -29,11 +29,11 @@
#include <string.h>
-static DB guild_db;
-static DB castle_db;
-static DB guild_expcache_db;
-static DB guild_infoevent_db;
-static DB guild_castleinfoevent_db;
+static DBMap* guild_db; // int guild_id -> struct guild*
+static DBMap* castle_db; // int castle_id -> struct guild_castle*
+static DBMap* guild_expcache_db; // int char_id -> struct guild_expcache*
+static DBMap* guild_infoevent_db; // int guild_id -> struct eventlist*
+static DBMap* guild_castleinfoevent_db; // int castle_id_index -> struct eventlist*
struct eventlist {
char name[50];
@@ -204,12 +204,12 @@ static int guild_read_castledb(void)
// 初期化
void do_init_guild(void)
{
- guild_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
- castle_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
- guild_expcache_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
- guild_infoevent_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
+ guild_db=idb_alloc(DB_OPT_RELEASE_DATA);
+ castle_db=idb_alloc(DB_OPT_RELEASE_DATA);
+ guild_expcache_db=idb_alloc(DB_OPT_BASE);
+ guild_infoevent_db=idb_alloc(DB_OPT_BASE);
expcache_ers = ers_new(sizeof(struct guild_expcache));
- guild_castleinfoevent_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
+ guild_castleinfoevent_db=idb_alloc(DB_OPT_BASE);
guild_read_castledb();
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index 46caca0da..513b19a2e 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -21,7 +21,7 @@
static struct item_data* itemdb_array[MAX_ITEMDB];
-static struct dbt* itemdb_other;
+static DBMap* itemdb_other;// int nameid -> struct item_data*
static struct item_group itemgroup_db[MAX_ITEMGROUP];
@@ -1044,7 +1044,7 @@ void do_final_itemdb(void)
int do_init_itemdb(void)
{
memset(itemdb_array, 0, sizeof(itemdb_array));
- itemdb_other = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
+ itemdb_other = idb_alloc(DB_OPT_BASE);
create_dummy_data(); //Dummy data item.
itemdb_read();
diff --git a/src/map/map.c b/src/map/map.c
index 590cafc5c..52153c55d 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -93,11 +93,11 @@ char *SCRIPT_CONF_NAME;
char *MSG_CONF_NAME;
// 極力 staticでロ?カルに?める
-static struct dbt * id_db=NULL;// id -> struct block_list
-static struct dbt * pc_db=NULL;// id -> struct map_session_data
-static struct dbt * map_db=NULL;
-static struct dbt * nick_db=NULL;// charid -> struct charid2nick (requested names of offline characters)
-static struct dbt * charid_db=NULL;// charid -> struct map_session_data
+static DBMap* id_db=NULL; // int id -> struct block_list*
+static DBMap* pc_db=NULL; // int id -> struct map_session_data*
+static DBMap* map_db=NULL; // unsigned int mapindex -> struct map_data*
+static DBMap* nick_db=NULL; // int char_id -> struct charid2nick* (requested names of offline characters)
+static DBMap* charid_db=NULL; // int char_id -> struct map_session_data*
static int map_users=0;
static struct block_list *objects[MAX_FLOORITEM];
@@ -3303,11 +3303,11 @@ int do_init(int argc, char *argv[])
inter_config_read(INTER_CONF_NAME);
log_config_read(LOG_CONF_NAME);
- id_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
- pc_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int)); //Added for reliable map_id2sd() use. [Skotlex]
- map_db = db_alloc(__FILE__,__LINE__,DB_UINT,DB_OPT_BASE,sizeof(int));
- nick_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
- charid_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
+ id_db = idb_alloc(DB_OPT_BASE);
+ pc_db = idb_alloc(DB_OPT_BASE); //Added for reliable map_id2sd() use. [Skotlex]
+ map_db = uidb_alloc(DB_OPT_BASE);
+ nick_db = idb_alloc(DB_OPT_BASE);
+ charid_db = idb_alloc(DB_OPT_BASE);
#ifndef TXT_ONLY
map_sql_init();
#endif /* not TXT_ONLY */
diff --git a/src/map/npc.c b/src/map/npc.c
index 3649731ed..f6e7f0cf0 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -49,8 +49,8 @@ static int npc_delay_mob=0;
static int npc_cache_mob=0;
int npc_get_new_npc_id(void){ return npc_id++; }
-static struct dbt *ev_db;
-static struct dbt *npcname_db;
+static DBMap* ev_db; // const char* event_name -> struct event_data*
+static DBMap* npcname_db; // const char* npc_name -> struct npc_data*
struct event_data {
struct npc_data *nd;
@@ -1794,7 +1794,7 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
src_id = 0;
if( script )
{
- DB label_db = script_get_label_db();
+ DBMap* label_db = script_get_label_db();
label_db->foreach(label_db, npc_convertlabel_db, &label_list, &label_list_num, filepath);
label_db->clear(label_db, NULL); // not needed anymore, so clear the db
}
@@ -2022,7 +2022,7 @@ int npc_changename(const char* name, const char* newname, short look)
/// function%TAB%script%TAB%<function name>%TAB%{<code>}
static const char* npc_parse_function(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath)
{
- struct dbt *func_db;
+ DBMap* func_db;
struct script_code *script;
struct script_code *oldscript;
const char* end;
@@ -2867,8 +2867,8 @@ int do_init_npc(void)
for( i = 1; i < MAX_NPC_CLASS; i++ )
npc_viewdb[i].class_ = i;
- ev_db = db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA,2*NAME_LENGTH+2+1);
- npcname_db = db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_BASE,NAME_LENGTH);
+ ev_db = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA,2*NAME_LENGTH+2+1);
+ npcname_db = strdb_alloc(DB_OPT_BASE,NAME_LENGTH);
memset(&ev_tm_b, -1, sizeof(ev_tm_b));
timer_event_ers = ers_new(sizeof(struct timer_event_data));
diff --git a/src/map/party.c b/src/map/party.c
index a81c7dc42..7b1e3f1ab 100644
--- a/src/map/party.c
+++ b/src/map/party.c
@@ -26,7 +26,7 @@
#include <string.h>
-static DB party_db;
+static DBMap* party_db; // int party_id -> struct party_data*
int party_share_level = 10;
int party_send_xy_timer(int tid,unsigned int tick,int id,int data);
@@ -56,7 +56,7 @@ void do_final_party(void)
// 初期化
void do_init_party(void)
{
- party_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ party_db=idb_alloc(DB_OPT_RELEASE_DATA);
add_timer_func_list(party_send_xy_timer, "party_send_xy_timer");
add_timer_interval(gettick()+battle_config.party_update_interval, party_send_xy_timer, 0, 0, battle_config.party_update_interval);
}
diff --git a/src/map/script.c b/src/map/script.c
index a1b0834e0..71aee9d6f 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -170,17 +170,17 @@ int str_hash[SCRIPT_HASH_SIZE];
//#define SCRIPT_HASH_ELF
//#define SCRIPT_HASH_PJW
-static struct dbt *mapreg_db=NULL;
-static struct dbt *mapregstr_db=NULL;
+static DBMap* mapreg_db=NULL; // int var_id -> int value
+static DBMap* mapregstr_db=NULL; // int var_id -> char* value
static int mapreg_dirty=-1;
char mapreg_txt[256]="save/mapreg.txt";
#define MAPREG_AUTOSAVE_INTERVAL (300*1000)
-static struct dbt *scriptlabel_db=NULL;
-static struct dbt *userfunc_db=NULL;
+static DBMap* scriptlabel_db=NULL; // const char* label_name -> int script_pos
+static DBMap* userfunc_db=NULL; // const char* func_name -> struct script_code*
static int parse_options=0;
-struct dbt* script_get_label_db(){ return scriptlabel_db; }
-struct dbt* script_get_userfunc_db(){ return userfunc_db; }
+DBMap* script_get_label_db(){ return scriptlabel_db; }
+DBMap* script_get_userfunc_db(){ return userfunc_db; }
struct Script_Config script_config;
@@ -3685,10 +3685,10 @@ int do_final_script()
*------------------------------------------*/
int do_init_script()
{
- mapreg_db= db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int));
- mapregstr_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
- userfunc_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_DUP_KEY,0);
- scriptlabel_db=db_alloc(__FILE__,__LINE__,DB_STRING,DB_OPT_DUP_KEY|DB_OPT_ALLOW_NULL_DATA,50);
+ mapreg_db= idb_alloc(DB_OPT_BASE);
+ mapregstr_db=idb_alloc(DB_OPT_RELEASE_DATA);
+ userfunc_db=strdb_alloc(DB_OPT_DUP_KEY,0);
+ scriptlabel_db=strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_ALLOW_NULL_DATA,50);
script_load_mapreg();
diff --git a/src/map/script.h b/src/map/script.h
index 1e92f73d1..709577c6d 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -88,8 +88,8 @@ void script_free_stack(struct script_stack*);
void script_free_code(struct script_code* code);
void script_free_vars(struct linkdb_node **node);
-struct dbt* script_get_label_db(void);
-struct dbt* script_get_userfunc_db(void);
+struct DBMap* script_get_label_db(void);
+struct DBMap* script_get_userfunc_db(void);
int script_config_read(char *cfgName);
int do_init_script(void);
diff --git a/src/map/storage.c b/src/map/storage.c
index 5d9b67778..e4ff030b3 100644
--- a/src/map/storage.c
+++ b/src/map/storage.c
@@ -24,8 +24,8 @@
#include <string.h>
-static struct dbt *storage_db;
-static struct dbt *guild_storage_db;
+static DBMap* storage_db; // int account_id -> struct storage*
+static DBMap* guild_storage_db; // int guild_id -> struct guild_storage*
/*==========================================
* 倉庫内アイテムソート
@@ -61,8 +61,8 @@ void storage_gsortitem (struct guild_storage* gstor)
*------------------------------------------*/
int do_init_storage(void) // map.c::do_init()から呼ばれる
{
- storage_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
- guild_storage_db=db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_RELEASE_DATA,sizeof(int));
+ storage_db=idb_alloc(DB_OPT_RELEASE_DATA);
+ guild_storage_db=idb_alloc(DB_OPT_RELEASE_DATA);
return 1;
}
void do_final_storage(void) // by [MC Cameri]
diff --git a/src/plugins/console.c b/src/plugins/console.c
index 549091f12..5374d784f 100644
--- a/src/plugins/console.c
+++ b/src/plugins/console.c
@@ -53,7 +53,7 @@ typedef struct _buffer {
/// In linux the worker is a process so it needs to comunicate through pipes.
#define WORKER_FUNC_DECLARE(name) void worker_ ## name(void)
#define WORKER_FUNC_START(name) void worker_ ## name(void) {
-#define WORKER_FUNC_END(name) _exit(EXIT_SUCCESS); }
+#define WORKER_FUNC_END(name) _exit(0); }
#define WORKER_EXECUTE(name,errvar) \
do{ \
int pid = fork(); \
diff --git a/src/txt-converter/login-converter.c b/src/txt-converter/login-converter.c
index 4a9b442f9..1e5aba76a 100644
--- a/src/txt-converter/login-converter.c
+++ b/src/txt-converter/login-converter.c
@@ -7,6 +7,7 @@
#include "../common/db.h"
#include "../common/showmsg.h"
#include "../common/sql.h"
+#include "../common/malloc.h"
#include <stdio.h>
#include <stdlib.h>
@@ -18,7 +19,7 @@ char login_user_pass[256]="user_pass";
char login_db[256]="login";
char globalreg_db[256]="global_reg_value";
-static struct dbt *gm_account_db;
+static DBMap* gm_account_db=NULL; // int account_id -> struct gm_account*
int db_server_port = 3306;
char db_server_ip[32] = "127.0.0.1";
@@ -52,7 +53,7 @@ int read_gm_account()
if( (fp = fopen(GM_ACCOUNT_NAME,"r")) == NULL )
return 1;
- gm_account_db = db_alloc(__FILE__,__LINE__,DB_INT,DB_OPT_BASE,sizeof(int)); //FIXME: never deallocated
+ gm_account_db = idb_alloc(DB_OPT_RELEASE_DATA);
while(fgets(line,sizeof(line),fp))
{
@@ -60,7 +61,7 @@ int read_gm_account()
if ((line[0] == '/' && line[1] == '/') || line[0] == '\0' || line[0] == '\n' || line[0] == '\r')
continue;
- p = (struct gm_account*)malloc(sizeof(struct gm_account));
+ p = (struct gm_account*)aMalloc(sizeof(struct gm_account));
if(p==NULL){
ShowFatalError("gm_account: out of memory!\n");
exit(EXIT_FAILURE);
@@ -73,7 +74,9 @@ int read_gm_account()
else {
if(p->level > 99)
p->level = 99;
- idb_put(gm_account_db,p->account_id,p);
+ p = idb_put(gm_account_db,p->account_id,p);
+ if( p )
+ aFree(p);// old entry replaced
gm_counter++;
ShowInfo("GM ID: %d Level: %d\n",p->account_id,p->level);
}
@@ -227,4 +230,11 @@ int do_init(int argc, char** argv)
void do_abort(void) {}
-void do_final(void) {}
+void do_final(void)
+{
+ if( gm_account_db )
+ {
+ db_destroy(gm_account_db);
+ gm_account_db = NULL;
+ }
+}