From eeb3db8bfd7fd0082256879a8847e8b72ba1e0f872120331b39359fc1e03e362 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Fri, 1 Aug 2025 01:47:08 -0400 Subject: [PATCH] A bit more RAII for DilloHtml... --- src/html.cc | 16 ++++------------ src/html_common.hh | 2 +- src/menu.cc | 6 ++---- src/menu.hh | 2 +- src/uicmd.cc | 4 ++-- src/uicmd.hh | 2 +- 6 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/html.cc b/src/html.cc index f124255..8554e6c 100644 --- a/src/html.cc +++ b/src/html.cc @@ -475,8 +475,6 @@ DilloHtml::DilloHtml(BrowserWindow *p_bw, const DilloUrl *url, styleEngine = std::make_unique< StyleEngine >(HT2LT (this), page_url, base_url, bw->zoom); - cssUrls = new misc::SimpleVector (1); - stack = new misc::SimpleVector (16); stack->increase(); stack->getRef(0)->parse_mode = DILLO_HTML_PARSE_MODE_INIT; @@ -554,10 +552,6 @@ DilloHtml::~DilloHtml() delete page_url; delete base_url; - for (int i = 0; i < cssUrls->size(); i++) - delete cssUrls->get(i); - delete (cssUrls); - for (std::size_t i = 0; i < forms.size(); i++) a_Html_form_delete (forms.at(i)); forms.clear(); @@ -729,9 +723,7 @@ void DilloHtml::loadImages (const DilloUrl *pattern) */ void DilloHtml::addCssUrl(const DilloUrl *url) { - int nu = cssUrls->size(); - cssUrls->increase(); - cssUrls->set(nu, a_Url_dup(url).release()); + cssUrls.push_back( a_Url_dup(url) ); } bool DilloHtml::HtmlLinkReceiver::enter (Widget *widget, int link, int img, @@ -774,7 +766,7 @@ bool DilloHtml::HtmlLinkReceiver::press (Widget *widget, int link, int img, ret = true; } else { if (link == -1) { - a_UIcmd_page_popup(bw, bw->num_page_bugs != 0, html->cssUrls); + a_UIcmd_page_popup(bw, bw->num_page_bugs != 0, &html->cssUrls); ret = true; } else { a_UIcmd_link_popup(bw, html->links.at(link).get(), html->page_url); @@ -1666,8 +1658,8 @@ static void Html_tag_close_head(DilloHtml *html) html->InFlags &= ~IN_HEAD; /* charset is already set, load remote stylesheets now */ - for (int i = 0; i < html->cssUrls->size(); i++) { - a_Html_load_stylesheet(html, html->cssUrls->get(i)); + for (int i = 0; i < html->cssUrls.size(); i++) { + a_Html_load_stylesheet(html, html->cssUrls.at(i).get()); } } else if (html->Num_HEAD > 1) { --html->Num_HEAD; diff --git a/src/html_common.hh b/src/html_common.hh index 85f1850..59e9f7e 100644 --- a/src/html_common.hh +++ b/src/html_common.hh @@ -185,7 +185,7 @@ public: //BUG: for now everything is public float DocTypeVersion; /* HTML or XHTML version number */ /* vector of remote CSS resources, as given by the LINK element */ - lout::misc::SimpleVector *cssUrls; + std::vector< std::unique_ptr< DilloUrl > > cssUrls; lout::misc::SimpleVector *stack; std::unique_ptr< StyleEngine > styleEngine; diff --git a/src/menu.cc b/src/menu.cc index 4cd0f59..90c6c62 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -353,10 +353,8 @@ static void Menu_popup_cb(void *data) * Page popup menu (construction & popup) */ void a_Menu_page_popup(BrowserWindow *bw, const DilloUrl *url, - bool_t has_bugs, void *v_cssUrls) + bool_t has_bugs, std::vector< std::unique_ptr< DilloUrl > > *cssUrls) { - lout::misc::SimpleVector *cssUrls = - (lout::misc::SimpleVector *) v_cssUrls; int j = 0; static Fl_Menu_Item *stylesheets = NULL; @@ -402,7 +400,7 @@ void a_Menu_page_popup(BrowserWindow *bw, const DilloUrl *url, memset(stylesheets, '\0', (cssUrls->size() + 1) * sizeof(Fl_Menu_Item)); for (j = 0; j < cssUrls->size(); j++) { - DilloUrl *url = cssUrls->get(j); + DilloUrl *url = cssUrls->at(j).get(); const char *url_str = URL_STR(url); const uint_t head_length = 30, tail_length = 40, url_len = strlen(url_str); diff --git a/src/menu.hh b/src/menu.hh index 0aa43ea..0fc43c1 100644 --- a/src/menu.hh +++ b/src/menu.hh @@ -8,7 +8,7 @@ extern "C" { #endif /* __cplusplus */ void a_Menu_page_popup(BrowserWindow *bw, const DilloUrl *url, - bool_t has_bugs, void *v_cssUrls); + bool_t has_bugs, std::vector< std::unique_ptr< DilloUrl > > *cssUrls); void a_Menu_link_popup(BrowserWindow *bw, const DilloUrl *url, const DilloUrl *page_url); void a_Menu_image_popup(BrowserWindow *bw, const DilloUrl *url, diff --git a/src/uicmd.cc b/src/uicmd.cc index 0dc629e..693be29 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -1253,11 +1253,11 @@ void a_UIcmd_add_bookmark(BrowserWindow *bw, const DilloUrl *url) /* * Popup the page menu */ -void a_UIcmd_page_popup(void *vbw, bool_t has_bugs, void *v_cssUrls) +void a_UIcmd_page_popup(void *vbw, bool_t has_bugs, std::vector< std::unique_ptr< DilloUrl > > *cssUrls) { BrowserWindow *bw = (BrowserWindow*)vbw; const DilloUrl *url = a_History_get_url(NAV_TOP_UIDX(bw)); - a_Menu_page_popup(bw, url, has_bugs, v_cssUrls); + a_Menu_page_popup(bw, url, has_bugs, cssUrls); } /* diff --git a/src/uicmd.hh b/src/uicmd.hh index 3673d0d..65abfba 100644 --- a/src/uicmd.hh +++ b/src/uicmd.hh @@ -58,7 +58,7 @@ void a_UIcmd_findtext_reset(BrowserWindow *bw); void a_UIcmd_findbar_toggle(BrowserWindow *bw, int on); void a_UIcmd_focus_main_area(BrowserWindow *bw); void a_UIcmd_focus_location(void *vbw); -void a_UIcmd_page_popup(void *vbw, bool_t has_bugs, void *v_cssUrls); +void a_UIcmd_page_popup(void *vbw, bool_t has_bugs, std::vector< std::unique_ptr< DilloUrl > > *cssUrls); void a_UIcmd_link_popup(void *vbw, const DilloUrl *url, const DilloUrl *page_url); void a_UIcmd_image_popup(void *vbw, const DilloUrl *url, bool_t loaded_img, DilloUrl *page_url, DilloUrl *link_url);