New msvcrt headers: malloc.h, search.h

François Gouget fgouget at codeweavers.com
Sun Apr 22 23:38:37 CDT 2001


Changelog:

   François Gouget <fgouget at codeweavers.com>

 * include/msvcrt/malloc.h,
   include/msvcrt/search.h,
   include/msvcrt/stdlib.h,
   dlls/msvcrt/console.c,
   dlls/msvcrt/cpp.c,
   dlls/msvcrt/heap.c,
   dlls/msvcrt/misc.c

   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


-- 
François Gouget
fgouget at codeweavers.com
-------------- next part --------------
--- /dev/null	Sun Apr 15 00:27:07 2001
+++ include/msvcrt/malloc.h	Mon Apr 16 19:50:22 2001
@@ -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 */
--- /dev/null	Sun Apr 15 00:27:07 2001
+++ include/msvcrt/search.h	Sun Apr 22 18:55:12 2001
@@ -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 */
Index: include/msvcrt/stdlib.h
===================================================================
RCS file: /home/wine/wine/include/msvcrt/stdlib.h,v
retrieving revision 1.1
diff -u -r1.1 stdlib.h
--- include/msvcrt/stdlib.h	2001/04/10 23:21:43	1.1
+++ include/msvcrt/stdlib.h	2001/04/23 02:29:22
@@ -9,13 +9,9 @@
 #define __WINE_STDLIB_H
 
 #include "winnt.h"
+#include "malloc.h"                /* For size_t, malloc & co */
+#include "search.h"                /* For bsearch and qsort */
 
-#ifdef USE_MSVCRT_PREFIX
-#define MSVCRT(x)    MSVCRT_##x
-#else
-#define MSVCRT(x)    x
-#endif
-
 
 #ifndef USE_MSVCRT_PREFIX
 #define EXIT_SUCCESS        0
@@ -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 @@
 
 
 typedef int (*_onexit_t)(void);
-typedef int (*_pfunccmp_t)(const void*,const void*);
 
 
 __int64     _atoi64(const char*);
@@ -151,25 +141,19 @@
 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);
 #else
 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);
Index: dlls/msvcrt/console.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/console.c,v
retrieving revision 1.3
diff -u -r1.3 console.c
--- dlls/msvcrt/console.c	2001/04/10 23:25:25	1.3
+++ dlls/msvcrt/console.c	2001/04/23 02:29:07
@@ -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);
 
Index: dlls/msvcrt/cpp.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/cpp.c,v
retrieving revision 1.4
diff -u -r1.4 cpp.c
--- dlls/msvcrt/cpp.c	2001/04/10 23:25:25	1.4
+++ dlls/msvcrt/cpp.c	2001/04/23 02:29:07
@@ -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);
Index: dlls/msvcrt/heap.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/heap.c,v
retrieving revision 1.4
diff -u -r1.4 heap.c
--- dlls/msvcrt/heap.c	2001/04/10 23:25:25	1.4
+++ dlls/msvcrt/heap.c	2001/04/23 02:29:09
@@ -9,7 +9,7 @@
 
 #include "msvcrt.h"
 
-#include "msvcrt/stdlib.h"
+#include "msvcrt/malloc.h"
 
 
 DEFAULT_DEBUG_CHANNEL(msvcrt);
@@ -19,28 +19,12 @@
 #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 @@
 /*********************************************************************
  *		_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 @@
   if (!HeapValidate( GetProcessHeap(), 0, NULL))
   {
     MSVCRT__set_errno(GetLastError());
-    return MSVCRT_HEAPBADNODE;
+    return _HEAPBADNODE;
   }
-  return MSVCRT_HEAPOK;
+  return _HEAPOK;
 }
 
 /*********************************************************************
@@ -146,21 +130,21 @@
 /*********************************************************************
  *		_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 @@
     {
       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 _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 @@
 /*********************************************************************
  *		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,18 +220,18 @@
 /*********************************************************************
  *                  malloc (MSVCRT.@)
  */
-void* MSVCRT_malloc(unsigned int size)
+void* MSVCRT_malloc(MSVCRT_size_t size)
 {
   void *ret = HeapAlloc(GetProcessHeap(),0,size);
   if (!ret)
     MSVCRT__set_errno(GetLastError());
   return ret;
 }
 
 /*********************************************************************
  *		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);
 }
Index: dlls/msvcrt/misc.c
===================================================================
RCS file: /home/wine/wine/dlls/msvcrt/misc.c,v
retrieving revision 1.4
diff -u -r1.4 misc.c
--- dlls/msvcrt/misc.c	2001/04/10 23:25:25	1.4
+++ dlls/msvcrt/misc.c	2001/04/23 02:29:09
@@ -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 +45,7 @@
  */
 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 +63,7 @@
  */
 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)


More information about the wine-patches mailing list