Ejemplo n.º 1
0
void test_refcounting(hid_t a_id, hid_t b_id) {

    RefTester a_tst = a_id;
    RefTester b_tst = b_id;

    T obj_invalid{};
    CPPUNIT_ASSERT_EQUAL(H5I_INVALID_HID, obj_invalid.h5id());

    T wa_copy(a_id, true); // +1
    a_tst.inc_check(&wa_copy);

    //non-transfering ownership test
    H5Iinc_ref(a_id); // +1, because if we transfer ownership, the need an extra one
    a_tst.inc_check();
    T wa_owner(a_id, false); // =, take ownership, no refcount change to a
    a_tst.check(&wa_owner);

    H5Iinc_ref(a_id);
    a_tst.inc_check();
    T wa_ic = a_id; // =, this transfers ownership
    a_tst.check(&wa_ic);

    {
        T tmp = T(a_id, true); //+1
        a_tst.inc_check(&tmp);
    }
    a_tst.dec_check();

    {
        T tmp = T(a_id, true); //+1
        a_tst.inc_check(&tmp);
        tmp.close();        //-1
        a_tst.dec_check();
    }

    a_tst.check();  // =

    wa_copy = wa_owner; //=, self assignment, i.e. no inc ref

    a_tst.check(&wa_copy);
    a_tst.check(&wa_owner);

    //now with two objects ...

    CPPUNIT_ASSERT(a_id != b_id);

    T wb_copy(b_id, true); // + 1
    b_tst.inc_check(&wb_copy);

    // copy-assignment ctor
    wa_copy = wb_copy; // + 1 b, - 1 a
    a_tst.dec_check();
    b_tst.inc_check(&wb_copy);
    b_tst.check(&wa_copy);
}
Ejemplo n.º 2
0
inline group::group(group const& other)
  : hid_(other.hid_)
{
    // copying would be safe if the exception were disabled.
    throw error("h5xx::group can not be copied. Copying must be elided by return value optimisation.");
    H5Iinc_ref(hid_);
}
Ejemplo n.º 3
0
 void update(hid_t id, F close, bool increment) {
     if (id && increment) {
         MPQC_FILE_THREADSAFE;
         MPQC_FILE_VERIFY(H5Iinc_ref(id));
     }
     id_ = id;
     close_ = close;
 }
Ejemplo n.º 4
0
/*
 * Class:     hdf_hdf5lib_H5
 * Method:    H5Iinc_ref
 * Signature: (J)I
 */
JNIEXPORT jint JNICALL
Java_hdf_hdf5lib_H5_H5Iinc_1ref
    (JNIEnv *env, jclass clss, jlong obj_id)
{
    int retVal = -1;

    retVal = H5Iinc_ref((hid_t)obj_id);
    if (retVal < 0)
        h5libraryError(env);

    return (jint)retVal;
} /* end Java_hdf_hdf5lib_H5_H5Iinc_1ref */
Ejemplo n.º 5
0
Archivo: H5If.c Proyecto: ElaraFX/hdf5
/****if* H5If/h5iinc_ref_c
 * NAME
 *  h5iinc_ref_c
 * PURPOSE
 *  Call H5Iinc_ref to increment object's reference count
 * INPUTS
 *  obj_id - object identifier
 * OUTPUTS
 *  ref_count - Reference count of ID
 * RETURNS
 *  current reference count on success, -1 on failure
 * AUTHOR
 *  Quincey Koziol
 *  Tuesday, December  9, 2003
 * SOURCE
*/
int_f
h5iinc_ref_c(hid_t_f *obj_id, int_f *ref_count)
/******/
{
     int ret_value;

     /*
      * Call H5Iinc_ref function
      */
     if ((ret_value = H5Iinc_ref(*obj_id)) < 0)
         HGOTO_DONE(FAIL);

    /* Set output & return values */
    *ref_count=ret_value;
    ret_value=0;

done:
      return ret_value;
}
Ejemplo n.º 6
0
/* Test function */
static int test_remove_clear_type(void)
{
    H5I_type_t obj_type;
    test_rct_list_t obj_list;
    test_rct_obj_t list[TEST_RCT_MAX_NOBJS];
    long i, j;
    long nobjs_found;
    hsize_t nmembers;
    herr_t  ret;        /* return value */

    /* Register type */
    obj_type = H5Iregister_type((size_t)8, 0, test_rct_free);
    CHECK(obj_type, H5I_BADID, "H5Iregister_type");
    if(obj_type == H5I_BADID)
        goto out;

    /* Init obj_list.list */
    obj_list.list = list;

    for(i = 0; i < TEST_RCT_NITER; i++) {
        /* Build object list */
        obj_list.nobjs = obj_list.nobjs_rem = TEST_RCT_MIN_NOBJS + (HDrandom() % (long)(TEST_RCT_MAX_NOBJS - TEST_RCT_MIN_NOBJS + 1));
        for(j = 0; j < obj_list.nobjs; j++) {
            list[j].nfrees = 0;
            list[j].freeing = FALSE;
            list[j].obj_list = &obj_list;
            list[j].id = H5Iregister(obj_type, &list[j]);
            CHECK(list[j].id, FAIL, "H5Iregister");
            if(list[j].id == FAIL)
                goto out;
            if(HDrandom() % 2) {
                ret = H5Iinc_ref(list[j].id);
                CHECK(ret, FAIL, "H5Iinc_ref");
                if(ret == FAIL)
                    goto out;
            } /* end if */
        } /* end for */

        /* Clear the type */
        ret = H5Iclear_type(obj_type, FALSE);
        CHECK(ret, FAIL, "H5Iclear_type");
        if(ret == FAIL)
            goto out;

        /* Verify list */
        nobjs_found = 0;
        for(j = 0; j < obj_list.nobjs; j++) {
            if(list[j].nfrees == 0)
                nobjs_found++;
            else {
                VERIFY(list[j].nfrees, (long)1, "list[j].nfrees");
                if(list[j].nfrees != (long)1)
                    goto out;
            } /* end else */
            VERIFY(list[j].freeing, FALSE, "list[j].freeing");
            if(list[j].freeing != FALSE)
                goto out;
        } /* end for */

        /* Verify number of objects */
        VERIFY(obj_list.nobjs_rem, nobjs_found, "obj_list.nobjs_rem");
        if(obj_list.nobjs_rem != nobjs_found)
            goto out;
        ret = H5Inmembers(obj_type, &nmembers);
        CHECK(ret, FAIL, "H5Inmembers");
        if(ret == FAIL)
            goto out;
        VERIFY(nmembers, (size_t)nobjs_found, "H5Inmembers");
        if(nmembers != (size_t)nobjs_found)
            goto out;

        /* Clear the type with force set to TRUE */
        ret = H5Iclear_type(obj_type, TRUE);
        CHECK(ret, FAIL, "H5Iclear_type");
        if(ret == FAIL)
            goto out;

        /* Verify list */
        for(j = 0; j < obj_list.nobjs; j++) {
            VERIFY(list[j].nfrees, (long)1, "list[j].nfrees");
            if(list[j].nfrees != (long)1)
                goto out;
            VERIFY(list[j].freeing, FALSE, "list[j].freeing");
            if(list[j].freeing != FALSE)
                goto out;
        } /* end for */

        /* Verify number of objects is 0 */
        VERIFY(obj_list.nobjs_rem, (long)0, "obj_list.nobjs_rem");
        if(obj_list.nobjs_rem != (long)0)
            goto out;
        ret = H5Inmembers(obj_type, &nmembers);
        CHECK(ret, FAIL, "H5Inmembers");
        if(ret == FAIL)
            goto out;
        VERIFY(nmembers, (size_t)0, "H5Inmembers");
        if(nmembers != (size_t)0)
            goto out;
    } /* end for */

    /* Destroy type */
    ret = H5Idestroy_type(obj_type);
    CHECK(ret, FAIL, "H5Idestroy_type");
    if(ret == FAIL)
        goto out;

    return 0;

out:
    /* Cleanup.  For simplicity, just destroy the types and ignore errors. */
    H5E_BEGIN_TRY
    H5Idestroy_type(obj_type);
    H5E_END_TRY
    return -1;
} /* end test_remove_clear_type() */
Ejemplo n.º 7
0
//--------------------------------------------------------------------------
// Function:    IdComponent::incRefCount
///\brief       Increment reference counter for a given id.
// Programmer   Binh-Minh Ribler - May 2005
//--------------------------------------------------------------------------
void IdComponent::incRefCount(const hid_t obj_id) const
{
    if (p_valid_id(obj_id))
        if (H5Iinc_ref(obj_id) < 0)
            throw IdComponentException(inMemFunc("incRefCount"), "incrementing object ref count failed");
}
Ejemplo n.º 8
0
/*-------------------------------------------------------------------------
 * Function: copy_named_datatype
 *
 * Purpose: Copies the specified datatype anonymously, and returns an open
 *          id for that datatype in the output file.  The first time this
 *          is called it scans every named datatype in travt into a
 *          private stack, afterwards it simply scans that stack.  The id
 *          returned must be closed after it is no longer needed.
 *          named_datatype_free must be called before the program exits
 *          to free the stack.
 *-------------------------------------------------------------------------
 */
hid_t copy_named_datatype(hid_t type_in, hid_t fidout,
        named_dt_t **named_dt_head_p, trav_table_t *travt, pack_opt_t *options) {
    named_dt_t *dt = *named_dt_head_p; /* Stack pointer */
    named_dt_t *dt_ret = NULL;         /* Datatype to return */
    H5O_info_t  oinfo;                 /* Object info of input dtype */
    hid_t       ret_value = -1;        /* The identifier of the named dtype in the out file */

    if (H5Oget_info(type_in, &oinfo) < 0)
        HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Oget_info failed");

    if (*named_dt_head_p) {
        /* Stack already exists, search for the datatype */
        while (dt && dt->addr_in != oinfo.addr)
            dt = dt->next;
        dt_ret = dt;
    }
    else {
        /* Create the stack */
        size_t i;

        for (i = 0; i < travt->nobjs; i++) {
            if (travt->objs[i].type == H5TRAV_TYPE_NAMED_DATATYPE) {
                /* Push onto the stack */
                if (NULL == (dt = (named_dt_t *)HDmalloc(sizeof(named_dt_t))))
                    HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "buffer allocation failed failed");
                dt->next = *named_dt_head_p;
                *named_dt_head_p = dt;

                /* Update the address and id */
                dt->addr_in = travt->objs[i].objno;
                dt->id_out = -1;

                /* Check if this type is the one requested */
                if (oinfo.addr == dt->addr_in) {
                    dt_ret = dt;
                } /* end if */
            } /* end if */
        } /* end for */
    } /* end else */

    /* Handle the case that the requested datatype was not found.  This is
    * possible if the datatype was committed anonymously in the input file. */
    if (!dt_ret) {
        /* Push the new datatype onto the stack */
        if (NULL == (dt_ret = (named_dt_t *)HDmalloc(sizeof(named_dt_t))))
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "buffer allocation failed failed");
        dt_ret->next = *named_dt_head_p;
        *named_dt_head_p = dt_ret;

        /* Update the address and id */
        dt_ret->addr_in = oinfo.addr;
        dt_ret->id_out = -1;
    } /* end if */

    /* If the requested datatype does not yet exist in the output file, copy it
    * anonymously */
    if (dt_ret->id_out < 0) {
        if (options->use_native == 1)
            dt_ret->id_out = H5Tget_native_type(type_in, H5T_DIR_DEFAULT);
        else
            dt_ret->id_out = H5Tcopy(type_in);
        if (dt_ret->id_out < 0)
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tget_native_type-H5Tcopy failed");
        if (H5Tcommit_anon(fidout, dt_ret->id_out, H5P_DEFAULT, H5P_DEFAULT) < 0)
            HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Tcommit_anon failed");
    } /* end if */

    /* Set return value */
    ret_value = dt_ret->id_out;

    /* Increment the ref count on id_out, because the calling function will try to close it */
    if(H5Iinc_ref(ret_value) < 0)
        HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Iinc_ref failed");

done:
    return ret_value;
} /* end copy_named_datatype */