1717
1818#define LFEED " \n "
1919
20+ // C++ helper
21+ namespace Sass {
22+ // see sass_copy_c_string(std::string str)
23+ static inline JsonNode* json_mkstream (const std::stringstream& stream)
24+ {
25+ // hold on to string on stack!
26+ std::string str (stream.str ());
27+ return json_mkstring (str.c_str ());
28+ }
29+ }
30+
2031extern " C" {
2132 using namespace Sass ;
2233
@@ -103,10 +114,9 @@ extern "C" {
103114 json_append_member (json_err, " line" , json_mknumber ((double )(e.pstate .line +1 )));
104115 json_append_member (json_err, " column" , json_mknumber ((double )(e.pstate .column +1 )));
105116 json_append_member (json_err, " message" , json_mkstring (e.what ()));
106- json_append_member (json_err, " formatted" , json_mkstring (msg_stream.str ().c_str ()));
107-
117+ json_append_member (json_err, " formatted" , json_mkstream (msg_stream));
108118 try { c_ctx->error_json = json_stringify (json_err, " " ); } catch (...) {}
109- c_ctx->error_message = sass_copy_c_string (msg_stream.str (). c_str ());
119+ c_ctx->error_message = sass_copy_string (msg_stream.str ());
110120 c_ctx->error_text = sass_copy_c_string (e.what ());
111121 c_ctx->error_status = 1 ;
112122 c_ctx->error_file = sass_copy_c_string (e.pstate .path );
@@ -123,9 +133,9 @@ extern "C" {
123133 msg_stream << " Unable to allocate memory: " << ba.what () << std::endl;
124134 json_append_member (json_err, " status" , json_mknumber (2 ));
125135 json_append_member (json_err, " message" , json_mkstring (ba.what ()));
126- json_append_member (json_err, " formatted" , json_mkstring (msg_stream. str (). c_str () ));
136+ json_append_member (json_err, " formatted" , json_mkstream (msg_stream));
127137 try { c_ctx->error_json = json_stringify (json_err, " " ); } catch (...) {}
128- c_ctx->error_message = sass_copy_c_string (msg_stream.str (). c_str ());
138+ c_ctx->error_message = sass_copy_string (msg_stream.str ());
129139 c_ctx->error_text = sass_copy_c_string (ba.what ());
130140 c_ctx->error_status = 2 ;
131141 c_ctx->output_string = 0 ;
@@ -138,9 +148,9 @@ extern "C" {
138148 msg_stream << " Internal Error: " << e.what () << std::endl;
139149 json_append_member (json_err, " status" , json_mknumber (3 ));
140150 json_append_member (json_err, " message" , json_mkstring (e.what ()));
141- json_append_member (json_err, " formatted" , json_mkstring (msg_stream. str (). c_str () ));
151+ json_append_member (json_err, " formatted" , json_mkstream (msg_stream));
142152 try { c_ctx->error_json = json_stringify (json_err, " " ); } catch (...) {}
143- c_ctx->error_message = sass_copy_c_string (msg_stream.str (). c_str ());
153+ c_ctx->error_message = sass_copy_string (msg_stream.str ());
144154 c_ctx->error_text = sass_copy_c_string (e.what ());
145155 c_ctx->error_status = 3 ;
146156 c_ctx->output_string = 0 ;
@@ -153,9 +163,9 @@ extern "C" {
153163 msg_stream << " Internal Error: " << e << std::endl;
154164 json_append_member (json_err, " status" , json_mknumber (4 ));
155165 json_append_member (json_err, " message" , json_mkstring (e.c_str ()));
156- json_append_member (json_err, " formatted" , json_mkstring (msg_stream. str (). c_str () ));
166+ json_append_member (json_err, " formatted" , json_mkstream (msg_stream));
157167 try { c_ctx->error_json = json_stringify (json_err, " " ); } catch (...) {}
158- c_ctx->error_message = sass_copy_c_string (msg_stream.str (). c_str ());
168+ c_ctx->error_message = sass_copy_string (msg_stream.str ());
159169 c_ctx->error_text = sass_copy_c_string (e.c_str ());
160170 c_ctx->error_status = 4 ;
161171 c_ctx->output_string = 0 ;
@@ -168,9 +178,9 @@ extern "C" {
168178 msg_stream << " Internal Error: " << e << std::endl;
169179 json_append_member (json_err, " status" , json_mknumber (4 ));
170180 json_append_member (json_err, " message" , json_mkstring (e));
171- json_append_member (json_err, " formatted" , json_mkstring (msg_stream. str (). c_str () ));
181+ json_append_member (json_err, " formatted" , json_mkstream (msg_stream));
172182 try { c_ctx->error_json = json_stringify (json_err, " " ); } catch (...) {}
173- c_ctx->error_message = sass_copy_c_string (msg_stream.str (). c_str ());
183+ c_ctx->error_message = sass_copy_string (msg_stream.str ());
174184 c_ctx->error_text = sass_copy_c_string (e);
175185 c_ctx->error_status = 4 ;
176186 c_ctx->output_string = 0 ;
@@ -184,7 +194,7 @@ extern "C" {
184194 json_append_member (json_err, " status" , json_mknumber (5 ));
185195 json_append_member (json_err, " message" , json_mkstring (" unknown" ));
186196 try { c_ctx->error_json = json_stringify (json_err, " " ); } catch (...) {}
187- c_ctx->error_message = sass_copy_c_string (msg_stream.str (). c_str ());
197+ c_ctx->error_message = sass_copy_string (msg_stream.str ());
188198 c_ctx->error_text = sass_copy_c_string (" unknown" );
189199 c_ctx->error_status = 5 ;
190200 c_ctx->output_string = 0 ;
0 commit comments