From cc79dfbdb09f75047cf4bcabf37870e6b9a406e9 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Tue, 21 Jul 2015 18:26:27 +0300 Subject: [PATCH 1/2] Fix some pointer compression issues on x64 --- src/duk_hbuffer_alloc.c | 9 +++++++-- src/duk_heap_alloc.c | 4 ++++ src/duk_hobject_alloc.c | 6 +++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/duk_hbuffer_alloc.c b/src/duk_hbuffer_alloc.c index 3c9619a2..6e63422f 100644 --- a/src/duk_hbuffer_alloc.c +++ b/src/duk_hbuffer_alloc.c @@ -63,9 +63,14 @@ DUK_INTERNAL duk_hbuffer *duk_hbuffer_alloc(duk_heap *heap, duk_size_t size, duk DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap, h, ptr); DUK_HBUFFER_DYNAMIC_SET_ALLOC_SIZE(h, size); /* snug */ } else { -#ifdef DUK_USE_EXPLICIT_NULL_INIT - h->curr_alloc = NULL; +#if defined(DUK_USE_EXPLICIT_NULL_INIT) +#if defined(DUK_USE_HEAPPTR16) +/* the compressed pointer is zeroed which maps to NULL, so nothing to do. */ +#else + DUK_HBUFFER_DYNAMIC_SET_DATA_PTR(heap, h, NULL); +#endif #endif + DUK_ASSERT(DUK_HBUFFER_DYNAMIC_GET_DATA_PTR(heap, h) == NULL); DUK_ASSERT(DUK_HBUFFER_DYNAMIC_GET_ALLOC_SIZE(h) == 0); } } diff --git a/src/duk_heap_alloc.c b/src/duk_heap_alloc.c index 89cb10ff..0192bb5c 100644 --- a/src/duk_heap_alloc.c +++ b/src/duk_heap_alloc.c @@ -720,12 +720,16 @@ duk_heap *duk_heap_alloc(duk_alloc_function alloc_func, res->strtable = (duk_hstring **) NULL; #endif #endif +#if defined(DUK_USE_HEAPPTR16) +/* res->strs16[] is zeroed and zero decodes to NULL, so no NULL inits. */ +#else { duk_small_uint_t i; for (i = 0; i < DUK_HEAP_NUM_STRINGS; i++) { res->strs[i] = NULL; } } +#endif #if defined(DUK_USE_DEBUGGER_SUPPORT) res->dbg_read_cb = NULL; res->dbg_write_cb = NULL; diff --git a/src/duk_hobject_alloc.c b/src/duk_hobject_alloc.c index 71e6e6fa..778b29db 100644 --- a/src/duk_hobject_alloc.c +++ b/src/duk_hobject_alloc.c @@ -78,7 +78,7 @@ DUK_INTERNAL duk_hcompiledfunction *duk_hcompiledfunction_alloc(duk_heap *heap, duk__init_object_parts(heap, &res->obj, hobject_flags); #ifdef DUK_USE_EXPLICIT_NULL_INIT -#ifdef DUK_HEAPPTR16 +#ifdef DUK_USE_HEAPPTR16 /* NULL pointer is required to encode to zero, so memset is enough. */ #else res->data = NULL; @@ -156,7 +156,11 @@ DUK_INTERNAL duk_hthread *duk_hthread_alloc(duk_heap *heap, duk_uint_t hobject_f res->catchstack = NULL; res->resumer = NULL; res->compile_ctx = NULL, +#ifdef DUK_USE_HEAPPTR16 + res->strs16 = NULL; +#else res->strs = NULL; +#endif { int i; for (i = 0; i < DUK_NUM_BUILTINS; i++) { From 1402d7537b7199ca91f25aea51c0f830d1e6e3e5 Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Tue, 21 Jul 2015 18:27:17 +0300 Subject: [PATCH 2/2] Releases: pointer compression fixes --- RELEASES.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/RELEASES.rst b/RELEASES.rst index 52fafe3d..3aa3256a 100644 --- a/RELEASES.rst +++ b/RELEASES.rst @@ -995,6 +995,8 @@ Planned * Fix compile error from array fast path when using low memory options (GH-174) +* Fix a few pointer compression issues (DUK_USE_HEAPPTR16) on 64-bit platforms + * Fix harmless MSVC warnings when using DUK_OPT_FASTINT on x86 (GH-172) * Fix harmless MSVC warnings for size_t casts on x64 (GH-177)