Skip to content

Commit

Permalink
error check, add tp_traverse to flagsobject
Browse files Browse the repository at this point in the history
  • Loading branch information
mattip committed Dec 12, 2023
1 parent d82d3a0 commit cb60cf6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions numpy/core/src/multiarray/flagsobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,15 @@ arrayflags_new_impl(HPyContext *ctx, HPy self, const HPy *args, HPy_ssize_t narg
return HPyArray_NewFlagsObject(ctx, self, arg);
}

HPyDef_SLOT(arrayflags_traverse, HPy_tp_traverse)
static int
arrayflags_traverse_impl(void *self, HPyFunc_visitproc visit, void *arg)
{
PyArrayFlagsObject *flags = (PyArrayFlagsObject *)self;
HPy_VISIT(&flags->arr);
return 0;
}

/*
static PyType_Slot arrayflags_slots[] = {
//{Py_tp_str, arrayflags_print},
Expand Down Expand Up @@ -929,6 +938,7 @@ static HPyDef *arrayflags_defines[] = {
&arrayflags_carray,
&arrayflags_farray,
&arrayflags_num,
&arrayflags_traverse,
NULL
};

Expand Down
6 changes: 6 additions & 0 deletions numpy/core/src/multiarray/scalarapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,12 @@ HPyArray_FromScalar(HPyContext *ctx, HPy h_scalar, /*PyArray_Descr*/ HPy h_outco
}
else {
char *memptr = hpy_scalar_value(ctx, h_scalar, typecode);
if (memptr == NULL)
{
HPy_Close(ctx, h_r);
HPy_Close(ctx, h_typecode);
return HPy_NULL;
}

memcpy(PyArray_DATA(r), memptr, typecode->elsize);
if (PyDataType_FLAGCHK(typecode, NPY_ITEM_HASOBJECT)) {
Expand Down

0 comments on commit cb60cf6

Please sign in to comment.