Skip to content

Commit

Permalink
Eliminate NEEDS_GENERIC_TEMPL_STATIC_DECL
Browse files Browse the repository at this point in the history
The old way of handling declarations for static members of a
template class was weird and required different implementations for
different compilers. This approach is standards-conformant and works
everywhere.
  • Loading branch information
speth committed Mar 29, 2022
1 parent 85e41ed commit 724df14
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 25 deletions.
1 change: 0 additions & 1 deletion SConstruct
Expand Up @@ -1818,7 +1818,6 @@ configh['SOLARIS'] = 1 if env['OS'] == 'Solaris' else None
configh['DARWIN'] = 1 if env['OS'] == 'Darwin' else None

if env['OS'] == 'Solaris' or env['HAS_CLANG']:
configh['NEEDS_GENERIC_TEMPL_STATIC_DECL'] = 1
env["RPATHPREFIX"] = "-Wl,-rpath,"

if env["OS"] == "Darwin" and env["use_rpath_linkage"] and not env.subst("$__RPATH"):
Expand Down
14 changes: 0 additions & 14 deletions include/cantera/base/config.h.in
Expand Up @@ -59,20 +59,6 @@ typedef int ftnlen; // Fortran hidden string length type
// with a native compiler
{SOLARIS!s}

//---------- C++ Compiler Variations ------------------------------

// This define is needed to account for the variability for how
// static variables in templated classes are defined. Right now
// this is only turned on for the SunPro compiler on Solaris.
// in that system , you need to declare the static storage variable.
// with the following line in the include file
//
// template<class M> Cabinet<M>* Cabinet<M>::s_storage;
//
// Note, on other systems that declaration is treated as a definition
// and this leads to multiple defines at link time
{NEEDS_GENERIC_TEMPL_STATIC_DECL!s}

//-------------- Optional Cantera Capabilities ----------------------

// Enable Sundials to use an external BLAS/LAPACK library if it was
Expand Down
9 changes: 0 additions & 9 deletions src/clib/Cabinet.h
Expand Up @@ -205,13 +205,4 @@ class Cabinet
std::vector<M*> m_table;
};

//! Declaration stating that the storage for the static member
//! of each instantiated template will exist
/*!
* The actual storage will be allocated in .cpp files
*/
#ifdef NEEDS_GENERIC_TEMPL_STATIC_DECL
template<class M, bool canDelete> Cabinet<M, canDelete>* Cabinet<M, canDelete>::s_storage;
#endif

#endif
1 change: 1 addition & 0 deletions src/clib/ct.cpp
Expand Up @@ -36,6 +36,7 @@ typedef Cabinet<XML_Node, false> XmlCabinet;
template<> ThermoCabinet* ThermoCabinet::s_storage = 0;
template<> KineticsCabinet* KineticsCabinet::s_storage = 0;
template<> TransportCabinet* TransportCabinet::s_storage = 0;
template<> XmlCabinet* XmlCabinet::s_storage; // defined in ctxml.cpp

/**
* Exported functions.
Expand Down
5 changes: 4 additions & 1 deletion src/clib/ctmultiphase.cpp
Expand Up @@ -17,7 +17,10 @@ using namespace std;
using namespace Cantera;

typedef Cabinet<MultiPhase> mixCabinet;
typedef Cabinet<ThermoPhase> ThermoCabinet;

template<> mixCabinet* mixCabinet::s_storage = 0;
template<> ThermoCabinet* ThermoCabinet::s_storage; // defined in ct.cpp

extern "C" {

Expand Down Expand Up @@ -54,7 +57,7 @@ extern "C" {
int mix_addPhase(int i, int j, double moles)
{
try {
mixCabinet::item(i).addPhase(&Cabinet<ThermoPhase>::item(j), moles);
mixCabinet::item(i).addPhase(&ThermoCabinet::item(j), moles);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand Down
3 changes: 3 additions & 0 deletions src/clib/ctonedim.cpp
Expand Up @@ -29,6 +29,9 @@ template<> DomainCabinet* DomainCabinet::s_storage = 0;
typedef Cabinet<ThermoPhase> ThermoCabinet;
typedef Cabinet<Kinetics> KineticsCabinet;
typedef Cabinet<Transport> TransportCabinet;
template<> ThermoCabinet* ThermoCabinet::s_storage; // defined in ct.cpp
template<> KineticsCabinet* KineticsCabinet::s_storage; // defined in ct.cpp
template<> TransportCabinet* TransportCabinet::s_storage; // defined in ct.cpp

extern "C" {

Expand Down
3 changes: 3 additions & 0 deletions src/clib/ctreactor.cpp
Expand Up @@ -32,6 +32,9 @@ template<> NetworkCabinet* NetworkCabinet::s_storage = 0;
template<> FlowDeviceCabinet* FlowDeviceCabinet::s_storage = 0;
template<> WallCabinet* WallCabinet::s_storage = 0;
template<> ReactorSurfaceCabinet* ReactorSurfaceCabinet::s_storage = 0;
template<> FuncCabinet* FuncCabinet::s_storage; // defined in ctfunc.cpp
template<> ThermoCabinet* ThermoCabinet::s_storage; // defined in ct.cpp
template<> KineticsCabinet* KineticsCabinet::s_storage; // defined in ct.cpp

extern "C" {

Expand Down
1 change: 1 addition & 0 deletions src/clib/ctrpath.cpp
Expand Up @@ -23,6 +23,7 @@ template<> DiagramCabinet* DiagramCabinet::s_storage = 0;
template<> BuilderCabinet* BuilderCabinet::s_storage = 0;

typedef Cabinet<Kinetics> KineticsCabinet;
template<> KineticsCabinet* KineticsCabinet::s_storage; // defined in ct.cpp

extern "C" {

Expand Down
2 changes: 2 additions & 0 deletions src/clib/ctsurf.cpp
Expand Up @@ -17,6 +17,8 @@ using namespace std;
using namespace Cantera;

typedef Cabinet<ThermoPhase> ThermoCabinet;
template<> ThermoCabinet* ThermoCabinet::s_storage; // defined in ct.cpp


extern "C" {

Expand Down

0 comments on commit 724df14

Please sign in to comment.