forked from fanchy/ffpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyops_for_embed.h
More file actions
77 lines (61 loc) · 1.77 KB
/
pyops_for_embed.h
File metadata and controls
77 lines (61 loc) · 1.77 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef __PYOPS_FOR_EMBED
#define __PYOPS_FOR_EMBED
#include "pyops_base.h"
template<typename T>
const T& pycall_t::call(const string& mod_name_, const string& func_name_, pycall_arg_t& pyarg_, pytype_tool_impl_t<T>& pyret)
{
PyObject *pName = NULL, *pModule = NULL;
string err_msg;
pName = PyString_FromString(mod_name_.c_str());
pModule = PyImport_Import(pName);
Py_DECREF(pName);
if (NULL == pModule)
{
pyops_t::traceback(err_msg);
throw runtime_error(err_msg.c_str());
return pyret.get_value();
}
call_func(pModule, mod_name_, func_name_, pyarg_, pyret, err_msg);
Py_DECREF(pModule);
if (!err_msg.empty())
{
throw runtime_error(err_msg.c_str());
}
return pyret.get_value();
}
template<typename T>
const T& pycall_t::call_obj_method(PyObject *pObj, const string& func_name_, pycall_arg_t& pyarg_, pytype_tool_impl_t<T>& pyret)
{
string err_msg;
if (NULL == pObj)
{
pyops_t::traceback(err_msg);
throw runtime_error(err_msg.c_str());
return pyret.get_value();
}
static string mod_name_ = "NaN";
call_func(pObj, mod_name_, func_name_, pyarg_, pyret, err_msg);
if (!err_msg.empty())
{
throw runtime_error(err_msg.c_str());
}
return pyret.get_value();
}
template<typename T>
const T& pycall_t::call_lambda(PyObject *pFunc, pycall_arg_t& pyarg_, pytype_tool_impl_t<T>& pyret)
{
string err_msg;
if (NULL == pFunc)
{
err_msg = "can not call null PyObject";
throw runtime_error(err_msg.c_str());
return pyret.get_value();
}
call_func_obj(pFunc, pyarg_, pyret, err_msg);
if (!err_msg.empty())
{
throw runtime_error(err_msg.c_str());
}
return pyret.get_value();
}
#endif