examples/libxml.c
hubbub_error unref_node(void *ctx, void *node)
{
	context *c = (context *) ctx;

	if (node == c->document) {
		xmlDoc *n = (xmlDoc *) node;
		uintptr_t count = (uintptr_t) n->_private;

		/* Trap any attempt to unref a non-referenced node */
		assert(count != 0 && "Node has refcount of zero");

		/* Never destroy document node */

		n->_private = (void *) --count;
	} else {
		xmlNode *n = (xmlNode *) node;
		uintptr_t count = (uintptr_t) n->_private;

		/* Trap any attempt to unref a non-referenced node */
		assert(count != 0 && "Node has refcount of zero");

		n->_private = (void *) --count;

		/* Destroy node, if it has no parent */
		if (count == 0 && n->parent == NULL) {
			xmlFreeNode(n);
		}
	}

	return HUBBUB_OK;
}
/**
 * Decrease a node's reference count
 *
 * \param ctx   Our context
 * \param node  The node to unreference
 * \return HUBBUB_OK on success, appropriate error otherwise
 *
 * Postcondition: If the node's reference count becomes zero, and it has no 
 * parent, and it is not the document node, then it is destroyed.
 */
Decrease a node's reference count
\param ctx   Our context
\param node  The node to unreference
\return HUBBUB_OK on success, appropriate error otherwise

If the node's reference count becomes zero, and it has no
parent, and it is not the document node, then it is destroyed.
Decrease a node ' s reference count \ param ctx Our context \ param node The node to unreference \ return HUBBUB_OK on success appropriate error otherwise If the node ' s reference count becomes zero and it has no parent and it is not the document node then it is destroyed .
hubbub_error unref_node(void *ctx, void *node)
{
	context *c = (context *) ctx;
	if (node == c->document) {
		xmlDoc *n = (xmlDoc *) node;
		uintptr_t count = (uintptr_t) n->_private;
		assert(count != 0 && "Node has refcount of zero");
		n->_private = (void *) --count;
	} else {
		xmlNode *n = (xmlNode *) node;
		uintptr_t count = (uintptr_t) n->_private;
		assert(count != 0 && "Node has refcount of zero");
		n->_private = (void *) --count;
		if (count == 0 && n->parent == NULL) {
			xmlFreeNode(n);
		}
	}
	return HUBBUB_OK;
}
hubbub_error unref_node ( void * ctx , void * node ) { context * c = ( context * ) ctx ; if ( node == c -> document ) { xmlDoc * n = ( xmlDoc * ) node ; uintptr_t count = ( uintptr_t ) n -> _private ; assert ( count != 0 && " " ) ; n -> _private = ( void * ) -- count ; } else { xmlNode * n = ( xmlNode * ) node ; uintptr_t count = ( uintptr_t ) n -> _private ; assert ( count != 0 && " " ) ; n -> _private = ( void * ) -- count ; if ( count == 0 && n -> parent == NULL ) { xmlFreeNode ( n ) ; } } return HUBBUB_OK ; }
Decrease a node's reference count
 \param ctx   Our context
 \param node  The node to unreference
 \return HUBBUB_OK on success, appropriate error otherwise
Decrease a node ' s reference count \ param ctx Our context \ param node The node to unreference \ return HUBBUB_OK on success appropriate error otherwise
/* Trap any attempt to unref a non-referenced node */ /* Never destroy document node */ /* Trap any attempt to unref a non-referenced node */ /* Destroy node, if it has no parent */