From peter@rulingia.com  Tue Oct  9 06:28:37 2012
Return-Path: <peter@rulingia.com>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 53A631037
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  9 Oct 2012 06:28:19 +0000 (UTC)
	(envelope-from peter@rulingia.com)
Received: from vps.rulingia.com (host-122-100-2-194.octopus.com.au [122.100.2.194])
	by mx1.freebsd.org (Postfix) with ESMTP id B0428904C3
	for <FreeBSD-gnats-submit@freebsd.org>; Tue,  9 Oct 2012 00:29:52 +0000 (UTC)
Received: from server.rulingia.com (c220-239-248-178.belrs5.nsw.optusnet.com.au [220.239.248.178])
	by vps.rulingia.com (8.14.5/8.14.5) with ESMTP id q990Towm033612
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 9 Oct 2012 11:29:51 +1100 (EST)
	(envelope-from peter@rulingia.com)
Received: from server.rulingia.com (localhost.rulingia.com [127.0.0.1])
	by server.rulingia.com (8.14.5/8.14.5) with ESMTP id q990TiZX082860
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);
	Tue, 9 Oct 2012 11:29:44 +1100 (EST)
	(envelope-from peter@server.rulingia.com)
Received: (from peter@localhost)
	by server.rulingia.com (8.14.5/8.14.5/Submit) id q990Timr082859;
	Tue, 9 Oct 2012 11:29:44 +1100 (EST)
	(envelope-from peter)
Message-Id: <201210090029.q990Timr082859@server.rulingia.com>
Date: Tue, 9 Oct 2012 11:29:44 +1100 (EST)
From: Peter Jeremy <peter@rulingia.com>
Reply-To: Peter Jeremy <peter@rulingia.com>
To: FreeBSD-gnats-submit@freebsd.org
Subject: [patch] FICL assumes standalone environment for testmain
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         172542
>Category:       bin
>Synopsis:       [patch] FICL assumes standalone environment for testmain
>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:   Tue Oct 09 22:30:22 UTC 2012
>Closed-Date:    Thu Aug 01 18:54:08 UTC 2013
>Last-Modified:  Thu Aug 01 18:54:08 UTC 2013
>Originator:     Peter Jeremy
>Release:        FreeBSD 8.3-STABLE amd64
>Organization:
n/a
>Environment:
System: FreeBSD server.rulingia.com 8.3-STABLE FreeBSD 8.3-STABLE #18 r237444M: Sun Jul 8 10:47:08 EST 2012 root@server.rulingia.com:/var/obj/usr/src/sys/server amd64

>Description:

	When ficl is compiled as a userland program via "make
	testmain", loader.c reports a number of warnings (and -Wall
	adds more) because required header files are missing from the
	TESTMAIN case.  A number of auto variables are also declared
	incorrectly relative to '#ifdef TESTMAIN' blocks.

	
>How-To-Repeat:
	# cd /sys/boot/ficl
        # make testmain
	note warnings when compiling loader.c

>Fix:
Index: sys/boot/ficl/loader.c
===================================================================
--- sys/boot/ficl/loader.c	(revision 241347)
+++ sys/boot/ficl/loader.c	(working copy)
@@ -34,10 +34,14 @@
 
 #ifdef TESTMAIN
 #include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <time.h>
 #else
 #include <stand.h>
+#include "bootstrap.h"
 #endif
-#include "bootstrap.h"
 #include <string.h>
 #include "ficl.h"
 
@@ -135,9 +139,9 @@
 ficlGetenv(FICL_VM *pVM)
 {
 #ifndef TESTMAIN
-	char	*name;
+	char	*name, *value;
 #endif
-	char	*namep, *value;
+	char	*namep;
 	int	names;
 
 #if FICL_ROBUST > 1
@@ -243,9 +247,9 @@
 ficlFindfile(FICL_VM *pVM)
 {
 #ifndef TESTMAIN
-	char	*name;
+	char	*type, *name;
 #endif
-	char	*type, *namep, *typep;
+	char	*namep, *typep;
 	struct	preloaded_file* fp;
 	int	names, types;
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Thu Oct 18 22:58:11 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=172542 
Responsible-Changed-From-To: eadler->freebsd-bugs 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Thu Nov 8 20:54:47 UTC 2012 
Responsible-Changed-Why:  
I won't be dealing with this PR for some time, so give it back to the 
pool 

http://www.freebsd.org/cgi/query-pr.cgi?pr=172542 

From: Jan Beich <jbeich@tormail.org>
To: Peter Jeremy <peter@rulingia.com>
Cc: bug-followup@freebsd.org
Subject: Re: bin/172542: [patch] FICL assumes standalone environment for testmain
Date: Thu, 01 Aug 2013 04:43:04 +0000

 --=-=-=
 Content-Type: text/plain
 
 testmain was further broken by freaddir in r253172.
 
 
 --=-=-=
 Content-Type: text/x-patch
 Content-Disposition: attachment; filename=ficl_testmain.diff
 
 Index: sys/boot/ficl/loader.c
 ===================================================================
 --- sys/boot/ficl/loader.c	(revision 253788)
 +++ sys/boot/ficl/loader.c	(working copy)
 @@ -33,11 +33,17 @@
  *******************************************************************/
  
  #ifdef TESTMAIN
 +#include <sys/stat.h>
 +#include <dirent.h>
 +#include <fcntl.h>
 +#include <stdio.h>
  #include <stdlib.h>
 +#include <time.h>
 +#include <unistd.h>
  #else
  #include <stand.h>
 +#include "bootstrap.h"
  #endif
 -#include "bootstrap.h"
  #include <string.h>
  #include "ficl.h"
  
 @@ -135,9 +141,9 @@ void
  ficlGetenv(FICL_VM *pVM)
  {
  #ifndef TESTMAIN
 -	char	*name;
 +	char	*name, *value;
  #endif
 -	char	*namep, *value;
 +	char	*namep;
  	int	names;
  
  #if FICL_ROBUST > 1
 @@ -243,9 +249,9 @@ void
  ficlFindfile(FICL_VM *pVM)
  {
  #ifndef TESTMAIN
 -	char	*name;
 +	char	*type, *name;
  #endif
 -	char	*type, *namep, *typep;
 +	char	*namep, *typep;
  	struct	preloaded_file* fp;
  	int	names, types;
  
 @@ -511,7 +517,7 @@ static void pfread(FICL_VM *pVM)
   */
  static void pfreaddir(FICL_VM *pVM)
  {
 -    struct dirent *d;
 +    struct dirent *d = NULL;
      int fd;
  
  #if FICL_ROBUST > 1
 @@ -519,7 +525,15 @@ static void pfreaddir(FICL_VM *pVM)
  #endif
  
      fd = stackPopINT(pVM->pStack);
 +#ifdef TESTMAIN
 +    static DIR *dir;
 +    if (lseek(fd, 0, SEEK_CUR) == 0)
 +       dir = fdopendir(fd);
 +    if (dir != NULL)
 +       d = readdir(dir);
 +#else
      d = readdirfd(fd);
 +#endif
      if (d != NULL) {
          stackPushPtr(pVM->pStack, d->d_name);
          stackPushINT(pVM->pStack, strlen(d->d_name));
 
 --=-=-=--

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/172542: commit references a PR
Date: Thu,  1 Aug 2013 18:07:06 +0000 (UTC)

 Author: marcel
 Date: Thu Aug  1 18:06:58 2013
 New Revision: 253862
 URL: http://svnweb.freebsd.org/changeset/base/253862
 
 Log:
   Fix the build of the testmain target. This target compiles a Forth
   interpreter that can be run on the system and as such cannot be
   compiled against libbstand. On the one hand this means we need to
   include the usual headers for system interfaces that we use and
   on the the other hand we can only use standard system interfaces.
   
   While here, define local variables only when needed to make this
   WARNS=2 clean on amd64.
   
   PR:		172542
   Obtained from:	peterj@
   Pointed out by: Jan Beich <jbeich@tormail.org>
 
 Modified:
   head/sys/boot/ficl/loader.c
 
 Modified: head/sys/boot/ficl/loader.c
 ==============================================================================
 --- head/sys/boot/ficl/loader.c	Thu Aug  1 16:04:48 2013	(r253861)
 +++ head/sys/boot/ficl/loader.c	Thu Aug  1 18:06:58 2013	(r253862)
 @@ -33,7 +33,13 @@
  *******************************************************************/
  
  #ifdef TESTMAIN
 +#include <sys/types.h>
 +#include <sys/stat.h>
 +#include <dirent.h>
 +#include <fcntl.h>
 +#include <stdio.h>
  #include <stdlib.h>
 +#include <unistd.h>
  #else
  #include <stand.h>
  #endif
 @@ -135,9 +141,9 @@ void
  ficlGetenv(FICL_VM *pVM)
  {
  #ifndef TESTMAIN
 -	char	*name;
 +	char	*name, *value;
  #endif
 -	char	*namep, *value;
 +	char	*namep;
  	int	names;
  
  #if FICL_ROBUST > 1
 @@ -243,9 +249,9 @@ void
  ficlFindfile(FICL_VM *pVM)
  {
  #ifndef TESTMAIN
 -	char	*name;
 +	char	*name, *type;
  #endif
 -	char	*type, *namep, *typep;
 +	char	*namep, *typep;
  	struct	preloaded_file* fp;
  	int	names, types;
  
 @@ -511,6 +517,14 @@ static void pfread(FICL_VM *pVM)
   */
  static void pfreaddir(FICL_VM *pVM)
  {
 +#ifdef TESTMAIN
 +    static union { 
 +	struct dirent dirent;
 +	char buf[512];
 +    } u;
 +    off_t off;
 +    int len;
 +#endif
      struct dirent *d;
      int fd;
  
 @@ -519,7 +533,20 @@ static void pfreaddir(FICL_VM *pVM)
  #endif
  
      fd = stackPopINT(pVM->pStack);
 +#if TESTMAIN
 +    /*
 +     * The readdirfd() function is specific to the loader environment.
 +     * We do the best we can to make freaddir work, but it's not at
 +     * all guaranteed.
 +     */
 +    off = lseek(fd, 0LL, SEEK_CUR);
 +    len = getdents(fd, u.buf, sizeof(u.buf));
 +    d = (len != -1) ? &u.dirent : NULL;
 +    if (d != NULL)
 +	lseek(fd, off + d->d_reclen, SEEK_SET);
 +#else
      d = readdirfd(fd);
 +#endif
      if (d != NULL) {
          stackPushPtr(pVM->pStack, d->d_name);
          stackPushINT(pVM->pStack, strlen(d->d_name));
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: marcel 
State-Changed-When: Thu Aug 1 18:53:32 UTC 2013 
State-Changed-Why:  
make testmain builds in HEAD. 

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