Commit d7fa6e8a authored by Kevin Modzelewski's avatar Kevin Modzelewski Committed by GitHub

Merge pull request #1307 from undingen/fix_long_leak

long: dealloc gmp memory
parents 513bc9ba 3e64ec6d
...@@ -63,6 +63,10 @@ int _PyLong_DigitValue[256] = { ...@@ -63,6 +63,10 @@ int _PyLong_DigitValue[256] = {
#define IS_LITTLE_ENDIAN (int)*(unsigned char*)&one #define IS_LITTLE_ENDIAN (int)*(unsigned char*)&one
#define PY_ABS_LLONG_MIN (0 - (unsigned PY_LONG_LONG)PY_LLONG_MIN) #define PY_ABS_LLONG_MIN (0 - (unsigned PY_LONG_LONG)PY_LLONG_MIN)
void BoxedLong::tp_dealloc(Box* b) noexcept {
mpz_clear(static_cast<BoxedLong*>(b)->n);
}
extern "C" int _PyLong_Sign(PyObject* l) noexcept { extern "C" int _PyLong_Sign(PyObject* l) noexcept {
return mpz_sgn(static_cast<BoxedLong*>(l)->n); return mpz_sgn(static_cast<BoxedLong*>(l)->n);
} }
......
...@@ -33,6 +33,8 @@ public: ...@@ -33,6 +33,8 @@ public:
BoxedLong() __attribute__((visibility("default"))) {} BoxedLong() __attribute__((visibility("default"))) {}
static void tp_dealloc(Box* b) noexcept;
DEFAULT_CLASS_SIMPLE(long_cls, false); DEFAULT_CLASS_SIMPLE(long_cls, false);
}; };
......
...@@ -4227,7 +4227,8 @@ void setupRuntime() { ...@@ -4227,7 +4227,8 @@ void setupRuntime() {
int_cls->tp_flags |= Py_TPFLAGS_INT_SUBCLASS; 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); 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); 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; long_cls->tp_flags |= Py_TPFLAGS_LONG_SUBCLASS;
float_cls = new (0) float_cls = new (0)
BoxedClass(object_cls, 0, 0, sizeof(BoxedFloat), false, "float", true, BoxedFloat::tp_dealloc, NULL, false); BoxedClass(object_cls, 0, 0, sizeof(BoxedFloat), false, "float", true, BoxedFloat::tp_dealloc, NULL, false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment