From bremner-dated-1071534382.3dc708@unb.ca  Mon Dec  1 16:26:25 2003
Return-Path: <bremner-dated-1071534382.3dc708@unb.ca>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 07D9816A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  1 Dec 2003 16:26:25 -0800 (PST)
Received: from convex.cs.unb.ca (convex.cs.unb.ca [131.202.244.141])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 5F97143FAF
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  1 Dec 2003 16:26:23 -0800 (PST)
	(envelope-from bremner-dated-1071534382.3dc708@unb.ca)
Received: from bremner by convex.cs.unb.ca with local (Exim 4.24; FreeBSD 5.1)
	id 1AQyMw-000CmI-3E
	for FreeBSD-gnats-submit@freebsd.org; Mon, 01 Dec 2003 20:26:22 -0400
Received: by convex.cs.unb.ca (tmda-sendmail, from uid 1266);
	Mon, 01 Dec 2003 20:26:22 -0400 (AST)
Received: from bremner by convex.cs.unb.ca with local (Exim 4.24; FreeBSD 5.1)
	id 1AQyMv-000Cm8-Lf
	for FreeBSD-gnats-submit@freebsd.org; Mon, 01 Dec 2003 20:26:21 -0400
Message-Id: <E1AQyMv-000Cm8-Lf@convex.cs.unb.ca>
Date: Mon, 01 Dec 2003 20:26:21 -0400
From: David Bremner <bremner@unb.ca>
Sender: David Bremner <bremner@convex.cs.unb.ca>
Reply-To: David Bremner <bremner@unb.ca>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: divert cannot be renamed in FreeBSD m4
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         59883
>Category:       bin
>Synopsis:       divert cannot be renamed in FreeBSD m4
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Dec 01 16:30:21 PST 2003
>Closed-Date:    Mon Aug 23 11:27:38 GMT 2004
>Last-Modified:  Mon Aug 23 11:27:38 GMT 2004
>Originator:     David Bremner
>Release:        FreeBSD 5.1-CURRENT i386
>Organization:
University of New Brunswick
>Environment:
System: FreeBSD convex.cs.unb.ca 5.1-CURRENT FreeBSD 5.1-CURRENT #8: Thu Nov 27 12:33:51 AST 2003 bremner@convex.cs.unb.ca:/usr/obj/usr/src/sys/CONVEX2 i386


	
>Description:
	define(`foo',defn(`divert')) makes a macro called foo
	but does not seem to invoke divert when called.

	Well, I realize this is a bit of a dark corner, but from 
	documentation it seems like it should work.
	
	The test case below works (i.e. produces one blank line of
	output)	with gnu m4
	
>How-To-Repeat:

run m4 on the following three line input:

define(`foo',defn(`divert'))
foo(-1)
this output should not appear


	
>Fix:


	



>Release-Note:
>Audit-Trail:

From: Craig Boston <craig@olyun.gank.org>
To: freebsd-gnats-submit@FreeBSD.org, bremner@unb.ca
Cc:  
Subject: Re: bin/59883: divert cannot be renamed in FreeBSD m4 [with patch]
Date: Tue, 27 Apr 2004 23:50:34 -0500

 --Boundary-00=_agzjAbC17iIIQlN
 Content-Type: text/plain;
   charset="us-ascii"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline
 
 Hi,
 
 I've recently run into the same problem with our m4 -- defn() appears to not 
 work correctly with builtins, so they cannot be copied/renamed at all.
 
 The problem seems to be the result of a commit from about 2 years (!) ago.  
 Guess nobody uses BSD m4 very much :)
 
 http://www.freebsd.org/cgi/cvsweb.cgi/src/usr.bin/m4/main.c?rev=1.14&content-type=text/x-cvsweb-markup
 
 	p->defn = null;
 
 was changed to
 
 	p->defn = xstrdup(null);
 
 as part of a GCC3 const/WARNS sweep.  null is apparently a pointer to a 
 somewhat "magic" empty string.  The problem happens in dodefn() in eval.c 
 when this is checked:
 
 	if (p->defn != null) {
 		[ do stuff for macros ]
 	} else ... {
 		[ do stuff for builtins ]
 	}
 
 p->defn is no longer == to null for builtins, but rather a copy of it.  I 
 changed it to instead check p->type to see if it's a macro or not and that 
 seems to fix it.  Also checked the OpenBSD CVS and it looks like they fixed 
 the problem there with a very similar (though more extensive) approach.  A 
 quick grep/once-over of the code didn't turn up any more (ab)use of pointers 
 to "null" that would be affected by this.
 
 Patch is both inline (tabs mangled I'm sure) and attached -- I don't remember 
 if gnats accepts MIME attachments :-/
 
 --- eval.c.orig	Tue Apr 27 23:33:03 2004
 +++ eval.c	Tue Apr 27 23:33:57 2004
 @@ -617,7 +617,7 @@
  	const char *real;
  
  	if ((p = lookup(name)) != nil) {
 -		if (p->defn != null) {
 +		if ((p->type & TYPEMASK) == MACRTYPE) {
  			pbstr(rquote);
  			pbstr(p->defn);
  			pbstr(lquote);
 
 --Boundary-00=_agzjAbC17iIIQlN
 Content-Type: text/plain;
   charset="us-ascii";
   name="bsd.m4.defn.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
 	filename="bsd.m4.defn.patch"
 
 --- eval.c.orig	Tue Apr 27 23:33:03 2004
 +++ eval.c	Tue Apr 27 23:33:57 2004
 @@ -617,7 +617,7 @@
  	const char *real;
  
  	if ((p = lookup(name)) != nil) {
 -		if (p->defn != null) {
 +		if ((p->type & TYPEMASK) == MACRTYPE) {
  			pbstr(rquote);
  			pbstr(p->defn);
  			pbstr(lquote);
 
 --Boundary-00=_agzjAbC17iIIQlN--
State-Changed-From-To: open->patched 
State-Changed-By: tjr 
State-Changed-When: Mon Aug 16 14:18:47 GMT 2004 
State-Changed-Why:  
Fixed in -current; the fix will be MFC'd in 1 week. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=59883 
State-Changed-From-To: patched->closed 
State-Changed-By: tjr 
State-Changed-When: Mon Aug 23 11:27:21 GMT 2004 
State-Changed-Why:  
Fixed in -stable; thanks for the report! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=59883 
>Unformatted:
