Skip to content

Commit 420ddc3

Browse files
committed
Replaced preprocessor constant "NDEBUG" by the more standard "DEBUG" one and flipped behavior accordingly
1 parent 143e38c commit 420ddc3

File tree

7 files changed

+22
-22
lines changed

7 files changed

+22
-22
lines changed

GCDWebServer.podspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Pod::Spec.new do |s|
2828
cs.ios.frameworks = 'MobileCoreServices', 'CFNetwork'
2929
cs.osx.library = 'z'
3030
cs.osx.framework = 'SystemConfiguration'
31-
cs.compiler_flags = '-DNDEBUG' # TODO: Only set this for Release configuration
3231
end
3332

3433
s.subspec 'WebDAV' do |cs|

GCDWebServer.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@
512512
buildSettings = {
513513
CLANG_ENABLE_OBJC_ARC = YES;
514514
GCC_OPTIMIZATION_LEVEL = 0;
515+
GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
515516
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = __GCDWEBSERVER_ENABLE_TESTING__;
516517
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";
517518
ONLY_ACTIVE_ARCH = YES;
@@ -539,7 +540,6 @@
539540
isa = XCBuildConfiguration;
540541
buildSettings = {
541542
CLANG_ENABLE_OBJC_ARC = YES;
542-
GCC_PREPROCESSOR_DEFINITIONS = NDEBUG;
543543
GCC_PREPROCESSOR_DEFINITIONS_NOT_USED_IN_PRECOMPS = __GCDWEBSERVER_ENABLE_TESTING__;
544544
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
545545
HEADER_SEARCH_PATHS = "$(SDKROOT)/usr/include/libxml2";

GCDWebServer/Core/GCDWebServer.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
/**
3434
* Log levels used by GCDWebServer.
3535
*
36-
* @warning kGCDWebServerLogLevel_Debug is only available if "NDEBUG" is not
37-
* defined when building.
36+
* @warning kGCDWebServerLogLevel_Debug is only functional if the preprocessor
37+
* constant "DEBUG" is is non-zero at build time.
3838
*/
3939
typedef NS_ENUM(int, GCDWebServerLogLevel) {
4040
kGCDWebServerLogLevel_Debug = 0,
@@ -489,8 +489,9 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
489489
/**
490490
* Sets the current log level below which logged messages are discarded.
491491
*
492-
* The default level is either DEBUG or INFO if "NDEBUG" is defined at build-time.
493-
* It can also be set at runtime with the "logLevel" environment variable.
492+
* The default level is INFO (or DEBUG if the preprocessor constant "DEBUG"
493+
* is non-zero at build time).
494+
* It can also be set at run time with the "logLevel" environment variable.
494495
*/
495496
+ (void)setLogLevel:(GCDWebServerLogLevel)level;
496497

GCDWebServer/Core/GCDWebServer.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@
6262
NSString* const GCDWebServerAuthenticationMethod_DigestAccess = @"DigestAccess";
6363

6464
#ifndef __GCDWEBSERVER_LOGGING_HEADER__
65-
#ifdef NDEBUG
66-
GCDWebServerLogLevel GCDLogLevel = kGCDWebServerLogLevel_Info;
67-
#else
65+
#if DEBUG
6866
GCDWebServerLogLevel GCDLogLevel = kGCDWebServerLogLevel_Debug;
67+
#else
68+
GCDWebServerLogLevel GCDLogLevel = kGCDWebServerLogLevel_Info;
6969
#endif
7070
#endif
7171

@@ -1138,7 +1138,7 @@ - (NSInteger)runTestsWithOptions:(NSDictionary*)options inDirectory:(NSString*)p
11381138
_LogResult(@" Bodies not matching:\n Expected: %lu bytes\n Actual: %lu bytes", (unsigned long)expectedBody.length, (unsigned long)actualBody.length);
11391139
success = NO;
11401140
#if !TARGET_OS_IPHONE
1141-
#ifndef NDEBUG
1141+
#if DEBUG
11421142
if (GCDWebServerIsTextContentType([expectedHeaders objectForKey:@"Content-Type"])) {
11431143
NSString* expectedPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:@"txt"]];
11441144
NSString* actualPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[[[NSProcessInfo processInfo] globallyUniqueString] stringByAppendingPathExtension:@"txt"]];

GCDWebServer/Core/GCDWebServerPrivate.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,7 @@ extern void GCDLogMessage(GCDWebServerLogLevel level, NSString* format, ...) NS_
8484
#define LOG_ERROR(...) do { if (GCDLogLevel <= kGCDWebServerLogLevel_Error) GCDLogMessage(kGCDWebServerLogLevel_Error, __VA_ARGS__); } while (0)
8585
#define LOG_EXCEPTION(__EXCEPTION__) do { if (GCDLogLevel <= kGCDWebServerLogLevel_Exception) GCDLogMessage(kGCDWebServerLogLevel_Exception, @"%@", __EXCEPTION__); } while (0)
8686

87-
#ifdef NDEBUG
88-
89-
#define DCHECK(__CONDITION__)
90-
#define DNOT_REACHED()
91-
#define LOG_DEBUG(...)
92-
93-
#else
87+
#if DEBUG
9488

9589
#define DCHECK(__CONDITION__) \
9690
do { \
@@ -101,6 +95,12 @@ extern void GCDLogMessage(GCDWebServerLogLevel level, NSString* format, ...) NS_
10195
#define DNOT_REACHED() abort()
10296
#define LOG_DEBUG(...) do { if (GCDLogLevel <= kGCDWebServerLogLevel_Debug) GCDLogMessage(kGCDWebServerLogLevel_Debug, __VA_ARGS__); } while (0)
10397

98+
#else
99+
100+
#define DCHECK(__CONDITION__)
101+
#define DNOT_REACHED()
102+
#define LOG_DEBUG(...)
103+
104104
#endif
105105

106106
#endif

Mac/main.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ int main(int argc, const char* argv[]) {
359359
if (webServer) {
360360
Delegate* delegate = [[Delegate alloc] init];
361361
if (testDirectory) {
362-
#ifndef NDEBUG
362+
#if DEBUG
363363
webServer.delegate = delegate;
364364
#endif
365365
fprintf(stdout, "<RUNNING TESTS FROM \"%s\">\n\n", [testDirectory UTF8String]);

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,20 +303,20 @@ HTTP connections are often initiated in batches (or bursts), for instance when l
303303
Debug Builds & Custom Logging
304304
=============================
305305
306-
When building GCDWebServer in "Debug" mode versus "Release" mode, GCDWebServer logs a lot more information and also performs a number of internal consistency checks. To disable this behavior, make sure to define the preprocessor constant ```NDEBUG``` when compiling GCDWebServer. In Xcode target settings, this can be done by adding ```NDEBUG``` to the build setting ```GCC_PREPROCESSOR_DEFINITIONS``` when building in Release configuration (this is done automatically for you if you use CocoaPods).
306+
When building GCDWebServer in "Debug" mode versus "Release" mode, GCDWebServer logs a lot more information and also performs a number of internal consistency checks. To enable this behavior, define the preprocessor constant ```DEBUG=1``` when compiling GCDWebServer. In Xcode target settings, this can be done by adding ```DEBUG=1``` to the build setting ```GCC_PREPROCESSOR_DEFINITIONS``` when building in Debug configuration.
307307
308308
It's also possible to replace the logging system used by GCDWebServer by a custom one. Simply define the preprocessor constant ```__GCDWEBSERVER_LOGGING_HEADER__``` to the name of a header file (e.g. "MyLogging.h") that defines these macros:
309309
310310
```
311-
#define LOG_DEBUG(...) // Should not do anything if NDEBUG is defined
311+
#define LOG_DEBUG(...) // Should not do anything unless the preprocessor constant DEBUG is non-zero
312312
#define LOG_VERBOSE(...)
313313
#define LOG_INFO(...)
314314
#define LOG_WARNING(...)
315315
#define LOG_ERROR(...)
316316
#define LOG_EXCEPTION(__EXCEPTION__)
317317

318-
#define DCHECK(__CONDITION__) // Should not do anything if NDEBUG is defined or abort if __CONDITION__ is false
319-
#define DNOT_REACHED() // Should not do anything if NDEBUG is defined
318+
#define DCHECK(__CONDITION__) // Should not do anything unless the preprocessor constant DEBUG is non-zero
319+
#define DNOT_REACHED() // Should not do anything unless the preprocessor constant DEBUG is non-zero
320320
```
321321
322322
Advanced Example 1: Implementing HTTP Redirects

0 commit comments

Comments
 (0)