mysql2 0.2.24 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +1 -0
  3. data/LICENSE +21 -0
  4. data/README.md +237 -85
  5. data/ext/mysql2/client.c +582 -249
  6. data/ext/mysql2/client.h +10 -38
  7. data/ext/mysql2/extconf.rb +217 -66
  8. data/ext/mysql2/infile.c +2 -2
  9. data/ext/mysql2/mysql2_ext.c +9 -2
  10. data/ext/mysql2/mysql2_ext.h +13 -14
  11. data/ext/mysql2/mysql_enc_name_to_ruby.h +62 -58
  12. data/ext/mysql2/mysql_enc_to_ruby.h +82 -18
  13. data/ext/mysql2/result.c +736 -200
  14. data/ext/mysql2/result.h +13 -6
  15. data/ext/mysql2/statement.c +612 -0
  16. data/ext/mysql2/statement.h +17 -0
  17. data/ext/mysql2/wait_for_single_fd.h +2 -1
  18. data/lib/mysql2/client.rb +110 -28
  19. data/lib/mysql2/console.rb +1 -1
  20. data/lib/mysql2/em.rb +15 -9
  21. data/lib/mysql2/error.rb +57 -36
  22. data/lib/mysql2/field.rb +3 -0
  23. data/lib/mysql2/result.rb +2 -0
  24. data/lib/mysql2/statement.rb +9 -0
  25. data/lib/mysql2/version.rb +1 -1
  26. data/lib/mysql2.rb +66 -15
  27. data/support/3A79BD29.asc +49 -0
  28. data/support/5072E1F5.asc +432 -0
  29. data/support/libmysql.def +219 -0
  30. data/support/mysql_enc_to_ruby.rb +15 -11
  31. data/support/ruby_enc_to_mysql.rb +8 -6
  32. metadata +30 -94
  33. data/MIT-LICENSE +0 -20
  34. data/examples/eventmachine.rb +0 -21
  35. data/examples/threaded.rb +0 -20
  36. data/lib/active_record/connection_adapters/mysql2_adapter.rb +0 -635
  37. data/lib/arel/engines/sql/compilers/mysql2_compiler.rb +0 -11
  38. data/spec/configuration.yml.example +0 -17
  39. data/spec/em/em_spec.rb +0 -114
  40. data/spec/my.cnf.example +0 -9
  41. data/spec/mysql2/client_spec.rb +0 -897
  42. data/spec/mysql2/error_spec.rb +0 -83
  43. data/spec/mysql2/result_spec.rb +0 -505
  44. data/spec/rcov.opts +0 -3
  45. data/spec/spec_helper.rb +0 -87
  46. data/spec/test_data +0 -1
data/ext/mysql2/client.h CHANGED
@@ -1,41 +1,6 @@
1
1
  #ifndef MYSQL2_CLIENT_H
2
2
  #define MYSQL2_CLIENT_H
3
3
 
4
- #ifndef HAVE_RB_THREAD_CALL_WITHOUT_GVL
5
- #ifdef HAVE_RB_THREAD_BLOCKING_REGION
6
-
7
- /* emulate rb_thread_call_without_gvl with rb_thread_blocking_region */
8
- #define rb_thread_call_without_gvl(func, data1, ubf, data2) \
9
- rb_thread_blocking_region((rb_blocking_function_t *)func, data1, ubf, data2)
10
-
11
- #else /* ! HAVE_RB_THREAD_BLOCKING_REGION */
12
- /*
13
- * partial emulation of the 2.0 rb_thread_call_without_gvl under 1.8,
14
- * this is enough for dealing with blocking I/O functions in the
15
- * presence of threads.
16
- */
17
-
18
- #include <rubysig.h>
19
- #define RUBY_UBF_IO ((rb_unblock_function_t *)-1)
20
- typedef void rb_unblock_function_t(void *);
21
- static void *
22
- rb_thread_call_without_gvl(
23
- void *(*func)(void *), void *data1,
24
- RB_MYSQL_UNUSED rb_unblock_function_t *ubf,
25
- RB_MYSQL_UNUSED void *data2)
26
- {
27
- void *rv;
28
-
29
- TRAP_BEG;
30
- rv = func(data1);
31
- TRAP_END;
32
-
33
- return rv;
34
- }
35
-
36
- #endif /* ! HAVE_RB_THREAD_BLOCKING_REGION */
37
- #endif /* ! HAVE_RB_THREAD_CALL_WITHOUT_GVL */
38
-
39
4
  typedef struct {
40
5
  VALUE encoding;
41
6
  VALUE active_thread; /* rb_thread_current() or Qnil */
@@ -43,14 +8,21 @@ typedef struct {
43
8
  int reconnect_enabled;
44
9
  unsigned int connect_timeout;
45
10
  int active;
46
- int connected;
11
+ int automatic_close;
47
12
  int initialized;
48
13
  int refcount;
49
- int freed;
14
+ int closed;
50
15
  MYSQL *client;
51
16
  } mysql_client_wrapper;
52
17
 
53
- void init_mysql2_client();
18
+ void rb_mysql_client_set_active_thread(VALUE self);
19
+ void rb_mysql_set_server_query_flags(MYSQL *client, VALUE result);
20
+
21
+ #define GET_CLIENT(self) \
22
+ mysql_client_wrapper *wrapper; \
23
+ Data_Get_Struct(self, mysql_client_wrapper, wrapper);
24
+
25
+ void init_mysql2_client(void);
54
26
  void decr_mysql2_client(mysql_client_wrapper *wrapper);
55
27
 
56
28
  #endif
@@ -1,81 +1,108 @@
1
- # encoding: UTF-8
2
1
  require 'mkmf'
2
+ require 'English'
3
3
 
4
- def asplode lib
5
- abort "-----\n#{lib} is missing. please check your installation of mysql and try again.\n-----"
4
+ def asplode(lib)
5
+ if RUBY_PLATFORM =~ /mingw|mswin/
6
+ abort "-----\n#{lib} is missing. Check your installation of MySQL or Connector/C, and try again.\n-----"
7
+ elsif RUBY_PLATFORM =~ /darwin/
8
+ abort "-----\n#{lib} is missing. You may need to 'brew install mysql' or 'port install mysql', and try again.\n-----"
9
+ else
10
+ abort "-----\n#{lib} is missing. You may need to 'sudo apt-get install libmariadb-dev', 'sudo apt-get install libmysqlclient-dev' or 'sudo yum install mysql-devel', and try again.\n-----"
11
+ end
12
+ end
13
+
14
+ def add_ssl_defines(header)
15
+ all_modes_found = %w[SSL_MODE_DISABLED SSL_MODE_PREFERRED SSL_MODE_REQUIRED SSL_MODE_VERIFY_CA SSL_MODE_VERIFY_IDENTITY].inject(true) do |m, ssl_mode|
16
+ m && have_const(ssl_mode, header)
17
+ end
18
+ if all_modes_found
19
+ $CFLAGS << ' -DFULL_SSL_MODE_SUPPORT'
20
+ else
21
+ # if we only have ssl toggle (--ssl,--disable-ssl) from 5.7.3 to 5.7.10
22
+ # and the verify server cert option. This is also the case for MariaDB.
23
+ has_verify_support = have_const('MYSQL_OPT_SSL_VERIFY_SERVER_CERT', header)
24
+ has_enforce_support = have_const('MYSQL_OPT_SSL_ENFORCE', header)
25
+ $CFLAGS << ' -DNO_SSL_MODE_SUPPORT' if !has_verify_support && !has_enforce_support
26
+ end
6
27
  end
7
28
 
8
- # 2.0-only
9
- have_header('ruby/thread.h') && have_func('rb_thread_call_without_gvl', 'ruby/thread.h')
29
+ # Homebrew openssl
30
+ if RUBY_PLATFORM =~ /darwin/ && system("command -v brew")
31
+ openssl_location = `brew --prefix openssl`.strip
32
+ $LDFLAGS << " -L#{openssl_location}/lib" if openssl_location
33
+ end
10
34
 
11
- # 1.9-only
12
- have_func('rb_thread_blocking_region')
35
+ # 2.1+
36
+ have_func('rb_absint_size')
37
+ have_func('rb_absint_singlebit_p')
38
+
39
+ # Missing in RBX (https://github.com/rubinius/rubinius/issues/3771)
13
40
  have_func('rb_wait_for_single_fd')
14
- have_func('rb_hash_dup')
15
- have_func('rb_intern3')
41
+
42
+ have_func("rb_enc_interned_str", "ruby.h")
16
43
 
17
44
  # borrowed from mysqlplus
18
45
  # http://github.com/oldmoe/mysqlplus/blob/master/ext/extconf.rb
19
- dirs = ENV['PATH'].split(File::PATH_SEPARATOR) + %w[
46
+ dirs = ENV.fetch('PATH').split(File::PATH_SEPARATOR) + %w[
20
47
  /opt
21
48
  /opt/local
22
49
  /opt/local/mysql
23
- /opt/local/lib/mysql5
50
+ /opt/local/lib/mysql5*
24
51
  /usr
25
52
  /usr/mysql
26
53
  /usr/local
27
54
  /usr/local/mysql
28
55
  /usr/local/mysql-*
29
- /usr/local/lib/mysql5
30
- ].map{|dir| "#{dir}/bin" }
56
+ /usr/local/lib/mysql5*
57
+ /usr/local/opt/mysql5*
58
+ /usr/local/opt/mysql@*
59
+ /usr/local/opt/mysql-client
60
+ /usr/local/opt/mysql-client@*
61
+ ].map { |dir| dir << '/bin' }
62
+
63
+ # For those without HOMEBREW_ROOT in PATH
64
+ dirs << "#{ENV['HOMEBREW_ROOT']}/bin" if ENV['HOMEBREW_ROOT']
31
65
 
32
- GLOB = "{#{dirs.join(',')}}/{mysql_config,mysql_config5}"
66
+ GLOB = "{#{dirs.join(',')}}/{mysql_config,mysql_config5,mariadb_config}".freeze
33
67
 
34
68
  # If the user has provided a --with-mysql-dir argument, we must respect it or fail.
35
69
  inc, lib = dir_config('mysql')
36
70
  if inc && lib
37
- # Ruby versions not incorporating the mkmf fix at
71
+ # Ruby versions below 2.0 on Unix and below 2.1 on Windows
72
+ # do not properly search for lib directories, and must be corrected:
38
73
  # https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/39717
39
- # do not properly search for lib directories, and must be corrected
40
74
  unless lib && lib[-3, 3] == 'lib'
41
75
  @libdir_basename = 'lib'
42
76
  inc, lib = dir_config('mysql')
43
77
  end
44
- abort "-----\nCannot find include dir(s) #{inc}\n-----" unless inc && inc.split(File::PATH_SEPARATOR).any?{|dir| File.directory?(dir)}
45
- abort "-----\nCannot find library dir(s) #{lib}\n-----" unless lib && lib.split(File::PATH_SEPARATOR).any?{|dir| File.directory?(dir)}
46
- warn "-----\nUsing --with-mysql-dir=#{File.dirname inc}\n-----"
78
+ abort "-----\nCannot find include dir(s) #{inc}\n-----" unless inc && inc.split(File::PATH_SEPARATOR).any? { |dir| File.directory?(dir) }
79
+ abort "-----\nCannot find library dir(s) #{lib}\n-----" unless lib && lib.split(File::PATH_SEPARATOR).any? { |dir| File.directory?(dir) }
80
+ warn "-----\nUsing --with-mysql-dir=#{File.dirname inc}\n-----"
47
81
  rpath_dir = lib
48
- elsif mc = (with_config('mysql-config') || Dir[GLOB].first)
82
+ have_library('mysqlclient')
83
+ elsif (mc = (with_config('mysql-config') || Dir[GLOB].first))
49
84
  # If the user has provided a --with-mysql-config argument, we must respect it or fail.
50
85
  # If the user gave --with-mysql-config with no argument means we should try to find it.
51
86
  mc = Dir[GLOB].first if mc == true
52
- abort "-----\nCannot find mysql_config at #{mc}\n-----" unless mc && File.exists?(mc)
87
+ abort "-----\nCannot find mysql_config at #{mc}\n-----" unless mc && File.exist?(mc)
53
88
  abort "-----\nCannot execute mysql_config at #{mc}\n-----" unless File.executable?(mc)
54
- warn "-----\nUsing mysql_config at #{mc}\n-----"
89
+ warn "-----\nUsing mysql_config at #{mc}\n-----"
55
90
  ver = `#{mc} --version`.chomp.to_f
56
91
  includes = `#{mc} --include`.chomp
57
- exit 1 if $? != 0
92
+ abort unless $CHILD_STATUS.success?
58
93
  libs = `#{mc} --libs_r`.chomp
59
94
  # MySQL 5.5 and above already have re-entrant code in libmysqlclient (no _r).
60
- if ver >= 5.5 || libs.empty?
61
- libs = `#{mc} --libs`.chomp
62
- end
63
- exit 1 if $? != 0
95
+ libs = `#{mc} --libs`.chomp if ver >= 5.5 || libs.empty?
96
+ abort unless $CHILD_STATUS.success?
64
97
  $INCFLAGS += ' ' + includes
65
98
  $libs = libs + " " + $libs
66
99
  rpath_dir = libs
67
100
  else
68
- inc, lib = dir_config('mysql', '/usr/local')
69
- libs = ['m', 'z', 'socket', 'nsl', 'mygcc']
70
- while not find_library('mysqlclient', 'mysql_query', lib, "#{lib}/mysql") do
71
- exit 1 if libs.empty?
72
- have_library(libs.shift)
73
- end
74
- rpath_dir = lib
75
- end
101
+ _, usr_local_lib = dir_config('mysql', '/usr/local')
102
+
103
+ asplode("mysql client") unless find_library('mysqlclient', nil, usr_local_lib, "#{usr_local_lib}/mysql")
76
104
 
77
- if RUBY_PLATFORM =~ /mswin|mingw/
78
- exit 1 unless have_library('libmysql')
105
+ rpath_dir = usr_local_lib
79
106
  end
80
107
 
81
108
  if have_header('mysql.h')
@@ -86,43 +113,167 @@ else
86
113
  asplode 'mysql.h'
87
114
  end
88
115
 
89
- %w{ errmsg.h mysqld_error.h }.each do |h|
90
- header = [prefix, h].compact.join '/'
91
- asplode h unless have_header h
116
+ %w[errmsg.h].each do |h|
117
+ header = [prefix, h].compact.join('/')
118
+ asplode h unless have_header header
92
119
  end
93
120
 
94
- # These gcc style flags are also supported by clang and xcode compilers,
95
- # so we'll use a does-it-work test instead of an is-it-gcc test.
96
- gcc_flags = ' -Wall -funroll-loops'
97
- if try_link('int main() {return 0;}', gcc_flags)
98
- $CFLAGS << gcc_flags
121
+ mysql_h = [prefix, 'mysql.h'].compact.join('/')
122
+ add_ssl_defines(mysql_h)
123
+ have_struct_member('MYSQL', 'net.vio', mysql_h)
124
+ have_struct_member('MYSQL', 'net.pvio', mysql_h)
125
+
126
+ # These constants are actually enums, so they cannot be detected by #ifdef in C code.
127
+ have_const('MYSQL_DEFAULT_AUTH', mysql_h)
128
+ have_const('MYSQL_ENABLE_CLEARTEXT_PLUGIN', mysql_h)
129
+ have_const('SERVER_QUERY_NO_GOOD_INDEX_USED', mysql_h)
130
+ have_const('SERVER_QUERY_NO_INDEX_USED', mysql_h)
131
+ have_const('SERVER_QUERY_WAS_SLOW', mysql_h)
132
+ have_const('MYSQL_OPTION_MULTI_STATEMENTS_ON', mysql_h)
133
+ have_const('MYSQL_OPTION_MULTI_STATEMENTS_OFF', mysql_h)
134
+
135
+ # my_bool is replaced by C99 bool in MySQL 8.0, but we want
136
+ # to retain compatibility with the typedef in earlier MySQLs.
137
+ have_type('my_bool', mysql_h)
138
+
139
+ # This is our wishlist. We use whichever flags work on the host.
140
+ # -Wall and -Wextra are included by default.
141
+ wishlist = [
142
+ '-Weverything',
143
+ '-Wno-bad-function-cast', # rb_thread_call_without_gvl returns void * that we cast to VALUE
144
+ '-Wno-conditional-uninitialized', # false positive in client.c
145
+ '-Wno-covered-switch-default', # result.c -- enum_field_types (when fully covered, e.g. mysql 5.5)
146
+ '-Wno-declaration-after-statement', # GET_CLIENT followed by GET_STATEMENT in statement.c
147
+ '-Wno-disabled-macro-expansion', # rubby :(
148
+ '-Wno-documentation-unknown-command', # rubby :(
149
+ '-Wno-missing-field-initializers', # gperf generates bad code
150
+ '-Wno-missing-variable-declarations', # missing symbols due to ruby native ext initialization
151
+ '-Wno-padded', # mysql :(
152
+ '-Wno-reserved-id-macro', # rubby :(
153
+ '-Wno-sign-conversion', # gperf generates bad code
154
+ '-Wno-static-in-inline', # gperf generates bad code
155
+ '-Wno-switch-enum', # result.c -- enum_field_types (when not fully covered, e.g. mysql 5.6+)
156
+ '-Wno-undef', # rubinius :(
157
+ '-Wno-unreachable-code', # rubby :(
158
+ '-Wno-used-but-marked-unused', # rubby :(
159
+ ]
160
+
161
+ usable_flags = wishlist.select do |flag|
162
+ try_link('int main() {return 0;}', "-Werror #{flag}")
99
163
  end
100
164
 
101
- case explicit_rpath = with_config('mysql-rpath')
165
+ $CFLAGS << ' ' << usable_flags.join(' ')
166
+
167
+ enabled_sanitizers = disabled_sanitizers = []
168
+ # Specify a comma-separated list of sanitizers, or try them all by default
169
+ sanitizers = with_config('sanitize')
170
+ case sanitizers
102
171
  when true
103
- abort "-----\nOption --with-mysql-rpath must have an argument\n-----"
104
- when false
105
- warn "-----\nOption --with-mysql-rpath has been disabled at your request\n-----"
172
+ # Try them all, turn on whatever we can
173
+ enabled_sanitizers = %w[address cfi integer memory thread undefined].select do |s|
174
+ try_link('int main() {return 0;}', "-Werror -fsanitize=#{s}")
175
+ end
176
+ abort "-----\nCould not enable any sanitizers!\n-----" if enabled_sanitizers.empty?
106
177
  when String
107
- # The user gave us a value so use it
108
- rpath_flags = " -Wl,-rpath,#{explicit_rpath}"
109
- warn "-----\nSetting mysql rpath to #{explicit_rpath}\n-----"
110
- $LDFLAGS << rpath_flags
178
+ # Figure out which sanitizers are supported
179
+ enabled_sanitizers, disabled_sanitizers = sanitizers.split(',').partition do |s|
180
+ try_link('int main() {return 0;}', "-Werror -fsanitize=#{s}")
181
+ end
182
+ end
183
+
184
+ unless disabled_sanitizers.empty?
185
+ abort "-----\nCould not enable requested sanitizers: #{disabled_sanitizers.join(',')}\n-----"
186
+ end
187
+
188
+ unless enabled_sanitizers.empty?
189
+ warn "-----\nEnabling sanitizers: #{enabled_sanitizers.join(',')}\n-----"
190
+ enabled_sanitizers.each do |s|
191
+ # address sanitizer requires runtime support
192
+ if s == 'address' # rubocop:disable Style/IfUnlessModifier
193
+ have_library('asan') || $LDFLAGS << ' -fsanitize=address'
194
+ end
195
+ $CFLAGS << " -fsanitize=#{s}"
196
+ end
197
+ # Options for line numbers in backtraces
198
+ $CFLAGS << ' -g -fno-omit-frame-pointer'
199
+ end
200
+
201
+ if RUBY_PLATFORM =~ /mswin|mingw/ && !defined?(RubyInstaller)
202
+ # Build libmysql.a interface link library
203
+ require 'rake'
204
+
205
+ # Build libmysql.a interface link library
206
+ # Use rake to rebuild only if these files change
207
+ deffile = File.expand_path('../../../support/libmysql.def', __FILE__)
208
+ libfile = File.expand_path(File.join(rpath_dir, 'libmysql.lib'))
209
+ file 'libmysql.a' => [deffile, libfile] do
210
+ when_writing 'building libmysql.a' do
211
+ # Ruby kindly shows us where dllwrap is, but that tool does more than we want.
212
+ # Maybe in the future Ruby could provide RbConfig::CONFIG['DLLTOOL'] directly.
213
+ dlltool = RbConfig::CONFIG['DLLWRAP'].gsub('dllwrap', 'dlltool')
214
+ sh dlltool, '--kill-at',
215
+ '--dllname', 'libmysql.dll',
216
+ '--output-lib', 'libmysql.a',
217
+ '--input-def', deffile, libfile
218
+ end
219
+ end
220
+
221
+ Rake::Task['libmysql.a'].invoke
222
+ $LOCAL_LIBS << ' ' << 'libmysql.a'
223
+
224
+ # Make sure the generated interface library works (if cross-compiling, trust without verifying)
225
+ unless RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
226
+ abort "-----\nCannot find libmysql.a\n-----" unless have_library('libmysql')
227
+ abort "-----\nCannot link to libmysql.a (my_init)\n-----" unless have_func('my_init')
228
+ end
229
+
230
+ # Vendor libmysql.dll
231
+ vendordir = File.expand_path('../../../vendor/', __FILE__)
232
+ directory vendordir
233
+
234
+ vendordll = File.join(vendordir, 'libmysql.dll')
235
+ dllfile = File.expand_path(File.join(rpath_dir, 'libmysql.dll'))
236
+ file vendordll => [dllfile, vendordir] do
237
+ when_writing 'copying libmysql.dll' do
238
+ cp dllfile, vendordll
239
+ end
240
+ end
241
+
242
+ # Copy libmysql.dll to the local vendor directory by default
243
+ if arg_config('--no-vendor-libmysql')
244
+ # Fine, don't.
245
+ puts "--no-vendor-libmysql"
246
+ else # Default: arg_config('--vendor-libmysql')
247
+ # Let's do it!
248
+ Rake::Task[vendordll].invoke
249
+ end
111
250
  else
112
- if libdir = rpath_dir[%r{(-L)?(/[^ ]+)}, 2]
113
- rpath_flags = " -Wl,-rpath,#{libdir}"
114
- if RbConfig::CONFIG["RPATHFLAG"].to_s.empty? && try_link('int main() {return 0;}', rpath_flags)
115
- # Usually Ruby sets RPATHFLAG the right way for each system, but not on OS X.
116
- warn "-----\nSetting rpath to #{libdir}\n-----"
117
- $LDFLAGS << rpath_flags
118
- else
119
- if RbConfig::CONFIG["RPATHFLAG"].to_s.empty?
120
- # If we got here because try_link failed, warn the user
121
- warn "-----\nDon't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load\n-----"
251
+ case explicit_rpath = with_config('mysql-rpath')
252
+ when true
253
+ abort "-----\nOption --with-mysql-rpath must have an argument\n-----"
254
+ when false
255
+ warn "-----\nOption --with-mysql-rpath has been disabled at your request\n-----"
256
+ when String
257
+ # The user gave us a value so use it
258
+ rpath_flags = " -Wl,-rpath,#{explicit_rpath}"
259
+ warn "-----\nSetting mysql rpath to #{explicit_rpath}\n-----"
260
+ $LDFLAGS << rpath_flags
261
+ else
262
+ if (libdir = rpath_dir[%r{(-L)?(/[^ ]+)}, 2])
263
+ rpath_flags = " -Wl,-rpath,#{libdir}"
264
+ if RbConfig::CONFIG["RPATHFLAG"].to_s.empty? && try_link('int main() {return 0;}', rpath_flags)
265
+ # Usually Ruby sets RPATHFLAG the right way for each system, but not on OS X.
266
+ warn "-----\nSetting rpath to #{libdir}\n-----"
267
+ $LDFLAGS << rpath_flags
268
+ else
269
+ if RbConfig::CONFIG["RPATHFLAG"].to_s.empty?
270
+ # If we got here because try_link failed, warn the user
271
+ warn "-----\nDon't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load\n-----"
272
+ end
273
+ # Make sure that LIBPATH gets set if we didn't explicitly set the rpath.
274
+ warn "-----\nSetting libpath to #{libdir}\n-----"
275
+ $LIBPATH << libdir unless $LIBPATH.include?(libdir)
122
276
  end
123
- # Make sure that LIBPATH gets set if we didn't explicitly set the rpath.
124
- warn "-----\nSetting libpath to #{libdir}\n-----"
125
- $LIBPATH << libdir unless $LIBPATH.include?(libdir)
126
277
  end
127
278
  end
128
279
  end
data/ext/mysql2/infile.c CHANGED
@@ -56,7 +56,7 @@ mysql2_local_infile_init(void **ptr, const char *filename, void *userdata)
56
56
  * < 0 error
57
57
  */
58
58
  static int
59
- mysql2_local_infile_read(void *ptr, char *buf, uint buf_len)
59
+ mysql2_local_infile_read(void *ptr, char *buf, unsigned int buf_len)
60
60
  {
61
61
  int count;
62
62
  mysql2_local_infile_data *data = (mysql2_local_infile_data *)ptr;
@@ -95,7 +95,7 @@ mysql2_local_infile_end(void *ptr)
95
95
  * Error message number (see http://dev.mysql.com/doc/refman/5.0/en/error-messages-client.html)
96
96
  */
97
97
  static int
98
- mysql2_local_infile_error(void *ptr, char *error_msg, uint error_msg_len)
98
+ mysql2_local_infile_error(void *ptr, char *error_msg, unsigned int error_msg_len)
99
99
  {
100
100
  mysql2_local_infile_data *data = (mysql2_local_infile_data *) ptr;
101
101
 
@@ -1,12 +1,19 @@
1
1
  #include <mysql2_ext.h>
2
2
 
3
- VALUE mMysql2, cMysql2Error;
3
+ VALUE mMysql2, cMysql2Error, cMysql2TimeoutError;
4
4
 
5
5
  /* Ruby Extension initializer */
6
6
  void Init_mysql2() {
7
- mMysql2 = rb_define_module("Mysql2");
7
+ mMysql2 = rb_define_module("Mysql2");
8
+ rb_global_variable(&mMysql2);
9
+
8
10
  cMysql2Error = rb_const_get(mMysql2, rb_intern("Error"));
11
+ rb_global_variable(&cMysql2Error);
12
+
13
+ cMysql2TimeoutError = rb_const_get(cMysql2Error, rb_intern("TimeoutError"));
14
+ rb_global_variable(&cMysql2TimeoutError);
9
15
 
10
16
  init_mysql2_client();
11
17
  init_mysql2_result();
18
+ init_mysql2_statement();
12
19
  }
@@ -1,44 +1,43 @@
1
1
  #ifndef MYSQL2_EXT
2
2
  #define MYSQL2_EXT
3
3
 
4
+ void Init_mysql2(void);
5
+
4
6
  /* tell rbx not to use it's caching compat layer
5
7
  by doing this we're making a promise to RBX that
6
8
  we'll never modify the pointers we get back from RSTRING_PTR */
7
9
  #define RSTRING_NOT_MODIFIED
8
10
  #include <ruby.h>
9
11
 
10
- #ifndef HAVE_UINT
11
- #define HAVE_UINT
12
- typedef unsigned short ushort;
13
- typedef unsigned int uint;
14
- #endif
15
-
16
12
  #ifdef HAVE_MYSQL_H
17
13
  #include <mysql.h>
18
- #include <mysql_com.h>
19
14
  #include <errmsg.h>
20
- #include <mysqld_error.h>
21
15
  #else
22
16
  #include <mysql/mysql.h>
23
- #include <mysql/mysql_com.h>
24
17
  #include <mysql/errmsg.h>
25
- #include <mysql/mysqld_error.h>
26
18
  #endif
27
19
 
28
- #ifdef HAVE_RUBY_ENCODING_H
29
20
  #include <ruby/encoding.h>
30
- #endif
31
- #ifdef HAVE_RUBY_THREAD_H
32
21
  #include <ruby/thread.h>
33
- #endif
34
22
 
35
23
  #if defined(__GNUC__) && (__GNUC__ >= 3)
24
+ #define RB_MYSQL_NORETURN __attribute__ ((noreturn))
36
25
  #define RB_MYSQL_UNUSED __attribute__ ((unused))
37
26
  #else
27
+ #define RB_MYSQL_NORETURN
38
28
  #define RB_MYSQL_UNUSED
39
29
  #endif
40
30
 
31
+ /* MySQL 8.0 replaces my_bool with C99 bool. Earlier versions of MySQL had
32
+ * a typedef to char. Gem users reported failures on big endian systems when
33
+ * using C99 bool types with older MySQLs due to mismatched behavior. */
34
+ #ifndef HAVE_TYPE_MY_BOOL
35
+ #include <stdbool.h>
36
+ typedef bool my_bool;
37
+ #endif
38
+
41
39
  #include <client.h>
40
+ #include <statement.h>
42
41
  #include <result.h>
43
42
  #include <infile.h>
44
43