Skip to content

Commit

Permalink
libjson-c: force json_c_ prefix on json-c namespace
Browse files Browse the repository at this point in the history
Problem: json-c exports symbols like json_object_put()
that conflict with other JSON implementations we might
want to migrate to, such as jansson as discussed in flux-framework#301.

To avoid such conflicts with the embedded json-c library,
force all visible json-c text symbols to have a json_c_
prefix, by including a new header, namespace.h in the json-c
sources and the "public" json.h header.  namespace.h redefines
text symbols that do not already have a json_c_ prefix, e.g.
  #define json_object_put json_c_object_put

This allows any part of flux-core to independently migrate
to a new JSON implementation that has clashing symbols by simply
not including src/common/libjson-c/json.h.
  • Loading branch information
garlick committed Oct 6, 2016
1 parent 812f133 commit 195c21a
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/common/libjson-c/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ AM_LDFLAGS = \
$(CODE_COVERAGE_LDFLAGS)

AM_CPPFLAGS = \
-I$(top_srcdir)
-I$(top_srcdir) \
-include $(srcdir)/namespace.h

noinst_LTLIBRARIES = libjson-c.la

Expand Down Expand Up @@ -34,6 +35,7 @@ libjson_c_la_SOURCES = \
random_seed.c \
random_seed.h \
json.h \
json_inttypes.h
json_inttypes.h \
namespace.h

EXTRA_DIST = AUTHORS COPYING
1 change: 1 addition & 0 deletions src/common/libjson-c/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
extern "C" {
#endif

#include "namespace.h"
#include "bits.h"
#include "debug.h"
#include "linkhash.h"
Expand Down
111 changes: 111 additions & 0 deletions src/common/libjson-c/namespace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#define array_list_add json_c_array_list_add
#define array_list_bsearch json_c_array_list_bsearch
#define array_list_del_idx json_c_array_list_del_idx
#define array_list_free json_c_array_list_free
#define array_list_get_idx json_c_array_list_get_idx
#define array_list_length json_c_array_list_length
#define array_list_new json_c_array_list_new
#define array_list_put_idx json_c_array_list_put_idx
#define array_list_sort json_c_array_list_sort
#define mc_debug json_c_mc_debug
#define mc_error json_c_mc_error
#define mc_get_debug json_c_mc_get_debug
#define mc_info json_c_mc_info
#define mc_set_debug json_c_mc_set_debug
#define mc_set_syslog json_c_mc_set_syslog
#define json_c_version json_c_version
#define json_c_version_num json_c_version_num
#define json_object_array_add json_c_object_array_add
#define json_object_array_bsearch json_c_object_array_bsearch
#define json_object_array_del_idx json_c_object_array_del_idx
#define json_object_array_get_idx json_c_object_array_get_idx
#define json_object_array_length json_c_object_array_length
#define json_object_array_put_idx json_c_object_array_put_idx
#define json_object_array_sort json_c_object_array_sort
#define json_object_double_to_json_string json_c_object_double_to_json_string
#define json_object_equal json_c_object_equal
#define json_object_free_userdata json_c_object_free_userdata
#define json_object_get json_c_object_get
#define json_object_get_array json_c_object_get_array
#define json_object_get_boolean json_c_object_get_boolean
#define json_object_get_double json_c_object_get_double
#define json_object_get_int json_c_object_get_int
#define json_object_get_int64 json_c_object_get_int64
#define json_object_get_object json_c_object_get_object
#define json_object_get_string json_c_object_get_string
#define json_object_get_string_len json_c_object_get_string_len
#define json_object_get_type json_c_object_get_type
#define json_object_get_userdata json_c_object_get_userdata
#define json_object_is_type json_c_object_is_type
#define json_object_new_array json_c_object_new_array
#define json_object_new_boolean json_c_object_new_boolean
#define json_object_new_double json_c_object_new_double
#define json_object_new_double_s json_c_object_new_double_s
#define json_object_new_int json_c_object_new_int
#define json_object_new_int64 json_c_object_new_int64
#define json_object_new_object json_c_object_new_object
#define json_object_new_string json_c_object_new_string
#define json_object_new_string_len json_c_object_new_string_len
#define json_object_object_add json_c_object_object_add
#define json_object_object_add_ex json_c_object_object_add_ex
#define json_object_object_del json_c_object_object_del
#define json_object_object_get json_c_object_object_get
#define json_object_object_get_ex json_c_object_object_get_ex
#define json_object_object_length json_c_object_object_length
#define json_object_put json_c_object_put
#define json_object_set_serializer json_c_object_set_serializer
#define json_object_set_userdata json_c_object_set_userdata
#define json_object_to_json_string json_c_object_to_json_string
#define json_object_to_json_string_ext json_c_object_to_json_string_ext
#define json_object_to_json_string_length json_c_object_to_json_string_length
#define json_object_userdata_to_json_string json_c_object_userdata_to_json_string
#define json_object_iter_begin json_c_object_iter_begin
#define json_object_iter_end json_c_object_iter_end
#define json_object_iter_equal json_c_object_iter_equal
#define json_object_iter_init_default json_c_object_iter_init_default
#define json_object_iter_next json_c_object_iter_next
#define json_object_iter_peek_name json_c_object_iter_peek_name
#define json_object_iter_peek_value json_c_object_iter_peek_value
#define json_tokener_error_desc json_c_tokener_error_desc
#define json_tokener_free json_c_tokener_free
#define json_tokener_get_error json_c_tokener_get_error
#define json_tokener_new json_c_tokener_new
#define json_tokener_new_ex json_c_tokener_new_ex
#define json_tokener_parse json_c_tokener_parse
#define json_tokener_parse_ex json_c_tokener_parse_ex
#define json_tokener_parse_verbose json_c_tokener_parse_verbose
#define json_tokener_reset json_c_tokener_reset
#define json_tokener_set_flags json_c_tokener_set_flags
#define json_object_from_fd json_c_object_from_fd
#define json_object_from_file json_c_object_from_file
#define json_object_to_file json_c_object_to_file
#define json_object_to_file_ext json_c_object_to_file_ext
#define json_parse_double json_c_parse_double
#define json_parse_int64 json_c_parse_int64
#define json_type_to_name json_c_type_to_name
#define json_util_get_last_err json_c_util_get_last_err
#define json_global_set_string_hash json_c_global_set_string_hash
#define lh_abort json_c_lh_abort
#define lh_char_equal json_c_lh_char_equal
#define lh_kchar_table_new json_c_lh_kchar_table_new
#define lh_kptr_table_new json_c_lh_kptr_table_new
#define lh_ptr_equal json_c_lh_ptr_equal
#define lh_table_delete json_c_lh_table_delete
#define lh_table_delete_entry json_c_lh_table_delete_entry
#define lh_table_free json_c_lh_table_free
#define lh_table_insert json_c_lh_table_insert
#define lh_table_insert_w_hash json_c_lh_table_insert_w_hash
#define lh_table_length json_c_lh_table_length
#define lh_table_lookup json_c_lh_table_lookup
#define lh_table_lookup_entry json_c_lh_table_lookup_entry
#define lh_table_lookup_entry_w_hash json_c_lh_table_lookup_entry_w_hash
#define lh_table_lookup_ex json_c_lh_table_lookup_ex
#define lh_table_new json_c_lh_table_new
#define lh_table_resize json_c_lh_table_resize
#define printbuf_free json_c_printbuf_free
#define printbuf_memappend json_c_printbuf_memappend
#define printbuf_memset json_c_printbuf_memset
#define printbuf_new json_c_printbuf_new
#define printbuf_reset json_c_printbuf_reset
#define sprintbuf json_c_sprintbuf
#define json_c_get_random_seed json_c_get_random_seed

0 comments on commit 195c21a

Please sign in to comment.