trilogy 2.12.6 → 2.13.0

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: d7bf5494671a9331547a73c7513cfe587b1a9300fe4bb96f70fd0957484c1ef4
4
- data.tar.gz: e5f8c4c57b5c6cddfe3e574e3727d662b056211885456520854b69a6213708b6
3
+ metadata.gz: aa039c6b0e08712590ea5c50bea7c9a6418d56b1878b3c2935568248d0c5deb5
4
+ data.tar.gz: f76d5315bd82dd00a58c43d7de51885448ba3b72fb0e2adcca3fd132e4bd1163
5
5
  SHA512:
6
- metadata.gz: 9ff46c61895e2a829c52faeb8d01d40c19f87106e121d3f92c344e8c66249ecc27de44fb43ab689dfc84f0d86e4508701c2b753be765852aebad8566a5d9daaf
7
- data.tar.gz: 573a75c06969df47df0a0c73b8888919aebbdec81004644bd47ad5cfab579f9a967fecfbce782188aeb81e2fc7ad63167b1f0f150eb0e8dfc252f3039f99631c
6
+ metadata.gz: 45cb57bc1614f81b1f477e987936b00ba97ec75acd4b88d4e86640848442daa76993cb14fe6b39bccf76c3e7a5a1dc6f86c37d5af96e179c0889c9e50356cac9
7
+ data.tar.gz: 5da626807137fe79611a85157b4537fde0c7451c047074ddac514732ecfed04f0e665b9e432607aa52fb73830bad176dd6d640fb2ab87019b71e46a44fea3b52
data/README.md CHANGED
@@ -86,3 +86,5 @@ differences:
86
86
  the transcoding step up to the caller.
87
87
  * There is no `as` query option. Calling `Trilogy::Result#each` will yield an array
88
88
  of row values. If you want a hash you should use `Trilogy::Result#each_hash`.
89
+ * The default `connect_timeout` is 5 seconds, while mysql2 defaults to 120 seconds.
90
+ Pass `connect_timeout: nil` to disable the timeout.
@@ -607,6 +607,18 @@ static int rb_io_descriptor(VALUE io)
607
607
  }
608
608
  #endif
609
609
 
610
+ static inline VALUE config_set_str(VALUE opts, ID key, char **member)
611
+ {
612
+ VALUE val = rb_hash_aref(opts, ID2SYM(key));
613
+ if (NIL_P(val)) {
614
+ return Qfalse;
615
+ }
616
+
617
+ Check_Type(val, T_STRING);
618
+ *member = StringValueCStr(val);
619
+ return val;
620
+ }
621
+
610
622
  static VALUE rb_trilogy_connect(VALUE self, VALUE raw_socket, VALUE encoding, VALUE charset, VALUE opts)
611
623
  {
612
624
  struct trilogy_ctx *ctx = get_ctx(self);
@@ -662,10 +674,10 @@ static VALUE rb_trilogy_connect(VALUE self, VALUE raw_socket, VALUE encoding, VA
662
674
  connopt.max_allowed_packet = NUM2SIZET(val);
663
675
  }
664
676
 
665
- if ((val = rb_hash_lookup(opts, ID2SYM(id_host))) != Qnil) {
666
- Check_Type(val, T_STRING);
677
+ VALUE host = config_set_str(opts, id_host, &connopt.hostname);
678
+ VALUE path;
667
679
 
668
- connopt.hostname = StringValueCStr(val);
680
+ if (host) {
669
681
  connopt.port = 3306;
670
682
 
671
683
  if ((val = rb_hash_lookup(opts, ID2SYM(id_port))) != Qnil) {
@@ -675,26 +687,17 @@ static VALUE rb_trilogy_connect(VALUE self, VALUE raw_socket, VALUE encoding, VA
675
687
  } else {
676
688
  connopt.path = (char *)"/tmp/mysql.sock";
677
689
 
678
- if ((val = rb_hash_lookup(opts, ID2SYM(id_socket))) != Qnil) {
679
- Check_Type(val, T_STRING);
680
- connopt.path = StringValueCStr(val);
681
- }
682
- }
683
-
684
- if ((val = rb_hash_aref(opts, ID2SYM(id_username))) != Qnil) {
685
- Check_Type(val, T_STRING);
686
- connopt.username = StringValueCStr(val);
690
+ path = config_set_str(opts, id_socket, &connopt.path);
687
691
  }
688
692
 
689
- if ((val = rb_hash_aref(opts, ID2SYM(id_password))) != Qnil) {
690
- Check_Type(val, T_STRING);
691
- connopt.password = RSTRING_PTR(val);
692
- connopt.password_len = RSTRING_LEN(val);
693
+ VALUE username = config_set_str(opts, id_username, &connopt.username);
694
+ VALUE password = config_set_str(opts, id_password, &connopt.password);
695
+ if (password) {
696
+ connopt.password_len = RSTRING_LEN(password);
693
697
  }
694
698
 
695
- if ((val = rb_hash_aref(opts, ID2SYM(id_database))) != Qnil) {
696
- Check_Type(val, T_STRING);
697
- connopt.database = StringValueCStr(val);
699
+ VALUE database = config_set_str(opts, id_database, &connopt.database);
700
+ if (database) {
698
701
  connopt.flags |= TRILOGY_CAPABILITIES_CONNECT_WITH_DB;
699
702
  }
700
703
 
@@ -714,45 +717,14 @@ static VALUE rb_trilogy_connect(VALUE self, VALUE raw_socket, VALUE encoding, VA
714
717
  connopt.flags |= TRILOGY_CAPABILITIES_MULTI_STATEMENTS;
715
718
  }
716
719
 
717
- if ((val = rb_hash_aref(opts, ID2SYM(id_ssl_ca))) != Qnil) {
718
- Check_Type(val, T_STRING);
719
- connopt.ssl_ca = StringValueCStr(val);
720
- }
721
-
722
- if ((val = rb_hash_aref(opts, ID2SYM(id_ssl_capath))) != Qnil) {
723
- Check_Type(val, T_STRING);
724
- connopt.ssl_capath = StringValueCStr(val);
725
- }
726
-
727
- if ((val = rb_hash_aref(opts, ID2SYM(id_ssl_cert))) != Qnil) {
728
- Check_Type(val, T_STRING);
729
- connopt.ssl_cert = StringValueCStr(val);
730
- }
731
-
732
- if ((val = rb_hash_aref(opts, ID2SYM(id_ssl_cipher))) != Qnil) {
733
- Check_Type(val, T_STRING);
734
- connopt.ssl_cipher = StringValueCStr(val);
735
- }
736
-
737
- if ((val = rb_hash_aref(opts, ID2SYM(id_ssl_crl))) != Qnil) {
738
- Check_Type(val, T_STRING);
739
- connopt.ssl_crl = StringValueCStr(val);
740
- }
741
-
742
- if ((val = rb_hash_aref(opts, ID2SYM(id_ssl_crlpath))) != Qnil) {
743
- Check_Type(val, T_STRING);
744
- connopt.ssl_crlpath = StringValueCStr(val);
745
- }
746
-
747
- if ((val = rb_hash_aref(opts, ID2SYM(id_ssl_key))) != Qnil) {
748
- Check_Type(val, T_STRING);
749
- connopt.ssl_key = StringValueCStr(val);
750
- }
751
-
752
- if ((val = rb_hash_aref(opts, ID2SYM(id_tls_ciphersuites))) != Qnil) {
753
- Check_Type(val, T_STRING);
754
- connopt.tls_ciphersuites = StringValueCStr(val);
755
- }
720
+ VALUE ssl_ca = config_set_str(opts, id_ssl_ca, &connopt.ssl_ca);
721
+ VALUE ssl_capath = config_set_str(opts, id_ssl_capath, &connopt.ssl_capath);
722
+ VALUE ssl_cert = config_set_str(opts, id_ssl_cert, &connopt.ssl_cert);
723
+ VALUE ssl_cipher = config_set_str(opts, id_ssl_cipher, &connopt.ssl_cipher);
724
+ VALUE ssl_crl = config_set_str(opts, id_ssl_crl, &connopt.ssl_crl);
725
+ VALUE ssl_crlpath = config_set_str(opts, id_ssl_crlpath, &connopt.ssl_crlpath);
726
+ VALUE ssl_key = config_set_str(opts, id_ssl_key, &connopt.ssl_key);
727
+ VALUE tls_ciphersuites = config_set_str(opts, id_tls_ciphersuites, &connopt.tls_ciphersuites);
756
728
 
757
729
  if ((val = rb_hash_aref(opts, ID2SYM(id_tls_min_version))) != Qnil) {
758
730
  Check_Type(val, T_FIXNUM);
@@ -791,6 +763,21 @@ static VALUE rb_trilogy_connect(VALUE self, VALUE raw_socket, VALUE encoding, VA
791
763
 
792
764
  rb_trilogy_release_buffer(ctx);
793
765
 
766
+ // Ensure all our strings are pinned.
767
+ RB_GC_GUARD(host);
768
+ RB_GC_GUARD(username);
769
+ RB_GC_GUARD(password);
770
+ RB_GC_GUARD(path);
771
+ RB_GC_GUARD(database);
772
+ RB_GC_GUARD(ssl_ca);
773
+ RB_GC_GUARD(ssl_capath);
774
+ RB_GC_GUARD(ssl_cert);
775
+ RB_GC_GUARD(ssl_cipher);
776
+ RB_GC_GUARD(ssl_crl);
777
+ RB_GC_GUARD(ssl_crlpath);
778
+ RB_GC_GUARD(ssl_key);
779
+ RB_GC_GUARD(tls_ciphersuites);
780
+
794
781
  return Qnil;
795
782
  }
796
783
 
@@ -799,6 +786,7 @@ static VALUE rb_trilogy_change_db(VALUE self, VALUE database)
799
786
  struct trilogy_ctx *ctx = get_open_ctx(self);
800
787
 
801
788
  StringValue(database);
789
+ database = rb_str_new_frozen(database);
802
790
 
803
791
  rb_trilogy_acquire_buffer(ctx);
804
792
 
@@ -830,6 +818,7 @@ static VALUE rb_trilogy_change_db(VALUE self, VALUE database)
830
818
  }
831
819
 
832
820
  rb_trilogy_release_buffer(ctx);
821
+ RB_GC_GUARD(database);
833
822
 
834
823
  return Qtrue;
835
824
  }
@@ -1140,6 +1129,7 @@ static VALUE rb_trilogy_query(VALUE self, VALUE query)
1140
1129
 
1141
1130
  StringValue(query);
1142
1131
  query = rb_str_export_to_enc(query, ctx->encoding);
1132
+ query = rb_str_new_frozen(query);
1143
1133
 
1144
1134
  rb_trilogy_acquire_buffer(ctx);
1145
1135
 
@@ -1153,6 +1143,7 @@ static VALUE rb_trilogy_query(VALUE self, VALUE query)
1153
1143
  handle_trilogy_error(ctx, rc, "trilogy_query_send");
1154
1144
  }
1155
1145
 
1146
+ RB_GC_GUARD(query);
1156
1147
  return execute_read_query_response(ctx);
1157
1148
  }
1158
1149
 
@@ -1196,9 +1187,11 @@ static VALUE rb_trilogy_ping(VALUE self)
1196
1187
  static VALUE rb_trilogy_escape(VALUE self, VALUE str)
1197
1188
  {
1198
1189
  struct trilogy_ctx *ctx = get_open_ctx(self);
1199
- rb_encoding *str_enc = rb_enc_get(str);
1200
1190
 
1201
1191
  StringValue(str);
1192
+ str = rb_str_new_frozen(str);
1193
+
1194
+ rb_encoding *str_enc = rb_enc_get(str);
1202
1195
 
1203
1196
  if (!rb_enc_asciicompat(str_enc)) {
1204
1197
  rb_raise(rb_eEncCompatError, "input string must be ASCII-compatible");
@@ -1219,6 +1212,7 @@ static VALUE rb_trilogy_escape(VALUE self, VALUE str)
1219
1212
 
1220
1213
  rb_trilogy_release_buffer(ctx);
1221
1214
 
1215
+ RB_GC_GUARD(str);
1222
1216
  return escaped_string;
1223
1217
  }
1224
1218
 
@@ -237,7 +237,7 @@ int trilogy_stmt_bind_data(trilogy_conn_t *conn, trilogy_stmt_t *stmt, uint16_t
237
237
 
238
238
  /* trilogy_stmt_read_full_row - Read a row from the prepared statement execute response.
239
239
  *
240
- * This should only be called after a sucessful call to trilogy_stmt_execute.
240
+ * This should only be called after a successful call to trilogy_stmt_execute.
241
241
  * You should continue calling this until TRILOGY_EOF is returned. Denoting the end
242
242
  * of the result set.
243
243
  *
@@ -68,7 +68,7 @@ int trilogy_buffer_write(trilogy_buffer_t *buffer, const uint8_t *ptr, size_t le
68
68
 
69
69
  /* trilogy_buffer_free - Free an trilogy_buffer_t's underlying storage. The buffer
70
70
  * must be re-initialized with trilogy_buffer_init if it is to be reused. Any
71
- * operations performed on an unintialized or freed buffer are undefined.
71
+ * operations performed on an uninitialized or freed buffer are undefined.
72
72
  *
73
73
  * buffer - An initialized trilogy_buffer_t.
74
74
  */
@@ -607,7 +607,7 @@ void trilogy_free(trilogy_conn_t *conn);
607
607
  * conn - A pre-initialized trilogy_conn_t pointer.
608
608
  *
609
609
  * Return values:
610
- * TRILOGY_OK - The connection was successfuly discarded and freed.
610
+ * TRILOGY_OK - The connection was successfully discarded and freed.
611
611
  * TRILOGY_SYSERR - A system error occurred, check errno. The connection wasn't freed.
612
612
  */
613
613
  int trilogy_discard(trilogy_conn_t *conn);
@@ -665,7 +665,7 @@ int trilogy_stmt_prepare_recv(trilogy_conn_t *conn, trilogy_stmt_t *stmt_out);
665
665
 
666
666
  /* trilogy_stmt_bind_data_send - Send a prepared statement bind long data command to the server.
667
667
  *
668
- * There is no pairing `trilogy_stmt_bind_data_recv` fucntion to this one because the server
668
+ * There is no pairing `trilogy_stmt_bind_data_recv` function to this one because the server
669
669
  * doesn't send a response to this command.
670
670
  *
671
671
  * conn - A connected trilogy_conn_t pointer. Using a disconnected trilogy_conn_t is
@@ -734,7 +734,7 @@ int trilogy_stmt_execute_recv(trilogy_conn_t *conn, uint64_t *column_count_out);
734
734
 
735
735
  /* trilogy_stmt_read_row - Read a row from the prepared statement execute response.
736
736
  *
737
- * This should only be called after a sucessful call to trilogy_stmt_execute_recv.
737
+ * This should only be called after a successful call to trilogy_stmt_execute_recv.
738
738
  * You should continue calling this until TRILOGY_EOF is returned. Denoting the end
739
739
  * of the result set.
740
740
  *
@@ -809,7 +809,7 @@ int trilogy_stmt_reset_recv(trilogy_conn_t *conn);
809
809
 
810
810
  /* trilogy_stmt_close_send - Send a prepared statement close command to the server.
811
811
  *
812
- * There is no pairing `trilogy_stmt_close_recv` fucntion to this one because the server
812
+ * There is no pairing `trilogy_stmt_close_recv` function to this one because the server
813
813
  * doesn't send a response to this command.
814
814
  *
815
815
  * conn - A connected trilogy_conn_t pointer. Using a disconnected trilogy_conn_t is
@@ -317,7 +317,7 @@ typedef enum {
317
317
  /* The column is part of a primary key. \
318
318
  */ \
319
319
  XX(TRILOGY_COLUMN_FLAG_PRI_KEY, 0x2) \
320
- /* The column has the `UNIQUE` flag set. Requring all values to be unique. \
320
+ /* The column has the `UNIQUE` flag set. Requiring all values to be unique. \
321
321
  */ \
322
322
  XX(TRILOGY_COLUMN_FLAG_UNIQUE_KEY, 0x4) \
323
323
  /* The column is part of a key. \
@@ -889,7 +889,7 @@ int trilogy_parse_ok_packet(const uint8_t *buff, size_t len, uint32_t capabiliti
889
889
  /* trilogy_parse_eof_packet - Parse an EOF packet.
890
890
  *
891
891
  * buff - A pointer to the buffer containing the EOF packet data.
892
- * len - The lenght of buff in bytes.
892
+ * len - The length of buff in bytes.
893
893
  * capabilities - A bitmask of TRILOGY_CAPABILITIES_t flags.
894
894
  * out_packet - Out parameter; A pointer to a pre-allocated
895
895
  * trilogy_eof_packet_t.
@@ -567,7 +567,7 @@ int trilogy_build_auth_packet(trilogy_builder_t *builder, const char *user, cons
567
567
  }
568
568
 
569
569
  if (pass_len > 0) {
570
- // Fallback to te default unless we have SHA2 requested
570
+ // Fallback to the default unless we have SHA2 requested
571
571
  if (!strcmp("caching_sha2_password", auth_plugin)) {
572
572
  trilogy_pack_scramble_sha2_hash(scramble, pass, pass_len, auth_response, &auth_response_len);
573
573
  } else {
@@ -1,3 +1,3 @@
1
1
  class Trilogy
2
- VERSION = "2.12.6"
2
+ VERSION = "2.13.0"
3
3
  end
data/lib/trilogy.rb CHANGED
@@ -22,15 +22,22 @@ class Trilogy
22
22
  super
23
23
  end
24
24
 
25
+ NEVER = { Object => :never }.freeze
26
+ IMMEDIATE = { Object => :immediate }.freeze
27
+
25
28
  synchronized_methods = Trilogy.public_instance_methods(false) - %i(closed? server_version)
26
29
  source = synchronized_methods.flat_map do |method|
27
30
  [
28
31
  "def #{method}(...)",
29
- "raise SynchronizationError unless @mutex.try_lock",
30
- "begin",
31
- "super",
32
- "ensure",
33
- "@mutex.unlock",
32
+ "Thread.handle_interrupt(NEVER) do",
33
+ "raise SynchronizationError unless @mutex.try_lock",
34
+ "begin",
35
+ "Thread.handle_interrupt(IMMEDIATE) do",
36
+ "super",
37
+ "end",
38
+ "ensure",
39
+ "@mutex.unlock",
40
+ "end",
34
41
  "end",
35
42
  "end",
36
43
  ]
@@ -52,7 +59,7 @@ class Trilogy
52
59
  begin
53
60
  if host = options[:host]
54
61
  port = options[:port] || 3306
55
- connect_timeout = options[:connect_timeout] || options[:write_timeout]
62
+ connect_timeout = options.fetch(:connect_timeout, 5) || options[:write_timeout]
56
63
 
57
64
  socket = TCPSocket.new(host, port, connect_timeout: connect_timeout)
58
65
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trilogy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.6
4
+ version: 2.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Engineering
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubygems_version: 4.0.12
90
+ rubygems_version: 4.0.6
91
91
  specification_version: 4
92
92
  summary: A friendly MySQL-compatible library for Ruby, binding to libtrilogy
93
93
  test_files: []