Tom Lane wrote:
I think the reason is that it's both an input and an output parameter,
to handle the case where the cast function returns NULL.

The only reference to `isnull' in the body of exec_cast_value() is:

if (!*isnull)
{
    /* ... */
}

i.e. it is never referenced again, let alone written through. Barring any objections I'll apply the attached patch tomorrow.

-Neil
Index: src/pl/plpgsql/src/pl_exec.c
===================================================================
RCS file: /var/lib/cvs/pgsql/src/pl/plpgsql/src/pl_exec.c,v
retrieving revision 1.150
diff -c -r1.150 pl_exec.c
*** src/pl/plpgsql/src/pl_exec.c	28 Jul 2005 00:26:30 -0000	1.150
--- src/pl/plpgsql/src/pl_exec.c	28 Jul 2005 05:29:21 -0000
***************
*** 173,182 ****
  				FmgrInfo *reqinput,
  				Oid reqtypioparam,
  				int32 reqtypmod,
! 				bool *isnull);
  static Datum exec_simple_cast_value(Datum value, Oid valtype,
  					   Oid reqtype, int32 reqtypmod,
! 					   bool *isnull);
  static void exec_init_tuple_store(PLpgSQL_execstate *estate);
  static bool compatible_tupdesc(TupleDesc td1, TupleDesc td2);
  static void exec_set_found(PLpgSQL_execstate *estate, bool state);
--- 173,182 ----
  				FmgrInfo *reqinput,
  				Oid reqtypioparam,
  				int32 reqtypmod,
! 				bool isnull);
  static Datum exec_simple_cast_value(Datum value, Oid valtype,
  					   Oid reqtype, int32 reqtypmod,
! 					   bool isnull);
  static void exec_init_tuple_store(PLpgSQL_execstate *estate);
  static bool compatible_tupdesc(TupleDesc td1, TupleDesc td2);
  static void exec_set_found(PLpgSQL_execstate *estate, bool state);
***************
*** 356,362 ****
  											&(func->fn_retinput),
  											func->fn_rettypioparam,
  											-1,
! 											&fcinfo->isnull);
  
  			/*
  			 * If the function's return type isn't by value, copy the value
--- 356,362 ----
  											&(func->fn_retinput),
  											func->fn_rettypioparam,
  											-1,
! 											fcinfo->isnull);
  
  			/*
  			 * If the function's return type isn't by value, copy the value
***************
*** 1348,1354 ****
  	value = exec_cast_value(value, valtype, var->datatype->typoid,
  							&(var->datatype->typinput),
  							var->datatype->typioparam,
! 							var->datatype->atttypmod, &isnull);
  	if (isnull)
  		ereport(ERROR,
  				(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
--- 1348,1354 ----
  	value = exec_cast_value(value, valtype, var->datatype->typoid,
  							&(var->datatype->typinput),
  							var->datatype->typioparam,
! 							var->datatype->atttypmod, isnull);
  	if (isnull)
  		ereport(ERROR,
  				(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
***************
*** 1364,1370 ****
  	value = exec_cast_value(value, valtype, var->datatype->typoid,
  							&(var->datatype->typinput),
  							var->datatype->typioparam,
! 							var->datatype->atttypmod, &isnull);
  	if (isnull)
  		ereport(ERROR,
  				(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
--- 1364,1370 ----
  	value = exec_cast_value(value, valtype, var->datatype->typoid,
  							&(var->datatype->typinput),
  							var->datatype->typioparam,
! 							var->datatype->atttypmod, isnull);
  	if (isnull)
  		ereport(ERROR,
  				(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
***************
*** 1868,1874 ****
  												var->datatype->typoid,
  												tupdesc->attrs[0]->atttypid,
  												tupdesc->attrs[0]->atttypmod,
! 												&isNull);
  
  				tuple = heap_form_tuple(tupdesc, &retval, &isNull);
  
--- 1868,1874 ----
  												var->datatype->typoid,
  												tupdesc->attrs[0]->atttypid,
  												tupdesc->attrs[0]->atttypmod,
! 												isNull);
  
  				tuple = heap_form_tuple(tupdesc, &retval, &isNull);
  
***************
*** 1934,1940 ****
  										rettype,
  										tupdesc->attrs[0]->atttypid,
  										tupdesc->attrs[0]->atttypmod,
! 										&isNull);
  
  		tuple = heap_form_tuple(tupdesc, &retval, &isNull);
  
--- 1934,1940 ----
  										rettype,
  										tupdesc->attrs[0]->atttypid,
  										tupdesc->attrs[0]->atttypmod,
! 										isNull);
  
  		tuple = heap_form_tuple(tupdesc, &retval, &isNull);
  
***************
*** 2995,3001 ****
  										   &(var->datatype->typinput),
  										   var->datatype->typioparam,
  										   var->datatype->atttypmod,
! 										   isNull);
  
  				if (*isNull && var->notnull)
  					ereport(ERROR,
--- 2995,3001 ----
  										   &(var->datatype->typinput),
  										   var->datatype->typioparam,
  										   var->datatype->atttypmod,
! 										   *isNull);
  
  				if (*isNull && var->notnull)
  					ereport(ERROR,
***************
*** 3194,3200 ****
  													 valtype,
  													 atttype,
  													 atttypmod,
! 													 &attisnull);
  				if (attisnull)
  					nulls[fno] = 'n';
  				else
--- 3194,3200 ----
  													 valtype,
  													 atttype,
  													 atttypmod,
! 													 attisnull);
  				if (attisnull)
  					nulls[fno] = 'n';
  				else
***************
*** 3340,3346 ****
  													   valtype,
  													   arrayelemtypeid,
  													   -1,
! 													   isNull);
  
  				/*
  				 * Build the modified array value.
--- 3340,3346 ----
  													   valtype,
  													   arrayelemtypeid,
  													   -1,
! 													   *isNull);
  
  				/*
  				 * Build the modified array value.
***************
*** 3564,3570 ****
  	exprdatum = exec_eval_expr(estate, expr, isNull, &exprtypeid);
  	exprdatum = exec_simple_cast_value(exprdatum, exprtypeid,
  									   INT4OID, -1,
! 									   isNull);
  	return DatumGetInt32(exprdatum);
  }
  
--- 3564,3570 ----
  	exprdatum = exec_eval_expr(estate, expr, isNull, &exprtypeid);
  	exprdatum = exec_simple_cast_value(exprdatum, exprtypeid,
  									   INT4OID, -1,
! 									   *isNull);
  	return DatumGetInt32(exprdatum);
  }
  
***************
*** 3586,3592 ****
  	exprdatum = exec_eval_expr(estate, expr, isNull, &exprtypeid);
  	exprdatum = exec_simple_cast_value(exprdatum, exprtypeid,
  									   BOOLOID, -1,
! 									   isNull);
  	return DatumGetBool(exprdatum);
  }
  
--- 3586,3592 ----
  	exprdatum = exec_eval_expr(estate, expr, isNull, &exprtypeid);
  	exprdatum = exec_simple_cast_value(exprdatum, exprtypeid,
  									   BOOLOID, -1,
! 									   *isNull);
  	return DatumGetBool(exprdatum);
  }
  
***************
*** 4060,4068 ****
  				FmgrInfo *reqinput,
  				Oid reqtypioparam,
  				int32 reqtypmod,
! 				bool *isnull)
  {
! 	if (!*isnull)
  	{
  		/*
  		 * If the type of the queries return value isn't that of the
--- 4060,4068 ----
  				FmgrInfo *reqinput,
  				Oid reqtypioparam,
  				int32 reqtypmod,
! 				bool isnull)
  {
! 	if (!isnull)
  	{
  		/*
  		 * If the type of the queries return value isn't that of the
***************
*** 4095,4103 ****
  static Datum
  exec_simple_cast_value(Datum value, Oid valtype,
  					   Oid reqtype, int32 reqtypmod,
! 					   bool *isnull)
  {
! 	if (!*isnull)
  	{
  		if (valtype != reqtype || reqtypmod != -1)
  		{
--- 4095,4103 ----
  static Datum
  exec_simple_cast_value(Datum value, Oid valtype,
  					   Oid reqtype, int32 reqtypmod,
! 					   bool isnull)
  {
! 	if (!isnull)
  	{
  		if (valtype != reqtype || reqtypmod != -1)
  		{
---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org

Reply via email to