Skip to content

Commit

Permalink
[perl #123063] allow assert() to be used as an expression
Browse files Browse the repository at this point in the history
In non-DEBUGGING builds it would be replaced with nothing, producing
a syntax error
  • Loading branch information
tonycoz committed Dec 3, 2014
1 parent 679f225 commit 11f9ab1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions ext/XS-APItest/APItest.xs
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,13 @@ INCLUDE: const-xs.inc

INCLUDE: numeric.xs

void
assertx(int x)
CODE:
/* this only needs to compile and checks that assert() can be
used this way syntactically */
(assert(x),1);

MODULE = XS::APItest::utf8 PACKAGE = XS::APItest::utf8

int
Expand Down
6 changes: 4 additions & 2 deletions perl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4035,6 +4035,7 @@ Gid_t getegid (void);
# define DEBUG_Pv_TEST DEBUG_Pv_TEST_

# define PERL_DEB(a) a
# define PERL_DEB2(a,b) a
# define PERL_DEBUG(a) if (PL_debug) a
# define DEBUG_p(a) if (DEBUG_p_TEST) a
# define DEBUG_s(a) if (DEBUG_s_TEST) a
Expand Down Expand Up @@ -4117,6 +4118,7 @@ Gid_t getegid (void);
# define DEBUG_Pv_TEST (0)

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

#define Perl_assert(what) PERL_DEB( \
#define Perl_assert(what) PERL_DEB2( \
((what) ? ((void) 0) : \
(Perl_croak_nocontext("Assertion %s failed: file \"" __FILE__ \
"\", line %d", STRINGIFY(what), __LINE__), \
(void) 0)))
(void) 0)), ((void)0))

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

0 comments on commit 11f9ab1

Please sign in to comment.