Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit465d7e1

Browse files
committed
Make CREATE TYPE print warnings if a datatype's I/O functions are volatile.
This is a followup to commit43ac12c,which added regression tests checking that I/O functions of built-intypes are not marked volatile. Complaining in CREATE TYPE should pushdevelopers of add-on types to fix any misdeclared functions in theirtypes. It's just a warning not an error, to avoid creating upgradeproblems for what might be just cosmetic mis-markings.Aside from adding the warning code, fix a number of types that weresloppily created in the regression tests.
1 parent66c029c commit465d7e1

File tree

7 files changed

+66
-20
lines changed

7 files changed

+66
-20
lines changed

‎src/backend/commands/typecmds.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,52 @@ DefineType(List *names, List *parameters)
547547
NameListToString(analyzeName));
548548
#endif
549549

550+
/*
551+
* Print warnings if any of the type's I/O functions are marked volatile.
552+
* There is a general assumption that I/O functions are stable or
553+
* immutable; this allows us for example to mark record_in/record_out
554+
* stable rather than volatile. Ideally we would throw errors not just
555+
* warnings here; but since this check is new as of 9.5, and since the
556+
* volatility marking might be just an error-of-omission and not a true
557+
* indication of how the function behaves, we'll let it pass as a warning
558+
* for now.
559+
*/
560+
if (inputOid&&func_volatile(inputOid)==PROVOLATILE_VOLATILE)
561+
ereport(WARNING,
562+
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
563+
errmsg("type input function %s should not be volatile",
564+
NameListToString(inputName))));
565+
if (outputOid&&func_volatile(outputOid)==PROVOLATILE_VOLATILE)
566+
ereport(WARNING,
567+
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
568+
errmsg("type output function %s should not be volatile",
569+
NameListToString(outputName))));
570+
if (receiveOid&&func_volatile(receiveOid)==PROVOLATILE_VOLATILE)
571+
ereport(WARNING,
572+
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
573+
errmsg("type receive function %s should not be volatile",
574+
NameListToString(receiveName))));
575+
if (sendOid&&func_volatile(sendOid)==PROVOLATILE_VOLATILE)
576+
ereport(WARNING,
577+
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
578+
errmsg("type send function %s should not be volatile",
579+
NameListToString(sendName))));
580+
if (typmodinOid&&func_volatile(typmodinOid)==PROVOLATILE_VOLATILE)
581+
ereport(WARNING,
582+
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
583+
errmsg("type modifier input function %s should not be volatile",
584+
NameListToString(typmodinName))));
585+
if (typmodoutOid&&func_volatile(typmodoutOid)==PROVOLATILE_VOLATILE)
586+
ereport(WARNING,
587+
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
588+
errmsg("type modifier output function %s should not be volatile",
589+
NameListToString(typmodoutName))));
590+
591+
/*
592+
* OK, we're done checking, time to make the type. We must assign the
593+
* array type OID ahead of calling TypeCreate, since the base type and
594+
* array type each refer to the other.
595+
*/
550596
array_oid=AssignTypeArrayOid();
551597

552598
/*

‎src/test/regress/expected/create_cast.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ CREATE TYPE casttesttype;
66
CREATE FUNCTION casttesttype_in(cstring)
77
RETURNS casttesttype
88
AS 'textin'
9-
LANGUAGE internal STRICT;
9+
LANGUAGE internal STRICT IMMUTABLE;
1010
NOTICE: return type casttesttype is only a shell
1111
CREATE FUNCTION casttesttype_out(casttesttype)
1212
RETURNS cstring
1313
AS 'textout'
14-
LANGUAGE internal STRICT;
14+
LANGUAGE internal STRICT IMMUTABLE;
1515
NOTICE: argument type casttesttype is only a shell
1616
CREATE TYPE casttesttype (
1717
internallength = variable,

‎src/test/regress/expected/create_type.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@ CREATE TYPE text_w_default;
4141
CREATE FUNCTION int42_in(cstring)
4242
RETURNS int42
4343
AS 'int4in'
44-
LANGUAGE internal STRICT;
44+
LANGUAGE internal STRICT IMMUTABLE;
4545
NOTICE: return type int42 is only a shell
4646
CREATE FUNCTION int42_out(int42)
4747
RETURNS cstring
4848
AS 'int4out'
49-
LANGUAGE internal STRICT;
49+
LANGUAGE internal STRICT IMMUTABLE;
5050
NOTICE: argument type int42 is only a shell
5151
CREATE FUNCTION text_w_default_in(cstring)
5252
RETURNS text_w_default
5353
AS 'textin'
54-
LANGUAGE internal STRICT;
54+
LANGUAGE internal STRICT IMMUTABLE;
5555
NOTICE: return type text_w_default is only a shell
5656
CREATE FUNCTION text_w_default_out(text_w_default)
5757
RETURNS cstring
5858
AS 'textout'
59-
LANGUAGE internal STRICT;
59+
LANGUAGE internal STRICT IMMUTABLE;
6060
NOTICE: argument type text_w_default is only a shell
6161
CREATE TYPE int42 (
6262
internallength = 4,

‎src/test/regress/input/create_function_1.source

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
CREATE FUNCTION widget_in(cstring)
66
RETURNS widget
77
AS '@libdir@/regress@DLSUFFIX@'
8-
LANGUAGE C STRICT;
8+
LANGUAGE C STRICT IMMUTABLE;
99

1010
CREATE FUNCTION widget_out(widget)
1111
RETURNS cstring
1212
AS '@libdir@/regress@DLSUFFIX@'
13-
LANGUAGE C STRICT;
13+
LANGUAGE C STRICT IMMUTABLE;
1414

1515
CREATE FUNCTION int44in(cstring)
1616
RETURNS city_budget
1717
AS '@libdir@/regress@DLSUFFIX@'
18-
LANGUAGE C STRICT;
18+
LANGUAGE C STRICT IMMUTABLE;
1919

2020
CREATE FUNCTION int44out(city_budget)
2121
RETURNS cstring
2222
AS '@libdir@/regress@DLSUFFIX@'
23-
LANGUAGE C STRICT;
23+
LANGUAGE C STRICT IMMUTABLE;
2424

2525
CREATE FUNCTION check_primary_key ()
2626
RETURNS trigger

‎src/test/regress/output/create_function_1.source

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
CREATE FUNCTION widget_in(cstring)
55
RETURNS widget
66
AS '@libdir@/regress@DLSUFFIX@'
7-
LANGUAGE C STRICT;
7+
LANGUAGE C STRICT IMMUTABLE;
88
NOTICE: type "widget" is not yet defined
99
DETAIL: Creating a shell type definition.
1010
CREATE FUNCTION widget_out(widget)
1111
RETURNS cstring
1212
AS '@libdir@/regress@DLSUFFIX@'
13-
LANGUAGE C STRICT;
13+
LANGUAGE C STRICT IMMUTABLE;
1414
NOTICE: argument type widget is only a shell
1515
CREATE FUNCTION int44in(cstring)
1616
RETURNS city_budget
1717
AS '@libdir@/regress@DLSUFFIX@'
18-
LANGUAGE C STRICT;
18+
LANGUAGE C STRICT IMMUTABLE;
1919
NOTICE: type "city_budget" is not yet defined
2020
DETAIL: Creating a shell type definition.
2121
CREATE FUNCTION int44out(city_budget)
2222
RETURNS cstring
2323
AS '@libdir@/regress@DLSUFFIX@'
24-
LANGUAGE C STRICT;
24+
LANGUAGE C STRICT IMMUTABLE;
2525
NOTICE: argument type city_budget is only a shell
2626
CREATE FUNCTION check_primary_key ()
2727
RETURNS trigger

‎src/test/regress/sql/create_cast.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ CREATE TYPE casttesttype;
88
CREATEFUNCTIONcasttesttype_in(cstring)
99
RETURNS casttesttype
1010
AS'textin'
11-
LANGUAGE internal STRICT;
11+
LANGUAGE internal STRICT IMMUTABLE;
1212
CREATEFUNCTIONcasttesttype_out(casttesttype)
1313
RETURNS cstring
1414
AS'textout'
15-
LANGUAGE internal STRICT;
15+
LANGUAGE internal STRICT IMMUTABLE;
1616

1717
CREATETYPEcasttesttype (
1818
internallength= variable,

‎src/test/regress/sql/create_type.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ CREATE TYPE text_w_default;
4444
CREATEFUNCTIONint42_in(cstring)
4545
RETURNS int42
4646
AS'int4in'
47-
LANGUAGE internal STRICT;
47+
LANGUAGE internal STRICT IMMUTABLE;
4848
CREATEFUNCTIONint42_out(int42)
4949
RETURNS cstring
5050
AS'int4out'
51-
LANGUAGE internal STRICT;
51+
LANGUAGE internal STRICT IMMUTABLE;
5252
CREATEFUNCTIONtext_w_default_in(cstring)
5353
RETURNS text_w_default
5454
AS'textin'
55-
LANGUAGE internal STRICT;
55+
LANGUAGE internal STRICT IMMUTABLE;
5656
CREATEFUNCTIONtext_w_default_out(text_w_default)
5757
RETURNS cstring
5858
AS'textout'
59-
LANGUAGE internal STRICT;
59+
LANGUAGE internal STRICT IMMUTABLE;
6060

6161
CREATETYPEint42 (
6262
internallength=4,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp