[PythonFilter] Fix svace errors in python filter
authorDongju Chae <dongju.chae@samsung.com>
Thu, 8 Aug 2019 08:06:23 +0000 (17:06 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Fri, 9 Aug 2019 04:29:32 +0000 (13:29 +0900)
This commit fixes svace errors.

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
ext/nnstreamer/tensor_filter/tensor_filter_python_core.cc
ext/nnstreamer/tensor_filter/tensor_filter_python_core.h

index eb8c2c3..6631491 100644 (file)
@@ -80,7 +80,10 @@ PYCore::PYCore (const char* _script_path, const char* _custom)
 
   /** Add current/directory path to sys.path */
   PyObject *sys_module = PyImport_ImportModule("sys");
+  g_assert(sys_module);
+
   PyObject *sys_path = PyObject_GetAttrString(sys_module, "path");
+  g_assert(sys_path);
 
   PyList_Append(sys_path, PyUnicode_FromString("."));
   PyList_Append(sys_path, PyUnicode_FromString(script_path.substr(0, last_idx).c_str()));
@@ -293,7 +296,7 @@ PYCore::getInputTensorDim (GstTensorsInfo * info)
 
   PyObject *result = PyObject_CallMethod(core_obj, (char*) "getInputDim", NULL);
   if (result) {
-    parseOutputTensors(result, info);
+    res = parseOutputTensors(result, info);
     Py_XDECREF(result);
   } else { 
     Py_ERRMSG("Fail to call 'getInputDim'");
@@ -322,7 +325,7 @@ PYCore::getOutputTensorDim (GstTensorsInfo * info)
 
   PyObject *result = PyObject_CallMethod(core_obj, (char*) "getOutputDim", NULL);
   if (result) {
-    parseOutputTensors(result, info);
+    res = parseOutputTensors(result, info);
     Py_XDECREF(result);
   } else { 
     Py_ERRMSG("Fail to call 'getOutputDim'");
@@ -374,8 +377,9 @@ PYCore::setInputTensorDim (const GstTensorsInfo * in_info, GstTensorsInfo * out_
   Py_XDECREF (param);
 
   if (result) {
-    parseOutputTensors(result, out_info);
-    outputTensorMeta.num_tensors = out_info->num_tensors;
+    res = parseOutputTensors(result, out_info);
+    if (res == 0)
+      outputTensorMeta.num_tensors = out_info->num_tensors;
     Py_XDECREF(result);
   } else { 
     Py_ERRMSG("Fail to call 'setInputDim'");
@@ -419,12 +423,16 @@ PYCore::PyTensorShape_New (const GstTensorInfo* info)
  * @brief parse the invoke result to feed output tensors
  * @param[result] Python object retunred by invoke
  * @param[info] info Structure for output tensor info
- * @return None
+ * @return 0 if no error, otherwise negative errno
  */
-void
+int
 PYCore::parseOutputTensors(PyObject* result, GstTensorsInfo * info)
 {
+  if (PyList_Size(result) < 0)
+    return -1;
+
   info->num_tensors = PyList_Size(result);
+
   for (int i = 0; i < info->num_tensors; i++) {
     /** don't own the reference */
     PyObject *tensor_shape = PyList_GetItem(result, (Py_ssize_t) i); 
@@ -445,6 +453,8 @@ PYCore::parseOutputTensors(PyObject* result, GstTensorsInfo * info)
     Py_XDECREF (shape_dims);
     Py_XDECREF (shape_type);
   }
+
+  return 0;
 }
 
 /**
index c4ef5de..37059fd 100644 (file)
@@ -72,7 +72,7 @@ public:
   int setInputTensorDim (const GstTensorsInfo * in_info, GstTensorsInfo * out_info);
   int run (const GstTensorMemory * input, GstTensorMemory * output);
 
-  void parseOutputTensors(PyObject* result, GstTensorsInfo * info);
+  int parseOutputTensors(PyObject* result, GstTensorsInfo * info);
 
   /** @brief Return callback type */
   cb_type getCbType () { return callback_type; }