diff options
author | Thomas Munro <tmunro@postgresql.org> | 2023-04-08 21:57:46 +1200 |
---|---|---|
committer | Thomas Munro <tmunro@postgresql.org> | 2023-04-08 22:10:39 +1200 |
commit | db4f21e4a34b1d5a3f7123e28e77f575d1a971ea (patch) | |
tree | 16cd41226f81b111ed78c0ac9f0c917e8e54125f /src/include/regex/regguts.h | |
parent | 6db75edb2ecbc9f6912f90b671b01ab4ac3a01b0 (diff) | |
download | postgresql-db4f21e4a34b1d5a3f7123e28e77f575d1a971ea.tar.gz postgresql-db4f21e4a34b1d5a3f7123e28e77f575d1a971ea.zip |
Redesign interrupt/cancel API for regex engine.
Previously, a PostgreSQL-specific callback checked by the regex engine
had a way to trigger a special error code REG_CANCEL if it detected that
the next call to CHECK_FOR_INTERRUPTS() would certainly throw via
ereport().
A later proposed bugfix aims to move some complex logic out of signal
handlers, so that it won't run until the next CHECK_FOR_INTERRUPTS(),
which makes the above design impossible unless we split
CHECK_FOR_INTERRUPTS() into two phases, one to run logic and another to
ereport(). We may develop such a system in the future, but for the
regex code it is no longer necessary.
An earlier commit moved regex memory management over to our
MemoryContext system. Given that the purpose of the two-phase interrupt
checking was to free memory before throwing, something we don't need to
worry about anymore, it seems simpler to inject CHECK_FOR_INTERRUPTS()
directly into cancelation points, and just let it throw.
Since the plan is to keep PostgreSQL-specific concerns separate from the
main regex engine code (with a view to bein able to stay in sync with
other projects), do this with a new macro INTERRUPT(), customizable in
regcustom.h and defaulting to nothing.
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CA%2BhUKGK3PGKwcKqzoosamn36YW-fsuTdOPPF1i_rtEO%3DnEYKSg%40mail.gmail.com
Diffstat (limited to 'src/include/regex/regguts.h')
-rw-r--r-- | src/include/regex/regguts.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/include/regex/regguts.h b/src/include/regex/regguts.h index 91a52840c47..3ca3647e118 100644 --- a/src/include/regex/regguts.h +++ b/src/include/regex/regguts.h @@ -77,6 +77,11 @@ #define FREE(p) free(VS(p)) #endif +/* interruption */ +#ifndef INTERRUPT +#define INTERRUPT(re) +#endif + /* want size of a char in bits, and max value in bounded quantifiers */ #ifndef _POSIX2_RE_DUP_MAX #define _POSIX2_RE_DUP_MAX 255 /* normally from <limits.h> */ @@ -510,13 +515,9 @@ struct subre struct fns { void FUNCPTR(free, (regex_t *)); - int FUNCPTR(cancel_requested, (void)); int FUNCPTR(stack_too_deep, (void)); }; -#define CANCEL_REQUESTED(re) \ - ((*((struct fns *) (re)->re_fns)->cancel_requested) ()) - #define STACK_TOO_DEEP(re) \ ((*((struct fns *) (re)->re_fns)->stack_too_deep) ()) |