From 3e64ec6d845a0ca246728752fa91e819d3b38f78 Mon Sep 17 00:00:00 2001 From: Marius Wachtler Date: Wed, 20 Jul 2016 20:11:01 +0100 Subject: [PATCH] long: dealloc gmp memory --- src/runtime/long.cpp | 4 ++++ src/runtime/long.h | 2 ++ src/runtime/types.cpp | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/runtime/long.cpp b/src/runtime/long.cpp index 5668b61da..6c625094a 100644 --- a/src/runtime/long.cpp +++ b/src/runtime/long.cpp @@ -63,6 +63,10 @@ int _PyLong_DigitValue[256] = { #define IS_LITTLE_ENDIAN (int)*(unsigned char*)&one #define PY_ABS_LLONG_MIN (0 - (unsigned PY_LONG_LONG)PY_LLONG_MIN) +void BoxedLong::tp_dealloc(Box* b) noexcept { + mpz_clear(static_cast(b)->n); +} + extern "C" int _PyLong_Sign(PyObject* l) noexcept { return mpz_sgn(static_cast(l)->n); } diff --git a/src/runtime/long.h b/src/runtime/long.h index c43baee73..03cdbd3b9 100644 --- a/src/runtime/long.h +++ b/src/runtime/long.h @@ -33,6 +33,8 @@ class BoxedLong : public Box { BoxedLong() __attribute__((visibility("default"))) {} + static void tp_dealloc(Box* b) noexcept; + DEFAULT_CLASS_SIMPLE(long_cls, false); }; diff --git a/src/runtime/types.cpp b/src/runtime/types.cpp index 60bc87cc4..3b14e375a 100644 --- a/src/runtime/types.cpp +++ b/src/runtime/types.cpp @@ -4227,7 +4227,8 @@ void setupRuntime() { int_cls->tp_flags |= Py_TPFLAGS_INT_SUBCLASS; bool_cls = new (0) BoxedClass(int_cls, 0, 0, sizeof(BoxedBool), false, "bool", false, NULL, NULL, false); complex_cls = new (0) BoxedClass(object_cls, 0, 0, sizeof(BoxedComplex), false, "complex", true, NULL, NULL, false); - long_cls = new (0) BoxedClass(object_cls, 0, 0, sizeof(BoxedLong), false, "long", true, NULL, NULL, false); + long_cls = new (0) + BoxedClass(object_cls, 0, 0, sizeof(BoxedLong), false, "long", true, BoxedLong::tp_dealloc, NULL, false); long_cls->tp_flags |= Py_TPFLAGS_LONG_SUBCLASS; float_cls = new (0) BoxedClass(object_cls, 0, 0, sizeof(BoxedFloat), false, "float", true, BoxedFloat::tp_dealloc, NULL, false);