@@ -104,19 +104,27 @@ _py_c_neg(PyObject *Py_UNUSED(module), PyObject *num)
104
104
static PyObject * \
105
105
_py_c_##suffix(PyObject *Py_UNUSED(module), PyObject *args) \
106
106
{ \
107
- Py_complex num, exp, res; \
107
+ Py_complex num, exp; \
108
+ PyObject *res, *err; \
108
109
\
109
110
if (!PyArg_ParseTuple(args, "DD", &num, &exp)) { \
110
111
return NULL; \
111
112
} \
112
113
\
113
114
errno = 0; \
114
- res = _Py_c_##suffix(num, exp); \
115
- _Py_ADJUST_ERANGE2(res .real, res .imag); \
115
+ num = _Py_c_##suffix(num, exp); \
116
+ _Py_ADJUST_ERANGE2(num .real, num .imag); \
116
117
\
117
- return PyTuple_Pack(2, \
118
- PyComplex_FromCComplex(res), \
119
- PyLong_FromLong(errno)); \
118
+ res = PyComplex_FromCComplex(num); \
119
+ if (!res) { \
120
+ return NULL; \
121
+ } \
122
+ err = PyLong_FromLong(errno); \
123
+ if (!err) { \
124
+ return NULL; \
125
+ } \
126
+ \
127
+ return PyTuple_Pack(2, res, err); \
120
128
};
121
129
122
130
_PY_C_FUNC2 (sum )
@@ -129,7 +137,8 @@ static PyObject*
129
137
_py_c_abs (PyObject * Py_UNUSED (module ), PyObject * obj )
130
138
{
131
139
Py_complex complex ;
132
- double res ;
140
+ PyObject * res , * err ;
141
+ double val ;
133
142
134
143
NULLABLE (obj );
135
144
complex = PyComplex_AsCComplex (obj );
@@ -139,9 +148,18 @@ _py_c_abs(PyObject *Py_UNUSED(module), PyObject* obj)
139
148
}
140
149
141
150
errno = 0 ;
142
- res = _Py_c_abs (complex );
143
- return PyTuple_Pack (2 , PyFloat_FromDouble (res ),
144
- PyLong_FromLong (errno ));
151
+ val = _Py_c_abs (complex );
152
+
153
+ res = PyFloat_FromDouble (val );
154
+ if (!res ) {
155
+ return NULL ;
156
+ }
157
+ err = PyLong_FromLong (errno );
158
+ if (!err ) {
159
+ return NULL ;
160
+ }
161
+
162
+ return PyTuple_Pack (2 , res , err );
145
163
}
146
164
147
165
0 commit comments