diff options
| author | Scott Myron <samyron@gmail.com> | 2025-11-17 21:08:29 -0600 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2025-11-18 08:20:51 +0000 |
| commit | f272aabb5c007d4a8f15e141edbd1bf2d079c5fc (patch) | |
| tree | bc1fc17150e96cf843db797035b53a50c3bb3769 | |
| parent | 54c07383095957c49d91300af6012ff43d41160f (diff) | |
[ruby/json] Use #if instead of #ifdef when checking for JSON_DEBUG so debugging code is not generated when JSON_DEBUG=0.
https://github.com/ruby/json/commit/4f1adb10d3
| -rw-r--r-- | ext/json/fbuffer/fbuffer.h | 12 | ||||
| -rw-r--r-- | ext/json/generator/extconf.rb | 2 | ||||
| -rw-r--r-- | ext/json/parser/extconf.rb | 2 | ||||
| -rw-r--r-- | ext/json/vendor/fpconv.c | 4 |
4 files changed, 10 insertions, 10 deletions
diff --git a/ext/json/fbuffer/fbuffer.h b/ext/json/fbuffer/fbuffer.h index ecba61465e..752d153b31 100644 --- a/ext/json/fbuffer/fbuffer.h +++ b/ext/json/fbuffer/fbuffer.h @@ -14,7 +14,7 @@ typedef struct FBufferStruct { unsigned long initial_length; unsigned long len; unsigned long capa; -#ifdef JSON_DEBUG +#if JSON_DEBUG unsigned long requested; #endif char *ptr; @@ -45,14 +45,14 @@ static void fbuffer_stack_init(FBuffer *fb, unsigned long initial_length, char * fb->ptr = stack_buffer; fb->capa = stack_buffer_size; } -#ifdef JSON_DEBUG +#if JSON_DEBUG fb->requested = 0; #endif } static inline void fbuffer_consumed(FBuffer *fb, unsigned long consumed) { -#ifdef JSON_DEBUG +#if JSON_DEBUG if (consumed > fb->requested) { rb_bug("fbuffer: Out of bound write"); } @@ -122,7 +122,7 @@ static void fbuffer_do_inc_capa(FBuffer *fb, unsigned long requested) static inline void fbuffer_inc_capa(FBuffer *fb, unsigned long requested) { -#ifdef JSON_DEBUG +#if JSON_DEBUG fb->requested = requested; #endif @@ -148,7 +148,7 @@ static inline void fbuffer_append(FBuffer *fb, const char *newstr, unsigned long /* Appends a character into a buffer. The buffer needs to have sufficient capacity, via fbuffer_inc_capa(...). */ static inline void fbuffer_append_reserved_char(FBuffer *fb, char chr) { -#ifdef JSON_DEBUG +#if JSON_DEBUG if (fb->requested < 1) { rb_bug("fbuffer: unreserved write"); } @@ -174,7 +174,7 @@ static void fbuffer_append_str_repeat(FBuffer *fb, VALUE str, size_t repeat) fbuffer_inc_capa(fb, repeat * len); while (repeat) { -#ifdef JSON_DEBUG +#if JSON_DEBUG fb->requested = len; #endif fbuffer_append_reserved(fb, newstr, len); diff --git a/ext/json/generator/extconf.rb b/ext/json/generator/extconf.rb index fb9afd07f7..ee1bbeaba7 100644 --- a/ext/json/generator/extconf.rb +++ b/ext/json/generator/extconf.rb @@ -6,7 +6,7 @@ if RUBY_ENGINE == 'truffleruby' else append_cflags("-std=c99") $defs << "-DJSON_GENERATOR" - $defs << "-DJSON_DEBUG" if ENV["JSON_DEBUG"] + $defs << "-DJSON_DEBUG" if ENV.fetch("JSON_DEBUG", "0") != "0" if enable_config('generator-use-simd', default=!ENV["JSON_DISABLE_SIMD"]) load __dir__ + "/../simd/conf.rb" diff --git a/ext/json/parser/extconf.rb b/ext/json/parser/extconf.rb index 079b37382d..2440e66d8b 100644 --- a/ext/json/parser/extconf.rb +++ b/ext/json/parser/extconf.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'mkmf' -$defs << "-DJSON_DEBUG" if ENV["JSON_DEBUG"] +$defs << "-DJSON_DEBUG" if ENV.fetch("JSON_DEBUG", "0") != "0" have_func("rb_enc_interned_str", "ruby/encoding.h") # RUBY_VERSION >= 3.0 have_func("rb_str_to_interned_str", "ruby.h") # RUBY_VERSION >= 3.0 have_func("rb_hash_new_capa", "ruby.h") # RUBY_VERSION >= 3.2 diff --git a/ext/json/vendor/fpconv.c b/ext/json/vendor/fpconv.c index e91c7889c2..4888ab4b8b 100644 --- a/ext/json/vendor/fpconv.c +++ b/ext/json/vendor/fpconv.c @@ -29,7 +29,7 @@ #include <string.h> #include <stdint.h> -#ifdef JSON_DEBUG +#if JSON_DEBUG #include <assert.h> #endif @@ -472,7 +472,7 @@ static int fpconv_dtoa(double d, char dest[28]) int ndigits = grisu2(d, digits, &K); str_len += emit_digits(digits, ndigits, dest + str_len, K, neg); -#ifdef JSON_DEBUG +#if JSON_DEBUG assert(str_len <= 32); #endif |
