Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/9fe01f09c879bd75c369e...
...commit
http://git.netsurf-browser.org/netsurf.git/commit/9fe01f09c879bd75c369ea0...
...tree
http://git.netsurf-browser.org/netsurf.git/tree/9fe01f09c879bd75c369ea064...
The branch, master has been updated
via 9fe01f09c879bd75c369ea064be519adaf3d9837 (commit)
from b41b672fe5228be936715254003132ee21843242 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=9fe01f09c879bd75c36...
commit 9fe01f09c879bd75c369ea064be519adaf3d9837
Author: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Commit: Daniel Silverstone <dsilvers(a)digital-scurf.org>
Replace duktape's default allocators. Realloc to zero is not guaranteed to free
on all platforms
diff --git a/javascript/duktape/dukky.c b/javascript/duktape/dukky.c
index 3549cd5..e56d517 100644
--- a/javascript/duktape/dukky.c
+++ b/javascript/duktape/dukky.c
@@ -289,6 +289,41 @@ dukky_inject_not_ctr(duk_context *ctx, int idx, const char *name)
return;
}
+/* Duktape heap utility functions */
+
+/* We need to override the defaults because not all platforms are fully ANSI
+ * compatible. E.g. RISC OS gets upset if we malloc or realloc a zero byte
+ * block, as do debugging tools such as Electric Fence by Bruce Perens.
+ */
+
+static void *dukky_alloc_function(void *udata, duk_size_t size)
+{
+ if (size == 0)
+ return NULL;
+
+ return malloc(size);
+}
+
+static void *dukky_realloc_function(void *udata, void *ptr, duk_size_t size)
+{
+ if (ptr == NULL && size == 0)
+ return NULL;
+
+ if (size == 0) {
+ free(ptr);
+ return NULL;
+ }
+
+ return realloc(ptr, size);
+}
+
+static void dukky_free_function(void *udata, void *ptr)
+{
+ if (ptr != NULL)
+ free(ptr);
+}
+
+
/**************************************** js.h ******************************/
struct jscontext {
duk_context *ctx;
@@ -322,7 +357,12 @@ nserror js_newcontext(int timeout, jscallback *cb, void *cbctx,
*jsctx = NULL;
LOG("Creating new duktape javascript context");
if (ret == NULL) return NSERROR_NOMEM;
- ctx = ret->ctx = duk_create_heap_default();
+ ctx = ret->ctx = duk_create_heap(
+ dukky_alloc_function,
+ dukky_realloc_function,
+ dukky_free_function,
+ NULL,
+ NULL);
if (ret->ctx == NULL) { free(ret); return NSERROR_NOMEM; }
/* Create the prototype stuffs */
duk_push_global_object(ctx);
-----------------------------------------------------------------------
Summary of changes:
javascript/duktape/dukky.c | 42 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/javascript/duktape/dukky.c b/javascript/duktape/dukky.c
index 3549cd5..e56d517 100644
--- a/javascript/duktape/dukky.c
+++ b/javascript/duktape/dukky.c
@@ -289,6 +289,41 @@ dukky_inject_not_ctr(duk_context *ctx, int idx, const char *name)
return;
}
+/* Duktape heap utility functions */
+
+/* We need to override the defaults because not all platforms are fully ANSI
+ * compatible. E.g. RISC OS gets upset if we malloc or realloc a zero byte
+ * block, as do debugging tools such as Electric Fence by Bruce Perens.
+ */
+
+static void *dukky_alloc_function(void *udata, duk_size_t size)
+{
+ if (size == 0)
+ return NULL;
+
+ return malloc(size);
+}
+
+static void *dukky_realloc_function(void *udata, void *ptr, duk_size_t size)
+{
+ if (ptr == NULL && size == 0)
+ return NULL;
+
+ if (size == 0) {
+ free(ptr);
+ return NULL;
+ }
+
+ return realloc(ptr, size);
+}
+
+static void dukky_free_function(void *udata, void *ptr)
+{
+ if (ptr != NULL)
+ free(ptr);
+}
+
+
/**************************************** js.h ******************************/
struct jscontext {
duk_context *ctx;
@@ -322,7 +357,12 @@ nserror js_newcontext(int timeout, jscallback *cb, void *cbctx,
*jsctx = NULL;
LOG("Creating new duktape javascript context");
if (ret == NULL) return NSERROR_NOMEM;
- ctx = ret->ctx = duk_create_heap_default();
+ ctx = ret->ctx = duk_create_heap(
+ dukky_alloc_function,
+ dukky_realloc_function,
+ dukky_free_function,
+ NULL,
+ NULL);
if (ret->ctx == NULL) { free(ret); return NSERROR_NOMEM; }
/* Create the prototype stuffs */
duk_push_global_object(ctx);
--
NetSurf Browser