Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a919e0e0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "vkjson: correctly handle std::numeric_limits<float>::infinity()"

parents 4883dfe1 b1b0b011
Loading
Loading
Loading
Loading
+15 −5
Original line number Original line Diff line number Diff line
@@ -21,11 +21,14 @@
#include "vkjson.h"
#include "vkjson.h"


#include <assert.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>


#include <cmath>
#include <json/json.h>

#include <algorithm>
#include <cinttypes>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstdio>
#include <limits>
#include <limits>
#include <memory>
#include <memory>
@@ -33,8 +36,6 @@
#include <type_traits>
#include <type_traits>
#include <utility>
#include <utility>


#include <json/json.h>

namespace {
namespace {


inline bool IsIntegral(double value) {
inline bool IsIntegral(double value) {
@@ -46,6 +47,14 @@ inline bool IsIntegral(double value) {
#endif
#endif
}
}


// Floating point fields of Vulkan structure use single precision. The string
// output of max double value in c++ will be larger than Java double's infinity
// value. Below fake double max/min values are only to serve the safe json text
// parsing in between C++ and Java, becasue Java json library simply cannot
// handle infinity.
static const double SAFE_DOUBLE_MAX = 0.99 * std::numeric_limits<double>::max();
static const double SAFE_DOUBLE_MIN = 0.99 * std::numeric_limits<double>::min();

template <typename T> struct EnumTraits;
template <typename T> struct EnumTraits;
template <> struct EnumTraits<VkPhysicalDeviceType> {
template <> struct EnumTraits<VkPhysicalDeviceType> {
  static uint32_t min() { return VK_PHYSICAL_DEVICE_TYPE_BEGIN_RANGE; }
  static uint32_t min() { return VK_PHYSICAL_DEVICE_TYPE_BEGIN_RANGE; }
@@ -851,7 +860,8 @@ Json::Value ToJsonValue(const T& value);


template <typename T, typename = EnableForArithmetic<T>>
template <typename T, typename = EnableForArithmetic<T>>
inline Json::Value ToJsonValue(const T& value) {
inline Json::Value ToJsonValue(const T& value) {
  return Json::Value(static_cast<double>(value));
  return Json::Value(
      std::clamp(static_cast<double>(value), SAFE_DOUBLE_MIN, SAFE_DOUBLE_MAX));
}
}


inline Json::Value ToJsonValue(const uint64_t& value) {
inline Json::Value ToJsonValue(const uint64_t& value) {