aboutsummaryrefslogtreecommitdiff
path: root/src/include/common/jsonapi.h
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2024-09-11 08:28:35 +0200
committerPeter Eisentraut <peter@eisentraut.org>2024-09-11 09:01:07 +0200
commit0785d1b8b2fa27074eeb18a3ac1f2a0e76cb8339 (patch)
tree188217f29a92589fe70b6fd5be57d2c7e3c9d3eb /src/include/common/jsonapi.h
parent3beb945da9d72a9803180deb1752cf8feeb66883 (diff)
downloadpostgresql-0785d1b8b2fa27074eeb18a3ac1f2a0e76cb8339.tar.gz
postgresql-0785d1b8b2fa27074eeb18a3ac1f2a0e76cb8339.zip
common/jsonapi: support libpq as a client
Based on a patch by Michael Paquier. For libpq, use PQExpBuffer instead of StringInfo. This requires us to track allocation failures so that we can return JSON_OUT_OF_MEMORY as needed rather than exit()ing. Author: Jacob Champion <jacob.champion@enterprisedb.com> Co-authored-by: Michael Paquier <michael@paquier.xyz> Co-authored-by: Daniel Gustafsson <daniel@yesql.se> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Discussion: https://www.postgresql.org/message-id/flat/d1b467a78e0e36ed85a09adf979d04cf124a9d4b.camel@vmware.com
Diffstat (limited to 'src/include/common/jsonapi.h')
-rw-r--r--src/include/common/jsonapi.h18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/include/common/jsonapi.h b/src/include/common/jsonapi.h
index a995fdbe081..c524ff5be8b 100644
--- a/src/include/common/jsonapi.h
+++ b/src/include/common/jsonapi.h
@@ -14,8 +14,6 @@
#ifndef JSONAPI_H
#define JSONAPI_H
-#include "lib/stringinfo.h"
-
typedef enum JsonTokenType
{
JSON_TOKEN_INVALID,
@@ -51,6 +49,7 @@ typedef enum JsonParseErrorType
JSON_EXPECTED_OBJECT_NEXT,
JSON_EXPECTED_STRING,
JSON_INVALID_TOKEN,
+ JSON_OUT_OF_MEMORY,
JSON_UNICODE_CODE_POINT_ZERO,
JSON_UNICODE_ESCAPE_FORMAT,
JSON_UNICODE_HIGH_ESCAPE,
@@ -65,6 +64,16 @@ typedef struct JsonParserStack JsonParserStack;
typedef struct JsonIncrementalState JsonIncrementalState;
/*
+ * Don't depend on the internal type header for strval; if callers need access
+ * then they can include the appropriate header themselves.
+ */
+#ifdef JSONAPI_USE_PQEXPBUFFER
+#define jsonapi_StrValType PQExpBufferData
+#else
+#define jsonapi_StrValType StringInfoData
+#endif
+
+/*
* All the fields in this structure should be treated as read-only.
*
* If strval is not null, then it should contain the de-escaped value
@@ -102,8 +111,9 @@ typedef struct JsonLexContext
const char *line_start; /* where that line starts within input */
JsonParserStack *pstack;
JsonIncrementalState *inc_state;
- StringInfo strval;
- StringInfo errormsg;
+ bool need_escapes;
+ struct jsonapi_StrValType *strval; /* only used if need_escapes == true */
+ struct jsonapi_StrValType *errormsg;
} JsonLexContext;
typedef JsonParseErrorType (*json_struct_action) (void *state);