summaryrefslogtreecommitdiffstats
path: root/pcilib
diff options
context:
space:
mode:
authorVasilii Chernov <vchernov@inr.ru>2016-02-11 12:28:37 +0100
committerVasilii Chernov <vchernov@inr.ru>2016-02-11 12:28:37 +0100
commit76ee5a167add1c169a982ab59aa0544f827cb365 (patch)
treebd10c0f170bdf2f68d258115145d5d39c075fa8a /pcilib
parentf526c4a5a3e4f35bb1c4b03af1f3244a8c0db48a (diff)
downloadpcitool-76ee5a167add1c169a982ab59aa0544f827cb365.tar.gz
pcitool-76ee5a167add1c169a982ab59aa0544f827cb365.tar.bz2
pcitool-76ee5a167add1c169a982ab59aa0544f827cb365.tar.xz
pcitool-76ee5a167add1c169a982ab59aa0544f827cb365.zip
Solve errors in serialing register_info function. Clear unused code
Diffstat (limited to 'pcilib')
-rw-r--r--pcilib/pcipywrap.c39
-rw-r--r--pcilib/py.c10
-rw-r--r--pcilib/xml.c47
3 files changed, 33 insertions, 63 deletions
diff --git a/pcilib/pcipywrap.c b/pcilib/pcipywrap.c
index db0e412..18874af 100644
--- a/pcilib/pcipywrap.c
+++ b/pcilib/pcipywrap.c
@@ -44,6 +44,7 @@ char* make_str(const char* msg, ...)
va_start(vl, msg);
char *buf = vmake_str(msg, vl);
va_end(vl);
+ return buf;
}
/*!
@@ -276,12 +277,12 @@ PyObject* set_property(const char *prop, PyObject* val)
void add_pcilib_value_to_dict(PyObject* dict, pcilib_value_t* val, const char *name)
{
- PyObject *py_val = pcilib_convert_val_to_pyobject(__ctx, val);
+ PyObject *py_val = (PyObject*)pcilib_convert_val_to_pyobject(__ctx, val);
if(py_val)
PyDict_SetItem(dict,
PyString_FromString(name),
- val);
+ py_val);
else
PyDict_SetItem(dict,
PyString_FromString("defvalue"),
@@ -407,13 +408,22 @@ PyObject * pcilib_convert_register_info_to_pyobject(pcilib_register_info_t listI
PyDict_SetItem(pylistItem,
PyString_FromString("mode"),
modes);
- add_pcilib_value_to_dict(pylistItem, &listItem.defvalue, "defvalue");
+
+ pcilib_value_t defval = {0};
+ pcilib_set_value_from_register_value(__ctx, &defval, listItem.defvalue);
+ add_pcilib_value_to_dict(pylistItem, &defval, "defvalue");
if(listItem.range)
{
+ pcilib_value_t minval = {0};
+ pcilib_set_value_from_register_value(__ctx, &minval, listItem.range->min);
+
+ pcilib_value_t maxval = {0};
+ pcilib_set_value_from_register_value(__ctx, &maxval, listItem.range->max);
+
PyObject* range = PyDict_New();
- add_pcilib_value_to_dict(range, &(listItem.range->min), "min");
- add_pcilib_value_to_dict(range, &(listItem.range->max), "max");
+ add_pcilib_value_to_dict(range, &minval, "min");
+ add_pcilib_value_to_dict(range, &maxval, "max");
PyDict_SetItem(pylistItem,
PyString_FromString("range"),
range);
@@ -426,10 +436,19 @@ PyObject * pcilib_convert_register_info_to_pyobject(pcilib_register_info_t listI
for (int j = 0; listItem.values[j].name; j++)
{
PyObject* valuesItem = PyDict_New();
-
- add_pcilib_value_to_dict(valuesItem, &(listItem.values[j].value), "value");
- add_pcilib_value_to_dict(valuesItem, &(listItem.values[j].min), "min");
- add_pcilib_value_to_dict(valuesItem, &(listItem.values[j].max), "max");
+
+ pcilib_value_t val = {0};
+ pcilib_set_value_from_register_value(__ctx, &val, listItem.values[j].value);
+
+ pcilib_value_t min = {0};
+ pcilib_set_value_from_register_value(__ctx, &min, listItem.values[j].min);
+
+ pcilib_value_t max = {0};
+ pcilib_set_value_from_register_value(__ctx, &max, listItem.values[j].max);
+
+ add_pcilib_value_to_dict(valuesItem, &val, "value");
+ add_pcilib_value_to_dict(valuesItem, &min, "min");
+ add_pcilib_value_to_dict(valuesItem, &max, "max");
if(listItem.values[j].name)
PyDict_SetItem(valuesItem,
@@ -510,7 +529,7 @@ PyObject* get_property_info(const char* branch)
PyObject* pyList = PyList_New(0);
- for(int i = 0; i < list[i].path; i++)
+ for(int i = 0; list[i].path; i++)
{
//serialize item attributes
PyObject* pylistItem = pcilib_convert_property_info_to_pyobject(list[i]);
diff --git a/pcilib/py.c b/pcilib/py.c
index acc18df..57a5f46 100644
--- a/pcilib/py.c
+++ b/pcilib/py.c
@@ -269,9 +269,7 @@ int pcilib_convert_pyobject_to_val(pcilib_t* ctx, void* pyObjVal, pcilib_value_t
}
int pcilib_init_py_script(pcilib_t *ctx, char* module_name, pcilib_script_t **module, pcilib_access_mode_t *mode)
-{
- int err;
-
+{
//Initialize python script, if it has not initialized already.
if(!module_name)
{
@@ -389,6 +387,8 @@ int pcilib_free_py_script(pcilib_script_t *module)
module->py_script_module = NULL;
}
}
+
+ return 0;
}
int pcilib_script_read(pcilib_t *ctx, pcilib_script_t *module, pcilib_value_t *val)
@@ -415,9 +415,7 @@ int pcilib_script_read(pcilib_t *ctx, pcilib_script_t *module, pcilib_value_t *v
}
int pcilib_script_write(pcilib_t *ctx, pcilib_script_t *module, pcilib_value_t *val)
-{
- int err;
-
+{
PyObject *input = pcilib_convert_val_to_pyobject(ctx, val);
if(!input)
{
diff --git a/pcilib/xml.c b/pcilib/xml.c
index f21480c..38bb917 100644
--- a/pcilib/xml.c
+++ b/pcilib/xml.c
@@ -554,53 +554,6 @@ static int pcilib_xml_parse_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDoc
return 0;
}
-static int pcilib_xml_create_script_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) {
- int err;
- xmlAttrPtr cur;
- const char *value, *name;
- pcilib_view_context_t *view_ctx;
-
-
- pcilib_access_mode_t mode = 0;
- pcilib_transform_view_description_t desc = {{0}};
-
- desc.base.api = &pcilib_transform_view_api;
- desc.base.type = PCILIB_TYPE_DOUBLE;
- desc.base.mode = PCILIB_ACCESS_RW;
- desc.script = NULL;
-
- err = pcilib_xml_parse_view(ctx, xpath, doc, node, (pcilib_view_description_t*)&desc);
- if (err) return err;
-
- for (cur = node->properties; cur != NULL; cur = cur->next) {
- if (!cur->children) continue;
- if (!xmlNodeIsText(cur->children)) continue;
-
- name = (char*)cur->name;
- value = (char*)cur->children->content;
- if (!value) continue;
-
- if (!strcasecmp(name, "script"))
- {
- //write script name to struct
- char* script_name = malloc(strlen(value));
- sprintf(script_name, "%s", value);
-
- err = pcilib_init_py_script(ctx, script_name, &(desc.script), &mode);
- if(err) return err;
- mode |= PCILIB_REGISTER_NO_CHK;
- }
- }
-
- desc.base.mode &= mode;
-
- err = pcilib_add_views_custom(ctx, 1, (pcilib_view_description_t*)&desc, &view_ctx);
- if (err) return err;
-
- view_ctx->xml = node;
- return 0;
-}
-
static int pcilib_xml_create_transform_view(pcilib_t *ctx, xmlXPathContextPtr xpath, xmlDocPtr doc, xmlNodePtr node) {
int err;
xmlAttrPtr cur;