From db3de6d282e6b1a69f0982114c8165973467e896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Horva=CC=81t?= Date: Sat, 16 Nov 2024 10:55:21 +0000 Subject: [PATCH 1/4] refactor: require C99 and remove platform.h --- CMakeLists.txt | 4 +++ src/CMakeLists.txt | 2 +- src/error.c | 1 - src/gss.c | 1 - src/hzeta.c | 1 - src/lbfgs.c | 1 - src/main.c | 1 - src/platform.c | 36 ------------------------ src/platform.h | 69 ---------------------------------------------- src/plfit.c | 1 - src/rbinom.c | 1 - src/sampling.c | 1 - 12 files changed, 5 insertions(+), 114 deletions(-) delete mode 100644 src/platform.c delete mode 100644 src/platform.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 162585b..a2b345d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,10 @@ project( ) enable_testing() +# Set C standard version +set(CMAKE_C_STANDARD 99) +set(CMAKE_C_STANDARD_REQUIRED True) + # Expose the BUILD_SHARED_LIBS option in the ccmake UI option(BUILD_SHARED_LIBS "Build shared libraries" OFF) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7a35942..f9a0b8d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,7 +8,7 @@ else() set(PKGCONFIG_LIBS_PRIVATE "-lm") endif() -set(PLFIT_CORE_SRCS error.c gss.c kolmogorov.c lbfgs.c mt.c platform.c plfit.c options.c rbinom.c sampling.c stats.c hzeta.c) +set(PLFIT_CORE_SRCS error.c gss.c kolmogorov.c lbfgs.c mt.c plfit.c options.c rbinom.c sampling.c stats.c hzeta.c) add_library(plfit ${PLFIT_CORE_SRCS}) target_include_directories(plfit PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/error.c b/src/error.c index ebb7159..238ab8f 100644 --- a/src/error.c +++ b/src/error.c @@ -20,7 +20,6 @@ #include #include #include "plfit_error.h" -#include "platform.h" static char *plfit_i_error_strings[] = { "No error", diff --git a/src/gss.c b/src/gss.c index 5c5ffbd..2d6eb21 100644 --- a/src/gss.c +++ b/src/gss.c @@ -22,7 +22,6 @@ #include #include "plfit_error.h" #include "gss.h" -#include "platform.h" /** * \def PHI diff --git a/src/hzeta.c b/src/hzeta.c index d8f9a6d..af099c0 100644 --- a/src/hzeta.c +++ b/src/hzeta.c @@ -50,7 +50,6 @@ #include #include "hzeta.h" #include "plfit_error.h" -#include "platform.h" /* because of NAN */ /* imported from gsl_machine.h */ diff --git a/src/lbfgs.c b/src/lbfgs.c index c4652da..8e71ff7 100644 --- a/src/lbfgs.c +++ b/src/lbfgs.c @@ -73,7 +73,6 @@ licence. #include #include "lbfgs.h" -#include "platform.h" #ifdef _MSC_VER #define inline __inline diff --git a/src/main.c b/src/main.c index 5e092dd..0aca272 100644 --- a/src/main.c +++ b/src/main.c @@ -25,7 +25,6 @@ #include #include #include "getopt.h" -#include "platform.h" #include "plfit.h" /* exit status code for incorrect input data as defined in sysexits.h (8.1) */ diff --git a/src/platform.c b/src/platform.c deleted file mode 100644 index 3787954..0000000 --- a/src/platform.c +++ /dev/null @@ -1,36 +0,0 @@ -/* platform.c - * - * Copyright (C) 2014 Tamas Nepusz - * - * 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 (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#include "platform.h" - -#ifdef _MSC_VER - -inline double _plfit_fmin(double a, double b) { - return (a < b) ? a : b; -} - -inline double _plfit_round(double x) { - return floor(x+0.5); -} - -#endif - -/* Dummy function to prevent a warning when compiling with Clang - the file - * would contain no symbols */ -void _plfit_i_unused(void) {} diff --git a/src/platform.h b/src/platform.h deleted file mode 100644 index 6512955..0000000 --- a/src/platform.h +++ /dev/null @@ -1,69 +0,0 @@ -/* platform.h - * - * Copyright (C) 2010-2011 Tamas Nepusz - * - * 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 (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -#ifndef __PLATFORM_H__ -#define __PLATFORM_H__ - -#undef __BEGIN_DECLS -#undef __END_DECLS -#ifdef __cplusplus -# define __BEGIN_DECLS extern "C" { -# define __END_DECLS } -#else -# define __BEGIN_DECLS /* empty */ -# define __END_DECLS /* empty */ -#endif - -#include - -__BEGIN_DECLS - -#ifdef _MSC_VER -#include - -#define snprintf _snprintf -#define inline __inline - -#ifndef isfinite -# define isfinite(x) _finite(x) -#endif - -extern double _plfit_fmin(double a, double b); -extern double _plfit_round(double x); - -#define fmin _plfit_fmin -#define round _plfit_round - -#endif /* _MSC_VER */ - -#ifndef isnan -# define isnan(x) ((x) != (x)) -#endif - -#ifndef INFINITY -# define INFINITY (1.0/0.0) -#endif - -#ifndef NAN -# define NAN ((double)0.0 / (double)DBL_MIN) -#endif - -__END_DECLS - -#endif /* __PLATFORM_H__ */ diff --git a/src/plfit.c b/src/plfit.c index 6eae747..27e788d 100644 --- a/src/plfit.c +++ b/src/plfit.c @@ -27,7 +27,6 @@ #include "plfit_error.h" #include "gss.h" #include "lbfgs.h" -#include "platform.h" #include "plfit.h" #include "kolmogorov.h" #include "plfit_sampling.h" diff --git a/src/rbinom.c b/src/rbinom.c index 354398d..6d7dbe9 100644 --- a/src/rbinom.c +++ b/src/rbinom.c @@ -44,7 +44,6 @@ #include #include #include "plfit_sampling.h" -#include "platform.h" #define repeat for(;;) diff --git a/src/sampling.c b/src/sampling.c index 1104494..a817f83 100644 --- a/src/sampling.c +++ b/src/sampling.c @@ -22,7 +22,6 @@ #include "plfit_error.h" #include "plfit_sampling.h" -#include "platform.h" inline double plfit_runif(double lo, double hi, plfit_mt_rng_t* rng) { if (rng == 0) { From f60e8d81019c017195233490de1de9acd8e9c69b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Horva=CC=81t?= Date: Sat, 16 Nov 2024 11:00:46 +0000 Subject: [PATCH 2/4] refactor: remove no-longer-needed MSVC adaptations --- src/lbfgs.c | 8 -------- src/plfit_mt.h | 7 +------ 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/src/lbfgs.c b/src/lbfgs.c index 8e71ff7..3f67094 100644 --- a/src/lbfgs.c +++ b/src/lbfgs.c @@ -65,20 +65,12 @@ licence. #include "config.h" #endif/*HAVE_CONFIG_H*/ -#ifndef _MSC_VER #include -#endif - #include #include #include "lbfgs.h" -#ifdef _MSC_VER -#define inline __inline -typedef unsigned int uint32_t; -#endif/*_MSC_VER*/ - #if defined(USE_SSE) && defined(__SSE2__) && LBFGS_FLOAT == 64 /* Use SSE2 optimization for 64bit double precision. */ #include "arithmetic_sse_double.h" diff --git a/src/plfit_mt.h b/src/plfit_mt.h index c7ed0dc..b30cdaf 100644 --- a/src/plfit_mt.h +++ b/src/plfit_mt.h @@ -14,12 +14,7 @@ #ifndef __PLFIT_MT_H__ #define __PLFIT_MT_H__ -/* VS 2010, i.e. _MSC_VER == 1600, already has stdint.h */ -#if defined(_MSC_VER) && _MSC_VER < 1600 -# define uint32_t unsigned __int32 -#else -# include -#endif +#include #undef __BEGIN_DECLS #undef __END_DECLS From 1217064c39657e463d8ce9fa81fcc87d265afa58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Horva=CC=81t?= Date: Sat, 16 Nov 2024 12:56:41 +0000 Subject: [PATCH 3/4] fix: work around buggy NAN in some MSVC versions See https://github.com/igraph/igraph/issues/2701 --- src/hzeta.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/hzeta.c b/src/hzeta.c index af099c0..ea7b9d3 100644 --- a/src/hzeta.c +++ b/src/hzeta.c @@ -51,6 +51,18 @@ #include "hzeta.h" #include "plfit_error.h" +/* Work around bug in some Windows SDK / MSVC versions where NAN is not a + * constant expression, triggering an error in the definition of + * hsl_sf_hzeta_eulermaclaurin_series_coeffs[] and + * hsl_sf_hzeta_eulermaclaurin_series_majorantratios[] below. + * We re-define NAN to the value it had in earlier MSVC versions. + * See https://github.com/igraph/igraph/issues/2701 + */ +#ifdef _MSC_VER +#undef NAN +#define NAN (-(float)(((float)(1e+300 * 1e+300)) * 0.0F)) +#endif + /* imported from gsl_machine.h */ #define GSL_LOG_DBL_MIN (-7.0839641853226408e+02) From b05eec05999a78cf7e9878c48b9a56463d49fd4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Horva=CC=81t?= Date: Sat, 16 Nov 2024 13:03:50 +0000 Subject: [PATCH 4/4] chore: update changelog --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0932cde..b4e9b14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # plfit library changelog +### Changed + +* plfit now requires a compiler that supports the C99 standard. + +### Fixed + +* Worked around a broken (non-constant) `NAN` macro with recent Windows 11 SDK / MSVC versions. + ## [0.9.6] ### Added