Skip to content

Commit

Permalink
Fix c++17 compatibility #103
Browse files Browse the repository at this point in the history
  • Loading branch information
BoPeng committed Sep 1, 2024
1 parent 3e48f2e commit bf79dc8
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 11 deletions.
3 changes: 2 additions & 1 deletion INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ conda install -c conda-forge simuPOP
### Compile from source

If you are working with a development version of simuPOP or an unsupported platform, you may need to install simuPOP from source.
Generally speaking, you will need a C/C++ compiler and zlib.

Generally speaking, you will need a recent C/C++ compiler that supports the `c++17` standard and zlib.

#### Checkout the simuPOP source code

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ The user guide and reference manual of simuPOP is available at http://bopeng.git

## Change Log since 1.1.7

### simuPOP 1.1.16
* [#103](https://github.com/BoPeng/simuPOP/issues/103) Fix compatibility with recent compilers with c++17 support, and fix conda-forge release.

### simuPOP 1.1.15
* [#122](https://github.com/BoPeng/simuPOP/issues/122) Fix compatibility with Visual Studio 2022 under windows.

Expand Down
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def is_maverick():
fin, fout, ferr = (p.stdin, p.stdout, p.stderr)
output = ferr.readlines()[-1].decode('utf8')
try:
version = re.match('.*gcc version\s*(\d+).(\d+).(\d+).*', output).groups()
version = re.match(r'.*gcc version\s*(\d+).(\d+).(\d+).*', output).groups()
if int(version[0]) < 4 or int(version[1]) < 2:
print('Support for openMP is turned off because version %s.%s.%s of gcc does not support this feature' % version)
USE_OPENMP = False
Expand Down Expand Up @@ -402,6 +402,8 @@ def replaceIntHeader(file):

COMMON_MACROS = [
('BOOST_UBLAS_NDEBUG', None),
('BOOST_NO_CXX98_FUNCTION_BASE', None),
('BOOST_COMPUTE_USE_CPP11', None),
('_HAS_ITERATOR_DEBUGGING', 0),
('BOOST_ALL_NO_LIB', None),
('NO_ZLIB', 0),
Expand Down Expand Up @@ -490,7 +492,7 @@ def replaceIntHeader(file):
# /wd4819 disables warning messages for non-unicode character in boost/uitlity/enable_if.hpp
# /wd4996 disables warning messages for unsafe function call in boost/serialization
# /wd4068 disables warning messages for unknown pragma set by gcc
common_extra_compile_args = ['/O2', '/GR', '/EHsc', '/wd4819', '/wd4996', '/wd4068']
common_extra_compile_args = ['/O2', '/GR', '/EHsc', '/wd4819', '/wd4996', '/wd4068', '/std:c++17']
# Enable openMP if USE_OPENMP = True
if USE_OPENMP:
if USE_ICC:
Expand Down Expand Up @@ -535,6 +537,7 @@ def try_compile(body='', ext='.cpp'):
oldstderr = os.dup(sys.stderr.fileno())
os.dup2(devnull.fileno(), sys.stderr.fileno())
cc = new_compiler()
distutils.sysconfig.customize_compiler(cc)
objects = cc.compile([fname], output_dir=tmpdir)
except:
return False
Expand Down Expand Up @@ -650,6 +653,7 @@ def ModuInfo(modu, SIMUPOP_VER, SIMUPOP_REV):
# try to get
print('Building static libraries')
c = new_compiler(verbose=1)
distutils.sysconfig.customize_compiler(c)
# -w suppress all warnings caused by the use of boost libraries
objects = c.compile(LIB_FILES,
include_dirs=['gsl', 'gsl/specfunc', 'build', '.', boost_include_dir] + common_extra_include_dirs,
Expand Down
8 changes: 4 additions & 4 deletions src/customizedTemplates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ template <typename T>
PyObject *
getarrayitem_template(struct arrayobject_template<T> * op, Py_ssize_t i)
{
register struct arrayobject_template<T> * ap;
struct arrayobject_template<T> * ap;

assert(is_carrayobject_template<T>(op));
ap = (struct arrayobject_template<T> *)op;
Expand All @@ -77,7 +77,7 @@ template <>
PyObject *
getarrayitem_template<GenoIterator>(struct arrayobject_template<GenoIterator> * op, Py_ssize_t i)
{
register struct arrayobject_template<GenoIterator> * ap;
struct arrayobject_template<GenoIterator> * ap;

assert(is_carrayobject_template<GenoIterator>(op));
ap = (struct arrayobject_template<GenoIterator> *)op;
Expand Down Expand Up @@ -746,7 +746,7 @@ template <typename T>
PyObject *
getarrayitem_template(PyObject * op, Py_ssize_t i)
{
register struct arrayobject_template<T> * ap;
struct arrayobject_template<T> * ap;

assert(is_carrayobject_template<T>(op));
ap = (struct arrayobject_template<T> *)op;
Expand Down Expand Up @@ -1485,7 +1485,7 @@ template <>
PyObject *
getarrayitem_template<GenoIterator>(PyObject * op, Py_ssize_t i)
{
register struct arrayobject_template<GenoIterator> * ap;
struct arrayobject_template<GenoIterator> * ap;

assert(is_carrayobject_template<GenoIterator>(op));
ap = (struct arrayobject_template<GenoIterator> *)op;
Expand Down
3 changes: 2 additions & 1 deletion src/simuPOP_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ typedef const unsigned char & ConstAlleleRef;

// max allowed allele state
extern const unsigned long ModuleMaxAllele;
extern const unsigned long MaxRandomNumber;
// extern const unsigned long MaxRandomNumber;
inline constexpr unsigned long MaxRandomNumber = std::numeric_limits<int32_t>::max();

#define PopSWIGType "simuPOP::Population *"
#define IndSWIGType "simuPOP::Individual *"
Expand Down
1 change: 0 additions & 1 deletion src/stator.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include <numeric>
using std::string;
using std::count_if;
using std::bind2nd;
using std::equal;
using std::greater;
using std::min;
Expand Down
1 change: 0 additions & 1 deletion src/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ using std::greater;
const Allele simuPOP::vectorm::zero_ = 0;
#endif
const unsigned long ModuleMaxAllele = std::numeric_limits<Allele>::max();
const unsigned long MaxRandomNumber = std::numeric_limits<int32_t>::max();
const unsigned char MaxTraitIndex = std::numeric_limits<TraitIndexType>::max();
const size_t InvalidValue = ~size_t(0);
const size_t MaxIndexSize = std::numeric_limits<size_t>::max();
Expand Down
31 changes: 30 additions & 1 deletion src/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -1775,13 +1775,37 @@ void closeOutput(const string & output = string());
class RNG_func
{
public:
typedef unsigned long int result_type;

RNG_func(gsl_rng * rng) : m_RNG(rng)
{

}


unsigned long int operator()(unsigned long int N) const
#ifdef BOOST_COMPUTE_USE_CPP11
// somehow these functions needs to be static (callable from class), so
// min/max cannot change with the underlying m_RNG. However, we demand that
// RNGs generate full range of int to have a minimal range from 0 to
// MaxRandomNumber, so we can set the max to MaxRandomNumber.
constexpr static result_type min()
{
return 0;
}

constexpr static result_type max()
{
return MaxRandomNumber - 1;
}

result_type operator()()
{
return gsl_rng_uniform_int(m_RNG, MaxRandomNumber);
}

#endif

result_type operator()(result_type N) const
{
return gsl_rng_uniform_int(m_RNG, N);
}
Expand Down Expand Up @@ -1981,7 +2005,12 @@ class RNG
// generator.
RNG_func rng(m_RNG);

#ifdef BOOST_COMPUTE_USE_CPP11
std::shuffle(begin, end, rng);
#else
std::random_shuffle(begin, end, rng);
#endif

}


Expand Down

0 comments on commit bf79dc8

Please sign in to comment.