@@ -49,11 +49,18 @@ QuadPrecisionObject * QuadPrecision_from_object(PyObject * value)
49
49
}
50
50
else if (PyLong_Check (value ))
51
51
{
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 );
53
60
}
54
61
else
55
62
{
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" );
57
64
Py_DECREF (self );
58
65
return NULL ;
59
66
}
@@ -91,13 +98,20 @@ static PyObject * QuadPrecision_repr(QuadPrecisionObject* self)
91
98
return res ;
92
99
}
93
100
101
+ static void
102
+ quad_dealloc (QuadPrecDTypeObject * self )
103
+ {
104
+ PyArrayDescr_Type .tp_dealloc ((PyObject * )self );
105
+ }
106
+
94
107
PyTypeObject QuadPrecision_Type =
95
108
{
96
109
PyVarObject_HEAD_INIT (NULL , 0 )
97
110
.tp_name = "QuadPrecType.QuadPrecision" ,
98
111
.tp_basicsize = sizeof (QuadPrecisionObject ),
99
112
.tp_itemsize = 0 ,
100
113
.tp_new = QuadPrecision_new ,
114
+ .tp_dealloc = (destructor )quad_dealloc ,
101
115
.tp_repr = (reprfunc )QuadPrecision_repr ,
102
116
.tp_str = (reprfunc )QuadPrecision_str ,
103
117
.tp_as_number = & quad_as_scalar ,
0 commit comments