From cb3dca041b3707f881e685457692d5aca6a1df25 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sat, 7 Jun 2025 10:58:40 -0400 Subject: [PATCH] src/svgtiny{.c,_internal.h}: intern SVG's XML namespace URI Intern the string "http://www.w3.org/2000/svg" in the parser state for later use in libcss's node_name() select handler. --- src/svgtiny.c | 17 +++++++++++++++++ src/svgtiny_internal.h | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/src/svgtiny.c b/src/svgtiny.c index b566768..361c43b 100644 --- a/src/svgtiny.c +++ b/src/svgtiny.c @@ -1234,6 +1234,19 @@ initialise_parse_state(struct svgtiny_parse_state *state, #include "svgtiny_strings.h" #undef SVGTINY_STRING_ACTION2 + /* Intern SVG's xmlns separately because it's an lwc_string + * and not a dom_string. We initialise its pointer to NULL + * because, during finalisation, the test to see if it needs + * to be free'd looks for NULL. Returning a LIBDOM_ERROR on + * failure is not perfect but it's the closest of the + * available options. */ + state->interned_svg_xmlns = NULL; + if (lwc_intern_string("http://www.w3.org/2000/svg", + 26, + &state->interned_svg_xmlns) != lwc_error_ok) { + return svgtiny_LIBDOM_ERROR; + } + /* get graphic dimensions */ state->viewport_width = viewport_width; state->viewport_height = viewport_height; @@ -1277,6 +1290,10 @@ static svgtiny_code finalise_parse_state(struct svgtiny_parse_state *state) #include "svgtiny_strings.h" #undef SVGTINY_STRING_ACTION2 + if (state->interned_svg_xmlns != NULL) { + lwc_string_unref(state->interned_svg_xmlns); + } + css_code = css_select_ctx_destroy(state->select_ctx); if (css_code != CSS_OK) { return svgtiny_LIBCSS_ERROR; diff --git a/src/svgtiny_internal.h b/src/svgtiny_internal.h index 7874053..641bc58 100644 --- a/src/svgtiny_internal.h +++ b/src/svgtiny_internal.h @@ -75,6 +75,14 @@ struct svgtiny_parse_state { #include "svgtiny_strings.h" #undef SVGTINY_STRING_ACTION2 + /* Where we store the interned copy of the SVG XML namespace, + * + * http://www.w3.org/2000/svg + * + * We handle it separately it has a different type + * (lwc_string) than those above (dom_string). + */ + lwc_string *interned_svg_xmlns; }; struct svgtiny_list; -- 2.49.0