diff --git a/configure.ac b/configure.ac
index 2835ad3..3402b37 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-AC_PREREQ([2.63])
+AC_PREREQ([2.61])
AC_INIT([jansson], [1.0.3+], [pe...@digip.org])
AM_INIT_AUTOMAKE([1.10 foreign])
diff --git a/src/dump.c b/src/dump.c
index 042b0c7..b276bfe 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -13,6 +13,28 @@
#include <jansson.h>
#include "strbuffer.h"
+#ifdef __WIN32
+#include <stdarg.h>
+int vasprintf( char **sptr, char *fmt, va_list argv )
+{
+ int wanted = vsnprintf( *sptr = NULL, 0, fmt, argv );
+ if( (wanted > 0) && ((*sptr = malloc( 1 + wanted )) != NULL) )
+ return vsprintf( *sptr, fmt, argv );
+
+ return wanted;
+}
+
+int asprintf( char **sptr, char *fmt, ... )
+{
+ int retval;
+ va_list argv;
+ va_start( argv, fmt );
+ retval = vasprintf( sptr, fmt, argv );
+ va_end( argv );
+ return retval;
+}
+#endif
+
typedef int (*dump_func)(const char *buffer, int size, void *data);
struct string
--
1.6.4.2
diff --git a/configure.ac b/configure.ac
index 2835ad3..3402b37 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-AC_PREREQ([2.63])
+AC_PREREQ([2.61])
AC_INIT([jansson], [1.0.3+], [pe...@digip.org])
AM_INIT_AUTOMAKE([1.10 foreign])
--
1.6.4.2
BTW, the subject is too long. Please use a shorter one and provide
more information in subsequent lines in commit message.
More comments in-line.
>
> Taken from: http://lists.zerezo.com/mingw-users/msg12649.html
The linked message doesn't provide a copyright notice, so I'm
reluctant to use the code as-is.
Only asprintf is used, so this is a bit overkill. How about using
snprintf directly in asprintf instead of calling (the otherwise
useless) vasprintf?
And the replacement functions should be declared static to not mess up
people's namespaces.
src/dump.c | 27 +++++++++++++--------------
1 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/src/dump.c b/src/dump.c
index 93717ab..dad64f8 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -13,6 +13,9 @@
#include <jansson.h>
#include "strbuffer.h"
+#define MAX_INTEGER_STR_LENGTH 100
+#define MAX_REAL_STR_LENGTH 100
+
typedef int (*dump_func)(const char *buffer, int size, void *data);
struct string
@@ -126,30 +129,26 @@ static int do_dump(const json_t *json, unsigned long flags, int depth,
case JSON_INTEGER:
{
- char *buffer;
- int size, ret;
+ char buffer[MAX_INTEGER_STR_LENGTH];
+ int size;
- size = asprintf(&buffer, "%d", json_integer_value(json));
- if(size == -1)
+ size = snprintf(buffer, MAX_INTEGER_STR_LENGTH, "%d", json_integer_value(json));
+ if(size >= MAX_INTEGER_STR_LENGTH)
return -1;
- ret = dump(buffer, size, data);
- free(buffer);
- return ret;
+ return dump(buffer, size, data);
}
case JSON_REAL:
{
- char *buffer;
- int size, ret;
+ char buffer[MAX_REAL_STR_LENGTH];
+ int size;
- size = asprintf(&buffer, "%.17f", json_real_value(json));
- if(size == -1)
+ size = snprintf(buffer, MAX_REAL_STR_LENGTH, "%0.17f", json_real_value(json));
+ if(size >= MAX_REAL_STR_LENGTH)
return -1;
- ret = dump(buffer, size, data);
- free(buffer);
- return ret;
+ return dump(buffer, size, data);
}
case JSON_STRING:
--
1.6.5
Thanks for the latest Jansson changes! As an extra dropping asprintf
should make Jansson even faster as you don't use anymore subsequent
allocation and free for each int/real value.
Thanks again for great small library,
Regards,
--
Adam