summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2016-02-23 08:12:30 +0100
committerSuren A. Chilingaryan <csa@suren.me>2016-02-23 08:12:30 +0100
commitdbef1e0271da298a0cbdc951dda84b7f150bbad0 (patch)
tree0e10f8953f5b61193c8393dd05b257c0fd9a44a1
parenta962c90543955bac98308c1b0d909048070d900a (diff)
downloadpcitool-dbef1e0271da298a0cbdc951dda84b7f150bbad0.tar.gz
pcitool-dbef1e0271da298a0cbdc951dda84b7f150bbad0.tar.bz2
pcitool-dbef1e0271da298a0cbdc951dda84b7f150bbad0.tar.xz
pcitool-dbef1e0271da298a0cbdc951dda84b7f150bbad0.zip
Stabilize merged code
-rw-r--r--.bzrignore1
-rw-r--r--pcilib/py.c30
-rw-r--r--pywrap/test_pcipywrap.py2
-rw-r--r--views/transform.c4
-rw-r--r--xml/test/test_prop3.py6
5 files changed, 25 insertions, 18 deletions
diff --git a/.bzrignore b/.bzrignore
index e7ce7bc..453185a 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -36,3 +36,4 @@ build.h
build
pcipywrap.py
pcipywrapPYTHON_wrap.c
+apps/test_multithread
diff --git a/pcilib/py.c b/pcilib/py.c
index 9254df7..1db18f7 100644
--- a/pcilib/py.c
+++ b/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 */
}
diff --git a/pywrap/test_pcipywrap.py b/pywrap/test_pcipywrap.py
index 257b4a5..dea73ba 100644
--- a/pywrap/test_pcipywrap.py
+++ b/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()
diff --git a/views/transform.c b/views/transform.c
index f2d4b4a..25f30d1 100644
--- a/views/transform.c
+++ b/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;
diff --git a/xml/test/test_prop3.py b/xml/test/test_prop3.py
index a082096..c0728a3 100644
--- a/xml/test/test_prop3.py
+++ b/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