I was wondering what the recommended approach to memory overflow is. Most of jsvar.c check for overflow and behave accordingly, while other code assume no overflow, e.g. _jswrap_interface_setTimeoutOrInterval. Then there is jsvObjectSetChildAndUnLock which doesn't unlock the child in case of overflow, while others like jsvArrayPushAndUnLock do.
I tried to use the following defines for perfect overflow coverage in my library
﹟define INIT(n) JsVar* _lock_array[n]; int _lock_index = 0
﹟define END(i) _end(i, _lock_array, _lock_index)
﹟define NEW(a) ({ JsVar* var = a; if (!var) return END(0); _lock_array[_lock_index++] = var; var; })
﹟define TMP(a) ({ JsVar* var = a; if (!var) return END(0); var; })
﹟define GRD(a) if (!(a)) return END(0);
JsVar* _end(int end_index, JsVar** array, int index) {
while (index != end_index) jsvUnLock(array[--index]);
return 0;
}
but I'm uncertain if its worth the trouble. What if I won't check for overflow, like _jswrap_interface_setTimeoutOrInterval, would it lead to unexpected behavior in case of overflow instead of noisy "segfault"?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Hi,
I was wondering what the recommended approach to memory overflow is. Most of
jsvar.c
check for overflow and behave accordingly, while other code assume no overflow, e.g._jswrap_interface_setTimeoutOrInterval
. Then there isjsvObjectSetChildAndUnLock
which doesn't unlock the child in case of overflow, while others likejsvArrayPushAndUnLock
do.I tried to use the following defines for perfect overflow coverage in my library
but I'm uncertain if its worth the trouble. What if I won't check for overflow, like
_jswrap_interface_setTimeoutOrInterval
, would it lead to unexpected behavior in case of overflow instead of noisy "segfault"?