8000 Merge pull request #13994 from charris/backport-13870 · charris/numpy@ba78b40 · GitHub
[go: up one dir, main page]

Skip to content

Commit ba78b40

Browse files
authored
Merge pull request numpy#13994 from charris/backport-13870
MAINT,BUG: Use nbytes to also catch empty descr during allocation
2 parents ca6480e + 31a21c4 commit ba78b40

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

numpy/core/src/multiarray/ctors.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
912912
int allow_emptystring)
913913
{
914914
PyArrayObject_fields *fa;
915-
int i, is_empty;
915+
int i;
916916
npy_intp nbytes;
917917

918918
if (descr->subarray) {
@@ -966,7 +966,6 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
966966
}
967967

968968
/* Check dimensions and multiply them to nbytes */
969-
is_empty = 0;
970969
for (i = 0; i < nd; i++) {
971970
npy_intp dim = dims[i];
972971

@@ -975,7 +974,6 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
975974
* Compare to PyArray_OverflowMultiplyList that
976975
* returns 0 in this case.
977976
*/
978-
is_empty = 1;
979977
continue;
980978
}
981979

@@ -1058,8 +1056,8 @@ PyArray_NewFromDescr_int(PyTypeObject *subtype, PyArray_Descr *descr, int nd,
10581056
* (a.data) doesn't work as it should.
10591057
* Could probably just allocate a few bytes here. -- Chuck
10601058
*/
1061-
if (is_empty) {
1062-
nbytes = descr->elsize;
1059+
if (nbytes == 0) {
1060+
nbytes = descr->elsize ? descr->elsize : 1;
10631061
}
10641062
/*
10651063
* It is bad to have uninitialized OBJECT pointers

0 commit comments

Comments
 (0)
0