summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/char/char.c12
-rw-r--r--src/char/int_guild.c4
-rw-r--r--src/char/inter.c2
-rw-r--r--src/common/HPM.c4
-rw-r--r--src/common/HPMi.h4
-rw-r--r--src/common/console.c2
-rw-r--r--src/common/core.c10
-rw-r--r--src/common/db.c32
-rw-r--r--src/common/db.h123
-rw-r--r--src/common/malloc.c79
-rw-r--r--src/common/malloc.h74
-rw-r--r--src/login/login.c6
-rw-r--r--src/map/atcommand.c8
-rw-r--r--src/map/battleground.c2
-rw-r--r--src/map/chrif.c6
-rw-r--r--src/map/guild.c28
-rw-r--r--src/map/itemdb.c8
-rw-r--r--src/map/map.c14
-rw-r--r--src/map/npc.c14
-rw-r--r--src/map/script.c2
-rw-r--r--src/map/skill.c2
-rw-r--r--src/map/storage.c4
22 files changed, 243 insertions, 197 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 6e0f5363e..00fc633df 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -187,7 +187,7 @@ static DBData create_online_char_data(DBKey key, va_list args)
character->pincode_enable = -1;
character->fd = -1;
character->waiting_disconnect = INVALID_TIMER;
- return db_ptr2data(character);
+ return DB->ptr2data(character);
}
void set_char_charselect(int account_id)
@@ -321,7 +321,7 @@ void set_char_offline(int char_id, int account_id)
*/
static int char_db_setoffline(DBKey key, DBData *data, va_list ap)
{
- struct online_char_data* character = (struct online_char_data*)db_data2ptr(data);
+ struct online_char_data* character = (struct online_char_data*)DB->data2ptr(data);
int server = va_arg(ap, int);
if (server == -1) {
character->char_id = -1;
@@ -340,7 +340,7 @@ static int char_db_setoffline(DBKey key, DBData *data, va_list ap)
*/
static int char_db_kickoffline(DBKey key, DBData *data, va_list ap)
{
- struct online_char_data* character = (struct online_char_data*)db_data2ptr(data);
+ struct online_char_data* character = (struct online_char_data*)DB->data2ptr(data);
int server_id = va_arg(ap, int);
if (server_id > -1 && character->server != server_id)
@@ -392,7 +392,7 @@ static DBData create_charstatus(DBKey key, va_list args)
struct mmo_charstatus *cp;
cp = (struct mmo_charstatus *) aCalloc(1,sizeof(struct mmo_charstatus));
cp->char_id = key.i;
- return db_ptr2data(cp);
+ return DB->ptr2data(cp);
}
int inventory_to_sql(const struct item items[], int max, int id);
@@ -4450,7 +4450,7 @@ int broadcast_user_count(int tid, unsigned int tick, int id, intptr_t data)
*/
static int send_accounts_tologin_sub(DBKey key, DBData *data, va_list ap)
{
- struct online_char_data* character = db_data2ptr(data);
+ struct online_char_data* character = DB->data2ptr(data);
int* i = va_arg(ap, int*);
if(character->server > -1)
@@ -4532,7 +4532,7 @@ static int chardb_waiting_disconnect(int tid, unsigned int tick, int id, intptr_
*/
static int online_data_cleanup_sub(DBKey key, DBData *data, va_list ap)
{
- struct online_char_data *character= db_data2ptr(data);
+ struct online_char_data *character= DB->data2ptr(data);
if (character->fd != -1)
return 0; //Character still connected
if (character->server == -2) //Unknown server.. set them offline
diff --git a/src/char/int_guild.c b/src/char/int_guild.c
index b666cadae..e1e012725 100644
--- a/src/char/int_guild.c
+++ b/src/char/int_guild.c
@@ -57,7 +57,7 @@ static int guild_save_timer(int tid, unsigned int tick, int id, intptr_t data)
if( last_id == 0 ) //Save the first guild in the list.
state = 1;
- for( g = db_data2ptr(iter->first(iter, &key)); dbi_exists(iter); g = db_data2ptr(iter->next(iter, &key)) )
+ for( g = DB->data2ptr(iter->first(iter, &key)); dbi_exists(iter); g = DB->data2ptr(iter->next(iter, &key)) )
{
if( state == 0 && g->guild_id == last_id )
state++; //Save next guild in the list.
@@ -739,7 +739,7 @@ int inter_guild_sql_init(void)
*/
static int guild_db_final(DBKey key, DBData *data, va_list ap)
{
- struct guild *g = db_data2ptr(data);
+ struct guild *g = DB->data2ptr(data);
if (g->save_flag&GS_MASK) {
inter_guild_tosql(g, g->save_flag&GS_MASK);
return 1;
diff --git a/src/char/inter.c b/src/char/inter.c
index 83989271e..a1b075a14 100644
--- a/src/char/inter.c
+++ b/src/char/inter.c
@@ -935,7 +935,7 @@ int mapif_disconnectplayer(int fd, int account_id, int char_id, int reason)
int check_ttl_wisdata_sub(DBKey key, DBData *data, va_list ap)
{
unsigned long tick;
- struct WisData *wd = db_data2ptr(data);
+ struct WisData *wd = DB->data2ptr(data);
tick = va_arg(ap, unsigned long);
if (DIFF_TICK(tick, wd->tick) > WISDATA_TTL && wis_delnum < WISDELLIST_MAX)
diff --git a/src/common/HPM.c b/src/common/HPM.c
index af06811a5..28ea8f413 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -264,6 +264,8 @@ void hplugins_share_defaults(void) {
HPM->share(&SERVER_TYPE,"SERVER_TYPE");
HPM->share((void*)get_svn_revision,"get_svn_revision");
HPM->share((void*)get_git_hash,"get_git_hash");
+ HPM->share(DB, "DB");
+ HPM->share(malloclib, "malloclib");
/* socket */
HPM->share(RFIFOSKIP,"RFIFOSKIP");
HPM->share(WFIFOSET,"WFIFOSET");
@@ -284,7 +286,7 @@ void hplugins_share_defaults(void) {
HPM->share(add_timer_interval,"add_timer_interval");
HPM->share(add_timer_func_list,"add_timer_func_list");
HPM->share(delete_timer,"delete_timer");
- HPM->share(get_uptime,"get_uptime");
+ HPM->share(get_uptime,"get_uptime");
}
CPCMD(plugins) {
if( HPM->plugin_count == 0 ) {
diff --git a/src/common/HPMi.h b/src/common/HPMi.h
index a58eeed38..3cdb804e0 100644
--- a/src/common/HPMi.h
+++ b/src/common/HPMi.h
@@ -57,14 +57,14 @@ enum hp_event_types {
};
/* Hercules Plugin Mananger Include Interface */
-struct HPMi_interface {
+HPExport struct HPMi_interface {
void (*event[HPET_MAX]) (void);
bool (*addCommand) (char *name, bool (*func)(const int fd, struct map_session_data* sd, const char* command, const char* message,struct AtCommandInfo *info));
bool (*addScript) (char *name, char *args, bool (*func)(struct script_state *st));
void (*addCPCommand) (char *name, CParseFunc func);
} HPMi_s;
#ifndef _HPM_H_
- struct HPMi_interface *HPMi;
+ HPExport struct HPMi_interface *HPMi;
#endif
#endif /* _HPMi_H_ */
diff --git a/src/common/console.c b/src/common/console.c
index 248dd7b45..ba93b8e09 100644
--- a/src/common/console.c
+++ b/src/common/console.c
@@ -98,7 +98,7 @@ CPCMD(help) {
}
/* [Ind/Hercules] */
CPCMD(malloc_usage) {
- unsigned int val = (unsigned int)malloc_usage();
+ unsigned int val = (unsigned int)malloclib->usage();
ShowInfo("malloc_usage: %.2f MB\n",(double)(val)/1024);
}
#define CP_DEF_C(x) { #x , NULL , NULL, NULL }
diff --git a/src/common/core.c b/src/common/core.c
index 984815bc2..0959e6fc9 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -284,9 +284,11 @@ void core_defaults(void) {
#endif
console_defaults();
strlib_defaults();
+ malloc_defaults();
#ifndef MINICORE
sql_defaults();
timer_defaults();
+ db_defaults();
#endif
}
/*======================================
@@ -305,7 +307,7 @@ int main (int argc, char **argv) {
}
core_defaults();
- malloc_init();// needed for Show* in display_title() [FlavioJS]
+ malloclib->init();// needed for Show* in display_title() [FlavioJS]
console->display_title();
@@ -320,7 +322,7 @@ int main (int argc, char **argv) {
Sql_Init();
rathread_init();
mempool_init();
- db_init();
+ DB->init();
signals_init();
#ifdef _WIN32
@@ -354,12 +356,12 @@ int main (int argc, char **argv) {
#endif
timer_final();
socket_final();
- db_final();
+ DB->final();
mempool_final();
rathread_final();
#endif
- malloc_final();
+ malloclib->final();
return 0;
}
diff --git a/src/common/db.c b/src/common/db.c
index f2e69abbb..561371787 100644
--- a/src/common/db.c
+++ b/src/common/db.c
@@ -510,7 +510,7 @@ static void db_rebalance_erase(DBNode node, DBNode *root)
// put the right of 'node' in 'y'
y->right = node->right;
node->right->parent = y;
- // 'y' is a direct child of 'node'
+ // 'y' is a direct child of 'node'
} else {
x_parent = y;
}
@@ -2349,7 +2349,7 @@ DBHasher db_default_hash(DBType type)
DBReleaser db_default_release(DBType type, DBOptions options)
{
DB_COUNTSTAT(db_default_release);
- options = db_fix_options(type, options);
+ 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))
return &db_release_both; // Release both key and data
@@ -2416,7 +2416,7 @@ DBMap* db_alloc(const char *file, const char *func, int line, DBType type, DBOpt
#endif /* DB_ENABLE_STATS */
db = ers_alloc(db_alloc_ers, struct DBMap_impl);
- options = db_fix_options(type, options);
+ options = DB->fix_options(type, options);
/* Interface of the database */
db->vtable.iterator = db_obj_iterator;
db->vtable.exists = db_obj_exists;
@@ -2447,9 +2447,9 @@ DBMap* db_alloc(const char *file, const char *func, int line, DBType type, DBOpt
/* Other */
snprintf(ers_name, 50, "db_alloc:nodes:%s:%s:%d",func,file,line);
db->nodes = ers_new(sizeof(struct dbn),ers_name,ERS_OPT_WAIT|ERS_OPT_FREE_NAME);
- db->cmp = db_default_cmp(type);
- db->hash = db_default_hash(type);
- db->release = db_default_release(type, options);
+ db->cmp = DB->default_cmp(type);
+ db->hash = DB->default_hash(type);
+ db->release = DB->default_release(type, options);
for (i = 0; i < HASH_SIZE; i++)
db->ht[i] = NULL;
db->cache = NULL;
@@ -2829,3 +2829,23 @@ void linkdb_final( struct linkdb_node** head )
}
*head = NULL;
}
+void db_defaults(void) {
+ DB = &DB_s;
+ DB->alloc = db_alloc;
+ DB->custom_release = db_custom_release;
+ DB->data2i = db_data2i;
+ DB->data2ptr = db_data2ptr;
+ DB->data2ui = db_data2ui;
+ DB->default_cmp = db_default_cmp;
+ DB->default_hash = db_default_hash;
+ DB->default_release = db_default_release;
+ DB->final = db_final;
+ DB->fix_options = db_fix_options;
+ DB->i2data = db_i2data;
+ DB->i2key = db_i2key;
+ DB->init = db_init;
+ DB->ptr2data = db_ptr2data;
+ DB->str2key = db_str2key;
+ DB->ui2data = db_ui2data;
+ DB->ui2key = db_ui2key;
+}
diff --git a/src/common/db.h b/src/common/db.h
index 45babed78..5a555b2fa 100644
--- a/src/common/db.h
+++ b/src/common/db.h
@@ -599,73 +599,73 @@ struct DBMap {
// For easy access to the common functions.
#define db_exists(db,k) ( (db)->exists((db),(k)) )
-#define idb_exists(db,k) ( (db)->exists((db),db_i2key(k)) )
-#define uidb_exists(db,k) ( (db)->exists((db),db_ui2key(k)) )
-#define strdb_exists(db,k) ( (db)->exists((db),db_str2key(k)) )
+#define idb_exists(db,k) ( (db)->exists((db),DB->i2key(k)) )
+#define uidb_exists(db,k) ( (db)->exists((db),DB->ui2key(k)) )
+#define strdb_exists(db,k) ( (db)->exists((db),DB->str2key(k)) )
// Get pointer-type data from DBMaps of various key types
-#define db_get(db,k) ( db_data2ptr((db)->get((db),(k))) )
-#define idb_get(db,k) ( db_data2ptr((db)->get((db),db_i2key(k))) )
-#define uidb_get(db,k) ( db_data2ptr((db)->get((db),db_ui2key(k))) )
-#define strdb_get(db,k) ( db_data2ptr((db)->get((db),db_str2key(k))) )
+#define db_get(db,k) ( DB->data2ptr((db)->get((db),(k))) )
+#define idb_get(db,k) ( DB->data2ptr((db)->get((db),DB->i2key(k))) )
+#define uidb_get(db,k) ( DB->data2ptr((db)->get((db),DB->ui2key(k))) )
+#define strdb_get(db,k) ( DB->data2ptr((db)->get((db),DB->str2key(k))) )
// Get int-type data from DBMaps of various key types
-#define db_iget(db,k) ( db_data2i((db)->get((db),(k))) )
-#define idb_iget(db,k) ( db_data2i((db)->get((db),db_i2key(k))) )
-#define uidb_iget(db,k) ( db_data2i((db)->get((db),db_ui2key(k))) )
-#define strdb_iget(db,k) ( db_data2i((db)->get((db),db_str2key(k))) )
+#define db_iget(db,k) ( DB->data2i((db)->get((db),(k))) )
+#define idb_iget(db,k) ( DB->data2i((db)->get((db),DB->i2key(k))) )
+#define uidb_iget(db,k) ( DB->data2i((db)->get((db),DB->ui2key(k))) )
+#define strdb_iget(db,k) ( DB->data2i((db)->get((db),DB->str2key(k))) )
// Get uint-type data from DBMaps of various key types
-#define db_uiget(db,k) ( db_data2ui((db)->get((db),(k))) )
-#define idb_uiget(db,k) ( db_data2ui((db)->get((db),db_i2key(k))) )
-#define uidb_uiget(db,k) ( db_data2ui((db)->get((db),db_ui2key(k))) )
-#define strdb_uiget(db,k) ( db_data2ui((db)->get((db),db_str2key(k))) )
+#define db_uiget(db,k) ( DB->data2ui((db)->get((db),(k))) )
+#define idb_uiget(db,k) ( DB->data2ui((db)->get((db),DB->i2key(k))) )
+#define uidb_uiget(db,k) ( DB->data2ui((db)->get((db),DB->ui2key(k))) )
+#define strdb_uiget(db,k) ( DB->data2ui((db)->get((db),DB->str2key(k))) )
// Put pointer-type data into DBMaps of various key types
-#define db_put(db,k,d) ( (db)->put((db),(k),db_ptr2data(d),NULL) )
-#define idb_put(db,k,d) ( (db)->put((db),db_i2key(k),db_ptr2data(d),NULL) )
-#define uidb_put(db,k,d) ( (db)->put((db),db_ui2key(k),db_ptr2data(d),NULL) )
-#define strdb_put(db,k,d) ( (db)->put((db),db_str2key(k),db_ptr2data(d),NULL) )
+#define db_put(db,k,d) ( (db)->put((db),(k),DB->ptr2data(d),NULL) )
+#define idb_put(db,k,d) ( (db)->put((db),DB->i2key(k),DB->ptr2data(d),NULL) )
+#define uidb_put(db,k,d) ( (db)->put((db),DB->ui2key(k),DB->ptr2data(d),NULL) )
+#define strdb_put(db,k,d) ( (db)->put((db),DB->str2key(k),DB->ptr2data(d),NULL) )
// Put int-type data into DBMaps of various key types
-#define db_iput(db,k,d) ( (db)->put((db),(k),db_i2data(d),NULL) )
-#define idb_iput(db,k,d) ( (db)->put((db),db_i2key(k),db_i2data(d),NULL) )
-#define uidb_iput(db,k,d) ( (db)->put((db),db_ui2key(k),db_i2data(d),NULL) )
-#define strdb_iput(db,k,d) ( (db)->put((db),db_str2key(k),db_i2data(d),NULL) )
+#define db_iput(db,k,d) ( (db)->put((db),(k),DB->i2data(d),NULL) )
+#define idb_iput(db,k,d) ( (db)->put((db),DB->i2key(k),DB->i2data(d),NULL) )
+#define uidb_iput(db,k,d) ( (db)->put((db),DB->ui2key(k),DB->i2data(d),NULL) )
+#define strdb_iput(db,k,d) ( (db)->put((db),DB->str2key(k),DB->i2data(d),NULL) )
// Put uint-type data into DBMaps of various key types
-#define db_uiput(db,k,d) ( (db)->put((db),(k),db_ui2data(d),NULL) )
-#define idb_uiput(db,k,d) ( (db)->put((db),db_i2key(k),db_ui2data(d),NULL) )
-#define uidb_uiput(db,k,d) ( (db)->put((db),db_ui2key(k),db_ui2data(d),NULL) )
-#define strdb_uiput(db,k,d) ( (db)->put((db),db_str2key(k),db_ui2data(d),NULL) )
+#define db_uiput(db,k,d) ( (db)->put((db),(k),DB->ui2data(d),NULL) )
+#define idb_uiput(db,k,d) ( (db)->put((db),DB->i2key(k),DB->ui2data(d),NULL) )
+#define uidb_uiput(db,k,d) ( (db)->put((db),DB->ui2key(k),DB->ui2data(d),NULL) )
+#define strdb_uiput(db,k,d) ( (db)->put((db),DB->str2key(k),DB->ui2data(d),NULL) )
// Remove entry from DBMaps of various key types
#define db_remove(db,k) ( (db)->remove((db),(k),NULL) )
-#define idb_remove(db,k) ( (db)->remove((db),db_i2key(k),NULL) )
-#define uidb_remove(db,k) ( (db)->remove((db),db_ui2key(k),NULL) )
-#define strdb_remove(db,k) ( (db)->remove((db),db_str2key(k),NULL) )
+#define idb_remove(db,k) ( (db)->remove((db),DB->i2key(k),NULL) )
+#define uidb_remove(db,k) ( (db)->remove((db),DB->ui2key(k),NULL) )
+#define strdb_remove(db,k) ( (db)->remove((db),DB->str2key(k),NULL) )
//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_data2ptr((db)->ensure((db),(k),(f))) )
-#define idb_ensure(db,k,f) ( db_data2ptr((db)->ensure((db),db_i2key(k),(f))) )
-#define uidb_ensure(db,k,f) ( db_data2ptr((db)->ensure((db),db_ui2key(k),(f))) )
-#define strdb_ensure(db,k,f) ( db_data2ptr((db)->ensure((db),db_str2key(k),(f))) )
+#define db_ensure(db,k,f) ( DB->data2ptr((db)->ensure((db),(k),(f))) )
+#define idb_ensure(db,k,f) ( DB->data2ptr((db)->ensure((db),DB->i2key(k),(f))) )
+#define uidb_ensure(db,k,f) ( DB->data2ptr((db)->ensure((db),DB->ui2key(k),(f))) )
+#define strdb_ensure(db,k,f) ( DB->data2ptr((db)->ensure((db),DB->str2key(k),(f))) )
// Database creation and destruction macros
-#define idb_alloc(opt) db_alloc(__FILE__,__func__,__LINE__,DB_INT,(opt),sizeof(int))
-#define uidb_alloc(opt) db_alloc(__FILE__,__func__,__LINE__,DB_UINT,(opt),sizeof(unsigned int))
-#define strdb_alloc(opt,maxlen) db_alloc(__FILE__,__func__,__LINE__,DB_STRING,(opt),(maxlen))
-#define stridb_alloc(opt,maxlen) db_alloc(__FILE__,__func__,__LINE__,DB_ISTRING,(opt),(maxlen))
+#define idb_alloc(opt) DB->alloc(__FILE__,__func__,__LINE__,DB_INT,(opt),sizeof(int))
+#define uidb_alloc(opt) DB->alloc(__FILE__,__func__,__LINE__,DB_UINT,(opt),sizeof(unsigned int))
+#define strdb_alloc(opt,maxlen) DB->alloc(__FILE__,__func__,__LINE__,DB_STRING,(opt),(maxlen))
+#define stridb_alloc(opt,maxlen) DB->alloc(__FILE__,__func__,__LINE__,DB_ISTRING,(opt),(maxlen))
#define db_destroy(db) ( (db)->destroy((db),NULL) )
// Other macros
#define db_clear(db) ( (db)->clear(db,NULL) )
#define db_size(db) ( (db)->size(db) )
#define db_iterator(db) ( (db)->iterator(db) )
-#define dbi_first(dbi) ( db_data2ptr((dbi)->first(dbi,NULL)) )
-#define dbi_last(dbi) ( db_data2ptr((dbi)->last(dbi,NULL)) )
-#define dbi_next(dbi) ( db_data2ptr((dbi)->next(dbi,NULL)) )
-#define dbi_prev(dbi) ( db_data2ptr((dbi)->prev(dbi,NULL)) )
+#define dbi_first(dbi) ( DB->data2ptr((dbi)->first(dbi,NULL)) )
+#define dbi_last(dbi) ( DB->data2ptr((dbi)->last(dbi,NULL)) )
+#define dbi_next(dbi) ( DB->data2ptr((dbi)->next(dbi,NULL)) )
+#define dbi_prev(dbi) ( DB->data2ptr((dbi)->prev(dbi,NULL)) )
#define dbi_remove(dbi) ( (dbi)->remove(dbi,NULL) )
#define dbi_exists(dbi) ( (dbi)->exists(dbi) )
#define dbi_destroy(dbi) ( (dbi)->destroy(dbi) )
@@ -692,6 +692,7 @@ struct DBMap {
* db_final - Finalizes the database system. *
\*****************************************************************************/
+struct db_interface {
/**
* Returns the fixed options according to the database type.
* Sets required options and unsets unsupported options.
@@ -704,7 +705,7 @@ struct DBMap {
* @see #DBOptions
* @see #db_default_release(DBType,DBOptions)
*/
-DBOptions db_fix_options(DBType type, DBOptions options);
+DBOptions (*fix_options) (DBType type, DBOptions options);
/**
* Returns the default comparator for the type of database.
@@ -714,7 +715,7 @@ DBOptions db_fix_options(DBType type, DBOptions options);
* @see #DBType
* @see #DBComparator
*/
-DBComparator db_default_cmp(DBType type);
+DBComparator (*default_cmp) (DBType type);
/**
* Returns the default hasher for the specified type of database.
@@ -724,7 +725,7 @@ DBComparator db_default_cmp(DBType type);
* @see #DBType
* @see #DBHasher
*/
-DBHasher db_default_hash(DBType type);
+DBHasher (*default_hash) (DBType type);
/**
* Returns the default releaser for the specified type of database with the
@@ -741,7 +742,7 @@ DBHasher db_default_hash(DBType type);
* @see #db_fix_options(DBType,DBOptions)
* @see #db_custom_release(DBRelease)
*/
-DBReleaser db_default_release(DBType type, DBOptions options);
+DBReleaser (*default_release) (DBType type, DBOptions options);
/**
* Returns the releaser that behaves as <code>which</code> specifies.
@@ -752,7 +753,7 @@ DBReleaser db_default_release(DBType type, DBOptions options);
* @see #DBReleaser
* @see #db_default_release(DBType,DBOptions)
*/
-DBReleaser db_custom_release(DBRelease which);
+DBReleaser (*custom_release) (DBRelease which);
/**
* Allocate a new database of the specified type.
@@ -775,7 +776,7 @@ DBReleaser db_custom_release(DBRelease which);
* @see #db_default_release(DBType,DBOptions)
* @see #db_fix_options(DBType,DBOptions)
*/
-DBMap* db_alloc(const char *file, const char *func, int line, DBType type, DBOptions options, unsigned short maxlen);
+DBMap* (*alloc) (const char *file, const char *func, int line, DBType type, DBOptions options, unsigned short maxlen);
/**
* Manual cast from 'int' to the union DBKey.
@@ -783,7 +784,7 @@ DBMap* db_alloc(const char *file, const char *func, int line, DBType type, DBOpt
* @return The key as a DBKey union
* @public
*/
-DBKey db_i2key(int key);
+DBKey (*i2key) (int key);
/**
* Manual cast from 'unsigned int' to the union DBKey.
@@ -791,7 +792,7 @@ DBKey db_i2key(int key);
* @return The key as a DBKey union
* @public
*/
-DBKey db_ui2key(unsigned int key);
+DBKey (*ui2key) (unsigned int key);
/**
* Manual cast from 'unsigned char *' to the union DBKey.
@@ -799,7 +800,7 @@ DBKey db_ui2key(unsigned int key);
* @return The key as a DBKey union
* @public
*/
-DBKey db_str2key(const char *key);
+DBKey (*str2key) (const char *key);
/**
* Manual cast from 'int' to the struct DBData.
@@ -807,7 +808,7 @@ DBKey db_str2key(const char *key);
* @return The data as a DBData struct
* @public
*/
-DBData db_i2data(int data);
+DBData (*i2data) (int data);
/**
* Manual cast from 'unsigned int' to the struct DBData.
@@ -815,7 +816,7 @@ DBData db_i2data(int data);
* @return The data as a DBData struct
* @public
*/
-DBData db_ui2data(unsigned int data);
+DBData (*ui2data) (unsigned int data);
/**
* Manual cast from 'void *' to the struct DBData.
@@ -823,7 +824,7 @@ DBData db_ui2data(unsigned int data);
* @return The data as a DBData struct
* @public
*/
-DBData db_ptr2data(void *data);
+DBData (*ptr2data) (void *data);
/**
* Gets int type data from struct DBData.
@@ -832,7 +833,7 @@ DBData db_ptr2data(void *data);
* @return Integer value of the data.
* @public
*/
-int db_data2i(DBData *data);
+int (*data2i) (DBData *data);
/**
* Gets unsigned int type data from struct DBData.
@@ -841,7 +842,7 @@ int db_data2i(DBData *data);
* @return Unsigned int value of the data.
* @public
*/
-unsigned int db_data2ui(DBData *data);
+unsigned int (*data2ui) (DBData *data);
/**
* Gets void* type data from struct DBData.
@@ -850,14 +851,14 @@ unsigned int db_data2ui(DBData *data);
* @return Void* value of the data.
* @public
*/
-void* db_data2ptr(DBData *data);
+void* (*data2ptr) (DBData *data);
/**
* Initialize the database system.
* @public
* @see #db_final(void)
*/
-void db_init(void);
+void (*init) (void);
/**
* Finalize the database system.
@@ -865,8 +866,12 @@ void db_init(void);
* @public
* @see #db_init(void)
*/
-void db_final(void);
+void (*final) (void);
+} DB_s;
+struct db_interface *DB;
+
+void db_defaults(void);
// Link DB System - From jAthena
struct linkdb_node {
struct linkdb_node *next;
diff --git a/src/common/malloc.c b/src/common/malloc.c
index d8799b2a1..4874aa0f4 100644
--- a/src/common/malloc.c
+++ b/src/common/malloc.c
@@ -130,21 +130,21 @@ void aFree_(void *p, const char *file, int line, const char *func)
/* USE_MEMMGR */
/*
- * Memory manager
- * able to handle malloc and free efficiently
- * Since the complex processing, I might be slightly heavier.
- *
- * (I'm sorry for the poor description ^ ^;) such as data structures
- * Divided into "blocks" of a plurality of memory, "unit" of a plurality of blocks further
- * I have to divide. Size of the unit, a plurality of distribution equal to the capacity of one block
- * That's what you have. For example, if one unit of 32KB, one block 1 Yu 32Byte
- * Knit, or are able to gather 1024, gathered 512 units 64Byte
- * I can be or have. (Excluding padding, the unit_head)
- *
- * Lead-linked list (block_prev, block_next) in each other is the same size block
- * Linked list (hash_prev, hash_nect) even among such one in the block with the figure
- * I like to have. Thus, reuse of memory no longer needed can be performed efficiently.
- */
+* Memory manager
+* able to handle malloc and free efficiently
+* Since the complex processing, I might be slightly heavier.
+*
+* (I'm sorry for the poor description ^ ^;) such as data structures
+* Divided into "blocks" of a plurality of memory, "unit" of a plurality of blocks further
+* I have to divide. Size of the unit, a plurality of distribution equal to the capacity of one block
+* That's what you have. For example, if one unit of 32KB, one block 1 Yu 32Byte
+* Knit, or are able to gather 1024, gathered 512 units 64Byte
+* I can be or have. (Excluding padding, the unit_head)
+*
+* Lead-linked list (block_prev, block_next) in each other is the same size block
+* Linked list (hash_prev, hash_nect) even among such one in the block with the figure
+* I like to have. Thus, reuse of memory no longer needed can be performed efficiently.
+*/
/* Alignment of the block */
#define BLOCK_ALIGNMENT1 16
@@ -210,7 +210,7 @@ static unsigned short size2hash( size_t size )
return (unsigned short)(size + BLOCK_ALIGNMENT1 - 1) / BLOCK_ALIGNMENT1;
} else if( size <= BLOCK_DATA_SIZE ){
return (unsigned short)(size - BLOCK_DATA_SIZE1 + BLOCK_ALIGNMENT2 - 1) / BLOCK_ALIGNMENT2
- + BLOCK_DATA_COUNT1;
+ + BLOCK_DATA_COUNT1;
} else {
return 0xffff; // If it exceeds the block length hash I do not
}
@@ -235,7 +235,7 @@ void* _mmalloc(size_t size, const char *file, int line, const char *func )
ShowError("_mmalloc: %d\n", size);
return NULL;
}
-
+
if(size == 0) {
return NULL;
}
@@ -332,7 +332,7 @@ void* _mmalloc(size_t size, const char *file, int line, const char *func )
void* _mcalloc(size_t num, size_t size, const char *file, int line, const char *func )
{
- void *p = _mmalloc(num * size,file,line,func);
+ void *p = malloclib->malloc(num * size,file,line,func);
memset(p,0,num * size);
return p;
}
@@ -341,7 +341,7 @@ void* _mrealloc(void *memblock, size_t size, const char *file, int line, const c
{
size_t old_size;
if(memblock == NULL) {
- return _mmalloc(size,file,line,func);
+ return malloclib->malloc(size,file,line,func);
}
old_size = ((struct unit_head *)((char *)memblock - sizeof(struct unit_head) + sizeof(long)))->size;
@@ -353,11 +353,11 @@ void* _mrealloc(void *memblock, size_t size, const char *file, int line, const c
return memblock;
} else {
// Size Large
- void *p = _mmalloc(size,file,line,func);
+ void *p = malloclib->malloc(size,file,line,func);
if(p != NULL) {
memcpy(p,memblock,old_size);
}
- _mfree(memblock,file,line,func);
+ malloclib->free(memblock,file,line,func);
return p;
}
}
@@ -368,7 +368,7 @@ char* _mstrdup(const char *p, const char *file, int line, const char *func )
return NULL;
} else {
size_t len = strlen(p);
- char *string = (char *)_mmalloc(len + 1,file,line,func);
+ char *string = (char *)malloclib->malloc(len + 1,file,line,func);
memcpy(string,p,len+1);
return string;
}
@@ -544,7 +544,7 @@ static void memmgr_log (char *buf)
t = localtime(&raw);
fprintf(log_fp, "\nMemory manager: Memory leaks found at %d/%02d/%02d %02dh%02dm%02ds (rev %s).\n",
(t->tm_year+1900), (t->tm_mon+1), t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec,
- git[0] != HERC_UNKNOWN_VER ? git : svn[0] != HERC_UNKNOWN_VER ? svn : "Unknown");
+ git[0] != HERC_UNKNOWN_VER ? git : svn[0] != HERC_UNKNOWN_VER ? svn : "Unknown");
}
fprintf(log_fp, "%s", buf);
return;
@@ -621,7 +621,7 @@ static void memmgr_final (void)
memmgr_log (buf);
#endif /* LOG_MEMMGR */
// get block pointer and free it [celest]
- _mfree(ptr, ALC_MARK);
+ malloclib->free(ptr, ALC_MARK);
}
}
}
@@ -663,9 +663,9 @@ static void memmgr_init (void)
/*======================================
- * Initialise
- *--------------------------------------
- */
+* Initialise
+*--------------------------------------
+*/
/// Tests the memory for errors and memory leaks.
@@ -719,3 +719,28 @@ void malloc_init (void)
memmgr_init ();
#endif
}
+
+void malloc_defaults()
+{
+ malloclib = &malloclib_s;
+ malloclib->init = malloc_init;
+ malloclib->final = malloc_final;
+ malloclib->memory_check = malloc_memory_check;
+ malloclib->usage = malloc_usage;
+ malloclib->verify_ptr = malloc_verify_ptr;
+
+// Athena's built-in Memory Manager
+#ifdef USE_MEMMGR
+ malloclib->malloc = _mmalloc;
+ malloclib->calloc = _mcalloc;
+ malloclib->realloc = _mrealloc;
+ malloclib->astrdup = _mstrdup;
+ malloclib->free = _mfree;
+#else
+ malloclib->malloc = aMalloc_;
+ malloclib->calloc = aCalloc_;
+ malloclib->realloc = aRealloc_;
+ malloclib->astrdup = aStrdup_;
+ malloclib->free = aFree_;
+#endif
+}
diff --git a/src/common/malloc.h b/src/common/malloc.h
index 6b4e8e5c4..34a26b56e 100644
--- a/src/common/malloc.h
+++ b/src/common/malloc.h
@@ -22,57 +22,32 @@
//////////////////////////////////////////////////////////////////////
-// Athena's built-in Memory Manager
-#ifdef USE_MEMMGR
-
// Enable memory manager logging by default
#define LOG_MEMMGR
// no logging for minicore
#if defined(MINICORE) && defined(LOG_MEMMGR)
-#undef LOG_MEMMGR
+ #undef LOG_MEMMGR
#endif
-# define aMalloc(n) _mmalloc(n,ALC_MARK)
-# define aCalloc(m,n) _mcalloc(m,n,ALC_MARK)
-# define aRealloc(p,n) _mrealloc(p,n,ALC_MARK)
-# define aStrdup(p) _mstrdup(p,ALC_MARK)
-# define aFree(p) _mfree(p,ALC_MARK)
-
- void* _mmalloc (size_t size, const char *file, int line, const char *func);
- void* _mcalloc (size_t num, size_t size, const char *file, int line, const char *func);
- void* _mrealloc (void *p, size_t size, const char *file, int line, const char *func);
- char* _mstrdup (const char *p, const char *file, int line, const char *func);
- void _mfree (void *p, const char *file, int line, const char *func);
-
-#else
-
-# define aMalloc(n) aMalloc_((n),ALC_MARK)
-# define aCalloc(m,n) aCalloc_((m),(n),ALC_MARK)
-# define aRealloc(p,n) aRealloc_(p,n,ALC_MARK)
-# define aStrdup(p) aStrdup_(p,ALC_MARK)
-# define aFree(p) aFree_(p,ALC_MARK)
-
- void* aMalloc_ (size_t size, const char *file, int line, const char *func);
- void* aCalloc_ (size_t num, size_t size, const char *file, int line, const char *func);
- void* aRealloc_ (void *p, size_t size, const char *file, int line, const char *func);
- char* aStrdup_ (const char *p, const char *file, int line, const char *func);
- void aFree_ (void *p, const char *file, int line, const char *func);
-
-#endif
+# define aMalloc(n) malloclib->malloc (n,ALC_MARK)
+# define aCalloc(m,n) malloclib->calloc (m,n,ALC_MARK)
+# define aRealloc(p,n) malloclib->realloc (p,n,ALC_MARK)
+# define aStrdup(p) malloclib->astrdup (p,ALC_MARK)
+# define aFree(p) malloclib->free (p,ALC_MARK)
/////////////// Buffer Creation /////////////////
// Full credit for this goes to Shinomori [Ajarn]
#ifdef __GNUC__ // GCC has variable length arrays
- #define CREATE_BUFFER(name, type, size) type name[size]
- #define DELETE_BUFFER(name)
+#define CREATE_BUFFER(name, type, size) type name[size]
+#define DELETE_BUFFER(name)
#else // others don't, so we emulate them
- #define CREATE_BUFFER(name, type, size) type *name = (type *) aCalloc (size, sizeof(type))
- #define DELETE_BUFFER(name) aFree(name)
+#define CREATE_BUFFER(name, type, size) type *name = (type *) aCalloc (size, sizeof(type))
+#define DELETE_BUFFER(name) aFree(name)
#endif
@@ -83,10 +58,27 @@
////////////////////////////////////////////////
-void malloc_memory_check(void);
-bool malloc_verify_ptr(void* ptr);
-size_t malloc_usage (void);
-void malloc_init (void);
-void malloc_final (void);
-
+//void malloc_memory_check(void);
+//bool malloc_verify_ptr(void* ptr);
+//size_t malloc_usage (void);
+//void malloc_init (void);
+//void malloc_final (void);
+
+void malloc_defaults(void);
+
+struct malloc_interface {
+ void* (*malloc )(size_t size, const char *file, int line, const char *func);
+ void* (*calloc )(size_t num, size_t size, const char *file, int line, const char *func);
+ void* (*realloc )(void *p, size_t size, const char *file, int line, const char *func);
+ char* (*astrdup )(const char *p, const char *file, int line, const char *func);
+ void (*free )(void *p, const char *file, int line, const char *func);
+
+ void (*memory_check)(void);
+ bool (*verify_ptr)(void* ptr);
+ size_t (*usage) (void);
+ void (*init) (void);
+ void (*final) (void);
+} malloclib_s;
+
+struct malloc_interface *malloclib;
#endif /* _MALLOC_H_ */
diff --git a/src/login/login.c b/src/login/login.c
index 09dd938db..8dd5ce20a 100644
--- a/src/login/login.c
+++ b/src/login/login.c
@@ -109,7 +109,7 @@ static DBData create_online_user(DBKey key, va_list args)
p->account_id = key.i;
p->char_server = -1;
p->waiting_disconnect = INVALID_TIMER;
- return db_ptr2data(p);
+ return DB->ptr2data(p);
}
struct online_login_data* add_online_user(int char_server, int account_id)
@@ -154,7 +154,7 @@ static int waiting_disconnect_timer(int tid, unsigned int tick, int id, intptr_t
*/
static int online_db_setoffline(DBKey key, DBData *data, va_list ap)
{
- struct online_login_data* p = db_data2ptr(data);
+ struct online_login_data* p = DB->data2ptr(data);
int server = va_arg(ap, int);
if( server == -1 )
{
@@ -175,7 +175,7 @@ static int online_db_setoffline(DBKey key, DBData *data, va_list ap)
*/
static int online_data_cleanup_sub(DBKey key, DBData *data, va_list ap)
{
- struct online_login_data *character= db_data2ptr(data);
+ struct online_login_data *character= DB->data2ptr(data);
if (character->char_server == -2) //Unknown server.. set them offline
remove_online_user(character->account_id);
return 0;
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index d831ca200..65da7aa24 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -5340,12 +5340,12 @@ ACMD(skillid) {
iter = db_iterator(skilldb_name2id);
for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) ) {
- idx = skill->get_index(db_data2i(data));
+ idx = skill->get_index(DB->data2i(data));
if (strnicmp(key.str, message, skillen) == 0 || strnicmp(skill_db[idx].desc, message, skillen) == 0) {
- sprintf(atcmd_output, msg_txt(1164), db_data2i(data), skill_db[idx].desc, key.str); // skill %d: %s (%s)
+ sprintf(atcmd_output, msg_txt(1164), DB->data2i(data), skill_db[idx].desc, key.str); // skill %d: %s (%s)
clif->message(fd, atcmd_output);
} else if ( found < MAX_SKILLID_PARTIAL_RESULTS && ( stristr(key.str,message) || stristr(skill_db[idx].desc,message) ) ) {
- snprintf(partials[found++], MAX_SKILLID_PARTIAL_RESULTS_LEN, msg_txt(1164), db_data2i(data), skill_db[idx].desc, key.str);
+ snprintf(partials[found++], MAX_SKILLID_PARTIAL_RESULTS_LEN, msg_txt(1164), DB->data2i(data), skill_db[idx].desc, key.str);
}
}
@@ -9156,7 +9156,7 @@ ACMD(channel) {
iter = db_iterator(channel->banned);
for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) ) {
- struct hChSysBanEntry * entry = db_data2ptr(data);
+ struct hChSysBanEntry * entry = DB->data2ptr(data);
if( !isA )
sprintf(atcmd_output, msg_txt(1444), entry->name);// - %s %s
diff --git a/src/map/battleground.c b/src/map/battleground.c
index fa4db436a..618679406 100644
--- a/src/map/battleground.c
+++ b/src/map/battleground.c
@@ -222,7 +222,7 @@ int bg_send_message(struct map_session_data *sd, const char *mes, int len)
*/
int bg_send_xy_timer_sub(DBKey key, DBData *data, va_list ap)
{
- struct battleground_data *bg = db_data2ptr(data);
+ struct battleground_data *bg = DB->data2ptr(data);
struct map_session_data *sd;
int i;
nullpo_ret(bg);
diff --git a/src/map/chrif.c b/src/map/chrif.c
index 3ba5a20f6..06956e731 100644
--- a/src/map/chrif.c
+++ b/src/map/chrif.c
@@ -479,7 +479,7 @@ int chrif_connectack(int fd) {
* @see DBApply
*/
static int chrif_reconnect(DBKey key, DBData *data, va_list ap) {
- struct auth_node *node = db_data2ptr(data);
+ struct auth_node *node = DB->data2ptr(data);
switch (node->state) {
case ST_LOGIN:
@@ -687,7 +687,7 @@ void chrif_authfail(int fd) {/* HELLO WORLD. ip in RFIFOL 15 is not being used (
* @see DBApply
*/
int auth_db_cleanup_sub(DBKey key, DBData *data, va_list ap) {
- struct auth_node *node = db_data2ptr(data);
+ struct auth_node *node = DB->data2ptr(data);
const char* states[] = { "Login", "Logout", "Map change" };
if(DIFF_TICK(gettick(),node->node_created)>60000) {
@@ -1596,7 +1596,7 @@ void chrif_send_report(char* buf, int len) {
* @see DBApply
*/
int auth_db_final(DBKey key, DBData *data, va_list ap) {
- struct auth_node *node = db_data2ptr(data);
+ struct auth_node *node = DB->data2ptr(data);
if (node->char_dat)
aFree(node->char_dat);
diff --git a/src/map/guild.c b/src/map/guild.c
index 9e7dc9b0f..b83f05f00 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -296,7 +296,7 @@ int guild_payexp_timer_sub(DBKey key, DBData *data, va_list ap) {
struct guild_expcache *c;
struct guild *g;
- c = db_data2ptr(data);
+ c = DB->data2ptr(data);
if (
(g = guild->search(c->guild_id)) == NULL ||
@@ -331,7 +331,7 @@ int guild_payexp_timer(int tid, unsigned int tick, int id, intptr_t data)
*/
int guild_send_xy_timer_sub(DBKey key, DBData *data, va_list ap)
{
- struct guild *g = db_data2ptr(data);
+ struct guild *g = DB->data2ptr(data);
int i;
nullpo_ret(g);
@@ -439,8 +439,8 @@ int guild_npc_request_info(int guild_id,const char *event)
ev=(struct eventlist *)aCalloc(sizeof(struct eventlist),1);
memcpy(ev->name,event,strlen(event));
//The one in the db (if present) becomes the next event from this.
- if (guild_infoevent_db->put(guild_infoevent_db, db_i2key(guild_id), db_ptr2data(ev), &prev))
- ev->next = db_data2ptr(&prev);
+ if (guild_infoevent_db->put(guild_infoevent_db, DB->i2key(guild_id), DB->ptr2data(ev), &prev))
+ ev->next = DB->data2ptr(&prev);
}
return guild->request_info(guild_id);
@@ -615,8 +615,8 @@ int guild_recv_info(struct guild *sg) {
}
//Occurrence of an event
- if (guild_infoevent_db->remove(guild_infoevent_db, db_i2key(sg->guild_id), &data)) {
- struct eventlist *ev = db_data2ptr(&data), *ev2;
+ if (guild_infoevent_db->remove(guild_infoevent_db, DB->i2key(sg->guild_id), &data)) {
+ struct eventlist *ev = DB->data2ptr(&data), *ev2;
while(ev) {
npc_event_do(ev->name);
ev2=ev->next;
@@ -1243,7 +1243,7 @@ static DBData create_expcache(DBKey key, va_list args)
c->account_id = sd->status.account_id;
c->char_id = sd->status.char_id;
c->exp = 0;
- return db_ptr2data(c);
+ return DB->ptr2data(c);
}
/*====================================================
@@ -1269,7 +1269,7 @@ unsigned int guild_payexp(struct map_session_data *sd,unsigned int exp) {
exp = exp * per / 100;
//Otherwise tax everything.
- c = db_data2ptr(guild_expcache_db->ensure(guild_expcache_db, db_i2key(sd->status.char_id), create_expcache, sd));
+ c = DB->data2ptr(guild_expcache_db->ensure(guild_expcache_db, DB->i2key(sd->status.char_id), create_expcache, sd));
if (c->exp > UINT64_MAX - exp)
c->exp = UINT64_MAX;
@@ -1292,7 +1292,7 @@ int guild_getexp(struct map_session_data *sd,int exp)
if (sd->status.guild_id == 0 || sd->guild == NULL)
return 0;
- c = db_data2ptr(guild_expcache_db->ensure(guild_expcache_db, db_i2key(sd->status.char_id), create_expcache, sd));
+ c = DB->data2ptr(guild_expcache_db->ensure(guild_expcache_db, DB->i2key(sd->status.char_id), create_expcache, sd));
if (c->exp > UINT64_MAX - exp)
c->exp = UINT64_MAX;
else
@@ -1692,7 +1692,7 @@ int guild_allianceack(int guild_id1,int guild_id2,int account_id1,int account_id
*/
int guild_broken_sub(DBKey key, DBData *data, va_list ap)
{
- struct guild *g = db_data2ptr(data);
+ struct guild *g = DB->data2ptr(data);
int guild_id=va_arg(ap,int);
int i,j;
struct map_session_data *sd=NULL;
@@ -1717,7 +1717,7 @@ int guild_broken_sub(DBKey key, DBData *data, va_list ap)
*/
int castle_guild_broken_sub(DBKey key, DBData *data, va_list ap)
{
- struct guild_castle *gc = db_data2ptr(data);
+ struct guild_castle *gc = DB->data2ptr(data);
int guild_id = va_arg(ap, int);
nullpo_ret(gc);
@@ -2145,7 +2145,7 @@ void guild_flag_remove(struct npc_data *nd) {
*/
static int eventlist_db_final(DBKey key, DBData *data, va_list ap) {
struct eventlist *next = NULL;
- struct eventlist *current = db_data2ptr(data);
+ struct eventlist *current = DB->data2ptr(data);
while (current != NULL) {
next = current->next;
aFree(current);
@@ -2158,7 +2158,7 @@ static int eventlist_db_final(DBKey key, DBData *data, va_list ap) {
* @see DBApply
*/
static int guild_expcache_db_final(DBKey key, DBData *data, va_list ap) {
- ers_free(expcache_ers, db_data2ptr(data));
+ ers_free(expcache_ers, DB->data2ptr(data));
return 0;
}
@@ -2166,7 +2166,7 @@ static int guild_expcache_db_final(DBKey key, DBData *data, va_list ap) {
* @see DBApply
*/
static int guild_castle_db_final(DBKey key, DBData *data, va_list ap) {
- struct guild_castle* gc = db_data2ptr(data);
+ struct guild_castle* gc = DB->data2ptr(data);
if( gc->temp_guardians )
aFree(gc->temp_guardians);
aFree(gc);
diff --git a/src/map/itemdb.c b/src/map/itemdb.c
index 590a0cf57..2a5fa48de 100644
--- a/src/map/itemdb.c
+++ b/src/map/itemdb.c
@@ -30,7 +30,7 @@ struct item_data dummy_item; //This is the default dummy item used for non-exist
*/
static int itemdb_searchname_sub(DBKey key, DBData *data, va_list ap)
{
- struct item_data *item = db_data2ptr(data), **dst, **dst2;
+ struct item_data *item = DB->data2ptr(data), **dst, **dst2;
char *str;
str=va_arg(ap,char *);
dst=va_arg(ap,struct item_data **);
@@ -83,7 +83,7 @@ struct item_data* itemdb_searchname(const char *str)
*/
static int itemdb_searchname_array_sub(DBKey key, DBData data, va_list ap)
{
- struct item_data *item = db_data2ptr(&data);
+ struct item_data *item = DB->data2ptr(&data);
char *str;
str=va_arg(ap,char *);
if (item == &dummy_item)
@@ -127,7 +127,7 @@ int itemdb_searchname_array(struct item_data** data, int size, const char *str)
size -= count;
db_count = itemdb_other->getall(itemdb_other, (DBData**)&db_data, size, itemdb_searchname_array_sub, str);
for (i = 0; i < db_count; i++)
- data[count++] = db_data2ptr(db_data[i]);
+ data[count++] = DB->data2ptr(db_data[i]);
count += db_count;
}
return count;
@@ -1376,7 +1376,7 @@ static void destroy_item_data(struct item_data* self, int free_self)
*/
static int itemdb_final_sub(DBKey key, DBData *data, va_list ap)
{
- struct item_data *id = db_data2ptr(data);
+ struct item_data *id = DB->data2ptr(data);
if( id != &dummy_item )
destroy_item_data(id, 1);
diff --git a/src/map/map.c b/src/map/map.c
index ddd2a9c82..d4c15cd6e 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -1478,7 +1478,7 @@ static DBData create_charid2nick(DBKey key, va_list args)
{
struct charid2nick *p;
CREATE(p, struct charid2nick, 1);
- return db_ptr2data(p);
+ return DB->ptr2data(p);
}
/// Adds(or replaces) the nick of charid to nick_db and fullfils pending requests.
@@ -1514,7 +1514,7 @@ void map_delnickdb(int charid, const char* name)
struct map_session_data* sd;
DBData data;
- if (!nick_db->remove(nick_db, db_i2key(charid), &data) || (p = db_data2ptr(&data)) == NULL)
+ if (!nick_db->remove(nick_db, DB->i2key(charid), &data) || (p = DB->data2ptr(&data)) == NULL)
return;
while( p->requests ) {
@@ -2702,7 +2702,7 @@ static DBData create_map_data_other_server(DBKey key, va_list args)
mdos=(struct map_data_other_server *)aCalloc(1,sizeof(struct map_data_other_server));
mdos->index = mapindex;
memcpy(mdos->name, mapindex_id2name(mapindex), MAP_NAME_LENGTH);
- return db_ptr2data(mdos);
+ return DB->ptr2data(mdos);
}
/*==========================================
@@ -2732,7 +2732,7 @@ int map_setipport(unsigned short mapindex, uint32 ip, uint16 port)
*/
int map_eraseallipport_sub(DBKey key, DBData *data, va_list va)
{
- struct map_data_other_server *mdos = db_data2ptr(data);
+ struct map_data_other_server *mdos = DB->data2ptr(data);
if(mdos->cell == NULL) {
db_remove(map_db,key);
aFree(mdos);
@@ -4851,7 +4851,7 @@ void read_map_zone_db(void) {
*/
int map_db_final(DBKey key, DBData *data, va_list ap)
{
- struct map_data_other_server *mdos = db_data2ptr(data);
+ struct map_data_other_server *mdos = DB->data2ptr(data);
if(mdos && mdos->cell == NULL)
aFree(mdos);
return 0;
@@ -4862,7 +4862,7 @@ int map_db_final(DBKey key, DBData *data, va_list ap)
*/
int nick_db_final(DBKey key, DBData *data, va_list args)
{
- struct charid2nick* p = db_data2ptr(data);
+ struct charid2nick* p = DB->data2ptr(data);
struct charid_request* req;
if( p == NULL )
@@ -4910,7 +4910,7 @@ int cleanup_sub(struct block_list *bl, va_list ap)
*/
static int cleanup_db_sub(DBKey key, DBData *data, va_list va)
{
- return cleanup_sub(db_data2ptr(data), va);
+ return cleanup_sub(DB->data2ptr(data), va);
}
/*==========================================
diff --git a/src/map/npc.c b/src/map/npc.c
index 913c13e0b..7d0d5c6e1 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -353,7 +353,7 @@ int npc_event_doall_sub(DBKey key, DBData *data, va_list ap)
const char* name;
int rid;
- nullpo_ret(ev = db_data2ptr(data));
+ nullpo_ret(ev = DB->data2ptr(data));
nullpo_ret(c = va_arg(ap, int *));
nullpo_ret(name = va_arg(ap, const char *));
rid = va_arg(ap, int);
@@ -381,7 +381,7 @@ static int npc_event_do_sub(DBKey key, DBData *data, va_list ap)
int* c;
const char* name;
- nullpo_ret(ev = db_data2ptr(data));
+ nullpo_ret(ev = DB->data2ptr(data));
nullpo_ret(c = va_arg(ap, int *));
nullpo_ret(name = va_arg(ap, const char *));
@@ -1785,7 +1785,7 @@ int npc_remove_map(struct npc_data* nd)
*/
static int npc_unload_ev(DBKey key, DBData *data, va_list ap)
{
- struct event_data* ev = db_data2ptr(data);
+ struct event_data* ev = DB->data2ptr(data);
char* npcname = va_arg(ap, char *);
if(strcmp(ev->nd->exname,npcname)==0){
@@ -2302,7 +2302,7 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const
int npc_convertlabel_db(DBKey key, DBData *data, va_list ap)
{
const char* lname = (const char*)key.str;
- int lpos = db_data2i(data);
+ int lpos = DB->data2i(data);
struct npc_label_list** label_list;
int* label_list_num;
const char* filepath;
@@ -2972,9 +2972,9 @@ static const char* npc_parse_function(char* w1, char* w2, char* w3, char* w4, co
return end;
func_db = script_get_userfunc_db();
- if (func_db->put(func_db, db_str2key(w3), db_ptr2data(script), &old_data))
+ if (func_db->put(func_db, DB->str2key(w3), DB->ptr2data(script), &old_data))
{
- struct script_code *oldscript = (struct script_code*)db_data2ptr(&old_data);
+ struct script_code *oldscript = (struct script_code*)DB->data2ptr(&old_data);
ShowInfo("npc_parse_function: Overwriting user function [%s] (%s:%d)\n", w3, filepath, strline(buffer,start-buffer));
script_free_vars(oldscript->script_vars);
aFree(oldscript->script_buf);
@@ -3776,7 +3776,7 @@ void npc_read_event_script(void)
for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) )
{
const char* p = key.str;
- struct event_data* ed = db_data2ptr(data);
+ struct event_data* ed = DB->data2ptr(data);
unsigned char count = script_event[i].event_count;
if( count >= ARRAYLENGTH(script_event[i].event) )
diff --git a/src/map/script.c b/src/map/script.c
index 76092f4ce..41f8e7472 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -3658,7 +3658,7 @@ int script_config_read(char *cfgName)
*/
static int db_script_free_code_sub(DBKey key, DBData *data, va_list ap)
{
- struct script_code *code = db_data2ptr(data);
+ struct script_code *code = DB->data2ptr(data);
if (code)
script_free_code(code);
return 0;
diff --git a/src/map/skill.c b/src/map/skill.c
index bbc88d9d2..06bfca5f8 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -15363,7 +15363,7 @@ int skill_unit_timer_sub_onplace (struct block_list* bl, va_list ap) {
* @see DBApply
*/
int skill_unit_timer_sub(DBKey key, DBData *data, va_list ap) {
- struct skill_unit* unit = db_data2ptr(data);
+ struct skill_unit* unit = DB->data2ptr(data);
struct skill_unit_group* group = unit->group;
unsigned int tick = va_arg(ap,unsigned int);
bool dissonance;
diff --git a/src/map/storage.c b/src/map/storage.c
index fda80735a..01da53907 100644
--- a/src/map/storage.c
+++ b/src/map/storage.c
@@ -73,7 +73,7 @@ void do_final_storage(void) // by [MC Cameri]
*/
static int storage_reconnect_sub(DBKey key, DBData *data, va_list ap)
{
- struct guild_storage *stor = db_data2ptr(data);
+ struct guild_storage *stor = DB->data2ptr(data);
if (stor->dirty && stor->storage_status == 0) //Save closed storages.
storage_guild_storagesave(0, stor->guild_id,0);
@@ -352,7 +352,7 @@ static DBData create_guildstorage(DBKey key, va_list args)
struct guild_storage *gs = NULL;
gs = (struct guild_storage *) aCalloc(sizeof(struct guild_storage), 1);
gs->guild_id=key.i;
- return db_ptr2data(gs);
+ return DB->ptr2data(gs);
}
struct guild_storage *guild2storage(int guild_id)