home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dbmalloc.zip / xmalloc.c < prev   
C/C++ Source or Header  |  1993-01-04  |  5KB  |  218 lines

  1. /*
  2.  * (c) Copyright 1990, 1991, 1992 Conor P. Cahill (cpcahil@virtech.vti.com)
  3.  *
  4.  * This software may be distributed freely as long as the following conditions
  5.  * are met:
  6.  *         * the distribution, or any derivative thereof, may not be
  7.  *          included as part of a commercial product
  8.  *        * full source code is provided including this copyright
  9.  *        * there is no charge for the software itself (there may be
  10.  *          a minimal charge for the copying or distribution effort)
  11.  *        * this copyright notice is not modified or removed from any
  12.  *          source file
  13.  */
  14. #ifndef lint
  15. static char rcs_hdr[] = "$Id: xmalloc.c,v 1.7 1992/08/22 16:27:13 cpcahil Exp $";
  16. #endif
  17.  
  18. /* $XConsortium: Alloc.c,v 1.46 91/07/30 11:04:41 rws Exp $ */
  19.  
  20. /***********************************************************
  21. Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  22. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  23.  
  24.                         All Rights Reserved
  25.  
  26. Permission to use, copy, modify, and distribute this software and its 
  27. documentation for any purpose and without fee is hereby granted, 
  28. provided that the above copyright notice appear in all copies and that
  29. both that copyright notice and this permission notice appear in 
  30. supporting documentation, and that the names of Digital or MIT not be
  31. used in advertising or publicity pertaining to distribution of the
  32. software without specific, written prior permission.  
  33.  
  34. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  35. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  36. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  37. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  38. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  39. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  40. SOFTWARE.
  41.  
  42. ******************************************************************/
  43.  
  44. #include <stdio.h>
  45.  
  46. #include "sysdefs.h"
  47.  
  48. #if FOUND_X_INTRINSIC
  49. #include "X11/Intrinsic.h"
  50. #endif
  51.  
  52. #include "mallocin.h"
  53.  
  54. void _XtAllocError(type)
  55.     CONST char * type;
  56. {
  57.     Cardinal num_params = 1;
  58.     extern String XtCXtToolkitError;
  59.  
  60.     if (type == NULL) type = "local memory allocation";
  61.     XtErrorMsg("allocError", type, XtCXtToolkitError,
  62.            "Cannot perform %s", &type, &num_params);
  63. }
  64.  
  65. void
  66. _XtBCopy(b1, b2, length)
  67.     char        * b1;
  68.     char        * b2;
  69.     int          length;
  70. {
  71.     DBFmemcpy("_XtBCopy", (char *)NULL, 0, b2, b1, (MEMSIZE)length);
  72. }
  73.  
  74. void
  75. debug_XtBcopy(file, line, b1, b2, length)
  76.     char         * file;
  77.     int          line;
  78.     char        * b1;
  79.     char        * b2;
  80.     int          length;
  81. {
  82.     DBFmemcpy("_XtBCopy", file, line, b2, b1, (MEMSIZE) length);
  83. }
  84.  
  85. char *
  86. XtMalloc(size)
  87.     unsigned int      size;
  88. {
  89.     return( debug_XtMalloc((char *)NULL, 0, size) );
  90. }
  91.  
  92. char *
  93. debug_XtMalloc(file,line,size)
  94.     CONST char    * file;
  95.     int          line;
  96.     unsigned int      size;
  97. {
  98.     static IDTYPE      call_counter;
  99.     char        * ptr;
  100.  
  101.     /*
  102.      * increment call counter
  103.      */
  104.     call_counter++;
  105.  
  106.     ptr = (char *) DBFmalloc("XtMalloc",M_T_XTMALLOC, call_counter,
  107.                   file, line, (SIZETYPE)size);
  108.  
  109.     if( ptr == NULL )
  110.     {
  111.             _XtAllocError("malloc");
  112.     }
  113.  
  114.     return(ptr);
  115. }
  116.  
  117. char *
  118. XtRealloc(ptr, size)
  119.     char        * ptr;
  120.     unsigned int      size;
  121. {
  122.     return( debug_XtRealloc((char *)NULL,0,ptr,size) );
  123. }
  124.  
  125. char *
  126. debug_XtRealloc(file,line,ptr, size)
  127.     CONST char    * file;
  128.     int          line;
  129.     char           * ptr;
  130.     unsigned int      size;
  131. {
  132.     static IDTYPE      call_counter;
  133.  
  134.     /*
  135.      * increment call counter
  136.      */
  137.     call_counter++;
  138.     
  139.     ptr = (char *) DBFrealloc("XtRealloc",M_T_XTREALLOC, call_counter,
  140.                   file,line,ptr,(SIZETYPE)size);
  141.  
  142.     if( ptr == NULL )
  143.     {
  144.             _XtAllocError("realloc");
  145.     }
  146.  
  147.     return(ptr);
  148. }
  149.  
  150. char *
  151. XtCalloc(num, size)
  152.     unsigned int      num;
  153.     unsigned int      size;
  154. {
  155.     return( debug_XtCalloc((char *)NULL, 0, num,size) );
  156. }
  157.  
  158. char *
  159. debug_XtCalloc(file,line,num,size)
  160.     CONST char    * file;
  161.     int          line;
  162.     unsigned int      num;
  163.     unsigned int      size;
  164. {
  165.     static IDTYPE      call_counter;
  166.     char        * ptr;
  167.  
  168.     /*
  169.      * increment call counter
  170.      */
  171.     call_counter++;
  172.  
  173.     ptr = (char *) DBFcalloc("XtCalloc",M_T_XTCALLOC, call_counter,
  174.                   file,line,(SIZETYPE)num,(SIZETYPE)size);
  175.  
  176.     if( ptr == NULL )
  177.     {
  178.             _XtAllocError("calloc");
  179.     }
  180.  
  181.     return(ptr);
  182. }
  183.  
  184. void
  185. XtFree(ptr)
  186.     char    * ptr;
  187. {
  188.     debug_XtFree( (char *) NULL, 0, ptr);
  189. }
  190.  
  191. void
  192. debug_XtFree(file,line,ptr)
  193.     CONST char     * file;
  194.     int          line;
  195.     char        * ptr;
  196. {
  197.     static IDTYPE      call_counter;
  198.     
  199.     /*
  200.      * increment call counter
  201.      */
  202.     call_counter++;
  203.  
  204.     DBFfree("XtFree",F_T_XTFREE,call_counter,file,line,ptr);
  205. }
  206.  
  207.  
  208. #ifndef DONT_FORCE_HEAPSTUFF
  209.  
  210. void
  211. NeverCalledFunctionFromAnywhere()
  212. {
  213.     _XtHeapInit(NULL);
  214. }
  215.  
  216. #endif
  217.  
  218.