summaryrefslogtreecommitdiff
path: root/src/common/db.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/db.c')
-rw-r--r--src/common/db.c86
1 files changed, 46 insertions, 40 deletions
diff --git a/src/common/db.c b/src/common/db.c
index bbcac4b33..bcd57875b 100644
--- a/src/common/db.c
+++ b/src/common/db.c
@@ -2,8 +2,8 @@
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
- * Copyright (C) 2012-2015 Hercules Dev Team
- * Copyright (C) Athena Dev Teams
+ * Copyright (C) 2012-2020 Hercules Dev Team
+ * Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -93,13 +93,14 @@
#include "common/ers.h"
#include "common/memmgr.h"
#include "common/mmo.h"
+#include "common/nullpo.h"
#include "common/showmsg.h"
#include "common/strlib.h"
#include <stdio.h>
#include <stdlib.h>
-struct db_interface DB_s;
+static struct db_interface DB_s;
struct db_interface *DB;
/*****************************************************************************
@@ -357,8 +358,8 @@ static struct db_stats {
#endif /* !defined(DB_ENABLE_STATS) */
/* [Ind/Hercules] */
-struct eri *db_iterator_ers;
-struct eri *db_alloc_ers;
+static struct eri *db_iterator_ers;
+static struct eri *db_alloc_ers;
/*****************************************************************************\
* (2) Section of private functions used by the database system. *
@@ -1249,7 +1250,7 @@ static void db_release_both(union DBKey key, struct DBData data, enum DBReleaseO
* @protected
* @see struct DBIterator#first()
*/
-struct DBData *dbit_obj_first(struct DBIterator *self, union DBKey *out_key)
+static struct DBData *dbit_obj_first(struct DBIterator *self, union DBKey *out_key)
{
struct DBIterator_impl *it = (struct DBIterator_impl *)self;
@@ -1271,7 +1272,7 @@ struct DBData *dbit_obj_first(struct DBIterator *self, union DBKey *out_key)
* @protected
* @see struct DBIterator#last()
*/
-struct DBData *dbit_obj_last(struct DBIterator *self, union DBKey *out_key)
+static struct DBData *dbit_obj_last(struct DBIterator *self, union DBKey *out_key)
{
struct DBIterator_impl *it = (struct DBIterator_impl *)self;
@@ -1293,7 +1294,7 @@ struct DBData *dbit_obj_last(struct DBIterator *self, union DBKey *out_key)
* @protected
* @see struct DBIterator#next()
*/
-struct DBData *dbit_obj_next(struct DBIterator *self, union DBKey *out_key)
+static struct DBData *dbit_obj_next(struct DBIterator *self, union DBKey *out_key)
{
struct DBIterator_impl *it = (struct DBIterator_impl *)self;
struct DBNode *node;
@@ -1369,7 +1370,7 @@ struct DBData *dbit_obj_next(struct DBIterator *self, union DBKey *out_key)
* @protected
* @see struct DBIterator#prev()
*/
-struct DBData *dbit_obj_prev(struct DBIterator *self, union DBKey *out_key)
+static struct DBData *dbit_obj_prev(struct DBIterator *self, union DBKey *out_key)
{
struct DBIterator_impl *it = (struct DBIterator_impl *)self;
struct DBNode *node;
@@ -1444,7 +1445,7 @@ struct DBData *dbit_obj_prev(struct DBIterator *self, union DBKey *out_key)
* @protected
* @see struct DBIterator#exists()
*/
-bool dbit_obj_exists(struct DBIterator *self)
+static bool dbit_obj_exists(struct DBIterator *self)
{
struct DBIterator_impl *it = (struct DBIterator_impl *)self;
@@ -1466,7 +1467,7 @@ bool dbit_obj_exists(struct DBIterator *self)
* @see struct DBMap#remove()
* @see struct DBIterator#remove()
*/
-int dbit_obj_remove(struct DBIterator *self, struct DBData *out_data)
+static int dbit_obj_remove(struct DBIterator *self, struct DBData *out_data)
{
struct DBIterator_impl *it = (struct DBIterator_impl *)self;
struct DBNode *node;
@@ -1493,7 +1494,7 @@ int dbit_obj_remove(struct DBIterator *self, struct DBData *out_data)
* @param self Iterator
* @protected
*/
-void dbit_obj_destroy(struct DBIterator *self)
+static void dbit_obj_destroy(struct DBIterator *self)
{
struct DBIterator_impl *it = (struct DBIterator_impl *)self;
@@ -2406,7 +2407,7 @@ static enum DBOptions db_obj_options(struct DBMap *self)
* @see #db_default_release()
* @see #db_alloc()
*/
-enum DBOptions db_fix_options(enum DBType type, enum DBOptions options)
+static enum DBOptions db_fix_options(enum DBType type, enum DBOptions options)
{
DB_COUNTSTAT(db_fix_options);
switch (type) {
@@ -2418,6 +2419,7 @@ enum DBOptions db_fix_options(enum DBType type, enum DBOptions options)
default:
ShowError("db_fix_options: Unknown database type %u with options %x\n", type, options);
+ FALLTHROUGH
case DB_STRING:
case DB_ISTRING: // String databases, no fix required
return options;
@@ -2436,7 +2438,7 @@ enum DBOptions db_fix_options(enum DBType type, enum DBOptions options)
* @see #db_int64_cmp()
* @see #db_uint64_cmp()
*/
-DBComparator db_default_cmp(enum DBType type)
+static DBComparator db_default_cmp(enum DBType type)
{
DB_COUNTSTAT(db_default_cmp);
switch (type) {
@@ -2464,7 +2466,7 @@ DBComparator db_default_cmp(enum DBType type)
* @see #db_int64_hash()
* @see #db_uint64_hash()
*/
-DBHasher db_default_hash(enum DBType type)
+static DBHasher db_default_hash(enum DBType type)
{
DB_COUNTSTAT(db_default_hash);
switch (type) {
@@ -2497,7 +2499,7 @@ DBHasher db_default_hash(enum DBType type)
* @see #db_release_both()
* @see #db_custom_release()
*/
-DBReleaser db_default_release(enum DBType type, enum DBOptions options)
+static DBReleaser db_default_release(enum DBType type, enum DBOptions options)
{
DB_COUNTSTAT(db_default_release);
options = DB->fix_options(type, options);
@@ -2522,7 +2524,7 @@ DBReleaser db_default_release(enum DBType type, enum DBOptions options)
* @see #db_release_both()
* @see #db_default_release()
*/
-DBReleaser db_custom_release(enum DBReleaseOption which)
+static DBReleaser db_custom_release(enum DBReleaseOption which)
{
DB_COUNTSTAT(db_custom_release);
switch (which) {
@@ -2553,7 +2555,7 @@ DBReleaser db_custom_release(enum DBReleaseOption which)
* @see struct DBMap_impl
* @see #db_fix_options()
*/
-struct DBMap *db_alloc(const char *file, const char *func, int line, enum DBType type, enum DBOptions options, unsigned short maxlen)
+static struct DBMap *db_alloc(const char *file, const char *func, int line, enum DBType type, enum DBOptions options, unsigned short maxlen)
{
struct DBMap_impl *db;
unsigned int i;
@@ -2627,7 +2629,7 @@ struct DBMap *db_alloc(const char *file, const char *func, int line, enum DBType
* @return The key as a DBKey union
* @public
*/
-union DBKey db_i2key(int key)
+static union DBKey db_i2key(int key)
{
union DBKey ret;
@@ -2642,7 +2644,7 @@ union DBKey db_i2key(int key)
* @return The key as a DBKey union
* @public
*/
-union DBKey db_ui2key(unsigned int key)
+static union DBKey db_ui2key(unsigned int key)
{
union DBKey ret;
@@ -2657,7 +2659,7 @@ union DBKey db_ui2key(unsigned int key)
* @return The key as a DBKey union
* @public
*/
-union DBKey db_str2key(const char *key)
+static union DBKey db_str2key(const char *key)
{
union DBKey ret;
@@ -2672,7 +2674,7 @@ union DBKey db_str2key(const char *key)
* @return The key as a DBKey union
* @public
*/
-union DBKey db_i642key(int64 key)
+static union DBKey db_i642key(int64 key)
{
union DBKey ret;
@@ -2687,7 +2689,7 @@ union DBKey db_i642key(int64 key)
* @return The key as a DBKey union
* @public
*/
-union DBKey db_ui642key(uint64 key)
+static union DBKey db_ui642key(uint64 key)
{
union DBKey ret;
@@ -2702,7 +2704,7 @@ union DBKey db_ui642key(uint64 key)
* @return The data as a DBData struct
* @public
*/
-struct DBData db_i2data(int data)
+static struct DBData db_i2data(int data)
{
struct DBData ret;
@@ -2718,7 +2720,7 @@ struct DBData db_i2data(int data)
* @return The data as a DBData struct
* @public
*/
-struct DBData db_ui2data(unsigned int data)
+static struct DBData db_ui2data(unsigned int data)
{
struct DBData ret;
@@ -2734,7 +2736,7 @@ struct DBData db_ui2data(unsigned int data)
* @return The data as a DBData struct
* @public
*/
-struct DBData db_ptr2data(void *data)
+static struct DBData db_ptr2data(void *data)
{
struct DBData ret;
@@ -2751,7 +2753,7 @@ struct DBData db_ptr2data(void *data)
* @return Integer value of the data.
* @public
*/
-int db_data2i(struct DBData *data)
+static int db_data2i(struct DBData *data)
{
DB_COUNTSTAT(db_data2i);
if (data && DB_DATA_INT == data->type)
@@ -2766,7 +2768,7 @@ int db_data2i(struct DBData *data)
* @return Unsigned int value of the data.
* @public
*/
-unsigned int db_data2ui(struct DBData *data)
+static unsigned int db_data2ui(struct DBData *data)
{
DB_COUNTSTAT(db_data2ui);
if (data && DB_DATA_UINT == data->type)
@@ -2781,7 +2783,7 @@ unsigned int db_data2ui(struct DBData *data)
* @return Void* value of the data.
* @public
*/
-void *db_data2ptr(struct DBData *data)
+static void *db_data2ptr(struct DBData *data)
{
DB_COUNTSTAT(db_data2ptr);
if (data && DB_DATA_PTR == data->type)
@@ -2794,7 +2796,8 @@ void *db_data2ptr(struct DBData *data)
* @public
* @see #db_final(void)
*/
-void db_init(void) {
+static void db_init(void)
+{
db_iterator_ers = ers_new(sizeof(struct DBIterator_impl),"db.c::db_iterator_ers",ERS_OPT_CLEAN|ERS_OPT_FLEX_CHUNK);
db_alloc_ers = ers_new(sizeof(struct DBMap_impl),"db.c::db_alloc_ers",ERS_OPT_CLEAN|ERS_OPT_FLEX_CHUNK);
ers_chunk_size(db_alloc_ers, 50);
@@ -2807,7 +2810,7 @@ void db_init(void) {
* @public
* @see #db_init(void)
*/
-void db_final(void)
+static void db_final(void)
{
#ifdef DB_ENABLE_STATS
DB_COUNTSTAT(db_final);
@@ -2906,7 +2909,7 @@ void db_final(void)
}
// Link DB System - jAthena
-void linkdb_insert( struct linkdb_node** head, void *key, void* data)
+void linkdb_insert(struct linkdb_node **head, void *key, void *data)
{
struct linkdb_node *node;
if( head == NULL ) return ;
@@ -2927,7 +2930,8 @@ void linkdb_insert( struct linkdb_node** head, void *key, void* data)
node->data = data;
}
-void linkdb_vforeach( struct linkdb_node** head, LinkDBFunc func, va_list ap) {
+void linkdb_vforeach(struct linkdb_node **head, LinkDBFunc func, va_list ap)
+{
struct linkdb_node *node;
if( head == NULL ) return;
node = *head;
@@ -2940,14 +2944,15 @@ void linkdb_vforeach( struct linkdb_node** head, LinkDBFunc func, va_list ap) {
}
}
-void linkdb_foreach( struct linkdb_node** head, LinkDBFunc func, ...) {
+void linkdb_foreach(struct linkdb_node **head, LinkDBFunc func, ...)
+{
va_list ap;
va_start(ap, func);
linkdb_vforeach(head, func, ap);
va_end(ap);
}
-void* linkdb_search( struct linkdb_node** head, void *key)
+void* linkdb_search(struct linkdb_node **head, void *key)
{
int n = 0;
struct linkdb_node *node;
@@ -2972,7 +2977,7 @@ void* linkdb_search( struct linkdb_node** head, void *key)
return NULL;
}
-void* linkdb_erase( struct linkdb_node** head, void *key)
+void* linkdb_erase(struct linkdb_node **head, void *key)
{
struct linkdb_node *node;
if( head == NULL ) return NULL;
@@ -2994,7 +2999,7 @@ void* linkdb_erase( struct linkdb_node** head, void *key)
return NULL;
}
-void linkdb_replace( struct linkdb_node** head, void *key, void *data )
+void linkdb_replace(struct linkdb_node **head, void *key, void *data)
{
int n = 0;
struct linkdb_node *node;
@@ -3021,7 +3026,7 @@ void linkdb_replace( struct linkdb_node** head, void *key, void *data )
linkdb_insert( head, key, data );
}
-void linkdb_final( struct linkdb_node** head )
+void linkdb_final(struct linkdb_node **head)
{
struct linkdb_node *node, *node2;
if( head == NULL ) return ;
@@ -3033,7 +3038,9 @@ void linkdb_final( struct linkdb_node** head )
}
*head = NULL;
}
-void db_defaults(void) {
+
+void db_defaults(void)
+{
DB = &DB_s;
DB->alloc = db_alloc;
DB->custom_release = db_custom_release;
@@ -3054,5 +3061,4 @@ void db_defaults(void) {
DB->ui2key = db_ui2key;
DB->i642key = db_i642key;
DB->ui642key = db_ui642key;
-
}