Skip to content

Commit 11f9ab1

Browse files
committed
[perl #123063] allow assert() to be used as an expression
In non-DEBUGGING builds it would be replaced with nothing, producing a syntax error
1 parent 679f225 commit 11f9ab1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

ext/XS-APItest/APItest.xs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,13 @@ INCLUDE: const-xs.inc
12561256

12571257
INCLUDE: numeric.xs
12581258

1259+
void
1260+
assertx(int x)
1261+
CODE:
1262+
/* this only needs to compile and checks that assert() can be
1263+
used this way syntactically */
1264+
(assert(x),1);
1265+
12591266
MODULE = XS::APItest::utf8 PACKAGE = XS::APItest::utf8
12601267

12611268
int

perl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4035,6 +4035,7 @@ Gid_t getegid (void);
40354035
# define DEBUG_Pv_TEST DEBUG_Pv_TEST_
40364036

40374037
# define PERL_DEB(a) a
4038+
# define PERL_DEB2(a,b) a
40384039
# define PERL_DEBUG(a) if (PL_debug) a
40394040
# define DEBUG_p(a) if (DEBUG_p_TEST) a
40404041
# define DEBUG_s(a) if (DEBUG_s_TEST) a
@@ -4117,6 +4118,7 @@ Gid_t getegid (void);
41174118
# define DEBUG_Pv_TEST (0)
41184119

41194120
# define PERL_DEB(a)
4121+
# define PERL_DEB2(a,b) b
41204122
# define PERL_DEBUG(a)
41214123
# define DEBUG_p(a)
41224124
# define DEBUG_s(a)
@@ -4159,11 +4161,11 @@ Gid_t getegid (void);
41594161
/* Keep the old croak based assert for those who want it, and as a fallback if
41604162
the platform is so heretically non-ANSI that it can't assert. */
41614163

4162-
#define Perl_assert(what) PERL_DEB( \
4164+
#define Perl_assert(what) PERL_DEB2( \
41634165
((what) ? ((void) 0) : \
41644166
(Perl_croak_nocontext("Assertion %s failed: file \"" __FILE__ \
41654167
"\", line %d", STRINGIFY(what), __LINE__), \
4166-
(void) 0)))
4168+
(void) 0)), ((void)0))
41674169

41684170
/* assert() gets defined if DEBUGGING (and I_ASSERT).
41694171
* If no DEBUGGING, the <assert.h> has not been included. */

0 commit comments

Comments
 (0)