PyBytes_FromString returning a None object

146 views Asked by At

I was wondering if I could get some help. Say I've got the following function to serialize an object:

PyObject * CKKSwrapper::SerializeContext() {
    std::string s;
    std::ostringstream os(s);
    Serial::Serialize(m_cc, os, SerType::BINARY);

    const std::string tmp = os.str();
    const char *msg = tmp.c_str();
    std::cout << "Length of context: " << tmp.length() << "\n";
    return PyBytes_FromString(msg);
}

The Boost module file has

BOOST_PYTHON_MODULE (pycrypto) {
    class_<pycrypto::CKKSwrapper>("CKKSwrapper")
        .def("SerializeContext", &pycrypto::CKKSwrapper::SerializeContext,
             return_value_policy<manage_new_object>());

where I am managing the object.

However, when I call the method in Python, I get a None object, and the output is

import pycrypto
a = pycrypto.SerializeContext()

a is None and I get Length of context: X to my console

0

There are 0 answers