0

我想知道我是否可以得到一些帮助。假设我有以下函数来序列化一个对象:

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);
}

Boost模块文件有

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

我在哪里管理对象。

但是,当我在 Python 中调用该方法时,我得到一个 None 对象,输出为

import pycrypto
a = pycrypto.SerializeContext()

一个是None,我Length of context: X到我的控制台

4

0 回答 0