/** * librdf_free_world: * @world: redland world object * * Terminate the library and frees all allocated resources. **/ void librdf_free_world(librdf_world *world) { if(!world) return; librdf_finish_serializer(world); librdf_finish_parser(world); librdf_finish_storage(world); librdf_finish_query(world); librdf_finish_model(world); librdf_finish_statement(world); librdf_finish_concepts(world); librdf_finish_node(world); librdf_finish_uri(world); librdf_finish_hash(world); librdf_finish_digest(world); librdf_finish_raptor(world); #ifdef WITH_THREADS if(world->hash_datums_mutex) { pthread_mutex_destroy(world->hash_datums_mutex); SYSTEM_FREE(world->hash_datums_mutex); world->hash_datums_mutex = NULL; } if(world->statements_mutex) { pthread_mutex_destroy(world->statements_mutex); SYSTEM_FREE(world->statements_mutex); world->statements_mutex = NULL; } if(world->nodes_mutex) { pthread_mutex_destroy(world->nodes_mutex); SYSTEM_FREE(world->nodes_mutex); world->nodes_mutex = NULL; } if(world->mutex) { pthread_mutex_destroy(world->mutex); SYSTEM_FREE(world->mutex); world->mutex = NULL; } #endif #ifdef MODULAR_LIBRDF if (world->ltdl_opened) lt_dlexit(); #endif LIBRDF_FREE(librdf_world, world); }
/** * librdf_hash_bdb_cursor_get - Retrieve a hash value for the given key * @context: BerkeleyDB hash cursor context * @key: pointer to key to use * @value: pointer to value to use * @flags: flags * * Return value: non 0 on failure **/ static int librdf_hash_bdb_cursor_get(void* context, librdf_hash_datum *key, librdf_hash_datum *value, unsigned int flags) { librdf_hash_bdb_cursor_context *cursor=(librdf_hash_bdb_cursor_context*)context; #ifdef HAVE_BDB_CURSOR DBC *bdb_cursor=cursor->cursor; #else /* For BDB V1 */ DB* db; #endif DBT bdb_key; DBT bdb_value; int ret; /* docs say you must zero DBT's before use */ memset(&bdb_key, 0, sizeof(DBT)); memset(&bdb_value, 0, sizeof(DBT)); /* Always initialise BDB version of key */ bdb_key.data = (char*)key->data; bdb_key.size = key->size; #ifdef DB_DBT_MALLOC /* BDB V2 or later? */ bdb_key.flags=DB_DBT_MALLOC; /* Return in malloc() allocated memory */ bdb_value.flags=DB_DBT_MALLOC; #endif #ifndef HAVE_BDB_CURSOR /* For BDB V1 */ db=cursor->hash->db; #endif switch(flags) { case LIBRDF_HASH_CURSOR_SET: #ifdef HAVE_BDB_CURSOR /* V2/V3 prototype: * int DBcursor->c_get(DBC *cursor, DBT *key, DBT *data, u_int32_t flags); */ ret=bdb_cursor->c_get(bdb_cursor, &bdb_key, &bdb_value, DB_SET); #else /* V1 */ ret=db->seq(db, &bdb_key, &bdb_value, 0); #endif break; case LIBRDF_HASH_CURSOR_FIRST: #ifdef HAVE_BDB_CURSOR /* V2/V3 prototype: * int DBcursor->c_get(DBC *cursor, DBT *key, DBT *data, u_int32_t flags); */ ret=bdb_cursor->c_get(bdb_cursor, &bdb_key, &bdb_value, DB_FIRST); #else /* V1 */ ret=db->seq(db, &bdb_key, &bdb_value, R_FIRST); #endif break; case LIBRDF_HASH_CURSOR_NEXT_VALUE: #ifdef HAVE_BDB_CURSOR /* V2/V3 */ ret=bdb_cursor->c_get(bdb_cursor, &bdb_key, &bdb_value, DB_NEXT); #else /* V1 */ ret=db->seq(db, &bdb_key, &bdb_value, R_NEXT); #endif /* If succeeded and key has changed, end */ if(!ret && cursor->last_key && memcmp(cursor->last_key, bdb_key.data, bdb_key.size)) { /* always allocated by BDB using system malloc */ SYSTEM_FREE(bdb_key.data); SYSTEM_FREE(bdb_value.data); #ifdef DB_NOTFOUND /* V2 and V3 */ ret=DB_NOTFOUND; #else ret=1; #endif } break; case LIBRDF_HASH_CURSOR_NEXT: #ifdef HAVE_BDB_CURSOR #ifdef DB_NEXT_NODUP /* V3 */ /* Get next key, or next key/value (when value defined) */ ret=bdb_cursor->c_get(bdb_cursor, &bdb_key, &bdb_value, (value) ? DB_NEXT : DB_NEXT_NODUP); #else /* V2 */ /* Must mess about finding next key - note this relies on * the bdb btree having the keys in sorted order */ while(1) { ret=bdb_cursor->c_get(bdb_cursor, &bdb_key, &bdb_value, DB_NEXT); /* finish on error, want all values or no previous key */ if(ret || value || !cursor->last_key) break; /* else have previous key and want unique keys, so keep * going until the key changes */ if(memcmp(cursor->last_key, bdb_key.data, bdb_key.size)) break; /* always allocated by BDB using system malloc */ SYSTEM_FREE(bdb_key.data); SYSTEM_FREE(bdb_value.data); } #endif #else /* V1 */ ret=db->seq(db, &bdb_key, &bdb_value, R_NEXT); #endif break; default: LIBRDF_ERROR2(cursor->hash->hash->world, "Unknown hash method flag %d\n", flags); return 1; } /* Free previous key and values */ if(cursor->last_key) { LIBRDF_FREE(cstring, cursor->last_key); cursor->last_key=NULL; } if(cursor->last_value) { LIBRDF_FREE(cstring, cursor->last_value); cursor->last_value=NULL; } if(ret) { #ifdef DB_NOTFOUND /* V2 and V3 */ if(ret != DB_NOTFOUND) LIBRDF_DEBUG2("BDB cursor error - %d\n", ret); #endif key->data=NULL; return ret; } cursor->last_key = key->data = LIBRDF_MALLOC(cstring, bdb_key.size); if(!key->data) { /* always allocated by BDB using system malloc */ if(flags != LIBRDF_HASH_CURSOR_SET) SYSTEM_FREE(bdb_key.data); SYSTEM_FREE(bdb_value.data); return 1; } memcpy(key->data, bdb_key.data, bdb_key.size); key->size = bdb_key.size; if(value) { cursor->last_value = value->data = LIBRDF_MALLOC(cstring, bdb_value.size); if(!value->data) { /* always allocated by BDB using system malloc */ if(flags != LIBRDF_HASH_CURSOR_SET) SYSTEM_FREE(bdb_key.data); SYSTEM_FREE(bdb_value.data); return 1; } memcpy(value->data, bdb_value.data, bdb_value.size); value->size = bdb_value.size; } /* always allocated by BDB using system malloc */ if(flags != LIBRDF_HASH_CURSOR_SET) SYSTEM_FREE(bdb_key.data); SYSTEM_FREE(bdb_value.data); return 0; }