aboutsummaryrefslogtreecommitdiff
path: root/src/include/fe_utils
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-03-13 17:14:46 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2017-03-13 17:14:46 -0400
commit895e36bb3f36fdb7ec8e573be1a20d104fac820b (patch)
tree0174e31cf8b59bc4ae31f314f323642bcc06bda7 /src/include/fe_utils
parent1c7a66a8e9378aeb092d7ed26890134d17fdd691 (diff)
downloadpostgresql-895e36bb3f36fdb7ec8e573be1a20d104fac820b.tar.gz
postgresql-895e36bb3f36fdb7ec8e573be1a20d104fac820b.zip
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/10108.1489418309@sss.pgh.pa.us
Diffstat (limited to 'src/include/fe_utils')
-rw-r--r--src/include/fe_utils/psqlscan.h5
-rw-r--r--src/include/fe_utils/psqlscan_int.h4
2 files changed, 7 insertions, 2 deletions
diff --git a/src/include/fe_utils/psqlscan.h b/src/include/fe_utils/psqlscan.h
index 21c4f227a13..0cc632b821b 100644
--- a/src/include/fe_utils/psqlscan.h
+++ b/src/include/fe_utils/psqlscan.h
@@ -53,7 +53,8 @@ typedef struct PsqlScanCallbacks
{
/* Fetch value of a variable, as a pfree'able string; NULL if unknown */
/* This pointer can be NULL if no variable substitution is wanted */
- char *(*get_variable) (const char *varname, bool escape, bool as_ident);
+ char *(*get_variable) (const char *varname, bool escape,
+ bool as_ident, void *passthrough);
/* Print an error message someplace appropriate */
/* (very old gcc versions don't support attributes on function pointers) */
#if defined(__GNUC__) && __GNUC__ < 4
@@ -67,6 +68,8 @@ typedef struct PsqlScanCallbacks
extern PsqlScanState psql_scan_create(const PsqlScanCallbacks *callbacks);
extern void psql_scan_destroy(PsqlScanState state);
+extern void psql_scan_set_passthrough(PsqlScanState state, void *passthrough);
+
extern void psql_scan_setup(PsqlScanState state,
const char *line, int line_len,
int encoding, bool std_strings);
diff --git a/src/include/fe_utils/psqlscan_int.h b/src/include/fe_utils/psqlscan_int.h
index 0fddc7a8564..b4044e806a8 100644
--- a/src/include/fe_utils/psqlscan_int.h
+++ b/src/include/fe_utils/psqlscan_int.h
@@ -115,9 +115,11 @@ typedef struct PsqlScanStateData
char *dolqstart; /* current $foo$ quote start string */
/*
- * Callback functions provided by the program making use of the lexer.
+ * Callback functions provided by the program making use of the lexer,
+ * plus a void* callback passthrough argument.
*/
const PsqlScanCallbacks *callbacks;
+ void *cb_passthrough;
} PsqlScanStateData;