sassc 1.7.1 → 1.8.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/ext/libsass/.gitignore +10 -6
  4. data/ext/libsass/.travis.yml +4 -1
  5. data/ext/libsass/GNUmakefile.am +88 -0
  6. data/ext/libsass/Makefile +157 -76
  7. data/ext/libsass/Makefile.conf +47 -0
  8. data/ext/libsass/Readme.md +13 -14
  9. data/ext/libsass/appveyor.yml +25 -41
  10. data/ext/libsass/configure.ac +20 -7
  11. data/ext/libsass/contrib/plugin.cpp +1 -1
  12. data/ext/libsass/include/sass.h +15 -0
  13. data/ext/libsass/{sass.h → include/sass/base.h} +17 -9
  14. data/ext/libsass/{sass_context.h → include/sass/context.h} +3 -1
  15. data/ext/libsass/{sass_functions.h → include/sass/functions.h} +4 -4
  16. data/ext/libsass/{sass_interface.h → include/sass/interface.h} +5 -2
  17. data/ext/libsass/{sass_values.h → include/sass/values.h} +15 -1
  18. data/ext/libsass/{sass_version.h → include/sass/version.h} +0 -0
  19. data/ext/libsass/{sass_version.h.in → include/sass/version.h.in} +0 -0
  20. data/ext/libsass/{sass2scss.h → include/sass2scss.h} +6 -7
  21. data/ext/libsass/m4/m4-ax_cxx_compile_stdcxx_11.m4 +167 -0
  22. data/ext/libsass/script/ci-build-libsass +67 -23
  23. data/ext/libsass/src/GNUmakefile.am +54 -0
  24. data/ext/libsass/src/ast.cpp +2029 -0
  25. data/ext/libsass/{ast.hpp → src/ast.hpp} +832 -660
  26. data/ext/libsass/src/ast_def_macros.hpp +47 -0
  27. data/ext/libsass/src/ast_factory.hpp +93 -0
  28. data/ext/libsass/{ast_fwd_decl.hpp → src/ast_fwd_decl.hpp} +9 -4
  29. data/ext/libsass/{b64 → src/b64}/cencode.h +1 -1
  30. data/ext/libsass/{b64 → src/b64}/encode.h +0 -0
  31. data/ext/libsass/{backtrace.hpp → src/backtrace.hpp} +9 -10
  32. data/ext/libsass/{base64vlq.cpp → src/base64vlq.cpp} +2 -2
  33. data/ext/libsass/{base64vlq.hpp → src/base64vlq.hpp} +1 -2
  34. data/ext/libsass/{bind.cpp → src/bind.cpp} +96 -59
  35. data/ext/libsass/{bind.hpp → src/bind.hpp} +1 -1
  36. data/ext/libsass/src/c99func.c +54 -0
  37. data/ext/libsass/{cencode.c → src/cencode.c} +5 -5
  38. data/ext/libsass/src/color_maps.cpp +643 -0
  39. data/ext/libsass/src/color_maps.hpp +333 -0
  40. data/ext/libsass/{constants.cpp → src/constants.cpp} +10 -1
  41. data/ext/libsass/{constants.hpp → src/constants.hpp} +7 -0
  42. data/ext/libsass/{context.cpp → src/context.cpp} +152 -122
  43. data/ext/libsass/src/context.hpp +150 -0
  44. data/ext/libsass/{cssize.cpp → src/cssize.cpp} +123 -109
  45. data/ext/libsass/{cssize.hpp → src/cssize.hpp} +9 -13
  46. data/ext/libsass/{debug.hpp → src/debug.hpp} +9 -9
  47. data/ext/libsass/src/debugger.hpp +683 -0
  48. data/ext/libsass/{emitter.cpp → src/emitter.cpp} +13 -13
  49. data/ext/libsass/{emitter.hpp → src/emitter.hpp} +10 -11
  50. data/ext/libsass/src/environment.cpp +184 -0
  51. data/ext/libsass/src/environment.hpp +92 -0
  52. data/ext/libsass/src/error_handling.cpp +46 -0
  53. data/ext/libsass/src/error_handling.hpp +34 -0
  54. data/ext/libsass/src/eval.cpp +1462 -0
  55. data/ext/libsass/src/eval.hpp +107 -0
  56. data/ext/libsass/src/expand.cpp +653 -0
  57. data/ext/libsass/{expand.hpp → src/expand.hpp} +17 -16
  58. data/ext/libsass/{extend.cpp → src/extend.cpp} +198 -139
  59. data/ext/libsass/{extend.hpp → src/extend.hpp} +7 -8
  60. data/ext/libsass/{file.cpp → src/file.cpp} +103 -57
  61. data/ext/libsass/{file.hpp → src/file.hpp} +23 -14
  62. data/ext/libsass/{functions.cpp → src/functions.cpp} +642 -333
  63. data/ext/libsass/{functions.hpp → src/functions.hpp} +17 -4
  64. data/ext/libsass/{inspect.cpp → src/inspect.cpp} +147 -260
  65. data/ext/libsass/{inspect.hpp → src/inspect.hpp} +7 -7
  66. data/ext/libsass/{json.cpp → src/json.cpp} +33 -43
  67. data/ext/libsass/{json.hpp → src/json.hpp} +1 -1
  68. data/ext/libsass/{kwd_arg_macros.hpp → src/kwd_arg_macros.hpp} +0 -0
  69. data/ext/libsass/{lexer.cpp → src/lexer.cpp} +28 -0
  70. data/ext/libsass/{lexer.hpp → src/lexer.hpp} +25 -10
  71. data/ext/libsass/{listize.cpp → src/listize.cpp} +17 -13
  72. data/ext/libsass/{listize.hpp → src/listize.hpp} +0 -2
  73. data/ext/libsass/{mapping.hpp → src/mapping.hpp} +0 -0
  74. data/ext/libsass/src/memory_manager.cpp +76 -0
  75. data/ext/libsass/src/memory_manager.hpp +48 -0
  76. data/ext/libsass/{node.cpp → src/node.cpp} +89 -18
  77. data/ext/libsass/{node.hpp → src/node.hpp} +5 -6
  78. data/ext/libsass/{operation.hpp → src/operation.hpp} +18 -12
  79. data/ext/libsass/{output.cpp → src/output.cpp} +47 -55
  80. data/ext/libsass/{output.hpp → src/output.hpp} +5 -4
  81. data/ext/libsass/src/parser.cpp +2529 -0
  82. data/ext/libsass/{parser.hpp → src/parser.hpp} +84 -60
  83. data/ext/libsass/{paths.hpp → src/paths.hpp} +10 -13
  84. data/ext/libsass/{plugins.cpp → src/plugins.cpp} +14 -17
  85. data/ext/libsass/{plugins.hpp → src/plugins.hpp} +10 -11
  86. data/ext/libsass/{position.cpp → src/position.cpp} +5 -6
  87. data/ext/libsass/{position.hpp → src/position.hpp} +19 -22
  88. data/ext/libsass/{prelexer.cpp → src/prelexer.cpp} +401 -53
  89. data/ext/libsass/{prelexer.hpp → src/prelexer.hpp} +50 -10
  90. data/ext/libsass/{remove_placeholders.cpp → src/remove_placeholders.cpp} +12 -16
  91. data/ext/libsass/{remove_placeholders.hpp → src/remove_placeholders.hpp} +1 -7
  92. data/ext/libsass/{sass.cpp → src/sass.cpp} +3 -5
  93. data/ext/libsass/{sass2scss.cpp → src/sass2scss.cpp} +51 -46
  94. data/ext/libsass/{sass_context.cpp → src/sass_context.cpp} +114 -112
  95. data/ext/libsass/{sass_functions.cpp → src/sass_functions.cpp} +11 -18
  96. data/ext/libsass/{sass_interface.cpp → src/sass_interface.cpp} +44 -81
  97. data/ext/libsass/{sass_util.cpp → src/sass_util.cpp} +26 -8
  98. data/ext/libsass/{sass_util.hpp → src/sass_util.hpp} +14 -18
  99. data/ext/libsass/{sass_values.cpp → src/sass_values.cpp} +91 -20
  100. data/ext/libsass/{source_map.cpp → src/source_map.cpp} +13 -13
  101. data/ext/libsass/{source_map.hpp → src/source_map.hpp} +9 -9
  102. data/ext/libsass/{subset_map.hpp → src/subset_map.hpp} +29 -31
  103. data/ext/libsass/{support → src/support}/libsass.pc.in +0 -0
  104. data/ext/libsass/src/to_c.cpp +73 -0
  105. data/ext/libsass/src/to_c.hpp +41 -0
  106. data/ext/libsass/src/to_string.cpp +47 -0
  107. data/ext/libsass/{to_string.hpp → src/to_string.hpp} +9 -7
  108. data/ext/libsass/src/to_value.cpp +109 -0
  109. data/ext/libsass/src/to_value.hpp +50 -0
  110. data/ext/libsass/{units.cpp → src/units.cpp} +56 -51
  111. data/ext/libsass/{units.hpp → src/units.hpp} +8 -9
  112. data/ext/libsass/{utf8.h → src/utf8.h} +0 -0
  113. data/ext/libsass/{utf8 → src/utf8}/checked.h +0 -0
  114. data/ext/libsass/{utf8 → src/utf8}/core.h +12 -12
  115. data/ext/libsass/{utf8 → src/utf8}/unchecked.h +0 -0
  116. data/ext/libsass/{utf8_string.cpp → src/utf8_string.cpp} +0 -0
  117. data/ext/libsass/{utf8_string.hpp → src/utf8_string.hpp} +6 -6
  118. data/ext/libsass/{util.cpp → src/util.cpp} +144 -86
  119. data/ext/libsass/src/util.hpp +59 -0
  120. data/ext/libsass/src/values.cpp +137 -0
  121. data/ext/libsass/src/values.hpp +12 -0
  122. data/ext/libsass/test/test_node.cpp +33 -33
  123. data/ext/libsass/test/test_paths.cpp +5 -6
  124. data/ext/libsass/test/test_selector_difference.cpp +4 -5
  125. data/ext/libsass/test/test_specificity.cpp +4 -5
  126. data/ext/libsass/test/test_subset_map.cpp +91 -91
  127. data/ext/libsass/test/test_superselector.cpp +11 -11
  128. data/ext/libsass/test/test_unification.cpp +4 -4
  129. data/ext/libsass/win/libsass.targets +101 -0
  130. data/ext/libsass/win/libsass.vcxproj +45 -127
  131. data/ext/libsass/win/libsass.vcxproj.filters +303 -0
  132. data/lib/sassc/import_handler.rb +1 -1
  133. data/lib/sassc/native/native_functions_api.rb +3 -3
  134. data/lib/sassc/version.rb +1 -1
  135. data/test/custom_importer_test.rb +1 -4
  136. data/test/functions_test.rb +3 -2
  137. data/test/native_test.rb +4 -3
  138. metadata +117 -110
  139. data/ext/libsass/Makefile.am +0 -146
  140. data/ext/libsass/ast.cpp +0 -945
  141. data/ext/libsass/ast_def_macros.hpp +0 -21
  142. data/ext/libsass/ast_factory.hpp +0 -92
  143. data/ext/libsass/color_names.hpp +0 -327
  144. data/ext/libsass/context.hpp +0 -157
  145. data/ext/libsass/contextualize.cpp +0 -148
  146. data/ext/libsass/contextualize.hpp +0 -46
  147. data/ext/libsass/contextualize_eval.cpp +0 -93
  148. data/ext/libsass/contextualize_eval.hpp +0 -44
  149. data/ext/libsass/debugger.hpp +0 -558
  150. data/ext/libsass/environment.hpp +0 -163
  151. data/ext/libsass/error_handling.cpp +0 -35
  152. data/ext/libsass/error_handling.hpp +0 -32
  153. data/ext/libsass/eval.cpp +0 -1392
  154. data/ext/libsass/eval.hpp +0 -88
  155. data/ext/libsass/expand.cpp +0 -575
  156. data/ext/libsass/memory_manager.hpp +0 -57
  157. data/ext/libsass/parser.cpp +0 -2403
  158. data/ext/libsass/posix/getopt.c +0 -562
  159. data/ext/libsass/posix/getopt.h +0 -95
  160. data/ext/libsass/to_c.cpp +0 -61
  161. data/ext/libsass/to_c.hpp +0 -44
  162. data/ext/libsass/to_string.cpp +0 -34
  163. data/ext/libsass/util.hpp +0 -54
  164. data/ext/libsass/win/libsass.filters +0 -312
@@ -1,24 +1,20 @@
1
- #ifdef _WIN32
2
- #include <io.h>
3
- #define LFEED "\n"
4
- #else
5
- #include <unistd.h>
6
- #define LFEED "\n"
7
- #endif
8
-
9
1
  #include <cstring>
10
2
  #include <stdexcept>
3
+ #include <sstream>
4
+ #include <string>
5
+ #include <vector>
6
+
7
+ #include "sass.h"
11
8
  #include "file.hpp"
12
9
  #include "json.hpp"
13
10
  #include "util.hpp"
14
11
  #include "context.hpp"
15
- #include "sass_values.h"
16
- #include "sass_context.h"
17
12
  #include "ast_fwd_decl.hpp"
18
13
  #include "error_handling.hpp"
19
14
 
15
+ #define LFEED "\n"
16
+
20
17
  extern "C" {
21
- using namespace std;
22
18
  using namespace Sass;
23
19
 
24
20
  // Input behaviours
@@ -183,73 +179,35 @@ extern "C" {
183
179
  type sass_context_take_##option (struct Sass_Context* ctx) \
184
180
  { type foo = ctx->option; ctx->option = 0; return foo; }
185
181
 
186
- // helper for safe access to c_ctx
187
- static const char* safe_str (const char* str) {
188
- return str == NULL ? "" : str;
189
- }
190
-
191
- static void copy_strings(const std::vector<std::string>& strings, char*** array) {
192
- int num = static_cast<int>(strings.size());
193
- char** arr = (char**) malloc(sizeof(char*) * (num + 1));
194
- if (arr == 0) throw(bad_alloc());
195
-
196
- for(int i = 0; i < num; i++) {
197
- arr[i] = (char*) malloc(sizeof(char) * (strings[i].size() + 1));
198
- if (arr[i] == 0) throw(bad_alloc());
199
- std::copy(strings[i].begin(), strings[i].end(), arr[i]);
200
- arr[i][strings[i].size()] = '\0';
201
- }
202
-
203
- arr[num] = 0;
204
- *array = arr;
205
- }
206
-
207
- static void free_string_array(char ** arr) {
208
- if(!arr)
209
- return;
210
-
211
- char **it = arr;
212
- while (it && (*it)) {
213
- free(*it);
214
- ++it;
215
- }
216
-
217
- free(arr);
218
- }
219
-
220
182
  static int handle_errors(Sass_Context* c_ctx) {
221
183
  try {
222
184
  throw;
223
185
  }
224
- catch (Sass_Error& e) {
225
- stringstream msg_stream;
226
- string cwd(Sass::File::get_cwd());
227
- JsonNode* json_err = json_mkobject();
228
- json_append_member(json_err, "status", json_mknumber(1));
229
- json_append_member(json_err, "file", json_mkstring(e.pstate.path.c_str()));
230
- json_append_member(json_err, "line", json_mknumber(e.pstate.line+1));
231
- json_append_member(json_err, "column", json_mknumber(e.pstate.column+1));
232
- json_append_member(json_err, "message", json_mkstring(e.message.c_str()));
233
- string rel_path(Sass::File::resolve_relative_path(e.pstate.path, cwd, cwd));
186
+ catch (Error_Invalid& e) {
187
+ std::stringstream msg_stream;
188
+ std::string cwd(Sass::File::get_cwd());
189
+ std::string rel_path(Sass::File::resolve_relative_path(e.pstate.path, cwd, cwd));
234
190
 
235
- string msg_prefix("Error: ");
191
+ std::string msg_prefix("Error: ");
236
192
  bool got_newline = false;
237
193
  msg_stream << msg_prefix;
238
194
  for (char chr : e.message) {
239
- if (chr == '\n') {
195
+ if (chr == '\r') {
196
+ got_newline = true;
197
+ } else if (chr == '\n') {
240
198
  got_newline = true;
241
199
  } else if (got_newline) {
242
- msg_stream << string(msg_prefix.size(), ' ');
200
+ msg_stream << std::string(msg_prefix.size(), ' ');
243
201
  got_newline = false;
244
202
  }
245
203
  msg_stream << chr;
246
204
  }
247
205
  if (!got_newline) msg_stream << "\n";
248
- msg_stream << string(msg_prefix.size(), ' ');
206
+ msg_stream << std::string(msg_prefix.size(), ' ');
249
207
  msg_stream << " on line " << e.pstate.line+1 << " of " << rel_path << "\n";
250
208
 
251
209
  // now create the code trace (ToDo: maybe have util functions?)
252
- if (e.pstate.line != string::npos && e.pstate.column != string::npos) {
210
+ if (e.pstate.line != std::string::npos && e.pstate.column != std::string::npos) {
253
211
  size_t line = e.pstate.line;
254
212
  const char* line_beg = e.pstate.src;
255
213
  while (line_beg && *line_beg && line) {
@@ -266,15 +224,23 @@ extern "C" {
266
224
  size_t move_in = e.pstate.column > max_left ? e.pstate.column - max_left : 0;
267
225
  size_t shorten = (line_end - line_beg) - move_in > max_right ?
268
226
  (line_end - line_beg) - move_in - max_right : 0;
269
- msg_stream << ">> " << string(line_beg + move_in, line_end - shorten) << "\n";
270
- msg_stream << " " << string(e.pstate.column - move_in, '-') << "^\n";
227
+ msg_stream << ">> " << std::string(line_beg + move_in, line_end - shorten) << "\n";
228
+ msg_stream << " " << std::string(e.pstate.column - move_in, '-') << "^\n";
271
229
  }
272
230
 
231
+ JsonNode* json_err = json_mkobject();
232
+ json_append_member(json_err, "status", json_mknumber(1));
233
+ json_append_member(json_err, "file", json_mkstring(e.pstate.path));
234
+ json_append_member(json_err, "line", json_mknumber((double)(e.pstate.line+1)));
235
+ json_append_member(json_err, "column", json_mknumber((double)(e.pstate.column+1)));
236
+ json_append_member(json_err, "message", json_mkstring(e.message.c_str()));
237
+ json_append_member(json_err, "formatted", json_mkstring(msg_stream.str().c_str()));
238
+
273
239
  c_ctx->error_json = json_stringify(json_err, " ");;
274
240
  c_ctx->error_message = sass_strdup(msg_stream.str().c_str());
275
- c_ctx->error_text = strdup(e.message.c_str());
241
+ c_ctx->error_text = sass_strdup(e.message.c_str());
276
242
  c_ctx->error_status = 1;
277
- c_ctx->error_file = sass_strdup(e.pstate.path.c_str());
243
+ c_ctx->error_file = sass_strdup(e.pstate.path);
278
244
  c_ctx->error_line = e.pstate.line+1;
279
245
  c_ctx->error_column = e.pstate.column+1;
280
246
  c_ctx->error_src = e.pstate.src;
@@ -282,57 +248,71 @@ extern "C" {
282
248
  c_ctx->source_map_string = 0;
283
249
  json_delete(json_err);
284
250
  }
285
- catch(bad_alloc& ba) {
286
- stringstream msg_stream;
251
+ catch (std::bad_alloc& ba) {
252
+ std::stringstream msg_stream;
287
253
  JsonNode* json_err = json_mkobject();
288
- msg_stream << "Unable to allocate memory: " << ba.what() << endl;
254
+ msg_stream << "Unable to allocate memory: " << ba.what() << std::endl;
289
255
  json_append_member(json_err, "status", json_mknumber(2));
290
256
  json_append_member(json_err, "message", json_mkstring(ba.what()));
291
257
  c_ctx->error_json = json_stringify(json_err, " ");;
292
258
  c_ctx->error_message = sass_strdup(msg_stream.str().c_str());
293
- c_ctx->error_text = strdup(ba.what());
259
+ c_ctx->error_text = sass_strdup(ba.what());
294
260
  c_ctx->error_status = 2;
295
261
  c_ctx->output_string = 0;
296
262
  c_ctx->source_map_string = 0;
297
263
  json_delete(json_err);
298
264
  }
299
265
  catch (std::exception& e) {
300
- stringstream msg_stream;
266
+ std::stringstream msg_stream;
301
267
  JsonNode* json_err = json_mkobject();
302
- msg_stream << "Error: " << e.what() << endl;
268
+ msg_stream << "Error: " << e.what() << std::endl;
303
269
  json_append_member(json_err, "status", json_mknumber(3));
304
270
  json_append_member(json_err, "message", json_mkstring(e.what()));
305
271
  c_ctx->error_json = json_stringify(json_err, " ");;
306
272
  c_ctx->error_message = sass_strdup(msg_stream.str().c_str());
307
- c_ctx->error_text = strdup(e.what());
273
+ c_ctx->error_text = sass_strdup(e.what());
308
274
  c_ctx->error_status = 3;
309
275
  c_ctx->output_string = 0;
310
276
  c_ctx->source_map_string = 0;
311
277
  json_delete(json_err);
312
278
  }
313
- catch (string& e) {
314
- stringstream msg_stream;
279
+ catch (std::string& e) {
280
+ std::stringstream msg_stream;
315
281
  JsonNode* json_err = json_mkobject();
316
- msg_stream << "Error: " << e << endl;
282
+ msg_stream << "Error: " << e << std::endl;
317
283
  json_append_member(json_err, "status", json_mknumber(4));
318
284
  json_append_member(json_err, "message", json_mkstring(e.c_str()));
319
285
  c_ctx->error_json = json_stringify(json_err, " ");;
320
286
  c_ctx->error_message = sass_strdup(msg_stream.str().c_str());
321
- c_ctx->error_text = strdup(e.c_str());
287
+ c_ctx->error_text = sass_strdup(e.c_str());
288
+ c_ctx->error_status = 4;
289
+ c_ctx->output_string = 0;
290
+ c_ctx->source_map_string = 0;
291
+ json_delete(json_err);
292
+ }
293
+ catch (const char* e) {
294
+ std::stringstream msg_stream;
295
+ JsonNode* json_err = json_mkobject();
296
+ msg_stream << "Error: " << e << std::endl;
297
+ json_append_member(json_err, "status", json_mknumber(4));
298
+ json_append_member(json_err, "message", json_mkstring(e));
299
+ c_ctx->error_json = json_stringify(json_err, " ");;
300
+ c_ctx->error_message = sass_strdup(msg_stream.str().c_str());
301
+ c_ctx->error_text = sass_strdup(e);
322
302
  c_ctx->error_status = 4;
323
303
  c_ctx->output_string = 0;
324
304
  c_ctx->source_map_string = 0;
325
305
  json_delete(json_err);
326
306
  }
327
307
  catch (...) {
328
- stringstream msg_stream;
308
+ std::stringstream msg_stream;
329
309
  JsonNode* json_err = json_mkobject();
330
- msg_stream << "Unknown error occurred" << endl;
310
+ msg_stream << "Unknown error occurred" << std::endl;
331
311
  json_append_member(json_err, "status", json_mknumber(5));
332
312
  json_append_member(json_err, "message", json_mkstring("unknown"));
333
313
  c_ctx->error_json = json_stringify(json_err, " ");;
334
314
  c_ctx->error_message = sass_strdup(msg_stream.str().c_str());
335
- c_ctx->error_text = strdup("unknown");
315
+ c_ctx->error_text = sass_strdup("unknown");
336
316
  c_ctx->error_status = 5;
337
317
  c_ctx->output_string = 0;
338
318
  c_ctx->source_map_string = 0;
@@ -347,8 +327,8 @@ extern "C" {
347
327
  try {
348
328
 
349
329
  // get input/output path from options
350
- string input_path = safe_str(c_ctx->input_path);
351
- string output_path = safe_str(c_ctx->output_path);
330
+ std::string input_path = safe_str(c_ctx->input_path);
331
+ std::string output_path = safe_str(c_ctx->output_path);
352
332
  // maybe we can extract an output path from input path
353
333
  if (output_path == "" && input_path != "") {
354
334
  int lastindex = static_cast<int>(input_path.find_last_of("."));
@@ -361,7 +341,7 @@ extern "C" {
361
341
  size_t inc_size = 0; while (inc) { inc_size ++; inc = inc->next; }
362
342
  // create char* array to hold all paths plus null terminator
363
343
  const char** include_paths = (const char**) calloc(inc_size + 1, sizeof(char*));
364
- if (include_paths == 0) throw(bad_alloc());
344
+ if (include_paths == 0) throw(std::bad_alloc());
365
345
  // reset iterator
366
346
  inc = c_ctx->include_paths;
367
347
  // copy over the paths
@@ -376,7 +356,7 @@ extern "C" {
376
356
  size_t imp_size = 0; while (imp) { imp_size ++; imp = imp->next; }
377
357
  // create char* array to hold all paths plus null terminator
378
358
  const char** plugin_paths = (const char**) calloc(imp_size + 1, sizeof(char*));
379
- if (plugin_paths == 0) throw(bad_alloc());
359
+ if (plugin_paths == 0) throw(std::bad_alloc());
380
360
  // reset iterator
381
361
  imp = c_ctx->plugin_paths;
382
362
  // copy over the paths
@@ -402,8 +382,8 @@ extern "C" {
402
382
  .plugin_paths_c_str(c_ctx->plugin_path)
403
383
  // .include_paths_array(include_paths)
404
384
  // .plugin_paths_array(plugin_paths)
405
- .include_paths(vector<string>())
406
- .plugin_paths(vector<string>())
385
+ .include_paths(std::vector<std::string>())
386
+ .plugin_paths(std::vector<std::string>())
407
387
  .precision(c_ctx->precision)
408
388
  .linefeed(c_ctx->linefeed)
409
389
  .indent(c_ctx->indent);
@@ -449,8 +429,8 @@ extern "C" {
449
429
  // reset error position
450
430
  c_ctx->error_src = 0;
451
431
  c_ctx->error_file = 0;
452
- c_ctx->error_line = string::npos;
453
- c_ctx->error_column = string::npos;
432
+ c_ctx->error_line = std::string::npos;
433
+ c_ctx->error_column = std::string::npos;
454
434
 
455
435
  // allocate a new compiler instance
456
436
  Sass_Compiler* compiler = (struct Sass_Compiler*) calloc(1, sizeof(struct Sass_Compiler));
@@ -488,29 +468,34 @@ extern "C" {
488
468
  try {
489
469
 
490
470
  // get input/output path from options
491
- string input_path = safe_str(c_ctx->input_path);
492
- string output_path = safe_str(c_ctx->output_path);
471
+ std::string input_path = safe_str(c_ctx->input_path);
472
+ std::string output_path = safe_str(c_ctx->output_path);
493
473
 
494
474
  // parsed root block
495
475
  Block* root = 0;
496
476
 
497
477
  // maybe skip some entries of included files
498
478
  // we do not include stdin for data contexts
499
- size_t skip = 0;
479
+ bool skip = false;
500
480
 
501
481
  // dispatch to the correct render function
502
482
  if (c_ctx->type == SASS_CONTEXT_FILE) {
503
483
  root = cpp_ctx->parse_file();
504
484
  } else if (c_ctx->type == SASS_CONTEXT_DATA) {
505
485
  root = cpp_ctx->parse_string();
506
- skip = 1; // skip first entry of includes
486
+ skip = true; // skip first entry of includes
507
487
  }
508
488
 
509
- // skip all prefixed files?
510
- skip += cpp_ctx->head_imports;
489
+ // skip all prefixed files? (ToDo: check srcmap)
490
+ // IMO source-maps should point to headers already
491
+ // therefore don't skip it for now. re-enable or
492
+ // remove completely once this is tested
493
+ size_t headers = cpp_ctx->head_imports;
511
494
 
512
495
  // copy the included files on to the context (dont forget to free)
513
- if (root) copy_strings(cpp_ctx->get_included_files(skip), &c_ctx->included_files);
496
+ if (root)
497
+ if (copy_strings(cpp_ctx->get_included_files(skip, headers), &c_ctx->included_files) == NULL)
498
+ throw(std::bad_alloc());
514
499
 
515
500
  // return parsed block
516
501
  return root;
@@ -554,7 +539,7 @@ extern "C" {
554
539
  Sass_Options* ADDCALL sass_make_options (void)
555
540
  {
556
541
  struct Sass_Options* options = (struct Sass_Options*) calloc(1, sizeof(struct Sass_Options));
557
- if (options == 0) { cerr << "Error allocating memory for options" << endl; return 0; }
542
+ if (options == 0) { std::cerr << "Error allocating memory for options" << std::endl; return 0; }
558
543
  init_options(options);
559
544
  return options;
560
545
  }
@@ -562,12 +547,12 @@ extern "C" {
562
547
  Sass_File_Context* ADDCALL sass_make_file_context(const char* input_path)
563
548
  {
564
549
  struct Sass_File_Context* ctx = (struct Sass_File_Context*) calloc(1, sizeof(struct Sass_File_Context));
565
- if (ctx == 0) { cerr << "Error allocating memory for file context" << endl; return 0; }
550
+ if (ctx == 0) { std::cerr << "Error allocating memory for file context" << std::endl; return 0; }
566
551
  ctx->type = SASS_CONTEXT_FILE;
567
552
  init_options(ctx);
568
553
  try {
569
- if (input_path == 0) { throw(runtime_error("File context created without an input path")); }
570
- if (*input_path == 0) { throw(runtime_error("File context created with empty input path")); }
554
+ if (input_path == 0) { throw(std::runtime_error("File context created without an input path")); }
555
+ if (*input_path == 0) { throw(std::runtime_error("File context created with empty input path")); }
571
556
  sass_option_set_input_path(ctx, input_path);
572
557
  } catch (...) {
573
558
  handle_errors(ctx);
@@ -578,12 +563,12 @@ extern "C" {
578
563
  Sass_Data_Context* ADDCALL sass_make_data_context(char* source_string)
579
564
  {
580
565
  struct Sass_Data_Context* ctx = (struct Sass_Data_Context*) calloc(1, sizeof(struct Sass_Data_Context));
581
- if (ctx == 0) { cerr << "Error allocating memory for data context" << endl; return 0; }
566
+ if (ctx == 0) { std::cerr << "Error allocating memory for data context" << std::endl; return 0; }
582
567
  ctx->type = SASS_CONTEXT_DATA;
583
568
  init_options(ctx);
584
569
  try {
585
- if (source_string == 0) { throw(runtime_error("Data context created without a source string")); }
586
- if (*source_string == 0) { throw(runtime_error("Data context created with empty source string")); }
570
+ if (source_string == 0) { throw(std::runtime_error("Data context created without a source string")); }
571
+ if (*source_string == 0) { throw(std::runtime_error("Data context created with empty source string")); }
587
572
  ctx->source_string = source_string;
588
573
  } catch (...) {
589
574
  handle_errors(ctx);
@@ -604,6 +589,7 @@ extern "C" {
604
589
  if (c_ctx == 0) return 0;
605
590
  Context::Data cpp_opt = Context::Data();
606
591
  cpp_opt.source_c_str(c_ctx->source_string);
592
+ c_ctx->source_string = 0; // passed away
607
593
  return sass_prepare_context(c_ctx, cpp_opt);
608
594
  }
609
595
 
@@ -615,9 +601,10 @@ extern "C" {
615
601
  return c_ctx->error_status;
616
602
  Context::Data cpp_opt = Context::Data();
617
603
  try {
618
- if (data_ctx->source_string == 0) { throw(runtime_error("Data context has no source string")); }
619
- if (*data_ctx->source_string == 0) { throw(runtime_error("Data context has empty source string")); }
604
+ if (data_ctx->source_string == 0) { throw(std::runtime_error("Data context has no source string")); }
605
+ if (*data_ctx->source_string == 0) { throw(std::runtime_error("Data context has empty source string")); }
620
606
  cpp_opt.source_c_str(data_ctx->source_string);
607
+ data_ctx->source_string = 0; // passed away
621
608
  }
622
609
  catch (...) { return handle_errors(c_ctx) | 1; }
623
610
  return sass_compile_context(c_ctx, cpp_opt);
@@ -631,8 +618,8 @@ extern "C" {
631
618
  return c_ctx->error_status;
632
619
  Context::Data cpp_opt = Context::Data();
633
620
  try {
634
- if (file_ctx->input_path == 0) { throw(runtime_error("File context has no input path")); }
635
- if (*file_ctx->input_path == 0) { throw(runtime_error("File context has empty input path")); }
621
+ if (file_ctx->input_path == 0) { throw(std::runtime_error("File context has no input path")); }
622
+ if (*file_ctx->input_path == 0) { throw(std::runtime_error("File context has empty input path")); }
636
623
  cpp_opt.entry_point(file_ctx->input_path);
637
624
  }
638
625
  catch (...) { return handle_errors(c_ctx) | 1; }
@@ -665,8 +652,8 @@ extern "C" {
665
652
  if (compiler->c_ctx->error_status)
666
653
  return compiler->c_ctx->error_status;
667
654
  compiler->state = SASS_COMPILER_EXECUTED;
668
- Context* cpp_ctx = (Context*) compiler->cpp_ctx;
669
- Block* root = (Block*) compiler->root;
655
+ Context* cpp_ctx = compiler->cpp_ctx;
656
+ Block* root = compiler->root;
670
657
  // compile the parsed root block
671
658
  try { compiler->c_ctx->output_string = cpp_ctx->compile_block(root); }
672
659
  // pass catched errors to generic error handler
@@ -756,6 +743,7 @@ extern "C" {
756
743
  if (ctx->error_file) free(ctx->error_file);
757
744
  if (ctx->input_path) free(ctx->input_path);
758
745
  if (ctx->output_path) free(ctx->output_path);
746
+ if (ctx->plugin_path) free(ctx->plugin_path);
759
747
  if (ctx->include_path) free(ctx->include_path);
760
748
  if (ctx->source_map_file) free(ctx->source_map_file);
761
749
  if (ctx->source_map_root) free(ctx->source_map_root);
@@ -779,16 +767,30 @@ extern "C" {
779
767
 
780
768
  void ADDCALL sass_delete_compiler (struct Sass_Compiler* compiler)
781
769
  {
782
- if (compiler == 0) return;
783
- Context* cpp_ctx = (Context*) compiler->cpp_ctx;
770
+ if (compiler == 0) {
771
+ return;
772
+ }
773
+ Context* cpp_ctx = compiler->cpp_ctx;
774
+ if (cpp_ctx) delete(cpp_ctx);
784
775
  compiler->cpp_ctx = 0;
785
- delete cpp_ctx;
786
776
  free(compiler);
787
777
  }
788
778
 
789
- // Deallocate all associated memory with contexts
790
- void ADDCALL sass_delete_file_context (struct Sass_File_Context* ctx) { sass_clear_context(ctx); free(ctx); }
791
- void ADDCALL sass_delete_data_context (struct Sass_Data_Context* ctx) { sass_clear_context(ctx); free(ctx); }
779
+ // Deallocate all associated memory with file context
780
+ void ADDCALL sass_delete_file_context (struct Sass_File_Context* ctx)
781
+ {
782
+ // clear the context and free it
783
+ sass_clear_context(ctx); free(ctx);
784
+ }
785
+ // Deallocate all associated memory with data context
786
+ void ADDCALL sass_delete_data_context (struct Sass_Data_Context* ctx)
787
+ {
788
+ // clean the source string if it was not passed
789
+ // we reset this member once we start parsing
790
+ if (ctx->source_string) free(ctx->source_string);
791
+ // clear the context and free it
792
+ sass_clear_context(ctx); free(ctx);
793
+ }
792
794
 
793
795
  // Getters for sass context from specific implementations
794
796
  struct Sass_Context* ADDCALL sass_file_context_get_context(struct Sass_File_Context* ctx) { return ctx; }
@@ -1,16 +1,9 @@
1
- #ifdef _WIN32
2
- #include <io.h>
3
- #else
4
- #include <unistd.h>
5
- #endif
6
-
7
1
  #include <cstring>
8
2
  #include "util.hpp"
9
3
  #include "context.hpp"
10
- #include "sass_functions.h"
4
+ #include "sass/functions.h"
11
5
 
12
6
  extern "C" {
13
- using namespace std;
14
7
  using namespace Sass;
15
8
 
16
9
  // Struct to hold custom function callback
@@ -45,8 +38,8 @@ extern "C" {
45
38
 
46
39
  // External import entry
47
40
  struct Sass_Import {
48
- char* path;
49
- char* base;
41
+ char* imp_path; // path as found in the import statement
42
+ char *abs_path; // path after importer has resolved it
50
43
  char* source;
51
44
  char* srcmap;
52
45
  // error handling
@@ -99,12 +92,12 @@ extern "C" {
99
92
 
100
93
  // Creator for a single import entry returned by the custom importer inside the list
101
94
  // We take ownership of the memory for source and srcmap (freed when context is destroyd)
102
- Sass_Import_Entry ADDCALL sass_make_import(const char* path, const char* base, char* source, char* srcmap)
95
+ Sass_Import_Entry ADDCALL sass_make_import(const char* imp_path, const char* abs_path, char* source, char* srcmap)
103
96
  {
104
97
  Sass_Import* v = (Sass_Import*) calloc(1, sizeof(Sass_Import));
105
98
  if (v == 0) return 0;
106
- v->path = path ? sass_strdup(path) : 0;
107
- v->base = base ? sass_strdup(base) : 0;
99
+ v->imp_path = imp_path ? sass_strdup(imp_path) : 0;
100
+ v->abs_path = abs_path ? sass_strdup(abs_path) : 0;
108
101
  v->source = source;
109
102
  v->srcmap = srcmap;
110
103
  v->error = 0;
@@ -124,7 +117,7 @@ extern "C" {
124
117
  {
125
118
  if (import == 0) return 0;
126
119
  if (import->error) free(import->error);
127
- import->error = error ? strdup(error) : 0;
120
+ import->error = error ? sass_strdup(error) : 0;
128
121
  import->line = line ? line : -1;
129
122
  import->column = col ? col : -1;
130
123
  return import;
@@ -149,8 +142,8 @@ extern "C" {
149
142
  // Just in case we have some stray import structs
150
143
  void ADDCALL sass_delete_import(Sass_Import_Entry import)
151
144
  {
152
- free(import->path);
153
- free(import->base);
145
+ free(import->imp_path);
146
+ free(import->abs_path);
154
147
  free(import->source);
155
148
  free(import->srcmap);
156
149
  free(import->error);
@@ -158,8 +151,8 @@ extern "C" {
158
151
  }
159
152
 
160
153
  // Getter for import entry
161
- const char* ADDCALL sass_import_get_path(Sass_Import_Entry entry) { return entry->path; }
162
- const char* ADDCALL sass_import_get_base(Sass_Import_Entry entry) { return entry->base; }
154
+ const char* ADDCALL sass_import_get_imp_path(Sass_Import_Entry entry) { return entry->imp_path; }
155
+ const char* ADDCALL sass_import_get_abs_path(Sass_Import_Entry entry) { return entry->abs_path; }
163
156
  const char* ADDCALL sass_import_get_source(Sass_Import_Entry entry) { return entry->source; }
164
157
  const char* ADDCALL sass_import_get_srcmap(Sass_Import_Entry entry) { return entry->srcmap; }
165
158