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.
This commit is contained in:
rdb 2018-11-06 18:08:48 +01:00
parent 82459fa21b
commit f43bd1a409
3 changed files with 14 additions and 12 deletions

View File

@ -96,11 +96,7 @@ PUBLISHED:
#ifdef HAVE_PYTHON #ifdef HAVE_PYTHON
// These versions are exposed to Python, which have additional logic to map // These versions are exposed to Python, which have additional logic to map
// from Python interned strings. // from Python interned strings.
#if PY_MAJOR_VERSION >= 3 EXTENSION(static PT(InternalName) make(PyObject *str));
EXTENSION(static PT(InternalName) make(PyUnicodeObject *str));
#else
EXTENSION(static PT(InternalName) make(PyStringObject *str));
#endif
#endif #endif
public: public:

View File

@ -24,7 +24,12 @@ using std::string;
*/ */
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
PT(InternalName) Extension<InternalName>:: PT(InternalName) Extension<InternalName>::
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)) { if (!PyUnicode_CHECK_INTERNED(str)) {
// Not an interned string; don't bother. // Not an interned string; don't bother.
Py_ssize_t len = 0; Py_ssize_t len = 0;
@ -50,7 +55,12 @@ make(PyUnicodeObject *str) {
#else #else
PT(InternalName) Extension<InternalName>:: PT(InternalName) Extension<InternalName>::
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)) { if (!PyString_CHECK_INTERNED(str)) {
// Not an interned string; don't bother. // Not an interned string; don't bother.
string name(PyString_AS_STRING(str), PyString_GET_SIZE(str)); string name(PyString_AS_STRING(str), PyString_GET_SIZE(str));

View File

@ -29,11 +29,7 @@
template<> template<>
class Extension<InternalName> : public ExtensionBase<InternalName> { class Extension<InternalName> : public ExtensionBase<InternalName> {
public: public:
#if PY_MAJOR_VERSION >= 3 static PT(InternalName) make(PyObject *str);
static PT(InternalName) make(PyUnicodeObject *str);
#else
static PT(InternalName) make(PyStringObject *str);
#endif
}; };
#endif // HAVE_PYTHON #endif // HAVE_PYTHON