Browse Source

add a USE define for deep C stacks used on mainstream platforms by default; add increased recursion limits when in use

pull/1/head
Sami Vaarala 11 years ago
parent
commit
22e03d2c6f
  1. 26
      src/duk_features.h
  2. 12
      src/duk_heap.h
  3. 5
      src/duk_json.h
  4. 4
      src/duk_regexp.h

26
src/duk_features.h

@ -131,12 +131,23 @@ static __inline__ unsigned long long duk_rdtsc(void) {
#define DUK_F_M68K
#endif
/* Linux */
#if defined(__linux)
#define DUK_F_LINUX
#endif
/* BSD variant */
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD) || \
defined(__bsdi__) || defined(__DragonFly__)
#define DUK_F_BSD
#endif
/* Windows (32-bit or above) */
#if defined(_WIN32) || defined(_WIN64) || defined(WIN32) || \
defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__)
#define DUK_F_WINDOWS
#endif
/* Atari ST TOS. __TOS__ defined by PureC (which doesn't work as a target now
* because int is 16-bit, to be fixed). No platform define in VBCC apparently,
* so to use with VBCC, user must define '__TOS__' manually.
@ -183,7 +194,7 @@ static __inline__ unsigned long long duk_rdtsc(void) {
* specify byte order explicitly on more exotic platforms.
*/
#if defined(__linux)
#if defined(DUK_F_LINUX)
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#endif
@ -912,6 +923,19 @@ extern double duk_computed_nan;
#define DUK_FUNC_MACRO "unknown"
#endif
/*
* Deep vs. shallow stack.
*
* Some embedded platforms have very shallow stack (e.g. 64kB); default to
* a shallow stack on unknown platforms or known embedded platforms.
*/
#if defined(DUK_F_LINUX) || defined(DUK_F_BSD) || defined(DUK_F_WINDOWS)
#define DUK_USE_DEEP_C_STACK
#else
#undef DUK_USE_DEEP_C_STACK
#endif
/*
* Profile processing
*

12
src/duk_heap.h

@ -77,14 +77,20 @@
* There is a separate callstack depth limit for threads.
*/
#define DUK_HEAP_DEFAULT_CALL_RECURSION_LIMIT 60 /* assuming 0.5 kB between calls, about 30kB of stack */
#if defined(DUK_USE_DEEP_C_STACK)
#define DUK_HEAP_DEFAULT_CALL_RECURSION_LIMIT 1000 /* assuming 0.5 kB between calls, about 500kB of stack */
#else
#define DUK_HEAP_DEFAULT_CALL_RECURSION_LIMIT 60 /* assuming 0.5 kB between calls, about 30kB of stack */
#endif
/* mark-and-sweep C recursion depth for marking phase; if reached,
* mark object as a TEMPROOT and use multi-pass marking.
*/
#ifdef DUK_USE_MARK_AND_SWEEP
#ifdef DUK_USE_GC_TORTURE
#if defined(DUK_USE_MARK_AND_SWEEP)
#if defined(DUK_USE_GC_TORTURE)
#define DUK_HEAP_DEFAULT_MARK_AND_SWEEP_RECURSION_LIMIT 3
#elif defined(DUK_USE_DEEP_C_STACK)
#define DUK_HEAP_DEFAULT_MARK_AND_SWEEP_RECURSION_LIMIT 256
#else
#define DUK_HEAP_DEFAULT_MARK_AND_SWEEP_RECURSION_LIMIT 32
#endif

5
src/duk_json.h

@ -6,8 +6,13 @@
#define DUK_JSON_H_INCLUDED
/* Object/array recursion limit (to protect C stack) */
#if defined(DUK_USE_DEEP_C_STACK)
#define DUK_JSON_ENC_RECURSION_LIMIT 1000
#define DUK_JSON_DEC_RECURSION_LIMIT 1000
#else
#define DUK_JSON_ENC_RECURSION_LIMIT 100
#define DUK_JSON_DEC_RECURSION_LIMIT 100
#endif
/* Encoding flags */
#define DUK_JSON_ENC_FLAG_ASCII_ONLY (1 << 0) /* escape any non-ASCII characters */

4
src/duk_regexp.h

@ -9,7 +9,11 @@
#define DUK_RE_MAX_ATOM_COPIES 1000
/* regexp compilation limits */
#if defined(DUK_USE_DEEP_C_STACK)
#define DUK_RE_COMPILE_RECURSION_LIMIT 1000
#else
#define DUK_RE_COMPILE_RECURSION_LIMIT 100
#endif
/* regexp execution limits */
#define DUK_RE_EXECUTE_RECURSION_LIMIT 100

Loading…
Cancel
Save