Skip to content

Commit 1e9fe1c

Browse files
authored
Merge pull request #14 from Perl-OpenMP/actions-update
fixing issue in perl 5.12 and 5.14, revealed via CI testing (added)
2 parents ffbf4d4 + 082ae1f commit 1e9fe1c

File tree

4 files changed

+66
-25
lines changed

4 files changed

+66
-25
lines changed

.github/workflows/other-perls.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ jobs:
66
build:
77
runs-on: ${{ matrix.os }}
88
strategy:
9+
fail-fast: false # Ensures that one failing job does not cancel others
910
matrix:
10-
os: ["ubuntu-latest"]
11-
perl: ["5.40","5.38","5.36","5.34","5.32","5.30","5.28","5.26","5.24","5.22","5.20"]
11+
os: ["ubuntu-latest","ubuntu-22.04"]
12+
perl: ["5.40","5.38","5.36","5.34","5.32","5.30","5.28","5.26","5.24","5.22","5.20","5.18","5.16","5.14","5.12"]
1213
name: Perl ${{ matrix.perl }} on ${{ matrix.os }}
1314

1415
steps:
@@ -26,12 +27,8 @@ jobs:
2627
run: |
2728
cpanm --verbose --notest Module::Build Inline::C Alien::OpenMP \
2829
Util::H2O::More File::Temp Test::Exception Test::Deep \
29-
OpenMP::Environment File::ShareDir Dist::Zilla
30-
31-
- name: Set Dist::Zilla for 'dzil test' command
32-
run: |
33-
dzil authordeps --missing | cpanm --verbose # Install required author dependencies
34-
cpanm --verbose --notest Dist::Zilla::Plugin::VersionFromModule # this may be redundant
30+
OpenMP::Environment File::ShareDir
3531
3632
- name: Run Tests
37-
run: dzil test
33+
run: ./test-runner.sh
34+
if: always() # Ensures tests run even if a previous step failed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ clean:
44
rm -rf t/_Inline
55
rm -rf blib
66

7+
clean2:
8+
rm -rf _Inline
9+
rm -rf t/_Inline
10+
rm -rf blib
11+
712
test: clean
813
./test-runner.sh
914

share/openmp-simple.h

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -454,45 +454,71 @@ void PerlOMP_VERIFY_2D_AoA(SV *AoA) {
454454
}
455455
}
456456

457-
/* Helper function to verify element types */
458-
bool is_float(SV *sv) { return SvNOK(sv); }
459-
bool is_int(SV *sv) { return SvIOK(sv); }
460-
bool is_string(SV *sv) { return SvPOK(sv); }
457+
/* Checks if an SV is an integer, allowing for stored floats that are whole numbers */
458+
bool is_int(SV *sv) {
459+
return SvIOK(sv) || (SvNOK(sv) && SvIV(sv) == SvNV(sv));
460+
}
461+
462+
/* Checks if an SV is a float, including cases where Perl stores it as an integer */
463+
bool is_float(SV *sv) {
464+
return SvNOK(sv) || (SvIOK(sv) && SvIV(sv) != SvNV(sv));
465+
}
466+
467+
/* Checks if an SV is a string, ensuring it's not just a numeric representation */
468+
bool is_string(SV *sv) {
469+
return SvPOK(sv) || (!SvNOK(sv) && !SvIOK(sv));
470+
}
461471

462-
/* Generic function to verify a 1D array's element type */
463472
void verify_1D_array_type(SV *array, bool (*type_check)(SV *), const char *type_name) {
464473
if (!is_array_ref(array)) {
465474
croak("Expected a 1D array reference");
466475
}
467476
AV *av = (AV *)SvRV(array);
468-
I32 len = av_len(av) + 1;
477+
I32 len = av_len(av);
478+
if (len == -1) return; // Handle empty arrays safely
479+
len++; // Convert last index to total count
480+
469481
for (I32 i = 0; i < len; i++) {
470482
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);
483+
if (!element || !*element || !type_check(*element)) {
484+
croak("Expected all elements to be %s at index %" IVdf, type_name, (IV)i);
473485
}
474486
}
475487
}
476488

477489
/* Implement type-specific 1D array verifications */
478490
void PerlOMP_VERIFY_1D_FLOAT_ARRAY(SV *array) { verify_1D_array_type(array, is_float, "float"); }
479491
void PerlOMP_VERIFY_1D_INT_ARRAY(SV *array) { verify_1D_array_type(array, is_int, "integer"); }
480-
void PerlOMP_VERIFY_1D_DOUBLE_ARRAY(SV *array) { verify_1D_array_type(array, is_float, "double"); }
481492
void PerlOMP_VERIFY_1D_STRING_ARRAY(SV *array) { verify_1D_array_type(array, is_string, "string"); }
482493

483494
/* Generic function to verify a 2D array's element type */
484495
void verify_2D_array_type(SV *AoA, bool (*type_check)(SV *), const char *type_name) {
485-
PerlOMP_VERIFY_2D_AoA(AoA);
496+
PerlOMP_VERIFY_2D_AoA(AoA); // Assuming this macro validates AoA correctly
497+
498+
if (!is_array_ref(AoA)) {
499+
croak("Expected a 2D array reference");
500+
}
501+
486502
AV *outer = (AV *)SvRV(AoA);
487-
I32 rows = av_len(outer) + 1;
503+
I32 rows = av_len(outer);
504+
if (rows == -1) return; // Handle empty outer array safely
505+
rows++; // Convert last index to total count
506+
488507
for (I32 i = 0; i < rows; i++) {
489508
SV **inner_ref = av_fetch(outer, i, 0);
509+
if (!inner_ref || !*inner_ref || !is_array_ref(*inner_ref)) {
510+
croak("Expected an array reference at row %" IVdf, (IV)i);
511+
}
512+
490513
AV *inner = (AV *)SvRV(*inner_ref);
491-
I32 cols = av_len(inner) + 1;
514+
I32 cols = av_len(inner);
515+
if (cols == -1) continue; // Handle empty inner arrays safely
516+
cols++; // Convert last index to total count
517+
492518
for (I32 j = 0; j < cols; j++) {
493519
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);
520+
if (!element || !*element || !type_check(*element)) {
521+
croak("Expected all elements to be %s at [%" IVdf "][%" IVdf "]", type_name, (IV)i, (IV)j);
496522
}
497523
}
498524
}
@@ -501,6 +527,5 @@ void verify_2D_array_type(SV *AoA, bool (*type_check)(SV *), const char *type_na
501527
/* Implement type-specific 2D array verifications */
502528
void PerlOMP_VERIFY_2D_FLOAT_ARRAY(SV *AoA) { verify_2D_array_type(AoA, is_float, "float"); }
503529
void PerlOMP_VERIFY_2D_INT_ARRAY(SV *AoA) { verify_2D_array_type(AoA, is_int, "integer"); }
504-
void PerlOMP_VERIFY_2D_DOUBLE_ARRAY(SV *AoA) { verify_2D_array_type(AoA, is_float, "double"); }
505530
void PerlOMP_VERIFY_2D_STRING_ARRAY(SV *AoA) { verify_2D_array_type(AoA, is_string, "string"); }
506531

test-runner.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
#!/usr/bin/env bash
22

3+
TESTS=$@
4+
5+
if [ -z "$TESTS" ]; then
6+
TESTS=$(ls -1 ./t)
7+
fi
8+
39
rm -rf blib > /dev/null 2>&1
410
mkdir -p blib/lib/auto/share/dist/OpenMP-Simple/
511
cp -f share/openmp-simple.h blib/lib/auto/share/dist/OpenMP-Simple/openmp-simple.h
612
cp -f share/ppport.h blib/lib/auto/share/dist/OpenMP-Simple/ppport.h
7-
PERL_DL_NONLAZY=1 perl -Ilib -MExtUtils::Command::MM -MTest::Harness -e "undef *Test::Harness::Switches; test_harness(1, 'blib/lib', 'blib/arch')" t/*.t | grep '\.\.\.\.'
13+
EXIT=0
14+
for FILE in $TESTS; do
15+
PERL_DL_NONLAZY=1 perl -Ilib -MExtUtils::Command::MM -MTest::Harness -e "undef *Test::Harness::Switches; test_harness(1, 'blib/lib', 'blib/arch')" t/$FILE
16+
if [ $? != 0 ]; then
17+
EXIT=$(($EXIT+1))
18+
fi
19+
done
20+
21+
exit $EXIT

0 commit comments

Comments
 (0)