intern the string "__new__" so we can call PyObject_GetAttr() rather
than PyObject_GetAttrString(). (Though it's a mystery why slot_tp_new
is being called when a class doesn't define __new__. I'll look into
that tomorrow.)
2.2 backport candidate (but I won't do it).
static PyObject *
slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- PyObject *func = PyObject_GetAttrString((PyObject *)type, "__new__");
+ static PyObject *new_str;
+ PyObject *func;
PyObject *newargs, *x;
int i, n;
+ if (new_str == NULL) {
+ new_str = PyString_InternFromString("__new__");
+ if (new_str == NULL)
+ return NULL;
+ }
+ func = PyObject_GetAttr((PyObject *)type, new_str);
if (func == NULL)
return NULL;
assert(PyTuple_Check(args));