-#define DICTSET_STR(dict, name, value) \
- t = PyString_FromString(value); \
- PyDict_SetItemString(dict, name, t); \
- Py_DECREF(t);
-
-#define DICTSET_CNT(dict, name, value) \
- t = PyInt_FromLong((long)value); \
- PyDict_SetItemString(dict, name, t); \
- Py_DECREF(t);
-
-#define DICTSET_VAL(dict, name, value) \
- t = isnan(value) ? (Py_INCREF(Py_None), Py_None) : \
- PyFloat_FromDouble((double)value); \
- PyDict_SetItemString(dict, name, t); \
- Py_DECREF(t);
-
- r = PyDict_New();
-
- DICTSET_STR(r, "filename", filename);
- DICTSET_STR(r, "rrd_version", rrd.stat_head->version);
- DICTSET_CNT(r, "step", rrd.stat_head->pdp_step);
- DICTSET_CNT(r, "last_update", rrd.live_head->last_up);
-
- ds = PyDict_New();
- PyDict_SetItemString(r, "ds", ds);
- Py_DECREF(ds);
-
- for (i = 0; i < rrd.stat_head->ds_cnt; i++) {
- PyObject *d;
-
- d = PyDict_New();
- PyDict_SetItemString(ds, rrd.ds_def[i].ds_nam, d);
- Py_DECREF(d);
-
- DICTSET_STR(d, "ds_name", rrd.ds_def[i].ds_nam);
- DICTSET_STR(d, "type", rrd.ds_def[i].dst);
- DICTSET_CNT(d, "minimal_heartbeat",
- rrd.ds_def[i].par[DS_mrhb_cnt].u_cnt);
- DICTSET_VAL(d, "min", rrd.ds_def[i].par[DS_min_val].u_val);
- DICTSET_VAL(d, "max", rrd.ds_def[i].par[DS_max_val].u_val);
- DICTSET_STR(d, "last_ds", rrd.pdp_prep[i].last_ds);
- DICTSET_VAL(d, "value", rrd.pdp_prep[i].scratch[PDP_val].u_val);
- DICTSET_CNT(d, "unknown_sec",
- rrd.pdp_prep[i].scratch[PDP_unkn_sec_cnt].u_cnt);
- }
-
- ds = PyList_New(rrd.stat_head->rra_cnt);
- PyDict_SetItemString(r, "rra", ds);
- Py_DECREF(ds);
-
- for (i = 0; i < rrd.stat_head->rra_cnt; i++) {
- PyObject *d, *cdp;