26.10.2013 13:17, Pavel Levshin:

Is it declared somewhere which integer size rsyslog does support? There is a inconsistence between internal number representation, which is signed long long, and JSON-c integers, which is signed int only. So you can use integers in range -2^63 .. 2^63-1 for RainerScript expressions, but variables can hold no more than -2^31 .. 2^31-1.

This appears to be easy to fix. Json-c supports int64 from and uses them internally in any case.

Note that this patch requires json-c >= 0.10.

Ommongodb seems to be prepared for int64, but I haven't tested it. Other modules, notably mmcount, left unchanged.

After the patch:

set $!min = -2147483648;
set $!max = 2147483647;
set $!under = -2147483648 - 1;
set $!over = 2147483647 + 1;
set $!under_s = cstr(-2147483648 - 1);
set $!over_s = cstr(2147483647 + 1);

"min": -2147483648, "max": 2147483647, "under": -2147483649, "over": 2147483648, "under_s": "-2147483650", "over_s": "2147483649"

set $!under_sj = "-1000000000000";
set $!over_sj = "1000000000000";
set $!under_sjn = cstr(cnum($!under_sj));
set $!over_sjn = cstr(cnum($!over_sj));
set $!under_sn = cstr(cnum("-1000000000000"));
set $!over_sn = cstr(cnum("-1000000000000"));

"under_sj": "-1000000000000", "over_sj": "1000000000000", "under_sjn": "-1000000000000", "over_sjn": "1000000000000", "under_sn": "-1000000000000", "over_sn": "-1000000000000"


--
Pavel Levshin

>From 4d7951f4b080656f6af155b5a396d13e8a60c799 Mon Sep 17 00:00:00 2001
From: Pavel Levshin <[email protected]>
Date: Sat, 26 Oct 2013 14:57:37 +0400
Subject: [PATCH] Make use of int64 json numbers

---
 configure.ac                  |    4 ++--
 grammar/rainerscript.c        |    2 +-
 plugins/ommongodb/ommongodb.c |    3 +--
 runtime/msg.c                 |    4 ++--
 4 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/configure.ac b/configure.ac
index 2f23147..108520d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,8 +33,8 @@ PKG_PROG_PKG_CONFIG
 
 # modules we require
 PKG_CHECK_MODULES(LIBESTR, libestr >= 0.1.8)
-PKG_CHECK_MODULES([JSON_C], [json],, [
-       PKG_CHECK_MODULES([JSON_C], [json-c])
+PKG_CHECK_MODULES([JSON_C], [json >= 0.10],, [
+       PKG_CHECK_MODULES([JSON_C], [json-c >= 0.10])
 ])
 
 case "${host}" in
diff --git a/grammar/rainerscript.c b/grammar/rainerscript.c
index 37f3509..6dc6eb1 100644
--- a/grammar/rainerscript.c
+++ b/grammar/rainerscript.c
@@ -1192,7 +1192,7 @@ var2Number(struct var *r, int *bSuccess)
                n = es_str2num(r->d.estr, bSuccess);
        } else {
                if(r->datatype == 'J') {
-                       n = (r->d.json == NULL) ? 0 : 
json_object_get_int(r->d.json);
+                       n = (r->d.json == NULL) ? 0 : 
json_object_get_int64(r->d.json);
                } else {
                        n = r->d.n;
                }
diff --git a/plugins/ommongodb/ommongodb.c b/plugins/ommongodb/ommongodb.c
index 78781c0..afd2d35 100644
--- a/plugins/ommongodb/ommongodb.c
+++ b/plugins/ommongodb/ommongodb.c
@@ -317,8 +317,7 @@ BSONAppendJSONObject(bson *doc, const gchar *name, struct 
json_object *json)
        case json_type_int: {
                int64_t i;
 
-               /* FIXME: the future version will have get_int64 */
-               i = json_object_get_int(json);
+               i = json_object_get_int64(json);
                if (i >= INT32_MIN && i <= INT32_MAX)
                        return bson_append_int32(doc, name, i);
                else
diff --git a/runtime/msg.c b/runtime/msg.c
index d173644..7a8045b 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -4049,7 +4049,7 @@ jsonDeepCopy(struct json_object *src)
                dst = json_object_new_double(json_object_get_double(src));
                break;
        case json_type_int:
-               dst = json_object_new_int(json_object_get_int(src));
+               dst = json_object_new_int64(json_object_get_int64(src));
                break;
        case json_type_string:
                dst = json_object_new_string(json_object_get_string(src));
@@ -4092,7 +4092,7 @@ msgSetJSONFromVar(msg_t *pMsg, uchar *varname, struct var 
*v)
                free(cstr);
                break;
        case 'N':/* number (integer) */
-               json = json_object_new_int((int) v->d.n);
+               json = json_object_new_int64(v->d.n);
                break;
        case 'J':/* native JSON */
                json = jsonDeepCopy(v->d.json);
-- 
1.7.9.5

_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards
NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad of 
sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you DON'T LIKE 
THAT.

Reply via email to