Skip to content

Commit 63dc446

Browse files
committed
added destructor function for tp_dealloc
1 parent 6e124e3 commit 63dc446

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

quaddtype/quaddtype/src/scalar.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,18 @@ QuadPrecisionObject * QuadPrecision_from_object(PyObject * value)
4949
}
5050
else if(PyLong_Check(value))
5151
{
52-
self->quad.value = Sleef_cast_from_int64q1(PyLong_AsLong(value));
52+
long int val = PyLong_AsLong(value);
53+
if (val == -1)
54+
{
55+
PyErr_SetString(PyExc_OverflowError, "Overflow Error, value out of range");
56+
Py_DECREF(self);
57+
return NULL;
58+
}
59+
self->quad.value = Sleef_cast_from_int64q1(val);
5360
}
5461
else
5562
{
56-
PyErr_SetString(PyExc_TypeError, "QuadPrecision value must be a float or string");
63+
PyErr_SetString(PyExc_TypeError, "QuadPrecision value must be a float, int or string");
5764
Py_DECREF(self);
5865
return NULL;
5966
}
@@ -91,13 +98,20 @@ static PyObject * QuadPrecision_repr(QuadPrecisionObject* self)
9198
return res;
9299
}
93100

101+
static void
102+
quad_dealloc(QuadPrecDTypeObject *self)
103+
{
104+
PyArrayDescr_Type.tp_dealloc((PyObject *)self);
105+
}
106+
94107
PyTypeObject QuadPrecision_Type =
95108
{
96109
PyVarObject_HEAD_INIT(NULL, 0)
97110
.tp_name = "QuadPrecType.QuadPrecision",
98111
.tp_basicsize = sizeof(QuadPrecisionObject),
99112
.tp_itemsize = 0,
100113
.tp_new = QuadPrecision_new,
114+
.tp_dealloc = (destructor)quad_dealloc,
101115
.tp_repr = (reprfunc)QuadPrecision_repr,
102116
.tp_str = (reprfunc)QuadPrecision_str,
103117
.tp_as_number = &quad_as_scalar,

0 commit comments

Comments
 (0)