Skip to content

Commit 227885f

Browse files
committed
Get rid of some more outdated compatibility code
All these macros are available on Ruby 2.3+
1 parent d77c4e3 commit 227885f

File tree

4 files changed

+111
-129
lines changed

4 files changed

+111
-129
lines changed

ext/json/ext/fbuffer/fbuffer.h

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,8 @@
1-
21
#ifndef _FBUFFER_H_
32
#define _FBUFFER_H_
43

54
#include "ruby.h"
6-
7-
#ifndef RHASH_SIZE
8-
#define RHASH_SIZE(hsh) (RHASH(hsh)->tbl->num_entries)
9-
#endif
10-
11-
#ifndef RFLOAT_VALUE
12-
#define RFLOAT_VALUE(val) (RFLOAT(val)->value)
13-
#endif
14-
15-
#ifndef RARRAY_LEN
16-
#define RARRAY_LEN(ARRAY) RARRAY(ARRAY)->len
17-
#endif
18-
#ifndef RSTRING_PTR
19-
#define RSTRING_PTR(string) RSTRING(string)->ptr
20-
#endif
21-
#ifndef RSTRING_LEN
22-
#define RSTRING_LEN(string) RSTRING(string)->len
23-
#endif
24-
25-
#ifdef PRIsVALUE
26-
# define RB_OBJ_CLASSNAME(obj) rb_obj_class(obj)
27-
# define RB_OBJ_STRING(obj) (obj)
28-
#else
29-
# define PRIsVALUE "s"
30-
# define RB_OBJ_CLASSNAME(obj) rb_obj_classname(obj)
31-
# define RB_OBJ_STRING(obj) StringValueCStr(obj)
32-
#endif
33-
345
#include "ruby/encoding.h"
35-
#define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding())
36-
37-
/* We don't need to guard objects for rbx, so let's do nothing at all. */
38-
#ifndef RB_GC_GUARD
39-
#define RB_GC_GUARD(object)
40-
#endif
416

427
typedef struct FBufferStruct {
438
unsigned long initial_length;
@@ -173,9 +138,8 @@ static void fbuffer_append_long(FBuffer *fb, long number)
173138

174139
static VALUE fbuffer_to_s(FBuffer *fb)
175140
{
176-
VALUE result = rb_str_new(FBUFFER_PTR(fb), FBUFFER_LEN(fb));
141+
VALUE result = rb_utf8_str_new(FBUFFER_PTR(fb), FBUFFER_LEN(fb));
177142
fbuffer_free(fb);
178-
FORCE_UTF8(result);
179143
return result;
180144
}
181145
#endif

ext/json/ext/generator/generator.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,9 @@ static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_St
620620
VALUE tmp = rb_funcall(obj, i_to_s, 0);
621621
if (!allow_nan) {
622622
if (isinf(value)) {
623-
rb_raise(eGeneratorError, "%"PRIsVALUE" not allowed in JSON", RB_OBJ_STRING(tmp));
623+
rb_raise(eGeneratorError, "%"PRIsVALUE" not allowed in JSON", tmp);
624624
} else if (isnan(value)) {
625-
rb_raise(eGeneratorError, "%"PRIsVALUE" not allowed in JSON", RB_OBJ_STRING(tmp));
625+
rb_raise(eGeneratorError, "%"PRIsVALUE" not allowed in JSON", tmp);
626626
}
627627
}
628628
fbuffer_append_str(buffer, tmp);
@@ -670,7 +670,7 @@ static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *s
670670
default:
671671
general:
672672
if (state->strict) {
673-
rb_raise(eGeneratorError, "%"PRIsVALUE" not allowed in JSON", RB_OBJ_STRING(CLASS_OF(obj)));
673+
rb_raise(eGeneratorError, "%"PRIsVALUE" not allowed in JSON", CLASS_OF(obj));
674674
} else if (rb_respond_to(obj, i_to_json)) {
675675
tmp = rb_funcall(obj, i_to_json, 1, Vstate);
676676
Check_Type(tmp, T_STRING);

0 commit comments

Comments
 (0)