Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 30a5c8b

Browse files
committed
PL/Perl portability fix: avoid including XSUB.h in plperl.c.
Back-patch of commit bebe174, which see for more info. Patch by me, with some help from Ashutosh Sharma Discussion: https://postgr.es/m/CANFyU97OVQ3+Mzfmt3MhuUm5NwPU=-FtbNH5Eb7nZL9ua8=rcA@mail.gmail.com
1 parent d38e706 commit 30a5c8b

File tree

6 files changed

+210
-137
lines changed

6 files changed

+210
-137
lines changed

contrib/hstore_plperl/hstore_plperl.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ PG_FUNCTION_INFO_V1(hstore_to_plperl);
1313
Datum
1414
hstore_to_plperl(PG_FUNCTION_ARGS)
1515
{
16+
dTHX;
1617
HStore *in = PG_GETARG_HS(0);
1718
int i;
1819
int count = HS_COUNT(in);
@@ -45,16 +46,15 @@ PG_FUNCTION_INFO_V1(plperl_to_hstore);
4546
Datum
4647
plperl_to_hstore(PG_FUNCTION_ARGS)
4748
{
48-
HV *hv;
49+
dTHX;
50+
HV *hv = (HV *) SvRV((SV *) PG_GETARG_POINTER(0));
4951
HE *he;
5052
int32 buflen;
5153
int32 i;
5254
int32 pcount;
5355
HStore *out;
5456
Pairs *pairs;
5557

56-
hv = (HV *) SvRV((SV *) PG_GETARG_POINTER(0));
57-
5858
pcount = hv_iterinit(hv);
5959

6060
pairs = palloc(pcount * sizeof(Pairs));

src/pl/plperl/SPI.xs

+2-30
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,16 @@
99

1010
/* this must be first: */
1111
#include "postgres.h"
12-
#include "mb/pg_wchar.h" /* for GetDatabaseEncoding */
1312

1413
/* Defined by Perl */
1514
#undef _
1615

1716
/* perl stuff */
17+
#define PG_NEED_PERL_XSUB_H
1818
#include "plperl.h"
1919
#include "plperl_helpers.h"
2020

2121

22-
/*
23-
* Interface routine to catch ereports and punt them to Perl
24-
*/
25-
static void
26-
do_plperl_return_next(SV *sv)
27-
{
28-
MemoryContext oldcontext = CurrentMemoryContext;
29-
30-
PG_TRY();
31-
{
32-
plperl_return_next(sv);
33-
}
34-
PG_CATCH();
35-
{
36-
ErrorData *edata;
37-
38-
/* Must reset elog.c's state */
39-
MemoryContextSwitchTo(oldcontext);
40-
edata = CopyErrorData();
41-
FlushErrorState();
42-
43-
/* Punt the error to Perl */
44-
croak_cstr(edata->message);
45-
}
46-
PG_END_TRY();
47-
}
48-
49-
5022
MODULE = PostgreSQL::InServer::SPI PREFIX = spi_
5123

5224
PROTOTYPES: ENABLE
@@ -76,7 +48,7 @@ void
7648
spi_return_next(rv)
7749
SV *rv;
7850
CODE:
79-
do_plperl_return_next(rv);
51+
plperl_return_next(rv);
8052

8153
SV *
8254
spi_spi_query(sv)

src/pl/plperl/Util.xs

+3-41
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,15 @@
1515
#include "fmgr.h"
1616
#include "utils/builtins.h"
1717
#include "utils/bytea.h" /* for byteain & byteaout */
18-
#include "mb/pg_wchar.h" /* for GetDatabaseEncoding */
18+
1919
/* Defined by Perl */
2020
#undef _
2121

2222
/* perl stuff */
23+
#define PG_NEED_PERL_XSUB_H
2324
#include "plperl.h"
2425
#include "plperl_helpers.h"
2526

26-
/*
27-
* Implementation of plperl's elog() function
28-
*
29-
* If the error level is less than ERROR, we'll just emit the message and
30-
* return. When it is ERROR, elog() will longjmp, which we catch and
31-
* turn into a Perl croak(). Note we are assuming that elog() can't have
32-
* any internal failures that are so bad as to require a transaction abort.
33-
*
34-
* This is out-of-line to suppress "might be clobbered by longjmp" warnings.
35-
*/
36-
static void
37-
do_util_elog(int level, SV *msg)
38-
{
39-
MemoryContext oldcontext = CurrentMemoryContext;
40-
char * volatile cmsg = NULL;
41-
42-
PG_TRY();
43-
{
44-
cmsg = sv2cstr(msg);
45-
elog(level, "%s", cmsg);
46-
pfree(cmsg);
47-
}
48-
PG_CATCH();
49-
{
50-
ErrorData *edata;
51-
52-
/* Must reset elog.c's state */
53-
MemoryContextSwitchTo(oldcontext);
54-
edata = CopyErrorData();
55-
FlushErrorState();
56-
57-
if (cmsg)
58-
pfree(cmsg);
59-
60-
/* Punt the error to Perl */
61-
croak_cstr(edata->message);
62-
}
63-
PG_END_TRY();
64-
}
6527

6628
static text *
6729
sv2text(SV *sv)
@@ -105,7 +67,7 @@ util_elog(level, msg)
10567
level = ERROR;
10668
if (level < DEBUG5)
10769
level = DEBUG5;
108-
do_util_elog(level, msg);
70+
plperl_util_elog(level, msg);
10971

11072
SV *
11173
util_quote_literal(sv)

0 commit comments

Comments
 (0)