* ENHANCEMENTS, OR MODIFICATIONS.
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.45 2001/10/19 02:43:46 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.46 2001/10/19 19:43:19 tgl Exp $
*
**********************************************************************/
int nargs;
FmgrInfo arg_out_func[FUNC_MAX_ARGS];
Oid arg_out_elem[FUNC_MAX_ARGS];
- int arg_out_len[FUNC_MAX_ARGS];
int arg_is_rel[FUNC_MAX_ARGS];
} pltcl_proc_desc;
Oid *argtypes;
FmgrInfo *arginfuncs;
Oid *argtypelems;
+ bool *argbyvals;
Datum *argvalues;
- int *arglen;
} pltcl_query_desc;
/************************************************************
* There is a module named unknown. Resemble the
* source from the modsrc attributes and evaluate
- * it in the safe interpreter
+ * it in the Tcl interpreter
************************************************************/
fno = SPI_fnumber(SPI_tuptable->tupdesc, "modsrc");
/************************************************************
* Create the tcl command to call the internal
- * proc in the safe interpreter
+ * proc in the Tcl interpreter
************************************************************/
Tcl_DStringInit(&tcl_cmd);
Tcl_DStringInit(&list_tmp);
tmp = DatumGetCString(FunctionCall3(&prodesc->arg_out_func[i],
fcinfo->arg[i],
ObjectIdGetDatum(prodesc->arg_out_elem[i]),
- Int32GetDatum(prodesc->arg_out_len[i])));
+ Int32GetDatum(-1)));
UTF_BEGIN;
Tcl_DStringAppendElement(&tcl_cmd, UTF_E2U(tmp));
UTF_END;
}
/************************************************************
- * Convert the result value from the safe interpreter
+ * Convert the result value from the Tcl interpreter
* into its PostgreSQL data format and return it.
* Again, the function call could fire an elog and we
* have to count for the current interpreter level we are
}
/************************************************************
- * Convert the result value from the safe interpreter
+ * Convert the result value from the Tcl interpreter
* and setup structures for SPI_modifytuple();
************************************************************/
if (Tcl_SplitList(interp, interp->result,
ret_values[--i],
tupdesc->attrs[attnum - 1]->atttypid);
}
- typinput = (Oid) (((Form_pg_type) GETSTRUCT(typeTup))->typinput);
- typelem = (Oid) (((Form_pg_type) GETSTRUCT(typeTup))->typelem);
+ typinput = ((Form_pg_type) GETSTRUCT(typeTup))->typinput;
+ typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem;
ReleaseSysCache(typeTup);
/************************************************************
* the in-/out-functions in the prodesc block and create
* a new hashtable entry for it.
*
- * Then we load the procedure into the safe interpreter.
+ * Then we load the procedure into the Tcl interpreter.
************************************************************/
if (hashent == NULL)
{
prodesc->arg_is_rel[i] = 0;
perm_fmgr_info(typeStruct->typoutput, &(prodesc->arg_out_func[i]));
- prodesc->arg_out_elem[i] = (Oid) (typeStruct->typelem);
- prodesc->arg_out_len[i] = typeStruct->typlen;
+ prodesc->arg_out_elem[i] = typeStruct->typelem;
if (i > 0)
strcat(proc_internal_args, " ");
/**********************************************************************
* pltcl_SPI_exec() - The builtin SPI_exec command
- * for the safe interpreter
+ * for the Tcl interpreter
**********************************************************************/
static int
pltcl_SPI_exec(ClientData cdata, Tcl_Interp *interp,
qdesc->argtypes = (Oid *) malloc(nargs * sizeof(Oid));
qdesc->arginfuncs = (FmgrInfo *) malloc(nargs * sizeof(FmgrInfo));
qdesc->argtypelems = (Oid *) malloc(nargs * sizeof(Oid));
+ qdesc->argbyvals = (bool *) malloc(nargs * sizeof(bool));
qdesc->argvalues = (Datum *) malloc(nargs * sizeof(Datum));
- qdesc->arglen = (int *) malloc(nargs * sizeof(int));
/************************************************************
* Prepare to start a controlled return through all
free(qdesc->argtypes);
free(qdesc->arginfuncs);
free(qdesc->argtypelems);
+ free(qdesc->argbyvals);
free(qdesc->argvalues);
- free(qdesc->arglen);
free(qdesc);
ckfree((char *) args);
return TCL_ERROR;
perm_fmgr_info(((Form_pg_type) GETSTRUCT(typeTup))->typinput,
&(qdesc->arginfuncs[i]));
qdesc->argtypelems[i] = ((Form_pg_type) GETSTRUCT(typeTup))->typelem;
+ qdesc->argbyvals[i] = ((Form_pg_type) GETSTRUCT(typeTup))->typbyval;
qdesc->argvalues[i] = (Datum) NULL;
- qdesc->arglen[i] = (int) (((Form_pg_type) GETSTRUCT(typeTup))->typlen);
ReleaseSysCache(typeTup);
}
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
for (j = 0; j < callnargs; j++)
{
- if (qdesc->arglen[j] < 0 &&
+ if (!qdesc->argbyvals[j] &&
qdesc->argvalues[j] != (Datum) NULL)
{
- pfree((char *) (qdesc->argvalues[j]));
+ pfree(DatumGetPointer(qdesc->argvalues[j]));
qdesc->argvalues[j] = (Datum) NULL;
}
}
FunctionCall3(&qdesc->arginfuncs[j],
CStringGetDatum(UTF_U2E(callargs[j])),
ObjectIdGetDatum(qdesc->argtypelems[j]),
- Int32GetDatum(qdesc->arglen[j]));
+ Int32GetDatum(-1));
UTF_END;
}
memcpy(&Warn_restart, &save_restart, sizeof(Warn_restart));
for (j = 0; j < callnargs; j++)
{
- if (qdesc->arglen[j] < 0 && qdesc->argvalues[j] != (Datum) NULL)
+ if (!qdesc->argbyvals[j] && qdesc->argvalues[j] != (Datum) NULL)
{
- pfree((char *) (qdesc->argvalues[j]));
+ pfree(DatumGetPointer(qdesc->argvalues[j]));
qdesc->argvalues[j] = (Datum) NULL;
}
}
************************************************************/
for (j = 0; j < callnargs; j++)
{
- if (qdesc->arglen[j] < 0 && qdesc->argvalues[j] != (Datum) NULL)
+ if (!qdesc->argbyvals[j] && qdesc->argvalues[j] != (Datum) NULL)
{
- pfree((char *) (qdesc->argvalues[j]));
+ pfree(DatumGetPointer(qdesc->argvalues[j]));
qdesc->argvalues[j] = (Datum) NULL;
}
}
attname, tupdesc->attrs[i]->atttypid);
}
- typoutput = (Oid) (((Form_pg_type) GETSTRUCT(typeTup))->typoutput);
- typelem = (Oid) (((Form_pg_type) GETSTRUCT(typeTup))->typelem);
+ typoutput = ((Form_pg_type) GETSTRUCT(typeTup))->typoutput;
+ typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem;
ReleaseSysCache(typeTup);
/************************************************************
outputstr = DatumGetCString(OidFunctionCall3(typoutput,
attr,
ObjectIdGetDatum(typelem),
- Int32GetDatum(tupdesc->attrs[i]->attlen)));
+ Int32GetDatum(tupdesc->attrs[i]->atttypmod)));
UTF_BEGIN;
Tcl_SetVar2(interp, *arrptr, *nameptr, UTF_E2U(outputstr), 0);
UTF_END;
attname, tupdesc->attrs[i]->atttypid);
}
- typoutput = (Oid) (((Form_pg_type) GETSTRUCT(typeTup))->typoutput);
- typelem = (Oid) (((Form_pg_type) GETSTRUCT(typeTup))->typelem);
+ typoutput = ((Form_pg_type) GETSTRUCT(typeTup))->typoutput;
+ typelem = ((Form_pg_type) GETSTRUCT(typeTup))->typelem;
ReleaseSysCache(typeTup);
/************************************************************
outputstr = DatumGetCString(OidFunctionCall3(typoutput,
attr,
ObjectIdGetDatum(typelem),
- Int32GetDatum(tupdesc->attrs[i]->attlen)));
+ Int32GetDatum(tupdesc->attrs[i]->atttypmod)));
Tcl_DStringAppendElement(retval, attname);
UTF_BEGIN;
Tcl_DStringAppendElement(retval, UTF_E2U(outputstr));