Skip to content

Commit 01d83ff

Browse files
committed
Improve efficiency of recent changes to plperl's sv2cstr().
Along the way, add a missing dependency in the GNUmakefile. Alex Hunsaker, with a slight adjustment by me.
1 parent b2b4af5 commit 01d83ff

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

src/pl/plperl/GNUmakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ perlchunks.h: $(PERLCHUNKS)
7272

7373
all: all-lib
7474

75-
SPI.c: SPI.xs
75+
SPI.c: SPI.xs plperl_helpers.h
7676
@if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch --with-perl was not specified."; exit 1; fi
7777
$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap $< >$@
7878

79-
Util.c: Util.xs
79+
Util.c: Util.xs plperl_helpers.h
8080
@if [ x"$(perl_privlibexp)" = x"" ]; then echo "configure switch --with-perl was not specified."; exit 1; fi
8181
$(PERL) $(XSUBPPDIR)/ExtUtils/xsubpp -typemap $(perl_privlibexp)/ExtUtils/typemap $< >$@
8282

src/pl/plperl/expected/plperl_elog.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@ select uses_global();
5858
uses_global worked
5959
(1 row)
6060

61+
-- make sure we don't choke on readonly values
62+
do language plperl $$ elog(NOTICE, ${^TAINT}); $$;
63+
NOTICE: 0
64+
CONTEXT: PL/Perl anonymous code block

src/pl/plperl/plperl_helpers.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,35 @@ sv2cstr(SV *sv)
4747
{
4848
char *val, *res;
4949
STRLEN len;
50-
SV *nsv;
5150

5251
/*
5352
* get a utf8 encoded char * out of perl. *note* it may not be valid utf8!
5453
*
5554
* SvPVutf8() croaks nastily on certain things, like typeglobs and
5655
* readonly objects such as $^V. That's a perl bug - it's not supposed to
57-
* happen. To avoid crashing the backend, we make a copy of the
58-
* sv before passing it to SvPVutf8(). The copy is garbage collected
56+
* happen. To avoid crashing the backend, we make a copy of the sv before
57+
* passing it to SvPVutf8(). The copy is garbage collected
5958
* when we're done with it.
6059
*/
61-
nsv = newSVsv(sv);
62-
val = SvPVutf8(nsv, len);
60+
if (SvREADONLY(sv) ||
61+
isGV_with_GP(sv) ||
62+
(SvTYPE(sv) > SVt_PVLV && SvTYPE(sv) != SVt_PVFM))
63+
sv = newSVsv(sv);
64+
else
65+
/* increase the reference count so we cant just SvREFCNT_dec() it when
66+
* we are done */
67+
SvREFCNT_inc(sv);
68+
69+
val = SvPVutf8(sv, len);
6370

6471
/*
6572
* we use perl's length in the event we had an embedded null byte to ensure
6673
* we error out properly
6774
*/
68-
res = utf_u2e(val, len);
75+
res = utf_u2e(val, len);
6976

7077
/* safe now to garbage collect the new SV */
71-
SvREFCNT_dec(nsv);
78+
SvREFCNT_dec(sv);
7279

7380
return res;
7481
}

src/pl/plperl/sql/plperl_elog.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ create or replace function uses_global() returns text language plperl as $$
4343
$$;
4444

4545
select uses_global();
46+
47+
-- make sure we don't choke on readonly values
48+
do language plperl $$ elog(NOTICE, ${^TAINT}); $$;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy