diff options
| author | Tom Lane | 2017-03-13 21:14:46 +0000 |
|---|---|---|
| committer | Tom Lane | 2017-03-13 21:14:46 +0000 |
| commit | 895e36bb3f36fdb7ec8e573be1a20d104fac820b (patch) | |
| tree | 0174e31cf8b59bc4ae31f314f323642bcc06bda7 /src/fe_utils | |
| parent | 1c7a66a8e9378aeb092d7ed26890134d17fdd691 (diff) | |
Add a "void *" passthrough pointer for psqlscan.l's callback functions.
The immediate motivation for this is to provide clean infrastructure
for the proposed \if...\endif patch for psql; but it seems like a good
thing to have even if that patch doesn't get in. Previously the callback
functions could only make use of application-global state, which is a
pretty severe handicap.
For the moment, the pointer is only passed through to the get_variable
callback function. I considered also passing it to the write_error
callback, but for now let's not. Neither psql nor pgbench has a use
for that, and in the case of psql we'd have to invent a separate wrapper
function because we would certainly not want to change the signature of
psql_error().
Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'src/fe_utils')
| -rw-r--r-- | src/fe_utils/psqlscan.l | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/fe_utils/psqlscan.l b/src/fe_utils/psqlscan.l index 1b29341fa87..19b3e57aa45 100644 --- a/src/fe_utils/psqlscan.l +++ b/src/fe_utils/psqlscan.l @@ -700,7 +700,8 @@ other . if (cur_state->callbacks->get_variable) value = cur_state->callbacks->get_variable(varname, false, - false); + false, + cur_state->cb_passthrough); else value = NULL; @@ -923,6 +924,19 @@ psql_scan_destroy(PsqlScanState state) } /* + * Set the callback passthrough pointer for the lexer. + * + * This could have been integrated into psql_scan_create, but keeping it + * separate allows the application to change the pointer later, which might + * be useful. + */ +void +psql_scan_set_passthrough(PsqlScanState state, void *passthrough) +{ + state->cb_passthrough = passthrough; +} + +/* * Set up to perform lexing of the given input line. * * The text at *line, extending for line_len bytes, will be scanned by @@ -1409,7 +1423,8 @@ psqlscan_escape_variable(PsqlScanState state, const char *txt, int len, /* Variable lookup. */ varname = psqlscan_extract_substring(state, txt + 2, len - 3); if (state->callbacks->get_variable) - value = state->callbacks->get_variable(varname, true, as_ident); + value = state->callbacks->get_variable(varname, true, as_ident, + state->cb_passthrough); else value = NULL; free(varname); |
