diff libinterp/corefcn/jsonencode.cc @ 28751:699bba597610

Use specific configure test to detect RapidJSON PrettyWriter functionality (bug #59114) * configure.ac: Use an AC_COMPILE_IFELSE test to determine whether system has a working RapidJSON PrettyWriter implementation. Rename feature to HAVE_RAPIDJSON_PRETTYWRITER. Us AC_CACHE_CHECK to cache value since compilations are expensive. * jsonencode.cc: Rename HAVE_RAPIDJSON_DEV to HAVE_RAPIDJSON_PRETTYWRITER. Conditionally #include <rapidjson/prettywrite.h> based on HAVE_RAPIDJSON_PRETTYWRITER.
author Rik <rik@octave.org>
date Thu, 17 Sep 2020 07:42:22 -0700
parents 80857685105b
children e82484e1b2f6
line wrap: on
line diff
--- a/libinterp/corefcn/jsonencode.cc	Thu Sep 17 05:07:02 2020 -0700
+++ b/libinterp/corefcn/jsonencode.cc	Thu Sep 17 07:42:22 2020 -0700
@@ -35,9 +35,11 @@
 #include "ovl.h"
 
 #if defined (HAVE_RAPIDJSON)
-#  include <rapidjson/prettywriter.h>
 #  include <rapidjson/stringbuffer.h>
 #  include <rapidjson/writer.h>
+#  if defined (HAVE_RAPIDJSON_PRETTYWRITER)
+#    include <rapidjson/prettywriter.h>
+#  endif
 #endif
 
 #if defined (HAVE_RAPIDJSON)
@@ -593,11 +595,7 @@
                R"(Valid options are "ConvertInfAndNaN" and "PrettyWriter")");
     }
 
-  // FIXME: RapidJSON 1.1.0 (2016-08-25) is the latest release (2020-08-18)
-  //        and does not support the "PrettyWriter" option.  Once a newer
-  //        RapidJSON version is released and established with major
-  //        distributions, make that version a requirement.
-# if ! defined (HAVE_RAPIDJSON_DEV)
+# if ! defined (HAVE_RAPIDJSON_PRETTYWRITER)
   if (PrettyWriter)
     {
       warn_disabled_feature ("jsonencode",
@@ -609,7 +607,7 @@
   rapidjson::StringBuffer json;
   if (PrettyWriter)
     {
-# if defined (HAVE_RAPIDJSON_DEV)
+# if defined (HAVE_RAPIDJSON_PRETTYWRITER)
       rapidjson::PrettyWriter<rapidjson::StringBuffer, rapidjson::UTF8<>,
                               rapidjson::UTF8<>, rapidjson::CrtAllocator,
                               rapidjson::kWriteNanAndInfFlag> writer (json);
@@ -650,7 +648,7 @@
 %! fail ("jsonencode (1, 'string', ones (2,2))", "option value must be a logical scalar");
 %! fail ("jsonencode (1, 'foobar', true)", 'Valid options are "ConvertInfAndNaN"');
 
-%!testif HAVE_RAPIDJSON; ! __have_feature__ ("HAVE_RAPIDJSON_DEV")
+%!testif HAVE_RAPIDJSON; ! __have_feature__ ("RAPIDJSON_PRETTYWRITER")
 %! fail ("jsonencode (1, 'PrettyWriter', true)", ...
 %!       "warning", 'the "PrettyWriter" option of RapidJSON was unavailable');