Skip to content

Commit

Permalink
fix to handle 'None' passed as a parameter from python.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Carroll committed Oct 30, 2013
1 parent 7bd25c0 commit 48dc153
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
8 changes: 4 additions & 4 deletions xbmc/interfaces/python/swig.cpp
Expand Up @@ -197,23 +197,23 @@ namespace PythonBindings
SetMessage("%s",msg.c_str());
}

XBMCAddon::AddonClass* doretrieveApiInstance(const PyHolder* pythonType, const TypeInfo* typeInfo, const char* expectedType,
XBMCAddon::AddonClass* doretrieveApiInstance(const PyHolder* pythonObj, const TypeInfo* typeInfo, const char* expectedType,
const char* methodNamespacePrefix, const char* methodNameForErrorString) throw (XBMCAddon::WrongTypeException)
{
if (pythonType == NULL || pythonType->magicNumber != XBMC_PYTHON_TYPE_MAGIC_NUMBER)
if (pythonObj->magicNumber != XBMC_PYTHON_TYPE_MAGIC_NUMBER)
throw XBMCAddon::WrongTypeException("Non api type passed to \"%s\" in place of the expected type \"%s.\"",
methodNameForErrorString, expectedType);
if (!isParameterRightType(typeInfo->swigType,expectedType,methodNamespacePrefix))
{
// maybe it's a child class
if (typeInfo->parentType)
return doretrieveApiInstance(pythonType, typeInfo->parentType,expectedType,
return doretrieveApiInstance(pythonObj, typeInfo->parentType,expectedType,
methodNamespacePrefix, methodNameForErrorString);
else
throw XBMCAddon::WrongTypeException("Incorrect type passed to \"%s\", was expecting a \"%s\" but received a \"%s\"",
methodNameForErrorString,expectedType,typeInfo->swigType);
}
return ((PyHolder*)pythonType)->pSelf;
return ((PyHolder*)pythonObj)->pSelf;
}

/**
Expand Down
19 changes: 11 additions & 8 deletions xbmc/interfaces/python/swig.h
Expand Up @@ -64,33 +64,36 @@ namespace PythonBindings
*
* Since the calls to this are generated there's no NULL pointer checks
*/
inline XBMCAddon::AddonClass* retrieveApiInstance(PyObject* pythonType, const TypeInfo* typeToCheck,
inline XBMCAddon::AddonClass* retrieveApiInstance(PyObject* pythonObj, const TypeInfo* typeToCheck,
const char* methodNameForErrorString,
const char* typenameForErrorString) throw (XBMCAddon::WrongTypeException)
{
if (pythonType == NULL || ((PyHolder*)pythonType)->magicNumber != XBMC_PYTHON_TYPE_MAGIC_NUMBER)
if (pythonObj == NULL || pythonObj == Py_None)
return NULL;
if (!PyObject_TypeCheck(pythonType, (PyTypeObject*)(&(typeToCheck->pythonType))))
if (((PyHolder*)pythonObj)->magicNumber != XBMC_PYTHON_TYPE_MAGIC_NUMBER || !PyObject_TypeCheck(pythonObj, (PyTypeObject*)(&(typeToCheck->pythonType))))
throw XBMCAddon::WrongTypeException("Incorrect type passed to \"%s\", was expecting a \"%s\".",methodNameForErrorString,typenameForErrorString);
return ((PyHolder*)pythonType)->pSelf;
return ((PyHolder*)pythonObj)->pSelf;
}

bool isParameterRightType(const char* passedType, const char* expectedType, const char* methodNamespacePrefix, bool tryReverse = true);

XBMCAddon::AddonClass* doretrieveApiInstance(const PyHolder* pythonType, const TypeInfo* typeInfo, const char* expectedType,
XBMCAddon::AddonClass* doretrieveApiInstance(const PyHolder* pythonObj, const TypeInfo* typeInfo, const char* expectedType,
const char* methodNamespacePrefix, const char* methodNameForErrorString) throw (XBMCAddon::WrongTypeException);

/**
* This method retrieves the pointer from the PyHolder. The return value should
* be cast to the appropriate type.
*
* Since the calls to this are generated there's no NULL pointer checks
*
* This method will return NULL if either the pythonObj is NULL or the
* pythonObj is Py_None.
*/
inline XBMCAddon::AddonClass* retrieveApiInstance(const PyObject* pythonType, const char* expectedType, const char* methodNamespacePrefix,
inline XBMCAddon::AddonClass* retrieveApiInstance(const PyObject* pythonObj, const char* expectedType, const char* methodNamespacePrefix,
const char* methodNameForErrorString) throw (XBMCAddon::WrongTypeException)
{
return (pythonType == NULL) ? NULL :
doretrieveApiInstance(((PyHolder*)pythonType),((PyHolder*)pythonType)->typeInfo, expectedType, methodNamespacePrefix, methodNameForErrorString);
return (pythonObj == NULL || pythonObj == Py_None) ? NULL :
doretrieveApiInstance(((PyHolder*)pythonObj),((PyHolder*)pythonObj)->typeInfo, expectedType, methodNamespacePrefix, methodNameForErrorString);
}

/**
Expand Down

0 comments on commit 48dc153

Please sign in to comment.