From 3259269c993e928e03c2716ba74e152289ce95f8 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Fri, 19 Jan 2018 11:10:45 -0800 Subject: [PATCH] deps/obs-scripting: Fix script_log in python to append newline --- deps/obs-scripting/obs-scripting-python.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/deps/obs-scripting/obs-scripting-python.c b/deps/obs-scripting/obs-scripting-python.c index 8ee4345a7..b445f1127 100644 --- a/deps/obs-scripting/obs-scripting-python.c +++ b/deps/obs-scripting/obs-scripting-python.c @@ -35,12 +35,12 @@ import os\n\ import obspython\n\ class stdout_logger(object):\n\ def write(self, message):\n\ - obspython.script_log(obspython.LOG_INFO, message)\n\ + obspython.script_log_no_endl(obspython.LOG_INFO, message)\n\ def flush(self):\n\ pass\n\ class stderr_logger(object):\n\ def write(self, message):\n\ - obspython.script_log(obspython.LOG_ERROR, message)\n\ + obspython.script_log_no_endl(obspython.LOG_ERROR, message)\n\ def flush(self):\n\ pass\n\ os.environ['PYTHONUNBUFFERED'] = '1'\n\ @@ -1164,7 +1164,8 @@ static PyObject *sceneitem_list_release(PyObject *self, PyObject *args) struct dstr cur_py_log_chunk = {0}; -static PyObject *py_script_log(PyObject *self, PyObject *args) +static PyObject *py_script_log_internal(PyObject *self, PyObject *args, + bool add_endl) { static bool calling_self = false; int log_level; @@ -1184,6 +1185,8 @@ static PyObject *py_script_log(PyObject *self, PyObject *args) goto fail; dstr_cat(&cur_py_log_chunk, msg); + if (add_endl) + dstr_cat(&cur_py_log_chunk, "\n"); const char *start = cur_py_log_chunk.array; char *endl = strchr(start, '\n'); @@ -1210,6 +1213,16 @@ fail: return python_none(); } +static PyObject *py_script_log_no_endl(PyObject *self, PyObject *args) +{ + return py_script_log_internal(self, args, false); +} + +static PyObject *py_script_log(PyObject *self, PyObject *args) +{ + return py_script_log_internal(self, args, true); +} + /* -------------------------------------------- */ static void add_hook_functions(PyObject *module) @@ -1217,6 +1230,7 @@ static void add_hook_functions(PyObject *module) static PyMethodDef funcs[] = { #define DEF_FUNC(n, c) {n, c, METH_VARARGS, NULL} + DEF_FUNC("script_log_no_endl", py_script_log_no_endl), DEF_FUNC("script_log", py_script_log), DEF_FUNC("timer_remove", timer_remove), DEF_FUNC("timer_add", timer_add),