1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 15:48:49 -05:00

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.
This commit is contained in:
Yang Tse 2011-09-02 19:40:53 +02:00
parent 749dbfbc87
commit 9194e17003
8 changed files with 48 additions and 19 deletions

View File

@ -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 */

View File

@ -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 {

View File

@ -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) {

View File

@ -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 */

View File

@ -302,6 +302,27 @@ struct timeval {
#endif
/*
* 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

View File

@ -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;
}

View File

@ -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 */

View File

@ -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);