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 7
7
8
8
def cleanup (obj ):
9
9
obj .close ()
10
+ gc .collect ()
10
11
11
12
class Device :
12
13
"""Creates a single instance of the buildhat for all devices to use"""
@@ -50,7 +51,6 @@ def whatami(self, port):
50
51
51
52
def close (self ):
52
53
del Device ._instance
53
- gc .collect ()
54
54
55
55
class PortDevice (Device ):
56
56
"""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)
1014
1014
{
1015
1015
PyObject * value ;
1016
1016
value = PyList_GetItem (device -> values , i );
1017
+ Py_INCREF (value );
1017
1018
if (value == NULL )
1018
1019
{
1019
1020
Py_DECREF (results );
1020
1021
return -1 ;
1021
1022
}
1022
1023
PyList_SET_ITEM (results , i , value );
1024
+ Py_DECREF (value );
1023
1025
}
1024
1026
1025
1027
PyObject * args = Py_BuildValue ("(O)" , results );
1026
-
1027
1028
rv = (PyObject_CallObject (device -> callback , args ) != NULL ) ? 0 : -1 ;
1028
1029
Py_XDECREF (args );
1029
1030
}
Original file line number Diff line number Diff line change @@ -117,6 +117,14 @@ static int build_hat_created = 0;
117
117
118
118
static void
119
119
Hub_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 )
120
128
{
121
129
PyObject * etype , * evalue , * etraceback ;
122
130
@@ -126,13 +134,11 @@ Hub_dealloc(HubObject *self)
126
134
PyErr_Restore (etype , evalue , etraceback );
127
135
128
136
PyObject_GC_UnTrack (self );
129
- Hub_clear (self );
137
+ Hub_clear (( HubObject * ) self );
130
138
Py_TYPE (self )-> tp_free ((PyObject * )self );
131
-
132
139
build_hat_created = 0 ;
133
140
}
134
141
135
-
136
142
static PyObject *
137
143
Hub_new (PyTypeObject * type , PyObject * args , PyObject * kwds )
138
144
{
@@ -334,6 +340,7 @@ static PyTypeObject HubType =
334
340
.tp_clear = (inquiry )Hub_clear ,
335
341
.tp_getset = Hub_getsetters ,
336
342
.tp_methods = Hub_methods ,
343
+ .tp_finalize = (destructor )Hub_finalize
337
344
};
338
345
339
346
Original file line number Diff line number Diff line change @@ -424,6 +424,13 @@ void parse_line(char *serbuf)
424
424
token = strtok (NULL , " " );
425
425
mcount ++ ;
426
426
}
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
+
427
434
callback_queue (CALLBACK_DEVICE , port , CALLBACK_DATA );
428
435
}
429
436
}
You can’t perform that action at this time.
0 commit comments