1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#ifndef WREPORT_PYTHON_DICT_H
#define WREPORT_PYTHON_DICT_H
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "core.h"
#include "values.h"
namespace wreport {
namespace python {
template<typename T>
inline void set_dict(PyObject* dict, const char* key, const T& val)
{
auto pyval = to_python(val);
if (PyDict_SetItemString(dict, key, pyval))
throw PythonException();
}
inline void set_dict(PyObject* dict, const char* key, PyObject* val)
{
if (PyDict_SetItemString(dict, key, val))
throw PythonException();
}
inline void set_dict(PyObject* dict, const char* key, pyo_unique_ptr& val)
{
if (PyDict_SetItemString(dict, key, val))
throw PythonException();
}
}
}
#endif
|