LCOV - code coverage report
Current view: top level - src/pl/plperl - SPI.c (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 88.0 % 92 81
Test Date: 2026-02-17 17:20:33 Functions: 100.0 % 12 12
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /*
       2              :  * This file was generated automatically by ExtUtils::ParseXS version 3.51 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           57 : XS_EUPXS(XS__spi_exec_query)
     175              : {
     176           57 :     dVAR; dXSARGS;
     177           57 :     if (items < 1)
     178            0 :        croak_xs_usage(cv,  "sv, ...");
     179              :     {
     180           57 :     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           51 :     RETVAL = sv_2mortal(RETVAL);
     200           51 :     ST(0) = RETVAL;
     201              :     }
     202           51 :     XSRETURN(1);
     203              : }
     204              : 
     205              : 
     206              : XS_EUPXS(XS__return_next); /* prototype to pass -Wmissing-prototypes */
     207           87 : XS_EUPXS(XS__return_next)
     208              : {
     209           87 :     dVAR; dXSARGS;
     210           87 :     if (items != 1)
     211            0 :        croak_xs_usage(cv,  "rv");
     212              :     {
     213           87 :     SV *    rv = ST(0)
     214              : ;
     215              : #line 47 "SPI.xs"
     216              :         plperl_return_next(rv);
     217              : #line 218 "SPI.c"
     218              :     }
     219           87 :     XSRETURN_EMPTY;
     220              : }
     221              : 
     222              : 
     223              : XS_EUPXS(XS__spi_query); /* prototype to pass -Wmissing-prototypes */
     224            9 : XS_EUPXS(XS__spi_query)
     225              : {
     226            9 :     dVAR; dXSARGS;
     227            9 :     if (items != 1)
     228            0 :        croak_xs_usage(cv,  "sv");
     229              :     {
     230            9 :     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            9 :     RETVAL = sv_2mortal(RETVAL);
     239            9 :     ST(0) = RETVAL;
     240              :     }
     241            9 :     XSRETURN(1);
     242              : }
     243              : 
     244              : 
     245              : XS_EUPXS(XS__spi_fetchrow); /* prototype to pass -Wmissing-prototypes */
     246           36 : XS_EUPXS(XS__spi_fetchrow)
     247              : {
     248           36 :     dVAR; dXSARGS;
     249           36 :     if (items != 1)
     250            0 :        croak_xs_usage(cv,  "sv");
     251              :     {
     252           36 :     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           36 :     RETVAL = sv_2mortal(RETVAL);
     261           36 :     ST(0) = RETVAL;
     262              :     }
     263           36 :     XSRETURN(1);
     264              : }
     265              : 
     266              : 
     267              : XS_EUPXS(XS__spi_prepare); /* prototype to pass -Wmissing-prototypes */
     268            8 : XS_EUPXS(XS__spi_prepare)
     269              : {
     270            8 :     dVAR; dXSARGS;
     271            8 :     if (items < 1)
     272            0 :        croak_xs_usage(cv,  "sv, ...");
     273              :     {
     274            8 :     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            7 :     RETVAL = sv_2mortal(RETVAL);
     291            7 :     ST(0) = RETVAL;
     292              :     }
     293            7 :     XSRETURN(1);
     294              : }
     295              : 
     296              : 
     297              : XS_EUPXS(XS__spi_exec_prepared); /* prototype to pass -Wmissing-prototypes */
     298            6 : XS_EUPXS(XS__spi_exec_prepared)
     299              : {
     300            6 :     dVAR; dXSARGS;
     301            6 :     if (items < 1)
     302            0 :        croak_xs_usage(cv,  "sv, ...");
     303              :     {
     304            6 :     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            6 :     RETVAL = sv_2mortal(RETVAL);
     333            6 :     ST(0) = RETVAL;
     334              :     }
     335            6 :     XSRETURN(1);
     336              : }
     337              : 
     338              : 
     339              : XS_EUPXS(XS__spi_query_prepared); /* prototype to pass -Wmissing-prototypes */
     340            2 : XS_EUPXS(XS__spi_query_prepared)
     341              : {
     342            2 :     dVAR; dXSARGS;
     343            2 :     if (items < 1)
     344            0 :        croak_xs_usage(cv,  "sv, ...");
     345              :     {
     346            2 :     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            2 :     RETVAL = sv_2mortal(RETVAL);
     364            2 :     ST(0) = RETVAL;
     365              :     }
     366            2 :     XSRETURN(1);
     367              : }
     368              : 
     369              : 
     370              : XS_EUPXS(XS__spi_freeplan); /* prototype to pass -Wmissing-prototypes */
     371            5 : XS_EUPXS(XS__spi_freeplan)
     372              : {
     373            5 :     dVAR; dXSARGS;
     374            5 :     if (items != 1)
     375            0 :        croak_xs_usage(cv,  "sv");
     376              :     {
     377            5 :     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            5 :     XSRETURN_EMPTY;
     386              : }
     387              : 
     388              : 
     389              : XS_EUPXS(XS__spi_cursor_close); /* prototype to pass -Wmissing-prototypes */
     390            1 : XS_EUPXS(XS__spi_cursor_close)
     391              : {
     392            1 :     dVAR; dXSARGS;
     393            1 :     if (items != 1)
     394            0 :        croak_xs_usage(cv,  "sv");
     395              :     {
     396            1 :     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            1 :     XSRETURN_EMPTY;
     405              : }
     406              : 
     407              : 
     408              : XS_EUPXS(XS__spi_commit); /* prototype to pass -Wmissing-prototypes */
     409           25 : XS_EUPXS(XS__spi_commit)
     410              : {
     411           25 :     dVAR; dXSARGS;
     412           25 :     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           20 :     XSRETURN_EMPTY;
     420              : }
     421              : 
     422              : 
     423              : XS_EUPXS(XS__spi_rollback); /* prototype to pass -Wmissing-prototypes */
     424           17 : XS_EUPXS(XS__spi_rollback)
     425              : {
     426           17 :     dVAR; dXSARGS;
     427           17 :     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           17 :     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           22 : XS_EXTERNAL(boot_PostgreSQL__InServer__SPI)
     442              : {
     443              : #if PERL_VERSION_LE(5, 21, 5)
     444              :     dVAR; dXSARGS;
     445              : #else
     446           22 :     dVAR; dXSBOOTARGSAPIVERCHK;
     447              : #endif
     448              : #if PERL_VERSION_LE(5, 8, 999) /* PERL_VERSION_LT is 5.33+ */
     449              :     char* file = __FILE__;
     450              : #else
     451           22 :     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           22 :         (void)newXSproto_portable("spi_exec_query", XS__spi_exec_query, file, "$;@");
     463           22 :         (void)newXSproto_portable("return_next", XS__return_next, file, "$");
     464           22 :         (void)newXSproto_portable("spi_query", XS__spi_query, file, "$");
     465           22 :         (void)newXSproto_portable("spi_fetchrow", XS__spi_fetchrow, file, "$");
     466           22 :         (void)newXSproto_portable("spi_prepare", XS__spi_prepare, file, "$;@");
     467           22 :         (void)newXSproto_portable("spi_exec_prepared", XS__spi_exec_prepared, file, "$;@");
     468           22 :         (void)newXSproto_portable("spi_query_prepared", XS__spi_query_prepared, file, "$;@");
     469           22 :         (void)newXSproto_portable("spi_freeplan", XS__spi_freeplan, file, "$");
     470           22 :         (void)newXSproto_portable("spi_cursor_close", XS__spi_cursor_close, file, "$");
     471           22 :         (void)newXSproto_portable("spi_commit", XS__spi_commit, file, "");
     472           22 :         (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           22 :     Perl_xs_boot_epilog(aTHX_ ax);
     491              : #endif
     492           22 : }
     493              : 
     494              : #ifdef __cplusplus
     495              : }
     496              : #endif
        

Generated by: LCOV version 2.0-1