Adjust src/include/utils/jsonapi.h so it's not backend-only.
authorRobert Haas <rhaas@postgresql.org>
Fri, 24 Jan 2020 17:58:37 +0000 (09:58 -0800)
committerRobert Haas <rhaas@postgresql.org>
Fri, 24 Jan 2020 17:58:37 +0000 (09:58 -0800)
The major change here is that we no longer include jsonb.h into
jsonapi.h. The reason that was necessary is that jsonapi.h included
several prototypes functions in jsonfuncs.c that depend on the Jsonb
type. Move those prototypes to a new header, jsonfuncs.h, and include
it where needed.

The other change is that JsonEncodeDateTime is now declared in
json.h rather than jsonapi.h.

Taken together, these steps eliminate all dependencies of jsonapi.h
on backend-only data types and header files, so that it can
potentially be included in frontend code.

src/backend/tsearch/to_tsany.c
src/backend/tsearch/wparser.c
src/backend/utils/adt/jsonb_util.c
src/backend/utils/adt/jsonfuncs.c
src/include/utils/json.h
src/include/utils/jsonapi.h
src/include/utils/jsonfuncs.h [new file with mode: 0644]

index cc694cda8cdd4dc255d8a0b5ed9409ad2886eb53..adf181c191f3d98c1c3ad78f9cf27b8ecd3d2744 100644 (file)
@@ -17,6 +17,7 @@
 #include "tsearch/ts_utils.h"
 #include "utils/builtins.h"
 #include "utils/jsonapi.h"
+#include "utils/jsonfuncs.h"
 
 
 typedef struct MorphOpaque
index 6b5960ecc152c6efbf4895d44821a5c654b0ff07..c7499a94ac61934d6788bd1a8cc64543429a1531 100644 (file)
@@ -21,6 +21,7 @@
 #include "tsearch/ts_utils.h"
 #include "utils/builtins.h"
 #include "utils/jsonapi.h"
+#include "utils/jsonfuncs.h"
 #include "utils/varlena.h"
 
 /******sql-level interface******/
index 7c9da701dddc69399af2d7d60b0d774fa84a3217..b33c3ef43ce163b3d171088b251282f8582530fd 100644 (file)
@@ -19,6 +19,7 @@
 #include "utils/builtins.h"
 #include "utils/datetime.h"
 #include "utils/hashutils.h"
+#include "utils/json.h"
 #include "utils/jsonapi.h"
 #include "utils/jsonb.h"
 #include "utils/memutils.h"
index 38758a626b2ff6973b8568000fc3c3f984984b76..2f9955d665ada7ba880790631df281f4e87f26af 100644 (file)
@@ -29,6 +29,7 @@
 #include "utils/json.h"
 #include "utils/jsonapi.h"
 #include "utils/jsonb.h"
+#include "utils/jsonfuncs.h"
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
 #include "utils/syscache.h"
index 20b5294491936053f87be70c077c179f53d570ff..4345fbdc31632c1a50183d4794615fb11847e6b1 100644 (file)
@@ -18,5 +18,7 @@
 
 /* functions in json.c */
 extern void escape_json(StringInfo buf, const char *str);
+extern char *JsonEncodeDateTime(char *buf, Datum value, Oid typid,
+                               const int *tzp);
 
 #endif                         /* JSON_H */
index f72f1cefd5ff4d6a6b6435cc7d4b67620ebe2632..1190947476694619cdab1b18160d8ce844bb43d6 100644 (file)
@@ -14,7 +14,6 @@
 #ifndef JSONAPI_H
 #define JSONAPI_H
 
-#include "jsonb.h"
 #include "lib/stringinfo.h"
 
 typedef enum
@@ -132,36 +131,4 @@ extern JsonLexContext *makeJsonLexContextCstringLen(char *json,
  */
 extern bool IsValidJsonNumber(const char *str, int len);
 
-/*
- * Flag types for iterate_json(b)_values to specify what elements from a
- * json(b) document we want to iterate.
- */
-typedef enum JsonToIndex
-{
-   jtiKey = 0x01,
-   jtiString = 0x02,
-   jtiNumeric = 0x04,
-   jtiBool = 0x08,
-   jtiAll = jtiKey | jtiString | jtiNumeric | jtiBool
-} JsonToIndex;
-
-/* an action that will be applied to each value in iterate_json(b)_values functions */
-typedef void (*JsonIterateStringValuesAction) (void *state, char *elem_value, int elem_len);
-
-/* an action that will be applied to each value in transform_json(b)_values functions */
-typedef text *(*JsonTransformStringValuesAction) (void *state, char *elem_value, int elem_len);
-
-extern uint32 parse_jsonb_index_flags(Jsonb *jb);
-extern void iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state,
-                                JsonIterateStringValuesAction action);
-extern void iterate_json_values(text *json, uint32 flags, void *action_state,
-                               JsonIterateStringValuesAction action);
-extern Jsonb *transform_jsonb_string_values(Jsonb *jsonb, void *action_state,
-                                           JsonTransformStringValuesAction transform_action);
-extern text *transform_json_string_values(text *json, void *action_state,
-                                         JsonTransformStringValuesAction transform_action);
-
-extern char *JsonEncodeDateTime(char *buf, Datum value, Oid typid,
-                               const int *tzp);
-
 #endif                         /* JSONAPI_H */
diff --git a/src/include/utils/jsonfuncs.h b/src/include/utils/jsonfuncs.h
new file mode 100644 (file)
index 0000000..19f087c
--- /dev/null
@@ -0,0 +1,49 @@
+/*-------------------------------------------------------------------------
+ *
+ * jsonfuncs.h
+ *   Functions to process JSON data types.
+ *
+ * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/utils/jsonapi.h
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#ifndef JSONFUNCS_H
+#define JSONFUNCS_H
+
+#include "utils/jsonapi.h"
+#include "utils/jsonb.h"
+
+/*
+ * Flag types for iterate_json(b)_values to specify what elements from a
+ * json(b) document we want to iterate.
+ */
+typedef enum JsonToIndex
+{
+   jtiKey = 0x01,
+   jtiString = 0x02,
+   jtiNumeric = 0x04,
+   jtiBool = 0x08,
+   jtiAll = jtiKey | jtiString | jtiNumeric | jtiBool
+} JsonToIndex;
+
+/* an action that will be applied to each value in iterate_json(b)_values functions */
+typedef void (*JsonIterateStringValuesAction) (void *state, char *elem_value, int elem_len);
+
+/* an action that will be applied to each value in transform_json(b)_values functions */
+typedef text *(*JsonTransformStringValuesAction) (void *state, char *elem_value, int elem_len);
+
+extern uint32 parse_jsonb_index_flags(Jsonb *jb);
+extern void iterate_jsonb_values(Jsonb *jb, uint32 flags, void *state,
+                                JsonIterateStringValuesAction action);
+extern void iterate_json_values(text *json, uint32 flags, void *action_state,
+                               JsonIterateStringValuesAction action);
+extern Jsonb *transform_jsonb_string_values(Jsonb *jsonb, void *action_state,
+                                           JsonTransformStringValuesAction transform_action);
+extern text *transform_json_string_values(text *json, void *action_state,
+                                         JsonTransformStringValuesAction transform_action);
+
+#endif