recmap icon indicating copy to clipboard operation
recmap copied to clipboard

STRICT_R_HEADERS via Rcpp

Open cpanse opened this issue 5 years ago • 0 comments

Moving towards STRICT_R_HEADERS by default

Summary

tl;dr: STRICT_R_HEADERS are a worthwhile change, and we want to make that change in one year. If your package is affected, you should get another email and we ask that you make the change within 12 months.

More details below.

What is this about?

Recently Romain opened ticket #898 on Github about possibly adding the define for STRICT_R_HEADERS by default. Please see the URL at https://github.com/RcppCore/Rcpp/issues/898 for more discussion. In general, we are all in favour but there are some side effects. Hence this email.

Background

What does the change do? As a brief summary, this only hits two R include files and, if set, omits the definitions from two header files in R_ext/, namely RS.h and Constants.h. The definitions are (indented by two spaces)

#ifndef STRICT_R_HEADERS

#define R_PROBLEM_BUFSIZE 4096 /* Parentheses added for FC4 with gcc4 and -D_FORTIFY_SOURCE=2 */ #define PROBLEM {char R_problem_buf[R_PROBLEM_BUFSIZE];(sprintf)(R_problem_buf, #define MESSAGE {char R_problem_buf[R_PROBLEM_BUFSIZE];(sprintf)(R_problem_buf, #define ERROR ),error(R_problem_buf);} #define RECOVER(x) ),error(R_problem_buf);} #define WARNING(x) ),warning(R_problem_buf);} #define LOCAL_EVALUATOR // #define NULL_ENTRY // #define WARN WARNING(NULL)

#endif

and

#ifndef STRICT_R_HEADERS /* S-PLUS 3.x but not 5.x NULLs the pointer in the following */ #define Calloc(n, t) (t *) R_chk_calloc( (R_SIZE_T) (n), sizeof(t) ) #define Realloc(p,n,t) (t *) R_chk_realloc( (void *)(p), (R_SIZE_T)((n) * sizeof(t)) ) #define Free(p) (R_chk_free( (void *)(p) ), (p) = NULL) #endif

and

#ifndef STRICT_R_HEADERS #define PI M_PI #include <float.h> /* Defines the rest, at least in C99 */ #define SINGLE_EPS FLT_EPSILON #define SINGLE_BASE FLT_RADIX #define SINGLE_XMIN FLT_MIN #define SINGLE_XMAX FLT_MAX #define DOUBLE_DIGITS DBL_MANT_DIG #define DOUBLE_EPS DBL_EPSILON #define DOUBLE_XMAX DBL_MAX #define DOUBLE_XMIN DBL_MIN #endif

The second sets is easiest. Just replace Calloc / Realloc / Free (if you really need it!) with R_Calloc / R_Realloc / R_Free. The third is easy too: instead of PI use M_PI and so on. The first set is problematic and where I have most often seen clashes (requiring change in include order, or #undef ERROR, or, ...). But R itself has Rf_error, Rf_warning, ... And Rcpp itself has Rcpp::stop() and Rcpp::warning() and more.

What is the effect?

We ran full reverse depends check last weekend and found 62 packages failed to compiled (but almost 1300 passes, 62 were skipped for various reasons).

The failing packages are list at the #898 issue ticket and below.

What changes are needed?

The really good news is that the changes should be trivial:

  • replace PI with M_PI
  • replace DBL_EPSILON with DOUBLE_EPS
  • replace Calloc with R_Calloc

and so on.

If you really cannot / do not want to make the change, define #RCPP_NO_STRICT_HEADERS before #include <Rcpp.h> and things will be as before. Otherwise we plan to make this a new default in twelve months.

How can you test things?

In your package, please just add the line #define STRICT_R_HEADERS before including Rcpp.h, ie use (ignore the twp space indent)

#define STRICT_R_HEADERS #include <Rcpp.h>

or, even simpler, set -DSTRICT_R_HEADERS in eg CXXFLAGS in ~/.R/Makevars.

How can you override things?

Define RCPP_NO_STRICT_R_HEADERS and things will remain as they are.

You can do that locally in you compiler-flags for now, and in your package in either its compiler flags (ie src/Makevars and src/Makevars.win) or your headers if you do not want to change your code to work with STRICT_R_HEADERS. However, we feel working with STRICT_R_HEADERS is an improvement so we suggest you set it now and work out the (likely few and simple) compilation errors.

Details logs

Below is a collated grep run finding the first (and hence NOT EXHAUSTIVE) failure per package.

** CorReg : BicLoc_cpp.cpp:70:53: error: ‘PI’ was not declared in this scope

** CoxPlus : coxReg.cpp:333:84: error: ‘DBL_MAX’ was not declared in this scope coxReg.cpp:415:16: error: ‘DBL_MAX’ was not declared in this scope coxReg.cpp:426:16: error: ‘DBL_MAX’ was not declared in this scope coxReg.cpp:943:16: error: ‘DBL_MAX’ was not declared in this scope

** DGM : dlmlpl.cpp:106:64: error: ‘PI’ was not declared in this scope

** EMVS : functions.cpp:20:30: error: ‘PI’ was not declared in this scope functions.cpp:27:37: error: ‘PI’ was not declared in this scope functions.cpp:142:23: error: ‘PI’ was not declared in this scope

** ETAS : fitMP.cpp:2107:28: error: ‘DBL_MAX’ was not declared in this scope

** GAS : snorm.cpp:14:45: error: ‘PI’ was not declared in this scope snorm.cpp:26:23: error: ‘PI’ was not declared in this scope snorm.cpp:37:28: error: ‘PI’ was not declared in this scope snorm.cpp:52:26: error: ‘PI’ was not declared in this scope snorm.cpp:64:26: error: ‘PI’ was not declared in this scope snorm.cpp:146:28: error: ‘PI’ was not declared in this scope

** Gmisc : Gmisc_lines.cpp:107:20: error: ‘FLT_EPSILON’ was not declared in this scope

** HardyWeinberg : SNPHWEX.cpp:84:21: error: ‘DBL_MAX’ was not declared in this scope SNPHWEX.cpp:130:21: error: ‘DBL_MAX’ was not declared in this scope SNPHWEX.cpp:360:21: error: ‘DBL_MAX’ was not declared in this scope SNPHWEX.cpp:421:21: error: ‘DBL_MAX’ was not declared in this scope SNPHWEX.cpp:587:21: error: ‘DBL_MAX’ was not declared in this scope

** MAINT.Data : msnCP_dev.h:8:26: error: ‘PI’ was not declared in this scope msnCP_dev.cpp:8:29: error: ‘PI’ was not declared in this scope msnCP_dev.cpp:41:36: error: ‘PI’ was not declared in this scope msnCP_dev_grad.cpp:7:26: error: ‘PI’ was not declared in this scope

** MSGARCH : Utils.h:8:28: error: ‘DBL_MIN’ was not declared in this scope

** MultiFit : singleFisher.cpp:25:19: error: ‘DBL_MIN’ was not declared in this scope singleFisher.cpp:30:37: error: ‘DBL_MIN’ was not declared in this scope

** PAFit : Cpp_code.cpp:751:41: error: ‘DBL_EPSILON’ was not declared in this scope Cpp_code.cpp:969:17: error: ‘LDBL_EPSILON’ was not declared in this scope

** ReIns : SpliceEM_Mstep.cpp:192:13: error: ‘DBL_MAX’ was not declared in this scope SpliceEM_Mstep.cpp:200:17: error: ‘DBL_MAX’ was not declared in this scope SpliceEM_Mstep.cpp:270:11: error: ‘DBL_MAX’ was not declared in this scope SpliceEM_Mstep.cpp:278:15: error: ‘DBL_MAX’ was not declared in this scope

** basad : utiliti.cpp:36:17: error: ‘PI’ was not declared in this scope

** bayesImageS : smcPotts.cpp:343:17: error: ‘DBL_EPSILON’ was not declared in this scope

** bcp : MCMC.h:119:16: error: ‘DBL_MAX’ was not declared in this scope MCMC.h:135:16: error: ‘DBL_MAX’ was not declared in this scope Cbcp.cpp:134:15: error: ‘DBL_MAX’ was not declared in this scope

** bfa : bfa_common.cpp:25:15: error: ‘DBL_MAX’ was not declared in this scope

** bigReg : map_reg.cpp:53:16: error: ‘DBL_EPSILON’ was not declared in this scope

** biglasso : binomial_hsr.cpp:6:9: error: ‘Free’ was not declared in this scope binomial_hsr.cpp:162:31: error: ‘Calloc’ was not declared in this scope

** bigmemory : ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:35:20: error: ‘FLT_MAX’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:35:20: error: ‘FLT_MAX’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:35:20: error: ‘FLT_MAX’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:35:20: error: ‘FLT_MAX’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:35:20: error: ‘FLT_MAX’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:35:20: error: ‘FLT_MAX’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:35:20: error: ‘FLT_MAX’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:35:20: error: ‘FLT_MAX’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:35:20: error: ‘FLT_MAX’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:35:20: error: ‘FLT_MAX’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:35:20: error: ‘FLT_MAX’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:35:20: error: ‘FLT_MAX’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:35:20: error: ‘FLT_MAX’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:35:20: error: ‘FLT_MAX’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:35:20: error: ‘FLT_MAX’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:34:18: error: ‘FLT_MIN’ was not declared in this scope ../inst/include/bigmemory/bigmemoryDefines.h:35:20: error: ‘FLT_MAX’ was not declared in this scope

** binnednp : gaussian_mise_201708_trsf.cpp:40:46: error: ‘PI’ was not declared in this scope

** biwavelet : rcpp_wt_bases_morlet.cpp:4:28: error: ‘PI’ was not declared in this scope

** blockmodels : models/gaussian.h:292:71: error: ‘PI’ was not declared in this scope models/gaussian.h:366:67: error: ‘PI’ was not declared in this scope models/gaussian_multivariate.h:302:93: error: ‘PI’ was not declared in this scope models/gaussian_multivariate.h:390:91: error: ‘PI’ was not declared in this scope models/gaussian_multivariate_independent.h:300:79: error: ‘PI’ was not declared in this scope models/gaussian_multivariate_independent.h:381:79: error: ‘PI’ was not declared in this scope models/gaussian_multivariate_independent_homoscedastic.h:293:88: error: ‘PI’ was not declared in this scope models/gaussian_multivariate_independent_homoscedastic.h:373:86: error: ‘PI’ was not declared in this scope models/gaussian_covariates.h:383:71: error: ‘PI’ was not declared in this scope models/gaussian_covariates.h:431:71: error: ‘PI’ was not declared in this scope models/gaussian_covariates.h:478:69: error: ‘PI’ was not declared in this scope

** castor : phylogenetics_cpp_routines.cpp:1559:67: error: ‘PI’ was not declared in this scope

** cbinom : cbinom.cpp:5:20: error: ‘DBL_EPSILON’ was not declared in this scope

** circumplex : circular.cpp:18:11: error: ‘DBL_EPSILON’ was not declared in this scope circular.cpp:31:20: error: ‘PI’ was not declared in this scope circular.cpp:34:12: error: ‘PI’ was not declared in this scope circular.cpp:43:20: error: ‘PI’ was not declared in this scope circular.cpp:48:37: error: ‘DBL_EPSILON’ was not declared in this scope circular.cpp:66:21: error: ‘PI’ was not declared in this scope

** emIRT : calcLB.cpp:86:46: error: ‘PI’ was not declared in this scope

** extraDistr : wald-distribution.cpp:40:27: error: ‘PI’ was not declared in this scope

** fDMA : tvpcpp.cpp:31:54: error: ‘PI’ was not declared in this scope

** facilitation : Random.cpp:29:25: error: ‘PI’ was not declared in this scope

** fastGHQuad : lib.cpp:331:49: error: ‘PI’ was not declared in this scope lib.cpp:358:21: error: ‘PI’ was not declared in this scope

** fasteraster : raster2vector.cpp:25:17: error: ‘DBL_MAX’ was not declared in this scope raster2vector.cpp:25:17: error: ‘DBL_MAX’ was not declared in this scope raster2vector.cpp:350:17: error: ‘PI’ was not declared in this scope raster2vector.cpp:352:17: error: ‘PI’ was not declared in this scope raster2vector.cpp:25:17: error: ‘DBL_MAX’ was not declared in this scope raster2vector.cpp:25:17: error: ‘DBL_MAX’ was not declared in this scope

** frailtySurv : distributions.cpp:217:38: error: ‘PI’ was not declared in this scope distributions.cpp:225:35: error: ‘PI’ was not declared in this scope distributions.cpp:234:61: error: ‘PI’ was not declared in this scope distributions.cpp:335:25: error: ‘PI’ was not declared in this scope distributions.cpp:342:35: error: ‘PI’ was not declared in this scope distributions.cpp:354:11: error: ‘PI’ was not declared in this scope distributions.cpp:459:24: error: ‘PI’ was not declared in this scope

** gcKrig : gcgcFun.cpp:34:14: error: ‘DOUBLE_EPS’ was not declared in this scope gcgcFun.cpp:40:47: error: ‘EPS1’ was not declared in this scope gcgcFun.cpp:85:14: error: ‘DOUBLE_EPS’ was not declared in this scope gcgcFun.cpp:100:45: error: ‘EPS1’ was not declared in this scope gcgcFun.cpp:163:56: error: ‘EPS1’ was not declared in this scope

** geogrid : minimal-assignment.cpp:407:21: error: ‘DBL_MAX’ was not declared in this scope

** glmBfp : ./types.h:53:32: error: ‘DOUBLE_EPS’ was not declared in this scope ./functionWraps.h:176:17: error: ‘DBL_MAX’ was not declared in this scope

** icenReg : icenReg_files/basicUtilities.cpp:149:37: error: ‘PI’ was not declared in this scope

** lidR : C_grid_canopy.cpp:58:31: error: ‘PI’ was not declared in this scope

** lpme : lpme_common.cpp:45:30: error: ‘PI’ was not declared in this scope lpme_common.cpp:111:51: error: ‘PI’ was not declared in this scope lpme_common.cpp:150:51: error: ‘PI’ was not declared in this scope

** mcmcse : msvec.cpp:16:21: error: ‘PI’ was not declared in this scope

** medfate : PenmanMonteith.cpp:21:41: error: ‘PI’ was not declared in this scope

** meteoland : radiation.cpp:56:40: error: ‘PI’ was not declared in this scope radiation.cpp:76:19: error: ‘PI’ was not declared in this scope radiation.cpp:98:46: error: ‘PI’ was not declared in this scope radiation.cpp:136:19: error: ‘PI’ was not declared in this scope radiation.cpp:187:40: error: ‘PI’ was not declared in this scope radiation.cpp:228:40: error: ‘PI’ was not declared in this scope radiation.cpp:291:63: error: ‘PI’ was not declared in this scope radiation.cpp:344:16: error: ‘PI’ was not declared in this scope

** minimaxdesign : kmeanspso.cpp:89:23: error: ‘DBL_MAX’ was not declared in this scope kmeanspso.cpp:267:24: error: ‘DBL_MAX’ was not declared in this scope

** multdyn : dlmlpl.cpp:106:64: error: ‘PI’ was not declared in this scope

** mwaved : mwaved.cpp:2736:49: error: ‘DBL_EPSILON’ was not declared in this scope

** netdiffuseR : plot.cpp:403:90: error: ‘PI’ was not declared in this scope plot.cpp:481:20: error: ‘PI’ was not declared in this scope

** nngeo : distance.cpp:15:22: error: ‘PI’ was not declared in this scope

** npsf : nllpk/simplexMethod.cpp:260:21: error: ‘DBL_MAX’ was not declared in this scope nllpk/simplexMethod.cpp:564:18: error: ‘DBL_MAX’ was not declared in this scope

** packcircles : pmenzel_circle_pack.cpp:182:28: error: ‘FLT_MAX’ was not declared in this scope

** partialCI : cfit.cc:179:41: error: ‘PI’ was not declared in this scope cfit.cc:211:66: error: ‘PI’ was not declared in this scope

** pense : InitialEstimator.cpp:185:21: error: ‘DBL_MAX’ was not declared in this scope

** precrec : calc_uauc.cpp:26:14: error: ‘DBL_MIN’ was not declared in this scope calc_uauc.cpp:28:14: error: ‘DBL_MAX’ was not declared in this scope

** recmap : ../inst/include/recmap.h:114:35: error: ‘PI’ was not declared in this scope ../inst/include/recmap.h:126:35: error: ‘PI’ was not declared in this scope ../inst/include/recmap.h:138:43: error: ‘PI’ was not declared in this scope ../inst/include/recmap.h:150:39: error: ‘PI’ was not declared in this scope ../inst/include/recmap.h:384:38: error: ‘PI’ was not declared in this scope

** rmgarch : ica.cpp:38:45: error: ‘PI’ was not declared in this scope

** robustlmm : fastGHQuad.cpp:356:49: error: ‘PI’ was not declared in this scope fastGHQuad.cpp:383:21: error: ‘PI’ was not declared in this scope

** rococo : rcor_exacttest.cpp:142:29: error: ‘DBL_EPSILON’ was not declared in this scope

** rotations : CppBayesFunctions.cpp:37:28: error: ‘PI’ was not declared in this scope CppBayesFunctions.cpp:52:30: error: ‘PI’ was not declared in this scope CppBayesFunctions.cpp:76:33: error: ‘PI’ was not declared in this scope CppBayesFunctions.cpp:110:17: error: ‘PI’ was not declared in this scope CppBayesFunctions.cpp:129:30: error: ‘PI’ was not declared in this scope CppBayesFunctions.cpp:153:33: error: ‘PI’ was not declared in this scope CppBayesFunctions.cpp:199:15: error: ‘PI’ was not declared in this scope CppBayesFunctions.cpp:360:26: error: ‘PI’ was not declared in this scope

** rtdists : CDF_st0_variability.h:126:20: error: ‘DBL_MAX’ was not declared in this scope

** serrsBayes : mixVoigt.cpp:34:18: error: ‘PI’ was not declared in this scope mixVoigt.cpp:44:25: error: ‘PI’ was not declared in this scope mixVoigt.cpp:73:85: error: ‘PI’ was not declared in this scope mixVoigt.cpp:99:50: error: ‘PI’ was not declared in this scope mixVoigt.cpp:136:165: error: ‘PI’ was not declared in this scope mixVoigt.cpp:252:37: error: ‘PI’ was not declared in this scope

** unmarked : nll_distsamp.cpp:25:22: error: ‘DOUBLE_XMIN’ was not declared in this scope

** updog : betabinom.cpp:5:21: error: ‘DBL_EPSILON’ was not declared in this scope

** vegclust : trajectories.cpp:94:38: error: ‘PI’ was not declared in this scope

In case of question please discuss on the rcpp-devel list.

Thanks,

Dirk on behalf of the RcppCore team

cpanse avatar Sep 19 '18 14:09 cpanse