From 24385aa274691a1bfc00f8a617bdd4a1487b567d Mon Sep 17 00:00:00 2001 From: Sami Vaarala Date: Wed, 26 Nov 2014 14:09:01 +0200 Subject: [PATCH] Example DUK_OPT_EXTSTR_FREE() for ajduk --- Makefile | 8 +++++--- examples/cmdline/duk_cmdline_ajduk.c | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 9a371ff2..8e38d9b3 100644 --- a/Makefile +++ b/Makefile @@ -823,9 +823,11 @@ CCOPTS_AJDUK += -DDUK_OPT_HEAPPTR16 CCOPTS_AJDUK += '-DDUK_OPT_HEAPPTR_ENC16(p)=ajsheap_enc16(p)' CCOPTS_AJDUK += '-DDUK_OPT_HEAPPTR_DEC16(x)=ajsheap_dec16(x)' CCOPTS_AJDUK += -DDUK_OPT_EXTERNAL_STRINGS -CCOPTS_AJDUK += '-DDUK_OPT_EXTSTR_INTERN_CHECK(ptr,len)=ajsheap_extstr_check_1((ptr),(len))' -#CCOPTS_AJDUK += '-DDUK_OPT_EXTSTR_INTERN_CHECK(ptr,len)=ajsheap_extstr_check_2((ptr),(len))' -CCOPTS_AJDUK += '-DDUK_OPT_DECLARE=extern uint8_t *ajsheap_ram; extern duk_uint16_t ajsheap_enc16(void *p); extern void *ajsheap_dec16(duk_uint16_t x); extern const void *ajsheap_extstr_check_1(const void *ptr, duk_size_t len); extern const void *ajsheap_extstr_check_2(const void *ptr, duk_size_t len);' +#CCOPTS_AJDUK += '-DDUK_OPT_EXTSTR_INTERN_CHECK(ptr,len)=ajsheap_extstr_check_1((ptr),(len))' +#CCOPTS_AJDUK += '-DDUK_OPT_EXTSTR_FREE(ptr)=ajsheap_extstr_free_1((ptr))' +CCOPTS_AJDUK += '-DDUK_OPT_EXTSTR_INTERN_CHECK(ptr,len)=ajsheap_extstr_check_2((ptr),(len))' +CCOPTS_AJDUK += '-DDUK_OPT_EXTSTR_FREE(ptr)=ajsheap_extstr_free_2((ptr))' +CCOPTS_AJDUK += '-DDUK_OPT_DECLARE=extern uint8_t *ajsheap_ram; extern duk_uint16_t ajsheap_enc16(void *p); extern void *ajsheap_dec16(duk_uint16_t x); extern const void *ajsheap_extstr_check_1(const void *ptr, duk_size_t len); extern const void *ajsheap_extstr_check_2(const void *ptr, duk_size_t len); extern void ajsheap_extstr_free_1(const void *ptr); extern void ajsheap_extstr_free_2(const void *ptr);' #CCOPTS_AJDUK += -DDUK_OPT_DEBUG -DDUK_OPT_DPRINT #CCOPTS_AJDUK += -DDUK_OPT_DEBUG -DDUK_OPT_DPRINT -DDUK_OPT_DDPRINT -DDUK_OPT_DDDPRINT diff --git a/examples/cmdline/duk_cmdline_ajduk.c b/examples/cmdline/duk_cmdline_ajduk.c index a77e12c5..a473c09c 100644 --- a/examples/cmdline/duk_cmdline_ajduk.c +++ b/examples/cmdline/duk_cmdline_ajduk.c @@ -260,6 +260,13 @@ const void *ajsheap_extstr_check_1(const void *ptr, duk_size_t len) { return (const void *) ret; } +void ajsheap_extstr_free_1(void *ptr) { + (void) ptr; +#if 0 + printf("ajsheap_extstr_free_1: freeing extstr %p\n", ptr); +#endif +} + /* * Simplified example of an external strings strategy where a set of strings * is gathered during application compile time and baked into the application @@ -268,7 +275,7 @@ const void *ajsheap_extstr_check_1(const void *ptr, duk_size_t len) { * Duktape built-in strings are available from duk_build_meta.json, see * util/duk_meta_to_strarray.py. There may also be a lot of application * specific strings, e.g. those used by application specific APIs. These - * must be gathered through some other means. + * must be gathered through some other means, see e.g. util/scan_strings.py. */ static const char *strdata_duk_builtin_strings[] = { @@ -664,6 +671,13 @@ const void *ajsheap_extstr_check_2(const void *ptr, duk_size_t len) { return NULL; } +void ajsheap_extstr_free_2(void *ptr) { + (void) ptr; +#if 0 + printf("ajsheap_extstr_free_2: freeing extstr %p\n", ptr); +#endif +} + #else /* DUK_CMDLINE_AJSHEAP */ int ajs_dummy = 0; /* to avoid empty source file */