0
0
mirror of https://github.com/zeux/pugixml.git synced 2025-01-15 02:17:56 +08:00

1674 Commits

Author SHA1 Message Date
Arseny Kapoulkine
1298c8db79 Fix -Wshadow warning 2015-10-17 12:14:04 -07:00
Arseny Kapoulkine
809f992f83 Fix MSVC6 header-only build
name_sentry dtor results in multiple symbol definition errors in MSVC6.
2015-10-17 10:51:20 -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
e8e54ea5de Use explicit tests in set_Name/set_value
Node type enum is not used as an array index anywhere else; the code is not
very readable and the value of this "optimization" is questionable.

The conditions are arranged so that in all normal cases the first comparison
returns true anyway.
2015-10-17 10:26:57 -07:00
Arseny Kapoulkine
122157eb0e Fix argument mismatch in integer parsing
The minneg argument is supposed to be the absolute value of the minimum negative
representable number. In case of two-complement arithmetic, it's the same as the
value itself but it's better to be explicit and negate the argument.
2015-10-17 10:14:52 -07:00
Arseny Kapoulkine
4230292830 Add compact_hash_table assertions 2015-10-17 10:13:40 -07:00
Arseny Kapoulkine
67702277e6 docs: Add a note about moving xpath_query 2015-10-17 08:59:41 -07:00
Arseny Kapoulkine
384db6ba29 Refactor output buffer encoding
Share the implementation for different encodings. We still need two functions
because endian_swap on uint8_t is ambiguous...
2015-10-12 09:15:01 -07:00
Arseny Kapoulkine
9aa28f1d05 docs: Regenerate HTML documentation 2015-10-10 13:51:34 -07:00
Arseny Kapoulkine
2ebd15b5d7 scripts: Use changelog URL as release notes 2015-10-10 13:51:01 -07:00
Arseny Kapoulkine
6b26a9a7f6 docs: Correct the acknowledgment section 2015-10-10 13:42:56 -07:00
Arseny Kapoulkine
f010cabb44 scripts: Use /Z7 for NuGet package
This avoids linker warning when building the final executable and we don't
have to package the .PDB file.
2015-10-10 13:32:40 -07:00
Arseny Kapoulkine
537aea56c6 tests: Fix version check :) 2015-10-10 13:07:53 -07:00
Arseny Kapoulkine
540424bd76 Add .gitignore 2015-10-10 13:05:04 -07:00
Arseny Kapoulkine
6fa0b39390 docs: Update changelog for 1.7 2015-10-10 13:04:06 -07:00
Arseny Kapoulkine
285fec31fc Fix 'make release' after clean checkout 2015-10-10 12:35:40 -07:00
Arseny Kapoulkine
0cfdba262e Update version to 1.7 2015-10-10 12:34:35 -07:00
Arseny Kapoulkine
99599f73e4 scripts: Fix NuGet description formatting 2015-10-10 11:53:58 -07:00
Arseny Kapoulkine
3147190f3d scripts: Cleanup NuGet packaging
Move pugixml project file for VS2015 to scripts/ and unify the output file
structure similar to old VS201x projects. Remove test projects and solution
since they are not required for building.

Provide more accurate information in the package script and handle build
errors during package construction properly.
2015-10-10 11:42:25 -07:00
Arseny Kapoulkine
c356bb071f Merge branch 'master' of https://github.com/igagis/pugixml into nuget 2015-10-10 10:55:22 -07:00
Arseny Kapoulkine
3e9cf53ea7 tests: Add a test for empty xpath_query ctor 2015-10-09 20:53:02 -07:00
Arseny Kapoulkine
bfc0f346b4 Refactor utf_decoder classes
Instead of functions with different names (e.g. decode_utf8_block), split
utf_decoder class into multiple classes with ::process static function.

This makes it easier to share code for decoding different encodings.
2015-10-09 20:46:39 -07:00
Ivan Gagis
ea190c8bd2 changed nuget name to pugixml without lib prefix 2015-10-08 13:33:54 +03:00
Arseny Kapoulkine
8ebab20fa5 Use correct type for lead in decode_utf16_block
This does not affect correctness but makes code more uniform.
2015-10-07 23:35:23 -07:00
Arseny Kapoulkine
e51a1a38e8 Refactor decode_utfN_block and decode_latin1_block
Make sure the looping structure is the same as in decode_utf8_block.
2015-10-07 22:42:37 -07:00
Arseny Kapoulkine
9f0a57a8f4 Simplify file/stream loading flow
Instead of calling xml_document public functions just call implementation of
load_buffer_inplace_own. This makes it so we only call reset() once during
load_file/load.
2015-10-07 22:06:43 -07:00
igagis
1402820ed0 Delete ReadMe.txt 2015-10-07 22:06:52 +03:00
Ivan Gagis
48beabdb3f nuget package scripts 2015-10-07 22:03:12 +03:00
Ivan Gagis
b112341a64 VisualStudio 2015 solution added 2015-10-07 21:46:35 +03: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
299e0b07c9 Merge pull request #58 from Breush/patch-1
Fixed missing PUGI__FN
2015-10-06 07:22:32 -07:00
A. Breust
dd2166ee27 Fixed missing PUGI__FN 2015-10-06 15:13:34 +02:00
Arseny Kapoulkine
2cda053345 scripts: Enable C++11 in CMakeLists
We now make sure that in CMake builds we have long long support. This requires
CMake 3.1 for target_compile_features.

Fixes #53 (as long as packages use this CMake script... most of them do)
2015-09-23 08:41:42 -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
b0b84277fa Merge pull request #56 from zeux/travis-osx
Add OSX to Travis CI config
2015-09-20 12:01:10 -07:00
Arseny Kapoulkine
d2252c5634 build: Reduce the build matrix
We don't need to test gcc on OSX
2015-09-20 11:48:31 -07:00
Arseny Kapoulkine
2ae191fe6f build: Add OSX to Travis config 2015-09-20 11:31:58 -07:00
Arseny Kapoulkine
1b2c1914b2 Fix signed/unsigned warnings for MSVC 2015-09-20 10:58:51 -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
ec0c9c5561 Implement custom string to integer conversion
This makes conversion significantly faster and removes more CRT dependencies;
in particular, to support long long pugixml only requires the type itself (and
the division operator...).

New implementation is up to 3x faster on short decimal numbers.

Note that unlike the old implementation, new implementation correctly handles
overflow and underflow and clamps the value to the representable range. This
means that there are some behavior changes - e.g. previously as_uint on "-1"
would return INT_MAX instead of 0.

In addition to CRT issues, for platforms with 64-bit long old implementation
incorrectly truncated from long to int or unsigned int, so even if CRT clamped
the values the result would have been incorrect.
2015-09-20 10:43:38 -07:00
Arseny Kapoulkine
bda55c818c Remove extra const from operator= declaration
This does not really matter too much but it's better to be consistent.
2015-09-20 00:48:40 -07:00
Arseny Kapoulkine
25cce38f50 Inline widen_ascii to get rid of an extra strlen call
Also since this function is only used once and is not defined in regular mode
to avoid warnings this simplifies code a bit.
2015-09-20 00:47:20 -07:00
Arseny Kapoulkine
9c539f92ab Eliminate redundant strlen calls during set_value/set
Since we use manual integer conversion we know the length of the string.

This makes set_value(int) ~30% faster for 4-digit numbers.
2015-09-20 00:43:37 -07:00
Arseny Kapoulkine
5750b7cc19 Force callers of strcpy_insitu to compute string length
This makes it possible to avoid calling strlen if we already know the string
size.
2015-09-20 00:19:30 -07:00
Arseny Kapoulkine
131c1a159c Implement integer to string conversion manually
This reduces the amount of non-standard C++ functionality pugixml may be using
by avoiding sprintf with %lld; additionally this implementation is significantly
faster (4-5x) than sprintf, mostly due to avoiding format string parsing and
stream setup that commonly happens in CRT implementations.

This comes at the expense of requiring long long division/remainder operations
if PUGIXML_USE_LONG_LONG is defined which will surely bite me one day.
2015-09-20 00:03:02 -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
d62b2541d7 Update README.md 2015-08-25 10:42:59 -07:00
Arseny Kapoulkine
abdba2235d build: Fix -o gcov option
Also upload just pugixml.cpp.gcov to codecov to avoid issues the script has
with old gcov.
2015-08-25 10:36:44 -07:00
Arseny Kapoulkine
c7acc6d1f4 build: Rework config=coverage to be more robust
Use find -exec instead of xargs to work around differences between xargs on OSX
and Linux.

Use -b option of gcov - for some reason gcov on Travis can't find .gcno files
otherwise (old version?).

And finally enable config=coverage again.
2015-08-25 09:57:21 -07:00
Arseny Kapoulkine
9865f042ed build: Disable config=coverage for now 2015-08-25 09:25:32 -07:00
Arseny Kapoulkine
ff85f2106c build: Actually use config=coverage 2015-08-25 08:18:13 -07:00
Arseny Kapoulkine
440116a75b build: Test codecov.io integration 2015-08-25 08:14:26 -07:00
Arseny Kapoulkine
1d854cd420 build: Simplify coverage configuration
Use -coverage option and keep NDEBUG off
2015-08-25 08:14:20 -07:00
Arseny Kapoulkine
ce4ac17780 docs: Clarify UTF-8 vs wchar_t memory efficiency 2015-08-14 07:55:24 -07:00
Arseny Kapoulkine
c55e551235 docs: Add PUGIXML_COMPACT documentation
Also add PUGIXML_COMPACT to pugiconfig.hpp
2015-08-14 07:55:24 -07:00
Arseny Kapoulkine
fd0467c568 Minor get_integer_base optimization
Remove an extra branch.
2015-08-14 07:55:24 -07:00
Arseny Kapoulkine
f738675f1d Fix two UB sanitizer false positives
Change the expression to reference the array element indirectly. The memory
block can be bigger than the structure so it's invalid to use static data[]
size for bounds checking.
2015-07-26 21:04:52 -07:00
Arseny Kapoulkine
bd7a8fa4bf XPath: Increase memory block alignment to 8 bytes
To be more precise, the memory block is now aligned to be able to reliably
allocate objects with both double and pointer fields. If there is a platform
with a 4-byte double and a 4-byte pointer, the memory block alignment there will
stay the same after this change.

Fixes #48.
2015-07-25 17:08:19 -04: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
66f242a4a9 XPath: Refactor block allocation
Extract memory page size and block alignment into named constants.
2015-07-25 17:01:30 -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
4460da54a1 XPath: Split optimize into optimize and optimize_self
This makes the code slightly more readable, but more importantly it fixes a
false positive in Clang static analyzer.

Fixes #47.
2015-07-22 21:07:44 -07:00
Arseny Kapoulkine
d4fedd6775 docs: Clarify hash_value behavior
Fixes #43.
2015-06-24 09:45:26 -07:00
Arseny Kapoulkine
238b786bfe Makefile now supports Xcode 7 ASAN
All other sanitizers are still unavailable so only enable them on non-OSX
systems.
2015-06-13 00:00:08 -07:00
Arseny Kapoulkine
d04df2a48b Fix Clang 3.7 compatibility
Apparently Clang 3.7 implements C++ DR 1748 that makes placement new with null
pointer undefined behavior. Which renders all C++ programs that rely on this
invalid. Which includes pugixml.

This is not very likely to happen in the wild because the allocations that are
subject to this in pugixml are relatively small, but tests break because of
this.

Fix the issue by adding null pointer checks (that are completely redundant in
all current compilers except Clang 3.7 but it's not like there is another
option).
2015-06-12 23:59:35 -07:00
Arseny Kapoulkine
97afc16ef2 tests: Add newline at the end of file 2015-05-22 20:20:03 -07:00
Arseny Kapoulkine
2a1aa9663b Fix MSVC7 compilation
Work around a name lookup bug by pulling auto_deleter name in the local
scope. We could also move auto_deleter to pugi:: namespace, but that
pollutes it unnecessarily for other compilers.
2015-05-22 18:05:30 -07:00
Arseny Kapoulkine
fc1dcab79d tests: Fix MSVC6 compilation 2015-05-22 08:43:36 -07:00
Arseny Kapoulkine
677e95010e Move default value handling into as_ functions
This makes get_value_* simpler and also works around DMC compilation issue.
2015-05-22 08:42:32 -07:00
Arseny Kapoulkine
243839012a XPath: Use strtod instead of atof
This makes code more consistent between wchar/utf8 mode.
2015-05-20 08:31:00 -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
107239c927 Add config=sanitize support to Makefile 2015-05-12 20:57:57 -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
708952d84e Update README.md 2015-05-03 19:15:47 -07:00
Arseny Kapoulkine
51faffa238 Update README.md 2015-05-03 19:12:23 -07:00
Arseny Kapoulkine
272c80f67c Switch Travis CI to use Docker 2015-05-03 18:40:21 -07:00
Arseny Kapoulkine
86548e14bd Fix NO_STL+NO_XPATH mode
auto_deleter is now used in all modes so we can't exclude it from compilation.
2015-05-03 17:58:20 -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
873c8e5011 Merge pull request #42 from zeux/compact
Implement compact mode.

This introduces a new storage mode that dramatically reduces node size at some performance cost.
The mode is enabled by defining PUGIXML_COMPACT. This does not change API/ABI - all existing functionality still works.

The pointers are stored using delta encoding and bytes, with some additional tricks to make encoding more optimal for e.g. parent pointer and string pointers. Since the node is fixed size, we have to fall back to a hash table if the pointer does not fit. Thus all DOM operations still have amortized complexity - constant number of operations if you don't need the hash table and amortized constant if you do.

Aside from some performance loss (which is inevitable since decoding takes time), the only other caveat is that we can't remove entries from the hash table - so in some edge cases with a lot of node removals the peak memory consumption can grow indefinitely. In theory we can implement this later; it's unclear that this is useful at this point.

The resulting node/attribute sizes are as follows:
non-compact node: 28b 32-bit, 56b 64-bit
compact node: 12b 32/64-bit
non-compact attribute: 20b 32-bit, 40b 64-bit
compact attribute: 8b 32/64-bit
2015-05-03 11:42:19 -07:00
Arseny Kapoulkine
9597265a12 Cleanup before merge 2015-05-03 11:02:42 -07:00
Arseny Kapoulkine
b1965061af Fix MSVC warning 2015-05-03 09:21:23 -07:00
Arseny Kapoulkine
f67e761970 Fix MSVC build 2015-05-02 16:41:21 -07:00
Arseny Kapoulkine
20e2041f14 Reorder conditions in compact_string implementation
Now compact_string matches compact_pointer_parent.

Turns out PUGI__UNLIKELY is good at reordering conditions but usually does not
really affect performance. Since MSVC should treat "if" branches as taken and
does not support branch probabilities, don't use them if we don't need to.
2015-05-02 15:57:46 -07:00
Arseny Kapoulkine
f8915c8eab Minor refactoring 2015-05-02 15:47:59 -07:00
Arseny Kapoulkine
fa8663c066 Revise marker deletion strategy
Instead of checking if the object being removed allocated a marker, mark the
marker block as deleted immediately upon allocation. This simplifies the logic
and prevents extra markers from being inserted if we allocate/deallocate the
same node indefinitely.

Also change marker pointer type to uint32_t*.
2015-05-02 15:40:30 -07:00
Arseny Kapoulkine
613301ce51 Optimize compact_string
First assignment uses a fast path; second assignment uses a specialized
path as well.
2015-05-02 14:52:27 -07:00
Arseny Kapoulkine
19d43d39fc tests: Add one more page reclamation test 2015-05-02 09:45:26 -07:00
Arseny Kapoulkine
b1578e32a5 Fix node deallocation
When we deallocate nodes/attributes that allocated the marker we have to
adjust the size accordingly, and dismiss the marker in case it gets
overwritten with something else...
2015-05-02 09:38:14 -07:00
Arseny Kapoulkine
dec4267fb1 Implement efficient compact_header storage
Header is now just 2 bytes, with optional additonal 4 bytes that are only
allocated for every 85 nodes / 128 attributes.
2015-05-02 08:59:47 -07:00
Arseny Kapoulkine
e4c539a869 Implement compact_string with shared storage 2015-05-01 22:47:53 -07:00
Arseny Kapoulkine
3915f7b144 Rename compact_string to compact_string_fat 2015-05-01 21:09:26 -07:00
Arseny Kapoulkine
bc5eb22b71 Revert to name/value storage inside node
This temporarily increases the node size to 16 bytes - we'll bring it back.

It allows us to remove the horrible node_pi hack and to reduce the amount of
changes against master. This comes at the price of not decreasing basline
xml_node_struct size.

The compact xml_node_struct is also increased by this change but a followup
change will reduce *both* xml_attribute_struct and xml_node_struct (to 8/12
bytes).
2015-05-01 20:03:17 -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
b2399f5ab5 Refactor offset_debug
Split a long line into multiple statements.
2015-04-29 09:20:08 -07:00
Arseny Kapoulkine
44e4f17348 Change xml_node_struct field order to match compact
Also remove useless comments.
2015-04-22 09:53:04 -07:00
Arseny Kapoulkine
3643b505a6 Fix node_pi memory leak 2015-04-22 08:38:52 -07:00