LCOV - differential code coverage report
Current view: top level - src/pl/plperl - Util.xs (source / functions) Coverage Total Hit UBC CBC
Current: Differential Code Coverage HEAD vs 15 Lines: 96.0 % 50 48 2 48
Current Date: 2023-04-08 15:15:32 Functions: 100.0 % 1 1 1
Baseline: 15
Baseline Date: 2023-04-08 15:09:40
Legend: Lines: hit not hit

           TLA  Line data    Source code
       1                 : /**********************************************************************
       2                 :  * PostgreSQL::InServer::Util
       3                 :  *
       4                 :  * src/pl/plperl/Util.xs
       5                 :  *
       6                 :  * Defines plperl interfaces for general-purpose utilities.
       7                 :  * This module is bootstrapped as soon as an interpreter is initialized.
       8                 :  * Currently doesn't define a PACKAGE= so all subs are in main:: to avoid
       9                 :  * the need for explicit importing.
      10                 :  *
      11                 :  **********************************************************************/
      12                 : 
      13                 : /* this must be first: */
      14                 : #include "postgres.h"
      15                 : 
      16                 : #include "fmgr.h"
      17                 : #include "utils/builtins.h"
      18                 : #include "utils/bytea.h"       /* for byteain & byteaout */
      19                 : #include "varatt.h"
      20                 : 
      21                 : /* perl stuff */
      22                 : #define PG_NEED_PERL_XSUB_H
      23                 : #include "plperl.h"
      24                 : 
      25                 : 
      26                 : static text *
      27 CBC          42 : sv2text(SV *sv)
      28                 : {
      29              42 :     char       *str = sv2cstr(sv);
      30                 :     text       *text;
      31                 : 
      32              42 :     text = cstring_to_text(str);
      33              42 :     pfree(str);
      34              42 :     return text;
      35                 : }
      36                 : 
      37                 : MODULE = PostgreSQL::InServer::Util PREFIX = util_
      38                 : 
      39                 : PROTOTYPES: ENABLE
      40                 : VERSIONCHECK: DISABLE
      41                 : 
      42                 : int
      43                 : _aliased_constants()
      44                 :     PROTOTYPE:
      45                 :     ALIAS:
      46                 :         DEBUG   = DEBUG2
      47                 :         LOG     = LOG
      48                 :         INFO    = INFO
      49                 :         NOTICE  = NOTICE
      50                 :         WARNING = WARNING
      51                 :         ERROR   = ERROR
      52                 :     CODE:
      53                 :     /* uses the ALIAS value as the return value */
      54             184 :     RETVAL = ix;
      55                 :     OUTPUT:
      56                 :     RETVAL
      57                 : 
      58                 : 
      59                 : void
      60                 : util_elog(level, msg)
      61                 :     int level
      62                 :     SV *msg
      63                 :     CODE:
      64             184 :         if (level > ERROR)      /* no PANIC allowed thanks */
      65 UBC           0 :             level = ERROR;
      66 CBC         184 :         if (level < DEBUG5)
      67 UBC           0 :             level = DEBUG5;
      68 CBC         184 :         plperl_util_elog(level, msg);
      69                 : 
      70                 : SV *
      71                 : util_quote_literal(sv)
      72                 :     SV *sv
      73                 :     CODE:
      74               7 :     if (!sv || !SvOK(sv)) {
      75               1 :         RETVAL = &PL_sv_undef;
      76                 :     }
      77                 :     else {
      78               6 :         text *arg = sv2text(sv);
      79               6 :         text *quoted = DatumGetTextPP(DirectFunctionCall1(quote_literal, PointerGetDatum(arg)));
      80                 :         char *str;
      81                 : 
      82               6 :         pfree(arg);
      83               6 :         str = text_to_cstring(quoted);
      84               6 :         RETVAL = cstr2sv(str);
      85               6 :         pfree(str);
      86                 :     }
      87                 :     OUTPUT:
      88                 :     RETVAL
      89                 : 
      90                 : SV *
      91                 : util_quote_nullable(sv)
      92                 :     SV *sv
      93                 :     CODE:
      94              30 :     if (!sv || !SvOK(sv))
      95                 :     {
      96               2 :         RETVAL = cstr2sv("NULL");
      97                 :     }
      98                 :     else
      99                 :     {
     100              28 :         text *arg = sv2text(sv);
     101              28 :         text *quoted = DatumGetTextPP(DirectFunctionCall1(quote_nullable, PointerGetDatum(arg)));
     102                 :         char *str;
     103                 : 
     104              28 :         pfree(arg);
     105              28 :         str = text_to_cstring(quoted);
     106              28 :         RETVAL = cstr2sv(str);
     107              28 :         pfree(str);
     108                 :     }
     109                 :     OUTPUT:
     110                 :     RETVAL
     111                 : 
     112                 : SV *
     113                 : util_quote_ident(sv)
     114                 :     SV *sv
     115                 :     PREINIT:
     116                 :         text *arg;
     117                 :         text *quoted;
     118                 :         char *str;
     119                 :     CODE:
     120               8 :         arg = sv2text(sv);
     121               8 :         quoted = DatumGetTextPP(DirectFunctionCall1(quote_ident, PointerGetDatum(arg)));
     122                 : 
     123               8 :         pfree(arg);
     124               8 :         str = text_to_cstring(quoted);
     125               8 :         RETVAL = cstr2sv(str);
     126               8 :         pfree(str);
     127                 :     OUTPUT:
     128                 :     RETVAL
     129                 : 
     130                 : SV *
     131                 : util_decode_bytea(sv)
     132                 :     SV *sv
     133                 :     PREINIT:
     134                 :         char *arg;
     135                 :         text *ret;
     136                 :     CODE:
     137               4 :         arg = SvPVbyte_nolen(sv);
     138               4 :         ret = DatumGetTextPP(DirectFunctionCall1(byteain, PointerGetDatum(arg)));
     139                 :         /* not cstr2sv because this is raw bytes not utf8'able */
     140               4 :         RETVAL = newSVpvn(VARDATA_ANY(ret), VARSIZE_ANY_EXHDR(ret));
     141                 :     OUTPUT:
     142                 :     RETVAL
     143                 : 
     144                 : SV *
     145                 : util_encode_bytea(sv)
     146                 :     SV *sv
     147                 :     PREINIT:
     148                 :         text *arg;
     149                 :         char *ret;
     150                 :         STRLEN len;
     151                 :     CODE:
     152                 :         /* not sv2text because this is raw bytes not utf8'able */
     153               5 :         ret = SvPVbyte(sv, len);
     154               5 :         arg = cstring_to_text_with_len(ret, len);
     155               5 :         ret = DatumGetCString(DirectFunctionCall1(byteaout, PointerGetDatum(arg)));
     156               5 :         RETVAL = cstr2sv(ret);
     157                 :     OUTPUT:
     158                 :     RETVAL
     159                 : 
     160                 : SV *
     161                 : looks_like_number(sv)
     162                 :     SV *sv
     163                 :     CODE:
     164              11 :     if (!SvOK(sv))
     165               1 :         RETVAL = &PL_sv_undef;
     166              10 :     else if ( looks_like_number(sv) )
     167               6 :         RETVAL = &PL_sv_yes;
     168                 :     else
     169               4 :         RETVAL = &PL_sv_no;
     170                 :     OUTPUT:
     171                 :     RETVAL
     172                 : 
     173                 : SV *
     174                 : encode_typed_literal(sv, typname)
     175                 :     SV     *sv
     176                 :     char   *typname;
     177                 :     PREINIT:
     178                 :         char    *outstr;
     179                 :     CODE:
     180              16 :         outstr = plperl_sv_to_literal(sv, typname);
     181              15 :         if (outstr == NULL)
     182               1 :             RETVAL = &PL_sv_undef;
     183                 :         else
     184              14 :             RETVAL = cstr2sv(outstr);
     185                 :     OUTPUT:
     186                 :     RETVAL
     187                 : 
     188                 : BOOT:
     189              23 :     items = 0;  /* avoid 'unused variable' warning */
        

Generated by: LCOV version v1.16-55-g56c0a2a