I am trying to pass a (large) integer from python to an extension module, but I am unable to parse pythons arbitrary precision integers to 256-bit unsigned integers uint256
. Here is the C callee:
#include <Python.h>
typedef unsigned _ExtInt(256) uint256;
static PyObject* test(PyObject* self, PyObject* args)
{
uint256 x;
if(!PyArg_ParseTuple(args, "O", &x)) {
puts("Could not parse the python arg");
return NULL;
}
// simple addition
x += (uint256) 1;
return Py_BuildValue("O", x);
}
// ... initalize extension module here ...
In python I run something like
import extension_module
extension_module.test(1)
And I get the error:
Bus error: 10
Or
Segmentation fault: 11
However, if I remove the simple addition x += (uint256) 1;
it will atleast not throw any error and return the argument.
How do I parse extended-integer types in my C extension module?