Browse Source

Example DUK_OPT_EXTSTR_FREE() for ajduk

pull/92/head
Sami Vaarala 10 years ago
parent
commit
24385aa274
  1. 8
      Makefile
  2. 16
      examples/cmdline/duk_cmdline_ajduk.c

8
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

16
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 */

Loading…
Cancel
Save