Permalink
Browse files

- Updated copyright notices for 2010

- Remove obsolete info from README and point to web site instead
- Consolidate and reorder all header files in order to avoid
  namespace conflicts between postgres/R/Win32
- Rather than referencing pkglib_path and Dynamic_library_path,
  reference my_exec_path instead. This is because the former are
  not exported in win32 and the latter is. Instead get Dynamic_library_path
  by calling GetConfigOptionByName() and pkglib_path by calling
  get_pkglib_path().
- Recognize hex input since bytea output is formatted that way by
  default starting with PostgreSQL 9.0
- Avoid dynamic assignments with array constructors since MSVC
  cannot handle them.
- Workaround fact that "char **environ" is not available on win32
  for plr_environ()
  • Loading branch information...
1 parent c7aa0e9 commit 85e0638fba0b166e0f154f27cd1e584f309a6d35 jconway committed Feb 1, 2010
Showing with 170 additions and 95 deletions.
  1. +3 −23 README.plr
  2. +23 −12 pg_backend_support.c
  3. +24 −12 pg_conversion.c
  4. +1 −2 pg_rsupport.c
  5. +54 −5 pg_userfuncs.c
  6. +12 −9 plr.c
  7. +53 −32 plr.h
View
@@ -2,7 +2,7 @@
* PL/R - PostgreSQL support for R as a
* procedural language (PL)
*
- * Copyright (c) 2003-2009 by Joseph E. Conway
+ * Copyright (c) 2003-2010 by Joseph E. Conway
* ALL RIGHTS RESERVED
*
* Joe Conway <mail@joeconway.com>
@@ -47,30 +47,10 @@ Installation:
See http://www.joeconway.com/plr/doc/plr-install.html
for the most up-to-date instructions.
- Place these files in a directory called 'plr' under 'contrib' in the
- PostgreSQL source tree. E.g. place the tarred source file in
- '/path/to/pg_source/contrib' and run:
-
- tar -xzf plr-x.y.z-alpha.tar.gz
-
- Then run:
-
- cd /path/to/pg_source/contrib/plr
- make
- make install
- make installcheck
-
- This is usually best done logged in as the PostgreSQL superuser
- (defaults to postgres), except root privileges may be needed for
- "make install".
-
- You can use plr.sql to create the functions in your database of choice, e.g.
-
- psql mydatabase < plr.sql
-
Documentation:
- See the following files:
+ See the following:
+ See http://www.joeconway.com/plr/doc/
doc/plr.sgml - PL/R documentation source
doc/*.html - Preprocessed html version of the documentation
View
@@ -2,7 +2,7 @@
* PL/R - PostgreSQL support for R as a
* procedural language (PL)
*
- * Copyright (c) 2003-2009 by Joseph E. Conway
+ * Copyright (c) 2003-2010 by Joseph E. Conway
* ALL RIGHTS RESERVED
*
* Joe Conway <mail@joeconway.com>
@@ -32,20 +32,12 @@
*/
#include "plr.h"
-#include "miscadmin.h"
-#include "optimizer/clauses.h"
-#include "utils/memutils.h"
-
#ifdef PGDLLIMPORT
-/* GUC variable */
-extern PGDLLIMPORT char *Dynamic_library_path;
/* Postgres global */
-extern PGDLLIMPORT char pkglib_path[];
+extern PGDLLIMPORT char my_exec_path[];
#else
-/* GUC variable */
-extern DLLIMPORT char *Dynamic_library_path;
/* Postgres global */
-extern DLLIMPORT char pkglib_path[];
+extern DLLIMPORT char my_exec_path[];
#endif /* PGDLLIMPORT */
/* compiled function hash table */
@@ -231,7 +223,23 @@ get_lib_pathstr(Oid funcid)
tmp = SysCacheGetAttr(PROCOID, procedureTuple, Anum_pg_proc_probin, &isnull);
raw_path = DatumGetCString(DirectFunctionCall1(byteaout, tmp));
- cooked_path = expand_dynamic_library_name(raw_path);
+
+ /* Recognize hex input */
+ if (raw_path[0] == '\\' && raw_path[1] == 'x')
+ {
+ char *result;
+ int bc;
+ size_t len = strlen(raw_path);
+
+ bc = (len - 2)/2 + 1; /* maximum possible length */
+ result = palloc0(bc);
+
+ bc = hex_decode(raw_path + 2, len - 2, result);
+ cooked_path = expand_dynamic_library_name(result);
+ }
+ else
+ cooked_path = expand_dynamic_library_name(raw_path);
+
if (!cooked_path)
cooked_path = pstrdup(raw_path);
@@ -350,8 +358,10 @@ substitute_libpath_macro(const char *name)
{
const char *sep_ptr;
char *ret;
+ char pkglib_path[MAXPGPATH];
AssertArg(name != NULL);
+ get_pkglib_path(my_exec_path, pkglib_path);
if (name[0] != '$')
return pstrdup(name);
@@ -384,6 +394,7 @@ find_in_dynamic_libpath(const char *basename)
{
const char *p;
size_t baselen;
+ char *Dynamic_library_path = GetConfigOptionByName("dynamic_library_path", NULL);
AssertArg(basename != NULL);
AssertArg(strchr(basename, '/') == NULL);
View
@@ -2,7 +2,7 @@
* PL/R - PostgreSQL support for R as a
* procedural language (PL)
*
- * Copyright (c) 2003-2009 by Joseph E. Conway
+ * Copyright (c) 2003-2010 by Joseph E. Conway
* ALL RIGHTS RESERVED
*
* Joe Conway <mail@joeconway.com>
@@ -33,9 +33,6 @@
* to pg types
*/
#include "plr.h"
-#include "funcapi.h"
-#include "miscadmin.h"
-#include "catalog/catversion.h"
static void pg_get_one_r(char *value, Oid arg_out_fn_oid, SEXP *obj,
int elnum);
@@ -896,9 +893,11 @@ get_frame_array_datum(SEXP rval, plr_function *function, int col, bool *isnull)
ArrayType *array;
int nr = 0;
int nc = length(rval);
- int ndims = 2;
- int dims[ndims];
- int lbs[ndims];
+#define FIXED_NUM_DIMS 2
+ int ndims = FIXED_NUM_DIMS;
+ int dims[FIXED_NUM_DIMS];
+ int lbs[FIXED_NUM_DIMS];
+#undef FIXED_NUM_DIMS
int idx;
SEXP dfcol = NULL;
int j;
@@ -1009,13 +1008,24 @@ get_md_array_datum(SEXP rval, int ndims, plr_function *function, int col, bool *
int nr = 1;
int nc = 1;
int nz = 1;
- int dims[ndims];
- int lbs[ndims];
+ int *dims;
+ int *lbs;
int idx;
int cntr = 0;
bool *nulls;
bool have_nulls = FALSE;
+ if (ndims > 0)
+ {
+ dims = palloc(ndims * sizeof(int));
+ lbs = palloc(ndims * sizeof(int));
+ }
+ else
+ {
+ dims = NULL;
+ lbs = NULL;
+ }
+
if (function->result_istuple)
{
result_elem = function->result_fld_elem_typid[col];
@@ -1122,9 +1132,11 @@ get_generic_array_datum(SEXP rval, plr_function *function, int col, bool *isnull
int i;
Datum *dvalues = NULL;
ArrayType *array;
- int ndims = 1;
- int dims[ndims];
- int lbs[ndims];
+#define FIXED_NUM_DIMS 1
+ int ndims = FIXED_NUM_DIMS;
+ int dims[FIXED_NUM_DIMS];
+ int lbs[FIXED_NUM_DIMS];
+#undef FIXED_NUM_DIMS
bool *nulls;
bool have_nulls = FALSE;
View
@@ -2,7 +2,7 @@
* PL/R - PostgreSQL support for R as a
* procedural language (PL)
*
- * Copyright (c) 2003-2009 by Joseph E. Conway
+ * Copyright (c) 2003-2010 by Joseph E. Conway
* ALL RIGHTS RESERVED
*
* Joe Conway <mail@joeconway.com>
@@ -31,7 +31,6 @@
* pg_rsupport.c - Postgres support for use within plr functions
*/
#include "plr.h"
-#include "utils/memutils.h"
extern MemoryContext plr_SPI_context;
extern char *last_R_error_msg;
View
@@ -2,7 +2,7 @@
* PL/R - PostgreSQL support for R as a
* procedural language (PL)
*
- * Copyright (c) 2003-2009 by Joseph E. Conway
+ * Copyright (c) 2003-2010 by Joseph E. Conway
* ALL RIGHTS RESERVED
*
* Joe Conway <mail@joeconway.com>
@@ -32,10 +32,9 @@
*/
#include "plr.h"
-#include "miscadmin.h"
-#include "utils/memutils.h"
-
+#ifndef WIN32
extern char **environ;
+#endif
static ArrayType *plr_array_create(FunctionCallInfo fcinfo,
int numelems, int elem_start);
@@ -281,10 +280,17 @@ plr_environ(PG_FUNCTION_ARGS)
AttInMetadata *attinmeta;
MemoryContext per_query_ctx;
MemoryContext oldcontext;
- char **current_env;
char *var_name;
char *var_val;
char *values[2];
+#ifndef WIN32
+ char **current_env;
+#else
+ char *buf;
+ LPTSTR envstr;
+ int count = 0;
+ int i;
+#endif
/* check to see if caller supports us returning a tuplestore */
if (!rsinfo || !(rsinfo->allowedModes & SFRM_Materialize))
@@ -319,6 +325,7 @@ plr_environ(PG_FUNCTION_ARGS)
/* initialize our tuplestore */
tupstore = TUPLESTORE_BEGIN_HEAP;
+#ifndef WIN32
for (current_env = environ;
current_env != NULL && *current_env != NULL;
current_env++)
@@ -340,7 +347,49 @@ plr_environ(PG_FUNCTION_ARGS)
tuplestore_puttuple(tupstore, tuple);
pfree(var_name);
}
+#else
+ buf = GetEnvironmentStrings();
+ envstr = buf;
+
+ while (true)
+ {
+ if (*envstr == 0)
+ break;
+ while (*envstr != 0)
+ envstr++;
+ envstr++;
+ count++;
+ }
+
+ while(*buf == '=')
+ buf++;
+ for (i = 0; i < count; i++)
+ {
+ Size name_len;
+
+ var_val = strchr(buf, '=');
+ if (!var_val)
+ continue;
+
+ name_len = var_val - buf;
+ var_name = (char *) palloc0(name_len + 1);
+ memcpy(var_name, buf, name_len);
+
+ values[0] = var_name;
+ values[1] = var_val + 1;
+
+ tuple = BuildTupleFromCStrings(attinmeta, values);
+ tuplestore_puttuple(tupstore, tuple);
+ pfree(var_name);
+
+ while(*buf != '\0')
+ buf++;
+ buf++;
+ }
+ FreeEnvironmentStrings(buf);
+#endif
+
/*
* no longer need the tuple descriptor reference created by
* TupleDescGetAttInMetadata()
View
21 plr.c
@@ -2,7 +2,7 @@
* PL/R - PostgreSQL support for R as a
* procedural language (PL)
*
- * Copyright (c) 2003-2009 by Joseph E. Conway
+ * Copyright (c) 2003-2010 by Joseph E. Conway
* ALL RIGHTS RESERVED
*
* Joe Conway <mail@joeconway.com>
@@ -31,10 +31,6 @@
* plr.c - Language handler and support functions
*/
#include "plr.h"
-#include "catalog/pg_namespace.h"
-#include "storage/ipc.h"
-#include "utils/memutils.h"
-#include "utils/typcache.h"
PG_MODULE_MAGIC;
@@ -592,15 +588,22 @@ plr_trigger_handler(PG_FUNCTION_ARGS)
bool argnull[FUNC_MAX_ARGS];
TriggerData *trigdata = (TriggerData *) fcinfo->context;
TupleDesc tupdesc = trigdata->tg_relation->rd_att;
- Datum dvalues[trigdata->tg_trigger->tgnargs];
+ Datum *dvalues;
ArrayType *array;
- int ndims = 1;
- int dims[ndims];
- int lbs[ndims];
+#define FIXED_NUM_DIMS 1
+ int ndims = FIXED_NUM_DIMS;
+ int dims[FIXED_NUM_DIMS];
+ int lbs[FIXED_NUM_DIMS];
+#undef FIXED_NUM_DIMS
TRIGGERTUPLEVARS;
ERRORCONTEXTCALLBACK;
int i;
+ if (trigdata->tg_trigger->tgnargs > 0)
+ dvalues = palloc(trigdata->tg_trigger->tgnargs * sizeof(Datum));
+ else
+ dvalues = NULL;
+
/* Find or compile the function */
function = compile_plr_function(fcinfo);
Oops, something went wrong.

0 comments on commit 85e0638

Please sign in to comment.