nokolexbor 0.5.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/nokolexbor/nl_document.c +37 -9
- data/ext/nokolexbor/nl_node.c +1 -1
- data/lib/nokolexbor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8686e83a70fe40537a072997e55f11ae40839ccf0b66125e18a251d9ba2c265
|
4
|
+
data.tar.gz: edfedec732ab50ee7a68a56c92b0d71166fdcf091c29105b0995e64096c5ebac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be9df7bc7747b0d155764069f6782e27127127c1c2ec74394b1d9ae01c56b3428811ee4aec1bf4e89fbc8bd6be61508d6dd26b93bd9929c2fdd70cb4e1b28a7d
|
7
|
+
data.tar.gz: 91d16cbe5143e480bd52f5fdbcfe7aa57ca8127cb8f4ea9f249280f027264297426c00f5c5525cf365969668d4240e80352738b86385e2a489e5f8e5d89a6e11
|
@@ -1,9 +1,15 @@
|
|
1
1
|
#include "nokolexbor.h"
|
2
|
+
#include "config.h"
|
2
3
|
|
3
4
|
extern VALUE mNokolexbor;
|
4
5
|
extern VALUE cNokolexborNode;
|
5
6
|
VALUE cNokolexborDocument;
|
6
7
|
|
8
|
+
#ifdef HAVE_PTHREAD_H
|
9
|
+
#include <pthread.h>
|
10
|
+
pthread_key_t p_key_parser;
|
11
|
+
#endif
|
12
|
+
|
7
13
|
static void
|
8
14
|
free_nl_document(lxb_html_document_t *document)
|
9
15
|
{
|
@@ -44,18 +50,27 @@ nl_document_parse(VALUE self, VALUE rb_string_or_io)
|
|
44
50
|
const char *html_c = StringValuePtr(rb_html);
|
45
51
|
size_t html_len = RSTRING_LEN(rb_html);
|
46
52
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
53
|
+
#ifdef HAVE_PTHREAD_H
|
54
|
+
lxb_html_parser_t *g_parser = (lxb_html_parser_t *)pthread_getspecific(p_key_parser);
|
55
|
+
#else
|
56
|
+
lxb_html_parser_t *g_parser = NULL;
|
57
|
+
#endif
|
58
|
+
if (g_parser == NULL) {
|
59
|
+
g_parser = lxb_html_parser_create();
|
60
|
+
lxb_status_t status = lxb_html_parser_init(g_parser);
|
61
|
+
if (status != LXB_STATUS_OK) {
|
62
|
+
nl_raise_lexbor_error(status);
|
63
|
+
}
|
64
|
+
g_parser->tree->scripting = true;
|
65
|
+
#ifdef HAVE_PTHREAD_H
|
66
|
+
pthread_setspecific(p_key_parser, g_parser);
|
67
|
+
#endif
|
52
68
|
}
|
53
69
|
|
54
|
-
|
70
|
+
lxb_html_document_t *document = lxb_html_parse(g_parser, (const lxb_char_t *)html_c, html_len);
|
55
71
|
|
56
|
-
|
57
|
-
|
58
|
-
nl_raise_lexbor_error(status);
|
72
|
+
if (document == NULL) {
|
73
|
+
rb_raise(rb_eRuntimeError, "Error parsing document");
|
59
74
|
}
|
60
75
|
|
61
76
|
return TypedData_Wrap_Struct(cNokolexborDocument, &nl_document_type, document);
|
@@ -127,8 +142,21 @@ nl_document_root(VALUE self)
|
|
127
142
|
return nl_rb_node_create(lxb_dom_document_root(doc), self);
|
128
143
|
}
|
129
144
|
|
145
|
+
static void
|
146
|
+
free_parser(void *data)
|
147
|
+
{
|
148
|
+
lxb_html_parser_t *g_parser = (lxb_html_parser_t *)data;
|
149
|
+
if (g_parser != NULL) {
|
150
|
+
g_parser = lxb_html_parser_destroy(g_parser);
|
151
|
+
}
|
152
|
+
}
|
153
|
+
|
130
154
|
void Init_nl_document(void)
|
131
155
|
{
|
156
|
+
#ifdef HAVE_PTHREAD_H
|
157
|
+
pthread_key_create(&p_key_parser, free_parser);
|
158
|
+
#endif
|
159
|
+
|
132
160
|
cNokolexborDocument = rb_define_class_under(mNokolexbor, "Document", cNokolexborNode);
|
133
161
|
rb_define_singleton_method(cNokolexborDocument, "new", nl_document_new, 0);
|
134
162
|
rb_define_singleton_method(cNokolexborDocument, "parse", nl_document_parse, 1);
|
data/ext/nokolexbor/nl_node.c
CHANGED
@@ -873,7 +873,7 @@ static VALUE
|
|
873
873
|
nl_node_equals(VALUE self, VALUE other)
|
874
874
|
{
|
875
875
|
if (!rb_obj_is_kind_of(other, cNokolexborNode)) {
|
876
|
-
return
|
876
|
+
return Qfalse;
|
877
877
|
}
|
878
878
|
lxb_dom_node_t *node1 = nl_rb_node_unwrap(self);
|
879
879
|
lxb_dom_node_t *node2 = nl_rb_node_unwrap(other);
|
data/lib/nokolexbor/version.rb
CHANGED
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.5.
|
4
|
+
version: 0.5.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: 2023-
|
11
|
+
date: 2023-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|