Browse Source

* Changed EXIT_SUCCESS back to 0 in console.c to avoid an unnecessary include.
* Fixed gm_account_db not being deallocated in login-converter.c.
* Refactoring names and documentation in db.h/db.c:
- changed 'struct dbt' to 'struct DBMap' and 'DB' to 'DBMap*'
- changed 'struct db' to 'struct DBMap_impl' and 'DB_impl' to 'DBMap_impl*'
- changed COUNT to DB_COUNTSTAT and made it's existence not depend on DB_ENABLE_STATS
- removed some @see links and corrected small typos in the documentation

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@11698 54d463be-8e91-2dee-dedb-b68131a5f0ec

FlavioJS 17 years ago
parent
commit
9d2688ad87

+ 9 - 2
Changelog-Trunk.txt

@@ -4,6 +4,13 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 
 2007/11/08
 2007/11/08
+	* Changed EXIT_SUCCESS back to 0 in console.c to avoid an unnecessary include.
+	* Fixed gm_account_db not being deallocated in login-converter.c.
+	* Refactoring names and documentation in db.h/db.c: [FlavioJS]
+	- changed 'struct dbt' to 'struct DBMap' and 'DB' to 'DBMap*'
+	- changed 'struct db' to 'struct DBMap_impl' and 'DB_impl' to 'DBMap_impl*'
+	- changed COUNT to DB_COUNTSTAT and made it's existence not depend on DB_ENABLE_STATS
+	- removed some @see links and corrected small typos in the documentation
 	* Fixed a glitch where all packets immediately after the map->char
 	* Fixed a glitch where all packets immediately after the map->char
 	  login packet would get discarded and the mapserver disconnected
 	  login packet would get discarded and the mapserver disconnected
 	* Synced charserver char creation creation code [ultramage]
 	* Synced charserver char creation creation code [ultramage]
@@ -11,10 +18,10 @@ IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 	- fixed sql charserver letting you use control chars in char names
 	- fixed sql charserver letting you use control chars in char names
 	- new chars will not start with the 'Knife' and 'Cotton Shirt' equipped
 	- new chars will not start with the 'Knife' and 'Cotton Shirt' equipped
 	  anymore (charserver blindly placed magic values into the equip field)
 	  anymore (charserver blindly placed magic values into the equip field)
-	* Updated configure script:
+	* Updated configure script: [FlavioJS]
 	- small correction to the help text of --with-mysql and --with-pcre
 	- small correction to the help text of --with-mysql and --with-pcre
 	- added the -Wno-switch compiler option to suppress the 
 	- added the -Wno-switch compiler option to suppress the 
-	  "enumeration value '%s' not handled in switch" warnings [FlavioJS]
+	  "enumeration value '%s' not handled in switch" warnings
 2007/11/07
 2007/11/07
 	* Some updates on the mail system packets [Zephyrus]
 	* Some updates on the mail system packets [Zephyrus]
 	- Corrected the mail database structure on main.sql
 	- Corrected the mail database structure on main.sql

+ 3 - 2
src/char/char.c

@@ -169,7 +169,8 @@ struct online_char_data {
 	short server;
 	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)
 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");
 	char_log("The char-server starting...\n");
 
 
 	ShowInfo("Initializing char server.\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();
 	mmo_char_init();
 	char_read_fame_list(); //Read fame lists.
 	char_read_fame_list(); //Read fame lists.
 #ifdef ENABLE_SC_SAVING
 #ifdef ENABLE_SC_SAVING

+ 4 - 4
src/char/int_guild.c

@@ -22,8 +22,8 @@ char guild_txt[1024] = "save/guild.txt";
 char castle_txt[1024] = "save/castle.txt";
 char castle_txt[1024] = "save/castle.txt";
 
 
 #ifndef TXT_SQL_CONVERT
 #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;
 static int guild_newid = 10000;
 
 
@@ -376,8 +376,8 @@ int inter_guild_init() {
 
 
 	inter_guild_readdb();
 	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)
 	if ((fp = fopen(guild_txt,"r")) == NULL)
 		return 1;
 		return 1;

+ 2 - 2
src/char/int_homun.c

@@ -17,7 +17,7 @@
 
 
 char homun_txt[1024]="save/homun.txt";
 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;
 static int homun_newid = 100;
 
 
 int inter_homun_tostr(char *str,struct s_homunculus *p)
 int inter_homun_tostr(char *str,struct s_homunculus *p)
@@ -118,7 +118,7 @@ int inter_homun_init()
 	FILE *fp;
 	FILE *fp;
 	int c=0;
 	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 )
 	if( (fp=fopen(homun_txt,"r"))==NULL )
 		return 1;
 		return 1;

+ 2 - 2
src/char/int_party.c

@@ -25,7 +25,7 @@ struct party_data {
 	unsigned char size; //Total size of party.
 	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;
 static int party_newid = 100;
 
 
 int mapif_party_broken(int party_id, int flag);
 int mapif_party_broken(int party_id, int flag);
@@ -178,7 +178,7 @@ int inter_party_init() {
 	int c = 0;
 	int c = 0;
 	int i, j;
 	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)
 	if ((fp = fopen(party_txt, "r")) == NULL)
 		return 1;
 		return 1;

+ 2 - 2
src/char/int_pet.c

@@ -18,7 +18,7 @@
 char pet_txt[1024]="save/pet.txt";
 char pet_txt[1024]="save/pet.txt";
 
 
 #ifndef TXT_SQL_CONVERT
 #ifndef TXT_SQL_CONVERT
-static struct dbt *pet_db;
+static DBMap* pet_db; // int pet_id -> struct s_pet*
 static int pet_newid = 100;
 static int pet_newid = 100;
 
 
 int inter_pet_tostr(char *str,struct s_pet *p)
 int inter_pet_tostr(char *str,struct s_pet *p)
@@ -88,7 +88,7 @@ int inter_pet_init()
 	FILE *fp;
 	FILE *fp;
 	int c=0;
 	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 )
 	if( (fp=fopen(pet_txt,"r"))==NULL )
 		return 1;
 		return 1;

+ 3 - 2
src/char/int_status.c

@@ -10,7 +10,8 @@
 
 
 #include <stdio.h>
 #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]
 char scdata_txt[1024]="save/scdata.txt"; //By [Skotlex]
 
 
 #ifdef ENABLE_SC_SAVING
 #ifdef ENABLE_SC_SAVING
@@ -156,7 +157,7 @@ void inter_status_save()
  *------------------------------------------*/
  *------------------------------------------*/
 void status_init()
 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);
 	status_load_scdata(scdata_txt);
 }
 }
 
 

+ 4 - 4
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";
 char guild_storage_txt[1024]="save/g_storage.txt";
 
 
 #ifndef TXT_SQL_CONVERT
 #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)
 int storage_tostr(char *str,struct storage *p)
@@ -198,7 +198,7 @@ int inter_storage_init()
 	struct guild_storage *gs;
 	struct guild_storage *gs;
 	FILE *fp;
 	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");
 	fp=fopen(storage_txt,"r");
 	if(fp==NULL){
 	if(fp==NULL){
@@ -227,7 +227,7 @@ int inter_storage_init()
 	fclose(fp);
 	fclose(fp);
 
 
 	c = 0;
 	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");
 	fp=fopen(guild_storage_txt,"r");
 	if(fp==NULL){
 	if(fp==NULL){

+ 4 - 4
src/char/inter.c

@@ -30,7 +30,7 @@ char accreg_txt[1024] = "save/accreg.txt";
 char inter_log_filename[1024] = "log/inter.log";
 char inter_log_filename[1024] = "log/inter.log";
 char main_chat_nick[16] = "Main";
 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;
 unsigned int party_share_level = 10;
 
 
@@ -66,7 +66,7 @@ struct WisData {
 	unsigned long tick;
 	unsigned long tick;
 	unsigned char src[24], dst[24], msg[1024];
 	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;
 static int wis_dellist[WISDELLIST_MAX], wis_delnum;
 
 
 
 
@@ -109,7 +109,7 @@ int inter_accreg_init(void) {
 	int c = 0;
 	int c = 0;
 	struct accreg *reg;
 	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)
 	if( (fp = fopen(accreg_txt, "r")) == NULL)
 		return 1;
 		return 1;
@@ -259,7 +259,7 @@ int inter_init_txt(const char *file) {
 	inter_config_read(file);
 	inter_config_read(file);
 
 
 #ifndef TXT_SQL_CONVERT
 #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_party_init();
 	inter_guild_init();
 	inter_guild_init();

+ 5 - 4
src/char_sql/char.c

@@ -64,7 +64,7 @@ char friend_db[256] = "friends";
 char hotkey_db[256] = "hotkey";
 char hotkey_db[256] = "hotkey";
 
 
 #ifndef TXT_SQL_CONVERT
 #ifndef TXT_SQL_CONVERT
-static struct dbt *char_db_;
+static DBMap* char_db_; // int char_id -> struct mmo_charstatus*
 
 
 char db_path[1024] = "db";
 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
 	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)
 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)
 int mmo_char_sql_init(void)
 {
 {
 	ShowInfo("Begin Initializing.......\n");
 	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){
 	if(char_per_account == 0){
 	  ShowStatus("Chars per Account: 'Unlimited'.......\n");
 	  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("Finished reading the inter-server configuration.\n");
 	
 	
 	ShowInfo("Initializing char server.\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();
 	mmo_char_sql_init();
 	char_read_fame_list(); //Read fame lists.
 	char_read_fame_list(); //Read fame lists.
 	if(char_gm_read)
 	if(char_gm_read)

+ 2 - 2
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
 #ifndef TXT_SQL_CONVERT
 //Guild cache
 //Guild cache
-static struct dbt *guild_db_;
+static DBMap* guild_db_; // int guild_id -> struct guild*
 
 
 struct guild_castle castles[MAX_GUILDCASTLE];
 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)
 int inter_guild_sql_init(void)
 {
 {
 	//Initialize the guild cache
 	//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
    //Read exp file
 	inter_guild_ReadEXP();
 	inter_guild_ReadEXP();

+ 2 - 2
src/char_sql/int_party.c

@@ -27,7 +27,7 @@ struct party_data {
 };
 };
 
 
 static struct party_data *party_pt;
 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 mapif_party_broken(int party_id,int flag);
 int party_check_empty(struct party_data *p);
 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)
 int inter_party_sql_init(void)
 {
 {
 	//memory alloc
 	//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);
 	party_pt = (struct party_data*)aCalloc(sizeof(struct party_data), 1);
 	if (!party_pt) {
 	if (!party_pt) {
 		ShowFatalError("inter_party_sql_init: Out of Memory!\n");
 		ShowFatalError("inter_party_sql_init: Out of Memory!\n");

+ 2 - 2
src/char_sql/inter.c

@@ -79,7 +79,7 @@ struct WisData {
 	unsigned long tick;
 	unsigned long tick;
 	unsigned char src[24], dst[24], msg[512];
 	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;
 static int wis_dellist[WISDELLIST_MAX], wis_delnum;
 
 
 int inter_sql_test (void);
 int inter_sql_test (void);
@@ -390,7 +390,7 @@ int inter_init_sql(const char *file)
 	}
 	}
 
 
 #ifndef TXT_SQL_CONVERT
 #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_guild_sql_init();
 	inter_storage_sql_init();
 	inter_storage_sql_init();
 	inter_party_sql_init();
 	inter_party_sql_init();

File diff suppressed because it is too large
+ 168 - 270
src/common/db.c


+ 105 - 126
src/common/db.h

@@ -23,8 +23,8 @@
  *  HISTORY:                                                                 *
  *  HISTORY:                                                                 *
  *    2.1 (Athena build #???#) - Portability fix                             *
  *    2.1 (Athena build #???#) - Portability fix                             *
  *      - Fixed the portability of casting to union and added the functions  *
  *      - 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                           *
  *    2.0 (Athena build 4859) - Transition version                           *
  *      - Almost everything recoded with a strategy similar to objects,      *
  *      - Almost everything recoded with a strategy similar to objects,      *
  *        database structure is maintained.                                  *
  *        database structure is maintained.                                  *
@@ -40,6 +40,7 @@
 #ifndef _DB_H_
 #ifndef _DB_H_
 #define _DB_H_
 #define _DB_H_
 
 
+#include "../common/cbasetypes.h"
 #include <stdarg.h>
 #include <stdarg.h>
 
 
 /*****************************************************************************\
 /*****************************************************************************\
@@ -51,19 +52,19 @@
  *  DBOptions    - Bitfield enumeration of database options.                 *
  *  DBOptions    - Bitfield enumeration of database options.                 *
  *  DBKey        - Union of used key types.                                  *
  *  DBKey        - Union of used key types.                                  *
  *  DBApply      - Format of functions applyed to the databases.             *
  *  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.          *
  *  DBComparator - Format of the comparators used by the databases.          *
  *  DBHasher     - Format of the hashers used by the databases.              *
  *  DBHasher     - Format of the hashers used by the databases.              *
  *  DBReleaser   - Format of the releasers 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.
  * Define this to enable the functions that cast to unions.
  * Required when the compiler doesn't support casting to unions.
  * Required when the compiler doesn't support casting to unions.
  * NOTE: It is recommened that the conditional tests to determine if this 
  * 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
  * @public
  * @see #db_i2key(int)
  * @see #db_i2key(int)
  * @see #db_ui2key(unsigned 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_KEY Releases the key.
  * @param DB_OPT_RELEASE_DATA Releases the data whenever an entry is removed 
  * @param DB_OPT_RELEASE_DATA Releases the data whenever an entry is removed 
  *          from the database.
  *          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.
  *          a dangling pointer will be returned.
  * @param DB_OPT_RELEASE_BOTH Releases both key and data.
  * @param DB_OPT_RELEASE_BOTH Releases both key and data.
  * @param DB_OPT_ALLOW_NULL_KEY Allow NULL keys in the database.
  * @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_default_release(DBType,DBOptions)
  * @see #db_alloc(const char *,int,DBType,DBOptions,unsigned short)
  * @see #db_alloc(const char *,int,DBType,DBOptions,unsigned short)
  */
  */
-typedef enum db_opt {
+typedef enum DBOptions {
 	DB_OPT_BASE            = 0,
 	DB_OPT_BASE            = 0,
 	DB_OPT_DUP_KEY         = 1,
 	DB_OPT_DUP_KEY         = 1,
 	DB_OPT_RELEASE_KEY     = 2,
 	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
  * @param str Type of key for DB_STRING and DB_ISTRING databases
  * @public
  * @public
  * @see #DBType
  * @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;
 	int i;
 	unsigned int ui;
 	unsigned int ui;
 	const char *str;
 	const char *str;
@@ -164,27 +165,27 @@ typedef union dbkey {
  * @param args Extra arguments of the funtion
  * @param args Extra arguments of the funtion
  * @return Data identified by the key to be put in the database
  * @return Data identified by the key to be put in the database
  * @public
  * @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 
  * Format of functions to be applyed to an unspecified quantity of entries of 
  * a database.
  * 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.
  * of values returned by this function.
  * @param key Key of the database entry
  * @param key Key of the database entry
  * @param data Data of the database entry
  * @param data Data of the database entry
  * @param args Extra arguments of the funtion
  * @param args Extra arguments of the funtion
  * @return Value to be added up by the funtion that is applying this
  * @return Value to be added up by the funtion that is applying this
  * @public
  * @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.
  * 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
  * @param args Extra arguments of the function
  * @return 0 if a match, another number otherwise
  * @return 0 if a match, another number otherwise
  * @public
  * @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.
  * 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_default_releaser(DBType,DBOptions)
  * @see #db_custom_release(DBRelease)
  * @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.
  * Public interface of a database. Only contains funtions.
  * All the functions take the interface as the first argument.
  * All the functions take the interface as the first argument.
  * @public
  * @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.
 	 * 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
 	 * @param key Key that identifies the entry
 	 * @return Data of the entry or NULL if not found
 	 * @return Data of the entry or NULL if not found
 	 * @protected
 	 * @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>.
 	 * Get the data of the entries matched by <code>match</code>.
 	 * It puts a maximum of <code>max</code> entries into <code>buf</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.
 	 * If <code>buf</code> is NULL, it only counts the matches.
 	 * Returns the number of entries that matched.
 	 * Returns the number of entries that matched.
 	 * NOTE: if the value returned is greater than <code>max</code>, only the 
 	 * NOTE: if the value returned is greater than <code>max</code>, only the 
 	 * first <code>max</code> entries found are put into the buffer.
 	 * 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 buf Buffer to put the data of the matched entries
 	 * @param max Maximum number of data entries to be put into buf
 	 * @param max Maximum number of data entries to be put into buf
 	 * @param match Function that matches the database entries
 	 * @param match Function that matches the database entries
 	 * @param ... Extra arguments for match
 	 * @param ... Extra arguments for match
 	 * @return The number of entries that matched
 	 * @return The number of entries that matched
 	 * @protected
 	 * @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>.
 	 * Get the data of the entries matched by <code>match</code>.
@@ -301,149 +293,139 @@ struct dbt {
 	 * Returns the number of entries that matched.
 	 * Returns the number of entries that matched.
 	 * NOTE: if the value returned is greater than <code>max</code>, only the 
 	 * NOTE: if the value returned is greater than <code>max</code>, only the 
 	 * first <code>max</code> entries found are put into the buffer.
 	 * 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 buf Buffer to put the data of the matched entries
 	 * @param max Maximum number of data entries to be put into buf
 	 * @param max Maximum number of data entries to be put into buf
 	 * @param match Function that matches the database entries
 	 * @param match Function that matches the database entries
 	 * @param ... Extra arguments for match
 	 * @param ... Extra arguments for match
 	 * @return The number of entries that matched
 	 * @return The number of entries that matched
 	 * @protected
 	 * @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.
 	 * 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 
 	 * If the entry does not exist, an entry is added with the data returned by 
 	 * <code>create</code>.
 	 * <code>create</code>.
-	 * @param dbi Interface of the database
+	 * @param self Database
 	 * @param key Key that identifies the entry
 	 * @param key Key that identifies the entry
 	 * @param create Function used to create the data if the entry doesn't exist
 	 * @param create Function used to create the data if the entry doesn't exist
 	 * @param ... Extra arguments for create
 	 * @param ... Extra arguments for create
 	 * @return Data of the entry
 	 * @return Data of the entry
 	 * @protected
 	 * @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.
 	 * 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 
 	 * If the entry does not exist, an entry is added with the data returned by 
 	 * <code>create</code>.
 	 * <code>create</code>.
-	 * @param dbi Interface of the database
+	 * @param self Database
 	 * @param key Key that identifies the entry
 	 * @param key Key that identifies the entry
 	 * @param create Function used to create the data if the entry doesn't exist
 	 * @param create Function used to create the data if the entry doesn't exist
 	 * @param args Extra arguments for create
 	 * @param args Extra arguments for create
 	 * @return Data of the entry
 	 * @return Data of the entry
 	 * @protected
 	 * @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.
 	 * Put the data identified by the key in the database.
 	 * Returns the previous data if the entry exists or NULL.
 	 * Returns the previous data if the entry exists or NULL.
 	 * NOTE: Uses the new key, the old one is released.
 	 * 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 key Key that identifies the data
 	 * @param data Data to be put in the database
 	 * @param data Data to be put in the database
 	 * @return The previous data if the entry exists or NULL
 	 * @return The previous data if the entry exists or NULL
 	 * @protected
 	 * @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.
 	 * Remove an entry from the database.
 	 * Returns the data of the entry.
 	 * Returns the data of the entry.
 	 * NOTE: The key (of the database) is released.
 	 * NOTE: The key (of the database) is released.
-	 * @param dbi Interface of the database
+	 * @param self Database
 	 * @param key Key that identifies the entry
 	 * @param key Key that identifies the entry
 	 * @return The data of the entry or NULL if not found
 	 * @return The data of the entry or NULL if not found
 	 * @protected
 	 * @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.
 	 * Apply <code>func</code> to every entry in the database.
 	 * Returns the sum of values returned by func.
 	 * Returns the sum of values returned by func.
-	 * @param dbi Interface of the database
+	 * @param self Database
 	 * @param func Function to be applyed
 	 * @param func Function to be applyed
 	 * @param ... Extra arguments for func
 	 * @param ... Extra arguments for func
 	 * @return Sum of the values returned by func
 	 * @return Sum of the values returned by func
 	 * @protected
 	 * @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.
 	 * Apply <code>func</code> to every entry in the database.
 	 * Returns the sum of values returned by func.
 	 * Returns the sum of values returned by func.
-	 * @param dbi Interface of the database
+	 * @param self Database
 	 * @param func Function to be applyed
 	 * @param func Function to be applyed
 	 * @param args Extra arguments for func
 	 * @param args Extra arguments for func
 	 * @return Sum of the values returned by func
 	 * @return Sum of the values returned by func
 	 * @protected
 	 * @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.
 	 * Removes all entries from the database.
 	 * Before deleting an entry, func is applyed to it.
 	 * Before deleting an entry, func is applyed to it.
 	 * Releases the key and the data.
 	 * Releases the key and the data.
 	 * Returns the sum of values returned by func, if it exists.
 	 * 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 func Function to be applyed to every entry before deleting
 	 * @param ... Extra arguments for func
 	 * @param ... Extra arguments for func
 	 * @return Sum of values returned by func
 	 * @return Sum of values returned by func
 	 * @protected
 	 * @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.
 	 * Removes all entries from the database.
 	 * Before deleting an entry, func is applyed to it.
 	 * Before deleting an entry, func is applyed to it.
 	 * Releases the key and the data.
 	 * Releases the key and the data.
 	 * Returns the sum of values returned by func, if it exists.
 	 * 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 func Function to be applyed to every entry before deleting
 	 * @param args Extra arguments for func
 	 * @param args Extra arguments for func
 	 * @return Sum of values returned by func
 	 * @return Sum of values returned by func
 	 * @protected
 	 * @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.
 	 * Finalize the database, feeing all the memory it uses.
 	 * Before deleting an entry, func is applyed to it.
 	 * Before deleting an entry, func is applyed to it.
 	 * Releases the key and the data.
 	 * Releases the key and the data.
 	 * Returns the sum of values returned by func, if it exists.
 	 * Returns the sum of values returned by func, if it exists.
 	 * NOTE: This locks the database globally. Any attempt to insert or remove 
 	 * 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).
 	 * 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 func Function to be applyed to every entry before deleting
 	 * @param ... Extra arguments for func
 	 * @param ... Extra arguments for func
 	 * @return Sum of values returned by func
 	 * @return Sum of values returned by func
 	 * @protected
 	 * @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.
 	 * 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.
 	 * Returns the sum of values returned by func, if it exists.
 	 * NOTE: This locks the database globally. Any attempt to insert or remove 
 	 * 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).
 	 * 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 func Function to be applyed to every entry before deleting
 	 * @param args Extra arguments for func
 	 * @param args Extra arguments for func
 	 * @return Sum of values returned by func
 	 * @return Sum of values returned by func
 	 * @protected
 	 * @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).
 	 * 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
 	 * @return Size of the database
 	 * @protected
 	 * @protected
-	 * @see #db_size(DB)
 	 */
 	 */
-	unsigned int (*size)(DB self);
+	unsigned int (*size)(DBMap* self);
 
 
 	/**
 	/**
 	 * Return the type of the database.
 	 * Return the type of the database.
-	 * @param dbi Interface of the database
+	 * @param self Database
 	 * @return Type of the database
 	 * @return Type of the database
 	 * @protected
 	 * @protected
-	 * @see #db_type(DB)
 	 */
 	 */
-	DBType (*type)(DB self);
+	DBType (*type)(DBMap* self);
 
 
 	/**
 	/**
 	 * Return the options of the database.
 	 * Return the options of the database.
-	 * @param dbi Interface of the database
+	 * @param self Database
 	 * @return Options of the database
 	 * @return Options of the database
 	 * @protected
 	 * @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))
 #	define str2key(k) ((DBKey)(const char *)(k))
 #endif /* not DB_MANUAL_CAST_TO_UNION */
 #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
 //These are discarding the possible vargs you could send to the function, so those
 //that require vargs must not use these defines.
 //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.                                       *
  *  (2) Section with public functions.                                       *
@@ -550,7 +535,6 @@ struct dbt {
  * @see #DBType
  * @see #DBType
  * @see #DBOptions
  * @see #DBOptions
  * @see #db_default_release(DBType,DBOptions)
  * @see #db_default_release(DBType,DBOptions)
- * @see common\db.c#db_fix_options(DBType,DBOptions)
  */
  */
 DBOptions db_fix_options(DBType type, DBOptions options);
 DBOptions db_fix_options(DBType type, DBOptions options);
 
 
@@ -561,7 +545,6 @@ DBOptions db_fix_options(DBType type, DBOptions options);
  * @public
  * @public
  * @see #DBType
  * @see #DBType
  * @see #DBComparator
  * @see #DBComparator
- * @see common\db.c#db_default_cmp(DBType)
  */
  */
 DBComparator db_default_cmp(DBType type);
 DBComparator db_default_cmp(DBType type);
 
 
@@ -572,7 +555,6 @@ DBComparator db_default_cmp(DBType type);
  * @public
  * @public
  * @see #DBType
  * @see #DBType
  * @see #DBHasher
  * @see #DBHasher
- * @see common\db.c#db_default_hash(DBType)
  */
  */
 DBHasher db_default_hash(DBType type);
 DBHasher db_default_hash(DBType type);
 
 
@@ -590,7 +572,6 @@ DBHasher db_default_hash(DBType type);
  * @see #DBReleaser
  * @see #DBReleaser
  * @see #db_fix_options(DBType,DBOptions)
  * @see #db_fix_options(DBType,DBOptions)
  * @see #db_custom_release(DBRelease)
  * @see #db_custom_release(DBRelease)
- * @see common\db.c#db_default_release(DBType,DBOptions)
  */
  */
 DBReleaser db_default_release(DBType type, DBOptions options);
 DBReleaser db_default_release(DBType type, DBOptions options);
 
 
@@ -602,7 +583,6 @@ DBReleaser db_default_release(DBType type, DBOptions options);
  * @see #DBRelease
  * @see #DBRelease
  * @see #DBReleaser
  * @see #DBReleaser
  * @see #db_default_release(DBType,DBOptions)
  * @see #db_default_release(DBType,DBOptions)
- * @see common\db.c#db_custom_release(DBRelease)
  */
  */
 DBReleaser db_custom_release(DBRelease which);
 DBReleaser db_custom_release(DBRelease which);
 
 
@@ -621,14 +601,13 @@ DBReleaser db_custom_release(DBRelease which);
  * @return The interface of the database
  * @return The interface of the database
  * @public
  * @public
  * @see #DBType
  * @see #DBType
- * @see #DB
+ * @see #DBMap
  * @see #db_default_cmp(DBType)
  * @see #db_default_cmp(DBType)
  * @see #db_default_hash(DBType)
  * @see #db_default_hash(DBType)
  * @see #db_default_release(DBType,DBOptions)
  * @see #db_default_release(DBType,DBOptions)
  * @see #db_fix_options(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
 #ifdef DB_MANUAL_CAST_TO_UNION
 /**
 /**

+ 2 - 2
src/login/login.c

@@ -159,7 +159,7 @@ char gm_pass[64] = "";
 int level_new_gm = 60;
 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);
 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;
 		server_fd[i] = -1;
 
 
 	// Online user database init
 	// 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");
 	add_timer_func_list(waiting_disconnect_timer, "waiting_disconnect_timer");
 
 
 	// Auth init
 	// Auth init

+ 2 - 2
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)
 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;
 		server_fd[i] = -1;
 
 
 	// Online user database init
 	// 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");
 	add_timer_func_list(waiting_disconnect_timer, "waiting_disconnect_timer");
 
 
 	// Auth init
 	// Auth init

+ 2 - 2
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)
  * @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 users_all;
 
 
 static int atcommand_users_sub1(struct map_session_data* sd,va_list va)
 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()
 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;
 	duel_count = 0;
 	memset(&duel_list[0], 0, sizeof(duel_list));
 	memset(&duel_list[0], 0, sizeof(duel_list));
 	add_timer_func_list(atshowmobs_timer, "atshowmobs_timer");
 	add_timer_func_list(atshowmobs_timer, "atshowmobs_timer");

+ 6 - 6
src/map/chrif.c

@@ -25,7 +25,7 @@
 #include <sys/types.h>
 #include <sys/types.h>
 #include <time.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
 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
 	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->account_id = sd->bl.id;
 		auth_data->login_id1 = sd->login_id1;
 		auth_data->login_id1 = sd->login_id1;
 		auth_data->node_created = gettick();
 		auth_data->node_created = gettick();
-		uidb_put(auth_db, sd->bl.id, auth_data);
+		idb_put(auth_db, sd->bl.id, auth_data);
 	}
 	}
 	return;
 	return;
 }
 }
@@ -451,7 +451,7 @@ void chrif_authok(int fd)
 			return;
 			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?
 	{	//Is the character already awaiting authorization?
 		if (auth_data->sd)
 		if (auth_data->sd)
 		{
 		{
@@ -472,7 +472,7 @@ void chrif_authok(int fd)
 		//Delete the data of this node...
 		//Delete the data of this node...
 		if (auth_data->char_dat)
 		if (auth_data->char_dat)
 			aFree (auth_data->char_dat);
 			aFree (auth_data->char_dat);
-		uidb_remove(auth_db, RFIFOL(fd, 4));
+		idb_remove(auth_db, RFIFOL(fd, 4));
 		return;
 		return;
 	}
 	}
 	// Awaiting for client to connect.
 	// Awaiting for client to connect.
@@ -485,7 +485,7 @@ void chrif_authok(int fd)
 	auth_data->login_id2=RFIFOL(fd, 16);
 	auth_data->login_id2=RFIFOL(fd, 16);
 	memcpy(auth_data->char_dat,RFIFOP(fd, 20),sizeof(struct mmo_charstatus));
 	memcpy(auth_data->char_dat,RFIFOP(fd, 20),sizeof(struct mmo_charstatus));
 	auth_data->node_created=gettick();
 	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)
 int auth_db_cleanup_sub(DBKey key,void *data,va_list ap)
@@ -1445,7 +1445,7 @@ int do_init_chrif(void)
 #endif
 #endif
 	add_timer_interval(gettick() + 1000, auth_db_cleanup, 0, 0, 30 * 1000);
 	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;
 	return 0;
 }
 }

+ 10 - 10
src/map/guild.c

@@ -29,11 +29,11 @@
 #include <string.h>
 #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 {
 struct eventlist {
 	char name[50];
 	char name[50];
@@ -204,12 +204,12 @@ static int guild_read_castledb(void)
 // �‰Šú‰»
 // �‰Šú‰»
 void do_init_guild(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)); 
 	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();
 	guild_read_castledb();
 
 

+ 2 - 2
src/map/itemdb.c

@@ -21,7 +21,7 @@
 
 
 
 
 static struct item_data* itemdb_array[MAX_ITEMDB];
 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];
 static struct item_group itemgroup_db[MAX_ITEMGROUP];
 
 
@@ -1044,7 +1044,7 @@ void do_final_itemdb(void)
 int do_init_itemdb(void)
 int do_init_itemdb(void)
 {
 {
 	memset(itemdb_array, 0, sizeof(itemdb_array));
 	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.
 	create_dummy_data(); //Dummy data item.
 	itemdb_read();
 	itemdb_read();
 
 

+ 10 - 10
src/map/map.c

@@ -93,11 +93,11 @@ char *SCRIPT_CONF_NAME;
 char *MSG_CONF_NAME;
 char *MSG_CONF_NAME;
 
 
 // ‹É—Í static‚Ń�?ƒJƒ‹‚É?‚ß‚é
 // ‹É—Í static‚Ń�?ƒJƒ‹‚É?‚ß‚é
-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 int map_users=0;
 static struct block_list *objects[MAX_FLOORITEM];
 static struct block_list *objects[MAX_FLOORITEM];
@@ -3303,11 +3303,11 @@ int do_init(int argc, char *argv[])
 	inter_config_read(INTER_CONF_NAME);
 	inter_config_read(INTER_CONF_NAME);
 	log_config_read(LOG_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
 #ifndef TXT_ONLY
 	map_sql_init();
 	map_sql_init();
 #endif /* not TXT_ONLY */
 #endif /* not TXT_ONLY */

+ 6 - 6
src/map/npc.c

@@ -49,8 +49,8 @@ static int npc_delay_mob=0;
 static int npc_cache_mob=0;
 static int npc_cache_mob=0;
 int npc_get_new_npc_id(void){ return npc_id++; }
 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 event_data {
 	struct npc_data *nd;
 	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;
 		src_id = 0;
 		if( script )
 		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->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
 			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>}
 /// 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)
 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 *script;
 	struct script_code *oldscript;
 	struct script_code *oldscript;
 	const char* end;
 	const char* end;
@@ -2867,8 +2867,8 @@ int do_init_npc(void)
 	for( i = 1; i < MAX_NPC_CLASS; i++ ) 
 	for( i = 1; i < MAX_NPC_CLASS; i++ ) 
 		npc_viewdb[i].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));
 	memset(&ev_tm_b, -1, sizeof(ev_tm_b));
 	timer_event_ers = ers_new(sizeof(struct timer_event_data));
 	timer_event_ers = ers_new(sizeof(struct timer_event_data));

+ 2 - 2
src/map/party.c

@@ -26,7 +26,7 @@
 #include <string.h>
 #include <string.h>
 
 
 
 
-static DB party_db;
+static DBMap* party_db; // int party_id -> struct party_data*
 int party_share_level = 10;
 int party_share_level = 10;
 int party_send_xy_timer(int tid,unsigned int tick,int id,int data);
 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)
 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_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);
 	add_timer_interval(gettick()+battle_config.party_update_interval, party_send_xy_timer, 0, 0, battle_config.party_update_interval);
 }
 }

+ 10 - 10
src/map/script.c

@@ -170,17 +170,17 @@ int str_hash[SCRIPT_HASH_SIZE];
 //#define SCRIPT_HASH_ELF
 //#define SCRIPT_HASH_ELF
 //#define SCRIPT_HASH_PJW
 //#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;
 static int mapreg_dirty=-1;
 char mapreg_txt[256]="save/mapreg.txt";
 char mapreg_txt[256]="save/mapreg.txt";
 #define MAPREG_AUTOSAVE_INTERVAL	(300*1000)
 #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;
 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;
 struct Script_Config script_config;
 
 
@@ -3685,10 +3685,10 @@ int do_final_script()
  *------------------------------------------*/
  *------------------------------------------*/
 int do_init_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();
 	script_load_mapreg();
 
 

+ 2 - 2
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_code(struct script_code* code);
 void script_free_vars(struct linkdb_node **node);
 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 script_config_read(char *cfgName);
 int do_init_script(void);
 int do_init_script(void);

+ 4 - 4
src/map/storage.c

@@ -24,8 +24,8 @@
 #include <string.h>
 #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()から呼ばれる
 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;
 	return 1;
 }
 }
 void do_final_storage(void) // by [MC Cameri]
 void do_final_storage(void) // by [MC Cameri]

+ 1 - 1
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.
 /// 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_DECLARE(name) void worker_ ## name(void)
 #define WORKER_FUNC_START(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) \
 #define WORKER_EXECUTE(name,errvar) \
 	do{ \
 	do{ \
 		int pid = fork(); \
 		int pid = fork(); \

+ 15 - 5
src/txt-converter/login-converter.c

@@ -7,6 +7,7 @@
 #include "../common/db.h"
 #include "../common/db.h"
 #include "../common/showmsg.h"
 #include "../common/showmsg.h"
 #include "../common/sql.h"
 #include "../common/sql.h"
+#include "../common/malloc.h"
 
 
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
@@ -18,7 +19,7 @@ char login_user_pass[256]="user_pass";
 char login_db[256]="login";
 char login_db[256]="login";
 char globalreg_db[256]="global_reg_value";
 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;
 int db_server_port = 3306;
 char db_server_ip[32] = "127.0.0.1";
 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 )
 	if( (fp = fopen(GM_ACCOUNT_NAME,"r")) == NULL )
 		return 1;
 		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))
 	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')
 		if ((line[0] == '/' && line[1] == '/') || line[0] == '\0' || line[0] == '\n' || line[0] == '\r')
 			continue;
 			continue;
 		
 		
-		p = (struct gm_account*)malloc(sizeof(struct gm_account));
+		p = (struct gm_account*)aMalloc(sizeof(struct gm_account));
 		if(p==NULL){
 		if(p==NULL){
 			ShowFatalError("gm_account: out of memory!\n");
 			ShowFatalError("gm_account: out of memory!\n");
 			exit(EXIT_FAILURE);
 			exit(EXIT_FAILURE);
@@ -73,7 +74,9 @@ int read_gm_account()
 		else {
 		else {
 			if(p->level > 99)
 			if(p->level > 99)
 				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++;
 			gm_counter++;
 			ShowInfo("GM ID: %d Level: %d\n",p->account_id,p->level);
 			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_abort(void) {}
 
 
-void do_final(void) {}
+void do_final(void)
+{
+	if( gm_account_db )
+	{
+		db_destroy(gm_account_db);
+		gm_account_db = NULL;
+	}
+}

Some files were not shown because too many files changed in this diff