@@ -5092,6 +5092,45 @@ Gid_t getegid (void);
5092
5092
Perl_deb (aTHX_ " %s scope %ld (savestack=%ld) at %s:%d\n " , \
5093
5093
where, (long )PL_scopestack_ix, (long )PL_savestack_ix, \
5094
5094
__FILE__, __LINE__));
5095
+ /*
5096
+ =for apidoc_section $directives
5097
+ =for apidoc Am|void|assert_|bool expr
5098
+ =for apidoc_item | |__ASSERT_
5099
+
5100
+ These are synonymous, used to wrap the libc C<assert()> call in comma
5101
+ expressions in macro expansions, but you probably don't want to use them nor
5102
+ plain C<assert>; read on.
5103
+
5104
+ In DEBUGGING builds, each expands to an assert of its argument, followed by
5105
+ a comma. (That is what the trailing underscore signifies.)
5106
+
5107
+ In non-DEBUGGING builds, each expands to nothing.
5108
+
5109
+ They thus can be used to string together a bunch of asserts in a comma
5110
+ expression that is syntactically valid in either type of build.
5111
+
5112
+ NOTE, however, use of these (and plain C<assert()>) is discouraged in a macro.
5113
+ This is because their usual use is to validate some of the arguments to that
5114
+ macro. That will likely lead to the evaluation of those arguments more than
5115
+ once during the macro expansion. If such an argument is an expression with
5116
+ side effects, the behavior of the macro will differ between DEBUGGING and
5117
+ non-DEBUGGING builds.
5118
+
5119
+ And, they are necessary only on platforms where the libc C<assert()> expands to
5120
+ nothing when not in a DEBUGGING build. There should be no such platforms now
5121
+ in existence, as the C89 standard forbids that, and Perl requires at least C99.
5122
+ So, you can just us plain C<assert>, and say S<C<assert(...), assert(...),>>
5123
+ and everything will compile (and will work if none of the arguments to the
5124
+ asserts is an expression with side effects).
5125
+
5126
+ These macros are retained for backward compatibility.
5127
+
5128
+ Do NOT use C<__ASSERT_>. A name with two leading underscores followed by a
5129
+ capital letter is reserved for the use of the compiler and libc in some
5130
+ contexts in C, and in all contexts in C++.
5131
+
5132
+ =cut
5133
+ */
5095
5134
5096
5135
/* Keep the old croak based assert for those who want it, and as a fallback if
5097
5136
the platform is so heretically non-ANSI that it can't assert. */
@@ -5110,9 +5149,11 @@ Gid_t getegid (void);
5110
5149
" file \" " __FILE__ " \" , line %" LINE_Tf, \
5111
5150
STRINGIFY (what), (line_t ) __LINE__))
5112
5151
# define assert_ (what ) assert(what),
5152
+ # define __ASSERT_ (statement ) assert(statement),
5113
5153
#else
5114
5154
# define Perl_assert (what ) ((void ) 0 )
5115
5155
# define assert_ (what )
5156
+ # define __ASSERT_ (statement )
5116
5157
#endif
5117
5158
5118
5159
struct ufuncs {
0 commit comments