summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--slv2/world.h2
-rw-r--r--src/world.c27
2 files changed, 27 insertions, 2 deletions
diff --git a/slv2/world.h b/slv2/world.h
index 8dfa1d3..527acbe 100644
--- a/slv2/world.h
+++ b/slv2/world.h
@@ -48,6 +48,8 @@ extern "C" {
/** Initialize a new, empty world.
+ *
+ * If initialization fails, NULL is returned.
*/
SLV2World
slv2_world_new();
diff --git a/src/world.c b/src/world.c
index dc2be1a..1458124 100644
--- a/src/world.c
+++ b/src/world.c
@@ -35,14 +35,23 @@ slv2_world_new()
SLV2World world = (SLV2World)malloc(sizeof(struct _SLV2World));
world->world = librdf_new_world();
+ if (!world->world)
+ goto fail;
+
librdf_world_open(world->world);
world->storage = librdf_new_storage(world->world, "hashes", NULL,
"hash-type='memory'");
+ if (!world->storage)
+ goto fail;
world->model = librdf_new_model(world->world, world->storage, NULL);
+ if (!world->model)
+ goto fail;
world->parser = librdf_new_parser(world->world, "turtle", NULL, NULL);
+ if (!world->parser)
+ goto fail;
world->plugin_classes = slv2_plugin_classes_new();
@@ -58,8 +67,12 @@ slv2_world_new()
world->rdf_a_node = librdf_new_node_from_uri_string(world->world,
(unsigned char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
-
+
return world;
+
+fail:
+ free(world);
+ return NULL;
}
@@ -69,13 +82,19 @@ slv2_world_new_using_rdf_world(librdf_world* rdf_world)
SLV2World world = (SLV2World)malloc(sizeof(struct _SLV2World));
world->world = rdf_world;
-
+
world->storage = librdf_new_storage(world->world, "hashes", NULL,
"hash-type='memory'");
+ if (!world->storage)
+ goto fail;
world->model = librdf_new_model(world->world, world->storage, NULL);
+ if (!world->model)
+ goto fail;
world->parser = librdf_new_parser(world->world, "turtle", NULL, NULL);
+ if (!world->parser)
+ goto fail;
world->plugin_classes = slv2_plugin_classes_new();
@@ -93,6 +112,10 @@ slv2_world_new_using_rdf_world(librdf_world* rdf_world)
(unsigned char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
return world;
+
+fail:
+ free(world);
+ return NULL;
}