Skip to content

Commit

Permalink
Merging from chakra-core#6970
Browse files Browse the repository at this point in the history
Avoid using MSVC-internal _STRINGIZE chakra-core#6970

Below is the comment from
Stephan T. Lavavej in the above mentioned pull request:

"I work on Microsoft's C++ Standard Library implementation, where we recently merged microsoft/STL#4405 to remove our internal _STRINGIZE macro. Our "Real World Code" test suite, which builds popular open-source projects like yours, found that you were using this MSVC-internal macro and therefore our change broke your code.

The C++ Standard's rule is that _Leading_underscore_capital identifiers (including _LEADING_UNDERSCORE_ALL_CAPS) are reserved for the compiler and Standard Library, so other libraries and applications should avoid using such reserved identifiers. This is N4971 5.10 [lex.name]/3:

In addition, some identifiers appearing as a token or preprocessing-token are reserved for use by C++ implementations and shall not be used otherwise; no diagnostic is required.
— Each identifier that contains a double underscore __ or begins with an underscore followed by an uppercase letter is reserved to the implementation for any use.

This PR introduces non-reserved names that will work on all platforms."
  • Loading branch information
bhmohanr-techie committed Jul 2, 2024
1 parent dfa5a16 commit d7c3d57
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
8 changes: 7 additions & 1 deletion bin/NativeTests/stdafx.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

Expand All @@ -25,11 +26,16 @@

#define DebugOnly(x) x

#if !defined(CHAKRACORE_STRINGIZE)
#define CHAKRACORE_STRINGIZE_IMPL(x) #x
#define CHAKRACORE_STRINGIZE(x) CHAKRACORE_STRINGIZE_IMPL(x)
#endif

#define AssertMsg(exp, comment) \
do { \
if (!(exp)) \
{ \
fprintf(stderr, "ASSERTION (%s, line %d) %s %s\n", __FILE__, __LINE__, _STRINGIZE(exp), comment); \
fprintf(stderr, "ASSERTION (%s, line %d) %s %s\n", __FILE__, __LINE__, CHAKRACORE_STRINGIZE(exp), comment); \
fflush(stderr); \
DebugBreak(); \
} \
Expand Down
10 changes: 5 additions & 5 deletions bin/ch/stdafx.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved.
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#pragma once
Expand Down Expand Up @@ -57,16 +57,16 @@

#if defined(DBG)

#define _STRINGIZE_(x) #x
#if !defined(_STRINGIZE)
#define _STRINGIZE(x) _STRINGIZE_(x)
#if !defined(CHAKRACORE_STRINGIZE)
#define CHAKRACORE_STRINGIZE_IMPL(x) #x
#define CHAKRACORE_STRINGIZE(x) CHAKRACORE_STRINGIZE_IMPL(x)
#endif

#define AssertMsg(exp, comment) \
do { \
if (!(exp)) \
{ \
fprintf(stderr, "ASSERTION (%s, line %d) %s %s\n", __FILE__, __LINE__, _STRINGIZE(exp), comment); \
fprintf(stderr, "ASSERTION (%s, line %d) %s %s\n", __FILE__, __LINE__, CHAKRACORE_STRINGIZE(exp), comment); \
fflush(stderr); \
DebugBreak(); \
} \
Expand Down
11 changes: 7 additions & 4 deletions pal/inc/assert_only.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Copyright (c) ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

// PAL free Assert definitions
#ifdef DEBUG

#define _QUOTE_(s) #s
#define _STRINGIZE_(s) _QUOTE_(s)
#if !defined(CHAKRACORE_STRINGIZE)
#define CHAKRACORE_STRINGIZE_IMPL(x) #x
#define CHAKRACORE_STRINGIZE(x) CHAKRACORE_STRINGIZE_IMPL(x)
#endif

#ifndef __ANDROID__
#define _ERR_OUTPUT_(condition, comment) \
fprintf(stderr, "ASSERTION (%s, line %d) %s %s\n", __FILE__, __LINE__, \
_STRINGIZE_(condition), comment); \
CHAKRACORE_STRINGIZE(condition), comment); \
fflush(stderr);
#else // ANDROID
#include <android/log.h>
#define _ERR_OUTPUT_(condition, comment) \
__android_log_print(ANDROID_LOG_ERROR, "chakracore-log", \
"ASSERTION (%s, line %d) %s %s\n", __FILE__, __LINE__, \
_STRINGIZE_(condition), comment);
CHAKRACORE_STRINGIZE(condition), comment);
#endif

#define _Assert_(condition, comment) \
Expand Down

0 comments on commit d7c3d57

Please sign in to comment.