Skip to content

Commit 65196bc

Browse files
Backport windows fixes with INFINITY/NAN (#19390)
* Fixed `NAN`/`INFINITY` definitions to work on Windows 11 SDK. * Regenerate stale files
1 parent c30f726 commit 65196bc

File tree

3 files changed

+87
-9
lines changed

3 files changed

+87
-9
lines changed

php/ext/google/protobuf/php-upb.c

+29-3
Original file line numberDiff line numberDiff line change
@@ -6256,9 +6256,35 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s,
62566256

62576257
// Must be last.
62586258

6259-
const float kUpb_FltInfinity = INFINITY;
6260-
const double kUpb_Infinity = INFINITY;
6261-
const double kUpb_NaN = NAN;
6259+
// The latest win32 SDKs have an invalid definition of NAN.
6260+
// https://developercommunity.visualstudio.com/t/NAN-is-no-longer-compile-time-constant-i/10688907
6261+
//
6262+
// Unfortunately, the `0.0 / 0.0` workaround doesn't work in Clang under C23, so
6263+
// try __builtin_nan first, if that exists.
6264+
#ifdef _WIN32
6265+
#ifdef __has_builtin
6266+
#if __has_builtin(__builtin_nan)
6267+
#define UPB_NAN __builtin_nan("0")
6268+
#endif
6269+
#if __has_builtin(__builtin_inf)
6270+
#define UPB_INFINITY __builtin_inf()
6271+
#endif
6272+
#endif
6273+
#ifndef UPB_NAN
6274+
#define UPB_NAN 0.0 / 0.0
6275+
#endif
6276+
#ifndef UPB_INFINITY
6277+
#define UPB_INFINITY 1.0 / 0.0
6278+
#endif
6279+
#else
6280+
// For !_WIN32, assume math.h works.
6281+
#define UPB_NAN NAN
6282+
#define UPB_INFINITY INFINITY
6283+
#endif
6284+
6285+
const float kUpb_FltInfinity = UPB_INFINITY;
6286+
const double kUpb_Infinity = UPB_INFINITY;
6287+
const double kUpb_NaN = UPB_NAN;
62626288

62636289
static const size_t overhead = sizeof(upb_Message_InternalData);
62646290

ruby/ext/google/protobuf_c/ruby-upb.c

+29-3
Original file line numberDiff line numberDiff line change
@@ -5771,9 +5771,35 @@ bool _upb_mapsorter_pushexts(_upb_mapsorter* s,
57715771

57725772
// Must be last.
57735773

5774-
const float kUpb_FltInfinity = INFINITY;
5775-
const double kUpb_Infinity = INFINITY;
5776-
const double kUpb_NaN = NAN;
5774+
// The latest win32 SDKs have an invalid definition of NAN.
5775+
// https://developercommunity.visualstudio.com/t/NAN-is-no-longer-compile-time-constant-i/10688907
5776+
//
5777+
// Unfortunately, the `0.0 / 0.0` workaround doesn't work in Clang under C23, so
5778+
// try __builtin_nan first, if that exists.
5779+
#ifdef _WIN32
5780+
#ifdef __has_builtin
5781+
#if __has_builtin(__builtin_nan)
5782+
#define UPB_NAN __builtin_nan("0")
5783+
#endif
5784+
#if __has_builtin(__builtin_inf)
5785+
#define UPB_INFINITY __builtin_inf()
5786+
#endif
5787+
#endif
5788+
#ifndef UPB_NAN
5789+
#define UPB_NAN 0.0 / 0.0
5790+
#endif
5791+
#ifndef UPB_INFINITY
5792+
#define UPB_INFINITY 1.0 / 0.0
5793+
#endif
5794+
#else
5795+
// For !_WIN32, assume math.h works.
5796+
#define UPB_NAN NAN
5797+
#define UPB_INFINITY INFINITY
5798+
#endif
5799+
5800+
const float kUpb_FltInfinity = UPB_INFINITY;
5801+
const double kUpb_Infinity = UPB_INFINITY;
5802+
const double kUpb_NaN = UPB_NAN;
57775803

57785804
static const size_t overhead = sizeof(upb_Message_InternalData);
57795805

upb/message/message.c

+29-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,35 @@
1515
// Must be last.
1616
#include "upb/port/def.inc"
1717

18-
const float kUpb_FltInfinity = INFINITY;
19-
const double kUpb_Infinity = INFINITY;
20-
const double kUpb_NaN = NAN;
18+
// The latest win32 SDKs have an invalid definition of NAN.
19+
// https://developercommunity.visualstudio.com/t/NAN-is-no-longer-compile-time-constant-i/10688907
20+
//
21+
// Unfortunately, the `0.0 / 0.0` workaround doesn't work in Clang under C23, so
22+
// try __builtin_nan first, if that exists.
23+
#ifdef _WIN32
24+
#ifdef __has_builtin
25+
#if __has_builtin(__builtin_nan)
26+
#define UPB_NAN __builtin_nan("0")
27+
#endif
28+
#if __has_builtin(__builtin_inf)
29+
#define UPB_INFINITY __builtin_inf()
30+
#endif
31+
#endif
32+
#ifndef UPB_NAN
33+
#define UPB_NAN 0.0 / 0.0
34+
#endif
35+
#ifndef UPB_INFINITY
36+
#define UPB_INFINITY 1.0 / 0.0
37+
#endif
38+
#else
39+
// For !_WIN32, assume math.h works.
40+
#define UPB_NAN NAN
41+
#define UPB_INFINITY INFINITY
42+
#endif
43+
44+
const float kUpb_FltInfinity = UPB_INFINITY;
45+
const double kUpb_Infinity = UPB_INFINITY;
46+
const double kUpb_NaN = UPB_NAN;
2147

2248
static const size_t overhead = sizeof(upb_Message_InternalData);
2349

0 commit comments

Comments
 (0)