Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 560 lines (500 sloc) 16.74 kB
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
1 /*
0820fa3 Improved handling of NULLs/NAs
postgres authored
2 * PL/R - PostgreSQL support for R as a
3 * procedural language (PL)
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
4 *
f9d1f18 @jconway Update copyright dates
authored
5 * Copyright (c) 2003-2015 by Joseph E. Conway
3553645 Changed license to GPL per discussion on R mailing list.
postgres authored
6 * ALL RIGHTS RESERVED
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
7 *
8 * Joe Conway <mail@joeconway.com>
3368fdd Modified attribution a bit. Changed a few function names to improve c…
postgres authored
9 *
10 * Based on pltcl by Jan Wieck
11 * and inspired by REmbeddedPostgres by
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
12 * Duncan Temple Lang <duncan@research.bell-labs.com>
13 * http://www.omegahat.org/RSPostgres/
14 *
3553645 Changed license to GPL per discussion on R mailing list.
postgres authored
15 * License: GPL version 2 or newer. http://www.gnu.org/copyleft/gpl.html
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
30 *
31 * plr.h
32 */
33 #ifndef PLR_H
34 #define PLR_H
35
7fea541 @jconway Change version from plr--8.3.0.15 -> plr--8.3.0.16 (missed a couple o…
authored
36 #define PLR_VERSION "08.03.00.16"
d550f02 @jconway - Add plr_version() function: outputs a version string. Includes
authored
37
85e0638 - Updated copyright notices for 2010
jconway authored
38 #include "postgres.h"
39
40 #include "fmgr.h"
41 #include "funcapi.h"
42 #include "miscadmin.h"
f9b628b @jconway - make WINDOW function feature safe for PostgreSQL 8.3 which does
authored
43 #if PG_VERSION_NUM >= 80400
6a9c69f @jconway - New feature: allow PL/R functions to be declared and used as WINDOW
authored
44 #include "windowapi.h"
f9b628b @jconway - make WINDOW function feature safe for PostgreSQL 8.3 which does
authored
45 #endif
85e0638 - Updated copyright notices for 2010
jconway authored
46 #include "access/heapam.h"
5d4d925 @jconway Allow use of OUT parameters
authored
47 #if PG_VERSION_NUM >= 90300
48 #include "access/htup_details.h"
49 #else
50 #include "access/htup.h"
51 #endif
85e0638 - Updated copyright notices for 2010
jconway authored
52 #include "catalog/catversion.h"
53 #include "catalog/pg_language.h"
54 #include "catalog/pg_namespace.h"
55 #include "catalog/pg_proc.h"
56 #include "catalog/pg_type.h"
57 #include "commands/trigger.h"
58 #include "executor/spi.h"
59 #include "lib/stringinfo.h"
60 #include "nodes/makefuncs.h"
61 #include "optimizer/clauses.h"
62 #include "parser/parse_type.h"
63 #include "storage/ipc.h"
64 #include "tcop/tcopprot.h"
65 #include "utils/array.h"
66 #include "utils/builtins.h"
a0cd74f - Adjust for the fact that bytea.h did not exist before PostgreSQL 9.0
jconway authored
67 #if PG_VERSION_NUM >= 80500
85e0638 - Updated copyright notices for 2010
jconway authored
68 #include "utils/bytea.h"
a0cd74f - Adjust for the fact that bytea.h did not exist before PostgreSQL 9.0
jconway authored
69 #endif
85e0638 - Updated copyright notices for 2010
jconway authored
70 #include "utils/lsyscache.h"
71 #include "utils/memutils.h"
6a9c69f @jconway - New feature: allow PL/R functions to be declared and used as WINDOW
authored
72 #include "utils/rel.h"
85e0638 - Updated copyright notices for 2010
jconway authored
73 #include "utils/syscache.h"
74 #include "utils/typcache.h"
75
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
76 #include <unistd.h>
77 #include <fcntl.h>
78 #include <setjmp.h>
089d346 - fix for non-portable use of setenv
jconway authored
79 #include <stdlib.h>
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
80 #include <sys/stat.h>
81
85e0638 - Updated copyright notices for 2010
jconway authored
82 /*
83 * The R headers define various symbols that are also defined by the
84 * Postgres headers, so undef them first to avoid conflicts.
85 */
86 #ifdef ERROR
87 #undef ERROR
88 #endif
89
90 #ifdef WARNING
91 #undef WARNING
92 #endif
93
2f6f75f - preserve callers memory context rather than assuming query memory c…
jconway authored
94 #include "R.h"
384893c - Fix Makefile for include directory names with embedded spaces
jconway authored
95 #include "Rversion.h"
85e0638 - Updated copyright notices for 2010
jconway authored
96
384893c - Fix Makefile for include directory names with embedded spaces
jconway authored
97 /*
98 * R version is calculated thus:
99 * Maj * 65536 + Minor * 256 + Build * 1
100 * So:
101 * version 1.8.0 results in:
102 * (1 * 65536) + (8 * 256) + (0 * 1) == 67584
103 * version 1.9.0 results in:
104 * (1 * 65536) + (9 * 256) + (0 * 1) == 67840
105 */
d2d5495 - Update all Copyright notices.
jconway authored
106 #if (R_VERSION >= 132096) /* R_VERSION >= 2.4.0 */
107 #include "Rembedded.h"
108 #endif
020c324 @jconway - fix for win64
authored
109 #if !defined(WIN32) && !defined(WIN64)
d2d5495 - Update all Copyright notices.
jconway authored
110 #include "Rinterface.h"
33a90a9 @jconway Update copyright for 2013
authored
111 #else
112 extern int R_SignalHandlers;
384893c - Fix Makefile for include directory names with embedded spaces
jconway authored
113 #endif
2f6f75f - preserve callers memory context rather than assuming query memory c…
jconway authored
114 #include "Rinternals.h"
115 #include "Rdefines.h"
c7aa0e9 - updated copyright statements
jconway authored
116 #if (R_VERSION < 133120) /* R_VERSION < 2.8.0 */
2f6f75f - preserve callers memory context rather than assuming query memory c…
jconway authored
117 #include "Rdevices.h"
2c727f3 - Fixed "Rdevices.h" not found error related to R-2.8.x
jconway authored
118 #endif
384893c - Fix Makefile for include directory names with embedded spaces
jconway authored
119
85e0638 - Updated copyright notices for 2010
jconway authored
120 /* Restore the Postgres headers */
2c727f3 - Fixed "Rdevices.h" not found error related to R-2.8.x
jconway authored
121
2f6f75f - preserve callers memory context rather than assuming query memory c…
jconway authored
122 #ifdef ERROR
123 #undef ERROR
124 #endif
125
126 #ifdef WARNING
127 #undef WARNING
128 #endif
129
85e0638 - Updated copyright notices for 2010
jconway authored
130 #define WARNING 19
131 #define ERROR 20
132
133 /* starting in R-2.7.0 this defn was removed from Rdevices.h */
134 #ifndef KillAllDevices
135 #define KillAllDevices Rf_KillAllDevices
2f6f75f - preserve callers memory context rather than assuming query memory c…
jconway authored
136 #endif
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
137
85e0638 - Updated copyright notices for 2010
jconway authored
138 /* for some reason this is not in any R header files, it is locally defined */
139 #define INTEGER_ELT(x,__i__) INTEGER(x)[__i__]
053627d First pass at adding trigger support. Not well tested, but works for …
postgres authored
140
85e0638 - Updated copyright notices for 2010
jconway authored
141 #ifndef R_HOME_DEFAULT
142 #define R_HOME_DEFAULT ""
143 #endif
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
144
30da539 Moved construct_md_array from pg_conversion.c to pg_backend_support.c…
postgres authored
145 /* working with postgres 7.3 compatible sources */
d2d5495 - Update all Copyright notices.
jconway authored
146 #if !defined(PG_VERSION_NUM) || PG_VERSION_NUM < 80200
2f6f75f - preserve callers memory context rather than assuming query memory c…
jconway authored
147 #error "This version of PL/R only builds with PostgreSQL 8.2 or later"
d2d5495 - Update all Copyright notices.
jconway authored
148 #elif PG_VERSION_NUM < 80300
f86bec4 - removed support (and overhead) for PostgreSQL prior to 8.2
jconway authored
149 #define PG_VERSION_82_COMPAT
f9b628b @jconway - make WINDOW function feature safe for PostgreSQL 8.3 which does
authored
150 #elif PG_VERSION_NUM < 80400
2f6f75f - preserve callers memory context rather than assuming query memory c…
jconway authored
151 #define PG_VERSION_83_COMPAT
f9b628b @jconway - make WINDOW function feature safe for PostgreSQL 8.3 which does
authored
152 #else
153 #define PG_VERSION_84_COMPAT
154 #endif
155
156 #ifdef PG_VERSION_84_COMPAT
157 #define HAVE_WINDOW_FUNCTIONS
30da539 Moved construct_md_array from pg_conversion.c to pg_backend_support.c…
postgres authored
158 #endif
159
842fe78 Fixed PROTECT/UNPROTECT related bug causing execution of prepared que…
postgres authored
160 #ifdef DEBUGPROTECT
161 #undef PROTECT
5b09a95 - add DLLIMPORT to Dynamic_library_path declaration for Win32
jconway authored
162 extern SEXP pg_protect(SEXP s, char *fn, int ln);
163 #define PROTECT(s) pg_protect(s, __FILE__, __LINE__)
164
842fe78 Fixed PROTECT/UNPROTECT related bug causing execution of prepared que…
postgres authored
165 #undef UNPROTECT
5b09a95 - add DLLIMPORT to Dynamic_library_path declaration for Win32
jconway authored
166 extern void pg_unprotect(int n, char *fn, int ln);
167 #define UNPROTECT(n) pg_unprotect(n, __FILE__, __LINE__)
842fe78 Fixed PROTECT/UNPROTECT related bug causing execution of prepared que…
postgres authored
168 #endif /* DEBUGPROTECT */
169
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
170 #define xpfree(var_) \
171 do { \
172 if (var_ != NULL) \
173 { \
174 pfree(var_); \
175 var_ = NULL; \
176 } \
177 } while (0)
178
179 #define freeStringInfo(mystr_) \
180 do { \
181 xpfree((mystr_)->data); \
182 xpfree(mystr_); \
183 } while (0)
184
185 #define NEXT_STR_ELEMENT " %s"
186
889f33a Code fixes and features:
postgres authored
187 #if (R_VERSION < 67840) /* R_VERSION < 1.9.0 */
188 #define SET_COLUMN_NAMES \
189 do { \
190 int i; \
191 char *names_buf; \
192 names_buf = SPI_fname(tupdesc, j + 1); \
193 for (i = 0; i < strlen(names_buf); i++) { \
194 if (names_buf[i] == '_') \
195 names_buf[i] = '.'; \
196 } \
197 SET_STRING_ELT(names, df_colnum, mkChar(names_buf)); \
198 pfree(names_buf); \
199 } while (0)
200 #else /* R_VERSION >= 1.9.0 */
201 #define SET_COLUMN_NAMES \
202 do { \
203 char *names_buf; \
204 names_buf = SPI_fname(tupdesc, j + 1); \
205 SET_STRING_ELT(names, df_colnum, mkChar(names_buf)); \
206 pfree(names_buf); \
207 } while (0)
208 #endif
209
210 #if (R_VERSION < 67584) /* R_VERSION < 1.8.0 */
67be537 Detect Rversion and starting with version 1.8.0 eliminate the need to
postgres authored
211 /*
212 * See the non-exported header file ${R_HOME}/src/include/Parse.h
81a88ef Interim commit:
postgres authored
213 */
214 extern SEXP R_ParseVector(SEXP, int, int *);
215 #define PARSE_NULL 0
216 #define PARSE_OK 1
217 #define PARSE_INCOMPLETE 2
218 #define PARSE_ERROR 3
219 #define PARSE_EOF 4
220
67be537 Detect Rversion and starting with version 1.8.0 eliminate the need to
postgres authored
221 #define R_PARSEVECTOR(a_, b_, c_) R_ParseVector(a_, b_, c_)
00c7a66 Dept of second thoughts -- instead of recommending setting of
postgres authored
222
223 /*
67be537 Detect Rversion and starting with version 1.8.0 eliminate the need to
postgres authored
224 * See the non-exported header file ${R_HOME}/src/include/Defn.h
00c7a66 Dept of second thoughts -- instead of recommending setting of
postgres authored
225 */
67be537 Detect Rversion and starting with version 1.8.0 eliminate the need to
postgres authored
226 extern void R_PreserveObject(SEXP);
227 extern void R_ReleaseObject(SEXP);
00c7a66 Dept of second thoughts -- instead of recommending setting of
postgres authored
228
adca941 Additional clean shutdown actions added per note from Prof. B. Ripley.
postgres authored
229 /* in main.c */
230 extern void R_dot_Last(void);
231
232 /* in memory.c */
233 extern void R_RunExitFinalizers(void);
234
235 #else /* R_VERSION >= 1.8.0 */
00c7a66 Dept of second thoughts -- instead of recommending setting of
postgres authored
236
67be537 Detect Rversion and starting with version 1.8.0 eliminate the need to
postgres authored
237 #include "R_ext/Parse.h"
238
2f6f75f - preserve callers memory context rather than assuming query memory c…
jconway authored
239 #if (R_VERSION >= 132352) /* R_VERSION >= 2.5.0 */
240 #define R_PARSEVECTOR(a_, b_, c_) R_ParseVector(a_, b_, (ParseStatus *) c_, R_NilValue)
241 #else /* R_VERSION < 2.5.0 */
242 #define R_PARSEVECTOR(a_, b_, c_) R_ParseVector(a_, b_, (ParseStatus *) c_)
243 #endif /* R_VERSION >= 2.5.0 */
244 #endif /* R_VERSION >= 1.8.0 */
00c7a66 Dept of second thoughts -- instead of recommending setting of
postgres authored
245
81a88ef Interim commit:
postgres authored
246 /* convert C string to text pointer */
247 #define PG_TEXT_GET_STR(textp_) \
248 DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(textp_)))
249 #define PG_STR_GET_TEXT(str_) \
250 DatumGetTextP(DirectFunctionCall1(textin, CStringGetDatum(str_)))
251 #define PG_REPLACE_STR(str_, substr_, replacestr_) \
252 PG_TEXT_GET_STR(DirectFunctionCall3(replace_text, \
253 PG_STR_GET_TEXT(str_), \
254 PG_STR_GET_TEXT(substr_), \
255 PG_STR_GET_TEXT(replacestr_)))
256
49b6a24 Modified compiled function hash table to be keyed on function Oid and
postgres authored
257 /* initial number of hash table entries for compiled functions */
258 #define FUNCS_PER_USER 64
81a88ef Interim commit:
postgres authored
259
211ae2d Backport ereport support from 7.4devel for use under 7.3.
postgres authored
260 #define ERRORCONTEXTCALLBACK \
261 ErrorContextCallback plerrcontext
262
263 #define PUSH_PLERRCONTEXT(_error_callback_, _plr_error_funcname_) \
264 do { \
265 plerrcontext.callback = _error_callback_; \
266 plerrcontext.arg = (void *) pstrdup(_plr_error_funcname_); \
267 plerrcontext.previous = error_context_stack; \
268 error_context_stack = &plerrcontext; \
269 } while (0)
270
271 #define POP_PLERRCONTEXT \
272 do { \
d2d5495 - Update all Copyright notices.
jconway authored
273 pfree(plerrcontext.arg); \
211ae2d Backport ereport support from 7.4devel for use under 7.3.
postgres authored
274 error_context_stack = plerrcontext.previous; \
275 } while (0)
276
277 #define SAVE_PLERRCONTEXT \
278 ErrorContextCallback *ecs_save; \
279 do { \
280 ecs_save = error_context_stack; \
281 error_context_stack = NULL; \
282 } while (0)
283
284 #define RESTORE_PLERRCONTEXT \
285 do { \
286 error_context_stack = ecs_save; \
287 } while (0)
288
053627d First pass at adding trigger support. Not well tested, but works for …
postgres authored
289 #ifndef TEXTARRAYOID
290 #define TEXTARRAYOID 1009
291 #endif
211ae2d Backport ereport support from 7.4devel for use under 7.3.
postgres authored
292
053627d First pass at adding trigger support. Not well tested, but works for …
postgres authored
293 #define TRIGGER_NARGS 9
81a88ef Interim commit:
postgres authored
294
863a820 Adjust for the fact that SortMem is now called work_mem in 7.5.
postgres authored
295 #define TUPLESTORE_BEGIN_HEAP tuplestore_begin_heap(true, false, work_mem)
296
49b6a24 Modified compiled function hash table to be keyed on function Oid and
postgres authored
297 #define INIT_AUX_FMGR_ATTS \
81a88ef Interim commit:
postgres authored
298 do { \
2f6f75f - preserve callers memory context rather than assuming query memory c…
jconway authored
299 finfo->fn_mcxt = plr_caller_context; \
49b6a24 Modified compiled function hash table to be keyed on function Oid and
postgres authored
300 finfo->fn_expr = (Node *) NULL; \
81a88ef Interim commit:
postgres authored
301 } while (0)
302
0b9d999 Adjust for Postgres 8.1devel changes to proargtypes data type (oidvector
jconway authored
303 #define PROARGTYPES(i) \
304 procStruct->proargtypes.values[i]
305 #define FUNCARGTYPES(_tup_) \
a931381 Update for 8.1devel (oidvector now varlena)
jconway authored
306 ((Form_pg_proc) GETSTRUCT(_tup_))->proargtypes.values
0b9d999 Adjust for Postgres 8.1devel changes to proargtypes data type (oidvector
jconway authored
307
5becd0e Add test for 7.4 and 7.5 catalog versions. New macro to deal with rec…
postgres authored
308 #define PLR_CLEANUP \
889f33a Code fixes and features:
postgres authored
309 plr_cleanup(int code, Datum arg)
310 #define TRIGGERTUPLEVARS \
311 HeapTuple tup; \
312 HeapTupleHeader dnewtup; \
313 HeapTupleHeader dtrigtup
314 #define SET_INSERT_ARGS_567 \
315 do { \
316 arg[5] = DirectFunctionCall1(textin, CStringGetDatum("INSERT")); \
317 tup = trigdata->tg_trigtuple; \
318 dtrigtup = (HeapTupleHeader) palloc(tup->t_len); \
319 memcpy((char *) dtrigtup, (char *) tup->t_data, tup->t_len); \
320 HeapTupleHeaderSetDatumLength(dtrigtup, tup->t_len); \
321 HeapTupleHeaderSetTypeId(dtrigtup, tupdesc->tdtypeid); \
322 HeapTupleHeaderSetTypMod(dtrigtup, tupdesc->tdtypmod); \
323 arg[6] = PointerGetDatum(dtrigtup); \
324 argnull[6] = false; \
325 arg[7] = (Datum) 0; \
326 argnull[7] = true; \
327 } while (0)
328 #define SET_DELETE_ARGS_567 \
329 do { \
330 arg[5] = DirectFunctionCall1(textin, CStringGetDatum("DELETE")); \
331 arg[6] = (Datum) 0; \
332 argnull[6] = true; \
333 tup = trigdata->tg_trigtuple; \
334 dtrigtup = (HeapTupleHeader) palloc(tup->t_len); \
335 memcpy((char *) dtrigtup, (char *) tup->t_data, tup->t_len); \
336 HeapTupleHeaderSetDatumLength(dtrigtup, tup->t_len); \
337 HeapTupleHeaderSetTypeId(dtrigtup, tupdesc->tdtypeid); \
338 HeapTupleHeaderSetTypMod(dtrigtup, tupdesc->tdtypmod); \
339 arg[7] = PointerGetDatum(dtrigtup); \
340 argnull[7] = false; \
341 } while (0)
342 #define SET_UPDATE_ARGS_567 \
343 do { \
344 arg[5] = DirectFunctionCall1(textin, CStringGetDatum("UPDATE")); \
345 tup = trigdata->tg_newtuple; \
346 dnewtup = (HeapTupleHeader) palloc(tup->t_len); \
347 memcpy((char *) dnewtup, (char *) tup->t_data, tup->t_len); \
348 HeapTupleHeaderSetDatumLength(dnewtup, tup->t_len); \
349 HeapTupleHeaderSetTypeId(dnewtup, tupdesc->tdtypeid); \
350 HeapTupleHeaderSetTypMod(dnewtup, tupdesc->tdtypmod); \
351 arg[6] = PointerGetDatum(dnewtup); \
352 argnull[6] = false; \
353 tup = trigdata->tg_trigtuple; \
354 dtrigtup = (HeapTupleHeader) palloc(tup->t_len); \
355 memcpy((char *) dtrigtup, (char *) tup->t_data, tup->t_len); \
356 HeapTupleHeaderSetDatumLength(dtrigtup, tup->t_len); \
357 HeapTupleHeaderSetTypeId(dtrigtup, tupdesc->tdtypeid); \
358 HeapTupleHeaderSetTypMod(dtrigtup, tupdesc->tdtypmod); \
359 arg[7] = PointerGetDatum(dtrigtup); \
360 argnull[7] = false; \
361 } while (0)
362 #define CONVERT_TUPLE_TO_DATAFRAME \
363 do { \
364 Oid tupType; \
365 int32 tupTypmod; \
366 TupleDesc tupdesc; \
367 HeapTuple tuple = palloc(sizeof(HeapTupleData)); \
368 HeapTupleHeader tuple_hdr = DatumGetHeapTupleHeader(arg[i]); \
369 tupType = HeapTupleHeaderGetTypeId(tuple_hdr); \
370 tupTypmod = HeapTupleHeaderGetTypMod(tuple_hdr); \
371 tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod); \
372 tuple->t_len = HeapTupleHeaderGetDatumLength(tuple_hdr); \
373 ItemPointerSetInvalid(&(tuple->t_self)); \
374 tuple->t_tableOid = InvalidOid; \
375 tuple->t_data = tuple_hdr; \
376 PROTECT(el = pg_tuple_get_r_frame(1, &tuple, tupdesc)); \
f86bec4 - removed support (and overhead) for PostgreSQL prior to 8.2
jconway authored
377 ReleaseTupleDesc(tupdesc); \
889f33a Code fixes and features:
postgres authored
378 pfree(tuple); \
379 } while (0)
380 #define GET_ARG_NAMES \
381 char **argnames; \
382 argnames = fetchArgNames(procTup, procStruct->pronargs)
383 #define SET_ARG_NAME \
384 do { \
385 if (argnames && argnames[i] && argnames[i][0]) \
386 { \
387 appendStringInfo(proc_internal_args, "%s", argnames[i]); \
388 pfree(argnames[i]); \
389 } \
390 else \
391 appendStringInfo(proc_internal_args, "arg%d", i + 1); \
392 } while (0)
6a9c69f @jconway - New feature: allow PL/R functions to be declared and used as WINDOW
authored
393 #define SET_FRAME_ARG_NAME \
394 do { \
395 appendStringInfo(proc_internal_args, "farg%d", i + 1); \
396 } while (0)
d3ce774 @jconway - Fixed few bugs in new farg code found based on test case from Ian Gow
authored
397 #define SET_FRAME_XARG_NAMES \
398 do { \
399 appendStringInfo(proc_internal_args, ",fnumrows,prownum"); \
400 } while (0)
889f33a Code fixes and features:
postgres authored
401 #define FREE_ARG_NAMES \
402 do { \
403 if (argnames) \
404 pfree(argnames); \
405 } while (0)
0b0ddea Adjust for PostgreSQL 8.0.0 and R-2.0.1, including docs. Specifically
jconway authored
406 #define PREPARE_PG_TRY \
407 ERRORCONTEXTCALLBACK
435688d @jconway - Minor improvements to how/when SPI is connected which
authored
408 #define SWITCHTO_PLR_SPI_CONTEXT(the_caller_context) \
7a6b824 @jconway - Fix crashbug where array datum is NULL under certain circumstances
authored
409 the_caller_context = MemoryContextSwitchTo(plr_SPI_context)
435688d @jconway - Minor improvements to how/when SPI is connected which
authored
410 #define CLEANUP_PLR_SPI_CONTEXT(the_caller_context) \
411 MemoryContextSwitchTo(the_caller_context)
fea4ae4 - Added pgxs makefile
postgres authored
412 #define PLR_PG_CATCH() \
413 PG_CATCH(); \
414 { \
435688d @jconway - Minor improvements to how/when SPI is connected which
authored
415 MemoryContext temp_context; \
fea4ae4 - Added pgxs makefile
postgres authored
416 ErrorData *edata; \
435688d @jconway - Minor improvements to how/when SPI is connected which
authored
417 SWITCHTO_PLR_SPI_CONTEXT(temp_context); \
fea4ae4 - Added pgxs makefile
postgres authored
418 edata = CopyErrorData(); \
6a9c69f @jconway - New feature: allow PL/R functions to be declared and used as WINDOW
authored
419 MemoryContextSwitchTo(temp_context); \
fea4ae4 - Added pgxs makefile
postgres authored
420 error("error in SQL statement : %s", edata->message); \
421 }
422 #define PLR_PG_END_TRY() \
423 PG_END_TRY()
5becd0e Add test for 7.4 and 7.5 catalog versions. New macro to deal with rec…
postgres authored
424
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
425 /*
426 * structs
427 */
428
49b6a24 Modified compiled function hash table to be keyed on function Oid and
postgres authored
429 typedef struct plr_func_hashkey
430 { /* Hash lookup key for functions */
431 Oid funcOid;
f95bc0e Add the trigger relation oid to the function cache hashkey struct. Match
postgres authored
432
433 /*
434 * For a trigger function, the OID of the relation triggered on is part
435 * of the hashkey --- we want to compile the trigger separately for each
436 * relation it is used with, in case the rowtype is different. Zero if
437 * not called as a trigger.
438 */
439 Oid trigrelOid;
440
49b6a24 Modified compiled function hash table to be keyed on function Oid and
postgres authored
441 /*
442 * We include actual argument types in the hash key to support
443 * polymorphic PLpgSQL functions. Be careful that extra positions
444 * are zeroed!
445 */
446 Oid argtypes[FUNC_MAX_ARGS];
447 } plr_func_hashkey;
448
449
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
450 /* The information we cache about loaded procedures */
49b6a24 Modified compiled function hash table to be keyed on function Oid and
postgres authored
451 typedef struct plr_function
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
452 {
49b6a24 Modified compiled function hash table to be keyed on function Oid and
postgres authored
453 char *proname;
454 TransactionId fn_xmin;
2f6f75f - preserve callers memory context rather than assuming query memory c…
jconway authored
455 ItemPointerData fn_tid;
49b6a24 Modified compiled function hash table to be keyed on function Oid and
postgres authored
456 plr_func_hashkey *fn_hashkey; /* back-link to hashtable key */
457 bool lanpltrusted;
458 Oid result_typid;
459 bool result_istuple;
460 FmgrInfo result_in_func;
461 Oid result_elem;
462 FmgrInfo result_elem_in_func;
463 int result_elem_typlen;
464 bool result_elem_typbyval;
465 char result_elem_typalign;
fea4ae4 - Added pgxs makefile
postgres authored
466 int result_natts;
467 Oid *result_fld_elem_typid;
468 FmgrInfo *result_fld_elem_in_func;
469 int *result_fld_elem_typlen;
470 bool *result_fld_elem_typbyval;
471 char *result_fld_elem_typalign;
49b6a24 Modified compiled function hash table to be keyed on function Oid and
postgres authored
472 int nargs;
473 Oid arg_typid[FUNC_MAX_ARGS];
d3ce774 @jconway - Fixed few bugs in new farg code found based on test case from Ian Gow
authored
474 bool arg_typbyval[FUNC_MAX_ARGS];
49b6a24 Modified compiled function hash table to be keyed on function Oid and
postgres authored
475 FmgrInfo arg_out_func[FUNC_MAX_ARGS];
476 Oid arg_elem[FUNC_MAX_ARGS];
477 FmgrInfo arg_elem_out_func[FUNC_MAX_ARGS];
478 int arg_elem_typlen[FUNC_MAX_ARGS];
479 bool arg_elem_typbyval[FUNC_MAX_ARGS];
480 char arg_elem_typalign[FUNC_MAX_ARGS];
481 int arg_is_rel[FUNC_MAX_ARGS];
482 SEXP fun; /* compiled R function */
f9b628b @jconway - make WINDOW function feature safe for PostgreSQL 8.3 which does
authored
483 #ifdef HAVE_WINDOW_FUNCTIONS
6a9c69f @jconway - New feature: allow PL/R functions to be declared and used as WINDOW
authored
484 bool iswindow;
f9b628b @jconway - make WINDOW function feature safe for PostgreSQL 8.3 which does
authored
485 #endif
49b6a24 Modified compiled function hash table to be keyed on function Oid and
postgres authored
486 } plr_function;
487
488 /* compiled function hash table */
489 typedef struct plr_hashent
490 {
491 plr_func_hashkey key;
492 plr_function *function;
493 } plr_HashEnt;
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
494
495 /*
496 * external declarations
497 */
498
499 /* libR interpreter initialization */
500 extern int Rf_initEmbeddedR(int argc, char **argv);
501
502 /* PL/R language handler */
503 extern Datum plr_call_handler(PG_FUNCTION_ARGS);
5becd0e Add test for 7.4 and 7.5 catalog versions. New macro to deal with rec…
postgres authored
504 extern void PLR_CLEANUP;
bc31a8a Reworked initialization functions to match recent changes to pltcl, e…
postgres authored
505 extern void plr_init(void);
435688d @jconway - Minor improvements to how/when SPI is connected which
authored
506 extern void plr_load_modules(void);
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
507 extern void load_r_cmd(const char *cmd);
3368fdd Modified attribution a bit. Changed a few function names to improve c…
postgres authored
508 extern SEXP call_r_func(SEXP fun, SEXP rargs);
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
509
510 /* argument and return value conversion functions */
0820fa3 Improved handling of NULLs/NAs
postgres authored
511 extern SEXP pg_scalar_get_r(Datum dvalue, Oid arg_typid, FmgrInfo arg_out_func);
512 extern SEXP pg_array_get_r(Datum dvalue, FmgrInfo out_func, int typlen, bool typbyval, char typalign);
6a9c69f @jconway - New feature: allow PL/R functions to be declared and used as WINDOW
authored
513 extern SEXP pg_datum_array_get_r(Datum *elem_values, bool *elem_nulls, int numels, bool has_nulls,
514 Oid element_type, FmgrInfo out_func, bool typbyval);
0820fa3 Improved handling of NULLs/NAs
postgres authored
515 extern SEXP pg_tuple_get_r_frame(int ntuples, HeapTuple *tuples, TupleDesc tupdesc);
49b6a24 Modified compiled function hash table to be keyed on function Oid and
postgres authored
516 extern Datum r_get_pg(SEXP rval, plr_function *function, FunctionCallInfo fcinfo);
37642ef @jconway - allow pg.spi.prepare/pg.spi.execp to use parameters which are 1D ar…
authored
517 extern Datum get_datum(SEXP rval, Oid typid, Oid typelem, FmgrInfo in_func, bool *isnull);
c7aa0e9 - updated copyright statements
jconway authored
518 extern Datum get_scalar_datum(SEXP rval, Oid result_typ, FmgrInfo result_in_func, bool *isnull);
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
519
520 /* Postgres support functions installed into the R interpreter */
7627a7f Removed conversion of non-numeric data.frame columns to factors in C …
postgres authored
521 extern void throw_pg_notice(const char **msg);
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
522 extern SEXP plr_quote_literal(SEXP rawstr);
523 extern SEXP plr_quote_ident(SEXP rawstr);
524 extern SEXP plr_SPI_exec(SEXP rsql);
525 extern SEXP plr_SPI_prepare(SEXP rsql, SEXP rargtypes);
526 extern SEXP plr_SPI_execp(SEXP rsaved_plan, SEXP rargvalues);
d2d5495 - Update all Copyright notices.
jconway authored
527 extern SEXP plr_SPI_cursor_open(SEXP cursor_name_arg,SEXP rsaved_plan, SEXP rargvalues);
528 extern SEXP plr_SPI_cursor_fetch(SEXP cursor_in,SEXP forward_in, SEXP rows_in);
529 extern void plr_SPI_cursor_close(SEXP cursor_in);
530 extern void plr_SPI_cursor_move(SEXP cursor_in, SEXP forward_in, SEXP rows_in);
842fe78 Fixed PROTECT/UNPROTECT related bug causing execution of prepared que…
postgres authored
531 extern SEXP plr_SPI_lastoid(void);
d0be9df Still working of getting errors with context from within R correct. I…
postgres authored
532 extern void throw_r_error(const char **msg);
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
533
534 /* Postgres callable functions useful in conjunction with PL/R */
d550f02 @jconway - Add plr_version() function: outputs a version string. Includes
authored
535 extern Datum plr_version(PG_FUNCTION_ARGS);
acf486f Move redundant 1D-to-multiD array creation code into one function, wi…
postgres authored
536 extern Datum reload_plr_modules(PG_FUNCTION_ARGS);
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
537 extern Datum install_rcmd(PG_FUNCTION_ARGS);
5cdb7b5 Sync'd support for Postgres 7.4 polymorphic array types with what act…
postgres authored
538 extern Datum plr_array_push(PG_FUNCTION_ARGS);
539 extern Datum plr_array(PG_FUNCTION_ARGS);
540 extern Datum plr_array_accum(PG_FUNCTION_ARGS);
541 extern Datum plr_environ(PG_FUNCTION_ARGS);
d2d5495 - Update all Copyright notices.
jconway authored
542 extern Datum plr_set_rhome(PG_FUNCTION_ARGS);
543 extern Datum plr_unset_rhome(PG_FUNCTION_ARGS);
c7aa0e9 - updated copyright statements
jconway authored
544 extern Datum plr_set_display(PG_FUNCTION_ARGS);
545 extern Datum plr_get_raw(PG_FUNCTION_ARGS);
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
546
547 /* Postgres backend support functions */
f95bc0e Add the trigger relation oid to the function cache hashkey struct. Match
postgres authored
548 extern void compute_function_hashkey(FunctionCallInfo fcinfo,
49b6a24 Modified compiled function hash table to be keyed on function Oid and
postgres authored
549 Form_pg_proc procStruct,
550 plr_func_hashkey *hashkey);
551 extern void plr_HashTableInit(void);
552 extern plr_function *plr_HashTableLookup(plr_func_hashkey *func_key);
553 extern void plr_HashTableInsert(plr_function *function,
554 plr_func_hashkey *func_key);
555 extern void plr_HashTableDelete(plr_function *function);
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
556 extern char *get_load_self_ref_cmd(Oid funcid);
557 extern void perm_fmgr_info(Oid functionId, FmgrInfo *finfo);
a1bf401 adjusted memory contexts throughout
postgres authored
558
afa0b3c Somehow got windows EOLs (CRLF) in some of the files. Purged them in …
postgres authored
559 #endif /* PLR_H */
Something went wrong with that request. Please try again.