From: Vsevolod Stakhov Date: Tue, 15 Oct 2013 12:55:09 +0000 (+0100) Subject: Add comparasion for rcl vs jansson. X-Git-Tag: 0.6.0~119 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=293ea2757b49fd5348c14b2fb178a2dcddced1f7;p=rspamd.git Add comparasion for rcl vs jansson. Fix some issues in jansson memory management. --- diff --git a/src/json/dump.c b/src/json/dump.c index f384760c5..7e4383abe 100644 --- a/src/json/dump.c +++ b/src/json/dump.c @@ -143,7 +143,7 @@ do_dump (const json_t * json, uint32_t flags, int depth, dump_func dump, void *d return -1; ret = dump (buffer, size, data); - g_free (buffer); + free (buffer); return ret; } @@ -157,7 +157,7 @@ do_dump (const json_t * json, uint32_t flags, int depth, dump_func dump, void *d return -1; ret = dump (buffer, size, data); - g_free (buffer); + free (buffer); return ret; } diff --git a/src/json/strbuffer.c b/src/json/strbuffer.c index 1ae336d3d..3fa1a92da 100644 --- a/src/json/strbuffer.c +++ b/src/json/strbuffer.c @@ -75,7 +75,7 @@ strbuffer_append_bytes (strbuffer_t * strbuff, const char *data, int size) if (strbuff->length + size >= strbuff->size) { strbuff->size = max (strbuff->size * STRBUFFER_FACTOR, strbuff->length + size + 1); - strbuff->value = realloc (strbuff->value, strbuff->size); + strbuff->value = g_realloc (strbuff->value, strbuff->size); if (!strbuff->value) return -1; } diff --git a/test/rspamd_rcl_test.c b/test/rspamd_rcl_test.c index 2a93169a6..778340890 100644 --- a/test/rspamd_rcl_test.c +++ b/test/rspamd_rcl_test.c @@ -21,9 +21,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "../src/config.h" -#include "../src/rcl/rcl.h" -#include "../src/main.h" +#include "config.h" +#include "rcl/rcl.h" +#include "main.h" +#include "json/jansson.h" #include "tests.h" const gchar *rcl_test_valid[] = { @@ -105,6 +106,8 @@ rspamd_rcl_test_func (void) GError *err = NULL; struct timespec start, end; gdouble seconds; + json_t *json; + json_error_t jerr; cur = rcl_test_valid; while (*cur != NULL) { @@ -162,14 +165,32 @@ rspamd_rcl_test_func (void) g_assert_no_error (err); clock_gettime (CLOCK_MONOTONIC, &end); seconds = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000000000.; - msg_info ("parsed json in %.4f seconds", seconds); + msg_info ("rcl: parsed json in %.4f seconds", seconds); /* Test config emitting */ clock_gettime (CLOCK_MONOTONIC, &start); emitted = rspamd_cl_object_emit (obj, RSPAMD_CL_EMIT_CONFIG); g_assert (emitted != NULL); clock_gettime (CLOCK_MONOTONIC, &end); seconds = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000000000.; - msg_info ("emitted object in %.4f seconds", seconds); + msg_info ("rcl: emitted object in %.4f seconds", seconds); rspamd_cl_parser_free (parser); rspamd_cl_obj_unref (obj); + g_free (emitted); + + clock_gettime (CLOCK_MONOTONIC, &start); + json = json_load_file ("./rcl_test.json", &jerr); + g_assert (json != NULL); + clock_gettime (CLOCK_MONOTONIC, &end); + seconds = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000000000.; + msg_info ("jansson: parsed json in %.4f seconds", seconds); + + clock_gettime (CLOCK_MONOTONIC, &start); + emitted = json_dumps (json, 0); + g_assert (emitted != NULL); + clock_gettime (CLOCK_MONOTONIC, &end); + seconds = (end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec) / 1000000000.; + msg_info ("jansson: emitted object in %.4f seconds", seconds); + + //json_decref (json); + g_free (emitted); }