Skip to content

Commit d280078

Browse files
committed
Fixing GC-related issue
1 parent 59a9e92 commit d280078

File tree

4 files changed

+30
-34
lines changed

4 files changed

+30
-34
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
sassc (0.1.3)
4+
sassc (0.1.5)
55
ffi
66
rake-compiler
77

lib/sassc/lib/context.rb

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Context < FFI::Struct
1010
# char* output_string;
1111
# char* source_map_string;
1212
# const char* source_map_file;
13+
# bool omit_source_map_url;
1314
# struct sass_options options;
1415
# int error_status;
1516
# char* error_message;
@@ -19,33 +20,20 @@ class Context < FFI::Struct
1920
# int num_included_files;
2021
# };
2122

22-
23-
24-
# struct sass_context {
25-
# const char* source_string;
26-
# char* output_string;
27-
# struct sass_options options;
28-
# int error_status;
29-
# char* error_message;
30-
# struct Sass_C_Function_Data* c_functions;
31-
# int num_c_functions;
32-
# char** included_files;
33-
# int num_included_files;
34-
# };
35-
36-
layout :input_path, :pointer,
37-
:output_path, :pointer,
38-
:source_string, :pointer,
39-
:output_string, :pointer,
40-
:source_map_string, :pointer,
41-
:source_map_file, :pointer,
42-
:options, SassOptions,
43-
:error_status, :int32,
44-
:error_message, :pointer,
45-
:c_functions, :pointer,
46-
:num_c_functions, :int32,
47-
:included_files, :pointer,
48-
:num_included_files, :int32
23+
layout :input_path, :pointer,
24+
:output_path, :pointer,
25+
:source_string, :pointer,
26+
:output_string, :pointer,
27+
:source_map_string, :pointer,
28+
:source_map_file, :pointer,
29+
:omit_source_map_url, :bool,
30+
:options, SassOptions,
31+
:error_status, :int32,
32+
:error_message, :pointer,
33+
:c_functions, :pointer,
34+
:num_c_functions, :int32,
35+
:included_files, :pointer,
36+
:num_included_files, :int32
4937

5038

5139
# Creates SASSC context using the input string and options provided.
@@ -68,20 +56,27 @@ def self.create(input_string, sass_options = {})
6856
# The functions are supposed to be Ruby blocks, received 1 argument and returning 1 result.
6957
#
7058
def set_custom_functions(input_funcs)
71-
funcs_ptr = FFI::MemoryPointer.new(SassC::Lib::SassCFunctionDescriptor, input_funcs.count + 1)
59+
@funcs_ptr = FFI::MemoryPointer.new(SassC::Lib::SassCFunctionDescriptor, input_funcs.count)
60+
@gc_staph = []
7261

7362
input_funcs.each.with_index do |(signature, block), i|
74-
fn = SassC::Lib::SassCFunctionDescriptor.new(funcs_ptr + i * SassC::Lib::SassCFunctionDescriptor.size)
63+
fn = SassC::Lib::SassCFunctionDescriptor.new(@funcs_ptr + i * SassC::Lib::SassCFunctionDescriptor.size)
7564

76-
fn[:signature] = FFI::MemoryPointer.from_string(signature)
77-
fn[:function] = FFI::Function.new(SassC::Lib::SassValue.by_value, [SassC::Lib::SassValue.by_value, :pointer]) do |arg, cookie|
65+
str = FFI::MemoryPointer.from_string(signature)
66+
fn[:signature] = str
67+
68+
func = FFI::Function.new(SassC::Lib::SassValue.by_value, [SassC::Lib::SassValue.by_value, :pointer]) do |arg, cookie|
7869
ruby_arg = arg.to_ruby
7970
ruby_result = block.call(ruby_arg)
8071
SassC::Lib::SassValue.new.from_ruby(ruby_result)
8172
end
73+
fn[:function] = func
74+
75+
@gc_staph << func
76+
@gc_staph << str
8277
end
8378

84-
self[:c_functions] = funcs_ptr
79+
self[:c_functions] = @funcs_ptr
8580
self[:num_c_functions] = input_funcs.size
8681
end
8782

lib/sassc/lib/sass_c_function_descriptor.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class SassCFunctionDescriptor < FFI::Struct
44
# struct Sass_C_Function_Descriptor {
55
# const char* signature;
66
# Sass_C_Function function;
7+
# void *cookie;
78
# };
89

910
layout :signature, :pointer,

0 commit comments

Comments
 (0)