Skip to content

Commit

Permalink
Fix sass_option_push_include_path / sass_option_push_plugin_path that…
Browse files Browse the repository at this point in the history
… were not working
  • Loading branch information
xoofx committed Apr 8, 2016
1 parent 140959c commit bf471e2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 53 deletions.
25 changes: 12 additions & 13 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ namespace Sass {

// collect more paths from different options
collect_include_paths(c_options.include_path);
// collect_include_paths(c_options.include_paths);
collect_include_paths(c_options.include_paths);
collect_plugin_paths(c_options.plugin_path);
// collect_plugin_paths(c_options.plugin_paths);
collect_plugin_paths(c_options.plugin_paths);

// load plugins and register custom behaviors
for(auto plug : plugin_paths) plugins.load_plugins(plug);
Expand Down Expand Up @@ -162,7 +162,6 @@ namespace Sass {

void Context::collect_include_paths(const char* paths_str)
{

if (paths_str) {
const char* beg = paths_str;
const char* end = Prelexer::find_first<PATH_SEP>(beg);
Expand All @@ -185,17 +184,17 @@ namespace Sass {
}
}

void Context::collect_include_paths(const char** paths_array)
void Context::collect_include_paths(string_list* paths_array)
{
if (!paths_array) return;
for (size_t i = 0; paths_array[i]; i++) {
collect_include_paths(paths_array[i]);
while (paths_array)
{
collect_include_paths(paths_array->string);
paths_array = paths_array->next;
}
}

void Context::collect_plugin_paths(const char* paths_str)
{

if (paths_str) {
const char* beg = paths_str;
const char* end = Prelexer::find_first<PATH_SEP>(beg);
Expand All @@ -218,15 +217,15 @@ namespace Sass {
}
}

void Context::collect_plugin_paths(const char** paths_array)
void Context::collect_plugin_paths(string_list* paths_array)
{
if (!paths_array) return;
for (size_t i = 0; paths_array[i]; i++) {
collect_plugin_paths(paths_array[i]);
while (paths_array)
{
collect_plugin_paths(paths_array->string);
paths_array = paths_array->next;
}
}


// resolve the imp_path in base_path or include_paths
// looks for alternatives and returns a list from one directory
std::vector<Include> Context::find_includes(const Importer& import)
Expand Down
4 changes: 2 additions & 2 deletions src/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ namespace Sass {

private:
void collect_plugin_paths(const char* paths_str);
void collect_plugin_paths(const char** paths_array);
void collect_plugin_paths(string_list* paths_array);
void collect_include_paths(const char* paths_str);
void collect_include_paths(const char** paths_array);
void collect_include_paths(string_list* paths_array);
std::string format_embedded_source_map();
std::string format_source_mapping_url(const std::string& out_path);

Expand Down
38 changes: 0 additions & 38 deletions src/sass_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,44 +198,6 @@ extern "C" {
static Sass_Compiler* sass_prepare_context (Sass_Context* c_ctx, Context* cpp_ctx) throw()
{
try {

// convert include path linked list to static array
struct string_list* inc = c_ctx->include_paths;
// very poor loop to get the length of the linked list
size_t inc_size = 0; while (inc) { inc_size ++; inc = inc->next; }
// create char* array to hold all paths plus null terminator
const char** include_paths = (const char**) calloc(inc_size + 1, sizeof(char*));
if (include_paths == 0) throw(std::bad_alloc());
// reset iterator
inc = c_ctx->include_paths;
// copy over the paths
for (size_t i = 0; inc; i++) {
include_paths[i] = inc->string;
inc = inc->next;
}

// convert plugin path linked list to static array
struct string_list* imp = c_ctx->plugin_paths;
// very poor loop to get the length of the linked list
size_t imp_size = 0; while (imp) { imp_size ++; imp = imp->next; }
// create char* array to hold all paths plus null terminator
const char** plugin_paths = (const char**) calloc(imp_size + 1, sizeof(char*));
if (plugin_paths == 0) {
free(include_paths); //free include_paths before throw
throw(std::bad_alloc());
}
// reset iterator
imp = c_ctx->plugin_paths;
// copy over the paths
for (size_t i = 0; imp; i++) {
plugin_paths[i] = imp->string;
imp = imp->next;
}

// free intermediate data
free(include_paths);
free(plugin_paths);

// register our custom functions
if (c_ctx->c_functions) {
auto this_func_data = c_ctx->c_functions;
Expand Down

0 comments on commit bf471e2

Please sign in to comment.