summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Kanis <lars@greiz-reinsdorf.de>2020-12-14 16:31:26 +0100
committerGitHub <noreply@github.com>2020-12-14 16:31:26 +0100
commita7f4c951f5004c338fbae237bbae69fbb6ca66c6 (patch)
tree3692824d4c0fe13a098ac431c77b8fe8a618c3f4
parentdfae59e293974efaa7b4d414e5116d7a2187a06e (diff)
parentb7cc0a8122cbac5ae9df417ad0299457dba48a63 (diff)
downloadffi-a7f4c951f5004c338fbae237bbae69fbb6ca66c6.tar.gz
Merge pull request #852 from larskanis/move-size-limit
Move Pointer#size_limit? to AbstractMemory and from C to ruby
-rw-r--r--ext/ffi_c/Pointer.c17
-rw-r--r--lib/ffi/abstract_memory.rb44
-rw-r--r--lib/ffi/ffi.rb1
-rw-r--r--spec/ffi/pointer_spec.rb2
4 files changed, 46 insertions, 18 deletions
diff --git a/ext/ffi_c/Pointer.c b/ext/ffi_c/Pointer.c
index 9e5ed5f..153fff1 100644
--- a/ext/ffi_c/Pointer.c
+++ b/ext/ffi_c/Pointer.c
@@ -315,22 +315,6 @@ ptr_address(VALUE self)
return ULL2NUM((uintptr_t) ptr->memory.address);
}
-/*
- * Document-method: size_limit?
- * call-seq: ptr.size_limit?
- * @return [Boolean]
- * Return +true+ if +self+ has a size limit.
- */
-static VALUE
-ptr_size_limit(VALUE self)
-{
- Pointer* ptr;
-
- Data_Get_Struct(self, Pointer, ptr);
-
- return ptr->memory.size == LONG_MAX ? Qfalse : Qtrue;
-}
-
#if BYTE_ORDER == LITTLE_ENDIAN
# define SWAPPED_ORDER BIG_ENDIAN
#else
@@ -513,7 +497,6 @@ rbffi_Pointer_Init(VALUE moduleFFI)
rb_define_method(rbffi_PointerClass, "autorelease?", ptr_autorelease_p, 0);
rb_define_method(rbffi_PointerClass, "free", ptr_free, 0);
rb_define_method(rbffi_PointerClass, "type_size", ptr_type_size, 0);
- rb_define_method(rbffi_PointerClass, "size_limit?", ptr_size_limit, 0);
rbffi_NullPointerSingleton = rb_class_new_instance(1, &rbNullAddress, rbffi_PointerClass);
/*
diff --git a/lib/ffi/abstract_memory.rb b/lib/ffi/abstract_memory.rb
new file mode 100644
index 0000000..e0aa221
--- /dev/null
+++ b/lib/ffi/abstract_memory.rb
@@ -0,0 +1,44 @@
+#
+# Copyright (C) 2020 Lars Kanis
+#
+# This file is part of ruby-ffi.
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# * Redistributions of source code must retain the above copyright notice, this
+# list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright notice
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+# * Neither the name of the Ruby FFI project nor the names of its contributors
+# may be used to endorse or promote products derived from this software
+# without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
+
+
+module FFI
+ class AbstractMemory
+ LONG_MAX = FFI::Pointer.new(1).size
+ private_constant :LONG_MAX
+
+ # Return +true+ if +self+ has a size limit.
+ #
+ # @return [Boolean]
+ def size_limit?
+ size != LONG_MAX
+ end
+ end
+end
diff --git a/lib/ffi/ffi.rb b/lib/ffi/ffi.rb
index 5201dae..dfffa8c 100644
--- a/lib/ffi/ffi.rb
+++ b/lib/ffi/ffi.rb
@@ -33,6 +33,7 @@ require 'ffi/data_converter'
require 'ffi/types'
require 'ffi/library'
require 'ffi/errno'
+require 'ffi/abstract_memory'
require 'ffi/pointer'
require 'ffi/memorypointer'
require 'ffi/struct'
diff --git a/spec/ffi/pointer_spec.rb b/spec/ffi/pointer_spec.rb
index f75d28d..b216a16 100644
--- a/spec/ffi/pointer_spec.rb
+++ b/spec/ffi/pointer_spec.rb
@@ -236,7 +236,7 @@ describe "Pointer" do
it "should have size limit" do
expect(FFI::Pointer.new(0).slice(0, 10).size_limit?).to be true
end
- end if RUBY_ENGINE != "truffleruby"
+ end
end
describe "AutoPointer" do