Skip to content

Commit

Permalink
Merge pull request #258 from ngtcp2/macro-comments
Browse files Browse the repository at this point in the history
Consistent macro comments
  • Loading branch information
tatsuhiro-t authored Sep 14, 2024
2 parents b970523 + 8511829 commit a872b6c
Show file tree
Hide file tree
Showing 51 changed files with 170 additions and 163 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ endif()
# Checks for symbols.
include(CheckSymbolExists)
if(HAVE_ENDIAN_H)
check_symbol_exists(be64toh "endian.h" HAVE_BE64TOH)
check_symbol_exists(be64toh "endian.h" HAVE_DECL_BE64TOH)
endif()
if(HAVE_SYS_ENDIAN_H)
check_symbol_exists(be64toh "sys/endian.h" HAVE_BE64TOH)
if(NOT HAVE_DECL_BE64TOH AND HAVE_SYS_ENDIAN_H)
check_symbol_exists(be64toh "sys/endian.h" HAVE_DECL_BE64TOH)
endif()

check_symbol_exists(bswap_64 "byteswap.h" HAVE_BSWAP_64)
check_symbol_exists(bswap_64 "byteswap.h" HAVE_DECL_BSWAP_64)

if(${CMAKE_C_BYTE_ORDER} STREQUAL "BIG_ENDIAN")
set(WORDS_BIGENDIAN 1)
Expand Down
7 changes: 5 additions & 2 deletions cmakeconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
/* Define to 1 if you have the <byteswap.h> header file. */
#cmakedefine HAVE_BYTESWAP_H 1

/* Define to 1 if you have the `be64toh' function. */
#cmakedefine HAVE_BE64TOH 1
/* Define to 1 if you have the `be64toh' function, otherwise 0. */
#cmakedefine01 HAVE_DECL_BE64TOH

/* Define to 1 if you have the `bswap_64' function, otherwise 0. */
#cmakedefine01 HAVE_DECL_BSWAP_64

/* Define WORDS_BIGENDIAN to 1 if target architecture is big
endian. */
Expand Down
4 changes: 2 additions & 2 deletions examples/qpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#endif // defined(HAVE_CONFIG_H)

#include <nghttp3/nghttp3.h>

Expand All @@ -41,4 +41,4 @@ struct Config {

} // namespace nghttp3

#endif // QPACK_H
#endif // !defined(QPACK_H)
4 changes: 2 additions & 2 deletions examples/qpack_decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#endif // defined(HAVE_CONFIG_H)

#include <nghttp3/nghttp3.h>

Expand Down Expand Up @@ -90,4 +90,4 @@ int decode(const std::string_view &outfile, const std::string_view &infile);

} // namespace nghttp3

#endif // QPACK_ENCODE_H
#endif // !defined(QPACK_DECODE_H)
4 changes: 2 additions & 2 deletions examples/qpack_encode.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#endif // defined(HAVE_CONFIG_H)

#include <nghttp3/nghttp3.h>

Expand Down Expand Up @@ -56,4 +56,4 @@ int encode(const std::string_view &outfile, const std::string_view &infile);

} // namespace nghttp3

#endif // QPACK_ENCODE_H
#endif // !defined(QPACK_ENCODE_H)
2 changes: 1 addition & 1 deletion examples/template.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ constexpr unsigned long long operator"" _g(unsigned long long g) {

} // namespace nghttp3

#endif // TEMPLATE_H
#endif // !defined(TEMPLATE_H)
29 changes: 17 additions & 12 deletions examples/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,42 @@

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#endif // defined(HAVE_CONFIG_H)

#include <stdint.h>

#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif /* HAVE_ARPA_INET_H */
#endif // defined(HAVE_ARPA_INET_H)

#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif /* HAVE_NETINET_IN_H */
#endif // defined(HAVE_NETINET_IN_H)

#ifdef HAVE_ENDIAN_H
# include <endian.h>
#endif /* HAVE_ENDIAN_H */
#endif // defined(HAVE_ENDIAN_H)x

#ifdef HAVE_SYS_ENDIAN_H
# include <sys/endian.h>
#endif /* HAVE_SYS_ENDIAN_H */
#endif // defined(HAVE_SYS_ENDIAN_H)

namespace nghttp3 {

#if defined HAVE_BE64TOH || HAVE_DECL_BE64TOH
#if HAVE_DECL_BE64TOH
# define nghttp3_ntohl64(N) be64toh(N)
# define nghttp3_htonl64(N) htobe64(N)
#else /* !HAVE_BE64TOH */
# define nghttp3_bswap64(N) \
((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
# define nghttp3_ntohl64(N) nghttp3_bswap64(N)
# define nghttp3_htonl64(N) nghttp3_bswap64(N)
#endif /* !HAVE_BE64TOH */
#else // !HAVE_DECL_BE64TOH
# ifdef WORDS_BIGENDIAN
# define nghttp3_ntohl64(N) (N)
# define nghttp3_htonl64(N) (N)
# else // !defined(WORDS_BIGENDIAN)
# define nghttp3_bswap64(N) \
((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
# define nghttp3_ntohl64(N) nghttp3_bswap64(N)
# define nghttp3_htonl64(N) nghttp3_bswap64(N)
# endif // !defined(WORDS_BIGENDIAN)
#endif // !HAVE_DECL_BE64TOH

} // namespace nghttp3

Expand Down
28 changes: 14 additions & 14 deletions lib/includes/nghttp3/nghttp3.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@
libcurl) */
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
# define WIN32
#endif
#endif /* (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) */

#ifdef __cplusplus
extern "C" {
#endif
#endif /* defined(__cplusplus) */

#include <stdlib.h>
#if defined(_MSC_VER) && (_MSC_VER < 1800)
/* MSVC < 2013 does not have inttypes.h because it is not C99
compliant. See compiler macros and version number in
https://sourceforge.net/p/predef/wiki/Compilers/ */
# include <stdint.h>
#else /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */
#else /* !(defined(_MSC_VER) && (_MSC_VER < 1800)) */
# include <inttypes.h>
#endif /* !defined(_MSC_VER) || (_MSC_VER >= 1800) */
#endif /* !(defined(_MSC_VER) && (_MSC_VER < 1800)) */
#include <sys/types.h>
#include <stdarg.h>
#include <stddef.h>
Expand All @@ -57,22 +57,22 @@ extern "C" {
#elif defined(WIN32)
# ifdef BUILDING_NGHTTP3
# define NGHTTP3_EXTERN __declspec(dllexport)
# else /* !BUILDING_NGHTTP3 */
# else /* !defined(BUILDING_NGHTTP3) */
# define NGHTTP3_EXTERN __declspec(dllimport)
# endif /* !BUILDING_NGHTTP3 */
#else /* !defined(WIN32) */
# endif /* !defined(BUILDING_NGHTTP3) */
#else /* !(defined(NGHTTP3_STATICLIB) || defined(WIN32)) */
# ifdef BUILDING_NGHTTP3
# define NGHTTP3_EXTERN __attribute__((visibility("default")))
# else /* !BUILDING_NGHTTP3 */
# else /* !defined(BUILDING_NGHTTP3) */
# define NGHTTP3_EXTERN
# endif /* !BUILDING_NGHTTP3 */
#endif /* !defined(WIN32) */
# endif /* !defined(BUILDING_NGHTTP3) */
#endif /* !(defined(NGHTTP3_STATICLIB) || defined(WIN32)) */

#ifdef _MSC_VER
# define NGHTTP3_ALIGN(N) __declspec(align(N))
#else /* !_MSC_VER */
#else /* !defined(_MSC_VER) */
# define NGHTTP3_ALIGN(N) __attribute__((aligned(N)))
#endif /* !_MSC_VER */
#endif /* !defined(_MSC_VER) */

/**
* @typedef
Expand Down Expand Up @@ -2936,6 +2936,6 @@ NGHTTP3_EXTERN int nghttp3_err_is_fatal(int liberr);

#ifdef __cplusplus
}
#endif
#endif /* defined(__cplusplus) */

#endif /* NGHTTP3_H */
#endif /* !defined(NGHTTP3_H) */
2 changes: 1 addition & 1 deletion lib/includes/nghttp3/version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
*/
#define NGHTTP3_VERSION_NUM @PACKAGE_VERSION_NUM@

#endif /* NGHTTP3_VERSION_H */
#endif /* !defined(NGHTTP3_VERSION_H) */
4 changes: 2 additions & 2 deletions lib/nghttp3_balloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#endif /* defined(HAVE_CONFIG_H) */

#include <nghttp3/nghttp3.h>

Expand Down Expand Up @@ -92,4 +92,4 @@ int nghttp3_balloc_get(nghttp3_balloc *balloc, void **pbuf, size_t n);
*/
void nghttp3_balloc_clear(nghttp3_balloc *balloc);

#endif /* NGHTTP3_BALLOC_H */
#endif /* !defined(NGHTTP3_BALLOC_H) */
4 changes: 2 additions & 2 deletions lib/nghttp3_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#endif /* defined(HAVE_CONFIG_H) */

#include <nghttp3/nghttp3.h>

Expand Down Expand Up @@ -71,4 +71,4 @@ void nghttp3_typed_buf_init(nghttp3_typed_buf *tbuf, const nghttp3_buf *buf,

void nghttp3_typed_buf_free(nghttp3_typed_buf *tbuf);

#endif /* NGHTTP3_BUF_H */
#endif /* !defined(NGHTTP3_BUF_H) */
4 changes: 2 additions & 2 deletions lib/nghttp3_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#endif /* defined(HAVE_CONFIG_H) */

#include <nghttp3/nghttp3.h>

Expand Down Expand Up @@ -204,4 +204,4 @@ int nghttp3_conn_reject_stream(nghttp3_conn *conn, nghttp3_stream *stream);
*/
nghttp3_stream *nghttp3_conn_get_next_tx_stream(nghttp3_conn *conn);

#endif /* NGHTTP3_CONN_H */
#endif /* !defined(NGHTTP3_CONN_H) */
46 changes: 22 additions & 24 deletions lib/nghttp3_conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,69 +28,67 @@

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#endif /* defined(HAVE_CONFIG_H) */

#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif /* HAVE_ARPA_INET_H */
#endif /* defined(HAVE_ARPA_INET_H) */

#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif /* HAVE_NETINET_IN_H */
#endif /* defined(HAVE_NETINET_IN_H) */

#ifdef HAVE_BYTESWAP_H
# include <byteswap.h>
#endif /* HAVE_BYTESWAP_H */
#endif /* defined(HAVE_BYTESWAP_H) */

#ifdef HAVE_ENDIAN_H
# include <endian.h>
#endif /* HAVE_ENDIAN_H */
#endif /* defined(HAVE_ENDIAN_H) */

#ifdef HAVE_SYS_ENDIAN_H
# include <sys/endian.h>
#endif /* HAVE_SYS_ENDIAN_H */
#endif /* defined(HAVE_SYS_ENDIAN_H) */

#if defined(__APPLE__)
#ifdef __APPLE__
# include <libkern/OSByteOrder.h>
#endif // __APPLE__
#endif /* defined(__APPLE__) */

#include <nghttp3/nghttp3.h>

#if defined(HAVE_BE64TOH) || \
(defined(HAVE_DECL_BE64TOH) && HAVE_DECL_BE64TOH > 0)
#if HAVE_DECL_BE64TOH
# define nghttp3_ntohl64(N) be64toh(N)
# define nghttp3_htonl64(N) htobe64(N)
#else /* !HAVE_BE64TOH */
# if defined(WORDS_BIGENDIAN)
#else /* !HAVE_DECL_BE64TOH */
# ifdef WORDS_BIGENDIAN
# define nghttp3_ntohl64(N) (N)
# define nghttp3_htonl64(N) (N)
# else /* !WORDS_BIGENDIAN */
# if defined(HAVE_BSWAP_64) || \
(defined(HAVE_DECL_BSWAP_64) && HAVE_DECL_BSWAP_64 > 0)
# else /* !defined(WORDS_BIGENDIAN) */
# if HAVE_DECL_BSWAP_64
# define nghttp3_bswap64 bswap_64
# elif defined(WIN32)
# define nghttp3_bswap64 _byteswap_uint64
# elif defined(__APPLE__)
# define nghttp3_bswap64 OSSwapInt64
# else /* !HAVE_BSWAP_64 && !WIN32 && !__APPLE__ */
# else /* !(HAVE_DECL_BSWAP_64 || defined(WIN32) || defined(__APPLE__)) */
# define nghttp3_bswap64(N) \
((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
# endif /* !HAVE_BSWAP_64 && !WIN32 && !__APPLE__ */
# endif /* !(HAVE_DECL_BSWAP_64 || defined(WIN32) || defined(__APPLE__)) */
# define nghttp3_ntohl64(N) nghttp3_bswap64(N)
# define nghttp3_htonl64(N) nghttp3_bswap64(N)
# endif /* !WORDS_BIGENDIAN */
#endif /* !HAVE_BE64TOH */
# endif /* !defined(WORDS_BIGENDIAN) */
#endif /* !HAVE_DECL_BE64TOH */

#if defined(WIN32)
#ifdef WIN32
/* Windows requires ws2_32 library for ntonl family of functions. We
define inline functions for those functions so that we don't have
dependency on that lib. */

# ifdef _MSC_VER
# define STIN static __inline
# else
# else /* !defined(_MSC_VER) */
# define STIN static inline
# endif
# endif /* !defined(_MSC_VER) */

STIN uint32_t htonl(uint32_t hostlong) {
uint32_t res;
Expand Down Expand Up @@ -128,7 +126,7 @@ STIN uint16_t ntohs(uint16_t netshort) {
return res;
}

#endif /* WIN32 */
#endif /* defined(WIN32) */

/*
* nghttp3_get_varint reads variable-length unsigned integer from |p|,
Expand Down Expand Up @@ -193,4 +191,4 @@ uint64_t nghttp3_ord_stream_id(int64_t stream_id);
*/
#define NGHTTP3_PRI_INC_MASK (1 << 7)

#endif /* NGHTTP3_CONV_H */
#endif /* !defined(NGHTTP3_CONV_H) */
4 changes: 2 additions & 2 deletions lib/nghttp3_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ void nghttp3_set_debug_vprintf_callback(
static_debug_vprintf_callback = debug_vprintf_callback;
}

#else /* !DEBUGBUILD */
#else /* !defined(DEBUGBUILD) */

void nghttp3_set_debug_vprintf_callback(
nghttp3_debug_vprintf_callback debug_vprintf_callback) {
(void)debug_vprintf_callback;
}

#endif /* !DEBUGBUILD */
#endif /* !defined(DEBUGBUILD) */
8 changes: 4 additions & 4 deletions lib/nghttp3_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#endif /* defined(HAVE_CONFIG_H) */

#include <nghttp3/nghttp3.h>

#ifdef DEBUGBUILD
# define DEBUGF(...) nghttp3_debug_vprintf(__VA_ARGS__)
void nghttp3_debug_vprintf(const char *format, ...);
#else
#else /* !defined(DEBUGBUILD) */
# define DEBUGF(...) \
do { \
} while (0)
#endif
#endif /* !defined(DEBUGBUILD) */

#endif /* NGHTTP3_DEBUG_H */
#endif /* !defined(NGHTTP3_DEBUG_H) */
Loading

0 comments on commit a872b6c

Please sign in to comment.