Skip to content

Commit 966cf18

Browse files
Prerak Singhczgdp1807
Prerak Singh
authored andcommitted
seg fault fix for ubuntu
1 parent 3eb4ea0 commit 966cf18

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

pydatastructs/utils/_backend/cpp/AdjacencyListGraphNode.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ static void AdjacencyListGraphNode_dealloc(AdjacencyListGraphNode* self) {
2121
for (auto& pair : self->adjacent) {
2222
Py_XDECREF(pair.second);
2323
}
24-
self->adjacent.~unordered_map<std::string, PyObject*>();
24+
self->adjacent.clear();
2525
Py_TYPE(self)->tp_free(reinterpret_cast<PyTypeObject*>(self));
2626
}
2727

2828
static PyObject* AdjacencyListGraphNode_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
29-
AdjacencyListGraphNode* self;
30-
self = reinterpret_cast<AdjacencyListGraphNode*>(type->tp_alloc(type, 0));
29+
AdjacencyListGraphNode* self = PyObject_New(AdjacencyListGraphNode, &AdjacencyListGraphNodeType);
3130
if (!self) return NULL;
3231
new (&self->adjacent) std::unordered_map<std::string, PyObject*>();
32+
new (&self->name) std::string();
3333

3434
static char* kwlist[] = { "name", "data", "adjacency_list", NULL };
3535
const char* name;

pydatastructs/utils/_backend/cpp/GraphNode.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ static void GraphNode_dealloc(GraphNode* self){
1919
static PyObject* GraphNode_new(PyTypeObject* type, PyObject* args, PyObject* kwds){
2020
GraphNode* self;
2121
self = reinterpret_cast<GraphNode*>(type->tp_alloc(type,0));
22+
new (&self->name) std::string();
2223
if (!self) return NULL;
2324

2425
static char* kwlist[] = { "name", "data", NULL };

0 commit comments

Comments
 (0)