31
31
* ENHANCEMENTS, OR MODIFICATIONS.
32
32
*
33
33
* IDENTIFICATION
34
- * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.45 2001/10/19 02 :43:46 tgl Exp $
34
+ * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.46 2001/10/19 19 :43:19 tgl Exp $
35
35
*
36
36
**********************************************************************/
37
37
@@ -107,7 +107,6 @@ typedef struct pltcl_proc_desc
107
107
int nargs ;
108
108
FmgrInfo arg_out_func [FUNC_MAX_ARGS ];
109
109
Oid arg_out_elem [FUNC_MAX_ARGS ];
110
- int arg_out_len [FUNC_MAX_ARGS ];
111
110
int arg_is_rel [FUNC_MAX_ARGS ];
112
111
} pltcl_proc_desc ;
113
112
@@ -123,8 +122,8 @@ typedef struct pltcl_query_desc
123
122
Oid * argtypes ;
124
123
FmgrInfo * arginfuncs ;
125
124
Oid * argtypelems ;
125
+ bool * argbyvals ;
126
126
Datum * argvalues ;
127
- int * arglen ;
128
127
} pltcl_query_desc ;
129
128
130
129
@@ -353,7 +352,7 @@ pltcl_init_load_unknown(Tcl_Interp *interp)
353
352
/************************************************************
354
353
* There is a module named unknown. Resemble the
355
354
* source from the modsrc attributes and evaluate
356
- * it in the safe interpreter
355
+ * it in the Tcl interpreter
357
356
************************************************************/
358
357
fno = SPI_fnumber (SPI_tuptable -> tupdesc , "modsrc" );
359
358
@@ -468,7 +467,7 @@ pltcl_func_handler(PG_FUNCTION_ARGS)
468
467
469
468
/************************************************************
470
469
* Create the tcl command to call the internal
471
- * proc in the safe interpreter
470
+ * proc in the Tcl interpreter
472
471
************************************************************/
473
472
Tcl_DStringInit (& tcl_cmd );
474
473
Tcl_DStringInit (& list_tmp );
@@ -525,7 +524,7 @@ pltcl_func_handler(PG_FUNCTION_ARGS)
525
524
tmp = DatumGetCString (FunctionCall3 (& prodesc -> arg_out_func [i ],
526
525
fcinfo -> arg [i ],
527
526
ObjectIdGetDatum (prodesc -> arg_out_elem [i ]),
528
- Int32GetDatum (prodesc -> arg_out_len [ i ] )));
527
+ Int32GetDatum (-1 )));
529
528
UTF_BEGIN ;
530
529
Tcl_DStringAppendElement (& tcl_cmd , UTF_E2U (tmp ));
531
530
UTF_END ;
@@ -567,7 +566,7 @@ pltcl_func_handler(PG_FUNCTION_ARGS)
567
566
}
568
567
569
568
/************************************************************
570
- * Convert the result value from the safe interpreter
569
+ * Convert the result value from the Tcl interpreter
571
570
* into its PostgreSQL data format and return it.
572
571
* Again, the function call could fire an elog and we
573
572
* have to count for the current interpreter level we are
@@ -823,7 +822,7 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS)
823
822
}
824
823
825
824
/************************************************************
826
- * Convert the result value from the safe interpreter
825
+ * Convert the result value from the Tcl interpreter
827
826
* and setup structures for SPI_modifytuple();
828
827
************************************************************/
829
828
if (Tcl_SplitList (interp , interp -> result ,
@@ -902,8 +901,8 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS)
902
901
ret_values [-- i ],
903
902
tupdesc -> attrs [attnum - 1 ]-> atttypid );
904
903
}
905
- typinput = (Oid ) ((( Form_pg_type ) GETSTRUCT (typeTup ))-> typinput ) ;
906
- typelem = (Oid ) ((( Form_pg_type ) GETSTRUCT (typeTup ))-> typelem ) ;
904
+ typinput = (( Form_pg_type ) GETSTRUCT (typeTup ))-> typinput ;
905
+ typelem = (( Form_pg_type ) GETSTRUCT (typeTup ))-> typelem ;
907
906
ReleaseSysCache (typeTup );
908
907
909
908
/************************************************************
@@ -1001,7 +1000,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
1001
1000
* the in-/out-functions in the prodesc block and create
1002
1001
* a new hashtable entry for it.
1003
1002
*
1004
- * Then we load the procedure into the safe interpreter.
1003
+ * Then we load the procedure into the Tcl interpreter.
1005
1004
************************************************************/
1006
1005
if (hashent == NULL )
1007
1006
{
@@ -1122,8 +1121,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
1122
1121
prodesc -> arg_is_rel [i ] = 0 ;
1123
1122
1124
1123
perm_fmgr_info (typeStruct -> typoutput , & (prodesc -> arg_out_func [i ]));
1125
- prodesc -> arg_out_elem [i ] = (Oid ) (typeStruct -> typelem );
1126
- prodesc -> arg_out_len [i ] = typeStruct -> typlen ;
1124
+ prodesc -> arg_out_elem [i ] = typeStruct -> typelem ;
1127
1125
1128
1126
if (i > 0 )
1129
1127
strcat (proc_internal_args , " " );
@@ -1442,7 +1440,7 @@ pltcl_returnnull(ClientData cdata, Tcl_Interp *interp,
1442
1440
1443
1441
/**********************************************************************
1444
1442
* pltcl_SPI_exec() - The builtin SPI_exec command
1445
- * for the safe interpreter
1443
+ * for the Tcl interpreter
1446
1444
**********************************************************************/
1447
1445
static int
1448
1446
pltcl_SPI_exec (ClientData cdata , Tcl_Interp * interp ,
@@ -1724,8 +1722,8 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp,
1724
1722
qdesc -> argtypes = (Oid * ) malloc (nargs * sizeof (Oid ));
1725
1723
qdesc -> arginfuncs = (FmgrInfo * ) malloc (nargs * sizeof (FmgrInfo ));
1726
1724
qdesc -> argtypelems = (Oid * ) malloc (nargs * sizeof (Oid ));
1725
+ qdesc -> argbyvals = (bool * ) malloc (nargs * sizeof (bool ));
1727
1726
qdesc -> argvalues = (Datum * ) malloc (nargs * sizeof (Datum ));
1728
- qdesc -> arglen = (int * ) malloc (nargs * sizeof (int ));
1729
1727
1730
1728
/************************************************************
1731
1729
* Prepare to start a controlled return through all
@@ -1739,8 +1737,8 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp,
1739
1737
free (qdesc -> argtypes );
1740
1738
free (qdesc -> arginfuncs );
1741
1739
free (qdesc -> argtypelems );
1740
+ free (qdesc -> argbyvals );
1742
1741
free (qdesc -> argvalues );
1743
- free (qdesc -> arglen );
1744
1742
free (qdesc );
1745
1743
ckfree ((char * ) args );
1746
1744
return TCL_ERROR ;
@@ -1761,8 +1759,8 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp,
1761
1759
perm_fmgr_info (((Form_pg_type ) GETSTRUCT (typeTup ))-> typinput ,
1762
1760
& (qdesc -> arginfuncs [i ]));
1763
1761
qdesc -> argtypelems [i ] = ((Form_pg_type ) GETSTRUCT (typeTup ))-> typelem ;
1762
+ qdesc -> argbyvals [i ] = ((Form_pg_type ) GETSTRUCT (typeTup ))-> typbyval ;
1764
1763
qdesc -> argvalues [i ] = (Datum ) NULL ;
1765
- qdesc -> arglen [i ] = (int ) (((Form_pg_type ) GETSTRUCT (typeTup ))-> typlen );
1766
1764
ReleaseSysCache (typeTup );
1767
1765
}
1768
1766
@@ -2035,10 +2033,10 @@ pltcl_SPI_execp(ClientData cdata, Tcl_Interp *interp,
2035
2033
memcpy (& Warn_restart , & save_restart , sizeof (Warn_restart ));
2036
2034
for (j = 0 ; j < callnargs ; j ++ )
2037
2035
{
2038
- if (qdesc -> arglen [j ] < 0 &&
2036
+ if (! qdesc -> argbyvals [j ] &&
2039
2037
qdesc -> argvalues [j ] != (Datum ) NULL )
2040
2038
{
2041
- pfree (( char * ) (qdesc -> argvalues [j ]));
2039
+ pfree (DatumGetPointer (qdesc -> argvalues [j ]));
2042
2040
qdesc -> argvalues [j ] = (Datum ) NULL ;
2043
2041
}
2044
2042
}
@@ -2060,7 +2058,7 @@ pltcl_SPI_execp(ClientData cdata, Tcl_Interp *interp,
2060
2058
FunctionCall3 (& qdesc -> arginfuncs [j ],
2061
2059
CStringGetDatum (UTF_U2E (callargs [j ])),
2062
2060
ObjectIdGetDatum (qdesc -> argtypelems [j ]),
2063
- Int32GetDatum (qdesc -> arglen [ j ] ));
2061
+ Int32GetDatum (-1 ));
2064
2062
UTF_END ;
2065
2063
}
2066
2064
@@ -2090,9 +2088,9 @@ pltcl_SPI_execp(ClientData cdata, Tcl_Interp *interp,
2090
2088
memcpy (& Warn_restart , & save_restart , sizeof (Warn_restart ));
2091
2089
for (j = 0 ; j < callnargs ; j ++ )
2092
2090
{
2093
- if (qdesc -> arglen [j ] < 0 && qdesc -> argvalues [j ] != (Datum ) NULL )
2091
+ if (! qdesc -> argbyvals [j ] && qdesc -> argvalues [j ] != (Datum ) NULL )
2094
2092
{
2095
- pfree (( char * ) (qdesc -> argvalues [j ]));
2093
+ pfree (DatumGetPointer (qdesc -> argvalues [j ]));
2096
2094
qdesc -> argvalues [j ] = (Datum ) NULL ;
2097
2095
}
2098
2096
}
@@ -2112,9 +2110,9 @@ pltcl_SPI_execp(ClientData cdata, Tcl_Interp *interp,
2112
2110
************************************************************/
2113
2111
for (j = 0 ; j < callnargs ; j ++ )
2114
2112
{
2115
- if (qdesc -> arglen [j ] < 0 && qdesc -> argvalues [j ] != (Datum ) NULL )
2113
+ if (! qdesc -> argbyvals [j ] && qdesc -> argvalues [j ] != (Datum ) NULL )
2116
2114
{
2117
- pfree (( char * ) (qdesc -> argvalues [j ]));
2115
+ pfree (DatumGetPointer (qdesc -> argvalues [j ]));
2118
2116
qdesc -> argvalues [j ] = (Datum ) NULL ;
2119
2117
}
2120
2118
}
@@ -2338,8 +2336,8 @@ pltcl_set_tuple_values(Tcl_Interp *interp, char *arrayname,
2338
2336
attname , tupdesc -> attrs [i ]-> atttypid );
2339
2337
}
2340
2338
2341
- typoutput = (Oid ) ((( Form_pg_type ) GETSTRUCT (typeTup ))-> typoutput ) ;
2342
- typelem = (Oid ) ((( Form_pg_type ) GETSTRUCT (typeTup ))-> typelem ) ;
2339
+ typoutput = (( Form_pg_type ) GETSTRUCT (typeTup ))-> typoutput ;
2340
+ typelem = (( Form_pg_type ) GETSTRUCT (typeTup ))-> typelem ;
2343
2341
ReleaseSysCache (typeTup );
2344
2342
2345
2343
/************************************************************
@@ -2355,7 +2353,7 @@ pltcl_set_tuple_values(Tcl_Interp *interp, char *arrayname,
2355
2353
outputstr = DatumGetCString (OidFunctionCall3 (typoutput ,
2356
2354
attr ,
2357
2355
ObjectIdGetDatum (typelem ),
2358
- Int32GetDatum (tupdesc -> attrs [i ]-> attlen )));
2356
+ Int32GetDatum (tupdesc -> attrs [i ]-> atttypmod )));
2359
2357
UTF_BEGIN ;
2360
2358
Tcl_SetVar2 (interp , * arrptr , * nameptr , UTF_E2U (outputstr ), 0 );
2361
2359
UTF_END ;
@@ -2410,8 +2408,8 @@ pltcl_build_tuple_argument(HeapTuple tuple, TupleDesc tupdesc,
2410
2408
attname , tupdesc -> attrs [i ]-> atttypid );
2411
2409
}
2412
2410
2413
- typoutput = (Oid ) ((( Form_pg_type ) GETSTRUCT (typeTup ))-> typoutput ) ;
2414
- typelem = (Oid ) ((( Form_pg_type ) GETSTRUCT (typeTup ))-> typelem ) ;
2411
+ typoutput = (( Form_pg_type ) GETSTRUCT (typeTup ))-> typoutput ;
2412
+ typelem = (( Form_pg_type ) GETSTRUCT (typeTup ))-> typelem ;
2415
2413
ReleaseSysCache (typeTup );
2416
2414
2417
2415
/************************************************************
@@ -2427,7 +2425,7 @@ pltcl_build_tuple_argument(HeapTuple tuple, TupleDesc tupdesc,
2427
2425
outputstr = DatumGetCString (OidFunctionCall3 (typoutput ,
2428
2426
attr ,
2429
2427
ObjectIdGetDatum (typelem ),
2430
- Int32GetDatum (tupdesc -> attrs [i ]-> attlen )));
2428
+ Int32GetDatum (tupdesc -> attrs [i ]-> atttypmod )));
2431
2429
Tcl_DStringAppendElement (retval , attname );
2432
2430
UTF_BEGIN ;
2433
2431
Tcl_DStringAppendElement (retval , UTF_E2U (outputstr ));
0 commit comments