Skip to content

Commit

Permalink
Merge branch 'zeux-master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
halx99 committed Feb 4, 2023
2 parents 5d8dbac + aee049f commit eae27e5
Show file tree
Hide file tree
Showing 20 changed files with 499 additions and 202 deletions.
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: Bug report
about: Create a report if you believe you've found a bug in this project; please use GitHub Discussions instead if you think the bug may be in your code.
title: ''
labels: bug
assignees: ''

---
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Help and support
url: https://github.com/zeux/pugixml/discussions
about: Please use GitHub Discussions if you have questions or need help.
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---
24 changes: 24 additions & 0 deletions .github/workflows/cifuzz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CIFuzz
on: [pull_request]
jobs:
Fuzzing:
runs-on: ubuntu-latest
steps:
- name: Build Fuzzers
id: build
uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master
with:
oss-fuzz-project-name: 'pugixml'
dry-run: false
- name: Run Fuzzers
uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master
with:
oss-fuzz-project-name: 'pugixml'
fuzz-seconds: 30
dry-run: false
- name: Upload Crash
uses: actions/upload-artifact@v3
if: failure() && steps.build.outcome == 'success'
with:
name: artifacts
path: ./out/artifacts
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.4)
project(pugixml VERSION 1.12 LANGUAGES CXX)
project(pugixml VERSION 1.13 LANGUAGES CXX)

include(CMakePackageConfigHelpers)
include(CMakeDependentOption)
Expand Down Expand Up @@ -101,6 +101,10 @@ if (BUILD_SHARED_LIBS)
${PROJECT_SOURCE_DIR}/src/pugixml.cpp)
add_library(pugixml::shared ALIAS pugixml-shared)
list(APPEND libs pugixml-shared)
string(CONCAT pugixml.msvc $<OR:
$<STREQUAL:${CMAKE_CXX_COMPILER_FRONTEND_VARIANT},MSVC>,
$<CXX_COMPILER_ID:MSVC>
>)

set_property(TARGET pugixml-shared PROPERTY EXPORT_NAME shared)
target_include_directories(pugixml-shared
Expand All @@ -111,7 +115,8 @@ if (BUILD_SHARED_LIBS)
${PUGIXML_BUILD_DEFINES}
${PUGIXML_PUBLIC_DEFINITIONS}
PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:PUGIXML_API=__declspec\(dllexport\)>)
PUGIXML_API=$<IF:${pugixml.msvc},__declspec\(dllexport\),__attribute__\(\(visibility\("default"\)\)\)>
)
target_compile_options(pugixml-shared
PRIVATE
${msvc-rt-mtd-shared}
Expand Down
68 changes: 58 additions & 10 deletions docs/manual.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,28 @@ xml_node xml_node::previous_sibling(const char_t* name) const;
for (pugi::xml_node tool = tools.child("Tool"); tool; tool = tool.next_sibling("Tool"))
----

[[xml_node::attribute_hinted]]
`attribute` function needs to look for the target attribute by name. If a node has many attributes, finding each by name can be time consuming. If you have an idea of how attributes are ordered in the node, you can use a faster function:

[source]
----
xml_attribute xml_node::attribute(const char_t* name, xml_attribute& hint) const;
----

The extra `hint` argument is used to guess where the attribute might be, and is updated to the location of the next attribute so that if you search for multiple attributes in the right order, the performance is maximized. Note that `hint` has to be either null or has to belong to the node, otherwise the behavior is undefined.

You can use this function as follows:

[source]
----
xml_attribute hint;
xml_attribute id = node.attribute("id", hint);
xml_attribute name = node.attribute("name", hint);
xml_attribute version = node.attribute("version", hint);
----

This code is correct regardless of the order of the attributes, but it's faster if `"id"`, `"name"` and `"version"` occur in that order.

[[xml_node::find_child_by_attribute]]
Occasionally the needed node is specified not by the unique name but instead by the value of some attribute; for example, it is common to have node collections with each node having a unique id: `<group><item id="1"/> <item id="2"/></group>`. There are two functions for finding child nodes based on the attribute values:

Expand Down Expand Up @@ -1254,6 +1276,7 @@ As discussed before, nodes can have name and value, both of which are strings. D
----
bool xml_node::set_name(const char_t* rhs);
bool xml_node::set_value(const char_t* rhs);
bool xml_node::set_value(const char_t* rhs, size_t size);
----

Both functions try to set the name/value to the specified string, and return the operation result. The operation fails if the node can not have name or value (for instance, when trying to call `set_name` on a <<node_pcdata,node_pcdata>> node), if the node handle is null, or if there is insufficient memory to handle the request. The provided string is copied into document managed memory and can be destroyed after the function returns (for example, you can safely pass stack-allocated buffers to these functions). The name/value content is not verified, so take care to use only valid XML names, or the document may become malformed.
Expand All @@ -1275,6 +1298,7 @@ All attributes have name and value, both of which are strings (value may be empt
----
bool xml_attribute::set_name(const char_t* rhs);
bool xml_attribute::set_value(const char_t* rhs);
bool xml_attribute::set_value(const char_t* rhs, size_t size);
----

Both functions try to set the name/value to the specified string, and return the operation result. The operation fails if the attribute handle is null, or if there is insufficient memory to handle the request. The provided string is copied into document managed memory and can be destroyed after the function returns (for example, you can safely pass stack-allocated buffers to these functions). The name/value content is not verified, so take care to use only valid XML names, or the document may become malformed.
Expand Down Expand Up @@ -1428,6 +1452,7 @@ Once you have an `xml_text` object, you can set the text contents using the foll
[source]
----
bool xml_text::set(const char_t* rhs);
bool xml_text::set(const char_t* rhs, size_t size);
----

This function tries to set the contents to the specified string, and returns the operation result. The operation fails if the text object was retrieved from a node that can not have a value and is not an element node (i.e. it is a <<node_declaration,node_declaration>> node), if the text object is empty, or if there is insufficient memory to handle the request. The provided string is copied into document managed memory and can be destroyed after the function returns (for example, you can safely pass stack-allocated buffers to this function). Note that if the text object was retrieved from an element node, this function creates the PCDATA child node if necessary (i.e. if the element node does not have a PCDATA/CDATA child already).
Expand Down Expand Up @@ -2138,6 +2163,23 @@ Because of the differences in document object models, performance considerations

:!numbered:

[[v1.13]]
=== v1.13 ^2022-11-01^

Maintenance release. Changes:

* Improvements:
. `xml_attribute::set_value`, `xml_node::set_value` and `xml_text::set` now have overloads that accept pointer to non-null-terminated string and size
. Improve performance of tree traversal when using compact mode (`PUGIXML_COMPACT`)

* Bug fixes:
. Fix error handling in `xml_document::save_file` that could result in the function succeeding while running out of disk space
. Fix memory leak during error handling of some out-of-memory conditions during `xml_document::load`

* Compatibility improvements:
. Fix exported symbols in CMake DLL builds when using CMake
. Fix exported symbols in CMake shared object builds when using -fvisibility=hidden

[[v1.12]]
=== v1.12 ^2022-02-09^

Expand Down Expand Up @@ -2798,6 +2840,7 @@ const unsigned int +++<a href="#parse_wnorm_attribute">parse_wnorm_attribute</a>
bool +++<a href="#xml_attribute::set_name">set_name</a>+++(const char_t* rhs);
bool +++<a href="#xml_attribute::set_value">set_value</a>+++(const char_t* rhs);
bool +++<a href="#xml_attribute::set_value">set_value</a>+++(const char_t* rhs, size_t size);
bool +++<a href="#xml_attribute::set_value">set_value</a>+++(int rhs);
bool +++<a href="#xml_attribute::set_value">set_value</a>+++(unsigned int rhs);
bool +++<a href="#xml_attribute::set_value">set_value</a>+++(long rhs);
Expand Down Expand Up @@ -2856,6 +2899,9 @@ const unsigned int +++<a href="#parse_wnorm_attribute">parse_wnorm_attribute</a>
xml_attribute +++<a href="#xml_node::attribute">attribute</a>+++(const char_t* name) const;
xml_node +++<a href="#xml_node::next_sibling_name">next_sibling</a>+++(const char_t* name) const;
xml_node +++<a href="#xml_node::previous_sibling_name">previous_sibling</a>+++(const char_t* name) const;
xml_attribute +++<a href="#xml_node::attribute_hinted">attribute</a>+++(const char_t* name, xml_attribute& hint) const;
xml_node +++<a href="#xml_node::find_child_by_attribute">find_child_by_attribute</a>+++(const char_t* name, const char_t* attr_name, const char_t* attr_value) const;
xml_node +++<a href="#xml_node::find_child_by_attribute">find_child_by_attribute</a>+++(const char_t* attr_name, const char_t* attr_value) const;
Expand Down Expand Up @@ -2884,6 +2930,7 @@ const unsigned int +++<a href="#parse_wnorm_attribute">parse_wnorm_attribute</a>
bool +++<a href="#xml_node::set_name">set_name</a>+++(const char_t* rhs);
bool +++<a href="#xml_node::set_value">set_value</a>+++(const char_t* rhs);
bool +++<a href="#xml_node::set_value">set_value</a>+++(const char_t* rhs, size_t size);
xml_attribute +++<a href="#xml_node::append_attribute">append_attribute</a>+++(const char_t* name);
xml_attribute +++<a href="#xml_node::prepend_attribute">prepend_attribute</a>+++(const char_t* name);
Expand Down Expand Up @@ -2996,16 +3043,17 @@ const unsigned int +++<a href="#parse_wnorm_attribute">parse_wnorm_attribute</a>
unsigned long long +++<a href="#xml_text::as_ullong">as_ullong</a>+++(unsigned long long def = 0) const;
bool +++<a href="#xml_text::set">set</a>+++(const char_t* rhs);
bool +++<a href="#xml_text::set">set</a>+++(int rhs);
bool +++<a href="#xml_text::set">set</a>+++(unsigned int rhs);
bool +++<a href="#xml_text::set">set</a>+++(long rhs);
bool +++<a href="#xml_text::set">set</a>+++(unsigned long rhs);
bool +++<a href="#xml_text::set">set</a>+++(double rhs);
bool +++<a href="#xml_text::set">set</a>+++(float rhs);
bool +++<a href="#xml_text::set">set</a>+++(bool rhs);
bool +++<a href="#xml_text::set">set</a>+++(long long rhs);
bool +++<a href="#xml_text::set">set</a>+++(unsigned long long rhs);
bool +++<a href="#xml_text::set">set</a>+++(const char_t* rhs, size_t size);
bool +++<a href="#xml_text::set_value">set</a>+++(int rhs);
bool +++<a href="#xml_text::set_value">set</a>+++(unsigned int rhs);
bool +++<a href="#xml_text::set_value">set</a>+++(long rhs);
bool +++<a href="#xml_text::set_value">set</a>+++(unsigned long rhs);
bool +++<a href="#xml_text::set_value">set</a>+++(double rhs);
bool +++<a href="#xml_text::set_value">set</a>+++(float rhs);
bool +++<a href="#xml_text::set_value">set</a>+++(bool rhs);
bool +++<a href="#xml_text::set_value">set</a>+++(long long rhs);
bool +++<a href="#xml_text::set_value">set</a>+++(unsigned long long rhs);
xml_text& +++<a href="#xml_text::assign">operator=</a>+++(const char_t* rhs);
xml_text& +++<a href="#xml_text::assign">operator=</a>+++(int rhs);
Expand Down
Loading

0 comments on commit eae27e5

Please sign in to comment.