1 /*-------------------------------------------------------------------------
4 * Common include file for PL/Perl files
6 * This should be included _AFTER_ postgres.h and system include files
8 * Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
9 * Portions Copyright (c) 1995, Regents of the University of California
11 * src/pl/plperl/plperl.h
17 /* stop perl headers from hijacking stdio and other stuff on Windows */
19 #define WIN32IO_IS_STDIO
23 * Supply a value of PERL_UNUSED_DECL that will satisfy gcc - the one
24 * perl itself supplies doesn't seem to.
26 #define PERL_UNUSED_DECL pg_attribute_unused()
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.
42 * Perl scribbles on the "_" macro too.
47 * ActivePerl 5.18 and later are MinGW-built, and their headers use GCC's
48 * __inline__. Translate to something MSVC recognizes. Also, perl.h sometimes
49 * defines isnan, so undefine it here and put back the definition later if
53 #define __inline__ inline
60 * Regarding bool, both PostgreSQL and Perl might use stdbool.h or not,
61 * depending on configuration. If both agree, things are relatively harmless.
62 * If not, things get tricky. If PostgreSQL does but Perl does not, define
63 * HAS_BOOL here so that Perl does not redefine bool; this avoids compiler
64 * warnings. If PostgreSQL does not but Perl does, we need to undefine bool
65 * after we include the Perl headers; see below.
73 * Get the basic Perl API. We use PERL_NO_GET_CONTEXT mode so that our code
74 * can compile against MULTIPLICITY Perl builds without including XSUB.h.
76 #define PERL_NO_GET_CONTEXT
81 * We want to include XSUB.h only within .xs files, because on some platforms
82 * it undesirably redefines a lot of libc functions. But it must appear
83 * before ppport.h, so use a #define flag to control inclusion here.
85 #ifdef PG_NEED_PERL_XSUB_H
87 * On Windows, win32_port.h defines macros for a lot of these same functions.
88 * To avoid compiler warnings when XSUB.h redefines them, #undef our versions.
114 /* put back our *printf macros ... this must match src/include/port.h */
140 #define vsnprintf pg_vsnprintf
141 #define snprintf pg_snprintf
142 #define vsprintf pg_vsprintf
143 #define sprintf pg_sprintf
144 #define vfprintf pg_vfprintf
145 #define fprintf pg_fprintf
146 #define vprintf pg_vprintf
147 #define printf(...) pg_printf(__VA_ARGS__)
150 * Put back "_" too; but rather than making it just gettext() as the core
151 * code does, make it dgettext() so that the right things will happen in
152 * loadable modules (if they've set up TEXTDOMAIN correctly). Note that
153 * we can't just set TEXTDOMAIN here, because this file is used by more
154 * extensions than just PL/Perl itself.
157 #define _(x) dgettext(TEXTDOMAIN, x)
159 /* put back the definition of isnan if needed */
162 #define isnan(x) _isnan(x)
166 /* perl version and platform portability */
168 #define NEED_newRV_noinc
169 #define NEED_sv_2pv_flags
173 * perl might have included stdbool.h. If we also did that earlier (see c.h),
174 * then that's fine. If not, we probably rejected it for some reason. In
175 * that case, undef bool and proceed with our own bool. (Note that stdbool.h
176 * makes bool a macro, but our own replacement is a typedef, so the undef
177 * makes ours visible again).
179 #ifndef PG_USE_STDBOOL
185 /* supply HeUTF8 if it's missing - ppport.h doesn't supply it, unfortunately */
187 #define HeUTF8(he) ((HeKLEN(he) == HEf_SVKEY) ? \
188 SvUTF8(HeKEY_sv(he)) : \
192 /* supply GvCV_set if it's missing - ppport.h doesn't supply it, unfortunately */
194 #define GvCV_set(gv, cv) (GvCV(gv) = cv)
197 /* Perl 5.19.4 changed array indices from I32 to SSize_t */
198 #if PERL_BCDVERSION >= 0x5019004
199 #define AV_SIZE_MAX SSize_t_MAX
201 #define AV_SIZE_MAX I32_MAX
204 /* declare routines from plperl.c for access by .xs files */
205 HV
*plperl_spi_exec(char *, int);
206 void plperl_return_next(SV
*);
207 SV
*plperl_spi_query(char *);
208 SV
*plperl_spi_fetchrow(char *);
209 SV
*plperl_spi_prepare(char *, int, SV
**);
210 HV
*plperl_spi_exec_prepared(char *, HV
*, int, SV
**);
211 SV
*plperl_spi_query_prepared(char *, int, SV
**);
212 void plperl_spi_freeplan(char *);
213 void plperl_spi_cursor_close(char *);
214 void plperl_spi_commit(void);
215 void plperl_spi_rollback(void);
216 char *plperl_sv_to_literal(SV
*, char *);
217 void plperl_util_elog(int level
, SV
*msg
);
219 #endif /* PL_PERL_H */