summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <[email protected]>2024-09-02 10:17:23 +0200
committerHiroshi SHIBATA <[email protected]>2024-09-03 11:51:51 +0900
commitd612f9fd347a3803ff8ecd3f2bef9cda2dbd3ad7 (patch)
treedd02f0105b92cd3311630c2435815d3abc89e1db
parent81c71efc55740ac5bdeb5817703110fd879f3693 (diff)
[flori/json] Remove outdated ifdef checks
`json` requires Ruby 2.3, so `HAVE_RUBY_ENCODING_H` and `HAVE_RB_ENC_RAISE` are always true. https://github.com/flori/json/commit/5c8dc6b70a
-rw-r--r--ext/json/fbuffer/fbuffer.h4
-rw-r--r--ext/json/generator/generator.c5
-rw-r--r--ext/json/parser/parser.c40
-rw-r--r--ext/json/parser/parser.rl36
4 files changed, 16 insertions, 69 deletions
diff --git a/ext/json/fbuffer/fbuffer.h b/ext/json/fbuffer/fbuffer.h
index dc8f406b5b..7ece0cee95 100644
--- a/ext/json/fbuffer/fbuffer.h
+++ b/ext/json/fbuffer/fbuffer.h
@@ -31,12 +31,8 @@
# define RB_OBJ_STRING(obj) StringValueCStr(obj)
#endif
-#ifdef HAVE_RUBY_ENCODING_H
#include "ruby/encoding.h"
#define FORCE_UTF8(obj) rb_enc_associate((obj), rb_utf8_encoding())
-#else
-#define FORCE_UTF8(obj)
-#endif
/* We don't need to guard objects for rbx, so let's do nothing at all. */
#ifndef RB_GC_GUARD
diff --git a/ext/json/generator/generator.c b/ext/json/generator/generator.c
index e968619205..766e199f74 100644
--- a/ext/json/generator/generator.c
+++ b/ext/json/generator/generator.c
@@ -947,23 +947,20 @@ static void generate_json_array(FBuffer *buffer, VALUE Vstate, JSON_Generator_St
fbuffer_append_char(buffer, ']');
}
-#ifdef HAVE_RUBY_ENCODING_H
static int enc_utf8_compatible_p(rb_encoding *enc)
{
if (enc == rb_usascii_encoding()) return 1;
if (enc == rb_utf8_encoding()) return 1;
return 0;
}
-#endif
static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
{
fbuffer_append_char(buffer, '"');
-#ifdef HAVE_RUBY_ENCODING_H
if (!enc_utf8_compatible_p(rb_enc_get(obj))) {
obj = rb_str_export_to_enc(obj, rb_utf8_encoding());
}
-#endif
+
if (state->ascii_only) {
convert_UTF8_to_JSON_ASCII(buffer, obj, state->script_safe);
} else {
diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c
index 7e44d469f8..128f683e0f 100644
--- a/ext/json/parser/parser.c
+++ b/ext/json/parser/parser.c
@@ -3,28 +3,6 @@
#include "../fbuffer/fbuffer.h"
#include "parser.h"
-#if defined HAVE_RUBY_ENCODING_H
-# define EXC_ENCODING rb_utf8_encoding(),
-# ifndef HAVE_RB_ENC_RAISE
-static void
-enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
-{
- va_list args;
- VALUE mesg;
-
- va_start(args, fmt);
- mesg = rb_enc_vsprintf(enc, fmt, args);
- va_end(args);
-
- rb_exc_raise(rb_exc_new3(exc, mesg));
-}
-# define rb_enc_raise enc_raise
-# endif
-#else
-# define EXC_ENCODING /* nothing */
-# define rb_enc_raise rb_raise
-#endif
-
/* unicode */
static const signed char digit_values[256] = {
@@ -555,7 +533,7 @@ tr3:
{p = (( p + 10))-1;}
p--; {p++; cs = 29; goto _out;}
} else {
- rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
+ rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p);
}
}
np = JSON_parse_float(json, p, pe, result);
@@ -587,7 +565,7 @@ tr25:
if (json->allow_nan) {
*result = CInfinity;
} else {
- rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p - 7);
+ rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p - 7);
}
}
goto st29;
@@ -597,7 +575,7 @@ tr27:
if (json->allow_nan) {
*result = CNaN;
} else {
- rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p - 2);
+ rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p - 2);
}
}
goto st29;
@@ -1436,7 +1414,7 @@ case 16:
if(cs >= JSON_array_first_final) {
return p + 1;
} else {
- rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
+ rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p);
return NULL;
}
}
@@ -1500,7 +1478,7 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int
ruby_xfree(bufferStart);
}
rb_enc_raise(
- EXC_ENCODING eParserError,
+ rb_utf8_encoding(), eParserError,
"incomplete unicode character escape sequence at '%s'", p
);
} else {
@@ -1513,7 +1491,7 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int
ruby_xfree(bufferStart);
}
rb_enc_raise(
- EXC_ENCODING eParserError,
+ rb_utf8_encoding(), eParserError,
"incomplete surrogate pair at '%s'", p
);
}
@@ -1777,7 +1755,6 @@ case 7:
static VALUE convert_encoding(VALUE source)
{
-#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *enc = rb_enc_get(source);
if (enc == rb_ascii8bit_encoding()) {
if (OBJ_FROZEN(source)) {
@@ -1787,8 +1764,7 @@ static VALUE convert_encoding(VALUE source)
} else {
source = rb_str_conv_enc(source, rb_enc_get(source), rb_utf8_encoding());
}
-#endif
- return source;
+ return source;
}
/*
@@ -2089,7 +2065,7 @@ case 9:
if (cs >= JSON_first_final && p == pe) {
return result;
} else {
- rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
+ rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p);
return Qnil;
}
}
diff --git a/ext/json/parser/parser.rl b/ext/json/parser/parser.rl
index e2522918dc..873c1b3007 100644
--- a/ext/json/parser/parser.rl
+++ b/ext/json/parser/parser.rl
@@ -1,28 +1,6 @@
#include "../fbuffer/fbuffer.h"
#include "parser.h"
-#if defined HAVE_RUBY_ENCODING_H
-# define EXC_ENCODING rb_utf8_encoding(),
-# ifndef HAVE_RB_ENC_RAISE
-static void
-enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
-{
- va_list args;
- VALUE mesg;
-
- va_start(args, fmt);
- mesg = rb_enc_vsprintf(enc, fmt, args);
- va_end(args);
-
- rb_exc_raise(rb_exc_new3(exc, mesg));
-}
-# define rb_enc_raise enc_raise
-# endif
-#else
-# define EXC_ENCODING /* nothing */
-# define rb_enc_raise rb_raise
-#endif
-
/* unicode */
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
if (json->allow_nan) {
*result = CNaN;
} else {
- rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p - 2);
+ rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p - 2);
}
}
action parse_infinity {
if (json->allow_nan) {
*result = CInfinity;
} else {
- rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p - 7);
+ rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p - 7);
}
}
action parse_string {
@@ -245,7 +223,7 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu
fexec p + 10;
fhold; fbreak;
} else {
- rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
+ rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p);
}
}
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
if(cs >= JSON_array_first_final) {
return p + 1;
} else {
- rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
+ rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p);
return NULL;
}
}
@@ -511,7 +489,7 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int
ruby_xfree(bufferStart);
}
rb_enc_raise(
- EXC_ENCODING eParserError,
+ rb_utf8_encoding(), eParserError,
"incomplete unicode character escape sequence at '%s'", p
);
} else {
@@ -524,7 +502,7 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int
ruby_xfree(bufferStart);
}
rb_enc_raise(
- EXC_ENCODING eParserError,
+ rb_utf8_encoding(), eParserError,
"incomplete surrogate pair at '%s'", p
);
}
@@ -849,7 +827,7 @@ static VALUE cParser_parse(VALUE self)
if (cs >= JSON_first_final && p == pe) {
return result;
} else {
- rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
+ rb_enc_raise(rb_utf8_encoding(), eParserError, "unexpected token at '%s'", p);
return Qnil;
}
}