Skip to content

Commit 4bd764f

Browse files
authored
Merge pull request #205 from larskanis/remove-libc
Use FFI::MemoryPointer instead of libc's malloc()
2 parents 1039a4d + d6d9dab commit 4bd764f

File tree

3 files changed

+6
-29
lines changed

3 files changed

+6
-29
lines changed

lib/sassc/native.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ module Native
3434
require_relative "native/sass_input_style"
3535
require_relative "native/sass_output_style"
3636
require_relative "native/string_list"
37-
require_relative "native/lib_c"
3837

3938
# Remove the redundant "sass_" from the beginning of every method name
4039
def self.attach_function(*args)
@@ -53,10 +52,9 @@ def self.return_string_array(ptr)
5352
end
5453

5554
def self.native_string(string)
56-
string = "#{string}\0"
57-
data = Native::LibC.malloc(string.bytesize)
58-
data.write_string(string)
59-
data
55+
m = FFI::MemoryPointer.from_string(string)
56+
m.autorelease = false
57+
m
6058
end
6159

6260
require_relative "native/native_context_api"

lib/sassc/native/lib_c.rb

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/native_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ def test_custom_importer
185185
funct = FFI::Function.new(:pointer, [:pointer, :pointer, :pointer]) do |url, prev, cookie|
186186
list = Native.make_import_list(2)
187187

188-
str = "$var: 5px;\0"
189-
data = Native::LibC.malloc(str.size)
190-
data.write_string(str)
188+
str = "$var: 5px;"
189+
data = FFI::MemoryPointer.from_string(str)
190+
data.autorelease = false
191191

192192
entry0 = Native.make_import_entry("fake_includ.scss", data, nil)
193193
entry1 = Native.make_import_entry("not_included.scss", nil, nil)

0 commit comments

Comments
 (0)