ox 2.14.11 → 2.14.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a654851f11a761fdb77beb9cb4ec9ae07b4697cec9a4c5578a973a344779ca97
4
- data.tar.gz: b4b004cc4fd90e3c52e142bd4007c471515a520d52a42ca2d81f332c11e6b2ba
3
+ metadata.gz: f9742d803f0730d6e9724d0f08809ec291b474beae8e966cf3b9ab3c95e165fa
4
+ data.tar.gz: 102f6dc50ee242f5a7cbb4e8395aa4004d826679b5b02f0e9734d3e8d206d7ec
5
5
  SHA512:
6
- metadata.gz: 6b0595691afa3021e1abada2fd0fc4fb21992a10155f744846b01eb40bd74e33bf52041db37ec502b3f916295b64bde60816c20d99ed9954633342d035225d8a
7
- data.tar.gz: e38010c8dcf091b983d17774464bd727a0f33538548d6b5d1820c6d043ba602d83552837a4ce4dd963c554ec19657475c21add9246323e5d5a9fbd7773c20e55
6
+ metadata.gz: 754fe3197d3944d4b398ba0334d62bc45d066448885e9a47ac8216c0a292203f273c4f0ab764a3ec4e5e49ebc472282ac89821aa0f03929491c60c659494e02b
7
+ data.tar.gz: 31f01b2ca8b2440511c9eda13fe590937bfd266173d83befcc81e228c0e8516545a29369755f1575c2e8bdb11aac791e463a397035fafed8e13848a23c8fb255
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  All changes to the Ox gem are documented here. Releases follow semantic versioning.
4
4
 
5
+ ## [2.14.13] - 2023-01-16
6
+
7
+ ### Fixed
8
+
9
+ - Fixed the intern cache to handle symbol memory changes.
10
+
11
+ ## [2.14.12] - 2022-12-27
12
+
13
+ ### Fixed
14
+
15
+ - Updated to support Ruby 3.2.
16
+
5
17
  ## [2.14.11] - 2022-03-31
6
18
 
7
19
  ### Fixed
data/ext/ox/builder.c CHANGED
@@ -10,6 +10,7 @@
10
10
 
11
11
  #include "ruby.h"
12
12
  #include "ruby/encoding.h"
13
+ #include "ruby/version.h"
13
14
  #include "ox.h"
14
15
  #include "buf.h"
15
16
  #include "err.h"
@@ -881,6 +882,35 @@ builder_column(VALUE self) {
881
882
  return LONG2NUM(((Builder)DATA_PTR(self))->col);
882
883
  }
883
884
 
885
+ /* call-seq: indent()
886
+ *
887
+ * Returns the indentation level
888
+ */
889
+ static VALUE
890
+ builder_get_indent(VALUE self) {
891
+ return INT2NUM(((Builder)DATA_PTR(self))->indent);
892
+ }
893
+
894
+ /* call-seq: indent=(indent)
895
+ *
896
+ * Sets the indentation level
897
+ *
898
+ * - +indent+ (Fixnum) indentaion level, negative values excludes terminating newline
899
+ */
900
+ static VALUE
901
+ builder_set_indent(VALUE self, VALUE indent) {
902
+ #ifdef RUBY_INTEGER_UNIFICATION
903
+ if (rb_cInteger != rb_obj_class(indent)) {
904
+ #else
905
+ if (rb_cFixnum != rb_obj_class(indent)) {
906
+ #endif
907
+ rb_raise(ox_parse_error_class, "indent must be a fixnum.\n");
908
+ }
909
+
910
+ ((Builder)DATA_PTR(self))->indent = NUM2INT(indent);
911
+ return Qnil;
912
+ }
913
+
884
914
  /* call-seq: pos()
885
915
  *
886
916
  * Returns the number of bytes written.
@@ -923,6 +953,9 @@ ox_init_builder(VALUE ox) {
923
953
  ox = rb_define_module("Ox");
924
954
  #endif
925
955
  builder_class = rb_define_class_under(ox, "Builder", rb_cObject);
956
+ #if RUBY_API_VERSION_CODE >= 30200
957
+ rb_undef_alloc_func(builder_class);
958
+ #endif
926
959
  rb_define_module_function(builder_class, "new", builder_new, -1);
927
960
  rb_define_module_function(builder_class, "file", builder_file, -1);
928
961
  rb_define_module_function(builder_class, "io", builder_io, -1);
@@ -940,4 +973,6 @@ ox_init_builder(VALUE ox) {
940
973
  rb_define_method(builder_class, "line", builder_line, 0);
941
974
  rb_define_method(builder_class, "column", builder_column, 0);
942
975
  rb_define_method(builder_class, "pos", builder_pos, 0);
976
+ rb_define_method(builder_class, "indent", builder_get_indent, 0);
977
+ rb_define_method(builder_class, "indent=", builder_set_indent, 1);
943
978
  }
data/ext/ox/hash_load.c CHANGED
@@ -35,7 +35,7 @@ mark_value(PInfo pi, VALUE val) {
35
35
  pi->mark_size = MARK_INC;
36
36
  } else if (pi->mark_size <= pi->mark_cnt) {
37
37
  pi->mark_size += MARK_INC;
38
- pi->marked = REALLOC_N(pi->marked, VALUE, pi->mark_size);
38
+ REALLOC_N(pi->marked, VALUE, pi->mark_size);
39
39
  }
40
40
  pi->marked[pi->mark_cnt] = val;
41
41
  pi->mark_cnt++;
data/ext/ox/intern.c CHANGED
@@ -5,6 +5,8 @@
5
5
 
6
6
  #include <stdint.h>
7
7
 
8
+ #include "ruby/version.h"
9
+
8
10
  #include "cache.h"
9
11
  #include "ox.h"
10
12
 
@@ -68,6 +70,9 @@ static VALUE form_id(const char *str, size_t len) {
68
70
 
69
71
  void ox_hash_init() {
70
72
  VALUE cache_class = rb_define_class_under(Ox, "Cache", rb_cObject);
73
+ #if RUBY_API_VERSION_CODE >= 30200
74
+ rb_undef_alloc_func(cache_class);
75
+ #endif
71
76
 
72
77
  ox_str_cache = ox_cache_create(0, form_str, true, false);
73
78
  ox_str_cache_obj = Data_Wrap_Struct(cache_class, ox_cache_mark, ox_cache_free, ox_str_cache);
data/ext/ox/sax.c CHANGED
@@ -762,6 +762,7 @@ CB:
762
762
  */
763
763
  static char read_element_start(SaxDrive dr) {
764
764
  const char *ename = 0;
765
+ size_t nlen;
765
766
  volatile VALUE name = Qnil;
766
767
  char c;
767
768
  int closed;
@@ -790,6 +791,7 @@ static char read_element_start(SaxDrive dr) {
790
791
  0 == strcasecmp("html", dr->buf.str)) {
791
792
  dr->options.hints = ox_hints_html();
792
793
  }
794
+ nlen = dr->buf.tail - dr->buf.str - 1;
793
795
  if (NULL != dr->options.hints) {
794
796
  hint_clear_empty(dr);
795
797
  h = ox_hint_find(dr->options.hints, dr->buf.str);
@@ -810,7 +812,7 @@ static char read_element_start(SaxDrive dr) {
810
812
  if (rb_respond_to(dr->handler, ox_abort_id)) {
811
813
  VALUE args[1];
812
814
 
813
- args[0] = str2sym(dr, dr->buf.str, dr->buf.tail - dr->buf.str - 1, NULL);
815
+ args[0] = str2sym(dr, dr->buf.str, nlen, NULL);
814
816
  rb_funcall2(dr->handler, ox_abort_id, 1, args);
815
817
  }
816
818
  dr->abort = true;
@@ -861,7 +863,7 @@ static char read_element_start(SaxDrive dr) {
861
863
  }
862
864
  }
863
865
  }
864
- name = str2sym(dr, dr->buf.str, dr->buf.tail - dr->buf.str - 1, &ename);
866
+ name = str2sym(dr, dr->buf.str, nlen, &ename);
865
867
  if (dr->has_start_element && 0 >= dr->blocked &&
866
868
  (NULL == h || ActiveOverlay == h->overlay || NestOverlay == h->overlay)) {
867
869
  VALUE args[1];
@@ -894,7 +896,7 @@ static char read_element_start(SaxDrive dr) {
894
896
  } else if (stackless) {
895
897
  end_element_cb(dr, name, pos, line, col, h);
896
898
  } else if (NULL != h && h->jump) {
897
- stack_push(&dr->stack, ename, name, h);
899
+ stack_push(&dr->stack, ename, nlen, name, h);
898
900
  if ('>' != c) {
899
901
  ox_sax_drive_error(dr, WRONG_CHAR "element not closed");
900
902
  return c;
@@ -902,7 +904,7 @@ static char read_element_start(SaxDrive dr) {
902
904
  read_jump(dr, h->name);
903
905
  return '<';
904
906
  } else {
905
- stack_push(&dr->stack, ename, name, h);
907
+ stack_push(&dr->stack, ename, nlen, name, h);
906
908
  }
907
909
  if ('>' != c) {
908
910
  ox_sax_drive_error(dr, WRONG_CHAR "element not closed");
data/ext/ox/sax_as.c CHANGED
@@ -15,6 +15,7 @@
15
15
  #include <time.h>
16
16
 
17
17
  #include "ruby.h"
18
+ #include "ruby/version.h"
18
19
  #include "ox.h"
19
20
  #include "sax.h"
20
21
 
@@ -254,11 +255,16 @@ void
254
255
  ox_sax_define() {
255
256
  #if 0
256
257
  ox = rb_define_module("Ox");
258
+ #if RUBY_API_VERSION_CODE >= 30200
257
259
  sax_module = rb_define_class_under(ox, "Sax", rb_cObject);
260
+ #endif
258
261
  #endif
259
262
  VALUE sax_module = rb_const_get_at(Ox, rb_intern("Sax"));
260
263
 
261
264
  ox_sax_value_class = rb_define_class_under(sax_module, "Value", rb_cObject);
265
+ #if RUBY_API_VERSION_CODE >= 30200
266
+ rb_undef_alloc_func(ox_sax_value_class);
267
+ #endif
262
268
 
263
269
  rb_define_method(ox_sax_value_class, "as_s", sax_value_as_s, 0);
264
270
  rb_define_method(ox_sax_value_class, "as_sym", sax_value_as_sym, 0);
data/ext/ox/sax_stack.h CHANGED
@@ -6,11 +6,16 @@
6
6
  #ifndef OX_SAX_STACK_H
7
7
  #define OX_SAX_STACK_H
8
8
 
9
+ #include <stdlib.h>
10
+
11
+ #include "intern.h"
9
12
  #include "sax_hint.h"
10
13
 
11
14
  #define STACK_INC 32
15
+ #define NV_BUF_MAX 64
12
16
 
13
17
  typedef struct _nv {
18
+ char name_buf[NV_BUF_MAX];
14
19
  const char *name;
15
20
  VALUE val;
16
21
  int childCnt;
@@ -44,7 +49,7 @@ stack_cleanup(NStack stack) {
44
49
  }
45
50
 
46
51
  inline static void
47
- stack_push(NStack stack, const char *name, VALUE val, Hint hint) {
52
+ stack_push(NStack stack, const char *name, size_t nlen, VALUE val, Hint hint) {
48
53
  if (stack->end <= stack->tail) {
49
54
  size_t len = stack->end - stack->head;
50
55
  size_t toff = stack->tail - stack->head;
@@ -58,7 +63,13 @@ stack_push(NStack stack, const char *name, VALUE val, Hint hint) {
58
63
  stack->tail = stack->head + toff;
59
64
  stack->end = stack->head + len + STACK_INC;
60
65
  }
61
- stack->tail->name = name;
66
+ if (NV_BUF_MAX <= nlen) {
67
+ stack->tail->name = ox_strndup(name, nlen);
68
+ } else {
69
+ strncpy(stack->tail->name_buf, name, nlen);
70
+ stack->tail->name_buf[nlen] = '\0';
71
+ stack->tail->name = stack->tail->name_buf;
72
+ }
62
73
  stack->tail->val = val;
63
74
  stack->tail->hint = hint;
64
75
  stack->tail->childCnt = 0;
@@ -77,6 +88,9 @@ inline static Nv
77
88
  stack_pop(NStack stack) {
78
89
  if (stack->head < stack->tail) {
79
90
  stack->tail--;
91
+ if (stack->tail->name != stack->tail->name_buf) {
92
+ free((char*)(stack->tail->name));
93
+ }
80
94
  return stack->tail;
81
95
  }
82
96
  return 0;
data/lib/ox/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Ox
3
3
  # Current version of the module.
4
- VERSION = '2.14.11'
4
+ VERSION = '2.14.13'
5
5
  end
data/lib/ox.rb CHANGED
@@ -76,4 +76,9 @@ require 'ox/document'
76
76
  require 'ox/bag'
77
77
  require 'ox/sax'
78
78
 
79
- require 'ox/ox' # C extension
79
+ # C extension
80
+ begin
81
+ require_relative 'ox.so'
82
+ rescue LoadError
83
+ require 'ox/ox'
84
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ox
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.14.11
4
+ version: 2.14.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-31 00:00:00.000000000 Z
11
+ date: 2023-01-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: "A fast XML parser and object serializer that uses only standard C lib.\n\nOptimized
14
14
  XML (Ox), as the name implies was written to provide speed optimized\nXML handling.