From b2a520f693702c8dd74cf5c8d0b3d93c7b23b603 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Thu, 25 May 2023 13:17:34 -0700 Subject: [PATCH] Respect NDEBUG for asserts even though Ruby 3+ pollutes it. Prior to this CL, asserts have no effect for Ruby 3+, because Ruby unconditionally defines `NDEBUG`: https://bugs.ruby-lang.org/issues/18777 We work around this by doing `#undef NDEBUG` right after including Ruby, if `NDEBUG` was not previously defined. PiperOrigin-RevId: 535359088 --- objectivec/GPBAny.pbobjc.m | 4 +-- objectivec/GPBApi.pbobjc.m | 12 +++---- objectivec/GPBDuration.pbobjc.m | 4 +-- objectivec/GPBEmpty.pbobjc.m | 4 +-- objectivec/GPBFieldMask.pbobjc.m | 4 +-- objectivec/GPBSourceContext.pbobjc.m | 4 +-- objectivec/GPBStruct.pbobjc.m | 12 +++---- objectivec/GPBTimestamp.pbobjc.m | 4 +-- objectivec/GPBType.pbobjc.m | 20 ++++++------ objectivec/GPBWrappers.pbobjc.m | 36 ++++++++++----------- ruby/ext/google/protobuf_c/convert.h | 2 -- ruby/ext/google/protobuf_c/defs.h | 2 -- ruby/ext/google/protobuf_c/map.h | 2 -- ruby/ext/google/protobuf_c/message.h | 2 -- ruby/ext/google/protobuf_c/protobuf.h | 14 ++++++-- ruby/ext/google/protobuf_c/repeated_field.c | 2 ++ ruby/ext/google/protobuf_c/repeated_field.h | 2 -- 17 files changed, 66 insertions(+), 64 deletions(-) diff --git a/objectivec/GPBAny.pbobjc.m b/objectivec/GPBAny.pbobjc.m index ada41e569d..9b7939d52b 100644 --- a/objectivec/GPBAny.pbobjc.m +++ b/objectivec/GPBAny.pbobjc.m @@ -91,9 +91,9 @@ typedef struct GPBAny__storage_ { "\001\001\004\241!!\000"; [localDescriptor setupExtraTextInfo:extraTextFormatInfo]; #endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/GPBApi.pbobjc.m b/objectivec/GPBApi.pbobjc.m index a6283a84f1..b416445c0f 100644 --- a/objectivec/GPBApi.pbobjc.m +++ b/objectivec/GPBApi.pbobjc.m @@ -145,9 +145,9 @@ typedef struct GPBApi__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBApi__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -272,9 +272,9 @@ typedef struct GPBMethod__storage_ { "\002\002\007\244\241!!\000\004\010\244\241!!\000"; [localDescriptor setupExtraTextInfo:extraTextFormatInfo]; #endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -341,9 +341,9 @@ typedef struct GPBMixin__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBMixin__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/GPBDuration.pbobjc.m b/objectivec/GPBDuration.pbobjc.m index 1a54a76b30..a618e9cd57 100644 --- a/objectivec/GPBDuration.pbobjc.m +++ b/objectivec/GPBDuration.pbobjc.m @@ -86,9 +86,9 @@ typedef struct GPBDuration__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBDuration__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/GPBEmpty.pbobjc.m b/objectivec/GPBEmpty.pbobjc.m index b69738c593..c33be8bb96 100644 --- a/objectivec/GPBEmpty.pbobjc.m +++ b/objectivec/GPBEmpty.pbobjc.m @@ -62,9 +62,9 @@ typedef struct GPBEmpty__storage_ { fieldCount:0 storageSize:sizeof(GPBEmpty__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/GPBFieldMask.pbobjc.m b/objectivec/GPBFieldMask.pbobjc.m index 8de5ad42ff..347bcbef0e 100644 --- a/objectivec/GPBFieldMask.pbobjc.m +++ b/objectivec/GPBFieldMask.pbobjc.m @@ -75,9 +75,9 @@ typedef struct GPBFieldMask__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBFieldMask__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/GPBSourceContext.pbobjc.m b/objectivec/GPBSourceContext.pbobjc.m index 7ae605b32a..cea417de1b 100644 --- a/objectivec/GPBSourceContext.pbobjc.m +++ b/objectivec/GPBSourceContext.pbobjc.m @@ -75,9 +75,9 @@ typedef struct GPBSourceContext__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBSourceContext__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/GPBStruct.pbobjc.m b/objectivec/GPBStruct.pbobjc.m index eabd761866..600b49574f 100644 --- a/objectivec/GPBStruct.pbobjc.m +++ b/objectivec/GPBStruct.pbobjc.m @@ -115,9 +115,9 @@ typedef struct GPBStruct__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBStruct__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -222,9 +222,9 @@ typedef struct GPBValue__storage_ { [localDescriptor setupOneofs:oneofs count:(uint32_t)(sizeof(oneofs) / sizeof(char*)) firstHasIndex:-1]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -285,9 +285,9 @@ typedef struct GPBListValue__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBListValue__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/GPBTimestamp.pbobjc.m b/objectivec/GPBTimestamp.pbobjc.m index edd73498a2..dc6baebf2c 100644 --- a/objectivec/GPBTimestamp.pbobjc.m +++ b/objectivec/GPBTimestamp.pbobjc.m @@ -86,9 +86,9 @@ typedef struct GPBTimestamp__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBTimestamp__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/GPBType.pbobjc.m b/objectivec/GPBType.pbobjc.m index db7a41f7e5..7b44e39951 100644 --- a/objectivec/GPBType.pbobjc.m +++ b/objectivec/GPBType.pbobjc.m @@ -307,9 +307,9 @@ typedef struct GPBType__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBType__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -468,9 +468,9 @@ typedef struct GPBField__storage_ { "\001\006\004\241!!\000"; [localDescriptor setupExtraTextInfo:extraTextFormatInfo]; #endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -593,9 +593,9 @@ typedef struct GPBEnum__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBEnum__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -673,9 +673,9 @@ typedef struct GPBEnumValue__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBEnumValue__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -730,9 +730,9 @@ typedef struct GPBOption__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBOption__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/objectivec/GPBWrappers.pbobjc.m b/objectivec/GPBWrappers.pbobjc.m index 07be68bace..30461e3f6f 100644 --- a/objectivec/GPBWrappers.pbobjc.m +++ b/objectivec/GPBWrappers.pbobjc.m @@ -83,9 +83,9 @@ typedef struct GPBDoubleValue__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBDoubleValue__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -129,9 +129,9 @@ typedef struct GPBFloatValue__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBFloatValue__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -175,9 +175,9 @@ typedef struct GPBInt64Value__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBInt64Value__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -221,9 +221,9 @@ typedef struct GPBUInt64Value__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBUInt64Value__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -267,9 +267,9 @@ typedef struct GPBInt32Value__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBInt32Value__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -313,9 +313,9 @@ typedef struct GPBUInt32Value__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBUInt32Value__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -358,9 +358,9 @@ typedef struct GPBBoolValue__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBBoolValue__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -404,9 +404,9 @@ typedef struct GPBStringValue__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBStringValue__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; @@ -450,9 +450,9 @@ typedef struct GPBBytesValue__storage_ { fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription)) storageSize:sizeof(GPBBytesValue__storage_) flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)]; - #if defined(DEBUG) && DEBUG +#if defined(DEBUG) && DEBUG NSAssert(descriptor == nil, @"Startup recursed!"); - #endif // DEBUG +#endif // DEBUG descriptor = localDescriptor; } return descriptor; diff --git a/ruby/ext/google/protobuf_c/convert.h b/ruby/ext/google/protobuf_c/convert.h index e48c979455..9fad5efbbf 100644 --- a/ruby/ext/google/protobuf_c/convert.h +++ b/ruby/ext/google/protobuf_c/convert.h @@ -31,8 +31,6 @@ #ifndef RUBY_PROTOBUF_CONVERT_H_ #define RUBY_PROTOBUF_CONVERT_H_ -#include - #include "protobuf.h" #include "ruby-upb.h" diff --git a/ruby/ext/google/protobuf_c/defs.h b/ruby/ext/google/protobuf_c/defs.h index f559cb0b9d..c3f4f7dc77 100644 --- a/ruby/ext/google/protobuf_c/defs.h +++ b/ruby/ext/google/protobuf_c/defs.h @@ -31,8 +31,6 @@ #ifndef RUBY_PROTOBUF_DEFS_H_ #define RUBY_PROTOBUF_DEFS_H_ -#include - #include "protobuf.h" #include "ruby-upb.h" diff --git a/ruby/ext/google/protobuf_c/map.h b/ruby/ext/google/protobuf_c/map.h index 7b4a1514ca..8d1dedb4fc 100644 --- a/ruby/ext/google/protobuf_c/map.h +++ b/ruby/ext/google/protobuf_c/map.h @@ -31,8 +31,6 @@ #ifndef RUBY_PROTOBUF_MAP_H_ #define RUBY_PROTOBUF_MAP_H_ -#include - #include "protobuf.h" #include "ruby-upb.h" diff --git a/ruby/ext/google/protobuf_c/message.h b/ruby/ext/google/protobuf_c/message.h index b409650ef8..bb508f78c4 100644 --- a/ruby/ext/google/protobuf_c/message.h +++ b/ruby/ext/google/protobuf_c/message.h @@ -31,8 +31,6 @@ #ifndef RUBY_PROTOBUF_MESSAGE_H_ #define RUBY_PROTOBUF_MESSAGE_H_ -#include - #include "protobuf.h" #include "ruby-upb.h" diff --git a/ruby/ext/google/protobuf_c/protobuf.h b/ruby/ext/google/protobuf_c/protobuf.h index c6af98fa47..a51d9a7316 100644 --- a/ruby/ext/google/protobuf_c/protobuf.h +++ b/ruby/ext/google/protobuf_c/protobuf.h @@ -31,8 +31,16 @@ #ifndef __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__ #define __GOOGLE_PROTOBUF_RUBY_PROTOBUF_H__ +// Ruby 3+ defines NDEBUG itself, see: https://bugs.ruby-lang.org/issues/18777 +#ifdef NDEBUG +#include +#else +#include +#undef NDEBUG +#endif + +#include // Must be included after the NDEBUG logic above. #include -#include #include #include "defs.h" @@ -110,7 +118,9 @@ extern VALUE cTypeError; do { \ } while (false && (expr)) #else -#define PBRUBY_ASSERT(expr) assert(expr) +#define PBRUBY_ASSERT(expr) \ + if (!(expr)) \ + rb_bug("Assertion failed at %s:%d, expr: %s", __FILE__, __LINE__, #expr) #endif #define PBRUBY_MAX(x, y) (((x) > (y)) ? (x) : (y)) diff --git a/ruby/ext/google/protobuf_c/repeated_field.c b/ruby/ext/google/protobuf_c/repeated_field.c index 700ca16f38..bcd5f45afb 100644 --- a/ruby/ext/google/protobuf_c/repeated_field.c +++ b/ruby/ext/google/protobuf_c/repeated_field.c @@ -100,6 +100,8 @@ VALUE RepeatedField_GetRubyWrapper(upb_Array* array, TypeInfo type_info, PBRUBY_ASSERT(ruby_to_RepeatedField(val)->type_info.type == type_info.type); PBRUBY_ASSERT(ruby_to_RepeatedField(val)->type_info.def.msgdef == type_info.def.msgdef); + PBRUBY_ASSERT(ruby_to_RepeatedField(val)->array == array); + return val; } diff --git a/ruby/ext/google/protobuf_c/repeated_field.h b/ruby/ext/google/protobuf_c/repeated_field.h index b0581635b8..ef9bd5733d 100644 --- a/ruby/ext/google/protobuf_c/repeated_field.h +++ b/ruby/ext/google/protobuf_c/repeated_field.h @@ -31,8 +31,6 @@ #ifndef RUBY_PROTOBUF_REPEATED_FIELD_H_ #define RUBY_PROTOBUF_REPEATED_FIELD_H_ -#include - #include "protobuf.h" #include "ruby-upb.h"