1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-15 03:41:20 +03:00

Code review for standalone composite types, query-specified composite

types, SRFs.  Not happy with memory management yet, but I'll commit these
other changes.
This commit is contained in:
Tom Lane
2002-08-29 00:17:06 +00:00
parent 7483749d82
commit 64505ed58b
41 changed files with 836 additions and 744 deletions

View File

@@ -5,22 +5,22 @@
* Copyright (c) 2002, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/lockfuncs.c,v 1.2 2002/08/27 04:00:28 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/lockfuncs.c,v 1.3 2002/08/29 00:17:05 tgl Exp $
*/
#include "postgres.h"
#include "fmgr.h"
#include "funcapi.h"
#include "catalog/pg_type.h"
#include "storage/lmgr.h"
#include "storage/lock.h"
#include "storage/lwlock.h"
#include "storage/proc.h"
#include "utils/builtins.h"
Datum pg_lock_status(PG_FUNCTION_ARGS);
static int next_lock(int locks[]);
Datum
pg_lock_status(PG_FUNCTION_ARGS)
{

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.34 2002/08/28 20:46:24 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/tid.c,v 1.35 2002/08/29 00:17:05 tgl Exp $
*
* NOTES
* input routine largely stolen from boxin().
@@ -226,9 +226,6 @@ currtid_byreloid(PG_FUNCTION_ARGS)
if (rel->rd_rel->relkind == RELKIND_VIEW)
return currtid_for_view(rel, tid);
if (rel->rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
elog(ERROR, "currtid can't handle type relations");
ItemPointerCopy(tid, result);
heap_get_latest_tid(rel, SnapshotNow, result);
@@ -252,9 +249,6 @@ currtid_byrelname(PG_FUNCTION_ARGS)
if (rel->rd_rel->relkind == RELKIND_VIEW)
return currtid_for_view(rel, tid);
if (rel->rd_rel->relkind == RELKIND_COMPOSITE_TYPE)
elog(ERROR, "currtid can't handle type relations");
result = (ItemPointer) palloc(sizeof(ItemPointerData));
ItemPointerCopy(tid, result);

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.80 2002/08/26 17:53:59 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.81 2002/08/29 00:17:05 tgl Exp $
*
* NOTES
* Eventually, the index information should go through here, too.
@@ -1190,6 +1190,33 @@ get_typtype(Oid typid)
return '\0';
}
/*
* getTypeInputInfo
*
* Get info needed for converting values of a type to internal form
*/
void
getTypeInputInfo(Oid type, Oid *typInput, Oid *typElem)
{
HeapTuple typeTuple;
Form_pg_type pt;
typeTuple = SearchSysCache(TYPEOID,
ObjectIdGetDatum(type),
0, 0, 0);
if (!HeapTupleIsValid(typeTuple))
elog(ERROR, "getTypeInputInfo: Cache lookup of type %u failed", type);
pt = (Form_pg_type) GETSTRUCT(typeTuple);
if (!pt->typisdefined)
elog(ERROR, "Type \"%s\" is only a shell", NameStr(pt->typname));
*typInput = pt->typinput;
*typElem = pt->typelem;
ReleaseSysCache(typeTuple);
}
/*
* getTypeOutputInfo
*

View File

@@ -6,13 +6,18 @@
*
* Copyright (c) 2002, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/funcapi.c,v 1.3 2002/08/29 00:17:05 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "funcapi.h"
#include "catalog/pg_type.h"
#include "utils/syscache.h"
/*
* init_MultiFuncCall
* Create an empty FuncCallContext data structure
@@ -99,8 +104,6 @@ per_MultiFuncCall(PG_FUNCTION_ARGS)
void
end_MultiFuncCall(PG_FUNCTION_ARGS, FuncCallContext *funcctx)
{
MemoryContext oldcontext;
/* unbind from fcinfo */
fcinfo->flinfo->fn_extra = NULL;
@@ -108,32 +111,8 @@ end_MultiFuncCall(PG_FUNCTION_ARGS, FuncCallContext *funcctx)
* Caller is responsible to free up memory for individual
* struct elements other than att_in_funcinfo and elements.
*/
oldcontext = MemoryContextSwitchTo(funcctx->fmctx);
if (funcctx->attinmeta != NULL)
pfree(funcctx->attinmeta);
pfree(funcctx);
MemoryContextSwitchTo(oldcontext);
}
void
get_type_metadata(Oid typeid, Oid *attinfuncid, Oid *attelem)
{
HeapTuple typeTuple;
Form_pg_type typtup;
typeTuple = SearchSysCache(TYPEOID,
ObjectIdGetDatum(typeid),
0, 0, 0);
if (!HeapTupleIsValid(typeTuple))
elog(ERROR, "get_type_metadata: Cache lookup of type %u failed", typeid);
typtup = (Form_pg_type) GETSTRUCT(typeTuple);
*attinfuncid = typtup->typinput;
*attelem = typtup->typelem;
ReleaseSysCache(typeTuple);
}

View File

@@ -5,7 +5,7 @@
* command, configuration file, and command line options.
* See src/backend/utils/misc/README for more information.
*
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.84 2002/08/26 17:53:59 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.85 2002/08/29 00:17:05 tgl Exp $
*
* Copyright 2000 by PostgreSQL Global Development Group
* Written by Peter Eisentraut <peter_e@gmx.net>.
@@ -2284,7 +2284,7 @@ ShowGUCConfigOption(const char *name)
tstate = begin_tup_output_tupdesc(dest, tupdesc);
/* Send it */
PROJECT_LINE_OF_TEXT(tstate, value);
do_text_output_oneline(tstate, value);
end_tup_output(tstate);
}
@@ -2462,7 +2462,7 @@ show_all_settings(PG_FUNCTION_ARGS)
if (call_cntr < max_calls) /* do when there is more left to send */
{
char **values;
char *values[2];
char *varname;
char *varval;
bool noshow;
@@ -2474,7 +2474,9 @@ show_all_settings(PG_FUNCTION_ARGS)
*/
do
{
varval = GetConfigOptionByNum(call_cntr, (const char **) &varname, &noshow);
varval = GetConfigOptionByNum(call_cntr,
(const char **) &varname,
&noshow);
if (noshow)
{
/* varval is a palloc'd copy, so free it */
@@ -2495,9 +2497,8 @@ show_all_settings(PG_FUNCTION_ARGS)
* This should be an array of C strings which will
* be processed later by the appropriate "in" functions.
*/
values = (char **) palloc(2 * sizeof(char *));
values[0] = pstrdup(varname);
values[1] = varval; /* varval is already a palloc'd copy */
values[0] = varname;
values[1] = varval;
/* build a tuple */
tuple = BuildTupleFromCStrings(attinmeta, values);
@@ -2506,10 +2507,8 @@ show_all_settings(PG_FUNCTION_ARGS)
result = TupleGetDatum(slot, tuple);
/* Clean up */
pfree(values[0]);
if (varval != NULL)
pfree(values[1]);
pfree(values);
pfree(varval);
SRF_RETURN_NEXT(funcctx, result);
}