leptris 1.9.356.0-arm-linux → 1.9.359.0-arm-linux

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +13 -5
  3. data/Rakefile +1 -1
  4. data/ext/leptris/native/native.c +353 -1
  5. data/lib/leptris/version.rb +1 -1
  6. data/lib/leptris/xml/cdata.rb +3 -0
  7. data/lib/leptris/xml/comment.rb +3 -0
  8. data/lib/leptris/xml/declaration.rb +59 -0
  9. data/lib/leptris/xml/doc_type.rb +33 -1
  10. data/lib/leptris/xml/document.rb +74 -2
  11. data/lib/leptris/xml/element.rb +21 -1
  12. data/lib/leptris/xml/entity_reference.rb +3 -0
  13. data/lib/leptris/xml/native.so +0 -0
  14. data/lib/leptris/xml/node_set.rb +22 -0
  15. data/lib/leptris/xml/processing_instruction.rb +3 -0
  16. data/lib/leptris/xml/sax/parser.rb +102 -78
  17. data/lib/leptris/xml/text.rb +4 -0
  18. data/lib/leptris/xml.rb +14 -0
  19. data/lib/libleptris.so +0 -0
  20. data/scripts/gem_smoke.rb +6 -3
  21. data/vendor-src/README.md +1 -1
  22. data/vendor-src/libleptris/CHANGELOG.md +95 -0
  23. data/vendor-src/libleptris/CMakeLists.txt +1 -1
  24. data/vendor-src/libleptris/TODO.xslt-full/REMAINING.md +37 -18
  25. data/vendor-src/libleptris/cli/commands/validate.c +15 -2
  26. data/vendor-src/libleptris/src/include/leptris.h +60 -4
  27. data/vendor-src/libleptris/src/leptris/dtd/content_check.c +280 -144
  28. data/vendor-src/libleptris/src/leptris/dtd/parser.c +17 -4
  29. data/vendor-src/libleptris/src/leptris/rng/parse.c +53 -8
  30. data/vendor-src/libleptris/src/leptris/rng/validate.c +63 -21
  31. data/vendor-src/libleptris/src/leptris/xinclude/xinclude.c +304 -12
  32. data/vendor-src/libleptris/src/leptris/xpath/evaluator.c +30 -0
  33. data/vendor-src/libleptris/src/leptris/xpath/evaluator.h +11 -0
  34. data/vendor-src/libleptris/src/leptris/xpath/evaluator_axes.c +3 -3
  35. data/vendor-src/libleptris/src/leptris/xpath/evaluator_path.c +4 -20
  36. data/vendor-src/libleptris/src/leptris/xpath/parser.c +4 -1
  37. data/vendor-src/libleptris/src/leptris/xpath/vm.c +41 -11
  38. data/vendor-src/libleptris/src/leptris/xpath/xpath_compiled.c +4 -3
  39. data/vendor-src/libleptris/src/leptris/xpath/xpath_public.c +2 -1
  40. data/vendor-src/libleptris/src/leptris/xsd/compile.c +981 -38
  41. data/vendor-src/libleptris/src/leptris/xsd/content_model.c +15 -3
  42. data/vendor-src/libleptris/src/leptris/xsd/validate.c +27 -9
  43. data/vendor-src/libleptris/src/leptris/xsd/xsd_internal.h +1 -0
  44. data/vendor-src/libleptris/test/cli/test_cli.cpp +50 -14
  45. data/vendor-src/libleptris/test/dtd/test_dtd_validate.cpp +80 -4
  46. data/vendor-src/libleptris/test/rng/include-cases/attr-text-choice.rng +18 -0
  47. data/vendor-src/libleptris/test/rng/include-cases/dup-inc-mid.rng +7 -0
  48. data/vendor-src/libleptris/test/rng/include-cases/dup-inc-shared.rng +5 -0
  49. data/vendor-src/libleptris/test/rng/include-cases/dup-inc-top.rng +6 -0
  50. data/vendor-src/libleptris/test/rng/test_rng.cpp +101 -0
  51. data/vendor-src/libleptris/test/xinclude/test_xinclude.cpp +261 -0
  52. data/vendor-src/libleptris/test/xpath/test_xpath.cpp +169 -0
  53. data/vendor-src/libleptris/test/xpath/test_xpath_conformance.cpp +8 -1
  54. data/vendor-src/libleptris/test/xsd/test_xsd_compile.cpp +128 -11
  55. data/vendor-src/libleptris/vcpkg.json +1 -1
  56. metadata +7 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d75e689f3c953ebdcb752c8ac1c21e51980b4b2115f7057649ba06eb36fc094
4
- data.tar.gz: c73906d31dd6da31ed1ecfa96a7b49ee766fd2d88ddf83e41f114bae11509e9b
3
+ metadata.gz: 446b489ed4e8998031c2beef2cbdeba48b1039e81f95b5deafdba667cfd92495
4
+ data.tar.gz: cf0af6644518dc71142e0e5b580b92cbd68ca3c708ca43924be5f4d7eac71593
5
5
  SHA512:
6
- metadata.gz: a9650ae5a1aae2ca20c40bf943e9c5ec53a0ce05e4b8112f7eb9bea62846177108eb8d24422b86c93e37fbde82f3713235f7ddb672343a8862f486a79e8ca314
7
- data.tar.gz: b684bbe8fdf2634fe29367f0feb4311f3ba0e09e5dde9d47eb8f1182127db2062926da5b22ee518e13dbbdbb6d6438e9cd696f6b6661bb04d1d3269ec7360367
6
+ metadata.gz: e0c019e17a75dcc2851e8c4bc9c28951676ef66e975bbc40d0aa4e77f5c98ccf0064e17283263ffc7f563f63693ef56df3b16991ccea244efdc4f2cceb26b295
7
+ data.tar.gz: c384f1f4059aeb9931188e849513ed3efdf9bd419504af160678938eff79c7cf5adb5d30f99deec65e7e8fc90139a8efc1ea2084c9692505affb272ec44aa460
data/README.adoc CHANGED
@@ -115,16 +115,24 @@ returned object is a `Leptris::XML::Document`.
115
115
 
116
116
  Malformed input raises `Leptris::XML::ParseError`. Parse with
117
117
  `recover: true` to get libxml2's `XML_PARSE_RECOVER` semantics
118
- instead — an empty document back, with the failure recorded on the
119
- thread-global last error:
118
+ instead — a best-effort partial tree back, with the recovered
119
+ diagnostics on `doc.errors` (leptris-ruby#465):
120
120
 
121
121
  [source,ruby]
122
122
  ----
123
- doc = Leptris::XML.parse("<broken", recover: true)
124
- doc.root # => nil
125
- Leptris::XML::FFI.leptris_last_error # => "..."
123
+ doc = Leptris::XML.parse("<a><b></a>", recover: true)
124
+ doc.root.name # => "a"
125
+ doc.errors.first.message # => "..."
126
126
  ----
127
127
 
128
+ **Nokogiri compatibility note (leptris-ruby#465):** nokogiri
129
+ recovers by DEFAULT — `Nokogiri::XML("<a><b></a>")` never raises and
130
+ exposes `doc.errors`. leptris keeps the stricter default (malformed
131
+ input raises; the failure detail is on the raised ParseError) — the
132
+ same information, delivered as an exception instead of silent
133
+ recovery. Migrating consumers that relied on nokogiri's recover-by-
134
+ default should pass `recover: true` or rescue `Leptris::XML::ParseError`.
135
+
128
136
  == HTML parsing
129
137
 
130
138
  `Leptris::XML.parse_html(html)` parses tolerant HTML4/5 into a
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ RSpec::Core::RakeTask.new(:spec)
8
8
  # Pin for `rake compile` and the platform-gem builds. Keep in lockstep
9
9
  # with .github/workflows/build.yml (which calls `rake compile`) and the
10
10
  # CHANGELOG when libleptris releases.
11
- LIBLEPTRIS_VERSION = "1.9.356"
11
+ LIBLEPTRIS_VERSION = "1.9.359"
12
12
  # Vendored alongside libleptris for fn:normalize-unicode (TODO
13
13
  # .restructure/20): built per platform with a RELOCATABLE @rpath
14
14
  # install name, loaded by ffi.rb before libleptris so the
@@ -119,6 +119,34 @@ typedef void *(*parse_str_fn)(const char *, size_t, void *);
119
119
  typedef void *(*parse_frag_fn)(const char *, size_t, void *, int *);
120
120
  typedef const char *(*last_err_fn)(void);
121
121
  typedef const char *(*status_str_fn)(int);
122
+
123
+ /* ==== SAX single transport (leptris-ruby SAX parity round) ====
124
+ * The engine's SAX handler struct — mirrors
125
+ * include/leptris/sax/sax.h field order. */
126
+ struct engine_sax_handler {
127
+ void (*start_document)(void*);
128
+ void (*end_document)(void*);
129
+ void (*start_element)(void*, const char*, const char**);
130
+ void (*end_element)(void*, const char*);
131
+ void (*characters)(void*, const char*, size_t);
132
+ void (*comment)(void*, const char*);
133
+ void (*cdata)(void*, const char*);
134
+ void (*processing_instruction)(void*, const char*, const char*);
135
+ void (*start_prefix_mapping)(void*, const char*, const char*);
136
+ void (*end_prefix_mapping)(void*, const char*);
137
+ void (*error)(void*, const char*, int, int);
138
+ };
139
+ typedef int (*sax_parse_fn)(const char*, size_t, struct engine_sax_handler*, void*);
140
+ typedef void* (*sax_create_fn)(struct engine_sax_handler*, void*);
141
+ typedef int (*sax_feed_fn)(void*, const char*, size_t, int);
142
+ typedef void (*sax_pfree_fn)(void*);
143
+ typedef void (*sax_flags_fn)(void*, unsigned);
144
+ static sax_parse_fn f_sax_parse;
145
+ static sax_create_fn f_sax_create;
146
+ static sax_feed_fn f_sax_feed;
147
+ static sax_pfree_fn f_sax_pfree;
148
+ static sax_flags_fn f_sax_set_flags;
149
+
122
150
  static set_str_fn f_elem_set_name, f_elem_set_text, f_text_set_content;
123
151
  static node_unlink_fn f_node_unlink;
124
152
  static traverse_fn f_node_traverse;
@@ -135,6 +163,7 @@ static set_root_fn f_set_root;
135
163
  static doc_free_fn f_doc_free;
136
164
 
137
165
  static VALUE c_native_node;
166
+ static VALUE c_sax_parser;
138
167
  /* Ivar reads (TODO.perf/07 tail): the binding Document keeps the
139
168
  * C address and the caches in plain ivars, so the hot C faces skip
140
169
  * rb_funcall dispatch entirely. */
@@ -280,6 +309,12 @@ static void resolve_symbols(const char *lib_path)
280
309
  f_status_str = (status_str_fn)lib_sym(h, "leptris_status_string");
281
310
  f_set_root = (set_root_fn)lib_sym(h, "leptris_document_set_root");
282
311
  f_doc_free = (doc_free_fn)lib_sym(h, "leptris_document_free");
312
+ f_sax_parse = (sax_parse_fn)lib_sym(h, "leptris_sax_parse");
313
+ f_sax_create = (sax_create_fn)lib_sym(h, "leptris_sax_parser_create");
314
+ f_sax_feed = (sax_feed_fn)lib_sym(h, "leptris_sax_parser_feed");
315
+ f_sax_pfree = (sax_pfree_fn)lib_sym(h, "leptris_sax_parser_free");
316
+ f_sax_set_flags =
317
+ (sax_flags_fn)lib_sym(h, "leptris_sax_parser_set_skip_flags");
283
318
  if (!f_elem_name || !f_text_content || !f_attr ||
284
319
  !f_children_ex || !f_node_type || !f_next_sibling || !f_parent ||
285
320
  !f_element_text || !f_doc_create || !f_elem_create || !f_text_create ||
@@ -292,7 +327,8 @@ static void resolve_symbols(const char *lib_path)
292
327
  !f_node_traverse || !f_node_visit || !f_free_str ||
293
328
  !f_node_xpath || !f_elem_copy || !f_parse_str ||
294
329
  !f_parse_frag || !f_last_err || !f_status_str ||
295
- !f_doc_free ||
330
+ !f_doc_free || !f_sax_parse || !f_sax_create || !f_sax_feed ||
331
+ !f_sax_pfree || !f_sax_set_flags ||
296
332
  !f_elem_prefix || !f_xp_count || !f_xp_nodes_ex ||
297
333
  !f_xp_node_kind || !f_xp_node_name || !f_xp_node_value ||
298
334
  !f_doc_serialize || !f_elem_serialize || !f_attr_first ||
@@ -1458,6 +1494,30 @@ static VALUE nn_byte_offset(VALUE self)
1458
1494
 
1459
1495
  /* The owning binding Document (moxml #213: adapters route
1460
1496
  * native.document exactly like Node#document). */
1497
+ /* leptris-ruby#460: the last contract face that was Ruby-only.
1498
+ * Element set-text / text set-content with the same freed and
1499
+ * readonly gates as set_binding_text, defined on the C class so
1500
+ * subclasses inherit it at native speed. The version bump (via
1501
+ * document_advance_version) invalidates the content memo. */
1502
+ static VALUE nn_content_set(VALUE self, VALUE content)
1503
+ {
1504
+ struct native_node *n;
1505
+ int st;
1506
+ TypedData_Get_Struct(self, struct native_node, &nn_type, n);
1507
+ if (NIL_P(rb_ivar_get(n->document, id_iv_c_address)))
1508
+ rb_raise(c_use_after_free_error,
1509
+ "owning document has been freed");
1510
+ if (rb_ivar_get(n->document, id_iv_readonly) == Qtrue)
1511
+ rb_raise(c_readonly_error,
1512
+ "document is readonly — mutation attempted");
1513
+ document_advance_version(n->document);
1514
+ st = f_node_type(n->ptr) == NT_ELEMENT
1515
+ ? f_elem_set_text(n->ptr, StringValueCStr(content))
1516
+ : f_text_set_content(n->ptr, StringValueCStr(content));
1517
+ check_status_c(st);
1518
+ return content;
1519
+ }
1520
+
1461
1521
  static VALUE nn_document(VALUE self)
1462
1522
  {
1463
1523
  struct native_node *n;
@@ -3062,6 +3122,275 @@ static VALUE leptris_native_resolve_rb(VALUE self, VALUE lib_path)
3062
3122
  # define LEPTRIS_INIT_EXPORT
3063
3123
  #endif
3064
3124
 
3125
+ /* ==== SAX single transport: C callbacks dispatch to Ruby via
3126
+ * rb_funcall (~100ns/event). Replaces BOTH Ruby-side transports —
3127
+ * the FFI::Function trampolines (~1.3us/event) and the record-
3128
+ * then-drain bulk pass — with one path that is fastest for every
3129
+ * handler shape. Only the kinds the handler overrides are attached
3130
+ * (the engine skips NULL callbacks), preserving the pay-for-what-
3131
+ * you-consume property. */
3132
+
3133
+ enum sax_kind_bits {
3134
+ SK_START_DOC = 1u << 0,
3135
+ SK_END_DOC = 1u << 1,
3136
+ SK_START_1ARG = 1u << 2, /* start_element(name) */
3137
+ SK_START_2ARG = 1u << 3, /* start_element(name, attrs) */
3138
+ SK_END_ELEM = 1u << 4,
3139
+ SK_CHARS = 1u << 5,
3140
+ SK_COMMENT = 1u << 6,
3141
+ SK_CDATA = 1u << 7,
3142
+ SK_PI = 1u << 8,
3143
+ SK_START_PREFIX = 1u << 9,
3144
+ SK_END_PREFIX = 1u << 10,
3145
+ SK_ERROR = 1u << 11
3146
+ };
3147
+
3148
+ static ID id_sax_start_document, id_sax_end_document, id_sax_start_element,
3149
+ id_sax_end_element, id_sax_characters, id_sax_comment, id_sax_cdata,
3150
+ id_sax_pi, id_sax_start_prefix, id_sax_end_prefix, id_sax_error;
3151
+
3152
+ struct sax_ctx {
3153
+ VALUE handler;
3154
+ unsigned kinds;
3155
+ };
3156
+
3157
+ static VALUE sax_utf8_str(const char* s)
3158
+ {
3159
+ return s ? rb_utf8_str_new_cstr(s) : Qnil;
3160
+ }
3161
+
3162
+ /* PI data strips leading whitespace — read_pi_data parity. */
3163
+ static VALUE sax_pi_data_str(const char* s)
3164
+ {
3165
+ if (!s) return Qnil;
3166
+ while (*s == ' ' || *s == '\t' || *s == '\r' || *s == '\n')
3167
+ s++;
3168
+ return rb_utf8_str_new_cstr(s);
3169
+ }
3170
+
3171
+ static void sax_cb_start_document(void* ud)
3172
+ {
3173
+ struct sax_ctx* c = ud;
3174
+ rb_funcall(c->handler, id_sax_start_document, 0);
3175
+ }
3176
+
3177
+ static void sax_cb_end_document(void* ud)
3178
+ {
3179
+ struct sax_ctx* c = ud;
3180
+ rb_funcall(c->handler, id_sax_end_document, 0);
3181
+ }
3182
+
3183
+ static void sax_cb_start_element(void* ud, const char* name,
3184
+ const char** attrs)
3185
+ {
3186
+ struct sax_ctx* c = ud;
3187
+ VALUE n = rb_utf8_str_new_cstr(name);
3188
+ if (c->kinds & SK_START_1ARG) {
3189
+ rb_funcall(c->handler, id_sax_start_element, 1, n);
3190
+ return;
3191
+ }
3192
+ VALUE pairs = rb_ary_new();
3193
+ if (attrs) {
3194
+ for (size_t i = 0; attrs[i]; i += 2)
3195
+ rb_ary_push(pairs, rb_assoc_new(
3196
+ rb_utf8_str_new_cstr(attrs[i]),
3197
+ rb_utf8_str_new_cstr(attrs[i + 1])));
3198
+ }
3199
+ rb_funcall(c->handler, id_sax_start_element, 2, n, pairs);
3200
+ }
3201
+
3202
+ static void sax_cb_end_element(void* ud, const char* name)
3203
+ {
3204
+ struct sax_ctx* c = ud;
3205
+ rb_funcall(c->handler, id_sax_end_element, 1,
3206
+ rb_utf8_str_new_cstr(name));
3207
+ }
3208
+
3209
+ static void sax_cb_characters(void* ud, const char* text, size_t len)
3210
+ {
3211
+ struct sax_ctx* c = ud;
3212
+ rb_funcall(c->handler, id_sax_characters, 1,
3213
+ rb_utf8_str_new(text, len));
3214
+ }
3215
+
3216
+ static void sax_cb_comment(void* ud, const char* comment)
3217
+ {
3218
+ struct sax_ctx* c = ud;
3219
+ rb_funcall(c->handler, id_sax_comment, 1,
3220
+ rb_utf8_str_new_cstr(comment));
3221
+ }
3222
+
3223
+ static void sax_cb_cdata(void* ud, const char* cdata)
3224
+ {
3225
+ struct sax_ctx* c = ud;
3226
+ rb_funcall(c->handler, id_sax_cdata, 1, rb_utf8_str_new_cstr(cdata));
3227
+ }
3228
+
3229
+ static void sax_cb_pi(void* ud, const char* target, const char* data)
3230
+ {
3231
+ struct sax_ctx* c = ud;
3232
+ rb_funcall(c->handler, id_sax_pi, 2, sax_utf8_str(target),
3233
+ sax_pi_data_str(data));
3234
+ }
3235
+
3236
+ static void sax_cb_start_prefix(void* ud, const char* prefix,
3237
+ const char* uri)
3238
+ {
3239
+ struct sax_ctx* c = ud;
3240
+ rb_funcall(c->handler, id_sax_start_prefix, 2, sax_utf8_str(prefix),
3241
+ sax_utf8_str(uri));
3242
+ }
3243
+
3244
+ static void sax_cb_end_prefix(void* ud, const char* prefix)
3245
+ {
3246
+ struct sax_ctx* c = ud;
3247
+ rb_funcall(c->handler, id_sax_end_prefix, 1, sax_utf8_str(prefix));
3248
+ }
3249
+
3250
+ static void sax_cb_error(void* ud, const char* msg, int line, int col)
3251
+ {
3252
+ struct sax_ctx* c = ud;
3253
+ rb_funcall(c->handler, id_sax_error, 3, rb_utf8_str_new_cstr(msg),
3254
+ INT2NUM(line), INT2NUM(col));
3255
+ }
3256
+
3257
+ static void sax_handler_fill(struct engine_sax_handler* h,
3258
+ struct sax_ctx* c)
3259
+ {
3260
+ memset(h, 0, sizeof(*h));
3261
+ if (c->kinds & SK_START_DOC)
3262
+ h->start_document = sax_cb_start_document;
3263
+ if (c->kinds & SK_END_DOC)
3264
+ h->end_document = sax_cb_end_document;
3265
+ if (c->kinds & (SK_START_1ARG | SK_START_2ARG))
3266
+ h->start_element = sax_cb_start_element;
3267
+ if (c->kinds & SK_END_ELEM)
3268
+ h->end_element = sax_cb_end_element;
3269
+ if (c->kinds & SK_CHARS)
3270
+ h->characters = sax_cb_characters;
3271
+ if (c->kinds & SK_COMMENT)
3272
+ h->comment = sax_cb_comment;
3273
+ if (c->kinds & SK_CDATA)
3274
+ h->cdata = sax_cb_cdata;
3275
+ if (c->kinds & SK_PI)
3276
+ h->processing_instruction = sax_cb_pi;
3277
+ if (c->kinds & SK_START_PREFIX)
3278
+ h->start_prefix_mapping = sax_cb_start_prefix;
3279
+ if (c->kinds & SK_END_PREFIX)
3280
+ h->end_prefix_mapping = sax_cb_end_prefix;
3281
+ if (c->kinds & SK_ERROR)
3282
+ h->error = sax_cb_error;
3283
+ }
3284
+
3285
+ static VALUE nf_sax_parse(VALUE self, VALUE handler, VALUE kinds,
3286
+ VALUE string)
3287
+ {
3288
+ struct engine_sax_handler h;
3289
+ struct sax_ctx c;
3290
+ int rc;
3291
+ (void)self;
3292
+ c.handler = handler;
3293
+ c.kinds = NUM2UINT(kinds);
3294
+ sax_handler_fill(&h, &c);
3295
+ rc = f_sax_parse(RSTRING_PTR(string), RSTRING_LEN(string), &h, &c);
3296
+ return INT2NUM(rc);
3297
+ }
3298
+
3299
+ /* Streaming parser wrapper: the handler VALUE must stay live for
3300
+ * the parser's lifetime, so the ctx rides a TypedData with mark. */
3301
+ struct sax_parser_obj {
3302
+ void* parser;
3303
+ struct engine_sax_handler h;
3304
+ struct sax_ctx c;
3305
+ int skip_flags;
3306
+ int flags_applied;
3307
+ };
3308
+
3309
+ static void sax_parser_mark(void* p)
3310
+ {
3311
+ struct sax_parser_obj* o = p;
3312
+ rb_gc_mark(o->c.handler);
3313
+ }
3314
+
3315
+ static void sax_parser_free(void* p)
3316
+ {
3317
+ struct sax_parser_obj* o = p;
3318
+ if (o->parser)
3319
+ f_sax_pfree(o->parser);
3320
+ xfree(o);
3321
+ }
3322
+
3323
+ static size_t sax_parser_size(const void* p)
3324
+ {
3325
+ return sizeof(struct sax_parser_obj);
3326
+ }
3327
+
3328
+ static const rb_data_type_t sax_parser_type = {
3329
+ "Leptris/XML/Native/SaxParser",
3330
+ {sax_parser_mark, sax_parser_free, sax_parser_size},
3331
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
3332
+ };
3333
+
3334
+ static VALUE nf_sax_parser_create(VALUE self, VALUE handler, VALUE kinds)
3335
+ {
3336
+ struct sax_parser_obj* o;
3337
+ VALUE obj;
3338
+ (void)self;
3339
+ o = ALLOC(struct sax_parser_obj);
3340
+ o->c.handler = handler;
3341
+ o->c.kinds = NUM2UINT(kinds);
3342
+ o->skip_flags = 0;
3343
+ o->flags_applied = 0;
3344
+ sax_handler_fill(&o->h, &o->c);
3345
+ o->parser = f_sax_create(&o->h, &o->c);
3346
+ if (!o->parser) {
3347
+ xfree(o);
3348
+ return Qnil;
3349
+ }
3350
+ obj = TypedData_Wrap_Struct(c_sax_parser, &sax_parser_type, o);
3351
+ return obj;
3352
+ }
3353
+
3354
+ static struct sax_parser_obj* sax_parser_unwrap(VALUE obj)
3355
+ {
3356
+ struct sax_parser_obj* o;
3357
+ TypedData_Get_Struct(obj, struct sax_parser_obj, &sax_parser_type, o);
3358
+ return o;
3359
+ }
3360
+
3361
+ static VALUE nf_sax_parser_feed(VALUE self, VALUE obj, VALUE chunk,
3362
+ VALUE is_final)
3363
+ {
3364
+ int rc;
3365
+ (void)self;
3366
+ rc = f_sax_feed(sax_parser_unwrap(obj)->parser, RSTRING_PTR(chunk),
3367
+ RSTRING_LEN(chunk), RTEST(is_final) ? 1 : 0);
3368
+ return INT2NUM(rc);
3369
+ }
3370
+
3371
+ static VALUE nf_sax_parser_set_skip_flags(VALUE self, VALUE obj,
3372
+ VALUE flags)
3373
+ {
3374
+ struct sax_parser_obj* o;
3375
+ (void)self;
3376
+ o = sax_parser_unwrap(obj);
3377
+ o->skip_flags = NUM2UINT(flags);
3378
+ f_sax_set_flags(o->parser, (unsigned)o->skip_flags);
3379
+ return Qnil;
3380
+ }
3381
+
3382
+ static VALUE nf_sax_parser_free(VALUE self, VALUE obj)
3383
+ {
3384
+ struct sax_parser_obj* o;
3385
+ (void)self;
3386
+ o = sax_parser_unwrap(obj);
3387
+ if (o->parser) {
3388
+ f_sax_pfree(o->parser);
3389
+ o->parser = 0;
3390
+ }
3391
+ return Qnil;
3392
+ }
3393
+
3065
3394
  LEPTRIS_INIT_EXPORT void Init_native(void)
3066
3395
  {
3067
3396
  VALUE m_leptris, m_xml, m_native;
@@ -3125,6 +3454,7 @@ LEPTRIS_INIT_EXPORT void Init_native(void)
3125
3454
  rb_define_method(c_native_node, "byte_offset", nn_byte_offset, 0);
3126
3455
  rb_define_method(c_native_node, "name", nn_name, 0);
3127
3456
  rb_define_method(c_native_node, "content", nn_content, 0);
3457
+ rb_define_method(c_native_node, "content=", nn_content_set, 1);
3128
3458
  rb_define_method(c_native_node, "attribute", nn_attribute, 1);
3129
3459
  rb_define_alias(c_native_node, "[]", "attribute");
3130
3460
  /* Unshadowed aliases for consumers whose contract modules shadow
@@ -3143,6 +3473,28 @@ LEPTRIS_INIT_EXPORT void Init_native(void)
3143
3473
  m_native = rb_define_module_under(m_xml, "Native");
3144
3474
  m_native_sentinel = m_native;
3145
3475
  rb_define_module_function(m_native, "fast_name", nf_name, 1);
3476
+ id_sax_start_document = rb_intern("start_document");
3477
+ id_sax_end_document = rb_intern("end_document");
3478
+ id_sax_start_element = rb_intern("start_element");
3479
+ id_sax_end_element = rb_intern("end_element");
3480
+ id_sax_characters = rb_intern("characters");
3481
+ id_sax_comment = rb_intern("comment");
3482
+ id_sax_cdata = rb_intern("cdata_block");
3483
+ id_sax_pi = rb_intern("processing_instruction");
3484
+ id_sax_start_prefix = rb_intern("start_prefix_mapping");
3485
+ id_sax_end_prefix = rb_intern("end_prefix_mapping");
3486
+ id_sax_error = rb_intern("error");
3487
+ c_sax_parser = rb_define_class_under(m_native, "SaxParser",
3488
+ rb_cObject);
3489
+ rb_define_module_function(m_native, "sax_parse", nf_sax_parse, 3);
3490
+ rb_define_module_function(m_native, "sax_parser_create",
3491
+ nf_sax_parser_create, 2);
3492
+ rb_define_module_function(m_native, "sax_parser_feed",
3493
+ nf_sax_parser_feed, 3);
3494
+ rb_define_module_function(m_native, "sax_parser_set_skip_flags",
3495
+ nf_sax_parser_set_skip_flags, 2);
3496
+ rb_define_module_function(m_native, "sax_parser_free",
3497
+ nf_sax_parser_free, 1);
3146
3498
  rb_define_module_function(m_native, "fast_element_text", nf_element_text, 1);
3147
3499
  rb_define_module_function(m_native, "fast_attribute", nf_attribute, 2);
3148
3500
  rb_define_module_function(m_native, "fast_prefix", nf_prefix, 1);
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Leptris
4
- VERSION = "1.9.356.0"
4
+ VERSION = "1.9.359.0"
5
5
  end
@@ -35,4 +35,7 @@ class Leptris::XML::CDATA < Leptris::XML::Text
35
35
  def to_s
36
36
  "<![CDATA[#{content}]]>"
37
37
  end
38
+
39
+ # leptris-ruby#464: CDATA serialization face.
40
+ alias_method :to_xml, :to_s
38
41
  end
@@ -35,4 +35,7 @@ class Leptris::XML::Comment < Leptris::XML::Node
35
35
  def to_s
36
36
  "<!--#{content}-->"
37
37
  end
38
+
39
+ # leptris-ruby#464: comment serialization face.
40
+ alias_method :to_xml, :to_s
38
41
  end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Node-shaped view of the document's XML declaration state
4
+ # (leptris-ruby#459 ask 1 — retires moxml's CustomizedLeptris value
5
+ # object). The engine stores the declaration as document state; this
6
+ # face reads and writes it in place. `remove`/`unlink` clears the
7
+ # state entirely (Document#clear_declaration).
8
+ class Leptris::XML::Declaration
9
+ attr_reader :document
10
+
11
+ def initialize(document)
12
+ @document = document
13
+ end
14
+
15
+ def version
16
+ @document.xml_version
17
+ end
18
+
19
+ def encoding
20
+ @document.xml_encoding
21
+ end
22
+
23
+ def standalone
24
+ @document.xml_standalone
25
+ end
26
+
27
+ def version=(value)
28
+ @document.xml_version = value
29
+ value
30
+ end
31
+
32
+ def encoding=(value)
33
+ @document.xml_encoding = value
34
+ value
35
+ end
36
+
37
+ def standalone=(value)
38
+ @document.xml_standalone = value
39
+ value
40
+ end
41
+
42
+ def remove
43
+ @document.clear_declaration
44
+ self
45
+ end
46
+ alias_method :unlink, :remove
47
+
48
+ def to_s
49
+ parts = ['<?xml version="' + version.to_s + '"']
50
+ parts << 'encoding="' + encoding.to_s + '"' if encoding
51
+ parts << 'standalone="' + (standalone ? "yes" : "no") + '"' unless standalone.nil?
52
+ parts.join(" ") + "?>"
53
+ end
54
+
55
+ def inspect
56
+ "#<#{self.class.name} version=#{version.inspect} " \
57
+ "encoding=#{encoding.inspect} standalone=#{standalone.inspect}>"
58
+ end
59
+ end
@@ -3,25 +3,54 @@
3
3
  class Leptris::XML::DocType
4
4
  attr_reader :c_ptr, :document
5
5
 
6
- def initialize(c_ptr, document)
6
+ def initialize(c_ptr, document, detached_name: nil,
7
+ detached_public_id: nil, detached_system_id: nil)
7
8
  @c_ptr = c_ptr
8
9
  @document = document
10
+ @detached_name = detached_name
11
+ @detached_public_id = detached_public_id
12
+ @detached_system_id = detached_system_id
13
+ end
14
+
15
+ # Detached token (leptris-ruby#459 ask 2): create first, attach
16
+ # later via Document#add_child — the two-phase facade contract.
17
+ def self.new_detached(document, name, public_id = nil, system_id = nil)
18
+ new(nil, document, detached_name: name.to_s,
19
+ detached_public_id: public_id, detached_system_id: system_id)
20
+ end
21
+
22
+ def attached?
23
+ !@c_ptr.nil?
24
+ end
25
+
26
+ # Installs the C node handle on a detached token (Document#add_child
27
+ # routes the attach). The detached field copies die here.
28
+ def attach!(c_ptr)
29
+ @c_ptr = c_ptr
30
+ @detached_name = nil
31
+ @detached_public_id = nil
32
+ @detached_system_id = nil
33
+ self
9
34
  end
10
35
 
11
36
  def name
37
+ return @detached_name if @c_ptr.nil?
12
38
  Leptris::XML::FFI.leptris_doctype_get_name(c_ptr)
13
39
  end
14
40
  alias_method :node_name, :name
15
41
 
16
42
  def root_name
43
+ return @detached_name if @c_ptr.nil?
17
44
  Leptris::XML::FFI.leptris_doctype_get_root_name(c_ptr)
18
45
  end
19
46
 
20
47
  def public_id
48
+ return @detached_public_id if @c_ptr.nil?
21
49
  Leptris::XML::FFI.leptris_doctype_get_public_id(c_ptr)
22
50
  end
23
51
 
24
52
  def system_id
53
+ return @detached_system_id if @c_ptr.nil?
25
54
  Leptris::XML::FFI.leptris_doctype_get_system_id(c_ptr)
26
55
  end
27
56
 
@@ -51,4 +80,7 @@ class Leptris::XML::DocType
51
80
  def inspect
52
81
  "#<#{self.class.name} name=#{name.inspect} public=#{public_id.inspect} system=#{system_id.inspect}>"
53
82
  end
83
+
84
+ # leptris-ruby#464: DOCTYPE serialization face.
85
+ alias_method :to_xml, :to_s
54
86
  end