Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Aug 2002 16:22:38 -0700 (PDT)
From:      Archie Cobbs <archie@dellroad.org>
To:        "M. Warner Losh" <imp@bsdimp.com>
Cc:        freebsd-arch@FreeBSD.ORG
Subject:   Re: NULL
Message-ID:  <200208212322.g7LNMcc08044@arch20m.dellroad.org>
In-Reply-To: <20020821.003628.52042275.imp@bsdimp.com> "from M. Warner Losh at Aug 21, 2002 00:36:28 am"

next in thread | previous in thread | raw e-mail | index | archive | help
M. Warner Losh writes:
> In message: <200208210323.g7L3NTR04362@arch20m.dellroad.org>
>             Archie Cobbs <archie@dellroad.org> writes:
> : So my vote is for NULL = "((void *)0)" when compiling C code
> : (and leaving "0" when compiling C++, which can easily be different).
> 
> That leaves just 7 files to ifdef.  Well, 9 files from the egrep:

The patch makes 'make buildworld' and 'make buildkernel KERNCONF=LINT'
work for me; fyi I have "NO_WERROR= YES" in /etc/make.conf.

Does anyone have an objection to this patch?

At the minimum, I'd like to apply the fixes for the incorrect uses
of 'NULL' where '0' is really meant.

Thanks,
-Archie

__________________________________________________________________________
Archie Cobbs     *     Packet Design     *     http://www.packetdesign.com

Index: include/dirent.h
===================================================================
RCS file: /home/cvs/freebsd/src/include/dirent.h,v
retrieving revision 1.11
diff -u -r1.11 dirent.h
--- include/dirent.h	23 Mar 2002 17:24:53 -0000	1.11
+++ include/dirent.h	21 Aug 2002 23:09:04 -0000
@@ -77,7 +77,11 @@
 #define __DTF_READALL	0x0008	/* everything has been read */
 
 #ifndef NULL
-#define	NULL	0
+#if defined(__cplusplus)
+#define NULL	0
+#else
+#define NULL	((void *)0)
+#endif
 #endif
 
 #endif /* _POSIX_SOURCE */
Index: include/locale.h
===================================================================
RCS file: /home/cvs/freebsd/src/include/locale.h,v
retrieving revision 1.6
diff -u -r1.6 locale.h
--- include/locale.h	23 Mar 2002 17:24:53 -0000	1.6
+++ include/locale.h	21 Aug 2002 23:09:04 -0000
@@ -59,7 +59,11 @@
 };
 
 #ifndef NULL
-#define	NULL	0
+#if defined(__cplusplus)
+#define NULL	0
+#else
+#define NULL	((void *)0)
+#endif
 #endif
 
 #define	LC_ALL		0
Index: include/stddef.h
===================================================================
RCS file: /home/cvs/freebsd/src/include/stddef.h,v
retrieving revision 1.7
diff -u -r1.7 stddef.h
--- include/stddef.h	9 Jul 2002 05:13:30 -0000	1.7
+++ include/stddef.h	21 Aug 2002 23:09:04 -0000
@@ -63,7 +63,11 @@
 #endif
 
 #ifndef	NULL
-#define	NULL	0
+#if defined(__cplusplus)
+#define NULL	0
+#else
+#define NULL	((void *)0)
+#endif
 #endif
 
 #define	offsetof(type, member)	__offsetof(type, member)
Index: include/stdio.h
===================================================================
RCS file: /home/cvs/freebsd/src/include/stdio.h,v
retrieving revision 1.44
diff -u -r1.44 stdio.h
--- include/stdio.h	15 Aug 2002 10:28:51 -0000	1.44
+++ include/stdio.h	21 Aug 2002 23:09:04 -0000
@@ -49,7 +49,11 @@
 #endif
 
 #ifndef NULL
-#define	NULL	0
+#if defined(__cplusplus)
+#define NULL	0
+#else
+#define NULL	((void *)0)
+#endif
 #endif
 
 typedef	_BSD_OFF_T_	fpos_t;
Index: include/stdlib.h
===================================================================
RCS file: /home/cvs/freebsd/src/include/stdlib.h,v
retrieving revision 1.38
diff -u -r1.38 stdlib.h
--- include/stdlib.h	15 Aug 2002 09:25:03 -0000	1.38
+++ include/stdlib.h	21 Aug 2002 23:09:04 -0000
@@ -81,7 +81,11 @@
 #endif
 
 #ifndef NULL
-#define	NULL	0
+#if defined(__cplusplus)
+#define NULL	0
+#else
+#define NULL	((void *)0)
+#endif
 #endif
 
 #define	EXIT_FAILURE	1
Index: include/string.h
===================================================================
RCS file: /home/cvs/freebsd/src/include/string.h,v
retrieving revision 1.14
diff -u -r1.14 string.h
--- include/string.h	15 Apr 2002 03:21:21 -0000	1.14
+++ include/string.h	21 Aug 2002 23:09:04 -0000
@@ -54,7 +54,11 @@
 #endif
 
 #ifndef	NULL
-#define	NULL	0
+#if defined(__cplusplus)
+#define NULL	0
+#else
+#define NULL	((void *)0)
+#endif
 #endif
 
 __BEGIN_DECLS
Index: include/time.h
===================================================================
RCS file: /home/cvs/freebsd/src/include/time.h,v
retrieving revision 1.27
diff -u -r1.27 time.h
--- include/time.h	14 Aug 2002 23:20:48 -0000	1.27
+++ include/time.h	21 Aug 2002 23:09:04 -0000
@@ -60,7 +60,11 @@
 #define	CLOCKS_PER_SEC	_BSD_CLOCKS_PER_SEC_
 
 #ifndef	NULL
-#define	NULL	0
+#if defined(__cplusplus)
+#define NULL	0
+#else
+#define NULL	((void *)0)
+#endif
 #endif
 
 #ifdef	_BSD_CLOCK_T_
Index: include/unistd.h
===================================================================
RCS file: /home/cvs/freebsd/src/include/unistd.h,v
retrieving revision 1.55
diff -u -r1.55 unistd.h
--- include/unistd.h	15 Jul 2002 22:21:27 -0000	1.55
+++ include/unistd.h	21 Aug 2002 23:09:13 -0000
@@ -71,7 +71,11 @@
 #define	STDERR_FILENO	2	/* standard error file descriptor */
 
 #ifndef NULL
-#define	NULL		0	/* null pointer constant */
+#if defined(__cplusplus)
+#define NULL		0		/* null pointer constant */
+#else
+#define NULL		((void *)0)	/* null pointer constant */
+#endif
 #endif
 
 #if __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
Index: include/wchar.h
===================================================================
RCS file: /home/cvs/freebsd/src/include/wchar.h,v
retrieving revision 1.15
diff -u -r1.15 wchar.h
--- include/wchar.h	20 Aug 2002 22:44:40 -0000	1.15
+++ include/wchar.h	21 Aug 2002 23:09:13 -0000
@@ -73,7 +73,11 @@
 #include <stdio.h>
 
 #ifndef NULL
+#if defined(__cplusplus)
 #define NULL	0
+#else
+#define NULL	((void *)0)
+#endif
 #endif
 
 #ifdef	_BSD_MBSTATE_T_
Index: include/rpc/types.h
===================================================================
RCS file: /home/cvs/freebsd/src/include/rpc/types.h,v
retrieving revision 1.10
diff -u -r1.10 types.h
--- include/rpc/types.h	19 Mar 2001 12:49:47 -0000	1.10
+++ include/rpc/types.h	21 Aug 2002 23:09:13 -0000
@@ -60,7 +60,11 @@
 #	define TRUE	(1)
 #endif
 #ifndef NULL
-#	define NULL	0
+#if defined(__cplusplus)
+#define NULL		0
+#else
+#define NULL		((void *)0)
+#endif
 #endif
 
 #define mem_alloc(bsize)	calloc(1, bsize)
Index: lib/libstand/stand.h
===================================================================
RCS file: /home/cvs/freebsd/src/lib/libstand/stand.h,v
retrieving revision 1.35
diff -u -r1.35 stand.h
--- lib/libstand/stand.h	21 Aug 2002 09:30:45 -0000	1.35
+++ lib/libstand/stand.h	21 Aug 2002 23:09:27 -0000
@@ -72,7 +72,11 @@
 #define PCHK(fmt, args...)	{printf("%s(%d): " fmt "\n", __FUNCTION__, __LINE__ , ##args); getchar();}
 
 #ifndef NULL
-#define	NULL	0
+#if defined(__cplusplus)
+#define NULL	0
+#else
+#define NULL	((void *)0)
+#endif
 #endif
 
 /* Avoid unwanted userlandish components */
Index: sbin/restore/restore.c
===================================================================
RCS file: /home/cvs/freebsd/src/sbin/restore/restore.c,v
retrieving revision 1.12
diff -u -r1.12 restore.c
--- sbin/restore/restore.c	21 Jun 2002 06:18:00 -0000	1.12
+++ sbin/restore/restore.c	21 Aug 2002 23:09:51 -0000
@@ -458,7 +458,7 @@
 	 * for it, we discard the name knowing that it will be on the
 	 * next incremental tape.
 	 */
-	case NULL:
+	case 0:
 		fprintf(stderr, "%s: (inode %d) not found on tape\n",
 			name, ino);
 		break;
Index: sys/dev/syscons/scvtb.c
===================================================================
RCS file: /home/cvs/freebsd/src/sys/dev/syscons/scvtb.c,v
retrieving revision 1.8
diff -u -r1.8 scvtb.c
--- sys/dev/syscons/scvtb.c	29 Jun 2001 08:24:56 -0000	1.8
+++ sys/dev/syscons/scvtb.c	21 Aug 2002 23:10:23 -0000
@@ -51,7 +51,7 @@
 	vtb->vtb_cols = cols;
 	vtb->vtb_rows = rows;
 	vtb->vtb_size = cols*rows;
-	vtb->vtb_buffer = NULL;
+	vtb->vtb_buffer = 0;
 	vtb->vtb_tail = 0;
 
 	switch (type) {
@@ -62,7 +62,7 @@
 				(vm_offset_t)malloc(cols*rows*sizeof(u_int16_t),
 						    M_DEVBUF, 
 						    (wait) ? M_WAITOK : M_NOWAIT);
-			if (vtb->vtb_buffer != NULL) {
+			if (vtb->vtb_buffer != 0) {
 				bzero((void *)sc_vtb_pointer(vtb, 0),
 				      cols*rows*sizeof(u_int16_t));
 				vtb->vtb_flags |= VTB_ALLOCED;
@@ -92,11 +92,11 @@
 	vtb->vtb_tail = 0;
 
 	p = vtb->vtb_buffer;
-	vtb->vtb_buffer = NULL;
+	vtb->vtb_buffer = 0;
 	switch (vtb->vtb_type) {
 	case VTB_MEMORY:
 	case VTB_RINGBUFFER:
-		if ((vtb->vtb_flags & VTB_ALLOCED) && (p != NULL))
+		if ((vtb->vtb_flags & VTB_ALLOCED) && (p != 0))
 			free((void *)p, M_DEVBUF);
 		break;
 	default:
Index: sys/dev/syscons/syscons.c
===================================================================
RCS file: /home/cvs/freebsd/src/sys/dev/syscons/syscons.c,v
retrieving revision 1.387
diff -u -r1.387 syscons.c
--- sys/dev/syscons/syscons.c	19 Aug 2002 16:32:09 -0000	1.387
+++ sys/dev/syscons/syscons.c	21 Aug 2002 23:10:31 -0000
@@ -867,7 +867,7 @@
 	    hstp = scp->history->vtb_buffer + sc_vtb_tail(scp->history) *
 		sizeof(u_int16_t) + ptr->x * sizeof(u_int16_t);
 	else
-	    hstp = NULL;
+	    hstp = 0;
 
 	retval = 0;
 	for (lnum = 0; lnum < (ptr->y + ptr->ysize); lnum++) {
Index: sys/i386/i386/busdma_machdep.c
===================================================================
RCS file: /home/cvs/freebsd/src/sys/i386/i386/busdma_machdep.c,v
retrieving revision 1.26
diff -u -r1.26 busdma_machdep.c
--- sys/i386/i386/busdma_machdep.c	19 Apr 2002 22:58:09 -0000	1.26
+++ sys/i386/i386/busdma_machdep.c	21 Aug 2002 23:10:31 -0000
@@ -571,7 +571,7 @@
 							 dmat->lowaddr,
 							 PAGE_SIZE,
 							 0);
-		if (bpage->vaddr == NULL) {
+		if (bpage->vaddr == 0) {
 			free(bpage, M_DEVBUF);
 			break;
 		}
Index: sys/i386/i386/dump_machdep.c
===================================================================
RCS file: /home/cvs/freebsd/src/sys/i386/i386/dump_machdep.c,v
retrieving revision 1.3
diff -u -r1.3 dump_machdep.c
--- sys/i386/i386/dump_machdep.c	4 May 2002 17:45:48 -0000	1.3
+++ sys/i386/i386/dump_machdep.c	21 Aug 2002 23:10:31 -0000
@@ -77,7 +77,7 @@
 
 	dumplo = di->mediaoffset + di->mediasize - Maxmem * (off_t)PAGE_SIZE;
 	dumplo -= sizeof kdh * 2;
-	i = di->dumper(di->priv, &kdh, NULL, dumplo, sizeof kdh);
+	i = di->dumper(di->priv, &kdh, 0, dumplo, sizeof kdh);
 	if (i)
 		printf("\nDump failed writing header (%d)\n", i);
 	dumplo += sizeof kdh;
@@ -100,7 +100,7 @@
 			printf(" %d", count / (1024 * 1024 / PAGE_SIZE));
 			mb = i;
 		}
-		i = di->dumper(di->priv, va, NULL, dumplo, left * PAGE_SIZE);
+		i = di->dumper(di->priv, va, 0, dumplo, left * PAGE_SIZE);
 		if (i)
 			break;
 		count += left;
@@ -114,10 +114,10 @@
 	}
 	if (i) 
 		printf("\nDump failed writing data (%d)\n", i);
-	i = di->dumper(di->priv, &kdh, NULL, dumplo, sizeof kdh);
+	i = di->dumper(di->priv, &kdh, 0, dumplo, sizeof kdh);
 	if (i)
 		printf("\nDump failed writing trailer (%d)\n", i);
-	di->dumper(di->priv, NULL, NULL, 0, 0);  /* tell them we are done */
+	di->dumper(di->priv, NULL, 0, 0, 0);  /* tell them we are done */
 	printf("\nDump complete\n");
 	return;
 }
Index: sys/i386/i386/pmap.c
===================================================================
RCS file: /home/cvs/freebsd/src/sys/i386/i386/pmap.c,v
retrieving revision 1.362
diff -u -r1.362 pmap.c
--- sys/i386/i386/pmap.c	18 Aug 2002 02:13:50 -0000	1.362
+++ sys/i386/i386/pmap.c	21 Aug 2002 23:10:35 -0000
@@ -2508,7 +2508,7 @@
 		if (addr < starta || addr >= entry->end)
 			continue;
 
-		if ((*pmap_pde(pmap, addr)) == NULL) 
+		if ((*pmap_pde(pmap, addr)) == 0) 
 			continue;
 
 		pte = vtopte(addr);
Index: sys/kern/subr_disk.c
===================================================================
RCS file: /home/cvs/freebsd/src/sys/kern/subr_disk.c,v
retrieving revision 1.55
diff -u -r1.55 subr_disk.c
--- sys/kern/subr_disk.c	9 Apr 2002 15:43:22 -0000	1.55
+++ sys/kern/subr_disk.c	21 Aug 2002 23:10:35 -0000
@@ -271,7 +271,7 @@
 	return error;
 }
  
-SYSCTL_PROC(_kern, OID_AUTO, disks, CTLTYPE_STRING | CTLFLAG_RD, 0, NULL, 
+SYSCTL_PROC(_kern, OID_AUTO, disks, CTLTYPE_STRING | CTLFLAG_RD, 0, 0, 
     sysctl_disks, "A", "names of available disks");
 
 /*
Index: sys/kern/sys_pipe.c
===================================================================
RCS file: /home/cvs/freebsd/src/sys/kern/sys_pipe.c,v
retrieving revision 1.117
diff -u -r1.117 sys_pipe.c
--- sys/kern/sys_pipe.c	19 Aug 2002 16:59:36 -0000	1.117
+++ sys/kern/sys_pipe.c	21 Aug 2002 23:10:43 -0000
@@ -360,7 +360,7 @@
 	/* so pipespace()->pipe_free_kmem() doesn't follow junk pointer */
 	cpipe->pipe_buffer.object = NULL;
 #ifndef PIPE_NODIRECT
-	cpipe->pipe_map.kva = NULL;
+	cpipe->pipe_map.kva = 0;
 #endif
 	/*
 	 * protect so pipeclose() doesn't follow a junk pointer
@@ -1344,7 +1344,7 @@
 		cpipe->pipe_buffer.buffer = NULL;
 	}
 #ifndef PIPE_NODIRECT
-	if (cpipe->pipe_map.kva != NULL) {
+	if (cpipe->pipe_map.kva != 0) {
 		amountpipekva -= cpipe->pipe_buffer.size + PAGE_SIZE;
 		kmem_free(kernel_map,
 			cpipe->pipe_map.kva,
Index: sys/sys/param.h
===================================================================
RCS file: /home/cvs/freebsd/src/sys/sys/param.h,v
retrieving revision 1.132
diff -u -r1.132 param.h
--- sys/sys/param.h	24 Jul 2002 03:02:42 -0000	1.132
+++ sys/sys/param.h	21 Aug 2002 23:11:02 -0000
@@ -58,7 +58,11 @@
 #define __FreeBSD_version 500038	/* Master, propagated to newvers */
 
 #ifndef NULL
-#define	NULL	0
+#if defined(__cplusplus)
+#define NULL	0
+#else
+#define NULL	((void *)0)
+#endif
 #endif
 
 #ifndef LOCORE
Index: sys/vm/uma_core.c
===================================================================
RCS file: /home/cvs/freebsd/src/sys/vm/uma_core.c,v
retrieving revision 1.34
diff -u -r1.34 uma_core.c
--- sys/vm/uma_core.c	5 Jul 2002 21:39:52 -0000	1.34
+++ sys/vm/uma_core.c	21 Aug 2002 23:11:10 -0000
@@ -835,7 +835,7 @@
 	vm_page_t p;
 	int pages;
 
-	retkva = NULL;
+	retkva = 0;
 	pages = zone->uz_pages;
 
 	/* 
@@ -848,7 +848,7 @@
 			return (NULL);
 
 		zkva = zone->uz_kva + pages * PAGE_SIZE;
-		if (retkva == NULL)
+		if (retkva == 0)
 			retkva = zkva;
 		pmap_qenter(zkva, &p, 1);
 		bytes -= PAGE_SIZE;

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200208212322.g7LNMcc08044>