File tree Expand file tree Collapse file tree 4 files changed +20
-5
lines changed Expand file tree Collapse file tree 4 files changed +20
-5
lines changed Original file line number Diff line number Diff line change 77
88def cleanup (obj ):
99 obj .close ()
10+ gc .collect ()
1011
1112class Device :
1213 """Creates a single instance of the buildhat for all devices to use"""
@@ -50,7 +51,6 @@ def whatami(self, port):
5051
5152 def close (self ):
5253 del Device ._instance
53- gc .collect ()
5454
5555class PortDevice (Device ):
5656 """Device which uses port"""
Original file line number Diff line number Diff line change @@ -1014,16 +1014,17 @@ int device_callback(PyObject *self, int event)
10141014 {
10151015 PyObject * value ;
10161016 value = PyList_GetItem (device -> values , i );
1017+ Py_INCREF (value );
10171018 if (value == NULL )
10181019 {
10191020 Py_DECREF (results );
10201021 return -1 ;
10211022 }
10221023 PyList_SET_ITEM (results , i , value );
1024+ Py_DECREF (value );
10231025 }
10241026
10251027 PyObject * args = Py_BuildValue ("(O)" , results );
1026-
10271028 rv = (PyObject_CallObject (device -> callback , args ) != NULL ) ? 0 : -1 ;
10281029 Py_XDECREF (args );
10291030 }
Original file line number Diff line number Diff line change @@ -117,6 +117,14 @@ static int build_hat_created = 0;
117117
118118static void
119119Hub_dealloc (HubObject * self )
120+ {
121+ //PyObject_GC_UnTrack(self); // calling this means finalize isn't called
122+ //Hub_clear(self);
123+ //Py_TYPE(self)->tp_free((PyObject *)self); // calling this means finalize isn't called
124+ }
125+
126+ static void
127+ Hub_finalize (PyObject * self )
120128{
121129 PyObject * etype , * evalue , * etraceback ;
122130
@@ -126,13 +134,11 @@ Hub_dealloc(HubObject *self)
126134 PyErr_Restore (etype , evalue , etraceback );
127135
128136 PyObject_GC_UnTrack (self );
129- Hub_clear (self );
137+ Hub_clear (( HubObject * ) self );
130138 Py_TYPE (self )-> tp_free ((PyObject * )self );
131-
132139 build_hat_created = 0 ;
133140}
134141
135-
136142static PyObject *
137143Hub_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
138144{
@@ -334,6 +340,7 @@ static PyTypeObject HubType =
334340 .tp_clear = (inquiry )Hub_clear ,
335341 .tp_getset = Hub_getsetters ,
336342 .tp_methods = Hub_methods ,
343+ .tp_finalize = (destructor )Hub_finalize
337344};
338345
339346
Original file line number Diff line number Diff line change @@ -424,6 +424,13 @@ void parse_line(char *serbuf)
424424 token = strtok (NULL , " " );
425425 mcount ++ ;
426426 }
427+
428+ // Add extra value, to prevent current segfault - Needs more investigation!
429+ data_t * tmpval = malloc (sizeof (data_t ));
430+ tmpval -> i_data = strtof ("1.0" , NULL );
431+ tmpval -> t = FLOAT ;
432+ port_new_any_value (port , mcount , tmpval );
433+
427434 callback_queue (CALLBACK_DEVICE , port , CALLBACK_DATA );
428435 }
429436 }
You can’t perform that action at this time.
0 commit comments