From 1b209e13ef9cc99eb49e3ead9ab86cb72ab13514 Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Sun, 27 Apr 2025 22:09:08 +1000 Subject: [PATCH 1/5] Add extra CPPFLAGS needed when testing R headers --- configure | 25 +++++++++++++++++++++++-- configure.ac | 17 ++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/configure b/configure index 96dfc2e0..84e8f8b8 100755 --- a/configure +++ b/configure @@ -3908,7 +3908,22 @@ printf "%s\n" "$as_me: Operating system is $platform" >&6;} # Test R features # #-------------------------------------------------------------------------------# -ac_fn_check_decl "$LINENO" "R_getVarEx" "ac_cv_have_decl_R_getVarEx" "#include +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: Checking R API features" >&5 +printf "%s\n" "$as_me: Checking R API features" >&6;} + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking CPPFLAGS for compiling R headers" >&5 +printf %s "checking CPPFLAGS for compiling R headers... " >&6; } +R_H_CPPFLAGS=`"${R_HOME}/bin/R" CMD config --cppflags` +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${R_H_CPPFLAGS}" >&5 +printf "%s\n" "${R_H_CPPFLAGS}" >&6; } + +SAVE_CPPFLAGS="$CPPFLAGS" +CPPFLAGS="${R_H_CPPFLAGS} $CPPFLAGS" + +ac_fn_check_decl "$LINENO" "R_getVarEx" "ac_cv_have_decl_R_getVarEx" " +#include +#include + " "$ac_c_undeclared_builtin_options" "CFLAGS" if test "x$ac_cv_have_decl_R_getVarEx" = xyes then : @@ -3918,7 +3933,10 @@ else case e in #( esac fi printf "%s\n" "#define HAVE_DECL_R_GETVAREX $ac_have_decl" >>confdefs.h -ac_fn_check_decl "$LINENO" "R_NewEnv" "ac_cv_have_decl_R_NewEnv" "#include +ac_fn_check_decl "$LINENO" "R_NewEnv" "ac_cv_have_decl_R_NewEnv" " +#include +#include + " "$ac_c_undeclared_builtin_options" "CFLAGS" if test "x$ac_cv_have_decl_R_NewEnv" = xyes then : @@ -3930,6 +3948,9 @@ fi printf "%s\n" "#define HAVE_DECL_R_NEWENV $ac_have_decl" >>confdefs.h +CPPFLAGS="${SAVE_CPPFLAGS}" + + #-------------------------------------------------------------------------------# # Prepend compiler/linker variables from nc-config (if enabled) # #-------------------------------------------------------------------------------# diff --git a/configure.ac b/configure.ac index 27d01bb1..33841e4f 100644 --- a/configure.ac +++ b/configure.ac @@ -109,7 +109,22 @@ AC_MSG_NOTICE([Operating system is $platform]) # Test R features # #-------------------------------------------------------------------------------# -AC_CHECK_DECLS([R_getVarEx, R_NewEnv], [], [], [#include ]) +AC_MSG_NOTICE([Checking R API features]) + +AC_MSG_CHECKING([CPPFLAGS for compiling R headers]) +R_H_CPPFLAGS=`"${R_HOME}/bin/R" CMD config --cppflags` +AC_MSG_RESULT([${R_H_CPPFLAGS}]) + +SAVE_CPPFLAGS="$CPPFLAGS" +CPPFLAGS="${R_H_CPPFLAGS} $CPPFLAGS" + +AC_CHECK_DECLS([R_getVarEx, R_NewEnv], [], [], [ +#include +#include +]) + +CPPFLAGS="${SAVE_CPPFLAGS}" + #-------------------------------------------------------------------------------# # Prepend compiler/linker variables from nc-config (if enabled) # From 2768dff58c99e71f3947e1b8f86588ab7b6dacf1 Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Sun, 27 Apr 2025 22:51:25 +1000 Subject: [PATCH 2/5] Use R version to select API features --- src/convert.c | 10 +++++++--- tools/convert.m4 | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/convert.c b/src/convert.c index 40b237ef..c601815d 100644 --- a/src/convert.c +++ b/src/convert.c @@ -48,6 +48,7 @@ #include #include +#include #include @@ -6884,7 +6885,10 @@ R_nc_char_symbol (char *in, size_t size, char *work) static void R_nc_enum_factor (R_nc_buf *io) { - SEXP levels, env, cmd, symbol, index; + SEXP levels, env, symbol, index; +#if !defined(R_VERSION) || R_VERSION < R_Version(4, 1, 0) + SEXP cmd; +#endif size_t size, nmem, ifac, nfac; char *memname, *memval, *work, *inval; int ncid, imem, imemmax, *out, any_undef; @@ -6903,7 +6907,7 @@ R_nc_enum_factor (R_nc_buf *io) /* Create a hashed environment for value-index pairs. Members inherit PROTECTion from the env. */ -#if defined(HAVE_DECL_R_NEWENV) && (HAVE_DECL_R_NEWENV == 1) +#if defined(R_VERSION) && R_VERSION >= R_Version(4, 1, 0) env = PROTECT(R_NewEnv(R_BaseEnv, TRUE, 0)); #else cmd = PROTECT(lang1 (install ("new.env"))); @@ -6948,7 +6952,7 @@ R_nc_enum_factor (R_nc_buf *io) any_undef = 0; for (ifac=0, inval=io->cbuf; ifac= R_Version(4, 5, 0) index = R_getVarEx(symbol, env, FALSE, R_UnboundValue); #else index = findVar (symbol, env); diff --git a/tools/convert.m4 b/tools/convert.m4 index 6195125d..e62371c5 100644 --- a/tools/convert.m4 +++ b/tools/convert.m4 @@ -49,6 +49,7 @@ dnl Insert warning into generated C code: #include #include +#include #include @@ -1300,7 +1301,10 @@ R_nc_char_symbol (char *in, size_t size, char *work) static void R_nc_enum_factor (R_nc_buf *io) { - SEXP levels, env, cmd, symbol, index; + SEXP levels, env, symbol, index; +#if !defined(R_VERSION) || R_VERSION < R_Version(4, 1, 0) + SEXP cmd; +#endif size_t size, nmem, ifac, nfac; char *memname, *memval, *work, *inval; int ncid, imem, imemmax, *out, any_undef; @@ -1319,7 +1323,7 @@ R_nc_enum_factor (R_nc_buf *io) /* Create a hashed environment for value-index pairs. Members inherit PROTECTion from the env. */ -#if defined(HAVE_DECL_R_NEWENV) && (HAVE_DECL_R_NEWENV == 1) +#if defined(R_VERSION) && R_VERSION >= R_Version(4, 1, 0) env = PROTECT(R_NewEnv(R_BaseEnv, TRUE, 0)); #else cmd = PROTECT(lang1 (install ("new.env"))); @@ -1364,7 +1368,7 @@ R_nc_enum_factor (R_nc_buf *io) any_undef = 0; for (ifac=0, inval=io->cbuf; ifac= R_Version(4, 5, 0) index = R_getVarEx(symbol, env, FALSE, R_UnboundValue); #else index = findVar (symbol, env); From c61b3b861ec6e1488da45d43bd68ab07d20778b4 Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Sun, 27 Apr 2025 22:52:16 +1000 Subject: [PATCH 3/5] Remove tests of API features from configure --- configure | 46 ---------------------------------------------- configure.ac | 20 -------------------- 2 files changed, 66 deletions(-) diff --git a/configure b/configure index 84e8f8b8..f7786bde 100755 --- a/configure +++ b/configure @@ -3904,52 +3904,6 @@ fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: Operating system is $platform" >&5 printf "%s\n" "$as_me: Operating system is $platform" >&6;} -#-------------------------------------------------------------------------------# -# Test R features # -#-------------------------------------------------------------------------------# - -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: Checking R API features" >&5 -printf "%s\n" "$as_me: Checking R API features" >&6;} - -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking CPPFLAGS for compiling R headers" >&5 -printf %s "checking CPPFLAGS for compiling R headers... " >&6; } -R_H_CPPFLAGS=`"${R_HOME}/bin/R" CMD config --cppflags` -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: ${R_H_CPPFLAGS}" >&5 -printf "%s\n" "${R_H_CPPFLAGS}" >&6; } - -SAVE_CPPFLAGS="$CPPFLAGS" -CPPFLAGS="${R_H_CPPFLAGS} $CPPFLAGS" - -ac_fn_check_decl "$LINENO" "R_getVarEx" "ac_cv_have_decl_R_getVarEx" " -#include -#include - -" "$ac_c_undeclared_builtin_options" "CFLAGS" -if test "x$ac_cv_have_decl_R_getVarEx" = xyes -then : - ac_have_decl=1 -else case e in #( - e) ac_have_decl=0 ;; -esac -fi -printf "%s\n" "#define HAVE_DECL_R_GETVAREX $ac_have_decl" >>confdefs.h -ac_fn_check_decl "$LINENO" "R_NewEnv" "ac_cv_have_decl_R_NewEnv" " -#include -#include - -" "$ac_c_undeclared_builtin_options" "CFLAGS" -if test "x$ac_cv_have_decl_R_NewEnv" = xyes -then : - ac_have_decl=1 -else case e in #( - e) ac_have_decl=0 ;; -esac -fi -printf "%s\n" "#define HAVE_DECL_R_NEWENV $ac_have_decl" >>confdefs.h - - -CPPFLAGS="${SAVE_CPPFLAGS}" - #-------------------------------------------------------------------------------# # Prepend compiler/linker variables from nc-config (if enabled) # diff --git a/configure.ac b/configure.ac index 33841e4f..45e0ec1f 100644 --- a/configure.ac +++ b/configure.ac @@ -105,26 +105,6 @@ AC_CHECK_DECLS([_WIN32], [platform=Unix-alike])]) AC_MSG_NOTICE([Operating system is $platform]) -#-------------------------------------------------------------------------------# -# Test R features # -#-------------------------------------------------------------------------------# - -AC_MSG_NOTICE([Checking R API features]) - -AC_MSG_CHECKING([CPPFLAGS for compiling R headers]) -R_H_CPPFLAGS=`"${R_HOME}/bin/R" CMD config --cppflags` -AC_MSG_RESULT([${R_H_CPPFLAGS}]) - -SAVE_CPPFLAGS="$CPPFLAGS" -CPPFLAGS="${R_H_CPPFLAGS} $CPPFLAGS" - -AC_CHECK_DECLS([R_getVarEx, R_NewEnv], [], [], [ -#include -#include -]) - -CPPFLAGS="${SAVE_CPPFLAGS}" - #-------------------------------------------------------------------------------# # Prepend compiler/linker variables from nc-config (if enabled) # From 8ffb1dad5fa9a4373d2dffec9b33a615e0901d20 Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Sun, 27 Apr 2025 22:52:58 +1000 Subject: [PATCH 4/5] Remove defs for API features from config.h.in --- src/config.h.in | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/config.h.in b/src/config.h.in index 1043629d..4b8f35cf 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -32,14 +32,6 @@ don't. */ #undef HAVE_DECL_NC_PERSIST -/* Define to 1 if you have the declaration of 'R_getVarEx', and to 0 if you - don't. */ -#undef HAVE_DECL_R_GETVAREX - -/* Define to 1 if you have the declaration of 'R_NewEnv', and to 0 if you - don't. */ -#undef HAVE_DECL_R_NEWENV - /* Define to 1 if you have the declaration of '_WIN32', and to 0 if you don't. */ #undef HAVE_DECL__WIN32 From 4915a7f8c4ef1b4bdb99a1c26b6f8223a9d2e9d8 Mon Sep 17 00:00:00 2001 From: Milton Woods Date: Sun, 27 Apr 2025 23:07:01 +1000 Subject: [PATCH 5/5] Fix mismatched UNPROTECT across R API versions --- src/convert.c | 4 ++++ tools/convert.m4 | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/convert.c b/src/convert.c index c601815d..1dbae5c3 100644 --- a/src/convert.c +++ b/src/convert.c @@ -6973,7 +6973,11 @@ R_nc_enum_factor (R_nc_buf *io) } /* Allow garbage collection of env and levels */ +#if defined(R_VERSION) && R_VERSION >= R_Version(4, 1, 0) + UNPROTECT(2); +#else UNPROTECT(3); +#endif } diff --git a/tools/convert.m4 b/tools/convert.m4 index e62371c5..7fb6bd4f 100644 --- a/tools/convert.m4 +++ b/tools/convert.m4 @@ -1389,7 +1389,11 @@ R_nc_enum_factor (R_nc_buf *io) } /* Allow garbage collection of env and levels */ +#if defined(R_VERSION) && R_VERSION >= R_Version(4, 1, 0) + UNPROTECT(2); +#else UNPROTECT(3); +#endif }