File Coverage

/usr/local/lib/perl5/site_perl/5.42.0/x86_64-linux/auto/share/module/Data-Checks/include/DataChecks.h
Criterion Covered Total %
statement 26 30 86.6
branch 9 18 50.0
condition n/a
subroutine n/a
pod n/a
total 35 48 72.9


line stmt bran cond sub pod time code
1             #ifndef __DATA_CHECKS_H__
2             #define __DATA_CHECKS_H__
3              
4             #ifdef HAVE_DATA_CHECKS_IMPL
5             # define DECLARE_FUNCTION(name, rettype, args, argnames) \
6             static rettype S_DataChecks_##name args;
7             #else
8             # define DECLARE_FUNCTION(name, rettype, args, argnames) \
9             static rettype (*name##_func) args; \
10             static rettype S_DataChecks_##name args \
11             { \
12             if(!name##_func) \
13             croak("Must call boot_data_checks() first"); \
14             return (*name##_func) argnames; \
15             }
16             #endif
17              
18             #define DATACHECKS_ABI_VERSION 1
19              
20             struct DataChecks_Checker;
21              
22             #define make_checkdata(checkspec) S_DataChecks_make_checkdata(aTHX_ checkspec)
23 13 50         DECLARE_FUNCTION(make_checkdata,
24             struct DataChecks_Checker *, (pTHX_ SV *checkspec), (aTHX_ checkspec))
25              
26             #define free_checkdata(checker) S_DataChecks_free_checkdata(aTHX_ checker)
27             DECLARE_FUNCTION(free_checkdata,
28             void, (pTHX_ struct DataChecks_Checker *checker), (aTHX_ checker))
29              
30             #define gen_assertmess(checker, name, constraint) S_DataChecks_gen_assertmess(aTHX_ checker, name, constraint)
31 11 50         DECLARE_FUNCTION(gen_assertmess,
32             void, (pTHX_ struct DataChecks_Checker *checker, SV *name, SV *constraint), (aTHX_ checker, name, constraint))
33              
34             #define make_assertop(checker, argop) S_DataChecks_make_assertop_flags(aTHX_ checker, 0, argop)
35             #define make_assertop_flags(checker, flags, argop) S_DataChecks_make_assertop_flags(aTHX_ checker, flags, argop)
36 19 50         DECLARE_FUNCTION(make_assertop_flags,
37             OP *, (pTHX_ struct DataChecks_Checker *checker, U32 flags, OP *argop), (aTHX_ checker, flags, argop))
38              
39             #define check_value(checker, value) S_DataChecks_check_value(aTHX_ checker, value)
40             DECLARE_FUNCTION(check_value,
41             bool, (pTHX_ struct DataChecks_Checker *checker, SV *value), (aTHX_ checker, value))
42              
43             #define assert_value(checker, value) S_DataChecks_assert_value(aTHX_ checker, value)
44 2 50         DECLARE_FUNCTION(assert_value,
45             void, (pTHX_ struct DataChecks_Checker *checker, SV *value), (aTHX_ checker, value))
46              
47             #ifndef HAVE_DATA_CHECKS_IMPL
48              
49             #define must_SvUV_from_modglobal(key) S_must_SvUV_from_modglobal(aTHX_ key)
50 36           static UV S_must_SvUV_from_modglobal(pTHX_ const char *key)
51             {
52 36           SV **svp = hv_fetch(PL_modglobal, key, strlen(key), 0);
53 36 50         if(!svp)
54 0           croak("Cannot load DataChecks.h: Expected to find %s in PL_modglobal", key);
55              
56 36           return SvUV(*svp);
57             }
58              
59             #define boot_data_checks(ver) S_boot_data_checks(aTHX_ ver)
60 6           static void S_boot_data_checks(pTHX_ double ver) {
61             SV **svp;
62 6 50         if(ver < 0.02)
63             ver = 0.02;
64 6           SV *versv = newSVnv(ver);
65              
66 6           load_module(PERL_LOADMOD_NOIMPORT, newSVpvs("Data::Checks"), versv, NULL);
67              
68 6           svp = hv_fetchs(PL_modglobal, "Data::Checks/ABIVERSION_MIN", 0);
69 6 50         if(!svp)
70 0           croak("Data::Checks ABI minimum version missing");
71 6           int abi_ver = SvIV(*svp);
72 6 50         if(abi_ver > DATACHECKS_ABI_VERSION)
73 0           croak("Data::Checks ABI version mismatch - library supports >= %d, compiled for %d",
74             abi_ver, DATACHECKS_ABI_VERSION);
75              
76 6           svp = hv_fetchs(PL_modglobal, "Data::Checks/ABIVERSION_MAX", 0);
77 6           abi_ver = SvIV(*svp);
78 6 50         if(abi_ver < DATACHECKS_ABI_VERSION)
79 0           croak("Data::Checks ABI version mismatch - library supports <= %d, compiled for %d",
80             abi_ver, DATACHECKS_ABI_VERSION);
81              
82 6           make_checkdata_func = INT2PTR(struct DataChecks_Checker *(*)(pTHX_ SV *checkspec),
83             must_SvUV_from_modglobal("Data::Checks/make_checkdata()@0"));
84 6           free_checkdata_func = INT2PTR(void (*)(pTHX_ struct DataChecks_Checker *checker),
85             must_SvUV_from_modglobal("Data::Checks/free_checkdata()@0"));
86 6           gen_assertmess_func = INT2PTR(void (*)(pTHX_ struct DataChecks_Checker *checker, SV *name, SV *constraint),
87             must_SvUV_from_modglobal("Data::Checks/gen_assertmess()@0"));
88 6           make_assertop_flags_func = INT2PTR(OP *(*)(pTHX_ struct DataChecks_Checker *checker, U32 flags, OP *argop),
89             must_SvUV_from_modglobal("Data::Checks/make_assertop()@1"));
90 6           check_value_func = INT2PTR(bool (*)(pTHX_ struct DataChecks_Checker *checker, SV *value),
91             must_SvUV_from_modglobal("Data::Checks/check_value()@0"));
92 6           assert_value_func = INT2PTR(void (*)(pTHX_ struct DataChecks_Checker *checker, SV *value),
93             must_SvUV_from_modglobal("Data::Checks/assert_value()@0"));
94 6           }
95              
96             #endif /* defined HAVE_DATA_CHECKS_IMPL */
97              
98             #endif