From 3bb43f1260ec30e919d11a554ab4e0d29dd9312e Mon Sep 17 00:00:00 2001 From: Vasilii Chernov Date: Fri, 19 Feb 2016 12:08:10 +0100 Subject: 1. Fix warnings in test_multithread app 2. Fix memory leak in transform view 3. Enchance test_pcipywrap with command line parsing --- pcilib/py.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'pcilib') diff --git a/pcilib/py.c b/pcilib/py.c index a288043..ea7e6d7 100644 --- a/pcilib/py.c +++ b/pcilib/py.c @@ -3,7 +3,6 @@ #endif #include -#include #include #include @@ -67,11 +66,13 @@ int pcilib_init_py(pcilib_t *ctx) { } PyObject* mod_name = PyString_FromString("Pcipywrap"); + PyObject* py_ctx = PyCObject_FromVoidPtr(ctx, NULL); ctx->py->pcilib_pywrap = PyObject_CallMethodObjArgs(py_script_module, mod_name, - PyCObject_FromVoidPtr(ctx, NULL), + py_ctx, NULL); Py_XDECREF(mod_name); + Py_XDECREF(py_ctx); if(!ctx->py->pcilib_pywrap) { @@ -93,17 +94,25 @@ int pcilib_py_add_script_dir(pcilib_t *ctx) if(!model_dir_added) { char* model_dir = getenv("PCILIB_MODEL_DIR"); + if(!model_dir) + { + pcilib_error("Enviroment variable PCILIB_MODEL_DIR not set."); + return PCILIB_ERROR_NOTINITIALIZED; + } char* model_path = malloc(strlen(model_dir) + strlen(ctx->model) + 2); if (!model_path) return PCILIB_ERROR_MEMORY; sprintf(model_path, "%s/%s", model_dir, ctx->model); //add path to python PyObject* path = PySys_GetObject("path"); - if(PyList_Append(path, PyString_FromString(model_path)) == -1) + PyObject* py_model_path = PyString_FromString(model_path); + if(PyList_Append(path, py_model_path) == -1) { + Py_XDECREF(py_model_path); pcilib_error("Cant set PCILIB_MODEL_DIR library path to python."); free(model_path); return PCILIB_ERROR_FAILED; } + Py_XDECREF(py_model_path); free(model_path); model_dir_added = 1; } @@ -119,7 +128,8 @@ void pcilib_free_py(pcilib_t *ctx) { if(ctx->py->py_initialized_inside) py_initialized_inside = 1; - // Dict and module references are borrowed + // Dict and module references are borrowed + Py_XDECREF(ctx->py->pcilib_pywrap); free(ctx->py); ctx->py = NULL; } @@ -434,10 +444,14 @@ pcilib_access_mode_t *mode) PyObject* dict = PyModule_GetDict(module->module); //Setting correct mode mode[0] = 0; - if(PyDict_Contains(dict, PyString_FromString("read_from_register"))) - mode[0] |= PCILIB_ACCESS_R; - if(PyDict_Contains(dict, PyString_FromString("write_to_register"))) - mode[0] |= PCILIB_ACCESS_W; + PyObject* py_read_from_register = PyString_FromString("read_from_register"); + if(PyDict_Contains(dict, py_read_from_register)) + mode[0] |= PCILIB_ACCESS_R; + Py_XDECREF(py_read_from_register); + PyObject* py_write_to_register = PyString_FromString("write_to_register"); + if(PyDict_Contains(dict, py_write_to_register)) + mode[0] |= PCILIB_ACCESS_W; + Py_XDECREF(py_write_to_register); return 0; #else mode[0] = PCILIB_ACCESS_RW; -- cgit v1.2.3 From b16fd97ffcaf9e7bd3fd52e505adbed2ffd0c768 Mon Sep 17 00:00:00 2001 From: Vasilii Chernov Date: Fri, 19 Feb 2016 15:38:47 +0100 Subject: Add istall step for pcipywrap --- pcilib/CMakeLists.txt | 6 +++++- pywrap/CMakeLists.txt | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'pcilib') diff --git a/pcilib/CMakeLists.txt b/pcilib/CMakeLists.txt index cdc9c3f..ea1db8b 100644 --- a/pcilib/CMakeLists.txt +++ b/pcilib/CMakeLists.txt @@ -21,6 +21,10 @@ install(FILES pcilib.h DESTINATION include ) -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 +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 view.h unit.h + DESTINATION include/pcilib +) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/version.h DESTINATION include/pcilib ) diff --git a/pywrap/CMakeLists.txt b/pywrap/CMakeLists.txt index 4592c9a..bebdf2e 100644 --- a/pywrap/CMakeLists.txt +++ b/pywrap/CMakeLists.txt @@ -18,5 +18,10 @@ SET(CMAKE_SWIG_FLAGS "") SWIG_ADD_MODULE(pcipywrap python pcipywrap.i pcipywrap.c) SWIG_LINK_LIBRARIES(pcipywrap ${PYTHON_LIBRARIES} pcilib) +#install pcilib python wrapper into Python site packages folder +execute_process ( COMMAND python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE) +install(TARGETS ${SWIG_MODULE_pcipywrap_REAL_NAME} DESTINATION ${PYTHON_SITE_PACKAGES}) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/pcipywrap.py DESTINATION ${PYTHON_SITE_PACKAGES}) + configure_file(server.py server.py) configure_file(test_pcipywrap.py test_pcipywrap.py) -- cgit v1.2.3 From ed7a7ff66c64cc2e164070865306e7d79652063a Mon Sep 17 00:00:00 2001 From: Vasilii Chernov Date: Thu, 25 Feb 2016 09:22:31 +0100 Subject: Set value description content to NULL in pcilib_xml_parse_value_name --- pcilib/xml.c | 2 ++ pywrap/pcipywrap.c | 15 ++++++++++----- pywrap/test_pcipywrap.py | 14 +++++++------- 3 files changed, 19 insertions(+), 12 deletions(-) (limited to 'pcilib') diff --git a/pcilib/xml.c b/pcilib/xml.c index fd12636..0463a40 100644 --- a/pcilib/xml.c +++ b/pcilib/xml.c @@ -615,6 +615,8 @@ static int pcilib_xml_parse_value_name(pcilib_t *ctx, xmlXPathContextPtr xpath, int min_set = 0, max_set = 0; pcilib_register_value_t val; + + memset(desc, 0, sizeof(pcilib_register_value_name_t)); for (cur = node->properties; cur != NULL; cur = cur->next) { if(!cur->children) continue; diff --git a/pywrap/pcipywrap.c b/pywrap/pcipywrap.c index fe53966..64e059a 100644 --- a/pywrap/pcipywrap.c +++ b/pywrap/pcipywrap.c @@ -232,6 +232,7 @@ PyObject * pcilib_convert_register_info_to_pyobject(pcilib_t* ctx, pcilib_regist PyString_FromString("bank"), PyString_FromString(listItem.bank)); + //serialize modes PyObject* modes = PyList_New(0); @@ -278,8 +279,9 @@ PyObject * pcilib_convert_register_info_to_pyobject(pcilib_t* ctx, pcilib_regist if(listItem.values) { - PyObject* values = PyList_New(0); + PyObject* values = PyList_New(0); + for (int j = 0; listItem.values[j].name; j++) { PyObject* valuesItem = PyDict_New(); @@ -301,12 +303,13 @@ PyObject * pcilib_convert_register_info_to_pyobject(pcilib_t* ctx, pcilib_regist pcilib_pydict_set_item(valuesItem, PyString_FromString("name"), PyString_FromString(listItem.values[j].name)); - if(listItem.values[j].description) + { pcilib_pydict_set_item(valuesItem, PyString_FromString("description"), PyString_FromString(listItem.values[j].description)); - + + } pcilib_pylist_append(values, valuesItem); } @@ -316,6 +319,7 @@ PyObject * pcilib_convert_register_info_to_pyobject(pcilib_t* ctx, pcilib_regist } return pylistItem; + } Pcipywrap *new_Pcipywrap(const char* fpga_device, const char* model) @@ -456,11 +460,12 @@ PyObject* Pcipywrap_get_registers_list(Pcipywrap *self, const char *bank) { pcilib_register_info_t *list = pcilib_get_register_list(self->ctx, bank, PCILIB_LIST_FLAGS_DEFAULT); PyObject* pyList = PyList_New(0); - for(int i = 0; i < 10/*((pcilib_t*)self->ctx)->num_reg*/; i++) + for(int i = 0; i < ((pcilib_t*)self->ctx)->num_reg; i++) { //serialize item attributes PyObject* pylistItem = pcilib_convert_register_info_to_pyobject(self->ctx, list[i]); pcilib_pylist_append(pyList, pylistItem); + //Py_DECREF(pylistItem); } pcilib_free_register_info(self->ctx, list); return pyList; @@ -544,7 +549,7 @@ void Pcipywrap_unlock_global(Pcipywrap *self) PyObject* Pcipywrap_lock(Pcipywrap *self, const char *lock_id) { pcilib_lock_t* lock = pcilib_get_lock(self->ctx, - PCILIB_LOCK_FLAG_PERSISTENT, + PCILIB_LOCK_FLAGS_DEFAULT, lock_id); if(!lock) { diff --git a/pywrap/test_pcipywrap.py b/pywrap/test_pcipywrap.py index d736639..91780ec 100644 --- a/pywrap/test_pcipywrap.py +++ b/pywrap/test_pcipywrap.py @@ -84,13 +84,13 @@ class test_pcipywrap(): while(1): val = random.randint(0, 8096) self.pcilib = pcipywrap.Pcipywrap(self.device, self.model) - #print self.pcilib.get_property_list(self.branch) - #print self.pcilib.get_register_info(self.register) - #print self.pcilib.get_registers_list(); - #print self.pcilib.read_register(self.register) - #print self.pcilib.write_register(val, self.register) - #print self.pcilib.get_property(self.prop) - #print self.pcilib.set_property(val, self.prop) + print self.pcilib.get_property_list(self.branch) + print self.pcilib.get_register_info(self.register) + print self.pcilib.get_registers_list(); + print self.pcilib.read_register(self.register) + print self.pcilib.write_register(val, self.register) + print self.pcilib.get_property(self.prop) + print self.pcilib.set_property(val, self.prop) except KeyboardInterrupt: print 'testing done' pass -- cgit v1.2.3