Skip to content

Commit

Permalink
giampaolo#517 The data type retrurned from kstat is interface dependent
Browse files Browse the repository at this point in the history
and not system dependent

_INT64_TYPE may be defined but kstat may still return
the IO counters in 32-bit types.
In addition, on SunOS, sizeof(long)==sizeof(long long)==8
so using 'k' and 'K' means the same, and we need to ue 'I' for
unsigned 32 bit integers.
  • Loading branch information
Arnon Yaari committed Sep 6, 2015
1 parent 9f394c7 commit 9fc4b0e
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions psutil/_psutil_sunos.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,26 +728,32 @@ psutil_net_io_counters(PyObject *self, PyObject *args) {
goto error;
}

#if defined(_INT64_TYPE)
py_ifc_info = Py_BuildValue("(KKKKkkii)",
wbytes->value.ui64,
rbytes->value.ui64,
wpkts->value.ui64,
rpkts->value.ui64,
ierrs->value.ui32,
oerrs->value.ui32,
#else
py_ifc_info = Py_BuildValue("(kkkkkkii)",
wbytes->value.ui32,
rbytes->value.ui32,
wpkts->value.ui32,
rpkts->value.ui32,
ierrs->value.ui32,
oerrs->value.ui32,
#endif
0, // dropin not supported
0 // dropout not supported
);
if (rbytes->data_type == KSTAT_DATA_UINT64)
{
py_ifc_info = Py_BuildValue("(KKKKIIii)",
wbytes->value.ui64,
rbytes->value.ui64,
wpkts->value.ui64,
rpkts->value.ui64,
ierrs->value.ui32,
oerrs->value.ui32,
0, // dropin not supported
0 // dropout not supported
);
}
else
{
py_ifc_info = Py_BuildValue("(IIIIIIii)",
wbytes->value.ui32,
rbytes->value.ui32,
wpkts->value.ui32,
rpkts->value.ui32,
ierrs->value.ui32,
oerrs->value.ui32,
0, // dropin not supported
0 // dropout not supported
);
}
if (!py_ifc_info)
goto error;
if (PyDict_SetItemString(py_retdict, ksp->ks_name, py_ifc_info))
Expand Down

0 comments on commit 9fc4b0e

Please sign in to comment.