@@ -13909,14 +13909,14 @@ PyObject *igraphmodule_Graph_community_voronoi(igraphmodule_GraphObject *self,
1390913909 PyObject *lengths_o = Py_None, *weights_o = Py_None;
1391013910 PyObject *mode_o = Py_None;
1391113911 PyObject *radius_o = Py_None;
13912- igraph_vector_t lengths_v, weights_v;
13912+ igraph_vector_t *lengths_v = 0;
13913+ igraph_vector_t *weights_v = 0;
1391313914 igraph_vector_int_t membership_v, generators_v;
1391413915 igraph_neimode_t mode = IGRAPH_ALL;
1391513916 igraph_real_t radius = -1.0; /* negative means auto-optimize */
13916- igraph_real_t modularity;
13917+ igraph_real_t modularity = IGRAPH_NAN ;
1391713918 PyObject *membership_o, *generators_o, *result_o;
1391813919 igraph_bool_t return_modularity = 1;
13919- igraph_bool_t lengths_allocated = 0, weights_allocated = 0;
1392013920
1392113921 if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOOO", kwlist,
1392213922 &lengths_o, &weights_o, &mode_o, &radius_o))
@@ -13943,34 +13943,40 @@ PyObject *igraphmodule_Graph_community_voronoi(igraphmodule_GraphObject *self,
1394313943
1394413944 /* Handle lengths parameter */
1394513945 if (lengths_o != Py_None) {
13946- if (igraphmodule_PyObject_to_vector_t (lengths_o, &lengths_v, 1 )) {
13946+ if (igraphmodule_attrib_to_vector_t (lengths_o, self, &lengths_v, ATTRIBUTE_TYPE_EDGE )) {
1394713947 return NULL;
1394813948 }
13949- lengths_allocated = 1;
1395013949 }
1395113950
1395213951 /* Handle weights parameter */
1395313952 if (weights_o != Py_None) {
13954- if (igraphmodule_PyObject_to_vector_t (weights_o, &weights_v, 1 )) {
13955- if (lengths_allocated ) {
13956- igraph_vector_destroy(& lengths_v);
13953+ if (igraphmodule_attrib_to_vector_t (weights_o, self, &weights_v, ATTRIBUTE_TYPE_EDGE )) {
13954+ if (lengths_v != 0 ) {
13955+ igraph_vector_destroy(lengths_v); free( lengths_v);
1395713956 }
1395813957 return NULL;
1395913958 }
13960- weights_allocated = 1;
1396113959 }
1396213960
1396313961 /* Initialize result vectors */
1396413962 if (igraph_vector_int_init(&membership_v, 0)) {
13965- if (lengths_allocated) igraph_vector_destroy(&lengths_v);
13966- if (weights_allocated) igraph_vector_destroy(&weights_v);
13963+ if (lengths_v != 0) {
13964+ igraph_vector_destroy(lengths_v); free(lengths_v);
13965+ }
13966+ if (weights_v != 0) {
13967+ igraph_vector_destroy(weights_v); free(weights_v);
13968+ }
1396713969 igraphmodule_handle_igraph_error();
1396813970 return NULL;
1396913971 }
1397013972
1397113973 if (igraph_vector_int_init(&generators_v, 0)) {
13972- if (lengths_allocated) igraph_vector_destroy(&lengths_v);
13973- if (weights_allocated) igraph_vector_destroy(&weights_v);
13974+ if (lengths_v != 0) {
13975+ igraph_vector_destroy(lengths_v); free(lengths_v);
13976+ }
13977+ if (weights_v != 0) {
13978+ igraph_vector_destroy(weights_v); free(weights_v);
13979+ }
1397413980 igraph_vector_int_destroy(&membership_v);
1397513981 igraphmodule_handle_igraph_error();
1397613982 return NULL;
@@ -13979,20 +13985,30 @@ PyObject *igraphmodule_Graph_community_voronoi(igraphmodule_GraphObject *self,
1397913985 /* Call the C function - pass NULL for None parameters */
1398013986 if (igraph_community_voronoi(&self->g, &membership_v, &generators_v,
1398113987 return_modularity ? &modularity : NULL,
13982- lengths_allocated ? & lengths_v : NULL ,
13983- weights_allocated ? & weights_v : NULL ,
13988+ lengths_v,
13989+ weights_v,
1398413990 mode, radius)) {
13985- if (lengths_allocated) igraph_vector_destroy(&lengths_v);
13986- if (weights_allocated) igraph_vector_destroy(&weights_v);
13991+
13992+ if (lengths_v != 0) {
13993+ igraph_vector_destroy(lengths_v); free(lengths_v);
13994+ }
13995+ if (weights_v != 0) {
13996+ igraph_vector_destroy(weights_v); free(weights_v);
13997+ }
1398713998 igraph_vector_int_destroy(&membership_v);
1398813999 igraph_vector_int_destroy(&generators_v);
1398914000 igraphmodule_handle_igraph_error();
1399014001 return NULL;
1399114002 }
1399214003
1399314004 /* Clean up input vectors */
13994- if (lengths_allocated) igraph_vector_destroy(&lengths_v);
13995- if (weights_allocated) igraph_vector_destroy(&weights_v);
14005+
14006+ if (lengths_v != 0) {
14007+ igraph_vector_destroy(lengths_v); free(lengths_v);
14008+ }
14009+ if (weights_v != 0) {
14010+ igraph_vector_destroy(weights_v); free(weights_v);
14011+ }
1399614012
1399714013 /* Convert results to Python objects */
1399814014 membership_o = igraphmodule_vector_int_t_to_PyList(&membership_v);
0 commit comments