From 2cc9ca5c4e8db299feafb96ee542a695c0201bd4 Mon Sep 17 00:00:00 2001 From: Nicolas Favre-Felix Date: Wed, 30 Aug 2023 16:44:55 -0700 Subject: [PATCH] Clean up Jansson source tree, document changes made * Update jansson_private_config.h to accurately reflect the presence or absence of certain compiler features and headers * Mark one function as unused to prevent a compilation warning * Disable one warning on GCC * Validate that all imported C files are used in the build * Remove unused Jansson build files, preserve LICENSE * Document these changes in WEBDIS-CHANGES.md and link from README.md --- README.md | 8 +- src/jansson/Makefile.am | 12 -- src/jansson/WEBDIS-CHANGES.md | 37 +++++ src/jansson/configure.ac | 181 ----------------------- src/jansson/jansson.pc.in | 10 -- src/jansson/src/Makefile.am | 30 ---- src/jansson/src/hashtable_seed.c | 1 + src/jansson/src/jansson_config.h.in | 51 ------- src/jansson/src/jansson_private_config.h | 23 ++- src/jansson/src/load.c | 9 ++ src/jansson/src/lookup3.h | 8 +- 11 files changed, 79 insertions(+), 291 deletions(-) delete mode 100644 src/jansson/Makefile.am create mode 100644 src/jansson/WEBDIS-CHANGES.md delete mode 100644 src/jansson/configure.ac delete mode 100644 src/jansson/jansson.pc.in delete mode 100644 src/jansson/src/Makefile.am delete mode 100644 src/jansson/src/jansson_config.h.in diff --git a/README.md b/README.md index bb0965e..4d7cecc 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,13 @@ # About Webdis -A very simple web server providing an HTTP interface to Redis. It uses [hiredis](https://github.com/antirez/hiredis), [jansson](https://github.com/akheron/jansson), [libevent](https://monkey.org/~provos/libevent/), and [http-parser](https://github.com/ry/http-parser/). +A very simple web server providing an HTTP interface to Redis. It embeds [hiredis](https://github.com/antirez/hiredis), [jansson](https://github.com/akheron/jansson) (with some [local changes](./src/jansson/WEBDIS-CHANGES.md)), and [http-parser](https://github.com/ry/http-parser/). It also depends on [libevent](https://monkey.org/~provos/libevent/), to be installed separately. -Webdis depends on libevent-dev. You can install it on Ubuntu by typing `sudo apt-get install libevent-dev` or on macOS by typing `brew install libevent`. +# Build and run from source -To build Webdis with support for encrypted connections to Redis, see [Building Webdis with SSL support](#building-webdis-with-ssl-support). +Building Webdis requires the libevent development package. You can install it on Ubuntu by typing `sudo apt-get install libevent-dev` or on macOS by typing `brew install libevent`. -# Build and run from source +To build Webdis with support for encrypted connections to Redis, see [Building Webdis with SSL support](#building-webdis-with-ssl-support). ```sh $ make clean all diff --git a/src/jansson/Makefile.am b/src/jansson/Makefile.am deleted file mode 100644 index a6f9192..0000000 --- a/src/jansson/Makefile.am +++ /dev/null @@ -1,12 +0,0 @@ -EXTRA_DIST = CHANGES LICENSE README.rst CMakeLists.txt cmake android examples scripts -SUBDIRS = doc src test - -# "make distcheck" builds the dvi target, so use it to check that the -# documentation is built correctly. -dvi: - $(MAKE) SPHINXOPTS_EXTRA=-W html - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = jansson.pc - -TESTS = scripts/clang-format-check diff --git a/src/jansson/WEBDIS-CHANGES.md b/src/jansson/WEBDIS-CHANGES.md new file mode 100644 index 0000000..47b173a --- /dev/null +++ b/src/jansson/WEBDIS-CHANGES.md @@ -0,0 +1,37 @@ +# Webdis changes to Jansson + +Webdis imports Jansson by including its source code under `src/jansson`. This document lists the changes made to Jansson files, mostly made to accommodate the requirements of the Webdis build process. + +Webdis currently imports Jansson version 2.14. + +## Includes and compiler builtins + +Added checks for various headers and compiler builtins. For example, `endian.h` is not available on macOS, although `machine/endian.h` is. + +## Unused code + +Marked `buf_to_uint32` as unused. + +## Unused source files + +To validate that all the C files imported are used in the build, we can compare the list of files in the Jansson source directory with the object files listed in the Webdis Makefile. + +The following `diff` command should not show any output: + +```sh +diff -u <(grep ^JANSSON_OBJ Makefile | head -1 | cut -f 2- -d = | tr ' ' '\n' | sed -Ee 's/\.o$/.c/g' | sort)\ + <(find src/jansson/src -name '*.c' | sort) +``` + +## Unused build files + +Autotool build files can be removed, namely: +- `configure.ac` +- `jansson.pc.in` +- `Makefile.am` (2 copies) +- `jansson_config.h.in` + +## Disabled warning + +A `#pragma` is used in `src/jansson/src/load.c` to disable overly strict warnings about string truncation. +No overflow is possible, GCC is only warning about the possibility of a string being truncated if it doesn't fit in the destination buffer. diff --git a/src/jansson/configure.ac b/src/jansson/configure.ac deleted file mode 100644 index f022eb7..0000000 --- a/src/jansson/configure.ac +++ /dev/null @@ -1,181 +0,0 @@ -AC_PREREQ([2.60]) -AC_INIT([jansson], [2.14], [https://github.com/akheron/jansson/issues]) - -AC_CONFIG_AUX_DIR([.]) -AM_INIT_AUTOMAKE([1.10 foreign]) - -AC_CONFIG_SRCDIR([src/value.c]) -AC_CONFIG_HEADERS([jansson_private_config.h]) - -# Checks for programs. -AC_PROG_CC -AC_PROG_CXX -AC_PROG_LIBTOOL -AM_CONDITIONAL([GCC], [test x$GCC = xyes]) - -# Checks for libraries. - -# Checks for header files. -AC_CHECK_HEADERS([endian.h fcntl.h locale.h sched.h unistd.h sys/param.h sys/stat.h sys/time.h sys/types.h]) - -# Checks for typedefs, structures, and compiler characteristics. -AC_TYPE_INT32_T -AC_TYPE_UINT32_T -AC_TYPE_UINT16_T -AC_TYPE_UINT8_T -AC_TYPE_LONG_LONG_INT - -AC_C_INLINE -case $ac_cv_c_inline in - yes) json_inline=inline;; - no) json_inline=;; - *) json_inline=$ac_cv_c_inline;; -esac -AC_SUBST([json_inline]) - -# Checks for library functions. -AC_CHECK_FUNCS([close getpid gettimeofday localeconv open read sched_yield strtoll]) - -AC_MSG_CHECKING([for gcc __sync builtins]) -have_sync_builtins=no -AC_TRY_LINK( - [], [unsigned long val; __sync_bool_compare_and_swap(&val, 0, 1); __sync_add_and_fetch(&val, 1); __sync_sub_and_fetch(&val, 1);], - [have_sync_builtins=yes], -) -if test "x$have_sync_builtins" = "xyes"; then - AC_DEFINE([HAVE_SYNC_BUILTINS], [1], - [Define to 1 if gcc's __sync builtins are available]) - json_have_sync_builtins=1 -else - json_have_sync_builtins=0 -fi -AC_SUBST([json_have_sync_builtins]) -AC_MSG_RESULT([$have_sync_builtins]) - -AC_MSG_CHECKING([for gcc __atomic builtins]) -have_atomic_builtins=no -AC_TRY_LINK( - [], [char l; unsigned long v; __atomic_test_and_set(&l, __ATOMIC_RELAXED); __atomic_store_n(&v, 1, __ATOMIC_RELEASE); __atomic_load_n(&v, __ATOMIC_ACQUIRE); __atomic_add_fetch(&v, 1, __ATOMIC_ACQUIRE); __atomic_sub_fetch(&v, 1, __ATOMIC_RELEASE);], - [have_atomic_builtins=yes], -) -if test "x$have_atomic_builtins" = "xyes"; then - AC_DEFINE([HAVE_ATOMIC_BUILTINS], [1], - [Define to 1 if gcc's __atomic builtins are available]) - json_have_atomic_builtins=1 -else - json_have_atomic_builtins=0 -fi -AC_SUBST([json_have_atomic_builtins]) -AC_MSG_RESULT([$have_atomic_builtins]) - -case "$ac_cv_type_long_long_int$ac_cv_func_strtoll" in - yesyes) json_have_long_long=1;; - *) json_have_long_long=0;; -esac -AC_SUBST([json_have_long_long]) - -case "$ac_cv_header_locale_h$ac_cv_func_localeconv" in - yesyes) json_have_localeconv=1;; - *) json_have_localeconv=0;; -esac -AC_SUBST([json_have_localeconv]) - -# Features -AC_ARG_ENABLE([urandom], - [AS_HELP_STRING([--disable-urandom], - [Don't use /dev/urandom to seed the hash function])], - [use_urandom=$enableval], [use_urandom=yes]) - -if test "x$use_urandom" = xyes; then -AC_DEFINE([USE_URANDOM], [1], - [Define to 1 if /dev/urandom should be used for seeding the hash function]) -fi - -AC_ARG_ENABLE([windows-cryptoapi], - [AS_HELP_STRING([--disable-windows-cryptoapi], - [Don't use CryptGenRandom to seed the hash function])], - [use_windows_cryptoapi=$enableval], [use_windows_cryptoapi=yes]) - -if test "x$use_windows_cryptoapi" = xyes; then -AC_DEFINE([USE_WINDOWS_CRYPTOAPI], [1], - [Define to 1 if CryptGenRandom should be used for seeding the hash function]) -fi - -AC_ARG_ENABLE([initial-hashtable-order], - [AS_HELP_STRING([--enable-initial-hashtable-order=VAL], - [Number of buckets new object hashtables contain is 2 raised to this power. The default is 3, so empty hashtables contain 2^3 = 8 buckets.])], - [initial_hashtable_order=$enableval], [initial_hashtable_order=3]) -AC_DEFINE_UNQUOTED([INITIAL_HASHTABLE_ORDER], [$initial_hashtable_order], - [Number of buckets new object hashtables contain is 2 raised to this power. E.g. 3 -> 2^3 = 8.]) - -AC_ARG_ENABLE([Bsymbolic], - [AS_HELP_STRING([--disable-Bsymbolic], - [Avoid linking with -Bsymbolic-function])], - [], [with_Bsymbolic=check]) - -if test "x$with_Bsymbolic" != "xno" ; then - AC_MSG_CHECKING([for -Bsymbolic-functions linker flag]) - saved_LDFLAGS="${LDFLAGS}" - LDFLAGS=-Wl,-Bsymbolic-functions - AC_TRY_LINK( - [], [int main (void) { return 0; }], - [AC_MSG_RESULT([yes]) - have_Bsymbolic=yes], - [AC_MSG_RESULT([no]) - have_Bsymbolic=no] - ) - LDFLAGS="${saved_LDFLAGS}" - - if test "x$with_Bsymbolic" = "xcheck" ; then - with_Bsymbolic=$have_Bsymbolic; - fi - if test "x$with_Bsymbolic:x$have_Bsymbolic" = "xyes:xno" ; then - AC_MSG_ERROR([linker support is required for -Bsymbolic]) - fi -fi - -AS_IF([test "x$with_Bsymbolic" = "xyes"], [JSON_BSYMBOLIC_LDFLAGS=-Wl[,]-Bsymbolic-functions]) -AC_SUBST(JSON_BSYMBOLIC_LDFLAGS) - -# Enable symbol versioning on GNU libc -JSON_SYMVER_LDFLAGS= -AC_CHECK_DECL([__GLIBC__], [JSON_SYMVER_LDFLAGS=-Wl,--default-symver]) -AC_SUBST([JSON_SYMVER_LDFLAGS]) - -AC_ARG_ENABLE([ossfuzzers], - [AS_HELP_STRING([--enable-ossfuzzers], - [Whether to generate the fuzzers for OSS-Fuzz])], - [have_ossfuzzers=yes], [have_ossfuzzers=no]) -AM_CONDITIONAL([USE_OSSFUZZERS], [test "x$have_ossfuzzers" = "xyes"]) - - -AC_SUBST([LIB_FUZZING_ENGINE]) -AM_CONDITIONAL([USE_OSSFUZZ_FLAG], [test "x$LIB_FUZZING_ENGINE" = "x-fsanitize=fuzzer"]) -AM_CONDITIONAL([USE_OSSFUZZ_STATIC], [test -f "$LIB_FUZZING_ENGINE"]) - - -if test x$GCC = xyes; then - AC_MSG_CHECKING(for -Wno-format-truncation) - wnoformat_truncation="-Wno-format-truncation" - AS_IF([${CC} -Wno-format-truncation -Werror -S -o /dev/null -xc /dev/null > /dev/null 2>&1], - [AC_MSG_RESULT(yes)], - [AC_MSG_RESULT(no) - wnoformat_truncation=""]) - - AM_CFLAGS="-Wall -Wextra -Wdeclaration-after-statement -Wshadow ${wnoformat_truncation}" -fi -AC_SUBST([AM_CFLAGS]) - -AC_CONFIG_FILES([ - jansson.pc - Makefile - doc/Makefile - src/Makefile - src/jansson_config.h - test/Makefile - test/bin/Makefile - test/ossfuzz/Makefile - test/suites/Makefile - test/suites/api/Makefile -]) -AC_OUTPUT diff --git a/src/jansson/jansson.pc.in b/src/jansson/jansson.pc.in deleted file mode 100644 index 69c9a43..0000000 --- a/src/jansson/jansson.pc.in +++ /dev/null @@ -1,10 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: Jansson -Description: Library for encoding, decoding and manipulating JSON data -Version: @VERSION@ -Libs: -L${libdir} -ljansson -Cflags: -I${includedir} diff --git a/src/jansson/src/Makefile.am b/src/jansson/src/Makefile.am deleted file mode 100644 index 63eda32..0000000 --- a/src/jansson/src/Makefile.am +++ /dev/null @@ -1,30 +0,0 @@ -EXTRA_DIST = jansson.def - -include_HEADERS = jansson.h -nodist_include_HEADERS = jansson_config.h - -lib_LTLIBRARIES = libjansson.la -libjansson_la_SOURCES = \ - dump.c \ - error.c \ - hashtable.c \ - hashtable.h \ - hashtable_seed.c \ - jansson_private.h \ - load.c \ - lookup3.h \ - memory.c \ - pack_unpack.c \ - strbuffer.c \ - strbuffer.h \ - strconv.c \ - utf.c \ - utf.h \ - value.c \ - version.c -libjansson_la_LDFLAGS = \ - -no-undefined \ - -export-symbols-regex '^json_|^jansson_' \ - -version-info 18:0:14 \ - @JSON_SYMVER_LDFLAGS@ \ - @JSON_BSYMBOLIC_LDFLAGS@ diff --git a/src/jansson/src/hashtable_seed.c b/src/jansson/src/hashtable_seed.c index 37cc072..0cf7881 100644 --- a/src/jansson/src/hashtable_seed.c +++ b/src/jansson/src/hashtable_seed.c @@ -41,6 +41,7 @@ #include "jansson.h" +__attribute__ ((unused)) static uint32_t buf_to_uint32(char *data) { size_t i; uint32_t result = 0; diff --git a/src/jansson/src/jansson_config.h.in b/src/jansson/src/jansson_config.h.in deleted file mode 100644 index fe692ab..0000000 --- a/src/jansson/src/jansson_config.h.in +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2010-2016 Petri Lehtinen - * - * Jansson is free software; you can redistribute it and/or modify - * it under the terms of the MIT license. See LICENSE for details. - * - * - * This file specifies a part of the site-specific configuration for - * Jansson, namely those things that affect the public API in - * jansson.h. - * - * The configure script copies this file to jansson_config.h and - * replaces @var@ substitutions by values that fit your system. If you - * cannot run the configure script, you can do the value substitution - * by hand. - */ - -#ifndef JANSSON_CONFIG_H -#define JANSSON_CONFIG_H - -/* If your compiler supports the inline keyword in C, JSON_INLINE is - defined to `inline', otherwise empty. In C++, the inline is always - supported. */ -#ifdef __cplusplus -#define JSON_INLINE inline -#else -#define JSON_INLINE @json_inline@ -#endif - -/* If your compiler supports the `long long` type and the strtoll() - library function, JSON_INTEGER_IS_LONG_LONG is defined to 1, - otherwise to 0. */ -#define JSON_INTEGER_IS_LONG_LONG @json_have_long_long@ - -/* If locale.h and localeconv() are available, define to 1, - otherwise to 0. */ -#define JSON_HAVE_LOCALECONV @json_have_localeconv@ - -/* If __atomic builtins are available they will be used to manage - reference counts of json_t. */ -#define JSON_HAVE_ATOMIC_BUILTINS @json_have_atomic_builtins@ - -/* If __atomic builtins are not available we try using __sync builtins - to manage reference counts of json_t. */ -#define JSON_HAVE_SYNC_BUILTINS @json_have_sync_builtins@ - -/* Maximum recursion depth for parsing JSON input. - This limits the depth of e.g. array-within-array constructions. */ -#define JSON_PARSER_MAX_DEPTH 2048 - -#endif diff --git a/src/jansson/src/jansson_private_config.h b/src/jansson/src/jansson_private_config.h index acbb36a..0b57872 100644 --- a/src/jansson/src/jansson_private_config.h +++ b/src/jansson/src/jansson_private_config.h @@ -2,7 +2,12 @@ /* jansson_private_config.h.in. Generated from configure.ac by autoheader. */ /* Define to 1 if gcc's __atomic builtins are available */ -#define HAVE_ATOMIC_BUILTINS 1 +#if defined(__has_include) && __has_include() +# include +# define HAVE_ATOMIC_BUILTINS 1 +#else +# define HAVE_ATOMIC_BUILTINS 0 +#endif /* Define to 1 if you have the `close' function. */ #define HAVE_CLOSE 1 @@ -10,8 +15,18 @@ /* Define to 1 if you have the header file. */ #define HAVE_DLFCN_H 1 -/* Define to 1 if you have the header file. */ +/* Locate the header file. */ +#if defined(__has_include) && __has_include() #define HAVE_ENDIAN_H 1 +#else +#define HAVE_ENDIAN_H 0 +#endif +#if defined(__has_include) && __has_include() +#define HAVE_MACHINE_ENDIAN_H 1 +#else +#define HAVE_MACHINE_ENDIAN_H 0 +#endif + /* Define to 1 if you have the header file. */ #define HAVE_FCNTL_H 1 @@ -65,7 +80,11 @@ #define HAVE_STRTOLL 1 /* Define to 1 if gcc's __sync builtins are available */ +#ifdef __GNUC__ #define HAVE_SYNC_BUILTINS 1 +#else +#define HAVE_SYNC_BUILTINS 0 +#endif /* Define to 1 if you have the header file. */ #define HAVE_SYS_PARAM_H 1 diff --git a/src/jansson/src/load.c b/src/jansson/src/load.c index 8ae7abd..48242a0 100644 --- a/src/jansson/src/load.c +++ b/src/jansson/src/load.c @@ -5,6 +5,11 @@ * it under the terms of the MIT license. See LICENSE for details. */ +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-truncation" +#endif + #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif @@ -1104,3 +1109,7 @@ json_t *json_load_callback(json_load_callback_t callback, void *arg, size_t flag lex_close(&lex); return result; } + +#if defined(__GNUC__) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif diff --git a/src/jansson/src/lookup3.h b/src/jansson/src/lookup3.h index 9b39aa1..c3bb557 100644 --- a/src/jansson/src/lookup3.h +++ b/src/jansson/src/lookup3.h @@ -49,9 +49,15 @@ on 1 byte), but shoehorning those bytes into integers efficiently is messy. #include /* attempt to define endianness */ #endif -#ifdef HAVE_ENDIAN_H +#if HAVE_ENDIAN_H # include /* attempt to define endianness */ #endif +#if HAVE_MACHINE_ENDIAN_H +# include +#endif +#if (!HAVE_ENDIAN_H && !HAVE_MACHINE_ENDIAN_H && !defined(BYTE_ORDER)) +# error "Unable to determine endianness" +#endif /* * My best guess at if you are big-endian or little-endian. This may