From 0e12e11ed817d66ff1e9246a32931e14e4fa6700 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Thu, 4 Feb 2016 01:18:33 +0100 Subject: Add build information --- pcilib/CMakeLists.txt | 8 ++++---- pcilib/build.h.in | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 pcilib/build.h.in (limited to 'pcilib') diff --git a/pcilib/CMakeLists.txt b/pcilib/CMakeLists.txt index cdc9c3f..a7557b7 100644 --- a/pcilib/CMakeLists.txt +++ b/pcilib/CMakeLists.txt @@ -8,10 +8,10 @@ include_directories( ${UTHASH_INCLUDE_DIRS} ) -set(HEADERS pcilib.h pci.h datacpy.h memcpy.h pagecpy.h cpu.h timing.h export.h value.h bar.h fifo.h model.h bank.h register.h view.h property.h unit.h xml.h py.h kmem.h irq.h locking.h lock.h dma.h event.h plugin.h tools.h error.h debug.h env.h version.h config.h) -add_library(pcilib SHARED pci.c datacpy.c memcpy.c pagecpy.c cpu.c timing.c export.c value.c bar.c fifo.c model.c bank.c register.c view.c unit.c property.c xml.c py.c kmem.c irq.c locking.c lock.c dma.c event.c plugin.c tools.c error.c debug.c env.c ) +set(HEADERS pcilib.h pci.h datacpy.h memcpy.h pagecpy.h cpu.h timing.h export.h value.h bar.h fifo.h model.h bank.h register.h view.h property.h unit.h xml.h py.h kmem.h irq.h locking.h lock.h dma.h event.h plugin.h tools.h error.h debug.h env.h version.h config.h build.h) +add_library(pcilib SHARED pci.c datacpy.c memcpy.c pagecpy.c cpu.c timing.c export.c value.c bar.c fifo.c model.c bank.c register.c view.c unit.c property.c xml.c py.c kmem.c irq.c locking.c lock.c dma.c event.c plugin.c tools.c error.c debug.c env.c) target_link_libraries(pcilib dma protocols views ${CMAKE_THREAD_LIBS_INIT} ${UFODECODE_LIBRARIES} ${CMAKE_DL_LIBS} ${EXTRA_SYSTEM_LIBS} ${LIBXML2_LIBRARIES} ${PYTHON_LIBRARIES}) -add_dependencies(pcilib dma protocols views) +add_dependencies(pcilib build dma protocols views) install(TARGETS pcilib LIBRARY DESTINATION lib${LIB_SUFFIX} @@ -23,4 +23,4 @@ install(FILES pcilib.h install(FILES bar.h kmem.h locking.h lock.h bank.h register.h xml.h dma.h event.h model.h error.h debug.h env.h tools.h timing.h cpu.h datacpy.h pagecpy.h memcpy.h export.h version.h view.h unit.h DESTINATION include/pcilib -) +) \ No newline at end of file diff --git a/pcilib/build.h.in b/pcilib/build.h.in new file mode 100644 index 0000000..1713378 --- /dev/null +++ b/pcilib/build.h.in @@ -0,0 +1,7 @@ +#define PCILIB_REVISION "${PCILIB_REVISION}" +#define PCILIB_REVISION_BRANCH "${PCILIB_REVISION_BRANCH}" +#define PCILIB_REVISION_AUTHOR "${PCILIB_REVISION_AUTHOR}" +#define PCILIB_REVISION_MODIFICATIONS "${PCILIB_REVISION_MODIFICATIONS}" +#define PCILIB_BUILD_DATE "${PCILIB_BUILD_DATE}" +#define PCILIB_BUILD_DIR "${CMAKE_SOURCE_DIR}" +#define PCILIB_LAST_MODIFICATION "${PCILIB_LAST_MODIFICATION}" -- cgit v1.2.3 From dbef1e0271da298a0cbdc951dda84b7f150bbad0 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Tue, 23 Feb 2016 08:12:30 +0100 Subject: Stabilize merged code --- pcilib/py.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'pcilib') 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 +#endif /* HAVE_PYTHON */ + #include #include #include @@ -10,11 +15,6 @@ #include "pcilib.h" #include "py.h" #include "error.h" -#include "config.h" - -#ifdef HAVE_PYTHON -# include -#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 */ } -- cgit v1.2.3 From 3ea1907f3169e0233d3a32a7d470af3c34b6f967 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Tue, 23 Feb 2016 09:03:22 +0100 Subject: Add more GILs to prevent Python crashes in multithreaded applications --- pcilib/py.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'pcilib') diff --git a/pcilib/py.c b/pcilib/py.c index 1db18f7..a5118fb 100644 --- a/pcilib/py.c +++ b/pcilib/py.c @@ -276,10 +276,12 @@ pcilib_py_object *pcilib_get_value_as_pyobject(pcilib_t* ctx, pcilib_value_t *va #ifdef HAVE_PYTHON int err = 0; PyObject *res = NULL; + PyGILState_STATE gstate; long ival; double fval; + gstate = PyGILState_Ensure(); switch(val->type) { case PCILIB_TYPE_LONG: ival = pcilib_get_value_as_int(ctx, val, &err); @@ -290,9 +292,12 @@ pcilib_py_object *pcilib_get_value_as_pyobject(pcilib_t* ctx, pcilib_value_t *va if (!err) res = (PyObject*)PyFloat_FromDouble(fval); break; default: - err = PCILIB_ERROR_NOTSUPPORTED; + PyGILState_Release(gstate); pcilib_error("Can't convert pcilib value of type (%lu) to PyObject", val->type); + if (ret) *ret = PCILIB_ERROR_NOTSUPPORTED; + return NULL; } + PyGILState_Release(gstate); if (err) { if (ret) *ret = err; @@ -314,7 +319,9 @@ int pcilib_set_value_from_pyobject(pcilib_t* ctx, pcilib_value_t *val, pcilib_py #ifdef HAVE_PYTHON int err = 0; PyObject *pyval = (PyObject*)pval; + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); if (PyInt_Check(pyval)) { err = pcilib_set_value_from_int(ctx, val, PyInt_AsLong(pyval)); } else if (PyFloat_Check(pyval)) { @@ -322,10 +329,12 @@ int pcilib_set_value_from_pyobject(pcilib_t* ctx, pcilib_value_t *val, pcilib_py } else if (PyString_Check(pyval)) { err = pcilib_set_value_from_string(ctx, val, PyString_AsString(pyval)); } else { + PyGILState_Release(gstate); pcilib_error("Can't convert PyObject to polymorphic pcilib value"); - err = PCILIB_ERROR_NOTSUPPORTED; + return PCILIB_ERROR_NOTSUPPORTED; } - + PyGILState_Release(gstate); + return err; #else /* HAVE_PYTHON */ pcilib_error("Python is not supported"); @@ -443,6 +452,8 @@ static char *pcilib_py_parse_string(pcilib_t *ctx, const char *codestr, pcilib_v int pcilib_py_eval_string(pcilib_t *ctx, const char *codestr, pcilib_value_t *value) { #ifdef HAVE_PYTHON + int err; + PyGILState_STATE gstate; char *code; PyObject* obj; @@ -463,7 +474,9 @@ int pcilib_py_eval_string(pcilib_t *ctx, const char *codestr, pcilib_value_t *va } pcilib_debug(VIEWS, "Evaluating a Python string \'%s\' to %lf=\'%s\'", codestr, PyFloat_AsDouble(obj), code); - return pcilib_set_value_from_float(ctx, value, PyFloat_AsDouble(obj)); + err = pcilib_set_value_from_float(ctx, value, PyFloat_AsDouble(obj)); + + return err; #else /* HAVE_PYTHON */ pcilib_error("Current build not support python."); return PCILIB_ERROR_NOTAVAILABLE; @@ -489,20 +502,22 @@ int pcilib_py_eval_func(pcilib_t *ctx, const char *script_name, const char *func if (err) return err; } + PyGILState_STATE gstate = PyGILState_Ensure(); + pyfunc = PyUnicode_FromString(func_name); if (!pyfunc) { if (pyval) Py_XDECREF(pyval); + PyGILState_Release(gstate); return PCILIB_ERROR_MEMORY; } - PyGILState_STATE gstate = PyGILState_Ensure(); pyret = PyObject_CallMethodObjArgs(module->module, pyfunc, ctx->py->pcilib_pywrap, pyval, NULL); - PyGILState_Release(gstate); Py_XDECREF(pyfunc); Py_XDECREF(pyval); if (!pyret) { + PyGILState_Release(gstate); pcilib_python_error("Error executing function (%s) of python script (%s)", func_name, script_name); return PCILIB_ERROR_FAILED; } @@ -511,6 +526,7 @@ int pcilib_py_eval_func(pcilib_t *ctx, const char *script_name, const char *func err = pcilib_set_value_from_pyobject(ctx, val, pyret); Py_XDECREF(pyret); + PyGILState_Release(gstate); return err; #else /* HAVE_PYTHON */ -- cgit v1.2.3