develooper Front page | perl.perl5.porters | Postings from March 2007

[perl #41775] Memoize bug (and patch): problem with LIST_CACHE => MERGE

Thread Next
From:
Father Chrysostomos
Date:
March 10, 2007 15:00
Subject:
[perl #41775] Memoize bug (and patch): problem with LIST_CACHE => MERGE
Message ID:
rt-3.6.HEAD-30201-1173557915-1780.41775-75-0@perl.org
# New Ticket Created by  Father Chrysostomos 
# Please include the string:  [perl #41775]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=41775 >


In Memoize 1.01,  LIST_CACHE => MERGE does not work properly if a  
memoized function is called in list context the first time it is called.

The following script:

	#!/usr/bin/perl -l
	
	use Memoize;
	
	sub er {
		warn qw[void scalar list][wantarray + defined wantarray];
		shift
	}
	memoize 'er', LIST_CACHE => 'MERGE';
	
	print er 5;
	print er 5;
	print er 6;
	print er 6;

prints:
	list at memotest line 7.
	5
	ARRAY(0x1828d6c)
	list at memotest line 7.
	6
	ARRAY(0x18298f4)


This patch fixes it. (I'm afraid I've never used diff before and I  
don't know how to produce the usual patch format. I simply used 'diff  
`perldoc -l Memoize` Memoize.pm > memoize_patch'.)

269,270c269,271
<       my $q = $cache->{$argstr} = [&{$info->{U}}(@_)];
<       @$q;
---
 >       my @q = &{$info->{U}}(@_);
 >       $cache->{$argstr} = $info->{O}{LIST_CACHE} eq 'MERGE' ? $q 
[0] : \@q;
 >       @q;

$ perl memotest
list at memotest line 7.
5
5
list at memotest line 7.
6
6

Whether $q[0] or $q[-1] should be used is debatable, I suppose. But  
then isn't LIST_CACHE => MERGE a promise that the function will never  
return more than one value? Maybe it could be documented that the  
result of returning multiple values (or an empty list) from a  
function with its list cache merged is officially undefined.

---
Flags:
     category=library
     severity=medium
---
Site configuration information for perl v5.8.8:

Configured by neo at Tue Jan  9 16:06:53 PST 2007.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
   Platform:
     osname=darwin, osvers=8.8.0, archname=darwin-thread-multi-2level
     uname='darwin treebeard.local 8.8.0 darwin kernel version 8.8.0:  
fri sep 8 17:18:57 pdt 2006; root:xnu-792.12.6.obj~1release_ppc power  
macintosh powerpc '
     config_args=''
     hint=recommended, useposix=true, d_sigaction=define
     usethreads=define use5005threads=undef useithreads=define  
usemultiplicity=define
     useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
     use64bitint=undef use64bitall=undef uselongdouble=undef
     usemymalloc=n, bincompat5005=undef
   Compiler:
     cc='cc', ccflags ='-g -pipe -fno-common -DPERL_DARWIN -no-cpp- 
precomp -fno-strict-aliasing -I/usr/local/include',
     optimize='-O3',
     cppflags='-no-cpp-precomp -g -pipe -fno-common -DPERL_DARWIN -no- 
cpp-precomp -fno-strict-aliasing -I/usr/local/include'
     ccversion='', gccversion='4.0.0 20041026 (Apple Computer, Inc.  
build 4061)', gccosandvers='darwin8'
     intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
     ivtype='long', ivsize=4, nvtype='double', nvsize=8,  
Off_t='off_t', lseeksize=8
     alignbytes=8, prototype=define
   Linker and Libraries:
     ld='env MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags =' -L/usr/ 
local/lib'
     libpth=/usr/local/lib /usr/lib
     libs=-ldbm -ldl -lm -lc
     perllibs=-ldl -lm -lc
     libc=, so=dylib, useshrplib=false, libperl=libperl.a
     gnulibc_version=''
   Dynamic Linking:
     dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
     cccdlflags=' ', lddlflags=' -bundle -undefined dynamic_lookup -L/ 
usr/local/lib'

Locally applied patches:


---
@INC for perl v5.8.8:
     /usr/local/lib/perl5/5.8.8/darwin-thread-multi-2level
     /usr/local/lib/perl5/5.8.8
     /usr/local/lib/perl5/site_perl/5.8.8/darwin-thread-multi-2level
     /usr/local/lib/perl5/site_perl/5.8.8
     /usr/local/lib/perl5/site_perl
     /System/Library/Perl/5.8.6/darwin-thread-multi-2level
     /System/Library/Perl/5.8.6/darwin-thread-multi-2level
     /System/Library/Perl/5.8.6
     /Library/Perl/5.8.6/darwin-thread-multi-2level
     /Library/Perl/5.8.6/darwin-thread-multi-2level
     /Library/Perl/5.8.6
     /Library/Perl
     /Network/Library/Perl/5.8.6/darwin-thread-multi-2level
     /Network/Library/Perl/5.8.6
     /Network/Library/Perl
     /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level
     /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level
     /System/Library/Perl/Extras/5.8.6
     /Library/Perl/5.8.1
     .

---
Environment for perl v5.8.8:
     DYLD_LIBRARY_PATH (unset)
     HOME=/Users/neo
     LANG (unset)
     LANGUAGE (unset)
     LD_LIBRARY_PATH (unset)
     LOGDIR (unset)
     PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/TeX/bin/powerpc- 
darwin6.8:/usr/local/bin
     PERL_BADLANG (unset)
     SHELL=/bin/bash




Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About