From 471cea1fd80c3cf9c1361b528b0eff8197e853ba Mon Sep 17 00:00:00 2001 From: deuce <> Date: Thu, 7 Feb 2013 00:27:17 +0000 Subject: [PATCH] Add *_TO_MSTRING() macros to return malloc()ed strings instead of the current alloca()ed ones. --- src/sbbs3/sbbs.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/sbbs3/sbbs.h b/src/sbbs3/sbbs.h index df3eb6e781..7b9647a107 100644 --- a/src/sbbs3/sbbs.h +++ b/src/sbbs3/sbbs.h @@ -111,6 +111,33 @@ extern int thread_suid_broken; /* NPTL is no longer broken */ #include <jsapi.h> #define JS_DestroyScript(cx,script) +#define JSSTRING_TO_MSTRING(cx, str, ret, lenptr) \ +{ \ + size_t *JSSTSlenptr=lenptr; \ + size_t JSSTSlen; \ + size_t JSSTSpos; \ + const jschar *JSSTSstrval; \ +\ + if(JSSTSlenptr==NULL) \ + JSSTSlenptr=&JSSTSlen; \ + (ret)=NULL; \ + if((str) != NULL) { \ + if((JSSTSstrval=JS_GetStringCharsAndLength((cx), (str), JSSTSlenptr))) { \ + if(((ret)=(char *)malloc(*JSSTSlenptr+1))) { \ + for(JSSTSpos=0; JSSTSpos<*JSSTSlenptr; JSSTSpos++) \ + (ret)[JSSTSpos]=(char)JSSTSstrval[JSSTSpos]; \ + (ret)[*JSSTSlenptr]=0; \ + } \ + } \ + } \ +} + +#define JSVALUE_TO_MSTRING(cx, val, ret, lenptr) \ +{ \ + JSString *JSVTSstr=JS_ValueToString((cx), (val)); \ + JSSTRING_TO_MSTRING((cx), JSVTSstr, (ret), lenptr); \ +} + #define JSSTRING_TO_STRING(cx, str, ret, lenptr) \ { \ size_t *JSSTSlenptr=lenptr; \ -- GitLab