3
3
* procedural language
4
4
*
5
5
* IDENTIFICATION
6
- * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.56 2003/04/24 21:16:44 tgl Exp $
6
+ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/pl_comp.c,v 1.57 2003/04/27 22: 21:22 tgl Exp $
7
7
*
8
8
* This software is copyrighted by Jan Wieck - Hamburg.
9
9
*
@@ -81,7 +81,7 @@ PLpgSQL_function *plpgsql_curr_compile;
81
81
82
82
83
83
static void plpgsql_compile_error_callback (void * arg );
84
- static PLpgSQL_row * build_rowtype ( Oid classOid );
84
+ static PLpgSQL_type * build_datatype ( HeapTuple typeTup , int32 typmod );
85
85
86
86
87
87
/*
@@ -275,19 +275,11 @@ plpgsql_compile(Oid fn_oid, int functype)
275
275
*/
276
276
var = malloc (sizeof (PLpgSQL_var ));
277
277
memset (var , 0 , sizeof (PLpgSQL_var ));
278
- var -> datatype = malloc (sizeof (PLpgSQL_type ));
279
- memset (var -> datatype , 0 , sizeof (PLpgSQL_type ));
280
278
281
279
var -> dtype = PLPGSQL_DTYPE_VAR ;
282
280
var -> refname = strdup (buf );
283
281
var -> lineno = 0 ;
284
- var -> datatype -> typname = strdup (NameStr (typeStruct -> typname ));
285
- var -> datatype -> typoid = procStruct -> proargtypes [i ];
286
- perm_fmgr_info (typeStruct -> typinput , & (var -> datatype -> typinput ));
287
- var -> datatype -> typelem = typeStruct -> typelem ;
288
- var -> datatype -> typbyval = typeStruct -> typbyval ;
289
- var -> datatype -> typlen = typeStruct -> typlen ;
290
- var -> datatype -> atttypmod = -1 ;
282
+ var -> datatype = build_datatype (typeTup , -1 );
291
283
var -> isconst = true;
292
284
var -> notnull = false;
293
285
var -> default_val = NULL ;
@@ -908,7 +900,6 @@ plpgsql_parse_wordtype(char *word)
908
900
if (HeapTupleIsValid (typeTup ))
909
901
{
910
902
Form_pg_type typeStruct = (Form_pg_type ) GETSTRUCT (typeTup );
911
- PLpgSQL_type * typ ;
912
903
913
904
if (!typeStruct -> typisdefined ||
914
905
typeStruct -> typrelid != InvalidOid )
@@ -918,17 +909,7 @@ plpgsql_parse_wordtype(char *word)
918
909
return T_ERROR ;
919
910
}
920
911
921
- typ = (PLpgSQL_type * ) malloc (sizeof (PLpgSQL_type ));
922
-
923
- typ -> typname = strdup (NameStr (typeStruct -> typname ));
924
- typ -> typoid = typeOid ;
925
- perm_fmgr_info (typeStruct -> typinput , & (typ -> typinput ));
926
- typ -> typelem = typeStruct -> typelem ;
927
- typ -> typbyval = typeStruct -> typbyval ;
928
- typ -> typlen = typeStruct -> typlen ;
929
- typ -> atttypmod = -1 ;
930
-
931
- plpgsql_yylval .dtype = typ ;
912
+ plpgsql_yylval .dtype = build_datatype (typeTup , -1 );
932
913
933
914
ReleaseSysCache (typeTup );
934
915
pfree (cp [0 ]);
@@ -960,8 +941,6 @@ plpgsql_parse_dblwordtype(char *word)
960
941
HeapTuple attrtup ;
961
942
Form_pg_attribute attrStruct ;
962
943
HeapTuple typetup ;
963
- Form_pg_type typeStruct ;
964
- PLpgSQL_type * typ ;
965
944
char * cp [3 ];
966
945
int i ;
967
946
@@ -1067,22 +1046,11 @@ plpgsql_parse_dblwordtype(char *word)
1067
1046
if (!HeapTupleIsValid (typetup ))
1068
1047
elog (ERROR , "cache lookup for type %u of %s.%s failed" ,
1069
1048
attrStruct -> atttypid , cp [0 ], cp [1 ]);
1070
- typeStruct = (Form_pg_type ) GETSTRUCT (typetup );
1071
1049
1072
1050
/*
1073
1051
* Found that - build a compiler type struct and return it
1074
1052
*/
1075
- typ = (PLpgSQL_type * ) malloc (sizeof (PLpgSQL_type ));
1076
-
1077
- typ -> typname = strdup (NameStr (typeStruct -> typname ));
1078
- typ -> typoid = attrStruct -> atttypid ;
1079
- perm_fmgr_info (typeStruct -> typinput , & (typ -> typinput ));
1080
- typ -> typelem = typeStruct -> typelem ;
1081
- typ -> typbyval = typeStruct -> typbyval ;
1082
- typ -> typlen = typeStruct -> typlen ;
1083
- typ -> atttypmod = attrStruct -> atttypmod ;
1084
-
1085
- plpgsql_yylval .dtype = typ ;
1053
+ plpgsql_yylval .dtype = build_datatype (typetup , attrStruct -> atttypmod );
1086
1054
1087
1055
ReleaseSysCache (classtup );
1088
1056
ReleaseSysCache (attrtup );
@@ -1107,8 +1075,6 @@ plpgsql_parse_tripwordtype(char *word)
1107
1075
HeapTuple attrtup ;
1108
1076
Form_pg_attribute attrStruct ;
1109
1077
HeapTuple typetup ;
1110
- Form_pg_type typeStruct ;
1111
- PLpgSQL_type * typ ;
1112
1078
char * cp [2 ];
1113
1079
char * colname [1 ];
1114
1080
int qualified_att_len ;
@@ -1192,22 +1158,11 @@ plpgsql_parse_tripwordtype(char *word)
1192
1158
if (!HeapTupleIsValid (typetup ))
1193
1159
elog (ERROR , "cache lookup for type %u of %s.%s failed" ,
1194
1160
attrStruct -> atttypid , cp [0 ], cp [1 ]);
1195
- typeStruct = (Form_pg_type ) GETSTRUCT (typetup );
1196
1161
1197
1162
/*
1198
1163
* Found that - build a compiler type struct and return it
1199
1164
*/
1200
- typ = (PLpgSQL_type * ) malloc (sizeof (PLpgSQL_type ));
1201
-
1202
- typ -> typname = strdup (NameStr (typeStruct -> typname ));
1203
- typ -> typoid = attrStruct -> atttypid ;
1204
- perm_fmgr_info (typeStruct -> typinput , & (typ -> typinput ));
1205
- typ -> typelem = typeStruct -> typelem ;
1206
- typ -> typbyval = typeStruct -> typbyval ;
1207
- typ -> typlen = typeStruct -> typlen ;
1208
- typ -> atttypmod = attrStruct -> atttypmod ;
1209
-
1210
- plpgsql_yylval .dtype = typ ;
1165
+ plpgsql_yylval .dtype = build_datatype (typetup , attrStruct -> atttypmod );
1211
1166
1212
1167
ReleaseSysCache (classtup );
1213
1168
ReleaseSysCache (attrtup );
@@ -1296,7 +1251,7 @@ plpgsql_parse_dblwordrowtype(char *word)
1296
1251
/*
1297
1252
* Build a rowtype data structure given the pg_class OID.
1298
1253
*/
1299
- static PLpgSQL_row *
1254
+ PLpgSQL_row *
1300
1255
build_rowtype (Oid classOid )
1301
1256
{
1302
1257
PLpgSQL_row * row ;
@@ -1341,7 +1296,6 @@ build_rowtype(Oid classOid)
1341
1296
HeapTuple attrtup ;
1342
1297
Form_pg_attribute attrStruct ;
1343
1298
HeapTuple typetup ;
1344
- Form_pg_type typeStruct ;
1345
1299
const char * attname ;
1346
1300
PLpgSQL_var * var ;
1347
1301
@@ -1365,7 +1319,6 @@ build_rowtype(Oid classOid)
1365
1319
if (!HeapTupleIsValid (typetup ))
1366
1320
elog (ERROR , "cache lookup for type %u of %s.%s failed" ,
1367
1321
attrStruct -> atttypid , relname , attname );
1368
- typeStruct = (Form_pg_type ) GETSTRUCT (typetup );
1369
1322
1370
1323
/*
1371
1324
* Create the internal variable
@@ -1384,14 +1337,7 @@ build_rowtype(Oid classOid)
1384
1337
strcpy (var -> refname , relname );
1385
1338
strcat (var -> refname , "." );
1386
1339
strcat (var -> refname , attname );
1387
- var -> datatype = malloc (sizeof (PLpgSQL_type ));
1388
- var -> datatype -> typname = strdup (NameStr (typeStruct -> typname ));
1389
- var -> datatype -> typoid = attrStruct -> atttypid ;
1390
- perm_fmgr_info (typeStruct -> typinput , & (var -> datatype -> typinput ));
1391
- var -> datatype -> typelem = typeStruct -> typelem ;
1392
- var -> datatype -> typbyval = typeStruct -> typbyval ;
1393
- var -> datatype -> typlen = typeStruct -> typlen ;
1394
- var -> datatype -> atttypmod = attrStruct -> atttypmod ;
1340
+ var -> datatype = build_datatype (typetup , attrStruct -> atttypmod );
1395
1341
var -> isconst = false;
1396
1342
var -> notnull = false;
1397
1343
var -> default_val = NULL ;
@@ -1428,7 +1374,6 @@ plpgsql_parse_datatype(char *string)
1428
1374
Oid type_id ;
1429
1375
int32 typmod ;
1430
1376
HeapTuple typeTup ;
1431
- Form_pg_type typeStruct ;
1432
1377
PLpgSQL_type * typ ;
1433
1378
1434
1379
/* Let the main parser try to parse it under standard SQL rules */
@@ -1440,20 +1385,34 @@ plpgsql_parse_datatype(char *string)
1440
1385
0 , 0 , 0 );
1441
1386
if (!HeapTupleIsValid (typeTup ))
1442
1387
elog (ERROR , "cache lookup failed for type %u" , type_id );
1443
- typeStruct = (Form_pg_type ) GETSTRUCT (typeTup );
1388
+
1389
+ typ = build_datatype (typeTup , typmod );
1390
+
1391
+ ReleaseSysCache (typeTup );
1392
+
1393
+ return typ ;
1394
+ }
1395
+
1396
+ /*
1397
+ * Utility subroutine to make a PLpgSQL_type struct given a pg_type entry
1398
+ */
1399
+ static PLpgSQL_type *
1400
+ build_datatype (HeapTuple typeTup , int32 typmod )
1401
+ {
1402
+ Form_pg_type typeStruct = (Form_pg_type ) GETSTRUCT (typeTup );
1403
+ PLpgSQL_type * typ ;
1444
1404
1445
1405
typ = (PLpgSQL_type * ) malloc (sizeof (PLpgSQL_type ));
1446
1406
1447
1407
typ -> typname = strdup (NameStr (typeStruct -> typname ));
1448
- typ -> typoid = type_id ;
1449
- perm_fmgr_info (typeStruct -> typinput , & (typ -> typinput ));
1450
- typ -> typelem = typeStruct -> typelem ;
1451
- typ -> typbyval = typeStruct -> typbyval ;
1408
+ typ -> typoid = HeapTupleGetOid (typeTup );
1452
1409
typ -> typlen = typeStruct -> typlen ;
1410
+ typ -> typbyval = typeStruct -> typbyval ;
1411
+ typ -> typrelid = typeStruct -> typrelid ;
1412
+ typ -> typelem = typeStruct -> typelem ;
1413
+ perm_fmgr_info (typeStruct -> typinput , & (typ -> typinput ));
1453
1414
typ -> atttypmod = typmod ;
1454
1415
1455
- ReleaseSysCache (typeTup );
1456
-
1457
1416
return typ ;
1458
1417
}
1459
1418
0 commit comments