Skip to content

Commit acaece6

Browse files
mkruskal-googlehabermanprotobuf-github-bot
authored
Backport windows fixes with INFINITY/NAN (#19389)
* Fixed `NAN`/`INFINITY` definitions to work on Windows 11 SDK. Fixes: #17308, #17238 Confirmation that this addresses the issue: grpc/grpc#37210 (comment) PiperOrigin-RevId: 652541857 * Fix compilation in Clang C23 mode. In C23, `false` is now of type `bool`, not `int`. This turned a couple places where `false` was returned instead of `NULL` into errors. The workaround in upb for Windows's broken NAN macro causes an error in Clang under C23, `cannot compile this static initializer yet`, I believe because `0.0 / 0.0` is not valid in constant-evaluation. This seems like it's probably a legitimate result of C23 standardizing constexpr, although it _could_ be a clang bug. In any case, refine the workaround a bit, to avoid this problem. I've also reverted the kUpb_FltInfinity/kUpb_Infinity back to their former definitions, as INFINITY wasn't broken by the windows header, only NAN. PiperOrigin-RevId: 683152452 * Fix const INFINITY issue on MSVC. We previously hit this for NAN, but it appears the latest version of MSVC used in windows github runners has the same issue for INFINITY. The same strategy can be applied here. This will be backported to fix broken release branches. PiperOrigin-RevId: 699390594 * Regenerate stale files * Update GitHub Actions to use macOS-13 ahead of macOS-12 deprecation. See actions/runner-images#10721. PiperOrigin-RevId: 684546079 * Pin to python 3.12 in upb/macos tests. Python 3.13 seems to have some issues with our dependencies and both numpy and setuptools fails to install. PiperOrigin-RevId: 689955916 * Fix bad cherry-pick --------- Co-authored-by: Joshua Haberman <[email protected]> Co-authored-by: Protobuf Team Bot <[email protected]>
1 parent 10a8f64 commit acaece6

File tree

12 files changed

+115
-36
lines changed

12 files changed

+115
-36
lines changed

.github/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This information is extracted from the MacOS runner specs located at:
2-
# https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md
2+
# https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md
33
#
44
# When updating, also ensure the "xcode_destination" entries in
55
# `.github/workflows/test_objectivec.yml` are supported for the given versions

.github/workflows/test_cpp.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,17 @@ jobs:
321321
matrix:
322322
include:
323323
- name: MacOS Bazel
324-
os: macos-12
325-
cache_key: macos-12
324+
os: macos-13
325+
cache_key: macos-13
326326
bazel: test //src/... //third_party/utf8_range/...
327327
- name: MacOS Bazel 7
328-
os: macos-12
329-
cache_key: macos-12-bazel7
328+
os: macos-13
329+
cache_key: macos-13-bazel7
330330
bazel: test //src/... //third_party/utf8_range/...
331331
bazel_version: '7.1.2'
332332
- name: MacOS Apple Silicon (build only) Bazel
333-
os: macos-12
334-
cache_key: macos-12-arm
333+
os: macos-13
334+
cache_key: macos-13-arm
335335
# Current github runners are all Intel based, so just build/compile
336336
# for Apple Silicon to detect issues there.
337337
bazel: build --cpu=darwin_arm64 //src/... //third_party/utf8_range/...
@@ -366,7 +366,7 @@ jobs:
366366
include:
367367
# TODO: investigate and fix
368368
# - name: MacOS CMake
369-
# os: macos-12
369+
# os: macos-13
370370
# flags: -DCMAKE_CXX_STANDARD=14
371371
# cache-prefix: macos-cmake
372372
- name: Windows CMake

.github/workflows/test_objectivec.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ jobs:
2525
destination: "platform=macOS"
2626
xc_project: "ProtocolBuffers_OSX.xcodeproj"
2727
- platform: "iOS"
28-
destination: "platform=iOS Simulator,name=iPhone 13,OS=latest"
28+
destination: "platform=iOS Simulator,name=iPhone 14,OS=latest"
2929
xc_project: "ProtocolBuffers_iOS.xcodeproj"
3030

3131
name: Xcode ${{ matrix.platform}} ${{ matrix.xc_config }}
32-
runs-on: macos-12
32+
runs-on: macos-13
3333
env:
3434
DEVELOPER_DIR: /Applications/Xcode_14.1.app/Contents/Developer
3535
steps:
@@ -72,7 +72,7 @@ jobs:
7272
PLATFORM: ["ios", "macos", "tvos", "watchos"]
7373
CONFIGURATION: ["Debug", "Release"]
7474
include:
75-
- OS: macos-12
75+
- OS: macos-13
7676
XCODE: "14.1"
7777
name: CocoaPods ${{ matrix.PLATFORM }} ${{ matrix.CONFIGURATION }}
7878
runs-on: ${{ matrix.OS }}
@@ -120,7 +120,7 @@ jobs:
120120
- platform: "macOS"
121121
bazel_targets: //objectivec/...
122122
name: Bazel ${{ matrix.platform }} ${{ matrix.config.name }}
123-
runs-on: macos-12
123+
runs-on: macos-13
124124
steps:
125125
- name: Checkout pending changes
126126
uses: protocolbuffers/protobuf-ci/checkout@v3

.github/workflows/test_php.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ jobs:
158158
version: ['8.2', '8.3']
159159

160160
name: MacOS PHP ${{ matrix.version }}
161-
runs-on: macos-12
161+
runs-on: macos-13
162162
steps:
163163
- name: Checkout pending changes
164164
uses: protocolbuffers/protobuf-ci/checkout@v3

.github/workflows/test_python.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
flags: --define=use_fast_cpp_protos=true
6666

6767
name: MacOS ${{ matrix.type }} ${{ matrix.version }}
68-
runs-on: macos-12
68+
runs-on: macos-13
6969
steps:
7070
- name: Checkout pending changes
7171
uses: protocolbuffers/protobuf-ci/checkout@v3

.github/workflows/test_ruby.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ jobs:
128128
- { version: "3.3", ffi: FFI }
129129

130130
name: MacOS Ruby ${{ matrix.version }}${{ matrix.ffi == 'FFI' && ' FFI' || '' }}
131-
runs-on: macos-12
131+
runs-on: macos-13
132132
steps:
133133
- name: Checkout pending changes
134134
uses: protocolbuffers/protobuf-ci/checkout@v3

.github/workflows/test_upb.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,15 @@ jobs:
9595
- { name: "macOS", bazel-command: "test" }
9696
- { name: "macOS ARM (build only)", bazel-command: "build", flags: "--cpu=darwin_arm64" }
9797
name: ${{ matrix.config.name }}
98-
runs-on: macos-12
98+
runs-on: macos-13
9999
steps:
100100
- name: Checkout pending changes
101101
uses: protocolbuffers/protobuf-ci/checkout@v3
102102
with:
103103
ref: ${{ inputs.safe-checkout }}
104104
- uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
105105
with:
106+
python-version: 3.12
106107
cache: pip
107108
cache-dependency-path: 'python/requirements.txt'
108109
- name: Run tests
@@ -175,11 +176,11 @@ jobs:
175176
# supported Python versions and assume this gives us sufficient test
176177
# coverage.
177178
- { os: ubuntu-latest, python-version: "3.8", architecture: x64, type: 'binary' }
178-
- { os: macos-12, python-version: "3.8", architecture: x64, type: 'binary' }
179+
- { os: macos-13, python-version: "3.8", architecture: x64, type: 'binary' }
179180
- { os: ubuntu-latest, python-version: "3.12", architecture: x64, type: 'binary' }
180181
- { os: macos-13, python-version: "3.12", architecture: x64, type: 'binary' }
181182
- { os: ubuntu-latest, python-version: "3.8", architecture: x64, type: 'source' }
182-
- { os: macos-12, python-version: "3.8", architecture: x64, type: 'source' }
183+
- { os: macos-13, python-version: "3.8", architecture: x64, type: 'source' }
183184
- { os: ubuntu-latest, python-version: "3.12", architecture: x64, type: 'source' }
184185
- { os: macos-13, python-version: "3.12", architecture: x64, type: 'source' }
185186

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

+30-4
Original file line numberDiff line numberDiff line change
@@ -6161,7 +6161,7 @@ upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type,
61616161
for (size_t i = 0; i < size; ++i) {
61626162
upb_MessageValue val = upb_Array_Get(array, i);
61636163
if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) {
6164-
return false;
6164+
return NULL;
61656165
}
61666166
upb_Array_Set(cloned_array, i, val);
61676167
}
@@ -12204,9 +12204,35 @@ upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)(
1220412204

1220512205
// Must be last.
1220612206

12207-
const float kUpb_FltInfinity = INFINITY;
12208-
const double kUpb_Infinity = INFINITY;
12209-
const double kUpb_NaN = NAN;
12207+
// The latest win32 SDKs have an invalid definition of NAN.
12208+
// https://developercommunity.visualstudio.com/t/NAN-is-no-longer-compile-time-constant-i/10688907
12209+
//
12210+
// Unfortunately, the `0.0 / 0.0` workaround doesn't work in Clang under C23, so
12211+
// try __builtin_nan first, if that exists.
12212+
#ifdef _WIN32
12213+
#ifdef __has_builtin
12214+
#if __has_builtin(__builtin_nan)
12215+
#define UPB_NAN __builtin_nan("0")
12216+
#endif
12217+
#if __has_builtin(__builtin_inf)
12218+
#define UPB_INFINITY __builtin_inf()
12219+
#endif
12220+
#endif
12221+
#ifndef UPB_NAN
12222+
#define UPB_NAN 0.0 / 0.0
12223+
#endif
12224+
#ifndef UPB_INFINITY
12225+
#define UPB_INFINITY 1.0 / 0.0
12226+
#endif
12227+
#else
12228+
// For !_WIN32, assume math.h works.
12229+
#define UPB_NAN NAN
12230+
#define UPB_INFINITY INFINITY
12231+
#endif
12232+
12233+
const float kUpb_FltInfinity = UPB_INFINITY;
12234+
const double kUpb_Infinity = UPB_INFINITY;
12235+
const double kUpb_NaN = UPB_NAN;
1221012236

1221112237
bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
1221212238
upb_Arena* a) {

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

+30-4
Original file line numberDiff line numberDiff line change
@@ -5649,7 +5649,7 @@ upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type,
56495649
for (size_t i = 0; i < size; ++i) {
56505650
upb_MessageValue val = upb_Array_Get(array, i);
56515651
if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) {
5652-
return false;
5652+
return NULL;
56535653
}
56545654
upb_Array_Set(cloned_array, i, val);
56555655
}
@@ -11692,9 +11692,35 @@ upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)(
1169211692

1169311693
// Must be last.
1169411694

11695-
const float kUpb_FltInfinity = INFINITY;
11696-
const double kUpb_Infinity = INFINITY;
11697-
const double kUpb_NaN = NAN;
11695+
// The latest win32 SDKs have an invalid definition of NAN.
11696+
// https://developercommunity.visualstudio.com/t/NAN-is-no-longer-compile-time-constant-i/10688907
11697+
//
11698+
// Unfortunately, the `0.0 / 0.0` workaround doesn't work in Clang under C23, so
11699+
// try __builtin_nan first, if that exists.
11700+
#ifdef _WIN32
11701+
#ifdef __has_builtin
11702+
#if __has_builtin(__builtin_nan)
11703+
#define UPB_NAN __builtin_nan("0")
11704+
#endif
11705+
#if __has_builtin(__builtin_inf)
11706+
#define UPB_INFINITY __builtin_inf()
11707+
#endif
11708+
#endif
11709+
#ifndef UPB_NAN
11710+
#define UPB_NAN 0.0 / 0.0
11711+
#endif
11712+
#ifndef UPB_INFINITY
11713+
#define UPB_INFINITY 1.0 / 0.0
11714+
#endif
11715+
#else
11716+
// For !_WIN32, assume math.h works.
11717+
#define UPB_NAN NAN
11718+
#define UPB_INFINITY INFINITY
11719+
#endif
11720+
11721+
const float kUpb_FltInfinity = UPB_INFINITY;
11722+
const double kUpb_Infinity = UPB_INFINITY;
11723+
const double kUpb_NaN = UPB_NAN;
1169811724

1169911725
bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
1170011726
upb_Arena* a) {

upb/message/copy.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type,
150150
for (size_t i = 0; i < size; ++i) {
151151
upb_MessageValue val = upb_Array_Get(array, i);
152152
if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) {
153-
return false;
153+
return NULL;
154154
}
155155
upb_Array_Set(cloned_array, i, val);
156156
}

upb/message/internal/message.c

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

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

2450
bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
2551
upb_Arena* a) {

upb/text/internal/encode.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
// Must be last.
2323
#include "upb/port/def.inc"
2424

25-
#define CHK(x) \
26-
do { \
27-
if (!(x)) { \
28-
return false; \
29-
} \
25+
#define CHK(x) \
26+
do { \
27+
if (!(x)) { \
28+
return NULL; \
29+
} \
3030
} while (0)
3131

3232
/*
@@ -177,4 +177,4 @@ void UPB_PRIVATE(_upb_TextEncode_Scalar)(txtenc* e, upb_MessageValue val,
177177
default:
178178
UPB_UNREACHABLE();
179179
}
180-
}
180+
}

0 commit comments

Comments
 (0)