1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Revise handling of oldstyle/newstyle functions per recent discussions

in pghackers list.  Support for oldstyle internal functions is gone
(no longer needed, since conversion is complete) and pg_language entry
'internal' now implies newstyle call convention.  pg_language entry
'newC' is gone; both old and newstyle dynamically loaded C functions
are now called language 'C'.  A newstyle function must be identified
by an associated info routine.  See src/backend/utils/fmgr/README.
This commit is contained in:
Tom Lane
2000-11-20 20:36:57 +00:00
parent 99198ac6b8
commit 5bb2300b59
52 changed files with 571 additions and 328 deletions

View File

@ -15,30 +15,30 @@ CREATE FUNCTION widget_out(opaque)
CREATE FUNCTION check_primary_key ()
RETURNS opaque
AS '@abs_builddir@/../../../contrib/spi/refint@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION check_foreign_key ()
RETURNS opaque
AS '@abs_builddir@/../../../contrib/spi/refint@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION autoinc ()
RETURNS opaque
AS '@abs_builddir@/../../../contrib/spi/autoinc@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION funny_dup17 ()
RETURNS opaque
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION ttdummy ()
RETURNS opaque
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION set_ttdummy (int4)
RETURNS int4
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';

View File

@ -30,28 +30,33 @@ CREATE FUNCTION user_relns()
CREATE FUNCTION pt_in_widget(point, widget)
RETURNS bool
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION overpaid(emp)
RETURNS bool
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION boxarea(box)
RETURNS float8
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION interpt_pp(path, path)
RETURNS point
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION reverse_name(name)
RETURNS name
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'c';
CREATE FUNCTION oldstyle_length(int4, text)
RETURNS int4
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'c';
--
-- Function dynamic loading
--

View File

@ -215,6 +215,19 @@ SELECT user_relns() AS user_relns
--SELECT name(equipment(hobby_construct(text 'skywalking', text 'mer'))) AS equip_name;
--
-- check that old-style C functions work properly with TOASTed values
--
create table oldstyle_test(i int4, t text);
insert into oldstyle_test values(null,null);
insert into oldstyle_test values(0,'12');
insert into oldstyle_test values(1000,'12');
insert into oldstyle_test values(0, repeat('x', 50000));
select i, length(t), octet_length(t), oldstyle_length(i,t) from oldstyle_test;
drop table oldstyle_test;
--
-- functional joins
--

View File

@ -13,24 +13,24 @@ CREATE FUNCTION widget_out(opaque)
CREATE FUNCTION check_primary_key ()
RETURNS opaque
AS '@abs_builddir@/../../../contrib/spi/refint@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION check_foreign_key ()
RETURNS opaque
AS '@abs_builddir@/../../../contrib/spi/refint@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION autoinc ()
RETURNS opaque
AS '@abs_builddir@/../../../contrib/spi/autoinc@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION funny_dup17 ()
RETURNS opaque
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION ttdummy ()
RETURNS opaque
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION set_ttdummy (int4)
RETURNS int4
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';

View File

@ -23,23 +23,27 @@ CREATE FUNCTION user_relns()
CREATE FUNCTION pt_in_widget(point, widget)
RETURNS bool
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION overpaid(emp)
RETURNS bool
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION boxarea(box)
RETURNS float8
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION interpt_pp(path, path)
RETURNS point
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'newC';
LANGUAGE 'C';
CREATE FUNCTION reverse_name(name)
RETURNS name
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'c';
CREATE FUNCTION oldstyle_length(int4, text)
RETURNS int4
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'c';
--
-- Function dynamic loading
--

View File

@ -657,6 +657,24 @@ SELECT user_relns() AS user_relns
--SELECT name(equipment(hobby_construct(text 'skywalking', text 'mer'))) AS equip_name;
--
-- check that old-style C functions work properly with TOASTed values
--
create table oldstyle_test(i int4, t text);
insert into oldstyle_test values(null,null);
insert into oldstyle_test values(0,'12');
insert into oldstyle_test values(1000,'12');
insert into oldstyle_test values(0, repeat('x', 50000));
select i, length(t), octet_length(t), oldstyle_length(i,t) from oldstyle_test;
i | length | octet_length | oldstyle_length
------+--------+--------------+-----------------
| | |
0 | 2 | 2 | 2
1000 | 2 | 2 | 1002
0 | 50000 | 581 | 50000
(4 rows)
drop table oldstyle_test;
--
-- functional joins
--
--

View File

@ -1,5 +1,5 @@
/*
* $Header: /cvsroot/pgsql/src/test/regress/regress.c,v 1.44 2000/08/24 23:34:11 tgl Exp $
* $Header: /cvsroot/pgsql/src/test/regress/regress.c,v 1.45 2000/11/20 20:36:53 tgl Exp $
*/
#include <float.h> /* faked on sunos */
@ -25,10 +25,13 @@ extern void regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2);
extern Datum overpaid(PG_FUNCTION_ARGS);
extern Datum boxarea(PG_FUNCTION_ARGS);
extern char *reverse_name(char *string);
extern int oldstyle_length(int n, text *t);
/*
** Distance from a point to a path
*/
PG_FUNCTION_INFO_V1(regress_dist_ptpath);
Datum
regress_dist_ptpath(PG_FUNCTION_ARGS)
{
@ -69,6 +72,8 @@ regress_dist_ptpath(PG_FUNCTION_ARGS)
/* this essentially does a cartesian product of the lsegs in the
two paths, and finds the min distance between any two lsegs */
PG_FUNCTION_INFO_V1(regress_path_dist);
Datum
regress_path_dist(PG_FUNCTION_ARGS)
{
@ -129,6 +134,8 @@ POLYGON *poly;
}
/* return the point where two paths intersect, or NULL if no intersection. */
PG_FUNCTION_INFO_V1(interpt_pp);
Datum
interpt_pp(PG_FUNCTION_ARGS)
{
@ -182,6 +189,8 @@ Point *pt2;
lseg->m = point_sl(pt1, pt2);
}
PG_FUNCTION_INFO_V1(overpaid);
Datum
overpaid(PG_FUNCTION_ARGS)
{
@ -254,6 +263,8 @@ WIDGET *widget;
return result;
}
PG_FUNCTION_INFO_V1(pt_in_widget);
Datum
pt_in_widget(PG_FUNCTION_ARGS)
{
@ -265,6 +276,8 @@ pt_in_widget(PG_FUNCTION_ARGS)
#define ABS(X) ((X) >= 0 ? (X) : -(X))
PG_FUNCTION_INFO_V1(boxarea);
Datum
boxarea(PG_FUNCTION_ARGS)
{
@ -278,8 +291,7 @@ boxarea(PG_FUNCTION_ARGS)
}
char *
reverse_name(string)
char *string;
reverse_name(char *string)
{
int i;
int len;
@ -301,6 +313,20 @@ char *string;
return new_string;
}
/* This rather silly function is just to test that oldstyle functions
* work correctly on toast-able inputs.
*/
int
oldstyle_length(int n, text *t)
{
int len = 0;
if (t)
len = VARSIZE(t) - VARHDRSZ;
return n + len;
}
#include "executor/spi.h" /* this is what you need to work with SPI */
#include "commands/trigger.h" /* -"- and triggers */
@ -312,6 +338,8 @@ static bool fd17b_recursion = true;
static bool fd17a_recursion = true;
extern Datum funny_dup17(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(funny_dup17);
Datum
funny_dup17(PG_FUNCTION_ARGS)
{
@ -428,6 +456,8 @@ extern Datum set_ttdummy(PG_FUNCTION_ARGS);
static void *splan = NULL;
static bool ttoff = false;
PG_FUNCTION_INFO_V1(ttdummy);
Datum
ttdummy(PG_FUNCTION_ARGS)
{
@ -625,6 +655,8 @@ ttdummy(PG_FUNCTION_ARGS)
return PointerGetDatum(rettuple);
}
PG_FUNCTION_INFO_V1(set_ttdummy);
Datum
set_ttdummy(PG_FUNCTION_ARGS)
{

View File

@ -38,6 +38,7 @@ DROP FUNCTION interpt_pp(path,path);
DROP FUNCTION reverse_name(name);
DROP FUNCTION oldstyle_length(int4, text);
--
-- OPERATOR REMOVAL