Commit 5ded4bd2 authored by Andres Freund's avatar Andres Freund

Remove support for version-0 calling conventions.

The V0 convention is failure prone because we've so far assumed that a
function is V0 if PG_FUNCTION_INFO_V1 is missing, leading to crashes
if a function was coded against the V1 interface.  V0 doesn't allow
proper NULL, SRF and toast handling.  V0 doesn't offer features that
V1 doesn't.

Thus remove V0 support and obsolete fmgr README contents relating to
it.

Author: Andres Freund, with contributions by Peter Eisentraut & Craig Ringer
Reviewed-By: Peter Eisentraut, Craig Ringer
Discussion: https://postgr.es/m/20161208213441.k3mbno4twhg2qf7g@alap3.anarazel.de
parent 389bb281
......@@ -88,16 +88,8 @@ geo_distance_internal(Point *pt1, Point *pt2)
*
* returns: float8
* distance between the points in miles on earth's surface
*
* If float8 is passed-by-value, the oldstyle version-0 calling convention
* is unportable, so we use version-1. However, if it's passed-by-reference,
* continue to use oldstyle. This is just because we'd like earthdistance
* to serve as a canary for any unintentional breakage of version-0 functions
* with float8 results.
******************************************************/
#ifdef USE_FLOAT8_BYVAL
PG_FUNCTION_INFO_V1(geo_distance);
Datum
......@@ -110,17 +102,3 @@ geo_distance(PG_FUNCTION_ARGS)
result = geo_distance_internal(pt1, pt2);
PG_RETURN_FLOAT8(result);
}
#else /* !USE_FLOAT8_BYVAL */
double *geo_distance(Point *pt1, Point *pt2);
double *
geo_distance(Point *pt1, Point *pt2)
{
double *resultp = palloc(sizeof(double));
*resultp = geo_distance_internal(pt1, pt2);
return resultp;
}
#endif /* USE_FLOAT8_BYVAL */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -336,10 +336,10 @@ extern struct varlena *pg_detoast_datum_packed(struct varlena * datum);
/*-------------------------------------------------------------------------
* Support for detecting call convention of dynamically-loaded functions
*
* Dynamically loaded functions may use either the version-1 ("new style")
* or version-0 ("old style") calling convention. Version 1 is the call
* convention defined in this header file; version 0 is the old "plain C"
* convention. A version-1 function must be accompanied by the macro call
* Dynamically loaded functions currently can only use the version-1 ("new
* style") calling convention. Version-0 ("old style") is not supported
* anymore. Version 1 is the call convention defined in this header file, and
* must be accompanied by the macro call
*
* PG_FUNCTION_INFO_V1(function_name);
*
......
......@@ -87,11 +87,6 @@ CREATE FUNCTION reverse_name(name)
AS '@libdir@/regress@DLSUFFIX@'
LANGUAGE C STRICT;
CREATE FUNCTION oldstyle_length(int4, text)
RETURNS int4
AS '@libdir@/regress@DLSUFFIX@'
LANGUAGE C; -- intentionally not strict
--
-- Function dynamic loading
--
......
......@@ -249,19 +249,6 @@ SELECT *, name(equipment(h.*)) FROM hobbies_r h;
SELECT *, (equipment(CAST((h.*) AS hobbies_r))).name FROM hobbies_r h;
--
-- 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
--
......
......@@ -67,10 +67,6 @@ CREATE FUNCTION reverse_name(name)
RETURNS name
AS '@libdir@/regress@DLSUFFIX@'
LANGUAGE C STRICT;
CREATE FUNCTION oldstyle_length(int4, text)
RETURNS int4
AS '@libdir@/regress@DLSUFFIX@'
LANGUAGE C; -- intentionally not strict
--
-- Function dynamic loading
--
......
......@@ -681,24 +681,6 @@ SELECT *, (equipment(CAST((h.*) AS hobbies_r))).name FROM hobbies_r h;
skywalking | | guts
(7 rows)
--
-- 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 | 50000 | 50000
(4 rows)
drop table oldstyle_test;
--
-- functional joins
--
......
......@@ -45,8 +45,6 @@
extern PATH *poly2path(POLYGON *poly);
extern void regress_lseg_construct(LSEG *lseg, Point *pt1, Point *pt2);
extern char *reverse_name(char *string);
extern int oldstyle_length(int n, text *t);
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
......@@ -240,14 +238,15 @@ typedef struct
double radius;
} WIDGET;
WIDGET *widget_in(char *str);
char *widget_out(WIDGET *widget);
PG_FUNCTION_INFO_V1(widget_in);
PG_FUNCTION_INFO_V1(widget_out);
#define NARGS 3
WIDGET *
widget_in(char *str)
Datum
widget_in(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
char *p,
*coord[NARGS];
int i;
......@@ -270,14 +269,16 @@ widget_in(char *str)
result->center.y = atof(coord[1]);
result->radius = atof(coord[2]);
return result;
PG_RETURN_POINTER(result);
}
char *
widget_out(WIDGET *widget)
Datum
widget_out(PG_FUNCTION_ARGS)
{
return psprintf("(%g,%g,%g)",
widget->center.x, widget->center.y, widget->radius);
WIDGET *widget = (WIDGET *) PG_GETARG_POINTER(0);
char *str = psprintf("(%g,%g,%g)",
widget->center.x, widget->center.y, widget->radius);
PG_RETURN_CSTRING(str);
}
PG_FUNCTION_INFO_V1(pt_in_widget);
......@@ -305,9 +306,12 @@ boxarea(PG_FUNCTION_ARGS)
PG_RETURN_FLOAT8(width * height);
}
char *
reverse_name(char *string)
PG_FUNCTION_INFO_V1(reverse_name);
Datum
reverse_name(PG_FUNCTION_ARGS)
{
char *string = PG_GETARG_CSTRING(0);
int i;
int len;
char *new_string;
......@@ -320,22 +324,7 @@ reverse_name(char *string)
len = i;
for (; i >= 0; --i)
new_string[len - i] = string[i];
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;
PG_RETURN_CSTRING(new_string);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment