Skip to content

Commit 2510268

Browse files
authored
Merge pull request libgit2#4700 from pks-t/pks/std-c90
C90 standard compliance
2 parents 6dfc8bc + e1a4a8e commit 2510268

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+239
-200
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ ELSE ()
196196
ENABLE_WARNINGS(extra)
197197

198198
IF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
199-
SET(CMAKE_C_FLAGS "-std=c99 -D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}")
199+
SET(CMAKE_C_FLAGS "-D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}")
200200
ENDIF()
201201

202202
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG -O0")

examples/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
INCLUDE_DIRECTORIES(${LIBGIT2_INCLUDES})
2+
INCLUDE_DIRECTORIES(SYSTEM ${LIBGIT2_SYSTEM_INCLUDES})
23

34
FILE(GLOB_RECURSE SRC_EXAMPLE_GIT2 network/*.c network/*.h common.?)
45
ADD_EXECUTABLE(cgit2 ${SRC_EXAMPLE_GIT2})
6+
SET_TARGET_PROPERTIES(cgit2 PROPERTIES C_STANDARD 90)
7+
58
IF(WIN32 OR ANDROID)
69
TARGET_LINK_LIBRARIES(cgit2 git2)
710
ELSE()
@@ -14,5 +17,6 @@ FOREACH(src_app ${SRC_EXAMPLE_APPS})
1417
IF(NOT ${app_name} STREQUAL "common")
1518
ADD_EXECUTABLE(${app_name} ${src_app} "common.c")
1619
TARGET_LINK_LIBRARIES(${app_name} git2)
20+
SET_TARGET_PROPERTIES(${app_name} PROPERTIES C_STANDARD 90)
1721
ENDIF()
1822
ENDFOREACH()

examples/general.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,13 @@ static void oid_parsing(git_oid *oid)
145145
*/
146146
git_oid_fromstr(oid, hex);
147147

148-
// Once we've converted the string into the oid value, we can get the raw
149-
// value of the SHA by accessing `oid.id`
150-
151-
// Next we will convert the 20 byte raw SHA1 value to a human readable 40
152-
// char hex value.
148+
/*
149+
* Once we've converted the string into the oid value, we can get the raw
150+
* value of the SHA by accessing `oid.id`
151+
*
152+
* Next we will convert the 20 byte raw SHA1 value to a human readable 40
153+
* char hex value.
154+
*/
153155
printf("\n*Raw to Hex*\n");
154156
out[GIT_OID_HEXSZ] = '\0';
155157

examples/network/clone.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static void print_progress(const progress_data *pd)
4848

4949
static int sideband_progress(const char *str, int len, void *payload)
5050
{
51-
(void)payload; // unused
51+
(void)payload; /* unused */
5252

5353
printf("remote: %.*s", len, str);
5454
fflush(stdout);
@@ -82,15 +82,15 @@ int do_clone(git_repository *repo, int argc, char **argv)
8282
const char *path = argv[2];
8383
int error;
8484

85-
(void)repo; // unused
85+
(void)repo; /* unused */
8686

87-
// Validate args
87+
/* Validate args */
8888
if (argc < 3) {
8989
printf ("USAGE: %s <url> <path>\n", argv[0]);
9090
return -1;
9191
}
9292

93-
// Set up options
93+
/* Set up options */
9494
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
9595
checkout_opts.progress_cb = checkout_progress;
9696
checkout_opts.progress_payload = &pd;
@@ -100,7 +100,7 @@ int do_clone(git_repository *repo, int argc, char **argv)
100100
clone_opts.fetch_opts.callbacks.credentials = cred_acquire_cb;
101101
clone_opts.fetch_opts.callbacks.payload = &pd;
102102

103-
// Do the clone
103+
/* Do the clone */
104104
error = git_clone(&cloned_repo, url, path, &clone_opts);
105105
printf("\n");
106106
if (error != 0) {

examples/network/index-pack.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
#endif
2020
#include "common.h"
2121

22-
// This could be run in the main loop whilst the application waits for
23-
// the indexing to finish in a worker thread
22+
/*
23+
* This could be run in the main loop whilst the application waits for
24+
* the indexing to finish in a worker thread
25+
*/
2426
static int index_cb(const git_transfer_progress *stats, void *data)
2527
{
2628
(void)data;

examples/network/ls-remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static int use_remote(git_repository *repo, char *name)
1212
size_t refs_len, i;
1313
git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
1414

15-
// Find the remote by name
15+
/* Find the remote by name */
1616
error = git_remote_lookup(&remote, repo, name);
1717
if (error < 0) {
1818
error = git_remote_create_anonymous(&remote, repo, name);

src/CMakeLists.txt

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ SET(LIBGIT2_INCLUDES
1616
"${CMAKE_CURRENT_BINARY_DIR}"
1717
"${libgit2_SOURCE_DIR}/src"
1818
"${libgit2_SOURCE_DIR}/include")
19+
SET(LIBGIT2_SYSTEM_INCLUDES "")
1920
SET(LIBGIT2_LIBS "")
2021

2122
# Installation paths
@@ -94,7 +95,7 @@ ADD_FEATURE_INFO(threadsafe THREADSAFE "threadsafe support")
9495

9596
IF (WIN32 AND EMBED_SSH_PATH)
9697
FILE(GLOB SRC_SSH "${EMBED_SSH_PATH}/src/*.c")
97-
LIST(APPEND LIBGIT2_INCLUDES "${EMBED_SSH_PATH}/include")
98+
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES "${EMBED_SSH_PATH}/include")
9899
FILE(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
99100
SET(GIT_SSH 1)
100101
ENDIF()
@@ -107,7 +108,7 @@ IF (WIN32 AND WINHTTP)
107108
IF (MINGW)
108109
ADD_SUBDIRECTORY("${libgit2_SOURCE_DIR}/deps/winhttp" "${libgit2_BINARY_DIR}/deps/winhttp")
109110
LIST(APPEND LIBGIT2_LIBS winhttp)
110-
LIST(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/winhttp")
111+
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES "${libgit2_SOURCE_DIR}/deps/winhttp")
111112
ELSE()
112113
LIST(APPEND LIBGIT2_LIBS "winhttp")
113114
LIST(APPEND LIBGIT2_PC_LIBS "-lwinhttp")
@@ -121,7 +122,7 @@ ELSE ()
121122
ENDIF ()
122123
IF (CURL_FOUND)
123124
SET(GIT_CURL 1)
124-
LIST(APPEND LIBGIT2_INCLUDES ${CURL_INCLUDE_DIRS})
125+
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${CURL_INCLUDE_DIRS})
125126
LIST(APPEND LIBGIT2_LIBS ${CURL_LIBRARIES})
126127
LIST(APPEND LIBGIT2_PC_LIBS ${CURL_LDFLAGS})
127128
ENDIF()
@@ -174,7 +175,7 @@ IF (USE_HTTPS)
174175
ENDIF()
175176

176177
SET(GIT_SECURE_TRANSPORT 1)
177-
LIST(APPEND LIBGIT2_INCLUDES ${SECURITY_INCLUDE_DIR})
178+
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${SECURITY_INCLUDE_DIR})
178179
LIST(APPEND LIBGIT2_LIBS ${COREFOUNDATION_LIBRARIES} ${SECURITY_LIBRARIES})
179180
LIST(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS})
180181
ELSEIF (HTTPS_BACKEND STREQUAL "OpenSSL")
@@ -183,7 +184,7 @@ IF (USE_HTTPS)
183184
ENDIF()
184185

185186
SET(GIT_OPENSSL 1)
186-
LIST(APPEND LIBGIT2_INCLUDES ${OPENSSL_INCLUDE_DIR})
187+
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${OPENSSL_INCLUDE_DIR})
187188
LIST(APPEND LIBGIT2_LIBS ${OPENSSL_LIBRARIES})
188189
LIST(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS})
189190
LIST(APPEND LIBGIT2_PC_REQUIRES "openssl")
@@ -230,7 +231,7 @@ IF (USE_HTTPS)
230231
ENDIF()
231232

232233
SET(GIT_MBEDTLS 1)
233-
LIST(APPEND LIBGIT2_INCLUDES ${MBEDTLS_INCLUDE_DIR})
234+
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
234235
LIST(APPEND LIBGIT2_LIBS ${MBEDTLS_LIBRARIES})
235236
# mbedTLS has no pkgconfig file, hence we can't require it
236237
# https://github.com/ARMmbed/mbedtls/issues/228
@@ -285,7 +286,7 @@ ELSEIF (SHA1_BACKEND STREQUAL "mbedTLS")
285286
ADD_FEATURE_INFO(SHA ON "using mbedTLS")
286287
SET(GIT_SHA1_MBEDTLS 1)
287288
FILE(GLOB SRC_SHA1 hash/hash_mbedtls.c)
288-
LIST(APPEND LIBGIT2_INCLUDES ${MBEDTLS_INCLUDE_DIR})
289+
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
289290
LIST(APPEND LIBGIT2_LIBS ${MBEDTLS_LIBRARIES})
290291
# mbedTLS has no pkgconfig file, hence we can't require it
291292
# https://github.com/ARMmbed/mbedtls/issues/228
@@ -298,21 +299,21 @@ ENDIF()
298299
# Include POSIX regex when it is required
299300
IF(WIN32 OR AMIGA OR CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
300301
ADD_SUBDIRECTORY("${libgit2_SOURCE_DIR}/deps/regex" "${libgit2_BINARY_DIR}/deps/regex")
301-
LIST(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/regex")
302+
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES "${libgit2_SOURCE_DIR}/deps/regex")
302303
LIST(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:regex>)
303304
ENDIF()
304305

305306
# Optional external dependency: http-parser
306307
FIND_PACKAGE(HTTP_Parser)
307308
IF (USE_EXT_HTTP_PARSER AND HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
308-
LIST(APPEND LIBGIT2_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS})
309+
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS})
309310
LIST(APPEND LIBGIT2_LIBS ${HTTP_PARSER_LIBRARIES})
310311
LIST(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
311312
ADD_FEATURE_INFO(http-parser ON "http-parser support")
312313
ELSE()
313314
MESSAGE(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.")
314315
ADD_SUBDIRECTORY("${libgit2_SOURCE_DIR}/deps/http-parser" "${libgit2_BINARY_DIR}/deps/http-parser")
315-
LIST(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/http-parser")
316+
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES "${libgit2_SOURCE_DIR}/deps/http-parser")
316317
LIST(APPEND LIBGIT2_OBJECTS "$<TARGET_OBJECTS:http-parser>")
317318
ADD_FEATURE_INFO(http-parser ON "http-parser support (bundled)")
318319
ENDIF()
@@ -321,7 +322,7 @@ ENDIF()
321322
IF(NOT USE_BUNDLED_ZLIB)
322323
FIND_PACKAGE(ZLIB)
323324
IF(ZLIB_FOUND)
324-
LIST(APPEND LIBGIT2_INCLUDES ${ZLIB_INCLUDE_DIRS})
325+
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${ZLIB_INCLUDE_DIRS})
325326
LIST(APPEND LIBGIT2_LIBS ${ZLIB_LIBRARIES})
326327
IF(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
327328
LIST(APPEND LIBGIT2_LIBS "z")
@@ -336,7 +337,7 @@ IF(NOT USE_BUNDLED_ZLIB)
336337
ENDIF()
337338
IF(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND)
338339
ADD_SUBDIRECTORY("${libgit2_SOURCE_DIR}/deps/zlib" "${libgit2_BINARY_DIR}/deps/zlib")
339-
LIST(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/zlib")
340+
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES "${libgit2_SOURCE_DIR}/deps/zlib")
340341
LIST(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:zlib>)
341342
ADD_FEATURE_INFO(zlib ON "using bundled zlib")
342343
ENDIF()
@@ -347,7 +348,7 @@ IF (USE_SSH)
347348
ENDIF()
348349
IF (LIBSSH2_FOUND)
349350
SET(GIT_SSH 1)
350-
LIST(APPEND LIBGIT2_INCLUDES ${LIBSSH2_INCLUDE_DIRS})
351+
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${LIBSSH2_INCLUDE_DIRS})
351352
LIST(APPEND LIBGIT2_LIBS ${LIBSSH2_LIBRARIES})
352353
LIST(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
353354

@@ -376,7 +377,7 @@ IF (USE_ICONV)
376377
ENDIF()
377378
IF (ICONV_FOUND)
378379
SET(GIT_USE_ICONV 1)
379-
LIST(APPEND LIBGIT2_INCLUDES ${ICONV_INCLUDE_DIR})
380+
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${ICONV_INCLUDE_DIR})
380381
LIST(APPEND LIBGIT2_LIBS ${ICONV_LIBRARIES})
381382
LIST(APPEND LIBGIT2_PC_LIBS ${ICONV_LIBRARIES})
382383
ENDIF()
@@ -449,19 +450,24 @@ CONFIGURE_FILE(features.h.in git2/sys/features.h)
449450
SET(LIBGIT2_SOURCES ${SRC_H} ${SRC_GIT2} ${SRC_OS} ${SRC_SSH} ${SRC_SHA1})
450451

451452
ADD_LIBRARY(git2internal OBJECT ${LIBGIT2_SOURCES})
453+
SET_TARGET_PROPERTIES(git2internal PROPERTIES C_STANDARD 90)
452454
IDE_SPLIT_SOURCES(git2internal)
453455
LIST(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:git2internal>)
454456

455457
IF (${CMAKE_VERSION} VERSION_LESS 2.8.12)
456458
INCLUDE_DIRECTORIES(${LIBGIT2_INCLUDES})
459+
INCLUDE_DIRECTORIES(SYSTEM ${LIBGIT2_SYSTEM_INCLUDES})
457460
ELSE()
458461
TARGET_INCLUDE_DIRECTORIES(git2internal
459462
PRIVATE ${LIBGIT2_INCLUDES}
460463
PUBLIC ${libgit2_SOURCE_DIR}/include)
464+
TARGET_INCLUDE_DIRECTORIES(git2internal
465+
SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
461466
ENDIF()
462467

463468
SET(LIBGIT2_OBJECTS ${LIBGIT2_OBJECTS} PARENT_SCOPE)
464469
SET(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE)
470+
SET(LIBGIT2_SYSTEM_INCLUDES ${LIBGIT2_SYSTEM_INCLUDES} PARENT_SCOPE)
465471
SET(LIBGIT2_LIBS ${LIBGIT2_LIBS} PARENT_SCOPE)
466472

467473
IF(XCODE_VERSION)
@@ -475,6 +481,7 @@ ENDIF()
475481
ADD_LIBRARY(git2 ${WIN_RC} ${LIBGIT2_OBJECTS})
476482
TARGET_LINK_LIBRARIES(git2 ${LIBGIT2_LIBS})
477483

484+
SET_TARGET_PROPERTIES(git2 PROPERTIES C_STANDARD 90)
478485
SET_TARGET_PROPERTIES(git2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})
479486
SET_TARGET_PROPERTIES(git2 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})
480487
SET_TARGET_PROPERTIES(git2 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})

src/common.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
/** Declare a function as always inlined. */
1818
#if defined(_MSC_VER)
1919
# define GIT_INLINE(type) static __inline type
20+
#elif defined(__GNUC__)
21+
# define GIT_INLINE(type) static __inline__ type
2022
#else
21-
# define GIT_INLINE(type) static inline type
23+
# define GIT_INLINE(type) static type
2224
#endif
2325

2426
/** Support for gcc/clang __has_builtin intrinsic */

src/khash.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ typedef unsigned long long khint64_t;
146146
#ifndef kh_inline
147147
#ifdef _MSC_VER
148148
#define kh_inline __inline
149+
#elif defined(__GNUC__)
150+
#define kh_inline __inline__
149151
#else
150-
#define kh_inline inline
152+
#define kh_inline
151153
#endif
152154
#endif /* kh_inline */
153155

src/notes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static int note_write(
285285
git_oid oid;
286286
git_tree *tree = NULL;
287287

288-
// TODO: should we apply filters?
288+
/* TODO: should we apply filters? */
289289
/* create note object */
290290
if ((error = git_blob_create_frombuffer(&oid, repo, note, strlen(note))) < 0)
291291
goto cleanup;

0 commit comments

Comments
 (0)