sparsam 0.2.5 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c47d8f62e5244736a0f3e8e0e02f1f0104d3fb41982da0ca598940d2bfb6bc52
4
- data.tar.gz: fe43b9eb4b3167adec9d435269a14ab90b08f4518f9c242875555a144fe3a689
3
+ metadata.gz: 34cdf5f3a73cda371b8a1275369af0063e525d0951f44c23a12e02e6dfa3c519
4
+ data.tar.gz: f5d7efaf6389491e9ceab33839b828fb26757d8b84b8cc3ba9cf87b509716e13
5
5
  SHA512:
6
- metadata.gz: a62b9bc043e205badb26495651e918b6ff14c6ab3574b2fbf5cbdc00ca61cd1f1bbd7f44ea18ebd40673bde1fffbff57e981cd3db532ffba43451b7e8d71e3b5
7
- data.tar.gz: 6d6454f006da2089124019b176d5e916b2a1ff77ff67731601e18cf64275f224afc234b9bd27a5d10ff687992163743bcf804b153cc00526d51155786eb77171
6
+ metadata.gz: c2482ca31e496f3e1fb2597eaf7eb8f83e2f5545d7b2f8165840c5b394b4f63ce522bff6c2d18e11287803cc739ad279b97cf45f97efa1bbdd2f29c5594c8fc2
7
+ data.tar.gz: 62c14e98d040e76fdf6d9a886c0b138e25f0e8b9b901445b000f6c9fed12947c7537749a24f5601fc84d4e920b6b18b816fbcbe946aa525242de57d269698abd
data/ext/extconf.rb CHANGED
@@ -7,12 +7,70 @@ if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
7
7
  $CPPFLAGS += $CXXFLAGS
8
8
  end
9
9
 
10
+ brew = find_executable('brew')
11
+
12
+ # Automatically use homebrew to discover thrift package if it is
13
+ # available and not disabled via --disable-homebrew.
14
+ use_homebrew = enable_config('homebrew', brew)
15
+
16
+ if use_homebrew
17
+ $stderr.puts "Using #{brew} to locate thrift and boost packages"
18
+ $stderr.puts '(disable Homebrew integration via --disable-homebrew)'
19
+
20
+ thrift_package = with_config('homebrew-thrift-package', 'thrift@0.9')
21
+ $stderr.puts "looking for Homebrew thrift package '#{thrift_package}'"
22
+ $stderr.puts '(change Homebrew thrift package name via --with-homebrew-thrift-package=<package>)'
23
+
24
+ thrift_prefix = `#{brew} --prefix #{thrift_package}`.strip
25
+
26
+ unless File.exists?(thrift_prefix)
27
+ $stderr.puts "#{thrift_prefix} does not exist"
28
+ $stderr.puts "To resolve, `brew install #{thrift_package}` or pass"
29
+ $stderr.puts '--with-homebrew-thrift-package=<package> to this build to specify'
30
+ $stderr.puts 'an alternative thrift package to build against. e.g.:'
31
+ $stderr.puts
32
+ $stderr.puts ' $ bundle config --global build.sparsam --with-homebrew-thrift-package=mythrift'
33
+
34
+ raise "Homebrew package #{thrift_package} not installed"
35
+ end
36
+
37
+ $stderr.puts "using Homebrew thrift at #{thrift_prefix}"
38
+ $CFLAGS << " -I#{thrift_prefix}/include"
39
+ $CXXFLAGS << " -I#{thrift_prefix}/include"
40
+ $CPPFLAGS << " -I#{thrift_prefix}/include"
41
+ $LDFLAGS << " -L#{thrift_prefix}/lib"
42
+
43
+ # Also add boost to the includes search path if it is installed.
44
+ boost_package = with_config('homebrew-boost-package', 'boost')
45
+ $stderr.puts "looking for Homebrew boost package '#{boost_package}'"
46
+ $stderr.puts '(change Homebrew boost package name via --with-homebrew-boost-package=<package>)'
47
+
48
+ boost_prefix = `#{brew} --prefix #{boost_package}`.strip
49
+
50
+ if File.exists?(boost_prefix)
51
+ $stderr.puts("using Homebrew boost at #{boost_prefix}")
52
+ $CFLAGS << " -I#{boost_prefix}/include"
53
+ $CXXFLAGS << " -I#{boost_prefix}/include"
54
+ $CPPFLAGS << " -I#{boost_prefix}/include"
55
+ else
56
+ $stderr.puts 'Homebrew boost not found; assuming boost is in default search paths'
57
+ end
58
+ end
59
+
10
60
  have_func("strlcpy", "string.h")
11
- have_library("thrift")
61
+
62
+ unless have_library("thrift")
63
+ raise 'thrift library not found; aborting since compile would fail'
64
+ end
65
+
12
66
  libs = ['-lthrift']
13
67
 
14
68
  libs.each do |lib|
15
69
  $LOCAL_LIBS << "#{lib} "
16
70
  end
17
71
 
72
+ # Ideally we'd validate boost as well. But boost is header only and
73
+ # mkmf's have_header() doesn't work with C++ headers.
74
+ # https://bugs.ruby-lang.org/issues/4924
75
+
18
76
  create_makefile 'sparsam_native'
data/ext/ruby_hooks.c CHANGED
@@ -1,7 +1,7 @@
1
- #include "stdio.h"
2
1
  #include <ruby.h>
3
2
  #include <ruby/intern.h>
4
3
  #include "serializer.h"
4
+ #include "stdio.h"
5
5
 
6
6
  VALUE Sparsam = Qnil;
7
7
  VALUE static_zero_array;
@@ -11,10 +11,10 @@ ID intern_for_DEFAULT_VALUES;
11
11
  ID intern_for_assign_defaults;
12
12
  ID intern_for_assign_from_arg;
13
13
 
14
- static void deallocate(void *data) { serializer_free(data); }
14
+ static void deallocate(void* data) { serializer_free(data); }
15
15
 
16
16
  static VALUE allocate(VALUE klass) {
17
- void *data = serializer_create();
17
+ void* data = serializer_create();
18
18
  return Data_Wrap_Struct(klass, NULL, deallocate, data);
19
19
  }
20
20
 
@@ -24,8 +24,8 @@ static VALUE sparsam_init_bang(VALUE self) {
24
24
  }
25
25
 
26
26
  static VALUE initialize(VALUE self, VALUE type_arg, VALUE str_arg) {
27
- void *self_data = NULL;
28
- void *input_string = NULL;
27
+ void* self_data = NULL;
28
+ void* input_string = NULL;
29
29
 
30
30
  Check_Type(type_arg, T_FIXNUM);
31
31
  int prot = NUM2INT(type_arg);
@@ -38,7 +38,7 @@ static VALUE initialize(VALUE self, VALUE type_arg, VALUE str_arg) {
38
38
  memcpy(input_string, StringValuePtr(str_arg), len);
39
39
  }
40
40
 
41
- Data_Get_Struct(self, void *, self_data);
41
+ Data_Get_Struct(self, void*, self_data);
42
42
  serializer_init(self_data, prot, input_string, len);
43
43
 
44
44
  return self;
@@ -46,7 +46,8 @@ static VALUE initialize(VALUE self, VALUE type_arg, VALUE str_arg) {
46
46
 
47
47
  VALUE sparsam_struct_initialize(int argc, VALUE* argv, VALUE self) {
48
48
  if (argc > 1) {
49
- rb_raise(rb_eArgError, "wrong number of arguments (given %d, expected 0..1)", argc);
49
+ rb_raise(rb_eArgError,
50
+ "wrong number of arguments (given %d, expected 0..1)", argc);
50
51
  }
51
52
 
52
53
  VALUE defaults = rb_const_get(rb_obj_class(self), intern_for_DEFAULT_VALUES);
@@ -70,14 +71,16 @@ void Init_sparsam_native() {
70
71
  Sparsam = rb_define_module("Sparsam");
71
72
  rb_define_singleton_method(Sparsam, "init!", sparsam_init_bang, 0);
72
73
  rb_define_singleton_method(Sparsam, "cache_fields", cache_fields, 1);
73
- VALUE SparsamSerializer = rb_define_class_under(Sparsam, "Serializer", rb_cObject);
74
+ VALUE SparsamSerializer =
75
+ rb_define_class_under(Sparsam, "Serializer", rb_cObject);
74
76
  SparsamNativeError =
75
77
  rb_define_class_under(Sparsam, "Exception", rb_eStandardError);
76
78
  rb_define_alloc_func(SparsamSerializer, allocate);
77
79
  rb_define_method(SparsamSerializer, "initialize", initialize, 2);
78
80
  rb_define_method(SparsamSerializer, "serialize", serializer_writeStruct, 2);
79
81
  rb_define_method(SparsamSerializer, "deserialize", serializer_readStruct, 1);
80
- rb_define_method(SparsamSerializer, "deserializeUnion", serializer_readUnion, 1);
82
+ rb_define_method(SparsamSerializer, "deserializeUnion", serializer_readUnion,
83
+ 1);
81
84
  rb_define_const(Sparsam, "CompactProtocol", INT2FIX(compact));
82
85
  rb_define_const(Sparsam, "BinaryProtocol", INT2FIX(binary));
83
86
  rb_define_const(Sparsam, "UNION", INT2FIX(t_union));
@@ -90,8 +93,9 @@ void Init_sparsam_native() {
90
93
  intern_for_assign_defaults = rb_intern("assign_defaults");
91
94
  intern_for_assign_from_arg = rb_intern("assign_from_arg");
92
95
 
93
-
94
- VALUE SparsamStructInitialization = rb_define_module_under(Sparsam, "StructInitialization");
95
- rb_define_method(SparsamStructInitialization, "initialize", sparsam_struct_initialize, -1);
96
+ VALUE SparsamStructInitialization =
97
+ rb_define_module_under(Sparsam, "StructInitialization");
98
+ rb_define_method(SparsamStructInitialization, "initialize",
99
+ sparsam_struct_initialize, -1);
96
100
  initialize_constants();
97
101
  }