if ( strlen( PyFuncName ) ) {
Automaton()->PyLock() ;
-
thePyRunMethod = Automaton()->PyFunction( PyFuncName ) ;
-
- //thePyRunMethod = NULL;
- // asv 28.02.05 : VERY BAD fix of the following problem: after change of a function,
- // the changes are NOT taken into account by Automation - it returns PyObject of the OLD function.
- // so here we force re-automating the PyObject EVERY TIME, regardless if the function has changed or not.
- // Once again - it is a very bad solution, it fully discards the whole idea of automation,
- // here is it done as a quick fix for a bug.
- // A better solution (to be implemented): store the PyObject NOT in Automation map, but in
- // InLine node itself! And if the method is changed - remove the PyObject and force to regenerate it.
- // But this means that PyObject must be stored in Editor's data model.
- // asv 01.03.05 : the fix is not needed, the described bug is not reproduced. To investigate:
- // WHERE PyObject is removed from Automation map on function change.
-
if ( (*aPythonFunction).length() ) {
if ( thePyRunMethod == NULL ) {
unsigned int i ;
return Result ;
}
+#define PyDynInvokeTrace 0
bool GraphExecutor::InNode::PyDynInvoke( PyObject * MyPyRunMethod ,
const char *method ,
ServicesAnyData * inParams , int nInParams ,
int n_out = nOutParams ;
const char * sname;
+#if PyDynInvokeTrace
cdebug_in << ThreadNo() << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " method " << method
<< " " << n_in << " InArgs " << n_out << " OutArgs MyPyRunMethod " ;
+#endif
if ( MyPyRunMethod ) {
+#if PyDynInvokeTrace
cdebug << MyPyRunMethod << " " << MyPyRunMethod->ob_refcnt << endl ;
+#endif
}
else {
+#if PyDynInvokeTrace
cdebug << " NULL" << endl ;
+#endif
return false ;
}
case CORBA::tk_string : {
char * t ;
data >>= t ;
- ArgValue = Py_BuildValue( "s" , t ) ;
+ PyObject * ArgValue = Py_BuildValue( "s" , t ) ;
PyTuple_SetItem( ArgsList , i , ArgValue ) ;
+#if PyDynInvokeTrace
cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << t << " (string) "
<< " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
<< ArgValue->ob_refcnt << endl ;
+#endif
break ;
}
case CORBA::tk_boolean : {
bool b ;
data >>= (CORBA::Any::to_boolean ) b ;
- ArgValue = Py_BuildValue( "b" , b ) ;
+ PyObject * ArgValue = Py_BuildValue( "b" , b ) ;
PyTuple_SetItem( ArgsList , i , ArgValue ) ;
+#if PyDynInvokeTrace
cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << b
<< " (boolean) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
<< ArgValue->ob_refcnt << endl ;
+#endif
break ;
}
case CORBA::tk_char : {
unsigned char c ;
data >>= (CORBA::Any::to_char ) c ;
- ArgValue = Py_BuildValue( "c" , c ) ;
+ PyObject * ArgValue = Py_BuildValue( "c" , c ) ;
PyTuple_SetItem( ArgsList , i , ArgValue ) ;
+#if PyDynInvokeTrace
cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << c
<< " (char) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
<< ArgValue->ob_refcnt << endl ;
+#endif
break ;
}
case CORBA::tk_short : {
short s ;
data >>= s ;
- ArgValue = Py_BuildValue( "h" , s ) ;
+ PyObject * ArgValue = Py_BuildValue( "h" , s ) ;
PyTuple_SetItem( ArgsList , i , ArgValue ) ;
+#if PyDynInvokeTrace
cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << s
<< " (short) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
<< ArgValue->ob_refcnt << endl ;
+#endif
break ;
}
case CORBA::tk_long : {
long l ;
data >>= l ;
- ArgValue = Py_BuildValue( "l" , l ) ;
+ PyObject * ArgValue = Py_BuildValue( "l" , l ) ;
+#if PyDynInvokeTrace
+ cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << l
+ << " ArgValue->ob_refcnt" << ArgValue->ob_refcnt << endl ;
+#endif
PyTuple_SetItem( ArgsList , i , ArgValue ) ;
+#if PyDynInvokeTrace
cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << l
<< " (long) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
<< ArgValue->ob_refcnt << endl ;
+#endif
break ;
}
case CORBA::tk_float : {
float f ;
data >>= f ;
- ArgValue = Py_BuildValue( "f" , f ) ;
+ PyObject * ArgValue = Py_BuildValue( "f" , f ) ;
PyTuple_SetItem( ArgsList , i , ArgValue ) ;
+#if PyDynInvokeTrace
cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << f
<< " (float) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
<< ArgValue->ob_refcnt << endl ;
+#endif
break ;
}
case CORBA::tk_double : {
double d ;
data >>= d ;
- ArgValue = Py_BuildValue( "d" , d ) ;
+ PyObject * ArgValue = Py_BuildValue( "d" , d ) ;
PyTuple_SetItem( ArgsList , i , ArgValue ) ;
+#if PyDynInvokeTrace
cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value " << d
<< " (double) ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
<< ArgValue->ob_refcnt << endl ;
+#endif
break ;
}
case CORBA::tk_objref : {
IORObjRef = ObjectToString( ObjRef ) ;
ObjValue = Py_BuildValue( "s" , IORObjRef ) ;
PyTuple_SetItem( MyPyObjRefList , 0 , ObjValue ) ;
+#if PyDynInvokeTrace
cdebug << "ArgIn" << i << " : " << sname << " " << method << " " << " Value " << IORObjRef << " (objref) "
<< MyPyObjRef->ob_refcnt << "/" << MyPyObjRefList->ob_refcnt << endl ;
+#endif
// ResultObj = PyEval_CallObject( MyPyObjRef , MyPyObjRefList ) ;
- ResultObj = PyEvalCallObject( MyPyObjRef , MyPyObjRefList ) ;
+ ResultObj = PyEvalCallObject( "PyObjRef" , MyPyObjRef , MyPyObjRefList ) ;
+#if PyDynInvokeTrace
cdebug << "ObjValue->ob_refcnt" << ObjValue->ob_refcnt << endl ;
+#endif
ArgValue = Py_BuildValue( "O" , ResultObj ) ;
PyTuple_SetItem( ArgsList , i , ArgValue ) ;
+#if PyDynInvokeTrace
cdebug << "ArgIn" << i << " : " << sname << " " << method << " Value (objref) ArgsList->ob_refcnt"
<< ArgsList->ob_refcnt << " ArgValue->ob_refcnt" << ArgValue->ob_refcnt << endl ;
cdebug << "MyPyObjRefList->ob_refcnt " << MyPyObjRefList->ob_refcnt-1 << endl ;
+#endif
Py_DECREF( MyPyObjRefList ) ;
if ( CORBA::is_nil( ObjRef ) ) {
ResultObj = NULL ;
}
else {
+#if PyDynInvokeTrace
cdebug << "ResultObj->ob_refcnt " << ResultObj->ob_refcnt-1 << endl ;
+#endif
Py_DECREF( ResultObj ) ;
}
break ;
}
// Result = PyEval_CallObject( MyPyRunMethod , ArgsList ) ;
- Result = PyEvalCallObject( MyPyRunMethod , ArgsList ) ;
+ Result = PyEvalCallObject( method , MyPyRunMethod , ArgsList ) ;
+#if PyDynInvokeTrace
cdebug << "ArgsList->ob_refcnt" << ArgsList->ob_refcnt << endl ;
+#endif
if ( Result == NULL ) {
cdebug_out << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " " << method << " Error Result == NULL"
switch ( data.type()->kind() ) {
case CORBA::tk_string : {
char * t = "" ;
+ PyObject * ArgValue ;
if ( PyTuple_Check( Result ) ) {
ArgValue = PyTuple_GetItem( Result , i ) ;
}
}
if ( !PyString_Check( ArgValue ) ) {
cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (string)" << endl ;
+ RetVal = false ;
}
else {
t = PyString_AsString( ArgValue ) ;
}
data <<= t ;
+#if PyDynInvokeTrace
cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << t << " (string)"
- << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
<< ArgValue->ob_refcnt << endl ;
+#endif
break ;
}
case CORBA::tk_boolean : {
bool b = false ;
+ PyObject * ArgValue ;
if ( PyTuple_Check( Result ) ) {
ArgValue = PyTuple_GetItem( Result , i ) ;
}
}
if ( !PyInt_Check( ArgValue ) ) {
cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (boolean)" << endl ;
+ RetVal = false ;
}
else {
b = PyInt_AsLong( ArgValue ) ;
}
data <<= (CORBA::Any::from_boolean ) b ;
+#if PyDynInvokeTrace
cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << b << " (boolean)"
- << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
<< ArgValue->ob_refcnt << endl ;
+#endif
break ;
}
case CORBA::tk_char : {
unsigned char c = 0 ;
+ PyObject * ArgValue ;
if ( PyTuple_Check( Result ) ) {
ArgValue = PyTuple_GetItem( Result , i ) ;
}
else {
ArgValue = Result ;
}
- if ( !PyInt_Check( ArgValue ) ) {
+//JR 04.04.2005 Debug if ( !PyInt_Check( ArgValue ) ) {
+//Difficult to understand that behavior ... Python char type is a string of length 1 !
+ if ( !PyString_Check( ArgValue ) ) {
cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (char)" << endl ;
+ RetVal = false ;
}
else {
c = PyInt_AsLong( ArgValue ) ;
}
data <<= (CORBA::Any::from_char ) c ;
+#if PyDynInvokeTrace
cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << c << " (char)"
- << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
<< ArgValue->ob_refcnt << endl ;
+#endif
break ;
}
case CORBA::tk_short : {
short s = 0 ;
+ PyObject * ArgValue ;
if ( PyTuple_Check( Result ) ) {
ArgValue = PyTuple_GetItem( Result , i ) ;
}
}
if ( !PyInt_Check( ArgValue ) ) {
cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (short)" << endl ;
+ RetVal = false ;
}
else {
s = PyInt_AsLong( ArgValue ) ;
}
data <<= s ;
+#if PyDynInvokeTrace
cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << s << " (short)"
- << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
<< ArgValue->ob_refcnt << endl ;
+#endif
break ;
}
case CORBA::tk_long : {
long l = 0 ;
+ PyObject * ArgValue ;
if ( PyTuple_Check( Result ) ) {
ArgValue = PyTuple_GetItem( Result , i ) ;
}
}
else {
cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (CORBA::tk_long)" << endl ;
+ RetVal = false ;
}
data <<= l ;
+#if PyDynInvokeTrace
cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << l << " (long)"
- << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
<< ArgValue->ob_refcnt << endl ;
+#endif
break ;
}
case CORBA::tk_float : {
float f = 0 ;
+ PyObject * ArgValue ;
if ( PyTuple_Check( Result ) ) {
ArgValue = PyTuple_GetItem( Result , i ) ;
}
}
if ( !PyFloat_Check( ArgValue ) ) {
cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (float)" << endl ;
+ RetVal = false ;
}
else {
f = PyFloat_AsDouble( ArgValue ) ;
}
data <<= f ;
+#if PyDynInvokeTrace
cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << f << " (float)"
- << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
<< ArgValue->ob_refcnt << endl ;
+#endif
break ;
}
case CORBA::tk_double : {
double d = 0 ;
+ PyObject * ArgValue ;
if ( PyTuple_Check( Result ) ) {
ArgValue = PyTuple_GetItem( Result , i ) ;
}
}
if ( !PyFloat_Check( ArgValue ) ) {
cdebug << "ArgOut" << i << " : " << sname << " " << method << " ERROR (double)" << endl ;
+ RetVal = false ;
}
else {
d = PyFloat_AsDouble( ArgValue ) ;
}
data <<= d ;
+#if PyDynInvokeTrace
cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << d << " (double)"
- << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ArgValue->ob_refcnt"
+ << " Result->ob_refcnt" << Result->ob_refcnt << " ArgValue->ob_refcnt"
<< ArgValue->ob_refcnt << endl ;
+#endif
break ;
}
case CORBA::tk_objref : {
else {
ObjIor = Result ;
}
+#if PyDynInvokeTrace
cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << "(object reference) "
- << " ArgsList->ob_refcnt" << ArgsList->ob_refcnt << " ObjIor->ob_refcnt"
+ << " Result->ob_refcnt" << Result->ob_refcnt << " ObjIor->ob_refcnt"
<< ObjIor->ob_refcnt << endl ;
+#endif
Py_INCREF( ObjIor ) ;
// PyObject_Print( ObjIor , stdout , 0 ) ;
PyTuple_SetItem( MyPyObjIorList , 0 , ObjIor ) ;
// ResultIor = PyEval_CallObject( MyPyObjIor , MyPyObjIorList ) ;
- ResultIor = PyEvalCallObject( MyPyObjIor , MyPyObjIorList ) ;
+ ResultIor = PyEvalCallObject( "PyObjIor" , MyPyObjIor , MyPyObjIorList ) ;
+#if PyDynInvokeTrace
cdebug << "ObjIor->ob_refcnt " << ObjIor->ob_refcnt-1 << endl ;
+#endif
Py_DECREF( ObjIor ) ;
+#if PyDynInvokeTrace
cdebug << "MyPyObjIorList->ob_refcnt " << MyPyObjIorList->ob_refcnt-1 << endl ;
+#endif
Py_DECREF( MyPyObjIorList ) ;
+#if PyDynInvokeTrace
cdebug << "MyPyObjIor->ob_refcnt " << MyPyObjIor->ob_refcnt << endl ;
+#endif
if ( ResultIor ) {
char * IOR = NULL ;
IOR = PyString_AsString( ResultIor ) ;
ObjRef = StringToObject( IOR ) ;
data <<= ObjRef ;
IORObjRef = ObjectToString( ObjRef ) ;
+#if PyDynInvokeTrace
cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << IORObjRef << " (objref) "
<< endl ;
+#endif
if ( CORBA::is_nil( ObjRef ) ) {
ResultIor = NULL ;
}
else {
+#if PyDynInvokeTrace
cdebug << "ResultIor->ob_refcnt " << ResultIor->ob_refcnt-1 << endl ;
+#endif
Py_DECREF( ResultIor ) ;
}
}
}
default : {
cdebug << "ArgOut" << i << " : " << sname << " " << method << " Value " << "(other ERROR)" << endl ;
+ RetVal = false ;
}
}
outParams[i].Value = data ;
}
- cdebug << "Result->ob_refcnt" << Result->ob_refcnt-1 << endl ;
+// int k ;
+// for ( k = 0 ; k < n_out ; k++ ) {
+// cdebug << "Result" << k << "->ob_refcnt " << PyTuple_GetItem( Result , k )->ob_refcnt << endl ;
+// Py_DECREF( PyTuple_GetItem( Result , k ) ) ;
+// }
+
+#if PyDynInvokeTrace
+ cdebug << "InNode::PyDynInvoke Result->ob_refcnt " << Result->ob_refcnt-1 << endl ;
+#endif
Py_DECREF( Result ) ;
}
- cdebug << "GraphExecutor::InNode::PyDynInvoke ArgsList->ob_refcnt"
- << ArgsList->ob_refcnt-1 << endl ;
+// int k ;
+// for ( k = 0 ; k < n_in ; k++ ) {
+// cdebug << "ArgsList" << k << "->ob_refcnt " << PyTuple_GetItem( ArgsList , k )->ob_refcnt << endl ;
+// Py_DECREF( PyTuple_GetItem( ArgsList , k ) ) ;
+// }
+
+#if PyDynInvokeTrace
+ cdebug << "InNode::PyDynInvoke ArgsList->ob_refcnt " << ArgsList->ob_refcnt-1 << endl ;
+#endif
Py_DECREF( ArgsList ) ;
}
+#if PyDynInvokeTrace
cdebug_out << "GraphExecutor::InNode::PyDynInvoke Node " << Name() << " method " << method << " " << RetVal
<< endl ;
+#endif
return RetVal ;
bool aRet;
try {
MESSAGE( pthread_self() << "Python method beginning : " << thePyString );
+#if PyDynInvokeTrace
cdebug_in << pthread_self() << "Python method beginning : " << thePyString << endl ;
+#endif
aRet = PyRun_SimpleString( thePyString );
// asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
//aRet = _OutNode->SuperVisionContainer()->ActivatePythonExecution( thePyString ) ;
MESSAGE( pthread_self() << "Python method finished." );
+#if PyDynInvokeTrace
cdebug_out << pthread_self() << "Python method finished." << endl ;
+#endif
} catch( ... ) {
MESSAGE( pthread_self() << "ERROR: Exception caught running Python method." );
cdebug_out << pthread_self() << "ERROR: Exception caught running Python method."
return aRet;
}
-PyObject * GraphExecutor::InNode::PyEvalCallObject( PyObject * MyPyRunMethod ,
+PyObject * GraphExecutor::InNode::PyEvalCallObject( const char *method ,
+ PyObject * MyPyRunMethod ,
PyObject * ArgsList ) {
- cdebug_in << "Executor::InNode::PyEvalCallObject " << Name() << endl ;
+// cdebug_in << "Executor::InNode::PyEvalCallObject " << Name() << endl ;
PyObject * Result = NULL ;
try {
- MESSAGE( pthread_self() << "PyEval_CallObject method beginning : " );
- cdebug << pthread_self() << "PyEval_CallObject method beginning : " << Name() << endl ;
+// MESSAGE( pthread_self() << "PyEval_CallObject " << Name() << " method beginning : " << method );
+// cdebug << pthread_self() << "PyEval_CallObject " << Name() << " method beginning : " << method << endl ;
Result = PyEval_CallObject( MyPyRunMethod , ArgsList ) ;
// asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
//Result = _OutNode->SuperVisionContainer()->ActivatePythonExecution( MyPyRunMethod , ArgsList ) ;
- MESSAGE( pthread_self() << "PyEval_CallObject method finished. Result " << Result );
- cdebug << pthread_self() << "PyEval_CallObject method finished. Result " << Result << endl ;
- cdebug_out << "Executor::InNode::PyEvalCallObject " << Name() << endl ;
+// MESSAGE( pthread_self() << "PyEval_CallObject method finished. Result " << Result );
+// cdebug << pthread_self() << "PyEval_CallObject method finished. Result " << Result << endl ;
+// cdebug_out << "Executor::InNode::PyEvalCallObject " << Name() << endl ;
} catch( ... ) {
- MESSAGE( pthread_self() << "ERROR: Exception caught PyEval_CallObject Python method. Result " << Result );
- cdebug << pthread_self() << "ERROR: Exception caught PyEval_CallObject Python method. Result "
- << Result << endl ;
+ MESSAGE( pthread_self() << "ERROR: Exception caught PyEval_CallObject " << Name()
+ << " Python method " << method << ". Result " << Result );
+ cdebug << pthread_self() << "ERROR: Exception caught PyEval_CallObject " << Name()
+ << " Python method " << method << ". Result " << Result << endl ;
MESSAGE( " Python was reinitialized. Previous Python definitions are lost Py_IsInitialized " << Py_IsInitialized() );
//JR ===> fatal error in python : no current thread
// asv : 20.01.05 : changes involved with switching to old (HEAD) KERNEL
if ( Result == NULL ) {
Kill() ; // Reset of _ThreadId
}
- cdebug_out << "Executor::InNode::PyEvalCallObject ERROR catched " << Name()
- << " Py_IsInitialized " << Py_IsInitialized() << endl ;
+// cdebug << "Executor::InNode::PyEvalCallObject ERROR catched " << Name()
+// << " Py_IsInitialized " << Py_IsInitialized() << endl ;
}
+// cdebug_out << "Executor::InNode::PyEvalCallObject " << Name() << endl ;
return Result ;
}