Skip to content

Commit 0695ac2

Browse files
committed
Upgrade libjson to the latest version from upstream[1]
Use the file list obtained from the upstream Makefile.am in json/Makefile.am Add the necessary autoconf checks from upstream to our configure.ac [1] https://github.com/json-c/json-c
1 parent a44b687 commit 0695ac2

31 files changed

+4513
-1311
lines changed

configure.ac

+11-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ AC_CHECK_HEADERS([arpa/inet.h errno.h fcntl.h dirent.h \
8181
sys/stat.h sys/types.h regex.h \
8282
syslog.h poll.h sys/epoll.h \
8383
unistd.h endian.h libgen.h \
84-
asm/types.h pwd.h grp.h wchar.h])
84+
asm/types.h pwd.h grp.h wchar.h stdarg.h])
8585

8686
AC_CHECK_HEADERS([resolv.h net/route.h net/if.h net/if_arp.h net/if_tun.h net/ethernet.h], [], [],
8787
[
@@ -105,6 +105,15 @@ AC_CHECK_HEADERS([resolv.h net/route.h net/if.h net/if_arp.h net/if_tun.h net/et
105105
#endif
106106
])
107107

108+
AC_CHECK_HEADER(inttypes.h,[AC_DEFINE([JSON_C_HAVE_INTTYPES_H],[1],[Public define for json_inttypes.h])])
109+
AC_CONFIG_HEADER(json/json_config.h)
110+
AC_CHECK_DECLS([INFINITY], [], [], [[#include <math.h>]])
111+
AC_CHECK_DECLS([nan], [], [], [[#include <math.h>]])
112+
AC_CHECK_DECLS([isnan], [], [], [[#include <math.h>]])
113+
AC_CHECK_DECLS([isinf], [], [], [[#include <math.h>]])
114+
AC_CHECK_DECLS([_isnan], [], [], [[#include <float.h>]])
115+
AC_CHECK_DECLS([_finite], [], [], [[#include <float.h>]])
116+
108117
# Checks for typedefs, structures, and compiler characteristics.
109118
AC_C_CONST
110119
AC_TYPE_UID_T
@@ -134,7 +143,7 @@ AC_FUNC_MMAP
134143
AC_CHECK_FUNCS([bzero clock_gettime dup2 gethostbyname getprotoent gettimeofday inet_ntoa \
135144
memchr memmove memset mkdir munmap regcomp select setenv socket strcasecmp \
136145
strchr strcspn strdup strerror strncasecmp strndup strrchr strspn strstr strtol getline dirname \
137-
glob getaddrinfo getnameinfo getifaddrs sysinfo strlcpy tzset])
146+
glob getaddrinfo getnameinfo getifaddrs sysinfo strlcpy tzset snprintf vsnprintf vasprintf])
138147
AC_CHECK_LIB(resolv, res_init)
139148

140149
AC_ARG_ENABLE(chilliquery, [AS_HELP_STRING([--disable-chilliquery],[Disable chilli_query])],

json/Makefile.am

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
lib_LTLIBRARIES = libjson.la
2+
23
libjson_la_SOURCES = \
3-
arraylist.c bits.h debug.h json_object.c json_object_private.h \
4-
json_tokener.h json_util.h linkhash.h printbuf.h \
5-
arraylist.h debug.c json.h json_object.h json_tokener.c \
6-
json_util.c linkhash.c printbuf.c
4+
arraylist.c \
5+
debug.c \
6+
json_c_version.c \
7+
json_object.c \
8+
json_object_iterator.c \
9+
json_tokener.c \
10+
json_util.c \
11+
linkhash.c \
12+
printbuf.c \
13+
random_seed.c
714

815
AM_CPPFLAGS = -g -Wall -std=gnu99 -D_GNU_SOURCE

json/README.html

+34-32
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
1-
<h2>JSON-C - A JSON implementation in C</h2>
2-
<p>Latest release: <a href="json-c-0.1.tar.gz">json-c-0.1.tar.gz</a></p>
3-
4-
<p>JSON-C implements a reference counting object model that allows you
5-
to easily construct JSON objects in C, output them as JSON formatted strings
6-
and parse JSON formatted strings back into the C representation of JSON
7-
objects.</p>
8-
9-
<p>Minimal documentation exists <a href="doc/html/json__object_8h.html">here</a>,
10-
Although you are probably better reading the example code in test1.c.</p>
11-
12-
<p>JSON-C currently depends on some gcc 3.0+ features so can probably only be
13-
compiled with gcc 3.0+. It also uses some specifc glibc functions such as
14-
vasprintf. Patches welcome to port to other compilers / platforms.</p>
15-
16-
<p>Please send bug reports to <a href="mailto:michael@metaparadigm.com">michael@metaparadigm.com</a></p>
17-
18-
<h3>Anonymous CVS</h3>
19-
<p><code># <b>export CVSROOT=:pserver:anoncvs@cvs.metaparadigm.com:/cvsroot</b><br>
20-
# <b>cvs login</b><br>
21-
Logging in to :pserver:anoncvs@cvs.metaparadigm.com:2401/cvsroot<br>
22-
CVS password: &lt;enter '<b>anoncvs</b>'&gt;<br>
23-
# <b>cvs co json-c</b></code></p>
24-
25-
<p>Copyright Metaparadigm Pte. Ltd. 2004. <a href="mailto:michael@metaparadigm.com">Michael Clark </a></p>
26-
27-
<p>This program is free software; you can redistribute it and/or
28-
modify it under the terms of the GNU Lesser General Public (LGPL)
29-
License as published by the Free Software Foundation; either
30-
version 2.1 of the License, or (at your option) any later version.</p>
31-
32-
<hr>
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3+
<head>
4+
<title>JSON-C - A JSON implementation in C</title>
5+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
6+
</head>
7+
<body>
8+
<h2>JSON-C - A JSON implementation in C</h2>
9+
10+
<h3>Overview</h3>
11+
<p>JSON-C implements a reference counting object model that allows you to easily
12+
construct JSON objects in C, output them as JSON formatted strings and parse
13+
JSON formatted strings back into the C representation of JSON objects.</p>
14+
15+
<h3>Building</h3>
16+
<p>To setup JSON-C to build on your system please run <tt>configure</tt> and <tt>make</tt>.</p>
17+
<p>If you are on Win32 and are not using the VS project file, be sure
18+
to rename <tt>config.h.win32</tt> to <tt>config.h</tt> before building.</p>
19+
20+
<h3>Documentation</h3>
21+
<P>Doxygen generated documentation exists <a href="doc/html/json__object_8h.html">here</a>
22+
and Win32 specific notes can be found <a href="README-WIN32.html">here</a>.</P>
23+
24+
<h3><a href="https://github.com/json-c/json-c">GIT Reposository</a></h3>
25+
<p><strong><code>git clone https://github.com/json-c/json-c.git</code></strong></p>
26+
27+
<h3><a href="http://groups.google.com/group/json-c">Mailing List</a></h3>
28+
<pi>Send email to <strong><code>json-c <i>&lt;at&gt;</i> googlegroups <i>&lt;dot&gt;</i> com</code></strong></p>
29+
30+
<h3><a href="COPYING">License</a></h3>
31+
<p>This program is free software; you can redistribute it and/or modify it under the terms of the MIT License..</p>
32+
<hr/>
33+
</body>
34+
</html>

json/arraylist.c

+62-48
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,108 @@
11
/*
2-
* $Id: arraylist.c,v 1.2 2004/07/21 01:24:33 mclark Exp $
2+
* $Id: arraylist.c,v 1.4 2006/01/26 02:16:28 mclark Exp $
33
*
4-
* Copyright Metaparadigm Pte. Ltd. 2004.
4+
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
55
* Michael Clark <michael@metaparadigm.com>
66
*
7-
* This library is free software; you can redistribute it and/or
8-
* modify it under the terms of the GNU Lesser General Public (LGPL)
9-
* License as published by the Free Software Foundation; either
10-
* version 2.1 of the License, or (at your option) any later version.
11-
*
12-
* This library is distributed in the hope that it will be useful,
13-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15-
* Lesser General Public License for more details: http://www.gnu.org/
7+
* This library is free software; you can redistribute it and/or modify
8+
* it under the terms of the MIT license. See COPYING for details.
169
*
1710
*/
1811

19-
#include <stdlib.h>
20-
#include <string.h>
21-
#include <strings.h>
12+
#include "../config.h"
2213

23-
#include "bits.h"
24-
#include "arraylist.h"
14+
#ifdef STDC_HEADERS
15+
# include <stdlib.h>
16+
# include <string.h>
17+
#endif /* STDC_HEADERS */
2518

19+
#if defined(HAVE_STRINGS_H) && !defined(_STRING_H) && !defined(__USE_BSD)
20+
# include <strings.h>
21+
#endif /* HAVE_STRINGS_H */
22+
23+
#include "arraylist.h"
2624

2725
struct array_list*
2826
array_list_new(array_list_free_fn *free_fn)
2927
{
30-
struct array_list *this;
28+
struct array_list *arr;
3129

32-
if(!(this = calloc(1, sizeof(struct array_list)))) return NULL;
33-
this->size = ARRAY_LIST_DEFAULT_SIZE;
34-
this->length = 0;
35-
this->free_fn = free_fn;
36-
if(!(this->array = calloc(sizeof(void*), this->size))) {
37-
free(this);
30+
arr = (struct array_list*)calloc(1, sizeof(struct array_list));
31+
if(!arr) return NULL;
32+
arr->size = ARRAY_LIST_DEFAULT_SIZE;
33+
arr->length = 0;
34+
arr->free_fn = free_fn;
35+
if(!(arr->array = (void**)calloc(sizeof(void*), arr->size))) {
36+
free(arr);
3837
return NULL;
3938
}
40-
return this;
39+
return arr;
4140
}
4241

4342
extern void
44-
array_list_free(struct array_list *this)
43+
array_list_free(struct array_list *arr)
4544
{
4645
int i;
47-
for(i = 0; i < this->length; i++)
48-
if(this->array[i]) this->free_fn(this->array[i]);
49-
free(this->array);
50-
free(this);
46+
for(i = 0; i < arr->length; i++)
47+
if(arr->array[i]) arr->free_fn(arr->array[i]);
48+
free(arr->array);
49+
free(arr);
5150
}
5251

5352
void*
54-
array_list_get_idx(struct array_list *this, int i)
53+
array_list_get_idx(struct array_list *arr, int i)
5554
{
56-
if(i >= this->length) return NULL;
57-
return this->array[i];
55+
if(i >= arr->length) return NULL;
56+
return arr->array[i];
5857
}
5958

60-
static int array_list_expand_internal(struct array_list *this, int max)
59+
static int array_list_expand_internal(struct array_list *arr, int max)
6160
{
6261
void *t;
6362
int new_size;
6463

65-
if(max < this->size) return 0;
66-
new_size = max(this->size << 1, max);
67-
if(!(t = realloc(this->array, new_size*sizeof(void*)))) return -1;
68-
this->array = t;
69-
bzero(this->array + this->size, (new_size-this->size)*sizeof(void*));
70-
this->size = new_size;
64+
if(max < arr->size) return 0;
65+
new_size = arr->size << 1;
66+
if (new_size < max)
67+
new_size = max;
68+
if(!(t = realloc(arr->array, new_size*sizeof(void*)))) return -1;
69+
arr->array = (void**)t;
70+
(void)memset(arr->array + arr->size, 0, (new_size-arr->size)*sizeof(void*));
71+
arr->size = new_size;
7172
return 0;
7273
}
7374

7475
int
75-
array_list_put_idx(struct array_list *this, int idx, void *data)
76+
array_list_put_idx(struct array_list *arr, int idx, void *data)
7677
{
77-
if(array_list_expand_internal(this, idx)) return -1;
78-
if(this->array[idx]) this->free_fn(this->array[idx]);
79-
this->array[idx] = data;
80-
if(this->length <= idx) this->length = idx + 1;
78+
if(array_list_expand_internal(arr, idx+1)) return -1;
79+
if(arr->array[idx]) arr->free_fn(arr->array[idx]);
80+
arr->array[idx] = data;
81+
if(arr->length <= idx) arr->length = idx + 1;
8182
return 0;
8283
}
8384

8485
int
85-
array_list_add(struct array_list *this, void *data)
86+
array_list_add(struct array_list *arr, void *data)
87+
{
88+
return array_list_put_idx(arr, arr->length, data);
89+
}
90+
91+
void
92+
array_list_sort(struct array_list *arr, int(*sort_fn)(const void *, const void *))
93+
{
94+
qsort(arr->array, arr->length, sizeof(arr->array[0]), sort_fn);
95+
}
96+
97+
void* array_list_bsearch(const void **key, struct array_list *arr,
98+
int (*sort_fn)(const void *, const void *))
8699
{
87-
return array_list_put_idx(this, this->length, data);
100+
return bsearch(key, arr->array, arr->length, sizeof(arr->array[0]),
101+
sort_fn);
88102
}
89103

90104
int
91-
array_list_length(struct array_list *this)
105+
array_list_length(struct array_list *arr)
92106
{
93-
return this->length;
107+
return arr->length;
94108
}

json/arraylist.h

+25-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
/*
2-
* $Id: arraylist.h,v 1.2 2004/07/21 01:24:33 mclark Exp $
2+
* $Id: arraylist.h,v 1.4 2006/01/26 02:16:28 mclark Exp $
33
*
4-
* Copyright Metaparadigm Pte. Ltd. 2004.
4+
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
55
* Michael Clark <michael@metaparadigm.com>
66
*
7-
* This library is free software; you can redistribute it and/or
8-
* modify it under the terms of the GNU Lesser General Public (LGPL)
9-
* License as published by the Free Software Foundation; either
10-
* version 2.1 of the License, or (at your option) any later version.
11-
*
12-
* This library is distributed in the hope that it will be useful,
13-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15-
* Lesser General Public License for more details: http://www.gnu.org/
7+
* This library is free software; you can redistribute it and/or modify
8+
* it under the terms of the MIT license. See COPYING for details.
169
*
1710
*/
1811

1912
#ifndef _arraylist_h_
2013
#define _arraylist_h_
2114

15+
#ifdef __cplusplus
16+
extern "C" {
17+
#endif
18+
2219
#define ARRAY_LIST_DEFAULT_SIZE 32
2320

2421
typedef void (array_list_free_fn) (void *data);
@@ -35,18 +32,30 @@ extern struct array_list*
3532
array_list_new(array_list_free_fn *free_fn);
3633

3734
extern void
38-
array_list_free(struct array_list *this);
35+
array_list_free(struct array_list *al);
3936

4037
extern void*
41-
array_list_get_idx(struct array_list *this, int i);
38+
array_list_get_idx(struct array_list *al, int i);
4239

4340
extern int
44-
array_list_put_idx(struct array_list *this, int i, void *data);
41+
array_list_put_idx(struct array_list *al, int i, void *data);
4542

4643
extern int
47-
array_list_add(struct array_list *this, void *data);
44+
array_list_add(struct array_list *al, void *data);
4845

4946
extern int
50-
array_list_length(struct array_list *this);
47+
array_list_length(struct array_list *al);
48+
49+
extern void
50+
array_list_sort(struct array_list *arr, int(*compar)(const void *, const void *));
51+
52+
extern void* array_list_bsearch(const void **key,
53+
struct array_list *arr,
54+
int (*sort_fn)(const void *, const void *));
55+
56+
57+
#ifdef __cplusplus
58+
}
59+
#endif
5160

5261
#endif

0 commit comments

Comments
 (0)