17
17
18
18
#define LFEED " \n "
19
19
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
+
20
31
extern " C" {
21
32
using namespace Sass ;
22
33
@@ -103,10 +114,9 @@ extern "C" {
103
114
json_append_member (json_err, " line" , json_mknumber ((double )(e.pstate .line +1 )));
104
115
json_append_member (json_err, " column" , json_mknumber ((double )(e.pstate .column +1 )));
105
116
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));
108
118
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 ());
110
120
c_ctx->error_text = sass_copy_c_string (e.what ());
111
121
c_ctx->error_status = 1 ;
112
122
c_ctx->error_file = sass_copy_c_string (e.pstate .path );
@@ -123,9 +133,9 @@ extern "C" {
123
133
msg_stream << " Unable to allocate memory: " << ba.what () << std::endl;
124
134
json_append_member (json_err, " status" , json_mknumber (2 ));
125
135
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));
127
137
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 ());
129
139
c_ctx->error_text = sass_copy_c_string (ba.what ());
130
140
c_ctx->error_status = 2 ;
131
141
c_ctx->output_string = 0 ;
@@ -138,9 +148,9 @@ extern "C" {
138
148
msg_stream << " Internal Error: " << e.what () << std::endl;
139
149
json_append_member (json_err, " status" , json_mknumber (3 ));
140
150
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));
142
152
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 ());
144
154
c_ctx->error_text = sass_copy_c_string (e.what ());
145
155
c_ctx->error_status = 3 ;
146
156
c_ctx->output_string = 0 ;
@@ -153,9 +163,9 @@ extern "C" {
153
163
msg_stream << " Internal Error: " << e << std::endl;
154
164
json_append_member (json_err, " status" , json_mknumber (4 ));
155
165
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));
157
167
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 ());
159
169
c_ctx->error_text = sass_copy_c_string (e.c_str ());
160
170
c_ctx->error_status = 4 ;
161
171
c_ctx->output_string = 0 ;
@@ -168,9 +178,9 @@ extern "C" {
168
178
msg_stream << " Internal Error: " << e << std::endl;
169
179
json_append_member (json_err, " status" , json_mknumber (4 ));
170
180
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));
172
182
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 ());
174
184
c_ctx->error_text = sass_copy_c_string (e);
175
185
c_ctx->error_status = 4 ;
176
186
c_ctx->output_string = 0 ;
@@ -184,7 +194,7 @@ extern "C" {
184
194
json_append_member (json_err, " status" , json_mknumber (5 ));
185
195
json_append_member (json_err, " message" , json_mkstring (" unknown" ));
186
196
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 ());
188
198
c_ctx->error_text = sass_copy_c_string (" unknown" );
189
199
c_ctx->error_status = 5 ;
190
200
c_ctx->output_string = 0 ;
0 commit comments