shithub: aubio

Download patch

ref: 6a72ff0b369d4791002e34d274b624f809a9b883
parent: 773a7f38d5d688fb801f03b8e79be5c94bbd5ff8
author: Paul Brossier <piem@piem.org>
date: Sat Aug 20 15:41:23 EDT 2016

python/lib/gen_code.py: improve del_ function, safer DECREF, fix indentation, emit RuntimeError

--- a/python/lib/gen_code.py
+++ b/python/lib/gen_code.py
@@ -306,7 +306,7 @@
         out += """
   // return -1 and set error string on failure
   if (self->o == NULL) {{
-    PyErr_Format (PyExc_Exception, "failed creating {shortname}");
+    PyErr_Format (PyExc_RuntimeError, "failed creating {shortname}");
     return -1;
   }}
 """.format(paramchars = paramchars, paramvals = paramvals, **self.__dict__)
@@ -348,18 +348,20 @@
         for input_param in self.do_inputs:
             if input_param['type'] == 'fmat_t *':
                 out += """
-    free(self->{0[name]}.data);""".format(input_param)
+  free(self->{0[name]}.data);""".format(input_param)
         for o in self.outputs:
             name = o['name']
             del_out = delfromtype_fn[o['type']]
             out += """
-    {del_out}(self->{name});""".format(del_out = del_out, name = name)
+  if (self->{name}) {{
+    {del_out}(self->{name});
+  }}""".format(del_out = del_out, name = name)
         del_fn = get_name(self.del_proto)
         out += """
-    if (self->o) {{
-        {del_fn}(self->o);
-    }}
-    Py_TYPE(self)->tp_free((PyObject *) self);
+  if (self->o) {{
+    {del_fn}(self->o);
+  }}
+  Py_TYPE(self)->tp_free((PyObject *) self);
 }}
 """.format(del_fn = del_fn)
         return out