Skip to content

Commit 504bc23

Browse files
committed
Set MemoryError in test C API allocation failures
1 parent 4c79929 commit 504bc23

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

Modules/_testcapi/monitoring.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ CodeLike_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
2424
PyMonitoringState *states = (PyMonitoringState *)PyMem_Calloc(
2525
num_events, sizeof(PyMonitoringState));
2626
if (states == NULL) {
27+
PyErr_NoMemory();
2728
return NULL;
2829
}
2930
PyCodeLikeObject *self = (PyCodeLikeObject *) type->tp_alloc(type, 0);

Modules/_testinternalcapi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,6 +2033,7 @@ check_pyobject_uninitialized_is_freed(PyObject *self,
20332033
{
20342034
PyObject *op = (PyObject *)PyObject_Malloc(sizeof(PyObject));
20352035
if (op == NULL) {
2036+
PyErr_NoMemory();
20362037
return NULL;
20372038
}
20382039
/* Initialize reference count to avoid early crash in ceval or GC */
@@ -2049,6 +2050,7 @@ check_pyobject_forbidden_bytes_is_freed(PyObject *self,
20492050
/* Allocate an incomplete PyObject structure: truncate 'ob_type' field */
20502051
PyObject *op = (PyObject *)PyObject_Malloc(offsetof(PyObject, ob_type));
20512052
if (op == NULL) {
2053+
PyErr_NoMemory();
20522054
return NULL;
20532055
}
20542056
/* Initialize reference count to avoid early crash in ceval or GC */

0 commit comments

Comments
 (0)