summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xamiga/gui.c14
-rw-r--r--css/css.c23
-rw-r--r--framebuffer/gui.c15
-rw-r--r--gtk/gtk_gui.c18
-rw-r--r--render/html.c20
-rw-r--r--render/hubbub_binding.c6
-rw-r--r--riscos/gui.c15
-rw-r--r--utils/utils.c13
-rw-r--r--utils/utils.h12
-rw-r--r--windows/gui.c14
10 files changed, 42 insertions, 108 deletions
diff --git a/amiga/gui.c b/amiga/gui.c
index 249f80c89..47aee25e7 100755
--- a/amiga/gui.c
+++ b/amiga/gui.c
@@ -157,7 +157,6 @@ void ami_scroller_hook(struct Hook *,Object *,struct IntuiMessage *);
uint32 ami_popup_hook(struct Hook *hook,Object *item,APTR reserved);
void ami_switch_tab(struct gui_window_2 *gwin,bool redraw);
void ami_change_tab(struct gui_window_2 *gwin, int direction);
-static void *myrealloc(void *ptr, size_t len, void *pw);
void ami_get_hscroll_pos(struct gui_window_2 *gwin, ULONG *xs);
void ami_get_vscroll_pos(struct gui_window_2 *gwin, ULONG *ys);
ULONG ami_set_border_gadget_balance(struct gui_window_2 *gwin);
@@ -417,7 +416,7 @@ void gui_init(int argc, char** argv)
quirks_stylesheet_url = "file:///PROGDIR:Resources/quirks.css";
adblock_stylesheet_url = "file:///PROGDIR:Resources/adblock.css";
- if(hubbub_initialise("PROGDIR:Resources/Aliases",myrealloc,NULL) != HUBBUB_OK)
+ if(hubbub_initialise("PROGDIR:Resources/Aliases", ns_realloc, NULL) != HUBBUB_OK)
{
die(messages_get("NoMemory"));
}
@@ -1967,7 +1966,7 @@ void gui_quit(void)
ami_cookies_free();
ami_global_history_free();
- hubbub_finalise(myrealloc,NULL);
+ hubbub_finalise(ns_realloc,NULL);
if(IApplication && ami_appid)
UnregisterApplication(ami_appid, NULL);
@@ -3752,12 +3751,3 @@ uint32 ami_popup_hook(struct Hook *hook,Object *item,APTR reserved)
return itemid;
}
-static void *myrealloc(void *ptr, size_t len, void *pw)
-{
- if (len == 0) {
- free(ptr);
- return NULL;
- }
-
- return realloc(ptr, len);
-}
diff --git a/css/css.c b/css/css.c
index 7fb17519b..69e0d4e33 100644
--- a/css/css.c
+++ b/css/css.c
@@ -27,6 +27,7 @@
#include "css/internal.h"
#include "desktop/gui.h"
#include "render/html.h"
+#include "utils/utils.h"
#include "utils/http.h"
#include "utils/messages.h"
@@ -51,24 +52,6 @@ static nserror nscss_import(hlcache_handle *handle,
const hlcache_event *event, void *pw);
/**
- * Allocation callback for libcss
- *
- * \param ptr Pointer to reallocate, or NULL for new allocation
- * \param size Number of bytes requires
- * \param pw Allocation context
- * \return Pointer to allocated block, or NULL on failure
- */
-static void *myrealloc(void *ptr, size_t size, void *pw)
-{
- if (size == 0) {
- free(ptr);
- return NULL;
- }
-
- return realloc(ptr, size);
-}
-
-/**
* Initialise a CSS content
*
* \param c Content to initialise
@@ -125,7 +108,7 @@ nserror nscss_create_css_data(struct content_css_data *c,
error = css_stylesheet_create(CSS_LEVEL_21, charset,
url, NULL, quirks, false,
- myrealloc, NULL,
+ ns_realloc, NULL,
nscss_resolve_url, NULL,
&c->sheet);
if (error != CSS_OK) {
@@ -448,7 +431,7 @@ css_error nscss_import_complete(struct content_css_data *c,
if (blank_import == NULL) {
error = css_stylesheet_create(CSS_LEVEL_DEFAULT,
NULL, "", NULL, false, false,
- myrealloc, NULL,
+ ns_realloc, NULL,
nscss_resolve_url, NULL,
&blank_import);
if (error != CSS_OK) {
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index 10a2b329d..14771ad27 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -321,17 +321,6 @@ fb_browser_window_redraw(fbtk_widget_t *root, fbtk_widget_t *widget, void *pw)
return 0;
}
-static void *myrealloc(void *ptr, size_t len, void *pw)
-{
- if (len == 0) {
- free(ptr);
- return NULL;
- }
-
- return realloc(ptr, len);
-}
-
-
static const char *fename;
static int febpp;
static int fewidth;
@@ -402,7 +391,7 @@ static void gui_init(int argc, char** argv)
fb_find_resource(buf, "Aliases", "./framebuffer/res/Aliases");
LOG(("Using '%s' as Aliases file", buf));
- if (hubbub_initialise(buf, myrealloc, NULL) != HUBBUB_OK)
+ if (hubbub_initialise(buf, ns_realloc, NULL) != HUBBUB_OK)
die("Unable to initialise HTML parsing library.\n");
option_core_select_menu = true;
@@ -504,7 +493,7 @@ void gui_quit(void)
framebuffer_finalise();
/* We don't care if this fails as we're about to exit, anyway */
- hubbub_finalise(myrealloc, NULL);
+ hubbub_finalise(ns_realloc, NULL);
}
/* called back when click in browser window */
diff --git a/gtk/gtk_gui.c b/gtk/gtk_gui.c
index 9a0eca10a..eec28a20a 100644
--- a/gtk/gtk_gui.c
+++ b/gtk/gtk_gui.c
@@ -98,7 +98,6 @@ static struct form_control *select_menu_control;
static void nsgtk_init_glade(void);
static void nsgtk_check_homedir(void);
-static void *nsgtk_hubbub_realloc(void *ptr, size_t len, void *pw);
static bool nsgtk_throbber_init(int framec);
static void nsgtk_ssl_accept(GtkButton *w, gpointer data);
static void nsgtk_ssl_reject(GtkButton *w, gpointer data);
@@ -199,7 +198,7 @@ static void gui_init(int argc, char** argv)
nsgtk_find_resource(buf, "Aliases", "./gtk/res/Aliases");
LOG(("Using '%s' as Aliases file", buf));
- if (hubbub_initialise(buf, nsgtk_hubbub_realloc, NULL) != HUBBUB_OK)
+ if (hubbub_initialise(buf, ns_realloc, NULL) != HUBBUB_OK)
die("Unable to initialise HTML parsing library.\n");
nsgtk_find_resource(buf, "netsurf.xpm", "./gtk/res/netsurf.xpm");
@@ -501,7 +500,7 @@ void gui_quit(void)
free(toolbar_indices_file_location);
gtk_fetch_filetype_fin();
/* We don't care if this fails as we're about to die, anyway */
- hubbub_finalise(nsgtk_hubbub_realloc, NULL);
+ hubbub_finalise(ns_realloc, NULL);
}
@@ -533,19 +532,6 @@ void nsgtk_check_homedir(void)
}
-/**
- * Allocator callback function for hubbub.
- */
-void *nsgtk_hubbub_realloc(void *ptr, size_t len, void *pw)
-{
- if (len == 0) {
- free(ptr);
- return NULL;
- }
-
- return realloc(ptr, len);
-}
-
/* This is an ugly hack to just get the new-style throbber going.
* It, along with the PNG throbber loader, need making more generic.
diff --git a/render/html.c b/render/html.c
index caada3c96..c818d6e36 100644
--- a/render/html.c
+++ b/render/html.c
@@ -97,24 +97,6 @@ static const char empty_document[] =
"</html>";
/**
- * Allocator
- *
- * \param ptr Pointer to reallocate, or NULL for new allocation
- * \param size Number of bytes requires
- * \param pw Allocation context
- * \return Pointer to allocated block, or NULL on failure
- */
-static void *myrealloc(void *ptr, size_t len, void *pw)
-{
- if (len == 0) {
- free(ptr);
- return NULL;
- }
-
- return realloc(ptr, len);
-}
-
-/**
* Create a CONTENT_HTML.
*
* The content_html_data structure is initialized and the HTML parser is
@@ -484,7 +466,7 @@ void html_finish_conversion(struct content *c)
}
/* Create selection context */
- error = css_select_ctx_create(myrealloc, c, &c->data.html.select_ctx);
+ error = css_select_ctx_create(ns_realloc, c, &c->data.html.select_ctx);
if (error != CSS_OK) {
msg_data.error = messages_get("NoMemory");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
diff --git a/render/hubbub_binding.c b/render/hubbub_binding.c
index bc509b4eb..f050862a0 100644
--- a/render/hubbub_binding.c
+++ b/render/hubbub_binding.c
@@ -126,7 +126,7 @@ static hubbub_tree_handler tree_handler = {
NULL
};
-static void *myrealloc(void *ptr, size_t len, void *pw)
+static void *ns_talloc_based_realloc(void *ptr, size_t len, void *pw)
{
/* talloc_realloc_size(pw, ptr, 0) == talloc_free(ptr) */
return talloc_realloc_size(pw, ptr, len);
@@ -152,8 +152,8 @@ binding_error binding_create_tree(void *arena, const char *charset, void **ctx)
c->quirks = BINDING_QUIRKS_MODE_NONE;
c->forms = NULL;
- error = hubbub_parser_create(charset, true, myrealloc, arena,
- &c->parser);
+ error = hubbub_parser_create(charset, true, ns_talloc_based_realloc,
+ arena, &c->parser);
if (error != HUBBUB_OK) {
free(c);
if (error == HUBBUB_BADENCODING)
diff --git a/riscos/gui.c b/riscos/gui.c
index d3148529c..eaba7bf58 100644
--- a/riscos/gui.c
+++ b/riscos/gui.c
@@ -271,17 +271,6 @@ static void ro_msg_save_desktop(wimp_message *message);
static void ro_msg_window_info(wimp_message *message);
static void ro_gui_view_source_bounce(wimp_message *message);
-static void *myrealloc(void *ptr, size_t len, void *pw)
-{
- if (len == 0) {
- free(ptr);
- return NULL;
- }
-
- return realloc(ptr, len);
-}
-
-
/**
* Initialise the gui (RISC OS specific part).
*/
@@ -321,7 +310,7 @@ static void gui_init(int argc, char** argv)
ro_plot_patterned_lines = false;
}
- if (hubbub_initialise("NetSurf:Resources.Aliases", myrealloc, NULL) !=
+ if (hubbub_initialise("NetSurf:Resources.Aliases", ns_realloc, NULL) !=
HUBBUB_OK)
die("Failed to initialise HTML parsing library.");
@@ -802,7 +791,7 @@ void gui_quit(void)
free(quirks_stylesheet_url);
free(adblock_stylesheet_url);
/* We don't care if this fails */
- hubbub_finalise(myrealloc, NULL);
+ hubbub_finalise(ns_realloc, NULL);
xhourglass_off();
}
diff --git a/utils/utils.c b/utils/utils.c
index 175b33073..346fd5585 100644
--- a/utils/utils.c
+++ b/utils/utils.c
@@ -39,6 +39,19 @@
#include "utils/utf8.h"
#include "utils/utils.h"
+void *
+ns_realloc(void *ptr, size_t size, void *pw)
+{
+ (void)pw;
+
+ if (ptr == NULL)
+ return size > 0 ? malloc(size) : NULL;
+ if (size == 0) {
+ free(ptr);
+ return NULL;
+ }
+ return realloc(ptr, size);
+}
char * strip(char * const s)
{
diff --git a/utils/utils.h b/utils/utils.h
index f58a2632b..5b06d9caa 100644
--- a/utils/utils.h
+++ b/utils/utils.h
@@ -78,6 +78,18 @@ typedef struct
#define nsmkdir(dir, mode) mkdir((dir))
#endif
+/**
+ * Private-word-capable realloc() implementation which
+ * behaves as most NS libraries expect in the face of
+ * realloc(ptr, 0) and realloc(NULL, size).
+ *
+ * \param ptr The pointer for reallocation
+ * \param size The number of bytes for the allocation
+ * \param pw A "private word" which we ignore.
+ * \return The new pointer (NULL on frees or errors)
+ */
+void *ns_realloc(void *ptr, size_t size, void *pw);
+
char * strip(char * const s);
int whitespace(const char * str);
char * squash_whitespace(const char * s);
diff --git a/windows/gui.c b/windows/gui.c
index 187430a3c..7dfa7579c 100644
--- a/windows/gui.c
+++ b/windows/gui.c
@@ -2282,21 +2282,11 @@ void gui_cert_verify(const char *url, const struct ssl_cert_info *certs,
}
-static void *myrealloc(void *ptr, size_t len, void *pw)
-{
- if (len == 0) {
- free(ptr);
- return NULL;
- }
-
- return realloc(ptr, len);
-}
-
void gui_quit(void)
{
LOG(("gui_quit"));
- hubbub_finalise(myrealloc, NULL);
+ hubbub_finalise(ns_realloc, NULL);
}
static void gui_init(int argc, char** argv)
@@ -2309,7 +2299,7 @@ static void gui_init(int argc, char** argv)
nsws_find_resource(buf, "Aliases", "./windows/res/Aliases");
LOG(("Using '%s' as Aliases file", buf));
- hubbub_error he = hubbub_initialise(buf, myrealloc, NULL);
+ hubbub_error he = hubbub_initialise(buf, ns_realloc, NULL);
LOG(("hubbub init %d", he));
if (he != HUBBUB_OK)
die("Unable to initialise HTML parsing library.\n");