0
0
mirror of https://github.com/zeux/pugixml.git synced 2024-12-27 13:33:17 +08:00

545 Commits

Author SHA1 Message Date
Arseny Kapoulkine
70f57fab6d tests: Don't use ranged for loop in move tests
Some compilers support move semantics but don't support ranged for.
2016-11-06 12:14:58 -08:00
Arseny Kapoulkine
aa117cce42 Refactor move semantics support detection
Do it in one place and set PUGIXML_HAS_MOVE if it's available.
2016-11-06 11:49:10 -08:00
Pavel Kryukov
c7c7349cb7 Add PUGIXML_OVERRIDE to headers of tests 2016-10-13 01:36:12 +03:00
Arseny Kapoulkine
5b102d108d tests: Fix clang warning 2016-07-15 18:53:59 -05:00
Arseny Kapoulkine
525b2fe5c3 tests: Add tests for latin1 detection 2016-07-14 23:04:17 -07:00
Arseny Kapoulkine
2e0ed8284b Remove extra space in an empty tag for format_raw
When using format_raw the space in the empty tag (<node />) is the only
character that does not have to be there; so format_raw almost results in
a minimal XML but not quite.

It's pretty unlikely that this is crucial for any users - the formatting
change should be benign, and it's better to improve format_raw than to add
yet another flag.

Fixes #87.
2016-04-14 00:30:24 -07:00
Arseny Kapoulkine
d2e72ee05a tests: Add tests for long setters 2016-02-02 08:49:32 -08:00
Stephan Beyer
fc9073289f test_parse.cpp: add newline to last line
This is necessary in order to comply with the C++03 standard.
2016-01-24 19:47:06 +01:00
Stephan Beyer
f7aa65db8a Fix whitespace issues
Git warns when it finds "whitespace errors". This commit gets
rid of these whitespace errors for code and adoc files.
2016-01-24 14:05:44 +01:00
Arseny Kapoulkine
fc6c8633dd tests: Add test for parse_embed_pcdata 2016-01-12 20:16:29 -08:00
Arseny Kapoulkine
94c08f27c6 tests: Fix Borland C++ 5.4 compilation
The tests now compile fine but crash on the first floating-point exception
despite our attempts to disable them in main()...
2015-10-25 13:44:26 -07:00
Arseny Kapoulkine
fd605bc9a7 tests: Fix GCC warning
Fix "this decimal constant is unsigned only in ISO C90".
2015-10-17 12:20:21 -07:00
Arseny Kapoulkine
0e09571f21 Fix integer overflow detection with leading zeros
Since they don't contribute to the resulting value just skip them before
parsing. This matches the behavior of strtol/strtoll and results in more
intuitive behavior.
2015-10-17 10:33:50 -07:00
Arseny Kapoulkine
537aea56c6 tests: Fix version check :) 2015-10-10 13:07:53 -07:00
Arseny Kapoulkine
3e9cf53ea7 tests: Add a test for empty xpath_query ctor 2015-10-09 20:53:02 -07:00
Arseny Kapoulkine
6e5163ba3e tests: Add a copy of header-only test
This makes sure we get linking errors whenever a symbol is not marked as inline
in header-only mode.
2015-10-06 07:26:24 -07:00
Arseny Kapoulkine
3229e67712 Fix parsing of integers that start with +
This matches the format strtol supports.
2015-09-21 00:35:57 -07:00
Arseny Kapoulkine
5b86a8f612 tests: Add tests for integer overflow during conversion
These tests are only testing attribute as_int in hopes that xml_text uses the
same underlying implementation (which it does).
2015-09-20 10:48:30 -07:00
Arseny Kapoulkine
234c2f3657 tests: Convert several files to Unix line endings
They were still using Windows EOL by mistake
2015-09-19 00:14:18 -07:00
Arseny Kapoulkine
e8fdd1303c tests: Fix test allocator to provide fundamental alignment
Previously test allocator only guaranteed alignment enough for a pointer.

On some platforms (e.g. SPARC) double has to be aligned to 8 bytes but pointers
can have a size of 4 bytes. This commit increases allocation header to fix that.

In practical terms the allocation header is now always 8 bytes.
2015-07-25 17:04:17 -04:00
Arseny Kapoulkine
a562bf6d3c tests: Only enable page heap on x86/x64
This fixes tests in PUGIXML_NO_XPATH mode on SPARC64 (#48).

SPARC does not allow unaligned accesses - e.g. you can't read an unaligned int.
Normally pugixml does not perform unaligned integer/pointer accesses, but page
heap can allocate blocks that are not aligned so that we can detect a single-
byte read/write overrun.

Additionally, the hardcoded page size we're currently using is really system
specific - on SPARC the page size can be 8 Kb instead of 4 Kb so mprotect can
fail.
2015-07-25 14:19:08 -04:00
Arseny Kapoulkine
97afc16ef2 tests: Add newline at the end of file 2015-05-22 20:20:03 -07:00
Arseny Kapoulkine
fc1dcab79d tests: Fix MSVC6 compilation 2015-05-22 08:43:36 -07:00
Arseny Kapoulkine
e2358e5e3b tests: Split fp roundtrip test into float and double 2015-05-20 08:05:43 -07:00
Arseny Kapoulkine
f828eae3ea Implement xml_node::attribute with a hint
Extra argument 'hint' is used to start the attribute lookup; if the attribute
is not found the lookup is restarted from the beginning of the attriubte list.

This allows to optimize attribute lookups if you need to get many attributes
from the node and can make assumptions about the likely ordering. The code is
correct regardless of the order, but it is faster than using vanilla lookups
if the order matches the calling order.

Fixes #30.
2015-05-14 08:04:06 -07:00
Arseny Kapoulkine
01f627a4d7 tests: Fix address sanitizer detection for GCC 2015-05-12 21:49:44 -07:00
Arseny Kapoulkine
59ce480f96 Add Visual Studio 2015 to AppVeyor 2015-05-12 20:55:59 -07:00
Arseny Kapoulkine
7342c5ed8c tests: Disable page allocator if address sanitizer is active
Address sanitizer can detect underflows so we don't really need the custom
allocator.

Additionally, custom allocator can return memory that is not pointer-aligned;
this causes undefined behavior sanitizer to complain.
2015-05-12 20:16:51 -07:00
Arseny Kapoulkine
9f7994ed71 tests: Fix clang 3.7 warning
Work around -Wself-move using ref-deref.
2015-05-12 20:02:53 -07:00
Arseny Kapoulkine
cff35dfa31 tests: Fix MSVC6 compatibility
Apply the usual workaround for for scoping issues. Also fix integer conversion
warning for BorlandC.
2015-05-03 17:58:20 -07:00
Arseny Kapoulkine
19d43d39fc tests: Add one more page reclamation test 2015-05-02 09:45:26 -07:00
Arseny Kapoulkine
dede617d9f tests: Fix spurious failures in compact mode
The memory_large_allocations test sometimes classified hash allocations
as page allocations since hash table could reach 512 entries.
2015-04-29 09:21:04 -07:00
Arseny Kapoulkine
3643b505a6 Fix node_pi memory leak 2015-04-22 08:38:52 -07:00
Arseny Kapoulkine
52bcb4ecd6 tests: Adjust allocation thresholds to fix tests 2015-04-21 21:35:54 -07:00
Arseny Kapoulkine
f9983ea2ed Merge branch 'master' into compact 2015-04-21 21:27:44 -07:00
Arseny Kapoulkine
a6cc636a6b tests: Fix MSVC warnings 2015-04-21 21:07:58 -07:00
Arseny Kapoulkine
4eadece45f tests: Add move semantics tests
Also test ranged for and copying big xpath_variable_set objects (to make
sure we actually handle hash collisions properly)
2015-04-21 19:44:19 -07:00
Arseny Kapoulkine
cbf3807ad4 Implement copy ctor/assignment for xpath_variable_set
xpath_variable_set is essentially an associative container; it's about time it
became copyable.

Implementation is slightly tricky due to out of memory handling. Both copy ctor
and assignment operator have strong exception guarantee (even if exceptions are
disabled! which translates to "roll back on allocation errors").
2015-04-15 23:22:31 -07:00
Arseny Kapoulkine
70a78b2fa5 tests: Fix Linux build 2015-04-15 22:11:13 -07:00
Arseny Kapoulkine
bb3aee447b tests: Use malloc for OSX/Linux page heap
Switch to malloc and manually aligning the pointer to the page boundary.

mmap is much slower than malloc; this change makes tests ~4x faster.
2015-04-15 21:44:52 -07:00
Arseny Kapoulkine
5158ee903b Fix xpath_node_set assignment to provide strong exception guarantee
Since the type of the set was updated before assignment, assigning in
out-of-memory condition could change the type to not match the content.
2015-04-14 19:23:36 -07:00
Arseny Kapoulkine
2a3435274f Refactor format_indent_attributes implementation
Fix code style and revert redundant parameters/whitespace changes.

Also remove format_each_attribute_on_new_line - we're only introducing one
extra formatting flag. The flag implies format_indent but does not include its
bitmask.

Also add a few more tests.

Fixes #14.
2015-04-13 21:49:08 -07:00
Arseny Kapoulkine
950693be7f Merge branch 'AlignAttributesEachOnSeparateLine' of git://github.com/halex2005/pugixml into indent_attributes 2015-04-13 20:56:18 -07:00
Arseny Kapoulkine
cb786665d4 tests: Add PUGIXML_COMPACT to AppVeyor 2015-04-13 20:36:04 -07:00
Arseny Kapoulkine
ed2c822643 Merge branch 'master' into compact 2015-04-13 20:35:26 -07:00
Arseny Kapoulkine
1c4098a7d9 Remove all files for the Jamplus-based build system
End of an era.

Make can be used for regular development (Linux/OSX), documentation building
and release packaging.
CMake can be used for regular development (Windows); it's also used by some
Linux distributions.

Continuous integration is now performed by Travis CI and AppVeyor.
2015-04-13 20:30:14 -07:00
Arseny Kapoulkine
218ddd0376 Add AppVeyor build scripts 2015-04-13 20:03:49 -07:00
halex2005
5d66ae9fb9 add tests for aligning each attribute on next line 2015-04-14 00:56:42 +05:00
Arseny Kapoulkine
054b0b447e Merge branch 'master' into compact 2015-04-12 22:09:45 -07:00
Arseny Kapoulkine
9539c488c2 Fix unused variable warning
Also fix test in wchar_t mode.
2015-04-12 22:06:17 -07:00
Arseny Kapoulkine
f04b56e178 Permit custom allocation function to throw
Ensure that all the necessary cleanup is performed in case the allocation fails
with an exception - files are closed, buffers are reclaimed, etc.

Any test that triggers a simulated out-of-memory condition is ran once again
with a throwing allocation function. Unobserved std::bad_alloc count as test
failures and require CHECK_ALLOC_FAIL macro.

Fixes #17.
2015-04-12 21:46:48 -07:00
Arseny Kapoulkine
5edeaf6765 tests: Add more out of memory tests
Also add tests that verify save_file for absence of FILE leaks.
2015-04-12 21:27:12 -07:00
Arseny Kapoulkine
6c11a0c693 Fix compilation and tests after merge. 2015-04-12 03:14:08 -07:00
Arseny Kapoulkine
a19da1c246 Merge branch 'master' into compact 2015-04-12 03:05:58 -07:00
Arseny Kapoulkine
a0d065cd22 Implment copyless copy for attributes
Previously attributes that were copied with their node used string sharing,
but standalone attributes that were copied using xml_node::*_copy(xml_attribute)
were not.
2015-04-12 03:03:56 -07:00
Arseny Kapoulkine
c5d07e2c28 tests: Add a test that verifies absence of file leaks
If an out of memory error happens in load_file there's a danger of leaking
the FILE object. Since there is a limited supply of the objects we can easily
test that the leak does not happen.
2015-04-12 02:34:48 -07:00
Arseny Kapoulkine
2537cccad3 tests: Fix some Coverity issues 2015-04-12 02:17:20 -07:00
Arseny Kapoulkine
3da7d68617 Fix Travis CI build. 2015-04-11 22:52:41 -07:00
Arseny Kapoulkine
4e004176ba tests: Improve out-of-memory tests
Previously there was no guarantee that the tests that check for out of memory
handling behavior are actually correct - e.g. that they correctly simulate out
of memory conditions.

Now every simulated out of memory condition has to be "guarded" using
CHECK_ALLOC_FAIL. It makes sure that every piece of code that is supposed to
cause out-of-memory does so, and that no other code runs out of memory
unnoticed.
2015-04-11 22:46:08 -07:00
Arseny Kapoulkine
37467c13bf tests: Add a test for throwing from xml_writer::write
We currently don't allocate/modify any state so there are no issues with this.
2015-04-11 22:44:42 -07:00
Arseny Kapoulkine
814443b147 Fix exception type for out-of-memory for XPath variables
When parsing XPath variables, we need to perform a heap allocation; if it
fails, an xpath_exception instead of bad_alloc used to be thrown.

Now we throw the exception of a correct type so that xpath_exception means
'parsing error'.
2015-04-11 22:40:30 -07:00
Arseny Kapoulkine
03ea04c32a tests: Use char_t instead of wchar_t 2015-04-11 00:33:35 -07:00
Arseny Kapoulkine
29fef9aca2 tests: Add more out of memory tests
This provides more coverage for #17.
2015-04-11 00:16:39 -07:00
Arseny Kapoulkine
e90d2ac8ba Merge branch 'master' into compact 2015-04-10 22:26:57 -07:00
Arseny Kapoulkine
f1d1534210 Fix archive packaging
Base directory is now using target basename.
2015-04-10 20:45:07 -07:00
Arseny Kapoulkine
5959a17967 tests: Final test fix for CW 2015-03-21 17:09:42 -07:00
Arseny Kapoulkine
250b690a54 tests: Work around fp issues in various runtime libraries
Disable/change some tests for some compilers; use binary float comparison
for early MSVC versions.
2015-03-21 01:05:31 -07:00
Arseny Kapoulkine
ce974094ac tests: Fix test compilation
Rename PAGE_SIZE to page_size to avoid define conflict with Android SDK.
Minor fixes in several tests.
2015-03-21 00:14:53 -07:00
Arseny Kapoulkine
86410cd696 tests: Fix tests in wchar mode 2015-03-18 21:30:30 -07:00
Arseny Kapoulkine
e68048518e Update version to 1.6 2015-03-18 21:20:40 -07:00
Arseny Kapoulkine
5f996eba6d Do not emit surrounding whitespace for text nodes
Previously we omitted extra whitespace for single PCDATA/CDATA children, but in
mixed content there was extra indentation before/after text nodes.

One of the problems with that is that the text that you saved is not exactly
the same as the parsing result using default flags (parse_trim_pcdata helps).

Another problem is that parse-format cycles do not have a fixed point for mixed
content - the result expands indefinitely. Some XML libraries, like Python
minidom, have the same issue, but this is definitely a problem.

Pretty-printing mixed content is hard. It seems that the only other sensible
choice is to switch mixed content nodes to raw formatting. In a way the code in
this change is a weaker version of that - it removes indentation around text
nodes but still keeps it around element siblings/children.

Thus we can switch to mixed-raw formatting at some point later, which will be
a superset of the current behavior.

To do this we have to either switch at the first text node (.NET XmlDocument
does that), or scan the children of each element for a possible text node and
switch before we output the first child.

The former behavior seems non-intuitive (and a bit broken); unfortunately, the
latter behavior can cost up to 20% of the output time for trees *without* mixed
content.

Fixes #13.
2015-03-18 09:59:17 -07:00
Arseny Kapoulkine
51da129b50 tests: Fix truncation test
data/truncation.xml was corrupted at some point and was not actually valid.
Fix the file and make the test fail if we can't parse truncation.xml at all.
2015-03-13 22:13:10 -07:00
Arseny Kapoulkine
6457f09412 Merge branch 'master' into compact 2015-03-13 08:12:46 -07:00
Arseny Kapoulkine
15fba1debc tests: Add support for afl-fuzz
With the current setup it successfully finds the (fixed) DOCTYPE buffer overrun
in ~50 minutes (on a single core).
2015-03-13 00:18:30 -07:00
Arseny Kapoulkine
0542b1869b Fix buffer overrun when parsing comments inside DOCTYPE 2015-03-12 20:21:59 -07:00
Arseny Kapoulkine
f81d7cc018 Merge branch 'master' into compact 2015-03-10 20:44:06 -07:00
Arseny Kapoulkine
604861e520 Escape ?> sequence in PI value during printing
This prevents malformed PI value from breaking the document structure.
2015-03-10 09:03:22 -07:00
Arseny Kapoulkine
12e137d12f tests: Move null buffer tests to test_document
Remove size=0 test since a better test is already there.
2015-03-05 11:46:34 -08:00
Arseny Kapoulkine
9749920c82 Refactor contents=0 behavior
Also change the error code to status_io_error
2015-03-05 11:35:39 -08:00
Arseny Kapoulkine
7ae7344256 Merge branch 'master' of https://github.com/mloy/pugixml into mloy-master 2015-03-05 10:09:54 -08:00
Arseny Kapoulkine
5a848de085 tests: Fix XPath string comparison
Also add new tests for translate. These are technically redundant since other
tests would catch the bug with the fixed comparison, but more tests is better.
2015-03-04 10:44:08 -08:00
Arseny Kapoulkine
ee4e2b8669 tests: Implement page heap for OSX/Linux
Align allocations to right end of page boundary to catch buffer overruns,
instead of unmapping on deallocations mark the page as no-access to guarantee
a page fault on use-after-free.
2015-03-01 20:57:22 -08:00
Arseny Kapoulkine
7835302297 tests: Fix tests for wchar mode 2015-02-12 08:54:44 -08:00
Arseny Kapoulkine
e94552c9ca DOCTYPE parsing is now stackless
This prevents malformed input XML with very deeply recursive DOCTYPE sections
from crashing the parser.

Fixes #29.
2015-02-12 08:12:12 -08:00
Arseny Kapoulkine
650a4c6cca Use string::append in implementations of xml_writer
The current code is not optimal; since users actually read samples/tests
change them to use faster (and shorter!) code.
2015-01-24 08:20:42 -08:00
Arseny Kapoulkine
3181a305ed tests: Fix MSVC 2008 compilation warning
Also include math.h to fix issues on some compilers.
2015-01-17 18:40:09 -08:00
Arseny Kapoulkine
617f302808 tests: Use Git instead of Subversion in autotest 2015-01-17 18:39:29 -08:00
Arseny Kapoulkine
e5ecbd63ce Merge branch 'master' into compact 2015-01-16 21:48:50 -08:00
Arseny Kapoulkine
d454013cff tests: Add tests for fp roundtrip
We test min/max and several different mantissas for the entire exponent range
for both float and double.

It's not clear whether all supported compilers provide an implementation of
sprintf/strtod that supports roundtripping so we may need to disable some of
these tests in the future.
2015-01-16 21:43:28 -08:00
Arseny Kapoulkine
f9ee391233 tests: Add coverage tests for new float setters
These only do basic testing to make sure the paths are covered and trivial
values work.
2015-01-16 21:42:35 -08:00
Arseny Kapoulkine
550ab4b635 Merge pull request #27 from sdoiel61/master
Make float/double round-trip

This change also adds xml_text::set and xml_attribute::set_value overloads for float so that float is only printed using just enough digits to represent float, instead of enough digits to represent double.
2015-01-16 20:54:58 -08:00
Steve Doiel
cf72c20ca1 Increase precision on large number test 2015-01-16 16:14:59 -08:00
Arseny Kapoulkine
f3e42969a5 Simplify header-only mode usage
It's sufficient to define PUGIXML_HEADER_ONLY anywhere now, source is included
automatically.

This is a second attempt; this time it includes a workaround for QMake bug
that caused it to generate incorrect Makefile.
2015-01-09 23:22:57 -08:00
Arseny Kapoulkine
ff16dbdd4c Don't use off64_t/_wfopen on MinGW32 in C++11 mode
Unfortunately, standard headers on MinGW32 insist on undefining off64_t
and _wfopen extensions if __STRICT_ANSI__ is true (e.g. C++11 mode). This
leads to compilation errors since b7a1fec started to use _wfopen in strict
mode. That change erroneously checked GCC version - however, the version
itself is irrelevant; the actual criteria is whether mingw64 runtime is
used.

off64_t is not useful on MinGW32 since we only need it to open large files
on 64-bit platforms; unfortunately, the lack of _wfopen means we won't be
able to support wide-char paths on Windows for MinGW32.

Fixes #24.
2014-12-13 20:34:10 -08:00
Arseny Kapoulkine
93c3ab4649 Merge branch 'master' into compact 2014-11-27 00:25:16 -08:00
Arseny Kapoulkine
b7a1feccf7 Use _wfopen and fseeko64 on MinGW in C++11 mode
Since MinGW 4.5 does not define these functions if __STRICT_ANSI__ is defined
(in case of _wfopen it defines it inconsistently between stdio.h and wchar.h)
use the baseline functions for MinGW 4.5 and earlier.

Fixes #23.
2014-11-24 20:49:12 -08:00
Arseny Kapoulkine
3e1ae89cf6 tests: Add a test for load_file with wide Unicode name 2014-11-24 18:27:54 -08:00
Arseny Kapoulkine
db8df4a566 Merge branch 'master' into compact 2014-11-20 23:47:16 -08:00
Arseny Kapoulkine
125aa55061 Fix node_declaration copying with empty name
node_copy_string relied on the fact that target node had an empty name and
value. Normally this is a safe assumption (and a good one to make since it
makes copying faster), however it was not checked and there was one case when
it did not hold.

Since we're reusing the logic for inserting nodes, newly inserted declaration
nodes had the name set automatically to xml, which in our case violates the
assumption and is counter-productive since we'll override the name right after
setting it.

For now the best solution is to do the same insertion manually - that results
in some code duplication that we can refactor later (same logic is partially
shared by _move variants anyway so on a level duplicating is not that bad).
2014-11-20 23:39:40 -08:00
Arseny Kapoulkine
417048d8cb tests: Fix tests on various compilers
Some compilers don't handle NaNs properly.
Some compilers don't implement fmod in a IEEE-compatible way.
Some compilers have exception handling codegen bugs (DMC...).
2014-11-19 16:34:57 -08:00
Arseny Kapoulkine
3c048bbb5e tests: Fix version test 2014-11-17 22:45:38 -08:00
Arseny Kapoulkine
e9956ae3a6 Rename xml_document::load to load_string
This should completely eliminate the confusion between load and load_file.
Of course, for compatibility reasons we have to preserve the old variant -
it will be deprecated in a future version and subsequently removed.
2014-11-17 19:52:23 -08:00
Arseny Kapoulkine
79ed320f89 tests: Don't use /dev/tty
The behavior on OSX is different - we don't get a I/O error so the test is
useless.
2014-11-17 08:35:34 -08:00
Arseny Kapoulkine
c74dc33604 Merge branch 'master' into compact 2014-11-07 21:02:44 +01:00
Arseny Kapoulkine
50bfdb1856 tests: Fix all tests for compact mode
Memory allocation behavior is different in compact mode so tests that rely
on current behavior have to be adjusted.
2014-11-06 09:59:07 +01:00
Arseny Kapoulkine
aa1a61c59f Fix xml_node::offset_debug for corner cases
Computed offsets for documents with nodes that were added using append_buffer
or newly appended nodes without name/value information were invalid.
2014-11-05 09:32:52 +01:00
Matthias Loy
1912894f53 :Merge remote-tracking branch 'upstream/master' 2014-11-03 20:23:35 +01:00
Arseny Kapoulkine
97a515f873 tests: Add more XPath mod tests 2014-11-03 07:50:00 +01:00
Arseny Kapoulkine
e9948b4b05 Fix undefined behavior while calling memcpy
Calling memcpy(x, 0, 0) is technically undefined (although it should usually
be a no-op).
2014-11-02 09:30:56 +01:00
Arseny Kapoulkine
f68a320a02 tests: Improve test coverage 2014-11-01 11:45:13 +01:00
mloy
837ced350c load_buffer_impl always checks if buffer is valid pointer and size > 0
added some tests to force invalid buffer and size = 0
2014-10-30 14:30:05 +01:00
Arseny Kapoulkine
6229138d80 Optimize node printing by using raw pointers
This lets us do fewer null pointer checks (making printing 2% faster with -O3)
and removes a lot of function calls (making printing 20% faster with -O0).
2014-10-27 22:29:14 -07:00
Arseny Kapoulkine
c64d4820b1 XPath: Optimize [position()=expr] and [last()]
To get more benefits from constant predicate/filter optimization we rewrite
[position()=expr] predicates into [expr] for numeric expressions. Right now
the rewrite is only for entire expressions - it may be beneficial to split
complex expressions like [position()=constant and expr] into [constant][expr]
but that is more complicated.

last() does not depend on the node set contents so is "constant" as far as
our optimization is concerned so we can evaluate it once.
2014-10-27 18:50:09 -07:00
Arseny Kapoulkine
d5e29292c6 XPath: Optimize constant filters/predicates
If a filter/predicate expression is a constant, we don't need to evaluate it
for every nodeset element - we can evaluate it once and pick the right element
or keep/discard the entire collection.

If the expression is 1, we can early out on first node when evaluating the
node set - queries like following::item[1] are now significantly faster.

Additionally this change refactors filters/predicates to have additional
metadata describing the expression type in _test field that is filled during
optimization.

Note that predicate_constant selection right now is very simple (but captures
most common use cases except for maybe [last()]).
2014-10-26 09:37:18 -07:00
Arseny Kapoulkine
f31c14e1fd tests: Remove git2svn helper script! 2014-10-26 02:22:27 -07:00
Arseny Kapoulkine
0e59ea8234 tests: Add a way for tests to verify allocation failure
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1081 99668b35-9821-0410-8761-19e4c4f06640
2014-10-26 03:46:28 +00:00
Arseny Kapoulkine
0b7964917c Fix node copying for some out of memory cases
A page can fail to allocate during attribute creation; this case was not
previously handled.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1080 99668b35-9821-0410-8761-19e4c4f06640
2014-10-25 16:37:16 +00:00
Arseny Kapoulkine
7b74531c1b tests: Fix test failure in PUGIXML_WCHAR_MODE
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1077 99668b35-9821-0410-8761-19e4c4f06640
2014-10-24 01:37:27 +00:00
Arseny Kapoulkine
546997683a tests: Add even more coverage tests
Also fix MSVC6 compilation (make convertions to function pointers explicit).

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1076 99668b35-9821-0410-8761-19e4c4f06640
2014-10-24 01:17:57 +00:00
Arseny Kapoulkine
903db8682a tests: Add more tests for better coverage
More tests for out-of-memory and other edge conditions

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1075 99668b35-9821-0410-8761-19e4c4f06640
2014-10-23 07:41:07 +00:00
Arseny Kapoulkine
bbd75fda46 tests: Improve test coverage
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1074 99668b35-9821-0410-8761-19e4c4f06640
2014-10-23 05:46:44 +00:00
Arseny Kapoulkine
3c92704c19 tests: Fix PUGIXML_WCHAR_MODE compilation
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1071 99668b35-9821-0410-8761-19e4c4f06640
2014-10-21 03:38:30 +00:00
Arseny Kapoulkine
7258aea09b tests: Assert on out-of-memory in tests
This should never happen but can improve debugging experience for
work-in-progress changes since that avoids memcpy() into negative memory
space (debugger can't backtrace from failed memcpy since it does not set
up the stack frame).

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1070 99668b35-9821-0410-8761-19e4c4f06640
2014-10-21 03:33:47 +00:00
Arseny Kapoulkine
7774cdd96e XPath: Make sure step_push is called with valid nodes
Some steps relied on step_push rejecting null inputs; this is no longer
the case. Additionally stepping now more rigorously filters null inputs.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1069 99668b35-9821-0410-8761-19e4c4f06640
2014-10-21 03:33:37 +00:00
Arseny Kapoulkine
45b6315d99 tests: Add a coverage test for unspecified_bool
It's unfortunate that we can even do that...

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1068 99668b35-9821-0410-8761-19e4c4f06640
2014-10-20 01:00:56 +00:00
Arseny Kapoulkine
1b8b87904b XPath: Introduce _first/_any set evaluation modes
Sometimes when evaluating the node set we don't need the entire set and
only need the first element in docorder or any element. In the absence of
iterator support we can still use this information to short-circuit
traversals.

This does not have any effect on straightforward node collection queries,
but frequently improves performance of complex queries with predicates
etc. XMark benchmark gets 15x faster with some queries enjoying 100x
speedup on 10 Mb dataset due to a significant complexity improvement.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1067 99668b35-9821-0410-8761-19e4c4f06640
2014-10-20 01:00:48 +00:00
Arseny Kapoulkine
c3eb9c92a8 XPath: Rename xml_node::select_single_node to ::select_node
select_node is shorter and mistyping nodes as node or vice versa should
not lead to any issues since return types are substantially different.

select_single_node method still works and will be deprecated with an
attribute and removed at some point.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1065 99668b35-9821-0410-8761-19e4c4f06640
2014-10-19 07:33:51 +00:00
Arseny Kapoulkine
f663558875 XPath: Introduce xpath_query::evaluate_node
This method is equivalent to xml_node::select_single_node. This makes
select_single_node faster in certain cases by avoiding an allocation and -
more importantly - paves the way for future step optimizations.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1064 99668b35-9821-0410-8761-19e4c4f06640
2014-10-19 07:33:42 +00:00
Arseny Kapoulkine
72ec01c5f6 XPath: Extend the descendant-or-self optimization
Use descendant-or-self::node() transformation for self, descendant and
descendant-or-self axis. Self axis should be semi-frequent; descendant
axes should not really be used with // but if they ever are the complexity
of the step becomes quadratic so it's better to optimize this if possible.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1063 99668b35-9821-0410-8761-19e4c4f06640
2014-10-18 15:28:02 +00:00
Arseny Kapoulkine
45e0c726f0 tests: Disable tests that rely on ceil() on CLR
CLR x64 JIT does not implement ceil() properly (ceil(-0.1) returns
positive zero instead of negative zero). Disable the relevant portions of
tests so that everything else is green...

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1062 99668b35-9821-0410-8761-19e4c4f06640
2014-10-16 06:41:04 +00:00
Arseny Kapoulkine
5da51dff27 XPath: Optimize attribute axis lookup
When looking for an attribute by name, finding the first attribute means
we can stop looking since attribute names are unique. This makes some
queries faster by 40%.

Another very common pattern in XPath queries is finding an attribute with
a specified value using a predicate (@name = 'value'). While we perform an
optimal amount of traversal in that case, there is a substantial overhead
with evaluating the nodes, saving and restoring the stack state, pushing
the attribute node into a set, etc. Detecting this pattern allows us to
use optimized code, resulting in up to 2x speedup for some queries.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1061 99668b35-9821-0410-8761-19e4c4f06640
2014-10-16 03:46:42 +00:00
Arseny Kapoulkine
883031fb45 XPath: Fix optimization bug with //name[last()]
The actual condition for the optimization is invariance from context list
-- this includes both position() and last().

Instead of splitting the posinv concept just include last() into
non-posinv expressions - this requires sorting for boolean predicates that
depend on last() and do not depend on position(). These cases should be
very rare.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1060 99668b35-9821-0410-8761-19e4c4f06640
2014-10-15 06:05:49 +00:00
Arseny Kapoulkine
87d4f03187 tests: Add a test for printing comments that contain --
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1059 99668b35-9821-0410-8761-19e4c4f06640
2014-10-14 04:11:26 +00:00
Arseny Kapoulkine
9e6dcc292d tests: Add XPath sorting test
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1054 99668b35-9821-0410-8761-19e4c4f06640
2014-10-05 08:39:44 +00:00
Arseny Kapoulkine
5239fcbd00 XPath: Implement optimized translate()
translate() with constant arguments now uses a 128-byte table and a table
lookup instead of searching characters in the source string. The table is
generated during query optimization.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1052 99668b35-9821-0410-8761-19e4c4f06640
2014-10-05 07:57:58 +00:00
Arseny Kapoulkine
b17501c3fb tests: Add XPath sorting tests and a simple test for numeric predicates
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1051 99668b35-9821-0410-8761-19e4c4f06640
2014-10-05 04:20:52 +00:00
Arseny Kapoulkine
f3b220ca4e tests: Fix MSVC6 compilation
Also fixes PUGIXML_NO_STL compilation and makes it possible to build with
any version of new Windows SDK.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1044 99668b35-9821-0410-8761-19e4c4f06640
2014-10-03 02:40:11 +00:00
Arseny Kapoulkine
59409f70ef tests: Add a test for out-of-memory during copy
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1040 99668b35-9821-0410-8761-19e4c4f06640
2014-10-02 16:19:55 +00:00
Arseny Kapoulkine
4d39ae9e45 tests: Add a test to verify that xml_document object works with any valid pointer alignment
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1039 99668b35-9821-0410-8761-19e4c4f06640
2014-10-02 03:07:08 +00:00
Arseny Kapoulkine
3fcc530b34 tests: Add missing tests to increase code coverage
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1038 99668b35-9821-0410-8761-19e4c4f06640
2014-10-02 03:06:59 +00:00
Arseny Kapoulkine
290bf521fa tests: Add XPath sorting tests for move/append_buffer
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1035 99668b35-9821-0410-8761-19e4c4f06640
2014-10-01 07:03:12 +00:00
Arseny Kapoulkine
3ae516abe2 tests: Add tests for copyless copy and related potential bugs
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1033 99668b35-9821-0410-8761-19e4c4f06640
2014-10-01 07:02:59 +00:00
Arseny Kapoulkine
0c1a4f40fe tests: Fix allocator.cpp indentation
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1030 99668b35-9821-0410-8761-19e4c4f06640
2014-10-01 07:02:39 +00:00
Arseny Kapoulkine
d519f7a473 tests: Add a test for stackless copy
This test has previously caused a stack overflow on x86/MSVC.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1028 99668b35-9821-0410-8761-19e4c4f06640
2014-09-28 23:23:35 +00:00
Arseny Kapoulkine
5b875e8487 tests: Add one more XPath optimization test
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1022 99668b35-9821-0410-8761-19e4c4f06640
2014-09-23 04:40:05 +00:00
Arseny Kapoulkine
89fc7c241c tests: More XPath tests
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1020 99668b35-9821-0410-8761-19e4c4f06640
2014-09-23 04:39:51 +00:00
Arseny Kapoulkine
53550424d9 tests: Fix PUGIXML_WCHAR_MODE build
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1017 99668b35-9821-0410-8761-19e4c4f06640
2014-09-21 21:52:24 +00:00
Arseny Kapoulkine
27109cd626 tests: Add test for custom indentation strings
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1016 99668b35-9821-0410-8761-19e4c4f06640
2014-09-21 21:52:19 +00:00
Arseny Kapoulkine
3abba14e72 tests: Add a test for stackless write.
This test previously caused a stack overflow on x86/MSVC.

git-svn-id: https://pugixml.googlecode.com/svn/trunk@1015 99668b35-9821-0410-8761-19e4c4f06640
2014-09-21 21:52:13 +00:00
Arseny Kapoulkine
fbfe207fe6 tests: Add git-svn reviving script
git-svn-id: https://pugixml.googlecode.com/svn/trunk@1010 99668b35-9821-0410-8761-19e4c4f06640
2014-09-12 15:04:20 +00:00