Skip to content

Commit 86d15ec

Browse files
committed
Add macro PERL_UNIQUE_NAME
This macro acts like a factory to produce a name from its argument that also includes the line number.
1 parent 1372fc7 commit 86d15ec

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

perl.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4208,6 +4208,14 @@ Obsolete form of C<UVuf>, which you should convert to instead use
42084208
# define UVf UVuf
42094209
#endif
42104210

4211+
/* Use this like:
4212+
* #define sv1_ PERL_UNIQUE_NAME(sv)
4213+
* and it will expand to something very likely unique to your file, beginning
4214+
* with 'PL_' which means there should be no name collision with the caller.
4215+
* an underscore. If two 'sv1_' are attempted to be defined, a compiler
4216+
* warning will get raised, so you can change one of them. */
4217+
#define PERL_UNIQUE_NAME(name) CAT2(PL_, CAT2(name, __LINE__))
4218+
42114219
#if !defined(DEBUGGING) && !defined(NDEBUG)
42124220
# define NDEBUG 1
42134221
#endif
@@ -4323,15 +4331,9 @@ where it has parity with the other two forms.
43234331
* We use a bit-field instead of an array because gcc accepts
43244332
typedef char x[n]
43254333
where n is not a compile-time constant. We want to enforce constantness.
4326-
*
4327-
* We need the FOOL macros to get proper cpp parameter concatanation. */
4328-
# define STATIC_ASSERT_STRUCT_NAME_FOOL_CPP_2_(line) \
4329-
static_assertion_failed_##line
4330-
# define STATIC_ASSERT_STRUCT_NAME_FOOL_CPP_(line) \
4331-
STATIC_ASSERT_STRUCT_NAME_FOOL_CPP_2_(line)
4334+
*/
43324335
/* Return the struct and element name */
4333-
# define STATIC_ASSERT_STRUCT_NAME_ \
4334-
STATIC_ASSERT_STRUCT_NAME_FOOL_CPP_(__LINE__)
4336+
# define STATIC_ASSERT_STRUCT_NAME_ PERL_UNIQUE_NAME(static_assertion_failed_)
43354337

43364338
/* Return the struct body */
43374339
# define STATIC_ASSERT_STRUCT_BODY_(COND, NAME) \

0 commit comments

Comments
 (0)