Skip to content

Commit a202095

Browse files
committed
more libsass 4 fixes
1 parent d6565ed commit a202095

File tree

1 file changed

+108
-84
lines changed

1 file changed

+108
-84
lines changed

_sass.c

Lines changed: 108 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -405,23 +405,18 @@ static struct SassValue* _call_py_f(
405405

406406

407407
static void _add_custom_functions(
408-
struct Sass_Options* options, PyObject* custom_functions
408+
struct SassCompiler* compiler, PyObject* custom_functions
409409
) {
410-
Py_ssize_t i;
411-
Sass_Function_List fn_list = sass_make_function_list(
412-
PyList_Size(custom_functions)
413-
);
414-
for (i = 0; i < PyList_Size(custom_functions); i += 1) {
410+
for (Py_ssize_t i = 0; i < PyList_Size(custom_functions); i += 1) {
415411
PyObject* sass_function = PyList_GetItem(custom_functions, i);
416412
PyObject* signature = PySass_Object_Bytes(sass_function);
417413
Sass_Function_Entry fn = sass_make_function(
418414
PyBytes_AsString(signature),
419415
_call_py_f,
420416
sass_function
421417
);
422-
sass_function_set_list_entry(fn_list, i, fn);
418+
sass_compiler_add_custom_function(compiler, fn);
423419
}
424-
sass_option_set_c_functions(options, fn_list);
425420
}
426421

427422
static struct SassImportList* _call_py_importer_f(
@@ -430,7 +425,7 @@ static struct SassImportList* _call_py_importer_f(
430425
PyObject* pyfunc = (PyObject*)sass_importer_get_cookie(cb);
431426
PyObject* py_result = NULL;
432427
struct SassImportList* sass_imports = NULL;
433-
struct Sass_Import* previous;
428+
struct SassImport* previous;
434429
const char* prev_path;
435430
Py_ssize_t i;
436431

@@ -450,8 +445,9 @@ static struct SassImportList* _call_py_importer_f(
450445

451446
/* Otherwise, we know our importer is well formed (because we wrap it)
452447
* The return value will be a tuple of 1, 2, or 3 tuples */
453-
sass_imports = sass_make_import_list(PyTuple_Size(py_result));
448+
sass_imports = sass_make_import_list();
454449
for (i = 0; i < PyTuple_Size(py_result); i += 1) {
450+
struct SassImport* import = NULL;
455451
char* path_str = NULL; /* XXX: Memory leak? */
456452
char* source_str = NULL;
457453
char* sourcemap_str = NULL;
@@ -477,9 +473,9 @@ static struct SassImportList* _call_py_importer_f(
477473
if (source_str) source_str = sass_copy_c_string(source_str);
478474
if (sourcemap_str) sourcemap_str = sass_copy_c_string(sourcemap_str);
479475

480-
sass_imports[i] = sass_make_import_entry(
481-
path_str, source_str, sourcemap_str
482-
);
476+
/* XXX: is this correct? source_map_str is gone? */
477+
import = sass_make_content_import(source_str, path_str);
478+
sass_import_list_push(sass_imports, import);
483479
}
484480

485481
done:
@@ -493,40 +489,36 @@ static struct SassImportList* _call_py_importer_f(
493489
}
494490

495491
static void _add_custom_importers(
496-
struct Sass_Options* options, PyObject* custom_importers
492+
struct SassCompiler* compiler, PyObject* custom_importers
497493
) {
498-
Py_ssize_t i;
499-
Sass_Importer_List importer_list;
500-
501494
if (custom_importers == Py_None) {
502495
return;
503496
}
504497

505-
importer_list = sass_make_importer_list(PyTuple_Size(custom_importers));
506-
507-
for (i = 0; i < PyTuple_Size(custom_importers); i += 1) {
498+
for (Py_ssize_t i = 0; i < PyTuple_Size(custom_importers); i += 1) {
499+
struct SassImporter* importer;
508500
PyObject* item = PyTuple_GetItem(custom_importers, i);
509501
int priority = 0;
510502
PyObject* import_function = NULL;
511503

512504
PyArg_ParseTuple(item, "iO", &priority, &import_function);
513505

514-
importer_list[i] = sass_make_importer(
506+
importer = sass_make_importer(
515507
_call_py_importer_f, priority, import_function
516508
);
509+
sass_compiler_add_custom_importer(compiler, importer);
517510
}
518-
519-
sass_option_set_c_importers(options, importer_list);
520511
}
521512

522513
static PyObject *
523514
PySass_compile_string(PyObject *self, PyObject *args) {
524-
struct Sass_Context *ctx;
525-
struct Sass_Data_Context *context;
526-
struct Sass_Options *options;
515+
struct SassCompiler* compiler;
516+
struct SassImport* entry;
517+
const struct SassError* error;
527518
char *string, *include_paths;
528519
const char *error_message, *output_string;
529-
enum Sass_Output_Style output_style;
520+
enum SassSrcMapMode srcmap_mode;
521+
enum SassOutputStyle output_style;
530522
int source_comments, error_status, precision, indented,
531523
source_map_embed, source_map_contents,
532524
omit_source_map_url;
@@ -545,48 +537,67 @@ PySass_compile_string(PyObject *self, PyObject *args) {
545537
return NULL;
546538
}
547539

548-
context = sass_make_data_context(sass_copy_c_string(string));
549-
options = sass_data_context_get_options(context);
550-
sass_option_set_output_style(options, output_style);
551-
sass_option_set_source_comments(options, source_comments);
552-
sass_option_set_include_path(options, include_paths);
553-
sass_option_set_precision(options, precision);
554-
sass_option_set_is_indented_syntax_src(options, indented);
555-
sass_option_set_source_map_contents(options, source_map_contents);
556-
sass_option_set_source_map_embed(options, source_map_embed);
557-
sass_option_set_omit_source_map_url(options, omit_source_map_url);
540+
compiler = sass_make_compiler();
541+
sass_compiler_set_output_style(compiler, output_style);
542+
sass_compiler_set_source_comments(compiler, source_comments);
543+
sass_compiler_add_include_paths(compiler, include_paths);
544+
sass_compiler_set_precision(compiler, precision);
545+
/* XXX: this is probably wrong */
546+
srcmap_mode = SASS_SRCMAP_NONE;
547+
if (source_map_contents) {
548+
srcmap_mode = SASS_SRCMAP_EMBED_LINK;
549+
}
550+
if (source_map_embed) {
551+
srcmap_mode = SASS_SRCMAP_EMBED_JSON;
552+
}
553+
if (srcmap_mode != SASS_SRCMAP_NONE) {
554+
sass_compiler_set_srcmap_embed_contents(compiler, !omit_source_map_url);
555+
}
556+
sass_compiler_set_srcmap_mode(compiler, srcmap_mode);
558557

559558
if (PyBytes_Check(source_map_root) && PyBytes_Size(source_map_root)) {
560-
sass_option_set_source_map_root(
561-
options, PyBytes_AsString(source_map_root)
559+
sass_compiler_set_srcmap_root(
560+
compiler, PyBytes_AsString(source_map_root)
562561
);
563562
}
564563

565-
_add_custom_functions(options, custom_functions);
566-
_add_custom_importers(options, custom_importers);
567-
sass_compile_data_context(context);
564+
_add_custom_functions(compiler, custom_functions);
565+
_add_custom_importers(compiler, custom_importers);
566+
567+
entry = sass_make_content_import(sass_copy_c_string(string), NULL);
568+
if (indented) {
569+
sass_import_set_format(entry, SASS_IMPORT_SASS);
570+
} else {
571+
sass_import_set_format(entry, SASS_IMPORT_SCSS);
572+
}
573+
sass_compiler_set_entry_point(compiler, entry);
574+
sass_delete_import(entry);
575+
576+
sass_compiler_parse(compiler);
577+
sass_compiler_compile(compiler);
578+
sass_compiler_render(compiler);
568579

569-
ctx = sass_data_context_get_context(context);
570-
error_status = sass_context_get_error_status(ctx);
571-
error_message = sass_context_get_error_message(ctx);
572-
output_string = sass_context_get_output_string(ctx);
580+
error = sass_compiler_get_error(compiler);
581+
error_status = sass_error_get_status(error);
582+
output_string = sass_compiler_get_output_string(compiler);
573583
result = Py_BuildValue(
574584
PySass_IF_PY3("hy", "hs"),
575585
(short int) !error_status,
576-
error_status ? error_message : output_string
586+
error_status ? sass_error_get_formatted(error) : output_string
577587
);
578-
sass_delete_data_context(context);
588+
sass_delete_compiler(compiler);
579589
return result;
580590
}
581591

582592
static PyObject *
583593
PySass_compile_filename(PyObject *self, PyObject *args) {
584-
struct Sass_Context *ctx;
585-
struct Sass_File_Context *context;
586-
struct Sass_Options *options;
594+
struct SassCompiler* compiler;
595+
struct SassImport* entry;
596+
const struct SassError* error;
587597
char *filename, *include_paths;
588-
const char *error_message, *output_string, *source_map_string;
589-
enum Sass_Output_Style output_style;
598+
const char *output_string, *source_map_string;
599+
enum SassSrcMapMode srcmap_mode;
600+
enum SassOutputStyle output_style;
590601
int source_comments, error_status, precision, source_map_embed,
591602
source_map_contents, omit_source_map_url;
592603
PyObject *source_map_filename, *custom_functions, *custom_importers,
@@ -603,53 +614,66 @@ PySass_compile_filename(PyObject *self, PyObject *args) {
603614
return NULL;
604615
}
605616

606-
context = sass_make_file_context(filename);
607-
options = sass_file_context_get_options(context);
617+
compiler = sass_make_compiler();
608618

609-
if (PyBytes_Check(source_map_filename)) {
610-
if (PyBytes_Size(source_map_filename)) {
611-
sass_option_set_source_map_file(
612-
options, PyBytes_AsString(source_map_filename)
613-
);
614-
}
615-
}
616619
if (PyBytes_Check(output_filename_hint)) {
617620
if (PyBytes_Size(output_filename_hint)) {
618-
sass_option_set_output_path(
619-
options, PyBytes_AsString(output_filename_hint)
621+
sass_compiler_set_output_path(
622+
compiler, PyBytes_AsString(output_filename_hint)
620623
);
621624
}
622625
}
623626

624627
if (PyBytes_Check(source_map_root) && PyBytes_Size(source_map_root)) {
625-
sass_option_set_source_map_root(
626-
options, PyBytes_AsString(source_map_root)
628+
sass_compiler_set_srcmap_root(
629+
compiler, PyBytes_AsString(source_map_root)
627630
);
628631
}
629632

630-
sass_option_set_output_style(options, output_style);
631-
sass_option_set_source_comments(options, source_comments);
632-
sass_option_set_include_path(options, include_paths);
633-
sass_option_set_precision(options, precision);
634-
sass_option_set_source_map_contents(options, source_map_contents);
635-
sass_option_set_source_map_embed(options, source_map_embed);
636-
sass_option_set_omit_source_map_url(options, omit_source_map_url);
637-
_add_custom_functions(options, custom_functions);
638-
_add_custom_importers(options, custom_importers);
639-
sass_compile_file_context(context);
640-
641-
ctx = sass_file_context_get_context(context);
642-
error_status = sass_context_get_error_status(ctx);
643-
error_message = sass_context_get_error_message(ctx);
644-
output_string = sass_context_get_output_string(ctx);
645-
source_map_string = sass_context_get_source_map_string(ctx);
633+
sass_compiler_set_output_style(compiler, output_style);
634+
sass_compiler_set_source_comments(compiler, source_comments);
635+
sass_compiler_add_include_paths(compiler, include_paths);
636+
sass_compiler_set_precision(compiler, precision);
637+
/* XXX: this is probably wrong */
638+
srcmap_mode = SASS_SRCMAP_NONE;
639+
if (PyBytes_Check(source_map_filename) && PyBytes_Size(source_map_filename)) {
640+
srcmap_mode = SASS_SRCMAP_EMBED_LINK;
641+
sass_compiler_set_srcmap_path(
642+
compiler, PyBytes_AsString(source_map_filename)
643+
);
644+
}
645+
if (source_map_contents) {
646+
srcmap_mode = SASS_SRCMAP_EMBED_LINK;
647+
}
648+
if (source_map_embed) {
649+
srcmap_mode = SASS_SRCMAP_EMBED_JSON;
650+
}
651+
if (srcmap_mode != SASS_SRCMAP_NONE) {
652+
sass_compiler_set_srcmap_embed_contents(compiler, !omit_source_map_url);
653+
}
654+
sass_compiler_set_srcmap_mode(compiler, srcmap_mode);
655+
_add_custom_functions(compiler, custom_functions);
656+
_add_custom_importers(compiler, custom_importers);
657+
658+
entry = sass_make_file_import(sass_copy_c_string(filename));
659+
sass_compiler_set_entry_point(compiler, entry);
660+
sass_delete_import(entry);
661+
662+
sass_compiler_parse(compiler);
663+
sass_compiler_compile(compiler);
664+
sass_compiler_render(compiler);
665+
666+
error = sass_compiler_get_error(compiler);
667+
error_status = sass_error_get_status(error);
668+
output_string = sass_compiler_get_output_string(compiler);
669+
source_map_string = sass_compiler_get_srcmap_string(compiler);
646670
result = Py_BuildValue(
647671
PySass_IF_PY3("hyy", "hss"),
648672
(short int) !error_status,
649-
error_status ? error_message : output_string,
673+
error_status ? sass_error_get_formatted(error) : output_string,
650674
error_status || source_map_string == NULL ? "" : source_map_string
651675
);
652-
sass_delete_file_context(context);
676+
sass_delete_compiler(compiler);
653677
return result;
654678
}
655679

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy