Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport windows fixes with INFINITY/NAN #19389

Merged
merged 7 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions php/ext/google/protobuf/php-upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -6161,7 +6161,7 @@ upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type,
for (size_t i = 0; i < size; ++i) {
upb_MessageValue val = upb_Array_Get(array, i);
if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) {
return false;
return NULL;
}
upb_Array_Set(cloned_array, i, val);
}
Expand Down Expand Up @@ -12204,9 +12204,35 @@ upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)(

// Must be last.

const float kUpb_FltInfinity = INFINITY;
const double kUpb_Infinity = INFINITY;
const double kUpb_NaN = NAN;
// The latest win32 SDKs have an invalid definition of NAN.
// https://developercommunity.visualstudio.com/t/NAN-is-no-longer-compile-time-constant-i/10688907
//
// Unfortunately, the `0.0 / 0.0` workaround doesn't work in Clang under C23, so
// try __builtin_nan first, if that exists.
#ifdef _WIN32
#ifdef __has_builtin
#if __has_builtin(__builtin_nan)
#define UPB_NAN __builtin_nan("0")
#endif
#if __has_builtin(__builtin_inf)
#define UPB_INFINITY __builtin_inf()
#endif
#endif
#ifndef UPB_NAN
#define UPB_NAN 0.0 / 0.0
#endif
#ifndef UPB_INFINITY
#define UPB_INFINITY 1.0 / 0.0
#endif
#else
// For !_WIN32, assume math.h works.
#define UPB_NAN NAN
#define UPB_INFINITY INFINITY
#endif

const float kUpb_FltInfinity = UPB_INFINITY;
const double kUpb_Infinity = UPB_INFINITY;
const double kUpb_NaN = UPB_NAN;

bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
upb_Arena* a) {
Expand Down
121 changes: 0 additions & 121 deletions php/ext/google/protobuf/wkt.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2584,127 +2584,6 @@ static void google_protobuf_Syntax_ModuleInit() {
strlen("SYNTAX_PROTO3"), 1);
}

/* google/protobuf/timestamp.proto */

zend_class_entry* GPBMetadata_Google_Protobuf_Timestamp_ce;

const char google_protobuf_timestamp_proto_descriptor [239] = {
'\n', '\037', 'g', 'o', 'o', 'g', 'l', 'e', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 't', 'i', 'm', 'e', 's', 't', 'a',
'm', 'p', '.', 'p', 'r', 'o', 't', 'o', '\022', '\017', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f',
'\"', '+', '\n', '\t', 'T', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', '\022', '\017', '\n', '\007', 's', 'e', 'c', 'o', 'n', 'd', 's', '\030',
'\001', ' ', '\001', '(', '\003', '\022', '\r', '\n', '\005', 'n', 'a', 'n', 'o', 's', '\030', '\002', ' ', '\001', '(', '\005', 'B', '\205', '\001', '\n', '\023',
'c', 'o', 'm', '.', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', 'B', '\016', 'T', 'i', 'm', 'e',
's', 't', 'a', 'm', 'p', 'P', 'r', 'o', 't', 'o', 'P', '\001', 'Z', '2', 'g', 'o', 'o', 'g', 'l', 'e', '.', 'g', 'o', 'l', 'a',
'n', 'g', '.', 'o', 'r', 'g', '/', 'p', 'r', 'o', 't', 'o', 'b', 'u', 'f', '/', 't', 'y', 'p', 'e', 's', '/', 'k', 'n', 'o',
'w', 'n', '/', 't', 'i', 'm', 'e', 's', 't', 'a', 'm', 'p', 'p', 'b', '\370', '\001', '\001', '\242', '\002', '\003', 'G', 'P', 'B', '\252', '\002',
'\036', 'G', 'o', 'o', 'g', 'l', 'e', '.', 'P', 'r', 'o', 't', 'o', 'b', 'u', 'f', '.', 'W', 'e', 'l', 'l', 'K', 'n', 'o', 'w',
'n', 'T', 'y', 'p', 'e', 's', 'b', '\006', 'p', 'r', 'o', 't', 'o', '3',
};

static void google_protobuf_timestamp_proto_AddDescriptor() {
if (DescriptorPool_HasFile("google/protobuf/timestamp.proto")) return;
DescriptorPool_AddDescriptor("google/protobuf/timestamp.proto", google_protobuf_timestamp_proto_descriptor,
sizeof(google_protobuf_timestamp_proto_descriptor));
}

static PHP_METHOD(GPBMetadata_Google_Protobuf_Timestamp, initOnce) {
google_protobuf_timestamp_proto_AddDescriptor();
}

static zend_function_entry GPBMetadata_Google_Protobuf_Timestamp_methods[] = {
PHP_ME(GPBMetadata_Google_Protobuf_Timestamp, initOnce, arginfo_void, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
ZEND_FE_END
};

static void GPBMetadata_Google_Protobuf_Timestamp_ModuleInit() {
zend_class_entry tmp_ce;

INIT_CLASS_ENTRY(tmp_ce, "GPBMetadata\\Google\\Protobuf\\Timestamp",
GPBMetadata_Google_Protobuf_Timestamp_methods);

GPBMetadata_Google_Protobuf_Timestamp_ce = zend_register_internal_class(&tmp_ce);
}

/* google_protobuf_Timestamp */

zend_class_entry* google_protobuf_Timestamp_ce;

static PHP_METHOD(google_protobuf_Timestamp, __construct) {
google_protobuf_timestamp_proto_AddDescriptor();
zim_Message___construct(INTERNAL_FUNCTION_PARAM_PASSTHRU);
}

static PHP_METHOD(google_protobuf_Timestamp, getSeconds) {
Message* intern = (Message*)Z_OBJ_P(getThis());
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(
intern->desc->msgdef, "seconds");
zval ret;
Message_get(intern, f, &ret);
RETURN_COPY_VALUE(&ret);
}

static PHP_METHOD(google_protobuf_Timestamp, setSeconds) {
Message* intern = (Message*)Z_OBJ_P(getThis());
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(
intern->desc->msgdef, "seconds");
zval *val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &val)
== FAILURE) {
return;
}
Message_set(intern, f, val);
RETURN_COPY(getThis());
}

static PHP_METHOD(google_protobuf_Timestamp, getNanos) {
Message* intern = (Message*)Z_OBJ_P(getThis());
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(
intern->desc->msgdef, "nanos");
zval ret;
Message_get(intern, f, &ret);
RETURN_COPY_VALUE(&ret);
}

static PHP_METHOD(google_protobuf_Timestamp, setNanos) {
Message* intern = (Message*)Z_OBJ_P(getThis());
const upb_FieldDef *f = upb_MessageDef_FindFieldByName(
intern->desc->msgdef, "nanos");
zval *val;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &val)
== FAILURE) {
return;
}
Message_set(intern, f, val);
RETURN_COPY(getThis());
}

ZEND_BEGIN_ARG_INFO_EX(arginfo_timestamp_fromdatetime, 0, 0, 1)
ZEND_ARG_INFO(0, datetime)
ZEND_END_ARG_INFO()

static zend_function_entry google_protobuf_Timestamp_phpmethods[] = {
PHP_ME(google_protobuf_Timestamp, __construct, arginfo_construct, ZEND_ACC_PUBLIC)
PHP_ME(google_protobuf_Timestamp, getSeconds, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(google_protobuf_Timestamp, setSeconds, arginfo_setter, ZEND_ACC_PUBLIC)
PHP_ME(google_protobuf_Timestamp, getNanos, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(google_protobuf_Timestamp, setNanos, arginfo_setter, ZEND_ACC_PUBLIC)
PHP_ME(google_protobuf_Timestamp, fromDateTime, arginfo_timestamp_fromdatetime, ZEND_ACC_PUBLIC)
PHP_ME(google_protobuf_Timestamp, toDateTime, arginfo_void, ZEND_ACC_PUBLIC)
ZEND_FE_END
};

static void google_protobuf_Timestamp_ModuleInit() {
zend_class_entry tmp_ce;

INIT_CLASS_ENTRY(tmp_ce, "Google\\Protobuf\\Timestamp",
google_protobuf_Timestamp_phpmethods);

google_protobuf_Timestamp_ce = zend_register_internal_class(&tmp_ce);
google_protobuf_Timestamp_ce->ce_flags |= ZEND_ACC_FINAL;
google_protobuf_Timestamp_ce->create_object = Message_create;
zend_do_inheritance(google_protobuf_Timestamp_ce, message_ce);
}

/* google/protobuf/wrappers.proto */

zend_class_entry* GPBMetadata_Google_Protobuf_Wrappers_ce;
Expand Down
34 changes: 30 additions & 4 deletions ruby/ext/google/protobuf_c/ruby-upb.c
Original file line number Diff line number Diff line change
Expand Up @@ -5649,7 +5649,7 @@ upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type,
for (size_t i = 0; i < size; ++i) {
upb_MessageValue val = upb_Array_Get(array, i);
if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) {
return false;
return NULL;
}
upb_Array_Set(cloned_array, i, val);
}
Expand Down Expand Up @@ -11692,9 +11692,35 @@ upb_Extension* UPB_PRIVATE(_upb_Message_GetOrCreateExtension)(

// Must be last.

const float kUpb_FltInfinity = INFINITY;
const double kUpb_Infinity = INFINITY;
const double kUpb_NaN = NAN;
// The latest win32 SDKs have an invalid definition of NAN.
// https://developercommunity.visualstudio.com/t/NAN-is-no-longer-compile-time-constant-i/10688907
//
// Unfortunately, the `0.0 / 0.0` workaround doesn't work in Clang under C23, so
// try __builtin_nan first, if that exists.
#ifdef _WIN32
#ifdef __has_builtin
#if __has_builtin(__builtin_nan)
#define UPB_NAN __builtin_nan("0")
#endif
#if __has_builtin(__builtin_inf)
#define UPB_INFINITY __builtin_inf()
#endif
#endif
#ifndef UPB_NAN
#define UPB_NAN 0.0 / 0.0
#endif
#ifndef UPB_INFINITY
#define UPB_INFINITY 1.0 / 0.0
#endif
#else
// For !_WIN32, assume math.h works.
#define UPB_NAN NAN
#define UPB_INFINITY INFINITY
#endif

const float kUpb_FltInfinity = UPB_INFINITY;
const double kUpb_Infinity = UPB_INFINITY;
const double kUpb_NaN = UPB_NAN;

bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
upb_Arena* a) {
Expand Down
2 changes: 1 addition & 1 deletion upb/message/copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ upb_Array* upb_Array_DeepClone(const upb_Array* array, upb_CType value_type,
for (size_t i = 0; i < size; ++i) {
upb_MessageValue val = upb_Array_Get(array, i);
if (!upb_Clone_MessageValue(&val, value_type, sub, arena)) {
return false;
return NULL;
}
upb_Array_Set(cloned_array, i, val);
}
Expand Down
32 changes: 29 additions & 3 deletions upb/message/internal/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,35 @@
// Must be last.
#include "upb/port/def.inc"

const float kUpb_FltInfinity = INFINITY;
const double kUpb_Infinity = INFINITY;
const double kUpb_NaN = NAN;
// The latest win32 SDKs have an invalid definition of NAN.
// https://developercommunity.visualstudio.com/t/NAN-is-no-longer-compile-time-constant-i/10688907
//
// Unfortunately, the `0.0 / 0.0` workaround doesn't work in Clang under C23, so
// try __builtin_nan first, if that exists.
#ifdef _WIN32
#ifdef __has_builtin
#if __has_builtin(__builtin_nan)
#define UPB_NAN __builtin_nan("0")
#endif
#if __has_builtin(__builtin_inf)
#define UPB_INFINITY __builtin_inf()
#endif
#endif
#ifndef UPB_NAN
#define UPB_NAN 0.0 / 0.0
#endif
#ifndef UPB_INFINITY
#define UPB_INFINITY 1.0 / 0.0
#endif
#else
// For !_WIN32, assume math.h works.
#define UPB_NAN NAN
#define UPB_INFINITY INFINITY
#endif

const float kUpb_FltInfinity = UPB_INFINITY;
const double kUpb_Infinity = UPB_INFINITY;
const double kUpb_NaN = UPB_NAN;

bool UPB_PRIVATE(_upb_Message_Realloc)(struct upb_Message* msg, size_t need,
upb_Arena* a) {
Expand Down
12 changes: 6 additions & 6 deletions upb/text/internal/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
// Must be last.
#include "upb/port/def.inc"

#define CHK(x) \
do { \
if (!(x)) { \
return false; \
} \
#define CHK(x) \
do { \
if (!(x)) { \
return NULL; \
} \
} while (0)

/*
Expand Down Expand Up @@ -177,4 +177,4 @@ void UPB_PRIVATE(_upb_TextEncode_Scalar)(txtenc* e, upb_MessageValue val,
default:
UPB_UNREACHABLE();
}
}
}
Loading