From 0102aaeb6b513fb40fef51103780fe121e13f549 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 18 Dec 2012 13:10:16 -0500 Subject: [PATCH 01/14] Define SIZEOF_INTPTR_T when defining replacement intptr_t Fixes bug 7669 --- src/common/torint.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common/torint.h b/src/common/torint.h index 0db9cc7e24..1d76ee6ac6 100644 --- a/src/common/torint.h +++ b/src/common/torint.h @@ -214,16 +214,20 @@ typedef int32_t ssize_t; #if (SIZEOF_VOID_P > 4 && SIZEOF_VOID_P <= 8) #ifndef HAVE_INTPTR_T typedef int64_t intptr_t; +#define SIZEOF_INTPTR_T 8 #endif #ifndef HAVE_UINTPTR_T typedef uint64_t uintptr_t; +#define SIZEOF_UINTPTR_T 8 #endif #elif (SIZEOF_VOID_P > 2 && SIZEOF_VOID_P <= 4) #ifndef HAVE_INTPTR_T typedef int32_t intptr_t; +#define SIZEOF_INTPTR_T 4 #endif #ifndef HAVE_UINTPTR_T typedef uint32_t uintptr_t; +#define SIZEOF_UINTPTR_T 4 #endif #else #error "void * is either >8 bytes or <= 2. In either case, I am confused." From b7dd71619519237af1383ee7185846fad3a5cdbe Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 18 Dec 2012 13:16:48 -0500 Subject: [PATCH 02/14] Add missing includes and libs to makefile.nmake Fixes bugs 7312 and 7310. --- src/common/Makefile.nmake | 2 +- src/or/Makefile.nmake | 11 ++++++----- src/test/Makefile.nmake | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/common/Makefile.nmake b/src/common/Makefile.nmake index e548273670..55923d2ebb 100644 --- a/src/common/Makefile.nmake +++ b/src/common/Makefile.nmake @@ -1,6 +1,6 @@ all: libor.lib libor-crypto.lib libor-event.lib -CFLAGS = /I ..\win32 /I ..\..\..\build-alpha\include +CFLAGS = /I ..\win32 /I ..\..\..\build-alpha\include /I ..\ext LIBOR_OBJECTS = address.obj compat.obj container.obj di_ops.obj \ log.obj memarea.obj mempool.obj procmon.obj util.obj \ diff --git a/src/or/Makefile.nmake b/src/or/Makefile.nmake index 677618e74f..71d18c11b0 100644 --- a/src/or/Makefile.nmake +++ b/src/or/Makefile.nmake @@ -1,11 +1,12 @@ all: tor.exe -CFLAGS = /I ..\win32 /I ..\..\..\build-alpha\include /I ..\common +CFLAGS = /I ..\win32 /I ..\..\..\build-alpha\include /I ..\common \ + /I ..\ext -LIBS = ..\..\..\build-alpha\lib\libevent.a \ - ..\..\..\build-alpha\lib\libcrypto.a \ - ..\..\..\build-alpha\lib\libssl.a \ - ..\..\..\build-alpha\lib\libz.a \ +LIBS = ..\..\..\build-alpha\lib\libevent.lib \ + ..\..\..\build-alpha\lib\libcrypto.lib \ + ..\..\..\build-alpha\lib\libssl.lib \ + ..\..\..\build-alpha\lib\libz.lib \ ws2_32.lib advapi32.lib shell32.lib LIBTOR_OBJECTS = buffers.obj channel.obj channeltls.obj circuitbuild.obj \ diff --git a/src/test/Makefile.nmake b/src/test/Makefile.nmake index aec477cf99..9580e39f4d 100644 --- a/src/test/Makefile.nmake +++ b/src/test/Makefile.nmake @@ -1,6 +1,7 @@ all: test.exe -CFLAGS = /I ..\win32 /I ..\..\..\build-alpha\include /I ..\common /I ..\or +CFLAGS = /I ..\win32 /I ..\..\..\build-alpha\include /I ..\common /I ..\or \ + /I ..\ext LIBS = ..\..\..\build-alpha\lib\libevent.lib \ ..\..\..\build-alpha\lib\libcrypto.lib \ From fb497dfe9eecafdab149a53f1b7fdd8a1d3a76a0 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 18 Dec 2012 13:20:32 -0500 Subject: [PATCH 03/14] Add missing objects to Makefile.nmake --- src/or/Makefile.nmake | 59 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 9 deletions(-) diff --git a/src/or/Makefile.nmake b/src/or/Makefile.nmake index 71d18c11b0..568c7455eb 100644 --- a/src/or/Makefile.nmake +++ b/src/or/Makefile.nmake @@ -9,15 +9,56 @@ LIBS = ..\..\..\build-alpha\lib\libevent.lib \ ..\..\..\build-alpha\lib\libz.lib \ ws2_32.lib advapi32.lib shell32.lib -LIBTOR_OBJECTS = buffers.obj channel.obj channeltls.obj circuitbuild.obj \ - circuitlist.obj circuitmux.obj circuitmux_ewma.obj circuituse.obj \ - command.obj config.obj connection.obj connection_edge.obj \ - connection_or.obj control.obj cpuworker.obj directory.obj \ - dirserv.obj dirvote.obj dns.obj dnsserv.obj geoip.obj hibernate.obj \ - main.obj microdesc.obj networkstatus.obj nodelist.obj onion.obj \ - policies.obj reasons.obj relay.obj rendclient.obj rendcommon.obj \ - rendmid.obj rendservice.obj rephist.obj router.obj routerlist.obj \ - routerparse.obj status.obj config_codedigest.obj ntmain.obj +LIBTOR_OBJECTS = \ + addressmap.obj \ + buffers.obj \ + channel.obj \ + channeltls.obj \ + circuitbuild.obj \ + circuitlist.obj \ + circuitmux.obj \ + circuitmux_ewma.obj \ + circuitstats.obj \ + circuituse.obj \ + command.obj \ + config.obj \ + config_codedigest.obj \ + confparse.obj \ + connection.obj \ + connection_edge.obj \ + connection_or.obj \ + control.obj \ + cpuworker.obj \ + directory.obj \ + dirserv.obj \ + dirvote.obj \ + dns.obj \ + dnsserv.obj \ + entrynodes.obj \ + geoip.obj \ + hibernate.obj \ + main.obj \ + microdesc.obj \ + networkstatus.obj \ + nodelist.obj \ + ntmain.obj \ + onion.obj \ + policies.obj \ + reasons.obj \ + relay.obj \ + rendclient.obj \ + rendcommon.obj \ + rendmid.obj \ + rendservice.obj \ + rephist.obj \ + replaycache.obj \ + router.obj \ + routerlist.obj \ + routerparse.obj \ + routerset.obj \ + statefile.obj \ + status.obj \ + transports.obj libtor.lib: $(LIBTOR_OBJECTS) lib $(LIBTOR_OBJECTS) /out:libtor.lib From ce2513abb8a7deeeea3e7b9450485b934d82c666 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 18 Dec 2012 13:24:19 -0500 Subject: [PATCH 04/14] Add clean target and test subdir to makefile.nmake --- Makefile.nmake | 10 ++++++++++ src/common/Makefile.nmake | 3 +++ 2 files changed, 13 insertions(+) diff --git a/Makefile.nmake b/Makefile.nmake index 425f1ec262..a0a11ebdb9 100644 --- a/Makefile.nmake +++ b/Makefile.nmake @@ -3,3 +3,13 @@ all: $(MAKE) /F Makefile.nmake cd ../../src/or $(MAKE) /F Makefile.nmake + cd ../../src/test + $(MAKE) /F Makefile.nmake + +clean: + cd src/common + $(MAKE) /F Makefile.nmake clean + cd ../../src/or + $(MAKE) /F Makefile.nmake clean + cd ../../src/test + $(MAKE) /F Makefile.nmake clean diff --git a/src/common/Makefile.nmake b/src/common/Makefile.nmake index 55923d2ebb..9672f4fe9d 100644 --- a/src/common/Makefile.nmake +++ b/src/common/Makefile.nmake @@ -18,3 +18,6 @@ libor-crypto.lib: $(LIBOR_CRYPTO_OBJECTS) libor-event.lib: $(LIBOR_EVENT_OBJECTS) lib $(LIBOR_EVENT_OBJECTS) /out:libor-event.lib + +clean: + del *.obj *.lib libor*.lib From 0558efbd62e0dc5a954cfdaacdd2f48ef9a4abe0 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 18 Dec 2012 13:33:15 -0500 Subject: [PATCH 05/14] Fix a const warning under msvc --- src/common/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/util.c b/src/common/util.c index 61d09aa4a8..b0055d6c78 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -4919,7 +4919,7 @@ tor_check_port_forwarding(const char *filename, status = tor_spawn_background(filename, argv, NULL, &child_handle); #endif - tor_free(argv); + tor_free((void*)argv); if (PROCESS_STATUS_ERROR == status) { log_warn(LD_GENERAL, "Failed to start port forwarding helper %s", From 7008d4393689115f85d076a17c6a870caa7973b4 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 18 Dec 2012 13:34:17 -0500 Subject: [PATCH 06/14] Add HAVE_EVENT2_DNS_H to MSVC orconfig.h Fix for bug 7313 --- src/win32/orconfig.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/win32/orconfig.h b/src/win32/orconfig.h index cca73b0a30..e7840954fd 100644 --- a/src/win32/orconfig.h +++ b/src/win32/orconfig.h @@ -248,3 +248,4 @@ #define FLEXIBLE_ARRAY_MEMBER 0 #define HAVE_EVENT2_EVENT_H #define SHARE_DATADIR "" +#define HAVE_EVENT2_DNS_H From 9ddcd961490dff3b47d2b863b25cd85e0a4d8fea Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 18 Dec 2012 13:38:01 -0500 Subject: [PATCH 07/14] Add missing targets to src/test/Makefile.nmake. Fix for 7316 --- src/test/Makefile.nmake | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/Makefile.nmake b/src/test/Makefile.nmake index 9580e39f4d..1b0660cb3b 100644 --- a/src/test/Makefile.nmake +++ b/src/test/Makefile.nmake @@ -1,4 +1,4 @@ -all: test.exe +all: test.exe test-child.exe bench.exe CFLAGS = /I ..\win32 /I ..\..\..\build-alpha\include /I ..\common /I ..\or \ /I ..\ext @@ -17,5 +17,11 @@ TEST_OBJECTS = test.obj test_addr.obj test_containers.obj \ test.exe: $(TEST_OBJECTS) $(CC) $(CFLAGS) $(LIBS) ..\common\*.lib $(TEST_OBJECTS) +bench.exe: bench.obj + $(CC) $(CFLAGS) bench.obj $(LIBS) ..\common\*.lib + +test-child.exe: test-child.obj + $(CC) $(CFLAGS) test-child.obj + clean: - del $(TEST_OBJECTS) *.lib test.exe + del *.obj *.lib test.exe bench.exe test-child.exe From ca3bc8973b406cb57bc64bc71bf1adfa27f3c5a9 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 18 Dec 2012 13:41:11 -0500 Subject: [PATCH 08/14] use the /Fe flag with msvc Fixes 7309 --- src/or/Makefile.nmake | 4 ++-- src/test/Makefile.nmake | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/or/Makefile.nmake b/src/or/Makefile.nmake index 568c7455eb..bf67769b52 100644 --- a/src/or/Makefile.nmake +++ b/src/or/Makefile.nmake @@ -61,10 +61,10 @@ LIBTOR_OBJECTS = \ transports.obj libtor.lib: $(LIBTOR_OBJECTS) - lib $(LIBTOR_OBJECTS) /out:libtor.lib + lib $(LIBTOR_OBJECTS) /out:$@ tor.exe: libtor.lib tor_main.obj - $(CC) $(CFLAGS) $(LIBS) libtor.lib ..\common\*.lib tor_main.obj + $(CC) $(CFLAGS) $(LIBS) libtor.lib ..\common\*.lib tor_main.obj /Fe$@ clean: del $(LIBTOR_OBJECTS) *.lib tor.exe diff --git a/src/test/Makefile.nmake b/src/test/Makefile.nmake index 1b0660cb3b..6d6af96af9 100644 --- a/src/test/Makefile.nmake +++ b/src/test/Makefile.nmake @@ -12,16 +12,20 @@ LIBS = ..\..\..\build-alpha\lib\libevent.lib \ TEST_OBJECTS = test.obj test_addr.obj test_containers.obj \ test_crypto.obj test_data.obj test_dir.obj test_microdesc.obj \ - test_pt.obj test_util.obj test_config.obj tinytest.obj + test_pt.obj test_util.obj test_config.obj test_cell_formats.obj \ + test_replay.obj test_introduce.obj tinytest.obj + +tinytest.obj: ..\ext\tinytest.c + $(CC) $(CFLAGS) /D snprintf=_snprintf /c ..\ext\tinytest.c test.exe: $(TEST_OBJECTS) - $(CC) $(CFLAGS) $(LIBS) ..\common\*.lib $(TEST_OBJECTS) + $(CC) $(CFLAGS) $(LIBS) ..\common\*.lib $(TEST_OBJECTS) /Fe$@ bench.exe: bench.obj - $(CC) $(CFLAGS) bench.obj $(LIBS) ..\common\*.lib + $(CC) $(CFLAGS) bench.obj $(LIBS) ..\common\*.lib /Fe$@ test-child.exe: test-child.obj - $(CC) $(CFLAGS) test-child.obj + $(CC) $(CFLAGS) test-child.obj /Fe$@ clean: del *.obj *.lib test.exe bench.exe test-child.exe From aa8f30a4874852f232826de0a60a3e74e16c21e6 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 18 Dec 2012 13:58:11 -0500 Subject: [PATCH 09/14] Try to build tinytest.obj from the right sources --- src/test/Makefile.nmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/Makefile.nmake b/src/test/Makefile.nmake index 6d6af96af9..7ba8f7ee81 100644 --- a/src/test/Makefile.nmake +++ b/src/test/Makefile.nmake @@ -18,6 +18,9 @@ TEST_OBJECTS = test.obj test_addr.obj test_containers.obj \ tinytest.obj: ..\ext\tinytest.c $(CC) $(CFLAGS) /D snprintf=_snprintf /c ..\ext\tinytest.c +tinytest.obj: ..\ext\tinytest.c + $(CC) $(CFLAGS) /c ..\exe\tinytest.c + test.exe: $(TEST_OBJECTS) $(CC) $(CFLAGS) $(LIBS) ..\common\*.lib $(TEST_OBJECTS) /Fe$@ From 3b2abd8a40dff20980cbe35102d3475f5aaba6c3 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 18 Dec 2012 13:59:59 -0500 Subject: [PATCH 10/14] Add more test modules for nmake makefiles --- src/test/Makefile.nmake | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/Makefile.nmake b/src/test/Makefile.nmake index 7ba8f7ee81..6d6af96af9 100644 --- a/src/test/Makefile.nmake +++ b/src/test/Makefile.nmake @@ -18,9 +18,6 @@ TEST_OBJECTS = test.obj test_addr.obj test_containers.obj \ tinytest.obj: ..\ext\tinytest.c $(CC) $(CFLAGS) /D snprintf=_snprintf /c ..\ext\tinytest.c -tinytest.obj: ..\ext\tinytest.c - $(CC) $(CFLAGS) /c ..\exe\tinytest.c - test.exe: $(TEST_OBJECTS) $(CC) $(CFLAGS) $(LIBS) ..\common\*.lib $(TEST_OBJECTS) /Fe$@ From 739e83ca694411c318d868e0838238b4e3d9b5eb Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 18 Dec 2012 14:21:13 -0500 Subject: [PATCH 11/14] Add HAVE_EVENT_BASE_LOOPEXIT to win32/orconfig.h Fix for bug 7308 --- src/win32/orconfig.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/win32/orconfig.h b/src/win32/orconfig.h index e7840954fd..a8b1d43709 100644 --- a/src/win32/orconfig.h +++ b/src/win32/orconfig.h @@ -249,3 +249,4 @@ #define HAVE_EVENT2_EVENT_H #define SHARE_DATADIR "" #define HAVE_EVENT2_DNS_H +#define HAVE_EVENT_BASE_LOOPEXIT From 5e06c4ee327b848f59578bc7d838cf34188ff6fd Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 18 Dec 2012 14:45:12 -0500 Subject: [PATCH 12/14] When building with MSVC, call every enum bitfield unsigned Fixes bug 7305. --- src/common/compat.h | 11 +++++++++++ src/common/crypto.c | 2 +- src/common/tortls.c | 15 +++++++++------ src/common/util.c | 3 ++- src/or/addressmap.c | 2 +- src/or/channel.h | 2 +- src/or/or.h | 28 ++++++++++++++++------------ 7 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/common/compat.h b/src/common/compat.h index 9c544fa309..86ea0c41d4 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -132,6 +132,17 @@ extern INLINE double U64_TO_DBL(uint64_t x) { #define DBL_TO_U64(x) ((uint64_t) (x)) #endif +#if defined(_MSC_VER) +/* XXXX024 we should instead have a more general check for "Is enum signed?"*/ +#define ENUM_BF(t) unsigned +#else +/** Wrapper for having a bitfield of an enumerated type. Where possible, we + * just use the enumerated type (so the compiler can help us and notice + * problems), but if enumerated types are unsigned, we must use unsigned, + * so that the loss of precision doesn't make large values negative. */ +#define ENUM_BF(t) t +#endif + /* GCC has several useful attributes. */ #if defined(__GNUC__) && __GNUC__ >= 3 #define ATTR_NORETURN __attribute__((noreturn)) diff --git a/src/common/crypto.c b/src/common/crypto.c index 39f5a4a642..ed8d457d45 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -1505,7 +1505,7 @@ struct crypto_digest_t { SHA256_CTX sha2; /**< state for SHA256 */ } d; /**< State for the digest we're using. Only one member of the * union is usable, depending on the value of algorithm. */ - digest_algorithm_t algorithm : 8; /**< Which algorithm is in use? */ + ENUM_BF(digest_algorithm_t) algorithm : 8; /**< Which algorithm is in use? */ }; /** Allocate and return a new digest object to compute SHA1 digests. diff --git a/src/common/tortls.c b/src/common/tortls.c index af3059a02d..1e01815095 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -129,6 +129,12 @@ typedef struct tor_tls_context_t { #define TOR_TLS_MAGIC 0x71571571 +typedef enum { + TOR_TLS_ST_HANDSHAKE, TOR_TLS_ST_OPEN, TOR_TLS_ST_GOTCLOSE, + TOR_TLS_ST_SENTCLOSE, TOR_TLS_ST_CLOSED, TOR_TLS_ST_RENEGOTIATE, + TOR_TLS_ST_BUFFEREVENT +} tor_tls_state_t; + /** Holds a SSL object and its associated data. Members are only * accessed from within tortls.c. */ @@ -138,12 +144,9 @@ struct tor_tls_t { SSL *ssl; /**< An OpenSSL SSL object. */ int socket; /**< The underlying file descriptor for this TLS connection. */ char *address; /**< An address to log when describing this connection. */ - enum { - TOR_TLS_ST_HANDSHAKE, TOR_TLS_ST_OPEN, TOR_TLS_ST_GOTCLOSE, - TOR_TLS_ST_SENTCLOSE, TOR_TLS_ST_CLOSED, TOR_TLS_ST_RENEGOTIATE, - TOR_TLS_ST_BUFFEREVENT - } state : 3; /**< The current SSL state, depending on which operations have - * completed successfully. */ + ENUM_BF(tor_tls_state_t) state : 3; /**< The current SSL state, + * depending on which operations + * have completed successfully. */ unsigned int isServer:1; /**< True iff this is a server-side connection */ unsigned int wasV2Handshake:1; /**< True iff the original handshake for * this connection used the updated version diff --git a/src/common/util.c b/src/common/util.c index b0055d6c78..7fcf69e128 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -4919,7 +4919,8 @@ tor_check_port_forwarding(const char *filename, status = tor_spawn_background(filename, argv, NULL, &child_handle); #endif - tor_free((void*)argv); + tor_free_((void*)argv); + argv=NULL; if (PROCESS_STATUS_ERROR == status) { log_warn(LD_GENERAL, "Failed to start port forwarding helper %s", diff --git a/src/or/addressmap.c b/src/or/addressmap.c index f4c31295a8..a7fc60a0a5 100644 --- a/src/or/addressmap.c +++ b/src/or/addressmap.c @@ -45,7 +45,7 @@ typedef struct { char *new_address; time_t expires; - addressmap_entry_source_t source:3; + ENUM_BF(addressmap_entry_source_t) source:3; unsigned src_wildcard:1; unsigned dst_wildcard:1; short num_resolve_failures; diff --git a/src/or/channel.h b/src/or/channel.h index d2106551aa..accc3dcebc 100644 --- a/src/or/channel.h +++ b/src/or/channel.h @@ -142,7 +142,7 @@ struct channel_s { * When we send CREATE cells along this connection, which half of the * space should we use? */ - circ_id_type_t circ_id_type:2; + ENUM_BF(circ_id_type_t) circ_id_type:2; /* * Which circ_id do we try to use next on this connection? This is * always in the range 0..1<<15-1. diff --git a/src/or/or.h b/src/or/or.h index 3a8e50c801..459e18e466 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1583,6 +1583,13 @@ typedef struct entry_connection_t { } entry_connection_t; +typedef enum { + DIR_SPOOL_NONE=0, DIR_SPOOL_SERVER_BY_DIGEST, DIR_SPOOL_SERVER_BY_FP, + DIR_SPOOL_EXTRA_BY_DIGEST, DIR_SPOOL_EXTRA_BY_FP, + DIR_SPOOL_CACHED_DIR, DIR_SPOOL_NETWORKSTATUS, + DIR_SPOOL_MICRODESC, /* NOTE: if we add another entry, add another bit. */ +} dir_spool_source_t; + /** Subtype of connection_t for an "directory connection" -- that is, an HTTP * connection to retrieve or serve directory material. */ typedef struct dir_connection_t { @@ -1601,12 +1608,8 @@ typedef struct dir_connection_t { * "spooling" of directory material to the outbuf. Otherwise, we'd have * to append everything to the outbuf in one enormous chunk. */ /** What exactly are we spooling right now? */ - enum { - DIR_SPOOL_NONE=0, DIR_SPOOL_SERVER_BY_DIGEST, DIR_SPOOL_SERVER_BY_FP, - DIR_SPOOL_EXTRA_BY_DIGEST, DIR_SPOOL_EXTRA_BY_FP, - DIR_SPOOL_CACHED_DIR, DIR_SPOOL_NETWORKSTATUS, - DIR_SPOOL_MICRODESC, /* NOTE: if we add another entry, add another bit. */ - } dir_spool_src : 3; + ENUM_BF(dir_spool_source_t) dir_spool_src : 3; + /** If we're fetching descriptors, what router purpose shall we assign * to them? */ uint8_t router_purpose; @@ -1782,7 +1785,8 @@ typedef enum { /** A reference-counted address policy rule. */ typedef struct addr_policy_t { int refcnt; /**< Reference count */ - addr_policy_action_t policy_type:2;/**< What to do when the policy matches.*/ + /** What to do when the policy matches.*/ + ENUM_BF(addr_policy_action_t) policy_type:2; unsigned int is_private:1; /**< True iff this is the pseudo-address, * "private". */ unsigned int is_canonical:1; /**< True iff this policy is the canonical @@ -1850,7 +1854,7 @@ typedef struct download_status_t { * again? */ uint8_t n_download_failures; /**< Number of failures trying to download the * most recent descriptor. */ - download_schedule_t schedule : 8; + ENUM_BF(download_schedule_t) schedule : 8; } download_status_t; /** If n_download_failures is this high, the download can never happen. */ @@ -2114,7 +2118,7 @@ typedef struct microdesc_t { */ time_t last_listed; /** Where is this microdescriptor currently stored? */ - saved_location_t saved_location : 3; + ENUM_BF(saved_location_t) saved_location : 3; /** If true, do not attempt to cache this microdescriptor on disk. */ unsigned int no_save : 1; /** If true, this microdesc has an entry in the microdesc_map */ @@ -2362,8 +2366,8 @@ typedef enum { /** A common structure to hold a v3 network status vote, or a v3 network * status consensus. */ typedef struct networkstatus_t { - networkstatus_type_t type : 8; /**< Vote, consensus, or opinion? */ - consensus_flavor_t flavor : 8; /**< If a consensus, what kind? */ + ENUM_BF(networkstatus_type_t) type : 8; /**< Vote, consensus, or opinion? */ + ENUM_BF(consensus_flavor_t) flavor : 8; /**< If a consensus, what kind? */ time_t published; /**< Vote only: Time when vote was written. */ time_t valid_after; /**< Time after which this vote or consensus applies. */ time_t fresh_until; /**< Time before which this is the most recent vote or @@ -2846,7 +2850,7 @@ typedef struct origin_circuit_t { /** Kludge to help us prevent the warn in bug #6475 and eventually * debug why we are not seeing first hops in some cases. */ - path_state_t path_state : 2; + ENUM_BF(path_state_t) path_state : 2; /** Set iff this is a hidden-service circuit which has timed out * according to our current circuit-build timeout, but which has From 65b90edbe4f456ee59c163e72bc75e522c4e9288 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 18 Dec 2012 15:09:13 -0500 Subject: [PATCH 13/14] Changes files for 024_msvc branch --- changes/build_with_msvc | 4 ++++ changes/enum_bitfield | 0 2 files changed, 4 insertions(+) create mode 100644 changes/build_with_msvc create mode 100644 changes/enum_bitfield diff --git a/changes/build_with_msvc b/changes/build_with_msvc new file mode 100644 index 0000000000..8da0c92bc2 --- /dev/null +++ b/changes/build_with_msvc @@ -0,0 +1,4 @@ + o Features (portability): + - Build correctly with MSVC and Makefile.nmake. This resolves + numerous bugs and fixes reported by ultramage, including 7305, + 7308, 7309, 7310, 7312, 7313, 7315, 7316, and 7669. diff --git a/changes/enum_bitfield b/changes/enum_bitfield new file mode 100644 index 0000000000..e69de29bb2 From b7cf7bd9ae31aeddd03ad2094dd480d2b1d34d4f Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 19 Dec 2012 16:51:53 -0500 Subject: [PATCH 14/14] Fix an instance of snprintf; don't use _snprintf directly --- changes/7304 | 7 +++++++ src/common/compat.h | 1 - src/or/or.h | 1 - src/or/routerparse.c | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 changes/7304 diff --git a/changes/7304 b/changes/7304 new file mode 100644 index 0000000000..bfb797b107 --- /dev/null +++ b/changes/7304 @@ -0,0 +1,7 @@ + o Minor bugfixes: + - Replace all calls to snprintf outside of src/ext with tor_snprintf. + Fix for bug 7304. + o Code simplification and refactoring: + - Remove the #define to replace snprintf with _snprintf on windows; + they have different semantics, and all of our callers should be + using tor_snprintf anyway. Partial fix for bug 7304. diff --git a/src/common/compat.h b/src/common/compat.h index 86ea0c41d4..630682e638 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -59,7 +59,6 @@ #include #include #include -#define snprintf _snprintf /* this is not exported as W .... */ #define SHGetPathFromIDListW SHGetPathFromIDList /* wcecompat has vasprintf */ diff --git a/src/or/or.h b/src/or/or.h index 459e18e466..6ec7c3a79c 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -81,7 +81,6 @@ #include #include #include -#define snprintf _snprintf #endif #ifdef USE_BUFFEREVENTS diff --git a/src/or/routerparse.c b/src/or/routerparse.c index 1aee4e5332..48744d6994 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -3828,7 +3828,7 @@ get_next_token(memarea_t *area, if ((size_t)(eol-next) != 9+obname_len+5 || strcmp_len(next+9, tok->object_type, obname_len) || strcmp_len(eol-5, "-----", 5)) { - snprintf(ebuf, sizeof(ebuf), "Malformed object: mismatched end tag %s", + tor_snprintf(ebuf, sizeof(ebuf), "Malformed object: mismatched end tag %s", tok->object_type); ebuf[sizeof(ebuf)-1] = '\0'; RET_ERR(ebuf);