mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-22 22:41:30 +03:00
Consolidate several 'myrealloc' functions into ns_realloc, rename one which *is* different, thereby eliminating the word 'myrealloc' from the NS codebase
svn path=/trunk/netsurf/; revision=10530
This commit is contained in:
parent
f0237aac92
commit
5e887908b3
14
amiga/gui.c
14
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);
|
||||
}
|
||||
|
23
css/css.c
23
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"
|
||||
|
||||
@ -50,24 +51,6 @@ static css_error nscss_import_complete(struct content_css_data *c,
|
||||
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
|
||||
*
|
||||
@ -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) {
|
||||
|
@ -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 */
|
||||
|
@ -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.
|
||||
|
@ -96,24 +96,6 @@ static const char empty_document[] =
|
||||
"</body>"
|
||||
"</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.
|
||||
*
|
||||
@ -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);
|
||||
|
@ -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)
|
||||
|
15
riscos/gui.c
15
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();
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user