home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sources / misc / 3900 < prev    next >
Encoding:
Text File  |  1992-09-03  |  54.3 KB  |  1,971 lines

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