Re: [Plperlng-devel] strange bug in plperl - Mailing list pgsql-hackers

From Sergej Sergeev
Subject Re: [Plperlng-devel] strange bug in plperl
Date
Msg-id 40EA6AEC.8050505@inbox.ru
Whole thread Raw
In response to strange bug in plperl  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-hackers
Atached patch fix this bug

Serg


Andrew Dunstan wrote:

>
> Can anyone suggest why I might be seeing this effect (each notice
> comes out once per row plus once per function call)
>
> thanks
>
> andrew
>
> andrew=# create function tstset() returns setof tst language plperl as $$
> andrew$# elog(NOTICE,"tstset called");
> andrew$# return [{i=>1,v=>"one"},{i=>2,v=>"two"}];
> andrew$# $$;
> CREATE FUNCTION
> andrew=# select * from tstset();
> NOTICE:  tstset called
> NOTICE:  tstset called
> NOTICE:  tstset called
> i |  v ---+-----
> 1 | one
> 2 | two
> (2 rows)
>
> _______________________________________________
> Plperlng-devel mailing list
> Plperlng-devel@pgfoundry.org
> http://pgfoundry.org/mailman/listinfo/plperlng-devel
>
>
*** plperl.c    2004-07-01 23:50:22.000000000 +0300
--- newplperl.c    2004-07-06 11:57:56.000000000 +0300
***************
*** 99,104 ****
--- 99,105 ----
  static HV  *plperl_proc_hash = NULL;
  AV           *g_row_keys = NULL;
  AV           *g_column_keys = NULL;
+ SV           *srf_perlret=NULL; /*keep returned value*/
  int            g_attr_num = 0;

  /**********************************************************************
***************
*** 839,847 ****
      /* Find or compile the function */
      prodesc = compile_plperl_function(fcinfo->flinfo->fn_oid, false);
      /************************************************************
!      * Call the Perl function
       ************************************************************/
!     perlret = plperl_call_perl_func(prodesc, fcinfo);
      if (prodesc->fn_retistuple && SRF_IS_FIRSTCALL())
      {

--- 840,855 ----
      /* Find or compile the function */
      prodesc = compile_plperl_function(fcinfo->flinfo->fn_oid, false);
      /************************************************************
!      * Call the Perl function if not returning set
       ************************************************************/
!      if (!prodesc->fn_retistuple)
!         perlret = plperl_call_perl_func(prodesc, fcinfo);
!      else {
!         if (SRF_IS_FIRSTCALL()) /*call function only once*/
!             srf_perlret = plperl_call_perl_func(prodesc, fcinfo);
!         perlret = srf_perlret;
!     }
!
      if (prodesc->fn_retistuple && SRF_IS_FIRSTCALL())
      {


pgsql-hackers by date:

Previous
From: Dennis Bjorklund
Date:
Subject: Re: Nested Transactions, Abort All
Next
From: "Najib Abi Fadel"
Date:
Subject: Re: [GENERAL] creating a complex aggregate function