Skip to content

Conversation

@samyron
Copy link
Contributor

@samyron samyron commented Nov 18, 2025

While profiling the C extension, I kept hitting code within the #ifdef JSON_DEBUG. Using #ifdef checks if the identifier is defined, not the value.

I did not have the JSON_DEBUG environment variable set but noticed the following in json.h:

#ifdef RUBY_DEBUG
#ifndef JSON_DEBUG
#define JSON_DEBUG RUBY_DEBUG
#endif
#endif

Adding #error "RUBY_DEBUG defined but not JSON_DEBUG" after the #ifndef and running rake outputs the following:

In file included from ../../../../../../ext/json/ext/generator/generator.c:1:
../../../../../../ext/json/ext/generator/../json.h:82:2: error: "RUBY_DEBUG defined but not JSON_DEBUG"
   82 | #error "RUBY_DEBUG defined but not JSON_DEBUG"
      |  ^
1 error generated.

I should note that I am not running debug build of Ruby. Adding a printf("RUBY_DEBUG=%lu\n", RUBY_DEBUG); outputs a lot of RUBY_DEBUG=0.

My assumption is we want this code to be excluded if JSON_DEBUG is 0.

append_cflags("-std=c99")
$defs << "-DJSON_GENERATOR"
$defs << "-DJSON_DEBUG" if ENV["JSON_DEBUG"]
$defs << "-DJSON_DEBUG" if ENV.fetch("JSON_DEBUG", "0") != "0"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is optional but it allows JSON_DEBUG=0 to not trigger debugging code. Feel free to remove if this isn't needed.

@byroot byroot merged commit 4f1adb1 into ruby:master Nov 18, 2025
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants