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

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