Skip to content

Commit

Permalink
sync clang-format changes from main
Browse files Browse the repository at this point in the history
  • Loading branch information
neteler committed Jan 4, 2023
1 parent 74207c5 commit ea058ff
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 356 deletions.
155 changes: 70 additions & 85 deletions include/grass/iostream/mm.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/****************************************************************************
*
*
* MODULE: iostream
*
* COPYRIGHT (C) 2007 Laura Toma
*
*
*
*
* Iostream is a library that implements streams, external memory
* sorting on streams, and an external memory priority queue on
* streams. These are the fundamental components used in external
* memory algorithms.
* memory algorithms.
* Credits: The library was developed by Laura Toma. The kernel of
* class STREAM is based on the similar class existent in the GPL TPIE
Expand All @@ -20,7 +20,7 @@
* porting Terraflow to GRASS in 2001. PEARL upgrades in 2003 by
* Rajiv Wickremesinghe as part of the Terracost project.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
Expand All @@ -33,7 +33,6 @@
* General Public License for more details. *
* **************************************************************************/


#ifndef _MM_H
#define _MM_H

Expand All @@ -48,42 +47,38 @@
#define MM_REGISTER_VERSION 2

// The default amount of memory we will allow to be allocated (40MB).
#define MM_DEFAULT_MM_SIZE (40<<20)

#define MM_DEFAULT_MM_SIZE (40 << 20)

// MM accounting modes
typedef enum {
MM_IGNORE_MEMORY_EXCEEDED=0,
MM_ABORT_ON_MEMORY_EXCEEDED,
MM_WARN_ON_MEMORY_EXCEEDED
MM_IGNORE_MEMORY_EXCEEDED = 0,
MM_ABORT_ON_MEMORY_EXCEEDED,
MM_WARN_ON_MEMORY_EXCEEDED
} MM_mode;


// MM Error codes
enum MM_err {
MM_ERROR_NO_ERROR = 0,
MM_ERROR_INSUFFICIENT_SPACE,
MM_ERROR_UNDERFLOW,
MM_ERROR_EXCESSIVE_ALLOCATION
MM_ERROR_NO_ERROR = 0,
MM_ERROR_INSUFFICIENT_SPACE,
MM_ERROR_UNDERFLOW,
MM_ERROR_EXCESSIVE_ALLOCATION
};


// types of memory usage queries we can make on streams
enum MM_stream_usage {
// Overhead of the object without the buffer
MM_STREAM_USAGE_OVERHEAD = 1,
// Overhead of the object without the buffer
MM_STREAM_USAGE_OVERHEAD = 1,

// amount used by a buffer
MM_STREAM_USAGE_BUFFER,
// amount used by a buffer
MM_STREAM_USAGE_BUFFER,

// Amount currently in use.
MM_STREAM_USAGE_CURRENT,
// Amount currently in use.
MM_STREAM_USAGE_CURRENT,

// Maximum amount possibly in use.
MM_STREAM_USAGE_MAXIMUM
// Maximum amount possibly in use.
MM_STREAM_USAGE_MAXIMUM
};


#ifdef GRASS_CMAKE_BUILD
#include <export/grass_iostream_export.h>
#else
Expand All @@ -94,88 +89,78 @@ enum MM_stream_usage {
// BTEs that rely on the underlying OS to manage physical memory.
class GRASS_IOSTREAM_EXPORT MM_register {
private:
// The number of instances of this class and descendents that exist.
static int instances;
// The amount of space remaining to be allocated.
size_t remaining;
// The user-specified limit on memory.
size_t user_limit;
// the amount that has been allocated.
size_t used;
// flag indicates how we are keeping track of memory
static MM_mode register_new;

//protected:
// // private methods, only called by operators new and delete.
// The number of instances of this class and descendents that exist.
static int instances;

// The amount of space remaining to be allocated.
size_t remaining;

// The user-specified limit on memory.
size_t user_limit;

// the amount that has been allocated.
size_t used;

// flag indicates how we are keeping track of memory
static MM_mode register_new;

// protected:
// // private methods, only called by operators new and delete.

public: // Need to be accessible from pqueue constructor
MM_err register_allocation (size_t sz);
MM_err register_deallocation(size_t sz);
MM_err register_allocation(size_t sz);
MM_err register_deallocation(size_t sz);


public:
MM_register();
~MM_register(void);
MM_register();
~MM_register(void);

MM_err set_memory_limit(size_t sz);
void enforce_memory_limit();
void ignore_memory_limit();
void warn_memory_limit();
MM_mode get_limit_mode();
void print_limit_mode();

MM_err set_memory_limit(size_t sz);
void enforce_memory_limit ();
void ignore_memory_limit ();
void warn_memory_limit ();
MM_mode get_limit_mode();
void print_limit_mode();
size_t memory_available();
size_t memory_used();
size_t memory_limit();

size_t memory_available ();
size_t memory_used ();
size_t memory_limit ();
int space_overhead();

int space_overhead ();

void print();
void print();

// make these members of MM_register
// make these members of MM_register
#ifdef GRASS_MM_USE_EXCEPTION_SPECIFIER
void * operator new(size_t) throw (std::bad_alloc);
void * operator new[] (size_t) throw (std::bad_alloc);
void operator delete(void *) throw();
void operator delete[](void *) throw();
void *operator new(size_t) throw(std::bad_alloc);
void *operator new[](size_t) throw(std::bad_alloc);
void operator delete(void *) throw();
void operator delete[](void *) throw();
#else
void * operator new(size_t);
void * operator new[] (size_t);
void operator delete(void *) noexcept;
void operator delete[](void *) noexcept;
void *operator new(size_t);
void *operator new[](size_t);
void operator delete(void *) noexcept;
void operator delete[](void *) noexcept;
#endif /* GRASS_MM_USE_EXCEPTION_SPECIFIER */

friend class mm_register_init;
friend class mm_register_init;
};




// A class to make sure that MM_manager gets set up properly (only one
// instance) .
class mm_register_init {
private:
// The number of mm_register_init objects that exist.
static unsigned int count;
// The number of mm_register_init objects that exist.
static unsigned int count;

public:
mm_register_init(void);
~mm_register_init(void);
mm_register_init(void);
~mm_register_init(void);
};

static mm_register_init source_file_mm_register_init;





// Here is the single memory management object (defined in mm.C).
extern GRASS_IOSTREAM_EXPORT MM_register MM_manager;



#endif // _MM_H
#endif // _MM_H
55 changes: 27 additions & 28 deletions lib/db/dbmi_base/dbmscap.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@
#include <grass/dbmi.h>
#include <grass/gis.h>

static char *dbmscap_files[] = {
"/etc/dbmscap",
"/lib/dbmscap",
"/usr/lib/dbmscap",
"/usr/local/lib/dbmscap",
"/usr/local/dbmi/lib/dbmscap",
NULL
};

static void
add_entry(dbDbmscap ** list, char *name, char *startup, char *comment);
static char *dbmscap_files[] = {"/etc/dbmscap",
"/lib/dbmscap",
"/usr/lib/dbmscap",
"/usr/local/lib/dbmscap",
"/usr/local/dbmi/lib/dbmscap",
NULL};

static void add_entry(dbDbmscap **list, char *name, char *startup,
char *comment);

static char *dbmscap_filename(int err_flag)
{
Expand Down Expand Up @@ -78,7 +76,7 @@ int db_has_dbms(void)
\param dst destination
\param src source
*/
void db_copy_dbmscap_entry(dbDbmscap * dst, dbDbmscap * src)
void db_copy_dbmscap_entry(dbDbmscap *dst, dbDbmscap *src)
{
strcpy(dst->driverName, src->driverName);
strcpy(dst->comment, src->comment);
Expand All @@ -90,16 +88,16 @@ void db_copy_dbmscap_entry(dbDbmscap * dst, dbDbmscap * src)
dbmscap file was used in grass5.0 but it is not used in
grass5.7 until we find it necessary. All code for dbmscap
file is commented here.
file is commented here.
Instead of in dbmscap file db_read_dbmscap() searches
Instead of in dbmscap file db_read_dbmscap() searches
for available dbmi drivers in $(GISBASE)/driver/db/
\return pointer to dbDbmscap
*/
dbDbmscap *db_read_dbmscap(void)
{
/*
/*
FILE *fd;
char *file;
char name[1024];
Expand Down Expand Up @@ -170,16 +168,15 @@ dbDbmscap *db_read_dbmscap(void)
dir = opendir(dirpath);
if (dir == NULL) {
db_syserror("Cannot open drivers directory");
return (dbDbmscap *) NULL;
return (dbDbmscap *)NULL;
}
G_free(dirpath);

/* read all drivers */
while ((ent = readdir(dir))) {
char *name;

if ((strcmp(ent->d_name, ".") == 0)
|| (strcmp(ent->d_name, "..") == 0))
if ((strcmp(ent->d_name, ".") == 0) || (strcmp(ent->d_name, "..") == 0))
continue;

#ifdef _WIN32
Expand All @@ -192,8 +189,8 @@ dbDbmscap *db_read_dbmscap(void)
name = G_str_replace(ent->d_name, ".exe", "");

#ifdef _WIN32
dirpath = G_malloc(strlen("\\driver\\db\\")
+ strlen(G_gisbase()) + strlen(ent->d_name) + 1);
dirpath = G_malloc(strlen("\\driver\\db\\") + strlen(G_gisbase()) +
strlen(ent->d_name) + 1);
sprintf(dirpath, "%s\\driver\\db\\%s", G_gisbase(), ent->d_name);
G_convert_dirseps_to_host(dirpath);
#else
Expand All @@ -209,20 +206,22 @@ dbDbmscap *db_read_dbmscap(void)
return list;
}

static int cmp_entry(dbDbmscap * a, dbDbmscap * b)
static int cmp_entry(dbDbmscap *a, dbDbmscap *b)
{
return (*a->driverName &&
*b->driverName ? strcmp(a->driverName, b->driverName) : 0);
return (*a->driverName && *b->driverName
? strcmp(a->driverName, b->driverName)
: 0);
}

static void add_entry(dbDbmscap ** list, char *name, char *startup,
static void add_entry(dbDbmscap **list, char *name, char *startup,
char *comment)
{
/* add an entry to the list, so that the list remains ordered (by driverName) */
/* add an entry to the list, so that the list remains ordered (by
* driverName) */

dbDbmscap *head, *cur, *tail;

cur = (dbDbmscap *) db_malloc(sizeof(dbDbmscap));
cur = (dbDbmscap *)db_malloc(sizeof(dbDbmscap));
if (cur == NULL) {
*list = NULL;
return;
Expand Down Expand Up @@ -256,11 +255,11 @@ static void add_entry(dbDbmscap ** list, char *name, char *startup,
}

/*!
\brief Free dbmscap
\brief Free dbmscap
\param list pointer to dbDbmscap
*/
void db_free_dbmscap(dbDbmscap * list)
void db_free_dbmscap(dbDbmscap *list)
{
dbDbmscap *next, *cur;

Expand Down
Loading

0 comments on commit ea058ff

Please sign in to comment.