Skip to content

Commit

Permalink
Merge pull request #803
Browse files Browse the repository at this point in the history
core: make "alist" and "dlist" type safe templates
  • Loading branch information
arogge committed May 27, 2021
2 parents e782ad2 + 4457ed6 commit 0a8f6a1
Show file tree
Hide file tree
Showing 135 changed files with 1,396 additions and 1,432 deletions.
1 change: 1 addition & 0 deletions .clang-format
Expand Up @@ -10,6 +10,7 @@ AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: true
AllowShortLambdasOnASingleLine: All
AlwaysBreakTemplateDeclarations: MultiLine
BinPackParameters: false
BraceWrapping:
AfterFunction: true
Expand Down
1 change: 1 addition & 0 deletions core/src/cats/bdb_mysql.h
Expand Up @@ -41,6 +41,7 @@ class JobControlRecord;

class BareosDbMysql : public BareosDbPrivateInterface {
private:
dlink<BareosDbMysql> link; /**< Queue control */
MYSQL* db_handle_;
MYSQL instance_;
MYSQL_RES* result_;
Expand Down
1 change: 1 addition & 0 deletions core/src/cats/bdb_postgresql.h
Expand Up @@ -34,6 +34,7 @@ class JobControlRecord;

class BareosDbPostgresql : public BareosDbPrivateInterface {
private:
dlink<BareosDbPostgresql> link; /**< Queue control */
PGconn* db_handle_;
PGresult* result_;
POOLMEM* buf_; /**< Buffer to manipulate queries */
Expand Down
1 change: 1 addition & 0 deletions core/src/cats/bdb_sqlite.h
Expand Up @@ -34,6 +34,7 @@ class JobControlRecord;

class BareosDbSqlite : public BareosDbPrivateInterface {
private:
dlink<BareosDbSqlite> link; /**< Queue control */
struct sqlite3* db_handle_;
char** result_; /**< sql_store_results() and SqlQueryWithoutHandler() */
char**
Expand Down
6 changes: 3 additions & 3 deletions core/src/cats/bvfs.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2009-2010 Free Software Foundation Europe e.V.
Copyright (C) 2016-2016 Planets Communications B.V.
Copyright (C) 2016-2020 Bareos GmbH & Co. KG
Copyright (C) 2016-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -43,7 +43,7 @@ class pathid_cache {
hlink* nodes;
int nb_node;
int max_node;
alist* table_node;
alist<hlink*>* table_node;
htable* cache_ppathid;

public:
Expand All @@ -55,7 +55,7 @@ class pathid_cache {
max_node = NITEMS;
nodes = (hlink*)malloc(max_node * sizeof(hlink));
nb_node = 0;
table_node = new alist(5, owned_by_alist);
table_node = new alist<hlink*>(5, owned_by_alist);
table_node->append(nodes);
}

Expand Down
9 changes: 3 additions & 6 deletions core/src/cats/cats.h
Expand Up @@ -42,8 +42,7 @@

#include <string>
#include <vector>

class dlist;
template <typename T> class dlist;

/* import automatically generated SQL_QUERY */
#include "bdb_query_enum_class.h"
Expand Down Expand Up @@ -492,7 +491,6 @@ typedef struct sql_field {
class BareosDb : public BareosDbQueryEnum {
protected:
brwlock_t lock_; /**< Transaction lock */
dlink link_; /**< Queue control */
SQL_INTERFACETYPE db_interface_type_
= SQL_INTERFACE_TYPE_UNKNOWN; /**< Type of backend used */
SQL_DBTYPE db_type_ = SQL_TYPE_UNKNOWN; /**< Database type */
Expand Down Expand Up @@ -1018,12 +1016,11 @@ struct SqlPoolEntry {
time_t last_update = 0; /**< When was this connection last updated either used
or put back on the pool */
BareosDb* db_handle = nullptr; /**< Connection handle to the database */
dlink link; /**< list management */
dlink<SqlPoolEntry> link; /**< list management */
};

// Pooled backend list descriptor (one defined per backend defined in config)
struct SqlPoolDescriptor {
dlist* pool_entries = nullptr; /**< Linked list of all pool entries */
bool active = false; /**< Is this an active pool, after a config reload an
pool is made inactive */
time_t last_update = 0; /**< When was this pool last updated */
Expand All @@ -1040,7 +1037,7 @@ struct SqlPoolDescriptor {
int validate_timeout = 0; /**< Number of seconds after which an idle
connection should be validated */
int nr_connections = 0; /**< Number of active connections in the pool */
dlink link; /**< list management */
dlink<SqlPoolDescriptor> link; /**< list management */
};

#include "include/jcr.h"
Expand Down
7 changes: 4 additions & 3 deletions core/src/cats/cats_backends.cc
Expand Up @@ -2,7 +2,7 @@
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -52,7 +52,7 @@ static struct backend_interface_mapping_t {
# define RTLD_NOW 2
# endif

static alist* loaded_backends = NULL;
static alist<backend_shared_library_t*>* loaded_backends = NULL;
static std::vector<std::string> backend_dirs;

void DbSetBackendDirs(std::vector<std::string>& new_backend_dirs)
Expand Down Expand Up @@ -233,7 +233,8 @@ BareosDb* db_init_database(JobControlRecord* jcr,
backend_shared_library->flush_backend = flush_backend;

if (loaded_backends == NULL) {
loaded_backends = new alist(10, not_owned_by_alist);
loaded_backends
= new alist<backend_shared_library_t*>(10, not_owned_by_alist);
}
loaded_backends->append(backend_shared_library);

Expand Down
16 changes: 7 additions & 9 deletions core/src/cats/mysql.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -53,7 +53,7 @@
*/

// List of open databases
static dlist* db_list = NULL;
static dlist<BareosDbMysql>* db_list = NULL;

static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

Expand Down Expand Up @@ -120,7 +120,9 @@ BareosDbMysql::BareosDbMysql(JobControlRecord* jcr,
result_ = NULL;

// Put the db in the list.
if (db_list == NULL) { db_list = new dlist(this, &this->link_); }
if (db_list == NULL) {
db_list = new dlist<BareosDbMysql>(this, &this->link);
}
db_list->append(this);

/* make the queries available using the queries variable from the parent class
Expand Down Expand Up @@ -397,9 +399,7 @@ bool BareosDbMysql::SqlQueryWithHandler(const char* query,
break;
case CR_SERVER_GONE_ERROR:
case CR_SERVER_LOST:
if (exit_on_fatal_) {
Emsg0(M_ERROR_TERM, 0, "Fatal database error\n");
}
if (exit_on_fatal_) { Emsg0(M_ERROR_TERM, 0, "Fatal database error\n"); }

if (try_reconnect_ && !transaction_) {
/*
Expand Down Expand Up @@ -505,9 +505,7 @@ bool BareosDbMysql::SqlQueryWithoutHandler(const char* query, int flags)
break;
case CR_SERVER_GONE_ERROR:
case CR_SERVER_LOST:
if (exit_on_fatal_) {
Emsg0(M_ERROR_TERM, 0, "Fatal database error\n");
}
if (exit_on_fatal_) { Emsg0(M_ERROR_TERM, 0, "Fatal database error\n"); }

if (try_reconnect_ && !transaction_) {
/*
Expand Down
12 changes: 6 additions & 6 deletions core/src/cats/postgresql.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2003-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -54,7 +54,7 @@
* -----------------------------------------------------------------------
*/

static dlist* db_list = NULL;
static dlist<BareosDbPostgresql>* db_list = NULL;

static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

Expand Down Expand Up @@ -126,7 +126,9 @@ BareosDbPostgresql::BareosDbPostgresql(JobControlRecord* jcr,
result_ = NULL;

// Put the db in the list.
if (db_list == NULL) { db_list = new dlist(this, &this->link_); }
if (db_list == NULL) {
db_list = new dlist<BareosDbPostgresql>(this, &this->link);
}
db_list->append(this);

/* make the queries available using the queries variable from the parent class
Expand Down Expand Up @@ -633,9 +635,7 @@ bool BareosDbPostgresql::SqlQueryWithoutHandler(const char* query, int flags)
break;
case PGRES_FATAL_ERROR:
Dmsg1(50, "Result status fatal: %s\n", query);
if (exit_on_fatal_) {
Emsg0(M_ERROR_TERM, 0, "Fatal database error\n");
}
if (exit_on_fatal_) { Emsg0(M_ERROR_TERM, 0, "Fatal database error\n"); }

if (try_reconnect_ && !transaction_) {
/*
Expand Down
10 changes: 6 additions & 4 deletions core/src/cats/sqlite.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -50,7 +50,7 @@
* -----------------------------------------------------------------------
*/

static dlist* db_list = NULL;
static dlist<BareosDbSqlite>* db_list = NULL;

static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

Expand Down Expand Up @@ -120,7 +120,9 @@ BareosDbSqlite::BareosDbSqlite(JobControlRecord* jcr,
lowlevel_errmsg_ = NULL;

// Put the db in the list.
if (db_list == NULL) { db_list = new dlist(this, &this->link_); }
if (db_list == NULL) {
db_list = new dlist<BareosDbSqlite>(this, &this->link);
}
db_list->append(this);

/* make the queries available using the queries variable from the parent class
Expand Down Expand Up @@ -664,7 +666,7 @@ BareosDb* db_init_database(JobControlRecord* jcr,
bool need_private)
# endif
{
BareosDb* mdb = NULL;
BareosDbSqlite* mdb = NULL;

P(mutex); /* lock DB queue */

Expand Down
8 changes: 4 additions & 4 deletions core/src/console/console.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2012 Planets Communications B.V.
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -380,7 +380,7 @@ static char* get_previous_keyword(int current_point, int nb)
}

struct ItemList {
alist list; /* holds the completion list */
alist<const char*> list; /* holds the completion list */
};

static ItemList* items = NULL;
Expand Down Expand Up @@ -464,8 +464,8 @@ static char* item_generator(const char* text,
const char* item,
cpl_item_t type)
{
static int list_index, len;
char* name;
static std::size_t list_index, len;
const char* name;

if (!state) {
list_index = 0;
Expand Down
16 changes: 8 additions & 8 deletions core/src/dird/dir_plugins.cc
Expand Up @@ -3,7 +3,7 @@
Copyright (C) 2007-2011 Free Software Foundation Europe e.V.
Copyright (C) 2011-2016 Planets Communications B.V.
Copyright (C) 2013-2020 Bareos GmbH & Co. KG
Copyright (C) 2013-2021 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
Expand Down Expand Up @@ -40,7 +40,7 @@ const char* plugin_type = "-dir.dll";
const char* plugin_type = "-dir.so";
#endif

static alist* dird_plugin_list;
static alist<Plugin*>* dird_plugin_list;
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

/* Forward referenced functions */
Expand Down Expand Up @@ -123,7 +123,7 @@ static inline bool trigger_plugin_event(JobControlRecord* jcr,
bDirEvent* event,
PluginContext* ctx,
void* value,
alist* plugin_ctx_list,
alist<PluginContext*>* plugin_ctx_list,
int* index,
bRC* rc)
{
Expand Down Expand Up @@ -159,7 +159,7 @@ static inline bool trigger_plugin_event(JobControlRecord* jcr,
* that moved back a position in the alist.
*/
if (index) {
UnloadPlugin(plugin_ctx_list, ctx->plugin, *index);
UnloadPlugin(dird_plugin_list, ctx->plugin, *index);
*index = ((*index) - 1);
}
break;
Expand Down Expand Up @@ -191,7 +191,7 @@ bRC GeneratePluginEvent(JobControlRecord* jcr,
{
int i;
bDirEvent event;
alist* plugin_ctx_list;
alist<PluginContext*>* plugin_ctx_list;
bRC rc = bRC_OK;

if (!dird_plugin_list) {
Expand Down Expand Up @@ -269,7 +269,7 @@ static void DumpDirPlugins(FILE* fp) { DumpPlugins(dird_plugin_list, fp); }
* This entry point is called internally by BAREOS to ensure
* that the plugin IO calls come into this code.
*/
void LoadDirPlugins(const char* plugin_dir, alist* plugin_names)
void LoadDirPlugins(const char* plugin_dir, alist<const char*>* plugin_names)
{
Plugin* plugin;
int i;
Expand All @@ -280,7 +280,7 @@ void LoadDirPlugins(const char* plugin_dir, alist* plugin_names)
return;
}

dird_plugin_list = new alist(10, not_owned_by_alist);
dird_plugin_list = new alist<Plugin*>(10, not_owned_by_alist);
if (!LoadPlugins((void*)&bareos_plugin_interface_version,
(void*)&bareos_core_functions, dird_plugin_list, plugin_dir,
plugin_names, plugin_type, IsPluginCompatible)) {
Expand Down Expand Up @@ -501,7 +501,7 @@ void NewPlugins(JobControlRecord* jcr)
Dmsg1(debuglevel, "dir-plugin-list size=%d\n", num);
if (num == 0) { return; }

jcr->plugin_ctx_list = new alist(10, owned_by_alist);
jcr->plugin_ctx_list = new alist<PluginContext*>(10, owned_by_alist);
foreach_alist_index (i, plugin, dird_plugin_list) {
// Start a new instance of each plugin
instantiate_plugin(jcr, plugin, 0);
Expand Down
4 changes: 2 additions & 2 deletions core/src/dird/dir_plugins.h
Expand Up @@ -47,7 +47,7 @@
#include "include/bc_types.h"
#include "lib/plugins.h"

class alist;
template <typename T> class alist;

namespace directordaemon {

Expand Down Expand Up @@ -151,7 +151,7 @@ typedef struct s_dirbareosFuncs {

// Bareos Core Routines -- not used within a plugin
#ifdef DIRECTOR_DAEMON
void LoadDirPlugins(const char* plugin_dir, alist* plugin_names);
void LoadDirPlugins(const char* plugin_dir, alist<const char*>* plugin_names);
void UnloadDirPlugins(void);
int ListDirPlugins(PoolMem& msg);
void DispatchNewPluginOptions(JobControlRecord* jcr);
Expand Down

0 comments on commit 0a8f6a1

Please sign in to comment.