From 66c0935d6725c49fda028fc9de27157fb9609a56 Mon Sep 17 00:00:00 2001 From: Bob Ippolito Date: Thu, 25 May 2006 19:59:56 +0000 Subject: enable darwin/x86 support for libffi and hence ctypes (doesn't yet support --enable-universalsdk) --- Modules/_ctypes/libffi/configure | 16 +++++++- Modules/_ctypes/libffi/configure.ac | 29 +++++++++++++- Modules/_ctypes/libffi/fficonfig.h.in | 15 ++++++- Modules/_ctypes/libffi/fficonfig.py.in | 12 ++++++ Modules/_ctypes/libffi/src/powerpc/darwin.S | 2 + .../_ctypes/libffi/src/powerpc/darwin_closure.S | 2 + Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c | 2 + Modules/_ctypes/libffi/src/prep_cif.c | 46 +++++++++++++++++++++- Modules/_ctypes/libffi/src/x86/ffitarget.h | 2 +- 9 files changed, 120 insertions(+), 6 deletions(-) diff --git a/Modules/_ctypes/libffi/configure b/Modules/_ctypes/libffi/configure index 27abbec..9fdd654 100755 --- a/Modules/_ctypes/libffi/configure +++ b/Modules/_ctypes/libffi/configure @@ -3483,6 +3483,7 @@ fi TARGETDIR="unknown" case "$host" in +i*86-*-darwin*) TARGET=X86_DARWIN; TARGETDIR=x86;; i*86-*-linux*) TARGET=X86; TARGETDIR=x86;; i*86-*-gnu*) TARGET=X86; TARGETDIR=x86;; i*86-*-solaris2.1[0-9]*) TARGET=X86_64; TARGETDIR=x86;; @@ -5243,6 +5244,9 @@ presetting ac_cv_c_bigendian=no (or yes) will help" >&2;} esac + + + if test x$TARGET = xSPARC; then echo "$as_me:$LINENO: checking assembler and linker support unaligned pc related relocs" >&5 echo $ECHO_N "checking assembler and linker support unaligned pc related relocs... $ECHO_C" >&6 @@ -5470,7 +5474,15 @@ _ACEOF ac_config_commands="$ac_config_commands src" - ac_config_links="$ac_config_links include/ffitarget.h:src/$TARGETDIR/ffitarget.h" +TARGETINCDIR=$TARGETDIR +case $host in +*-*-darwin*) + TARGETINCDIR="darwin" + ;; +esac + + + ac_config_links="$ac_config_links include/ffitarget.h:src/$TARGETINCDIR/ffitarget.h" ac_config_links="$ac_config_links include/ffi_common.h:include/ffi_common.h" @@ -6017,7 +6029,7 @@ do # Handling of arguments. "include/ffi.h" ) CONFIG_FILES="$CONFIG_FILES include/ffi.h" ;; "fficonfig.py" ) CONFIG_FILES="$CONFIG_FILES fficonfig.py" ;; - "include/ffitarget.h" ) CONFIG_LINKS="$CONFIG_LINKS include/ffitarget.h:src/$TARGETDIR/ffitarget.h" ;; + "include/ffitarget.h" ) CONFIG_LINKS="$CONFIG_LINKS include/ffitarget.h:src/$TARGETINCDIR/ffitarget.h" ;; "include/ffi_common.h" ) CONFIG_LINKS="$CONFIG_LINKS include/ffi_common.h:include/ffi_common.h" ;; "include" ) CONFIG_COMMANDS="$CONFIG_COMMANDS include" ;; "src" ) CONFIG_COMMANDS="$CONFIG_COMMANDS src" ;; diff --git a/Modules/_ctypes/libffi/configure.ac b/Modules/_ctypes/libffi/configure.ac index 6dafe35..a0d7513 100644 --- a/Modules/_ctypes/libffi/configure.ac +++ b/Modules/_ctypes/libffi/configure.ac @@ -21,6 +21,7 @@ AC_FUNC_MMAP_BLACKLIST TARGETDIR="unknown" case "$host" in +i*86-*-darwin*) TARGET=X86_DARWIN; TARGETDIR=x86;; i*86-*-linux*) TARGET=X86; TARGETDIR=x86;; i*86-*-gnu*) TARGET=X86; TARGETDIR=x86;; i*86-*-solaris2.1[[0-9]]*) TARGET=X86_64; TARGETDIR=x86;; @@ -99,6 +100,24 @@ fi AC_SUBST(HAVE_LONG_DOUBLE) AC_C_BIGENDIAN +AH_VERBATIM([WORDS_BIGENDIAN], +[ +/* Define to 1 if your processor stores words with the most significant byte + first (like Motorola and SPARC, unlike Intel and VAX). + + The block below does compile-time checking for endianness on platforms + that use GCC and therefore allows compiling fat binaries on OSX by using + '-arch ppc -arch i386' as the compile flags. The phrasing was choosen + such that the configure-result is used on systems that don't use GCC. +*/ +#ifdef __BIG_ENDIAN__ +#define WORDS_BIGENDIAN 1 +#else +#ifndef __LITTLE_ENDIAN__ +#undef WORDS_BIGENDIAN +#endif +#endif]) + if test x$TARGET = xSPARC; then AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs], @@ -201,7 +220,15 @@ test -d src || mkdir src test -d src/$TARGETDIR || mkdir src/$TARGETDIR ], [TARGETDIR="$TARGETDIR"]) -AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h) +TARGETINCDIR=$TARGETDIR +case $host in +*-*-darwin*) + TARGETINCDIR="darwin" + ;; +esac + + +AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETINCDIR/ffitarget.h) AC_CONFIG_LINKS(include/ffi_common.h:include/ffi_common.h) AC_CONFIG_FILES(include/ffi.h fficonfig.py) diff --git a/Modules/_ctypes/libffi/fficonfig.h.in b/Modules/_ctypes/libffi/fficonfig.h.in index 0fd2db5..bcc5a58 100644 --- a/Modules/_ctypes/libffi/fficonfig.h.in +++ b/Modules/_ctypes/libffi/fficonfig.h.in @@ -114,9 +114,22 @@ /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS + /* Define to 1 if your processor stores words with the most significant byte - first (like Motorola and SPARC, unlike Intel and VAX). */ + first (like Motorola and SPARC, unlike Intel and VAX). + + The block below does compile-time checking for endianness on platforms + that use GCC and therefore allows compiling fat binaries on OSX by using + '-arch ppc -arch i386' as the compile flags. The phrasing was choosen + such that the configure-result is used on systems that don't use GCC. +*/ +#ifdef __BIG_ENDIAN__ +#define WORDS_BIGENDIAN 1 +#else +#ifndef __LITTLE_ENDIAN__ #undef WORDS_BIGENDIAN +#endif +#endif #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE diff --git a/Modules/_ctypes/libffi/fficonfig.py.in b/Modules/_ctypes/libffi/fficonfig.py.in index 89f7969..1a7a67a 100644 --- a/Modules/_ctypes/libffi/fficonfig.py.in +++ b/Modules/_ctypes/libffi/fficonfig.py.in @@ -6,6 +6,7 @@ ffi_platforms = { 'MIPS_IRIX': ['src/mips/ffi.c', 'src/mips/o32.S', 'src/mips/n32.S'], 'MIPS_LINUX': ['src/mips/ffi.c', 'src/mips/o32.S'], 'X86': ['src/x86/ffi.c', 'src/x86/sysv.S'], + 'X86_DARWIN': ['src/x86/ffi_darwin.c', 'src/x86/darwin.S'], 'X86_WIN32': ['src/x86/ffi.c', 'src/x86/win32.S'], 'SPARC': ['src/sparc/ffi.c', 'src/sparc/v8.S', 'src/sparc/v9.S'], 'ALPHA': ['src/alpha/ffi.c', 'src/alpha/osf.S'], @@ -26,6 +27,17 @@ ffi_platforms = { 'PA': ['src/pa/linux.S', 'src/pa/ffi.c'], } +# Build all darwin related files on all supported darwin architectures, this +# makes it easier to build universal binaries. +if 0: + all_darwin = ('X86_DARWIN', 'POWERPC_DARWIN') + all_darwin_files = [] + for pn in all_darwin: + all_darwin_files.extend(ffi_platforms[pn]) + for pn in all_darwin: + ffi_platforms[pn] = all_darwin_files + del all_darwin, all_darwin_files, pn + ffi_srcdir = '@srcdir@' ffi_sources += ffi_platforms['@MKTARGET@'] ffi_sources = [os.path.join('@srcdir@', f) for f in ffi_sources] diff --git a/Modules/_ctypes/libffi/src/powerpc/darwin.S b/Modules/_ctypes/libffi/src/powerpc/darwin.S index d8a1df5..917dc93 100644 --- a/Modules/_ctypes/libffi/src/powerpc/darwin.S +++ b/Modules/_ctypes/libffi/src/powerpc/darwin.S @@ -1,3 +1,4 @@ +#ifdef __ppc__ /* ----------------------------------------------------------------------- darwin.S - Copyright (c) 2000 John Hornkvist Copyright (c) 2004 Free Software Foundation, Inc. @@ -243,3 +244,4 @@ LEFDE1: .align LOG2_GPR_BYTES LLFB0$non_lazy_ptr: .g_long LFB0 +#endif diff --git a/Modules/_ctypes/libffi/src/powerpc/darwin_closure.S b/Modules/_ctypes/libffi/src/powerpc/darwin_closure.S index 6d9a364..71054f5 100644 --- a/Modules/_ctypes/libffi/src/powerpc/darwin_closure.S +++ b/Modules/_ctypes/libffi/src/powerpc/darwin_closure.S @@ -1,3 +1,4 @@ +#ifdef __ppc__ /* ----------------------------------------------------------------------- darwin_closure.S - Copyright (c) 2002, 2003, 2004, Free Software Foundation, Inc. based on ppc_closure.S @@ -315,3 +316,4 @@ L_ffi_closure_helper_DARWIN$lazy_ptr: .align LOG2_GPR_BYTES LLFB1$non_lazy_ptr: .g_long LFB1 +#endif diff --git a/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c b/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c index 9337e66..1595b00 100644 --- a/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c +++ b/Modules/_ctypes/libffi/src/powerpc/ffi_darwin.c @@ -1,3 +1,4 @@ +#ifdef __ppc__ /* ----------------------------------------------------------------------- ffi.c - Copyright (c) 1998 Geoffrey Keating @@ -767,3 +768,4 @@ int ffi_closure_helper_DARWIN (ffi_closure* closure, void * rvalue, /* Tell ffi_closure_ASM to perform return type promotions. */ return cif->rtype->type; } +#endif diff --git a/Modules/_ctypes/libffi/src/prep_cif.c b/Modules/_ctypes/libffi/src/prep_cif.c index 0faa5dd..8d76718 100644 --- a/Modules/_ctypes/libffi/src/prep_cif.c +++ b/Modules/_ctypes/libffi/src/prep_cif.c @@ -55,11 +55,29 @@ static ffi_status initialize_aggregate(/*@out@*/ ffi_type *arg) /* Perform a sanity check on the argument type */ FFI_ASSERT_VALID_TYPE(*ptr); +#ifdef POWERPC_DARWIN + { + int curalign; + + curalign = (*ptr)->alignment; + if (ptr != &(arg->elements[0])) { + if (curalign > 4 && curalign != 16) { + curalign = 4; + } + } + arg->size = ALIGN(arg->size, curalign); + arg->size += (*ptr)->size; + + arg->alignment = (arg->alignment > curalign) ? + arg->alignment : curalign; + } +#else arg->size = ALIGN(arg->size, (*ptr)->alignment); arg->size += (*ptr)->size; arg->alignment = (arg->alignment > (*ptr)->alignment) ? arg->alignment : (*ptr)->alignment; +#endif ptr++; } @@ -89,6 +107,19 @@ static ffi_status initialize_aggregate(/*@out@*/ ffi_type *arg) /* Perform machine independent ffi_cif preparation, then call machine dependent routine. */ +#ifdef X86_DARWIN +static inline int struct_on_stack(int size) +{ + if (size > 8) return 1; + /* This is not what the ABI says, but is what is really implemented */ + switch (size) { + case 1: case 2: case 4: case 8: return 0; + return 1; + } +} +#endif + + ffi_status ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif *cif, ffi_abi abi, unsigned int nargs, /*@dependent@*/ /*@out@*/ /*@partial@*/ ffi_type *rtype, @@ -124,6 +155,10 @@ ffi_status ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif *cif, #ifdef SPARC && (cif->abi != FFI_V9 || cif->rtype->size > 32) #endif +#ifdef X86_DARWIN + + && (struct_on_stack(cif->rtype->size)) +#endif ) bytes = STACK_ARG_SIZE(sizeof(void*)); #endif @@ -139,7 +174,16 @@ ffi_status ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif *cif, check after the initialization. */ FFI_ASSERT_VALID_TYPE(*ptr); -#if !defined __x86_64__ && !defined S390 && !defined PA +#if defined(X86_DARWIN) + { + int align = (*ptr)->alignment; + if (align > 4) align = 4; + if ((align - 1) & bytes) + bytes = ALIGN(bytes, align); + bytes += STACK_ARG_SIZE((*ptr)->size); + } + +#elif !defined __x86_64__ && !defined S390 && !defined PA #ifdef SPARC if (((*ptr)->type == FFI_TYPE_STRUCT && ((*ptr)->size > 16 || cif->abi != FFI_V9)) diff --git a/Modules/_ctypes/libffi/src/x86/ffitarget.h b/Modules/_ctypes/libffi/src/x86/ffitarget.h index 9500f40..8b20d3c 100644 --- a/Modules/_ctypes/libffi/src/x86/ffitarget.h +++ b/Modules/_ctypes/libffi/src/x86/ffitarget.h @@ -51,7 +51,7 @@ typedef enum ffi_abi { #endif /* ---- Intel x86 and AMD x86-64 - */ -#if !defined(X86_WIN32) && (defined(__i386__) || defined(__x86_64__)) +#if !defined(X86_WIN32) && (defined(__i386__) || defined(__x86_64__)) FFI_SYSV, FFI_UNIX64, /* Unix variants all use the same ABI for x86-64 */ #ifdef __i386__ -- cgit v0.12 ='n119' href='#n119'>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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * 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 COPYING file, which can be found at the root of the source code       *
 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
 * If you do not have access to either file, you may request a copy from     *
 * help@hdfgroup.org.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
 * Programmer:  James Laird <jlaird@ncsa.uiuc.edu>
 *              Thursday, March 30, 2006
 *
 * Purpose:     This file contains declarations which are visible only within
 *              the H5SM shared object header messages package.  Source files
 *              outside the H5SM package should	include H5SMprivate.h instead.
 */
#if !(defined H5SM_FRIEND || defined H5SM_MODULE)
#error "Do not include this file outside the H5SM package!"
#endif

#ifndef _H5SMpkg_H
#define _H5SMpkg_H

/* Get package's private header */
#include "H5SMprivate.h"	/* Shared Object Header Messages	*/

/* Other private headers needed by this file */
#include "H5ACprivate.h"        /* Metadata Cache		  	*/
#include "H5B2private.h"        /* B-trees                              */
#include "H5HFprivate.h"        /* Fractal heaps		  	*/


/****************************/
/* Package Macros           */
/****************************/

/* Size of checksum information (on disk) */
#define H5SM_SIZEOF_CHECKSUM 4

#define H5SM_HEAP_LOC_SIZE (                                                  \
        (unsigned)4                     /* Reference count */                 \
        + sizeof(H5O_fheap_id_t)        /* size of heap ID on disk */         \
    )

#define H5SM_OH_LOC_SIZE(f) (                                                 \
        (unsigned)1             /* reserved (possible flags?) */              \
        + (unsigned)1           /* message type ID */			      \
        + (unsigned)2           /* creation index of message in OH */         \
        + H5F_SIZEOF_ADDR(f)    /* address of OH */                           \
    )

#define H5SM_SOHM_ENTRY_SIZE(f) (                                             \
        (unsigned)1             /* Message location */                        \
        + (unsigned)4           /* Hash value */                              \
        + MAX(H5SM_HEAP_LOC_SIZE, H5SM_OH_LOC_SIZE(f))  /* Entry */           \
    )

#define H5SM_INDEX_HEADER_SIZE(f) (                                           \
        (unsigned)1             /* Whether index is a list or B-tree */       \
        + (unsigned)1           /* Version of index format */                 \
        + (unsigned)2           /* Type of messages stored in the index */    \
        + (unsigned)4           /* Minimum size of messages to share */       \
        + (unsigned)(3 * 2)     /* B-tree cutoff, list cutoff, # of shared messages */ \
        + H5F_SIZEOF_ADDR(f)    /* Location of list or B-tree */              \
        + H5F_SIZEOF_ADDR(f)    /* Address of heap */                         \
    )

/* Format overhead for all SOHM tree metadata in the file */
#define H5SM_METADATA_PREFIX_SIZE (                                           \
    H5_SIZEOF_MAGIC             /* Signature */                               \
    + H5SM_SIZEOF_CHECKSUM      /* Checksum */                                \
    )

#define H5SM_TABLE_SIZE(f) (                                                  \
    /* General metadata fields */                                             \
    H5SM_METADATA_PREFIX_SIZE                                                 \
                                                                              \
    /* Indices */                                                             \
    + (H5F_SOHM_NINDEXES(f) * H5SM_INDEX_HEADER_SIZE(f))                      \
    )

#define H5SM_LIST_SIZE(f, num_mesg) (                                         \
    /* General metadata fields */                                             \
    H5SM_METADATA_PREFIX_SIZE                                                 \
                                                                              \
    /* Message entries */                                                     \
    + (H5SM_SOHM_ENTRY_SIZE(f) * num_mesg)                                    \
    )

#define H5SM_B2_NODE_SIZE 512
#define H5SM_B2_SPLIT_PERCENT 100
#define H5SM_B2_MERGE_PERCENT 40

#define H5SM_LIST_VERSION	0	/* Version of Shared Object Header Message List Indexes */

/****************************/
/* Package Typedefs         */
/****************************/

/* There are a number of Shared Object Header Message-specific structs here.
 *
 * The H5SM_master_table_t is pointed to by the file superblock.  Since a file
 * can have more than one SOHM index, this table collects all the indexes into
 * one place.  It holds an array of H5SM_index_header_t structs.
 *
 * An H5SM_index_header_t is actually the for a given index.  It holds
 * the number of messages in the index, the types of messages in the index,
 * etc.  It also records whether the index is a list or a b-tree, and has
 * the address of the list or b-tree.
 *
 * If the index is a list, the address in the index header should be given
 * to the cache, which can load it into a H5SM_list_t struct.  This is mostly
 * just a header for the cache information; it contains a pointer back to
 * the index header and an unsorted array of messages.
 *
 * These messages are H5SM_sohm_t structs.  They hold the actual SOHM's
 * address, hash value, and refcount.
 *
 * If the index is a b-tree, the H5SM_index_header_t struct holds the address
 * of the b-tree instead of the address of a H5SM_list_t.  The B-tree's nodes
 * are still 'H5SM_sohm_t's.
 *
 * H5SM_mesg_key_t structs are used to search lists and B-trees for a certain
 * message.  They correspond to a message that hasn't yet been written to
 * disk.
 */

/* Where a message is stored */
typedef enum {
    H5SM_NO_LOC = -1,
    H5SM_IN_HEAP = 0,    	/* Message is stored in the heap */
    H5SM_IN_OH    		/* Message is stored in an object header */
} H5SM_storage_loc_t;

/* Typedef for a record's location if it's stored in the heap */
typedef struct {
    hsize_t ref_count;		/* Number of times this message is used in the file */
    H5O_fheap_id_t fheap_id;    /* ID of the OHM in the fractal heap */
} H5SM_heap_loc_t;

/* Typedef for a SOHM index node */
typedef struct {
    H5SM_storage_loc_t location;        /* Type of message location */
    uint32_t hash;		        /* Hash value for encoded OHM */
    unsigned msg_type_id;               /* Message's type ID */
    union {
        H5O_mesg_loc_t mesg_loc;        /* Location of message in object header */
        H5SM_heap_loc_t heap_loc;       /* Heap ID for message in SOHM heap */
    } u;
} H5SM_sohm_t;

/* Types of message indices */
typedef enum {
    H5SM_BADTYPE = -1,
    H5SM_LIST,    		/* Index is an unsorted list */
    H5SM_BTREE    		/* Index is a sorted B-tree */
} H5SM_index_type_t;

/* Typedef for a SOHM index header */
typedef struct {
/* Stored */
    unsigned mesg_types;	/* Bit flag vector of message types */
    size_t min_mesg_size;	/* number of messages being tracked */
    size_t list_max;		/* >= this many messages, index with a B-tree */
    size_t btree_min;		/* <= this many messages, index with a list again */
    size_t num_messages;	/* number of messages being tracked */
    H5SM_index_type_t index_type; /* Is the index a list or a B-tree? */
    haddr_t index_addr;		/* Address of the actual index (list or B-tree) */
    haddr_t heap_addr;		/* Address of the fheap used to store shared messages */

/* Not stored */
    size_t list_size;           /* Size of list index on disk */
} H5SM_index_header_t;

/* Typedef for a SOHM list */
typedef struct {
    /* Information for H5AC cache functions, _must_ be first field in structure */
    H5AC_info_t cache_info;

    H5SM_index_header_t *header;    /* Pointer to the corresponding index header */
    H5SM_sohm_t *messages;          /* Actual list, stored as an array */
} H5SM_list_t;

/* Typedef for shared object header message master table */
struct H5SM_master_table_t {
    /* Information for H5AC cache functions, _must_ be first field in structure */
    H5AC_info_t cache_info;

    size_t table_size;              /* Size of table on disk */
    unsigned num_indexes;           /* Number of indexes */
    H5SM_index_header_t *indexes;   /* Array of num_indexes indexes */
};

/* Typedef for searching an index (list or B-tree) */
typedef struct {
    H5F_t *file;                        /* File in which sharing is happening */
    H5HF_t *fheap;    			/* The heap for this message type, open. */
    void *encoding; 		        /* The message encoded, or NULL */
    size_t encoding_size; 		/* Size of the encoding, or 0 */
    H5SM_sohm_t message;                /* The message to find/insert.
                                         * If the message doesn't yet have a
                                         * heap ID, the heap ID will be 0. */
} H5SM_mesg_key_t;

/*
 * Data exchange structure to pass through the fractal heap layer for the
 * H5HF_op function when computing a hash value for a message.
 */
typedef struct {
    /* downward (internal) */
    unsigned    type_id;                /* Message type */

    /* upward */
    uint32_t    hash;                   /* Hash value */
} H5SM_fh_ud_gh_t;

/* Typedef to increment a reference count in the B-tree */
typedef struct {
    H5SM_mesg_key_t *key;       /* IN: key for message being incremented */
    H5O_fheap_id_t fheap_id;    /* OUT: fheap ID of record */
} H5SM_incr_ref_opdata;

/* v2 B-tree client callback context */
typedef struct H5SM_bt2_ctx_t {
    uint8_t     sizeof_addr;    /* Size of file addresses */
} H5SM_bt2_ctx_t;

/* Callback info for loading a shared message table index into the cache */
typedef struct H5SM_table_cache_ud_t {
    H5F_t *f;                   /* File that shared message index stored as a table is in */
} H5SM_table_cache_ud_t;

/* Callback info for loading a shared message list index into the cache */
typedef struct H5SM_list_cache_ud_t {
    H5F_t *f;                   /* File that shared message index stored as a table is in */
    H5SM_index_header_t *header; /* Index header for this list */
} H5SM_list_cache_ud_t;


/****************************/
/* Package Variables        */
/****************************/

/* Declare free lists to manage H5SM structs */
H5FL_EXTERN(H5SM_master_table_t);
H5FL_ARR_EXTERN(H5SM_index_header_t);
H5FL_EXTERN(H5SM_list_t);
H5FL_ARR_EXTERN(H5SM_sohm_t);

H5_DLLVAR const H5B2_class_t H5SM_INDEX[1];

/****************************/
/* Package Prototypes       */
/****************************/

/* General routines */
H5_DLL ssize_t H5SM_get_index(const H5SM_master_table_t *table, unsigned type_id);

/* Encode and decode routines, used for B-tree and cache encoding/decoding */
H5_DLL herr_t H5SM__message_compare(const void *rec1, const void *rec2, int *result);
H5_DLL herr_t H5SM__message_encode(uint8_t *raw, const void *native, void *ctx);
H5_DLL herr_t H5SM__message_decode(const uint8_t *raw, void *native, void *ctx);

/* H5B2_remove_t callback to add messages to a list index */
H5_DLL herr_t H5SM_bt2_convert_to_list_op(const void * record, void *op_data);

/* Fractal heap 'op' callback to compute hash value for message "in place" */
H5_DLL herr_t H5SM_get_hash_fh_cb(const void *obj, size_t obj_len, void *_udata);

/* Routines to release data structures */
herr_t H5SM_table_free(H5SM_master_table_t *table);
herr_t H5SM_list_free(H5SM_list_t *list);

/* Testing functions */
#ifdef H5SM_TESTING
H5_DLL herr_t H5SM__get_mesg_count_test(H5F_t *f, unsigned type_id, size_t *mesg_count);
#endif /* H5SM_TESTING */

#endif /* _H5SMpkg_H */