PG_FREE_IF_COPY()

Поиск
Список
Период
Сортировка
Искать

PG_FREE_IF_COPY()

От:
"John Hansen" <john@geeknet.com.au>
Дата:
Given the following snippet:
HeapTupleHeader     tuple;Datum               temp;bool			  isnull;tuple = PG_GETARG_HEAPTUPLEHEADER(0);temp  = GetAttributeByName(tuple, "data", &isnull);


When using this for a btree operator functions, you need to
PG_FREE_IF_COPY(?,?);

Which of the above parameters need I free?

tuple, or temp,.... Or both?

... John

Re: PG_FREE_IF_COPY()

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"John Hansen"  writes:
> Given the following snippet:
> 	HeapTupleHeader     tuple;
> 	Datum               temp;
> 	bool			  isnull;
> 	tuple = PG_GETARG_HEAPTUPLEHEADER(0);
> 	temp  = GetAttributeByName(tuple, "data", &isnull);

> When using this for a btree operator functions, you need to
> PG_FREE_IF_COPY(?,?);

> Which of the above parameters need I free?

It'd probably be wise to do a FREE_IF_COPY on the tuple.

GetAttributeByName, however, hasn't copied anything (if it's
a pass-by-ref type you'll just get a pointer into the tuple).
If you do a copy further down that might be a reason to free
something, but this code alone isn't making a copy.
		regards, tom lane

Re: PG_FREE_IF_COPY()

От:
"John Hansen" <john@geeknet.com.au>
Дата:
Tom Lane [mailto:tgl@sss.pgh.pa.us] wrote:
> "John Hansen"  writes:
> > Given the following snippet:
> > 	HeapTupleHeader     tuple;
> > 	Datum               temp;
> > 	bool			  isnull;
> 	
> > 	tuple = PG_GETARG_HEAPTUPLEHEADER(0);
> > 	temp  = GetAttributeByName(tuple, "data", &isnull);
> 
> > When using this for a btree operator functions, you need to 
> > PG_FREE_IF_COPY(?,?);
> 
> > Which of the above parameters need I free?
> 
> It'd probably be wise to do a FREE_IF_COPY on the tuple.
> 
> GetAttributeByName, however, hasn't copied anything (if it's 
> a pass-by-ref type you'll just get a pointer into the tuple).
> If you do a copy further down that might be a reason to free 
> something, but this code alone isn't making a copy.

Cool, thanks...

> 
> 			regards, tom lane
> 
> 

... John

FAQ