Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FFI::MemoryPointer instead of libc's malloc() #205

Merged
merged 1 commit into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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