Class Nokogiri::XML::NodeSet
In: lib/nokogiri/xml/node_set.rb
ext/nokogiri/xml_document_fragment.c
Parent: Object

xmlXPathFreeNodeSet() contains an implicit assumption that it is being called before any of its pointed-to nodes have been free()d. this assumption lies in the operation where it dereferences nodeTab pointers while searching for namespace nodes to free.

however, since Ruby‘s GC mechanism cannot guarantee the strict order in which ruby objects will be GC‘d, nodes may be garbage collected before a nodeset containing pointers to those nodes. (this is true regardless of how we declare dependencies between objects with rb_gc_mark().)

as a result, xmlXPathFreeNodeSet() will perform unsafe memory operations, and calling it would be evil.

on the bright side, though, Nokogiri‘s API currently does not cause namespace nodes to be included in node sets, ever.

armed with that fact, we examined xmlXPathFreeNodeSet() and related libxml code and determined that, within the Nokogiri abstraction, we will not leak memory if we simply free the node set‘s memory directly. that‘s only quasi-evil!

there‘s probably a lesson in here somewhere about intermingling, within a single array, structs with different memory-ownership semantics. or more generally, a lesson about building an API in C/C++ that does not contain assumptions about the strict order in which memory will be released. hey, that sounds like a great idea for a blog post! get to it!

"In Valgrind We Trust." seriously.

Methods

/   []   add_class   after   at   attr   before   css   each   empty?   first   inner_html   inner_text   last   length   new   push   remove   remove_attr   remove_class   search   set   text   to_html   to_s   to_xhtml   to_xml   unlink   wrap   xpath  

Included Modules

Enumerable

External Aliases

push -> <<
length -> size
to_a -> to_ary

Attributes

document  [RW] 

Public Class methods

Public Instance methods

/(*paths)

Alias for search

Get the node at index i

Append the class attribute name to all Node objects in the NodeSet.

Insert datum after the last Node in this NodeSet

If path is a string, search this document for path returning the first Node. Otherwise, index in to the array with path.

Set the attribute key to value or the return value of blk on all Node objects in the NodeSet.

Insert datum before the first Node in this NodeSet

css(*paths)

Alias for search

Iterate over each node, yielding to block

Get the first element of the NodeSet.

Get the inner html of all contained Node objects

Get the inner text of all contained Node objects

Get the last element of the NodeSet.

Get the length of the node set

Append node to the NodeSet.

remove()

Alias for unlink

Remove the attributed named name from all Node objects in the NodeSet

Remove the class attribute name from all Node objects in the NodeSet.

Search this document for paths

set(key, value = nil, &blk)

Alias for attr

text()

Alias for inner_text

Unlink this NodeSet and all Node objects it contains from their current context.

Wrap this NodeSet with html or the results of the builder in blk

xpath(*paths)

Alias for search

[Validate]