Skip to content

Commit 785bc52

Browse files
committed
added more robust 'type checks' that work in Perls 5.12 adn 5.14
1 parent 6399094 commit 785bc52

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

share/openmp-simple.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,20 @@ 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 SvIOKp(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

462472
void verify_1D_array_type(SV *array, bool (*type_check)(SV *), const char *type_name) {
463473
if (!is_array_ref(array)) {

t/00-PerlOMP_VERIFY.t

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ lives_ok { _PerlOMP_VERIFY_1D_Array($valid_1d_int) } "Valid 1D array passes veri
2828
lives_ok { _PerlOMP_VERIFY_1D_INT_ARRAY($valid_1d_int) } "Valid 1D integer array";
2929
dies_ok { _PerlOMP_VERIFY_1D_INT_ARRAY($valid_1d_float) } "Float 1D array should fail int verification";
3030

31-
done_testing;
32-
exit;
33-
3431
lives_ok { _PerlOMP_VERIFY_1D_FLOAT_ARRAY($valid_1d_float) } "Valid 1D float array";
3532
dies_ok { _PerlOMP_VERIFY_1D_FLOAT_ARRAY($valid_1d_int) } "Int 1D array should fail float verification";
3633

0 commit comments

Comments
 (0)