Module: kamailio
Branch: master
Commit: ecd22245336f2d3d6d2f9404ebfdd4369f19bd97
URL:
https://github.com/kamailio/kamailio/commit/ecd22245336f2d3d6d2f9404ebfdd43…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2016-10-31T20:10:36+01:00
lib/srutils: removed valueint field from json struct
- numbers are stored in the valuedouble
- helper macros added to retrivie fixed type numbers
---
Modified: lib/srutils/srjson.c
Modified: lib/srutils/srjson.h
---
Diff:
https://github.com/kamailio/kamailio/commit/ecd22245336f2d3d6d2f9404ebfdd43…
Patch:
https://github.com/kamailio/kamailio/commit/ecd22245336f2d3d6d2f9404ebfdd43…
---
diff --git a/lib/srutils/srjson.c b/lib/srutils/srjson.c
index b8c1945..fdaf87a 100644
--- a/lib/srutils/srjson.c
+++ b/lib/srutils/srjson.c
@@ -193,7 +193,6 @@ static const char *parse_number(srjson_doc_t *doc, srjson_t *item,
const char *n
* 10^+/- exponent */
item->valuedouble = n;
- item->valueint = (int) n;
item->type = srjson_Number;
return num;
}
@@ -203,12 +202,13 @@ static char *print_number(srjson_doc_t *doc, srjson_t *item)
{
char *str;
double d = item->valuedouble;
- if (fabs(((double) item->valueint) - d) <= DBL_EPSILON && d <= INT_MAX
&& d >= INT_MIN) {
+ int i = (int)d;
+ if (fabs(((double) i) - d) <= DBL_EPSILON && d <= INT_MAX && d
>= INT_MIN) {
str = (char *) doc->malloc_fn(21); /* 2^64+1 can be
* represented in 21
* chars. */
if (str)
- sprintf(str, "%d", item->valueint);
+ sprintf(str, "%d", i);
} else {
str = (char *) doc->malloc_fn(64); /* This is a nice
* tradeoff. */
@@ -452,7 +452,6 @@ static const char *parse_value(srjson_doc_t *doc, srjson_t *item,
const char *va
}
if (!strncmp(value, "true", 4)) {
item->type = srjson_True;
- item->valueint = 1;
return value + 4;
}
if (*value == '\"') {
@@ -956,7 +955,6 @@ srjson_t *srjson_CreateNumber(srjson_doc_t *doc, double num) {
if (item) {
item->type = srjson_Number;
item->valuedouble = num;
- item->valueint = (int) num;
} return item;
}
diff --git a/lib/srutils/srjson.h b/lib/srutils/srjson.h
index 02d65d7..c46f121 100644
--- a/lib/srutils/srjson.h
+++ b/lib/srutils/srjson.h
@@ -47,6 +47,13 @@ extern "C"
#define srjson_IsReference 256
+/* helper macros */
+
+#define SRJSON_GET_INT(sj) ((int)((sj)->valuedouble))
+#define SRJSON_GET_UINT(sj) ((unsigned int)((sj)->valuedouble))
+#define SRJSON_GET_LONG(sj) ((long)((sj)->valuedouble))
+#define SRJSON_GET_ULONG(sj) ((unsigned long)((sj)->valuedouble))
+
/* The srjson node structure: */
typedef struct srjson {
struct srjson *parent;
@@ -64,8 +71,6 @@ typedef struct srjson {
int type; /* The type of the item, as above. */
char *valuestring; /* The item's string, if
* type==srjson_String */
- int valueint; /* The item's number, if
- * type==srjson_Number */
double valuedouble; /* The item's number, if
* type==srjson_Number */
char *string; /* The item's name string, if this