Compare commits

...

7 Commits
rawhide ... el6

Author SHA1 Message Date
Dominic Cleal
74240a1a1a Fix support for bools in structs (upstream #114)
Required by smart_proxy_abrt project:
https://groups.google.com/d/msg/foreman-dev/8QTojFHmAIE/3hDV7J8HSYkJ
2014-10-08 13:36:23 +01:00
Dominic Cleal
b2e020647f Fix install location of built library and gemspec (RHBZ#975332) 2014-03-28 13:15:36 -04:00
Bryan Kearney
28c402d727 Move the ruby dependency back to 1.8 2013-01-07 13:09:14 -05:00
Bryan Kearney
3f429b0c70 Fix date in changelog 2013-01-03 14:17:24 -05:00
Bryan Kearney
acd7b0e436 Bump the version 2013-01-03 14:15:00 -05:00
Bryan Kearney
ea651d5997 Add the gem macros which rubygems-devel would have provided 2013-01-03 13:56:23 -05:00
Bryan Kearney
b608a5d329 Change the dependency to rubygems instead of rubygems-devel 2013-01-02 16:34:52 -05:00
2 changed files with 146 additions and 8 deletions

View File

@ -0,0 +1,121 @@
From 2e84385010cd544efb475672ba52d8e466e05332 Mon Sep 17 00:00:00 2001
From: Wayne Meissner <wmeissner@gmail.com>
Date: Sun, 29 May 2011 18:01:28 +1000
Subject: [PATCH] Fix issue #114 (Structs no longer support bools).
(cherry picked from commit 21d839cf5ff5f0920bd6818ff47ab95a0c2ee739)
Add failing spec to for FFI::Struct :bool member
(cherry picked from commit da06600c806375c5a7eb30d09845de12112a752f)
Add bool operation for Struct#[]
(cherry picked from commit 5cd65c41941d6e6788444817185e0fa23cfb71f9)
Conflicts:
ext/ffi_c/AbstractMemory.c
---
ext/ffi_c/AbstractMemory.c | 16 ++++++++++++++++
ext/ffi_c/AbstractMemory.h | 3 +++
lib/ffi/struct_layout_builder.rb | 3 ++-
spec/ffi/struct_spec.rb | 11 +++++++++++
4 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/ext/ffi_c/AbstractMemory.c b/ext/ffi_c/AbstractMemory.c
index 5359bc7..1849d16 100644
--- a/ext/ffi_c/AbstractMemory.c
+++ b/ext/ffi_c/AbstractMemory.c
@@ -256,6 +256,21 @@ get_pointer_value(VALUE value)
NUM_OP(pointer, void *, get_pointer_value, rbffi_Pointer_NewInstance, NOSWAP);
+static inline uint8_t
+rbffi_bool_value(VALUE value)
+{
+ return RTEST(value);
+}
+
+static inline VALUE
+rbffi_bool_new(uint8_t value)
+{
+ return (value & 1) != 0 ? Qtrue : Qfalse;
+}
+
+NUM_OP(bool, unsigned char, rbffi_bool_value, rbffi_bool_new, NOSWAP);
+
+
static VALUE
memory_clear(VALUE self)
{
@@ -535,6 +550,7 @@ MemoryOps rbffi_AbstractMemoryOps = {
.float64 = &memory_op_float64,
.pointer = &memory_op_pointer,
.strptr = &memory_op_strptr,
+ .boolOp = &memory_op_bool,
};
void
diff --git a/ext/ffi_c/AbstractMemory.h b/ext/ffi_c/AbstractMemory.h
index 1ba5bcb..f902856 100644
--- a/ext/ffi_c/AbstractMemory.h
+++ b/ext/ffi_c/AbstractMemory.h
@@ -60,6 +60,7 @@ typedef struct {
MemoryOp* float64;
MemoryOp* pointer;
MemoryOp* strptr;
+ MemoryOp* boolOp;
} MemoryOps;
struct AbstractMemory_ {
@@ -136,6 +137,8 @@ get_memory_op(Type* type)
return rbffi_AbstractMemoryOps.pointer;
case NATIVE_STRING:
return rbffi_AbstractMemoryOps.strptr;
+ case NATIVE_BOOL:
+ return rbffi_AbstractMemoryOps.boolOp;
default:
return NULL;
}
diff --git a/lib/ffi/struct_layout_builder.rb b/lib/ffi/struct_layout_builder.rb
index c1aec44..40f0066 100644
--- a/lib/ffi/struct_layout_builder.rb
+++ b/lib/ffi/struct_layout_builder.rb
@@ -71,6 +71,7 @@ module FFI
Type::UINT64,
Type::FLOAT32,
Type::FLOAT64,
+ Type::BOOL,
]
def add(name, type, offset = nil)
@@ -155,4 +156,4 @@ module FFI
end
end
-end
\ No newline at end of file
+end
diff --git a/spec/ffi/struct_spec.rb b/spec/ffi/struct_spec.rb
index 4c00c93..4add214 100644
--- a/spec/ffi/struct_spec.rb
+++ b/spec/ffi/struct_spec.rb
@@ -669,4 +669,15 @@ describe "Struct allocation" do
end
S.new(FFI::MemoryPointer.new(S)).null?.should be_false
end
+
+ it "supports :bool as a struct member" do
+ lambda do
+ c = Class.new(FFI::Struct) do
+ layout :b, :bool
+ end
+ struct = c.new
+ struct[:b] = ! struct[:b]
+ end.should_not raise_error
+ end
+
end
--
1.9.3

View File

@ -1,3 +1,4 @@
%{!?ruby_sitearch: %global ruby_sitearch %(ruby -rrbconfig -e "puts Config::CONFIG['sitearchdir']")}
%global gem_name ffi
%global libname %{gem_name}_c.so
%global githubhash b79eb61
@ -7,7 +8,7 @@
Name: rubygem-%{gem_name}
Version: 1.0.9
Release: 5%{?dist}
Release: 10%{?dist}
Summary: FFI Extensions for Ruby
Group: Development/Languages
@ -19,12 +20,13 @@ URL: http://wiki.github.com/ffi/ffi
Source0: %{tarballname}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: ruby ruby-devel rubygems-devel rubygem(rake) rubygem(rake-compiler) libffi-devel rubygem(rspec-core)
BuildRequires: ruby-devel
Patch1: 0001-Fix-issue-114-Structs-no-longer-support-bools.patch
BuildRequires: ruby-devel rubygems-devel rubygem(rake) rubygem(rake-compiler) libffi-devel rubygem(rspec-core)
BuildRequires: pkgconfig
Requires: libffi
Requires: ruby(rubygems)
Requires: ruby(abi) = 1.9.1
Requires: ruby(abi) = 1.8
Provides: rubygem(%{gem_name}) = %{version}
%description
@ -36,6 +38,7 @@ using Ruby-FFI here[http://wiki.github.com/ffi/ffi/why-use-ffi].
%prep
%setup -q -n %{gitinternalname}
%patch1 -p1
%build
export CFLAGS="%{optflags}"
@ -47,10 +50,9 @@ gem install -V -d --local --no-ri -i ./geminst --force pkg/%{gem_name}-%{version
rm -rf %{buildroot}
mkdir %{buildroot}
install -d -m0755 %{buildroot}%{gem_dir}
install -d -m0755 %{buildroot}%{gem_extdir}/lib
install -d -m0755 %{buildroot}%{ruby_sitearch}
cp -R %{_builddir}/%{gitinternalname}/geminst/* %{buildroot}%{gem_dir}
mv %{buildroot}%{gem_libdir}/%{libname} %{buildroot}%{gem_extdir}/lib/%{libname}
rm -rf %{buildroot}%{gem_libdir}/%{libname}
mv %{buildroot}%{gem_libdir}/%{libname} %{buildroot}%{ruby_sitearch}/%{libname}
rm -rf %{buildroot}%{gem_instdir}/ext
%check
@ -77,12 +79,27 @@ rm -rf %{buildroot}
%{gem_libdir}
%{gem_instdir}/spec
%{gem_instdir}/tasks
%{gem_extdir}/
%{ruby_sitearch}/%{libname}
%{gem_cache}
%{gem_spec}
%changelog
* Wed Oct 08 2014 Dominic Cleal <dcleal@redhat.com> - 1.0.9-10
- Fix support for bools in structs (upstream #114)
* Wed Mar 26 2014 Dominic Cleal <dcleal@redhat.com> - 1.0.9-9
- Fix install location of built library and gemspec (RHBZ#975332)
* Thu Jan 07 2013 Bryan Kearney <bkearney@redhat.com> - 1.0.9-8
- Change the ruby version back to 1.8
* Thu Jan 03 2013 Bryan Kearney <bkearney@redhat.com> - 1.0.9-7
- Add the gem macros which rubygems-devel would have provided
* Wed Jan 01 2013 Bryan Kearney <bkearney@redhat.com> - 1.0.9-6
- Change dependency to rubygems instead of rubgems-devel
* Sat Jul 21 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 1.0.9-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild