From 48dc153aadc4d04542147b97b60cc9fffb856064 Mon Sep 17 00:00:00 2001 From: Jim Carroll Date: Tue, 29 Oct 2013 21:00:41 -0400 Subject: [PATCH] fix to handle 'None' passed as a parameter from python. --- xbmc/interfaces/python/swig.cpp | 8 ++++---- xbmc/interfaces/python/swig.h | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/xbmc/interfaces/python/swig.cpp b/xbmc/interfaces/python/swig.cpp index 6a3e9c46a690e..f7499e695d1ad 100644 --- a/xbmc/interfaces/python/swig.cpp +++ b/xbmc/interfaces/python/swig.cpp @@ -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; } /** diff --git a/xbmc/interfaces/python/swig.h b/xbmc/interfaces/python/swig.h index f772942713392..e8bd15d267c0e 100644 --- a/xbmc/interfaces/python/swig.h +++ b/xbmc/interfaces/python/swig.h @@ -64,20 +64,20 @@ 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); /** @@ -85,12 +85,15 @@ namespace PythonBindings * 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); } /**