From eee58b123eabdc2a5fb81710cbfd00a8d48155d3 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Sun, 21 May 2023 23:50:57 -0700 Subject: [PATCH] Fix segfault. Thanks to @jackykwok2024 for catching this. --- python/lib/pythontarget.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/python/lib/pythontarget.c b/python/lib/pythontarget.c index 239ad40a7..ebab1094b 100644 --- a/python/lib/pythontarget.c +++ b/python/lib/pythontarget.c @@ -412,11 +412,6 @@ void destroy_action_capsule(PyObject* capsule) { * Individual ports can then later be accessed in Python code as port[idx]. */ PyObject* convert_C_port_to_py(void* port, int width) { - generic_port_instance_struct* cport; - if (width == -2) { - // Not a multiport - cport = (generic_port_instance_struct *)port; - } // Create the port struct in Python PyObject* cap = (PyObject*)PyObject_GC_New(generic_port_capsule_struct, &py_port_capsule_t); @@ -433,13 +428,14 @@ PyObject* convert_C_port_to_py(void* port, int width) { // Fill in the Python port struct ((generic_port_capsule_struct*)cap)->port = capsule; ((generic_port_capsule_struct*)cap)->width = width; - FEDERATED_ASSIGN_FIELDS(((generic_port_capsule_struct*)cap), cport); if (width == -2) { + generic_port_instance_struct* cport = (generic_port_instance_struct *) port; + FEDERATED_ASSIGN_FIELDS(((generic_port_capsule_struct*)cap), cport); + ((generic_port_capsule_struct*)cap)->is_present = cport->is_present; - if (cport->value == NULL) { // Value is absent Py_INCREF(Py_None);