Skip to content

Commit f43bd1a

Browse files
committed
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.
1 parent 82459fa commit f43bd1a

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

panda/src/gobj/internalName.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,7 @@ class EXPCL_PANDA_GOBJ InternalName final : public TypedWritableReferenceCount {
9696
#ifdef HAVE_PYTHON
9797
// These versions are exposed to Python, which have additional logic to map
9898
// from Python interned strings.
99-
#if PY_MAJOR_VERSION >= 3
100-
EXTENSION(static PT(InternalName) make(PyUnicodeObject *str));
101-
#else
102-
EXTENSION(static PT(InternalName) make(PyStringObject *str));
103-
#endif
99+
EXTENSION(static PT(InternalName) make(PyObject *str));
104100
#endif
105101

106102
public:

panda/src/gobj/internalName_ext.cxx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ using std::string;
2424
*/
2525
#if PY_MAJOR_VERSION >= 3
2626
PT(InternalName) Extension<InternalName>::
27-
make(PyUnicodeObject *str) {
27+
make(PyObject *str) {
28+
if (!PyUnicode_Check(str)) {
29+
Dtool_Raise_ArgTypeError(str, 0, "InternalName.make", "str");
30+
return nullptr;
31+
}
32+
2833
if (!PyUnicode_CHECK_INTERNED(str)) {
2934
// Not an interned string; don't bother.
3035
Py_ssize_t len = 0;
@@ -50,7 +55,12 @@ make(PyUnicodeObject *str) {
5055

5156
#else
5257
PT(InternalName) Extension<InternalName>::
53-
make(PyStringObject *str) {
58+
make(PyObject *str) {
59+
if (!PyString_Check(str)) {
60+
Dtool_Raise_ArgTypeError(str, 0, "InternalName.make", "str");
61+
return nullptr;
62+
}
63+
5464
if (!PyString_CHECK_INTERNED(str)) {
5565
// Not an interned string; don't bother.
5666
string name(PyString_AS_STRING(str), PyString_GET_SIZE(str));

panda/src/gobj/internalName_ext.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@
2929
template<>
3030
class Extension<InternalName> : public ExtensionBase<InternalName> {
3131
public:
32-
#if PY_MAJOR_VERSION >= 3
33-
static PT(InternalName) make(PyUnicodeObject *str);
34-
#else
35-
static PT(InternalName) make(PyStringObject *str);
36-
#endif
32+
static PT(InternalName) make(PyObject *str);
3733
};
3834

3935
#endif // HAVE_PYTHON

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy