X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1AC7B5299A for ; Tue, 12 Jul 2005 15:59:42 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 47512-08 for ; Tue, 12 Jul 2005 18:59:40 +0000 (GMT) Received: from trolak.mydnsbox2.com (ns1.mydnsbox2.com [207.44.142.118]) by svr1.postgresql.org (Postfix) with ESMTP id 2322252986 for ; Tue, 12 Jul 2005 15:59:39 -0300 (ADT) Received: from [192.168.1.103] (cpe-024-211-165-134.nc.res.rr.com [24.211.165.134]) (authenticated (0 bits)) by trolak.mydnsbox2.com (8.11.6/8.11.6) with ESMTP id j6CIDqm08355; Tue, 12 Jul 2005 13:13:52 -0500 Message-ID: <42D41319.70107@dunslane.net> Date: Tue, 12 Jul 2005 14:59:37 -0400 From: Andrew Dunstan User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050513 Fedora/1.7.8-1.3.1 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Michael Fuhr Cc: pgsql-hackers@postgresql.org Subject: Re: PL/Perl list value return causes segfault References: <20050712130452.GA84564@winnie.fuhr.org> In-Reply-To: <20050712130452.GA84564@winnie.fuhr.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.044 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200507/438 X-Sequence-Number: 70490 Michael Fuhr wrote: >In the latest HEAD, a PL/Perl function that returns a list value >instead of a reference causes a segmentation fault: > >CREATE FUNCTION foo() RETURNS integer[] AS $$ >return (1, 2, 3, 4); >$$ LANGUAGE plperl; > >SELECT foo(); >server closed the connection unexpectedly > >Here's the stack trace: > >#0 0xfed45bcc in plperl_call_handler (fcinfo=0xffbfe230) at plperl.c:1031 >#1 0x0010e7d4 in ExecMakeFunctionResult (fcache=0x44af00, econtext=0x44ae58, > isNull=0x44b470 "\177~\177\177\177\177\177\177", isDone=0x44b4d8) at execQual.c:1031 >#2 0x001122b0 in ExecProject (projInfo=0x44af00, isDone=0x44ae58) at execQual.c:3607 > > Patch below fixes the SEGV, and you will see instead: andrew=# select foo(); ERROR: array value must start with "{" or dimension information which might not immediately point you to the source of the error :-( , but is certainly better than a SEGV. Note that all plperl functions are called in scalar context, and it is always wrong to return a list (as opposed to a listref). In fact, the value received might surprise you even if it worked (it would be the value of the last member of the list). cheers andrew Index: plperl.c =================================================================== RCS file: /projects/cvsroot/pgsql/src/pl/plperl/plperl.c,v retrieving revision 1.85 diff -c -r1.85 plperl.c *** plperl.c 12 Jul 2005 01:16:21 -0000 1.85 --- plperl.c 12 Jul 2005 18:52:54 -0000 *************** *** 1021,1027 **** char *val; ! if (prodesc->fn_retisarray && SvTYPE(SvRV(perlret)) == SVt_PVAV) { array_ret = plperl_convert_to_pg_array(perlret); SvREFCNT_dec(perlret); --- 1021,1028 ---- char *val; ! if (prodesc->fn_retisarray && SvROK(perlret) && ! SvTYPE(SvRV(perlret)) == SVt_PVAV) { array_ret = plperl_convert_to_pg_array(perlret); SvREFCNT_dec(perlret);