Skip to content

Commit 4f1adb1

Browse files
samyronbyroot
authored andcommitted
Use #if instead of #ifdef when checking for JSON_DEBUG so debugging code is not generated when JSON_DEBUG=0.
1 parent a3ee527 commit 4f1adb1

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

ext/json/ext/fbuffer/fbuffer.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ typedef struct FBufferStruct {
1414
unsigned long initial_length;
1515
unsigned long len;
1616
unsigned long capa;
17-
#ifdef JSON_DEBUG
17+
#if JSON_DEBUG
1818
unsigned long requested;
1919
#endif
2020
char *ptr;
@@ -45,14 +45,14 @@ static void fbuffer_stack_init(FBuffer *fb, unsigned long initial_length, char *
4545
fb->ptr = stack_buffer;
4646
fb->capa = stack_buffer_size;
4747
}
48-
#ifdef JSON_DEBUG
48+
#if JSON_DEBUG
4949
fb->requested = 0;
5050
#endif
5151
}
5252

5353
static inline void fbuffer_consumed(FBuffer *fb, unsigned long consumed)
5454
{
55-
#ifdef JSON_DEBUG
55+
#if JSON_DEBUG
5656
if (consumed > fb->requested) {
5757
rb_bug("fbuffer: Out of bound write");
5858
}
@@ -122,7 +122,7 @@ static void fbuffer_do_inc_capa(FBuffer *fb, unsigned long requested)
122122

123123
static inline void fbuffer_inc_capa(FBuffer *fb, unsigned long requested)
124124
{
125-
#ifdef JSON_DEBUG
125+
#if JSON_DEBUG
126126
fb->requested = requested;
127127
#endif
128128

@@ -148,7 +148,7 @@ static inline void fbuffer_append(FBuffer *fb, const char *newstr, unsigned long
148148
/* Appends a character into a buffer. The buffer needs to have sufficient capacity, via fbuffer_inc_capa(...). */
149149
static inline void fbuffer_append_reserved_char(FBuffer *fb, char chr)
150150
{
151-
#ifdef JSON_DEBUG
151+
#if JSON_DEBUG
152152
if (fb->requested < 1) {
153153
rb_bug("fbuffer: unreserved write");
154154
}
@@ -174,7 +174,7 @@ static void fbuffer_append_str_repeat(FBuffer *fb, VALUE str, size_t repeat)
174174

175175
fbuffer_inc_capa(fb, repeat * len);
176176
while (repeat) {
177-
#ifdef JSON_DEBUG
177+
#if JSON_DEBUG
178178
fb->requested = len;
179179
#endif
180180
fbuffer_append_reserved(fb, newstr, len);

ext/json/ext/generator/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
else
77
append_cflags("-std=c99")
88
$defs << "-DJSON_GENERATOR"
9-
$defs << "-DJSON_DEBUG" if ENV["JSON_DEBUG"]
9+
$defs << "-DJSON_DEBUG" if ENV.fetch("JSON_DEBUG", "0") != "0"
1010

1111
if enable_config('generator-use-simd', default=!ENV["JSON_DISABLE_SIMD"])
1212
load __dir__ + "/../simd/conf.rb"

ext/json/ext/parser/extconf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22
require 'mkmf'
33

4-
$defs << "-DJSON_DEBUG" if ENV["JSON_DEBUG"]
4+
$defs << "-DJSON_DEBUG" if ENV.fetch("JSON_DEBUG", "0") != "0"
55
have_func("rb_enc_interned_str", "ruby/encoding.h") # RUBY_VERSION >= 3.0
66
have_func("rb_str_to_interned_str", "ruby.h") # RUBY_VERSION >= 3.0
77
have_func("rb_hash_new_capa", "ruby.h") # RUBY_VERSION >= 3.2

ext/json/ext/vendor/fpconv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <string.h>
3030
#include <stdint.h>
3131

32-
#ifdef JSON_DEBUG
32+
#if JSON_DEBUG
3333
#include <assert.h>
3434
#endif
3535

@@ -472,7 +472,7 @@ static int fpconv_dtoa(double d, char dest[28])
472472
int ndigits = grisu2(d, digits, &K);
473473

474474
str_len += emit_digits(digits, ndigits, dest + str_len, K, neg);
475-
#ifdef JSON_DEBUG
475+
#if JSON_DEBUG
476476
assert(str_len <= 32);
477477
#endif
478478

0 commit comments

Comments
 (0)