Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 58f6b95

Browse files
committed
Fix a lot of confusion between typlen and typmod. Didn't hurt too much
back when only varlena types paid any attention to typmod ...
1 parent 861a679 commit 58f6b95

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

src/pl/tcl/pltcl.c

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* ENHANCEMENTS, OR MODIFICATIONS.
3232
*
3333
* 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 $
3535
*
3636
**********************************************************************/
3737

@@ -107,7 +107,6 @@ typedef struct pltcl_proc_desc
107107
int nargs;
108108
FmgrInfo arg_out_func[FUNC_MAX_ARGS];
109109
Oid arg_out_elem[FUNC_MAX_ARGS];
110-
int arg_out_len[FUNC_MAX_ARGS];
111110
int arg_is_rel[FUNC_MAX_ARGS];
112111
} pltcl_proc_desc;
113112

@@ -123,8 +122,8 @@ typedef struct pltcl_query_desc
123122
Oid *argtypes;
124123
FmgrInfo *arginfuncs;
125124
Oid *argtypelems;
125+
bool *argbyvals;
126126
Datum *argvalues;
127-
int *arglen;
128127
} pltcl_query_desc;
129128

130129

@@ -353,7 +352,7 @@ pltcl_init_load_unknown(Tcl_Interp *interp)
353352
/************************************************************
354353
* There is a module named unknown. Resemble the
355354
* source from the modsrc attributes and evaluate
356-
* it in the safe interpreter
355+
* it in the Tcl interpreter
357356
************************************************************/
358357
fno = SPI_fnumber(SPI_tuptable->tupdesc, "modsrc");
359358

@@ -468,7 +467,7 @@ pltcl_func_handler(PG_FUNCTION_ARGS)
468467

469468
/************************************************************
470469
* Create the tcl command to call the internal
471-
* proc in the safe interpreter
470+
* proc in the Tcl interpreter
472471
************************************************************/
473472
Tcl_DStringInit(&tcl_cmd);
474473
Tcl_DStringInit(&list_tmp);
@@ -525,7 +524,7 @@ pltcl_func_handler(PG_FUNCTION_ARGS)
525524
tmp = DatumGetCString(FunctionCall3(&prodesc->arg_out_func[i],
526525
fcinfo->arg[i],
527526
ObjectIdGetDatum(prodesc->arg_out_elem[i]),
528-
Int32GetDatum(prodesc->arg_out_len[i])));
527+
Int32GetDatum(-1)));
529528
UTF_BEGIN;
530529
Tcl_DStringAppendElement(&tcl_cmd, UTF_E2U(tmp));
531530
UTF_END;
@@ -567,7 +566,7 @@ pltcl_func_handler(PG_FUNCTION_ARGS)
567566
}
568567

569568
/************************************************************
570-
* Convert the result value from the safe interpreter
569+
* Convert the result value from the Tcl interpreter
571570
* into its PostgreSQL data format and return it.
572571
* Again, the function call could fire an elog and we
573572
* have to count for the current interpreter level we are
@@ -823,7 +822,7 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS)
823822
}
824823

825824
/************************************************************
826-
* Convert the result value from the safe interpreter
825+
* Convert the result value from the Tcl interpreter
827826
* and setup structures for SPI_modifytuple();
828827
************************************************************/
829828
if (Tcl_SplitList(interp, interp->result,
@@ -902,8 +901,8 @@ pltcl_trigger_handler(PG_FUNCTION_ARGS)
902901
ret_values[--i],
903902
tupdesc->attrs[attnum - 1]->atttypid);
904903
}
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;
907906
ReleaseSysCache(typeTup);
908907

909908
/************************************************************
@@ -1001,7 +1000,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
10011000
* the in-/out-functions in the prodesc block and create
10021001
* a new hashtable entry for it.
10031002
*
1004-
* Then we load the procedure into the safe interpreter.
1003+
* Then we load the procedure into the Tcl interpreter.
10051004
************************************************************/
10061005
if (hashent == NULL)
10071006
{
@@ -1122,8 +1121,7 @@ compile_pltcl_function(Oid fn_oid, bool is_trigger)
11221121
prodesc->arg_is_rel[i] = 0;
11231122

11241123
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;
11271125

11281126
if (i > 0)
11291127
strcat(proc_internal_args, " ");
@@ -1442,7 +1440,7 @@ pltcl_returnnull(ClientData cdata, Tcl_Interp *interp,
14421440

14431441
/**********************************************************************
14441442
* pltcl_SPI_exec() - The builtin SPI_exec command
1445-
* for the safe interpreter
1443+
* for the Tcl interpreter
14461444
**********************************************************************/
14471445
static int
14481446
pltcl_SPI_exec(ClientData cdata, Tcl_Interp *interp,
@@ -1724,8 +1722,8 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp,
17241722
qdesc->argtypes = (Oid *) malloc(nargs * sizeof(Oid));
17251723
qdesc->arginfuncs = (FmgrInfo *) malloc(nargs * sizeof(FmgrInfo));
17261724
qdesc->argtypelems = (Oid *) malloc(nargs * sizeof(Oid));
1725+
qdesc->argbyvals = (bool *) malloc(nargs * sizeof(bool));
17271726
qdesc->argvalues = (Datum *) malloc(nargs * sizeof(Datum));
1728-
qdesc->arglen = (int *) malloc(nargs * sizeof(int));
17291727

17301728
/************************************************************
17311729
* Prepare to start a controlled return through all
@@ -1739,8 +1737,8 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp,
17391737
free(qdesc->argtypes);
17401738
free(qdesc->arginfuncs);
17411739
free(qdesc->argtypelems);
1740+
free(qdesc->argbyvals);
17421741
free(qdesc->argvalues);
1743-
free(qdesc->arglen);
17441742
free(qdesc);
17451743
ckfree((char *) args);
17461744
return TCL_ERROR;
@@ -1761,8 +1759,8 @@ pltcl_SPI_prepare(ClientData cdata, Tcl_Interp *interp,
17611759
perm_fmgr_info(((Form_pg_type) GETSTRUCT(typeTup))->typinput,
17621760
&(qdesc->arginfuncs[i]));
17631761
qdesc->argtypelems[i] = ((Form_pg_type) GETSTRUCT(typeTup))->typelem;
1762+
qdesc->argbyvals[i] = ((Form_pg_type) GETSTRUCT(typeTup))->typbyval;
17641763
qdesc->argvalues[i] = (Datum) NULL;
1765-
qdesc->arglen[i] = (int) (((Form_pg_type) GETSTRUCT(typeTup))->typlen);
17661764
ReleaseSysCache(typeTup);
17671765
}
17681766

@@ -2035,10 +2033,10 @@ pltcl_SPI_execp(ClientData cdata, Tcl_Interp *interp,
20352033
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
20362034
for (j = 0; j < callnargs; j++)
20372035
{
2038-
if (qdesc->arglen[j] < 0 &&
2036+
if (!qdesc->argbyvals[j] &&
20392037
qdesc->argvalues[j] != (Datum) NULL)
20402038
{
2041-
pfree((char *) (qdesc->argvalues[j]));
2039+
pfree(DatumGetPointer(qdesc->argvalues[j]));
20422040
qdesc->argvalues[j] = (Datum) NULL;
20432041
}
20442042
}
@@ -2060,7 +2058,7 @@ pltcl_SPI_execp(ClientData cdata, Tcl_Interp *interp,
20602058
FunctionCall3(&qdesc->arginfuncs[j],
20612059
CStringGetDatum(UTF_U2E(callargs[j])),
20622060
ObjectIdGetDatum(qdesc->argtypelems[j]),
2063-
Int32GetDatum(qdesc->arglen[j]));
2061+
Int32GetDatum(-1));
20642062
UTF_END;
20652063
}
20662064

@@ -2090,9 +2088,9 @@ pltcl_SPI_execp(ClientData cdata, Tcl_Interp *interp,
20902088
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
20912089
for (j = 0; j < callnargs; j++)
20922090
{
2093-
if (qdesc->arglen[j] < 0 && qdesc->argvalues[j] != (Datum) NULL)
2091+
if (!qdesc->argbyvals[j] && qdesc->argvalues[j] != (Datum) NULL)
20942092
{
2095-
pfree((char *) (qdesc->argvalues[j]));
2093+
pfree(DatumGetPointer(qdesc->argvalues[j]));
20962094
qdesc->argvalues[j] = (Datum) NULL;
20972095
}
20982096
}
@@ -2112,9 +2110,9 @@ pltcl_SPI_execp(ClientData cdata, Tcl_Interp *interp,
21122110
************************************************************/
21132111
for (j = 0; j < callnargs; j++)
21142112
{
2115-
if (qdesc->arglen[j] < 0 && qdesc->argvalues[j] != (Datum) NULL)
2113+
if (!qdesc->argbyvals[j] && qdesc->argvalues[j] != (Datum) NULL)
21162114
{
2117-
pfree((char *) (qdesc->argvalues[j]));
2115+
pfree(DatumGetPointer(qdesc->argvalues[j]));
21182116
qdesc->argvalues[j] = (Datum) NULL;
21192117
}
21202118
}
@@ -2338,8 +2336,8 @@ pltcl_set_tuple_values(Tcl_Interp *interp, char *arrayname,
23382336
attname, tupdesc->attrs[i]->atttypid);
23392337
}
23402338

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;
23432341
ReleaseSysCache(typeTup);
23442342

23452343
/************************************************************
@@ -2355,7 +2353,7 @@ pltcl_set_tuple_values(Tcl_Interp *interp, char *arrayname,
23552353
outputstr = DatumGetCString(OidFunctionCall3(typoutput,
23562354
attr,
23572355
ObjectIdGetDatum(typelem),
2358-
Int32GetDatum(tupdesc->attrs[i]->attlen)));
2356+
Int32GetDatum(tupdesc->attrs[i]->atttypmod)));
23592357
UTF_BEGIN;
23602358
Tcl_SetVar2(interp, *arrptr, *nameptr, UTF_E2U(outputstr), 0);
23612359
UTF_END;
@@ -2410,8 +2408,8 @@ pltcl_build_tuple_argument(HeapTuple tuple, TupleDesc tupdesc,
24102408
attname, tupdesc->attrs[i]->atttypid);
24112409
}
24122410

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;
24152413
ReleaseSysCache(typeTup);
24162414

24172415
/************************************************************
@@ -2427,7 +2425,7 @@ pltcl_build_tuple_argument(HeapTuple tuple, TupleDesc tupdesc,
24272425
outputstr = DatumGetCString(OidFunctionCall3(typoutput,
24282426
attr,
24292427
ObjectIdGetDatum(typelem),
2430-
Int32GetDatum(tupdesc->attrs[i]->attlen)));
2428+
Int32GetDatum(tupdesc->attrs[i]->atttypmod)));
24312429
Tcl_DStringAppendElement(retval, attname);
24322430
UTF_BEGIN;
24332431
Tcl_DStringAppendElement(retval, UTF_E2U(outputstr));

0 commit comments

Comments
 (0)