1 /*------------------------------------------------------------------------- 2 * 3 * plperl.h 4 * Common include file for PL/Perl files 5 * 6 * This should be included _AFTER_ postgres.h and system include files 7 * 8 * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group 9 * Portions Copyright (c) 1995, Regents of the University of California 10 * 11 * src/pl/plperl/plperl.h 12 */ 13 14 #ifndef PL_PERL_H 15 #define PL_PERL_H 16 17 /* stop perl headers from hijacking stdio and other stuff on Windows */ 18 #ifdef WIN32 19 #define WIN32IO_IS_STDIO 20 #endif /* WIN32 */ 21 22 /* 23 * Supply a value of PERL_UNUSED_DECL that will satisfy gcc - the one 24 * perl itself supplies doesn't seem to. 25 */ 26 #define PERL_UNUSED_DECL pg_attribute_unused() 27 28 /* 29 * Sometimes perl carefully scribbles on our *printf macros. 30 * So we undefine them here and redefine them after it's done its dirty deed. 31 */ 32 33 #ifdef USE_REPL_SNPRINTF 34 #undef snprintf 35 #undef vsnprintf 36 #endif 37 38 /* 39 * ActivePerl 5.18 and later are MinGW-built, and their headers use GCC's 40 * __inline__. Translate to something MSVC recognizes. 41 */ 42 #ifdef _MSC_VER 43 #define __inline__ inline 44 #endif 45 46 /* 47 * Regarding bool, both PostgreSQL and Perl might use stdbool.h or not, 48 * depending on configuration. If both agree, things are relatively harmless. 49 * If not, things get tricky. If PostgreSQL does but Perl does not, define 50 * HAS_BOOL here so that Perl does not redefine bool; this avoids compiler 51 * warnings. If PostgreSQL does not but Perl does, we need to undefine bool 52 * after we include the Perl headers; see below. 53 */ 54 #ifdef USE_STDBOOL 55 #define HAS_BOOL 1 56 #endif 57 58 59 /* 60 * Get the basic Perl API. We use PERL_NO_GET_CONTEXT mode so that our code 61 * can compile against MULTIPLICITY Perl builds without including XSUB.h. 62 */ 63 #define PERL_NO_GET_CONTEXT 64 #include "EXTERN.h" 65 #include "perl.h" 66 67 /* 68 * We want to include XSUB.h only within .xs files, because on some platforms 69 * it undesirably redefines a lot of libc functions. But it must appear 70 * before ppport.h, so use a #define flag to control inclusion here. 71 */ 72 #ifdef PG_NEED_PERL_XSUB_H 73 /* 74 * On Windows, port_win32.h defines macros for a lot of these same functions. 75 * To avoid compiler warnings when XSUB.h redefines them, #undef our versions. 76 */ 77 #ifdef WIN32 78 #undef accept 79 #undef bind 80 #undef connect 81 #undef fopen 82 #undef kill 83 #undef listen 84 #undef lstat 85 #undef mkdir 86 #undef open 87 #undef putenv 88 #undef recv 89 #undef rename 90 #undef select 91 #undef send 92 #undef socket 93 #undef stat 94 #undef unlink 95 #undef vfprintf 96 #endif 97 98 #include "XSUB.h" 99 #endif 100 101 /* put back our snprintf and vsnprintf */ 102 #ifdef USE_REPL_SNPRINTF 103 #ifdef snprintf 104 #undef snprintf 105 #endif 106 #ifdef vsnprintf 107 #undef vsnprintf 108 #endif 109 #ifdef __GNUC__ 110 #define vsnprintf(...) pg_vsnprintf(__VA_ARGS__) 111 #define snprintf(...) pg_snprintf(__VA_ARGS__) 112 #else 113 #define vsnprintf pg_vsnprintf 114 #define snprintf pg_snprintf 115 #endif /* __GNUC__ */ 116 #endif /* USE_REPL_SNPRINTF */ 117 118 /* perl version and platform portability */ 119 #define NEED_eval_pv 120 #define NEED_newRV_noinc 121 #define NEED_sv_2pv_flags 122 #include "ppport.h" 123 124 /* 125 * perl might have included stdbool.h. If we also did that earlier (see c.h), 126 * then that's fine. If not, we probably rejected it for some reason. In 127 * that case, undef bool and proceed with our own bool. (Note that stdbool.h 128 * makes bool a macro, but our own replacement is a typedef, so the undef 129 * makes ours visible again). 130 */ 131 #ifndef USE_STDBOOL 132 #ifdef bool 133 #undef bool 134 #endif 135 #endif 136 137 /* supply HeUTF8 if it's missing - ppport.h doesn't supply it, unfortunately */ 138 #ifndef HeUTF8 139 #define HeUTF8(he) ((HeKLEN(he) == HEf_SVKEY) ? \ 140 SvUTF8(HeKEY_sv(he)) : \ 141 (U32)HeKUTF8(he)) 142 #endif 143 144 /* supply GvCV_set if it's missing - ppport.h doesn't supply it, unfortunately */ 145 #ifndef GvCV_set 146 #define GvCV_set(gv, cv) (GvCV(gv) = cv) 147 #endif 148 149 /* Perl 5.19.4 changed array indices from I32 to SSize_t */ 150 #if PERL_BCDVERSION >= 0x5019004 151 #define AV_SIZE_MAX SSize_t_MAX 152 #else 153 #define AV_SIZE_MAX I32_MAX 154 #endif 155 156 /* declare routines from plperl.c for access by .xs files */ 157 HV *plperl_spi_exec(char *, int); 158 void plperl_return_next(SV *); 159 SV *plperl_spi_query(char *); 160 SV *plperl_spi_fetchrow(char *); 161 SV *plperl_spi_prepare(char *, int, SV **); 162 HV *plperl_spi_exec_prepared(char *, HV *, int, SV **); 163 SV *plperl_spi_query_prepared(char *, int, SV **); 164 void plperl_spi_freeplan(char *); 165 void plperl_spi_cursor_close(char *); 166 void plperl_spi_commit(void); 167 void plperl_spi_rollback(void); 168 char *plperl_sv_to_literal(SV *, char *); 169 void plperl_util_elog(int level, SV *msg); 170 171 #endif /* PL_PERL_H */ 172