From 5f93c94e879f636867733aaff1a209c6535e4583 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 14 Dec 2015 01:56:11 +0000 Subject: [PATCH] Python tp_allocs -> tp_next corrections Updates for Python 2.5 and later and for -builtin. --- Lib/python/builtin.swg | 8 +++++++- Lib/python/pyinit.swg | 8 +++++++- Lib/python/pyrun.swg | 16 ++++++++++++++-- Source/Modules/python.cxx | 9 +++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Lib/python/builtin.swg b/Lib/python/builtin.swg index 4604e4397..0107c52d5 100644 --- a/Lib/python/builtin.swg +++ b/Lib/python/builtin.swg @@ -439,7 +439,13 @@ SwigPyStaticVar_Type(void) { 0, /* tp_finalize */ #endif #ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ + 0, /* tp_allocs */ + 0, /* tp_frees */ + 0, /* tp_maxalloc */ +#if PY_VERSION_HEX >= 0x02050000 + 0, /* tp_prev */ +#endif + 0 /* tp_next */ #endif }; staticvar_type = tmp; diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index 9398443e3..2e21b8265 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -189,7 +189,13 @@ swig_varlink_type(void) { 0, /* tp_finalize */ #endif #ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ + 0, /* tp_allocs */ + 0, /* tp_frees */ + 0, /* tp_maxalloc */ +#if PY_VERSION_HEX >= 0x02050000 + 0, /* tp_prev */ +#endif + 0 /* tp_next */ #endif }; varlink_type = tmp; diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index f13154794..1326ed775 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -812,7 +812,13 @@ SwigPyObject_TypeOnce(void) { 0, /* tp_finalize */ #endif #ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ + 0, /* tp_allocs */ + 0, /* tp_frees */ + 0, /* tp_maxalloc */ +#if PY_VERSION_HEX >= 0x02050000 + 0, /* tp_prev */ +#endif + 0 /* tp_next */ #endif }; swigpyobject_type = tmp; @@ -994,7 +1000,13 @@ SwigPyPacked_TypeOnce(void) { 0, /* tp_finalize */ #endif #ifdef COUNT_ALLOCS - 0,0,0,0 /* tp_alloc -> tp_next */ + 0, /* tp_allocs */ + 0, /* tp_frees */ + 0, /* tp_maxalloc */ +#if PY_VERSION_HEX >= 0x02050000 + 0, /* tp_prev */ +#endif + 0 /* tp_next */ #endif }; swigpypacked_type = tmp; diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index 75d8ffafa..eff263be6 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -4053,6 +4053,15 @@ public: Printv(f, "#if PY_VERSION_HEX >= 0x03040000\n", NIL); printSlot(f, getSlot(n, "feature:python:tp_finalize"), "tp_finalize", "destructor"); Printv(f, "#endif\n", NIL); + Printv(f, "#ifdef COUNT_ALLOCS\n", NIL); + printSlot(f, getSlot(), "tp_allocs", "Py_ssize_t"); + printSlot(f, getSlot(), "tp_frees", "Py_ssize_t"); + printSlot(f, getSlot(), "tp_maxalloc", "Py_ssize_t"); + Printv(f, "#if PY_VERSION_HEX >= 0x02050000\n", NIL); + printSlot(f, getSlot(), "tp_prev", "struct _typeobject*"); + Printv(f, "#endif\n", NIL); + printSlot(f, getSlot(), "tp_next", "struct _typeobject*"); + Printv(f, "#endif\n", NIL); Printf(f, " },\n"); // PyAsyncMethods as_async