Skip to content

Commit 8e4132e

Browse files
authored
Update openmp-simple.h
1 parent 8aac8d4 commit 8e4132e

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

share/openmp-simple.h

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -459,17 +459,19 @@ bool is_float(SV *sv) { return SvNOK(sv); }
459459
bool is_int(SV *sv) { return SvIOK(sv); }
460460
bool is_string(SV *sv) { return SvPOK(sv); }
461461

462-
/* Generic function to verify a 1D array's element type */
463462
void verify_1D_array_type(SV *array, bool (*type_check)(SV *), const char *type_name) {
464463
if (!is_array_ref(array)) {
465464
croak("Expected a 1D array reference");
466465
}
467466
AV *av = (AV *)SvRV(array);
468-
I32 len = av_len(av) + 1;
467+
I32 len = av_len(av);
468+
if (len == -1) return; // Handle empty arrays safely
469+
len++; // Convert last index to total count
470+
469471
for (I32 i = 0; i < len; i++) {
470472
SV **element = av_fetch(av, i, 0);
471-
if (!element || !type_check(*element)) {
472-
croak("Expected all elements to be %s at index %d", type_name, i);
473+
if (!element || !*element || !type_check(*element)) {
474+
croak("Expected all elements to be %s at index %" IVdf, type_name, (IV)i);
473475
}
474476
}
475477
}
@@ -482,17 +484,32 @@ void PerlOMP_VERIFY_1D_STRING_ARRAY(SV *array) { verify_1D_array_type(array, is_
482484

483485
/* Generic function to verify a 2D array's element type */
484486
void verify_2D_array_type(SV *AoA, bool (*type_check)(SV *), const char *type_name) {
485-
PerlOMP_VERIFY_2D_AoA(AoA);
487+
PerlOMP_VERIFY_2D_AoA(AoA); // Assuming this macro validates AoA correctly
488+
489+
if (!is_array_ref(AoA)) {
490+
croak("Expected a 2D array reference");
491+
}
492+
486493
AV *outer = (AV *)SvRV(AoA);
487-
I32 rows = av_len(outer) + 1;
494+
I32 rows = av_len(outer);
495+
if (rows == -1) return; // Handle empty outer array safely
496+
rows++; // Convert last index to total count
497+
488498
for (I32 i = 0; i < rows; i++) {
489499
SV **inner_ref = av_fetch(outer, i, 0);
500+
if (!inner_ref || !*inner_ref || !is_array_ref(*inner_ref)) {
501+
croak("Expected an array reference at row %" IVdf, (IV)i);
502+
}
503+
490504
AV *inner = (AV *)SvRV(*inner_ref);
491-
I32 cols = av_len(inner) + 1;
505+
I32 cols = av_len(inner);
506+
if (cols == -1) continue; // Handle empty inner arrays safely
507+
cols++; // Convert last index to total count
508+
492509
for (I32 j = 0; j < cols; j++) {
493510
SV **element = av_fetch(inner, j, 0);
494-
if (!element || !type_check(*element)) {
495-
croak("Expected all elements to be %s at [%d][%d]", type_name, i, j);
511+
if (!element || !*element || !type_check(*element)) {
512+
croak("Expected all elements to be %s at [%" IVdf "][%" IVdf "]", type_name, (IV)i, (IV)j);
496513
}
497514
}
498515
}

0 commit comments

Comments
 (0)