Skip to content

Commit

Permalink
Wrap PIR subroutines
Browse files Browse the repository at this point in the history
Stored procedures are now wrapped in their own anonymous subroutine, so that
users do not have the ability to override other functions
  • Loading branch information
leto committed Apr 15, 2010
1 parent 1a02f12 commit e4fe808
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 32 deletions.
20 changes: 16 additions & 4 deletions plparrot.c
Expand Up @@ -142,8 +142,11 @@ plparrot_func_handler(PG_FUNCTION_ARGS)
HeapTuple proctup;
Oid returntype, *argtypes;

int numargs, rc, i;
int numargs, rc, i, length;
char *proc_src, *errmsg, *tmp;
char *pir_src;
char pir_begin[13] = ".sub p :anon";
char pir_end[4] = ".end";
char **argnames, *argmodes;
bool isnull;

Expand All @@ -167,10 +170,19 @@ plparrot_func_handler(PG_FUNCTION_ARGS)
/* procstruct probably isn't valid after this ReleaseSysCache call, so don't use it anymore */
ReleaseSysCache(proctup);
proc_src = TextDatum2String(procsrc_datum);

/* elog(NOTICE,"about to compile a PIR string: %s", proc_src); */
length = strlen(proc_src);
pir_src = malloc( 13 + length + 4 );
memcpy(pir_src, pir_begin, 13);
/* This should have a sane default and be configurable */
strncat(pir_src, proc_src, 1000);
strncat(pir_src, pir_end, 4);

/* elog(NOTICE,"about to compile a PIR string: %s", pir_src); */
/* Our current plan of attack is the pass along a ResizablePMCArray to all stored procedures */
func_pmc = Parrot_compile_string(interp, create_string("PIR"), proc_src, &err);
func_pmc = Parrot_compile_string(interp, create_string("PIR"), pir_src, &err);

free(pir_src);

func_args = create_pmc("ResizablePMCArray");

for (i = 0; i < numargs; i++) {
Expand Down
28 changes: 0 additions & 28 deletions t/sql/test.sql
Expand Up @@ -26,102 +26,74 @@ SELECT true;
$$;

CREATE FUNCTION test_void() RETURNS void AS $$
.sub main :anon
.return()
.end
$$ LANGUAGE plparrot;

CREATE FUNCTION test_int() RETURNS int AS $$
.sub main :anon
.return(1)
.end
$$ LANGUAGE plparrot;

CREATE FUNCTION test_int_in(int) RETURNS int AS $$
.sub main :anon
.param int x
.return(1)
.end
$$ LANGUAGE plparrot;

CREATE FUNCTION test_int_out(int) RETURNS int AS $$
.sub main :anon
.param int x
.return(42)
.end
$$ LANGUAGE plparrot;

CREATE FUNCTION test_increment_int_int(int) RETURNS int AS $$
.sub main :anon
.param int x
inc x
.return(x)
.end
$$ LANGUAGE plparrot;

CREATE FUNCTION test_float() RETURNS float AS $$
.sub main :anon
$N0 = 1.0
.return($N0)
.end
$$ LANGUAGE plparrot;

CREATE FUNCTION test_float_add(float) RETURNS float AS $$
.sub main :anon
.param num x
x += 5
.return(x)
.end
$$ LANGUAGE plparrot;

CREATE FUNCTION test_text_in(text) RETURNS text AS $$
.sub main :anon
.param string s
.return(s)
.end
$$ LANGUAGE plparrot;

CREATE FUNCTION test_text_out(text) RETURNS text AS $$
.sub main :anon
$S1 = 'blue'
.return($S1)
.end
$$ LANGUAGE plparrot;

CREATE FUNCTION test_varchar_in(varchar) RETURNS varchar AS $$
.sub main :anon
.param string s
.return(s)
.end
$$ LANGUAGE plparrot;

CREATE FUNCTION test_varchar_out(varchar) RETURNS varchar AS $$
.sub main :anon
$S1 = 'blue'
.return($S1)
.end
$$ LANGUAGE plparrot;

CREATE FUNCTION test_char_in(char) RETURNS char AS $$
.sub main :anon
.param string s
.return(s)
.end
$$ LANGUAGE plparrot;

CREATE FUNCTION test_char_out(char) RETURNS char AS $$
.sub main :anon
$S1 = 'b'
.return($S1)
.end
$$ LANGUAGE plparrot;

CREATE FUNCTION test_int_float(int, float) RETURNS int AS $$
.sub main :anon
.param int x
.param num y
.return(1)
.end
$$ LANGUAGE plparrot;


Expand Down

0 comments on commit e4fe808

Please sign in to comment.