Restructure soft-error handling in formatting.c.

Replace the error trapping scheme introduced in 5bc450629 with our
shiny new errsave/ereturn mechanism.  This doesn't have any real
functional impact (although I think that the new coding is able
to report a few more errors softly than v15 did).  And I doubt
there's any measurable performance difference either.  But this
gets rid of an ad-hoc, one-of-a-kind design in favor of a mechanism
that will be widely used going forward, so it should be a net win
for code readability.

Discussion: https://postgr.es/m/3bbbb0df-7382-bf87-9737-340ba096e034@postgrespro.ru
This commit is contained in:
Tom Lane 2022-12-09 20:15:56 -05:00
parent c60488b474
commit 4dd687502d
3 changed files with 323 additions and 359 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1808,7 +1808,7 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
text *template;
char *template_str;
int template_len;
bool have_error = false;
ErrorSaveContext escontext = {T_ErrorSaveContext};
jspGetArg(jsp, &elem);
@ -1822,9 +1822,9 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
value = parse_datetime(datetime, template, collid, true,
&typid, &typmod, &tz,
jspThrowErrors(cxt) ? NULL : &have_error);
jspThrowErrors(cxt) ? NULL : (Node *) &escontext);
if (have_error)
if (escontext.error_occurred)
res = jperError;
else
res = jperOk;
@ -1859,7 +1859,7 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
/* loop until datetime format fits */
for (i = 0; i < lengthof(fmt_str); i++)
{
bool have_error = false;
ErrorSaveContext escontext = {T_ErrorSaveContext};
if (!fmt_txt[i])
{
@ -1872,9 +1872,9 @@ executeDateTimeMethod(JsonPathExecContext *cxt, JsonPathItem *jsp,
value = parse_datetime(datetime, fmt_txt[i], collid, true,
&typid, &typmod, &tz,
&have_error);
(Node *) &escontext);
if (!have_error)
if (!escontext.error_occurred)
{
res = jperOk;
break;

View File

@ -28,6 +28,6 @@ extern char *asc_initcap(const char *buff, size_t nbytes);
extern Datum parse_datetime(text *date_txt, text *fmt, Oid collid, bool strict,
Oid *typid, int32 *typmod, int *tz,
bool *have_error);
struct Node *escontext);
#endif