summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2011-09-02 19:40:53 +0200
committerYang Tse <yangsita@gmail.com>2011-09-02 19:40:53 +0200
commit9194e1700312f27c6e2abdfb1f604e130497e887 (patch)
treeb8aff846ffca0041e9865850875025968fa9fc7e /lib
parent749dbfbc87d6043c4bfb57041ecbf2be6a1d42bb (diff)
downloadgnurl-9194e1700312f27c6e2abdfb1f604e130497e887.tar.gz
gnurl-9194e1700312f27c6e2abdfb1f604e130497e887.tar.bz2
gnurl-9194e1700312f27c6e2abdfb1f604e130497e887.zip
MemoryTracking: fix logging of free() calls done where Curl_safefree is called
Just internal stuff... Curl_safefree is now a macro defined in memdebug.h instead of a function prototyped in url.h and implemented in url.c, so inclusion of url.h is no longer required in order to simply use Curl_safefree. Provide definition of macro WHILE_FALSE in setup_once.h in order to allow other macros such as DEBUGF and DEBUGASSERT, and code using it, to compile without 'conditional expression is constant' warnings. The WHILE_FALSE stuff fixes 150+ MSVC compiler warnings.
Diffstat (limited to 'lib')
-rw-r--r--lib/memdebug.h18
-rw-r--r--lib/mprintf.c2
-rw-r--r--lib/multi.c6
-rw-r--r--lib/select.c4
-rw-r--r--lib/setup_once.h25
-rw-r--r--lib/transfer.c5
-rw-r--r--lib/url.c6
-rw-r--r--lib/url.h1
8 files changed, 48 insertions, 19 deletions
diff --git a/lib/memdebug.h b/lib/memdebug.h
index 02df08877..a042bb474 100644
--- a/lib/memdebug.h
+++ b/lib/memdebug.h
@@ -1,6 +1,6 @@
-#ifdef CURLDEBUG
#ifndef HEADER_CURL_MEMDEBUG_H
#define HEADER_CURL_MEMDEBUG_H
+#ifdef CURLDEBUG
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
@@ -139,9 +139,21 @@ CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
#endif /* MEMDEBUG_NODEFINES */
-#endif /* HEADER_CURL_MEMDEBUG_H */
#endif /* CURLDEBUG */
+/*
+** Following section applies even when CURLDEBUG is not defined.
+*/
+
#ifndef fake_sclose
-#define fake_sclose(x)
+#define fake_sclose(x) do { } WHILE_FALSE
#endif
+
+/*
+ * Curl_safefree defined as a macro to allow MemoryTracking feature
+ * to log free() calls at same location where Curl_safefree is used.
+ */
+
+#define Curl_safefree(ptr) do {if((ptr)) free((ptr));} WHILE_FALSE
+
+#endif /* HEADER_CURL_MEMDEBUG_H */
diff --git a/lib/mprintf.c b/lib/mprintf.c
index 38732e099..0990f4024 100644
--- a/lib/mprintf.c
+++ b/lib/mprintf.c
@@ -103,7 +103,7 @@ static const char upper_digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
done++; \
else \
return done; /* return immediately on failure */ \
- } while(0)
+ } WHILE_FALSE
/* Data type to read from the arglist */
typedef enum {
diff --git a/lib/multi.c b/lib/multi.c
index aee190cea..d100ef0a0 100644
--- a/lib/multi.c
+++ b/lib/multi.c
@@ -952,8 +952,8 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
data = easy->easy_handle;
do {
- /* this is a do-while loop just to allow a break to skip to the end
- of it */
+ /* this is a single-iteration do-while loop just to allow a
+ break to skip to the end of it */
bool disconnect_conn = FALSE;
/* Handle the case when the pipe breaks, i.e., the connection
@@ -1657,7 +1657,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
else if(easy->easy_conn && Curl_pgrsUpdate(easy->easy_conn))
easy->result = CURLE_ABORTED_BY_CALLBACK;
}
- } while(0);
+ } WHILE_FALSE; /* just to break out from! */
if(CURLM_STATE_COMPLETED == easy->state) {
if(data->dns.hostcachetype == HCACHE_MULTI) {
diff --git a/lib/select.c b/lib/select.c
index 56dbc44f4..bd5fa075d 100644
--- a/lib/select.c
+++ b/lib/select.c
@@ -49,7 +49,7 @@
/* Winsock and TPF sockets are not in range [0..FD_SETSIZE-1] */
#if defined(USE_WINSOCK) || defined(TPF)
-#define VERIFY_SOCK(x) do { } while(0)
+#define VERIFY_SOCK(x) do { } WHILE_FALSE
#else
#define VALID_SOCK(s) (((s) >= 0) && ((s) < FD_SETSIZE))
#define VERIFY_SOCK(x) do { \
@@ -57,7 +57,7 @@
SET_SOCKERRNO(EINVAL); \
return -1; \
} \
-} while(0)
+} WHILE_FALSE
#endif
/* Convenience local macros */
diff --git a/lib/setup_once.h b/lib/setup_once.h
index 4f7d0d791..63a3698de 100644
--- a/lib/setup_once.h
+++ b/lib/setup_once.h
@@ -303,6 +303,27 @@ struct timeval {
/*
+ * Macro WHILE_FALSE may be used to build single-iteration do-while loops,
+ * avoiding compiler warnings. Mostly intended for other macro definitions.
+ */
+
+#define WHILE_FALSE while(0)
+
+#if defined(_MSC_VER) && !defined(__POCC__)
+# undef WHILE_FALSE
+# if (_MSC_VER < 1500)
+# define WHILE_FALSE while(1, 0)
+# else
+# define WHILE_FALSE \
+__pragma(warning(push)) \
+__pragma(warning(disable:4127)) \
+while(0) \
+__pragma(warning(pop))
+# endif
+#endif
+
+
+/*
* Typedef to 'int' if sig_atomic_t is not an available 'typedefed' type.
*/
@@ -339,7 +360,7 @@ typedef int sig_atomic_t;
#ifdef DEBUGBUILD
#define DEBUGF(x) x
#else
-#define DEBUGF(x) do { } while (0)
+#define DEBUGF(x) do { } WHILE_FALSE
#endif
@@ -350,7 +371,7 @@ typedef int sig_atomic_t;
#if defined(DEBUGBUILD) && defined(HAVE_ASSERT_H)
#define DEBUGASSERT(x) assert(x)
#else
-#define DEBUGASSERT(x) do { } while (0)
+#define DEBUGASSERT(x) do { } WHILE_FALSE
#endif
diff --git a/lib/transfer.c b/lib/transfer.c
index b0ae8f02a..dbb06dbd5 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -800,6 +800,9 @@ static CURLcode readwrite_upload(struct SessionHandle *data,
/*
* We loop here to do the READ and SEND loop until we run out of
* data to send or until we get EWOULDBLOCK back
+ *
+ * FIXME: above comment is misleading. Currently no looping is
+ * actually done in do-while loop below.
*/
do {
@@ -971,7 +974,7 @@ static CURLcode readwrite_upload(struct SessionHandle *data,
Curl_pgrsSetUploadCounter(data, k->writebytecount);
- } while(0); /* just to break out from! */
+ } WHILE_FALSE; /* just to break out from! */
return CURLE_OK;
}
diff --git a/lib/url.c b/lib/url.c
index 4d39f2e01..23ca7a5d4 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -252,12 +252,6 @@ static const struct Curl_handler Curl_handler_dummy = {
PROTOPT_NONE /* flags */
};
-void Curl_safefree(void *ptr)
-{
- if(ptr)
- free(ptr);
-}
-
static void close_connections(struct SessionHandle *data)
{
/* Loop through all open connections and kill them one by one */
diff --git a/lib/url.h b/lib/url.h
index 677e63954..62e3ef3ef 100644
--- a/lib/url.h
+++ b/lib/url.h
@@ -42,7 +42,6 @@ CURLcode Curl_disconnect(struct connectdata *, bool dead_connection);
CURLcode Curl_protocol_connect(struct connectdata *conn, bool *done);
CURLcode Curl_protocol_connecting(struct connectdata *conn, bool *done);
CURLcode Curl_protocol_doing(struct connectdata *conn, bool *done);
-void Curl_safefree(void *ptr);
CURLcode Curl_setup_conn(struct connectdata *conn,
bool *protocol_done);