shithub: aubio

Download patch

ref: 67537d79eda6ce4e5765b7ebf548be4a3946760d
parent: aa5828d22daf11ee3efa8de971d50036d38a7cd6
author: Paul Brossier <piem@piem.org>
date: Thu Sep 22 18:55:47 EDT 2016

python/ext/aubiomodule.c: use custom logging function for errors and warnings

--- a/python/ext/aubiomodule.c
+++ b/python/ext/aubiomodule.c
@@ -256,6 +256,22 @@
 };
 #endif
 
+void
+aubio_log_function(int level, const char *message, void *data)
+{
+  // remove trailing \n
+  char *pos;
+  if ((pos=strchr(message, '\n')) != NULL) {
+        *pos = '\0';
+  }
+  // warning or error
+  if (level == AUBIO_LOG_ERR) {
+    PyErr_Format(PyExc_RuntimeError, "%s", message);
+  } else {
+    PyErr_WarnEx(PyExc_UserWarning, message, 1);
+  }
+}
+
 static PyObject *
 initaubio (void)
 {
@@ -315,6 +331,8 @@
   // add ufunc
   add_ufuncs(m);
 
+  aubio_log_set_level_function(AUBIO_LOG_ERR, aubio_log_function, NULL);
+  aubio_log_set_level_function(AUBIO_LOG_WRN, aubio_log_function, NULL);
   return m;
 }