- Removing some unneeded definitions of NULL(cruft related to 1970's C).

In C90, NULL is guaranteed to be declared in <stddef.h> and also in
  <string.h>.  Though the correct way to define NULL in FreeBSD is to
  include <sys/_null.h>, other parts of libstand still require <string.h>
  to build; therefore, we keep <string.h> in stand.h and add a note about
  this;
- Removing no longer used 'Prototype' definition.  Quote from bde@:

	'Cruft related to getting incomplete struct declarations within
	prototypes forward-declared before the structs.  It doesn't mean
	"prototype" but only part of a prototype-related hack.  No longer
	used.'

- Replacing iaddr_t with uintptr_t;
- Removing use of long double to determine alignment.  Use a fixed 16 byte
  alignment instead;

Reviewed by:	bde
Obtained from:	DragonFlyBSD (partially)
MFC after:	1 month
This commit is contained in:
Tai-hwa Liang 2011-07-10 07:25:34 +00:00
parent 5f099d0a7d
commit f497fbf5e4
6 changed files with 15 additions and 29 deletions

@ -65,15 +65,13 @@
#include <sys/cdefs.h>
#include <sys/stat.h>
#include <sys/dirent.h>
/* this header intentionally exports NULL from <string.h> */
#include <string.h>
#define CHK(fmt, args...) printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args)
#define PCHK(fmt, args...) {printf("%s(%d): " fmt "\n", __func__, __LINE__ , ##args); getchar();}
#ifndef NULL
#define NULL 0
#endif
/* Avoid unwanted userlandish components */
#define _KERNEL
#include <sys/errno.h>

@ -77,7 +77,7 @@ __FBSDID("$FreeBSD$");
*/
void *
znalloc(MemPool *mp, iaddr_t bytes)
znalloc(MemPool *mp, uintptr_t bytes)
{
/*
* align according to pool object size (can be 0). This is
@ -136,7 +136,7 @@ znalloc(MemPool *mp, iaddr_t bytes)
*/
void
zfree(MemPool *mp, void *ptr, iaddr_t bytes)
zfree(MemPool *mp, void *ptr, uintptr_t bytes)
{
/*
* align according to pool object size (can be 0). This is
@ -153,7 +153,7 @@ zfree(MemPool *mp, void *ptr, iaddr_t bytes)
if ((char *)ptr < (char *)mp->mp_Base ||
(char *)ptr + bytes > (char *)mp->mp_End ||
((iaddr_t)ptr & MEMNODE_SIZE_MASK) != 0)
((uintptr_t)ptr & MEMNODE_SIZE_MASK) != 0)
panic("zfree(%p,%ju): wild pointer", ptr, (uintmax_t)bytes);
/*
@ -245,7 +245,7 @@ zfree(MemPool *mp, void *ptr, iaddr_t bytes)
*/
void
zextendPool(MemPool *mp, void *base, iaddr_t bytes)
zextendPool(MemPool *mp, void *base, uintptr_t bytes)
{
if (mp->mp_Size == 0) {
mp->mp_Base = base;

@ -39,20 +39,11 @@
#define ZALLOCDEBUG
#include <sys/stdint.h>
#include <string.h>
#include "stand.h"
typedef uintptr_t iaddr_t; /* unsigned int same size as pointer */
typedef intptr_t saddr_t; /* signed int same size as pointer */
#include "zalloc_mem.h"
#define Prototype extern
#define Library extern
#ifndef NULL
#define NULL ((void *)0)
#endif
/*
* block extension for sbrk()
*/
@ -61,8 +52,7 @@ typedef intptr_t saddr_t; /* signed int same size as pointer */
#define BLKEXTENDMASK (BLKEXTEND - 1)
/*
* required malloc alignment. Use sizeof(long double) for architecture
* independance.
* required malloc alignment. Just hardwire to 16.
*
* Note: if we implement a more sophisticated realloc, we should ensure that
* MALLOCALIGN is at least as large as MemNode.
@ -73,10 +63,8 @@ typedef struct Guard {
size_t ga_Magic; /* must be at least 32 bits */
} Guard;
#define MATYPE long double
#define MALLOCALIGN ((sizeof(MATYPE) > sizeof(Guard)) ? sizeof(MATYPE) : sizeof(Guard))
#define MALLOCALIGN 16
#define GAMAGIC 0x55FF44FD
#define GAFREE 0x5F54F4DF
#include "zalloc_protos.h"

@ -126,7 +126,7 @@ Free(void *ptr, const char *file, int line)
void *
Calloc(size_t n1, size_t n2, const char *file, int line)
{
iaddr_t bytes = (iaddr_t)n1 * (iaddr_t)n2;
uintptr_t bytes = (uintptr_t)n1 * (uintptr_t)n2;
void *res;
if ((res = Malloc(bytes, file, line)) != NULL) {

@ -37,15 +37,15 @@
typedef struct MemNode {
struct MemNode *mr_Next;
iaddr_t mr_Bytes;
uintptr_t mr_Bytes;
} MemNode;
typedef struct MemPool {
void *mp_Base;
void *mp_End;
MemNode *mp_First;
iaddr_t mp_Size;
iaddr_t mp_Used;
uintptr_t mp_Size;
uintptr_t mp_Used;
} MemPool;
#define MEMNODE_SIZE_MASK ((sizeof(MemNode) <= 8) ? 7 : 15)

@ -29,7 +29,7 @@
* $FreeBSD$
*/
Library void *znalloc(struct MemPool *mpool, iaddr_t bytes);
Library void zfree(struct MemPool *mpool, void *ptr, iaddr_t bytes);
Library void zextendPool(MemPool *mp, void *base, iaddr_t bytes);
Library void *znalloc(struct MemPool *mpool, uintptr_t bytes);
Library void zfree(struct MemPool *mpool, void *ptr, uintptr_t bytes);
Library void zextendPool(MemPool *mp, void *base, uintptr_t bytes);
Library void zallocstats(struct MemPool *mp);