Update of /cvsroot/wpdev/wolfpack
In directory sc8-pr-cvs1:/tmp/cvs-serv30835
Modified Files:
basechar.cpp items.h pythonscript.cpp pythonscript.h
Log Message:
Fixed several missing Py_DECREF in the python script code.
also fixed issue with every item decaying.
Index: basechar.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/basechar.cpp,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** basechar.cpp 21 Aug 2003 01:02:40 -0000 1.33
--- basechar.cpp 26 Aug 2003 03:55:13 -0000 1.34
***************
*** 1159,1163 ****
}
! return (char*)0;
}
--- 1159,1163 ----
}
! return QString::null;
}
Index: items.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/items.h,v
retrieving revision 1.168
retrieving revision 1.169
diff -C2 -d -r1.168 -r1.169
*** items.h 23 Aug 2003 01:03:31 -0000 1.168
--- items.h 26 Aug 2003 03:55:13 -0000 1.169
***************
*** 213,217 ****
void setLodamage( SI16 nValue ) { lodamage_ = nValue; flagChanged(); changed( TOOLTIP );};
void setWipe( bool nValue ) { ( nValue ) ? priv_ &= 0x10 : priv_ |= 0xEF; flagChanged();};
! void setNoDecay( bool nValue ) { ( nValue ) ? priv_ &= 0x01 : priv_ |= 0xFE; flagChanged(); };
void setWeight( SI16 nValue );
void setHp( SI16 nValue ) { hp_ = nValue; flagChanged(); changed( TOOLTIP );};
--- 213,217 ----
void setLodamage( SI16 nValue ) { lodamage_ = nValue; flagChanged(); changed( TOOLTIP );};
void setWipe( bool nValue ) { ( nValue ) ? priv_ &= 0x10 : priv_ |= 0xEF; flagChanged();};
! void setNoDecay( bool nValue ) { ( nValue ) ? priv_ |= 0x01 : priv_ &= ~0x01; flagChanged(); };
void setWeight( SI16 nValue );
void setHp( SI16 nValue ) { hp_ = nValue; flagChanged(); changed( TOOLTIP );};
Index: pythonscript.cpp
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/pythonscript.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** pythonscript.cpp 6 Jul 2003 16:44:14 -0000 1.3
--- pythonscript.cpp 26 Aug 2003 03:55:13 -0000 1.4
***************
*** 87,105 ****
void cPythonScript::unload( void )
{
! if( codeModule == NULL )
return;
! if( PyObject_HasAttr( codeModule, PyString_FromString( "onUnload" ) ) )
! {
! PyObject* method = PyObject_GetAttr( codeModule, PyString_FromString( "onUnload" ) );
!
! if( ( method == NULL ) || ( !PyCallable_Check( method ) ) )
! return;
! PyObject_CallObject( method, NULL );
! PyReportError();
}
codeModule = 0;
}
--- 87,117 ----
void cPythonScript::unload( void )
{
! if( !codeModule )
return;
! PyObject* method = PyObject_GetAttrString( codeModule, "onUnload" );
! if( !method )
! {
! PyErr_Clear();
! Py_DECREF( codeModule );
! codeModule = 0;
! return;
}
+ if ( !PyCallable_Check( method ) )
+ {
+ Py_DECREF( method );
+ Py_DECREF( codeModule );
+ codeModule = 0;
+ }
+
+ PyObject* result = PyObject_CallObject( method, NULL );
+ PyReportError();
+ Py_XDECREF( result ); // void
+ Py_DECREF( method );
+ Py_DECREF( codeModule );
codeModule = 0;
+
}
***************
*** 113,117 ****
QString name = element->text();
! if( name == QString::null )
return false;
--- 125,129 ----
QString name = element->text();
! if( name.isNull() )
return false;
***************
*** 123,133 ****
return false;
! // Compile the codemodule
! char moduleNameStr[1024]; // Just to be sure
! strcpy( &moduleNameStr[ 0 ], moduleName.latin1() );
!
! codeModule = PyImport_ImportModule( moduleNameStr );
! if( codeModule == NULL )
{
clConsole.ProgressFail();
--- 135,141 ----
return false;
! codeModule = PyImport_ImportModule( const_cast<char*>(moduleName.latin1()) );
! if( !codeModule )
{
clConsole.ProgressFail();
***************
*** 142,157 ****
// Call the load Function
! if( PyObject_HasAttr( codeModule, PyString_FromString( "onLoad" ) ) )
! {
! PyObject* method = PyObject_GetAttr( codeModule, PyString_FromString( "onLoad" ) );
!
! if( ( method == NULL ) || ( !PyCallable_Check( method ) ) )
! return true;
! PyObject_CallObject( method, NULL );
! PyReportError();
}
!
! handleSpeech_ = PyObject_HasAttr( codeModule, PyString_FromString( "onSpeech" ) );
return true;
}
--- 150,167 ----
// Call the load Function
! PyObject* method = PyObject_GetAttrString( codeModule, "onLoad" );
! if ( method )
! {
! if ( PyCallable_Check( method ) )
! {
! PyObject* result = PyObject_CallObject( method, NULL );
! PyReportError();
! Py_XDECREF( result );
! }
! Py_DECREF( method );
}
!
! handleSpeech_ = PyObject_HasAttrString( codeModule, "onSpeech" );
return true;
}
***************
*** 161,168 ****
{
PyHasMethod( "onServerstart" )
!
! PyObject *tuple = PyTuple_New( 0 );
!
! PyEvalMethod( "onServerstart" )
}
--- 171,175 ----
{
PyHasMethod( "onServerstart" )
! return PyEvalMethod( "onServerstart", PyTuple_New( 0 ) );
}
***************
*** 176,180 ****
PyTuple_SetItem( tuple, 1, PyGetItemObject( Used ) );
! PyEvalMethod( "onUse" )
}
--- 183,187 ----
PyTuple_SetItem( tuple, 1, PyGetItemObject( Used ) );
! return PyEvalMethod( "onUse", tuple );
}
***************
*** 187,191 ****
PyTuple_SetItem( tuple, 1, PyGetCharObject( Viewer ) );
! PyEvalMethod( "onSingleClick" )
}
--- 194,198 ----
PyTuple_SetItem( tuple, 1, PyGetCharObject( Viewer ) );
! return PyEvalMethod( "onSingleClick", tuple );
}
***************
*** 198,202 ****
PyTuple_SetItem( tuple, 1, PyGetCharObject( Viewer ) );
! PyEvalMethod( "onSingleClick" )
}
--- 205,209 ----
PyTuple_SetItem( tuple, 1, PyGetCharObject( Viewer ) );
! return PyEvalMethod( "onSingleClick", tuple );
}
***************
*** 208,212 ****
PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
! PyEvalMethod( "onLogout" )
}
--- 215,219 ----
PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
! return PyEvalMethod( "onLogout", tuple );
}
***************
*** 218,222 ****
PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
! PyEvalMethod( "onLogin" )
}
--- 225,229 ----
PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
! return PyEvalMethod( "onLogin", tuple );
}
***************
*** 229,233 ****
PyTuple_SetItem( tuple, 1, PyGetItemObject( Obstacle ) );
! PyEvalMethod( "onCollideItem" )
}
--- 236,240 ----
PyTuple_SetItem( tuple, 1, PyGetItemObject( Obstacle ) );
! return PyEvalMethod( "onCollideItem", tuple );
}
***************
*** 240,244 ****
PyTuple_SetItem( tuple, 1, PyGetCharObject( Obstacle ) );
! PyEvalMethod( "onCollideChar" )
}
--- 247,251 ----
PyTuple_SetItem( tuple, 1, PyGetCharObject( Obstacle ) );
! return PyEvalMethod( "onCollideChar", tuple );
}
***************
*** 252,256 ****
PyTuple_SetItem( tuple, 2, PyInt_FromLong( Sequence ) );
! PyEvalMethod( "onWalk" )
}
--- 259,263 ----
PyTuple_SetItem( tuple, 2, PyInt_FromLong( Sequence ) );
! return PyEvalMethod( "onWalk", tuple );
}
***************
*** 268,272 ****
PyTuple_SetItem( tuple, 5, PyString_FromString( Lang.ascii() ) );
! PyEvalMethod( "onTalk" )
}
--- 275,279 ----
PyTuple_SetItem( tuple, 5, PyString_FromString( Lang.ascii() ) );
! return PyEvalMethod( "onTalk", tuple );
}
***************
*** 279,283 ****
PyTuple_SetItem( tuple, 1, ( War ? PyInt_FromLong( 1 ) : PyInt_FromLong( 0 ) ) );
! PyEvalMethod( "onWarModeToggle" )
}
--- 286,290 ----
PyTuple_SetItem( tuple, 1, ( War ? PyInt_FromLong( 1 ) : PyInt_FromLong( 0 ) ) );
! return PyEvalMethod( "onWarModeToggle", tuple );
}
***************
*** 289,293 ****
PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
! PyEvalMethod( "onHelp" )
}
--- 296,300 ----
PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
! return PyEvalMethod( "onHelp", tuple );
}
***************
*** 300,304 ****
PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
! PyEvalMethod( "onChat" )
}
--- 307,311 ----
PyTuple_SetItem( tuple, 0, PyGetCharObject( Character ) );
! return PyEvalMethod( "onChat", tuple );
}
***************
*** 312,316 ****
PyTuple_SetItem( tuple, 1, PyInt_FromLong( Skill ) );
! PyEvalMethod( "onSkillUse" )
}
--- 319,323 ----
PyTuple_SetItem( tuple, 1, PyInt_FromLong( Skill ) );
! return PyEvalMethod( "onSkillUse", tuple );
}
***************
*** 326,330 ****
PyTuple_SetItem( tuple, 4, PyInt_FromLong( success ) );
! PyEvalMethod( "onSkillGain" )
}
--- 333,337 ----
PyTuple_SetItem( tuple, 4, PyInt_FromLong( success ) );
! return PyEvalMethod( "onSkillGain", tuple );
}
***************
*** 338,342 ****
PyTuple_SetItem( tuple, 2, PyInt_FromLong( amount ) );
! PyEvalMethod( "onStatGain" )
}
--- 345,349 ----
PyTuple_SetItem( tuple, 2, PyInt_FromLong( amount ) );
! return PyEvalMethod( "onStatGain", tuple );
}
***************
*** 355,359 ****
PyTuple_SetItem( tuple, 2, PyInt_FromLong( id ) );
! PyEvalMethod( "onContextEntry" )
}
--- 362,366 ----
PyTuple_SetItem( tuple, 2, PyInt_FromLong( id ) );
! return PyEvalMethod( "onContextEntry", tuple );
}
***************
*** 370,374 ****
PyTuple_SetItem( tuple, 1, PyGetCharObject( (P_CHAR)pObject ) );
! PyEvalMethod( "onShowContextMenu" )
}
--- 377,381 ----
PyTuple_SetItem( tuple, 1, PyGetCharObject( (P_CHAR)pObject ) );
! return PyEvalMethod( "onShowContextMenu", tuple );
}
***************
*** 387,402 ****
PyTuple_SetItem( tuple, 2, PyGetTooltipObject( tooltip ) );
! PyEvalMethod( "onShowToolTip" )
}
unsigned int cPythonScript::onDamage( P_CHAR pChar, unsigned char type, unsigned int amount, cUObject *source )
{
! if( !codeModule || !PyObject_HasAttr( codeModule, PyString_FromString( "onDamage" ) ) )
return amount;
! PyObject *method = PyObject_GetAttr( codeModule, PyString_FromString( "onDamage" ) );
! if( !method || !PyCallable_Check( method ) )
return amount;
PyObject *args = PyTuple_New( 4 );
--- 394,415 ----
PyTuple_SetItem( tuple, 2, PyGetTooltipObject( tooltip ) );
! return PyEvalMethod( "onShowToolTip", tuple );
}
unsigned int cPythonScript::onDamage( P_CHAR pChar, unsigned char type, unsigned int amount, cUObject *source )
{
! if( !codeModule )
return amount;
! PyObject *method = PyObject_GetAttrString( codeModule, "onDamage" );
! if( !method )
! return amount;
!
! if ( !PyCallable_Check( method ) )
! {
! Py_DECREF( method );
return amount;
+ }
PyObject *args = PyTuple_New( 4 );
***************
*** 414,423 ****
PyObject *returnValue = PyObject_CallObject( method, args );
! PyReportError();
! if( !returnValue || !PyInt_Check( returnValue ) )
return amount;
! return PyInt_AsLong( returnValue );
}
--- 427,445 ----
PyObject *returnValue = PyObject_CallObject( method, args );
! PyReportError();
! Py_DECREF( args );
! Py_DECREF( method );
! if( !returnValue )
return amount;
+ if ( !PyInt_Check( returnValue ) )
+ {
+ Py_DECREF( returnValue );
+ return amount;
+ }
! amount = PyInt_AsLong( returnValue );
! Py_DECREF( returnValue );
! return amount;
}
***************
*** 430,434 ****
PyTuple_SetItem( tuple, 1, PyInt_FromLong( spell ) );
! PyEvalMethod( "onCastSpell" )
}
--- 452,456 ----
PyTuple_SetItem( tuple, 1, PyInt_FromLong( spell ) );
! return PyEvalMethod( "onCastSpell", tuple );
}
***************
*** 446,450 ****
PyTuple_SetItem( tuple, 1, PyString_FromString( definition.latin1() ) );
! PyEvalMethod( "onCreate" )
}
--- 468,472 ----
PyTuple_SetItem( tuple, 1, PyString_FromString( definition.latin1() ) );
! return PyEvalMethod( "onCreate", tuple );
}
***************
*** 469,473 ****
PyTuple_SetItem( tuple, 3, list );
! PyEvalMethod( "onSpeech" )
}
--- 491,495 ----
PyTuple_SetItem( tuple, 3, list );
! return PyEvalMethod( "onSpeech", tuple );
}
***************
*** 480,484 ****
PyTuple_SetItem( tuple, 1, PyGetItemObject( pItem ) );
! PyEvalMethod( "onDropOnChar" )
}
--- 502,506 ----
PyTuple_SetItem( tuple, 1, PyGetItemObject( pItem ) );
! return PyEvalMethod( "onDropOnChar", tuple );
}
***************
*** 491,495 ****
PyTuple_SetItem( tuple, 1, PyGetItemObject( pItem ) );
! PyEvalMethod( "onDropOnItem" )
}
--- 513,517 ----
PyTuple_SetItem( tuple, 1, PyGetItemObject( pItem ) );
! return PyEvalMethod( "onDropOnItem", tuple );
}
***************
*** 502,506 ****
PyTuple_SetItem( tuple, 1, PyGetCoordObject( pos ) );
! PyEvalMethod( "onDropOnGround" )
}
--- 524,528 ----
PyTuple_SetItem( tuple, 1, PyGetCoordObject( pos ) );
! return PyEvalMethod( "onDropOnGround", tuple );
}
***************
*** 513,517 ****
PyTuple_SetItem( tuple, 1, PyGetItemObject( pItem ) );
! PyEvalMethod( "onPickup" )
}
--- 535,539 ----
PyTuple_SetItem( tuple, 1, PyGetItemObject( pItem ) );
! return PyEvalMethod( "onPickup", tuple );
}
***************
*** 526,530 ****
PyTuple_SetItem( tuple, 2, PyString_FromString( args.latin1() ) );
! PyEvalMethod( "onCommand" )
}
--- 548,552 ----
PyTuple_SetItem( tuple, 2, PyString_FromString( args.latin1() ) );
! return PyEvalMethod( "onCommand", tuple );
}
***************
*** 538,542 ****
PyTuple_SetItem( tuple, 1, PyGetCharObject( pOrigin ) );
! PyEvalMethod( "onShowPaperdoll" )
}
--- 560,564 ----
PyTuple_SetItem( tuple, 1, PyGetCharObject( pOrigin ) );
! return PyEvalMethod( "onShowPaperdoll", tuple );
}
***************
*** 548,552 ****
PyObject *tuple = PyTuple_New( 1 );
PyTuple_SetItem( tuple, 0, PyGetCharObject( pChar ) );
! PyEvalMethod( "onDeath" )
}
--- 570,574 ----
PyObject *tuple = PyTuple_New( 1 );
PyTuple_SetItem( tuple, 0, PyGetCharObject( pChar ) );
! return PyEvalMethod( "onDeath", tuple );
}
***************
*** 559,571 ****
PyTuple_SetItem( tuple, 0, PyGetCharObject( pChar ) );
! PyEvalMethod( "onShowSkillGump" )
}
QString cPythonScript::onShowPaperdollName( P_CHAR pChar, P_CHAR pOrigin )
{
! if( codeModule == NULL )
! return (char*)0;
! if( !PyObject_HasAttr( codeModule, PyString_FromString( "onShowPaperdollName" ) ) )
! return (char*)0;
// Create our args for the python function
--- 581,602 ----
PyTuple_SetItem( tuple, 0, PyGetCharObject( pChar ) );
! return PyEvalMethod( "onShowSkillGump", tuple );
}
QString cPythonScript::onShowPaperdollName( P_CHAR pChar, P_CHAR pOrigin )
{
! if( !codeModule )
! return QString::null;
!
! PyObject* method = PyObject_GetAttrString( codeModule, "onShowPaperdollName" );
!
! if ( !method )
! return QString::null;
!
! if( !PyCallable_Check( method ) )
! {
! Py_DECREF( method );
! return QString::null;
! }
// Create our args for the python function
***************
*** 574,589 ****
PyTuple_SetItem( tuple, 1, PyGetCharObject( pOrigin ) );
- PyObject* method = PyObject_GetAttr( codeModule, PyString_FromString( "onShowPaperdollName" ) );
- if( ( method == NULL ) || ( !PyCallable_Check( method ) ) )
- return (char*)0;
-
PyObject *returnValue = PyObject_CallObject( method, tuple );
! PyReportError();
! if( returnValue == NULL )
! return (char*)0;
if( !PyString_Check( returnValue ) )
! return (char*)0;
! return PyString_AsString( returnValue );
}
--- 605,624 ----
PyTuple_SetItem( tuple, 1, PyGetCharObject( pOrigin ) );
PyObject *returnValue = PyObject_CallObject( method, tuple );
! PyReportError();
! Py_DECREF( tuple );
! Py_DECREF( method );
!
! if( !returnValue )
! return QString::null;
if( !PyString_Check( returnValue ) )
! {
! Py_DECREF( returnValue );
! return QString::null;
! }
! QString result = PyString_AsString( returnValue );
! Py_DECREF( returnValue );
! return result;
}
Index: pythonscript.h
===================================================================
RCS file: /cvsroot/wpdev/wolfpack/pythonscript.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** pythonscript.h 4 Aug 2003 07:28:17 -0000 1.3
--- pythonscript.h 26 Aug 2003 03:55:13 -0000 1.4
***************
*** 129,132 ****
--- 129,166 ----
// It shouldn't be that much.
bool onCastSpell( cPlayer *player, unsigned int spell );
+
+ // Method Calling Macro!
+ inline bool PyEvalMethod( char* a, PyObject* tuple )
+ {
+ PyObject* method = PyObject_GetAttrString( codeModule, a );
+ if ( !method )
+ {
+ Py_XDECREF( tuple );
+ return false;
+ }
+
+ PyObject *returnValue = PyObject_CallObject( method, tuple );
+
+ Py_XDECREF( tuple );
+ Py_DECREF( method );
+ if( PyErr_Occurred() )
+ {
+ PyErr_Print();
+ PyErr_Clear();
+ }
+
+ if( !returnValue )
+ return false;
+ int isTrue = PyObject_IsTrue( returnValue );
+ Py_DECREF( returnValue );
+ switch ( isTrue )
+ {
+ case -1:
+ case 0: return false;
+ case 1:
+ default: return true;
+ }
+ }
+
};
|