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-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 /*
21  * isnan is defined in both the perl and mingw headers. We don't use it,
22  * so this just clears up the compile warning.
23  */
24 #ifdef isnan
25 #undef isnan
26 #endif
27 #endif /* WIN32 */
28 
29 /*
30  * Supply a value of PERL_UNUSED_DECL that will satisfy gcc - the one
31  * perl itself supplies doesn't seem to.
32  */
33 #define PERL_UNUSED_DECL pg_attribute_unused()
34 
35 /*
36  * Sometimes perl carefully scribbles on our *printf macros.
37  * So we undefine them here and redefine them after it's done its dirty deed.
38  */
39 
40 #ifdef USE_REPL_SNPRINTF
41 #undef snprintf
42 #undef vsnprintf
43 #endif
44 
45 /*
46  * ActivePerl 5.18 and later are MinGW-built, and their headers use GCC's
47  * __inline__. Translate to something MSVC recognizes.
48  */
49 #ifdef _MSC_VER
50 #define __inline__ inline
51 #endif
52 
53 /*
54  * Regarding bool, both PostgreSQL and Perl might use stdbool.h or not,
55  * depending on configuration. If both agree, things are relatively harmless.
56  * If not, things get tricky. If PostgreSQL does but Perl does not, define
57  * HAS_BOOL here so that Perl does not redefine bool; this avoids compiler
58  * warnings. If PostgreSQL does not but Perl does, we need to undefine bool
59  * after we include the Perl headers; see below.
60  */
61 #ifdef USE_STDBOOL
62 #define HAS_BOOL 1
63 #endif
64 
65 
66 /*
67  * Get the basic Perl API. We use PERL_NO_GET_CONTEXT mode so that our code
68  * can compile against MULTIPLICITY Perl builds without including XSUB.h.
69  */
70 #define PERL_NO_GET_CONTEXT
71 #include "EXTERN.h"
72 #include "perl.h"
73 
74 /*
75  * We want to include XSUB.h only within .xs files, because on some platforms
76  * it undesirably redefines a lot of libc functions. But it must appear
77  * before ppport.h, so use a #define flag to control inclusion here.
78  */
79 #ifdef PG_NEED_PERL_XSUB_H
80 #include "XSUB.h"
81 #endif
82 
83 /* put back our snprintf and vsnprintf */
84 #ifdef USE_REPL_SNPRINTF
85 #ifdef snprintf
86 #undef snprintf
87 #endif
88 #ifdef vsnprintf
89 #undef vsnprintf
90 #endif
91 #ifdef __GNUC__
92 #define vsnprintf(...) pg_vsnprintf(__VA_ARGS__)
93 #define snprintf(...) pg_snprintf(__VA_ARGS__)
94 #else
95 #define vsnprintf pg_vsnprintf
96 #define snprintf pg_snprintf
97 #endif /* __GNUC__ */
98 #endif /* USE_REPL_SNPRINTF */
99 
100 /* perl version and platform portability */
101 #define NEED_eval_pv
102 #define NEED_newRV_noinc
103 #define NEED_sv_2pv_flags
104 #include "ppport.h"
105 
106 /*
107  * perl might have included stdbool.h. If we also did that earlier (see c.h),
108  * then that's fine. If not, we probably rejected it for some reason. In
109  * that case, undef bool and proceed with our own bool. (Note that stdbool.h
110  * makes bool a macro, but our own replacement is a typedef, so the undef
111  * makes ours visible again).
112  */
113 #ifndef USE_STDBOOL
114 #ifdef bool
115 #undef bool
116 #endif
117 #endif
118 
119 /* supply HeUTF8 if it's missing - ppport.h doesn't supply it, unfortunately */
120 #ifndef HeUTF8
121 #define HeUTF8(he) ((HeKLEN(he) == HEf_SVKEY) ? \
122  SvUTF8(HeKEY_sv(he)) : \
123  (U32)HeKUTF8(he))
124 #endif
125 
126 /* supply GvCV_set if it's missing - ppport.h doesn't supply it, unfortunately */
127 #ifndef GvCV_set
128 #define GvCV_set(gv, cv) (GvCV(gv) = cv)
129 #endif
130 
131 /* Perl 5.19.4 changed array indices from I32 to SSize_t */
132 #if PERL_BCDVERSION >= 0x5019004
133 #define AV_SIZE_MAX SSize_t_MAX
134 #else
135 #define AV_SIZE_MAX I32_MAX
136 #endif
137 
138 /* declare routines from plperl.c for access by .xs files */
139 HV *plperl_spi_exec(char *, int);
140 void plperl_return_next(SV *);
141 SV *plperl_spi_query(char *);
142 SV *plperl_spi_fetchrow(char *);
143 SV *plperl_spi_prepare(char *, int, SV **);
144 HV *plperl_spi_exec_prepared(char *, HV *, int, SV **);
145 SV *plperl_spi_query_prepared(char *, int, SV **);
146 void plperl_spi_freeplan(char *);
147 void plperl_spi_cursor_close(char *);
148 void plperl_spi_commit(void);
149 void plperl_spi_rollback(void);
150 char *plperl_sv_to_literal(SV *, char *);
151 void plperl_util_elog(int level, SV *msg);
152 
153 #endif /* PL_PERL_H */
void plperl_spi_freeplan(char *)
Definition: plperl.c:3930
char * plperl_sv_to_literal(SV *, char *)
Definition: plperl.c:1433
SV * plperl_spi_fetchrow(char *)
Definition: plperl.c:3447
void plperl_spi_rollback(void)
Definition: plperl.c:3988
void plperl_spi_cursor_close(char *)
Definition: plperl.c:3521
void plperl_return_next(SV *)
Definition: plperl.c:3218
SV * plperl_spi_query(char *)
Definition: plperl.c:3375
HV * plperl_spi_exec_prepared(char *, HV *, int, SV **)
Definition: plperl.c:3685
HV * plperl_spi_exec(char *, int)
Definition: plperl.c:3106
SV * plperl_spi_prepare(char *, int, SV **)
Definition: plperl.c:3537
void plperl_util_elog(int level, SV *msg)
Definition: plperl.c:4026
SV * plperl_spi_query_prepared(char *, int, SV **)
Definition: plperl.c:3812
void plperl_spi_commit(void)
Definition: plperl.c:3961