Skip to content

Commit 701d116

Browse files
committed
perlapi: Combine all general croak() and die() entries
This includes vcroak, croak_sv, and die_sv This makes it easier for the reader to decide which one to use.
1 parent 3327ffe commit 701d116

File tree

1 file changed

+25
-69
lines changed

1 file changed

+25
-69
lines changed

util.c

Lines changed: 25 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,16 +1757,6 @@ Perl_invoke_exception_hook(pTHX_ SV *ex, bool warn)
17571757
return FALSE;
17581758
}
17591759

1760-
/*
1761-
=for apidoc die_sv
1762-
1763-
This behaves the same as L</croak_sv>, except for the return type.
1764-
It should be used only where the C<OP *> return type is required.
1765-
The function never actually returns.
1766-
1767-
=cut
1768-
*/
1769-
17701760
/* silence __declspec(noreturn) warnings */
17711761
MSVC_DIAG_IGNORE(4646 4645)
17721762
OP *
@@ -1812,27 +1802,6 @@ Perl_die(pTHX_ const char* pat, ...)
18121802
}
18131803
MSVC_DIAG_RESTORE
18141804

1815-
/*
1816-
=for apidoc croak_sv
1817-
1818-
This is an XS interface to Perl's C<die> function.
1819-
1820-
C<baseex> is the error message or object. If it is a reference, it
1821-
will be used as-is. Otherwise it is used as a string, and if it does
1822-
not end with a newline then it will be extended with some indication of
1823-
the current location in the code, as described for L</mess_sv>.
1824-
1825-
The error message or object will be used as an exception, by default
1826-
returning control to the nearest enclosing C<eval>, but subject to
1827-
modification by a C<$SIG{__DIE__}> handler. In any case, the C<croak_sv>
1828-
function never returns normally.
1829-
1830-
To die with a simple string message, the L</croak> function may be
1831-
more convenient.
1832-
1833-
=cut
1834-
*/
1835-
18361805
void
18371806
Perl_croak_sv(pTHX_ SV *baseex)
18381807
{
@@ -1842,31 +1811,6 @@ Perl_croak_sv(pTHX_ SV *baseex)
18421811
die_unwind(ex);
18431812
}
18441813

1845-
/*
1846-
=for apidoc vcroak
1847-
1848-
This is an XS interface to Perl's C<die> function.
1849-
1850-
C<pat> and C<args> are a sprintf-style format pattern and encapsulated
1851-
argument list. These are used to generate a string message. If the
1852-
message does not end with a newline, then it will be extended with
1853-
some indication of the current location in the code, as described for
1854-
L</mess_sv>.
1855-
1856-
The error message will be used as an exception, by default
1857-
returning control to the nearest enclosing C<eval>, but subject to
1858-
modification by a C<$SIG{__DIE__}> handler. In any case, the C<croak>
1859-
function never returns normally.
1860-
1861-
For historical reasons, if C<pat> is null then the contents of C<ERRSV>
1862-
(C<$@>) will be used as an error message or object instead of building an
1863-
error message from arguments. If you want to throw a non-string object,
1864-
or build an error message in an SV yourself, it is preferable to use
1865-
the L</croak_sv> function, which does not involve clobbering C<ERRSV>.
1866-
1867-
=cut
1868-
*/
1869-
18701814
void
18711815
Perl_vcroak(pTHX_ const char* pat, va_list *args)
18721816
{
@@ -1877,27 +1821,39 @@ Perl_vcroak(pTHX_ const char* pat, va_list *args)
18771821

18781822
/*
18791823
=for apidoc croak
1824+
=for apidoc_item croak_sv
1825+
=for apidoc_item vcroak
18801826
=for apidoc_item die
1827+
=for apidoc_item die_sv
18811828
=for apidoc_item croak_nocontext
18821829
=for apidoc_item die_nocontext
18831830
18841831
These are XS interfaces to Perl's C<die> function.
18851832
1886-
They take a sprintf-style format pattern and argument list, which are used to
1887-
generate a string message. If the message does not end with a newline, then it
1888-
will be extended with some indication of the current location in the code, as
1889-
described for C<L</mess_sv>>.
1833+
The arguments are used to generate a string message. If the message does not
1834+
end with a newline, it will be extended with some indication of the current
1835+
location in the code, as described for C<L</mess_sv>>.
1836+
1837+
The error message will be used as an exception, by default returning control to
1838+
the nearest enclosing C<eval>, but subject to modification by a
1839+
C<$SIG{__DIE__}> handler. In any case, none of these functions ever actually
1840+
return normally.
1841+
1842+
In C<croak_sv> and C<die_sv>, C<baseex> is the error message or object. If it
1843+
is a reference, it will be used as-is. Otherwise it is used as a string.
1844+
1845+
To die with a simple string message, one of the other forms may be more
1846+
convenient. These take a sprintf-style format pattern, with arguments, to
1847+
generate the message.
18901848
1891-
The error message will be used as an exception, by default
1892-
returning control to the nearest enclosing C<eval>, but subject to
1893-
modification by a C<$SIG{__DIE__}> handler. In any case, these croak
1894-
functions never return normally.
1849+
The arguments to C<vcroak> are specified as a C<va_list>. The arguments to the
1850+
remaining forms are specified as a sprintf-style list of arguments.
18951851
1896-
For historical reasons, if C<pat> is null then the contents of C<ERRSV>
1897-
(C<$@>) will be used as an error message or object instead of building an
1898-
error message from arguments. If you want to throw a non-string object,
1899-
or build an error message in an SV yourself, it is preferable to use
1900-
the C<L</croak_sv>> function, which does not involve clobbering C<ERRSV>.
1852+
In the non-C<_sv> forms, for historical reasons, if C<pat> is null then the
1853+
contents of C<L</ERRSV>> (C<$@>) will be used as an error message or object
1854+
instead of building an error message from arguments. Use the C<_sv> forms
1855+
instead if you want to throw a non-string object, or build an error message in
1856+
an SV yourself; these do not involve clobbering C<ERRSV>.
19011857
19021858
The difference between the C<croak> forms and the C<die> forms is only the
19031859
return type of the functions. The C<croak> forms return C<void>; the C<die>

0 commit comments

Comments
 (0)