]> sourceware.org Git - glibc.git/commitdiff
benchtests: Print string array elements, int and uint in json
authorSiddhesh Poyarekar <siddhesh@sourceware.org>
Thu, 22 Jun 2017 18:14:12 +0000 (23:44 +0530)
committerSiddhesh Poyarekar <siddhesh@sourceware.org>
Thu, 22 Jun 2017 18:14:12 +0000 (23:44 +0530)
Enhance the json module in benchtests to print signed and unsigned
integers and string array elements.

* benchtests/json-lib.h: Include inttypes.h.
(json_attr_int, json_attr_int, json_element_string,
json_element_int, json_element_uint): New functions.
* benchtests/json-lib.c: (json_attr_int, json_attr_int,
json_element_string, json_element_int, json_element_uint): New
functions.

benchtests/json-lib.c
benchtests/json-lib.h

index 61573c579a41400147dc0031c52c14346a966c82..9743506c00b6999cbdc862b6246551d6ab25060b 100644 (file)
@@ -100,6 +100,32 @@ json_attr_string (json_ctx_t *ctx, const char *name, const char *s)
   fprintf (ctx->fp, "\"%s\": \"%s\"", name, s);
 }
 
+void
+json_attr_uint (json_ctx_t *ctx, const char *name, uint64_t d)
+{
+  if (!ctx->first_element)
+    fprintf (ctx->fp, ",\n");
+  else
+    ctx->first_element = false;
+
+  do_indent (ctx);
+
+  fprintf (ctx->fp, "\"%s\": %" PRIu64 , name, d);
+}
+
+void
+json_attr_int (json_ctx_t *ctx, const char *name, int64_t d)
+{
+  if (!ctx->first_element)
+    fprintf (ctx->fp, ",\n");
+  else
+    ctx->first_element = false;
+
+  do_indent (ctx);
+
+  fprintf (ctx->fp, "\"%s\": %" PRId64 , name, d);
+}
+
 void
 json_attr_double (json_ctx_t *ctx, const char *name, double d)
 {
@@ -136,6 +162,42 @@ json_array_end (json_ctx_t *ctx)
   fputs ("]", ctx->fp);
 }
 
+void
+json_element_string (json_ctx_t *ctx, const char *s)
+{
+  if (!ctx->first_element)
+    fprintf (ctx->fp, ", \"%s\"", s);
+  else
+    {
+      fprintf (ctx->fp, "\"%s\"", s);
+      ctx->first_element = false;
+    }
+}
+
+void
+json_element_uint (json_ctx_t *ctx, uint64_t d)
+{
+  if (!ctx->first_element)
+    fprintf (ctx->fp, ", %" PRIu64, d);
+  else
+    {
+      fprintf (ctx->fp, "%" PRIu64, d);
+      ctx->first_element = false;
+    }
+}
+
+void
+json_element_int (json_ctx_t *ctx, int64_t d)
+{
+  if (!ctx->first_element)
+    fprintf (ctx->fp, ", %" PRId64, d);
+  else
+    {
+      fprintf (ctx->fp, "%" PRId64, d);
+      ctx->first_element = false;
+    }
+}
+
 void
 json_element_double (json_ctx_t *ctx, double d)
 {
index 8a4e5917403cd120fc1e62ef70361ab0edca4e1c..b3df4b560b809a733f5dab3ee4e9543ee2f9ea65 100644 (file)
@@ -20,6 +20,7 @@
 #define __JSON_LIB_H__
 
 #include <stdbool.h>
+#include <inttypes.h>
 #include <stdio.h>
 
 struct json_ctx
@@ -37,9 +38,14 @@ void json_document_end (json_ctx_t *ctx);
 void json_attr_object_begin (json_ctx_t *ctx, const char *name);
 void json_attr_object_end (json_ctx_t *ctx);
 void json_attr_string (json_ctx_t *ctx, const char *name, const char *s);
+void json_attr_int (json_ctx_t *ctx, const char *name, int64_t d);
+void json_attr_uint (json_ctx_t *ctx, const char *name, uint64_t d);
 void json_attr_double (json_ctx_t *ctx, const char *name, double d);
 void json_array_begin (json_ctx_t *ctx, const char *name);
 void json_array_end (json_ctx_t *ctx);
+void json_element_string (json_ctx_t *ctx, const char *s);
+void json_element_int (json_ctx_t *ctx, int64_t d);
+void json_element_uint (json_ctx_t *ctx, uint64_t d);
 void json_element_double (json_ctx_t *ctx, double d);
 void json_element_object_begin (json_ctx_t *ctx);
 void json_element_object_end (json_ctx_t *ctx);
This page took 0.043395 seconds and 5 git commands to generate.