Mercurial > hg
comparison mercurial/parsers.c @ 16604:48e42f984074 stable
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')
author | Adrian Buehlmann <adrian@cadifra.com> |
---|---|
date | Tue, 08 May 2012 11:20:07 +0200 |
parents | b767382a8675 |
children | 8c3c9031f5aa e6dfbc5df76f |
comparison
equal
deleted
inserted
replaced
16598:20a9d823f242 | 16604:48e42f984074 |
---|---|
1090 0, /* tp_descr_get */ | 1090 0, /* tp_descr_get */ |
1091 0, /* tp_descr_set */ | 1091 0, /* tp_descr_set */ |
1092 0, /* tp_dictoffset */ | 1092 0, /* tp_dictoffset */ |
1093 (initproc)index_init, /* tp_init */ | 1093 (initproc)index_init, /* tp_init */ |
1094 0, /* tp_alloc */ | 1094 0, /* tp_alloc */ |
1095 PyType_GenericNew, /* tp_new */ | |
1096 }; | 1095 }; |
1097 | 1096 |
1098 /* | 1097 /* |
1099 * returns a tuple of the form (index, index, cache) with elements as | 1098 * returns a tuple of the form (index, index, cache) with elements as |
1100 * follows: | 1099 * follows: |
1148 {NULL, NULL} | 1147 {NULL, NULL} |
1149 }; | 1148 }; |
1150 | 1149 |
1151 static void module_init(PyObject *mod) | 1150 static void module_init(PyObject *mod) |
1152 { | 1151 { |
1152 indexType.tp_new = PyType_GenericNew; | |
1153 if (PyType_Ready(&indexType) < 0) | 1153 if (PyType_Ready(&indexType) < 0) |
1154 return; | 1154 return; |
1155 Py_INCREF(&indexType); | 1155 Py_INCREF(&indexType); |
1156 | 1156 |
1157 PyModule_AddObject(mod, "index", (PyObject *)&indexType); | 1157 PyModule_AddObject(mod, "index", (PyObject *)&indexType); |