Skip to content
Snippets Groups Projects
  1. Jun 05, 2023
  2. Jun 04, 2023
    • Jonathan Schöbel's avatar
      NodeFragment: added remove_attr methods · 76e06eec
      Jonathan Schöbel authored
      Two alternatives are provided: remove_attr and pop_attr. While the
      former free's the Attr's data, the latter allocates a new Attr, to store
      and return the data. Both functionality is provided by a single
      (internal) static method.
      76e06eec
  3. Jun 03, 2023
  4. Jun 02, 2023
    • Jonathan Schöbel's avatar
      NodeFragment: added tests for get_attr method. · e8deb8ce
      Jonathan Schöbel authored
      added tests for getter
      e8deb8ce
    • Jonathan Schöbel's avatar
      fixup! Attr: (internal) added move method · 51a3ab66
      Jonathan Schöbel authored
      This is a severe bug. The purpose of Attr_free is to free the internal
      data, while leaving the outer structure unfreed. What is needed here is
      quite the opposite: freeing the outer structure but leaving the internal
      data intact. Of course the internal data is still needed, as it is data
      that was just assigned to the dest Attr. This bug introduced a double
      free, which is undefined behaviour with all of it's scary effects.
      51a3ab66
    • Jonathan Schöbel's avatar
      Attr: added is_equal_name method · 1eb4c294
      Jonathan Schöbel authored
      Sometimes it is interesting to know, whether to Attr are referring to
      the same attribute. Note that it is not intended to provide a method for
      the values, as that would be meaningless on its own and if it is used in
      a more complex tasks, this is still possible with the current set of
      methods, which is prefered as the complex task can then be implemented
      on the outside completely.
      1eb4c294
    • Jonathan Schöbel's avatar
      Attr: added is_equal method · 86d926c5
      Jonathan Schöbel authored
      A method to compare two Attr's for exact equality was added both to
      internal and external methods.
      86d926c5
  5. Jun 01, 2023
    • Jonathan Schöbel's avatar
      NodeFragment: added insert_copy methods for attributes · 7ccc8bee
      Jonathan Schöbel authored
      Sometimes you want to reuse an Attr after adding it, this is done via
      the insert_copy methods.
      7ccc8bee
    • Jonathan Schöbel's avatar
      fixup! NodeFragment: added remove methods · c747392d
      Jonathan Schöbel authored
      When a child is removed, the array may be reallocated, to not waste
      unused memory. If the child is removed out of the middle, all subsequent
      childs have to be moved. However, if it turns out that the reallocation
      is not currently possible, the method should return the NodeFragment in
      a state, as if the call to the remove method never happened. This means,
      that all the childs, that were moved before the realloc call, have to be
      moved back and the original child has also to be written back. This was
      forgotten, which is clearly a bug, which is fixed hereby.
      Note that it would be theoretically possible to not move everything back
      and forth, by storing the last value before the call to realloc and only
      in case of success move everything. While this is possible and more
      efficient, it is also a bit more complicated, and as this only takes
      effect, if the OS fails to provide memory, which should be an uncommon
      event, the algorithm is not changed, leaving that possible inefficient
      approach.
      c747392d
    • Jonathan Schöbel's avatar
      NodeFragment: added getter & insert methods for attributes · 13ac85b5
      Jonathan Schöbel authored
      The method SH_NodeFragment_get_attr provides a pointer to an Attr, by
      its index. Note, that it directly points to the internal data, instead
      of copying the data to a new Attr, which would be unneccessary overhead,
      if only reading access is needed. That's why it is also a const pointer.
      If the user intends to modify it, a copy should be taken via
      SH_Attr_copy.
      
      Multiple insert methods allow either to add an existing Attr, or to
      create a new one implicitly. If the Attr is not already used beforehand,
      it is more efficient to call the attr_new methods. Also an old Attr is
      freed, after it was inserted, thus it can't be used afterwards. This is
      neccessary, as for efficiency reasons an array of Attr is used directly,
      instead of the indirect approach of storing a pointer of Attr. This
      means, that the contents of the Attr has to be copied to the internal
      structure. If the old Attr would be left unfreed, there would be two
      Attrs, the original one and the implicit one, referring to the same
      data, which would lead to at least data corruption, or undefined
      behaviour like a double free, which would be a serious threat for a
      library which is to be used on a webserver. ...
      For each of the two insert modes, there is a method to prepend, append
      or insert at a specific position. An incorrect position is handled
      inside of the external method and an E_VALUE is thrown. The internal
      method doesn't handle this, so special care must be taken to not make
      undefined behaviour. However enforcing this check would be unneccessary
      overhead for the prepend and append methods, which are known to have
      correct indicies, as well for other internal methods, where the internal
      method may be used.
      
      The tests for the new methods are still missing, as well as the methods
      to remove an Attr. As the implementation is already a bit dated, the
      changes are commited now anyways.
      13ac85b5
  6. Mar 20, 2023
  7. Mar 17, 2023
  8. Mar 16, 2023
    • Jonathan Schöbel's avatar
      NodeFragment: added remove methods · 8d84e3c7
      Jonathan Schöbel authored
      Various remove methods were added, which are all implemented by an
      static method, analog to the last commit.
      8d84e3c7
    • Jonathan Schöbel's avatar
      NodeFragment: improved insert methods · 1e575a13
      Jonathan Schöbel authored
      The single method (formerly SH_NodeFragment_append_child) to add a child
      at the end of the child list was replaced, by a bunch of methods to
      insert a child at the beginning (SH_NodeFragment_prepend_child), at the
      end (SH_NodeFragment_append_child), at a specific position
      (SH_NodeFragment_insert_child) and directly before
      (SH_NodeFragment_insert_child_before) or after another child
      (SH_NodeFragment_insert_child_after). All these methods are implemented
      by a single internal one (insert_child), as there isn't really much
      difference in inserting one or the other way.
      But this internal method doesn't check whether this insertion request is
      actually doable, to save overhead as not every insertion method requires
      this check. This is done by the respective method. However if the check
      is not done correctly the internal method will attempt to write at not
      allocated space, which will hopefully result in a segfault.
      
      The child list is implemented as an array. To reduce the overhead to
      realloc calls, the array is allocated in chunks of childs. The
      calculation how many has to be allocated is done by another static
      method and determined by the macro CHILD_CHUNK. This is set to 5, which
      is just a guess. It should be somewhere around the average number of
      childs per html element, to reduce unused overhead.
      
      Also some predicates (SH_NodeFragment_is_parent,
      SH_NodeFragment_is_ancestor) were added to check whether a relationship
      exists between to nodes, thus whether they are linked through one or
      multiple levels. These functions could replace the old ones
      (SH_NodeFragment_is_child, SH_NodeFragment_is_descendant) semantically.
      Furthermore they are more efficient as this is now possible to check
      over the parent pointer. The internal insert method also uses these
      methods to check whether the child node is actually a parent of the
      parent node, which would result in errors later one.
      
      The old test is now obsolete but remained, as it is not bad to test
      more.
      1e575a13
  9. Mar 13, 2023
    • Jonathan Schöbel's avatar
      fixup! implement NodeFragment as Fragment · 95051add
      Jonathan Schöbel authored
      Removed some unnecessary type casts.
      Added some forgotten calls to free.
      95051add
    • Jonathan Schöbel's avatar
      Fragment: added parent · 92ed2019
      Jonathan Schöbel authored
      Every fragment has a parent now, this is useful for both traversing the
      tree and checking for cycles when a node is added, which would cause
      problems, like freeing things twice or similar nice bugs. Both wouldn't
      be possible otherwise. These features are not implemented yet.
      92ed2019
    • Jonathan Schöbel's avatar
      NodeFragment: added unsafe getter for tag · 0bab1f50
      Jonathan Schöbel authored
      The library provides a way to directly access the tag in a read-only
      way, which saves an call to strdup. This is useful if only reading is
      necessary , but needs special care by developers, as it is neither
      allowed to modify it nor to free it. Disregarding this will lead to a
      segfault in the best, and to silent data corruption and security bugs in
      the worst case.
      0bab1f50
  10. Jan 09, 2023
Loading