22 #include "GaudiKernel/IInterface.h"
23 #include "GaudiKernel/INamedInterface.h"
24 #include "GaudiKernel/StatusCode.h"
28 #include "CPyCppyy/PyException.h"
34 #include "TClassRef.h"
53 unsigned long& minor )
59 const_cast<char*
>(
"interfaceID"),
60 const_cast<char*
>(
"") );
64 return StatusCode::FAILURE;
67 PyObject* pyId = PyObject_CallMethod( idObj,
68 const_cast<char*
>(
"id"),
69 const_cast<char*
>(
"") );
73 return StatusCode::FAILURE;
75 id = PyLong_AsUnsignedLong(pyId);
78 PyObject* pyMajor = PyObject_CallMethod( idObj,
79 const_cast<char*
>(
"majorVersion"),
80 const_cast<char*
>(
"") );
84 return StatusCode::FAILURE;
86 major = PyLong_AsUnsignedLong(pyMajor);
89 PyObject* pyMinor = PyObject_CallMethod( idObj,
90 const_cast<char*
>(
"minorVersion"),
91 const_cast<char*
>(
"") );
95 return StatusCode::FAILURE;
97 minor = PyLong_AsUnsignedLong(pyMinor);
101 return StatusCode::SUCCESS;
110 PyObject* py_repr = PyObject_Repr( o );
113 Py_DECREF( py_repr );
125 PyObject* py_str = PyObject_Str( o );
140 PyObject* pytype = 0, *pyvalue = 0, *pytrace = 0;
141 PyErr_Fetch (&pytype, &pyvalue, &pytrace);
143 Py_XINCREF (pyvalue);
144 Py_XINCREF (pytrace);
146 PyErr_Restore (pytype, pyvalue, pytrace);
152 PyObject*
f = PySys_GetObject (
const_cast<char*
>(
"stderr"));
153 #if PY_VERSION_HEX < 0x03000000
154 PyObject* fstr = PyString_FromString (
"flush");
156 PyObject* fstr = PyUnicode_FromString (
"flush");
158 PyObject*
x = PyObject_CallMethodObjArgs (
f, fstr, NULL);
169 const char* methodName,
173 char*
method =
const_cast<char*
>(methodName);
176 if ( 0 ==
self || 0 ==
method ) {
return StatusCode::FAILURE; }
182 r = PyObject_CallMethod(
self,
method,
const_cast<char*
>(
"O"),
arg );
184 r = PyObject_CallMethod(
self,
method,
const_cast<char*
>(
"") );
190 #if PY_VERSION_HEX < 0x03000000
191 if ( PyInt_Check(
r ) || PyLong_Check(
r) ) {
194 if ( PyLong_Check(
r ) ) {
204 if ( PyObject_HasAttrString (
r, (
char*)
"getCode") ) {
205 c = PyObject_CallMethod(
r,
206 const_cast<char*
>(
"getCode"),
207 const_cast<char*
>(
"") );
212 std::ostringstream
msg;
213 msg <<
"unexpected returned type from (python) function '"
217 PyErr_SetString (PyExc_TypeError,
msg.str().c_str());
227 if ( PyLong_Check (
c) ) {
234 std::ostringstream
msg;
235 msg <<
"unexpected returned type from (python) function '"
236 <<
method <<
"().getCode()' [got "
239 PyErr_SetString (PyExc_TypeError,
msg.str().c_str());
243 return StatusCode::FAILURE;
248 const InterfaceID& riid,
249 void** ppvInterface )
255 <<
"==============[ " <<
PyAthena::repr(
self) <<
" ]=============="
261 const_cast<char*
>(
"__class__") );
268 bases = PyObject_CallMethod(
type,
269 const_cast<char*
>(
"mro"),
270 const_cast<char*
>(
"") );
271 if ( !bases || !PySequence_Check( bases ) ) {
277 const int nBases = PySequence_Size( bases );
278 if ( -1 == nBases ) {
284 for (
int i = 0;
i < nBases; ++
i ) {
290 unsigned long id = 0;
291 unsigned long major = 0;
292 unsigned long minor = 0;
293 if ( !fetchInterfaceId(
base,
id, major, minor ).isSuccess() ) {
298 InterfaceID pyID(
id, major, minor );
299 if ( !pyID.versionMatch( riid ) ) {
305 pyname = PyObject_GetAttrString(
base,
306 const_cast<char*
>(
"__name__") );
314 const std::string cppName = ((MyObjProxy*)
self)->m_class->GetName();
316 std::cout <<
"::: would like to do: *ppvInterface = static_cast<"
317 << cppBaseName <<
"*>( "
318 << cppName <<
"|m_self );"
322 const RootType toType( cppBaseName );
323 void* objProxy = TPython::CPPInstance_AsVoidPtr(
self);
324 *ppvInterface = objProxy;
326 *ppvInterface = fromType.
Class()->DynamicCast (toType.
Class(), objProxy);
327 std::cout <<
"::: [" << cppName <<
"]: "
328 << ( (
bool)fromType ?
" OK" :
"ERR" )
331 <<
"::: [" << cppBaseName <<
"]: "
332 << ( (
bool)toType ?
" OK" :
"ERR" )
333 <<
" " << *ppvInterface
335 std::cout <<
"::: *ppvInterface: " << *ppvInterface << std::endl;
336 if ( *ppvInterface ) {
338 const_cast<char*
>(
"addRef"),
339 const_cast<char*
>(
"") );
340 if (
c && PyLong_Check(
c) ) {
341 sc = StatusCode::SUCCESS;
346 if (
sc.isSuccess() ) {
361 const char* component )
366 (
char*)
"ss",
evt, component);
380 const char* component,
384 PyObject* pySc = TPython::CPPInstance_FromVoidPtr((
void*)&
sc,
392 (
char*)
"ssO",
evt, component, pySc);