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

Commit c5b02a7

Browse files
committed
Attached is a uuencoded tarball that contains
3 new files and two patches for the plperl subdir. These changes add the ability for plperl functions to call 'elog'. It also sets up the frame work to allow me to add access to the SPI functions. -- Mark Hollomon
1 parent 1380921 commit c5b02a7

File tree

5 files changed

+122
-7
lines changed

5 files changed

+122
-7
lines changed

src/pl/plperl/Makefile.PL

+11-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ print MAKEFILE <<_STATIC_;
4747
SRCDIR= ../../../src
4848
include \$(SRCDIR)/Makefile.global
4949
50+
EXTDIR= $Config{privlib}/ExtUtils
51+
52+
XSUBPP= \$(EXTDIR)/xsubpp
53+
54+
TYPEMAP= -typemap \$(EXTDIR)/typemap
5055
5156
# use the same compiler as perl did
5257
CC= $Config{cc}
@@ -95,12 +100,16 @@ endif
95100
#
96101
all: plperl
97102
98-
plperl : plperl.o
99-
\$(CC) -o plperl.so plperl.o \$(SHLIB_EXTRA_LIBS) \$(LDADD) \$(LDFLAGS)
103+
plperl : plperl.o SPI.o
104+
\$(CC) -o plperl.so plperl.o SPI.o \$(SHLIB_EXTRA_LIBS) \$(LDADD) \$(LDFLAGS)
100105
101106
%.o : %.c
102107
\$(CC) -c \$(CFLAGS) \$<
103108
109+
%.o : %.xs
110+
\$(XSUBPP} \$(TYPEMAP) \$< > xtmp.c
111+
\$(CC) -c \$(CFLAGS) -o \$@ xtmp.c
112+
104113
105114
#
106115
# Clean

src/pl/plperl/SPI.xs

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* system stuff */
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
#include <stdarg.h>
5+
#include <unistd.h>
6+
#include <fcntl.h>
7+
#include <string.h>
8+
#include <setjmp.h>
9+
10+
/* postgreSQL stuff */
11+
#include "executor/spi.h"
12+
#include "commands/trigger.h"
13+
#include "utils/elog.h"
14+
#include "utils/builtins.h"
15+
#include "fmgr.h"
16+
#include "access/heapam.h"
17+
18+
#include "tcop/tcopprot.h"
19+
#include "utils/syscache.h"
20+
#include "catalog/pg_proc.h"
21+
#include "catalog/pg_type.h"
22+
23+
/* perl stuff */
24+
/*
25+
* Evil Code Alert
26+
*
27+
* both posgreSQL and perl try to do 'the right thing'
28+
* and provide union semun if the platform doesn't define
29+
* it in a system header.
30+
* psql uses HAVE_UNION_SEMUN
31+
* perl uses HAS_UNION_SEMUN
32+
* together, they cause compile errors.
33+
* If we need it, the psql headers above will provide it.
34+
* So we tell perl that we have it.
35+
*/
36+
#ifndef HAS_UNION_SEMUN
37+
#define HAS_UNION_SEMUN
38+
#endif
39+
40+
#include "EXTERN.h"
41+
#include "perl.h"
42+
#include "XSUB.h"
43+
44+
#include "eloglvl.h"
45+
46+
47+
48+
MODULE = SPI PREFIX = elog_
49+
50+
PROTOTYPES: ENABLE
51+
VERSIONCHECK: DISABLE
52+
53+
void
54+
elog_elog(level, message)
55+
int level
56+
char* message
57+
CODE:
58+
if (level > 0)
59+
return;
60+
else
61+
elog(level, message);
62+
63+
64+
int
65+
elog_NOIND()
66+
67+
int
68+
elog_DEBUG()
69+
70+
int
71+
elog_ERROR()
72+
73+
int
74+
elog_NOTICE()

src/pl/plperl/eloglvl.c

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "utils/elog.h"
2+
3+
/*
4+
* This kludge is necessary because of the conflicting
5+
* definitions of 'DEBUG' between postgres and perl.
6+
* we'll live.
7+
*/
8+
9+
#include "eloglvl.h"
10+
11+
int elog_DEBUG(void) {
12+
return DEBUG;
13+
}
14+
15+
int elog_ERROR(void) {
16+
return ERROR;
17+
}
18+
19+
int elog_NOIND(void) {
20+
return NOIND;
21+
}
22+
23+
int elog_NOTICE(void) {
24+
return NOTICE;
25+
}

src/pl/plperl/eloglvl.h

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
int elog_DEBUG(void) ;
3+
4+
int elog_ERROR(void) ;
5+
6+
int elog_NOIND(void) ;
7+
8+
int elog_NOTICE(void);

src/pl/plperl/plperl.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ static void
218218
plperl_init_safe_interp(void)
219219
{
220220

221-
char *embedding[] = { "", "-e", "BEGIN { use DynaLoader; require Safe;}", "0" };
221+
char *embedding[] = { "", "-e", "use DynaLoader; require Safe; SPI::bootstrap()", "0" };
222222

223223
plperl_safe_interp = perl_alloc();
224224
if (!plperl_safe_interp)
@@ -235,10 +235,6 @@ plperl_init_safe_interp(void)
235235
************************* ***********************************/
236236
plperl_proc_hash = newHV();
237237

238-
/************************************************************
239-
* Install the commands for SPI support in the safe interpreter
240-
* Someday.
241-
************************************************************/
242238
}
243239

244240

@@ -356,13 +352,15 @@ plperl_create_sub(SV *s) {
356352

357353
extern void boot_DynaLoader _((CV* cv));
358354
extern void boot_Opcode _((CV* cv));
355+
extern void boot_SPI _((CV* cv));
359356

360357
extern void
361358
plperl_init_shared_libs(void)
362359
{
363360
char *file = __FILE__;
364361
newXS("DynaLoader::bootstrap", boot_DynaLoader, file);
365362
newXS("Opcode::bootstrap", boot_Opcode, file);
363+
newXS("SPI::bootstrap", boot_SPI, file);
366364
}
367365

368366
/**********************************************************************
@@ -574,6 +572,7 @@ plperl_func_handler(FmgrInfo *proinfo,
574572
proc_internal_def = newSVpvf(
575573
"$::x = new Safe;"
576574
"$::x->permit_only(':default');"
575+
"$::x->share(qw[&elog &DEBUG &NOTICE &NOIND &ERROR]);"
577576
"use strict;"
578577
"return $::x->reval( q[ sub { %s } ]);", proc_source);
579578

0 commit comments

Comments
 (0)