aboutsummaryrefslogtreecommitdiff
path: root/src/pl/plpython/plpython.c
Commit message (Collapse)AuthorAge
* Restructure some header files a bit, in particular heapam.h, by removing someAlvaro Herrera2008-05-12
| | | | | | | | | | | | unnecessary #include lines in it. Also, move some tuple routine prototypes and macros to htup.h, which allows removal of heapam.h inclusion from some .c files. For this to work, a new header file access/sysattr.h needed to be created, initially containing attribute numbers of system columns, for pg_dump usage. While at it, make contrib ltree, intarray and hstore header files more consistent with our header style.
* Fix plpython to not get totally confused by OUT arguments. (It still doesn'tTom Lane2008-05-03
| | | | | | support multiple OUT arguments, though.) Hannu Krosing
* Support statement-level ON TRUNCATE triggers. Simon RiggsTom Lane2008-03-28
|
* Simplify and standardize conversions between TEXT datums and ordinary CTom Lane2008-03-25
| | | | | | | | | | | | | | | | | | | | strings. This patch introduces four support functions cstring_to_text, cstring_to_text_with_len, text_to_cstring, and text_to_cstring_buffer, and two macros CStringGetTextDatum and TextDatumGetCString. A number of existing macros that provided variants on these themes were removed. Most of the places that need to make such conversions now require just one function or macro call, in place of the multiple notational layers that used to be needed. There are no longer any direct calls of textout or textin, and we got most of the places that were using handmade conversions via memcpy (there may be a few still lurking, though). This commit doesn't make any serious effort to eliminate transient memory leaks caused by detoasting toasted text objects before they reach text_to_cstring. We changed PG_GETARG_TEXT_P to PG_GETARG_TEXT_PP in a few places where it was easy, but much more could be done. Brendan Jurd and Tom Lane
* Fix plpython's overoptimistic caching of information about the rowtype ofTom Lane2008-01-02
| | | | | | | | | | | a trigger's target table. The rowtype could change from one call to the next, so cope in such cases, while avoiding doing repetitive catalog lookups. Per bug #3847 from Mark Reid. Backpatch to 8.2.x. Likely this fix should go further back, but I can't test it because I no longer have a machine with a pre-2.5 Python installation. (Maybe we should rethink that idea about not supporting Python 2.5 in the older branches.)
* Fix buggy usage of vsnprintf in PL/Python by removing it altogether, insteadAlvaro Herrera2007-11-23
| | | | | relying on stringinfo.c. This fixes a problem reported by Marko Kreen, but I didn't use his patch, per subsequent discussion.
* pgindent run for 8.3.Bruce Momjian2007-11-15
|
* Fix uninitialized-memory bug in plpython proargnames patch. Per bug #3523Tom Lane2007-08-10
|
* Volatile-qualify a dozen variables in plpython.c to eliminate warningsTom Lane2007-07-13
| | | | | | from old versions of gcc. It's not clear to me that this is really necessary for correctness, but less warnings are always good. Per buildfarm results and local testing.
* Make some messages more consistentPeter Eisentraut2007-05-31
|
* Remove plpython casts C source code casts:Bruce Momjian2007-04-04
| | | | | | | | | | | | | | It removes last remaining casts inside struct definitions. Such usage is bad practice, as it hides problems from compiler. Reason for the cast is popular practice in some circles to define functions as foo(MyObj *) instead of foo(PyObject *) thus avoiding a local variable inside functions and make direct calling easier. As pl/python does not use such style, the casts were unnecessary from the start. Marko Kreen
* Allow pl/pythonu >= version 2.3 to return boolean, rather than 1/0.Bruce Momjian2007-04-03
| | | | Marko Kreen
* Allow PL/PythonU to compile on Python 2.5. Change needed because of APIBruce Momjian2007-04-03
| | | | | | changes in Python. Marko Kreen
* Support enum data types. Along the way, use macros for the values ofTom Lane2007-04-02
| | | | | pg_type.typtype whereever practical. Tom Dunstan, with some kibitzing from Tom Lane.
* Allow pltcl args to spi_prepare and plpython args to plpy.prepare to be ↵Andrew Dunstan2007-02-21
| | | | standard type aliases as well as those known in pg_type. Similar to recent change in plperl.
* Combine cmin and cmax fields of HeapTupleHeaders into a single field, byTom Lane2007-02-09
| | | | | | | | | | keeping private state in each backend that has inserted and deleted the same tuple during its current top-level transaction. This is sufficient since there is no need to be able to determine the cmin/cmax from any other transaction. This gets us back down to 23-byte headers, removing a penalty paid in 8.0 to support subtransactions. Patch by Heikki Linnakangas, with minor revisions by moi, following a design hashed out awhile back on the pghackers list.
* Wording cleanup for error messages. Also change can't -> cannot.Bruce Momjian2007-02-01
| | | | | | | | | | | | | | Standard English uses "may", "can", and "might" in different ways: may - permission, "You may borrow my rake." can - ability, "I can lift that log." might - possibility, "It might rain today." Unfortunately, in conversational English, their use is often mixed, as in, "You may use this variable to do X", when in fact, "can" is a better choice. Similarly, "It may crash" is better stated, "It might crash".
* Fix plpython MSVC build in non-debug mode.Andrew Dunstan2007-01-28
|
* Reverse out use of Py_RETURN_TRUE in plpython, only supported in Python >=Bruce Momjian2007-01-25
| | | | 2.3.
* Fix for plpython functions; return true/false for boolean,Bruce Momjian2007-01-25
| | | | | | | rather than 1/0. This helps when creating trigger functions that output SQL. Guido Goldstein
* Fix plpython to work (or at least pass its regression tests) withTom Lane2006-11-21
| | | | | | python 2.5. This involves fixing several violations of the published spec for creating PyTypeObjects, and adding another regression test expected output for yet another variation of error message spelling.
* pgindent run for 8.2.Bruce Momjian2006-10-04
|
* Define errcode as __msvc_errcode not __vc_errcode for MSVC builds,Tom Lane2006-09-16
| | | | per Magnus.
* Allow PL/python to return composite types and result setsBruce Momjian2006-09-02
| | | | Sven Suursoho
* Add new return codes SPI_OK_INSERT_RETURNING etc to the SPI API.Tom Lane2006-08-27
| | | | | | | Fix all the standard PLs to be able to return tuples from FOO_RETURNING statements as well as utility statements that return tuples. Also, fix oversight that SPI_processed wasn't set for a utility statement returning tuples. Per recent discussion.
* Add a feature for automatic initialization and finalization of dynamicallyTom Lane2006-08-08
| | | | | | | | | loaded libraries: call functions _PG_init() and _PG_fini() if the library defines such symbols. Hence we no longer need to specify an initialization function in preload_libraries: we can assume that the library used the _PG_init() convention, instead. This removes one source of pilot error in use of preloaded libraries. Original patch by Ralf Engelschall, preload_libraries changes by me.
* Attached patch is required ot build with the CRT that comes with VisualBruce Momjian2006-07-06
| | | | | | | | | | Studio 2005. Basically MS defined errcode in the headers with a typedef, so we have to #define it out of the way. While at it, fix a function declaration in plpython that didn't match the implementation (volatile missing). Magnus Hagander
* Fix Win32/Cygwin problems:Bruce Momjian2006-06-25
| | | | | | | | | | | | | | After updating to the latest cvs, and also building most of the addons (like PLs), the following patch is neededf for win32 + Visual C++. * Switch to use the new win32 semaphore code * Rename win32_open to pgwin32_open. win32_open collides with symbols defined in Perl. MingW didn't detect ig, MSVC did. And it's a bit too generic a name to export globally, imho... * Python defines some partially broken #pragmas in the headers when doing a debug build. Workaround. Magnus Hagander
* Fix problems with cached tuple descriptors disappearing while still in useTom Lane2006-06-16
| | | | | | | | | | by creating a reference-count mechanism, similar to what we did a long time ago for catcache entries. The back branches have an ugly solution involving lots of extra copies, but this way is more efficient. Reference counting is only applied to tupdescs that are actually in caches --- there seems no need to use it for tupdescs that are generated in the executor, since they'll go away during plan shutdown by virtue of being in the per-query memory context. Neil Conway and Tom Lane
* Magic blocks don't do us any good unless we use 'em ... so install oneTom Lane2006-05-30
| | | | in every shared library.
* Add table_name and table_schema to plpython trigger data, plus docs and ↵Andrew Dunstan2006-05-26
| | | | regression test.
* Revert patch, causing plpython regression failues:Bruce Momjian2006-04-27
| | | | | | > >> >> > 1) named parameters additionally to args[] > >> >> > 2) return composite-types from plpython as dictionary > >> >> > 3) return result-set from plpython as list, iterator or generator
* plpython improvements:Bruce Momjian2006-04-27
| | | | | | | | | 1) named parameters additionally to args[] 2) return composite-types from plpython as dictionary 3) return result-set from plpython as list, iterator or generator Hannu Krosing Sven Suursoho
* Modify all callers of datatype input and receive functions so that if theseTom Lane2006-04-04
| | | | | | | | | | | | | | | 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.
* Improve parser so that we can show an error cursor position for errorsTom Lane2006-03-14
| | | | | | | | | | | 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.
* Remove copyright notices from Jan (per author approval), and those filesBruce Momjian2006-03-11
| | | | derived from Jan's.
* This patch makes the error message strings throughout the backendNeil Conway2006-03-01
| | | | | | | | more compliant with the error message style guide. In particular, errdetail should begin with a capital letter and end with a period, whereas errmsg should not. I also fixed a few related issues in passing, such as fixing the repeated misspelling of "lexeme" in contrib/tsearch2 (per Tom's suggestion).
* Tweak the error message emitted when a void-returning PL/Python functionNeil Conway2006-02-28
| | | | does not return None, per suggestion from Tom.
* Allow PL/Python functions to return void, per gripe from James RobinsonNeil Conway2006-02-28
| | | | | | | (I didn't use his patch, however). A void-returning PL/Python function must return None (from Python), which is translated into a void datum (and *not* NULL) for Postgres. I also added some regression tests for this functionality.
* Fix three Python reference leaks in PLy_traceback(). This would resultNeil Conway2006-02-20
| | | | | | | | | | in leaking memory when invoking a PL/Python procedure that raises an exception. Unfortunately this still leaks memory, but at least the largest leak has been plugged. This patch also fixes a reference counting mistake in PLy_modify_tuple() for 8.0, 8.1 and HEAD: we don't actually own a reference to `platt', so we shouldn't Py_DECREF() it.
* In PLy_function_build_args(), the code loops repeatedly, constructingNeil Conway2006-01-10
| | | | | | | | | | | | | | | | one argument at a time and then inserting the argument into a Python list via PyList_SetItem(). This "steals" the reference to the argument: that is, the reference to the new list member is now held by the Python list itself. This works fine, except if an elog occurs. This causes the function's PG_CATCH() block to be invoked, which decrements the reference counts on both the current argument and the list of arguments. If the elog happens to occur during the second or subsequent iteration of the loop, the reference count on the current argument will be decremented twice. The fix is simple: set the local pointer to the current argument to NULL immediately after adding it to the argument list. This ensures that the Py_XDECREF() in the PG_CATCH() block doesn't double-decrement.
* Minor code cleanup for PL/Python: fixup some strangely formatted comments,Neil Conway2006-01-09
| | | | | and change two elogs into ereports because they could actually occur in practice.
* Index: src/pl/plpython/plpython.cNeil Conway2005-12-29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | =================================================================== RCS file: /Users/neilc/postgres/cvs_root/pgsql/src/pl/plpython/plpython.c,v retrieving revision 1.67 diff -c -r1.67 plpython.c *** src/pl/plpython/plpython.c 26 Dec 2005 04:28:48 -0000 1.67 --- src/pl/plpython/plpython.c 29 Dec 2005 16:54:57 -0000 *************** *** 2,8 **** * plpython.c - python as a procedural language for PostgreSQL * * This software is copyright by Andrew Bosma ! * but is really shameless cribbed from pltcl.c by Jan Weick, and * plperl.c by Mark Hollomon. * * The author hereby grants permission to use, copy, modify, --- 2,8 ---- * plpython.c - python as a procedural language for PostgreSQL * * This software is copyright by Andrew Bosma ! * but is really shamelessly cribbed from pltcl.c by Jan Wieck, and * plperl.c by Mark Hollomon. * * The author hereby grants permission to use, copy, modify, *************** *** 1996,2002 **** int i, rv; PLyPlanObject *plan; - char *nulls; MemoryContext oldcontext; if (list != NULL) --- 1996,2001 ---- *************** *** 2018,2024 **** if (nargs != plan->nargs) { char *sv; - PyObject *so = PyObject_Str(list); if (!so) --- 2017,2022 ---- *************** *** 2036,2048 **** oldcontext = CurrentMemoryContext; PG_TRY(); { ! nulls = palloc(nargs * sizeof(char)); for (i = 0; i < nargs; i++) { PyObject *elem, *so; - char *sv; elem = PySequence_GetItem(list, i); if (elem != Py_None) --- 2034,2045 ---- oldcontext = CurrentMemoryContext; PG_TRY(); { ! char *nulls = palloc(nargs * sizeof(char)); for (i = 0; i < nargs; i++) { PyObject *elem, *so; elem = PySequence_GetItem(list, i); if (elem != Py_None) *************** *** 2051,2070 **** if (!so) PLy_elog(ERROR, "function \"%s\" could not execute plan", PLy_procedure_name(PLy_curr_procedure)); ! sv = PyString_AsString(so); ! /* ! * FIXME -- if this elogs, we have Python reference leak ! */ ! plan->values[i] = ! FunctionCall3(&(plan->args[i].out.d.typfunc), ! CStringGetDatum(sv), ! ObjectIdGetDatum(plan->args[i].out.d.typioparam), ! Int32GetDatum(-1)); ! Py_DECREF(so); ! Py_DECREF(elem); nulls[i] = ' '; } else --- 2048,2073 ---- if (!so) PLy_elog(ERROR, "function \"%s\" could not execute plan", PLy_procedure_name(PLy_curr_procedure)); ! Py_DECREF(elem); ! PG_TRY(); ! { ! char *sv = PyString_AsString(so); ! plan->values[i] = ! FunctionCall3(&(plan->args[i].out.d.typfunc), ! CStringGetDatum(sv), ! ObjectIdGetDatum(plan->args[i].out.d.typioparam), ! Int32GetDatum(-1)); ! } ! PG_CATCH(); ! { ! Py_DECREF(so); ! PG_RE_THROW(); ! } ! PG_END_TRY(); + Py_DECREF(so); nulls[i] = ' '; } else
* Various cosmetic code cleanup for PL/Python:Neil Conway2005-12-26
| | | | | | | | | | | | - use "bool" rather than "int" for boolean variables - use "PLy_malloc" rather than "malloc" in two places - define "PLy_strdup", and use it rather than malloc() + strcpy() in two places (which should have been memcpy(), anyway). - remove a bunch of redundant parentheses from expressions that do not need the parentheses for code clarity
* Standard pgindent run for 8.1.Bruce Momjian2005-10-15
|
* This patch addresses the problem mentioned in the "process crashBruce Momjian2005-07-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | when a plpython function returns unicode" thread: http://archives.postgresql.org/pgsql-bugs/2005-06/msg00105.php In several places PL/Python was calling PyObject_Str() and then PyString_AsString() without checking if the former had returned NULL to indicate an error. PyString_AsString() doesn't expect a NULL argument, so passing one causes a segmentation fault. This patch adds checks for NULL and raises errors via PLy_elog(), which prints details of the underlying Python exception. The patch also adds regression tests for these checks. All tests pass on my Solaris 9 box running HEAD and Python 2.4.1. In one place the patch doesn't call PLy_elog() because that could cause infinite recursion; see the comment I added. I'm not sure how to test that particular case or whether it's even possible to get an error there: the value that the code should check is the Python exception type, so I wonder if a NULL value "shouldn't happen." This patch converts NULL to "Unknown Exception" but I wonder if an Assert() would be appropriate. The patch is against HEAD but the same changes should be applied to earlier versions because they have the same problem. The patch might not apply cleanly against earlier versions -- will the committer take care of little differences or should I submit different versions of the patch? Michael Fuhr
* Back out patch. This should be done like other server-side languages.Bruce Momjian2005-07-05
| | | | | | | | | | | | | | | | | --------------------------------------------------------------------------- This patch allows the PL/Python module to do (SRF) functions. The patch was taken from the CVS version. I have modified the plpython.c file and have added a test sql script for testing the functionality. It was actually the script that was in the 8.0.3 version but have since been removed. In order to signal the end of a set, the called python function must simply return plpy.EndOfSet and the set would be returned. Gerrit van Dyk
* This patch allows the PL/Python module to do (SRF) functions.Bruce Momjian2005-07-04
| | | | | | | | | | | | | The patch was taken from the CVS version. I have modified the plpython.c file and have added a test sql script for testing the functionality. It was actually the script that was in the 8.0.3 version but have since been removed. In order to signal the end of a set, the called python function must simply return plpy.EndOfSet and the set would be returned. Gerrit van Dyk
* For some reason access/tupmacs.h has been #including utils/memutils.h,Tom Lane2005-05-06
| | | | | | | 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.
* Change SPI functions to use a `long' when specifying the number of tuplesNeil Conway2005-05-02
| | | | | | | | to produce when running the executor. This is consistent with the internal executor APIs (such as ExecutorRun), which also use a long for this purpose. It also allows FETCH_ALL to be passed -- since FETCH_ALL is defined as LONG_MAX, this wouldn't have worked on platforms where int and long are of different sizes. Per report from Tzahi Fadida.