-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfunctor.cpp
More file actions
95 lines (81 loc) · 2.28 KB
/
functor.cpp
File metadata and controls
95 lines (81 loc) · 2.28 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
#include "functor.hpp"
#include "mi_context_wrapper.hpp"
#include "mi_module_wrapper.hpp"
#include "mi_instance_wrapper.hpp"
#include <cassert>
namespace scx
{
/*ctor*/
Load_Unload_Functor::Load_Unload_Functor (
py_ptr<PyObject> const& pFn)
: m_pFn (pFn)
{
//SCX_BOOKEND ("Load_Unload_Functor::ctor");
}
/*dtor*/
Load_Unload_Functor::~Load_Unload_Functor ()
{
//SCX_BOOKEND ("Load_Unload_Functor::dtor");
}
int
Load_Unload_Functor::operator () (
scx::MI_Module::Ptr const& pModule,
scx::MI_Context::Ptr const& pContext) const
{
SCX_BOOKEND ("Load_Unload_Functor::operator ()");
int rval = EXIT_SUCCESS;
MI_Module_Wrapper::PyPtr pyModule (
MI_Module_Wrapper::createPyPtr (pModule));
MI_Context_Wrapper::PyPtr pyContext (
MI_Context_Wrapper::createPyPtr (pContext));
if (pyModule && pyContext)
{
PyObjPtr pArgs (PyTuple_New (2));
if (pArgs)
{
PyTuple_SetItem (pArgs.get (), 0,
reinterpret_cast<PyObject*>(pyModule.get ()));
PyTuple_SetItem (pArgs.get (), 1,
reinterpret_cast<PyObject*>(pyContext.get ()));
if (m_pFn)
{
SCX_BOOKEND_PRINT ("m_pFn is not NULL");
}
else
{
SCX_BOOKEND_PRINT ("m_pFn is NULL");
}
PyObjPtr pRval (PyObject_CallObject (m_pFn.get (), pArgs.get ()));
if (!pRval)
{
#if(PRINT_BOOKENDS == 1)
PyObject* p_Error = PyErr_Occurred();
if(p_Error){
PyErr_Print();
}
#endif
rval = EXIT_FAILURE;
}
else
{
if (Py_None == pRval.get ())
{
SCX_BOOKEND_PRINT ("an object was returned (Py_None)");
}
else
{
SCX_BOOKEND_PRINT ("an object was returned (not Py_None)");
}
}
}
}
else
{
PyErr_SetString (PyExc_TypeError, "invalid argument");
rval = EXIT_FAILURE;
}
return rval;
}
} // namespace scx