Add msvcrt/malloc.h (for the MFC).

Add msvcrt/search.h.
Move duplicated definitions to the new headers.
Use malloc.h instead of stdlib.h when sensible.
This commit is contained in:
Francois Gouget 2001-04-23 18:20:55 +00:00 committed by Alexandre Julliard
parent 131961d4ab
commit b29120d2c4
8 changed files with 145 additions and 65 deletions

View File

@ -10,8 +10,8 @@
#include "wincon.h"
#include "msvcrt/conio.h"
#include "msvcrt/malloc.h"
#include "msvcrt/stdio.h"
#include "msvcrt/stdlib.h"
DEFAULT_DEBUG_CHANNEL(msvcrt);

View File

@ -3,9 +3,9 @@
*
* Copyright 2000 Jon Griffiths
*/
#include "msvcrt.h"
#include "msvcrt/stdlib.h"
#include "msvcrt.h"
#include "msvcrt/malloc.h"
DEFAULT_DEBUG_CHANNEL(msvcrt);

View File

@ -9,7 +9,7 @@
#include "msvcrt.h"
#include "msvcrt/stdlib.h"
#include "msvcrt/malloc.h"
DEFAULT_DEBUG_CHANNEL(msvcrt);
@ -19,28 +19,12 @@ extern CRITICAL_SECTION MSVCRT_heap_cs;
#define LOCK_HEAP EnterCriticalSection(&MSVCRT_heap_cs)
#define UNLOCK_HEAP LeaveCriticalSection(&MSVCRT_heap_cs)
/* heap function constants */
#define MSVCRT_HEAPEMPTY -1
#define MSVCRT_HEAPOK -2
#define MSVCRT_HEAPBADBEGIN -3
#define MSVCRT_HEAPBADNODE -4
#define MSVCRT_HEAPEND -5
#define MSVCRT_HEAPBADPTR -6
#define MSVCRT_FREEENTRY 0
#define MSVCRT_USEDENTRY 1
typedef struct MSVCRT_heapinfo
{
int * _pentry;
size_t _size;
int _useflag;
} MSVCRT_HEAPINFO;
typedef void (*MSVCRT_new_handler_func)(void);
static MSVCRT_new_handler_func MSVCRT_new_handler;
static int MSVCRT_new_mode;
/*********************************************************************
* operator_new (MSVCRT.@)
*/
@ -111,7 +95,7 @@ int MSVCRT__set_new_mode(int mode)
/*********************************************************************
* _expand (MSVCRT.@)
*/
void* _expand(void* mem, unsigned int size)
void* _expand(void* mem, MSVCRT_size_t size)
{
return HeapReAlloc(GetProcessHeap(), HEAP_REALLOC_IN_PLACE_ONLY, mem, size);
}
@ -124,9 +108,9 @@ int _heapchk(void)
if (!HeapValidate( GetProcessHeap(), 0, NULL))
{
MSVCRT__set_errno(GetLastError());
return MSVCRT_HEAPBADNODE;
return _HEAPBADNODE;
}
return MSVCRT_HEAPOK;
return _HEAPOK;
}
/*********************************************************************
@ -146,21 +130,21 @@ int _heapmin(void)
/*********************************************************************
* _heapwalk (MSVCRT.@)
*/
int _heapwalk(MSVCRT_HEAPINFO* next)
int _heapwalk(_HEAPINFO* next)
{
PROCESS_HEAP_ENTRY phe;
LOCK_HEAP;
phe.lpData = next->_pentry;
phe.cbData = next->_size;
phe.wFlags = next->_useflag == MSVCRT_USEDENTRY ? PROCESS_HEAP_ENTRY_BUSY : 0;
phe.wFlags = next->_useflag == _USEDENTRY ? PROCESS_HEAP_ENTRY_BUSY : 0;
if (phe.lpData && phe.wFlags & PROCESS_HEAP_ENTRY_BUSY &&
!HeapValidate( GetProcessHeap(), 0, phe.lpData ))
{
UNLOCK_HEAP;
MSVCRT__set_errno(GetLastError());
return MSVCRT_HEAPBADNODE;
return _HEAPBADNODE;
}
do
@ -169,19 +153,19 @@ int _heapwalk(MSVCRT_HEAPINFO* next)
{
UNLOCK_HEAP;
if (GetLastError() == ERROR_NO_MORE_ITEMS)
return MSVCRT_HEAPEND;
return _HEAPEND;
MSVCRT__set_errno(GetLastError());
if (!phe.lpData)
return MSVCRT_HEAPBADBEGIN;
return MSVCRT_HEAPBADNODE;
return _HEAPBADBEGIN;
return _HEAPBADNODE;
}
} while (phe.wFlags & (PROCESS_HEAP_REGION|PROCESS_HEAP_UNCOMMITTED_RANGE));
UNLOCK_HEAP;
next->_pentry = phe.lpData;
next->_size = phe.cbData;
next->_useflag = phe.wFlags & PROCESS_HEAP_ENTRY_BUSY ? MSVCRT_USEDENTRY : MSVCRT_FREEENTRY;
return MSVCRT_HEAPOK;
next->_useflag = phe.wFlags & PROCESS_HEAP_ENTRY_BUSY ? _USEDENTRY : _FREEENTRY;
return _HEAPOK;
}
/*********************************************************************
@ -190,23 +174,23 @@ int _heapwalk(MSVCRT_HEAPINFO* next)
int _heapset(unsigned int value)
{
int retval;
MSVCRT_HEAPINFO heap;
_HEAPINFO heap;
memset( &heap, 0, sizeof(MSVCRT_HEAPINFO) );
memset( &heap, 0, sizeof(_HEAPINFO) );
LOCK_HEAP;
while ((retval = _heapwalk(&heap)) == MSVCRT_HEAPOK)
while ((retval = _heapwalk(&heap)) == _HEAPOK)
{
if (heap._useflag == MSVCRT_FREEENTRY)
if (heap._useflag == _FREEENTRY)
memset(heap._pentry, value, heap._size);
}
UNLOCK_HEAP;
return retval == MSVCRT_HEAPEND? MSVCRT_HEAPOK : retval;
return retval == _HEAPEND? _HEAPOK : retval;
}
/*********************************************************************
* _msize (MSVCRT.@)
*/
long _msize(void* mem)
MSVCRT_size_t _msize(void* mem)
{
long size = HeapSize(GetProcessHeap(),0,mem);
if (size == -1)
@ -220,7 +204,7 @@ long _msize(void* mem)
/*********************************************************************
* calloc (MSVCRT.@)
*/
void* MSVCRT_calloc(unsigned int size, unsigned int count)
void* MSVCRT_calloc(MSVCRT_size_t size, MSVCRT_size_t count)
{
return HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size * count );
}
@ -236,7 +220,7 @@ void MSVCRT_free(void* ptr)
/*********************************************************************
* malloc (MSVCRT.@)
*/
void* MSVCRT_malloc(unsigned int size)
void* MSVCRT_malloc(MSVCRT_size_t size)
{
void *ret = HeapAlloc(GetProcessHeap(),0,size);
if (!ret)
@ -247,7 +231,7 @@ void* MSVCRT_malloc(unsigned int size)
/*********************************************************************
* realloc (MSVCRT.@)
*/
void* MSVCRT_realloc(void* ptr, unsigned int size)
void* MSVCRT_realloc(void* ptr, MSVCRT_size_t size)
{
return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
}

View File

@ -4,15 +4,14 @@
* Copyright 2000 Jon Griffiths
*/
#include "msvcrt.h"
#include <stdlib.h>
#include "msvcrt.h"
#include "msvcrt/stdlib.h"
DEFAULT_DEBUG_CHANNEL(msvcrt);
typedef int (*MSVCRT_comp_func)(const void*, const void*);
/*********************************************************************
* _beep (MSVCRT.@)
@ -45,7 +44,7 @@ void _sleep(unsigned long timeout)
*/
void* _lfind(const void* match, const void* start,
unsigned int* array_size, unsigned int elem_size,
MSVCRT_comp_func cf)
MSVCRT_compar_fn_t cf)
{
unsigned int size = *array_size;
if (size)
@ -63,7 +62,7 @@ void* _lfind(const void* match, const void* start,
*/
void* _lsearch(const void* match, void* start,
unsigned int* array_size, unsigned int elem_size,
MSVCRT_comp_func cf)
MSVCRT_compar_fn_t cf)
{
unsigned int size = *array_size;
if (size)

View File

@ -6,8 +6,8 @@
* Copyright 1997,2000 Uwe Bonnes
* Copyright 2000 Jon Griffiths
*/
#include "msvcrt.h"
#include "msvcrt.h"
#include "msvcrt/stdlib.h"
#include "msvcrt/string.h"

69
include/msvcrt/malloc.h Normal file
View File

@ -0,0 +1,69 @@
/*
* Heap definitions
*
* Copyright 2001 Francois Gouget.
*/
#ifndef __WINE_MALLOC_H
#define __WINE_MALLOC_H
#ifdef USE_MSVCRT_PREFIX
#define MSVCRT(x) MSVCRT_##x
#else
#define MSVCRT(x) x
#endif
/* heap function constants */
#define _HEAPEMPTY -1
#define _HEAPOK -2
#define _HEAPBADBEGIN -3
#define _HEAPBADNODE -4
#define _HEAPEND -5
#define _HEAPBADPTR -6
#define _FREEENTRY 0
#define _USEDENTRY 1
#ifndef MSVCRT_SIZE_T_DEFINED
typedef unsigned int MSVCRT(size_t);
#define MSVCRT_SIZE_T_DEFINED
#endif
typedef struct _heapinfo
{
int* _pentry;
MSVCRT(size_t) _size;
int _useflag;
} _HEAPINFO;
#ifdef __cplusplus
extern "C" {
#endif
void* _alloca(MSVCRT(size_t));
void* _expand(void*,MSVCRT(size_t));
int _heapadd(void*,MSVCRT(size_t));
int _heapchk(void);
int _heapmin(void);
int _heapset(unsigned int);
MSVCRT(size_t) _heapused(MSVCRT(size_t)*,MSVCRT(size_t)*);
int _heapwalk(_HEAPINFO*);
MSVCRT(size_t) _msize(void*);
void* MSVCRT(calloc)(MSVCRT(size_t),MSVCRT(size_t));
void MSVCRT(free)(void*);
void* MSVCRT(malloc)(MSVCRT(size_t));
void* MSVCRT(realloc)(void*,MSVCRT(size_t));
#ifdef __cplusplus
}
#endif
#ifndef USE_MSVCRT_PREFIX
#define alloca _alloca
#endif /* USE_MSVCRT_PREFIX */
#endif /* __WINE_MALLOC_H */

44
include/msvcrt/search.h Normal file
View File

@ -0,0 +1,44 @@
/*
* Heap definitions
*
* Copyright 2001 Francois Gouget.
*/
#ifndef __WINE_SEARCH_H
#define __WINE_SEARCH_H
#ifdef USE_MSVCRT_PREFIX
#define MSVCRT(x) MSVCRT_##x
#else
#define MSVCRT(x) x
#endif
#ifndef MSVCRT_SIZE_T_DEFINED
typedef unsigned int MSVCRT(size_t);
#define MSVCRT_SIZE_T_DEFINED
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef int (*MSVCRT_compar_fn_t)(const void*,const void*);
void* _lfind(const void*,const void*,unsigned int*,unsigned int,MSVCRT_compar_fn_t);
void* _lsearch(const void*,void*,unsigned int*,unsigned int,MSVCRT_compar_fn_t);
void* MSVCRT(bsearch)(const void*,const void*,MSVCRT(size_t),MSVCRT(size_t),MSVCRT_compar_fn_t);
void MSVCRT(qsort)(void*,MSVCRT(size_t),MSVCRT(size_t),MSVCRT_compar_fn_t);
#ifdef __cplusplus
}
#endif
#ifndef USE_MSVCRT_PREFIX
#define lfind _lfind
#define lsearch _lsearch
#endif /* USE_MSVCRT_PREFIX */
#endif /* __WINE_SEARCH_H */

View File

@ -9,12 +9,8 @@
#define __WINE_STDLIB_H
#include "winnt.h"
#ifdef USE_MSVCRT_PREFIX
#define MSVCRT(x) MSVCRT_##x
#else
#define MSVCRT(x) x
#endif
#include "msvcrt/malloc.h" /* For size_t, malloc & co */
#include "msvcrt/search.h" /* For bsearch and qsort */
#ifndef USE_MSVCRT_PREFIX
@ -34,11 +30,6 @@
#endif
#ifndef MSVCRT_SIZE_T_DEFINED
typedef unsigned int MSVCRT(size_t);
#define MSVCRT_SIZE_T_DEFINED
#endif
typedef struct MSVCRT(_div_t) {
int quot;
int rem;
@ -113,7 +104,6 @@ extern int* MSVCRT(_errno)(void);
typedef int (*_onexit_t)(void);
typedef int (*_pfunccmp_t)(const void*,const void*);
__int64 _atoi64(const char*);
@ -151,8 +141,6 @@ int MSVCRT(atexit)(_onexit_t);
double MSVCRT(atof)(const char*);
int MSVCRT(atoi)(const char*);
long MSVCRT(atol)(const char*);
void* MSVCRT(bsearch)(const void*,const void*,MSVCRT(size_t),MSVCRT(size_t),_pfunccmp_t);
void* MSVCRT(calloc)(MSVCRT(size_t),MSVCRT(size_t));
#ifdef __i386__
LONGLONG MSVCRT(div)(int,int);
ULONGLONG MSVCRT(ldiv)(long,long);
@ -161,15 +149,11 @@ MSVCRT(div_t) MSVCRT(div)(int,int);
MSVCRT(ldiv_t) MSVCRT(ldiv)(long,long);
#endif
void MSVCRT(exit)(int);
void MSVCRT(free)(void*);
char* MSVCRT(getenv)(const char*);
long MSVCRT(labs)(long);
void* MSVCRT(malloc)(MSVCRT(size_t));
int MSVCRT(mblen)(const char*,MSVCRT(size_t));
void MSVCRT(perror)(const char*);
void MSVCRT(qsort)(const void*,MSVCRT(size_t),MSVCRT(size_t),_pfunccmp_t);
int MSVCRT(rand)(void);
void* MSVCRT(realloc)(void*,MSVCRT(size_t));
void MSVCRT(srand)(unsigned int);
double MSVCRT(strtod)(const char*,char**);
long MSVCRT(strtol)(const char*,char**,int);