summaryrefslogtreecommitdiff
path: root/src/pl/plperl/plperl.c
AgeCommit message (Collapse)Author
2006-04-04Modify all callers of datatype input and receive functions so that if theseTom Lane
functions are not strict, they will be called (passing a NULL first parameter) during any attempt to input a NULL value of their datatype. Currently, all our input functions are strict and so this commit does not change any behavior. However, this will make it possible to build domain input functions that centralize checking of domain constraints, thereby closing numerous holes in our domain support, as per previous discussion. While at it, I took the opportunity to introduce convenience functions InputFunctionCall, OutputFunctionCall, etc to use in code that calls I/O functions. This eliminates a lot of grotty-looking casts, but the main motivation is to make it easier to grep for these places if we ever need to touch them again.
2006-03-19Fix a few places that were checking for the return value of palloc() to beNeil Conway
non-NULL: palloc() ereports on OOM, so we can safely assume it returns a valid pointer.
2006-03-14Improve parser so that we can show an error cursor position for errorsTom Lane
during parse analysis, not only errors detected in the flex/bison stages. This is per my earlier proposal. This commit includes all the basic infrastructure, but locations are only tracked and reported for errors involving column references, function calls, and operators. More could be done later but this seems like a good set to start with. I've also moved the ReportSyntaxErrorPosition logic out of psql and into libpq, which should make it available to more people --- even within psql this is an improvement because warnings weren't handled by ReportSyntaxErrorPosition.
2006-03-11Remove copyright notices from Jan (per author approval), and those filesBruce Momjian
derived from Jan's.
2006-03-05Prepared queries for PLPerl, plus fixing a small plperl memory leak. PatchAndrew Dunstan
and docs from Dmitry Karasik, slightly editorialised.
2006-02-28Fix typo in comment.Neil Conway
2006-02-26Fix a few minor typos in comments in PL/Perl.Neil Conway
2006-01-28Undo perl's nasty locale setting on Windows. Since we can't do that asAndrew Dunstan
elsewhere by setting the environment appropriately, we make perl do it right after interpreter startup by calling its POSIX::setlocale().
2006-01-28Per a bug report from Theo Schlossnagle, plperl_return_next() leaksNeil Conway
memory in the executor's per-query memory context. It also inefficient: it invokes get_call_result_type() and TupleDescGetAttInMetadata() for every call to return_next, rather than invoking them once (per PL/Perl function call) and memoizing the result. This patch makes the following changes: - refactor the code to include all the "per PL/Perl function call" data inside a single struct, "current_call_data". This means we don't need to save and restore N pointers for every recursive call into PL/Perl, we can just save and restore one. - lookup the return type metadata needed by plperl_return_next() once, and then stash it in "current_call_data", so as to avoid doing the lookup for every call to return_next. - create a temporary memory context in which to evaluate the return type's input functions. This memory context is reset for each call to return_next. The patch appears to fix the memory leak, and substantially reduces the overhead imposed by return_next.
2006-01-08Rationalise perl header inclusions via a common include file, which alsoAndrew Dunstan
declares routines in plperl.c and spi_internal.c used in other files. Along the way, also stop perl from hijacking stdio and other stuff on Windows.
2005-12-29Move declaration of check_function_bodies to where the perl headersAndrew Dunstan
haven't had a chance to mangle the definition of DLLIMPORT (thanks again, perl guys).
2005-12-28Fix plperl validator to honor check_function_bodies: when that is OFF,Tom Lane
we want it to check the argument/result data types and no more. In particular, libperl shouldn't get initialized in this case.
2005-11-22Re-run pgindent, fixing a problem where comment lines after a blankBruce Momjian
comment line where output as too long, and update typedefs for /lib directory. Also fix case where identifiers were used as variable names in the backend, but as typedefs in ecpg (favor the backend for indenting). Backpatch to 8.1.X.
2005-11-18translate undef to NULL for result arrayref, now that we allow NULLs in ↵Andrew Dunstan
arrays. Update plperl regression test accordingly.
2005-10-18Code review for spi_query/spi_fetchrow patch: handle errors sanely,Tom Lane
avoid leaking memory. I would add a regression test for error handling except it seems eval{} can't be used in unprivileged plperl :-(
2005-10-15Standard pgindent run for 8.1.Bruce Momjian
2005-08-24Get rid of inappropriate use of croak(). Per report from Michael Fuhr.Tom Lane
2005-08-24Fix up plperl 'use_strict' so that it can be enabled or disabled on theTom Lane
fly. Fix problem with incompletely duplicated setup code. Andrew Dunstan, from an idea of Michael Fuhr's.
2005-08-20Invoke mksafefunc and mkunsafefunc with :: decoration. This seems a goodTom Lane
idea on consistency grounds, whether or not it really fixes bug #1831. Michael Fuhr
2005-08-12Un-break plperl for non-set case.Tom Lane
2005-08-12More rsi assignment line too.Bruce Momjian
2005-08-12> The attached patch moves a plperl sanity check into the correctBruce Momjian
> position. Performing the check in the existing position allows the call > to go through to perl first, possibly resulting in a SEGV. Andrew Dunstan
2005-07-12Fix plperl crash with list value return for an array result type.Tom Lane
Reported by Michael Fuhr, fixed by Andrew Dunstan.
2005-07-12Fix plperl to do recursion safely, and fix a problem with array results.Tom Lane
Add suitable regression tests. Andrew Dunstan
2005-07-10Rename xmalloc to pg_malloc for consistency with psql usage.Bruce Momjian
Add missing plperl include.
2005-07-10Following up a previous thought I had, yesterday I realised how toBruce Momjian
return arays nicely without having to make the plperl programmer aware of anything. The attached patch allows plperl to return an arrayref where the function returns an array type. It silently calls a perl function to stringify the array before passing it to the pg array parser. Non-array returns are handled as before (i.e. passed through this process) so it is backwards compatible. I will presently submit regression tests and docs. example: andrew=# create or replace function blah() returns text[][] language plperl as $$ return [['a"b','c,d'],['e\\f','g']]; $$; CREATE FUNCTION andrew=# select blah(); blah ----------------------------- {{"a\"b","c,d"},{"e\\f",g}} This would complete half of the TODO item: . Pass arrays natively instead of as text between plperl and postgres (The other half is translating pg array arguments to perl arrays - that will have to wait for 8.1). Some of this patch is adapted from a previously submitted patch from Sergej Sergeev. Both he and Abhijit Menon-Sen have looked it over briefly and tentatively said it looks ok. Andrew Dunstan
2005-07-10The attached patch implements spi_query() and spi_fetchrow() functionsBruce Momjian
for PL/Perl, to avoid loading the entire result set into memory as the existing spi_exec_query() function does. Here's how one might use the new functions: $x = spi_query("select ..."); while (defined ($y = spi_fetchrow($x))) { ... return_next(...); } The changes do not affect the spi_exec_query() interface in any way. Abhijit Menon-Sen
2005-07-06Currently, nonfatal warnings are not trapped (as they should be) byBruce Momjian
plperl - the attached small patch remedies that omission, and adds a small regression test for error and warning output - the new regression input and expected output are in separate attached files. Andrew Dunstan
2005-07-06Currently, nonfatal warnings are not trapped (as they should be) byBruce Momjian
plperl - the attached small patch remedies that omission. Andrew Dunstan
2005-07-03Fix memory leak in plperl_hash_from_tuple(), per report from Jean-Max Reymond.Tom Lane
2005-06-22Add a validator function for plperl. Andrew DunstanTom Lane
2005-06-15> Here's a patch I added against plperl, originally against beta5, nowBruce Momjian
> against rc1. It simply checks with GetDatabaseEncoding() if the current > database is in UTF-8, and if so, sets the UTF-8 flag on the arguments > that are passed to perl. This means that it isn't necessary to > utf8::upgrade() every string, as perl has no way of knowing offhand > that a string is UTF-8 -- but postgres does, because the database > encoding is specified, so it makes sense to turn the flag on. You > should also be able to properly manipulate UTF-8 strings now from > plperl as opposed to plperlu, because otherwise you'd have to use > encoding 'utf8' which was not allowed. It could also eliminate some > unexpected bugs if you assume that perl knows the string is unicode. It > is enabled only for perl 5.6 and higher, so earlier versions will not > be affected. > > I have been assured by crab that the patch is quite harmless and will > not break anything. It would be great to see it in 8 final! :-) David Kamholz
2005-06-05Here's a patch to do the following:Bruce Momjian
1. Rename spi_return_next to return_next. 2. Add a new test for return_next. 3. Update the expected output. 4. Update the documentation. Abhijit Menon-Sen
2005-06-04At 2005-05-21 20:18:50 +0530, ams@oryx.com wrote:Bruce Momjian
> > > The second issue is where plperl returns a large result set. I have attached the following seven patches to address this problem: 1. Trivial. Replaces some errant spaces with tabs. 2. Trivial. Fixes the spelling of Jan's name, and gets rid of many inane, useless, annoying, and often misleading comments. Here's a sample: "plperl_init_all() - Initialize all". (I have tried to add some useful comments here and there, and will continue to do so now and again.) 3. Trivial. Splits up some long lines. 4. Converts SRFs in PL/Perl to use a Tuplestore and SFRM_Materialize to return the result set, based on the PL/PgSQL model. There are two major consequences: result sets will spill to disk when they can no longer fit in work_mem; and "select foo_srf()" no longer works. (I didn't lose sleep over the latter, since that form is not valid in PL/PgSQL, and it's not documented in PL/Perl.) 5. Trivial, but important. Fixes use of "undef" instead of undef. This would cause empty functions to fail in bizarre ways. I suspect that there's still another (old) bug here. I'll investigate further. 6. Moves the majority of (4) out into a new plperl_return_next() function, to make it possible to expose the functionality to Perl; cleans up some of the code besides. 7. Add an spi_return_next function for use in Perl code. If you want to apply the patches and try them out, 8-composite.diff is what you should use. (Note: my patches depend upon Andrew's use-strict and %_SHARED patches being applied.) Here's something to try: create or replace function foo() returns setof record as $$ $i = 0; for ("World", "PostgreSQL", "PL/Perl") { spi_return_next({f1=>++$i, f2=>'Hello', f3=>$_}); } return; $$ language plperl; select * from foo() as (f1 integer, f2 text, f3 text); (Many thanks to Andrews Dunstan and Supernews for their help.) Abhijit Menon-Sen
2005-05-23Fix typo in PL/Perl Safe.pm initialization that prevented the properNeil Conway
sharing of %_SHARED. From Andrew Dunstan.
2005-05-06For some reason access/tupmacs.h has been #including utils/memutils.h,Tom Lane
which is neither needed by nor related to that header. Remove the bogus inclusion and instead include the header in those C files that actually need it. Also fix unnecessary inclusions and bad inclusion order in tsearch2 files.
2005-05-01Change CREATE TYPE to require datatype output and send functions to haveTom Lane
only one argument. (Per recent discussion, the option to accept multiple arguments is pretty useless for user-defined types, and would be a likely source of security holes if it was used.) Simplify call sites of output/send functions to not bother passing more than one argument.
2005-04-01Make plperl work with OUT parameters.Tom Lane
2005-03-29Convert oidvector and int2vector into variable-length arrays. ThisTom Lane
change saves a great deal of space in pg_proc and its primary index, and it eliminates the former requirement that INDEX_MAX_KEYS and FUNC_MAX_ARGS have the same value. INDEX_MAX_KEYS is still embedded in the on-disk representation (because it affects index tuple header size), but FUNC_MAX_ARGS is not. I believe it would now be possible to increase FUNC_MAX_ARGS at little cost, but haven't experimented yet. There are still a lot of vestigial references to FUNC_MAX_ARGS, which I will clean up in a separate pass. However, getting rid of it altogether would require changing the FunctionCallInfoData struct, and I'm not sure I want to buy into that.
2005-02-23Properly undef _(x) gettext macro.Bruce Momjian
2005-02-22Use _() macro consistently rather than gettext(). Add translationBruce Momjian
macros around strings that were missing them.
2005-01-14plperl trigger handler tried to fetch new/old tuples even when firedTom Lane
as a statement trigger :-(. Per report from Sokolov Yura.
2005-01-11plperl was not being quite paranoid enough about detecting 'undef' valuesTom Lane
returned by Perl. Per report from Nicolas Addington.
2004-11-29Update plperl to use ereport() not elog() for user-facing messages,Tom Lane
so that they will be translatable. Give messages some semblance of conformance to the style guide.
2004-11-24Avoid getting bit by roundoff error while checking $Safe::VERSION.Tom Lane
Per report from Mark Kirkwood.
2004-11-23Further plperl cleanup: be more paranoid about checking the type ofTom Lane
data returned from Perl. Consolidate multiple bits of code to convert a Perl hash to a tuple, and drive the conversion off the keys present in the hash rather than the tuple column names, so we detect error if the hash contains keys it shouldn't. (This means keys not in the hash will silently default to NULL, which seems ok to me.) Fix a bunch of reference-count leaks too.
2004-11-22Try to instill some sanity in plperl's function result processing.Tom Lane
Get rid of static variables for SETOF result, don't crash when called from non-FROM context, eliminate dead code, etc.
2004-11-21Suppress remaining compile warnings, and add a comment about whyTom Lane
it's not really broken. Andrew Dunstan
2004-11-21Fix plperl and pltcl error handling per my previous proposal. SPITom Lane
operations are now run as subtransactions, so that errors in them can be reported as ordinary Perl or Tcl errors and caught by the normal error handling convention of those languages. Also do some minor code cleanup in pltcl.c: extract a large chunk of duplicated code in pltcl_SPI_execute and pltcl_SPI_execute_plan into a shared subroutine.
2004-11-20Fix plperl's elog() function to convert elog(ERROR) into Perl croak(),Tom Lane
rather than longjmp'ing clear out of Perl and thereby leaving Perl in a broken state. Also some minor prettification of error messages. Still need to do something with spi_exec_query() error handling.