home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume32 / dbmalloc / part04 < prev    next >
Encoding:
Text File  |  1992-09-03  |  54.1 KB  |  1,965 lines

  1. Newsgroups: comp.sources.misc
  2. From: cpcahil@vti.com (Conor P. Cahill)
  3. Subject:  v32i009:  dbmalloc - Debug Malloc Library PL14, Part04/10
  4. Message-ID: <1992Sep4.151954.12833@sparky.imd.sterling.com>
  5. X-Md4-Signature: a5c78259367cabf81ba0798f95880618
  6. Date: Fri, 4 Sep 1992 15:19:54 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: cpcahil@vti.com (Conor P. Cahill)
  10. Posting-number: Volume 32, Issue 9
  11. Archive-name: dbmalloc/part04
  12. Environment: C, UNIX
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then unpack
  16. # it by saving it into a file and typing "sh file".  To overwrite existing
  17. # files, type "sh file -c".  You can also feed this as standard input via
  18. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  19. # will see the following message at the end:
  20. #        "End of archive 4 (of 10)."
  21. # Contents:  free.c leak.c m_init.c m_perror.c malign.c malloc.h.org
  22. # Wrapped by cpcahil@virtech on Thu Sep  3 18:39:19 1992
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. if test -f 'free.c' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'free.c'\"
  26. else
  27. echo shar: Extracting \"'free.c'\" \(8341 characters\)
  28. sed "s/^X//" >'free.c' <<'END_OF_FILE'
  29. X
  30. X/*
  31. X * (c) Copyright 1990, 1991, 1992 Conor P. Cahill (cpcahil@virtech.vti.com)
  32. X *
  33. X * This software may be distributed freely as long as the following conditions
  34. X * are met:
  35. X *         * the distribution, or any derivative thereof, may not be
  36. X *          included as part of a commercial product
  37. X *        * full source code is provided including this copyright
  38. X *        * there is no charge for the software itself (there may be
  39. X *          a minimal charge for the copying or distribution effort)
  40. X *        * this copyright notice is not modified or removed from any
  41. X *          source file
  42. X */
  43. X#include <stdio.h>
  44. X#include "mallocin.h"
  45. X#include "debug.h"
  46. X
  47. X/*
  48. X * Function:    free()
  49. X *
  50. X * Purpose:    to deallocate malloced data
  51. X *
  52. X * Arguments:    ptr    - pointer to data area to deallocate
  53. X *
  54. X * Returns:    nothing of any value
  55. X *
  56. X * Narrative:
  57. X *        verify pointer is within malloc region
  58. X *        get mlist pointer from passed address
  59. X *        verify magic number
  60. X *        verify inuse flag
  61. X *        verify pointer connections with surrounding segments
  62. X *        turn off inuse flag
  63. X *        verify no data overrun into non-malloced area at end of segment
  64. X *        IF possible join segment with next segment
  65. X *        IF possible join segment with previous segment
  66. X *        Clear all data in segment (to make sure it isn't reused)
  67. X *
  68. X */
  69. X#ifndef lint
  70. Xstatic
  71. Xchar rcs_hdr[] = "$Id: free.c,v 1.29 1992/08/22 16:27:13 cpcahil Exp $";
  72. X#endif
  73. X
  74. XFREETYPE
  75. Xfree(cptr)
  76. X    DATATYPE    * cptr;
  77. X{
  78. X    debug_free((char *)NULL, 0, cptr);
  79. X}
  80. X
  81. XFREETYPE
  82. Xdebug_free(file,line,cptr)
  83. X    CONST char    * file;
  84. X    int          line;
  85. X    DATATYPE    * cptr;
  86. X{
  87. X    static IDTYPE      counter;
  88. X
  89. X    counter++;
  90. X
  91. X    DBFfree("free",F_T_FREE,counter,file,line,cptr);
  92. X}
  93. X
  94. XFREETYPE
  95. XDBFfree(func,type,counter,file,line,cptr)
  96. X    CONST char    * func;
  97. X    int          type;
  98. X    IDTYPE          counter;
  99. X    CONST char    * file;
  100. X    int          line;
  101. X    DATATYPE    * cptr;
  102. X{
  103. X    register struct mlist    * oldptr;
  104. X    register struct mlist    * ptr;
  105. X
  106. X    /*
  107. X     * initialize the malloc sub-system.
  108. X     */
  109. X    MALLOC_INIT();
  110. X
  111. X    /*
  112. X     * IF malloc chain checking is on, go do it.
  113. X     */
  114. X    if( malloc_opts & MOPT_CKCHAIN )
  115. X    {
  116. X        VOIDCAST DBFmalloc_chain_check(func,file,line,1);
  117. X    }
  118. X
  119. X#if defined(ANSI_NULLS) || (__STDC__ && ! defined(NO_ANSI_NULLS))
  120. X
  121. X    if( cptr == NULL )
  122. X    {
  123. X        return;
  124. X    }
  125. X
  126. X#else
  127. X
  128. X    if( (cptr == NULL) && (type == F_T_XTFREE) )
  129. X    {
  130. X        return;
  131. X    }
  132. X
  133. X#endif
  134. X
  135. X    /*
  136. X     * verify that cptr is within the malloc region and that it is on
  137. X     * the correct alignment
  138. X     */
  139. X    if(        (cptr < malloc_data_start)
  140. X        || (cptr > malloc_data_end)
  141. X        || ((((long)cptr) & malloc_round) != 0)  )
  142. X    {
  143. X        malloc_errno = M_CODE_BAD_PTR;
  144. X        malloc_warning(func,file,line,(struct mlist *)NULL);
  145. X        return;
  146. X    }
  147. X
  148. X    /* 
  149. X     * convert pointer to mlist struct pointer.  To do this we must 
  150. X     * move the pointer backwards the correct number of bytes...
  151. X     */
  152. X    ptr = DATATOMLIST(cptr);
  153. X
  154. X    /*
  155. X     * check the magic number 
  156. X     */    
  157. X    if( (ptr->flag&M_MAGIC_BITS) != M_MAGIC )
  158. X    {
  159. X        malloc_errno = M_CODE_BAD_MAGIC;
  160. X        malloc_warning(func,file,line,(struct mlist *)NULL);
  161. X        return;
  162. X    }
  163. X
  164. X    /*
  165. X     * if this segment is not flagged as being in use
  166. X     */
  167. X    if( ! (ptr->flag & M_INUSE) )
  168. X    {
  169. X        malloc_errno = M_CODE_NOT_INUSE;
  170. X        malloc_warning(func,file,line,ptr);
  171. X        return;
  172. X    }
  173. X
  174. X    /*
  175. X     * check to see that the pointers are still connected
  176. X     */
  177. X     if( (ptr->prev && (ptr->prev->next != ptr) ) ||
  178. X        (ptr->next && (ptr->next->prev != ptr) ) ||
  179. X        ((ptr->next == NULL) && (ptr->prev == NULL)) )
  180. X    {
  181. X        malloc_errno = M_CODE_BAD_CONNECT;
  182. X        malloc_warning(func,file,line,ptr);
  183. X        return;
  184. X    }
  185. X
  186. X    /*
  187. X     * check fill regions for overflow
  188. X     */
  189. X    VOIDCAST FILLCHECK(func,file,line,ptr,SHOWERRORS);
  190. X
  191. X    /*
  192. X     * if this block has been marked and we are warning about marked frees
  193. X     * give the user a warning about the free.
  194. X     */
  195. X    if( ((malloc_opts&MOPT_FREEMARK) != 0) && ((ptr->flag & M_MARKED) != 0))
  196. X    {
  197. X        malloc_errno = M_CODE_FREEMARK;
  198. X        malloc_warning(func,file,line,ptr);
  199. X    }
  200. X
  201. X    /*
  202. X     * flag block as freed
  203. X     */
  204. X    ptr->flag &= ~M_INUSE;
  205. X
  206. X    DEBUG3(10,"pointers: prev: 0x%.7x,  ptr: 0x%.7x, next: 0x%.7x",
  207. X            ptr->prev, ptr, ptr->next);
  208. X    
  209. X    DEBUG3(10,"size:     prev: %9d,  ptr: %9d, next: %9d",
  210. X            ptr->prev->s.size, ptr->s.size, ptr->next->s.size);
  211. X    
  212. X    DEBUG3(10,"flags:    prev: 0x%.7x,  ptr: 0x%.7x, next: 0x%.7x",
  213. X            ptr->prev->flag, ptr->flag, ptr->next->flag);
  214. X    
  215. X    /*
  216. X     * identify where this section was freed
  217. X     */
  218. X    ptr->ffile     = file;
  219. X    ptr->fline     = line;
  220. X    ptr->fid       = counter;
  221. X    ptr->freestack = StackCurrent();
  222. X    SETFTYPE(ptr,type);
  223. X    
  224. X    /*
  225. X     * Fill in the freed segment
  226. X     */
  227. X    FILLDATA(ptr,FILL_FREE,0,(struct mlist *)NULL);
  228. X
  229. X    /*
  230. X     * if we are reusing code
  231. X     */
  232. X    if( malloc_opts & MOPT_REUSE  )
  233. X    {
  234. X        /*
  235. X         * check to see if this block can be combined with the next
  236. X         * and/or previous block.  Since it may be joined with the
  237. X          * previous block we will save a pointer to the previous
  238. X         * block and test to verify if it is joined (it's next ptr
  239. X         * will no longer point to ptr).
  240. X          */
  241. X        malloc_join(ptr,ptr->next,NOTINUSE,DOFILL);
  242. X
  243. X        oldptr = ptr->prev;
  244. X
  245. X        malloc_join(ptr->prev, ptr,NOTINUSE,DOFILL);
  246. X
  247. X        if( oldptr->next != ptr )
  248. X        {
  249. X            DEBUG0(10,"Oldptr was changed");
  250. X            ptr = oldptr;
  251. X        }
  252. X
  253. X        /*
  254. X         * else, since the oldptr did not change, ptr is now a new free
  255. X         * segment that must be added to the free list, so go do it.
  256. X         */
  257. X        else
  258. X        {
  259. X            malloc_freeseg(M_FREE_ADD,ptr);
  260. X        }
  261. X    }
  262. X
  263. X} /* DBFfree(... */
  264. X
  265. X/*
  266. X * $Log: free.c,v $
  267. X * Revision 1.29  1992/08/22  16:27:13  cpcahil
  268. X * final changes for pl14
  269. X *
  270. X * Revision 1.28  1992/07/12  15:30:58  cpcahil
  271. X * Merged in Jonathan I Kamens' changes
  272. X *
  273. X * Revision 1.27  1992/07/03  00:03:25  cpcahil
  274. X * more fixes for pl13, several suggestons from Rich Salz.
  275. X *
  276. X * Revision 1.26  1992/07/02  13:49:54  cpcahil
  277. X * added support for new malloc_size function and additional tests to testerr
  278. X *
  279. X * Revision 1.25  1992/05/14  23:02:27  cpcahil
  280. X * added support for ANSI NULL behavior even with non-ansi compilers (if
  281. X * chosen at compile time).
  282. X *
  283. X * Revision 1.24  1992/05/06  04:53:29  cpcahil
  284. X * performance enhancments
  285. X *
  286. X * Revision 1.23  1992/04/24  11:18:52  cpcahil
  287. X * Fixes from Denny Page and Better integration of Xt alloc hooks
  288. X *
  289. X * Revision 1.22  1992/04/22  18:17:32  cpcahil
  290. X * added support for Xt Alloc functions, linted code
  291. X *
  292. X * Revision 1.21  1992/04/13  03:06:33  cpcahil
  293. X * Added Stack support, marking of non-leaks, auto-config, auto-testing
  294. X *
  295. X * Revision 1.20  1992/03/01  12:42:38  cpcahil
  296. X * added support for managing freed areas and fixed doublword bndr problems
  297. X *
  298. X * Revision 1.19  1992/02/19  01:41:35  cpcahil
  299. X * added check for alignment on the free'd pointer.
  300. X *
  301. X * Revision 1.18  1992/01/30  12:23:06  cpcahil
  302. X * renamed mallocint.h -> mallocin.h
  303. X *
  304. X * Revision 1.17  1992/01/28  14:30:18  cpcahil
  305. X * Changes from the c.s.r second review
  306. X *
  307. X * Revision 1.16  1992/01/10  17:28:03  cpcahil
  308. X * Added support for overriding void datatype
  309. X *
  310. X * Revision 1.15  1991/12/06  17:58:44  cpcahil
  311. X * added cfree() for compatibility with some wierd systems
  312. X *
  313. X * Revision 1.14  91/12/06  08:54:17  cpcahil
  314. X * cleanup of __STDC__ usage and addition of CHANGES file
  315. X * 
  316. X * Revision 1.13  91/12/04  09:23:37  cpcahil
  317. X * several performance enhancements including addition of free list
  318. X * 
  319. X * Revision 1.12  91/12/02  19:10:09  cpcahil
  320. X * changes for patch release 5
  321. X * 
  322. X * Revision 1.11  91/11/25  14:41:53  cpcahil
  323. X * Final changes in preparation for patch 4 release
  324. X * 
  325. X * Revision 1.10  91/11/24  00:49:25  cpcahil
  326. X * first cut at patch 4
  327. X * 
  328. X * Revision 1.9  90/08/29  21:22:48  cpcahil
  329. X * miscellaneous lint fixes
  330. X * 
  331. X * Revision 1.8  90/05/11  00:13:08  cpcahil
  332. X * added copyright statment
  333. X * 
  334. X * Revision 1.7  90/02/25  11:00:18  cpcahil
  335. X * added support for malloc chain checking.
  336. X * 
  337. X * Revision 1.6  90/02/24  21:50:18  cpcahil
  338. X * lots of lint fixes
  339. X * 
  340. X * Revision 1.5  90/02/24  17:29:13  cpcahil
  341. X * changed $Header to $Id so full path wouldnt be included as part of rcs 
  342. X * id string
  343. X * 
  344. X * Revision 1.4  90/02/24  15:15:32  cpcahil
  345. X * 1. changed ALREADY_FREE errno to NOT_INUSE so that the same errno could
  346. X *    be used by both free and realloc (since it was the same error).
  347. X * 2. fixed coding bug
  348. X * 
  349. X * Revision 1.3  90/02/24  14:23:45  cpcahil
  350. X * fixed malloc_warning calls
  351. X * 
  352. X * Revision 1.2  90/02/24  13:59:10  cpcahil
  353. X * added function header.
  354. X * Modified calls to malloc_warning/malloc_fatal to use new code error messages
  355. X * Added support for malloc_errno setting of error codes.
  356. X * 
  357. X * Revision 1.1  90/02/22  23:17:43  cpcahil
  358. X * Initial revision
  359. X * 
  360. X */
  361. END_OF_FILE
  362. if test 8341 -ne `wc -c <'free.c'`; then
  363.     echo shar: \"'free.c'\" unpacked with wrong size!
  364. fi
  365. # end of 'free.c'
  366. fi
  367. if test -f 'leak.c' -a "${1}" != "-c" ; then 
  368.   echo shar: Will not clobber existing file \"'leak.c'\"
  369. else
  370. echo shar: Extracting \"'leak.c'\" \(5934 characters\)
  371. sed "s/^X//" >'leak.c' <<'END_OF_FILE'
  372. X/*
  373. X * (c) Copyright 1990, 1991, 1992 Conor P. Cahill (cpcahil@virtech.vti.com)
  374. X *
  375. X * This software may be distributed freely as long as the following conditions
  376. X * are met:
  377. X *         * the distribution, or any derivative thereof, may not be
  378. X *          included as part of a commercial product
  379. X *        * full source code is provided including this copyright
  380. X *        * there is no charge for the software itself (there may be
  381. X *          a minimal charge for the copying or distribution effort)
  382. X *        * this copyright notice is not modified or removed from any
  383. X *          source file
  384. X */
  385. X
  386. X#ifndef lint
  387. Xstatic
  388. Xchar rcs_hdr[] = "$Id: leak.c,v 1.12 1992/08/22 16:27:13 cpcahil Exp $";
  389. X#endif
  390. X
  391. X#include <stdio.h>
  392. X
  393. X#include "mallocin.h"
  394. X
  395. X/*
  396. X * Function:    malloc_inuse()
  397. X *
  398. X * Purpose:    to determine the amount of memory in use
  399. X *
  400. X * Arguments:    histidptr - pointer to hist id area
  401. X *
  402. X * Returns:    Number of bytes currently in use
  403. X *
  404. X * Narrative:    make sure the malloc chain is ok
  405. X *        for each element in the malloc chain
  406. X *            if it is in use
  407. X *                add size to total size
  408. X *         if hist id is wanted
  409. X *                  set it
  410. X *        return total in-use size
  411. X *        
  412. X */
  413. X
  414. Xunsigned long
  415. Xmalloc_inuse(histptr)
  416. X    unsigned long        * histptr;
  417. X{
  418. X    return( DBmalloc_inuse((char *)NULL,0,histptr) );
  419. X}
  420. X
  421. Xunsigned long
  422. XDBmalloc_inuse(file,line,histptr)
  423. X    CONST char        * file;
  424. X    int               line;
  425. X    unsigned long        * histptr;
  426. X{
  427. X    unsigned long          size = 0;
  428. X    struct mlist        * ptr;
  429. X
  430. X    MALLOC_INIT();
  431. X
  432. X    /*
  433. X     * make sure the chain is ok (otherwise we will have a problem
  434. X     * parsing through it
  435. X     */
  436. X    VOIDCAST DBFmalloc_chain_check("malloc_inuse",file,line,1);
  437. X
  438. X    /*
  439. X     * for each element in the malloc chain
  440. X     */
  441. X    for(ptr = &malloc_start; ptr; ptr = ptr->next)
  442. X    {
  443. X        /*
  444. X         * if the element is in use and it is not marked and it is
  445. X          * not a stack segment (an internal allocation used by the
  446. X         * malloc subsystem when tracking program stack)
  447. X         */
  448. X        if(    ((ptr->flag & M_INUSE)  == M_INUSE)
  449. X            && ((ptr->flag & M_MARKED) != M_MARKED) 
  450. X            && ( GETTYPE(ptr) != M_T_STACK) )
  451. X        {
  452. X            /* 
  453. X             * add its requested size into the total size
  454. X             */
  455. X            size += ptr->r_size;
  456. X        }
  457. X    }
  458. X
  459. X    /*
  460. X     * if the hist id is desired, give it to em.
  461. X     */
  462. X    if( histptr != NULL )
  463. X    {
  464. X        *histptr = malloc_hist_id;
  465. X    }
  466. X
  467. X    /*
  468. X     * return the size
  469. X     */
  470. X    return(size);
  471. X
  472. X} /* DBmalloc_inuse(... */
  473. X
  474. X
  475. X/*
  476. X * Function:    malloc_mark()
  477. X *
  478. X * Purpose:    to mark memory as validly in-use. This is used in order to 
  479. X *        exempt verified segments from the leak list/counters so that
  480. X *        once you verify that it is valid to leave the segment around
  481. X *        forever, you can mark the segment and it won't be counted in
  482. X *        the leak memory counts, no the leak segment list
  483. X *
  484. X * Arguments:    ptr    - pointer to data area to mark
  485. X *
  486. X * Returns:    true    - segment has been marked
  487. X *        false    - segment not marked because it is invalid
  488. X *
  489. X * Narrative:
  490. X *        make sure malloc subsystem is initialized
  491. X *        if necessary, check malloc chain
  492. X *        verify pointer is within malloc region
  493. X *        get mlist pointer from passed address
  494. X *        verify magic number
  495. X *        verify inuse flag
  496. X *        verify valid linkage
  497. X *        mark segment
  498. X */
  499. X
  500. XVOIDTYPE
  501. Xmalloc_mark(cptr)
  502. X    DATATYPE    * cptr;
  503. X{
  504. X    DBmalloc_mark((char *)NULL, 0, cptr);
  505. X}
  506. X
  507. XVOIDTYPE
  508. XDBmalloc_mark(file,line,cptr)
  509. X    CONST char    * file;
  510. X    int          line;
  511. X    DATATYPE    * cptr;
  512. X{
  513. X    CONST char        * func = "malloc_mark";
  514. X    register struct mlist    * ptr;
  515. X
  516. X    /*
  517. X     * initialize the malloc sub-system.
  518. X     */
  519. X    MALLOC_INIT();
  520. X
  521. X    /*
  522. X     * If malloc chain checking is on, go do it.
  523. X     */
  524. X    if( malloc_opts & MOPT_CKCHAIN )
  525. X    {
  526. X        VOIDCAST DBFmalloc_chain_check(func,file,line,1);
  527. X    }
  528. X
  529. X    /*
  530. X     * verify that cptr is within the malloc region and that it is on
  531. X     * the correct alignment
  532. X     */
  533. X    if(        (cptr < malloc_data_start)
  534. X        || (cptr > malloc_data_end)
  535. X        || ((((long)cptr) & malloc_round) != 0)  )
  536. X    {
  537. X        malloc_errno = M_CODE_BAD_PTR;
  538. X        malloc_warning(func,file,line,(struct mlist *)NULL);
  539. X        return;
  540. X    }
  541. X
  542. X    /* 
  543. X     * convert pointer to mlist struct pointer.  To do this we must 
  544. X     * move the pointer backwards the correct number of bytes...
  545. X     */
  546. X    ptr = (struct mlist *) (((char *)cptr) - M_SIZE);
  547. X
  548. X    /*
  549. X     * check the magic number 
  550. X     */    
  551. X    if( (ptr->flag&M_MAGIC_BITS) != M_MAGIC )
  552. X    {
  553. X        malloc_errno = M_CODE_BAD_MAGIC;
  554. X        malloc_warning(func,file,line,(struct mlist *)NULL);
  555. X        return;
  556. X    }
  557. X
  558. X    /*
  559. X     * if this segment is not flagged as being in use
  560. X     */
  561. X    if( ! (ptr->flag & M_INUSE) )
  562. X    {
  563. X        malloc_errno = M_CODE_NOT_INUSE;
  564. X        malloc_warning(func,file,line,ptr);
  565. X        return;
  566. X    }
  567. X
  568. X    /*
  569. X     * check to see that the pointers are still connected
  570. X     */
  571. X     if( (ptr->prev && (ptr->prev->next != ptr) ) ||
  572. X        (ptr->next && (ptr->next->prev != ptr) ) ||
  573. X        ((ptr->next == NULL) && (ptr->prev == NULL)) )
  574. X    {
  575. X        malloc_errno = M_CODE_BAD_CONNECT;
  576. X        malloc_warning(func,file,line,ptr);
  577. X        return;
  578. X    }
  579. X
  580. X    ptr->flag |= M_MARKED;
  581. X
  582. X} /* DBmalloc_mark(... */
  583. X
  584. X/*
  585. X * $Log: leak.c,v $
  586. X * Revision 1.12  1992/08/22  16:27:13  cpcahil
  587. X * final changes for pl14
  588. X *
  589. X * Revision 1.11  1992/07/02  13:49:54  cpcahil
  590. X * added support for new malloc_size function and additional tests to testerr
  591. X *
  592. X * Revision 1.10  1992/06/30  13:06:39  cpcahil
  593. X * added support for aligned allocations
  594. X *
  595. X * Revision 1.9  1992/06/27  22:48:48  cpcahil
  596. X * misc fixes per bug reports from first week of reviews
  597. X *
  598. X * Revision 1.8  1992/06/22  23:40:10  cpcahil
  599. X * many fixes for working on small int systems
  600. X *
  601. X * Revision 1.7  1992/04/13  19:57:15  cpcahil
  602. X * more patch 8 fixes
  603. X *
  604. X * Revision 1.6  1992/04/13  03:06:33  cpcahil
  605. X * Added Stack support, marking of non-leaks, auto-config, auto-testing
  606. X *
  607. X * Revision 1.5  1992/01/30  12:23:06  cpcahil
  608. X * renamed mallocint.h -> mallocin.h
  609. X *
  610. X * Revision 1.4  1992/01/10  17:28:03  cpcahil
  611. X * Added support for overriding void datatype
  612. X *
  613. X * Revision 1.3  1991/12/02  19:10:09  cpcahil
  614. X * changes for patch release 5
  615. X *
  616. X * Revision 1.2  91/11/25  14:41:54  cpcahil
  617. X * Final changes in preparation for patch 4 release
  618. X * 
  619. X * Revision 1.1  91/11/24  00:49:26  cpcahil
  620. X * first cut at patch 4
  621. X */
  622. END_OF_FILE
  623. if test 5934 -ne `wc -c <'leak.c'`; then
  624.     echo shar: \"'leak.c'\" unpacked with wrong size!
  625. fi
  626. # end of 'leak.c'
  627. fi
  628. if test -f 'm_init.c' -a "${1}" != "-c" ; then 
  629.   echo shar: Will not clobber existing file \"'m_init.c'\"
  630. else
  631. echo shar: Extracting \"'m_init.c'\" \(5934 characters\)
  632. sed "s/^X//" >'m_init.c' <<'END_OF_FILE'
  633. X
  634. X/*
  635. X * (c) Copyright 1990, 1991, 1992 Conor P. Cahill (cpcahil@virtech.vti.com)
  636. X *
  637. X * This software may be distributed freely as long as the following conditions
  638. X * are met:
  639. X *         * the distribution, or any derivative thereof, may not be
  640. X *          included as part of a commercial product
  641. X *        * full source code is provided including this copyright
  642. X *        * there is no charge for the software itself (there may be
  643. X *          a minimal charge for the copying or distribution effort)
  644. X *        * this copyright notice is not modified or removed from any
  645. X *          source file
  646. X */
  647. X
  648. X#ifndef lint
  649. Xstatic
  650. Xchar rcs_hdr[] = "$Id: m_init.c,v 1.22 1992/08/22 16:27:13 cpcahil Exp $";
  651. X#endif
  652. X
  653. X#include <stdio.h>
  654. X#include "mallocin.h"
  655. X
  656. X/*
  657. X * Function:    malloc_init()
  658. X *
  659. X * Purpose:    to initialize the pointers and variables use by the
  660. X *        malloc() debugging library
  661. X *
  662. X * Arguments:    none
  663. X *
  664. X * Returns:    nothing of any value
  665. X *
  666. X * Narrative:    Just initialize all the needed variables.  Use dbmallopt
  667. X *        to set options taken from the environment.
  668. X *
  669. X */
  670. XVOIDTYPE
  671. Xmalloc_init()
  672. X{
  673. X    char            * cptr;
  674. X    union dbmalloptarg      m;
  675. X    int              size;
  676. X    int              round;
  677. X
  678. X    /*
  679. X      * If already initialized...
  680. X     */
  681. X    if( malloc_data_start != (char *) 0)
  682. X    {
  683. X        return;
  684. X    }
  685. X
  686. X
  687. X    malloc_data_start = sbrk(0);
  688. X    malloc_data_end = malloc_data_start;
  689. X    malloc_start.s.size = 0;
  690. X    malloc_end = &malloc_start;
  691. X
  692. X    /*
  693. X     * test to see what rounding we need to use for this system
  694. X     */
  695. X    size = M_SIZE;
  696. X    round = M_RND;
  697. X    while( round > 0 )
  698. X    {
  699. X    
  700. X        if( (size & (round-1)) == 0 )
  701. X        {
  702. X            malloc_round = round-1;
  703. X            break;
  704. X        }
  705. X        round >>= 1;
  706. X    }
  707. X
  708. X    if( round == 0 )
  709. X    {
  710. X        malloc_errno = M_CODE_NOBOUND;
  711. X        malloc_fatal("malloc_init",__FILE__,__LINE__,(struct mlist*)0);
  712. X    }
  713. X
  714. X    /*
  715. X     * the following settings can only be set in the environment.  They
  716. X     * cannot be set via calls to dbmallopt().
  717. X     */
  718. X    if( (cptr=getenv("MALLOC_BOUNDSIZE")) != NULL )
  719. X    {
  720. X        malloc_boundsize = atoi(cptr);
  721. X
  722. X        if( malloc_boundsize < 1 )
  723. X        {
  724. X            malloc_boundsize = M_DFLT_BSIZE;
  725. X        }
  726. X    }
  727. X
  728. X    
  729. X    if( (cptr=getenv("MALLOC_CKCHAIN")) != NULL)
  730. X    {
  731. X        m.i = atoi(cptr);
  732. X        VOIDCAST dbmallopt(MALLOC_CKCHAIN,&m);
  733. X    }
  734. X
  735. X    if( (cptr=getenv("MALLOC_CKDATA")) != NULL)
  736. X    {
  737. X        m.i = atoi(cptr);
  738. X        VOIDCAST dbmallopt(MALLOC_CKDATA,&m);
  739. X    }
  740. X
  741. X    if( (cptr=getenv("MALLOC_DETAIL")) != NULL)
  742. X    {
  743. X        m.i = atoi(cptr);
  744. X        VOIDCAST dbmallopt(MALLOC_DETAIL,&m);
  745. X    }
  746. X
  747. X    if( (cptr=getenv("MALLOC_ERRFILE")) != NULL)
  748. X    {
  749. X        m.str = cptr;
  750. X        VOIDCAST dbmallopt(MALLOC_ERRFILE,&m);
  751. X    }
  752. X
  753. X    if( (cptr=getenv("MALLOC_FATAL")) != NULL)
  754. X    {
  755. X        m.i = atoi(cptr);
  756. X        VOIDCAST dbmallopt(MALLOC_FATAL,&m);
  757. X    }
  758. X
  759. X    if( (cptr=getenv("MALLOC_FILLAREA")) != NULL)
  760. X    {
  761. X        m.i = atoi(cptr);
  762. X        VOIDCAST dbmallopt(MALLOC_FILLAREA,&m);
  763. X    }
  764. X
  765. X    if( (cptr=getenv("MALLOC_FILLBYTE")) != NULL )
  766. X    {
  767. X        malloc_fillbyte = atoi(cptr);
  768. X
  769. X        if( (malloc_fillbyte < 0) || (malloc_fillbyte > 255) )
  770. X        {
  771. X            malloc_fillbyte = M_DFLT_FILL;
  772. X        }
  773. X    }
  774. X
  775. X    if( (cptr=getenv("MALLOC_FREEBYTE")) != NULL )
  776. X    {
  777. X        malloc_freebyte = atoi(cptr);
  778. X
  779. X        if( (malloc_freebyte < 0) || (malloc_freebyte > 255) )
  780. X        {
  781. X            malloc_freebyte = M_DFLT_FREE_FILL;
  782. X        }
  783. X    }
  784. X
  785. X    if( (cptr=getenv("MALLOC_FREEMARK")) != NULL)
  786. X    {
  787. X        m.i = atoi(cptr);
  788. X        VOIDCAST dbmallopt(MALLOC_FREEMARK,&m);
  789. X    }
  790. X
  791. X    if( (cptr=getenv("MALLOC_LOWFRAG")) != NULL)
  792. X    {
  793. X        m.i = atoi(cptr);
  794. X        VOIDCAST dbmallopt(MALLOC_LOWFRAG,&m);
  795. X    }
  796. X
  797. X    if( (cptr=getenv("MALLOC_REUSE")) != NULL)
  798. X    {
  799. X        m.i = atoi(cptr);
  800. X        VOIDCAST dbmallopt(MALLOC_REUSE,&m);
  801. X    }
  802. X
  803. X    if( (cptr=getenv("MALLOC_SHOWLINKS")) != NULL)
  804. X    {
  805. X        m.i = atoi(cptr);
  806. X        VOIDCAST dbmallopt(MALLOC_SHOWLINKS,&m);
  807. X    }
  808. X
  809. X    if( (cptr=getenv("MALLOC_WARN")) != NULL )
  810. X    {
  811. X        m.i = atoi(cptr);
  812. X        VOIDCAST dbmallopt(MALLOC_WARN,&m);
  813. X    }
  814. X
  815. X    if( (cptr=getenv("MALLOC_ZERO")) != NULL )
  816. X    {
  817. X        m.i = atoi(cptr);
  818. X        VOIDCAST dbmallopt(MALLOC_ZERO,&m);
  819. X    }
  820. X
  821. X    /*
  822. X     * set the malloc_fill initial value 
  823. X     */
  824. X    if( (malloc_opts & (MOPT_MFILL | MOPT_FFILL | MOPT_DFILL)) != 0 )
  825. X    {
  826. X        malloc_fill = 1;
  827. X    }
  828. X
  829. X} /* malloc_init(... */
  830. X
  831. X/*
  832. X * $Log: m_init.c,v $
  833. X * Revision 1.22  1992/08/22  16:27:13  cpcahil
  834. X * final changes for pl14
  835. X *
  836. X * Revision 1.21  1992/07/03  00:03:25  cpcahil
  837. X * more fixes for pl13, several suggestons from Rich Salz.
  838. X *
  839. X * Revision 1.20  1992/07/02  15:35:52  cpcahil
  840. X * misc cleanups for PL13
  841. X *
  842. X * Revision 1.19  1992/06/30  13:06:39  cpcahil
  843. X * added support for aligned allocations
  844. X *
  845. X * Revision 1.18  1992/06/22  23:40:10  cpcahil
  846. X * many fixes for working on small int systems
  847. X *
  848. X * Revision 1.17  1992/05/08  02:30:35  cpcahil
  849. X * minor cleanups from minix/atari port
  850. X *
  851. X * Revision 1.16  1992/05/06  05:37:44  cpcahil
  852. X * added overriding of fill characters and boundary size
  853. X *
  854. X * Revision 1.15  1992/05/06  04:53:29  cpcahil
  855. X * performance enhancments
  856. X *
  857. X * Revision 1.14  1992/04/13  03:06:33  cpcahil
  858. X * Added Stack support, marking of non-leaks, auto-config, auto-testing
  859. X *
  860. X * Revision 1.13  1992/03/01  12:42:38  cpcahil
  861. X * added support for managing freed areas and fixed doublword bndr problems
  862. X *
  863. X * Revision 1.12  1992/01/30  12:23:06  cpcahil
  864. X * renamed mallocint.h -> mallocin.h
  865. X *
  866. X * Revision 1.11  1992/01/10  17:28:03  cpcahil
  867. X * Added support for overriding void datatype
  868. X *
  869. X * Revision 1.10  1991/12/31  21:31:26  cpcahil
  870. X * changes for patch 6.  See CHANGES file for more info
  871. X *
  872. X * Revision 1.9  1991/12/04  09:23:38  cpcahil
  873. X * several performance enhancements including addition of free list
  874. X *
  875. X * Revision 1.8  91/11/25  14:41:54  cpcahil
  876. X * Final changes in preparation for patch 4 release
  877. X * 
  878. X * Revision 1.7  91/11/24  00:49:26  cpcahil
  879. X * first cut at patch 4
  880. X * 
  881. X * Revision 1.6  90/08/29  22:23:21  cpcahil
  882. X * fixed mallopt to use a union as an argument.
  883. X * 
  884. X * Revision 1.5  90/08/29  21:22:50  cpcahil
  885. X * miscellaneous lint fixes
  886. X * 
  887. X * Revision 1.4  90/05/11  15:53:35  cpcahil
  888. X * fixed bug in initialization code.
  889. X * 
  890. X * Revision 1.3  90/05/11  00:13:08  cpcahil
  891. X * added copyright statment
  892. X * 
  893. X * Revision 1.2  90/02/24  21:50:20  cpcahil
  894. X * lots of lint fixes
  895. X * 
  896. X * Revision 1.1  90/02/24  17:10:53  cpcahil
  897. X * Initial revision
  898. X * 
  899. X */
  900. END_OF_FILE
  901. if test 5934 -ne `wc -c <'m_init.c'`; then
  902.     echo shar: \"'m_init.c'\" unpacked with wrong size!
  903. fi
  904. # end of 'm_init.c'
  905. fi
  906. if test -f 'm_perror.c' -a "${1}" != "-c" ; then 
  907.   echo shar: Will not clobber existing file \"'m_perror.c'\"
  908. else
  909. echo shar: Extracting \"'m_perror.c'\" \(4417 characters\)
  910. sed "s/^X//" >'m_perror.c' <<'END_OF_FILE'
  911. X/*
  912. X * (c) Copyright 1990, 1991, 1992 Conor P. Cahill (cpcahil@virtech.vti.com)
  913. X *
  914. X * This software may be distributed freely as long as the following conditions
  915. X * are met:
  916. X *         * the distribution, or any derivative thereof, may not be
  917. X *          included as part of a commercial product
  918. X *        * full source code is provided including this copyright
  919. X *        * there is no charge for the software itself (there may be
  920. X *          a minimal charge for the copying or distribution effort)
  921. X *        * this copyright notice is not modified or removed from any
  922. X *          source file
  923. X */
  924. X
  925. X#ifndef lint
  926. Xstatic
  927. Xchar rcsid[] = "$Id: m_perror.c,v 1.23 1992/08/22 16:27:13 cpcahil Exp $";
  928. X#endif
  929. X
  930. X#include "mallocin.h"
  931. X
  932. X/*
  933. X * malloc errno error strings...
  934. X */
  935. X
  936. XCONST char *malloc_err_strings[] = 
  937. X{
  938. X    "No errors",
  939. X    "Malloc chain is corrupted, pointers out of order",
  940. X    "Malloc chain is corrupted, end before end pointer",
  941. X    "Pointer is not within malloc area",
  942. X    "Malloc region does not have valid magic number in header",
  943. X    "Pointers between this segment and adjoining segments are invalid",
  944. X    "Data has overrun beyond requested number of bytes",
  945. X    "Data in free'd area has been modified",
  946. X    "Data area is not in use (can't be freed or realloced, or used)",
  947. X    "Unable to get additional memory from the system",
  948. X    "Pointer within malloc region, but outside of malloc data bounds",
  949. X    "Malloc segment in free list is in-use",
  950. X    "Unable to determine doubleword boundary",
  951. X    "No current function on stack, probably missing call to malloc_enter ",
  952. X    "Current function name doesn't match name on stack",
  953. X    "Data has written before beginning of requested bytes",
  954. X    "Free of a marked segment",
  955. X    "Allocation of zero length segment",
  956. X    (CONST char *) 0
  957. X};
  958. X
  959. X/*
  960. X * Function:    malloc_perror()
  961. X *
  962. X * Purpose:    to print malloc_errno error message
  963. X *
  964. X * Arguments:    str    - string to print with error message
  965. X *
  966. X * Returns:    nothing of any value
  967. X *
  968. X * Narrative:
  969. X */
  970. XVOIDTYPE
  971. Xmalloc_perror(str)
  972. X    CONST char    * str;
  973. X{
  974. X    register CONST char     * s;
  975. X    register CONST char     * t;
  976. X
  977. X    if( str && *str)
  978. X    {
  979. X        for(s=str; *s; s++)
  980. X        {
  981. X            /* do nothing */;
  982. X        }
  983. X
  984. X        VOIDCAST write(2,str,(WRTSIZE)(s-str));
  985. X        VOIDCAST write(2,": ",(WRTSIZE)2);
  986. X    }
  987. X
  988. X    t = malloc_err_strings[malloc_errno];
  989. X
  990. X    for(s=t; *s; s++)
  991. X    {
  992. X        /* do nothing */;
  993. X    }
  994. X
  995. X    VOIDCAST write(2,t,(WRTSIZE)(s-t));
  996. X
  997. X    VOIDCAST write(2,"\n",(WRTSIZE)1);
  998. X}
  999. X
  1000. X/*
  1001. X * $Log: m_perror.c,v $
  1002. X * Revision 1.23  1992/08/22  16:27:13  cpcahil
  1003. X * final changes for pl14
  1004. X *
  1005. X * Revision 1.22  1992/07/03  00:03:25  cpcahil
  1006. X * more fixes for pl13, several suggestons from Rich Salz.
  1007. X *
  1008. X * Revision 1.21  1992/06/22  23:40:10  cpcahil
  1009. X * many fixes for working on small int systems
  1010. X *
  1011. X * Revision 1.20  1992/05/08  02:30:35  cpcahil
  1012. X * minor cleanups from minix/atari port
  1013. X *
  1014. X * Revision 1.19  1992/05/08  01:44:11  cpcahil
  1015. X * more performance enhancements
  1016. X *
  1017. X * Revision 1.18  1992/05/06  04:53:29  cpcahil
  1018. X * performance enhancments
  1019. X *
  1020. X * Revision 1.17  1992/04/20  22:29:14  cpcahil
  1021. X * changes to fix problems introduced by insertion of size_t
  1022. X *
  1023. X * Revision 1.16  1992/04/15  12:51:06  cpcahil
  1024. X * fixes per testing of patch 8
  1025. X *
  1026. X * Revision 1.15  1992/04/15  11:47:54  cpcahil
  1027. X * spelling changes.
  1028. X *
  1029. X * Revision 1.14  1992/04/14  01:15:25  cpcahil
  1030. X * port to RS/6000
  1031. X *
  1032. X * Revision 1.13  1992/04/13  03:06:33  cpcahil
  1033. X * Added Stack support, marking of non-leaks, auto-config, auto-testing
  1034. X *
  1035. X * Revision 1.12  1992/03/01  12:42:38  cpcahil
  1036. X * added support for managing freed areas and fixed doublword bndr problems
  1037. X *
  1038. X * Revision 1.11  1992/02/19  01:42:29  cpcahil
  1039. X * fixed typo in error message
  1040. X *
  1041. X * Revision 1.10  1992/01/30  12:23:06  cpcahil
  1042. X * renamed mallocint.h -> mallocin.h
  1043. X *
  1044. X * Revision 1.9  1992/01/10  17:28:03  cpcahil
  1045. X * Added support for overriding void datatype
  1046. X *
  1047. X * Revision 1.8  1991/12/04  09:23:38  cpcahil
  1048. X * several performance enhancements including addition of free list
  1049. X *
  1050. X * Revision 1.7  91/11/25  14:41:55  cpcahil
  1051. X * Final changes in preparation for patch 4 release
  1052. X * 
  1053. X * Revision 1.6  91/11/24  00:49:27  cpcahil
  1054. X * first cut at patch 4
  1055. X * 
  1056. X * Revision 1.5  90/08/29  21:25:08  cpcahil
  1057. X * added additional error message that was missing (and 
  1058. X * caused a core dump)
  1059. X * 
  1060. X * Revision 1.4  90/05/11  00:13:08  cpcahil
  1061. X * added copyright statment
  1062. X * 
  1063. X * Revision 1.3  90/02/24  21:50:21  cpcahil
  1064. X * lots of lint fixes
  1065. X * 
  1066. X * Revision 1.2  90/02/24  17:39:55  cpcahil
  1067. X * 1. added function header
  1068. X * 2. added rcs id and log strings.
  1069. X * 
  1070. X */
  1071. END_OF_FILE
  1072. if test 4417 -ne `wc -c <'m_perror.c'`; then
  1073.     echo shar: \"'m_perror.c'\" unpacked with wrong size!
  1074. fi
  1075. # end of 'm_perror.c'
  1076. fi
  1077. if test -f 'malign.c' -a "${1}" != "-c" ; then 
  1078.   echo shar: Will not clobber existing file \"'malign.c'\"
  1079. else
  1080. echo shar: Extracting \"'malign.c'\" \(5428 characters\)
  1081. sed "s/^X//" >'malign.c' <<'END_OF_FILE'
  1082. X/*
  1083. X * (c) Copyright 1990, 1991, 1992 Conor P. Cahill (cpcahil@virtech.vti.com)
  1084. X *
  1085. X * This software may be distributed freely as long as the following conditions
  1086. X * are met:
  1087. X *         * the distribution, or any derivative thereof, may not be
  1088. X *          included as part of a commercial product
  1089. X *        * full source code is provided including this copyright
  1090. X *        * there is no charge for the software itself (there may be
  1091. X *          a minimal charge for the copying or distribution effort)
  1092. X *        * this copyright notice is not modified or removed from any
  1093. X *          source file
  1094. X */
  1095. X#include <stdio.h>
  1096. X#include <fcntl.h>
  1097. X#include <sys/types.h>
  1098. X#include <signal.h>
  1099. X
  1100. X#include "sysdefs.h"
  1101. X
  1102. X/* 
  1103. X * make sure mallocin.h doesn't include sys/types.h since we have already
  1104. X * included it.
  1105. X */
  1106. X#ifndef SYS_TYPES_H_INCLUDED
  1107. X#define SYS_TYPES_H_INCLUDED 1
  1108. X#endif
  1109. X
  1110. X#include "mallocin.h"
  1111. X#include "tostring.h"
  1112. X
  1113. X#include "debug.h"
  1114. X
  1115. X#ifndef lint
  1116. Xstatic char rcs_hdr[] = "$Id: malign.c,v 1.2 1992/08/22 16:27:13 cpcahil Exp $";
  1117. X#endif
  1118. X
  1119. X/*
  1120. X * Function:    mem_align()
  1121. X *
  1122. X * Purpose:    allocate memory aligned to a multiple of the specified 
  1123. X *        alignment.
  1124. X *
  1125. X * Arguments:    size    - size of data area needed
  1126. X *
  1127. X * Returns:    whatever debug_malloc returns.
  1128. X *
  1129. X * Narrative:
  1130. X *
  1131. X */
  1132. XDATATYPE *
  1133. Xmemalign(align,size)
  1134. X    SIZETYPE      align;
  1135. X    SIZETYPE      size;
  1136. X{
  1137. X    return( DBmemalign(NULL,-1,align,size) );
  1138. X}
  1139. X
  1140. X/*
  1141. X * Function:    debug_malloc()
  1142. X *
  1143. X * Purpose:    the real memory allocator
  1144. X *
  1145. X * Arguments:    size    - size of data area needed
  1146. X *
  1147. X * Returns:    pointer to allocated area, or NULL if unable
  1148. X *        to allocate addtional data.
  1149. X *
  1150. X * Narrative:
  1151. X *
  1152. X */
  1153. XDATATYPE *
  1154. XDBmemalign(file,line,align,size)
  1155. X    CONST char    * file;
  1156. X    int          line;
  1157. X    SIZETYPE      align;
  1158. X    SIZETYPE      size;
  1159. X{
  1160. X    SIZETYPE      bitcnt = 0;
  1161. X    static IDTYPE      call_counter;
  1162. X    SIZETYPE      i;
  1163. X
  1164. X    /*
  1165. X     * increment the counter for the number of calls to this func.
  1166. X     */
  1167. X    call_counter++;
  1168. X
  1169. X    /*
  1170. X     * perform some checks first 
  1171. X     */
  1172. X
  1173. X    /*
  1174. X     * count up the number of bits that have been set (a number
  1175. X     * that is a power of two will only have one bit set)
  1176. X     */
  1177. X    for( i=0; i < (sizeof(align) * 8); i++)
  1178. X    {
  1179. X        if ( (align & (0x01 << i)) != 0 )
  1180. X        {
  1181. X            bitcnt++;
  1182. X        }
  1183. X    }
  1184. X
  1185. X    /*
  1186. X     * if there is other than a single bit set, there was a problem,
  1187. X     * so return NULL.
  1188. X     */
  1189. X    if( bitcnt != 1 )
  1190. X    {
  1191. X        return( (DATATYPE *) NULL);
  1192. X    }
  1193. X
  1194. X    /*
  1195. X     * if the alignment is too small, increase it until it is 
  1196. X     * large enough 
  1197. X     */
  1198. X    while( align < malloc_round )
  1199. X    {
  1200. X        align <<= 1;
  1201. X    }
  1202. X
  1203. X    /*
  1204. X     * set the alignment value for this call
  1205. X     */
  1206. X    malloc_align = align;
  1207. X
  1208. X    /*
  1209. X     * call the malloc function and return its result.
  1210. X     */
  1211. X    return( DBFmalloc("memalign",M_T_ALIGNED,call_counter,file,line,size) );
  1212. X
  1213. X} /* DBmemalign(... */
  1214. X
  1215. X/*
  1216. X * AlignedFit() - determine how close the aligned requirement fits within
  1217. X *          the specified malloc segment.
  1218. X *
  1219. X * This function takes into account the amount of offset into the specified
  1220. X * segment the new malloc pointer will have to be in order to be aligned
  1221. X * on the correct boundry.
  1222. X */
  1223. Xint
  1224. XAlignedFit(mptr,align,size)
  1225. X    struct mlist    * mptr;
  1226. X    SIZETYPE      align;
  1227. X    SIZETYPE      size;
  1228. X{
  1229. X    int          fit;
  1230. X    SIZETYPE      offset;
  1231. X
  1232. X    offset = AlignedOffset(mptr,align);
  1233. X
  1234. X    fit = mptr->s.size - (offset + size);
  1235. X
  1236. X    return( fit );
  1237. X
  1238. X} /* AlignedFit(... */
  1239. X
  1240. X/*
  1241. X * AlignedMakeSeg() - make a new segment at the correct offset within
  1242. X *               the specified old segment such that this new 
  1243. X *              segment will have it's data pointer aligned at the
  1244. X *              correct offset.
  1245. X */
  1246. X
  1247. Xstruct mlist *
  1248. XAlignedMakeSeg(mptr,align)
  1249. X    struct mlist     * mptr;
  1250. X    SIZETYPE      align;
  1251. X{
  1252. X    struct mlist    * newptr;
  1253. X    SIZETYPE      offset;
  1254. X
  1255. X    DEBUG2(10,"AlignedMakeSeg(0x%lx,%d) called...", mptr, align);
  1256. X
  1257. X    /*
  1258. X     * get the offset of the pointer which will ensure that we have
  1259. X     * a new segment with the correct alignment.
  1260. X     */
  1261. X    offset = AlignedOffset(mptr,align);
  1262. X
  1263. X    if( offset > mptr->s.size )
  1264. X    {
  1265. X        abort();
  1266. X    }
  1267. X    DEBUG2(20,"Adjusting space (0x%lx) by %d bytes to get alignment",
  1268. X        mptr->data, offset);
  1269. X
  1270. X    /*
  1271. X     * get a pointer to the new segment
  1272. X     */
  1273. X    newptr = (struct mlist *) (((char *)mptr) + offset);
  1274. X
  1275. X    /*
  1276. X     * initialize the new segment
  1277. X      */
  1278. X    InitMlist(newptr,M_T_SPLIT);
  1279. X
  1280. X    /*
  1281. X     * link in the new segment
  1282. X     */
  1283. X    newptr->prev = mptr;
  1284. X    newptr->next = mptr->next;
  1285. X    if( newptr->next )
  1286. X    {
  1287. X        newptr->next->prev = newptr;
  1288. X    }
  1289. X    mptr->next   = newptr;
  1290. X
  1291. X    /*
  1292. X     * set the size in the new segment
  1293. X     */
  1294. X    newptr->s.size = mptr->s.size - offset;
  1295. X    newptr->r_size = newptr->s.size;
  1296. X
  1297. X    /*
  1298. X     * set the size in the old segment
  1299. X     */
  1300. X    DEBUG2(20,"Adjusting old segment size from %d to %d",
  1301. X            mptr->s.size, offset-M_SIZE);
  1302. X    mptr->s.size = offset - M_SIZE;
  1303. X    mptr->r_size = mptr->s.size;
  1304. X
  1305. X    /*
  1306. X     * if mptr was the end of the list, newptr is the new end.
  1307. X     */
  1308. X    if( mptr == malloc_end )
  1309. X    {
  1310. X        malloc_end = newptr;
  1311. X    }
  1312. X
  1313. X    return(newptr);
  1314. X
  1315. X} /* AlignedMakeSeg(... */
  1316. X
  1317. X/*
  1318. X * AlignedOffset() - calculate the offset from the current data pointer to
  1319. X *             a new data pointer that will have the specified
  1320. X *             alignment
  1321. X */
  1322. XSIZETYPE
  1323. XAlignedOffset(mptr,align)
  1324. X    struct mlist    * mptr;
  1325. X    SIZETYPE      align;
  1326. X{
  1327. X    SIZETYPE      offset;
  1328. X
  1329. X    /*
  1330. X     * figure out the offset between the current data pointer and the next
  1331. X     * correctly aligned location
  1332. X     */
  1333. X    offset = align - (((SIZETYPE)mptr->data) & (align-1));
  1334. X
  1335. X    /*
  1336. X     * keep incrementing the offset until we have at least the malloc
  1337. X     * struct overhead in the offset (so we can make a new segment at
  1338. X     * the begining of this segment
  1339. X     */
  1340. X    while( offset < sizeof(struct mlist) )
  1341. X    {
  1342. X        offset += align;
  1343. X    }
  1344. X
  1345. X    return(offset);
  1346. X}
  1347. X
  1348. END_OF_FILE
  1349. if test 5428 -ne `wc -c <'malign.c'`; then
  1350.     echo shar: \"'malign.c'\" unpacked with wrong size!
  1351. fi
  1352. # end of 'malign.c'
  1353. fi
  1354. if test -f 'malloc.h.org' -a "${1}" != "-c" ; then 
  1355.   echo shar: Will not clobber existing file \"'malloc.h.org'\"
  1356. else
  1357. echo shar: Extracting \"'malloc.h.org'\" \(19660 characters\)
  1358. sed "s/^X//" >'malloc.h.org' <<'END_OF_FILE'
  1359. X/*
  1360. X * (c) Copyright 1990, 1991, 1992 Conor P. Cahill (cpcahil@virtech.vti.com)
  1361. X *
  1362. X * This software may be distributed freely as long as the following conditions
  1363. X * are met:
  1364. X *         * the distribution, or any derivative thereof, may not be
  1365. X *          included as part of a commercial product
  1366. X *        * full source code is provided including this copyright
  1367. X *        * there is no charge for the software itself (there may be
  1368. X *          a minimal charge for the copying or distribution effort)
  1369. X *        * this copyright notice is not modified or removed from any
  1370. X *          source file
  1371. X */
  1372. X/*
  1373. X * $Id: malloc.h.org,v 1.38 1992/08/22 16:27:13 cpcahil Exp $
  1374. X */
  1375. X
  1376. X#ifndef _DEBUG_MALLOC_INC
  1377. X#define _DEBUG_MALLOC_INC 1
  1378. X
  1379. X#ifdef    force_cproto_to_use_defines
  1380. X
  1381. X/*
  1382. X * these are just here because cproto used the c-preprocessor to generate
  1383. X * the prototypes and if they were left as #defines the prototypes.h file
  1384. X * would have the contents of the define, not the define itself
  1385. X */
  1386. X
  1387. Xtypedef char        DATATYPE;
  1388. Xtypedef int        SIZETYPE;
  1389. Xtypedef void        VOIDTYPE;
  1390. Xtypedef char        MEMDATA;
  1391. Xtypedef int        MEMSIZE;
  1392. Xtypedef int        STRSIZE;
  1393. Xtypedef int        FREETYPE;
  1394. Xtypedef int        EXITTYPE;
  1395. X
  1396. X#ifdef WRTSIZE
  1397. X#undef WRTSIZE
  1398. X#endif
  1399. Xtypedef unsigned int    WRTSIZE;
  1400. X
  1401. X/*
  1402. X * for now, define CONST as const.  A sed script in the makefile will change 
  1403. X * this back to CONST in the prototypes.h file.
  1404. X */
  1405. X#define CONST const
  1406. X
  1407. X#else  /* force_cproto_to_use_defines */
  1408. X
  1409. X/*
  1410. X * The following entries are automatically added by the Configure script.
  1411. X * If they are not correct for your system, then Configure is not handling
  1412. X * your system correctly.  Please report this to the author along with
  1413. X * a description of your system and the correct values
  1414. X */
  1415. X
  1416. XDATATYPES_MARKER
  1417. X
  1418. X/*
  1419. X * END of automatic configuration stuff.
  1420. X */
  1421. X
  1422. X/*
  1423. X * if DATATYPE is not defined, then the configure script must have had a 
  1424. X * problem, or was used with a different compiler.  So we have to stop
  1425. X * here and get the user to fix the problem.
  1426. X */
  1427. X#ifndef   DATATYPE
  1428. X    /*
  1429. X     * the following string should cause a comilation error and get the
  1430. X     * user to look at this stuff to find out what is wrong.
  1431. X     */
  1432. X    "This file is not configured correctly for this system. Run configure
  1433. X     and check its results"
  1434. X    char * malloc(); /* DON'T REMOVE THIS LINE if you get a compiler error
  1435. X                here it is because the malloc.h file is not 
  1436. X                configured correctly  See the readme/problems
  1437. X                files for more info */
  1438. X
  1439. X#endif /* DATATYPE */
  1440. X
  1441. X#endif /* force_cproto_to_use_defines */
  1442. X
  1443. X#define VOIDCAST (VOIDTYPE)
  1444. X
  1445. X/*
  1446. X * since we redefine much of the stuff that is #defined in string.h and 
  1447. X * memory.h, we should do what we can to make sure that they don't get 
  1448. X * included after us.  This is typically accomplished by a special symbol
  1449. X * (similar to _DEBUG_MALLOC_INC defined above) that is #defined when the
  1450. X * file is included.  Since we don't want the file to be included we will
  1451. X * #define the symbol ourselves.  These will typically have to change from
  1452. X * one system to another.  I have put in several standard mechanisms used to
  1453. X * support this mechanism, so hopefully you won't have to modify this file.
  1454. X */
  1455. X#ifndef _H_STRING
  1456. X#define _H_STRING        1
  1457. X#endif 
  1458. X#ifndef __STRING_H
  1459. X#define __STRING_H        1
  1460. X#endif 
  1461. X#ifndef _STRING_H_
  1462. X#define _STRING_H_        1
  1463. X#endif 
  1464. X#ifndef _STRING_H 
  1465. X#define _STRING_H         1
  1466. X#endif 
  1467. X#ifndef _STRING_INCLUDED
  1468. X#define _STRING_INCLUDED    1
  1469. X#endif
  1470. X#ifndef __string_h
  1471. X#define __string_h        1
  1472. X#endif
  1473. X#ifndef _string_h
  1474. X#define _string_h        1
  1475. X#endif
  1476. X#ifndef __string_h__
  1477. X#define __string_h__        1
  1478. X#endif
  1479. X#ifndef _strings_h
  1480. X#define _strings_h        1
  1481. X#endif
  1482. X#ifndef __strings_h
  1483. X#define __strings_h        1
  1484. X#endif
  1485. X#ifndef __strings_h__
  1486. X#define __strings_h__        1
  1487. X#endif
  1488. X#ifndef _H_MEMORY
  1489. X#define _H_MEMORY        1
  1490. X#endif
  1491. X#ifndef __MEMORY_H
  1492. X#define __MEMORY_H        1
  1493. X#endif
  1494. X#ifndef _MEMORY_H_
  1495. X#define _MEMORY_H_        1
  1496. X#endif
  1497. X#ifndef _MEMORY_H
  1498. X#define _MEMORY_H        1
  1499. X#endif
  1500. X#ifndef _MEMORY_INCLUDED
  1501. X#define _MEMORY_INCLUDED    1
  1502. X#endif
  1503. X#ifndef __memory_h
  1504. X#define __memory_h        1
  1505. X#endif
  1506. X#ifndef _memory_h
  1507. X#define _memory_h        1
  1508. X#endif
  1509. X#ifndef __memory_h__
  1510. X#define __memory_h__        1
  1511. X#endif
  1512. X
  1513. X/*
  1514. X * for NCR, we need to disable their in-line expansion of the str* routines
  1515. X */
  1516. X#define ISTRING    1
  1517. X
  1518. X/*
  1519. X * Malloc warning/fatal error handler defines...
  1520. X */
  1521. X#define M_HANDLE_DUMP    0x80  /* 128 */
  1522. X#define M_HANDLE_IGNORE    0
  1523. X#define M_HANDLE_ABORT    1
  1524. X#define M_HANDLE_EXIT    2
  1525. X#define M_HANDLE_CORE    3
  1526. X    
  1527. X/*
  1528. X * Mallopt commands and defaults
  1529. X *
  1530. X * the first four settings are ignored by the debugging dbmallopt, but are
  1531. X * here to maintain compatibility with the system malloc.h.
  1532. X */
  1533. X#define M_MXFAST    1        /* ignored by mallopt        */
  1534. X#define M_NLBLKS    2        /* ignored by mallopt        */
  1535. X#define M_GRAIN        3        /* ignored by mallopt        */
  1536. X#define M_KEEP        4        /* ignored by mallopt        */
  1537. X#define MALLOC_WARN    100        /* set malloc warning handling    */
  1538. X#define MALLOC_FATAL    101        /* set malloc fatal handling    */
  1539. X#define MALLOC_ERRFILE    102        /* specify malloc error file    */
  1540. X#define MALLOC_CKCHAIN    103        /* turn on chain checking    */
  1541. X#define MALLOC_FILLAREA    104        /* turn off area filling    */
  1542. X#define MALLOC_LOWFRAG    105        /* use best fit allocation mech    */
  1543. X#define MALLOC_CKDATA    106        /* turn off/on data checking    */
  1544. X#define MALLOC_REUSE    107        /* turn off/on freed seg reuse    */
  1545. X#define MALLOC_SHOWLINKS 108        /* turn off/on adjacent link disp */
  1546. X#define MALLOC_DETAIL    109        /* turn off/on detail output    */
  1547. X#define MALLOC_FREEMARK    110        /* warn about freeing marked segs*/
  1548. X#define MALLOC_ZERO    111        /* warn about zero len allocs    */
  1549. X
  1550. Xunion dbmalloptarg
  1551. X{
  1552. X    int      i;
  1553. X    char    * str;
  1554. X};
  1555. X
  1556. X/*
  1557. X * disable the standard mallopt function
  1558. X */
  1559. X#define mallopt(a,b)    (0)
  1560. X
  1561. X/*
  1562. X * Malloc warning/fatal error codes
  1563. X */
  1564. X#define M_CODE_CHAIN_BROKE    1    /* malloc chain is broken    */
  1565. X#define M_CODE_NO_END        2    /* chain end != endptr        */
  1566. X#define M_CODE_BAD_PTR        3    /* pointer not in malloc area    */
  1567. X#define M_CODE_BAD_MAGIC    4    /* bad magic number in header    */
  1568. X#define M_CODE_BAD_CONNECT    5    /* chain poingers corrupt    */
  1569. X#define M_CODE_OVERRUN        6    /* data overrun in malloc seg    */
  1570. X#define M_CODE_REUSE        7    /* reuse of freed area        */
  1571. X#define M_CODE_NOT_INUSE    8    /* pointer is not in use    */
  1572. X#define M_CODE_NOMORE_MEM    9    /* no more memory available    */
  1573. X#define M_CODE_OUTOF_BOUNDS    10    /* gone beyound bounds         */
  1574. X#define M_CODE_FREELIST_BAD    11    /* inuse segment on freelist    */
  1575. X#define M_CODE_NOBOUND        12    /* can't calculate boundry    */
  1576. X#define M_CODE_STK_NOCUR    13    /* no current element on stack    */
  1577. X#define M_CODE_STK_BADFUNC    14    /* current func doesn't match    */
  1578. X#define M_CODE_UNDERRUN        15    /* data underrun in malloc seg    */
  1579. X#define M_CODE_FREEMARK        16    /* free of marked segment    */
  1580. X#define M_CODE_ZERO_ALLOC    17    /* zero length allocation    */
  1581. X
  1582. X#ifndef __STDCARGS
  1583. X#if  __STDC__ || __cplusplus
  1584. X#define __STDCARGS(a) a
  1585. X#else
  1586. X#define __STDCARGS(a) ()
  1587. X#endif
  1588. X#endif
  1589. X
  1590. X#if __cplusplus
  1591. Xextern "C" {
  1592. X#endif
  1593. X
  1594. XVOIDTYPE      malloc_dump __STDCARGS((int));
  1595. XVOIDTYPE      malloc_list __STDCARGS((int,unsigned long, unsigned long));
  1596. Xint          dbmallopt __STDCARGS((int, union dbmalloptarg *));
  1597. XDATATYPE    * debug_calloc __STDCARGS((CONST char *,int,SIZETYPE,SIZETYPE));
  1598. XFREETYPE      debug_cfree __STDCARGS((CONST char *, int, DATATYPE *));
  1599. XFREETYPE      debug_free __STDCARGS((CONST char *, int, DATATYPE *));
  1600. XDATATYPE    * debug_malloc __STDCARGS((CONST char *,int, SIZETYPE));
  1601. XDATATYPE    * debug_realloc __STDCARGS((CONST char *,int,
  1602. X                        DATATYPE *,SIZETYPE));
  1603. XVOIDTYPE      DBmalloc_mark __STDCARGS((CONST char *,int, DATATYPE *));
  1604. Xunsigned long      DBmalloc_inuse __STDCARGS((CONST char *,int,
  1605. X                        unsigned long *));
  1606. Xint          DBmalloc_chain_check __STDCARGS((CONST char *,int,int));
  1607. XSIZETYPE      DBmalloc_size __STDCARGS((CONST char *,int,CONST DATATYPE *));
  1608. XDATATYPE    * DBmemalign __STDCARGS((CONST char *, int,SIZETYPE, SIZETYPE));
  1609. Xvoid          StackEnter __STDCARGS((CONST char *, CONST char *, int));
  1610. Xvoid          StackLeave __STDCARGS((CONST char *, CONST char *, int));
  1611. X
  1612. X/*
  1613. X * X allocation related prototypes
  1614. X */
  1615. Xchar        * debug_XtMalloc __STDCARGS((CONST char *, int, unsigned int));
  1616. Xchar        * debug_XtRealloc __STDCARGS((CONST char *, int,
  1617. X                        char *, unsigned int));
  1618. Xchar        * debug_XtCalloc __STDCARGS((CONST char *, int,
  1619. X                        unsigned int, unsigned int));
  1620. Xvoid          debug_XtFree __STDCARGS((CONST char *, int, char *));
  1621. Xvoid        * debug_XtBCopy  __STDCARGS((CONST char *, int, char *,
  1622. X                        char *, int));
  1623. Xextern void    (*XtAllocErrorHandler) __STDCARGS((CONST char *));
  1624. X
  1625. X/*
  1626. X * memory(3) related prototypes
  1627. X */
  1628. XMEMDATA      * DBmemccpy __STDCARGS((CONST char *file, int line,
  1629. X                    MEMDATA  *ptr1, CONST MEMDATA  *ptr2,
  1630. X                    int ch, MEMSIZE len));
  1631. XMEMDATA      * DBmemchr __STDCARGS((CONST char *file, int line,
  1632. X                    CONST MEMDATA  *ptr1, int ch,
  1633. X                    MEMSIZE len));
  1634. XMEMDATA     * DBmemmove __STDCARGS((CONST char *file, int line,
  1635. X                    MEMDATA  *ptr1, CONST MEMDATA  *ptr2,
  1636. X                    MEMSIZE len));
  1637. XMEMDATA     * DBmemcpy __STDCARGS((CONST char *file, int line,
  1638. X                    MEMDATA  *ptr1, CONST MEMDATA  *ptr2,
  1639. X                    MEMSIZE len));
  1640. Xint          DBmemcmp __STDCARGS((CONST char *file, int line,
  1641. X                    CONST MEMDATA  *ptr1,
  1642. X                    CONST MEMDATA  *ptr2, MEMSIZE len));
  1643. XMEMDATA     * DBmemset __STDCARGS((CONST char *file, int line,
  1644. X                    MEMDATA  *ptr1, int ch, MEMSIZE len));
  1645. XMEMDATA     * DBbcopy __STDCARGS((CONST char *file, int line,
  1646. X                    CONST MEMDATA  *ptr2, MEMDATA  *ptr1,
  1647. X                    MEMSIZE len));
  1648. XMEMDATA      * DBbzero __STDCARGS((CONST char *file, int line,
  1649. X                    MEMDATA  *ptr1, MEMSIZE len));
  1650. Xint          DBbcmp __STDCARGS((CONST char *file, int line,
  1651. X                    CONST MEMDATA  *ptr2,
  1652. X                    CONST MEMDATA  *ptr1, MEMSIZE len));
  1653. X
  1654. X/*
  1655. X * string(3) related prototypes
  1656. X */
  1657. Xchar        * DBstrcat __STDCARGS((CONST char *file,int line, char *str1,
  1658. X                    CONST char *str2));
  1659. Xchar        * DBstrdup __STDCARGS((CONST char *file, int line,
  1660. X                    CONST char *str1));
  1661. Xchar        * DBstrncat __STDCARGS((CONST char *file, int line, char *str1,
  1662. X                    CONST char *str2, STRSIZE len));
  1663. Xint          DBstrcmp __STDCARGS((CONST char *file, int line,
  1664. X                    CONST char *str1, CONST char *str2));
  1665. Xint          DBstrncmp __STDCARGS((CONST char *file, int line,
  1666. X                    CONST char *str1, CONST char *str2,
  1667. X                    STRSIZE len));
  1668. Xint          DBstricmp __STDCARGS((CONST char *file, int line,
  1669. X                    CONST char *str1, CONST char *str2));
  1670. Xint          DBstrincmp __STDCARGS((CONST char *file, int line,
  1671. X                    CONST char *str1, CONST char *str2,
  1672. X                    STRSIZE len));
  1673. Xchar        * DBstrcpy __STDCARGS((CONST char *file, int line, char *str1,
  1674. X                    CONST char *str2));
  1675. Xchar        * DBstrncpy __STDCARGS((CONST char *file, int line, char *str1,
  1676. X                    CONST char *str2, STRSIZE len));
  1677. XSTRSIZE          DBstrlen __STDCARGS((CONST char *file, int line,
  1678. X                    CONST char *str1));
  1679. Xchar        * DBstrchr __STDCARGS((CONST char *file, int line,
  1680. X                    CONST char *str1, int c));
  1681. Xchar        * DBstrrchr __STDCARGS((CONST char *file, int line,
  1682. X                    CONST char *str1, int c));
  1683. Xchar        * DBindex __STDCARGS((CONST char *file, int line,
  1684. X                    CONST char *str1, int c));
  1685. Xchar        * DBrindex __STDCARGS((CONST char *file, int line,
  1686. X                    CONST char *str1, int c));
  1687. Xchar        * DBstrpbrk __STDCARGS((CONST char *file, int line,
  1688. X                    CONST char *str1, CONST char *str2));
  1689. XSTRSIZE          DBstrspn __STDCARGS((CONST char *file, int line,
  1690. X                    CONST char *str1, CONST char *str2));
  1691. XSTRSIZE          DBstrcspn __STDCARGS((CONST char *file, int line,
  1692. X                    CONST char *str1, CONST char *str2));
  1693. Xchar        * DBstrstr __STDCARGS((CONST char *file, int line,
  1694. X                    CONST char *str1, CONST char *str2));
  1695. Xchar        * DBstrtok __STDCARGS((CONST char *file, int line, char *str1,
  1696. X                    CONST char *str2));
  1697. X
  1698. X#if __cplusplus
  1699. X};
  1700. X#endif
  1701. X
  1702. X/*
  1703. X * Macro which enables logging of the file and line number for each allocation
  1704. X * so that it is easier to determine where the offending malloc comes from.
  1705. X *
  1706. X * NOTE that only code re-compiled with this include file will have this 
  1707. X * additional info.  Calls from libraries that have not been recompiled will
  1708. X * just have a null string for this info.
  1709. X */
  1710. X#ifndef IN_MALLOC_CODE
  1711. X
  1712. X/*
  1713. X * allocation functions
  1714. X */
  1715. X#define malloc(len)        debug_malloc( __FILE__,__LINE__, (len))
  1716. X#define realloc(ptr,len)    debug_realloc(__FILE__,__LINE__, (ptr), (len))
  1717. X#define calloc(numelem,size)    debug_calloc(__FILE__,__LINE__,(numelem),(size))
  1718. X#define cfree(ptr)        debug_cfree(__FILE__,__LINE__,(ptr))
  1719. X#define free(ptr)        debug_free(__FILE__,__LINE__,(ptr))
  1720. X#define malloc_chain_check(do)  DBmalloc_chain_check(__FILE__,__LINE__,(do))
  1721. X#define malloc_mark(ptr)    DBmalloc_mark(__FILE__,__LINE__,(ptr))
  1722. X#define malloc_inuse(histptr)    DBmalloc_inuse(__FILE__,__LINE__,(histptr))
  1723. X#define malloc_size(ptr)    DBmalloc_size(__FILE__,__LINE__,(ptr))
  1724. X#define memalign(align,size)    DBmemalign(__FILE__,__LINE__,(align),(size))
  1725. X
  1726. X/* 
  1727. X * X allocation routines
  1728. X */
  1729. X#define XtCalloc(_num,_size)    debug_XtCalloc(__FILE__,__LINE__,_num,_size)
  1730. X#define XtMalloc(_size)        debug_XtMalloc(__FILE__,__LINE__,_size)
  1731. X#define XtRealloc(_ptr,_size)    debug_XtRealloc(__FILE__,__LINE__,_ptr,_size)
  1732. X#define XtFree(_ptr)        debug_XtFree(__FILE__,__LINE__,_ptr)
  1733. X#define _XtBCopy(ptr1,ptr2,len) debug_XtBcopy(__FILE__,__LINE__,ptr1,ptr2,len)
  1734. X
  1735. X/*
  1736. X * Other allocation functions
  1737. X */
  1738. X#define _malloc(_size)        debug_malloc(__FILE__,__LINE__,_size)
  1739. X#define _realloc(_ptr,_size)    debug_realloc(__FILE__,__LINE__,_ptr,_size)
  1740. X#define _calloc(_num,_size)    debug_calloc(__FILE__,__LINE__,_num,_size)
  1741. X#define _free(_ptr)        debug_free(__FILE__,__LINE__,_ptr)
  1742. X
  1743. X/*
  1744. X * memory(3) related functions
  1745. X */
  1746. X#ifdef bcopy
  1747. X#undef bcopy
  1748. X#endif
  1749. X#ifdef bzero
  1750. X#undef bzero
  1751. X#endif
  1752. X#ifdef bcmp
  1753. X#undef bcmp
  1754. X#endif
  1755. X#define memccpy(ptr1,ptr2,ch,len) DBmemccpy(__FILE__,__LINE__,ptr1,ptr2,ch,len)
  1756. X#define memchr(ptr1,ch,len)      DBmemchr(__FILE__,__LINE__,ptr1,ch,len)
  1757. X#define memmove(ptr1,ptr2,len)    DBmemmove(__FILE__,__LINE__,ptr1, ptr2, len)
  1758. X#define memcpy(ptr1,ptr2,len)     DBmemcpy(__FILE__, __LINE__, ptr1, ptr2, len)
  1759. X#define memcmp(ptr1,ptr2,len)     DBmemcmp(__FILE__,__LINE__,ptr1, ptr2, len)
  1760. X#define memset(ptr1,ch,len)       DBmemset(__FILE__,__LINE__,ptr1, ch, len)
  1761. X#define bcopy(ptr2,ptr1,len)      DBbcopy(__FILE__,__LINE__,ptr2,ptr1,len)
  1762. X#define bzero(ptr1,len)           DBbzero(__FILE__,__LINE__,ptr1,len)
  1763. X#define bcmp(ptr2,ptr1,len)       DBbcmp(__FILE__, __LINE__, ptr2, ptr1, len)
  1764. X
  1765. X#define _bcopy(ptr2,ptr1,len)     DBbcopy(__FILE__,__LINE__,ptr2,ptr1,len)
  1766. X#define _bzero(ptr1,len)          DBbzero(__FILE__,__LINE__,ptr1,len)
  1767. X#define _bcmp(ptr2,ptr1,len)      DBbcmp(__FILE__,__LINE__,ptr2,ptr1,len)
  1768. X#define __dg_bcopy(ptr2,ptr1,len) DBbcopy(__FILE__,__LINE__,ptr2,ptr1,len)
  1769. X#define __dg_bzero(ptr1,len)      DBbzero(__FILE__,__LINE__,ptr1,len)
  1770. X#define __dg_bcmp(ptr2,ptr1,len)  DBbcmp(__FILE__,__LINE__,ptr2,ptr1,len)
  1771. X
  1772. X/*
  1773. X * string(3) related functions
  1774. X */
  1775. X#ifdef index
  1776. X#undef index
  1777. X#endif
  1778. X#ifdef rindex
  1779. X#undef rindex
  1780. X#endif
  1781. X#ifdef strcpy
  1782. X#undef strcpy
  1783. X#endif
  1784. X#ifdef strcpy
  1785. X#undef strcmp
  1786. X#endif
  1787. X#define index(str1,c)          DBindex(__FILE__, __LINE__, str1, c)
  1788. X#define rindex(str1,c)          DBrindex(__FILE__, __LINE__, str1, c)
  1789. X#define strcat(str1,str2)      DBstrcat(__FILE__,__LINE__,str1,str2)
  1790. X#define strchr(str1,c)          DBstrchr(__FILE__, __LINE__, str1,c)
  1791. X#define strcmp(str1,str2)      DBstrcmp(__FILE__, __LINE__, str1, str2)
  1792. X#define strcpy(str1,str2)      DBstrcpy(__FILE__, __LINE__, str1, str2)
  1793. X#define strcspn(str1,str2)      DBstrcspn(__FILE__, __LINE__, str1,str2)
  1794. X#define strdup(str1)          DBstrdup(__FILE__, __LINE__, str1)
  1795. X#define stricmp(str1,str2)      DBstricmp(__FILE__, __LINE__, str1, str2)
  1796. X#define strincmp(str1,str2,len)      DBstrincmp(__FILE__, __LINE__, str1,str2,len)
  1797. X#define strlen(str1)          DBstrlen(__FILE__, __LINE__, str1)
  1798. X#define strncat(str1,str2,len)      DBstrncat(__FILE__, __LINE__, str1,str2,len)
  1799. X#define strncpy(str1,str2,len)      DBstrncpy(__FILE__,__LINE__,str1,str2,len)
  1800. X#define strncmp(str1,str2,len)      DBstrncmp(__FILE__, __LINE__, str1,str2,len)
  1801. X#define strpbrk(str1,str2)      DBstrpbrk(__FILE__, __LINE__, str1,str2)
  1802. X#define strrchr(str1,c)          DBstrrchr(__FILE__,__LINE__,str1,c)
  1803. X#define strspn(str1,str2)      DBstrspn(__FILE__, __LINE__, str1,str2)
  1804. X#define strstr(str1,str2)      DBstrstr(__FILE__, __LINE__, str1, str2)
  1805. X#define strtok(str1,str2)      DBstrtok(__FILE__, __LINE__, str1, str2)
  1806. X
  1807. X/*
  1808. X * malloc stack related functions
  1809. X */
  1810. X#define malloc_enter(func)      StackEnter(func,__FILE__,__LINE__)
  1811. X#define malloc_leave(func)      StackLeave(func,__FILE__,__LINE__)
  1812. X
  1813. X#endif /* IN_MALLOC_CODE */
  1814. X
  1815. X#endif /* _DEBUG_MALLOC_INC */
  1816. X
  1817. X/*
  1818. X * $Log: malloc.h.org,v $
  1819. X * Revision 1.38  1992/08/22  16:27:13  cpcahil
  1820. X * final changes for pl14
  1821. X *
  1822. X * Revision 1.37  1992/08/18  11:42:00  cpcahil
  1823. X * added more #defs to preclude memory/string.h inclusion
  1824. X *
  1825. X * Revision 1.36  1992/07/12  15:30:58  cpcahil
  1826. X * Merged in Jonathan I Kamens' changes
  1827. X *
  1828. X * Revision 1.35  1992/07/03  00:03:25  cpcahil
  1829. X * more fixes for pl13, several suggestons from Rich Salz.
  1830. X *
  1831. X * Revision 1.34  1992/07/02  15:35:52  cpcahil
  1832. X * misc cleanups for PL13
  1833. X *
  1834. X * Revision 1.33  1992/07/02  13:49:54  cpcahil
  1835. X * added support for new malloc_size function and additional tests to testerr
  1836. X *
  1837. X * Revision 1.32  1992/06/30  13:06:39  cpcahil
  1838. X * added support for aligned allocations
  1839. X *
  1840. X * Revision 1.31  1992/06/22  23:40:10  cpcahil
  1841. X * many fixes for working on small int systems
  1842. X *
  1843. X * Revision 1.30  1992/05/06  04:53:29  cpcahil
  1844. X * performance enhancments
  1845. X *
  1846. X * Revision 1.29  1992/04/22  18:17:32  cpcahil
  1847. X * added support for Xt Alloc functions, linted code
  1848. X *
  1849. X * Revision 1.28  1992/04/13  19:08:18  cpcahil
  1850. X * fixed case insensitive stuff
  1851. X *
  1852. X * Revision 1.27  1992/04/13  18:41:18  cpcahil
  1853. X * added case insensitive string comparison routines
  1854. X *
  1855. X * Revision 1.26  1992/04/13  17:26:25  cpcahil
  1856. X * minor portability changes
  1857. X *
  1858. X * Revision 1.25  1992/04/13  14:13:18  cpcahil
  1859. X * cleanup of log message.
  1860. X *
  1861. X * Revision 1.24  1992/04/13  03:09:14  cpcahil
  1862. X * lots of changes.
  1863. X *
  1864. X * Revision 1.23  1992/03/01  12:42:38  cpcahil
  1865. X * added support for managing freed areas and fixed doublword bndr problems
  1866. X *
  1867. X * Revision 1.22  1992/02/07  15:51:07  cpcahil
  1868. X * mods for sun4
  1869. X *
  1870. X * Revision 1.21  1992/01/29  01:35:32  cpcahil
  1871. X * added sgi definition.
  1872. X *
  1873. X * Revision 1.20  1992/01/28  21:42:25  cpcahil
  1874. X * changes for the ibmRS6000
  1875. X *
  1876. X * Revision 1.19  1992/01/28  18:05:37  cpcahil
  1877. X * misc fixes for patch 7
  1878. X *
  1879. X * Revision 1.18  1992/01/22  16:21:35  cpcahil
  1880. X * added code to prevent inclusions of string.h and memory.h after malloc.h
  1881. X * was included.
  1882. X *
  1883. X * Revision 1.17  1992/01/10  17:26:46  cpcahil
  1884. X * fixed prototypes use of void.
  1885. X *
  1886. X * Revision 1.16  1992/01/10  16:53:39  cpcahil
  1887. X * added more info on sizetype and datatype. added support for overriding
  1888. X * use of void type.
  1889. X *
  1890. X * Revision 1.15  1992/01/09  17:19:11  cpcahil
  1891. X * put the close brace in the correct position.
  1892. X *
  1893. X * Revision 1.14  1992/01/09  17:12:36  cpcahil
  1894. X * added code to support inclusion in C++ modules
  1895. X *
  1896. X * Revision 1.13  1991/12/31  21:31:26  cpcahil
  1897. X * changes for patch 6.  See CHANGES file for more info
  1898. X *
  1899. X * Revision 1.12  1991/12/26  22:31:29  cpcahil
  1900. X * added check to make sure file is not included twice.
  1901. X *
  1902. X * Revision 1.11  1991/12/06  17:58:46  cpcahil
  1903. X * added cfree() for compatibility with some wierd systems
  1904. X *
  1905. X * Revision 1.10  91/12/06  08:54:18  cpcahil
  1906. X * cleanup of __STDC__ usage and addition of CHANGES file
  1907. X * 
  1908. X * Revision 1.9  91/12/04  09:23:40  cpcahil
  1909. X * several performance enhancements including addition of free list
  1910. X * 
  1911. X * Revision 1.8  91/12/02  19:10:11  cpcahil
  1912. X * changes for patch release 5
  1913. X * 
  1914. X * Revision 1.7  91/11/25  14:42:00  cpcahil
  1915. X * Final changes in preparation for patch 4 release
  1916. X * 
  1917. X * Revision 1.6  91/11/24  00:49:28  cpcahil
  1918. X * first cut at patch 4
  1919. X * 
  1920. X * Revision 1.5  91/11/20  11:54:10  cpcahil
  1921. X * interim checkin
  1922. X * 
  1923. X * Revision 1.4  90/08/29  22:23:38  cpcahil
  1924. X * fixed mallopt to use a union as an argument.
  1925. X * 
  1926. X * Revision 1.3  90/05/11  11:04:10  cpcahil
  1927. X * took out some extraneous lines
  1928. X * 
  1929. X * Revision 1.2  90/05/11  00:13:09  cpcahil
  1930. X * added copyright statment
  1931. X * 
  1932. X * Revision 1.1  90/02/23  07:09:03  cpcahil
  1933. X * Initial revision
  1934. X * 
  1935. X */
  1936. END_OF_FILE
  1937. if test 19660 -ne `wc -c <'malloc.h.org'`; then
  1938.     echo shar: \"'malloc.h.org'\" unpacked with wrong size!
  1939. fi
  1940. # end of 'malloc.h.org'
  1941. fi
  1942. echo shar: End of archive 4 \(of 10\).
  1943. cp /dev/null ark4isdone
  1944. MISSING=""
  1945. for I in 1 2 3 4 5 6 7 8 9 10 ; do
  1946.     if test ! -f ark${I}isdone ; then
  1947.     MISSING="${MISSING} ${I}"
  1948.     fi
  1949. done
  1950. if test "${MISSING}" = "" ; then
  1951.     echo You have unpacked all 10 archives.
  1952.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1953. else
  1954.     echo You still need to unpack the following archives:
  1955.     echo "        " ${MISSING}
  1956. fi
  1957. ##  End of shell archive.
  1958. exit 0
  1959. *** SENTINEL(tm) The ultimate Debugging Environment - email for more info ***
  1960.  
  1961. Conor P. Cahill              (703)430-9247            cpcahil@virtech.vti.com
  1962. Virtual Technologies, Inc.  46030 Manekin Plaza          Dulles, VA 21066 
  1963.  
  1964. exit 0 # Just in case...
  1965.