nokolexbor 0.3.1 → 0.3.2

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: 6bfa3062e8718581cd8aabef75f0084a6626bd90301c9db4957ee975215edec1
4
- data.tar.gz: 243f5c217c85750f63bfc0dcb8af575c019d3f2fd920f41769c0affc8a219802
3
+ metadata.gz: e83f343175997fd437b89893ae63b7cc6eaffa86711800a42e8ce64371c03c85
4
+ data.tar.gz: ea272e36f2a37cd5bc3e8e13b3fa8993098503abdaa85299bcf99f59ae484918
5
5
  SHA512:
6
- metadata.gz: e66b390ef696ed5cafa480065e8ac8fc66ce98d86a7cb15f2f59d8acb7df21381942e5fe6f0244e3b9c7bf54787131c5241a49faeaba328eb49e65af0ac3216c
7
- data.tar.gz: d266e2a7c49a202aec4112667807158b54878cc014b42fc32492fc0977c06db76b1a5ded827d9810f2e7966ba3e5068fe54ab89915a4c56e499181ddc190b6d7
6
+ metadata.gz: be0f026e8f2571705f1ae6225ddc4a3b7e78d7108e441a63d8b0988d4d0c91afa7af57ce8c6c318c1f2a5c38ebf00d9190ce29ec27de8e17505250273209d834
7
+ data.tar.gz: 0000f9c78d7743e789c8edc11aaeaf4bf8a75503d0b6631a0a25a9d3c571a56fb424fc69d3e4c2a737d38c4a84c23424cd79a87f4b6f967b749522b217bd1abd
@@ -477,11 +477,10 @@ XMLPUBFUN xmlXPathParserContextPtr XMLCALL
477
477
  XMLPUBFUN void XMLCALL
478
478
  nl_xmlXPathFreeParserContext (xmlXPathParserContextPtr ctxt);
479
479
 
480
- /* TODO: remap to xmlXPathValuePop and Push. */
481
- static xmlXPathObjectPtr XMLCALL
482
- valuePop (xmlXPathParserContextPtr ctxt);
483
- static int XMLCALL
484
- valuePush (xmlXPathParserContextPtr ctxt,
480
+ XMLPUBFUN xmlXPathObjectPtr XMLCALL
481
+ nl_xmlXPathValuePop (xmlXPathParserContextPtr ctxt);
482
+ XMLPUBFUN int XMLCALL
483
+ nl_xmlXPathValuePush (xmlXPathParserContextPtr ctxt,
485
484
  xmlXPathObjectPtr value);
486
485
 
487
486
  XMLPUBFUN xmlXPathObjectPtr XMLCALL
@@ -15,12 +15,110 @@ VALUE cNokolexborXpathContext;
15
15
  VALUE mNokolexborXpath;
16
16
  VALUE cNokolexborXpathSyntaxError;
17
17
 
18
+ static const xmlChar *NOKOGIRI_PREFIX = (const xmlChar *)"nokogiri";
19
+ static const xmlChar *NOKOGIRI_URI = (const xmlChar *)"http://www.nokogiri.org/default_ns/ruby/extensions_functions";
20
+ static const xmlChar *NOKOGIRI_BUILTIN_PREFIX = (const xmlChar *)"nokogiri-builtin";
21
+ static const xmlChar *NOKOGIRI_BUILTIN_URI = (const xmlChar *)"https://www.nokogiri.org/default_ns/ruby/builtins";
22
+
18
23
  static void
19
24
  free_xml_xpath_context(xmlXPathContextPtr ctx)
20
25
  {
21
26
  nl_xmlXPathFreeContext(ctx);
22
27
  }
23
28
 
29
+ /* find a CSS class in an HTML element's `class` attribute */
30
+ static const xmlChar *
31
+ builtin_css_class(const xmlChar *str, const xmlChar *val)
32
+ {
33
+ int val_len;
34
+
35
+ if (str == NULL) {
36
+ return (NULL);
37
+ }
38
+ if (val == NULL) {
39
+ return (NULL);
40
+ }
41
+
42
+ val_len = nl_xmlStrlen(val);
43
+ if (val_len == 0) {
44
+ return (str);
45
+ }
46
+
47
+ while (*str != 0) {
48
+ if ((*str == *val) && !nl_xmlStrncmp(str, val, val_len)) {
49
+ const xmlChar *next_byte = str + val_len;
50
+
51
+ /* only match if the next byte is whitespace or end of string */
52
+ if ((*next_byte == 0) || (IS_BLANK_CH(*next_byte))) {
53
+ return ((const xmlChar *)str);
54
+ }
55
+ }
56
+
57
+ /* advance str to whitespace */
58
+ while ((*str != 0) && !IS_BLANK_CH(*str)) {
59
+ str++;
60
+ }
61
+
62
+ /* advance str to start of next word or end of string */
63
+ while ((*str != 0) && IS_BLANK_CH(*str)) {
64
+ str++;
65
+ }
66
+ }
67
+
68
+ return (NULL);
69
+ }
70
+
71
+ /* xmlXPathFunction to wrap builtin_css_class() */
72
+ static void
73
+ xpath_builtin_css_class(xmlXPathParserContextPtr ctxt, int nargs)
74
+ {
75
+ xmlXPathObjectPtr hay, needle;
76
+
77
+ CHECK_ARITY(2);
78
+
79
+ CAST_TO_STRING;
80
+ needle = nl_xmlXPathValuePop(ctxt);
81
+ if ((needle == NULL) || (needle->type != XPATH_STRING)) {
82
+ nl_xmlXPathFreeObject(needle);
83
+ XP_ERROR(XPATH_INVALID_TYPE);
84
+ }
85
+
86
+ CAST_TO_STRING;
87
+ hay = nl_xmlXPathValuePop(ctxt);
88
+ if ((hay == NULL) || (hay->type != XPATH_STRING)) {
89
+ nl_xmlXPathFreeObject(hay);
90
+ nl_xmlXPathFreeObject(needle);
91
+ XP_ERROR(XPATH_INVALID_TYPE);
92
+ }
93
+
94
+ if (builtin_css_class(hay->stringval, needle->stringval)) {
95
+ nl_xmlXPathValuePush(ctxt, nl_xmlXPathNewBoolean(1));
96
+ } else {
97
+ nl_xmlXPathValuePush(ctxt, nl_xmlXPathNewBoolean(0));
98
+ }
99
+
100
+ nl_xmlXPathFreeObject(hay);
101
+ nl_xmlXPathFreeObject(needle);
102
+ }
103
+
104
+ /* xmlXPathFunction to select nodes whose local name matches, for HTML5 CSS queries that should ignore namespaces */
105
+ static void
106
+ xpath_builtin_local_name_is(xmlXPathParserContextPtr ctxt, int nargs)
107
+ {
108
+ xmlXPathObjectPtr element_name;
109
+ size_t tmp_len;
110
+
111
+ CHECK_ARITY(1);
112
+ CAST_TO_STRING;
113
+ CHECK_TYPE(XPATH_STRING);
114
+ element_name = nl_xmlXPathValuePop(ctxt);
115
+
116
+ const lxb_char_t *node_name = lxb_dom_node_name_qualified(ctxt->context->node, &tmp_len);
117
+ nl_xmlXPathValuePush(ctxt, nl_xmlXPathNewBoolean(nl_xmlStrEqual((xmlChar *)node_name, element_name->stringval)));
118
+
119
+ nl_xmlXPathFreeObject(element_name);
120
+ }
121
+
24
122
  /*
25
123
  * call-seq:
26
124
  * register_ns(prefix, uri)
@@ -228,6 +326,13 @@ nl_xpath_context_new(VALUE klass, VALUE rb_node)
228
326
  ctx = nl_xmlXPathNewContext(node->owner_document);
229
327
  ctx->node = node;
230
328
 
329
+ nl_xmlXPathRegisterNs(ctx, NOKOGIRI_PREFIX, NOKOGIRI_URI);
330
+ nl_xmlXPathRegisterNs(ctx, NOKOGIRI_BUILTIN_PREFIX, NOKOGIRI_BUILTIN_URI);
331
+ nl_xmlXPathRegisterFuncNS(ctx, (const xmlChar *)"css-class", NOKOGIRI_BUILTIN_URI,
332
+ xpath_builtin_css_class);
333
+ nl_xmlXPathRegisterFuncNS(ctx, (const xmlChar *)"local-name-is", NOKOGIRI_BUILTIN_URI,
334
+ xpath_builtin_local_name_is);
335
+
231
336
  self = Data_Wrap_Struct(klass, 0, free_xml_xpath_context, ctx);
232
337
  rb_iv_set(self, "@document", nl_rb_document_get(rb_node));
233
338
 
@@ -54,6 +54,9 @@ void nl_raise_lexbor_error(lxb_status_t error)
54
54
 
55
55
  void Init_nokolexbor(void)
56
56
  {
57
+ #ifndef NOKOLEXBOR_ASAN
58
+ lexbor_memory_setup(ruby_xmalloc, ruby_xrealloc, ruby_xcalloc, ruby_xfree);
59
+ #endif
57
60
  mNokolexbor = rb_define_module("Nokolexbor");
58
61
  eLexborError = rb_define_class_under(mNokolexbor, "LexborError", rb_eStandardError);
59
62
  eLexborSyntaxError = rb_define_class_under(mNokolexbor, "LexborSyntaxError", eLexborError);
@@ -2897,6 +2897,10 @@ valuePop(xmlXPathParserContextPtr ctxt)
2897
2897
  ctxt->valueTab[ctxt->valueNr] = NULL;
2898
2898
  return (ret);
2899
2899
  }
2900
+
2901
+ xmlXPathObjectPtr
2902
+ nl_xmlXPathValuePop(xmlXPathParserContextPtr ctxt) { return valuePop(ctxt); }
2903
+
2900
2904
  /**
2901
2905
  * valuePush:
2902
2906
  * @ctxt: an XPath evaluation context
@@ -2941,6 +2945,9 @@ valuePush(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr value)
2941
2945
  return (ctxt->valueNr++);
2942
2946
  }
2943
2947
 
2948
+ int
2949
+ nl_xmlXPathValuePush(xmlXPathParserContextPtr ctxt, xmlXPathObjectPtr value) { return valuePush(ctxt, value); }
2950
+
2944
2951
  /**
2945
2952
  * nl_xmlXPathPopBoolean:
2946
2953
  * @ctxt: an XPath parser context
@@ -93,5 +93,9 @@ module Nokolexbor
93
93
  head.prepend_child(element)
94
94
  end
95
95
  end
96
+
97
+ private
98
+
99
+ IMPLIED_XPATH_CONTEXTS = ["//"].freeze # :nodoc:
96
100
  end
97
101
  end
@@ -192,6 +192,16 @@ module Nokolexbor
192
192
  at_css_impl(args.join(', '))
193
193
  end
194
194
 
195
+ def nokogiri_css(*args)
196
+ rules, handler, ns, _ = extract_params(args)
197
+
198
+ nokogiri_css_internal(self, rules, handler, ns)
199
+ end
200
+
201
+ def nokogiri_at_css(*args)
202
+ nokogiri_css(*args).first
203
+ end
204
+
195
205
  def xpath(*args)
196
206
  paths, handler, ns, binds = extract_params(args)
197
207
 
@@ -299,6 +309,10 @@ module Nokolexbor
299
309
 
300
310
  private
301
311
 
312
+ def nokogiri_css_internal(node, rules, handler, ns)
313
+ xpath_internal(node, css_rules_to_xpath(rules, ns), handler, ns, nil)
314
+ end
315
+
302
316
  def xpath_internal(node, paths, handler, ns, binds)
303
317
  # document = node.document
304
318
  # return NodeSet.new(document) unless document
@@ -326,6 +340,34 @@ module Nokolexbor
326
340
  ctx.evaluate(path, handler)
327
341
  end
328
342
 
343
+ def css_rules_to_xpath(rules, ns)
344
+ rules.map { |rule| xpath_query_from_css_rule(rule, ns) }
345
+ end
346
+
347
+ def ensure_nokogiri
348
+ unless defined?(Nokogiri) && defined?(Nokogiri::CSS)
349
+ require 'nokogiri'
350
+ end
351
+ rescue LoadError
352
+ fail('nokogiri_css and nokogiri_at_css require Nokogiri to be installed')
353
+ end
354
+
355
+ def xpath_query_from_css_rule(rule, ns)
356
+ ensure_nokogiri
357
+ if defined? Nokogiri::CSS::XPathVisitor::BuiltinsConfig
358
+ visitor = Nokogiri::CSS::XPathVisitor.new(
359
+ builtins: Nokogiri::CSS::XPathVisitor::BuiltinsConfig::OPTIMAL,
360
+ doctype: :html4,
361
+ )
362
+ else
363
+ visitor = Nokogiri::CSS::XPathVisitorOptimallyUseBuiltins.new
364
+ end
365
+ self.class::IMPLIED_XPATH_CONTEXTS.map do |implied_xpath_context|
366
+ Nokogiri::CSS.xpath_for(rule.to_s, { prefix: implied_xpath_context, ns: ns,
367
+ visitor: visitor, })
368
+ end.join(" | ")
369
+ end
370
+
329
371
  def extract_params(params)
330
372
  handler = params.find do |param|
331
373
  ![Hash, String, Symbol].include?(param.class)
@@ -344,5 +386,7 @@ module Nokolexbor
344
386
 
345
387
  [params, handler, ns, binds]
346
388
  end
389
+
390
+ IMPLIED_XPATH_CONTEXTS = [".//"].freeze
347
391
  end
348
- end
392
+ end
@@ -126,6 +126,23 @@ module Nokolexbor
126
126
  end
127
127
  end
128
128
  end
129
+
130
+ def nokogiri_css(*args)
131
+ rules, handler, ns, _ = extract_params(args)
132
+ paths = css_rules_to_xpath(rules, ns)
133
+
134
+ NodeSet.new(@document) do |set|
135
+ each do |node|
136
+ node.send(:xpath_internal, node, paths, handler, ns, nil).each do |inner_node|
137
+ set << inner_node
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+ private
144
+
145
+ IMPLIED_XPATH_CONTEXTS = [".//", "self::"].freeze # :nodoc:
129
146
 
130
147
  end
131
148
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nokolexbor
4
- VERSION = '0.3.1'
4
+ VERSION = '0.3.2'
5
5
  end
@@ -13,7 +13,7 @@ index 2b19f18..5e56181 100644
13
13
  lxb_css_selector_pseudo_element_id_t;
14
14
 
15
15
  diff --git i/source/lexbor/css/selectors/pseudo_res.h w/source/lexbor/css/selectors/pseudo_res.h
16
- index 398d1bb..b35bfab 100644
16
+ index 398d1bb..ddd5f3e 100644
17
17
  --- i/source/lexbor/css/selectors/pseudo_res.h
18
18
  +++ w/source/lexbor/css/selectors/pseudo_res.h
19
19
  @@ -124,7 +124,8 @@ static const lxb_css_selectors_pseudo_data_t lxb_css_selectors_pseudo_data_pseud
@@ -36,7 +36,7 @@ index 398d1bb..b35bfab 100644
36
36
  {"grammar-error", (void *) &lxb_css_selectors_pseudo_data_pseudo_element[LXB_CSS_SELECTOR_PSEUDO_ELEMENT_GRAMMAR_ERROR], 13, 0},
37
37
  {"before", (void *) &lxb_css_selectors_pseudo_data_pseudo_element[LXB_CSS_SELECTOR_PSEUDO_ELEMENT_BEFORE], 6, 0},
38
38
  diff --git i/source/lexbor/selectors/selectors.c w/source/lexbor/selectors/selectors.c
39
- index c2d18ea..84b5b14 100644
39
+ index fef05d3..1ceaa19 100644
40
40
  --- i/source/lexbor/selectors/selectors.c
41
41
  +++ w/source/lexbor/selectors/selectors.c
42
42
  @@ -156,6 +156,12 @@ lxb_selectors_descendant(lxb_selectors_t *selectors, lxb_selectors_entry_t *entr
@@ -91,16 +91,7 @@ index c2d18ea..84b5b14 100644
91
91
 
92
92
  node = node->next;
93
93
  }
94
- @@ -262,6 +286,8 @@ lxb_selectors_sibling(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
95
- {
96
- node = node->next;
97
-
98
- + if (node == NULL) return NULL;
99
- +
100
- do {
101
- if (node->type == LXB_DOM_NODE_TYPE_ELEMENT) {
102
- if (lxb_selectors_match(selectors, entry, selector, node)) {
103
- @@ -290,6 +316,12 @@ lxb_selectors_following(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry
94
+ @@ -289,6 +313,12 @@ lxb_selectors_following(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry
104
95
  {
105
96
  return node;
106
97
  }
@@ -113,7 +104,7 @@ index c2d18ea..84b5b14 100644
113
104
 
114
105
  node = node->next;
115
106
  }
116
- @@ -1429,6 +1461,8 @@ lxb_selectors_pseudo_element(lxb_selectors_t *selectors,
107
+ @@ -1428,6 +1458,8 @@ lxb_selectors_pseudo_element(lxb_selectors_t *selectors,
117
108
  lxb_css_selector_pseudo_t *pseudo = &selector->u.pseudo;
118
109
 
119
110
  switch (pseudo->type) {
@@ -2,7 +2,7 @@ diff --git i/source/lexbor/selectors/selectors.c w/source/lexbor/selectors/selec
2
2
  index c2d18ea..84b5b14 100644
3
3
  --- i/source/lexbor/selectors/selectors.c
4
4
  +++ w/source/lexbor/selectors/selectors.c
5
- @@ -751,7 +783,7 @@ lxb_selectors_match(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
5
+ @@ -750,7 +780,7 @@ lxb_selectors_match(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
6
6
  src = &selector->name;
7
7
 
8
8
  if (trg->length == src->length
@@ -11,7 +11,7 @@ index c2d18ea..84b5b14 100644
11
11
  {
12
12
  return true;
13
13
  }
14
- @@ -766,7 +798,7 @@ lxb_selectors_match(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
14
+ @@ -765,7 +795,7 @@ lxb_selectors_match(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
15
15
  }
16
16
 
17
17
  return lxb_selectors_match_class(element->attr_class->value,
@@ -13,6 +13,10 @@ extern "C" {
13
13
 
14
14
  #include "lexbor/core/def.h"
15
15
 
16
+ typedef void *(*lexbor_memory_malloc_f)(size_t size);
17
+ typedef void *(*lexbor_memory_realloc_f)(void *dst, size_t size);
18
+ typedef void *(*lexbor_memory_calloc_f)(size_t num, size_t size);
19
+ typedef void (*lexbor_memory_free_f)(void *dst);
16
20
 
17
21
  LXB_API void *
18
22
  lexbor_malloc(size_t size);
@@ -26,6 +30,10 @@ lexbor_calloc(size_t num, size_t size);
26
30
  LXB_API void *
27
31
  lexbor_free(void *dst);
28
32
 
33
+ LXB_API lxb_status_t
34
+ lexbor_memory_setup(lexbor_memory_malloc_f new_malloc, lexbor_memory_realloc_f new_realloc,
35
+ lexbor_memory_calloc_f new_calloc, lexbor_memory_free_f new_free);
36
+
29
37
 
30
38
  #ifdef __cplusplus
31
39
  } /* extern "C" */
@@ -6,28 +6,48 @@
6
6
 
7
7
  #include "lexbor/core/base.h"
8
8
 
9
+ static lexbor_memory_malloc_f lexbor_memory_malloc = malloc;
10
+ static lexbor_memory_realloc_f lexbor_memory_realloc = realloc;
11
+ static lexbor_memory_calloc_f lexbor_memory_calloc = calloc;
12
+ static lexbor_memory_free_f lexbor_memory_free = free;
9
13
 
10
14
  void *
11
15
  lexbor_malloc(size_t size)
12
16
  {
13
- return malloc(size);
17
+ return lexbor_memory_malloc(size);
14
18
  }
15
19
 
16
20
  void *
17
21
  lexbor_realloc(void *dst, size_t size)
18
22
  {
19
- return realloc(dst, size);
23
+ return lexbor_memory_realloc(dst, size);
20
24
  }
21
25
 
22
26
  void *
23
27
  lexbor_calloc(size_t num, size_t size)
24
28
  {
25
- return calloc(num, size);
29
+ return lexbor_memory_calloc(num, size);
26
30
  }
27
31
 
28
32
  void *
29
33
  lexbor_free(void *dst)
30
34
  {
31
- free(dst);
35
+ lexbor_memory_free(dst);
32
36
  return NULL;
33
37
  }
38
+
39
+ lxb_status_t
40
+ lexbor_memory_setup(lexbor_memory_malloc_f new_malloc, lexbor_memory_realloc_f new_realloc,
41
+ lexbor_memory_calloc_f new_calloc, lexbor_memory_free_f new_free)
42
+ {
43
+ if (new_malloc == NULL || new_realloc == NULL || new_calloc == NULL || new_free == NULL) {
44
+ return LXB_STATUS_ERROR_OBJECT_IS_NULL;
45
+ }
46
+
47
+ lexbor_memory_malloc = new_malloc;
48
+ lexbor_memory_realloc = new_realloc;
49
+ lexbor_memory_calloc = new_calloc;
50
+ lexbor_memory_free = new_free;
51
+
52
+ return LXB_STATUS_OK;
53
+ }
@@ -6,28 +6,48 @@
6
6
 
7
7
  #include "lexbor/core/base.h"
8
8
 
9
+ static lexbor_memory_malloc_f lexbor_memory_malloc = malloc;
10
+ static lexbor_memory_realloc_f lexbor_memory_realloc = realloc;
11
+ static lexbor_memory_calloc_f lexbor_memory_calloc = calloc;
12
+ static lexbor_memory_free_f lexbor_memory_free = free;
9
13
 
10
14
  void *
11
15
  lexbor_malloc(size_t size)
12
16
  {
13
- return malloc(size);
17
+ return lexbor_memory_malloc(size);
14
18
  }
15
19
 
16
20
  void *
17
21
  lexbor_realloc(void *dst, size_t size)
18
22
  {
19
- return realloc(dst, size);
23
+ return lexbor_memory_realloc(dst, size);
20
24
  }
21
25
 
22
26
  void *
23
27
  lexbor_calloc(size_t num, size_t size)
24
28
  {
25
- return calloc(num, size);
29
+ return lexbor_memory_calloc(num, size);
26
30
  }
27
31
 
28
32
  void *
29
33
  lexbor_free(void *dst)
30
34
  {
31
- free(dst);
35
+ lexbor_memory_free(dst);
32
36
  return NULL;
33
37
  }
38
+
39
+ lxb_status_t
40
+ lexbor_memory_setup(lexbor_memory_malloc_f new_malloc, lexbor_memory_realloc_f new_realloc,
41
+ lexbor_memory_calloc_f new_calloc, lexbor_memory_free_f new_free)
42
+ {
43
+ if (new_malloc == NULL || new_realloc == NULL || new_calloc == NULL || new_free == NULL) {
44
+ return LXB_STATUS_ERROR_OBJECT_IS_NULL;
45
+ }
46
+
47
+ lexbor_memory_malloc = new_malloc;
48
+ lexbor_memory_realloc = new_realloc;
49
+ lexbor_memory_calloc = new_calloc;
50
+ lexbor_memory_free = new_free;
51
+
52
+ return LXB_STATUS_OK;
53
+ }
@@ -262,7 +262,7 @@ lxb_selectors_sibling(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
262
262
  {
263
263
  node = node->next;
264
264
 
265
- do {
265
+ while (node != NULL) {
266
266
  if (node->type == LXB_DOM_NODE_TYPE_ELEMENT) {
267
267
  if (lxb_selectors_match(selectors, entry, selector, node)) {
268
268
  return node;
@@ -273,7 +273,6 @@ lxb_selectors_sibling(lxb_selectors_t *selectors, lxb_selectors_entry_t *entry,
273
273
 
274
274
  node = node->next;
275
275
  }
276
- while (node != NULL);
277
276
 
278
277
  return NULL;
279
278
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nokolexbor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yicheng Zhou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-31 00:00:00.000000000 Z
11
+ date: 2023-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler
@@ -78,7 +78,6 @@ files:
78
78
  - ext/nokolexbor/libxml/xpath.h
79
79
  - ext/nokolexbor/libxml/xpathInternals.h
80
80
  - ext/nokolexbor/libxml/xpointer.h
81
- - ext/nokolexbor/memory.c
82
81
  - ext/nokolexbor/nl_cdata.c
83
82
  - ext/nokolexbor/nl_comment.c
84
83
  - ext/nokolexbor/nl_document.c
@@ -1,46 +0,0 @@
1
- /*
2
- * This file overrides the default `lexbor_malloc` and other
3
- * related functions to reduce memory bloat and allow Ruby to
4
- * GC more often.
5
- * By calling `ruby_xmalloc` instead of `malloc`, Ruby can
6
- * count the memory usage of the C extension and run GC
7
- * whenever `malloc_increase_byte` exceeds the limit. Similar
8
- * to Nokogiri's solution by calling `xmlMemSetup`.
9
- * The downside will be the downgrade of performance because
10
- * of more frequent GC.
11
- */
12
-
13
- #include "lexbor/core/base.h"
14
- #include <ruby.h>
15
-
16
- // Disable using ruby memory functions when ASAN is enabled,
17
- // otherwise memory leak info will be all about ruby which
18
- // is useless.
19
- #ifndef NOKOLEXBOR_ASAN
20
-
21
- void *
22
- lexbor_malloc(size_t size)
23
- {
24
- return ruby_xmalloc(size);
25
- }
26
-
27
- void *
28
- lexbor_realloc(void *dst, size_t size)
29
- {
30
- return ruby_xrealloc(dst, size);
31
- }
32
-
33
- void *
34
- lexbor_calloc(size_t num, size_t size)
35
- {
36
- return ruby_xcalloc(num, size);
37
- }
38
-
39
- void *
40
- lexbor_free(void *dst)
41
- {
42
- ruby_xfree(dst);
43
- return NULL;
44
- }
45
-
46
- #endif