From ea409958b38424f296aacc5c2d8d7bf3bcd1d2db Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Thu, 30 Nov 2023 11:40:13 -0500 Subject: [ruby/prism] Remove ability to decode other encodings https://github.com/ruby/prism/commit/98e218d989 --- prism/parser.h | 16 ---------------- prism/prism.c | 27 +-------------------------- prism/prism.h | 12 ------------ 3 files changed, 1 insertion(+), 54 deletions(-) diff --git a/prism/parser.h b/prism/parser.h index 424d150ebe..bfad39a1d9 100644 --- a/prism/parser.h +++ b/prism/parser.h @@ -421,14 +421,6 @@ typedef struct { */ typedef void (*pm_encoding_changed_callback_t)(pm_parser_t *parser); -/** - * When an encoding is encountered that isn't understood by prism, we provide - * the ability here to call out to a user-defined function to get an encoding - * struct. If the function returns something that isn't NULL, we set that to - * our encoding and use it to parse identifiers. - */ -typedef pm_encoding_t *(*pm_encoding_decode_callback_t)(pm_parser_t *parser, const uint8_t *name, size_t width); - /** * When you are lexing through a file, the lexer needs all of the information * that the parser additionally provides (for example, the local table). So if @@ -608,14 +600,6 @@ struct pm_parser { */ pm_encoding_changed_callback_t encoding_changed_callback; - /** - * When an encoding is encountered that isn't understood by prism, we - * provide the ability here to call out to a user-defined function to get an - * encoding struct. If the function returns something that isn't NULL, we - * set that to our encoding and use it to parse identifiers. - */ - pm_encoding_decode_callback_t encoding_decode_callback; - /** * This pointer indicates where a comment must start if it is to be * considered an encoding comment. diff --git a/prism/prism.c b/prism/prism.c index baab318b9a..effe3661c4 100644 --- a/prism/prism.c +++ b/prism/prism.c @@ -6155,19 +6155,7 @@ static bool parser_lex_magic_comment_encoding_value(pm_parser_t *parser, const uint8_t *start, const uint8_t *end) { size_t width = (size_t) (end - start); - // First, we're going to call out to a user-defined callback if one was - // provided. If they return an encoding struct that we can use, then we'll - // use that here. - if (parser->encoding_decode_callback != NULL) { - pm_encoding_t *encoding = parser->encoding_decode_callback(parser, start, width); - - if (encoding != NULL) { - parser->encoding = *encoding; - return true; - } - } - - // Next, we're going to check for UTF-8. This is the most common encoding. + // First, we're going to check for UTF-8. This is the most common encoding. // utf-8 can contain extra information at the end about the platform it is // encoded on, such as utf-8-mac or utf-8-unix. We'll ignore those suffixes. if ((start + 5 <= end) && (pm_strncasecmp(start, (const uint8_t *) "utf-8", 5) == 0)) { @@ -17039,7 +17027,6 @@ pm_parser_init(pm_parser_t *parser, const uint8_t *source, size_t size, const pm .current_context = NULL, .encoding = pm_encoding_utf_8, .encoding_changed_callback = NULL, - .encoding_decode_callback = NULL, .encoding_comment_start = source, .lex_callback = NULL, .filepath_string = { 0 }, @@ -17154,18 +17141,6 @@ pm_parser_register_encoding_changed_callback(pm_parser_t *parser, pm_encoding_ch parser->encoding_changed_callback = callback; } -/** - * Register a callback that will be called when prism encounters a magic comment - * with an encoding referenced that it doesn't understand. The callback should - * return NULL if it also doesn't understand the encoding or it should return a - * pointer to a pm_encoding_t struct that contains the functions necessary to - * parse identifiers. - */ -PRISM_EXPORTED_FUNCTION void -pm_parser_register_encoding_decode_callback(pm_parser_t *parser, pm_encoding_decode_callback_t callback) { - parser->encoding_decode_callback = callback; -} - /** * Free all of the memory associated with the comment list. */ diff --git a/prism/prism.h b/prism/prism.h index 5eec5f49ec..ab5811f9ac 100644 --- a/prism/prism.h +++ b/prism/prism.h @@ -61,18 +61,6 @@ PRISM_EXPORTED_FUNCTION void pm_parser_init(pm_parser_t *parser, const uint8_t * */ PRISM_EXPORTED_FUNCTION void pm_parser_register_encoding_changed_callback(pm_parser_t *parser, pm_encoding_changed_callback_t callback); -/** - * Register a callback that will be called when prism encounters a magic comment - * with an encoding referenced that it doesn't understand. The callback should - * return NULL if it also doesn't understand the encoding or it should return a - * pointer to a pm_encoding_t struct that contains the functions necessary to - * parse identifiers. - * - * @param parser The parser to register the callback with. - * @param callback The callback to register. - */ -PRISM_EXPORTED_FUNCTION void pm_parser_register_encoding_decode_callback(pm_parser_t *parser, pm_encoding_decode_callback_t callback); - /** * Free any memory associated with the given parser. * -- cgit v1.2.3