Skip to content

Commit

Permalink
Stop repeatedly setting C attribute handler
Browse files Browse the repository at this point in the history
It only needs to be set once on program startup and then left alone.
  • Loading branch information
robgjansen committed Dec 30, 2023
1 parent a47fba7 commit b3553ba
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
6 changes: 0 additions & 6 deletions src/tgen-graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -1268,9 +1268,6 @@ TGenGraph* tgengraph_new(gchar* path) {
* from multiple threads at the same time. this is not a problem when shadow
* uses dlmopen to get a private namespace for each plugin. */

/* use the built-in C attribute handler */
igraph_attribute_table_t* oldHandler = igraph_set_attribute_table(&igraph_cattribute_table);

g->graph = _tgengraph_loadNewGraph(g->graphPath);
if(!g->graph) {
error = g_error_new(G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
Expand All @@ -1287,9 +1284,6 @@ TGenGraph* tgengraph_new(gchar* path) {
if(!error) {
error = _tgengraph_parseGraphVertices(g);
}

/* replace the old handler */
igraph_set_attribute_table(oldHandler);
}

if(error) {
Expand Down
4 changes: 4 additions & 0 deletions src/tgen-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <igraph.h>

#include "tgen.h"
#include "tgen-igraph-compat.h"

static void _tgenmain_cleanup(gint status, gpointer arg) {
if(arg) {
Expand Down Expand Up @@ -82,6 +83,9 @@ static gint _tgenmain_run(gint argc, gchar *argv[]) {
tgen_message("Set SIG_IGN for signal SIGPIPE");
}

/* use the built-in C attribute handler. this is set once and then left alone. */
igraph_set_attribute_table(&igraph_cattribute_table);

/* parse the config file */
TGenGraph* graph = tgengraph_new(argv[1]);
if (!graph) {
Expand Down
4 changes: 0 additions & 4 deletions src/tgen-markovmodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,10 +880,6 @@ static igraph_t* _tgenmarkovmodel_loadGraph(FILE* graphFileStream, const gchar*
rewind(graphFileStream);

igraph_t* graph = g_new0(igraph_t, 1);

/* make sure we use the correct attribute handler */
igraph_set_attribute_table(&igraph_cattribute_table);

result = igraph_read_graph_graphml(graph, graphFileStream, 0);

if (result != IGRAPH_SUCCESS) {
Expand Down
5 changes: 5 additions & 0 deletions test/test-markovmodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include <stdint.h>

#include <glib.h>
#include <igraph.h>

#include "tgen-igraph-compat.h"
#include "tgen-log.h"
#include "tgen-markovmodel.h"

Expand Down Expand Up @@ -87,6 +89,9 @@ gint main(gint argc, gchar *argv[]) {
return EXIT_FAILURE;
}

/* use the built-in C attribute handler. this is set once and then left alone. */
igraph_set_attribute_table(&igraph_cattribute_table);

guint32 seed = (guint32)atoi(argv[1]);
gchar* path = g_strdup(argv[2]);
gchar* name = g_path_get_basename(path);
Expand Down

0 comments on commit b3553ba

Please sign in to comment.