From f43bd1a40962b07b543b0fc9835435b71c7743fa Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 6 Nov 2018 18:08:48 +0100 Subject: [PATCH] gobj: remove use of PY_MAJOR_VERSION in internalName.h We should not use this symbol in the interrogated headers as it means we cannot reuse the output of interrogate with different versions of Python. --- panda/src/gobj/internalName.h | 6 +----- panda/src/gobj/internalName_ext.cxx | 14 ++++++++++++-- panda/src/gobj/internalName_ext.h | 6 +----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/panda/src/gobj/internalName.h b/panda/src/gobj/internalName.h index 729ec15ab8..5e61e81916 100644 --- a/panda/src/gobj/internalName.h +++ b/panda/src/gobj/internalName.h @@ -96,11 +96,7 @@ PUBLISHED: #ifdef HAVE_PYTHON // These versions are exposed to Python, which have additional logic to map // from Python interned strings. -#if PY_MAJOR_VERSION >= 3 - EXTENSION(static PT(InternalName) make(PyUnicodeObject *str)); -#else - EXTENSION(static PT(InternalName) make(PyStringObject *str)); -#endif + EXTENSION(static PT(InternalName) make(PyObject *str)); #endif public: diff --git a/panda/src/gobj/internalName_ext.cxx b/panda/src/gobj/internalName_ext.cxx index f1cdf0a725..4821880677 100644 --- a/panda/src/gobj/internalName_ext.cxx +++ b/panda/src/gobj/internalName_ext.cxx @@ -24,7 +24,12 @@ using std::string; */ #if PY_MAJOR_VERSION >= 3 PT(InternalName) Extension:: -make(PyUnicodeObject *str) { +make(PyObject *str) { + if (!PyUnicode_Check(str)) { + Dtool_Raise_ArgTypeError(str, 0, "InternalName.make", "str"); + return nullptr; + } + if (!PyUnicode_CHECK_INTERNED(str)) { // Not an interned string; don't bother. Py_ssize_t len = 0; @@ -50,7 +55,12 @@ make(PyUnicodeObject *str) { #else PT(InternalName) Extension:: -make(PyStringObject *str) { +make(PyObject *str) { + if (!PyString_Check(str)) { + Dtool_Raise_ArgTypeError(str, 0, "InternalName.make", "str"); + return nullptr; + } + if (!PyString_CHECK_INTERNED(str)) { // Not an interned string; don't bother. string name(PyString_AS_STRING(str), PyString_GET_SIZE(str)); diff --git a/panda/src/gobj/internalName_ext.h b/panda/src/gobj/internalName_ext.h index 20016abd60..8637eae16e 100644 --- a/panda/src/gobj/internalName_ext.h +++ b/panda/src/gobj/internalName_ext.h @@ -29,11 +29,7 @@ template<> class Extension : public ExtensionBase { public: -#if PY_MAJOR_VERSION >= 3 - static PT(InternalName) make(PyUnicodeObject *str); -#else - static PT(InternalName) make(PyStringObject *str); -#endif + static PT(InternalName) make(PyObject *str); }; #endif // HAVE_PYTHON