home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sources / misc / 3905 < prev    next >
Encoding:
Text File  |  1992-09-04  |  48.2 KB  |  2,147 lines

  1. Newsgroups: comp.sources.misc
  2. Path: sparky!kent
  3. From: cpcahil@vti.com (Conor P. Cahill)
  4. Subject:  v32i014:  dbmalloc - Debug Malloc Library PL14, Part09/10
  5. Message-ID: <1992Sep4.152359.13562@sparky.imd.sterling.com>
  6. Followup-To: comp.sources.d
  7. X-Md4-Signature: 4ad69faaf2548893877deaf388c97c00
  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:23:59 GMT
  12. Approved: kent@sparky.imd.sterling.com
  13. Lines: 2132
  14.  
  15. Submitted-by: cpcahil@vti.com (Conor P. Cahill)
  16. Posting-number: Volume 32, Issue 14
  17. Archive-name: dbmalloc/part09
  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 9 (of 10)."
  27. # Contents:  string.c testerr.base testmalloc.c tostring.c xheap.c
  28. #   xmalloc.c
  29. # Wrapped by cpcahil@virtech on Thu Sep  3 18:39:21 1992
  30. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  31. if test -f 'string.c' -a "${1}" != "-c" ; then 
  32.   echo shar: Will not clobber existing file \"'string.c'\"
  33. else
  34. echo shar: Extracting \"'string.c'\" \(20827 characters\)
  35. sed "s/^X//" >'string.c' <<'END_OF_FILE'
  36. X
  37. X/*
  38. X * (c) Copyright 1990, 1991, 1992 Conor P. Cahill (cpcahil@virtech.vti.com)
  39. X *
  40. X * This software may be distributed freely as long as the following conditions
  41. X * are met:
  42. X *         * the distribution, or any derivative thereof, may not be
  43. X *          included as part of a commercial product
  44. X *        * full source code is provided including this copyright
  45. X *        * there is no charge for the software itself (there may be
  46. X *          a minimal charge for the copying or distribution effort)
  47. X *        * this copyright notice is not modified or removed from any
  48. X *          source file
  49. X */
  50. X
  51. X/*
  52. X * NOTE: if you have problems compiling this file, the first thing to try is
  53. X * to take out the include of string.h.  This is due to the fact that some
  54. X * systems (like ultrix) have conflicting definitions and some (like aix)
  55. X * even set up some of these functions to be in-lined.
  56. X */
  57. X
  58. X#include <stdio.h>
  59. X#if ! defined(_IBMR2) && ! defined(ultrix)
  60. X#include <string.h>
  61. X#endif
  62. X
  63. X#include "mallocin.h"
  64. X
  65. X
  66. X#include <ctype.h>
  67. X
  68. X#ifndef CTYPE_SUPPORT
  69. X#define CTYPE_SUPPORT 1
  70. X#endif
  71. X
  72. X#if CTYPE_SUPPORT == 3
  73. X
  74. X#undef islower
  75. X#undef isascii
  76. X#undef toupper
  77. X
  78. X#endif
  79. X
  80. X#if CTYPE_SUPPORT > 1
  81. X
  82. X#define isascii(a) 1
  83. X
  84. X#endif
  85. X
  86. X#if CTYPE_SUPPORT == 2
  87. X
  88. X#include <locale.h>
  89. X
  90. Xstatic int locale_initialized;
  91. X
  92. X#define INIT_CTYPE() (local_initialized ? 0 : \
  93. X             local_initialized++, setlocale(LC_CTYPE,"") )
  94. X
  95. X#else /* CTYPE_SUPPORT == 2 */
  96. X
  97. X#define INIT_CTYPE()
  98. X
  99. X#endif /* CTYPE_SUPPORT == 2 */
  100. X
  101. X#ifndef lint
  102. Xstatic
  103. Xchar rcs_hdr[] = "$Id: string.c,v 1.30 1992/08/22 16:27:13 cpcahil Exp $";
  104. X#endif
  105. X
  106. Xstatic int    in_string_code;
  107. X
  108. X#define CompareUpper(c) ((STRCMPTYPE) \
  109. X            (isascii((int)(unsigned char)(c)) \
  110. X                && islower( (int) (unsigned char)(c)) ? \
  111. X                toupper((int)(unsigned char)(c)) \
  112. X             /* else */ : \
  113. X                (c)))
  114. X
  115. X/*
  116. X * strcat - concatenate a string onto the end of another string
  117. X */
  118. Xchar *
  119. Xstrcat(str1,str2)
  120. X    char        * str1;
  121. X    CONST char    * str2;
  122. X{
  123. X    return( DBstrcat((char *)NULL,0,str1,str2) );
  124. X}
  125. X
  126. Xchar *
  127. XDBstrcat(file,line,str1,str2)
  128. X    CONST char        * file;
  129. X    int              line;
  130. X    register char        * str1;
  131. X    register CONST char    * str2;
  132. X{
  133. X    char            * rtn;
  134. X    SIZETYPE          len;
  135. X
  136. X    /* 
  137. X     * check pointers agains malloc region.  The malloc* functions
  138. X     * will properly handle the case where a pointer does not
  139. X     * point into malloc space.
  140. X     */
  141. X    in_string_code++;
  142. X
  143. X    len = strlen(str2);
  144. X    malloc_check_str("strcat", file, line, str2);
  145. X
  146. X    len += strlen(str1) + 1;
  147. X    in_string_code--;
  148. X
  149. X    malloc_check_data("strcat", file, line, str1, (SIZETYPE)len);
  150. X
  151. X    rtn = str1;
  152. X
  153. X    while( *str1 )
  154. X    {
  155. X        str1++;
  156. X    }
  157. X    
  158. X    while( (*str1 = *str2) != '\0' )
  159. X    {
  160. X        str1++;
  161. X        str2++;
  162. X    }
  163. X    
  164. X    return(rtn);
  165. X}
  166. X
  167. X/*
  168. X * strdup - duplicate a string
  169. X */
  170. Xchar *
  171. Xstrdup(str1)
  172. X    CONST char    * str1;
  173. X{
  174. X    return( DBstrdup((char *)NULL, 0, str1) );
  175. X}
  176. X
  177. Xchar *
  178. XDBstrdup(file, line, str1)
  179. X    CONST char        * file;
  180. X    int              line;
  181. X    register CONST char    * str1;
  182. X{
  183. X    char            * rtn;
  184. X    register char        * str2;
  185. X
  186. X    malloc_check_str("strdup", file, line, str1);
  187. X
  188. X    in_string_code++;
  189. X    rtn = str2 = malloc((SIZETYPE)strlen(str1)+1);
  190. X    in_string_code--;
  191. X
  192. X    if( rtn != (char *) 0)
  193. X    {
  194. X        while( (*str2 = *str1) != '\0' )
  195. X        {
  196. X            str1++;
  197. X            str2++;
  198. X        }
  199. X    }
  200. X
  201. X    return(rtn);
  202. X}
  203. X
  204. X/*
  205. X * strncat - concatenate a string onto the end of another up to a specified len
  206. X */
  207. Xchar *
  208. Xstrncat(str1,str2,len)
  209. X    char        * str1;
  210. X    CONST char    * str2;
  211. X    STRSIZE       len;
  212. X{
  213. X    return( DBstrncat((char *)NULL, 0, str1, str2, len) );
  214. X}
  215. X
  216. Xchar *
  217. XDBstrncat(file, line, str1, str2, len)
  218. X    CONST char        * file;
  219. X    int              line;
  220. X    register char        * str1;
  221. X    register CONST char    * str2;
  222. X    register STRSIZE       len;
  223. X{
  224. X    STRSIZE       len1;
  225. X    STRSIZE       len2;
  226. X    char        * rtn;
  227. X
  228. X    malloc_check_strn("strncat", file, line, str2, len);
  229. X
  230. X    in_string_code++;
  231. X
  232. X    len2 = strlen(str2) + 1;
  233. X    len1 = strlen(str1);
  234. X
  235. X    in_string_code--;
  236. X
  237. X
  238. X    if( (len+1) < len2 )
  239. X    {
  240. X        len1 += len + 1;
  241. X    }
  242. X    else
  243. X    {
  244. X        len1 += len2;
  245. X    }
  246. X    malloc_check_data("strncat", file, line, str1, (SIZETYPE)len1);
  247. X
  248. X    rtn = str1;
  249. X
  250. X    while( *str1 )
  251. X    {
  252. X        str1++;
  253. X    }
  254. X
  255. X    while( len && ((*str1++ = *str2++) != '\0') )
  256. X    {
  257. X        len--;
  258. X    }
  259. X    
  260. X    if( ! len )
  261. X    {
  262. X        *str1 = '\0';
  263. X    }
  264. X
  265. X    return(rtn);
  266. X}
  267. X
  268. X/*
  269. X * strcmp - compare two strings
  270. X */
  271. Xint
  272. Xstrcmp(str1,str2)
  273. X    register CONST char    * str1;
  274. X    register CONST char    * str2;
  275. X{
  276. X    return( DBstrcmp((char *) NULL, 0, str1, str2) );
  277. X}
  278. X
  279. Xint
  280. XDBstrcmp(file, line, str1, str2)
  281. X    CONST char        * file;
  282. X    int              line;
  283. X    register CONST char    * str1;
  284. X    register CONST char    * str2;
  285. X{
  286. X    malloc_check_str("strcmp", file, line, str1);
  287. X    malloc_check_str("strcmp", file, line, str2);
  288. X
  289. X    while( *str1 && (*str1 == *str2) )
  290. X    {
  291. X        str1++;
  292. X        str2++;
  293. X    }
  294. X
  295. X
  296. X    /*
  297. X     * in order to deal with the case of a negative last char of either
  298. X     * string when the other string has a null
  299. X     */
  300. X    if( (*str2 == '\0') && (*str1 == '\0') )
  301. X    {
  302. X        return(0);
  303. X    }
  304. X    else if( *str2 == '\0' )
  305. X    {
  306. X        return(1);
  307. X    }
  308. X    else if( *str1 == '\0' )
  309. X    {
  310. X        return(-1);
  311. X    }
  312. X    
  313. X    return( *(CONST STRCMPTYPE *)str1 - *(CONST STRCMPTYPE *)str2 );
  314. X}
  315. X
  316. X/*
  317. X * strncmp - compare two strings up to a specified length
  318. X */
  319. Xint
  320. Xstrncmp(str1,str2,len)
  321. X    register CONST char    * str1;
  322. X    register CONST char    * str2;
  323. X    register STRSIZE       len;
  324. X{
  325. X    return( DBstrncmp((char *)NULL, 0, str1, str2, len) );
  326. X}
  327. X
  328. Xint
  329. XDBstrncmp(file, line, str1,str2,len)
  330. X    CONST char        * file;
  331. X    int              line;
  332. X    register CONST char    * str1;
  333. X    register CONST char    * str2;
  334. X    register STRSIZE       len;
  335. X{
  336. X    malloc_check_strn("strncmp", file, line, str1, len);
  337. X    malloc_check_strn("strncmp", file, line, str2, len);
  338. X
  339. X    while( len > 0 && *str1 && (*str1 == *str2) )
  340. X    {
  341. X        len--;
  342. X        str1++;
  343. X        str2++;
  344. X    }
  345. X
  346. X    if( len == 0 )
  347. X    {
  348. X        return(0);
  349. X    }
  350. X    /*
  351. X     * in order to deal with the case of a negative last char of either
  352. X     * string when the other string has a null
  353. X     */
  354. X    if( (*str2 == '\0') && (*str1 == '\0') )
  355. X    {
  356. X        return(0);
  357. X    }
  358. X    else if( *str2 == '\0' )
  359. X    {
  360. X        return(1);
  361. X    }
  362. X    else if( *str1 == '\0' )
  363. X    {
  364. X        return(-1);
  365. X    }
  366. X    
  367. X    return( *(CONST STRCMPTYPE *)str1 - *(CONST STRCMPTYPE *)str2 );
  368. X}
  369. X
  370. X/*
  371. X * stricmp - compare two strings
  372. X */
  373. Xint
  374. Xstricmp(str1,str2)
  375. X    register CONST char    * str1;
  376. X    register CONST char    * str2;
  377. X{
  378. X    return( DBstricmp((char *) NULL, 0, str1, str2) );
  379. X}
  380. X
  381. Xint
  382. XDBstricmp(file, line, str1, str2)
  383. X    CONST char        * file;
  384. X    int              line;
  385. X    register CONST char    * str1;
  386. X    register CONST char    * str2;
  387. X{
  388. X
  389. X    /*
  390. X     * Make sure ctype is initialized
  391. X     */
  392. X    INIT_CTYPE();
  393. X
  394. X    malloc_check_str("stricmp", file, line, str1);
  395. X    malloc_check_str("stricmp", file, line, str2);
  396. X
  397. X    while( *str1 && (CompareUpper(*str1) == CompareUpper(*str2)) )
  398. X    {
  399. X        str1++;
  400. X        str2++;
  401. X    }
  402. X
  403. X
  404. X    /*
  405. X     * in order to deal with the case of a negative last char of either
  406. X     * string when the other string has a null
  407. X     */
  408. X    if( (*str2 == '\0') && (*str1 == '\0') )
  409. X    {
  410. X        return(0);
  411. X    }
  412. X    else if( *str2 == '\0' )
  413. X    {
  414. X        return(1);
  415. X    }
  416. X    else if( *str1 == '\0' )
  417. X    {
  418. X        return(-1);
  419. X    }
  420. X    
  421. X    return( CompareUpper(*str1) - CompareUpper(*str2) );
  422. X
  423. X} /* DBstricmp(... */
  424. X
  425. X/*
  426. X * strincmp - compare two strings up to a specified length, ignoring case
  427. X */
  428. Xint
  429. Xstrincmp(str1,str2,len)
  430. X    register CONST char    * str1;
  431. X    register CONST char    * str2;
  432. X    register STRSIZE       len;
  433. X{
  434. X    return( DBstrincmp((char *)NULL, 0, str1, str2, len) );
  435. X}
  436. X
  437. Xint
  438. XDBstrincmp(file, line, str1,str2,len)
  439. X    CONST char        * file;
  440. X    int              line;
  441. X    register CONST char    * str1;
  442. X    register CONST char    * str2;
  443. X    register STRSIZE       len;
  444. X{
  445. X
  446. X    /*
  447. X     * Make sure ctype is initialized
  448. X     */
  449. X    INIT_CTYPE();
  450. X
  451. X    malloc_check_strn("strincmp", file, line, str1, len);
  452. X    malloc_check_strn("strincmp", file, line, str2, len);
  453. X
  454. X    while( len > 0 && *str1 && (CompareUpper(*str1)==CompareUpper(*str2)) )
  455. X    {
  456. X        len--;
  457. X        str1++;
  458. X        str2++;
  459. X    }
  460. X
  461. X    if( len == 0 )
  462. X    {
  463. X        return(0);
  464. X    }
  465. X    /*
  466. X     * in order to deal with the case of a negative last char of either
  467. X     * string when the other string has a null
  468. X     */
  469. X    if( (*str2 == '\0') && (*str1 == '\0') )
  470. X    {
  471. X        return(0);
  472. X    }
  473. X    else if( *str2 == '\0' )
  474. X    {
  475. X        return(1);
  476. X    }
  477. X    else if( *str1 == '\0' )
  478. X    {
  479. X        return(-1);
  480. X    }
  481. X    
  482. X    return( CompareUpper(*str1) - CompareUpper(*str2) );
  483. X
  484. X} /* DBstrincmp(... */
  485. X
  486. X/*
  487. X * strcpy - copy a string somewhere else
  488. X */
  489. Xchar *
  490. Xstrcpy(str1,str2)
  491. X    register char        * str1;
  492. X    register CONST char    * str2;
  493. X{
  494. X    return( DBstrcpy((char *)NULL, 0, str1, str2) );
  495. X}
  496. X
  497. Xchar *
  498. XDBstrcpy(file, line, str1, str2)
  499. X    CONST char        * file;
  500. X    int              line;
  501. X    register char        * str1;
  502. X    register CONST char    * str2;
  503. X{
  504. X    char        * rtn;
  505. X    SIZETYPE      len;
  506. X
  507. X    in_string_code++;
  508. X    len = strlen(str2) + 1;
  509. X    in_string_code--;
  510. X
  511. X    malloc_check_data("strcpy", file, line, str1, len);
  512. X    malloc_check_data("strcpy", file, line, str2, len);
  513. X
  514. X    rtn = str1;
  515. X
  516. X    DataMC(str1, str2, len);
  517. X
  518. X    return(rtn);
  519. X}
  520. X
  521. X/*
  522. X * strncpy - copy a string upto a specified number of chars somewhere else
  523. X */
  524. Xchar *
  525. Xstrncpy(str1,str2,len)
  526. X    register char        * str1;
  527. X    register CONST char    * str2;
  528. X    register STRSIZE       len;
  529. X{
  530. X    return( DBstrncpy((char *)NULL, 0, str1, str2, len) );
  531. X}
  532. X
  533. Xchar *
  534. XDBstrncpy(file,line,str1,str2,len)
  535. X    CONST char        * file;
  536. X    int              line;
  537. X    register char        * str1;
  538. X    register CONST char    * str2;
  539. X    STRSIZE               len;
  540. X{
  541. X    register SIZETYPE          i;
  542. X    char            * rtn = str1;
  543. X
  544. X    malloc_check_data("strncpy", file, line, str1, len);
  545. X
  546. X    for(i=0; (i < len) && (str2[i] != '\0'); i++)
  547. X    {
  548. X        /* do nothing */;
  549. X    }
  550. X
  551. X    malloc_check_data("strncpy", file, line, str2, i);
  552. X
  553. X    /*
  554. X     * copy the real data
  555. X     */
  556. X    DataMC(str1,str2,i);
  557. X
  558. X    /*
  559. X     * if there is data left over
  560. X     */
  561. X    if( i < len )
  562. X    {
  563. X        /*
  564. X         * figure out where and how much is left over
  565. X         */
  566. X        str1 += i;
  567. X        len  -= i;
  568. X
  569. X        /*
  570. X         * fill in the rest of the bytes with nulls
  571. X         */
  572. X        DataMS(str1, '\0', len);
  573. X    }
  574. X
  575. X    return(rtn);
  576. X}
  577. X
  578. X/*
  579. X * strlen - determine length of a string
  580. X */
  581. XSTRSIZE 
  582. Xstrlen(str1)
  583. X    CONST char    * str1;
  584. X{
  585. X    return( DBstrlen((char *) NULL, 0, str1) );
  586. X}
  587. X
  588. XSTRSIZE 
  589. XDBstrlen(file, line, str1)
  590. X    CONST char        * file;
  591. X    int              line;
  592. X    register CONST char    * str1;
  593. X{
  594. X    register CONST char    * s;
  595. X
  596. X    if(! in_string_code )
  597. X    {
  598. X        malloc_check_str("strlen", file, line, str1);
  599. X    }
  600. X
  601. X    for( s = str1; *s; s++)
  602. X    {
  603. X    }
  604. X
  605. X    return( s - str1 );
  606. X}
  607. X
  608. X/*
  609. X * strchr - find location of a character in a string
  610. X */
  611. Xchar *
  612. Xstrchr(str1,c)
  613. X    CONST char    * str1;
  614. X    int          c;
  615. X{
  616. X    return( DBstrchr((char *)NULL,0,str1,c) );
  617. X}
  618. X
  619. Xchar *
  620. XDBstrchr(file, line, str1,c)
  621. X    CONST char        * file;
  622. X    int              line;
  623. X    CONST char        * str1;
  624. X    int              c;
  625. X{
  626. X    return( DBFstrchr("strchr",file,line,str1,c) );
  627. X}
  628. X
  629. Xchar *
  630. XDBFstrchr(func,file, line, str1,c)
  631. X    CONST char        * func;
  632. X    CONST char        * file;
  633. X    int              line;
  634. X    register CONST char    * str1;
  635. X    register int          c;
  636. X{
  637. X    malloc_check_str(func, file, line, str1);
  638. X
  639. X    while( *str1 && (*str1 != (char) c) )
  640. X    {
  641. X        str1++;
  642. X    }
  643. X
  644. X    if(*str1 != (char) c)
  645. X    {
  646. X        str1 = (char *) 0;
  647. X    }
  648. X
  649. X    return((char *)str1);
  650. X}
  651. X
  652. X/*
  653. X * strrchr - find rightmost location of a character in a string
  654. X */
  655. X
  656. Xchar *
  657. Xstrrchr(str1,c)
  658. X    CONST char    * str1;
  659. X    int          c;
  660. X{
  661. X    return( DBstrrchr( (char *)NULL, 0, str1, c) );
  662. X}
  663. X
  664. Xchar *
  665. XDBstrrchr(file,line,str1,c)
  666. X    CONST char        * file;
  667. X    int              line;
  668. X    CONST char        * str1;
  669. X    int              c;
  670. X{
  671. X    return( DBFstrrchr("strchr",file,line,str1,c) );
  672. X}
  673. X
  674. Xchar *
  675. XDBFstrrchr(func,file,line,str1,c)
  676. X    CONST char        * func;
  677. X    CONST char        * file;
  678. X    int              line;
  679. X    register CONST char    * str1;
  680. X    register int          c;
  681. X{
  682. X    char    * rtn = (char *) 0;
  683. X
  684. X    malloc_check_str(func, file, line, str1);
  685. X
  686. X    while( *str1 )
  687. X    {
  688. X        if(*str1 == (char) c )
  689. X        {
  690. X            rtn = (char *)str1;
  691. X        }
  692. X        str1++;
  693. X    }
  694. X
  695. X    if( *str1 == (char) c)
  696. X    {
  697. X        rtn = (char *)str1;
  698. X    }
  699. X
  700. X    return(rtn);
  701. X}
  702. X
  703. X/*
  704. X * index - find location of character within string
  705. X */
  706. Xchar *
  707. Xindex(str1,c)
  708. X    CONST char        * str1;
  709. X    char          c;
  710. X{
  711. X    return( DBindex((char *) NULL, 0, str1, c) );
  712. X}
  713. Xchar *
  714. XDBindex(file, line, str1, c)
  715. X    CONST char    * file;
  716. X    int          line;
  717. X    CONST char    * str1;
  718. X    char          c;
  719. X{
  720. X    return( DBFstrchr("index",file,line,str1,c) );
  721. X}
  722. X
  723. X/*
  724. X * rindex - find rightmost location of character within string
  725. X */
  726. Xchar *
  727. Xrindex(str1,c)
  728. X    CONST char    * str1;
  729. X    char          c;
  730. X{
  731. X    return( DBrindex((char *)NULL, 0, str1, c) );
  732. X}
  733. X
  734. Xchar *
  735. XDBrindex(file, line, str1, c)
  736. X    CONST char    * file;
  737. X    int          line;
  738. X    CONST char    * str1;
  739. X    char          c;
  740. X{
  741. X    return( DBFstrrchr("rindex",file,line,str1,c) );
  742. X}
  743. X
  744. X/*
  745. X * strpbrk - find the first occurance of any character from str2 in str1
  746. X */
  747. Xchar *
  748. Xstrpbrk(str1,str2)
  749. X    CONST char    * str1;
  750. X    CONST char    * str2;
  751. X{
  752. X    return( DBstrpbrk((char *)NULL, 0, str1, str2) );
  753. X}
  754. X
  755. Xchar *
  756. XDBstrpbrk(file, line, str1,str2)
  757. X    CONST char        * file;
  758. X    int              line;
  759. X    register CONST char    * str1;
  760. X    register CONST char    * str2;
  761. X{
  762. X    register CONST char    * tmp;
  763. X
  764. X    malloc_check_str("strpbrk", file, line, str1);
  765. X    malloc_check_str("strpbrk", file, line, str2);
  766. X
  767. X    while(*str1)
  768. X    {
  769. X        for( tmp=str2; *tmp && *tmp != *str1; tmp++)
  770. X        {
  771. X        }
  772. X        if( *tmp )
  773. X        {
  774. X            break;
  775. X        }
  776. X        str1++;
  777. X    }
  778. X
  779. X    if( ! *str1 )
  780. X    {
  781. X        str1 = (char *) 0;
  782. X    }
  783. X
  784. X    return( (char *) str1);
  785. X}
  786. X
  787. X/*
  788. X * strspn - get length of str1 that consists totally of chars from str2
  789. X */
  790. XSTRSIZE 
  791. Xstrspn(str1,str2)
  792. X    CONST char    * str1;
  793. X    CONST char    * str2;
  794. X{
  795. X    return( DBstrspn((char *)NULL, 0, str1, str2) );
  796. X}
  797. X
  798. XSTRSIZE 
  799. XDBstrspn(file, line, str1,str2)
  800. X    CONST char        * file;
  801. X    int              line;
  802. X    register CONST char    * str1;
  803. X    register CONST char    * str2;
  804. X{
  805. X    register CONST char    * tmp;
  806. X    CONST char        * orig = str1;
  807. X
  808. X    malloc_check_str("strspn", file, line, str1);
  809. X    malloc_check_str("strspn", file, line, str2);
  810. X
  811. X    while(*str1)
  812. X    {
  813. X        for( tmp=str2; *tmp && *tmp != *str1; tmp++)
  814. X        {
  815. X        }
  816. X        if(! *tmp )
  817. X        {
  818. X            break;
  819. X        }
  820. X        str1++;
  821. X    }
  822. X
  823. X    return( (STRSIZE ) (str1 - orig) );
  824. X}
  825. X
  826. X/*
  827. X * strcspn - get lenght of str1 that consists of no chars from str2
  828. X */
  829. XSTRSIZE 
  830. Xstrcspn(str1,str2)
  831. X    CONST char    * str1;
  832. X    CONST char    * str2;
  833. X{
  834. X    return( DBstrcspn((char *)NULL,0,str1,str2) );
  835. X}
  836. X
  837. XSTRSIZE 
  838. XDBstrcspn(file, line, str1,str2)
  839. X    CONST char        * file;
  840. X    int              line;
  841. X    register CONST char    * str1;
  842. X    register CONST char    * str2;
  843. X{
  844. X    register CONST char    * tmp;
  845. X    CONST char    * orig = str1;
  846. X
  847. X    malloc_check_str("strcspn", file, line, str1);
  848. X    malloc_check_str("strcspn", file, line, str2);
  849. X
  850. X    while(*str1)
  851. X    {
  852. X        for( tmp=str2; *tmp && *tmp != *str1; tmp++)
  853. X        {
  854. X        }
  855. X        if( *tmp )
  856. X        {
  857. X            break;
  858. X        }
  859. X        str1++;
  860. X    }
  861. X
  862. X    return( (int) (str1 - orig) );
  863. X}
  864. X
  865. X/*
  866. X * strstr - locate string within another string
  867. X */
  868. Xchar *
  869. Xstrstr(str1, str2)
  870. X    CONST char    * str1;
  871. X    CONST char    * str2;
  872. X{
  873. X    return( DBstrstr((char *)NULL, 0, str1, str2) );
  874. X}
  875. X
  876. Xchar *
  877. XDBstrstr(file, line, str1, str2)
  878. X    CONST char    * file;
  879. X    int          line;
  880. X    CONST char    * str1;
  881. X    CONST char    * str2;
  882. X{
  883. X    register CONST char    * s;
  884. X    register CONST char    * t;
  885. X    
  886. X    malloc_check_str("strstr", file, line, str1);
  887. X    malloc_check_str("strstr", file, line, str2);
  888. X
  889. X    /*
  890. X     * until we run out of room in str1
  891. X     */
  892. X    while( *str1 != '\0' )
  893. X    {
  894. X        /*
  895. X         * get tmp pointers to both strings
  896. X         */
  897. X        s = str2;
  898. X        t = str1;
  899. X
  900. X        /*
  901. X         * see if they match
  902. X         */
  903. X        while( *s &&  (*s == *t) )
  904. X        {
  905. X            s++;
  906. X            t++;
  907. X        }
  908. X
  909. X        /*
  910. X         * if we ran out of str2, we found the match,
  911. X         * so return the pointer within str1.
  912. X         */
  913. X        if( ! *s )
  914. X        {
  915. X            return( (char *) str1);
  916. X        }
  917. X        str1++;
  918. X    }
  919. X
  920. X    if( *str2 == '\0' )
  921. X    {
  922. X        return( (char *) str1);
  923. X    }
  924. X    return(NULL);
  925. X}
  926. X
  927. X/*
  928. X * strtok() source taken from that posted to comp.lang.c by Chris Torek
  929. X * in Jan 1990.
  930. X */
  931. X
  932. X/*
  933. X * Copyright (c) 1989 The Regents of the University of California.
  934. X * All rights reserved.
  935. X *
  936. X * Redistribution and use in source and binary forms are permitted
  937. X * provided that the above copyright notice and this paragraph are
  938. X * duplicated in all such forms and that any documentation,
  939. X * advertising materials, and other materials related to such
  940. X * distribution and use acknowledge that the software was developed
  941. X * by the University of California, Berkeley.  The name of the
  942. X * University may not be used to endorse or promote products derived
  943. X * from this software without specific prior written permission.
  944. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  945. X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  946. X * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  947. X */
  948. X
  949. X/*
  950. X * Get next token from string s (NULL on 2nd, 3rd, etc. calls),
  951. X * where tokens are nonempty strings separated by runs of
  952. X * chars from delim.  Writes NULs into s to end tokens.  delim need not
  953. X * remain CONSTant from call to call.
  954. X *
  955. X * Modified by cpc:     changed variable names to conform with naming
  956. X *            conventions used in rest of code.  Added malloc pointer
  957. X *            check calls.
  958. X */
  959. X
  960. Xchar *
  961. Xstrtok(str1, str2)
  962. X    char         * str1;
  963. X    CONST char    * str2;
  964. X{
  965. X    return( DBstrtok( (char *)NULL, 0, str1, str2) );
  966. X}
  967. X
  968. Xchar *
  969. XDBstrtok(file, line, str1, str2)
  970. X    CONST char    * file;
  971. X    int          line;
  972. X    char         * str1;
  973. X    CONST char    * str2;
  974. X{
  975. X    static char     * last;
  976. X
  977. X    if( str1 )
  978. X    {
  979. X        malloc_check_str("strtok", file, line, str1);
  980. X        last = str1;
  981. X    }
  982. X    malloc_check_str("strtok", file, line, str2);
  983. X
  984. X    return (strtoken(&last, str2, 1));
  985. X}
  986. X
  987. X
  988. X/*
  989. X * Get next token from string *stringp, where tokens are (possibly empty)
  990. X * strings separated by characters from delim.  Tokens are separated
  991. X * by exactly one delimiter iff the skip parameter is false; otherwise
  992. X * they are separated by runs of characters from delim, because we
  993. X * skip over any initial `delim' characters.
  994. X *
  995. X * Writes NULs into the string at *stringp to end tokens.
  996. X * delim will usually, but need not, remain CONSTant from call to call.
  997. X * On return, *stringp points past the last NUL written (if there might
  998. X * be further tokens), or is NULL (if there are definitely no more tokens).
  999. X *
  1000. X * If *stringp is NULL, strtoken returns NULL.
  1001. X */
  1002. Xchar *
  1003. Xstrtoken(stringp, delim, skip)
  1004. X    register char **stringp;
  1005. X    register CONST char *delim;
  1006. X    int skip;
  1007. X{
  1008. X    register char *s;
  1009. X    register CONST char *spanp;
  1010. X    register int c, sc;
  1011. X    char *tok;
  1012. X
  1013. X    if ((s = *stringp) == NULL)
  1014. X        return (NULL);
  1015. X
  1016. X    if (skip) {
  1017. X        /*
  1018. X         * Skip (span) leading delimiters (s += strspn(s, delim)).
  1019. X         */
  1020. X    cont:
  1021. X        c = *s;
  1022. X        for (spanp = delim; (sc = *spanp++) != 0;) {
  1023. X            if (c == sc) {
  1024. X                s++;
  1025. X                goto cont;
  1026. X            }
  1027. X        }
  1028. X        if (c == 0) {        /* no token found */
  1029. X            *stringp = NULL;
  1030. X            return (NULL);
  1031. X        }
  1032. X    }
  1033. X
  1034. X    /*
  1035. X     * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
  1036. X     * Note that delim must have one NUL; we stop if we see that, too.
  1037. X     */
  1038. X    for (tok = s;;) {
  1039. X        c = *s++;
  1040. X        spanp = delim;
  1041. X        do {
  1042. X            if ((sc = *spanp++) == c) {
  1043. X                if (c == 0)
  1044. X                    s = NULL;
  1045. X                else
  1046. X                    s[-1] = 0;
  1047. X                *stringp = s;
  1048. X                return( (char *) tok );
  1049. X            }
  1050. X        } while (sc != 0);
  1051. X    }
  1052. X    /* NOTREACHED */
  1053. X}
  1054. X
  1055. X/*
  1056. X * $Log: string.c,v $
  1057. X * Revision 1.30  1992/08/22  16:27:13  cpcahil
  1058. X * final changes for pl14
  1059. X *
  1060. X * Revision 1.29  1992/07/03  00:03:25  cpcahil
  1061. X * more fixes for pl13, several suggestons from Rich Salz.
  1062. X *
  1063. X * Revision 1.28  1992/06/30  13:06:39  cpcahil
  1064. X * added support for aligned allocations
  1065. X *
  1066. X * Revision 1.27  1992/06/27  22:48:48  cpcahil
  1067. X * misc fixes per bug reports from first week of reviews
  1068. X *
  1069. X * Revision 1.26  1992/06/23  11:12:54  cpcahil
  1070. X * fixed bug in case insensitive comparisons.
  1071. X *
  1072. X * Revision 1.25  1992/06/22  23:40:10  cpcahil
  1073. X * many fixes for working on small int systems
  1074. X *
  1075. X * Revision 1.24  1992/05/09  21:27:09  cpcahil
  1076. X * final (hopefully) changes for patch 11
  1077. X *
  1078. X * Revision 1.23  1992/05/09  00:16:16  cpcahil
  1079. X * port to hpux and lots of fixes
  1080. X *
  1081. X * Revision 1.22  1992/05/08  02:30:35  cpcahil
  1082. X * minor cleanups from minix/atari port
  1083. X *
  1084. X * Revision 1.21  1992/05/08  01:44:11  cpcahil
  1085. X * more performance enhancements
  1086. X *
  1087. X * Revision 1.20  1992/04/20  22:29:14  cpcahil
  1088. X * changes to fix problems introduced by insertion of size_t
  1089. X *
  1090. X * Revision 1.19  1992/04/14  01:15:25  cpcahil
  1091. X * port to RS/6000
  1092. X *
  1093. X * Revision 1.18  1992/04/13  19:08:18  cpcahil
  1094. X * fixed case insensitive stuff
  1095. X *
  1096. X * Revision 1.17  1992/04/13  18:41:18  cpcahil
  1097. X * added case insensitive string comparison routines
  1098. X *
  1099. X * Revision 1.16  1992/04/13  03:06:33  cpcahil
  1100. X * Added Stack support, marking of non-leaks, auto-config, auto-testing
  1101. X *
  1102. X * Revision 1.15  1992/01/30  12:23:06  cpcahil
  1103. X * renamed mallocint.h -> mallocin.h
  1104. X *
  1105. X * Revision 1.14  1991/12/04  09:23:44  cpcahil
  1106. X * several performance enhancements including addition of free list
  1107. X *
  1108. X * Revision 1.13  91/12/02  19:10:14  cpcahil
  1109. X * changes for patch release 5
  1110. X * 
  1111. X * Revision 1.12  91/11/25  14:42:05  cpcahil
  1112. X * Final changes in preparation for patch 4 release
  1113. X * 
  1114. X * Revision 1.11  91/11/24  16:56:43  cpcahil
  1115. X * porting changes for patch level 4
  1116. X * 
  1117. X * Revision 1.10  91/11/24  00:49:32  cpcahil
  1118. X * first cut at patch 4
  1119. X * 
  1120. X * Revision 1.9  91/11/20  11:54:11  cpcahil
  1121. X * interim checkin
  1122. X * 
  1123. X * Revision 1.8  91/05/30  12:07:04  cpcahil
  1124. X * added fix to get the stuff to compile correctly on ultirx and aix systems.
  1125. X * 
  1126. X * Revision 1.7  90/08/29  22:24:19  cpcahil
  1127. X * added new function to check on strings up to a specified length 
  1128. X * and used it within several strn* functions.
  1129. X * 
  1130. X * Revision 1.6  90/07/16  20:06:56  cpcahil
  1131. X * fixed several minor bugs found with Henry Spencer's string/mem function
  1132. X * tester program.
  1133. X * 
  1134. X * Revision 1.5  90/06/10  14:59:49  cpcahil
  1135. X * Fixed a couple of bugs in strncpy & strdup
  1136. X * 
  1137. X * Revision 1.4  90/05/11  00:13:10  cpcahil
  1138. X * added copyright statment
  1139. X * 
  1140. X * Revision 1.3  90/02/24  21:50:32  cpcahil
  1141. X * lots of lint fixes
  1142. X * 
  1143. X * Revision 1.2  90/02/24  17:29:40  cpcahil
  1144. X * changed $Header to $Id so full path wouldnt be included as part of rcs 
  1145. X * id string
  1146. X * 
  1147. X * Revision 1.1  90/02/22  23:17:44  cpcahil
  1148. X * Initial revision
  1149. X * 
  1150. X */
  1151. END_OF_FILE
  1152. if test 20827 -ne `wc -c <'string.c'`; then
  1153.     echo shar: \"'string.c'\" unpacked with wrong size!
  1154. fi
  1155. # end of 'string.c'
  1156. fi
  1157. if test -f 'testerr.base' -a "${1}" != "-c" ; then 
  1158.   echo shar: Will not clobber existing file \"'testerr.base'\"
  1159. else
  1160. echo shar: Extracting \"'testerr.base'\" \(3791 characters\)
  1161. sed "s/^X//" >'testerr.base' <<'END_OF_FILE'
  1162. X-------------------------------------
  1163. XTesting malloc_inuse()...OK
  1164. X-------------------------------------
  1165. XTesting malloc_mark()...OK
  1166. X-------------------------------------
  1167. XTesting malloc_size()...OK
  1168. X-------------------------------------
  1169. XTesting memalign()...OK
  1170. X-------------------------------------
  1171. XError from strcpy() - out of bounds
  1172. XMALLOC Warning from strncpy() (called from testerr.c line 128):
  1173. XPointer within malloc region, but outside of malloc data bounds
  1174. XThis error is *probably* associated with the following allocation:
  1175. X
  1176. X    A call to malloc for 10 bytes in testerr.c on line 123.
  1177. X
  1178. X-------------------------------------
  1179. XError from memset() - out of bounds (beyond)
  1180. XMALLOC Warning from memset() (called from testerr.c line 133):
  1181. XPointer within malloc region, but outside of malloc data bounds
  1182. XThis error is *probably* associated with the following allocation:
  1183. X
  1184. X    A call to malloc for 20 bytes in testerr.c on line 121.
  1185. X
  1186. X-------------------------------------
  1187. XError from free() - overrun
  1188. XMALLOC Warning from free() (called from testerr.c line 138):
  1189. XData has overrun beyond requested number of bytes
  1190. XThis error is *probably* associated with the following allocation:
  1191. X
  1192. X    A call to malloc for 20 bytes in testerr.c on line 121.
  1193. X
  1194. XMALLOC Warning from free() (called from testerr.c line 138):
  1195. XData has overrun beyond requested number of bytes
  1196. XThis error is *probably* associated with the following allocation:
  1197. X
  1198. X    A call to malloc for 10 bytes in testerr.c on line 123.
  1199. X
  1200. X-------------------------------------
  1201. XError from free() - double free
  1202. XMALLOC Warning from free() (called from testerr.c line 143):
  1203. XData area is not in use (can't be freed or realloced, or used)
  1204. XThis error is *probably* associated with the following allocation:
  1205. X
  1206. X    A call to malloc for 20 bytes in testerr.c on line 121.
  1207. X
  1208. X    in testerr.c on line 138.
  1209. X
  1210. X-------------------------------------
  1211. XNO error from bzero
  1212. X-------------------------------------
  1213. XError from bzero() - out of bounds
  1214. XMALLOC Warning from bzero() (called from testerr.c line 153):
  1215. XPointer within malloc region, but outside of malloc data bounds
  1216. XThis error is *probably* associated with the following allocation:
  1217. X
  1218. X    A call to malloc for 10 bytes in testerr.c on line 123.
  1219. X
  1220. X-------------------------------------
  1221. XError from free() - overrun
  1222. XMALLOC Warning from free() (called from testerr.c line 158):
  1223. XData has overrun beyond requested number of bytes
  1224. XThis error is *probably* associated with the following allocation:
  1225. X
  1226. X    A call to malloc for 10 bytes in testerr.c on line 123.
  1227. X
  1228. X-------------------------------------
  1229. XError from memset() - out of bounds (before)
  1230. XMALLOC Warning from memset() (called from testerr.c line 165):
  1231. XPointer within malloc region, but outside of malloc data bounds
  1232. XThis error is *probably* associated with the following allocation:
  1233. X
  1234. X    A call to malloc for 1 bytes in testerr.c on line 160.
  1235. X
  1236. X-------------------------------------
  1237. XError from free() - underrun
  1238. XMALLOC Warning from free() (called from testerr.c line 170):
  1239. XData has written before beginning of requested bytes
  1240. XThis error is *probably* associated with the following allocation:
  1241. X
  1242. X    A call to malloc for 1 bytes in testerr.c on line 160.
  1243. X
  1244. X-------------------------------------
  1245. XError from memset() - out of bounds
  1246. XMALLOC Warning from memset() (called from testerr.c line 178):
  1247. XPointer within malloc region, but outside of malloc data bounds
  1248. XThis error is *probably* associated with the following allocation:
  1249. X
  1250. X    A call to malloc for 10 bytes in testerr.c on line 172.
  1251. X
  1252. X-------------------------------------
  1253. XError from malloc() - chain broken
  1254. XMALLOC Warning from malloc() (called from testerr.c line 184):
  1255. XPointers between this segment and adjoining segments are invalid
  1256. XThis error is *probably* associated with the following allocation:
  1257. X
  1258. X    A call to malloc for 10 bytes in testerr.c on line 172.
  1259. X
  1260. END_OF_FILE
  1261. if test 3791 -ne `wc -c <'testerr.base'`; then
  1262.     echo shar: \"'testerr.base'\" unpacked with wrong size!
  1263. fi
  1264. # end of 'testerr.base'
  1265. fi
  1266. if test -f 'testmalloc.c' -a "${1}" != "-c" ; then 
  1267.   echo shar: Will not clobber existing file \"'testmalloc.c'\"
  1268. else
  1269. echo shar: Extracting \"'testmalloc.c'\" \(5910 characters\)
  1270. sed "s/^X//" >'testmalloc.c' <<'END_OF_FILE'
  1271. X/* NOT copyright by SoftQuad Inc. -- msb, 1988 */
  1272. X/*
  1273. X * (c) Copyright 1990, 1991, 1992 Conor P. Cahill (cpcahil@virtech.vti.com)
  1274. X *
  1275. X * This software may be distributed freely as long as the following conditions
  1276. X * are met:
  1277. X *         * the distribution, or any derivative thereof, may not be
  1278. X *          included as part of a commercial product
  1279. X *        * full source code is provided including this copyright
  1280. X *        * there is no charge for the software itself (there may be
  1281. X *          a minimal charge for the copying or distribution effort)
  1282. X *        * this copyright notice is not modified or removed from any
  1283. X *          source file
  1284. X */
  1285. X#ifndef lint
  1286. Xstatic char *SQ_SccsId = "@(#)mtest3.c    1.2 88/08/25";
  1287. X#endif
  1288. X#include <stdio.h>
  1289. X#include <sys/types.h>
  1290. X/*
  1291. X** looptest.c -- intensive allocator tester 
  1292. X**
  1293. X** Usage:  looptest
  1294. X**
  1295. X** History:
  1296. X**    4-Feb-1987 rtech!daveb 
  1297. X*/
  1298. X
  1299. X#ifndef HAS_VADVISE
  1300. X#ifdef random
  1301. X#undef random
  1302. X#endif
  1303. X# define random    rand
  1304. X#else
  1305. X# include <sys/vadvise.h>
  1306. X#endif
  1307. X
  1308. X# include <math.h>
  1309. X# include <stdio.h>
  1310. X# include <signal.h>
  1311. X# include <setjmp.h>
  1312. X
  1313. X#include "malloc.h"
  1314. X
  1315. X# define MAXITER    1000000        /* main loop iterations */
  1316. X# define MAXOBJS    1000        /* objects in pool */
  1317. X# define BIGOBJ        90000        /* max size of a big object */
  1318. X# define TINYOBJ    80        /* max size of a small object */
  1319. X# define BIGMOD        100        /* 1 in BIGMOD is a BIGOBJ */
  1320. X# define STATMOD    10000        /* interation interval for status */
  1321. X
  1322. Xint
  1323. Xmain( argc, argv )
  1324. Xint argc;
  1325. Xchar **argv;
  1326. X{
  1327. X    register int     **objs;    /* array of objects */
  1328. X    register SIZETYPE *sizes;    /* array of object sizes */
  1329. X    register SIZETYPE n;        /* iteration counter */
  1330. X    register SIZETYPE i;        /* object index */
  1331. X    register SIZETYPE size;        /* object size */
  1332. X    register SIZETYPE r;        /* random number */
  1333. X
  1334. X    SIZETYPE objmax;        /* max size this iteration */
  1335. X    long cnt;            /* number of allocated objects */
  1336. X    long nm = 0;            /* number of mallocs */
  1337. X    long nre = 0;            /* number of reallocs */
  1338. X    long startsize;            /* size at loop start */
  1339. X    long endsize;            /* size at loop exit */
  1340. X    long maxiter = 0;        /* real max # iterations */
  1341. X
  1342. X    double * dblptr;        /* pointer for doubleword test */
  1343. X
  1344. X    extern char end;        /* memory before heap */
  1345. X    char *sbrk();
  1346. X    long atol();
  1347. X    union dbmalloptarg m;
  1348. X
  1349. X#ifdef HAS_VADVISE
  1350. X    /* your milage may vary... */
  1351. X    vadvise( VA_ANOM );
  1352. X#endif
  1353. X
  1354. X    /*
  1355. X     * test that allocation can be used for doubleword manipulation
  1356. X     */
  1357. X    dblptr = (double *) malloc(sizeof(double));
  1358. X    if( (dblptr == 0) || ((*dblptr=10.0) != 10.0) )
  1359. X    {
  1360. X        fprintf(stderr,"Doubleword test failed\n");
  1361. X        exit(1);
  1362. X    }
  1363. X    free( (DATATYPE *) dblptr);
  1364. X
  1365. X    if (argc > 1)
  1366. X        maxiter = atol (argv[1]);
  1367. X    if (maxiter <= 0)
  1368. X        maxiter = MAXITER;
  1369. X
  1370. X    printf("MAXITER %ld MAXOBJS %d ", maxiter, MAXOBJS );
  1371. X    printf("BIGOBJ %ld, TINYOBJ %d, nbig/ntiny 1/%d\n",
  1372. X    BIGOBJ, TINYOBJ, BIGMOD );
  1373. X    fflush( stdout );
  1374. X
  1375. X    if( NULL == (objs = (int **)calloc( MAXOBJS, sizeof( *objs ) ) ) )
  1376. X    {
  1377. X        fprintf(stderr, "Can't allocate memory for objs array\n");
  1378. X        exit(1);
  1379. X    }
  1380. X
  1381. X    if( NULL == ( sizes = (SIZETYPE *)calloc( MAXOBJS, sizeof( *sizes ) ) ))
  1382. X    {
  1383. X        fprintf(stderr, "Can't allocate memory for sizes array\n");
  1384. X        exit(1);
  1385. X    }
  1386. X
  1387. X    /* as per recent discussion on net.lang.c, calloc does not 
  1388. X    ** necessarily fill in NULL pointers...
  1389. X    */
  1390. X    for( i = 0; i < MAXOBJS; i++ )
  1391. X        objs[ i ] = NULL;
  1392. X
  1393. X    startsize = sbrk(0) - &end;
  1394. X    printf( "Memory use at start: %ld bytes\n", startsize );
  1395. X    fflush(stdout);
  1396. X
  1397. X    printf("Starting the test...\n");
  1398. X    fflush(stdout);
  1399. X    for( n = 0; n < maxiter ; n++ )
  1400. X    {
  1401. X        if( !(n % STATMOD) )
  1402. X        {
  1403. X            printf("%ld iterations\n", n);
  1404. X            fflush(stdout);
  1405. X        }
  1406. X
  1407. X        /* determine object of interest and its size */
  1408. X
  1409. X        r = random();
  1410. X        objmax = ( r % BIGMOD ) ? TINYOBJ : BIGOBJ;
  1411. X        size = r % objmax;
  1412. X        i = r % (MAXOBJS - 1);
  1413. X
  1414. X        /*
  1415. X         * make sure size is at least one byte
  1416. X         */
  1417. X        if( size == 0 )
  1418. X        {
  1419. X            size++;
  1420. X        }
  1421. X        /* either replace the object or get a new one */
  1422. X
  1423. X        if( objs[ i ] == NULL )
  1424. X        {
  1425. X            if( (i % 5) == 0 )
  1426. X            {
  1427. X                objs[ i ] = (int *)memalign(1024, size );
  1428. X            }
  1429. X            else if( (i % 4) == 0 )
  1430. X            {
  1431. X                objs[ i ] = (int *)calloc(1, size );
  1432. X            }
  1433. X            else if( (i%3) == 0 )
  1434. X            {
  1435. X                objs[ i ] = (int *)XtCalloc(1, size );
  1436. X            }
  1437. X            else if( (i%2) == 0 )
  1438. X            {
  1439. X                objs[ i ] = (int *)XtMalloc( size );
  1440. X            }
  1441. X            else
  1442. X            {
  1443. X                objs[ i ] = (int *)malloc( size );
  1444. X            }
  1445. X            nm++;
  1446. X        }
  1447. X        else
  1448. X        {
  1449. X            /* don't keep bigger objects around */
  1450. X            if( size > sizes[ i ] )
  1451. X            {
  1452. X                if( (i & 0x01) == 0 )
  1453. X                {
  1454. X                    objs[ i ] = (int *)realloc(
  1455. X                            (DATATYPE *) objs[ i ], size );
  1456. X                }
  1457. X                else
  1458. X                {
  1459. X                    objs[ i ] = (int *)XtRealloc(
  1460. X                            (DATATYPE *) objs[ i ], size );
  1461. X                }
  1462. X                nre++;
  1463. X            }
  1464. X            else
  1465. X            {
  1466. X                if( (i & 0x01) == 0 )
  1467. X                {
  1468. X                    free( (DATATYPE *) objs[ i ] );
  1469. X                }
  1470. X                else
  1471. X                {
  1472. X                    XtFree( (DATATYPE *) objs[ i ] );
  1473. X                }
  1474. X                objs[ i ] = (int *)malloc( size );
  1475. X                nm++;
  1476. X            }
  1477. X        }
  1478. X
  1479. X        sizes[ i ] = size;
  1480. X        if( objs[ i ] == NULL )
  1481. X        {
  1482. X            printf("\nCouldn't allocate %ld byte object!\n", 
  1483. X                size );
  1484. X            break;
  1485. X        }
  1486. X    } /* for() */
  1487. X
  1488. X    printf( "\n" );
  1489. X    cnt = 0;
  1490. X    for( i = 0; i < MAXOBJS; i++ )
  1491. X        if( objs[ i ] )
  1492. X            cnt++;
  1493. X
  1494. X    printf( "Did %ld iterations, %d objects, %d mallocs, %d reallocs\n",
  1495. X        n, cnt, nm, nre );
  1496. X    printf( "Memory use at end: %ld bytes\n", sbrk(0) - &end );
  1497. X    fflush( stdout );
  1498. X
  1499. X    /* free all the objects */
  1500. X    for( i = 0; i < MAXOBJS; i++ )
  1501. X    {
  1502. X        if( objs[ i ] != NULL )
  1503. X        {
  1504. X                if( (i & 0x01) == 0 )
  1505. X                {
  1506. X                    free( (DATATYPE *) objs[ i ] );
  1507. X                }
  1508. X                else
  1509. X                {
  1510. X                    XtFree( (DATATYPE *) objs[ i ] );
  1511. X                }
  1512. X        }
  1513. X    }
  1514. X
  1515. X    endsize = sbrk(0) - &end;
  1516. X    printf( "Memory use after free: %ld bytes\n", endsize );
  1517. X    fflush( stdout );
  1518. X
  1519. X    if( startsize != endsize )
  1520. X        printf("startsize %ld != endsize %d\n", startsize, endsize );
  1521. X
  1522. X    free( (DATATYPE *) objs );
  1523. X    free( (DATATYPE *) sizes );
  1524. X
  1525. X    /*
  1526. X     * make sure detail mode is enabled
  1527. X     */    
  1528. X    m.i = 1;
  1529. X    dbmallopt(MALLOC_DETAIL,&m);
  1530. X
  1531. X    malloc_dump(2);
  1532. X    exit( 0 );
  1533. X    /*NOTREACHED*/
  1534. X}
  1535. X
  1536. X/*
  1537. X * Fake X Windows stuff in order to get xmalloc stuff to link correctly.
  1538. X */
  1539. Xchar * XtCXtToolkitError = "junk string";
  1540. Xint
  1541. XXtErrorMsg()
  1542. X{
  1543. X    return(0);
  1544. X}
  1545. END_OF_FILE
  1546. if test 5910 -ne `wc -c <'testmalloc.c'`; then
  1547.     echo shar: \"'testmalloc.c'\" unpacked with wrong size!
  1548. fi
  1549. # end of 'testmalloc.c'
  1550. fi
  1551. if test -f 'tostring.c' -a "${1}" != "-c" ; then 
  1552.   echo shar: Will not clobber existing file \"'tostring.c'\"
  1553. else
  1554. echo shar: Extracting \"'tostring.c'\" \(4106 characters\)
  1555. sed "s/^X//" >'tostring.c' <<'END_OF_FILE'
  1556. X
  1557. X/*
  1558. X * (c) Copyright 1990, 1991, 1992 Conor P. Cahill (cpcahil@virtech.vti.com)
  1559. X *
  1560. X * This software may be distributed freely as long as the following conditions
  1561. X * are met:
  1562. X *         * the distribution, or any derivative thereof, may not be
  1563. X *          included as part of a commercial product
  1564. X *        * full source code is provided including this copyright
  1565. X *        * there is no charge for the software itself (there may be
  1566. X *          a minimal charge for the copying or distribution effort)
  1567. X *        * this copyright notice is not modified or removed from any
  1568. X *          source file
  1569. X */
  1570. X#include "tostring.h"
  1571. X#include "mallocin.h"
  1572. X
  1573. X/*
  1574. X * Function:    tostring()
  1575. X *
  1576. X * Purpose:    to convert an integer to an ascii display string
  1577. X *
  1578. X * Arguments:    buf    - place to put the 
  1579. X *        val    - integer to convert
  1580. X *        len    - length of output field (0 if just enough to hold data)
  1581. X *        base    - base for number conversion (only works for base <= 16)
  1582. X *        fill    - fill char when len > # digits
  1583. X *
  1584. X * Returns:    length of string
  1585. X *
  1586. X * Narrative:    IF fill character is non-blank
  1587. X *            Determine base
  1588. X *                If base is HEX
  1589. X *                    add "0x" to begining of string
  1590. X *                IF base is OCTAL
  1591. X *                    add "0" to begining of string
  1592. X *
  1593. X *        While value is greater than zero
  1594. X *            use val % base as index into xlation str to get cur char
  1595. X *            divide val by base
  1596. X *
  1597. X *        Determine fill-in length
  1598. X *
  1599. X *        Fill in fill chars
  1600. X *
  1601. X *        Copy in number
  1602. X *        
  1603. X *
  1604. X * Mod History:    
  1605. X *   90/01/24    cpcahil        Initial revision.
  1606. X */
  1607. X
  1608. X#ifndef lint
  1609. Xstatic
  1610. Xchar rcs_hdr[] = "$Id: tostring.c,v 1.9 1992/08/22 16:27:13 cpcahil Exp $";
  1611. X#endif
  1612. X
  1613. X#define T_LEN 15
  1614. X
  1615. Xint
  1616. Xtostring(buf,val,len,base,fill)
  1617. X    char        * buf;
  1618. X    unsigned long      val;
  1619. X    int          len;
  1620. X    int          base;
  1621. X    char          fill;
  1622. X    
  1623. X{
  1624. X    char        * bufstart = buf;
  1625. X    int          filled = 0;
  1626. X    int          i = T_LEN;
  1627. X    CONST char    * xbuf = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  1628. X    char          tbuf[T_LEN];
  1629. X
  1630. X    /*
  1631. X     * if we are filling with non-blanks, make sure the
  1632. X     * proper start string is added
  1633. X     */
  1634. X    if( fill != ' ' )
  1635. X    {
  1636. X        switch(base)
  1637. X        {
  1638. X            case B_HEX:
  1639. X                if( (len == 0) ||  (len > 2) )
  1640. X                {
  1641. X                    filled = 2;
  1642. X                    *(buf++) = '0';
  1643. X                    *(buf++) = 'x';
  1644. X                    if( len )
  1645. X                    {
  1646. X                        len -= 2;
  1647. X                    }
  1648. X                }
  1649. X                break;
  1650. X            case B_OCTAL:
  1651. X                *(buf++) = fill;
  1652. X                if( len )
  1653. X                {
  1654. X                    len--;
  1655. X                }
  1656. X                break;
  1657. X            default:
  1658. X                break;
  1659. X        }
  1660. X    }
  1661. X
  1662. X    /*
  1663. X     * convert the value to a string
  1664. X     */
  1665. X    do
  1666. X    {
  1667. X        tbuf[--i] = xbuf[val % (unsigned long)base];
  1668. X        val = val / (unsigned long)base;
  1669. X    }
  1670. X    while( val > 0 );
  1671. X
  1672. X
  1673. X    if( len )
  1674. X    {
  1675. X        len -= (T_LEN - i);
  1676. X
  1677. X        /*
  1678. X         * if we are out of room and we already filled in some of the
  1679. X         * output buffer (usually 0x for hex output), strip the pre-fill
  1680. X         * so that we get as much data as we can.
  1681. X         */
  1682. X        if( (len < 0) && filled )
  1683. X        {
  1684. X            len += filled;
  1685. X            buf -= filled;
  1686. X        }
  1687. X
  1688. X        if( len > 0 )
  1689. X        {
  1690. X            while(len-- > 0)
  1691. X            {
  1692. X                *(buf++) = fill;
  1693. X            }
  1694. X        }
  1695. X        else
  1696. X        {
  1697. X            /* 
  1698. X             * string is too long so we must truncate
  1699. X             * off some characters.  We do this the easiest
  1700. X             * way by just incrementing i.  This means the
  1701. X             * most significant digits are lost.
  1702. X             */
  1703. X            while( len++ < 0 )
  1704. X            {
  1705. X                i++;
  1706. X            }
  1707. X        }
  1708. X    }
  1709. X
  1710. X    while( i < T_LEN )
  1711. X    {
  1712. X        *(buf++) = tbuf[i++];
  1713. X    }
  1714. X
  1715. X    return( (int) (buf - bufstart) );
  1716. X
  1717. X} /* tostring(... */
  1718. X
  1719. X/*
  1720. X * $Log: tostring.c,v $
  1721. X * Revision 1.9  1992/08/22  16:27:13  cpcahil
  1722. X * final changes for pl14
  1723. X *
  1724. X * Revision 1.8  1992/05/08  02:30:35  cpcahil
  1725. X * minor cleanups from minix/atari port
  1726. X *
  1727. X * Revision 1.7  1992/04/14  02:27:30  cpcahil
  1728. X * adjusted output of pointes so that values that had the high bit
  1729. X * set would print correctly.
  1730. X *
  1731. X * Revision 1.6  1992/04/13  03:06:33  cpcahil
  1732. X * Added Stack support, marking of non-leaks, auto-config, auto-testing
  1733. X *
  1734. X * Revision 1.5  1991/11/25  14:42:06  cpcahil
  1735. X * Final changes in preparation for patch 4 release
  1736. X *
  1737. X * Revision 1.4  90/05/11  00:13:11  cpcahil
  1738. X * added copyright statment
  1739. X * 
  1740. X * Revision 1.3  90/02/24  21:50:33  cpcahil
  1741. X * lots of lint fixes
  1742. X * 
  1743. X * Revision 1.2  90/02/24  17:29:42  cpcahil
  1744. X * changed $Header to $Id so full path wouldnt be included as part of rcs 
  1745. X * id string
  1746. X * 
  1747. X * Revision 1.1  90/02/22  23:17:44  cpcahil
  1748. X * Initial revision
  1749. X * 
  1750. X */
  1751. END_OF_FILE
  1752. if test 4106 -ne `wc -c <'tostring.c'`; then
  1753.     echo shar: \"'tostring.c'\" unpacked with wrong size!
  1754. fi
  1755. # end of 'tostring.c'
  1756. fi
  1757. if test -f 'xheap.c' -a "${1}" != "-c" ; then 
  1758.   echo shar: Will not clobber existing file \"'xheap.c'\"
  1759. else
  1760. echo shar: Extracting \"'xheap.c'\" \(3940 characters\)
  1761. sed "s/^X//" >'xheap.c' <<'END_OF_FILE'
  1762. X
  1763. X/*
  1764. X * (c) Copyright 1990, 1991, 1992 Conor P. Cahill (cpcahil@virtech.vti.com)
  1765. X *
  1766. X * This software may be distributed freely as long as the following conditions
  1767. X * are met:
  1768. X *         * the distribution, or any derivative thereof, may not be
  1769. X *          included as part of a commercial product
  1770. X *        * full source code is provided including this copyright
  1771. X *        * there is no charge for the software itself (there may be
  1772. X *          a minimal charge for the copying or distribution effort)
  1773. X *        * this copyright notice is not modified or removed from any
  1774. X *          source file
  1775. X */
  1776. X#ifndef lint
  1777. Xstatic char rcs_hdr[] = "$Id: xheap.c,v 1.4 1992/08/22 16:27:13 cpcahil Exp $";
  1778. X#endif
  1779. X
  1780. X/***********************************************************
  1781. XCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  1782. Xand the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  1783. X
  1784. X                        All Rights Reserved
  1785. X
  1786. XPermission to use, copy, modify, and distribute this software and its 
  1787. Xdocumentation for any purpose and without fee is hereby granted, 
  1788. Xprovided that the above copyright notice appear in all copies and that
  1789. Xboth that copyright notice and this permission notice appear in 
  1790. Xsupporting documentation, and that the names of Digital or MIT not be
  1791. Xused in advertising or publicity pertaining to distribution of the
  1792. Xsoftware without specific, written prior permission.  
  1793. X
  1794. XDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  1795. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  1796. XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  1797. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  1798. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  1799. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  1800. XSOFTWARE.
  1801. X
  1802. X******************************************************************/
  1803. X
  1804. X/*
  1805. X * X Toolkit Memory Allocation Routines
  1806. X *
  1807. X * Uses Xlib memory management, which is spec'd to be re-entrant.
  1808. X */
  1809. X
  1810. X#if FOUND_X_INTRINSIC
  1811. X#include "X11/Intrinsic.h"
  1812. X#endif
  1813. X
  1814. X#include "mallocin.h"
  1815. X
  1816. X#ifndef NULL
  1817. X#define NULL ((char *)0)
  1818. X#endif
  1819. X
  1820. Xvoid _XtHeapInit(heap)
  1821. X    Heap*    heap;
  1822. X{
  1823. X    heap->start = NULL;
  1824. X    heap->bytes_remaining = 0;
  1825. X}
  1826. X
  1827. X#ifndef HEAP_SEGMENT_SIZE
  1828. X#define HEAP_SEGMENT_SIZE 1492
  1829. X#endif
  1830. X
  1831. Xchar* _XtHeapAlloc(heap, bytes)
  1832. X    Heap*    heap;
  1833. X    Cardinal    bytes;
  1834. X{
  1835. X    register char* heap_loc;
  1836. X    if (heap == (Heap *) NULL) return XtMalloc(bytes);
  1837. X    if (heap->bytes_remaining < (int)bytes) {
  1838. X    if ((bytes + sizeof(char*)) >= (HEAP_SEGMENT_SIZE>>1)) {
  1839. X        /* preserve current segment; insert this one in front */
  1840. X#ifdef _TRACE_HEAP
  1841. X        printf( "allocating large segment (%d bytes) on heap %#x\n",
  1842. X            bytes, heap );
  1843. X#endif
  1844. X        heap_loc = XtMalloc(bytes + sizeof(char*));
  1845. X        if (heap->start) {
  1846. X        *(char**)heap_loc = *(char**)heap->start;
  1847. X        *(char**)heap->start = heap_loc;
  1848. X        }
  1849. X        else {
  1850. X        *(char**)heap_loc = NULL;
  1851. X        heap->start = heap_loc;
  1852. X        }
  1853. X        return heap_loc + sizeof(char*);
  1854. X    }
  1855. X    /* else discard remainder of this segment */
  1856. X#ifdef _TRACE_HEAP
  1857. X    printf( "allocating new segment on heap %#x\n", heap );
  1858. X#endif
  1859. X    heap_loc = XtMalloc((unsigned)HEAP_SEGMENT_SIZE);
  1860. X    *(char**)heap_loc = heap->start;
  1861. X    heap->start = heap_loc;
  1862. X    heap->current = heap_loc + sizeof(char*);
  1863. X    heap->bytes_remaining = HEAP_SEGMENT_SIZE - sizeof(char*);
  1864. X    }
  1865. X#ifdef WORD64
  1866. X    /* round to nearest 8-byte boundary */
  1867. X    bytes = (bytes + 7) & (~7);
  1868. X#else
  1869. X    /* round to nearest 4-byte boundary */
  1870. X    bytes = (bytes + 3) & (~3);
  1871. X#endif /* WORD64 */
  1872. X    heap_loc = heap->current;
  1873. X    heap->current += bytes;
  1874. X    heap->bytes_remaining -= bytes; /* can be negative, if rounded */
  1875. X    return heap_loc;
  1876. X}
  1877. X
  1878. Xvoid _XtHeapFree(heap)
  1879. X    Heap*    heap;
  1880. X{
  1881. X    char* segment = heap->start;
  1882. X    while (segment != NULL) {
  1883. X    char* next_segment = *(char**)segment;
  1884. X    XtFree(segment);
  1885. X    segment = next_segment;
  1886. X    }
  1887. X    heap->start = NULL;
  1888. X    heap->bytes_remaining = 0;
  1889. X}
  1890. END_OF_FILE
  1891. if test 3940 -ne `wc -c <'xheap.c'`; then
  1892.     echo shar: \"'xheap.c'\" unpacked with wrong size!
  1893. fi
  1894. # end of 'xheap.c'
  1895. fi
  1896. if test -f 'xmalloc.c' -a "${1}" != "-c" ; then 
  1897.   echo shar: Will not clobber existing file \"'xmalloc.c'\"
  1898. else
  1899. echo shar: Extracting \"'xmalloc.c'\" \(4617 characters\)
  1900. sed "s/^X//" >'xmalloc.c' <<'END_OF_FILE'
  1901. X/*
  1902. X * (c) Copyright 1990, 1991, 1992 Conor P. Cahill (cpcahil@virtech.vti.com)
  1903. X *
  1904. X * This software may be distributed freely as long as the following conditions
  1905. X * are met:
  1906. X *         * the distribution, or any derivative thereof, may not be
  1907. X *          included as part of a commercial product
  1908. X *        * full source code is provided including this copyright
  1909. X *        * there is no charge for the software itself (there may be
  1910. X *          a minimal charge for the copying or distribution effort)
  1911. X *        * this copyright notice is not modified or removed from any
  1912. X *          source file
  1913. X */
  1914. X#ifndef lint
  1915. Xstatic char rcs_hdr[] = "$Id: xmalloc.c,v 1.7 1992/08/22 16:27:13 cpcahil Exp $";
  1916. X#endif
  1917. X
  1918. X/* $XConsortium: Alloc.c,v 1.46 91/07/30 11:04:41 rws Exp $ */
  1919. X
  1920. X/***********************************************************
  1921. XCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts,
  1922. Xand the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  1923. X
  1924. X                        All Rights Reserved
  1925. X
  1926. XPermission to use, copy, modify, and distribute this software and its 
  1927. Xdocumentation for any purpose and without fee is hereby granted, 
  1928. Xprovided that the above copyright notice appear in all copies and that
  1929. Xboth that copyright notice and this permission notice appear in 
  1930. Xsupporting documentation, and that the names of Digital or MIT not be
  1931. Xused in advertising or publicity pertaining to distribution of the
  1932. Xsoftware without specific, written prior permission.  
  1933. X
  1934. XDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  1935. XALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  1936. XDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  1937. XANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  1938. XWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  1939. XARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  1940. XSOFTWARE.
  1941. X
  1942. X******************************************************************/
  1943. X
  1944. X#include <stdio.h>
  1945. X
  1946. X#include "sysdefs.h"
  1947. X
  1948. X#if FOUND_X_INTRINSIC
  1949. X#include "X11/Intrinsic.h"
  1950. X#endif
  1951. X
  1952. X#include "mallocin.h"
  1953. X
  1954. Xvoid _XtAllocError(type)
  1955. X    CONST char * type;
  1956. X{
  1957. X    Cardinal num_params = 1;
  1958. X    extern String XtCXtToolkitError;
  1959. X
  1960. X    if (type == NULL) type = "local memory allocation";
  1961. X    XtErrorMsg("allocError", type, XtCXtToolkitError,
  1962. X           "Cannot perform %s", &type, &num_params);
  1963. X}
  1964. X
  1965. Xvoid
  1966. X_XtBCopy(b1, b2, length)
  1967. X    char        * b1;
  1968. X    char        * b2;
  1969. X    int          length;
  1970. X{
  1971. X    DBFmemcpy("_XtBCopy", (char *)NULL, 0, b2, b1, (MEMSIZE)length);
  1972. X}
  1973. X
  1974. Xvoid
  1975. Xdebug_XtBcopy(file, line, b1, b2, length)
  1976. X    char         * file;
  1977. X    int          line;
  1978. X    char        * b1;
  1979. X    char        * b2;
  1980. X    int          length;
  1981. X{
  1982. X    DBFmemcpy("_XtBCopy", file, line, b2, b1, (MEMSIZE) length);
  1983. X}
  1984. X
  1985. Xchar *
  1986. XXtMalloc(size)
  1987. X    unsigned int      size;
  1988. X{
  1989. X    return( debug_XtMalloc((char *)NULL, 0, size) );
  1990. X}
  1991. X
  1992. Xchar *
  1993. Xdebug_XtMalloc(file,line,size)
  1994. X    CONST char    * file;
  1995. X    int          line;
  1996. X    unsigned int      size;
  1997. X{
  1998. X    static IDTYPE      call_counter;
  1999. X    char        * ptr;
  2000. X
  2001. X    /*
  2002. X     * increment call counter
  2003. X     */
  2004. X    call_counter++;
  2005. X
  2006. X    ptr = (char *) DBFmalloc("XtMalloc",M_T_XTMALLOC, call_counter,
  2007. X                  file, line, (SIZETYPE)size);
  2008. X
  2009. X    if( ptr == NULL )
  2010. X    {
  2011. X            _XtAllocError("malloc");
  2012. X    }
  2013. X
  2014. X    return(ptr);
  2015. X}
  2016. X
  2017. Xchar *
  2018. XXtRealloc(ptr, size)
  2019. X    char        * ptr;
  2020. X    unsigned int      size;
  2021. X{
  2022. X    return( debug_XtRealloc((char *)NULL,0,ptr,size) );
  2023. X}
  2024. X
  2025. Xchar *
  2026. Xdebug_XtRealloc(file,line,ptr, size)
  2027. X    CONST char    * file;
  2028. X    int          line;
  2029. X    char           * ptr;
  2030. X    unsigned int      size;
  2031. X{
  2032. X    static IDTYPE      call_counter;
  2033. X
  2034. X    /*
  2035. X     * increment call counter
  2036. X     */
  2037. X    call_counter++;
  2038. X    
  2039. X    ptr = (char *) DBFrealloc("XtRealloc",M_T_XTREALLOC, call_counter,
  2040. X                  file,line,ptr,(SIZETYPE)size);
  2041. X
  2042. X    if( ptr == NULL )
  2043. X    {
  2044. X            _XtAllocError("realloc");
  2045. X    }
  2046. X
  2047. X    return(ptr);
  2048. X}
  2049. X
  2050. Xchar *
  2051. XXtCalloc(num, size)
  2052. X    unsigned int      num;
  2053. X    unsigned int      size;
  2054. X{
  2055. X    return( debug_XtCalloc((char *)NULL, 0, num,size) );
  2056. X}
  2057. X
  2058. Xchar *
  2059. Xdebug_XtCalloc(file,line,num,size)
  2060. X    CONST char    * file;
  2061. X    int          line;
  2062. X    unsigned int      num;
  2063. X    unsigned int      size;
  2064. X{
  2065. X    static IDTYPE      call_counter;
  2066. X    char        * ptr;
  2067. X
  2068. X    /*
  2069. X     * increment call counter
  2070. X     */
  2071. X    call_counter++;
  2072. X
  2073. X    ptr = (char *) DBFcalloc("XtCalloc",M_T_XTCALLOC, call_counter,
  2074. X                  file,line,(SIZETYPE)num,(SIZETYPE)size);
  2075. X
  2076. X    if( ptr == NULL )
  2077. X    {
  2078. X            _XtAllocError("calloc");
  2079. X    }
  2080. X
  2081. X    return(ptr);
  2082. X}
  2083. X
  2084. Xvoid
  2085. XXtFree(ptr)
  2086. X    char    * ptr;
  2087. X{
  2088. X    debug_XtFree( (char *) NULL, 0, ptr);
  2089. X}
  2090. X
  2091. Xvoid
  2092. Xdebug_XtFree(file,line,ptr)
  2093. X    CONST char     * file;
  2094. X    int          line;
  2095. X    char        * ptr;
  2096. X{
  2097. X    static IDTYPE      call_counter;
  2098. X    
  2099. X    /*
  2100. X     * increment call counter
  2101. X     */
  2102. X    call_counter++;
  2103. X
  2104. X    DBFfree("XtFree",F_T_XTFREE,call_counter,file,line,ptr);
  2105. X}
  2106. X
  2107. X
  2108. X#ifndef DONT_FORCE_HEAPSTUFF
  2109. X
  2110. Xvoid
  2111. XNeverCalledFunctionFromAnywhere()
  2112. X{
  2113. X    _XtHeapInit(NULL);
  2114. X}
  2115. X
  2116. X#endif
  2117. X
  2118. END_OF_FILE
  2119. if test 4617 -ne `wc -c <'xmalloc.c'`; then
  2120.     echo shar: \"'xmalloc.c'\" unpacked with wrong size!
  2121. fi
  2122. # end of 'xmalloc.c'
  2123. fi
  2124. echo shar: End of archive 9 \(of 10\).
  2125. cp /dev/null ark9isdone
  2126. MISSING=""
  2127. for I in 1 2 3 4 5 6 7 8 9 10 ; do
  2128.     if test ! -f ark${I}isdone ; then
  2129.     MISSING="${MISSING} ${I}"
  2130.     fi
  2131. done
  2132. if test "${MISSING}" = "" ; then
  2133.     echo You have unpacked all 10 archives.
  2134.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2135. else
  2136.     echo You still need to unpack the following archives:
  2137.     echo "        " ${MISSING}
  2138. fi
  2139. ##  End of shell archive.
  2140. exit 0
  2141. *** SENTINEL(tm) The ultimate Debugging Environment - email for more info ***
  2142.  
  2143. Conor P. Cahill              (703)430-9247            cpcahil@virtech.vti.com
  2144. Virtual Technologies, Inc.  46030 Manekin Plaza          Dulles, VA 21066 
  2145.  
  2146. exit 0 # Just in case...
  2147.