Skip to content

Commit

Permalink
Use C++ streams for error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
a-andre committed Jul 29, 2024
1 parent 6fa5d84 commit 345a254
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 66 deletions.
5 changes: 3 additions & 2 deletions src/CoinAdjacencyVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <vector>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <limits>
#include "CoinAdjacencyVector.hpp"

Expand Down Expand Up @@ -116,7 +117,7 @@ static void *xmalloc( const size_t size )
void *result = malloc( size );
if (!result)
{
fprintf(stderr, "No more memory available. Trying to allocate %zu bytes.", size);
std::cerr << "No more memory available. Trying to allocate " << size << " bytes.";
abort();
}

Expand All @@ -128,7 +129,7 @@ static void *xrealloc( void *ptr, const size_t size )
void * res = realloc( ptr, size );
if (!res)
{
fprintf(stderr, "No more memory available. Trying to allocate %zu bytes.", size);
std::cerr << "No more memory available. Trying to allocate " << size << " bytes.";
abort();
}

Expand Down
9 changes: 5 additions & 4 deletions src/CoinBronKerbosch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include "CoinBronKerbosch.hpp"
#include "CoinConflictGraph.hpp"
#include "CoinCliqueList.hpp"
Expand Down Expand Up @@ -417,15 +418,15 @@ void CoinBronKerbosch::computeFitness(const double *weights) {
break;
}
default:
fprintf(stderr, "Invalid option %lu for pivoting strategy!\n", pivotingStrategy_);
std::cerr << "Invalid option " << pivotingStrategy_ << " for pivoting strategy!" << std::endl;
abort();
}
}

static void *xmalloc( const size_t size ) {
void *result = malloc( size );
if (!result) {
fprintf(stderr, "No more memory available. Trying to allocate %zu bytes.", size);
std::cerr << "No more memory available. Trying to allocate " << size << "bytes.";
abort();
}

Expand All @@ -435,7 +436,7 @@ static void *xmalloc( const size_t size ) {
static void *xcalloc( const size_t elements, const size_t size ) {
void *result = calloc( elements, size );
if (!result) {
fprintf(stderr, "No more memory available. Trying to callocate %zu bytes.", size * elements);
std::cerr << "No more memory available. Trying to callocate " << size * elements << " bytes.";
abort();
}

Expand All @@ -445,7 +446,7 @@ static void *xcalloc( const size_t elements, const size_t size ) {
static void *xrealloc( void *ptr, const size_t size ) {
void * res = realloc( ptr, size );
if (!res) {
fprintf(stderr, "No more memory available. Trying to allocate %zu bytes in CoinCliqueList", size);
std::cerr << "No more memory available. Trying to allocate " << size << " bytes in CoinCliqueList";
abort();
}

Expand Down
11 changes: 6 additions & 5 deletions src/CoinCliqueExtender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <ctime>
#include <cassert>
#include <cmath>
#include <iostream>
#include <limits>
#include <algorithm>
#include "CoinCliqueExtender.hpp"
Expand Down Expand Up @@ -66,7 +67,7 @@ CoinCliqueExtender::CoinCliqueExtender(const CoinConflictGraph *cgraph, size_t e
maxRC_ = maxRC;

if ((extMethod_ == 4 || extMethod_ == 5) && !rc_) {
fprintf(stderr, "Warning: using random selection for extension since no costs were informed.\n");
std::cerr << "Warning: using random selection for extension since no costs were informed." << std::endl;
extMethod_ = 1;
}

Expand Down Expand Up @@ -133,7 +134,7 @@ CoinCliqueExtender::CoinCliqueExtender(const CoinConflictGraph *cgraph, size_t e
break;
}
default:
fprintf(stderr, "Invalid option %lu\n", extMethod_);
std::cerr << "Invalid option " << extMethod_ << std::endl;
abort();
}
}
Expand Down Expand Up @@ -273,7 +274,7 @@ bool CoinCliqueExtender::extendClique(const size_t *clqIdxs, const size_t clqSiz
result = greedySelection(clqIdxs, clqSize, costs_);
break;
default:
fprintf(stderr, "Invalid option %lu\n", extMethod_);
std::cerr << "Invalid option " << extMethod_ << std::endl;
abort();
}

Expand Down Expand Up @@ -363,7 +364,7 @@ size_t CoinCliqueExtender::getCliqueSize(const size_t i) const {
static void *xmalloc( const size_t size ) {
void *result = malloc( size );
if (!result) {
fprintf(stderr, "No more memory available. Trying to allocate %zu bytes.", size);
std::cerr << "No more memory available. Trying to allocate " << size << " bytes.";
abort();
}

Expand All @@ -373,7 +374,7 @@ static void *xmalloc( const size_t size ) {
static void *xcalloc( const size_t elements, const size_t size ) {
void *result = calloc( elements, size );
if (!result) {
fprintf(stderr, "No more memory available. Trying to callocate %zu bytes.", size * elements);
std::cerr << "No more memory available. Trying to callocate " << size * elements << " bytes.";
abort();
}

Expand Down
13 changes: 7 additions & 6 deletions src/CoinCliqueList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include "CoinCliqueList.hpp"

#ifdef DEBUGCG
Expand Down Expand Up @@ -91,7 +92,7 @@ static void *xmalloc( const size_t size )
void *result = malloc( size );
if (!result)
{
fprintf(stderr, "No more memory available. Trying to allocate %zu bytes in CoinCliqueList.\n", size);
std::cerr << "No more memory available. Trying to allocate " << size << " bytes in CoinCliqueList." << std::endl;
exit(1);
}

Expand All @@ -113,7 +114,7 @@ void CoinCliqueList::computeNodeOccurrences(size_t nNodes)
// couting number of occurrences for each node
size_t *noc = (size_t *)calloc( nNodes, sizeof(size_t) );
if (!noc) {
fprintf( stderr, "No more memory available.\n" );
std::cerr << "No more memory available." << std::endl;
abort();
}

Expand Down Expand Up @@ -160,7 +161,7 @@ static void *xrealloc( void *ptr, const size_t size )
void * res = realloc( ptr, size );
if (!res)
{
fprintf(stderr, "No more memory available. Trying to allocate %zu bytes in CoinCliqueList", size);
std::cerr << "No more memory available. Trying to allocate " << size << " bytes in CoinCliqueList";
abort();
}

Expand Down Expand Up @@ -194,7 +195,7 @@ size_t CoinCliqueList::nNodeOccurrences(size_t idxNode) const
#ifdef DEBUGCG
void CoinCliqueList::validateClique(const CoinConflictGraph *cgraph, const size_t *idxs, const size_t size) {
if (size == 0) {
fprintf(stderr, "Empty clique!\n");
std::cerr << "Empty clique!" << std::endl;
abort();
}

Expand All @@ -206,10 +207,10 @@ void CoinCliqueList::validateClique(const CoinConflictGraph *cgraph, const size_
for (size_t i = 0; i < size - 1; i++) {
for (size_t j = i + 1; j < size; j++) {
if ((!cgraph->conflicting(idxs[i], idxs[j])) || (idxs[i] == idxs[j])) {
fprintf(stderr, "ERROR: Nodes %ld and %ld are not in conflict.\n", idxs[i], idxs[j]);
std::cerr << "ERROR: Nodes " << idxs[i] << " and " << idxs[j] << " are not in conflict." << std::endl;
abort();
}
}
}
}
#endif
#endif
7 changes: 4 additions & 3 deletions src/CoinCliqueSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

const size_t CoinCliqueSet::sequence_[] = {37, 31, 29, 17, 13, 11, 7, 1};
const size_t CoinCliqueSet::nSequence_ = 8;
Expand Down Expand Up @@ -184,7 +185,7 @@ bool CoinCliqueSet::alreadyInserted(size_t size, const size_t els[], size_t hash
static void *xmalloc( const size_t size ) {
void *result = malloc( size );
if (!result) {
fprintf(stderr, "No more memory available. Trying to allocate %zu bytes.", size);
std::cerr << "No more memory available. Trying to allocate " << size << " bytes.";
abort();
}

Expand All @@ -194,9 +195,9 @@ static void *xmalloc( const size_t size ) {
static void *xrealloc( void *ptr, const size_t size ) {
void * result = realloc( ptr, size );
if (!result) {
fprintf(stderr, "No more memory available. Trying to allocate %zu bytes in CoinCliqueList", size);
std::cerr << "No more memory available. Trying to allocate " << size << " bytes in CoinCliqueList";
abort();
}

return result;
}
}
4 changes: 2 additions & 2 deletions src/CoinConflictGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ bool CoinConflictGraph::conflicting(size_t n1, size_t n2) const {
static void *xmalloc(const size_t size) {
void *result = malloc(size);
if (!result) {
fprintf(stderr, "No more memory available. Trying to allocate %zu bytes.", size);
std::cerr << "No more memory available. Trying to allocate " << size << " bytes.";
abort();
}

Expand All @@ -103,7 +103,7 @@ static void *xmalloc(const size_t size) {
static void *xcalloc(const size_t elements, const size_t size) {
void *result = calloc(elements, size);
if (!result) {
fprintf(stderr, "No more memory available. Trying to callocate %zu bytes.", size * elements);
std::cerr << "No more memory available. Trying to callocate " << size * elements << " bytes.";
abort();
}

Expand Down
9 changes: 5 additions & 4 deletions src/CoinCutPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <cmath>
#include <cassert>
#include <algorithm>
#include <iostream>

#define CUTPOOL_EPS 1e-8

Expand Down Expand Up @@ -408,7 +409,7 @@ void CoinCutPool::removeNullCuts() {
static void *xmalloc( const size_t size ) {
void *result = malloc( size );
if (!result) {
fprintf(stderr, "No more memory available. Trying to allocate %zu bytes.", size);
std::cerr << "No more memory available. Trying to allocate " << size << " bytes.";
abort();
}

Expand All @@ -418,7 +419,7 @@ static void *xmalloc( const size_t size ) {
static void *xrealloc( void *ptr, const size_t size ) {
void * res = realloc( ptr, size );
if (!res) {
fprintf(stderr, "No more memory available. Trying to allocate %zu bytes in CoinCliqueList", size);
std::cerr << "No more memory available. Trying to allocate " << size << " bytes in CoinCliqueList";
abort();
}

Expand All @@ -428,9 +429,9 @@ static void *xrealloc( void *ptr, const size_t size ) {
static void *xcalloc( const size_t elements, const size_t size ) {
void *result = calloc( elements, size );
if (!result) {
fprintf(stderr, "No more memory available. Trying to callocate %zu bytes.", size * elements);
std::cerr << "No more memory available. Trying to callocate " << size * elements << " bytes.";
abort();
}

return result;
}
}
8 changes: 4 additions & 4 deletions src/CoinDynamicConflictGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ CoinDynamicConflictGraph::CoinDynamicConflictGraph (

char *iv = (char *) calloc( size_, sizeof(char) );
if (!iv) {
fprintf( stderr, "out of memory.\n" );
std::cerr << "out of memory." << std::endl;
abort();
}

Expand Down Expand Up @@ -546,7 +546,7 @@ static void *xrealloc( void *ptr, const size_t size )
void * res = realloc( ptr, size );
if (!res)
{
fprintf(stderr, "No more memory available. Trying to allocate %zu bytes.", size);
std::cerr << "No more memory available. Trying to allocate " << size << " bytes.";
abort();
}

Expand All @@ -558,7 +558,7 @@ static void *xmalloc( const size_t size )
void *result = malloc( size );
if (!result)
{
fprintf(stderr, "No more memory available. Trying to allocate %zu bytes.", size);
std::cerr << "No more memory available. Trying to allocate " << size << " bytes.";
abort();
}

Expand All @@ -568,7 +568,7 @@ static void *xmalloc( const size_t size )
static void *xcalloc( const size_t elements, const size_t size ) {
void *result = calloc( elements, size );
if (!result) {
fprintf(stderr, "No more memory available. Trying to callocate %zu bytes.", size * elements);
std::cerr << "No more memory available. Trying to callocate " << size * elements << " bytes.";
abort();
}

Expand Down
2 changes: 1 addition & 1 deletion src/CoinFactorization.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ class COINUTILSLIB_EXPORT CoinFactorization {
if (l + numberInPivotColumn > lengthAreaL_) {
//need more memory
if ((messageLevel_ & 4) != 0)
printf("more memory needed in middle of invert\n");
std::cout <<"more memory needed in middle of invert\n";
return false;
}
//l+=currentAreaL_->elementByColumn-elementL;
Expand Down
Loading

0 comments on commit 345a254

Please sign in to comment.