[PATCH STABLE] parsers: statically initializing tp_new to PyType_GenericNew is not portable

Adrian Buehlmann adrian at cadifra.com
Mon May 7 18:32:52 CDT 2012


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1336429551 -7200
# Branch stable
# Node ID 9638a7034948ff842e8a931d0b322e39dd9db764
# Parent  91323a78aac252b630144f66e1039321cd41c9ef
parsers: statically initializing tp_new to PyType_GenericNew is not portable

As detailed on http://docs.python.org/extending/newtypes.html (quote):

  "In this case, we can just use the default implementation provided by the API
  function PyType_GenericNew(). We’d like to just assign this to the
  tp_new slot, but we can’t, for portability sake. On some platforms or
  compilers, we can’t statically initialize a structure member with a function
  defined in another C module, so, instead, we’ll assign the tp_new slot in the
  module initialization function just before calling PyType_Ready()"

Fixes "gcc (GCC) 3.4.5 (mingw-vista special r3)" complaining with:

  mercurial/parsers.c:1096: error: initializer element is not constant
  mercurial/parsers.c:1096: error: (near initialization for `indexType.tp_new')

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1092,7 +1092,7 @@
 	0,                         /* tp_dictoffset */
 	(initproc)index_init,      /* tp_init */
 	0,                         /* tp_alloc */
-	PyType_GenericNew,         /* tp_new */
+	/* PyType_GenericNew,         tp_new */
 };
 
 /*
@@ -1150,6 +1150,7 @@
 
 static void module_init(PyObject *mod)
 {
+	indexType.tp_new = PyType_GenericNew;
 	if (PyType_Ready(&indexType) < 0)
 		return;
 	Py_INCREF(&indexType);


More information about the Mercurial-devel mailing list