Skip Menu |
Report information
Id: 133439
Status: resolved
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: slaven [at] rezic.de
Cc:
AdminCc:

Operating System: (no value)
PatchStatus: (no value)
Severity: low
Type: unknown
Perl Version: (no value)
Fixed In: (no value)

Attachments


To: perlbug [...] perl.org
CC: srezic [...] cpan.org
Date: Fri, 10 Aug 2018 15:46:01 +0200
Subject: Misleading output for calloc while -Dm in effect
From: slaven [...] rezic.de
Download (untitled) / with headers
text/plain 3.5k
This is a bug report for perl from slaven@rezic.de, generated with the help of perlbug 1.41 running under perl 5.28.0. ----------------------------------------------------------------- If -Dm is used then calloc() calls are logged like this: 0x2cbf90930: (2217022366) calloc 32808 x 32808 bytes It looks like approximately 1GB is allocated here. But the actual DEBUG_m call is the following: DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%" UVxf ": (%05ld) calloc %ld x %ld bytes\n",PTR2UV(ptr),(long)PL_an++,(long)count,(long)total_size)); so the last number is not the single element size, but the total size of the memory allocation. Probably the output should look different here, for example calloc %ld elements totalling %ld bytes or calloc %ld x %ld = %ld bytes", ... count, size, total_size or so. ----------------------------------------------------------------- --- Flags: category=core severity=low --- Site configuration information for perl 5.28.0: Configured by eserte at Sat Jun 23 08:28:02 CEST 2018. Summary of my perl5 (revision 5 version 28 subversion 0) configuration: Platform: osname=linux osvers=3.16.0-4-amd64 archname=x86_64-linux uname='linux cabulja 3.16.0-4-amd64 #1 smp debian 3.16.51-3 (2017-12-13) x86_64 gnulinux ' config_args='-ds -e -Dprefix=/opt/perl-5.28.0 -Dcf_email=srezic@cpan.org' hint=recommended useposix=true d_sigaction=define useithreads=undef usemultiplicity=undef use64bitint=define use64bitall=define uselongdouble=undef usemymalloc=n default_inc_excludes_dot=define bincompat5005=undef Compiler: cc='cc' ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2' optimize='-O2' cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include' ccversion='' gccversion='4.9.2' gccosandvers='' intsize=4 longsize=8 ptrsize=8 doublesize=8 byteorder=12345678 doublekind=3 d_longlong=define longlongsize=8 d_longdbl=define longdblsize=16 longdblkind=3 ivtype='long' ivsize=8 nvtype='double' nvsize=8 Off_t='off_t' lseeksize=8 alignbytes=8 prototype=define Linker and Libraries: ld='cc' ldflags =' -fstack-protector-strong -L/usr/local/lib' libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc libc=libc-2.19.so so=so useshrplib=false libperl=libperl.a gnulibc_version='2.19' Dynamic Linking: dlsrc=dl_dlopen.xs dlext=so d_dlsymun=undef ccdlflags='-Wl,-E' cccdlflags='-fPIC' lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong' --- @INC for perl 5.28.0: /opt/perl-5.28.0/lib/site_perl/5.28.0/x86_64-linux /opt/perl-5.28.0/lib/site_perl/5.28.0 /opt/perl-5.28.0/lib/5.28.0/x86_64-linux /opt/perl-5.28.0/lib/5.28.0 --- Environment for perl 5.28.0: HOME=/home/eserte LANG=en_US.UTF-8 LANGUAGE=en_US:en LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/eserte/bin/linux-gnu:/home/eserte/bin/sh:/home/eserte/bin:/home/eserte/bin/pistachio-perl/bin:/usr/games:/home/eserte/devel PERLDOC=-MPod::Perldoc::ToTextOverstrike PERL_BADLANG (unset) SHELL=/bin/zsh
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 767b
On Fri, 10 Aug 2018 06:50:56 -0700, slaven@rezic.de wrote: Show quoted text
> If -Dm is used then calloc() calls are logged like this: > > 0x2cbf90930: (2217022366) calloc 32808 x 32808 bytes > > It looks like approximately 1GB is allocated here. But the actual > DEBUG_m > call is the following: > > DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%" UVxf ": (%05ld) calloc %ld > x %ld > bytes\n",PTR2UV(ptr),(long)PL_an++,(long)count,(long)total_size)); > > so the last number is not the single element size, but the total size > of the memory allocation. > > Probably the output should look different here, for example > > calloc %ld elements totalling %ld bytes > > or > > calloc %ld x %ld = %ld bytes", ... count, size, total_size > > or so.
Something like the attached? Tony
Subject: 0001-perl-133439-fix-Dm-reporting-for-calloc.patch
From 75b5f4074fce363842f2171e79c1b39b330b6ea4 Mon Sep 17 00:00:00 2001 From: Tony Cook <tony@develop-help.com> Date: Thu, 6 Sep 2018 14:05:20 +1000 Subject: (perl #133439) fix -Dm reporting for calloc() a) report both the size and count, and the total allocated rather than just the count and total allocated, which was displayed in a misleading fashion b) use %zu formatting to match the original types (size_t) and remove the casts to long, which can lose information on Win32, where long is 32-bits on x64 builds. --- util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util.c b/util.c index ff88a54bf6..a9bf9b8609 100644 --- a/util.c +++ b/util.c @@ -439,7 +439,7 @@ Perl_safesyscalloc(MEM_SIZE count, MEM_SIZE size) ptr = (Malloc_t)PerlMem_calloc(count ? count : 1, size ? size : 1); #endif PERL_ALLOC_CHECK(ptr); - DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%" UVxf ": (%05ld) calloc %ld x %ld bytes\n",PTR2UV(ptr),(long)PL_an++,(long)count,(long)total_size)); + DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%" UVxf ": (%05ld) calloc %zu x %zu = %zu bytes\n",PTR2UV(ptr),(long)PL_an++, count, size, total_size)); if (ptr != NULL) { #ifdef USE_MDH { -- 2.11.0
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 924b
On Wed, 05 Sep 2018 21:06:12 -0700, tonyc wrote: Show quoted text
> On Fri, 10 Aug 2018 06:50:56 -0700, slaven@rezic.de wrote:
> > If -Dm is used then calloc() calls are logged like this: > > > > 0x2cbf90930: (2217022366) calloc 32808 x 32808 bytes > > > > It looks like approximately 1GB is allocated here. But the actual > > DEBUG_m > > call is the following: > > > > DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%" UVxf ": (%05ld) calloc %ld > > x %ld > > bytes\n",PTR2UV(ptr),(long)PL_an++,(long)count,(long)total_size)); > > > > so the last number is not the single element size, but the total size > > of the memory allocation. > > > > Probably the output should look different here, for example > > > > calloc %ld elements totalling %ld bytes > > > > or > > > > calloc %ld x %ld = %ld bytes", ... count, size, total_size > > > > or so.
> > Something like the attached?
Applied as 2273039810f46a2ccd5940a26c7c04f8e039aa8f. Tony
Download (untitled) / with headers
text/plain 313b
Thank you for filing this report. You have helped make Perl better. With the release today of Perl 5.30.0, this and 160 other issues have been resolved. Perl 5.30.0 may be downloaded via: https://metacpan.org/release/XSAWYERX/perl-5.30.0 If you find that the problem persists, feel free to reopen this ticket.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org