PostgreSQL Source Code  git master
plperl.h
Go to the documentation of this file.
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-2019, 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 #undef vsnprintf
33 #undef snprintf
34 #undef vsprintf
35 #undef sprintf
36 #undef vfprintf
37 #undef fprintf
38 #undef vprintf
39 #undef printf
40 
41 /*
42  * Perl scribbles on the "_" macro too.
43  */
44 #undef _
45 
46 /*
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
50  * perl.h doesn't.
51  */
52 #ifdef _MSC_VER
53 #define __inline__ inline
54 #ifdef isnan
55 #undef isnan
56 #endif
57 #endif
58 
59 /*
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.
66  */
67 #ifdef USE_STDBOOL
68 #define HAS_BOOL 1
69 #endif
70 
71 
72 /*
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.
75  */
76 #define PERL_NO_GET_CONTEXT
77 #include "EXTERN.h"
78 #include "perl.h"
79 
80 /*
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.
84  */
85 #ifdef PG_NEED_PERL_XSUB_H
86 /*
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.
89  */
90 #ifdef WIN32
91 #undef accept
92 #undef bind
93 #undef connect
94 #undef fopen
95 #undef kill
96 #undef listen
97 #undef lstat
98 #undef mkdir
99 #undef open
100 #undef putenv
101 #undef recv
102 #undef rename
103 #undef select
104 #undef send
105 #undef socket
106 #undef stat
107 #undef unlink
108 #endif
109 
110 #include "XSUB.h"
111 #endif
112 
113 /* put back our *printf macros ... this must match src/include/port.h */
114 #ifdef vsnprintf
115 #undef vsnprintf
116 #endif
117 #ifdef snprintf
118 #undef snprintf
119 #endif
120 #ifdef vsprintf
121 #undef vsprintf
122 #endif
123 #ifdef sprintf
124 #undef sprintf
125 #endif
126 #ifdef vfprintf
127 #undef vfprintf
128 #endif
129 #ifdef fprintf
130 #undef fprintf
131 #endif
132 #ifdef vprintf
133 #undef vprintf
134 #endif
135 #ifdef printf
136 #undef printf
137 #endif
138 
139 #define vsnprintf pg_vsnprintf
140 #define snprintf pg_snprintf
141 #define vsprintf pg_vsprintf
142 #define sprintf pg_sprintf
143 #define vfprintf pg_vfprintf
144 #define fprintf pg_fprintf
145 #define vprintf pg_vprintf
146 #define printf(...) pg_printf(__VA_ARGS__)
147 
148 /*
149  * Put back "_" too; but rather than making it just gettext() as the core
150  * code does, make it dgettext() so that the right things will happen in
151  * loadable modules (if they've set up TEXTDOMAIN correctly). Note that
152  * we can't just set TEXTDOMAIN here, because this file is used by more
153  * extensions than just PL/Perl itself.
154  */
155 #undef _
156 #define _(x) dgettext(TEXTDOMAIN, x)
157 
158 /* put back the definition of isnan if needed */
159 #ifdef _MSC_VER
160 #ifndef isnan
161 #define isnan(x) _isnan(x)
162 #endif
163 #endif
164 
165 /* perl version and platform portability */
166 #define NEED_eval_pv
167 #define NEED_newRV_noinc
168 #define NEED_sv_2pv_flags
169 #include "ppport.h"
170 
171 /*
172  * perl might have included stdbool.h. If we also did that earlier (see c.h),
173  * then that's fine. If not, we probably rejected it for some reason. In
174  * that case, undef bool and proceed with our own bool. (Note that stdbool.h
175  * makes bool a macro, but our own replacement is a typedef, so the undef
176  * makes ours visible again).
177  */
178 #ifndef USE_STDBOOL
179 #ifdef bool
180 #undef bool
181 #endif
182 #endif
183 
184 /* supply HeUTF8 if it's missing - ppport.h doesn't supply it, unfortunately */
185 #ifndef HeUTF8
186 #define HeUTF8(he) ((HeKLEN(he) == HEf_SVKEY) ? \
187  SvUTF8(HeKEY_sv(he)) : \
188  (U32)HeKUTF8(he))
189 #endif
190 
191 /* supply GvCV_set if it's missing - ppport.h doesn't supply it, unfortunately */
192 #ifndef GvCV_set
193 #define GvCV_set(gv, cv) (GvCV(gv) = cv)
194 #endif
195 
196 /* Perl 5.19.4 changed array indices from I32 to SSize_t */
197 #if PERL_BCDVERSION >= 0x5019004
198 #define AV_SIZE_MAX SSize_t_MAX
199 #else
200 #define AV_SIZE_MAX I32_MAX
201 #endif
202 
203 /* declare routines from plperl.c for access by .xs files */
204 HV *plperl_spi_exec(char *, int);
205 void plperl_return_next(SV *);
206 SV *plperl_spi_query(char *);
207 SV *plperl_spi_fetchrow(char *);
208 SV *plperl_spi_prepare(char *, int, SV **);
209 HV *plperl_spi_exec_prepared(char *, HV *, int, SV **);
210 SV *plperl_spi_query_prepared(char *, int, SV **);
211 void plperl_spi_freeplan(char *);
212 void plperl_spi_cursor_close(char *);
213 void plperl_spi_commit(void);
214 void plperl_spi_rollback(void);
215 char *plperl_sv_to_literal(SV *, char *);
216 void plperl_util_elog(int level, SV *msg);
217 
218 #endif /* PL_PERL_H */
void plperl_spi_freeplan(char *)
Definition: plperl.c:3951
char * plperl_sv_to_literal(SV *, char *)
Definition: plperl.c:1432
SV * plperl_spi_fetchrow(char *)
Definition: plperl.c:3467
void plperl_spi_rollback(void)
Definition: plperl.c:4007
void plperl_spi_cursor_close(char *)
Definition: plperl.c:3542
void plperl_return_next(SV *)
Definition: plperl.c:3238
SV * plperl_spi_query(char *)
Definition: plperl.c:3395
HV * plperl_spi_exec_prepared(char *, HV *, int, SV **)
Definition: plperl.c:3706
HV * plperl_spi_exec(char *, int)
Definition: plperl.c:3126
SV * plperl_spi_prepare(char *, int, SV **)
Definition: plperl.c:3558
void plperl_util_elog(int level, SV *msg)
Definition: plperl.c:4043
SV * plperl_spi_query_prepared(char *, int, SV **)
Definition: plperl.c:3833
void plperl_spi_commit(void)
Definition: plperl.c:3982