LCOV - differential code coverage report
Current view: top level - contrib/hstore_plperl - hstore_plperl.c (source / functions) Coverage Total Hit UNC UBC GNC CBC DCB
Current: ba12a202ce1b5581dc0ed149cf3f637d7897ad5d vs 2866d8c7dbfc9d882a7d80fef93fbbe763709932 Lines: 97.0 % 66 64 2 9 55 6
Current Date: 2026-08-27 14:31:44 +0300 Functions: 100.0 % 6 6 1 5
Baseline: lcov-20260827-baseline Branches: 71.1 % 38 27 5 6 9 18
Baseline Date: 2026-08-27 14:31:58 +0300 Line coverage date bins:
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
(7,30] days: 87.5 % 16 14 2 9 5
(30,360] days: 100.0 % 2 2 2
(360..) days: 100.0 % 48 48 48
Function coverage date bins:
(360..) days: 100.0 % 6 6 1 5
Branch coverage date bins:
(7,30] days: 65.0 % 20 13 5 2 9 4
(30,360] days: 50.0 % 2 1 1 1
(360..) days: 81.2 % 16 13 3 13

 Age         Owner                    Branch data    TLA  Line data    Source code
                                  1                 :                : #include "postgres.h"
                                  2                 :                : 
                                  3                 :                : #include "fmgr.h"
                                  4                 :                : #include "hstore/hstore.h"
                                  5                 :                : #include "miscadmin.h"
                                  6                 :                : #include "plperl.h"
                                  7                 :                : 
  519 tgl@sss.pgh.pa.us           8                 :CBC           3 : PG_MODULE_MAGIC_EXT(
                                  9                 :                :                     .name = "hstore_plperl",
                                 10                 :                :                     .version = PG_VERSION
                                 11                 :                : );
                                 12                 :                : 
                                 13                 :                : /* Linkage to functions in hstore module */
                                 14                 :                : typedef HStore *(*hstoreUpgrade_t) (Datum orig);
                                 15                 :                : static hstoreUpgrade_t hstoreUpgrade_p;
                                 16                 :                : typedef int (*hstoreUniquePairs_t) (Pairs *a, int32 l, Size *buflen);
                                 17                 :                : static hstoreUniquePairs_t hstoreUniquePairs_p;
                                 18                 :                : typedef HStore *(*hstorePairs_t) (Pairs *pairs, int32 pcount, Size buflen);
                                 19                 :                : static hstorePairs_t hstorePairs_p;
                                 20                 :                : typedef size_t (*hstoreCheckKeyLen_t) (size_t len);
                                 21                 :                : static hstoreCheckKeyLen_t hstoreCheckKeyLen_p;
                                 22                 :                : typedef size_t (*hstoreCheckValLen_t) (size_t len);
                                 23                 :                : static hstoreCheckValLen_t hstoreCheckValLen_p;
                                 24                 :                : 
                                 25                 :                : /* Static asserts verify that typedefs above match original declarations */
                                 26                 :                : StaticAssertVariableIsOfType(&hstoreUpgrade, hstoreUpgrade_t);
                                 27                 :                : StaticAssertVariableIsOfType(&hstoreUniquePairs, hstoreUniquePairs_t);
                                 28                 :                : StaticAssertVariableIsOfType(&hstorePairs, hstorePairs_t);
                                 29                 :                : StaticAssertVariableIsOfType(&hstoreCheckKeyLen, hstoreCheckKeyLen_t);
                                 30                 :                : StaticAssertVariableIsOfType(&hstoreCheckValLen, hstoreCheckValLen_t);
                                 31                 :                : 
                                 32                 :                : 
                                 33                 :                : /*
                                 34                 :                :  * Module initialize function: fetch function pointers for cross-module calls.
                                 35                 :                :  */
                                 36                 :                : void
 3614                            37                 :              3 : _PG_init(void)
                                 38                 :                : {
                                 39                 :              3 :     hstoreUpgrade_p = (hstoreUpgrade_t)
                                 40                 :              3 :         load_external_function("$libdir/hstore", "hstoreUpgrade",
                                 41                 :                :                                true, NULL);
                                 42                 :              3 :     hstoreUniquePairs_p = (hstoreUniquePairs_t)
                                 43                 :              3 :         load_external_function("$libdir/hstore", "hstoreUniquePairs",
                                 44                 :                :                                true, NULL);
                                 45                 :              3 :     hstorePairs_p = (hstorePairs_t)
                                 46                 :              3 :         load_external_function("$libdir/hstore", "hstorePairs",
                                 47                 :                :                                true, NULL);
                                 48                 :              3 :     hstoreCheckKeyLen_p = (hstoreCheckKeyLen_t)
                                 49                 :              3 :         load_external_function("$libdir/hstore", "hstoreCheckKeyLen",
                                 50                 :                :                                true, NULL);
                                 51                 :              3 :     hstoreCheckValLen_p = (hstoreCheckValLen_t)
                                 52                 :              3 :         load_external_function("$libdir/hstore", "hstoreCheckValLen",
                                 53                 :                :                                true, NULL);
                                 54                 :              3 : }
                                 55                 :                : 
                                 56                 :                : 
                                 57                 :                : /* These defines must be after the module init function */
                                 58                 :                : #define hstoreUpgrade hstoreUpgrade_p
                                 59                 :                : #define hstoreUniquePairs hstoreUniquePairs_p
                                 60                 :                : #define hstorePairs hstorePairs_p
                                 61                 :                : #define hstoreCheckKeyLen hstoreCheckKeyLen_p
                                 62                 :                : #define hstoreCheckValLen hstoreCheckValLen_p
                                 63                 :                : 
                                 64                 :                : 
 4141 peter_e@gmx.net            65                 :              5 : PG_FUNCTION_INFO_V1(hstore_to_plperl);
                                 66                 :                : 
                                 67                 :                : Datum
                                 68                 :              7 : hstore_to_plperl(PG_FUNCTION_ARGS)
                                 69                 :                : {
 3317 tgl@sss.pgh.pa.us          70                 :              7 :     dTHX;
 3265                            71                 :              7 :     HStore     *in = PG_GETARG_HSTORE_P(0);
                                 72                 :                :     int         i;
 4141 peter_e@gmx.net            73                 :              7 :     int         count = HS_COUNT(in);
                                 74                 :              7 :     char       *base = STRPTR(in);
                                 75                 :              7 :     HEntry     *entries = ARRPTR(in);
                                 76                 :                :     HV         *hv;
                                 77                 :                : 
                                 78                 :              7 :     hv = newHV();
                                 79                 :                : 
                                 80         [ +  + ]:             20 :     for (i = 0; i < count; i++)
                                 81                 :                :     {
                                 82                 :                :         const char *key;
                                 83                 :                :         SV         *value;
                                 84                 :                : 
 3934 tgl@sss.pgh.pa.us          85         [ +  + ]:             13 :         key = pnstrdup(HSTORE_KEY(entries, base, i),
                                 86         [ +  + ]:             13 :                        HSTORE_KEYLEN(entries, i));
                                 87         [ +  + ]:             13 :         value = HSTORE_VALISNULL(entries, i) ? newSV(0) :
                                 88         [ +  - ]:              7 :             cstr2sv(pnstrdup(HSTORE_VAL(entries, base, i),
                                 89         [ -  + ]:              7 :                              HSTORE_VALLEN(entries, i)));
                                 90                 :                : 
 4141 peter_e@gmx.net            91                 :             13 :         (void) hv_store(hv, key, strlen(key), value, 0);
                                 92                 :                :     }
                                 93                 :                : 
                                 94                 :              7 :     return PointerGetDatum(newRV((SV *) hv));
                                 95                 :                : }
                                 96                 :                : 
                                 97                 :                : 
                                 98                 :              6 : PG_FUNCTION_INFO_V1(plperl_to_hstore);
                                 99                 :                : 
                                100                 :                : Datum
                                101                 :              8 : plperl_to_hstore(PG_FUNCTION_ARGS)
                                102                 :                : {
 3317 tgl@sss.pgh.pa.us         103                 :              8 :     dTHX;
 2992                           104                 :              8 :     SV         *in = (SV *) PG_GETARG_POINTER(0);
                                105                 :                :     HV         *hv;
                                106                 :                :     HE         *he;
                                107                 :                :     Size        buflen;
                                108                 :                :     int32       i;
                                109                 :                :     int32       pcount;
                                110                 :                :     HStore     *out;
                                111                 :                :     Pairs      *pairs;
                                112                 :                : 
                                113                 :                :     /* Dereference references recursively. */
    8 tgl@sss.pgh.pa.us         114         [ +  - ]:GNC           8 :     plperl_materialize_sv(in);
                                115   [ +  -  +  + ]:             15 :     while (in && SvROK(in))
                                116                 :                :     {
                                117                 :                :         /*
                                118                 :                :          * It's possible for circular references to make this an infinite
                                119                 :                :          * loop.  Checking for such a situation seems like much more trouble
                                120                 :                :          * than it's worth, but let's provide a way to break out of the loop.
                                121                 :                :          */
   70 tgl@sss.pgh.pa.us         122         [ -  + ]:CBC           7 :         CHECK_FOR_INTERRUPTS();
 2992                           123                 :              7 :         in = SvRV(in);
    8 tgl@sss.pgh.pa.us         124         [ +  - ]:GNC           7 :         plperl_materialize_sv(in);
                                125                 :                :     }
                                126                 :                : 
                                127                 :                :     /* Now we must have a hash. */
                                128   [ +  -  +  + ]:              8 :     if (!in || SvTYPE(in) != SVt_PVHV)
 2992 tgl@sss.pgh.pa.us         129         [ +  - ]:CBC           2 :         ereport(ERROR,
                                130                 :                :                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
                                131                 :                :                  errmsg("cannot transform non-hash Perl value to hstore")));
                                132                 :              6 :     hv = (HV *) in;
                                133                 :                : 
   17                           134                 :              6 :     (void) hv_iterinit(hv);
                                135                 :                : 
                                136                 :              6 :     pcount = 64;                /* arbitrary initial guess */
  108 heikki.linnakangas@i      137                 :              6 :     pairs = palloc_array(Pairs, pcount);
                                138                 :                : 
 4141 peter_e@gmx.net           139                 :              6 :     i = 0;
                                140         [ +  + ]:             22 :     while ((he = hv_iternext(hv)))
                                141                 :                :     {
    9 tgl@sss.pgh.pa.us         142                 :GNC          16 :         char       *key = hek2cstr(he);
    8                           143                 :             16 :         SV         *value = hv_iterval(hv, he);
                                144                 :                : 
                                145         [ +  - ]:             16 :         plperl_materialize_sv(value);
                                146                 :                : 
   17 tgl@sss.pgh.pa.us         147         [ -  + ]:CBC          16 :         if (i >= pcount)
                                148                 :                :         {
   17 tgl@sss.pgh.pa.us         149                 :UBC           0 :             pcount *= 2;
                                150                 :              0 :             pairs = repalloc_array(pairs, Pairs, pcount);
                                151                 :                :         }
                                152                 :                : 
    9 tgl@sss.pgh.pa.us         153                 :GNC          16 :         pairs[i].key = key;
 4141 peter_e@gmx.net           154                 :CBC          16 :         pairs[i].keylen = hstoreCheckKeyLen(strlen(pairs[i].key));
                                155                 :             16 :         pairs[i].needfree = true;
                                156                 :                : 
    9 tgl@sss.pgh.pa.us         157   [ +  -  +  + ]:             16 :         if (!value || !SvOK(value))
                                158                 :                :         {
 4141 peter_e@gmx.net           159                 :              5 :             pairs[i].val = NULL;
                                160                 :              5 :             pairs[i].vallen = 0;
                                161                 :              5 :             pairs[i].isnull = true;
                                162                 :                :         }
                                163                 :                :         else
                                164                 :                :         {
    9 tgl@sss.pgh.pa.us         165                 :GNC          11 :             pairs[i].val = sv2cstr(value);
 4141 peter_e@gmx.net           166                 :CBC          11 :             pairs[i].vallen = hstoreCheckValLen(strlen(pairs[i].val));
                                167                 :             11 :             pairs[i].isnull = false;
                                168                 :                :         }
                                169                 :                : 
                                170                 :             16 :         i++;
                                171                 :                :     }
                                172                 :                : 
   17 tgl@sss.pgh.pa.us         173                 :              6 :     pcount = hstoreUniquePairs(pairs, i, &buflen);
 4141 peter_e@gmx.net           174                 :              6 :     out = hstorePairs(pairs, pcount, buflen);
                                175                 :              6 :     PG_RETURN_POINTER(out);
                                176                 :                : }
        

Generated by: LCOV version 2.0-1