is an iterator, this returns itself. */
#define PyIter_Check(obj) \
- (PyType_HasFeature((obj)->ob_type, Py_TPFLAGS_HAVE_ITER) && \
- (obj)->ob_type->tp_iternext != NULL)
+ ((obj)->ob_type->tp_iternext != NULL)
PyAPI_FUNC(PyObject *) PyIter_Next(PyObject *);
/* Takes an iterator object and calls its tp_iternext slot,
typedef int (*traverseproc)(PyObject *, visitproc, void *);
typedef struct {
- /* For numbers without flag bit Py_TPFLAGS_CHECKTYPES set, all
- arguments are guaranteed to be of the object's type (modulo
- coercion hacks -- i.e. if the type's coercion function
- returns other types, then these are allowed as well). Numbers that
- have the Py_TPFLAGS_CHECKTYPES flag bit set should check *both*
+ /* Number implementations should check *both*
arguments for proper type and implement the necessary conversions
in the slot functions themselves. */
all extension writers who publically release their extensions (this will
be fewer than you might expect!)..
-Python 1.5.2 introduced the bf_getcharbuffer slot into PyBufferProcs.
+Most flags were removed as of Python 3.0 to make room for new flags. (Some
+flags are not for backwards compatibility but to indicate the presence of an
+optional feature; these flags remain of course.)
Type definitions should use Py_TPFLAGS_DEFAULT for their tp_flags value.
given type object has a specified feature.
*/
-/* PyBufferProcs contains bf_getcharbuffer */
-#define Py_TPFLAGS_HAVE_GETCHARBUFFER (1L<<0)
-
-/* PySequenceMethods contains sq_contains */
-#define Py_TPFLAGS_HAVE_SEQUENCE_IN (1L<<1)
-
-/* This is here for backwards compatibility. Extensions that use the old GC
- * API will still compile but the objects will not be tracked by the GC. */
-#define Py_TPFLAGS_GC 0 /* used to be (1L<<2) */
-
-/* PySequenceMethods and PyNumberMethods contain in-place operators */
-#define Py_TPFLAGS_HAVE_INPLACEOPS (1L<<3)
-
-/* PyNumberMethods do their own coercion */
-#define Py_TPFLAGS_CHECKTYPES (1L<<4)
-
-/* tp_richcompare is defined */
-#define Py_TPFLAGS_HAVE_RICHCOMPARE (1L<<5)
-
-/* Objects which are weakly referencable if their tp_weaklistoffset is >0 */
-#define Py_TPFLAGS_HAVE_WEAKREFS (1L<<6)
-
-/* tp_iter is defined */
-#define Py_TPFLAGS_HAVE_ITER (1L<<7)
-
-/* New members introduced by Python 2.2 exist */
-#define Py_TPFLAGS_HAVE_CLASS (1L<<8)
-
/* Set if the type object is dynamically allocated */
#define Py_TPFLAGS_HEAPTYPE (1L<<9)
#define Py_TPFLAGS_HAVE_STACKLESS_EXTENSION 0
#endif
-/* Objects support nb_index in PyNumberMethods */
-#define Py_TPFLAGS_HAVE_INDEX (1L<<17)
-
#define Py_TPFLAGS_DEFAULT ( \
- Py_TPFLAGS_HAVE_GETCHARBUFFER | \
- Py_TPFLAGS_HAVE_SEQUENCE_IN | \
- Py_TPFLAGS_HAVE_INPLACEOPS | \
- Py_TPFLAGS_HAVE_RICHCOMPARE | \
- Py_TPFLAGS_HAVE_WEAKREFS | \
- Py_TPFLAGS_HAVE_ITER | \
- Py_TPFLAGS_HAVE_CLASS | \
Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
- Py_TPFLAGS_HAVE_INDEX | \
0)
#define PyType_HasFeature(t,f) (((t)->tp_flags & (f)) != 0)
/* Test if a type supports weak references */
-#define PyType_SUPPORTS_WEAKREFS(t) \
- (PyType_HasFeature((t), Py_TPFLAGS_HAVE_WEAKREFS) \
- && ((t)->tp_weaklistoffset > 0))
+#define PyType_SUPPORTS_WEAKREFS(t) ((t)->tp_weaklistoffset > 0)
#define PyObject_GET_WEAKREFS_LISTPTR(o) \
((PyObject **) (((char *) (o)) + (o)->ob_type->tp_weaklistoffset))
signature = self._signature
if type(signature) == AEDescType:
self.target = signature
- elif type(signature) == InstanceType and hasattr(signature, '__aepack__'):
+ elif hasattr(signature, '__aepack__'):
self.target = signature.__aepack__()
elif type(signature) == StringType and len(signature) == 4:
self.target = AE.AECreateDesc(AppleEvents.typeApplSignature, signature)
]
# These need to return something other than None
-# "coerce",
# "hash",
# "str",
# "repr",
# "delattr",
class AllTests:
- def __coerce__(self, *args):
- print "__coerce__:", args
- return (self,) + args
-
def __hash__(self, *args):
print "__hash__:", args
return hash(id(self))
#
dict, objects = self.make_weak_valued_dict()
for o in objects:
- self.assert_(weakref.getweakrefcount(o) == 1,
- "wrong number of weak references to %r!" % o)
+ self.assertEqual(weakref.getweakrefcount(o), 1)
self.assert_(o is dict[o.arg],
"wrong object returned by weak dict!")
items1 = dict.items()
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
if (!PyType_Check(obj))
return NULL;
type = (PyTypeObject *)obj;
- if (!PyType_HasFeature(type, Py_TPFLAGS_HAVE_CLASS))
- return NULL;
if (!type->tp_dict || !StgDict_Check(type->tp_dict))
return NULL;
return (StgDictObject *)type->tp_dict;
PyObject_GenericSetAttr, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
+ Py_TPFLAGS_BASETYPE, /* tp_flags */
partial_doc, /* tp_doc */
(traverseproc)partial_traverse, /* tp_traverse */
0, /* tp_clear */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_ITER|Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
cursor_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
pattern_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
PyObject_GenericGetAttr, /* tp_getattro */
PyObject_GenericSetAttr, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_WEAKREFS,/* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
s__doc__, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
return s;
}
-#define HASINDEX(o) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_HAVE_INDEX)
-
static PyObject*
array_subscr(arrayobject* self, PyObject* item)
{
PyNumberMethods *nb = item->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(item) && nb->nb_index != NULL) {
+ if (nb != NULL && nb->nb_index != NULL) {
Py_ssize_t i = nb->nb_index(item);
if (i==-1 && PyErr_Occurred()) {
return NULL;
array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
{
PyNumberMethods *nb = item->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(item) && nb->nb_index != NULL) {
+ if (nb != NULL && nb->nb_index != NULL) {
Py_ssize_t i = nb->nb_index(item);
if (i==-1 && PyErr_Occurred())
return -1;
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
&array_as_buffer, /* tp_as_buffer*/
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
arraytype_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_HAVE_GC, /* tp_flags */
deque_doc, /* tp_doc */
(traverseproc)deque_traverse, /* tp_traverse */
(inquiry)deque_clear, /* tp_clear */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
- Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_HAVE_GC, /* tp_flags */
defdict_doc, /* tp_doc */
defdict_traverse, /* tp_traverse */
(inquiry)defdict_tp_clear, /* tp_clear */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
delta_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
date_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
tzinfo_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
time_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
datetime_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /*tp_getattro*/
0, /*tp_setattro*/
&mmap_as_buffer, /*tp_as_buffer*/
- Py_TPFLAGS_HAVE_GETCHARBUFFER, /*tp_flags*/
+ Py_TPFLAGS_DEFAULT, /*tp_flags*/
0, /*tp_doc*/
};
-#define HASINDEX(o) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_HAVE_INDEX)
-
/* extract the map size from the given PyObject
Returns -1 on error, with an appropriate Python exception raised. On
_GetMapSize(PyObject *o)
{
PyNumberMethods *nb = o->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(o) && nb->nb_index != NULL) {
+ if (nb != NULL && nb->nb_index != NULL) {
Py_ssize_t i = nb->nb_index(o);
if (i==-1 && PyErr_Occurred())
return -1;
#include "structmember.h" /* we need the offsetof() macro from there */
#include "longintrepr.h"
-#define NEW_STYLE_NUMBER(o) PyType_HasFeature((o)->ob_type, \
- Py_TPFLAGS_CHECKTYPES)
-
-#define HASINDEX(o) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_HAVE_INDEX)
-
/* Shorthands to return certain errors */
if (o->ob_type->tp_as_sequence) {
PyNumberMethods *nb = key->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(key) && nb->nb_index != NULL) {
+ if (nb != NULL && nb->nb_index != NULL) {
Py_ssize_t key_value = nb->nb_index(key);
if (key_value == -1 && PyErr_Occurred())
return NULL;
if (o->ob_type->tp_as_sequence) {
PyNumberMethods *nb = key->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(key) && nb->nb_index != NULL) {
+ if (nb != NULL && nb->nb_index != NULL) {
Py_ssize_t key_value = nb->nb_index(key);
if (key_value == -1 && PyErr_Occurred())
return -1;
if (o->ob_type->tp_as_sequence) {
PyNumberMethods *nb = key->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(key) && nb->nb_index != NULL) {
+ if (nb != NULL && nb->nb_index != NULL) {
Py_ssize_t key_value = nb->nb_index(key);
if (key_value == -1 && PyErr_Occurred())
return -1;
binaryfunc slotv = NULL;
binaryfunc slotw = NULL;
- if (v->ob_type->tp_as_number != NULL && NEW_STYLE_NUMBER(v))
+ if (v->ob_type->tp_as_number != NULL)
slotv = NB_BINOP(v->ob_type->tp_as_number, op_slot);
if (w->ob_type != v->ob_type &&
- w->ob_type->tp_as_number != NULL && NEW_STYLE_NUMBER(w)) {
+ w->ob_type->tp_as_number != NULL) {
slotw = NB_BINOP(w->ob_type->tp_as_number, op_slot);
if (slotw == slotv)
slotw = NULL;
return x;
Py_DECREF(x); /* can't do it */
}
- if (!NEW_STYLE_NUMBER(v) || !NEW_STYLE_NUMBER(w)) {
- int err = PyNumber_CoerceEx(&v, &w);
- if (err < 0) {
- return NULL;
- }
- if (err == 0) {
- PyNumberMethods *mv = v->ob_type->tp_as_number;
- if (mv) {
- binaryfunc slot;
- slot = NB_BINOP(mv, op_slot);
- if (slot) {
- x = slot(v, w);
- Py_DECREF(v);
- Py_DECREF(w);
- return x;
- }
- }
- /* CoerceEx incremented the reference counts */
- Py_DECREF(v);
- Py_DECREF(w);
- }
- }
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
mv = v->ob_type->tp_as_number;
mw = w->ob_type->tp_as_number;
- if (mv != NULL && NEW_STYLE_NUMBER(v))
+ if (mv != NULL)
slotv = NB_TERNOP(mv, op_slot);
if (w->ob_type != v->ob_type &&
- mw != NULL && NEW_STYLE_NUMBER(w)) {
+ mw != NULL) {
slotw = NB_TERNOP(mw, op_slot);
if (slotw == slotv)
slotw = NULL;
Py_DECREF(x); /* can't do it */
}
mz = z->ob_type->tp_as_number;
- if (mz != NULL && NEW_STYLE_NUMBER(z)) {
+ if (mz != NULL) {
slotz = NB_TERNOP(mz, op_slot);
if (slotz == slotv || slotz == slotw)
slotz = NULL;
}
}
- if (!NEW_STYLE_NUMBER(v) || !NEW_STYLE_NUMBER(w) ||
- (z != Py_None && !NEW_STYLE_NUMBER(z))) {
- /* we have an old style operand, coerce */
- PyObject *v1, *z1, *w2, *z2;
- int c;
-
- c = PyNumber_Coerce(&v, &w);
- if (c != 0)
- goto error3;
-
- /* Special case: if the third argument is None, it is
- treated as absent argument and not coerced. */
- if (z == Py_None) {
- if (v->ob_type->tp_as_number) {
- slotz = NB_TERNOP(v->ob_type->tp_as_number,
- op_slot);
- if (slotz)
- x = slotz(v, w, z);
- else
- c = -1;
- }
- else
- c = -1;
- goto error2;
- }
- v1 = v;
- z1 = z;
- c = PyNumber_Coerce(&v1, &z1);
- if (c != 0)
- goto error2;
- w2 = w;
- z2 = z1;
- c = PyNumber_Coerce(&w2, &z2);
- if (c != 0)
- goto error1;
-
- if (v1->ob_type->tp_as_number != NULL) {
- slotv = NB_TERNOP(v1->ob_type->tp_as_number,
- op_slot);
- if (slotv)
- x = slotv(v1, w2, z2);
- else
- c = -1;
- }
- else
- c = -1;
-
- Py_DECREF(w2);
- Py_DECREF(z2);
- error1:
- Py_DECREF(v1);
- Py_DECREF(z1);
- error2:
- Py_DECREF(v);
- Py_DECREF(w);
- error3:
- if (c >= 0)
- return x;
- }
-
if (z == Py_None)
PyErr_Format(
PyExc_TypeError,
{
Py_ssize_t count;
PyNumberMethods *nb = n->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(n) && nb->nb_index != NULL) {
+ if (nb != NULL && nb->nb_index != NULL) {
count = nb->nb_index(n);
if (count == -1 && PyErr_Occurred())
return NULL;
*/
-#define HASINPLACE(t) \
- PyType_HasFeature((t)->ob_type, Py_TPFLAGS_HAVE_INPLACEOPS)
-
static PyObject *
binary_iop1(PyObject *v, PyObject *w, const int iop_slot, const int op_slot)
{
PyNumberMethods *mv = v->ob_type->tp_as_number;
- if (mv != NULL && HASINPLACE(v)) {
+ if (mv != NULL) {
binaryfunc slot = NB_BINOP(mv, iop_slot);
if (slot) {
PyObject *x = (slot)(v, w);
Py_DECREF(result);
if (m != NULL) {
binaryfunc f = NULL;
- if (HASINPLACE(v))
- f = m->sq_inplace_concat;
+ f = m->sq_inplace_concat;
if (f == NULL)
f = m->sq_concat;
if (f != NULL)
PySequenceMethods *mw = w->ob_type->tp_as_sequence;
Py_DECREF(result);
if (mv != NULL) {
- if (HASINPLACE(v))
- f = mv->sq_inplace_repeat;
+ f = mv->sq_inplace_repeat;
if (f == NULL)
f = mv->sq_repeat;
if (f != NULL)
PyObject *
PyNumber_InPlacePower(PyObject *v, PyObject *w, PyObject *z)
{
- if (HASINPLACE(v) && v->ob_type->tp_as_number &&
+ if (v->ob_type->tp_as_number &&
v->ob_type->tp_as_number->nb_inplace_power != NULL) {
return ternary_op(v, w, z, NB_SLOT(nb_inplace_power), "**=");
}
{
Py_ssize_t value = -1;
PyNumberMethods *nb = item->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(item) && nb->nb_index != NULL) {
+ if (nb != NULL && nb->nb_index != NULL) {
value = nb->nb_index(item);
}
else {
return null_error();
m = s->ob_type->tp_as_sequence;
- if (m && HASINPLACE(s) && m->sq_inplace_concat)
+ if (m && m->sq_inplace_concat)
return m->sq_inplace_concat(s, o);
if (m && m->sq_concat)
return m->sq_concat(s, o);
return null_error();
m = o->ob_type->tp_as_sequence;
- if (m && HASINPLACE(o) && m->sq_inplace_repeat)
+ if (m && m->sq_inplace_repeat)
return m->sq_inplace_repeat(o, count);
if (m && m->sq_repeat)
return m->sq_repeat(o, count);
PySequence_Contains(PyObject *seq, PyObject *ob)
{
Py_ssize_t result;
- if (PyType_HasFeature(seq->ob_type, Py_TPFLAGS_HAVE_SEQUENCE_IN)) {
- PySequenceMethods *sqm = seq->ob_type->tp_as_sequence;
- if (sqm != NULL && sqm->sq_contains != NULL)
- return (*sqm->sq_contains)(seq, ob);
- }
+ PySequenceMethods *sqm = seq->ob_type->tp_as_sequence;
+ if (sqm != NULL && sqm->sq_contains != NULL)
+ return (*sqm->sq_contains)(seq, ob);
result = _PySequence_IterSearch(seq, ob, PY_ITERSEARCH_CONTAINS);
return Py_SAFE_DOWNCAST(result, Py_ssize_t, int);
}
{
PyTypeObject *t = o->ob_type;
getiterfunc f = NULL;
- if (PyType_HasFeature(t, Py_TPFLAGS_HAVE_ITER))
- f = t->tp_iter;
+ f = t->tp_iter;
if (f == NULL) {
if (PySequence_Check(o))
return PySeqIter_New(o);
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES, /* tp_flags */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
bool_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
if (!PyBytes_Check(obj)) {
PyErr_Format(PyExc_TypeError,
"can only join an iterable of bytes "
- "(item %d has type '%.100s')",
- i, obj->ob_type->tp_name);
+ "(item %ld has type '%.100s')",
+ /* XXX %ld isn't right on Win64 */
+ (long)i, obj->ob_type->tp_name);
goto error;
}
totalsize += PyBytes_GET_SIZE(obj);
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
&bytes_as_buffer, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES, /* tp_flags */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
/* bytes is 'final' or 'sealed' */
bytes_doc, /* tp_doc */
0, /* tp_traverse */
#include "Python.h"
#include "structmember.h"
-#define TP_DESCR_GET(t) \
- (PyType_HasFeature(t, Py_TPFLAGS_HAVE_CLASS) ? (t)->tp_descr_get : NULL)
+#define TP_DESCR_GET(t) ((t)->tp_descr_get)
/* Forward */
(getattrofunc)instance_getattr, /* tp_getattro */
(setattrofunc)instance_setattr, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES,/*tp_flags*/
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
instance_doc, /* tp_doc */
(traverseproc)instance_traverse, /* tp_traverse */
0, /* tp_clear */
PyTypeObject *tp = obj->ob_type;
PyObject *descr = NULL;
- if (PyType_HasFeature(tp, Py_TPFLAGS_HAVE_CLASS)) {
+ {
if (tp->tp_dict == NULL) {
if (PyType_Ready(tp) < 0)
return NULL;
instancemethod_getattro, /* tp_getattro */
PyObject_GenericSetAttr, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
instancemethod_doc, /* tp_doc */
(traverseproc)instancemethod_traverse, /* tp_traverse */
0, /* tp_clear */
return combined;
}
+/* This macro may return! */
+#define TO_COMPLEX(obj, c) \
+ if (PyComplex_Check(obj)) \
+ c = ((PyComplexObject *)(obj))->cval; \
+ else if (to_complex(&(obj), &(c)) < 0) \
+ return (obj)
+
+static int
+to_complex(PyObject **pobj, Py_complex *pc)
+{
+ PyObject *obj = *pobj;
+
+ pc->real = pc->imag = 0.0;
+ if (PyInt_Check(obj)) {
+ pc->real = PyInt_AS_LONG(obj);
+ return 0;
+ }
+ if (PyLong_Check(obj)) {
+ pc->real = PyLong_AsDouble(obj);
+ if (pc->real == -1.0 && PyErr_Occurred()) {
+ *pobj = NULL;
+ return -1;
+ }
+ return 0;
+ }
+ if (PyFloat_Check(obj)) {
+ pc->real = PyFloat_AsDouble(obj);
+ return 0;
+ }
+ Py_INCREF(Py_NotImplemented);
+ *pobj = Py_NotImplemented;
+ return -1;
+}
+
+
static PyObject *
-complex_add(PyComplexObject *v, PyComplexObject *w)
+complex_add(PyObject *v, PyObject *w)
{
Py_complex result;
+ Py_complex a, b;
+ TO_COMPLEX(v, a);
+ TO_COMPLEX(w, b);
PyFPE_START_PROTECT("complex_add", return 0)
- result = c_sum(v->cval,w->cval);
+ result = c_sum(a, b);
PyFPE_END_PROTECT(result)
return PyComplex_FromCComplex(result);
}
static PyObject *
-complex_sub(PyComplexObject *v, PyComplexObject *w)
+complex_sub(PyObject *v, PyObject *w)
{
Py_complex result;
+ Py_complex a, b;
+ TO_COMPLEX(v, a);
+ TO_COMPLEX(w, b);
PyFPE_START_PROTECT("complex_sub", return 0)
- result = c_diff(v->cval,w->cval);
+ result = c_diff(a, b);
PyFPE_END_PROTECT(result)
return PyComplex_FromCComplex(result);
}
static PyObject *
-complex_mul(PyComplexObject *v, PyComplexObject *w)
+complex_mul(PyObject *v, PyObject *w)
{
Py_complex result;
+ Py_complex a, b;
+ TO_COMPLEX(v, a);
+ TO_COMPLEX(w, b);
PyFPE_START_PROTECT("complex_mul", return 0)
- result = c_prod(v->cval,w->cval);
+ result = c_prod(a, b);
PyFPE_END_PROTECT(result)
return PyComplex_FromCComplex(result);
}
static PyObject *
-complex_div(PyComplexObject *v, PyComplexObject *w)
+complex_div(PyObject *v, PyObject *w)
{
Py_complex quot;
+ Py_complex a, b;
+ TO_COMPLEX(v, a);
+ TO_COMPLEX(w, b);
PyFPE_START_PROTECT("complex_div", return 0)
errno = 0;
- quot = c_quot(v->cval,w->cval);
+ quot = c_quot(a, b);
PyFPE_END_PROTECT(quot)
if (errno == EDOM) {
PyErr_SetString(PyExc_ZeroDivisionError, "complex division");
}
static PyObject *
-complex_remainder(PyComplexObject *v, PyComplexObject *w)
+complex_remainder(PyObject *v, PyObject *w)
{
Py_complex div, mod;
+ Py_complex a, b;
+ TO_COMPLEX(v, a);
+ TO_COMPLEX(w, b);
if (PyErr_Warn(PyExc_DeprecationWarning,
"complex divmod(), // and % are deprecated") < 0)
return NULL;
errno = 0;
- div = c_quot(v->cval,w->cval); /* The raw divisor value. */
+ div = c_quot(a, b); /* The raw divisor value. */
if (errno == EDOM) {
PyErr_SetString(PyExc_ZeroDivisionError, "complex remainder");
return NULL;
}
div.real = floor(div.real); /* Use the floor of the real part. */
div.imag = 0.0;
- mod = c_diff(v->cval, c_prod(w->cval, div));
+ mod = c_diff(a, c_prod(b, div));
return PyComplex_FromCComplex(mod);
}
static PyObject *
-complex_divmod(PyComplexObject *v, PyComplexObject *w)
+complex_divmod(PyObject *v, PyObject *w)
{
Py_complex div, mod;
PyObject *d, *m, *z;
+ Py_complex a, b;
+ TO_COMPLEX(v, a);
+ TO_COMPLEX(w, b);
if (PyErr_Warn(PyExc_DeprecationWarning,
"complex divmod(), // and % are deprecated") < 0)
return NULL;
errno = 0;
- div = c_quot(v->cval,w->cval); /* The raw divisor value. */
+ div = c_quot(a, b); /* The raw divisor value. */
if (errno == EDOM) {
PyErr_SetString(PyExc_ZeroDivisionError, "complex divmod()");
return NULL;
}
div.real = floor(div.real); /* Use the floor of the real part. */
div.imag = 0.0;
- mod = c_diff(v->cval, c_prod(w->cval, div));
+ mod = c_diff(a, c_prod(b, div));
d = PyComplex_FromCComplex(div);
m = PyComplex_FromCComplex(mod);
z = PyTuple_Pack(2, d, m);
}
static PyObject *
-complex_pow(PyComplexObject *v, PyObject *w, PyComplexObject *z)
+complex_pow(PyObject *v, PyObject *w, PyObject *z)
{
Py_complex p;
Py_complex exponent;
long int_exponent;
+ Py_complex a, b;
+ TO_COMPLEX(v, a);
+ TO_COMPLEX(w, b);
- if ((PyObject *)z!=Py_None) {
+ if (z != Py_None) {
PyErr_SetString(PyExc_ValueError, "complex modulo");
return NULL;
}
PyFPE_START_PROTECT("complex_pow", return 0)
errno = 0;
- exponent = ((PyComplexObject*)w)->cval;
+ exponent = b;
int_exponent = (long)exponent.real;
if (exponent.imag == 0. && exponent.real == int_exponent)
- p = c_powi(v->cval,int_exponent);
+ p = c_powi(a, int_exponent);
else
- p = c_pow(v->cval,exponent);
+ p = c_pow(a, exponent);
PyFPE_END_PROTECT(p)
Py_ADJUST_ERANGE2(p.real, p.imag);
}
static PyObject *
-complex_int_div(PyComplexObject *v, PyComplexObject *w)
+complex_int_div(PyObject *v, PyObject *w)
{
PyObject *t, *r;
/* softspace is writable: we must supply tp_setattro */
PyObject_GenericSetAttr, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
file_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
float_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
int_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT |
- Py_TPFLAGS_HAVE_RICHCOMPARE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
sortwrapper_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
"list() -> new list\n"
"list(sequence) -> new list initialized from sequence's items");
-#define HASINDEX(o) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_HAVE_INDEX)
-
static PyObject *
list_subscript(PyListObject* self, PyObject* item)
{
PyNumberMethods *nb = item->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(item) && nb->nb_index != NULL) {
+ if (nb != NULL && nb->nb_index != NULL) {
Py_ssize_t i = nb->nb_index(item);
if (i == -1 && PyErr_Occurred())
return NULL;
list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
{
PyNumberMethods *nb = item->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(item) && nb->nb_index != NULL) {
+ if (nb != NULL && nb->nb_index != NULL) {
Py_ssize_t i = nb->nb_index(item);
if (i == -1 && PyErr_Occurred())
return -1;
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
long_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
/* Macro to get the tp_richcompare field of a type if defined */
-#define RICHCOMPARE(t) (PyType_HasFeature((t), Py_TPFLAGS_HAVE_RICHCOMPARE) \
- ? (t)->tp_richcompare : NULL)
+#define RICHCOMPARE(t) ((t)->tp_richcompare)
/* Map rich comparison operators to their swapped version, e.g. LT --> GT */
int _Py_SwappedOp[] = {Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE};
Py_ssize_t dictoffset;
PyTypeObject *tp = obj->ob_type;
- if (!(tp->tp_flags & Py_TPFLAGS_HAVE_CLASS))
- return NULL;
dictoffset = tp->tp_dictoffset;
if (dictoffset == 0)
return NULL;
Py_XINCREF(descr);
f = NULL;
- if (descr != NULL &&
- PyType_HasFeature(descr->ob_type, Py_TPFLAGS_HAVE_CLASS)) {
+ if (descr != NULL) {
f = descr->ob_type->tp_descr_get;
if (f != NULL && PyDescr_IsData(descr)) {
res = f(descr, obj, (PyObject *)obj->ob_type);
descr = _PyType_Lookup(tp, name);
f = NULL;
- if (descr != NULL &&
- PyType_HasFeature(descr->ob_type, Py_TPFLAGS_HAVE_CLASS)) {
+ if (descr != NULL) {
f = descr->ob_type->tp_descr_set;
if (f != NULL && PyDescr_IsData(descr)) {
res = f(descr, obj, value);
register PyObject *w = *pw;
int res;
- /* Shortcut only for old-style types */
- if (v->ob_type == w->ob_type &&
- !PyType_HasFeature(v->ob_type, Py_TPFLAGS_CHECKTYPES))
- {
- Py_INCREF(v);
- Py_INCREF(w);
- return 0;
- }
if (v->ob_type->tp_as_number && v->ob_type->tp_as_number->nb_coerce) {
res = (*v->ob_type->tp_as_number->nb_coerce)(pv, pw);
if (res <= 0)
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES |
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
set_doc, /* tp_doc */
(traverseproc)set_traverse, /* tp_traverse */
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_CHECKTYPES |
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE, /* tp_flags */
frozenset_doc, /* tp_doc */
(traverseproc)set_traverse, /* tp_traverse */
return x;
}
-#define HASINDEX(o) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_HAVE_INDEX)
-
static PyObject*
string_subscript(PyStringObject* self, PyObject* item)
{
PyNumberMethods *nb = item->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(item) && nb->nb_index != NULL) {
+ if (nb != NULL && nb->nb_index != NULL) {
Py_ssize_t i = nb->nb_index(item);
if (i == -1 && PyErr_Occurred())
return NULL;
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
&string_as_buffer, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
string_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
(objobjproc)tuplecontains, /* sq_contains */
};
-#define HASINDEX(o) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_HAVE_INDEX)
-
static PyObject*
tuplesubscript(PyTupleObject* self, PyObject* item)
{
PyNumberMethods *nb = item->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(item) && nb->nb_index != NULL) {
+ if (nb != NULL && nb->nb_index != NULL) {
Py_ssize_t i = nb->nb_index(item);
if (i == -1 && PyErr_Occurred())
return NULL;
if (!PyType_IsSubtype(obj->ob_type, type))
return obj;
type = obj->ob_type;
- if (PyType_HasFeature(type, Py_TPFLAGS_HAVE_CLASS) &&
- type->tp_init != NULL &&
+ if (type->tp_init != NULL &&
type->tp_init(obj, args, kwds) < 0) {
Py_DECREF(obj);
obj = NULL;
{
PyObject *mro;
- if (!(a->tp_flags & Py_TPFLAGS_HAVE_CLASS))
- return b == a || b == &PyBaseObject_Type;
-
mro = a->tp_mro;
if (mro != NULL) {
/* Deal with multiple inheritance without recursion
if (base->tp_flags & Py_TPFLAGS_HAVE_GC)
type->tp_flags |= Py_TPFLAGS_HAVE_GC;
- /* It's a new-style number unless it specifically inherits any
- old-style numeric behavior */
- if ((base->tp_flags & Py_TPFLAGS_CHECKTYPES) ||
- (base->tp_as_number == NULL))
- type->tp_flags |= Py_TPFLAGS_CHECKTYPES;
-
/* Initialize essential fields */
type->tp_as_number = &et->as_number;
type->tp_as_sequence = &et->as_sequence;
{
Py_ssize_t oldsize, newsize;
- /* Special flag magic */
- if (!type->tp_as_buffer && base->tp_as_buffer) {
- type->tp_flags &= ~Py_TPFLAGS_HAVE_GETCHARBUFFER;
- type->tp_flags |=
- base->tp_flags & Py_TPFLAGS_HAVE_GETCHARBUFFER;
- }
- if (!type->tp_as_sequence && base->tp_as_sequence) {
- type->tp_flags &= ~Py_TPFLAGS_HAVE_SEQUENCE_IN;
- type->tp_flags |= base->tp_flags & Py_TPFLAGS_HAVE_SEQUENCE_IN;
- }
- if ((type->tp_flags & Py_TPFLAGS_HAVE_INPLACEOPS) !=
- (base->tp_flags & Py_TPFLAGS_HAVE_INPLACEOPS)) {
- if ((!type->tp_as_number && base->tp_as_number) ||
- (!type->tp_as_sequence && base->tp_as_sequence)) {
- type->tp_flags &= ~Py_TPFLAGS_HAVE_INPLACEOPS;
- if (!type->tp_as_number && !type->tp_as_sequence) {
- type->tp_flags |= base->tp_flags &
- Py_TPFLAGS_HAVE_INPLACEOPS;
- }
- }
- /* Wow */
- }
- if (!type->tp_as_number && base->tp_as_number) {
- type->tp_flags &= ~Py_TPFLAGS_CHECKTYPES;
- type->tp_flags |= base->tp_flags & Py_TPFLAGS_CHECKTYPES;
- }
-
/* Copying basicsize is connected to the GC flags */
oldsize = base->tp_basicsize;
newsize = type->tp_basicsize ? type->tp_basicsize : oldsize;
if (!(type->tp_flags & Py_TPFLAGS_HAVE_GC) &&
(base->tp_flags & Py_TPFLAGS_HAVE_GC) &&
- (type->tp_flags & Py_TPFLAGS_HAVE_RICHCOMPARE/*GC slots exist*/) &&
(!type->tp_traverse && !type->tp_clear)) {
type->tp_flags |= Py_TPFLAGS_HAVE_GC;
if (type->tp_traverse == NULL)
if (type->tp_clear == NULL)
type->tp_clear = base->tp_clear;
}
- if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_CLASS) {
+ {
/* The condition below could use some explanation.
It appears that tp_new is not inherited for static types
whose base class is 'object'; this seems to be a precaution
if (type->SLOT == 0) type->SLOT = base->SLOT
COPYVAL(tp_itemsize);
- if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_WEAKREFS) {
- COPYVAL(tp_weaklistoffset);
- }
- if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_CLASS) {
- COPYVAL(tp_dictoffset);
- }
+ COPYVAL(tp_weaklistoffset);
+ COPYVAL(tp_dictoffset);
}
static void
COPYNUM(nb_floor_divide);
COPYNUM(nb_inplace_true_divide);
COPYNUM(nb_inplace_floor_divide);
- /* XXX(nnorwitz): we don't need to check flags do we? */
- if (base->tp_flags & Py_TPFLAGS_HAVE_INDEX) {
- COPYNUM(nb_index);
- }
+ COPYNUM(nb_index);
}
if (type->tp_as_sequence != NULL && base->tp_as_sequence != NULL) {
/* tp_hash see tp_richcompare */
COPYSLOT(tp_call);
COPYSLOT(tp_str);
- if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_RICHCOMPARE) {
+ {
if (type->tp_compare == NULL &&
type->tp_richcompare == NULL &&
type->tp_hash == NULL)
type->tp_hash = base->tp_hash;
}
}
- else {
- COPYSLOT(tp_compare);
- }
- if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_ITER) {
+ {
COPYSLOT(tp_iter);
COPYSLOT(tp_iternext);
}
- if (type->tp_flags & base->tp_flags & Py_TPFLAGS_HAVE_CLASS) {
+ {
COPYSLOT(tp_descr_get);
COPYSLOT(tp_descr_set);
COPYSLOT(tp_dictoffset);
if (!check_num_args(args, 1))
return NULL;
other = PyTuple_GET_ITEM(args, 0);
- if (!(self->ob_type->tp_flags & Py_TPFLAGS_CHECKTYPES) &&
- !PyType_IsSubtype(other->ob_type, self->ob_type)) {
- Py_INCREF(Py_NotImplemented);
- return Py_NotImplemented;
- }
return (*func)(self, other);
}
if (!check_num_args(args, 1))
return NULL;
other = PyTuple_GET_ITEM(args, 0);
- if (!(self->ob_type->tp_flags & Py_TPFLAGS_CHECKTYPES) &&
- !PyType_IsSubtype(other->ob_type, self->ob_type)) {
+ if (!PyType_IsSubtype(other->ob_type, self->ob_type)) {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}
PyUnicode_Contains, /* sq_contains */
};
-#define HASINDEX(o) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_HAVE_INDEX)
-
static PyObject*
unicode_subscript(PyUnicodeObject* self, PyObject* item)
{
PyNumberMethods *nb = item->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(item) && nb->nb_index != NULL) {
+ if (nb != NULL && nb->nb_index != NULL) {
Py_ssize_t i = nb->nb_index(item);
if (i == -1 && PyErr_Occurred())
return NULL;
PyObject_GenericGetAttr, /* tp_getattro */
0, /* tp_setattro */
&unicode_as_buffer, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES |
- Py_TPFLAGS_BASETYPE, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
unicode_doc, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_RICHCOMPARE
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC
| Py_TPFLAGS_BASETYPE, /*tp_flags*/
0, /*tp_doc*/
(traverseproc)gc_traverse, /*tp_traverse*/
proxy_getattr, /* tp_getattro */
(setattrofunc)proxy_setattr, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC
- | Py_TPFLAGS_CHECKTYPES, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
0, /* tp_doc */
(traverseproc)gc_traverse, /* tp_traverse */
(inquiry)gc_clear, /* tp_clear */
proxy_getattr, /* tp_getattro */
(setattrofunc)proxy_setattr, /* tp_setattro */
0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC
- | Py_TPFLAGS_CHECKTYPES, /* tp_flags */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */
0, /* tp_doc */
(traverseproc)gc_traverse, /* tp_traverse */
(inquiry)gc_clear, /* tp_clear */
x = PyInt_AsSsize_t(v);
}
else if (v->ob_type->tp_as_number &&
- PyType_HasFeature(v->ob_type, Py_TPFLAGS_HAVE_INDEX)
- && v->ob_type->tp_as_number->nb_index) {
+ v->ob_type->tp_as_number->nb_index) {
x = v->ob_type->tp_as_number->nb_index(v);
if (x == -1 && PyErr_Occurred())
return 0;
#undef ISINDEX
#define ISINDEX(x) ((x) == NULL || PyInt_Check(x) || PyLong_Check(x) || \
((x)->ob_type->tp_as_number && \
- PyType_HasFeature((x)->ob_type, Py_TPFLAGS_HAVE_INDEX) \
- && (x)->ob_type->tp_as_number->nb_index))
+ (x)->ob_type->tp_as_number->nb_index))
static PyObject *
apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */
return converterr(
"invalid use of 't' format character",
arg, msgbuf, bufsize);
- if (!PyType_HasFeature(arg->ob_type,
- Py_TPFLAGS_HAVE_GETCHARBUFFER) ||
- pb == NULL || pb->bf_getcharbuffer == NULL ||
+ if (pb == NULL || pb->bf_getcharbuffer == NULL ||
pb->bf_getsegcount == NULL)
return converterr(
"string or read-only character buffer",