Browse Source

Stabilize merged code

Suren A. Chilingaryan 8 years ago
parent
commit
dbef1e0271
5 changed files with 25 additions and 18 deletions
  1. 1 0
      .bzrignore
  2. 18 12
      pcilib/py.c
  3. 1 1
      pywrap/test_pcipywrap.py
  4. 2 2
      views/transform.c
  5. 3 3
      xml/test/test_prop3.py

+ 1 - 0
.bzrignore

@@ -36,3 +36,4 @@ build.h
 build
 pcipywrap.py
 pcipywrapPYTHON_wrap.c
+apps/test_multithread

+ 18 - 12
pcilib/py.c

@@ -1,4 +1,9 @@
-#define _GNU_SOURCE
+#include "config.h"
+
+#ifdef HAVE_PYTHON
+# include <Python.h>
+#endif /* HAVE_PYTHON */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -10,11 +15,6 @@
 #include "pcilib.h"
 #include "py.h"
 #include "error.h"
-#include "config.h"
-
-#ifdef HAVE_PYTHON
-# include <Python.h>
-#endif /* HAVE_PYTHON */
 
 #ifdef HAVE_PYTHON
 typedef struct pcilib_script_s pcilib_script_t;
@@ -40,13 +40,19 @@ void pcilib_log_python_error(const char *file, int line, pcilib_log_flags_t flag
     const char *val = NULL;
 
 #ifdef HAVE_PYTHON
+    PyGILState_STATE gstate;
     PyObject *pytype = NULL;
     PyObject *pyval = NULL;
     PyObject *pytraceback = NULL;
 
-    PyErr_Fetch(&pytype, &pyval, &pytraceback);
-    type = PyString_AsString(pytype);
-    val = PyString_AsString(pyval);
+
+    gstate = PyGILState_Ensure();
+    if (PyErr_Occurred()) {
+	PyErr_Fetch(&pytype, &pyval, &pytraceback);
+	type = PyString_AsString(pytype);
+	val = PyString_AsString(pyval);
+    }
+    PyGILState_Release(gstate);
 #endif /* HAVE_PYTHON */
     
     va_start(va, msg);
@@ -77,9 +83,9 @@ void pcilib_log_python_error(const char *file, int line, pcilib_log_flags_t flag
     va_end(va);
 
 #ifdef HAVE_PYTHON
-    Py_XDECREF(pytype);
-    Py_XDECREF(pyval);
-    Py_XDECREF(pytraceback);
+    if (pytype) Py_XDECREF(pytype);
+    if (pyval) Py_XDECREF(pyval);
+    if (pytraceback) Py_XDECREF(pytraceback);
 #endif /* HAVE_PYTHON */
 }
 

+ 1 - 1
pywrap/test_pcipywrap.py

@@ -112,7 +112,7 @@ class test_pcipywrap():
          pass
 
 if __name__ == '__main__':
-   lib = test_pcipywrap('/dev/fpga0','test_pywrap', num_threads = 150,
+   lib = test_pcipywrap('/dev/fpga0','test', num_threads = 150,
    write_percentage = 0.1, register = 'test_prop2',server_host = 'http://localhost', server_port = 12412,
    server_message_delay = 0)
    lib.testThreadSafeReadWrite()

+ 2 - 2
views/transform.c

@@ -10,13 +10,13 @@
 #include "transform.h"
 #include "py.h"
 #include "error.h"
+#include "pci.h"
 
 static pcilib_view_context_t * pcilib_transform_view_init(pcilib_t *ctx, pcilib_view_t view) {
     int err;
 
     pcilib_view_context_t *view_ctx;
-    const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
-    pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(model_info->views[view]);
+    pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(ctx->views[view]);
 
     if(v->script) {	
 	pcilib_access_mode_t mode = 0;

+ 3 - 3
xml/test/test_prop3.py

@@ -1,5 +1,5 @@
 def read_from_register(ctx, value):
-   return ctx.get_property('/registers/fpga/reg1')
-    
+   return ctx.get_property('/registers/fpga/sensor_temperature') + 500
+
 def write_to_register(ctx, value):
-   ctx.set_property(value, '/registers/fpga/reg1')
+   ctx.set_property(value, '/registers/fpga/sensor_temperature') - 500