Date: Sun, 30 Nov 2003 16:06:59 -0800 From: Marcel Moolenaar <marcel@xcllnt.net> To: standards@FreeBSD.org Subject: 64-bit NULL: please review patch Message-ID: <20031201000659.GA48096@dhcp01.pn.xcllnt.net>
next in thread | raw e-mail | index | archive | help
--envbJBWh7q8WU6mo Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Ok, Attached a patch to help us out in the various ways we may want or need to define NULL. First and foremost, it centralizes the definition so that we don't have to modify a dozen headers to make a change. Secondly, it defines NULL as 0L on ia64 when compiling for the LP64 runtime. When adding -milp32 to gcc (not yet supported), __LP64__ is not defined and NULL will be defined as 0. This is the correct behaviour. With the definition of NULL in a seperate header we can also utilize compiler built-in definitions for NULL is such exist or define NULL specially for lint or other conditions. Please review, -- Marcel Moolenaar USPA: A-39004 marcel@xcllnt.net --envbJBWh7q8WU6mo Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ia64.diff" Index: include/dirent.h =========================================================================== --- include/dirent.h 2003/11/30 14:58:52 #4 +++ include/dirent.h 2003/11/30 14:58:52 @@ -54,6 +54,8 @@ #if __BSD_VISIBLE +#include <sys/_null.h> + /* definitions for library routines operating on directories. */ #define DIRBLKSIZ 1024 @@ -81,10 +83,6 @@ #define DTF_REWIND 0x0004 /* rewind after reading union stack */ #define __DTF_READALL 0x0008 /* everything has been read */ -#ifndef NULL -#define NULL 0 -#endif - #else /* !__BSD_VISIBLE */ typedef void * DIR; Index: include/locale.h =========================================================================== --- include/locale.h 2003/11/30 14:58:52 #3 +++ include/locale.h 2003/11/30 14:58:52 @@ -37,6 +37,8 @@ #ifndef _LOCALE_H_ #define _LOCALE_H_ +#include <sys/_null.h> + struct lconv { char *decimal_point; char *thousands_sep; @@ -64,10 +66,6 @@ char int_n_sign_posn; }; -#ifndef NULL -#define NULL 0 -#endif - #define LC_ALL 0 #define LC_COLLATE 1 #define LC_CTYPE 2 Index: include/rpc/types.h =========================================================================== --- include/rpc/types.h 2003/11/30 14:58:52 #1 +++ include/rpc/types.h 2003/11/30 14:58:52 @@ -40,6 +40,7 @@ #define _RPC_TYPES_H #include <sys/types.h> +#include <sys/_null.h> typedef int32_t bool_t; typedef int32_t enum_t; @@ -59,9 +60,6 @@ #ifndef TRUE # define TRUE (1) #endif -#ifndef NULL -# define NULL 0 -#endif #define mem_alloc(bsize) calloc(1, bsize) #define mem_free(ptr, bsize) free(ptr) Index: include/stddef.h =========================================================================== --- include/stddef.h 2003/11/30 14:58:52 #5 +++ include/stddef.h 2003/11/30 14:58:52 @@ -39,6 +39,7 @@ #define _STDDEF_H_ #include <sys/cdefs.h> +#include <sys/_null.h> #include <sys/_types.h> typedef __ptrdiff_t ptrdiff_t; @@ -62,10 +63,6 @@ #endif #endif -#ifndef NULL -#define NULL 0 -#endif - #define offsetof(type, member) __offsetof(type, member) #endif /* _STDDEF_H_ */ Index: include/stdio.h =========================================================================== --- include/stdio.h 2003/11/30 14:58:52 #17 +++ include/stdio.h 2003/11/30 14:58:52 @@ -41,6 +41,7 @@ #define _STDIO_H_ #include <sys/cdefs.h> +#include <sys/_null.h> #include <sys/_types.h> typedef __off_t fpos_t; @@ -57,10 +58,6 @@ #endif #endif -#ifndef NULL -#define NULL 0 -#endif - #define _FSTDIO /* Define for new stdio with functions. */ /* Index: include/stdlib.h =========================================================================== --- include/stdlib.h 2003/11/30 14:58:52 #32 +++ include/stdlib.h 2003/11/30 14:58:52 @@ -38,6 +38,7 @@ #define _STDLIB_H_ #include <sys/cdefs.h> +#include <sys/_null.h> #include <sys/_types.h> #if __BSD_VISIBLE @@ -69,10 +70,6 @@ long rem; } ldiv_t; -#ifndef NULL -#define NULL 0 -#endif - #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 Index: include/string.h =========================================================================== --- include/string.h 2003/11/30 14:58:52 #13 +++ include/string.h 2003/11/30 14:58:52 @@ -38,6 +38,7 @@ #define _STRING_H_ #include <sys/cdefs.h> +#include <sys/_null.h> #include <sys/_types.h> /* @@ -53,10 +54,6 @@ #define _SIZE_T_DECLARED #endif -#ifndef NULL -#define NULL 0 -#endif - __BEGIN_DECLS #if __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE void *memccpy(void * __restrict, const void * __restrict, int, size_t); Index: include/time.h =========================================================================== --- include/time.h 2003/11/30 14:58:52 #14 +++ include/time.h 2003/11/30 14:58:52 @@ -46,6 +46,7 @@ #define _TIME_H_ #include <sys/cdefs.h> +#include <sys/_null.h> #include <sys/_types.h> #if __POSIX_VISIBLE > 0 && __POSIX_VISIBLE < 200112 || __BSD_VISIBLE @@ -59,10 +60,6 @@ /* Frequency of the clock ticks reported by clock(). */ #define CLOCKS_PER_SEC 128 -#ifndef NULL -#define NULL 0 -#endif - #ifndef _CLOCK_T_DECLARED typedef __clock_t clock_t; #define _CLOCK_T_DECLARED Index: include/unistd.h =========================================================================== --- include/unistd.h 2003/11/30 14:58:52 #28 +++ include/unistd.h 2003/11/30 14:58:52 @@ -40,6 +40,7 @@ #include <sys/cdefs.h> #include <sys/types.h> /* XXX adds too much pollution. */ #include <sys/unistd.h> +#include <sys/_null.h> #include <sys/_types.h> #ifndef _GID_T_DECLARED @@ -81,10 +82,6 @@ #define STDOUT_FILENO 1 /* standard output file descriptor */ #define STDERR_FILENO 2 /* standard error file descriptor */ -#ifndef NULL -#define NULL 0 /* null pointer constant */ -#endif - #if __XSI_VISIBLE || __POSIX_VISIBLE >= 200112 #define F_ULOCK 0 /* unlock locked section */ #define F_LOCK 1 /* lock a section for exclusive use */ Index: include/wchar.h =========================================================================== --- include/wchar.h 2003/11/30 14:58:52 #32 +++ include/wchar.h 2003/11/30 14:58:52 @@ -68,13 +68,10 @@ #define _WCHAR_H_ #include <sys/cdefs.h> +#include <sys/_null.h> #include <sys/_types.h> #include <machine/_limits.h> -#ifndef NULL -#define NULL 0 -#endif - #ifndef _MBSTATE_T_DECLARED typedef __mbstate_t mbstate_t; #define _MBSTATE_T_DECLARED Index: sys/sys/_null.h =========================================================================== *** /dev/null Sun Nov 30 14:55:39 2003 --- sys/sys/_null.h Sun Nov 30 14:59:01 2003 *************** *** 0 **** --- 1,37 ---- + /* + * Copyright (c) 2003 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + + #ifndef NULL + + #ifdef __LP64__ + #define NULL 0L + #else + #define NULL 0 + #endif + + #endif Index: sys/sys/param.h =========================================================================== --- sys/sys/param.h 2003/11/30 14:58:52 #78 +++ sys/sys/param.h 2003/11/30 14:58:52 @@ -42,6 +42,8 @@ #ifndef _SYS_PARAM_H_ #define _SYS_PARAM_H_ +#include <sys/_null.h> + #define BSD 199506 /* System version (year & month). */ #define BSD4_3 1 #define BSD4_4 1 @@ -59,10 +61,6 @@ #undef __FreeBSD_version #define __FreeBSD_version 501114 /* Master, propagated to newvers */ -#ifndef NULL -#define NULL 0 -#endif - #ifndef LOCORE #include <sys/types.h> #endif Index: sys/sys/stddef.h =========================================================================== --- sys/sys/stddef.h 2003/11/30 14:58:52 #1 +++ sys/sys/stddef.h 2003/11/30 14:58:52 @@ -30,14 +30,11 @@ #define _SYS_STDDEF_H_ #include <sys/cdefs.h> +#include <sys/_null.h> #include <machine/_types.h> typedef __ptrdiff_t ptrdiff_t; #define offsetof(type, field) __offsetof(type, field) -#ifndef NULL -#define NULL 0 -#endif - #endif /* !_SYS_STDDEF_H_ */ --envbJBWh7q8WU6mo--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20031201000659.GA48096>