forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitbebe174
committed
PL/Perl portability fix: avoid including XSUB.h in plperl.c.
In Perl builds that define PERL_IMPLICIT_SYS, XSUB.h defines macrosthat replace a whole lot of basic libc functions with Perl functions.We can't tolerate that in plperl.c; it breaks at least PG_TRY andprobably other stuff. The core idea of this patch is to include XSUB.honly in the .xs files where it's really needed, and to move any codebroken by PERL_IMPLICIT_SYS out of the .xs files and into plperl.c.The reason this hasn't been a problem before is that our build techniquesdid not result in PERL_IMPLICIT_SYS appearing as a #define in PL/Perl,even on some platforms where Perl thinks it is defined. That's about tochange in order to fix a nasty portability issue, so we need this work tomake the code safe for that.Rather unaccountably, the Perl people chose XSUB.h as the place to providethe versions of the aTHX/aTHX_ macros that are needed by code that's notexplicitly aware of the MULTIPLICITY API conventions. Hence, just removingXSUB.h from plperl.c fails miserably. But we can work around that bydefining PERL_NO_GET_CONTEXT (which would make the relevant stanza ofXSUB.h a no-op anyway). As explained in perlguts.pod, that means we needto add a "dTHX" macro call in every C function that calls a Perl APIfunction. In most of them we just add this at the top; but since themacro fetches the current Perl interpreter pointer, more care is neededin functions that switch the active interpreter. Lack of the macro iseasily recognized since it results in bleats about "my_perl" not beingdefined.(A nice side benefit of this is that it significantly reduces the numberof fetches of the current interpreter pointer. On my machine, plperl.sogets more than 10% smaller, and there's probably some performance win too.We could reduce the number of fetches still more by decorating the codewith pTHX_/aTHX_ macros to pass the interpreter pointer around, asexplained by perlguts.pod; but that's a task for another day.)Formatting note: pgindent seems happy to treat "dTHX;" as a declarationso long as it's the first thing after the left brace, as we'd alreadyobserved with respect to the similar macro "dSP;". If you try to putit later in a set of declarations, pgindent puts ugly extra spacearound it.Having removed XSUB.h from plperl.c, we need only move the supportfunctions for spi_return_next and util_elog (both of which use PG_TRY)out of the .xs files and into plperl.c. This seems sufficient toavoid the known problems caused by PERL_IMPLICIT_SYS, although wecould move more code if additional issues emerge.This will need to be back-patched, but first let's see what thebuildfarm makes of it.Patch by me, with some help from Ashutosh SharmaDiscussion:https://postgr.es/m/CANFyU97OVQ3+Mzfmt3MhuUm5NwPU=-FtbNH5Eb7nZL9ua8=rcA@mail.gmail.com1 parent8d30407 commitbebe174
File tree
6 files changed
+210
-137
lines changed- contrib/hstore_plperl
- src/pl/plperl
6 files changed
+210
-137
lines changedLines changed: 3 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
67 | 67 |
| |
68 | 68 |
| |
69 | 69 |
| |
| 70 | + | |
70 | 71 |
| |
71 | 72 |
| |
72 | 73 |
| |
| |||
99 | 100 |
| |
100 | 101 |
| |
101 | 102 |
| |
102 |
| - | |
| 103 | + | |
| 104 | + | |
103 | 105 |
| |
104 | 106 |
| |
105 | 107 |
| |
106 | 108 |
| |
107 | 109 |
| |
108 | 110 |
| |
109 | 111 |
| |
110 |
| - | |
111 |
| - | |
112 | 112 |
| |
113 | 113 |
| |
114 | 114 |
| |
|
Lines changed: 2 additions & 30 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
9 | 9 |
| |
10 | 10 |
| |
11 | 11 |
| |
12 |
| - | |
13 | 12 |
| |
14 | 13 |
| |
15 | 14 |
| |
16 | 15 |
| |
17 | 16 |
| |
| 17 | + | |
18 | 18 |
| |
19 | 19 |
| |
20 | 20 |
| |
21 | 21 |
| |
22 |
| - | |
23 |
| - | |
24 |
| - | |
25 |
| - | |
26 |
| - | |
27 |
| - | |
28 |
| - | |
29 |
| - | |
30 |
| - | |
31 |
| - | |
32 |
| - | |
33 |
| - | |
34 |
| - | |
35 |
| - | |
36 |
| - | |
37 |
| - | |
38 |
| - | |
39 |
| - | |
40 |
| - | |
41 |
| - | |
42 |
| - | |
43 |
| - | |
44 |
| - | |
45 |
| - | |
46 |
| - | |
47 |
| - | |
48 |
| - | |
49 |
| - | |
50 | 22 |
| |
51 | 23 |
| |
52 | 24 |
| |
| |||
76 | 48 |
| |
77 | 49 |
| |
78 | 50 |
| |
79 |
| - | |
| 51 | + | |
80 | 52 |
| |
81 | 53 |
| |
82 | 54 |
| |
|
Lines changed: 3 additions & 41 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
15 | 15 |
| |
16 | 16 |
| |
17 | 17 |
| |
18 |
| - | |
| 18 | + | |
19 | 19 |
| |
20 | 20 |
| |
21 | 21 |
| |
22 | 22 |
| |
| 23 | + | |
23 | 24 |
| |
24 | 25 |
| |
25 | 26 |
| |
26 |
| - | |
27 |
| - | |
28 |
| - | |
29 |
| - | |
30 |
| - | |
31 |
| - | |
32 |
| - | |
33 |
| - | |
34 |
| - | |
35 |
| - | |
36 |
| - | |
37 |
| - | |
38 |
| - | |
39 |
| - | |
40 |
| - | |
41 |
| - | |
42 |
| - | |
43 |
| - | |
44 |
| - | |
45 |
| - | |
46 |
| - | |
47 |
| - | |
48 |
| - | |
49 |
| - | |
50 |
| - | |
51 |
| - | |
52 |
| - | |
53 |
| - | |
54 |
| - | |
55 |
| - | |
56 |
| - | |
57 |
| - | |
58 |
| - | |
59 |
| - | |
60 |
| - | |
61 |
| - | |
62 |
| - | |
63 |
| - | |
64 |
| - | |
65 | 27 |
| |
66 | 28 |
| |
67 | 29 |
| |
| |||
105 | 67 |
| |
106 | 68 |
| |
107 | 69 |
| |
108 |
| - | |
| 70 | + | |
109 | 71 |
| |
110 | 72 |
| |
111 | 73 |
| |
|
0 commit comments
Comments
(0)