passing uint64_t between python and c++
Fredrik Lundh
fredrik at pythonware.com
Thu Oct 14 02:37:25 EDT 2004
Jhy-Chun Wang wrote:
> I have a c++ extension that does thing like:
>
> extern "C"
> static PyObject *
> nasUtil_access_cmd(PyObject *self, PyObject *args)
> {
> uint64_t paddr;
> uint64_t data;
>
> if (!PyArg_ParseTuple(args, (char*)"LL", &paddr, &data)) {
> return NULL;
> }
> ...
> }
from the documentation:
http://www.python.org/doc/current/api/arg-parsing.html
"L" (integer) [PY_LONG_LONG]
Convert a Python integer to a C long long. This format is only available
on platforms that support long long (or _int64 on Windows).
"K" (integer) [unsigned PY_LONG_LONG]
Convert a Python integer to a C unsigned long long without overflow
checking. This format is only available on platforms that support
unsigned long long (or unsigned _int64 on Windows). New in
version 2.3.
in other words, you should use "K" instead of "L", and you should use an
"unsigned PY_LONG_LONG" to hold the value (this may or may not be
the same thing as uint64_t, but why write non-portable code if you don't
have to)
</F>
More information about the Python-list
mailing list