summaryrefslogtreecommitdiffstats
path: root/Mac/Include/pythonresources.h
blob: 8dfe9ad4e6465c9288af79c5addb471aa1ccec5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/***********************************************************
Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
The Netherlands.

                        All Rights Reserved

Permission to use, copy, modify, and distribute this software and its 
documentation for any purpose and without fee is hereby granted, 
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in 
supporting documentation, and that the names of Stichting Mathematisch
Centrum or CWI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior permission.

STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

******************************************************************/

/*
** Resource-IDs in use by Python.
**
** All resources used by the python interpreter itself fall
** in the range 228-256. The range 128-228 is not used, because
** there is too much chance of conflicts with other packages.
**
** Standard python modules use resources in the range
** 256-512.
**
** Python programs that use their own resources are advised to
** choose resource numbers higher than 512.
*/

/*
** Resources that reside in the python executable (or, for
** shared ppc python, in the core dynamic library)
*/
#ifndef Py_PYTHONRESOURCES_H
#define Py_PYTHONRESOURCES_H

#ifdef __cplusplus
	extern "C" {
#endif

#define BASE_ID 228

/* The alert for "No Python directory, where is it?" (OBSOLETE) */
#define NOPYTHON_ALERT	BASE_ID+0
#define YES_ITEM		1
#define NO_ITEM			2
#define CURWD_ITEM		3

/* The alert for "this is an applet template" */
#define NOPYC_ALERT		BASE_ID+1

/* The dialog for our GetDirectory and PromptGetFile call */
#define GETDIR_ID 		BASE_ID+2		/* Resource ID for our "get directory" */
#define GETFILEPROMPT_ID BASE_ID+4		/* Resource id for prompted get file */
#define PROMPT_ITEM		10				/* The prompt, at the top */
#define SELECTCUR_ITEM	11				/* "Select current directory" button */


/* The dialog for interactive options */
#define OPT_DIALOG		BASE_ID+3		/* Resource ID for dialog */
#define OPT_OK			1
#define OPT_CANCEL		2
#define OPT_INSPECT		3
#define OPT_VERBOSE		4
#define OPT_OPTIMIZE	5
#define OPT_UNBUFFERED	6
#define OPT_DEBUGGING	7
#define OPT_KEEPALWAYS	8
#define OPT_KEEPOUTPUT	9
#define OPT_KEEPERROR   10
#define OPT_KEEPNEVER   11
#define OPT_CMDLINE		12
#define OPT_TABWARN	13
#define OPT_NOSITE	14
#define OPT_HELP	15
#define OPT_NONAVSERV 16
#define OPT_VERBOSEVERBOSE	19
#define OPT_DIVISIONWARN	20
#define OPT_UNIXNEWLINES		21

/* Dialog for 'No preferences directory' */
#define NOPREFDIR_ID	BASE_ID+5

/* Dialog for 'Bad or outdated preferences' */
#define BADPREFERENCES_ID	BASE_ID+6
#define BADPREF_DELETE		1
#define BADPREF_CONTINUE	2
#define BADPREF_QUIT		3
/* Dialog for 'Bad preference file' */
#define BADPREFFILE_ID	BASE_ID+7

/* About box */
#define ABOUT_ID		BASE_ID+8

/* No preferences file name resource */
#define NOPREFNAME_ID	BASE_ID+9

/* Not a script */
#define NOTASCRIPT_ID BASE_ID+10

/* EditPythonPrefs range. Needed here to forestall conflicts with applets */
#define EDITPYTHONPREFS_MIN	508
#define EDITPYTHONPREFS_MAX 511
/* twit range. Again needed to forestall conflicts with scripts using their own resources */
#define TWIT_MIN		500
#define TWIT_MAX		507
/* Bruce range. The same */
#define BRUCE_MIN		468
#define BRUCE_MAX		499

/*
** The following are valid both in the binary (or shared library)
** and in the Preferences file.
** For all these the override is tried first, in the application resource fork
** only, this allows an applet to override standard settings.
** If there is no override resource the preferences file is added to the head
** of the resource file chain and the non-override version of the resource is
** searched in any resource file.
**
** The effect of this is that, for example, a 'Popt' of 228 in the application or
** shared library provides default options for use when no preferences are set,
** while a 'Popt' of 229 (in the application *only*) overrides any options in the
** preferences file.
*/

/* The STR resource that holds the preference file name */
#define PREFFILENAME_ID 228		/* For Rez only */
#define PREFFILENAME_PASCAL_NAME "PythonPreferenceFileName"
#define PREFFILENAME_NAME "\pPythonPreferenceFileName"

/* The STR# resource for sys.path initialization */
#define PYTHONPATH_ID 228
#define PYTHONPATHOVERRIDE_ID 229

/* The alis resource for locating the python home directory */
#define PYTHONHOME_ID 228
#define PYTHONHOMEOVERRIDE_ID 229

/* The Python options resource and offset of its members */
#define PYTHONOPTIONS_ID 228
#define PYTHONOPTIONSOVERRIDE_ID 229

#define POPT_VERSION_CURRENT	8	/* Current version number */
#define   POPT_KEEPCONSOLE_NEVER  0
#define   POPT_KEEPCONSOLE_OUTPUT 1
#define   POPT_KEEPCONSOLE_ERROR  2
#define   POPT_KEEPCONSOLE_ALWAYS 3

#ifndef rez
typedef struct PyMac_PrefRecord {
	unsigned char	version;
	unsigned char	inspect;
	unsigned char	verbose;
	unsigned char	optimize;
	unsigned char	unbuffered;
	unsigned char	debugging;
	unsigned char	unused;
	unsigned char	keep_console;
	unsigned char	nointopt;
	unsigned char	noargs;
	unsigned char	tabwarn;
	unsigned char	nosite;
	unsigned char	nonavservice;
	unsigned char	delayconsole;
	unsigned char	divisionwarn;
	unsigned char	unixnewlines;
} PyMac_PrefRecord;
#endif

/* The GUSI options resources */
#define GUSIOPTIONS_ID	10240
#define GUSIOPTIONSOVERRIDE_ID 10241

#ifndef rez
/* From macgetpath.c: */
void PyMac_PreferenceOptions(PyMac_PrefRecord *);
char * PyMac_GetPythonDir(void);
/* from macmain.c: */
extern PyMac_PrefRecord PyMac_options;
#endif

#ifdef __cplusplus
}
#endif

#endif
#n426'>426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have     *
 * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/* Programmer:  Quincey Koziol <koziol@ncsa.uiuc.edu>
 *              Tuesday, May 3, 2005
 */
#include "h5test.h"

/*
 * This file needs to access private datatypes from the H5MP package.
 * This file also needs to access the memory pool testing code.
 */
#define H5MP_PACKAGE
#define H5MP_TESTING
#include "H5MPpkg.h"		/* Memory Pools				*/

/* Other private headers that this test requires */

/* Local macros */
#define MPOOL_PAGE_SIZE         H5MP_PAGE_SIZE_DEFAULT
#define MPOOL_FLAGS             H5MP_FLG_DEFAULT
#define MPOOL_NUM_NORMAL_BLOCKS 15
#define MPOOL_NORMAL_BLOCK      512
#define MPOOL_LARGE_BLOCK       (MPOOL_PAGE_SIZE * 3)
#define MPOOL_NUM_SMALL_BLOCKS  64
#define MPOOL_SMALL_BLOCK       1
#define MPOOL_NUM_RANDOM        10*1024
#define MPOOL_RANDOM_MAX_SIZE   (MPOOL_PAGE_SIZE * 2)


/*-------------------------------------------------------------------------
 * Function:	test_create
 *
 * Purpose:	Test trivial creating & closing memory pool
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, May 3, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_create(void)
{
    H5MP_pool_t *mp;            /* Memory pool */
    H5MP_page_t *page;          /* Memory pool page */
    size_t free_size;           /* Free size in pool */

    /*
     * Test memory pool creation
     */
    TESTING("memory pool creation");

    /* Create a memory pool */
    if (NULL == (mp = H5MP_create(MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
        TEST_ERROR

    /* Check free space */
    if (H5MP_get_pool_free_size(mp, &free_size) < 0)
        TEST_ERROR;
    if(free_size != 0)
        TEST_ERROR

    /* Check first page */
    if (H5MP_get_pool_first_page(mp, &page) < 0)
        TEST_ERROR;
    if(page != NULL)
        TEST_ERROR

    /* Close the memory pool */
    if (H5MP_close(mp) < 0)
        TEST_ERROR

    PASSED();

    return 0;

error:
    H5E_BEGIN_TRY {
    } H5E_END_TRY;
    return 1;
} /* test_create() */


/*-------------------------------------------------------------------------
 * Function:	test_close_one
 *
 * Purpose:	Tests closing pool with one block allocated
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Friday, May 6, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_close_one(void)
{
    H5MP_pool_t *mp;            /* Memory pool */
    void *spc1;                 /* Pointer to space allocated */

    /*
     * Test memory pool closing
     */
    TESTING("closing pool with blocks still allocated in one page");

    /* Create a memory pool */
    if (NULL == (mp = H5MP_create(MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
        TEST_ERROR

    /* Allocate space in pool */
    if (NULL == (spc1 = H5MP_malloc(mp, MPOOL_NORMAL_BLOCK)))
        TEST_ERROR

    /* Close the memory pool */
    if (H5MP_close(mp) < 0)
        TEST_ERROR

    PASSED();

    return 0;

error:
    H5E_BEGIN_TRY {
    } H5E_END_TRY;
    return 1;
} /* test_close_one() */


/*-------------------------------------------------------------------------
 * Function:	test_allocate_first
 *
 * Purpose:	Tests allocating first block in pool
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, May 3, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_allocate_first(void)
{
    H5MP_pool_t *mp;            /* Memory pool */
    H5MP_page_t *page;          /* Memory pool page */
    size_t free_size;           /* Free size in pool */
    void *spc;                  /* Pointer to space allocated */

    /*
     * Test memory pool allocation
     */
    TESTING("allocating first block in pool");

    /* Create a memory pool */
    if (NULL == (mp = H5MP_create(MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
        TEST_ERROR

    /* Allocate space in pool */
    if (NULL == (spc = H5MP_malloc(mp, MPOOL_NORMAL_BLOCK)))
        TEST_ERROR

    /* Check pool's free space */
    if (H5MP_get_pool_free_size(mp, &free_size) < 0)
        TEST_ERROR;
    if(free_size != MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))))
        TEST_ERROR

    /* Get first page */
    if (H5MP_get_pool_first_page(mp, &page) < 0)
        TEST_ERROR;
    if(page == NULL)
        TEST_ERROR

    /* Check page's free space */
    if (H5MP_get_page_free_size(page, &free_size) < 0)
        TEST_ERROR;
    if(free_size != MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))))
        TEST_ERROR

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Check next page */
    if (H5MP_get_page_next_page(page, &page) < 0)
        TEST_ERROR;
    if(page != NULL)
        TEST_ERROR

    /* Free space in pool */
    H5MP_free(mp, spc);

    /* Check pool's free space */
    if (H5MP_get_pool_free_size(mp, &free_size) < 0)
        TEST_ERROR;
    if(free_size != MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))
        TEST_ERROR

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Close the memory pool */
    if (H5MP_close(mp) < 0)
        TEST_ERROR

    PASSED();

    TESTING("allocating large first block in pool");

    /* Create a memory pool */
    if (NULL == (mp = H5MP_create(MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
        TEST_ERROR

    /* Allocate space in pool */
    if (NULL == (spc = H5MP_malloc(mp, MPOOL_LARGE_BLOCK)))
        TEST_ERROR

    /* Check pool's free space */
    if (H5MP_get_pool_free_size(mp, &free_size) < 0)
        TEST_ERROR;
    if(free_size != 0)
        TEST_ERROR

    /* Get first page */
    if (H5MP_get_pool_first_page(mp, &page) < 0)
        TEST_ERROR;
    if(page == NULL)
        TEST_ERROR

    /* Check page's free space */
    if (H5MP_get_page_free_size(page, &free_size) < 0)
        TEST_ERROR;
    if(free_size != 0)
        TEST_ERROR

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Check next page */
    if (H5MP_get_page_next_page(page, &page) < 0)
        TEST_ERROR;
    if(page != NULL)
        TEST_ERROR

    /* Free space in pool */
    H5MP_free(mp, spc);

    /* Check pool's free space */
    if (H5MP_get_pool_free_size(mp, &free_size) < 0)
        TEST_ERROR;
    if(free_size != MPOOL_LARGE_BLOCK + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)))
        TEST_ERROR

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Close the memory pool */
    if (H5MP_close(mp) < 0)
        TEST_ERROR

    PASSED();

    return 0;

error:
    H5E_BEGIN_TRY {
    } H5E_END_TRY;
    return 1;
} /* test_allocate_first() */


/*-------------------------------------------------------------------------
 * Function:	test_allocate_split
 *
 * Purpose:	Tests allocating block in pool that requires splitting
 *              existing block
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, May 3, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_allocate_split(void)
{
    H5MP_pool_t *mp;            /* Memory pool */
    size_t free_size;           /* Free size in pool */
    void *spc1;                 /* Pointer to space allocated */
    void *spc2;                 /* Pointer to space allocated */

    /*
     * Test memory pool allocation
     */
    TESTING("splitting block in pool");

    /* Create a memory pool */
    if (NULL == (mp = H5MP_create(MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
        TEST_ERROR

    /* Allocate space in pool */
    if (NULL == (spc1 = H5MP_malloc(mp, MPOOL_NORMAL_BLOCK)))
        TEST_ERROR

    /* Check pool's free space */
    if (H5MP_get_pool_free_size(mp, &free_size) < 0)
        TEST_ERROR;
    if(free_size != MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))))
        TEST_ERROR

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Allocate more space in pool */
    if (NULL == (spc2 = H5MP_malloc(mp, MPOOL_NORMAL_BLOCK)))
        TEST_ERROR

    /* Check pool's free space */
    if (H5MP_get_pool_free_size(mp, &free_size) < 0)
        TEST_ERROR;
    if(free_size != MPOOL_PAGE_SIZE - (((H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))) * 2) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))))
        TEST_ERROR

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Free first block in pool */
    H5MP_free(mp, spc1);

    /* Check pool's free space */
    if (H5MP_get_pool_free_size(mp, &free_size) < 0)
        TEST_ERROR;
    if(free_size != MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))))
        TEST_ERROR

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Free second block in pool (should merge with first block) */
    H5MP_free(mp, spc2);

    /* Check pool's free space */
    if (H5MP_get_pool_free_size(mp, &free_size) < 0)
        TEST_ERROR;
    if(free_size != MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))
        TEST_ERROR

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Close the memory pool */
    if (H5MP_close(mp) < 0)
        TEST_ERROR

    PASSED();

    return 0;

error:
    H5E_BEGIN_TRY {
    } H5E_END_TRY;
    return 1;
} /* test_allocate_split() */


/*-------------------------------------------------------------------------
 * Function:	test_allocate_many_small
 *
 * Purpose:	Tests allocating many small blocks in a pool
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, May 6, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_allocate_many_small(void)
{
    H5MP_pool_t *mp;            /* Memory pool */
    size_t free_size;           /* Free size in pool */
    void *spc[MPOOL_NUM_SMALL_BLOCKS]; /* Pointers to space allocated */
    int i;                      /* Local index variable */

    /*
     * Test memory pool allocation
     */
    TESTING("allocating many small blocks");

    /* Create a memory pool */
    if (NULL == (mp = H5MP_create(MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
        TEST_ERROR

    /* Allocate space in pool */
    for (i = 0; i < MPOOL_NUM_SMALL_BLOCKS; i++)
        if (NULL == (spc[i] = H5MP_malloc(mp, MPOOL_SMALL_BLOCK)))
            TEST_ERROR

    /* Check pool's free space */
    if (H5MP_get_pool_free_size(mp, &free_size) < 0)
        TEST_ERROR;
    if(free_size != MPOOL_PAGE_SIZE - (((H5MP_BLOCK_ALIGN(MPOOL_SMALL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))) * MPOOL_NUM_SMALL_BLOCKS) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))))
        TEST_ERROR

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Free blocks in pool */
    /* (Tests free block merging with block after it */
    for(i = (MPOOL_NUM_SMALL_BLOCKS - 1); i >= 0; i--)
        H5MP_free(mp, spc[i]);

    /* Check pool's free space */
    if (H5MP_get_pool_free_size(mp, &free_size) < 0)
        TEST_ERROR;
    if(free_size != MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)))
        TEST_ERROR

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Close the memory pool */
    if (H5MP_close(mp) < 0)
        TEST_ERROR

    PASSED();

    return 0;

error:
    H5E_BEGIN_TRY {
    } H5E_END_TRY;
    return 1;
} /* test_allocate_many_small() */


/*-------------------------------------------------------------------------
 * Function:	test_allocate_new_page
 *
 * Purpose:	Tests allocating block in pool that requires allocating
 *              new page
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Friday, May 6, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_allocate_new_page(void)
{
    H5MP_pool_t *mp;            /* Memory pool */
    size_t free_size;           /* Free size in pool */
    size_t u;                   /* Local index variable */
    void *spc[MPOOL_NUM_NORMAL_BLOCKS]; /* Pointer to space allocated */
    void *spc1;                 /* Pointer to space allocated */
    void *spc2;                 /* Pointer to space allocated */

    /*
     * Test memory pool allocation
     */
    TESTING("allocate normal-sized block in new page");

    /* Create a memory pool */
    if (NULL == (mp = H5MP_create(MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
        TEST_ERROR

    /* Allocate space in pool */
    for(u = 0; u < MPOOL_NUM_NORMAL_BLOCKS; u++)
        if (NULL == (spc[u] = H5MP_malloc(mp, MPOOL_NORMAL_BLOCK)))
            TEST_ERROR

    /* Check pool's free space */
    if (H5MP_get_pool_free_size(mp, &free_size) < 0)
        TEST_ERROR;
    if(free_size != (MPOOL_PAGE_SIZE * 3) - (((H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))) * MPOOL_NUM_NORMAL_BLOCKS) + (H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)) * 3)))
        TEST_ERROR

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Free blocks in pool */
    /* (Free alternating blocks, in two passes, which tests block merging w/both neighbors) */
    for(u = 0; u < MPOOL_NUM_NORMAL_BLOCKS; u+=2)
        H5MP_free(mp, spc[u]);
    for(u = 1; u < MPOOL_NUM_NORMAL_BLOCKS; u+=2)
        H5MP_free(mp, spc[u]);

    /* Check pool's free space */
    if (H5MP_get_pool_free_size(mp, &free_size) < 0)
        TEST_ERROR;
    if(free_size != ((MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))) * 3))
        TEST_ERROR

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Close the memory pool */
    if (H5MP_close(mp) < 0)
        TEST_ERROR

    PASSED();

    TESTING("allocate large-sized block in new page");

    /* Create a memory pool */
    if (NULL == (mp = H5MP_create(MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
        TEST_ERROR

    /* Allocate space in pool */
    /* (Normal sized block) */
    if (NULL == (spc1 = H5MP_malloc(mp, MPOOL_NORMAL_BLOCK)))
        TEST_ERROR
    /* (Larger sized block) */
    if (NULL == (spc2 = H5MP_malloc(mp, MPOOL_LARGE_BLOCK)))
        TEST_ERROR

    /* Check pool's free space */
    if (H5MP_get_pool_free_size(mp, &free_size) < 0)
        TEST_ERROR;
    if(free_size != MPOOL_PAGE_SIZE - (H5MP_BLOCK_ALIGN(MPOOL_NORMAL_BLOCK) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t)) + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))))
        TEST_ERROR

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Free blocks in pool */
    H5MP_free(mp, spc1);
    H5MP_free(mp, spc2);

    /* Check pool's free space */
    if (H5MP_get_pool_free_size(mp, &free_size) < 0)
        TEST_ERROR;
    if(free_size != ((MPOOL_PAGE_SIZE - H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t))) +
            MPOOL_LARGE_BLOCK + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_blk_t))))
        TEST_ERROR

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Close the memory pool */
    if (H5MP_close(mp) < 0)
        TEST_ERROR

    PASSED();

    return 0;

error:
    H5E_BEGIN_TRY {
    } H5E_END_TRY;
    return 1;
} /* test_allocate_new_page() */


/*-------------------------------------------------------------------------
 * Function:	test_allocate_random
 *
 * Purpose:	Tests allocating random sized blocks in pool
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Friday, May 6, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
test_allocate_random(void)
{
    H5MP_pool_t *mp;            /* Memory pool */
    size_t u;                   /* Local index variable */
    time_t curr_time;           /* Current time, for seeding random number generator */
    size_t *blk_size = NULL;    /* Pointer to block sizes */
    void **spc = NULL;          /* Pointer to space allocated */
    size_t swap_idx;            /* Location to swap with when shuffling */
    void *swap_ptr;             /* Pointer to swap when shuffling */

    /*
     * Test memory pool allocation
     */
    TESTING("allocate many random sized blocks");

    /* Initialize random number seed */
    curr_time=HDtime(NULL);
#ifdef QAK
curr_time=1115412944;
HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time);
#endif /* QAK */
    HDsrandom((unsigned long)curr_time);

    /* Create a memory pool */
    if (NULL == (mp = H5MP_create(MPOOL_PAGE_SIZE, MPOOL_FLAGS)))
        TEST_ERROR

    /* Allocate space for the block sizes */
    if(NULL == (blk_size = HDmalloc(sizeof(size_t) * MPOOL_NUM_RANDOM)))
        TEST_ERROR

    /* Allocate space for the block pointers */
    if(NULL == (spc = HDmalloc(sizeof(void *) * MPOOL_NUM_RANDOM)))
        TEST_ERROR

    /* Initialize the block sizes with random values */
    for(u = 0; u < MPOOL_NUM_RANDOM; u++)
        blk_size[u] = (size_t)(HDrandom() % MPOOL_RANDOM_MAX_SIZE) + 1;

    /* Allocate space in pool */
    for(u = 0; u < MPOOL_NUM_RANDOM; u++)
        if (NULL == (spc[u] = H5MP_malloc(mp, blk_size[u])))
            TEST_ERROR

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Shuffle pointers to free */
    for(u = 0; u < MPOOL_NUM_RANDOM; u++) {
        swap_idx = (size_t)(HDrandom() % (MPOOL_NUM_RANDOM - u)) + u;
        swap_ptr = spc[u];
        spc[u] = spc[swap_idx];
        spc[swap_idx] = swap_ptr;
    } /* end for */

    /* Free blocks in pool */
    for(u = 0; u < MPOOL_NUM_RANDOM; u++)
        H5MP_free(mp, spc[u]);

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Initialize the block sizes with random values */
    for(u = 0; u < MPOOL_NUM_RANDOM; u++)
        blk_size[u] = (size_t)(HDrandom() % MPOOL_RANDOM_MAX_SIZE) + 1;

    /* Allocate space in pool (again) */
    /* (Leave allocated to test closing pool with many blocks still allocated) */
    for(u = 0; u < MPOOL_NUM_RANDOM; u++)
        if (NULL == (spc[u] = H5MP_malloc(mp, blk_size[u])))
            TEST_ERROR

    /* Check that free space totals match */
    if (H5MP_pool_is_free_size_correct(mp) <= 0)
        TEST_ERROR;

    /* Close the memory pool */
    if (H5MP_close(mp) < 0)
        TEST_ERROR

    /* Free memory for block sizes & pointers */
    HDfree(blk_size);
    HDfree(spc);

    PASSED();

    return 0;

error:
    if(blk_size)
        HDfree(blk_size);
    if(spc)
        HDfree(spc);
    H5E_BEGIN_TRY {
    } H5E_END_TRY;
    return 1;
} /* test_allocate_random() */


/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	Test the memory pool code
 *
 * Return:	Success:
 *
 *		Failure:
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, May 3, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    int		nerrors=0;

    /* Reset library */
    h5_reset();

    /* Test memory pool creation */
    nerrors += test_create();

    /* Test memory pool space closing */
    nerrors += test_close_one();

    /* Test memory pool space allocation */
    nerrors += test_allocate_first();
    nerrors += test_allocate_split();
    nerrors += test_allocate_many_small();
    nerrors += test_allocate_new_page();
    nerrors += test_allocate_random();

    if (nerrors) goto error;
    puts("All memory pool tests passed.");
    return 0;

error:
    puts("*** TESTS FAILED ***");
    H5E_BEGIN_TRY {
    } H5E_END_TRY;
    return 1;
}