Browse Source

Merge remote-tracking branch 'upstream/master'

pull/354/head
Maarten Billemont 8 years ago
parent
commit
3e5ad38a83
8 changed files with 88 additions and 26 deletions
  1. +1
    -0
      CMakeLists.txt
  2. +39
    -7
      Makefile.am
  3. +5
    -7
      json_object.c
  4. +4
    -7
      json_util.c
  5. +1
    -0
      printbuf.c
  6. +36
    -0
      snprintf_compat.h
  7. +1
    -0
      tests/test_locale.c
  8. +1
    -5
      vasprintf_compat.h

+ 1
- 0
CMakeLists.txt View File

@@ -67,6 +67,7 @@ set(JSON_C_SOURCES
./linkhash.c
./printbuf.c
./random_seed.c
./strerror_override.c
)

add_library(json-c


+ 39
- 7
Makefile.am View File

@@ -1,6 +1,6 @@
EXTRA_DIST = README.md README.html README-WIN32.html
EXTRA_DIST += config.h.win32 json-c.vcproj json-c.vcxproj json-c.vcxproj.filters
EXTRA_DIST += Doxyfile doc
EXTRA_DIST += Doxyfile

dist-hook:
test -d "$(distdir)/doc" || mkdir "$(distdir)/doc"
@@ -35,7 +35,8 @@ libjson_cinclude_HEADERS = \
strdup_compat.h \
vasprintf_compat.h \
printbuf.h \
random_seed.h
random_seed.h \
strerror_override.h

libjson_c_la_LDFLAGS = -version-info 3:0:0 -no-undefined @JSON_BSYMBOLIC_LDFLAGS@

@@ -52,15 +53,46 @@ libjson_c_la_SOURCES = \
linkhash.c \
printbuf.c \
random_seed.c \
strerror_override.c
strerror_override.c \
strerror_override_private.h


DISTCLEANFILES=
DISTCLEANFILES+= \
config.h \
json-c-uninstalled.pc \
json-c.pc \
json_config.h

distclean-local:
-rm -rf $(testsubdir)
-rm -rf config.h.in~ Makefile.in aclocal.m4 autom4te.cache/ config.guess config.sub depcomp install-sh ltmain.sh missing
-rm -f INSTALL test-driver tests/Makefile.in compile

maintainer-clean-local:
-rm -rf configure
JSON_CLEANFILES=
JSON_CLEANFILES+= \
Makefile.in \
aclocal.m4 \
autom4te.cache/ \
compile \
config.guess \
config.h.in \
config.sub \
configure \
depcomp \
install-sh \
ltmain.sh \
missing \
test-driver \
tests/Makefile.in
JSON_CLEANFILES+= \
libtool \
stamp-h1 \
stamp-h2

# There's no built-in way to remove these after all the other
# maintainer-clean steps happen, so do it explicitly here.
really-clean:
$(MAKE) maintainer-clean
rm -rf ${JSON_CLEANFILES}

uninstall-local:
rm -rf "$(DESTDIR)@includedir@/json-c"


+ 5
- 7
json_object.c View File

@@ -31,13 +31,7 @@
#include "json_util.h"
#include "math_compat.h"
#include "strdup_compat.h"

#if !defined(HAVE_SNPRINTF) && defined(_MSC_VER)
/* MSC has the version as _snprintf */
# define snprintf _snprintf
#elif !defined(HAVE_SNPRINTF)
# error You do not have snprintf on your system.
#endif /* HAVE_SNPRINTF */
#include "snprintf_compat.h"

// Don't define this. It's not thread-safe.
/* #define REFCOUNT_DEBUG 1 */
@@ -635,6 +629,10 @@ int32_t json_object_get_int(const struct json_object *jso)
return INT32_MAX;
return (int32_t) cint64;
case json_type_double:
if (jso->o.c_double <= INT32_MIN)
return INT32_MIN;
if (jso->o.c_double >= INT32_MAX)
return INT32_MAX;
return (int32_t)jso->o.c_double;
case json_type_boolean:
return jso->o.c_boolean;


+ 4
- 7
json_util.c View File

@@ -48,12 +48,7 @@
# define open _open
#endif

#if !defined(HAVE_SNPRINTF) && defined(_MSC_VER)
/* MSC has the version as _snprintf */
# define snprintf _snprintf
#elif !defined(HAVE_SNPRINTF)
# error You do not have snprintf on your system.
#endif /* HAVE_SNPRINTF */
#include "snprintf_compat.h"

#include "debug.h"
#include "printbuf.h"
@@ -195,7 +190,9 @@ int json_object_to_file(const char *filename, struct json_object *obj)

int json_parse_double(const char *buf, double *retval)
{
return (sscanf(buf, "%lf", retval)==1 ? 0 : 1);
char *end;
*retval = strtod(buf, &end);
return end == buf ? 1 : 0;
}

/*


+ 1
- 0
printbuf.c View File

@@ -27,6 +27,7 @@

#include "debug.h"
#include "printbuf.h"
#include "snprintf_compat.h"
#include "vasprintf_compat.h"

static int printbuf_extend(struct printbuf *p, int min_size);


+ 36
- 0
snprintf_compat.h View File

@@ -0,0 +1,36 @@
#ifndef __snprintf_compat_h
#define __snprintf_compat_h

/*
* Microsoft's _vsnprintf and _snprint don't always terminate
* the string, so use wrappers that ensure that.
*/

#include <stdarg.h>

#if !defined(HAVE_SNPRINTF) && defined(_MSC_VER)
static int json_c_vsnprintf(char *str, size_t size, const char *format, va_list ap)
{
int ret;
ret = _vsnprintf(str, size, format, ap);
str[size - 1] = '\0';
return ret;
}
#define vsnprintf json_c_vsnprintf

static int json_c_snprintf(char *str, size_t size, const char *format, ...)
{
va_list ap;
int ret;
va_start(ap, format);
ret = json_c_vsnprintf(str, size, format, ap);
va_end(ap);
return ret;
}
#define snprintf json_c_snprintf

#elif !defined(HAVE_SNPRINTF) /* !HAVE_SNPRINTF */
# error Need vsnprintf!
#endif /* !HAVE_SNPRINTF && defined(WIN32) */

#endif /* __snprintf_compat_h */

+ 1
- 0
tests/test_locale.c View File

@@ -7,6 +7,7 @@
#include "config.h"
#include "json.h"
#include "json_tokener.h"
#include "snprintf_compat.h"

#ifdef HAVE_LOCALE_H
#include <locale.h>


+ 1
- 5
vasprintf_compat.h View File

@@ -1,11 +1,7 @@
#ifndef __vasprintf_compat_h
#define __vasprintf_compat_h

#if !defined(HAVE_VSNPRINTF) && defined(_MSC_VER)
# define vsnprintf _vsnprintf
#elif !defined(HAVE_VSNPRINTF) /* !HAVE_VSNPRINTF */
# error Need vsnprintf!
#endif /* !HAVE_VSNPRINTF && defined(WIN32) */
#include "snprintf_compat.h"

#if !defined(HAVE_VASPRINTF)
/* CAW: compliant version of vasprintf */


Loading…
Cancel
Save