gh-114569: Use PyMem_* APIs for most non-PyObject uses (#114574)

Fix usage in Modules, Objects, and Parser subdirectories.
This commit is contained in:
Erlend E. Aasland 2024-01-26 11:11:35 +01:00 committed by GitHub
parent d0f7f5c41d
commit dcd28b5c35
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 36 additions and 33 deletions

View file

@ -2570,7 +2570,7 @@ math_dist_impl(PyObject *module, PyObject *p, PyObject *q)
goto error_exit;
}
if (n > NUM_STACK_ELEMS) {
diffs = (double *) PyObject_Malloc(n * sizeof(double));
diffs = (double *) PyMem_Malloc(n * sizeof(double));
if (diffs == NULL) {
PyErr_NoMemory();
goto error_exit;
@ -2590,7 +2590,7 @@ math_dist_impl(PyObject *module, PyObject *p, PyObject *q)
}
result = vector_norm(n, diffs, max, found_nan);
if (diffs != diffs_on_stack) {
PyObject_Free(diffs);
PyMem_Free(diffs);
}
if (p_allocated) {
Py_DECREF(p);
@ -2602,7 +2602,7 @@ math_dist_impl(PyObject *module, PyObject *p, PyObject *q)
error_exit:
if (diffs != diffs_on_stack) {
PyObject_Free(diffs);
PyMem_Free(diffs);
}
if (p_allocated) {
Py_DECREF(p);
@ -2626,7 +2626,7 @@ math_hypot(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
double *coordinates = coord_on_stack;
if (nargs > NUM_STACK_ELEMS) {
coordinates = (double *) PyObject_Malloc(nargs * sizeof(double));
coordinates = (double *) PyMem_Malloc(nargs * sizeof(double));
if (coordinates == NULL) {
return PyErr_NoMemory();
}
@ -2643,13 +2643,13 @@ math_hypot(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
}
result = vector_norm(nargs, coordinates, max, found_nan);
if (coordinates != coord_on_stack) {
PyObject_Free(coordinates);
PyMem_Free(coordinates);
}
return PyFloat_FromDouble(result);
error_exit:
if (coordinates != coord_on_stack) {
PyObject_Free(coordinates);
PyMem_Free(coordinates);
}
return NULL;
}