Patchwork manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3

login
register
mail settings
Submitter Gregory Szorc
Date Oct. 8, 2016, 3:34 p.m.
Message ID <33f1118c90814a8e06f3.1475940883@gps-mbp.local>
Download mbox | patch
Permalink /patch/16937/
State Superseded
Headers show

Comments

Gregory Szorc - Oct. 8, 2016, 3:34 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1475940865 -7200
#      Sat Oct 08 17:34:25 2016 +0200
# Node ID 33f1118c90814a8e06f390940829255a01f4e4a1
# Parent  ece8e9fc1bf2effb388bbca7222d3c644996aa2b
manifest: drop Py_TPFLAGS_HAVE_SEQUENCE_IN from tp_flags in Python 3

This flag disappeared in Python 3. It is only necessary in Python 2,
apparently.

Patch

diff --git a/mercurial/manifest.c b/mercurial/manifest.c
--- a/mercurial/manifest.c
+++ b/mercurial/manifest.c
@@ -13,8 +13,12 @@ 
 #include <stdlib.h>
 
 #include "util.h"
 
+#if PY_MAJOR_VERSION >= 3
+#define IS_PY3K
+#endif
+
 #define DEFAULT_LINES 100000
 
 typedef struct {
 	char *start;
@@ -253,8 +257,15 @@  done:
 	Py_XDECREF(flags);
 	return ret;
 }
 
+#ifdef IS_PY3K
+#define LAZYMANIFESTENTRIESITERATOR_TPFLAGS Py_TPFLAGS_DEFAULT
+#else
+#define LAZYMANIFESTENTRIESITERATOR_TPFLAGS Py_TPFLAGS_DEFAULT \
+	| Py_TPFLAGS_HAVE_ITER
+#endif
+
 static PyTypeObject lazymanifestEntriesIterator = {
 	PyObject_HEAD_INIT(NULL)
 	0,                               /*ob_size */
 	"parsers.lazymanifest.entriesiterator", /*tp_name */
@@ -274,11 +285,9 @@  static PyTypeObject lazymanifestEntriesI
 	0,                               /*tp_str */
 	0,                               /*tp_getattro */
 	0,                               /*tp_setattro */
 	0,                               /*tp_as_buffer */
-	/* tp_flags: Py_TPFLAGS_HAVE_ITER tells python to
-	   use tp_iter and tp_iternext fields. */
-	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
+	LAZYMANIFESTENTRIESITERATOR_TPFLAGS, /* tp_flags */
 	"Iterator for 3-tuples in a lazymanifest.",  /* tp_doc */
 	0,                               /* tp_traverse */
 	0,                               /* tp_clear */
 	0,                               /* tp_richcompare */
@@ -297,8 +306,15 @@  static PyObject *lmiter_iterkeysnext(PyO
 	pl = pathlen(l);
 	return PyString_FromStringAndSize(l->start, pl);
 }
 
+#ifdef IS_PY3K
+#define LAZYMANIFESTKEYSITERATOR_TPFLAGS Py_TPFLAGS_DEFAULT
+#else
+#define LAZYMANIFESTKEYSITERATOR_TPFLAGS Py_TPFLAGS_DEFAULT \
+	| Py_TPFLAGS_HAVE_ITER
+#endif
+
 static PyTypeObject lazymanifestKeysIterator = {
 	PyObject_HEAD_INIT(NULL)
 	0,                               /*ob_size */
 	"parsers.lazymanifest.keysiterator", /*tp_name */
@@ -318,11 +334,9 @@  static PyTypeObject lazymanifestKeysIter
 	0,                               /*tp_str */
 	0,                               /*tp_getattro */
 	0,                               /*tp_setattro */
 	0,                               /*tp_as_buffer */
-	/* tp_flags: Py_TPFLAGS_HAVE_ITER tells python to
-	   use tp_iter and tp_iternext fields. */
-	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_ITER,
+	LAZYMANIFESTKEYSITERATOR_TPFLAGS, /* tp_flags */
 	"Keys iterator for a lazymanifest.",  /* tp_doc */
 	0,                               /* tp_traverse */
 	0,                               /* tp_clear */
 	0,                               /* tp_richcompare */
@@ -872,8 +886,14 @@  static PyMethodDef lazymanifest_methods[
 	 "Encode this manifest to text."},
 	{NULL},
 };
 
+#ifdef IS_PY3K
+#define LAZYMANIFEST_TPFLAGS Py_TPFLAGS_DEFAULT
+#else
+#define LAZYMANIFEST_TPFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_SEQUENCE_IN
+#endif
+
 static PyTypeObject lazymanifestType = {
 	PyObject_HEAD_INIT(NULL)
 	0,                                                /* ob_size */
 	"parsers.lazymanifest",                           /* tp_name */
@@ -893,9 +913,9 @@  static PyTypeObject lazymanifestType = {
 	0,                                                /* tp_str */
 	0,                                                /* tp_getattro */
 	0,                                                /* tp_setattro */
 	0,                                                /* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_SEQUENCE_IN, /* tp_flags */
+	LAZYMANIFEST_TPFLAGS,                             /* tp_flags */
 	"TODO(augie)",                                    /* tp_doc */
 	0,                                                /* tp_traverse */
 	0,                                                /* tp_clear */
 	0,                                                /* tp_richcompare */