Esempio n. 1
0
/**
 * json_node_unref:
 * @node: (transfer full): a #JsonNode
 *
 * Decrement the reference count of @node. If it reaches zero, the node is
 * freed.
 *
 * Since: 1.2
 */
void
json_node_unref (JsonNode *node)
{
  g_return_if_fail (JSON_NODE_IS_VALID (node));

  if (g_atomic_int_dec_and_test (&node->ref_count))
    {
      json_node_unset (node);
      if (node->allocated)
        g_slice_free (JsonNode, node);
    }
}
Esempio n. 2
0
/**
 * json_node_init:
 * @node: the #JsonNode to initialize
 * @type: the type of JSON node to initialize @node to
 *
 * Initializes a @node to a specific @type.
 *
 * If the node has already been initialized once, it will be reset to
 * the given type, and any data contained will be cleared.
 *
 * Return value: (transfer none): the initialized #JsonNode
 *
 * Since: 0.16
 */
JsonNode *
json_node_init (JsonNode *node,
                JsonNodeType type)
{
  g_return_val_if_fail (type >= JSON_NODE_OBJECT &&
                        type <= JSON_NODE_NULL, NULL);

  json_node_unset (node);

  node->type = type;

  return node;
}
Esempio n. 3
0
/**
 * json_node_free:
 * @node: a #JsonNode
 *
 * Frees the resources allocated by @node.
 */
void
json_node_free (JsonNode *node)
{
  g_return_if_fail (node == NULL || JSON_NODE_IS_VALID (node));
  g_return_if_fail (node == NULL || node->allocated);

  if (G_LIKELY (node))
    {
      if (node->ref_count > 1)
        g_warning ("Freeing a JsonNode %p owned by other code.", node);

      json_node_unset (node);
      g_slice_free (JsonNode, node);
    }
}