diff --git a/lib/sassc/native.rb b/lib/sassc/native.rb index 74e0099e..3b9f515f 100644 --- a/lib/sassc/native.rb +++ b/lib/sassc/native.rb @@ -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) @@ -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" diff --git a/lib/sassc/native/lib_c.rb b/lib/sassc/native/lib_c.rb deleted file mode 100644 index 8e9b08ee..00000000 --- a/lib/sassc/native/lib_c.rb +++ /dev/null @@ -1,21 +0,0 @@ -# frozen_string_literal: true - -module SassC - module Native - module LibC - extend FFI::Library - ffi_lib FFI::Library::LIBC - - # memory allocators - attach_function :malloc, [:size_t], :pointer - # attach_function :calloc, [:size_t], :pointer - # attach_function :valloc, [:size_t], :pointer - # attach_function :realloc, [:pointer, :size_t], :pointer - # attach_function :free, [:pointer], :void - - # memory movers - # attach_function :memcpy, [:pointer, :pointer, :size_t], :pointer - # attach_function :bcopy, [:pointer, :pointer, :size_t], :void - end - end -end diff --git a/test/native_test.rb b/test/native_test.rb index 66b38eec..c83ad52a 100644 --- a/test/native_test.rb +++ b/test/native_test.rb @@ -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)