[PATCH] was RE: [PATCH] printf.patch: Adding printf checking for gcc

------_=_NextPart_000_01C55BDB.607BAAD0
Content-Type: text/plain;
	charset="iso-8859-1"



-----Original Message-----
From: Andy Lester [mailto:andy@petdance.com]
Sent: 03 May 2005 20:15
To: Robin Barker
Cc: 'Perl 5 Porters '
Subject: Re: [PATCH] printf.patch: Adding printf checking for gcc

> Should Porting/pumpkin.pod say something more/different about CHECK_FORMAT,
> or should it be said somewhere else?

For that matter, is there any reason to not have it on by default?

-----

The attached patch makes CHECK_FORMAT the default.
SVf is fixed as '%-p' , replacing the invented '%_' format.

The code in sv.c only interprets '%-p' format as SVf for internal 
code, calls to C<sprintf> correctly interpret '%-p' as left-aligned 
pointer values (and I've added a test for this).

There may be some clashes with Andy's attribute patches,
so I've shipped this as soon as I could.

Robin



-------------------------------------------------------------------
This e-mail and any attachments may contain confidential and/or
privileged material; it is for the intended addressee(s) only.
If you are not a named addressee, you must not use, retain or
disclose such information.

NPL Management Ltd cannot guarantee that the e-mail or any
attachments are free from viruses.

NPL Management Ltd. Registered in England and Wales. No: 2937881
Registered Office: Serco House, 16 Bartley Wood Business Park,
                   Hook, Hampshire, United Kingdom  RG27 9UY
-------------------------------------------------------------------
------_=_NextPart_000_01C55BDB.607BAAD0
Content-Type: application/octet-stream;
	name="format-arg-592.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="format-arg-592.patch"

--- /home/rmb1/temp/perl/perl-current/perl.h	Wed May 18 12:07:14 =
2005=0A=
+++ perl.h=0A=
@@ -2514,20 +2514,17 @@=0A=
 #  define PERL_SET_THX(t)		PERL_SET_CONTEXT(t)=0A=
 #endif=0A=
 =0A=
+/*  This replaces the previous %_ "hack" by the "%-p" hack=0A=
+    All that is required is that the perl source does not=0A=
+    use "%-p" or "%-<number>p" format.  These format will=0A=
+    still work in perl code.   RMB 2005/05/17=0A=
+*/=0A=
 #ifndef SVf=0A=
-#  ifdef CHECK_FORMAT=0A=
 #    define SVf "-p"=0A=
-#  else=0A=
-#    define SVf "_"=0A=
-#  endif=0A=
 #endif=0A=
 =0A=
 #ifndef SVf_precision=0A=
-#  ifdef CHECK_FORMAT=0A=
 #    define SVf_precision(n) "-" n "p"=0A=
-#  else=0A=
-#    define SVf_precision(n) "." n "_"=0A=
-#  endif=0A=
 #endif=0A=
 =0A=
 #ifndef SVf32=0A=
@@ -2543,19 +2540,11 @@=0A=
 #endif=0A=
 =0A=
 #ifndef DieNull=0A=
-#  ifdef CHECK_FORMAT=0A=
 #    define DieNull Perl_vdie(aTHX_ Nullch, Null(va_list *))=0A=
-#  else=0A=
-#    define DieNull Perl_die(aTHX_ Nullch)=0A=
-#  endif=0A=
 #endif=0A=
 =0A=
 #ifndef __attribute__format__=0A=
-#  ifdef CHECK_FORMAT=0A=
-#    define __attribute__format__(x,y,z) =
__attribute__((format(x,y,z)))=0A=
-#  else=0A=
-#    define __attribute__format__(x,y,z)=0A=
-#  endif=0A=
+#    define __attribute__format__(x,y,z) =
__attribute__((__format__(x,y,z)))=0A=
 #endif=0A=
 =0A=
 /* See http://www.ohse.de/uwe/articles/gcc-attributes.html, but=0A=
--- /home/rmb1/temp/perl/perl-current/perlio.h	Wed May 18 12:07:15 =
2005=0A=
+++ perlio.h=0A=
@@ -210,11 +210,7 @@=0A=
 =0A=
 START_EXTERN_C=0A=
 #ifndef __attribute__format__=0A=
-#  ifdef CHECK_FORMAT=0A=
-#    define __attribute__format__(x,y,z) =
__attribute__((format(x,y,z)))=0A=
-#  else=0A=
-#    define __attribute__format__(x,y,z)=0A=
-#endif=0A=
+#    define __attribute__format__(x,y,z) =
__attribute__((__format__(x,y,z)))=0A=
 #endif=0A=
 #ifndef NEXT30_NO_ATTRIBUTE=0A=
 #ifndef HASATTRIBUTE		/* disable GNU-cc attribute checking? */=0A=
diff -ur /home/rmb1/temp/perl/perl-current/sv.c ./sv.c=0A=
--- /home/rmb1/temp/perl/perl-current/sv.c	Wed May 18 12:07:24 2005=0A=
+++ sv.c=0A=
@@ -9222,12 +9222,10 @@=0A=
     /* no matter what, this is a string now */=0A=
     (void)SvPV_force(sv, origlen);=0A=
 =0A=
-    /* special-case "", "%s", and "%_" */=0A=
+    /* special-case "", "%s", and "%-p" (SVf) */=0A=
     if (patlen =3D=3D 0)=0A=
 	return;=0A=
-    if (patlen =3D=3D 2 && pat[0] =3D=3D '%') {=0A=
-	switch (pat[1]) {=0A=
-	case 's':=0A=
+    if (patlen =3D=3D 2 && pat[0] =3D=3D '%' && pat[1] =3D=3D 's') =
{=0A=
 	    if (args) {=0A=
                 const char *s =3D va_arg(*args, char*);=0A=
 		sv_catpv(sv, s ? s : nullstr);=0A=
@@ -9238,7 +9236,9 @@=0A=
 		    SvUTF8_on(sv);=0A=
 	    }=0A=
 	    return;=0A=
-	case '_':=0A=
+    }=0A=
+    if (patlen =3D=3D 3 && pat[0] =3D=3D '%' &&=0A=
+	pat[1] =3D=3D '-' && pat[2] =3D=3D 'p') {=0A=
 	    if (args) {=0A=
 		argsv =3D va_arg(*args, SV*);=0A=
 		sv_catsv(sv, argsv);=0A=
@@ -9246,9 +9246,6 @@=0A=
 		    SvUTF8_on(sv);=0A=
 		return;=0A=
 	    }=0A=
-	    /* See comment on '_' below */=0A=
-	    break;=0A=
-	}=0A=
     }=0A=
 =0A=
 #ifndef USE_LONG_DOUBLE=0A=
@@ -9626,23 +9623,6 @@=0A=
 		    is_utf8 =3D TRUE;=0A=
 		}=0A=
 	    }=0A=
-	    goto string;=0A=
-=0A=
-	case '_':=0A=
-#ifdef CHECK_FORMAT=0A=
-	format_sv:=0A=
-#endif=0A=
-	    /*=0A=
-	     * The "%_" hack might have to be changed someday,=0A=
-	     * if ISO or ANSI decide to use '_' for something.=0A=
-	     * So we keep it hidden from users' code.=0A=
-	     */=0A=
-	    if (!args || vectorize)=0A=
-		goto unknown;=0A=
-	    argsv =3D va_arg(*args, SV*);=0A=
-	    eptr =3D SvPVx(argsv, elen);=0A=
-	    if (DO_UTF8(argsv))=0A=
-		is_utf8 =3D TRUE;=0A=
 =0A=
 	string:=0A=
 	    vectorize =3D FALSE;=0A=
@@ -9653,17 +9633,21 @@=0A=
 	    /* INTEGERS */=0A=
 =0A=
 	case 'p':=0A=
-#ifdef CHECK_FORMAT=0A=
-	    if (left) {=0A=
+	    if (left && args) {		/* SVf */=0A=
 		left =3D FALSE;=0A=
-	        if (!width)=0A=
-		    goto format_sv;	/* %-p	-> %_	*/=0A=
-		precis =3D width;=0A=
-		has_precis =3D TRUE;=0A=
-		width =3D 0;=0A=
-		goto format_sv;		/* %-Np	-> %.N_	*/	=0A=
+		if (width) {=0A=
+		    precis =3D width;=0A=
+		    has_precis =3D TRUE;=0A=
+		    width =3D 0;=0A=
+		}=0A=
+		if (vectorize)=0A=
+		    goto unknown;=0A=
+		argsv =3D va_arg(*args, SV*);=0A=
+		eptr =3D SvPVx(argsv, elen);=0A=
+		if (DO_UTF8(argsv))=0A=
+		    is_utf8 =3D TRUE;=0A=
+		goto string;=0A=
 	    }=0A=
-#endif=0A=
 	    if (alt || vectorize)=0A=
 		goto unknown;=0A=
 	    uv =3D PTR2UV(args ? va_arg(*args, void*) : argsv);=0A=
diff -ur /home/rmb1/temp/perl/perl-current/t/op/sprintf.t =
../t/op/sprintf.t=0A=
--- /home/rmb1/temp/perl/perl-current/t/op/sprintf.t	Wed Jan 12 =
14:25:02 2005=0A=
+++ t/op/sprintf.t=0A=
@@ -323,6 +323,7 @@=0A=
 >%+o<       >642<         >1202<=0A=
 >%#o<       >642<         >01202<=0A=
 >%d< >$p=3Dsprintf('%p',$p);$p=3D~/^[0-9a-f]+$/< >1< >Coarse hack: hex =
from %p?<=0A=
+>%d< >$p=3Dsprintf('%-8p',$p);$p=3D~/^[0-9a-f]+\s*$/< >1< >Coarse =
hack: hex from %p?<=0A=
 >%#p<       >''<          >%#p INVALID<=0A=
 >%q<        >''<          >%q INVALID<=0A=
 >%r<        >''<          >%r INVALID<=0A=

------_=_NextPart_000_01C55BDB.607BAAD0--
0
Robin
5/18/2005 6:57:02 PM
perl.perl5.porters 48287 articles. 1 followers. Follow

1 Replies
621 Views

Similar Articles

[PageSpeed] 33
Get it on Google Play
Get it on Apple App Store

On Wed, May 18, 2005 at 07:57:02PM +0100, Robin Barker (Robin.Barker@npl.co.uk) wrote:
> > Should Porting/pumpkin.pod say something more/different about CHECK_FORMAT,
> > or should it be said somewhere else?
> 
> For that matter, is there any reason to not have it on by default?

I don't see why we wouldn't.

I'll include that in my megapatch.

xoa


-- 
Andy Lester => andy@petdance.com => www.petdance.com => AIM:petdance
0
andy
5/18/2005 7:04:40 PM
Reply:

Similar Artilces:

[PATCH] printf.patch: Adding printf checking for gcc
--ZGiS0Q5IWpPtfppv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline We have printf format checking infrastructure in place, but it's broken. The directives for GCC are incorrect, so have no effect. This patch fixes that, as well as other little things found from compiler warnings on testdrive: * Remove two unused variables in Time::HiRes * Consting and localizing in gv.c. Also fixed some indentation. * Squashed an "unused argc and argv" warning in ExtUtils::Embed's tests * Removed unused var getting set in Perl_cv_clone() in pad.c * Quie...

Patches, patches, patches...
To forestall potential incidents of Warnock's Dillemma... I'm about to apply a whole heap 'o patches to Parrot. (With appropriate [APPLIED] responses, I hope) If, at the end of the day, I have *not* applied or commented on a patch you've sent, it means I've Officially Missed It, so give another try. Sorry 'bout this. Too much mail in the mailbox, and going back in time is tricky, as it can miss subsequent discussions on patches 'n stuff. -- Dan --------------------------------------"it's like th...

Patches, patches, patches... #2
OK, this is advance warning that I'm about to be reposting a bunch of patches of mine which appear to have succumbed to Warnock's Dilemma. The first three should be uncontroversial: there's a documentation fix-up for core.ops, and new tests for strings and stacks. The last one is rather larger, and consists of a greatly expanded set of tests for PerlString's, plus a bunch of bug-fixes. I'd be grateful if Jeff or Dan could take a look at this, as I have the feeling that a lot of the scalar PMCs are going to need similar fixes. Simon ...

[PATCH] Patch to patch for callbacks in core
I should have tested this better before submitting it. This patch is to Perl 11722 after applying my previous patch. Now callbacks will actually work. :-) - D <dmlloyd@tds.net> --- mg.c-old Tue Aug 21 13:26:52 2001 +++ perl-devel/mg.c Tue Aug 21 15:09:16 2001 @@ -1068,7 +1068,18 @@ void Perl_despatch_signals(pTHX) { - PL_event_pending = 0; + if (PL_callback_head != NULL) { + CALLBACK *cur, *next; + + for (cur = PL_callback_head; cur != NULL; cur = next) { + next = cur->next; + (*cur->callback)(cur->data); + ...

RE: [PATCH perlio.h] (was RE: [PATCH] %_ (was Re: [PATCH] operati on o n `PL_na' may be undefined))
The "audit" should reveal no cases in the 5.8.0 sources, because (a) I wrote a little script to check, (b) GCC would have spotted it. As Nick says, there are two possible solutions 1. Ban %_ in these functions, undo my patch, and gcc -Wall will find any transgressions. Any post-5.8.0 use of %_ in these functions would have to be reworked. 2. Allow %_ in these functions, and trawl through the #define spaghetti to ensure that these functions will always be defined (non-circularly) in terms of functions that implement %_. Robin -----Original Message...

RE: [PATCH Configure] was RE: [PATCH] was RE: Perl_die() /Perl_croak()
------_=_NextPart_001_01C708ED.431BF6FB Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable -----Original Message----- From: H.Merijn Brand [mailto:h.m.brand@xs4all.nl] Sent: 14 November 2006 19:07 To: perl5-porters@perl.org Subject: Re: [PATCH Configure] was RE: [PATCH] was RE: Perl_die() /Perl_croak() >=0D > Patch to Configure and config_h.SH to calculate PRINTF_FORMAT_NULL_OK I'll have a look > I would edit the metaconfig units but I don't know how to get them. They're on my CPAN, but I do n...

[PATCH perlio.h] (was RE: [PATCH] %_ (was Re: [PATCH] operation o n `PL_na' may be undefined))
This should fix the original problem (patch below) Robin > > I can't offer any great insight, as I did not really understand the > original problem. > > "%_" or "%"SVf should give the same behaviour, as noone (except me) does > -DCHECK_FORMAT. > The original problem might have arisen because a function had managed to > gain a FORMAT > attribute. These are added in proto.h, but only #ifdef CHECK_FORMAT. > > Perhaps I could recreate the problem with the sources, but I can't > resync through my > firewall s...

[DOC PATCH] Re: platform check (CODE PATCH : libwin32 )
------=_NextPart_000_14d5_34aa_4adb Content-Type: text/plain; format=flowed >From: Gurusamy Sarathy <gsar@ActiveState.com> >To: "Yves Orton" <demerphq@hotmail.com> >on Fri, 07 Jun 2002 12:26:57 -0700 > >Win32.pm is in libwin32 (get it from CPAN). There is a 0.19 version >coming over the weekend, but Win32.pm hasn't changed materially since >the last version. > Aha! No wonder we couldnt figure out where it came from. :-) >Patch (both doc and code) to libwin32 welcome. Attached. Jos Boumans helped me put this together ...

Re: [PATCH] Re: [PATCH] Re: Win32 modules & cygwin
From: Yitzchak Scott-Thoennes <sthoenna@efn.org> To: Cc: On Mon, Feb 26, 2007 at 01:28:51PM +0000, Steve Hay wrote: > Yitzchak Scott-Thoennes wrote: > >>On 2/23/07, Steve Hay <steve.hay@uk.radan.com> wrote: > >>>Craig Berry wrote: > >>>>Hmm. I get the following on VMS with blead@30382: > >>>> > >>>>ext/Win32API/File/t/file....................................FAILED at > >>>>test 1 > >>>>ext/Win32API/File/t/tie.....................................FAILED at > >>>...

[PATCH Configure] was RE: [PATCH] was RE: Perl_die() / Perl_croak()
------_=_NextPart_001_01C70812.AFE43257 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable -----Original Message----- From: Rafael Garcia-Suarez [mailto:rgarciasuarez@mandriva.com] Sent: 13 November 2006 11:38 To: perl5-porters@perl.org Subject: Re: [PATCH] was RE: Perl_die() / Perl_croak() Robin Barker wrote: >=0D > Attached patch restores the printf checking of croak/die, in the presence= of -DPRINTF_FORMAT_NULL_OK > PRINTF_FORMAT_NULL_OK indicates that the compiler allows for format to be= null, e.g. not...

[PATCH] RE: [PATCH] RE: maint snapshot @ 19525
------_=_NextPart_000_01C32148.E2DDE260 Content-Type: text/plain; charset="iso-8859-1" Further patch, implementing the idea in question 5 below. To be applied on top of last week's patch. Attached and appended. Robin -----Original Message----- From: Robin Barker [mailto:Robin.Barker@npl.co.uk] Sent: 16 May 2003 17:17 To: perl5-porters@perl.org Subject: [PATCH] RE: maint snapshot @ 19525 Patch for format and other warnings (using gcc-3.3 !) Appended and attached to beat the MS line wrapping. Some questions. (1) I have changed all 'format(printf)&#...

RE: [PATCH] Re: [PATCH] support POSIX SA_SIGINFO
------_=_NextPart_001_01C59137.6F325985 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable My weekly build of bleedperl failed last night: mg.c: In function `Perl_sighandler': mg.c:2715: structure has no member named `si_errno' I tracked it down to the sa_siginfo changes. Stratus VOS implements the 1996 revision of the POSIX standard. That version defines the minimum siginfo_t type to have the members si_code, si_signo, and si_value. The 2001 revision of the POSIX standard adds the si_errno, si_pid, si_uid, si_addr, ...

Re: [PATCH perldiag.pod] Re: [PATCH] Re: Useless use of constants
Benjamin Sugars <bsugars@canoe.ca> wrote > Hey, wait a minute. Didn't someone decide yesterday that perldiag.pod by > itself wasn't sufficient? Yeah, that was me. But I guess Sarathy outranks me. :-( I suspect the dichotomy is between those who "use diagnostics" and don't like their STDERR cluttered as against those who do not and are more concerned with the clutter in the rest of the pods. Mike Guy ...

RE: [PATCH] Last patch needed to get Perl5.7 to build natively on VOS
We have a bug in our native c compiler such that the search rules it uses for header files are different than the rules that GCC uses. GCC is correct, IMHO. Thus, the need to distinguish between the two compilers. PG -----Original Message----- From: Abhijit Menon-Sen [mailto:ams@wiw.org] Sent: Monday, January 07, 2002 5:49 PM To: Paul.Green@stratus.com Cc: perl5-porters@perl.org; Ted.Goodwin@stratus.com; Margaret.Fieland@stratus.com Subject: Re: [PATCH] Last patch needed to get Perl5.7 to build natively on VOS At 2002-01-07 16:59:38, Paul.Green@stratus.com wrote: > >...