Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add static to non-public functions, helped by -Wmissing-prototypes #942

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ if (MSVC)
CONFIGURATIONS Debug RelWithDebInfo)
endif()

IF ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
# set the same warning options as Makefile
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers")
ENDIF()

# For NuGet packages
INSTALL(FILES hiredis.targets
DESTINATION build/native)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export REDIS_TEST_CONFIG
CC:=$(shell sh -c 'type $${CC%% *} >/dev/null 2>/dev/null && echo $(CC) || echo gcc')
CXX:=$(shell sh -c 'type $${CXX%% *} >/dev/null 2>/dev/null && echo $(CXX) || echo g++')
OPTIMIZATION?=-O3
WARNINGS=-Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers
WARNINGS=-Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers
DEBUG_FLAGS?= -g -ggdb
REAL_CFLAGS=$(OPTIMIZATION) -fPIC $(CPPFLAGS) $(CFLAGS) $(WARNINGS) $(DEBUG_FLAGS)
REAL_LDFLAGS=$(LDFLAGS)
Expand Down
5 changes: 1 addition & 4 deletions async.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "dict.c"
#include "sds.h"
#include "win32.h"
#include "private.h"

#include "async_private.h"

Expand All @@ -52,10 +53,6 @@
#define assert(e) (void)(e)
#endif

/* Forward declarations of hiredis.c functions */
int __redisAppendCommand(redisContext *c, const char *cmd, size_t len);
void __redisSetError(redisContext *c, int type, const char *str);

/* Functions managing dictionary of callbacks for pub/sub. */
static unsigned int callbackHash(const void *key) {
return dictGenHashFunction((const unsigned char *)key,
Expand Down
4 changes: 1 addition & 3 deletions hiredis.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@
#include "sds.h"
#include "async.h"
#include "win32.h"

extern int redisContextUpdateConnectTimeout(redisContext *c, const struct timeval *timeout);
extern int redisContextUpdateCommandTimeout(redisContext *c, const struct timeval *timeout);
#include "private.h"

static redisContextFuncs redisContextDefaultFuncs = {
.free_privctx = NULL,
Expand Down
4 changes: 1 addition & 3 deletions net.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
#include "sds.h"
#include "sockcompat.h"
#include "win32.h"

/* Defined in hiredis.c */
void __redisSetError(redisContext *c, int type, const char *str);
#include "private.h"

void redisNetClose(redisContext *c) {
if (c && c->fd != REDIS_INVALID_FD) {
Expand Down
11 changes: 11 additions & 0 deletions private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef __HIREDIS_INTERNAL_H
#define __HIREDIS_INTERNAL_H

#include "hiredis.h"

int redisContextUpdateCommandTimeout(redisContext *c, const struct timeval *timeout);
int redisContextUpdateConnectTimeout(redisContext *c, const struct timeval *timeout);
void __redisSetError(redisContext *c, int type, const char *str);
int __redisAppendCommand(redisContext *c, const char *cmd, size_t len);

#endif
6 changes: 3 additions & 3 deletions sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ sds sdscpy(sds s, const char *t) {
* The function returns the length of the null-terminated string
* representation stored at 's'. */
#define SDS_LLSTR_SIZE 21
int sdsll2str(char *s, long long value) {
static int sdsll2str(char *s, long long value) {
char *p, aux;
unsigned long long v;
size_t l;
Expand Down Expand Up @@ -460,7 +460,7 @@ int sdsll2str(char *s, long long value) {
}

/* Identical sdsll2str(), but for unsigned long long type. */
int sdsull2str(char *s, unsigned long long v) {
static int sdsull2str(char *s, unsigned long long v) {
char *p, aux;
size_t l;

Expand Down Expand Up @@ -896,7 +896,7 @@ sds sdscatrepr(sds s, const char *p, size_t len) {

/* Helper function for sdssplitargs() that converts a hex digit into an
* integer from 0 to 15 */
int hex_digit_to_int(char c) {
static int hex_digit_to_int(char c) {
switch(c) {
case '0': return 0;
case '1': return 1;
Expand Down
12 changes: 6 additions & 6 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static long long usec(void) {

/* Helper to extract Redis version information. Aborts on any failure. */
#define REDIS_VERSION_FIELD "redis_version:"
void get_redis_version(redisContext *c, int *majorptr, int *minorptr) {
static void get_redis_version(redisContext *c, int *majorptr, int *minorptr) {
redisReply *reply;
char *eptr, *s, *e;
int major, minor;
Expand Down Expand Up @@ -825,7 +825,7 @@ static void test_blocking_connection_errors(void) {
}

/* Test push handler */
void push_handler(void *privdata, void *r) {
static void push_handler(void *privdata, void *r) {
struct pushCounters *pcounts = privdata;
redisReply *reply = r, *payload;

Expand All @@ -846,7 +846,7 @@ void push_handler(void *privdata, void *r) {
}

/* Dummy function just to test setting a callback with redisOptions */
void push_handler_async(redisAsyncContext *ac, void *reply) {
static void push_handler_async(redisAsyncContext *ac, void *reply) {
(void)ac;
(void)reply;
}
Expand Down Expand Up @@ -911,7 +911,7 @@ static void test_resp3_push_handler(redisContext *c) {
send_hello(c, 2);
}

redisOptions get_redis_tcp_options(struct config config) {
static redisOptions get_redis_tcp_options(struct config config) {
redisOptions options = {0};
REDIS_OPTIONS_SET_TCP(&options, config.tcp.host, config.tcp.port);
return options;
Expand Down Expand Up @@ -956,7 +956,7 @@ static void test_resp3_push_options(struct config config) {
redisAsyncFree(ac);
}

void free_privdata(void *privdata) {
static void free_privdata(void *privdata) {
struct privdata *data = privdata;
data->dtor_counter++;
}
Expand Down Expand Up @@ -1213,7 +1213,7 @@ static void test_invalid_timeout_errors(struct config config) {

/* Wrap malloc to abort on failure so OOM checks don't make the test logic
* harder to follow. */
void *hi_malloc_safe(size_t size) {
static void *hi_malloc_safe(size_t size) {
void *ptr = hi_malloc(size);
if (ptr == NULL) {
fprintf(stderr, "Error: Out of memory\n");
Expand Down