LCOV - code coverage report
Current view: top level - src/pl/plperl - SPI.c (source / functions) Hit Total Coverage
Test: PostgreSQL 13devel Lines: 81 92 88.0 %
Date: 2019-11-21 12:06:29 Functions: 12 12 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * This file was generated automatically by ExtUtils::ParseXS version 3.31 from the
       3             :  * contents of SPI.xs. Do not edit this file, edit SPI.xs instead.
       4             :  *
       5             :  *    ANY CHANGES MADE HERE WILL BE LOST!
       6             :  *
       7             :  */
       8             : 
       9             : #line 1 "SPI.xs"
      10             : /**********************************************************************
      11             :  * PostgreSQL::InServer::SPI
      12             :  *
      13             :  * SPI interface for plperl.
      14             :  *
      15             :  *    src/pl/plperl/SPI.xs
      16             :  *
      17             :  **********************************************************************/
      18             : 
      19             : /* this must be first: */
      20             : #include "postgres.h"
      21             : 
      22             : /* perl stuff */
      23             : #define PG_NEED_PERL_XSUB_H
      24             : #include "plperl.h"
      25             : #include "plperl_helpers.h"
      26             : 
      27             : 
      28             : #line 29 "SPI.c"
      29             : #ifndef PERL_UNUSED_VAR
      30             : #  define PERL_UNUSED_VAR(var) if (0) var = var
      31             : #endif
      32             : 
      33             : #ifndef dVAR
      34             : #  define dVAR      dNOOP
      35             : #endif
      36             : 
      37             : 
      38             : /* This stuff is not part of the API! You have been warned. */
      39             : #ifndef PERL_VERSION_DECIMAL
      40             : #  define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
      41             : #endif
      42             : #ifndef PERL_DECIMAL_VERSION
      43             : #  define PERL_DECIMAL_VERSION \
      44             :       PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
      45             : #endif
      46             : #ifndef PERL_VERSION_GE
      47             : #  define PERL_VERSION_GE(r,v,s) \
      48             :       (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
      49             : #endif
      50             : #ifndef PERL_VERSION_LE
      51             : #  define PERL_VERSION_LE(r,v,s) \
      52             :       (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
      53             : #endif
      54             : 
      55             : /* XS_INTERNAL is the explicit static-linkage variant of the default
      56             :  * XS macro.
      57             :  *
      58             :  * XS_EXTERNAL is the same as XS_INTERNAL except it does not include
      59             :  * "STATIC", ie. it exports XSUB symbols. You probably don't want that
      60             :  * for anything but the BOOT XSUB.
      61             :  *
      62             :  * See XSUB.h in core!
      63             :  */
      64             : 
      65             : 
      66             : /* TODO: This might be compatible further back than 5.10.0. */
      67             : #if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
      68             : #  undef XS_EXTERNAL
      69             : #  undef XS_INTERNAL
      70             : #  if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
      71             : #    define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
      72             : #    define XS_INTERNAL(name) STATIC XSPROTO(name)
      73             : #  endif
      74             : #  if defined(__SYMBIAN32__)
      75             : #    define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
      76             : #    define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
      77             : #  endif
      78             : #  ifndef XS_EXTERNAL
      79             : #    if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
      80             : #      define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
      81             : #      define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
      82             : #    else
      83             : #      ifdef __cplusplus
      84             : #        define XS_EXTERNAL(name) extern "C" XSPROTO(name)
      85             : #        define XS_INTERNAL(name) static XSPROTO(name)
      86             : #      else
      87             : #        define XS_EXTERNAL(name) XSPROTO(name)
      88             : #        define XS_INTERNAL(name) STATIC XSPROTO(name)
      89             : #      endif
      90             : #    endif
      91             : #  endif
      92             : #endif
      93             : 
      94             : /* perl >= 5.10.0 && perl <= 5.15.1 */
      95             : 
      96             : 
      97             : /* The XS_EXTERNAL macro is used for functions that must not be static
      98             :  * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
      99             :  * macro defined, the best we can do is assume XS is the same.
     100             :  * Dito for XS_INTERNAL.
     101             :  */
     102             : #ifndef XS_EXTERNAL
     103             : #  define XS_EXTERNAL(name) XS(name)
     104             : #endif
     105             : #ifndef XS_INTERNAL
     106             : #  define XS_INTERNAL(name) XS(name)
     107             : #endif
     108             : 
     109             : /* Now, finally, after all this mess, we want an ExtUtils::ParseXS
     110             :  * internal macro that we're free to redefine for varying linkage due
     111             :  * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
     112             :  * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
     113             :  */
     114             : 
     115             : #undef XS_EUPXS
     116             : #if defined(PERL_EUPXS_ALWAYS_EXPORT)
     117             : #  define XS_EUPXS(name) XS_EXTERNAL(name)
     118             : #else
     119             :    /* default to internal */
     120             : #  define XS_EUPXS(name) XS_INTERNAL(name)
     121             : #endif
     122             : 
     123             : #ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
     124             : #define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)
     125             : 
     126             : /* prototype to pass -Wmissing-prototypes */
     127             : STATIC void
     128             : S_croak_xs_usage(const CV *const cv, const char *const params);
     129             : 
     130             : STATIC void
     131             : S_croak_xs_usage(const CV *const cv, const char *const params)
     132             : {
     133             :     const GV *const gv = CvGV(cv);
     134             : 
     135             :     PERL_ARGS_ASSERT_CROAK_XS_USAGE;
     136             : 
     137             :     if (gv) {
     138             :         const char *const gvname = GvNAME(gv);
     139             :         const HV *const stash = GvSTASH(gv);
     140             :         const char *const hvname = stash ? HvNAME(stash) : NULL;
     141             : 
     142             :         if (hvname)
     143             :         Perl_croak_nocontext("Usage: %s::%s(%s)", hvname, gvname, params);
     144             :         else
     145             :         Perl_croak_nocontext("Usage: %s(%s)", gvname, params);
     146             :     } else {
     147             :         /* Pants. I don't think that it should be possible to get here. */
     148             :     Perl_croak_nocontext("Usage: CODE(0x%"UVxf")(%s)", PTR2UV(cv), params);
     149             :     }
     150             : }
     151             : #undef  PERL_ARGS_ASSERT_CROAK_XS_USAGE
     152             : 
     153             : #define croak_xs_usage        S_croak_xs_usage
     154             : 
     155             : #endif
     156             : 
     157             : /* NOTE: the prototype of newXSproto() is different in versions of perls,
     158             :  * so we define a portable version of newXSproto()
     159             :  */
     160             : #ifdef newXS_flags
     161             : #define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
     162             : #else
     163             : #define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
     164             : #endif /* !defined(newXS_flags) */
     165             : 
     166             : #if PERL_VERSION_LE(5, 21, 5)
     167             : #  define newXS_deffile(a,b) Perl_newXS(aTHX_ a,b,file)
     168             : #else
     169             : #  define newXS_deffile(a,b) Perl_newXS_deffile(aTHX_ a,b)
     170             : #endif
     171             : 
     172             : #line 173 "SPI.c"
     173             : 
     174             : XS_EUPXS(XS__spi_exec_query); /* prototype to pass -Wmissing-prototypes */
     175         100 : XS_EUPXS(XS__spi_exec_query)
     176             : {
     177         100 :     dVAR; dXSARGS;
     178         100 :     if (items < 1)
     179           0 :        croak_xs_usage(cv,  "sv, ...");
     180             :     {
     181         100 :     SV* sv = ST(0)
     182             : ;
     183             : #line 28 "SPI.xs"
     184             :         HV *ret_hash;
     185             :         int limit = 0;
     186             :         char *query;
     187             : #line 188 "SPI.c"
     188             :     SV *    RETVAL;
     189             : #line 32 "SPI.xs"
     190             :         if (items > 2)
     191             :             croak("Usage: spi_exec_query(query, limit) "
     192             :                   "or spi_exec_query(query)");
     193             :         if (items == 2)
     194             :             limit = SvIV(ST(1));
     195             :         query = sv2cstr(sv);
     196             :         ret_hash = plperl_spi_exec(query, limit);
     197             :         pfree(query);
     198             :         RETVAL = newRV_noinc((SV*) ret_hash);
     199             : #line 200 "SPI.c"
     200          88 :     RETVAL = sv_2mortal(RETVAL);
     201          88 :     ST(0) = RETVAL;
     202             :     }
     203          88 :     XSRETURN(1);
     204             : }
     205             : 
     206             : 
     207             : XS_EUPXS(XS__return_next); /* prototype to pass -Wmissing-prototypes */
     208         174 : XS_EUPXS(XS__return_next)
     209             : {
     210         174 :     dVAR; dXSARGS;
     211         174 :     if (items != 1)
     212           0 :        croak_xs_usage(cv,  "rv");
     213             :     {
     214         174 :     SV *    rv = ST(0)
     215             : ;
     216             : #line 48 "SPI.xs"
     217             :         plperl_return_next(rv);
     218             : #line 219 "SPI.c"
     219             :     }
     220         174 :     XSRETURN_EMPTY;
     221             : }
     222             : 
     223             : 
     224             : XS_EUPXS(XS__spi_query); /* prototype to pass -Wmissing-prototypes */
     225          18 : XS_EUPXS(XS__spi_query)
     226             : {
     227          18 :     dVAR; dXSARGS;
     228          18 :     if (items != 1)
     229           0 :        croak_xs_usage(cv,  "sv");
     230             :     {
     231          18 :     SV *    sv = ST(0)
     232             : ;
     233             :     SV *    RETVAL;
     234             : #line 54 "SPI.xs"
     235             :         char* query = sv2cstr(sv);
     236             :         RETVAL = plperl_spi_query(query);
     237             :         pfree(query);
     238             : #line 239 "SPI.c"
     239          18 :     RETVAL = sv_2mortal(RETVAL);
     240          18 :     ST(0) = RETVAL;
     241             :     }
     242          18 :     XSRETURN(1);
     243             : }
     244             : 
     245             : 
     246             : XS_EUPXS(XS__spi_fetchrow); /* prototype to pass -Wmissing-prototypes */
     247          72 : XS_EUPXS(XS__spi_fetchrow)
     248             : {
     249          72 :     dVAR; dXSARGS;
     250          72 :     if (items != 1)
     251           0 :        croak_xs_usage(cv,  "sv");
     252             :     {
     253          72 :     SV* sv = ST(0)
     254             : ;
     255             :     SV *    RETVAL;
     256             : #line 64 "SPI.xs"
     257             :         char* cursor = sv2cstr(sv);
     258             :         RETVAL = plperl_spi_fetchrow(cursor);
     259             :         pfree(cursor);
     260             : #line 261 "SPI.c"
     261          72 :     RETVAL = sv_2mortal(RETVAL);
     262          72 :     ST(0) = RETVAL;
     263             :     }
     264          72 :     XSRETURN(1);
     265             : }
     266             : 
     267             : 
     268             : XS_EUPXS(XS__spi_prepare); /* prototype to pass -Wmissing-prototypes */
     269          16 : XS_EUPXS(XS__spi_prepare)
     270             : {
     271          16 :     dVAR; dXSARGS;
     272          16 :     if (items < 1)
     273           0 :        croak_xs_usage(cv,  "sv, ...");
     274             :     {
     275          16 :     SV* sv = ST(0)
     276             : ;
     277             :     SV *    RETVAL;
     278             : #line 74 "SPI.xs"
     279             :         int i;
     280             :         SV** argv;
     281             :         char* query = sv2cstr(sv);
     282             :         if (items < 1)
     283             :             Perl_croak(aTHX_ "Usage: spi_prepare(query, ...)");
     284             :         argv = ( SV**) palloc(( items - 1) * sizeof(SV*));
     285             :         for ( i = 1; i < items; i++)
     286             :             argv[i - 1] = ST(i);
     287             :         RETVAL = plperl_spi_prepare(query, items - 1, argv);
     288             :         pfree( argv);
     289             :         pfree(query);
     290             : #line 291 "SPI.c"
     291          14 :     RETVAL = sv_2mortal(RETVAL);
     292          14 :     ST(0) = RETVAL;
     293             :     }
     294          14 :     XSRETURN(1);
     295             : }
     296             : 
     297             : 
     298             : XS_EUPXS(XS__spi_exec_prepared); /* prototype to pass -Wmissing-prototypes */
     299          12 : XS_EUPXS(XS__spi_exec_prepared)
     300             : {
     301          12 :     dVAR; dXSARGS;
     302          12 :     if (items < 1)
     303           0 :        croak_xs_usage(cv,  "sv, ...");
     304             :     {
     305          12 :     SV* sv = ST(0)
     306             : ;
     307             : #line 92 "SPI.xs"
     308             :         HV *ret_hash;
     309             : #line 310 "SPI.c"
     310             :     SV *    RETVAL;
     311             : #line 94 "SPI.xs"
     312             :         HV *attr = NULL;
     313             :         int i, offset = 1, argc;
     314             :         SV ** argv;
     315             :         char *query = sv2cstr(sv);
     316             :         if ( items < 1)
     317             :             Perl_croak(aTHX_ "Usage: spi_exec_prepared(query, [\\%%attr,] "
     318             :                        "[\\@bind_values])");
     319             :         if ( items > 1 && SvROK( ST( 1)) && SvTYPE( SvRV( ST( 1))) == SVt_PVHV)
     320             :         {
     321             :             attr = ( HV*) SvRV(ST(1));
     322             :             offset++;
     323             :         }
     324             :         argc = items - offset;
     325             :         argv = ( SV**) palloc( argc * sizeof(SV*));
     326             :         for ( i = 0; offset < items; offset++, i++)
     327             :             argv[i] = ST(offset);
     328             :         ret_hash = plperl_spi_exec_prepared(query, attr, argc, argv);
     329             :         RETVAL = newRV_noinc((SV*)ret_hash);
     330             :         pfree( argv);
     331             :         pfree(query);
     332             : #line 333 "SPI.c"
     333          12 :     RETVAL = sv_2mortal(RETVAL);
     334          12 :     ST(0) = RETVAL;
     335             :     }
     336          12 :     XSRETURN(1);
     337             : }
     338             : 
     339             : 
     340             : XS_EUPXS(XS__spi_query_prepared); /* prototype to pass -Wmissing-prototypes */
     341           4 : XS_EUPXS(XS__spi_query_prepared)
     342             : {
     343           4 :     dVAR; dXSARGS;
     344           4 :     if (items < 1)
     345           0 :        croak_xs_usage(cv,  "sv, ...");
     346             :     {
     347           4 :     SV *    sv = ST(0)
     348             : ;
     349             :     SV *    RETVAL;
     350             : #line 121 "SPI.xs"
     351             :         int i;
     352             :         SV ** argv;
     353             :         char *query = sv2cstr(sv);
     354             :         if ( items < 1)
     355             :             Perl_croak(aTHX_ "Usage: spi_query_prepared(query, "
     356             :                        "[\\@bind_values])");
     357             :         argv = ( SV**) palloc(( items - 1) * sizeof(SV*));
     358             :         for ( i = 1; i < items; i++)
     359             :             argv[i - 1] = ST(i);
     360             :         RETVAL = plperl_spi_query_prepared(query, items - 1, argv);
     361             :         pfree( argv);
     362             :         pfree(query);
     363             : #line 364 "SPI.c"
     364           4 :     RETVAL = sv_2mortal(RETVAL);
     365           4 :     ST(0) = RETVAL;
     366             :     }
     367           4 :     XSRETURN(1);
     368             : }
     369             : 
     370             : 
     371             : XS_EUPXS(XS__spi_freeplan); /* prototype to pass -Wmissing-prototypes */
     372          10 : XS_EUPXS(XS__spi_freeplan)
     373             : {
     374          10 :     dVAR; dXSARGS;
     375          10 :     if (items != 1)
     376           0 :        croak_xs_usage(cv,  "sv");
     377             :     {
     378          10 :     SV *    sv = ST(0)
     379             : ;
     380             : #line 140 "SPI.xs"
     381             :         char *query = sv2cstr(sv);
     382             :         plperl_spi_freeplan(query);
     383             :         pfree(query);
     384             : #line 385 "SPI.c"
     385             :     }
     386          10 :     XSRETURN_EMPTY;
     387             : }
     388             : 
     389             : 
     390             : XS_EUPXS(XS__spi_cursor_close); /* prototype to pass -Wmissing-prototypes */
     391           2 : XS_EUPXS(XS__spi_cursor_close)
     392             : {
     393           2 :     dVAR; dXSARGS;
     394           2 :     if (items != 1)
     395           0 :        croak_xs_usage(cv,  "sv");
     396             :     {
     397           2 :     SV *    sv = ST(0)
     398             : ;
     399             : #line 148 "SPI.xs"
     400             :         char *cursor = sv2cstr(sv);
     401             :         plperl_spi_cursor_close(cursor);
     402             :         pfree(cursor);
     403             : #line 404 "SPI.c"
     404             :     }
     405           2 :     XSRETURN_EMPTY;
     406             : }
     407             : 
     408             : 
     409             : XS_EUPXS(XS__spi_commit); /* prototype to pass -Wmissing-prototypes */
     410          46 : XS_EUPXS(XS__spi_commit)
     411             : {
     412          46 :     dVAR; dXSARGS;
     413          46 :     if (items != 0)
     414           0 :        croak_xs_usage(cv,  "");
     415             :     {
     416             : #line 155 "SPI.xs"
     417             :         plperl_spi_commit();
     418             : #line 419 "SPI.c"
     419             :     }
     420          40 :     XSRETURN_EMPTY;
     421             : }
     422             : 
     423             : 
     424             : XS_EUPXS(XS__spi_rollback); /* prototype to pass -Wmissing-prototypes */
     425          34 : XS_EUPXS(XS__spi_rollback)
     426             : {
     427          34 :     dVAR; dXSARGS;
     428          34 :     if (items != 0)
     429           0 :        croak_xs_usage(cv,  "");
     430             :     {
     431             : #line 160 "SPI.xs"
     432             :         plperl_spi_rollback();
     433             : #line 434 "SPI.c"
     434             :     }
     435          34 :     XSRETURN_EMPTY;
     436             : }
     437             : 
     438             : #ifdef __cplusplus
     439             : extern "C"
     440             : #endif
     441             : XS_EXTERNAL(boot_PostgreSQL__InServer__SPI); /* prototype to pass -Wmissing-prototypes */
     442          32 : XS_EXTERNAL(boot_PostgreSQL__InServer__SPI)
     443             : {
     444             : #if PERL_VERSION_LE(5, 21, 5)
     445             :     dVAR; dXSARGS;
     446             : #else
     447          32 :     dVAR; dXSBOOTARGSAPIVERCHK;
     448             : #endif
     449             : #if (PERL_REVISION == 5 && PERL_VERSION < 9)
     450             :     char* file = __FILE__;
     451             : #else
     452          32 :     const char* file = __FILE__;
     453             : #endif
     454             : 
     455             :     PERL_UNUSED_VAR(file);
     456             : 
     457             :     PERL_UNUSED_VAR(cv); /* -W */
     458             :     PERL_UNUSED_VAR(items); /* -W */
     459             : #if PERL_VERSION_LE(5, 21, 5) && defined(XS_APIVERSION_BOOTCHECK)
     460             :   XS_APIVERSION_BOOTCHECK;
     461             : #endif
     462             : 
     463          32 :         (void)newXSproto_portable("spi_exec_query", XS__spi_exec_query, file, "$;@");
     464          32 :         (void)newXSproto_portable("return_next", XS__return_next, file, "$");
     465          32 :         (void)newXSproto_portable("spi_query", XS__spi_query, file, "$");
     466          32 :         (void)newXSproto_portable("spi_fetchrow", XS__spi_fetchrow, file, "$");
     467          32 :         (void)newXSproto_portable("spi_prepare", XS__spi_prepare, file, "$;@");
     468          32 :         (void)newXSproto_portable("spi_exec_prepared", XS__spi_exec_prepared, file, "$;@");
     469          32 :         (void)newXSproto_portable("spi_query_prepared", XS__spi_query_prepared, file, "$;@");
     470          32 :         (void)newXSproto_portable("spi_freeplan", XS__spi_freeplan, file, "$");
     471          32 :         (void)newXSproto_portable("spi_cursor_close", XS__spi_cursor_close, file, "$");
     472          32 :         (void)newXSproto_portable("spi_commit", XS__spi_commit, file, "");
     473          32 :         (void)newXSproto_portable("spi_rollback", XS__spi_rollback, file, "");
     474             : 
     475             :     /* Initialisation Section */
     476             : 
     477             : #line 163 "SPI.xs"
     478             :     items = 0;  /* avoid 'unused variable' warning */
     479             : 
     480             : #line 481 "SPI.c"
     481             : 
     482             :     /* End of Initialisation Section */
     483             : 
     484             : #if PERL_VERSION_LE(5, 21, 5)
     485             : #  if PERL_VERSION_GE(5, 9, 0)
     486             :     if (PL_unitcheckav)
     487             :         call_list(PL_scopestack_ix, PL_unitcheckav);
     488             : #  endif
     489             :     XSRETURN_YES;
     490             : #else
     491          32 :     Perl_xs_boot_epilog(aTHX_ ax);
     492             : #endif
     493          32 : }
     494             : 

Generated by: LCOV version 1.13