Skip to content

Commit

Permalink
Fix bug in C-API with context compiler status
Browse files Browse the repository at this point in the history
Fixes sass#1035
  • Loading branch information
mgreter committed Apr 2, 2015
1 parent fd7f20f commit 0ca5a03
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions sass_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ extern "C" {
}

// generic compilation function (not exported, use file/data compile instead)
static Context* sass_prepare_context (Sass_Context* c_ctx, Context::Data cpp_opt) throw()
static Context* sass_prepare_context (Sass_Compiler* compiler, Sass_Context* c_ctx, Context::Data cpp_opt) throw()
{
try {

Expand Down Expand Up @@ -452,6 +452,10 @@ extern "C" {
c_ctx->error_line = string::npos;
c_ctx->error_column = string::npos;

// store in sass compiler
compiler->cpp_ctx = cpp_ctx;
cpp_ctx->c_compiler = compiler;

// use to parse block
return cpp_ctx;

Expand All @@ -464,8 +468,17 @@ extern "C" {

}

static Block* sass_parse_block (Sass_Context* c_ctx, Context* cpp_ctx) throw()
static Block* sass_parse_block (Sass_Compiler* compiler) throw()
{

// assert valid pointer
if (compiler == 0) return 0;
// The cpp context must be set by now
Context* cpp_ctx = compiler->cpp_ctx;
Sass_Context* c_ctx = compiler->c_ctx;
// We will take care to wire up the rest
compiler->cpp_ctx->c_compiler = compiler;

try {

// get input/output path from options
Expand Down Expand Up @@ -509,11 +522,14 @@ extern "C" {
static int sass_compile_context (Sass_Context* c_ctx, Context::Data cpp_opt)
{

// create an interim sass compiler instance
struct Sass_Compiler* compiler = (struct Sass_Compiler*) calloc(1, sizeof(struct Sass_Compiler));

// first prepare the c++ context
Context* cpp_ctx = sass_prepare_context(c_ctx, cpp_opt);
Context* cpp_ctx = sass_prepare_context(compiler, c_ctx, cpp_opt);

// parse given context and return root block
Block* root = cpp_ctx ? sass_parse_block(c_ctx, cpp_ctx) : 0;
Block* root = cpp_ctx ? sass_parse_block(compiler) : 0;

if (cpp_ctx && root) {

Expand All @@ -531,7 +547,7 @@ extern "C" {

}

delete cpp_ctx;
sass_delete_compiler(compiler);

return c_ctx->error_status;
}
Expand Down Expand Up @@ -592,8 +608,7 @@ extern "C" {
compiler->c_ctx = c_ctx;
Context::Data cpp_opt = Context::Data();
cpp_opt.entry_point(c_ctx->input_path);
compiler->cpp_ctx = sass_prepare_context(c_ctx, cpp_opt);
compiler->cpp_ctx->c_compiler = compiler;
sass_prepare_context(compiler, c_ctx, cpp_opt);
return compiler;
}

Expand All @@ -606,8 +621,7 @@ extern "C" {
compiler->c_ctx = c_ctx;
Context::Data cpp_opt = Context::Data();
cpp_opt.source_c_str(c_ctx->source_string);
compiler->cpp_ctx = sass_prepare_context(c_ctx, cpp_opt);
compiler->cpp_ctx->c_compiler = compiler;
sass_prepare_context(compiler, c_ctx, cpp_opt);
return compiler;
}

Expand Down Expand Up @@ -653,9 +667,8 @@ extern "C" {
if (compiler->c_ctx->error_status)
return compiler->c_ctx->error_status;
compiler->state = SASS_COMPILER_PARSED;
Context* cpp_ctx = (Context*) compiler->cpp_ctx;
// parse the context we have set up (file or data)
compiler->root = sass_parse_block(compiler->c_ctx, cpp_ctx);
compiler->root = sass_parse_block(compiler);
// success
return 0;
}
Expand Down

0 comments on commit 0ca5a03

Please sign in to comment.