Alien-Judy
view release on metacpan or search on metacpan
src/judy-1.0.5/test/malloc-pre2.8a.c view on Meta::CPAN
/*
WIN32 sets up defaults for MS environment and compilers.
Otherwise defaults are for unix.
*/
/* #define WIN32 */
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
/* No-op failure action */
#define MALLOC_FAILURE_ACTION
/* Win32 doesn't supply or need the following headers */
#define LACKS_UNISTD_H
#define LACKS_SYS_PARAM_H
#define LACKS_SYS_MMAN_H
/* Use the supplied emulation of sbrk */
#define MORECORE sbrk
#define MORECORE_CONTIGUOUS 1
#define MORECORE_FAILURE ((void*)(-1))
/* Use the supplied emulation of mmap and munmap */
#define HAVE_MMAP 1
#define MUNMAP_FAILURE (-1)
#define MMAP_CLEARS 1
/* These values don't really matter in windows mmap emulation */
#define MAP_PRIVATE 1
#define MAP_ANONYMOUS 2
#define PROT_READ 1
#define PROT_WRITE 2
/* Emulation functions defined at the end of this file */
/* If USE_MALLOC_LOCK, use supplied critical-section-based lock functions */
#ifdef USE_MALLOC_LOCK
static int slwait(int *sl);
static int slrelease(int *sl);
#endif
static long getpagesize(void);
static long getregionsize(void);
static void *sbrk(long size);
static void *mmap(void *ptr, long size, long prot, long type, long handle, long arg);
static long munmap(void *ptr, long size);
static void vminfo (unsigned long*free, unsigned long*reserved, unsigned long*committed);
static int cpuinfo (int whole, unsigned long*kernel, unsigned long*user);
#endif
#include <strings.h>
/*
Void_t* is the pointer type that malloc should say it returns
*/
#ifndef Void_t
#define Void_t void
#endif /*Void_t*/
#include <stddef.h> /* for size_t */
#ifdef __cplusplus
extern "C" {
#endif
/* define LACKS_UNISTD_H if your system does not have a <unistd.h>. */
/* #define LACKS_UNISTD_H */
#ifndef LACKS_UNISTD_H
#include <unistd.h>
#endif
/* define LACKS_SYS_PARAM_H if your system does not have a <sys/param.h>. */
/* #define LACKS_SYS_PARAM_H */
#include <stdio.h> /* needed for malloc_stats */
#include <errno.h> /* needed for optional MALLOC_FAILURE_ACTION */
/*
Debugging:
Because freed chunks may be overwritten with bookkeeping fields, this
malloc will often die when freed memory is overwritten by user
programs. This can be very effective (albeit in an annoying way)
in helping track down dangling pointers.
If you compile with -DDEBUG, a number of assertion checks are
enabled that will catch more memory errors. You probably won't be
able to make much sense of the actual assertion errors, but they
should help you locate incorrectly overwritten memory. The
checking is fairly extensive, and will slow down execution
noticeably. Calling malloc_stats or mallinfo with DEBUG set will
attempt to check every non-mmapped allocated and free chunk in the
course of computing the summmaries. (By nature, mmapped regions
cannot be checked very much automatically.)
Setting DEBUG may also be helpful if you are trying to modify
this code. The assertions in the check routines spell out in more
detail the assumptions and invariants underlying the algorithms.
Setting DEBUG does NOT provide an automated mechanism for checking
that all accesses to malloced memory stay within their
bounds. However, there are several add-ons and adaptations of this
or other mallocs available that do this.
*/
#if DEBUG
#include <assert.h>
/* #define assert(x) if(!(x)) abort() */
( run in 0.768 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )