Exemplo n.º 1
0
Arquivo: rdf_uri.c Projeto: njh/librdf
/**
 * librdf_free_uri:
 * @uri: #librdf_uri object
 *
 * Destructor - destroy a #librdf_uri object.
 * 
 **/
void
librdf_free_uri(librdf_uri* uri) 
{
#ifdef LIBRDF_USE_RAPTOR_URI
  if(!uri)
    return;
  
  raptor_free_uri(uri);
#else
  librdf_hash_datum key; /* on stack */
#ifdef WITH_THREADS
  librdf_world *world;
#endif

  if(!uri)
    return;
  
#ifdef WITH_THREADS
  world = uri->world;
  pthread_mutex_lock(world->mutex);
#endif

  uri->usage--;
  
#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1
  LIBRDF_DEBUG3("URI %s usage count now %d\n", uri->string, uri->usage);
#endif

  /* decrement usage, don't free if not 0 yet*/
  if(uri->usage) {
#ifdef WITH_THREADS
    pthread_mutex_unlock(world->mutex);
#endif
    return;
  }

#if defined(LIBRDF_DEBUG) && LIBRDF_DEBUG > 1
  LIBRDF_DEBUG3("Deleting URI %s from hash, max usage was %d\n", uri->string, uri->max_usage);
#endif

  key.data=uri->string;
  key.size=uri->string_length;
  /* Hash deletion fails only if the key is not found.
     This is not a fatal error so do not check for return value. */
  librdf_hash_delete_all(uri->world->uris_hash, &key);

  if(uri->string)
    LIBRDF_FREE(cstring, uri->string);
  LIBRDF_FREE(librdf_uri, uri);

#ifdef WITH_THREADS
  pthread_mutex_unlock(world->mutex);
#endif
#endif /* !LIBRDF_USE_RAPTOR_URI */
}
Exemplo n.º 2
0
static int delete_key_value (librdf_world *world, librdf_hash *h, const char* key, const char* value, librdf_hash_datum *hd_key, librdf_hash_datum *hd_value) {
  int ret = -1;
  /* Delete key value */
  hd_key->data=(char*)key;
  hd_key->size=strlen((char*)hd_key->data);

  if (value != NULL && hd_value != NULL) {
    hd_value->data=(char*)value;
    hd_value->size=strlen((char*)hd_value->data);
    ret = librdf_hash_delete(h, hd_key, hd_value);
  }
  else {
    /* delete all keys */
    ret = librdf_hash_delete_all(h, hd_key);
  }

  return ret;
}