void check_md5(rainbow_t *r, string_table_t *table) { /* Check for an existing bucket */ for (int i = 0; i < ENTRY_SIZE; i++) { md5_binary_t *binary = &r->hashes[i], *start; unsigned int bucket = calc_bucket_binary(binary); uint32_t s = array[bucket]; /* If its an empty bucket, just bail */ if (likely(s == UINT32_MAX)) continue; /* If we have a stored top and it doesn't match, continue */ if (get_top(s) && (calc_top_binary(binary) != get_top(s))) continue; /* Search for a match */ for (start = hash_buff + remove_top(s); start->r64[0] < binary->r64[0]; start++) { } for (; start->r64[0] == binary->r64[0]; start++) { if (start->r64[1] == binary->r64[1]) { print_found(r, i, table); start->r64[1] = 0; __sync_fetch_and_add(&match, 1); break; } } } }
/* Print the buffer */ static void buffer_print(void) { unsigned i; move_cursor(0, 0); for (i = 0; i <= max_displayed_line; i++) if (pattern_valid) print_found(buffer[i]); else print_ascii(buffer[i]); status_print(); }
hsize_t diff_attr(hid_t loc1_id, hid_t loc2_id, const char *path1, const char *path2, diff_opt_t *options) { hid_t attr1_id=-1; /* attr ID */ hid_t attr2_id=-1; /* attr ID */ hid_t space1_id=-1; /* space ID */ hid_t space2_id=-1; /* space ID */ hid_t ftype1_id=-1; /* file data type ID */ hid_t ftype2_id=-1; /* file data type ID */ hid_t mtype1_id=-1; /* memory data type ID */ hid_t mtype2_id=-1; /* memory data type ID */ size_t msize1; /* memory size of memory type */ size_t msize2; /* memory size of memory type */ void *buf1=NULL; /* data buffer */ void *buf2=NULL; /* data buffer */ hsize_t nelmts1; /* number of elements in dataset */ int rank1; /* rank of dataset */ int rank2; /* rank of dataset */ hsize_t dims1[H5S_MAX_RANK];/* dimensions of dataset */ hsize_t dims2[H5S_MAX_RANK];/* dimensions of dataset */ char name1[512]; char name2[512]; char np1[512]; char np2[512]; H5O_info_t oinfo1, oinfo2; /* Object info */ unsigned u; /* Local index variable */ hsize_t nfound = 0; hsize_t nfound_total = 0; int j; if(H5Oget_info(loc1_id, &oinfo1) < 0) goto error; if(H5Oget_info(loc2_id, &oinfo2) < 0) goto error; if(oinfo1.num_attrs != oinfo2.num_attrs) return 1; for( u = 0; u < (unsigned)oinfo1.num_attrs; u++) { /* reset buffers for every attribute, we might goto out and call free */ buf1 = NULL; buf2 = NULL; /* open attribute */ if((attr1_id = H5Aopen_by_idx(loc1_id, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)u, H5P_DEFAULT, H5P_DEFAULT)) < 0) goto error; /* get name */ if(H5Aget_name(attr1_id, 255, name1) < 0) goto error; /* use the name on the first file to open the second file */ H5E_BEGIN_TRY { if((attr2_id = H5Aopen(loc2_id, name1, H5P_DEFAULT)) < 0) goto error; } H5E_END_TRY; /* get name */ if(H5Aget_name(attr2_id, 255, name2) < 0) goto error; /* get the datatypes */ if ((ftype1_id = H5Aget_type(attr1_id)) < 0) goto error; if ((ftype2_id = H5Aget_type(attr2_id)) < 0) goto error; if ((mtype1_id = h5tools_get_native_type(ftype1_id))<0) goto error; if ((mtype2_id = h5tools_get_native_type(ftype2_id))<0) goto error; if ((msize1 = H5Tget_size(mtype1_id))==0) goto error; if ((msize2 = H5Tget_size(mtype2_id))==0) goto error; /* get the dataspace */ if ((space1_id = H5Aget_space(attr1_id)) < 0) goto error; if ((space2_id = H5Aget_space(attr2_id)) < 0) goto error; /* get dimensions */ if ( (rank1 = H5Sget_simple_extent_dims(space1_id, dims1, NULL)) < 0 ) goto error; if ( (rank2 = H5Sget_simple_extent_dims(space2_id, dims2, NULL)) < 0 ) goto error; /*------------------------------------------------------------------------- * check for comparable TYPE and SPACE *------------------------------------------------------------------------- */ if ( msize1 != msize2 || diff_can_type(ftype1_id, ftype2_id, rank1, rank2, dims1, dims2, NULL, NULL, name1, name2, options, 0)!=1) { if (H5Tclose(ftype1_id)<0) goto error; if (H5Tclose(ftype2_id)<0) goto error; if (H5Sclose(space1_id)<0) goto error; if (H5Sclose(space2_id)<0) goto error; if (H5Aclose(attr1_id)<0) goto error; if (H5Aclose(attr2_id)<0) goto error; if (H5Tclose(mtype1_id)<0) goto error; if (H5Tclose(mtype2_id)<0) goto error; continue; } /*------------------------------------------------------------------------- * read *------------------------------------------------------------------------- */ nelmts1=1; for (j=0; j<rank1; j++) nelmts1*=dims1[j]; buf1=(void *) HDmalloc((unsigned)(nelmts1*msize1)); buf2=(void *) HDmalloc((unsigned)(nelmts1*msize2)); if ( buf1==NULL || buf2==NULL){ parallel_print( "cannot read into memory\n" ); goto error; } if (H5Aread(attr1_id,mtype1_id,buf1)<0) goto error; if (H5Aread(attr2_id,mtype2_id,buf2)<0) goto error; /* format output string */ sprintf(np1,"%s of <%s>",name1,path1); sprintf(np2,"%s of <%s>",name2,path2); /*------------------------------------------------------------------------- * array compare *------------------------------------------------------------------------- */ /* always print name */ if (options->m_verbose) { do_print_objname ("attribute", np1, np2); nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1, options, np1, np2, mtype1_id, attr1_id, attr2_id); print_found(nfound); } /* check first if we have differences */ else { if (options->m_quiet==0) { /* shut up temporarily */ options->m_quiet=1; nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1, options, np1, np2, mtype1_id, attr1_id, attr2_id); /* print again */ options->m_quiet=0; if (nfound) { do_print_objname ("attribute", np1, np2); nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1, options, np1, np2, mtype1_id, attr1_id, attr2_id); print_found(nfound); } /*if*/ } /*if*/ /* in quiet mode, just count differences */ else { nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1, options, np1, np2, mtype1_id, attr1_id, attr2_id); } /*else quiet */ } /*else verbose */ /*------------------------------------------------------------------------- * close *------------------------------------------------------------------------- */ if (H5Tclose(ftype1_id)<0) goto error; if (H5Tclose(ftype2_id)<0) goto error; if (H5Sclose(space1_id)<0) goto error; if (H5Sclose(space2_id)<0) goto error; if (H5Aclose(attr1_id)<0) goto error; if (H5Aclose(attr2_id)<0) goto error; if (H5Tclose(mtype1_id)<0) goto error; if (H5Tclose(mtype2_id)<0) goto error; if (buf1) HDfree(buf1); if (buf2) HDfree(buf2); nfound_total += nfound; } /* u */ return nfound_total; error: H5E_BEGIN_TRY { H5Tclose(ftype1_id); H5Tclose(ftype2_id); H5Tclose(mtype1_id); H5Tclose(mtype2_id); H5Sclose(space1_id); H5Sclose(space2_id); H5Aclose(attr1_id); H5Aclose(attr2_id); if (buf1) HDfree(buf1); if (buf2) HDfree(buf2); } H5E_END_TRY; options->err_stat=1; return nfound_total; }
hsize_t diff_attr(hid_t loc1_id, hid_t loc2_id, const char *path1, const char *path2, diff_opt_t *options) { hid_t attr1_id=-1; /* attr ID */ hid_t attr2_id=-1; /* attr ID */ hid_t space1_id=-1; /* space ID */ hid_t space2_id=-1; /* space ID */ hid_t ftype1_id=-1; /* file data type ID */ hid_t ftype2_id=-1; /* file data type ID */ int vstrtype1=0; /* ftype1 is a variable string */ int vstrtype2=0; /* ftype2 is a variable string */ hid_t mtype1_id=-1; /* memory data type ID */ hid_t mtype2_id=-1; /* memory data type ID */ size_t msize1; /* memory size of memory type */ size_t msize2; /* memory size of memory type */ void *buf1=NULL; /* data buffer */ void *buf2=NULL; /* data buffer */ int buf1hasdata=0; /* buffer has data */ int buf2hasdata=0; /* buffer has data */ hsize_t nelmts1; /* number of elements in dataset */ int rank1; /* rank of dataset */ int rank2; /* rank of dataset */ hsize_t dims1[H5S_MAX_RANK];/* dimensions of dataset */ hsize_t dims2[H5S_MAX_RANK];/* dimensions of dataset */ char *name1; char *name2; char np1[512]; char np2[512]; unsigned u; /* Local index variable */ hsize_t nfound = 0; hsize_t nfound_total = 0; int j; table_attrs_t * match_list_attrs = NULL; if( build_match_list_attrs(loc1_id, loc2_id, &match_list_attrs, options) < 0) goto error; /* if detect any unique extra attr */ if(match_list_attrs->nattrs_only1 || match_list_attrs->nattrs_only2) { /* exit will be 1 */ options->contents = 0; } for(u = 0; u < (unsigned)match_list_attrs->nattrs; u++) { if( (match_list_attrs->attrs[u].exist[0]) && (match_list_attrs->attrs[u].exist[1]) ) { name1 = name2 = match_list_attrs->attrs[u].name; /*-------------- * attribute 1 */ if((attr1_id = H5Aopen(loc1_id, name1, H5P_DEFAULT)) < 0) goto error; /*-------------- * attribute 2 */ if((attr2_id = H5Aopen(loc2_id, name2, H5P_DEFAULT)) < 0) goto error; /* get the datatypes */ if((ftype1_id = H5Aget_type(attr1_id)) < 0) goto error; vstrtype1 = H5Tis_variable_str(ftype1_id); if((ftype2_id = H5Aget_type(attr2_id)) < 0) goto error; vstrtype2 = H5Tis_variable_str(ftype2_id); /* no compare if either one but not both are variable string type */ if (vstrtype1 != vstrtype2){ if ((options->m_verbose||options->m_list_not_cmp)) parallel_print("Not comparable: one of attribute <%s/%s> or <%s/%s> is of variable length type\n", path1, name1, path2, name2); options->not_cmp = 1; return 0; } if((mtype1_id = h5tools_get_native_type(ftype1_id))<0) goto error; if((mtype2_id = h5tools_get_native_type(ftype2_id))<0) goto error; if((msize1 = H5Tget_size(mtype1_id))==0) goto error; if((msize2 = H5Tget_size(mtype2_id))==0) goto error; /* get the dataspace */ if((space1_id = H5Aget_space(attr1_id)) < 0) goto error; if((space2_id = H5Aget_space(attr2_id)) < 0) goto error; /* get dimensions */ if((rank1 = H5Sget_simple_extent_dims(space1_id, dims1, NULL)) < 0) goto error; if((rank2 = H5Sget_simple_extent_dims(space2_id, dims2, NULL)) < 0) goto error; /*---------------------------------------------------------------------- * check for comparable TYPE and SPACE *---------------------------------------------------------------------- */ /* pass dims1 and dims2 for maxdims as well since attribute's maxdims * are always same */ if( diff_can_type(ftype1_id, ftype2_id, rank1, rank2, dims1, dims2, dims1, dims2, name1, name2, options, 0) != 1 ) { if(H5Tclose(ftype1_id) < 0) goto error; if(H5Tclose(ftype2_id) < 0) goto error; if(H5Sclose(space1_id) < 0) goto error; if(H5Sclose(space2_id) < 0) goto error; if(H5Aclose(attr1_id) < 0) goto error; if(H5Aclose(attr2_id) < 0) goto error; if(H5Tclose(mtype1_id) < 0) goto error; if(H5Tclose(mtype2_id) < 0) goto error; continue; } /*----------------------------------------------------------------- * "upgrade" the smaller memory size *------------------------------------------------------------------ */ if (FAIL == match_up_memsize (ftype1_id, ftype2_id, &mtype1_id, &mtype2_id, &msize1, &msize2)) goto error; /*--------------------------------------------------------------------- * read *---------------------------------------------------------------------- */ nelmts1 = 1; for(j = 0; j < rank1; j++) nelmts1 *= dims1[j]; buf1 = (void *)HDmalloc((size_t)(nelmts1 * msize1)); buf2 = (void *)HDmalloc((size_t)(nelmts1 * msize2)); if(buf1 == NULL || buf2 == NULL){ parallel_print( "cannot read into memory\n" ); goto error; } if(H5Aread(attr1_id,mtype1_id,buf1) < 0){ parallel_print("Failed reading attribute1 %s/%s\n", path1, name1); goto error; }else buf1hasdata = 1; if(H5Aread(attr2_id,mtype2_id,buf2) < 0){ parallel_print("Failed reading attribute2 %s/%s\n", path2, name2); goto error; }else buf2hasdata = 1; /* format output string */ HDsnprintf(np1, sizeof(np1), "%s of <%s>", name1, path1); HDsnprintf(np2, sizeof(np1), "%s of <%s>", name2, path2); /*--------------------------------------------------------------------- * array compare *---------------------------------------------------------------------- */ /* always print name */ /* verbose (-v) and report (-r) mode */ if(options->m_verbose || options->m_report) { do_print_attrname("attribute", np1, np2); nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1, options, np1, np2, mtype1_id, attr1_id, attr2_id); print_found(nfound); } /* quiet mode (-q), just count differences */ else if(options->m_quiet) { nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1, options, np1, np2, mtype1_id, attr1_id, attr2_id); } /* the rest (-c, none, ...) */ else { nfound = diff_array(buf1, buf2, nelmts1, (hsize_t)0, rank1, dims1, options, np1, np2, mtype1_id, attr1_id, attr2_id); /* print info if compatible and difference found */ if(nfound) { do_print_attrname("attribute", np1, np2); print_found(nfound); } /* end if */ } /* end else */ /*---------------------------------------------------------------------- * close *---------------------------------------------------------------------- */ /* Free buf1 and buf2, check both VLEN-data VLEN-string to reclaim any * VLEN memory first */ if(TRUE == h5tools_detect_vlen(mtype1_id)) H5Dvlen_reclaim(mtype1_id, space1_id, H5P_DEFAULT, buf1); HDfree(buf1); buf1 = NULL; if(TRUE == h5tools_detect_vlen(mtype2_id)) H5Dvlen_reclaim(mtype2_id, space2_id, H5P_DEFAULT, buf2); HDfree(buf2); buf2 = NULL; if(H5Tclose(ftype1_id) < 0) goto error; if(H5Tclose(ftype2_id) < 0) goto error; if(H5Sclose(space1_id) < 0) goto error; if(H5Sclose(space2_id) < 0) goto error; if(H5Aclose(attr1_id) < 0) goto error; if(H5Aclose(attr2_id) < 0) goto error; if(H5Tclose(mtype1_id) < 0) goto error; if(H5Tclose(mtype2_id) < 0) goto error; nfound_total += nfound; } } /* u */ table_attrs_free(match_list_attrs); return nfound_total; error: H5E_BEGIN_TRY { if(buf1) { if(buf1hasdata && TRUE == h5tools_detect_vlen(mtype1_id)) H5Dvlen_reclaim(mtype1_id, space1_id, H5P_DEFAULT, buf1); HDfree(buf1); } /* end if */ if(buf2) { if(buf2hasdata && TRUE == h5tools_detect_vlen(mtype2_id)) H5Dvlen_reclaim(mtype2_id, space2_id, H5P_DEFAULT, buf2); HDfree(buf2); } /* end if */ table_attrs_free(match_list_attrs); H5Tclose(ftype1_id); H5Tclose(ftype2_id); H5Tclose(mtype1_id); H5Tclose(mtype2_id); H5Sclose(space1_id); H5Sclose(space2_id); H5Aclose(attr1_id); H5Aclose(attr2_id); } H5E_END_TRY; options->err_stat = 1; return nfound_total; }