Skip to content

Commit 03f24b8

Browse files
committed
Make croak() always expand to Perl_croak_nocontext()
Perl almost always opts for saving time over saving space. Hence, we have croak() that saves time at the expense of space, but needs thread context available; and croak_no_context() that doesn't need that, but takes extra time But, when we are about to die, time isn't that important. Even if we are doing eval after eval in a tight loop, the potential time savings of passing the thread context to Perl_croak is insignificant compared to the tear-down that follows. My claim then is that croak() never needed a thread context parameter to save a bit of time just before death. It is an optimization that isn't worth it. And having it do so required the invention of croak_nocontext(), and the extra cognitive load associated with two methods for the same task. This commit changes plain croak() to not use a thread context parameter. It and croak_nocontext() now behave identically. That means that going forward, people will likely choose croak() which requires less typing and occupies fewer columns on the screen, and they won't have to remember which form to use when.
1 parent e1e4832 commit 03f24b8

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

autodoc.pl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@
8686

8787
# This is a copy of the list in regen/embed.pl.
8888
my @have_compatibility_macros = qw(
89-
croak
9089
deb
9190
die
9291
form

embed.fnc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ px |void |create_eval_scope \
922922
|NN SV **sp \
923923
|U32 flags
924924
: croak()'s first parm can be NULL. Otherwise, mod_perl breaks.
925-
Adfpr |void |croak |NULLOK const char *pat \
925+
AMdfpr |void |croak |NULLOK const char *pat \
926926
|...
927927
Tfpr |void |croak_caller |NULLOK const char *pat \
928928
|...

embed.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
#if !defined(MULTIPLICITY)
3131
/* undefined symbols, point them back at the usual ones */
32-
# define Perl_croak_nocontext Perl_croak
3332
# define Perl_deb_nocontext Perl_deb
3433
# define Perl_die_nocontext Perl_die
3534
# define Perl_form_nocontext Perl_form
@@ -78,7 +77,6 @@
7877

7978
# if defined(MULTIPLICITY) && !defined(PERL_NO_SHORT_NAMES) && \
8079
!defined(PERL_WANT_VARARGS)
81-
# define croak Perl_croak_nocontext
8280
# define deb Perl_deb_nocontext
8381
# define die Perl_die_nocontext
8482
# define form Perl_form_nocontext
@@ -914,7 +912,6 @@
914912
# endif /* defined(MULTIPLICITY) */
915913
# if !defined(MULTIPLICITY) || defined(PERL_CORE) || \
916914
defined(PERL_WANT_VARARGS)
917-
# define croak(...) Perl_croak(aTHX_ __VA_ARGS__)
918915
# define deb(...) Perl_deb(aTHX_ __VA_ARGS__)
919916
# define die(...) Perl_die(aTHX_ __VA_ARGS__)
920917
# define form(...) Perl_form(aTHX_ __VA_ARGS__)

regen/embed.pl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ BEGIN
4141
# N.B. If you change this list, update the copy in autodoc.pl. This is likely
4242
# to never happen, so not worth coding automatic synchronization.
4343
my @have_compatibility_macros = qw(
44-
croak
4544
deb
4645
die
4746
form

util.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,10 +1912,9 @@ error message from arguments. If you want to throw a non-string object,
19121912
or build an error message in an SV yourself, it is preferable to use
19131913
the C<L</croak_sv>> function, which does not involve clobbering C<ERRSV>.
19141914
1915-
The two forms differ only in that C<croak_nocontext> does not take a thread
1916-
context (C<aTHX>) parameter. It is usually preferred as it takes up fewer
1917-
bytes of code than plain C<Perl_croak>, and time is rarely a critical resource
1918-
when you are about to throw an exception.
1915+
The reasons for the existence of C<croak_nocontext> are no longer applicable.
1916+
croak() can now be used in all circumstances. C<Perl_croak_nocontext> might be
1917+
useful when compiling with C<PERL_NO_SHORT_NAMES>.
19191918
19201919
=cut
19211920
*/

util.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111
#ifndef PERL_UTIL_H_
1212
#define PERL_UTIL_H_
1313

14+
/* Calling Perl_croak_nocontext instead of plain Perl_croak is one less
15+
* argument to pass under threads, so each instance takes up fewer bytes (but
16+
* the nocontext function has to derive the thread context itself, taking more
17+
* time). We trade time for less space here, because time is rarely a
18+
* critical resource when you are about to throw an exception. */
19+
#define croak(...) Perl_croak_nocontext(__VA_ARGS__)
20+
#ifndef MULTIPLICITY
21+
# define Perl_croak_nocontext Perl_croak
22+
#endif
1423

1524
#ifdef VMS
1625
# define PERL_FILE_IS_ABSOLUTE(f) \

0 commit comments

Comments
 (0)