How to transform a python (long) integer to a boost multiprecision int with C API

98 Views Asked by At

I want to transform a python integer to a boost multi precision cpp_int in C++, to be able to work with integers of arbitrary size. My code is entirely in C++, so I need to do this using Python API for C, working with PyObject.

I am currently doing it through string representation using PyObject_Str and PyUnicode_AsUTF8AndSize. Is it possible to optimize this by using byte array instead? boost cpp_int has import_bits to generate from a byte array, but I couldn't find anything in python C api to transform an integer to bytes (like to_bytes in python) PyObject_Bytes and PyBytes_FromObject don't seem to work. both return NULL.

0

There are 0 best solutions below