Skip to content

Commit 5c8dc6b

Browse files
committed
Remove outdated ifdef checks
`json` requires Ruby 2.3, so `HAVE_RUBY_ENCODING_H` and `HAVE_RB_ENC_RAISE` are always true.
1 parent 80b5865 commit 5c8dc6b

File tree

4 files changed

+16
-69
lines changed

4 files changed

+16
-69
lines changed

ext/json/ext/fbuffer/fbuffer.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,8 @@
3131
# define RB_OBJ_STRING(obj) StringValueCStr(obj)
3232
#endif
3333

34-
#ifdef HAVE_RUBY_ENCODING_H
3534
#include "ruby/encoding.h"
3635
#define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding())
37-
#else
38-
#define FORCE_UTF8(obj)
39-
#endif
4036

4137
/* We don't need to guard objects for rbx, so let's do nothing at all. */
4238
#ifndef RB_GC_GUARD

ext/json/ext/generator/generator.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -947,23 +947,20 @@ static void generate_json_array(FBuffer *buffer, VALUE Vstate, JSON_Generator_St
947947
fbuffer_append_char(buffer, ']');
948948
}
949949

950-
#ifdef HAVE_RUBY_ENCODING_H
951950
static int enc_utf8_compatible_p(rb_encoding *enc)
952951
{
953952
if (enc == rb_usascii_encoding()) return 1;
954953
if (enc == rb_utf8_encoding()) return 1;
955954
return 0;
956955
}
957-
#endif
958956

959957
static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
960958
{
961959
fbuffer_append_char(buffer, '"');
962-
#ifdef HAVE_RUBY_ENCODING_H
963960
if (!enc_utf8_compatible_p(rb_enc_get(obj))) {
964961
obj = rb_str_export_to_enc(obj, rb_utf8_encoding());
965962
}
966-
#endif
963+
967964
if (state->ascii_only) {
968965
convert_UTF8_to_JSON_ASCII(buffer, obj, state->script_safe);
969966
} else {

ext/json/ext/parser/parser.c

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,6 @@
33
#include "../fbuffer/fbuffer.h"
44
#include "parser.h"
55

6-
#if defined HAVE_RUBY_ENCODING_H
7-
# define EXC_ENCODING rb_utf8_encoding(),
8-
# ifndef HAVE_RB_ENC_RAISE
9-
static void
10-
enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
11-
{
12-
va_list args;
13-
VALUE mesg;
14-
15-
va_start(args, fmt);
16-
mesg = rb_enc_vsprintf(enc, fmt, args);
17-
va_end(args);
18-
19-
rb_exc_raise(rb_exc_new3(exc, mesg));
20-
}
21-
# define rb_enc_raise enc_raise
22-
# endif
23-
#else
24-
# define EXC_ENCODING /* nothing */
25-
# define rb_enc_raise rb_raise
26-
#endif
27-
286
/* unicode */
297

308
static const signed char digit_values[256] = {
@@ -555,7 +533,7 @@ cs = 0;
555533
{p = (( p + 10))-1;}
556534
p--; {p++; cs = 29; goto _out;}
557535
} else {
558-
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
536+
rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p);
559537
}
560538
}
561539
np = JSON_parse_float(json, p, pe, result);
@@ -587,7 +565,7 @@ cs = 0;
587565
if (json->allow_nan) {
588566
*result = CInfinity;
589567
} else {
590-
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p - 7);
568+
rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p - 7);
591569
}
592570
}
593571
goto st29;
@@ -597,7 +575,7 @@ cs = 0;
597575
if (json->allow_nan) {
598576
*result = CNaN;
599577
} else {
600-
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p - 2);
578+
rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p - 2);
601579
}
602580
}
603581
goto st29;
@@ -1436,7 +1414,7 @@ case 16:
14361414
if(cs >= JSON_array_first_final) {
14371415
return p + 1;
14381416
} else {
1439-
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
1417+
rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p);
14401418
return NULL;
14411419
}
14421420
}
@@ -1500,7 +1478,7 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int
15001478
ruby_xfree(bufferStart);
15011479
}
15021480
rb_enc_raise(
1503-
EXC_ENCODING eParserError,
1481+
rb_utf8_encoding(), eParserError,
15041482
"incomplete unicode character escape sequence at '%s'", p
15051483
);
15061484
} else {
@@ -1513,7 +1491,7 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int
15131491
ruby_xfree(bufferStart);
15141492
}
15151493
rb_enc_raise(
1516-
EXC_ENCODING eParserError,
1494+
rb_utf8_encoding(), eParserError,
15171495
"incomplete surrogate pair at '%s'", p
15181496
);
15191497
}
@@ -1777,7 +1755,6 @@ case 7:
17771755

17781756
static VALUE convert_encoding(VALUE source)
17791757
{
1780-
#ifdef HAVE_RUBY_ENCODING_H
17811758
rb_encoding *enc = rb_enc_get(source);
17821759
if (enc == rb_ascii8bit_encoding()) {
17831760
if (OBJ_FROZEN(source)) {
@@ -1787,8 +1764,7 @@ static VALUE convert_encoding(VALUE source)
17871764
} else {
17881765
source = rb_str_conv_enc(source, rb_enc_get(source), rb_utf8_encoding());
17891766
}
1790-
#endif
1791-
return source;
1767+
return source;
17921768
}
17931769

17941770
/*
@@ -2089,7 +2065,7 @@ case 9:
20892065
if (cs >= JSON_first_final && p == pe) {
20902066
return result;
20912067
} else {
2092-
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
2068+
rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p);
20932069
return Qnil;
20942070
}
20952071
}

ext/json/ext/parser/parser.rl

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
11
#include "../fbuffer/fbuffer.h"
22
#include "parser.h"
33

4-
#if defined HAVE_RUBY_ENCODING_H
5-
# define EXC_ENCODING rb_utf8_encoding(),
6-
# ifndef HAVE_RB_ENC_RAISE
7-
static void
8-
enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
9-
{
10-
va_list args;
11-
VALUE mesg;
12-
13-
va_start(args, fmt);
14-
mesg = rb_enc_vsprintf(enc, fmt, args);
15-
va_end(args);
16-
17-
rb_exc_raise(rb_exc_new3(exc, mesg));
18-
}
19-
# define rb_enc_raise enc_raise
20-
# endif
21-
#else
22-
# define EXC_ENCODING /* nothing */
23-
# define rb_enc_raise rb_raise
24-
#endif
25-
264
/* unicode */
275

286
static const signed char digit_values[256] = {
@@ -222,14 +200,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
222200
if (json->allow_nan) {
223201
*result = CNaN;
224202
} else {
225-
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p - 2);
203+
rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p - 2);
226204
}
227205
}
228206
action parse_infinity {
229207
if (json->allow_nan) {
230208
*result = CInfinity;
231209
} else {
232-
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p - 7);
210+
rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p - 7);
233211
}
234212
}
235213
action parse_string {
@@ -245,7 +223,7 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
245223
fexec p + 10;
246224
fhold; fbreak;
247225
} else {
248-
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
226+
rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p);
249227
}
250228
}
251229
np = JSON_parse_float(json, fpc, pe, result);
@@ -447,7 +425,7 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul
447425
if(cs >= JSON_array_first_final) {
448426
return p + 1;
449427
} else {
450-
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
428+
rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p);
451429
return NULL;
452430
}
453431
}
@@ -511,7 +489,7 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int
511489
ruby_xfree(bufferStart);
512490
}
513491
rb_enc_raise(
514-
EXC_ENCODING eParserError,
492+
rb_utf8_encoding(), eParserError,
515493
"incomplete unicode character escape sequence at '%s'", p
516494
);
517495
} else {
@@ -524,7 +502,7 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int
524502
ruby_xfree(bufferStart);
525503
}
526504
rb_enc_raise(
527-
EXC_ENCODING eParserError,
505+
rb_utf8_encoding(), eParserError,
528506
"incomplete surrogate pair at '%s'", p
529507
);
530508
}
@@ -849,7 +827,7 @@ static VALUE cParser_parse(VALUE self)
849827
if (cs >= JSON_first_final && p == pe) {
850828
return result;
851829
} else {
852-
rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
830+
rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p);
853831
return Qnil;
854832
}
855833
}

0 commit comments

Comments
 (0)