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

Generated by: LCOV version 1.14