Skip to content

Commit

Permalink
Merge pull request #205 from larskanis/remove-libc
Browse files Browse the repository at this point in the history
Use FFI::MemoryPointer instead of libc's malloc()
  • Loading branch information
bolandrm committed Jun 2, 2020
2 parents 1039a4d + d6d9dab commit 4bd764f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 29 deletions.
8 changes: 3 additions & 5 deletions lib/sassc/native.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ module Native
require_relative "native/sass_input_style"
require_relative "native/sass_output_style"
require_relative "native/string_list"
require_relative "native/lib_c"

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

def self.native_string(string)
string = "#{string}\0"
data = Native::LibC.malloc(string.bytesize)
data.write_string(string)
data
m = FFI::MemoryPointer.from_string(string)
m.autorelease = false
m
end

require_relative "native/native_context_api"
Expand Down
21 changes: 0 additions & 21 deletions lib/sassc/native/lib_c.rb

This file was deleted.

6 changes: 3 additions & 3 deletions test/native_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ def test_custom_importer
funct = FFI::Function.new(:pointer, [:pointer, :pointer, :pointer]) do |url, prev, cookie|
list = Native.make_import_list(2)

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

entry0 = Native.make_import_entry("fake_includ.scss", data, nil)
entry1 = Native.make_import_entry("not_included.scss", nil, nil)
Expand Down

0 comments on commit 4bd764f

Please sign in to comment.