diff options
author | Vasilii Chernov <vchernov@inr.ru> | 2016-02-19 12:08:10 +0100 |
---|---|---|
committer | Vasilii Chernov <vchernov@inr.ru> | 2016-02-19 12:08:10 +0100 |
commit | 3bb43f1260ec30e919d11a554ab4e0d29dd9312e (patch) | |
tree | ffc2371b461b3d8eb70c607c2e2e33684adbd752 /pcilib/py.c | |
parent | 52eb7f4fb76ddf99dedf44332aae7af4df76ab36 (diff) | |
download | pcitool-3bb43f1260ec30e919d11a554ab4e0d29dd9312e.tar.gz pcitool-3bb43f1260ec30e919d11a554ab4e0d29dd9312e.tar.bz2 pcitool-3bb43f1260ec30e919d11a554ab4e0d29dd9312e.tar.xz pcitool-3bb43f1260ec30e919d11a554ab4e0d29dd9312e.zip |
1. Fix warnings in test_multithread app
2. Fix memory leak in transform view
3. Enchance test_pcipywrap with command line parsing
Diffstat (limited to 'pcilib/py.c')
-rw-r--r-- | pcilib/py.c | 30 |
1 files changed, 22 insertions, 8 deletions
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 <stdio.h> -#include <stdlib.h> #include <string.h> #include <strings.h> @@ -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; |