Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ext/json/ext/fbuffer/fbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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

Expand All @@ -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");
}
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ext/json/ext/generator/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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"
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.


if enable_config('generator-use-simd', default=!ENV["JSON_DISABLE_SIMD"])
load __dir__ + "/../simd/conf.rb"
Expand Down
2 changes: 1 addition & 1 deletion ext/json/ext/parser/extconf.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions ext/json/ext/vendor/fpconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <string.h>
#include <stdint.h>

#ifdef JSON_DEBUG
#if JSON_DEBUG
#include <assert.h>
#endif

Expand Down Expand Up @@ -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

Expand Down
Loading